From a45be58d26811414d05a433f6d21e2afa92ced1c Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Wed, 14 Jun 2017 12:18:07 +0200 Subject: [PATCH] mufs: add subtree argument to mkpath() to create a path for an existing tree object --- source/fs/mufs/dir.c | 2 +- source/fs/mufs/file.c | 2 +- source/fs/mufs/path.c | 14 ++++++++++---- source/fs/mufs/path.h | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/source/fs/mufs/dir.c b/source/fs/mufs/dir.c index 6eb0d8e..b64dfd6 100644 --- a/source/fs/mufs/dir.c +++ b/source/fs/mufs/dir.c @@ -316,7 +316,7 @@ int mufs_readdir(struct mufs_dir *dir, struct mufs_dirent *dirent) int mufs_mkdir(struct mufs *fs, const char *path) { - return mufs_mkpath(fs, path, MUFS_DIR); + return mufs_mkpath(fs, path, NULL, MUFS_DIR); } int mufs_rmdir(struct mufs *fs, const char *path) diff --git a/source/fs/mufs/file.c b/source/fs/mufs/file.c index c70aa40..dfa8567 100644 --- a/source/fs/mufs/file.c +++ b/source/fs/mufs/file.c @@ -21,7 +21,7 @@ struct mufs_file { int mufs_create(struct mufs *fs, const char *path) { - return mufs_mkpath(fs, path, MUFS_FILE); + return mufs_mkpath(fs, path, NULL, MUFS_FILE); } struct mufs_file *mufs_open(struct mufs *fs, const char *path, int mode) diff --git a/source/fs/mufs/path.c b/source/fs/mufs/path.c index 6a1b4ff..9e6aaeb 100644 --- a/source/fs/mufs/path.c +++ b/source/fs/mufs/path.c @@ -13,7 +13,8 @@ #include "path.h" #include "tree.h" -int mufs_mkpath(struct mufs *fs, const char *path, unsigned type) +int mufs_mkpath(struct mufs *fs, const char *path, struct mufs_tree *subtree, + unsigned type) { struct mufs_stat stat; struct mufs_dirent dirent; @@ -43,15 +44,20 @@ int mufs_mkpath(struct mufs *fs, const char *path, unsigned type) if (!(tree = resolve_path(fs, s, &stat)) || stat.type != MUFS_DIR) return -1; + memset(&dirent, 0, sizeof dirent); + len = min(strlen(name), sizeof(dirent.path) - 1); memcpy(dirent.path, name, len); dirent.path[len] = '\0'; dirent.type = type; dirent.tree.fs = fs; - dirent.tree.file_size = 0; - dirent.tree.root = 0; - dirent.tree.depth = 0; + + if (subtree) { + dirent.tree.file_size = subtree->file_size; + dirent.tree.root = subtree->root; + dirent.tree.depth = subtree->depth; + } tree->file_size = find_dirent_size(fs, tree, tree->file_size); diff --git a/source/fs/mufs/path.h b/source/fs/mufs/path.h index 160c698..9cc5259 100644 --- a/source/fs/mufs/path.h +++ b/source/fs/mufs/path.h @@ -1,4 +1,5 @@ #pragma once -int mufs_mkpath(struct mufs *fs, const char *path, unsigned type); +int mufs_mkpath(struct mufs *fs, const char *path, struct mufs_tree *subtree, + unsigned type); int mufs_rmpath(struct mufs *fs, const char *path);