diff --git a/source/fs/mufs/file.c b/source/fs/mufs/file.c index a8e8db7..26eee33 100644 --- a/source/fs/mufs/file.c +++ b/source/fs/mufs/file.c @@ -34,7 +34,18 @@ struct mufs_file *mufs_open(struct mufs *fs, const char *path, int mode) file->fs = fs; - if (!(file->tree = resolve_path(fs, path, &stat)) || stat.type != MUFS_FILE) + if (!(file->tree = resolve_path(fs, path, &stat))) { + if (!(mode & MUFS_WRITE)) + goto err_free_file; + + if (mufs_create(fs, path) < 0) + goto err_free_file; + + if (!(file->tree = resolve_path(fs, path, &stat))) + goto err_free_file; + } + + if (stat.type != MUFS_FILE) goto err_free_file; file->mode = mode;