parent
1c736c3324
commit
a65cdbfedf
@ -0,0 +1,68 @@ |
|||||||
|
#include <stddef.h> |
||||||
|
#include <stdint.h> |
||||||
|
#include <stdio.h> |
||||||
|
#include <stdlib.h> |
||||||
|
#include <string.h> |
||||||
|
|
||||||
|
#include <flash.h> |
||||||
|
#include <macros.h> |
||||||
|
|
||||||
|
#include <fs/mufs.h> |
||||||
|
|
||||||
|
#include "dir.h" |
||||||
|
#include "path.h" |
||||||
|
#include "tree.h" |
||||||
|
|
||||||
|
int mufs_mkpath(struct mufs *fs, const char *path, unsigned type) |
||||||
|
{ |
||||||
|
struct mufs_dirent dirent; |
||||||
|
struct mufs_tree *tree; |
||||||
|
size_t len; |
||||||
|
char *s; |
||||||
|
char *name; |
||||||
|
|
||||||
|
if (!path || *path == '\0') |
||||||
|
return -1; |
||||||
|
|
||||||
|
if (!(s = mufs_abspath(path))) |
||||||
|
return -1; |
||||||
|
|
||||||
|
/* TODO: already exists. */ |
||||||
|
if (resolve_path(fs, s)) { |
||||||
|
free(s); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
if (!(name = strrchr(s, '/'))) { |
||||||
|
name = s; |
||||||
|
s = "/"; |
||||||
|
} else { |
||||||
|
*name++ = '\0'; |
||||||
|
} |
||||||
|
|
||||||
|
if (*name == '\0') |
||||||
|
return -1; |
||||||
|
|
||||||
|
if (!(tree = resolve_path(fs, s))) |
||||||
|
return -1; |
||||||
|
|
||||||
|
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 (!is_aligned(tree->file_size, fs->dev->log2_block_size) && |
||||||
|
write_dirent(tree, tree->file_size, &dirent) > 0) |
||||||
|
return 0; |
||||||
|
|
||||||
|
if (write_dirent(tree, align_up(tree->file_size, |
||||||
|
fs->dev->log2_block_size), &dirent) > 0) |
||||||
|
return 0; |
||||||
|
|
||||||
|
return -1; |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
int mufs_mkpath(struct mufs *fs, const char *path, unsigned type); |
Loading…
Reference in new issue