|
|
|
@ -15,6 +15,7 @@ |
|
|
|
|
struct mufs_file { |
|
|
|
|
struct mufs *fs; |
|
|
|
|
struct mufs_tree *tree; |
|
|
|
|
int mode; |
|
|
|
|
uint32_t va; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -23,7 +24,7 @@ int mufs_create(struct mufs *fs, const char *path) |
|
|
|
|
return mufs_mkpath(fs, path, MUFS_FILE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct mufs_file *mufs_open(struct mufs *fs, const char *path) |
|
|
|
|
struct mufs_file *mufs_open(struct mufs *fs, const char *path, int mode) |
|
|
|
|
{ |
|
|
|
|
struct mufs_file *file; |
|
|
|
|
|
|
|
|
@ -35,6 +36,7 @@ struct mufs_file *mufs_open(struct mufs *fs, const char *path) |
|
|
|
|
if (!(file->tree = resolve_path(fs, path))) |
|
|
|
|
goto err_free_file; |
|
|
|
|
|
|
|
|
|
file->mode = mode; |
|
|
|
|
file->va = 0; |
|
|
|
|
|
|
|
|
|
return file; |
|
|
|
@ -59,6 +61,9 @@ size_t mufs_read(struct mufs_file *file, void *data, size_t len) |
|
|
|
|
if (!file || !data || !len) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
if (!(file->mode & MUFS_READ)) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
if (!(ret = mufs_tree_read(file->tree, data, file->va, len))) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
@ -74,6 +79,12 @@ size_t mufs_write(struct mufs_file *file, const void *data, size_t len) |
|
|
|
|
if (!file || !data || !len) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
if (!(file->mode & MUFS_WRITE)) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
if (file->mode & MUFS_APPEND) |
|
|
|
|
file->va = file->tree->file_size; |
|
|
|
|
|
|
|
|
|
if (!(ret = mufs_tree_write(file->tree, (void *)data, file->va, len))) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|