diff --git a/lfs.c b/lfs.c index b9e3bfc0..ce1a9afd 100644 --- a/lfs.c +++ b/lfs.c @@ -3070,15 +3070,26 @@ static int lfs_file_opencfg_(lfs_t *lfs, lfs_file_t *file, file->off = 0; file->cache.buffer = NULL; - // allocate entry for file if it doesn't exist - lfs_stag_t tag = lfs_dir_find(lfs, &file->m, &path, &file->id); - if (tag < 0 && !(tag == LFS_ERR_NOENT && file->id != 0x3ff)) { - err = tag; - goto cleanup; + lfs_stag_t tag; + // special case for root + if (path == NULL || *path == '\0' || strcmp(path, "/") == 0) { + tag = 0x3ff; + file->type = LFS_TYPE_DIR; + err = lfs_dir_fetch(lfs, &file->m, lfs->root); + if (err) { + goto cleanup; + } + } else { + // allocate entry for file if it doesn't exist + tag = lfs_dir_find(lfs, &file->m, &path, &file->id); + file->type = (tag == LFS_ERR_NOENT) ? LFS_TYPE_REG : lfs_tag_type3(tag); + if (tag < 0 && !(tag == LFS_ERR_NOENT && file->id != 0x3ff)) { + err = tag; + goto cleanup; + } } // get id, add to list of mdirs to catch update changes - file->type = LFS_TYPE_REG; lfs_mlist_append(lfs, (struct lfs_mlist *)file); #ifdef LFS_READONLY @@ -3117,16 +3128,20 @@ static int lfs_file_opencfg_(lfs_t *lfs, lfs_file_t *file, err = LFS_ERR_EXIST; goto cleanup; #endif - } else if (lfs_tag_type3(tag) != LFS_TYPE_REG) { - err = LFS_ERR_ISDIR; + } else if (file->type != LFS_TYPE_REG && file->type != LFS_TYPE_DIR) { + err = LFS_ERR_NOENT; goto cleanup; #ifndef LFS_READONLY } else if (flags & LFS_O_TRUNC) { + if(file->type != LFS_TYPE_REG) { + err = LFS_ERR_ISDIR; + goto cleanup; + } // truncate if requested tag = LFS_MKTAG(LFS_TYPE_INLINESTRUCT, file->id, 0); file->flags |= LFS_F_DIRTY; #endif - } else { + } else if (file->type == LFS_TYPE_REG) { // try to load what's on disk, if it's inlined we'll fix it later tag = lfs_dir_get(lfs, &file->m, LFS_MKTAG(0x700, 0x3ff, 0), LFS_MKTAG(LFS_TYPE_STRUCT, file->id, 8), &file->ctz); @@ -3327,6 +3342,10 @@ static int lfs_file_outline(lfs_t *lfs, lfs_file_t *file) { #endif static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { + if (file->type != LFS_TYPE_REG) { + return LFS_ERR_ISDIR; + } + if (file->flags & LFS_F_READING) { if (!(file->flags & LFS_F_INLINE)) { lfs_cache_drop(lfs, &file->cache); @@ -3341,6 +3360,7 @@ static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { if (!(file->flags & LFS_F_INLINE)) { // copy over anything after current branch lfs_file_t orig = { + .type = file->type, .ctz.head = file->ctz.head, .ctz.size = file->ctz.size, .flags = LFS_O_RDONLY, @@ -3408,6 +3428,10 @@ static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { #ifndef LFS_READONLY static int lfs_file_sync_(lfs_t *lfs, lfs_file_t *file) { + if (file->type != LFS_TYPE_REG) { + return 0; + } + if (file->flags & LFS_F_ERRED) { // it's not safe to do anything if our file errored return 0; @@ -3533,6 +3557,10 @@ static lfs_ssize_t lfs_file_read_(lfs_t *lfs, lfs_file_t *file, void *buffer, lfs_size_t size) { LFS_ASSERT((file->flags & LFS_O_RDONLY) == LFS_O_RDONLY); + if (file->type != LFS_TYPE_REG) { + return 0; + } + #ifndef LFS_READONLY if (file->flags & LFS_F_WRITING) { // flush out any writes @@ -3636,6 +3664,10 @@ static lfs_ssize_t lfs_file_write_(lfs_t *lfs, lfs_file_t *file, const void *buffer, lfs_size_t size) { LFS_ASSERT((file->flags & LFS_O_WRONLY) == LFS_O_WRONLY); + if (file->type != LFS_TYPE_REG) { + return (size == 0) ? 0 : LFS_ERR_ISDIR; + } + if (file->flags & LFS_F_READING) { // drop any reads int err = lfs_file_flush(lfs, file); @@ -3678,6 +3710,10 @@ static lfs_ssize_t lfs_file_write_(lfs_t *lfs, lfs_file_t *file, static lfs_soff_t lfs_file_seek_(lfs_t *lfs, lfs_file_t *file, lfs_soff_t off, int whence) { + if (file->type != LFS_TYPE_REG) { + return LFS_ERR_ISDIR; + } + // find new pos lfs_off_t npos = file->pos; if (whence == LFS_SEEK_SET) { @@ -3743,6 +3779,10 @@ static lfs_soff_t lfs_file_seek_(lfs_t *lfs, lfs_file_t *file, static int lfs_file_truncate_(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { LFS_ASSERT((file->flags & LFS_O_WRONLY) == LFS_O_WRONLY); + if (file->type != LFS_TYPE_REG) { + return LFS_ERR_ISDIR; + } + if (size > LFS_FILE_MAX) { return LFS_ERR_INVAL; } @@ -3824,6 +3864,9 @@ static int lfs_file_truncate_(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { static lfs_soff_t lfs_file_tell_(lfs_t *lfs, lfs_file_t *file) { (void)lfs; + if (file->type != LFS_TYPE_REG) { + return LFS_ERR_ISDIR; + } return file->pos; } @@ -3839,6 +3882,10 @@ static int lfs_file_rewind_(lfs_t *lfs, lfs_file_t *file) { static lfs_soff_t lfs_file_size_(lfs_t *lfs, lfs_file_t *file) { (void)lfs; + if (file->type != LFS_TYPE_REG) { + return 0; + } + #ifndef LFS_READONLY if (file->flags & LFS_F_WRITING) { return lfs_max(file->pos, file->ctz.size); diff --git a/tests/test_attrs.toml b/tests/test_attrs.toml index 3c69001c..5532a5df 100644 --- a/tests/test_attrs.toml +++ b/tests/test_attrs.toml @@ -161,156 +161,176 @@ code = ''' [cases.test_attrs_get_set_file] code = ''' - lfs_t lfs; - lfs_format(&lfs, cfg) => 0; - lfs_mount(&lfs, cfg) => 0; - lfs_mkdir(&lfs, "hello") => 0; - lfs_file_t file; - lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); - lfs_file_close(&lfs, &file); - lfs_unmount(&lfs) => 0; - - lfs_mount(&lfs, cfg) => 0; - uint8_t buffer[1024]; - memset(buffer, 0, sizeof(buffer)); - struct lfs_attr attrs1[] = { - {'A', buffer, 4}, - {'B', buffer+4, 6}, - {'C', buffer+10, 5}, - }; - struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; - - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; - memcpy(buffer, "aaaa", 4); - memcpy(buffer+4, "bbbbbb", 6); - memcpy(buffer+10, "ccccc", 5); - lfs_file_close(&lfs, &file) => 0; - memset(buffer, 0, 15); - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file) => 0; - memcmp(buffer, "aaaa", 4) => 0; - memcmp(buffer+4, "bbbbbb", 6) => 0; - memcmp(buffer+10, "ccccc", 5) => 0; - - attrs1[1].size = 0; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file) => 0; - memset(buffer, 0, 15); - attrs1[1].size = 6; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file) => 0; - memcmp(buffer, "aaaa", 4) => 0; - memcmp(buffer+4, "\0\0\0\0\0\0", 6) => 0; - memcmp(buffer+10, "ccccc", 5) => 0; - - attrs1[1].size = 6; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; - memcpy(buffer+4, "dddddd", 6); - lfs_file_close(&lfs, &file) => 0; - memset(buffer, 0, 15); - attrs1[1].size = 6; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file) => 0; - memcmp(buffer, "aaaa", 4) => 0; - memcmp(buffer+4, "dddddd", 6) => 0; - memcmp(buffer+10, "ccccc", 5) => 0; - - attrs1[1].size = 3; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; - memcpy(buffer+4, "eee", 3); - lfs_file_close(&lfs, &file) => 0; - memset(buffer, 0, 15); - attrs1[1].size = 6; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file) => 0; - memcmp(buffer, "aaaa", 4) => 0; - memcmp(buffer+4, "eee\0\0\0", 6) => 0; - memcmp(buffer+10, "ccccc", 5) => 0; - - attrs1[0].size = LFS_ATTR_MAX+1; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) - => LFS_ERR_NOSPC; - - struct lfs_attr attrs2[] = { - {'A', buffer, 4}, - {'B', buffer+4, 9}, - {'C', buffer+13, 5}, - }; - struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3}; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDWR, &cfg2) => 0; - memcpy(buffer+4, "fffffffff", 9); - lfs_file_close(&lfs, &file) => 0; - attrs1[0].size = 4; - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file) => 0; - - lfs_unmount(&lfs) => 0; - - lfs_mount(&lfs, cfg) => 0; - memset(buffer, 0, sizeof(buffer)); - struct lfs_attr attrs3[] = { - {'A', buffer, 4}, - {'B', buffer+4, 9}, - {'C', buffer+13, 5}, - }; - struct lfs_file_config cfg3 = {.attrs=attrs3, .attr_count=3}; - - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg3) => 0; - lfs_file_close(&lfs, &file) => 0; - memcmp(buffer, "aaaa", 4) => 0; - memcmp(buffer+4, "fffffffff", 9) => 0; - memcmp(buffer+13, "ccccc", 5) => 0; - - lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello"); - memcmp(buffer, "hello", strlen("hello")) => 0; - lfs_file_close(&lfs, &file); - lfs_unmount(&lfs) => 0; + for (int isdir = 0; isdir < 1; ++isdir) { + lfs_t lfs; + lfs_format(&lfs, cfg) => 0; + lfs_mount(&lfs, cfg) => 0; + lfs_mkdir(&lfs, "hello") => 0; + if (isdir) { + lfs_mkdir(&lfs, "hello/hello") => 0; + } + lfs_file_t file; + lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; + if (isdir) { + lfs_file_write(&lfs, &file, "hello", strlen("hello")) => LFS_ERR_ISDIR; + } else { + lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); + } + lfs_file_close(&lfs, &file); + lfs_unmount(&lfs) => 0; + + lfs_mount(&lfs, cfg) => 0; + uint8_t buffer[1024]; + memset(buffer, 0, sizeof(buffer)); + struct lfs_attr attrs1[] = { + {'A', buffer, 4}, + {'B', buffer+4, 6}, + {'C', buffer+10, 5}, + }; + struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; + + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + memcpy(buffer, "aaaa", 4); + memcpy(buffer+4, "bbbbbb", 6); + memcpy(buffer+10, "ccccc", 5); + lfs_file_close(&lfs, &file) => 0; + memset(buffer, 0, 15); + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; + memcmp(buffer, "aaaa", 4) => 0; + memcmp(buffer+4, "bbbbbb", 6) => 0; + memcmp(buffer+10, "ccccc", 5) => 0; + + attrs1[1].size = 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; + memset(buffer, 0, 15); + attrs1[1].size = 6; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; + memcmp(buffer, "aaaa", 4) => 0; + memcmp(buffer+4, "\0\0\0\0\0\0", 6) => 0; + memcmp(buffer+10, "ccccc", 5) => 0; + + attrs1[1].size = 6; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + memcpy(buffer+4, "dddddd", 6); + lfs_file_close(&lfs, &file) => 0; + memset(buffer, 0, 15); + attrs1[1].size = 6; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; + memcmp(buffer, "aaaa", 4) => 0; + memcmp(buffer+4, "dddddd", 6) => 0; + memcmp(buffer+10, "ccccc", 5) => 0; + + attrs1[1].size = 3; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + memcpy(buffer+4, "eee", 3); + lfs_file_close(&lfs, &file) => 0; + memset(buffer, 0, 15); + attrs1[1].size = 6; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; + memcmp(buffer, "aaaa", 4) => 0; + memcmp(buffer+4, "eee\0\0\0", 6) => 0; + memcmp(buffer+10, "ccccc", 5) => 0; + + attrs1[0].size = LFS_ATTR_MAX+1; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) + => LFS_ERR_NOSPC; + + struct lfs_attr attrs2[] = { + {'A', buffer, 4}, + {'B', buffer+4, 9}, + {'C', buffer+13, 5}, + }; + struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3}; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDWR, &cfg2) => 0; + memcpy(buffer+4, "fffffffff", 9); + lfs_file_close(&lfs, &file) => 0; + attrs1[0].size = 4; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; + + lfs_unmount(&lfs) => 0; + + lfs_mount(&lfs, cfg) => 0; + memset(buffer, 0, sizeof(buffer)); + struct lfs_attr attrs3[] = { + {'A', buffer, 4}, + {'B', buffer+4, 9}, + {'C', buffer+13, 5}, + }; + struct lfs_file_config cfg3 = {.attrs=attrs3, .attr_count=3}; + + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg3) => 0; + lfs_file_close(&lfs, &file) => 0; + memcmp(buffer, "aaaa", 4) => 0; + memcmp(buffer+4, "fffffffff", 9) => 0; + memcmp(buffer+13, "ccccc", 5) => 0; + + if (!isdir) { + lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello"); + memcmp(buffer, "hello", strlen("hello")) => 0; + lfs_file_close(&lfs, &file); + } + lfs_unmount(&lfs) => 0; + } ''' [cases.test_attrs_deferred_file] code = ''' - lfs_t lfs; - lfs_format(&lfs, cfg) => 0; - lfs_mount(&lfs, cfg) => 0; - lfs_mkdir(&lfs, "hello") => 0; - lfs_file_t file; - lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); - lfs_file_close(&lfs, &file); - lfs_unmount(&lfs) => 0; - - lfs_mount(&lfs, cfg) => 0; - lfs_setattr(&lfs, "hello/hello", 'B', "fffffffff", 9) => 0; - lfs_setattr(&lfs, "hello/hello", 'C', "ccccc", 5) => 0; - - uint8_t buffer[1024]; - memset(buffer, 0, sizeof(buffer)); - struct lfs_attr attrs1[] = { - {'B', "gggg", 4}, - {'C', "", 0}, - {'D', "hhhh", 4}, - }; - struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; - - lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; - - lfs_getattr(&lfs, "hello/hello", 'B', buffer, 9) => 9; - lfs_getattr(&lfs, "hello/hello", 'C', buffer+9, 9) => 5; - lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => LFS_ERR_NOATTR; - memcmp(buffer, "fffffffff", 9) => 0; - memcmp(buffer+9, "ccccc\0\0\0\0", 9) => 0; - memcmp(buffer+18, "\0\0\0\0\0\0\0\0\0", 9) => 0; - - lfs_file_sync(&lfs, &file) => 0; - lfs_getattr(&lfs, "hello/hello", 'B', buffer, 9) => 4; - lfs_getattr(&lfs, "hello/hello", 'C', buffer+9, 9) => 0; - lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => 4; - memcmp(buffer, "gggg\0\0\0\0\0", 9) => 0; - memcmp(buffer+9, "\0\0\0\0\0\0\0\0\0", 9) => 0; - memcmp(buffer+18, "hhhh\0\0\0\0\0", 9) => 0; - - lfs_file_close(&lfs, &file) => 0; - lfs_unmount(&lfs) => 0; + for (int isdir = 0; isdir < 1; ++isdir) { + lfs_t lfs; + lfs_format(&lfs, cfg) => 0; + lfs_mount(&lfs, cfg) => 0; + lfs_mkdir(&lfs, "hello") => 0; + if (isdir) { + lfs_mkdir(&lfs, "hello/hello") => 0; + } + lfs_file_t file; + lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; + if (isdir) { + lfs_file_write(&lfs, &file, "hello", strlen("hello")) => LFS_ERR_ISDIR; + } else { + lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); + } + lfs_file_close(&lfs, &file); + lfs_unmount(&lfs) => 0; + + lfs_mount(&lfs, cfg) => 0; + lfs_setattr(&lfs, "hello/hello", 'B', "fffffffff", 9) => 0; + lfs_setattr(&lfs, "hello/hello", 'C', "ccccc", 5) => 0; + + uint8_t buffer[1024]; + memset(buffer, 0, sizeof(buffer)); + struct lfs_attr attrs1[] = { + {'B', "gggg", 4}, + {'C', "", 0}, + {'D', "hhhh", 4}, + }; + struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; + + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + + lfs_getattr(&lfs, "hello/hello", 'B', buffer, 9) => 9; + lfs_getattr(&lfs, "hello/hello", 'C', buffer+9, 9) => 5; + lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => LFS_ERR_NOATTR; + memcmp(buffer, "fffffffff", 9) => 0; + memcmp(buffer+9, "ccccc\0\0\0\0", 9) => 0; + memcmp(buffer+18, "\0\0\0\0\0\0\0\0\0", 9) => 0; + + lfs_file_sync(&lfs, &file) => 0; + lfs_getattr(&lfs, "hello/hello", 'B', buffer, 9) => 4; + lfs_getattr(&lfs, "hello/hello", 'C', buffer+9, 9) => 0; + lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => 4; + memcmp(buffer, "gggg\0\0\0\0\0", 9) => 0; + memcmp(buffer+9, "\0\0\0\0\0\0\0\0\0", 9) => 0; + memcmp(buffer+18, "hhhh\0\0\0\0\0", 9) => 0; + + lfs_file_close(&lfs, &file) => 0; + lfs_unmount(&lfs) => 0; + } ''' diff --git a/tests/test_dirs.toml b/tests/test_dirs.toml index cb1f2e94..53fdf433 100644 --- a/tests/test_dirs.toml +++ b/tests/test_dirs.toml @@ -749,11 +749,12 @@ code = ''' lfs_dir_open(&lfs, &dir, "tomato") => LFS_ERR_NOENT; lfs_dir_open(&lfs, &dir, "burito") => LFS_ERR_NOTDIR; lfs_file_open(&lfs, &file, "tomato", LFS_O_RDONLY) => LFS_ERR_NOENT; - lfs_file_open(&lfs, &file, "potato", LFS_O_RDONLY) => LFS_ERR_ISDIR; lfs_file_open(&lfs, &file, "tomato", LFS_O_WRONLY) => LFS_ERR_NOENT; - lfs_file_open(&lfs, &file, "potato", LFS_O_WRONLY) => LFS_ERR_ISDIR; + lfs_file_open(&lfs, &file, "potato", - LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR; + LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_write(&lfs, &file, "abc", 3) => LFS_ERR_ISDIR; + lfs_file_close(&lfs, &file) => 0; lfs_file_open(&lfs, &file, "tacoto", LFS_O_WRONLY | LFS_O_CREAT) => 0; lfs_file_close(&lfs, &file) => 0; @@ -763,10 +764,6 @@ code = ''' lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST; lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_EXIST; - lfs_file_open(&lfs, &file, "/", LFS_O_RDONLY) => LFS_ERR_ISDIR; - lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY) => LFS_ERR_ISDIR; - lfs_file_open(&lfs, &file, "/", - LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR; // check that errors did not corrupt directory lfs_dir_open(&lfs, &dir, "/") => 0; diff --git a/tests/test_paths.toml b/tests/test_paths.toml index 97a519ea..accb2204 100644 --- a/tests/test_paths.toml +++ b/tests/test_paths.toml @@ -218,8 +218,8 @@ code = ''' lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST; lfs_file_t file; - lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY | LFS_O_CREAT) - => LFS_ERR_ISDIR; + lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_remove(&lfs, "/") => LFS_ERR_INVAL; lfs_unmount(&lfs) => 0;