mufs: add subtree argument to mkpath() to create a path for an existing tree object

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 8921af25b3
commit a45be58d26
  1. 2
      source/fs/mufs/dir.c
  2. 2
      source/fs/mufs/file.c
  3. 14
      source/fs/mufs/path.c
  4. 3
      source/fs/mufs/path.h

@ -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)

@ -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)

@ -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);

@ -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);

Loading…
Cancel
Save