MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_file_unlink

Function dfs_file_unlink

components/dfs/dfs_v1/src/dfs_file.c:484–528  ·  view source on GitHub ↗

* this function will unlink (remove) a specified path file from file system. * * @param path the specified path file to be unlinked. * * @return 0 on successful, -1 on failed. */

Source from the content-addressed store, hash-verified

482 * @return 0 on successful, -1 on failed.
483 */
484int dfs_file_unlink(const char *path)
485{
486 int result;
487 char *fullpath;
488 struct dfs_filesystem *fs;
489
490 /* Make sure we have an absolute path */
491 fullpath = dfs_normalize_path(NULL, path);
492 if (fullpath == NULL)
493 {
494 return -EINVAL;
495 }
496
497 /* Check whether file is already open */
498 if (dfs_file_is_open(fullpath))
499 {
500 result = -EBUSY;
501 goto __exit;
502 }
503
504 /* get filesystem */
505 if ((fs = dfs_filesystem_lookup(fullpath)) == NULL)
506 {
507 result = -ENOENT;
508 goto __exit;
509 }
510
511 if (fs->ops->unlink != NULL)
512 {
513 if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
514 {
515 if (dfs_subdir(fs->path, fullpath) == NULL)
516 result = fs->ops->unlink(fs, "/");
517 else
518 result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath));
519 }
520 else
521 result = fs->ops->unlink(fs, fullpath);
522 }
523 else result = -ENOSYS;
524
525__exit:
526 rt_free(fullpath);
527 return result;
528}
529
530/**
531 * this function will write some specified length data to file system.

Callers 7

unlinkFunction · 0.70
rmdirFunction · 0.70
rmFunction · 0.70
test_dfs_unlinkFunction · 0.50
test_dfs_renameFunction · 0.50
utest_tc_initFunction · 0.50
utest_tc_cleanupFunction · 0.50

Calls 5

dfs_file_is_openFunction · 0.85
dfs_filesystem_lookupFunction · 0.85
rt_freeFunction · 0.85
dfs_normalize_pathFunction · 0.70
dfs_subdirFunction · 0.70

Tested by 2

test_dfs_unlinkFunction · 0.40
test_dfs_renameFunction · 0.40