mufs: create file when opening a file for writing

This commit is contained in:
S.J.R. van Schaik 2017-06-12 17:20:23 +02:00
parent 4e02f0417b
commit 2cac788ba7

View file

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