From 65c1fc28d3eae3c34e1bab8a890cfdf9af4dbb79 Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Mon, 12 Jun 2017 15:37:22 +0200 Subject: [PATCH] mufs: implement mufs_unlink() --- include/fs/mufs.h | 1 + source/fs/mufs/file.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/fs/mufs.h b/include/fs/mufs.h index 1fc93ac..d1a253f 100644 --- a/include/fs/mufs.h +++ b/include/fs/mufs.h @@ -56,3 +56,4 @@ void mufs_close(struct mufs_file *file); long mufs_seek(struct mufs_file *file, long offset, int whence); size_t mufs_read(struct mufs_file *file, void *data, size_t len); size_t mufs_write(struct mufs_file *file, const void *data, size_t len); +int mufs_unlink(struct mufs *fs, const char *path); diff --git a/source/fs/mufs/file.c b/source/fs/mufs/file.c index 9c146af..a8e8db7 100644 --- a/source/fs/mufs/file.c +++ b/source/fs/mufs/file.c @@ -116,3 +116,20 @@ size_t mufs_write(struct mufs_file *file, const void *data, size_t len) return ret; } + +int mufs_unlink(struct mufs *fs, const char *path) +{ + struct mufs_stat stat; + struct mufs_tree *tree; + + if (!(tree = resolve_path(fs, path, &stat))) + return -1; + + if (stat.type != MUFS_FILE) + return -1; + + if (mufs_shrink_tree(tree, 0) < 0) + return -1; + + return mufs_rmpath(fs, path); +}