119ea8026Sopenharmony_ci[cases.test_move_file]
219ea8026Sopenharmony_cicode = '''
319ea8026Sopenharmony_ci    lfs_t lfs;
419ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
519ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
619ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
719ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
819ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
919ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
1019ea8026Sopenharmony_ci    lfs_file_t file;
1119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
1219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
1319ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
1419ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
1519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
1619ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
1719ea8026Sopenharmony_ci
1819ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
1919ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hello", "c/hello") => 0;
2019ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
2119ea8026Sopenharmony_ci
2219ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
2319ea8026Sopenharmony_ci    lfs_dir_t dir;
2419ea8026Sopenharmony_ci    struct lfs_info info;
2519ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
2619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
2719ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
2819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
2919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
3019ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
3119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
3219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
3319ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
3419ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
3519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
3619ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
3719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
3819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
3919ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
4019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
4119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
4219ea8026Sopenharmony_ci    assert(strcmp(info.name, "hello") == 0);
4319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
4419ea8026Sopenharmony_ci    assert(info.size == 5+8+6);
4519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
4619ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
4719ea8026Sopenharmony_ci
4819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
4919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
5019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
5119ea8026Sopenharmony_ci    uint8_t buffer[1024];
5219ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 5) => 5;
5319ea8026Sopenharmony_ci    memcmp(buffer, "hola\n", 5) => 0;
5419ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 8) => 8;
5519ea8026Sopenharmony_ci    memcmp(buffer, "bonjour\n", 8) => 0;
5619ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 6) => 6;
5719ea8026Sopenharmony_ci    memcmp(buffer, "ohayo\n", 6) => 0;
5819ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
5919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
6019ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
6119ea8026Sopenharmony_ci'''
6219ea8026Sopenharmony_ci
6319ea8026Sopenharmony_ci[cases.test_move_nop] # yes this is legal
6419ea8026Sopenharmony_cicode = '''
6519ea8026Sopenharmony_ci    lfs_t lfs;
6619ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
6719ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
6819ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "hi") => 0;
6919ea8026Sopenharmony_ci    lfs_rename(&lfs, "hi", "hi") => 0;
7019ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "hi/hi") => 0;
7119ea8026Sopenharmony_ci    lfs_rename(&lfs, "hi/hi", "hi/hi") => 0;
7219ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "hi/hi/hi") => 0;
7319ea8026Sopenharmony_ci    lfs_rename(&lfs, "hi/hi/hi", "hi/hi/hi") => 0;
7419ea8026Sopenharmony_ci    struct lfs_info info;
7519ea8026Sopenharmony_ci    lfs_stat(&lfs, "hi/hi/hi", &info) => 0;
7619ea8026Sopenharmony_ci    assert(strcmp(info.name, "hi") == 0);
7719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
7819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
7919ea8026Sopenharmony_ci'''
8019ea8026Sopenharmony_ci
8119ea8026Sopenharmony_ci[cases.test_move_file_corrupt_source]
8219ea8026Sopenharmony_ciin = "lfs.c"
8319ea8026Sopenharmony_cicode = '''
8419ea8026Sopenharmony_ci    lfs_t lfs;
8519ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
8619ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
8719ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
8819ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
8919ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
9019ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
9119ea8026Sopenharmony_ci    lfs_file_t file;
9219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
9319ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
9419ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
9519ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
9619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
9719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
9819ea8026Sopenharmony_ci
9919ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
10019ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hello", "c/hello") => 0;
10119ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
10219ea8026Sopenharmony_ci
10319ea8026Sopenharmony_ci    // corrupt the source
10419ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
10519ea8026Sopenharmony_ci    lfs_dir_t dir;
10619ea8026Sopenharmony_ci    struct lfs_info info;
10719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
10819ea8026Sopenharmony_ci    lfs_block_t block = dir.m.pair[0];
10919ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
11019ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
11119ea8026Sopenharmony_ci    uint8_t buffer[BLOCK_SIZE];
11219ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
11319ea8026Sopenharmony_ci    int off = BLOCK_SIZE-1;
11419ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
11519ea8026Sopenharmony_ci        off -= 1;
11619ea8026Sopenharmony_ci    }
11719ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
11819ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
11919ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
12019ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
12119ea8026Sopenharmony_ci
12219ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
12319ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
12419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
12519ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
12619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
12719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
12819ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
12919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
13019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
13119ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
13219ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
13319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
13419ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
13519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
13619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
13719ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
13819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
13919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
14019ea8026Sopenharmony_ci    assert(strcmp(info.name, "hello") == 0);
14119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
14219ea8026Sopenharmony_ci    assert(info.size == 5+8+6);
14319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
14419ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
14519ea8026Sopenharmony_ci
14619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
14719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
14819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
14919ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 5) => 5;
15019ea8026Sopenharmony_ci    memcmp(buffer, "hola\n", 5) => 0;
15119ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 8) => 8;
15219ea8026Sopenharmony_ci    memcmp(buffer, "bonjour\n", 8) => 0;
15319ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 6) => 6;
15419ea8026Sopenharmony_ci    memcmp(buffer, "ohayo\n", 6) => 0;
15519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
15619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
15719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
15819ea8026Sopenharmony_ci'''
15919ea8026Sopenharmony_ci
16019ea8026Sopenharmony_ci# move file corrupt source and dest
16119ea8026Sopenharmony_ci[cases.test_move_file_corrupt_source_dest]
16219ea8026Sopenharmony_ciin = "lfs.c"
16319ea8026Sopenharmony_ciif = 'PROG_SIZE <= 0x3fe' # only works with one crc per commit
16419ea8026Sopenharmony_cicode = '''
16519ea8026Sopenharmony_ci    lfs_t lfs;
16619ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
16719ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
16819ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
16919ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
17019ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
17119ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
17219ea8026Sopenharmony_ci    lfs_file_t file;
17319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
17419ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
17519ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
17619ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
17719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
17819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
17919ea8026Sopenharmony_ci
18019ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
18119ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hello", "c/hello") => 0;
18219ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
18319ea8026Sopenharmony_ci
18419ea8026Sopenharmony_ci    // corrupt the source
18519ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
18619ea8026Sopenharmony_ci    lfs_dir_t dir;
18719ea8026Sopenharmony_ci    struct lfs_info info;
18819ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
18919ea8026Sopenharmony_ci    lfs_block_t block = dir.m.pair[0];
19019ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
19119ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
19219ea8026Sopenharmony_ci    uint8_t buffer[BLOCK_SIZE];
19319ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
19419ea8026Sopenharmony_ci    int off = BLOCK_SIZE-1;
19519ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
19619ea8026Sopenharmony_ci        off -= 1;
19719ea8026Sopenharmony_ci    }
19819ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
19919ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
20019ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
20119ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
20219ea8026Sopenharmony_ci
20319ea8026Sopenharmony_ci    // corrupt the destination
20419ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
20519ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
20619ea8026Sopenharmony_ci    block = dir.m.pair[0];
20719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
20819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
20919ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
21019ea8026Sopenharmony_ci    off = BLOCK_SIZE-1;
21119ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
21219ea8026Sopenharmony_ci        off -= 1;
21319ea8026Sopenharmony_ci    }
21419ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
21519ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
21619ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
21719ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
21819ea8026Sopenharmony_ci
21919ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
22019ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
22119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
22219ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
22319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
22419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
22519ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
22619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
22719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
22819ea8026Sopenharmony_ci    assert(strcmp(info.name, "hello") == 0);
22919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
23019ea8026Sopenharmony_ci    assert(info.size == 5+8+6);
23119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
23219ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
23319ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
23419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
23519ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
23619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
23719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
23819ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
23919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
24019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
24119ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
24219ea8026Sopenharmony_ci
24319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => 0;
24419ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 5) => 5;
24519ea8026Sopenharmony_ci    memcmp(buffer, "hola\n", 5) => 0;
24619ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 8) => 8;
24719ea8026Sopenharmony_ci    memcmp(buffer, "bonjour\n", 8) => 0;
24819ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 6) => 6;
24919ea8026Sopenharmony_ci    memcmp(buffer, "ohayo\n", 6) => 0;
25019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
25119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
25219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
25319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
25419ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
25519ea8026Sopenharmony_ci'''
25619ea8026Sopenharmony_ci
25719ea8026Sopenharmony_ci[cases.test_move_file_after_corrupt]
25819ea8026Sopenharmony_ciin = "lfs.c"
25919ea8026Sopenharmony_ciif = 'PROG_SIZE <= 0x3fe' # only works with one crc per commit
26019ea8026Sopenharmony_cicode = '''
26119ea8026Sopenharmony_ci    lfs_t lfs;
26219ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
26319ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
26419ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
26519ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
26619ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
26719ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
26819ea8026Sopenharmony_ci    lfs_file_t file;
26919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
27019ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
27119ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
27219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
27319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
27419ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
27519ea8026Sopenharmony_ci
27619ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
27719ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hello", "c/hello") => 0;
27819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
27919ea8026Sopenharmony_ci
28019ea8026Sopenharmony_ci    // corrupt the source
28119ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
28219ea8026Sopenharmony_ci    lfs_dir_t dir;
28319ea8026Sopenharmony_ci    struct lfs_info info;
28419ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
28519ea8026Sopenharmony_ci    lfs_block_t block = dir.m.pair[0];
28619ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
28719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
28819ea8026Sopenharmony_ci    uint8_t buffer[BLOCK_SIZE];
28919ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
29019ea8026Sopenharmony_ci    int off = BLOCK_SIZE-1;
29119ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
29219ea8026Sopenharmony_ci        off -= 1;
29319ea8026Sopenharmony_ci    }
29419ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
29519ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
29619ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
29719ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
29819ea8026Sopenharmony_ci
29919ea8026Sopenharmony_ci    // corrupt the destination
30019ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
30119ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
30219ea8026Sopenharmony_ci    block = dir.m.pair[0];
30319ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
30419ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
30519ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
30619ea8026Sopenharmony_ci    off = BLOCK_SIZE-1;
30719ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
30819ea8026Sopenharmony_ci        off -= 1;
30919ea8026Sopenharmony_ci    }
31019ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
31119ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
31219ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
31319ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
31419ea8026Sopenharmony_ci
31519ea8026Sopenharmony_ci    // continue move
31619ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
31719ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hello", "c/hello") => 0;
31819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
31919ea8026Sopenharmony_ci
32019ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
32119ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
32219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
32319ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
32419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
32519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
32619ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
32719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
32819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
32919ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
33019ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
33119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
33219ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
33319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
33419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
33519ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
33619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
33719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
33819ea8026Sopenharmony_ci    assert(strcmp(info.name, "hello") == 0);
33919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
34019ea8026Sopenharmony_ci    assert(info.size == 5+8+6);
34119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
34219ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
34319ea8026Sopenharmony_ci
34419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
34519ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
34619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
34719ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 5) => 5;
34819ea8026Sopenharmony_ci    memcmp(buffer, "hola\n", 5) => 0;
34919ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 8) => 8;
35019ea8026Sopenharmony_ci    memcmp(buffer, "bonjour\n", 8) => 0;
35119ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 6) => 6;
35219ea8026Sopenharmony_ci    memcmp(buffer, "ohayo\n", 6) => 0;
35319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
35419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
35519ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
35619ea8026Sopenharmony_ci'''
35719ea8026Sopenharmony_ci
35819ea8026Sopenharmony_ci[cases.test_move_reentrant_file]
35919ea8026Sopenharmony_cireentrant = true
36019ea8026Sopenharmony_cicode = '''
36119ea8026Sopenharmony_ci    lfs_t lfs;
36219ea8026Sopenharmony_ci    int err = lfs_mount(&lfs, cfg);
36319ea8026Sopenharmony_ci    if (err) {
36419ea8026Sopenharmony_ci        lfs_format(&lfs, cfg) => 0;
36519ea8026Sopenharmony_ci        lfs_mount(&lfs, cfg) => 0;
36619ea8026Sopenharmony_ci    }
36719ea8026Sopenharmony_ci    err = lfs_mkdir(&lfs, "a");
36819ea8026Sopenharmony_ci    assert(!err || err == LFS_ERR_EXIST);
36919ea8026Sopenharmony_ci    err = lfs_mkdir(&lfs, "b");
37019ea8026Sopenharmony_ci    assert(!err || err == LFS_ERR_EXIST);
37119ea8026Sopenharmony_ci    err = lfs_mkdir(&lfs, "c");
37219ea8026Sopenharmony_ci    assert(!err || err == LFS_ERR_EXIST);
37319ea8026Sopenharmony_ci    err = lfs_mkdir(&lfs, "d");
37419ea8026Sopenharmony_ci    assert(!err || err == LFS_ERR_EXIST);
37519ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
37619ea8026Sopenharmony_ci
37719ea8026Sopenharmony_ci    while (true) {
37819ea8026Sopenharmony_ci        lfs_mount(&lfs, cfg) => 0;
37919ea8026Sopenharmony_ci        // there should never exist _2_ hello files
38019ea8026Sopenharmony_ci        int count = 0;
38119ea8026Sopenharmony_ci        struct lfs_info info;
38219ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "a/hello", &info) == 0) {
38319ea8026Sopenharmony_ci            assert(strcmp(info.name, "hello") == 0);
38419ea8026Sopenharmony_ci            assert(info.type == LFS_TYPE_REG);
38519ea8026Sopenharmony_ci            assert(info.size == 5+8+6 || info.size == 0);
38619ea8026Sopenharmony_ci            count += 1;
38719ea8026Sopenharmony_ci        }
38819ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "b/hello", &info) == 0) {
38919ea8026Sopenharmony_ci            assert(strcmp(info.name, "hello") == 0);
39019ea8026Sopenharmony_ci            assert(info.type == LFS_TYPE_REG);
39119ea8026Sopenharmony_ci            assert(info.size == 5+8+6);
39219ea8026Sopenharmony_ci            count += 1;
39319ea8026Sopenharmony_ci        }
39419ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "c/hello", &info) == 0) {
39519ea8026Sopenharmony_ci            assert(strcmp(info.name, "hello") == 0);
39619ea8026Sopenharmony_ci            assert(info.type == LFS_TYPE_REG);
39719ea8026Sopenharmony_ci            assert(info.size == 5+8+6);
39819ea8026Sopenharmony_ci            count += 1;
39919ea8026Sopenharmony_ci        }
40019ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "d/hello", &info) == 0) {
40119ea8026Sopenharmony_ci            assert(strcmp(info.name, "hello") == 0);
40219ea8026Sopenharmony_ci            assert(info.type == LFS_TYPE_REG);
40319ea8026Sopenharmony_ci            assert(info.size == 5+8+6);
40419ea8026Sopenharmony_ci            count += 1;
40519ea8026Sopenharmony_ci        }
40619ea8026Sopenharmony_ci        assert(count <= 1);
40719ea8026Sopenharmony_ci        lfs_unmount(&lfs) => 0;
40819ea8026Sopenharmony_ci
40919ea8026Sopenharmony_ci        lfs_mount(&lfs, cfg) => 0;
41019ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "a/hello", &info) == 0 && info.size > 0) {
41119ea8026Sopenharmony_ci            lfs_rename(&lfs, "a/hello", "b/hello") => 0;
41219ea8026Sopenharmony_ci        } else if (lfs_stat(&lfs, "b/hello", &info) == 0) {
41319ea8026Sopenharmony_ci            lfs_rename(&lfs, "b/hello", "c/hello") => 0;
41419ea8026Sopenharmony_ci        } else if (lfs_stat(&lfs, "c/hello", &info) == 0) {
41519ea8026Sopenharmony_ci            lfs_rename(&lfs, "c/hello", "d/hello") => 0;
41619ea8026Sopenharmony_ci        } else if (lfs_stat(&lfs, "d/hello", &info) == 0) {
41719ea8026Sopenharmony_ci            // success
41819ea8026Sopenharmony_ci            lfs_unmount(&lfs) => 0;
41919ea8026Sopenharmony_ci            break;
42019ea8026Sopenharmony_ci        } else {
42119ea8026Sopenharmony_ci            // create file
42219ea8026Sopenharmony_ci            lfs_file_t file;
42319ea8026Sopenharmony_ci            lfs_file_open(&lfs, &file, "a/hello",
42419ea8026Sopenharmony_ci                    LFS_O_WRONLY | LFS_O_CREAT) => 0;
42519ea8026Sopenharmony_ci            lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
42619ea8026Sopenharmony_ci            lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
42719ea8026Sopenharmony_ci            lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
42819ea8026Sopenharmony_ci            lfs_file_close(&lfs, &file) => 0;
42919ea8026Sopenharmony_ci        }
43019ea8026Sopenharmony_ci        lfs_unmount(&lfs) => 0;
43119ea8026Sopenharmony_ci    }
43219ea8026Sopenharmony_ci
43319ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
43419ea8026Sopenharmony_ci    lfs_dir_t dir;
43519ea8026Sopenharmony_ci    struct lfs_info info;
43619ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
43719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
43819ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
43919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
44019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
44119ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
44219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
44319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
44419ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
44519ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "d") => 0;
44619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
44719ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
44819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
44919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
45019ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
45119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
45219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
45319ea8026Sopenharmony_ci    assert(strcmp(info.name, "hello") == 0);
45419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
45519ea8026Sopenharmony_ci    assert(info.size == 5+8+6);
45619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
45719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
45819ea8026Sopenharmony_ci
45919ea8026Sopenharmony_ci    lfs_file_t file;
46019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
46119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
46219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
46319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
46419ea8026Sopenharmony_ci    uint8_t buffer[1024];
46519ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 5) => 5;
46619ea8026Sopenharmony_ci    memcmp(buffer, "hola\n", 5) => 0;
46719ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 8) => 8;
46819ea8026Sopenharmony_ci    memcmp(buffer, "bonjour\n", 8) => 0;
46919ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 6) => 6;
47019ea8026Sopenharmony_ci    memcmp(buffer, "ohayo\n", 6) => 0;
47119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
47219ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
47319ea8026Sopenharmony_ci'''
47419ea8026Sopenharmony_ci
47519ea8026Sopenharmony_ci[cases.test_move_dir]
47619ea8026Sopenharmony_cicode = '''
47719ea8026Sopenharmony_ci    lfs_t lfs;
47819ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
47919ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
48019ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
48119ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
48219ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
48319ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
48419ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi") => 0;
48519ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/hola") => 0;
48619ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
48719ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
48819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
48919ea8026Sopenharmony_ci
49019ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
49119ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hi", "c/hi") => 0;
49219ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
49319ea8026Sopenharmony_ci
49419ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
49519ea8026Sopenharmony_ci    lfs_dir_t dir;
49619ea8026Sopenharmony_ci    struct lfs_info info;
49719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
49819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
49919ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
50019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
50119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
50219ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
50319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
50419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
50519ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
50619ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
50719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
50819ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
50919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
51019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
51119ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
51219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
51319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
51419ea8026Sopenharmony_ci    assert(strcmp(info.name, "hi") == 0);
51519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
51619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
51719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
51819ea8026Sopenharmony_ci
51919ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
52019ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
52119ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c/hi") => 0;
52219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
52319ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
52419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
52519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
52619ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
52719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
52819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
52919ea8026Sopenharmony_ci    assert(strcmp(info.name, "bonjour") == 0);
53019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
53119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
53219ea8026Sopenharmony_ci    assert(strcmp(info.name, "hola") == 0);
53319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
53419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
53519ea8026Sopenharmony_ci    assert(strcmp(info.name, "ohayo") == 0);
53619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
53719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
53819ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
53919ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
54019ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
54119ea8026Sopenharmony_ci'''
54219ea8026Sopenharmony_ci
54319ea8026Sopenharmony_ci[cases.test_move_dir_corrupt_source]
54419ea8026Sopenharmony_ciin = "lfs.c"
54519ea8026Sopenharmony_cicode = '''
54619ea8026Sopenharmony_ci    lfs_t lfs;
54719ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
54819ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
54919ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
55019ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
55119ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
55219ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
55319ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi") => 0;
55419ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/hola") => 0;
55519ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
55619ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
55719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
55819ea8026Sopenharmony_ci
55919ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
56019ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hi", "c/hi") => 0;
56119ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
56219ea8026Sopenharmony_ci
56319ea8026Sopenharmony_ci    // corrupt the source
56419ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
56519ea8026Sopenharmony_ci    lfs_dir_t dir;
56619ea8026Sopenharmony_ci    struct lfs_info info;
56719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
56819ea8026Sopenharmony_ci    lfs_block_t block = dir.m.pair[0];
56919ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
57019ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
57119ea8026Sopenharmony_ci    uint8_t buffer[BLOCK_SIZE];
57219ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
57319ea8026Sopenharmony_ci    int off = BLOCK_SIZE-1;
57419ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
57519ea8026Sopenharmony_ci        off -= 1;
57619ea8026Sopenharmony_ci    }
57719ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
57819ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
57919ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
58019ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
58119ea8026Sopenharmony_ci
58219ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
58319ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
58419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
58519ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
58619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
58719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
58819ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
58919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
59019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
59119ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
59219ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
59319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
59419ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
59519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
59619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
59719ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
59819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
59919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
60019ea8026Sopenharmony_ci    assert(strcmp(info.name, "hi") == 0);
60119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
60219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
60319ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
60419ea8026Sopenharmony_ci
60519ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
60619ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
60719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c/hi") => 0;
60819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
60919ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
61019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
61119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
61219ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
61319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
61419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
61519ea8026Sopenharmony_ci    assert(strcmp(info.name, "bonjour") == 0);
61619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
61719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
61819ea8026Sopenharmony_ci    assert(strcmp(info.name, "hola") == 0);
61919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
62019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
62119ea8026Sopenharmony_ci    assert(strcmp(info.name, "ohayo") == 0);
62219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
62319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
62419ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
62519ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
62619ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
62719ea8026Sopenharmony_ci'''
62819ea8026Sopenharmony_ci
62919ea8026Sopenharmony_ci[cases.test_move_dir_corrupt_source_dest]
63019ea8026Sopenharmony_ciin = "lfs.c"
63119ea8026Sopenharmony_ciif = 'PROG_SIZE <= 0x3fe' # only works with one crc per commit
63219ea8026Sopenharmony_cicode = '''
63319ea8026Sopenharmony_ci    lfs_t lfs;
63419ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
63519ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
63619ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
63719ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
63819ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
63919ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
64019ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi") => 0;
64119ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/hola") => 0;
64219ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
64319ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
64419ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
64519ea8026Sopenharmony_ci
64619ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
64719ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hi", "c/hi") => 0;
64819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
64919ea8026Sopenharmony_ci
65019ea8026Sopenharmony_ci    // corrupt the source
65119ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
65219ea8026Sopenharmony_ci    lfs_dir_t dir;
65319ea8026Sopenharmony_ci    struct lfs_info info;
65419ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
65519ea8026Sopenharmony_ci    lfs_block_t block = dir.m.pair[0];
65619ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
65719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
65819ea8026Sopenharmony_ci    uint8_t buffer[BLOCK_SIZE];
65919ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
66019ea8026Sopenharmony_ci    int off = BLOCK_SIZE-1;
66119ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
66219ea8026Sopenharmony_ci        off -= 1;
66319ea8026Sopenharmony_ci    }
66419ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
66519ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
66619ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
66719ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
66819ea8026Sopenharmony_ci
66919ea8026Sopenharmony_ci    // corrupt the destination
67019ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
67119ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
67219ea8026Sopenharmony_ci    block = dir.m.pair[0];
67319ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
67419ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
67519ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
67619ea8026Sopenharmony_ci    off = BLOCK_SIZE-1;
67719ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
67819ea8026Sopenharmony_ci        off -= 1;
67919ea8026Sopenharmony_ci    }
68019ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
68119ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
68219ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
68319ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
68419ea8026Sopenharmony_ci
68519ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
68619ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
68719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
68819ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
68919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
69019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
69119ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
69219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
69319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
69419ea8026Sopenharmony_ci    assert(strcmp(info.name, "hi") == 0);
69519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
69619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
69719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
69819ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
69919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
70019ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
70119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
70219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
70319ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
70419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
70519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
70619ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
70719ea8026Sopenharmony_ci
70819ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a/hi") => 0;
70919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
71019ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
71119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
71219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
71319ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
71419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
71519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
71619ea8026Sopenharmony_ci    assert(strcmp(info.name, "bonjour") == 0);
71719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
71819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
71919ea8026Sopenharmony_ci    assert(strcmp(info.name, "hola") == 0);
72019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
72119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
72219ea8026Sopenharmony_ci    assert(strcmp(info.name, "ohayo") == 0);
72319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
72419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
72519ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
72619ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
72719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT;
72819ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
72919ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
73019ea8026Sopenharmony_ci'''
73119ea8026Sopenharmony_ci
73219ea8026Sopenharmony_ci[cases.test_move_dir_after_corrupt]
73319ea8026Sopenharmony_ciin = "lfs.c"
73419ea8026Sopenharmony_ciif = 'PROG_SIZE <= 0x3fe' # only works with one crc per commit
73519ea8026Sopenharmony_cicode = '''
73619ea8026Sopenharmony_ci    lfs_t lfs;
73719ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
73819ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
73919ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
74019ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
74119ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
74219ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
74319ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi") => 0;
74419ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/hola") => 0;
74519ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
74619ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
74719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
74819ea8026Sopenharmony_ci
74919ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
75019ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hi", "c/hi") => 0;
75119ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
75219ea8026Sopenharmony_ci
75319ea8026Sopenharmony_ci    // corrupt the source
75419ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
75519ea8026Sopenharmony_ci    lfs_dir_t dir;
75619ea8026Sopenharmony_ci    struct lfs_info info;
75719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
75819ea8026Sopenharmony_ci    lfs_block_t block = dir.m.pair[0];
75919ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
76019ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
76119ea8026Sopenharmony_ci    uint8_t buffer[BLOCK_SIZE];
76219ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
76319ea8026Sopenharmony_ci    int off = BLOCK_SIZE-1;
76419ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
76519ea8026Sopenharmony_ci        off -= 1;
76619ea8026Sopenharmony_ci    }
76719ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
76819ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
76919ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
77019ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
77119ea8026Sopenharmony_ci
77219ea8026Sopenharmony_ci    // corrupt the destination
77319ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
77419ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
77519ea8026Sopenharmony_ci    block = dir.m.pair[0];
77619ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
77719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
77819ea8026Sopenharmony_ci    cfg->read(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
77919ea8026Sopenharmony_ci    off = BLOCK_SIZE-1;
78019ea8026Sopenharmony_ci    while (off >= 0 && buffer[off] == ERASE_VALUE) {
78119ea8026Sopenharmony_ci        off -= 1;
78219ea8026Sopenharmony_ci    }
78319ea8026Sopenharmony_ci    memset(&buffer[off-3], BLOCK_SIZE, 3);
78419ea8026Sopenharmony_ci    cfg->erase(cfg, block) => 0;
78519ea8026Sopenharmony_ci    cfg->prog(cfg, block, 0, buffer, BLOCK_SIZE) => 0;
78619ea8026Sopenharmony_ci    cfg->sync(cfg) => 0;
78719ea8026Sopenharmony_ci
78819ea8026Sopenharmony_ci    // continue move
78919ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
79019ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hi", "c/hi") => 0;
79119ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
79219ea8026Sopenharmony_ci
79319ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
79419ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
79519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
79619ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
79719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
79819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
79919ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
80019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
80119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
80219ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
80319ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c") => 0;
80419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
80519ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
80619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
80719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
80819ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
80919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
81019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
81119ea8026Sopenharmony_ci    assert(strcmp(info.name, "hi") == 0);
81219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
81319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
81419ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
81519ea8026Sopenharmony_ci
81619ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
81719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
81819ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c/hi") => 0;
81919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
82019ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
82119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
82219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
82319ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
82419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
82519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
82619ea8026Sopenharmony_ci    assert(strcmp(info.name, "bonjour") == 0);
82719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
82819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
82919ea8026Sopenharmony_ci    assert(strcmp(info.name, "hola") == 0);
83019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
83119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
83219ea8026Sopenharmony_ci    assert(strcmp(info.name, "ohayo") == 0);
83319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
83419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
83519ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
83619ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
83719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
83819ea8026Sopenharmony_ci'''
83919ea8026Sopenharmony_ci
84019ea8026Sopenharmony_ci[cases.test_reentrant_dir]
84119ea8026Sopenharmony_cireentrant = true
84219ea8026Sopenharmony_cicode = '''
84319ea8026Sopenharmony_ci    lfs_t lfs;
84419ea8026Sopenharmony_ci    int err = lfs_mount(&lfs, cfg);
84519ea8026Sopenharmony_ci    if (err) {
84619ea8026Sopenharmony_ci        lfs_format(&lfs, cfg) => 0;
84719ea8026Sopenharmony_ci        lfs_mount(&lfs, cfg) => 0;
84819ea8026Sopenharmony_ci    }
84919ea8026Sopenharmony_ci    err = lfs_mkdir(&lfs, "a");
85019ea8026Sopenharmony_ci    assert(!err || err == LFS_ERR_EXIST);
85119ea8026Sopenharmony_ci    err = lfs_mkdir(&lfs, "b");
85219ea8026Sopenharmony_ci    assert(!err || err == LFS_ERR_EXIST);
85319ea8026Sopenharmony_ci    err = lfs_mkdir(&lfs, "c");
85419ea8026Sopenharmony_ci    assert(!err || err == LFS_ERR_EXIST);
85519ea8026Sopenharmony_ci    err = lfs_mkdir(&lfs, "d");
85619ea8026Sopenharmony_ci    assert(!err || err == LFS_ERR_EXIST);
85719ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
85819ea8026Sopenharmony_ci
85919ea8026Sopenharmony_ci    while (true) {
86019ea8026Sopenharmony_ci        lfs_mount(&lfs, cfg) => 0;
86119ea8026Sopenharmony_ci        // there should never exist _2_ hi directories
86219ea8026Sopenharmony_ci        int count = 0;
86319ea8026Sopenharmony_ci        struct lfs_info info;
86419ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "a/hi", &info) == 0) {
86519ea8026Sopenharmony_ci            assert(strcmp(info.name, "hi") == 0);
86619ea8026Sopenharmony_ci            assert(info.type == LFS_TYPE_DIR);
86719ea8026Sopenharmony_ci            count += 1;
86819ea8026Sopenharmony_ci        }
86919ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "b/hi", &info) == 0) {
87019ea8026Sopenharmony_ci            assert(strcmp(info.name, "hi") == 0);
87119ea8026Sopenharmony_ci            assert(info.type == LFS_TYPE_DIR);
87219ea8026Sopenharmony_ci            count += 1;
87319ea8026Sopenharmony_ci        }
87419ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "c/hi", &info) == 0) {
87519ea8026Sopenharmony_ci            assert(strcmp(info.name, "hi") == 0);
87619ea8026Sopenharmony_ci            assert(info.type == LFS_TYPE_DIR);
87719ea8026Sopenharmony_ci            count += 1;
87819ea8026Sopenharmony_ci        }
87919ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "d/hi", &info) == 0) {
88019ea8026Sopenharmony_ci            assert(strcmp(info.name, "hi") == 0);
88119ea8026Sopenharmony_ci            assert(info.type == LFS_TYPE_DIR);
88219ea8026Sopenharmony_ci            count += 1;
88319ea8026Sopenharmony_ci        }
88419ea8026Sopenharmony_ci        assert(count <= 1);
88519ea8026Sopenharmony_ci        lfs_unmount(&lfs) => 0;
88619ea8026Sopenharmony_ci
88719ea8026Sopenharmony_ci        lfs_mount(&lfs, cfg) => 0;
88819ea8026Sopenharmony_ci        if (lfs_stat(&lfs, "a/hi", &info) == 0) {
88919ea8026Sopenharmony_ci            lfs_rename(&lfs, "a/hi", "b/hi") => 0;
89019ea8026Sopenharmony_ci        } else if (lfs_stat(&lfs, "b/hi", &info) == 0) {
89119ea8026Sopenharmony_ci            lfs_rename(&lfs, "b/hi", "c/hi") => 0;
89219ea8026Sopenharmony_ci        } else if (lfs_stat(&lfs, "c/hi", &info) == 0) {
89319ea8026Sopenharmony_ci            lfs_rename(&lfs, "c/hi", "d/hi") => 0;
89419ea8026Sopenharmony_ci        } else if (lfs_stat(&lfs, "d/hi", &info) == 0) {
89519ea8026Sopenharmony_ci            lfs_unmount(&lfs) => 0;
89619ea8026Sopenharmony_ci            break; // success
89719ea8026Sopenharmony_ci        } else {
89819ea8026Sopenharmony_ci            // create dir and rename for atomicity
89919ea8026Sopenharmony_ci            err = lfs_mkdir(&lfs, "temp");
90019ea8026Sopenharmony_ci            assert(!err || err == LFS_ERR_EXIST);
90119ea8026Sopenharmony_ci            err = lfs_mkdir(&lfs, "temp/hola");
90219ea8026Sopenharmony_ci            assert(!err || err == LFS_ERR_EXIST);
90319ea8026Sopenharmony_ci            err = lfs_mkdir(&lfs, "temp/bonjour");
90419ea8026Sopenharmony_ci            assert(!err || err == LFS_ERR_EXIST);
90519ea8026Sopenharmony_ci            err = lfs_mkdir(&lfs, "temp/ohayo");
90619ea8026Sopenharmony_ci            assert(!err || err == LFS_ERR_EXIST);
90719ea8026Sopenharmony_ci            lfs_rename(&lfs, "temp", "a/hi") => 0;
90819ea8026Sopenharmony_ci        }
90919ea8026Sopenharmony_ci        lfs_unmount(&lfs) => 0;
91019ea8026Sopenharmony_ci    }
91119ea8026Sopenharmony_ci
91219ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
91319ea8026Sopenharmony_ci    lfs_dir_t dir;
91419ea8026Sopenharmony_ci    struct lfs_info info;
91519ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a") => 0;
91619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
91719ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
91819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
91919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
92019ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
92119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
92219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
92319ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
92419ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "d") => 0;
92519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
92619ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
92719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
92819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
92919ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
93019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
93119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
93219ea8026Sopenharmony_ci    assert(strcmp(info.name, "hi") == 0);
93319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
93419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
93519ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
93619ea8026Sopenharmony_ci
93719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
93819ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
93919ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT;
94019ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "d/hi") => 0;
94119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
94219ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
94319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
94419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
94519ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
94619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
94719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
94819ea8026Sopenharmony_ci    assert(strcmp(info.name, "bonjour") == 0);
94919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
95019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
95119ea8026Sopenharmony_ci    assert(strcmp(info.name, "hola") == 0);
95219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
95319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
95419ea8026Sopenharmony_ci    assert(strcmp(info.name, "ohayo") == 0);
95519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
95619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
95719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
95819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
95919ea8026Sopenharmony_ci'''
96019ea8026Sopenharmony_ci
96119ea8026Sopenharmony_ci[cases.test_move_state_stealing]
96219ea8026Sopenharmony_cicode = '''
96319ea8026Sopenharmony_ci    lfs_t lfs;
96419ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
96519ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
96619ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "a") => 0;
96719ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "b") => 0;
96819ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "c") => 0;
96919ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "d") => 0;
97019ea8026Sopenharmony_ci    lfs_file_t file;
97119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
97219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
97319ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
97419ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
97519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
97619ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
97719ea8026Sopenharmony_ci
97819ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
97919ea8026Sopenharmony_ci    lfs_rename(&lfs, "a/hello", "b/hello") => 0;
98019ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
98119ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
98219ea8026Sopenharmony_ci    lfs_rename(&lfs, "b/hello", "c/hello") => 0;
98319ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
98419ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
98519ea8026Sopenharmony_ci    lfs_rename(&lfs, "c/hello", "d/hello") => 0;
98619ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
98719ea8026Sopenharmony_ci
98819ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
98919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
99019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
99119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
99219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
99319ea8026Sopenharmony_ci    uint8_t buffer[1024];
99419ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 5) => 5;
99519ea8026Sopenharmony_ci    memcmp(buffer, "hola\n", 5) => 0;
99619ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 8) => 8;
99719ea8026Sopenharmony_ci    memcmp(buffer, "bonjour\n", 8) => 0;
99819ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 6) => 6;
99919ea8026Sopenharmony_ci    memcmp(buffer, "ohayo\n", 6) => 0;
100019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
100119ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
100219ea8026Sopenharmony_ci
100319ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
100419ea8026Sopenharmony_ci    lfs_remove(&lfs, "b") => 0;
100519ea8026Sopenharmony_ci    lfs_remove(&lfs, "c") => 0;
100619ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
100719ea8026Sopenharmony_ci
100819ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
100919ea8026Sopenharmony_ci    struct lfs_info info;
101019ea8026Sopenharmony_ci    lfs_stat(&lfs, "a", &info) => 0;
101119ea8026Sopenharmony_ci    lfs_stat(&lfs, "b", &info) => LFS_ERR_NOENT;
101219ea8026Sopenharmony_ci    lfs_stat(&lfs, "c", &info) => LFS_ERR_NOENT;
101319ea8026Sopenharmony_ci    lfs_stat(&lfs, "d", &info) => 0;
101419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
101519ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
101619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
101719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
101819ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 5) => 5;
101919ea8026Sopenharmony_ci    memcmp(buffer, "hola\n", 5) => 0;
102019ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 8) => 8;
102119ea8026Sopenharmony_ci    memcmp(buffer, "bonjour\n", 8) => 0;
102219ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 6) => 6;
102319ea8026Sopenharmony_ci    memcmp(buffer, "ohayo\n", 6) => 0;
102419ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
102519ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
102619ea8026Sopenharmony_ci'''
102719ea8026Sopenharmony_ci
102819ea8026Sopenharmony_ci# Other specific corner cases
102919ea8026Sopenharmony_ci
103019ea8026Sopenharmony_ci# create + delete in same commit with neighbors
103119ea8026Sopenharmony_ci[cases.test_move_create_delete_same]
103219ea8026Sopenharmony_cicode = '''
103319ea8026Sopenharmony_ci    lfs_t lfs;
103419ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
103519ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
103619ea8026Sopenharmony_ci
103719ea8026Sopenharmony_ci    // littlefs keeps files sorted, so we know the order these will be in
103819ea8026Sopenharmony_ci    lfs_file_t file;
103919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/1.move_me",
104019ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
104119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
104219ea8026Sopenharmony_ci
104319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/0.before",
104419ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
104519ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.1", 7) => 7;
104619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
104719ea8026Sopenharmony_ci
104819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/2.in_between",
104919ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
105019ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.2", 7) => 7;
105119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
105219ea8026Sopenharmony_ci
105319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/4.after",
105419ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
105519ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.3", 7) => 7;
105619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
105719ea8026Sopenharmony_ci
105819ea8026Sopenharmony_ci    lfs_file_t files[3];
105919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[0], "0.before",
106019ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
106119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[1], "2.in_between",
106219ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
106319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[2], "4.after",
106419ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
106519ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[0], "test.4", 7) => 7;
106619ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[1], "test.5", 7) => 7;
106719ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[2], "test.6", 7) => 7;
106819ea8026Sopenharmony_ci
106919ea8026Sopenharmony_ci    // rename file while everything is open, this triggers both
107019ea8026Sopenharmony_ci    // a create and delete simultaneously
107119ea8026Sopenharmony_ci    lfs_rename(&lfs, "/1.move_me", "/3.move_me") => 0;
107219ea8026Sopenharmony_ci
107319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[0]) => 0;
107419ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[1]) => 0;
107519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[2]) => 0;
107619ea8026Sopenharmony_ci
107719ea8026Sopenharmony_ci    // check that nothing was corrupted
107819ea8026Sopenharmony_ci    lfs_dir_t dir;
107919ea8026Sopenharmony_ci    struct lfs_info info;
108019ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/") => 0;
108119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
108219ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
108319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
108419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
108519ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
108619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
108719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
108819ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
108919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
109019ea8026Sopenharmony_ci    assert(info.size == 7);
109119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
109219ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.in_between") == 0);
109319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
109419ea8026Sopenharmony_ci    assert(info.size == 7);
109519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
109619ea8026Sopenharmony_ci    assert(strcmp(info.name, "3.move_me") == 0);
109719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
109819ea8026Sopenharmony_ci    assert(info.size == 0);
109919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
110019ea8026Sopenharmony_ci    assert(strcmp(info.name, "4.after") == 0);
110119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
110219ea8026Sopenharmony_ci    assert(info.size == 7);
110319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
110419ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
110519ea8026Sopenharmony_ci
110619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/0.before", LFS_O_RDONLY) => 0;
110719ea8026Sopenharmony_ci    uint8_t buffer[1024];
110819ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
110919ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.4") == 0);
111019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
111119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/2.in_between", LFS_O_RDONLY) => 0;
111219ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
111319ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.5") == 0);
111419ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
111519ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/4.after", LFS_O_RDONLY) => 0;
111619ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
111719ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.6") == 0);
111819ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
111919ea8026Sopenharmony_ci
112019ea8026Sopenharmony_ci    // now move back
112119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[0], "0.before",
112219ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
112319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[1], "2.in_between",
112419ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
112519ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[2], "4.after",
112619ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
112719ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[0], "test.7", 7) => 7;
112819ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[1], "test.8", 7) => 7;
112919ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[2], "test.9", 7) => 7;
113019ea8026Sopenharmony_ci
113119ea8026Sopenharmony_ci    // rename file while everything is open, this triggers both
113219ea8026Sopenharmony_ci    // a create and delete simultaneously
113319ea8026Sopenharmony_ci    lfs_rename(&lfs, "/3.move_me", "/1.move_me") => 0;
113419ea8026Sopenharmony_ci
113519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[0]) => 0;
113619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[1]) => 0;
113719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[2]) => 0;
113819ea8026Sopenharmony_ci
113919ea8026Sopenharmony_ci    // and check that nothing was corrupted again
114019ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/") => 0;
114119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
114219ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
114319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
114419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
114519ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
114619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
114719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
114819ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
114919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
115019ea8026Sopenharmony_ci    assert(info.size == 7);
115119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
115219ea8026Sopenharmony_ci    assert(strcmp(info.name, "1.move_me") == 0);
115319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
115419ea8026Sopenharmony_ci    assert(info.size == 0);
115519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
115619ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.in_between") == 0);
115719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
115819ea8026Sopenharmony_ci    assert(info.size == 7);
115919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
116019ea8026Sopenharmony_ci    assert(strcmp(info.name, "4.after") == 0);
116119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
116219ea8026Sopenharmony_ci    assert(info.size == 7);
116319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
116419ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
116519ea8026Sopenharmony_ci
116619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/0.before", LFS_O_RDONLY) => 0;
116719ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
116819ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.7") == 0);
116919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
117019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/2.in_between", LFS_O_RDONLY) => 0;
117119ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
117219ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.8") == 0);
117319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
117419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/4.after", LFS_O_RDONLY) => 0;
117519ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
117619ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.9") == 0);
117719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
117819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
117919ea8026Sopenharmony_ci'''
118019ea8026Sopenharmony_ci
118119ea8026Sopenharmony_ci# create + delete + delete in same commit with neighbors
118219ea8026Sopenharmony_ci[cases.test_move_create_delete_delete_same]
118319ea8026Sopenharmony_cicode = '''
118419ea8026Sopenharmony_ci    lfs_t lfs;
118519ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
118619ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
118719ea8026Sopenharmony_ci
118819ea8026Sopenharmony_ci    // littlefs keeps files sorted, so we know the order these will be in
118919ea8026Sopenharmony_ci    lfs_file_t file;
119019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/1.move_me",
119119ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
119219ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
119319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/3.move_me",
119419ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
119519ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "remove me",
119619ea8026Sopenharmony_ci            sizeof("remove me")) => sizeof("remove me");
119719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
119819ea8026Sopenharmony_ci
119919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/0.before",
120019ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
120119ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.1", 7) => 7;
120219ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
120319ea8026Sopenharmony_ci
120419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/2.in_between",
120519ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
120619ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.2", 7) => 7;
120719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
120819ea8026Sopenharmony_ci
120919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/4.after",
121019ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
121119ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.3", 7) => 7;
121219ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
121319ea8026Sopenharmony_ci
121419ea8026Sopenharmony_ci    lfs_file_t files[3];
121519ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[0], "0.before",
121619ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
121719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[1], "2.in_between",
121819ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
121919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[2], "4.after",
122019ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
122119ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[0], "test.4", 7) => 7;
122219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[1], "test.5", 7) => 7;
122319ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[2], "test.6", 7) => 7;
122419ea8026Sopenharmony_ci
122519ea8026Sopenharmony_ci    // rename file while everything is open, this triggers both
122619ea8026Sopenharmony_ci    // a create and delete simultaneously
122719ea8026Sopenharmony_ci    lfs_rename(&lfs, "/1.move_me", "/3.move_me") => 0;
122819ea8026Sopenharmony_ci
122919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[0]) => 0;
123019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[1]) => 0;
123119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[2]) => 0;
123219ea8026Sopenharmony_ci
123319ea8026Sopenharmony_ci    // check that nothing was corrupted
123419ea8026Sopenharmony_ci    lfs_dir_t dir;
123519ea8026Sopenharmony_ci    struct lfs_info info;
123619ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/") => 0;
123719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
123819ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
123919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
124019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
124119ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
124219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
124319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
124419ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
124519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
124619ea8026Sopenharmony_ci    assert(info.size == 7);
124719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
124819ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.in_between") == 0);
124919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
125019ea8026Sopenharmony_ci    assert(info.size == 7);
125119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
125219ea8026Sopenharmony_ci    assert(strcmp(info.name, "3.move_me") == 0);
125319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
125419ea8026Sopenharmony_ci    assert(info.size == 0);
125519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
125619ea8026Sopenharmony_ci    assert(strcmp(info.name, "4.after") == 0);
125719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
125819ea8026Sopenharmony_ci    assert(info.size == 7);
125919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
126019ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
126119ea8026Sopenharmony_ci
126219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/0.before", LFS_O_RDONLY) => 0;
126319ea8026Sopenharmony_ci    uint8_t buffer[1024];
126419ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
126519ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.4") == 0);
126619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
126719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/2.in_between", LFS_O_RDONLY) => 0;
126819ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
126919ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.5") == 0);
127019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
127119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/4.after", LFS_O_RDONLY) => 0;
127219ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
127319ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.6") == 0);
127419ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
127519ea8026Sopenharmony_ci
127619ea8026Sopenharmony_ci    // now move back
127719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/1.move_me",
127819ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
127919ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "remove me",
128019ea8026Sopenharmony_ci            sizeof("remove me")) => sizeof("remove me");
128119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
128219ea8026Sopenharmony_ci
128319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[0], "0.before",
128419ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
128519ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[1], "2.in_between",
128619ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
128719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[2], "4.after",
128819ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
128919ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[0], "test.7", 7) => 7;
129019ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[1], "test.8", 7) => 7;
129119ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[2], "test.9", 7) => 7;
129219ea8026Sopenharmony_ci
129319ea8026Sopenharmony_ci    // rename file while everything is open, this triggers both
129419ea8026Sopenharmony_ci    // a create and delete simultaneously
129519ea8026Sopenharmony_ci    lfs_rename(&lfs, "/3.move_me", "/1.move_me") => 0;
129619ea8026Sopenharmony_ci
129719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[0]) => 0;
129819ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[1]) => 0;
129919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[2]) => 0;
130019ea8026Sopenharmony_ci
130119ea8026Sopenharmony_ci    // and check that nothing was corrupted again
130219ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/") => 0;
130319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
130419ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
130519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
130619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
130719ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
130819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
130919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
131019ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
131119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
131219ea8026Sopenharmony_ci    assert(info.size == 7);
131319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
131419ea8026Sopenharmony_ci    assert(strcmp(info.name, "1.move_me") == 0);
131519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
131619ea8026Sopenharmony_ci    assert(info.size == 0);
131719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
131819ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.in_between") == 0);
131919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
132019ea8026Sopenharmony_ci    assert(info.size == 7);
132119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
132219ea8026Sopenharmony_ci    assert(strcmp(info.name, "4.after") == 0);
132319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
132419ea8026Sopenharmony_ci    assert(info.size == 7);
132519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
132619ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
132719ea8026Sopenharmony_ci
132819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/0.before", LFS_O_RDONLY) => 0;
132919ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
133019ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.7") == 0);
133119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
133219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/2.in_between", LFS_O_RDONLY) => 0;
133319ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
133419ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.8") == 0);
133519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
133619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/4.after", LFS_O_RDONLY) => 0;
133719ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
133819ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.9") == 0);
133919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
134019ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
134119ea8026Sopenharmony_ci'''
134219ea8026Sopenharmony_ci
134319ea8026Sopenharmony_ci# create + delete in different dirs with neighbors
134419ea8026Sopenharmony_ci[cases.test_move_create_delete_different]
134519ea8026Sopenharmony_cicode = '''
134619ea8026Sopenharmony_ci    lfs_t lfs;
134719ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
134819ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
134919ea8026Sopenharmony_ci
135019ea8026Sopenharmony_ci    // littlefs keeps files sorted, so we know the order these will be in
135119ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "/dir.1") => 0;
135219ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "/dir.2") => 0;
135319ea8026Sopenharmony_ci    lfs_file_t file;
135419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.1/1.move_me",
135519ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
135619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
135719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.2/1.move_me",
135819ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
135919ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "remove me",
136019ea8026Sopenharmony_ci            sizeof("remove me")) => sizeof("remove me");
136119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
136219ea8026Sopenharmony_ci
136319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.1/0.before",
136419ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
136519ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.1", 7) => 7;
136619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
136719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.1/2.after",
136819ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
136919ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.2", 7) => 7;
137019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
137119ea8026Sopenharmony_ci
137219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.2/0.before",
137319ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
137419ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.3", 7) => 7;
137519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
137619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.2/2.after",
137719ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
137819ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.4", 7) => 7;
137919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
138019ea8026Sopenharmony_ci
138119ea8026Sopenharmony_ci    lfs_file_t files[4];
138219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[0], "/dir.1/0.before",
138319ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
138419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[1], "/dir.1/2.after",
138519ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
138619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[2], "/dir.2/0.before",
138719ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
138819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[3], "/dir.2/2.after",
138919ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
139019ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[0], "test.5", 7) => 7;
139119ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[1], "test.6", 7) => 7;
139219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[2], "test.7", 7) => 7;
139319ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[3], "test.8", 7) => 7;
139419ea8026Sopenharmony_ci
139519ea8026Sopenharmony_ci    // rename file while everything is open, this triggers both
139619ea8026Sopenharmony_ci    // a create and delete as it overwrites the destination file
139719ea8026Sopenharmony_ci    lfs_rename(&lfs, "/dir.1/1.move_me", "/dir.2/1.move_me") => 0;
139819ea8026Sopenharmony_ci
139919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[0]) => 0;
140019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[1]) => 0;
140119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[2]) => 0;
140219ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[3]) => 0;
140319ea8026Sopenharmony_ci
140419ea8026Sopenharmony_ci    // check that nothing was corrupted
140519ea8026Sopenharmony_ci    lfs_dir_t dir;
140619ea8026Sopenharmony_ci    struct lfs_info info;
140719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/") => 0;
140819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
140919ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
141019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
141119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
141219ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
141319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
141419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
141519ea8026Sopenharmony_ci    assert(strcmp(info.name, "dir.1") == 0);
141619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
141719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
141819ea8026Sopenharmony_ci    assert(strcmp(info.name, "dir.2") == 0);
141919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
142019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
142119ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
142219ea8026Sopenharmony_ci
142319ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/dir.1") => 0;
142419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
142519ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
142619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
142719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
142819ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
142919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
143019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
143119ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
143219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
143319ea8026Sopenharmony_ci    assert(info.size == 7);
143419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
143519ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.after") == 0);
143619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
143719ea8026Sopenharmony_ci    assert(info.size == 7);
143819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
143919ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
144019ea8026Sopenharmony_ci
144119ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/dir.2") => 0;
144219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
144319ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
144419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
144519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
144619ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
144719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
144819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
144919ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
145019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
145119ea8026Sopenharmony_ci    assert(info.size == 7);
145219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
145319ea8026Sopenharmony_ci    assert(strcmp(info.name, "1.move_me") == 0);
145419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
145519ea8026Sopenharmony_ci    assert(info.size == 0);
145619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
145719ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.after") == 0);
145819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
145919ea8026Sopenharmony_ci    assert(info.size == 7);
146019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
146119ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
146219ea8026Sopenharmony_ci
146319ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.1/0.before", LFS_O_RDONLY) => 0;
146419ea8026Sopenharmony_ci    uint8_t buffer[1024];
146519ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
146619ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.5") == 0);
146719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
146819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.1/2.after", LFS_O_RDONLY) => 0;
146919ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
147019ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.6") == 0);
147119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
147219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.2/0.before", LFS_O_RDONLY) => 0;
147319ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
147419ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.7") == 0);
147519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
147619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.2/2.after", LFS_O_RDONLY) => 0;
147719ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
147819ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.8") == 0);
147919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
148019ea8026Sopenharmony_ci
148119ea8026Sopenharmony_ci    // now move back
148219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.1/1.move_me",
148319ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
148419ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "remove me",
148519ea8026Sopenharmony_ci            sizeof("remove me")) => sizeof("remove me");
148619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
148719ea8026Sopenharmony_ci
148819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[0], "/dir.1/0.before",
148919ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
149019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[1], "/dir.1/2.after",
149119ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
149219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[2], "/dir.2/0.before",
149319ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
149419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[3], "/dir.2/2.after",
149519ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
149619ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[0], "test.9", 7) => 7;
149719ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[1], "test.a", 7) => 7;
149819ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[2], "test.b", 7) => 7;
149919ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[3], "test.c", 7) => 7;
150019ea8026Sopenharmony_ci
150119ea8026Sopenharmony_ci    // rename file while everything is open, this triggers both
150219ea8026Sopenharmony_ci    // a create and delete simultaneously
150319ea8026Sopenharmony_ci    lfs_rename(&lfs, "/dir.2/1.move_me", "/dir.1/1.move_me") => 0;
150419ea8026Sopenharmony_ci
150519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[0]) => 0;
150619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[1]) => 0;
150719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[2]) => 0;
150819ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[3]) => 0;
150919ea8026Sopenharmony_ci
151019ea8026Sopenharmony_ci    // and check that nothing was corrupted again
151119ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/") => 0;
151219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
151319ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
151419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
151519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
151619ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
151719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
151819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
151919ea8026Sopenharmony_ci    assert(strcmp(info.name, "dir.1") == 0);
152019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
152119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
152219ea8026Sopenharmony_ci    assert(strcmp(info.name, "dir.2") == 0);
152319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
152419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
152519ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
152619ea8026Sopenharmony_ci
152719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/dir.1") => 0;
152819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
152919ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
153019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
153119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
153219ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
153319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
153419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
153519ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
153619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
153719ea8026Sopenharmony_ci    assert(info.size == 7);
153819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
153919ea8026Sopenharmony_ci    assert(strcmp(info.name, "1.move_me") == 0);
154019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
154119ea8026Sopenharmony_ci    assert(info.size == 0);
154219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
154319ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.after") == 0);
154419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
154519ea8026Sopenharmony_ci    assert(info.size == 7);
154619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
154719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
154819ea8026Sopenharmony_ci
154919ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/dir.2") => 0;
155019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
155119ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
155219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
155319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
155419ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
155519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
155619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
155719ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
155819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
155919ea8026Sopenharmony_ci    assert(info.size == 7);
156019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
156119ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.after") == 0);
156219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
156319ea8026Sopenharmony_ci    assert(info.size == 7);
156419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
156519ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
156619ea8026Sopenharmony_ci
156719ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.1/0.before", LFS_O_RDONLY) => 0;
156819ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
156919ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.9") == 0);
157019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
157119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.1/2.after", LFS_O_RDONLY) => 0;
157219ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
157319ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.a") == 0);
157419ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
157519ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.2/0.before", LFS_O_RDONLY) => 0;
157619ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
157719ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.b") == 0);
157819ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
157919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/dir.2/2.after", LFS_O_RDONLY) => 0;
158019ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
158119ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.c") == 0);
158219ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
158319ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
158419ea8026Sopenharmony_ci'''
158519ea8026Sopenharmony_ci
158619ea8026Sopenharmony_ci# move fix in relocation
158719ea8026Sopenharmony_ci[cases.test_move_fix_relocation]
158819ea8026Sopenharmony_ciin = "lfs.c"
158919ea8026Sopenharmony_cidefines.RELOCATIONS = 'range(4)'
159019ea8026Sopenharmony_cidefines.ERASE_CYCLES = 0xffffffff
159119ea8026Sopenharmony_cicode = '''
159219ea8026Sopenharmony_ci    lfs_t lfs;
159319ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
159419ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
159519ea8026Sopenharmony_ci
159619ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "/parent") => 0;
159719ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "/parent/child") => 0;
159819ea8026Sopenharmony_ci
159919ea8026Sopenharmony_ci    lfs_file_t file;
160019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/1.move_me",
160119ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
160219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "move me",
160319ea8026Sopenharmony_ci            sizeof("move me")) => sizeof("move me");
160419ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
160519ea8026Sopenharmony_ci
160619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/0.before",
160719ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
160819ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.1", 7) => 7;
160919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
161019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/2.after",
161119ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
161219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.2", 7) => 7;
161319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
161419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/child/0.before",
161519ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
161619ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.3", 7) => 7;
161719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
161819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/child/2.after",
161919ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
162019ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.4", 7) => 7;
162119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
162219ea8026Sopenharmony_ci
162319ea8026Sopenharmony_ci    lfs_file_t files[4];
162419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[0], "/parent/0.before",
162519ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
162619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[1], "/parent/2.after",
162719ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
162819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[2], "/parent/child/0.before",
162919ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
163019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[3], "/parent/child/2.after",
163119ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
163219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[0], "test.5", 7) => 7;
163319ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[1], "test.6", 7) => 7;
163419ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[2], "test.7", 7) => 7;
163519ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[3], "test.8", 7) => 7;
163619ea8026Sopenharmony_ci
163719ea8026Sopenharmony_ci    // force specific directories to relocate
163819ea8026Sopenharmony_ci    if (RELOCATIONS & 0x1) {
163919ea8026Sopenharmony_ci        lfs_dir_t dir;
164019ea8026Sopenharmony_ci        lfs_dir_open(&lfs, &dir, "/parent");
164119ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[0], 0xffffffff) => 0;
164219ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[1], 0xffffffff) => 0;
164319ea8026Sopenharmony_ci        lfs_dir_close(&lfs, &dir) => 0;
164419ea8026Sopenharmony_ci    }
164519ea8026Sopenharmony_ci    if (RELOCATIONS & 0x2) {
164619ea8026Sopenharmony_ci        lfs_dir_t dir;
164719ea8026Sopenharmony_ci        lfs_dir_open(&lfs, &dir, "/parent/child");
164819ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[0], 0xffffffff) => 0;
164919ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[1], 0xffffffff) => 0;
165019ea8026Sopenharmony_ci        lfs_dir_close(&lfs, &dir) => 0;
165119ea8026Sopenharmony_ci    }
165219ea8026Sopenharmony_ci
165319ea8026Sopenharmony_ci    // ok, now we move the file, this creates a move that needs to be
165419ea8026Sopenharmony_ci    // fixed, possibly in a metadata-pair that needs to be relocated
165519ea8026Sopenharmony_ci    //
165619ea8026Sopenharmony_ci    // the worst case is if we need to relocate and we need to implicit
165719ea8026Sopenharmony_ci    // fix the move in our parent before it falls out of date
165819ea8026Sopenharmony_ci    lfs_rename(&lfs, "/parent/1.move_me", "/parent/child/1.move_me") => 0;
165919ea8026Sopenharmony_ci
166019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[0]) => 0;
166119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[1]) => 0;
166219ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[2]) => 0;
166319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[3]) => 0;
166419ea8026Sopenharmony_ci
166519ea8026Sopenharmony_ci    // check that nothing was corrupted
166619ea8026Sopenharmony_ci    lfs_dir_t dir;
166719ea8026Sopenharmony_ci    struct lfs_info info;
166819ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/parent") => 0;
166919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
167019ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
167119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
167219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
167319ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
167419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
167519ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
167619ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
167719ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
167819ea8026Sopenharmony_ci    assert(info.size == 7);
167919ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
168019ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.after") == 0);
168119ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
168219ea8026Sopenharmony_ci    assert(info.size == 7);
168319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
168419ea8026Sopenharmony_ci    assert(strcmp(info.name, "child") == 0);
168519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
168619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
168719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
168819ea8026Sopenharmony_ci
168919ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/parent/child") => 0;
169019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
169119ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
169219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
169319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
169419ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
169519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
169619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
169719ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
169819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
169919ea8026Sopenharmony_ci    assert(info.size == 7);
170019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
170119ea8026Sopenharmony_ci    assert(strcmp(info.name, "1.move_me") == 0);
170219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
170319ea8026Sopenharmony_ci    assert(info.size == sizeof("move me"));
170419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
170519ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.after") == 0);
170619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
170719ea8026Sopenharmony_ci    assert(info.size == 7);
170819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
170919ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
171019ea8026Sopenharmony_ci
171119ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/0.before", LFS_O_RDONLY) => 0;
171219ea8026Sopenharmony_ci    uint8_t buffer[1024];
171319ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
171419ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.5") == 0);
171519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
171619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/2.after", LFS_O_RDONLY) => 0;
171719ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
171819ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.6") == 0);
171919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
172019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/child/0.before", LFS_O_RDONLY) => 0;
172119ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
172219ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.7") == 0);
172319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
172419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/child/2.after", LFS_O_RDONLY) => 0;
172519ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
172619ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.8") == 0);
172719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
172819ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
172919ea8026Sopenharmony_ci'''
173019ea8026Sopenharmony_ci
173119ea8026Sopenharmony_ci# move fix in relocation with predecessor
173219ea8026Sopenharmony_ci[cases.test_move_fix_relocation_predecessor]
173319ea8026Sopenharmony_ciin = "lfs.c"
173419ea8026Sopenharmony_cidefines.RELOCATIONS = 'range(8)'
173519ea8026Sopenharmony_cidefines.ERASE_CYCLES = 0xffffffff
173619ea8026Sopenharmony_cicode = '''
173719ea8026Sopenharmony_ci    lfs_t lfs;
173819ea8026Sopenharmony_ci    lfs_format(&lfs, cfg) => 0;
173919ea8026Sopenharmony_ci    lfs_mount(&lfs, cfg) => 0;
174019ea8026Sopenharmony_ci
174119ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "/parent") => 0;
174219ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "/parent/child") => 0;
174319ea8026Sopenharmony_ci    lfs_mkdir(&lfs, "/parent/sibling") => 0;
174419ea8026Sopenharmony_ci
174519ea8026Sopenharmony_ci    lfs_file_t file;
174619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/sibling/1.move_me",
174719ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
174819ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "move me",
174919ea8026Sopenharmony_ci            sizeof("move me")) => sizeof("move me");
175019ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
175119ea8026Sopenharmony_ci
175219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/sibling/0.before",
175319ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
175419ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.1", 7) => 7;
175519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
175619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/sibling/2.after",
175719ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
175819ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.2", 7) => 7;
175919ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
176019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/child/0.before",
176119ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
176219ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.3", 7) => 7;
176319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
176419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/child/2.after",
176519ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_CREAT) => 0;
176619ea8026Sopenharmony_ci    lfs_file_write(&lfs, &file, "test.4", 7) => 7;
176719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
176819ea8026Sopenharmony_ci
176919ea8026Sopenharmony_ci    lfs_file_t files[4];
177019ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[0], "/parent/sibling/0.before",
177119ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
177219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[1], "/parent/sibling/2.after",
177319ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
177419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[2], "/parent/child/0.before",
177519ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
177619ea8026Sopenharmony_ci    lfs_file_open(&lfs, &files[3], "/parent/child/2.after",
177719ea8026Sopenharmony_ci            LFS_O_WRONLY | LFS_O_TRUNC) => 0;
177819ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[0], "test.5", 7) => 7;
177919ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[1], "test.6", 7) => 7;
178019ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[2], "test.7", 7) => 7;
178119ea8026Sopenharmony_ci    lfs_file_write(&lfs, &files[3], "test.8", 7) => 7;
178219ea8026Sopenharmony_ci
178319ea8026Sopenharmony_ci    // force specific directories to relocate
178419ea8026Sopenharmony_ci    if (RELOCATIONS & 0x1) {
178519ea8026Sopenharmony_ci        lfs_dir_t dir;
178619ea8026Sopenharmony_ci        lfs_dir_open(&lfs, &dir, "/parent");
178719ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[0], 0xffffffff) => 0;
178819ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[1], 0xffffffff) => 0;
178919ea8026Sopenharmony_ci        lfs_dir_close(&lfs, &dir) => 0;
179019ea8026Sopenharmony_ci    }
179119ea8026Sopenharmony_ci    if (RELOCATIONS & 0x2) {
179219ea8026Sopenharmony_ci        lfs_dir_t dir;
179319ea8026Sopenharmony_ci        lfs_dir_open(&lfs, &dir, "/parent/sibling");
179419ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[0], 0xffffffff) => 0;
179519ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[1], 0xffffffff) => 0;
179619ea8026Sopenharmony_ci        lfs_dir_close(&lfs, &dir) => 0;
179719ea8026Sopenharmony_ci    }
179819ea8026Sopenharmony_ci    if (RELOCATIONS & 0x4) {
179919ea8026Sopenharmony_ci        lfs_dir_t dir;
180019ea8026Sopenharmony_ci        lfs_dir_open(&lfs, &dir, "/parent/child");
180119ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[0], 0xffffffff) => 0;
180219ea8026Sopenharmony_ci        lfs_emubd_setwear(cfg, dir.m.pair[1], 0xffffffff) => 0;
180319ea8026Sopenharmony_ci        lfs_dir_close(&lfs, &dir) => 0;
180419ea8026Sopenharmony_ci    }
180519ea8026Sopenharmony_ci
180619ea8026Sopenharmony_ci    // ok, now we move the file, this creates a move that needs to be
180719ea8026Sopenharmony_ci    // fixed, possibly in a metadata-pair that needs to be relocated
180819ea8026Sopenharmony_ci    //
180919ea8026Sopenharmony_ci    // and now relocations can force us to need to fix our move in either
181019ea8026Sopenharmony_ci    // the parent or child before things break
181119ea8026Sopenharmony_ci    lfs_rename(&lfs,
181219ea8026Sopenharmony_ci            "/parent/sibling/1.move_me",
181319ea8026Sopenharmony_ci            "/parent/child/1.move_me") => 0;
181419ea8026Sopenharmony_ci
181519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[0]) => 0;
181619ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[1]) => 0;
181719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[2]) => 0;
181819ea8026Sopenharmony_ci    lfs_file_close(&lfs, &files[3]) => 0;
181919ea8026Sopenharmony_ci
182019ea8026Sopenharmony_ci    // check that nothing was corrupted
182119ea8026Sopenharmony_ci    lfs_dir_t dir;
182219ea8026Sopenharmony_ci    struct lfs_info info;
182319ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/parent") => 0;
182419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
182519ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
182619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
182719ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
182819ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
182919ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
183019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
183119ea8026Sopenharmony_ci    assert(strcmp(info.name, "child") == 0);
183219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
183319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
183419ea8026Sopenharmony_ci    assert(strcmp(info.name, "sibling") == 0);
183519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
183619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
183719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
183819ea8026Sopenharmony_ci
183919ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/parent/sibling") => 0;
184019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
184119ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
184219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
184319ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
184419ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
184519ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
184619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
184719ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
184819ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
184919ea8026Sopenharmony_ci    assert(info.size == 7);
185019ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
185119ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.after") == 0);
185219ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
185319ea8026Sopenharmony_ci    assert(info.size == 7);
185419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
185519ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
185619ea8026Sopenharmony_ci
185719ea8026Sopenharmony_ci    lfs_dir_open(&lfs, &dir, "/parent/child") => 0;
185819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
185919ea8026Sopenharmony_ci    assert(strcmp(info.name, ".") == 0);
186019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
186119ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
186219ea8026Sopenharmony_ci    assert(strcmp(info.name, "..") == 0);
186319ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_DIR);
186419ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
186519ea8026Sopenharmony_ci    assert(strcmp(info.name, "0.before") == 0);
186619ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
186719ea8026Sopenharmony_ci    assert(info.size == 7);
186819ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
186919ea8026Sopenharmony_ci    assert(strcmp(info.name, "1.move_me") == 0);
187019ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
187119ea8026Sopenharmony_ci    assert(info.size == sizeof("move me"));
187219ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 1;
187319ea8026Sopenharmony_ci    assert(strcmp(info.name, "2.after") == 0);
187419ea8026Sopenharmony_ci    assert(info.type == LFS_TYPE_REG);
187519ea8026Sopenharmony_ci    assert(info.size == 7);
187619ea8026Sopenharmony_ci    lfs_dir_read(&lfs, &dir, &info) => 0;
187719ea8026Sopenharmony_ci    lfs_dir_close(&lfs, &dir) => 0;
187819ea8026Sopenharmony_ci
187919ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/sibling/0.before", LFS_O_RDONLY) => 0;
188019ea8026Sopenharmony_ci    uint8_t buffer[1024];
188119ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
188219ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.5") == 0);
188319ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
188419ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/sibling/2.after", LFS_O_RDONLY) => 0;
188519ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
188619ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.6") == 0);
188719ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
188819ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/child/0.before", LFS_O_RDONLY) => 0;
188919ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
189019ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.7") == 0);
189119ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
189219ea8026Sopenharmony_ci    lfs_file_open(&lfs, &file, "/parent/child/2.after", LFS_O_RDONLY) => 0;
189319ea8026Sopenharmony_ci    lfs_file_read(&lfs, &file, buffer, 7) => 7;
189419ea8026Sopenharmony_ci    assert(strcmp((char*)buffer, "test.8") == 0);
189519ea8026Sopenharmony_ci    lfs_file_close(&lfs, &file) => 0;
189619ea8026Sopenharmony_ci    lfs_unmount(&lfs) => 0;
189719ea8026Sopenharmony_ci'''
1898