| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957 |
- [[case]] # move file
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
- lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
- lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
- lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
- lfs_file_close(&lfs, &file) => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hello", "c/hello") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
- lfs_file_read(&lfs, &file, buffer, 5) => 5;
- memcmp(buffer, "hola\n", 5) => 0;
- lfs_file_read(&lfs, &file, buffer, 8) => 8;
- memcmp(buffer, "bonjour\n", 8) => 0;
- lfs_file_read(&lfs, &file, buffer, 6) => 6;
- memcmp(buffer, "ohayo\n", 6) => 0;
- lfs_file_close(&lfs, &file) => 0;
- lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # move file corrupt source
- in = "lfs.c"
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
- lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
- lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
- lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
- lfs_file_close(&lfs, &file) => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hello", "c/hello") => 0;
- lfs_unmount(&lfs) => 0;
- // corrupt the source
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_block_t block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- uint8_t bbuffer[LFS_BLOCK_SIZE];
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- int off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
- lfs_file_read(&lfs, &file, buffer, 5) => 5;
- memcmp(buffer, "hola\n", 5) => 0;
- lfs_file_read(&lfs, &file, buffer, 8) => 8;
- memcmp(buffer, "bonjour\n", 8) => 0;
- lfs_file_read(&lfs, &file, buffer, 6) => 6;
- memcmp(buffer, "ohayo\n", 6) => 0;
- lfs_file_close(&lfs, &file) => 0;
- lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # move file corrupt source and dest
- in = "lfs.c"
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
- lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
- lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
- lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
- lfs_file_close(&lfs, &file) => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hello", "c/hello") => 0;
- lfs_unmount(&lfs) => 0;
- // corrupt the source
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_block_t block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- uint8_t bbuffer[LFS_BLOCK_SIZE];
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- int off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- // corrupt the destination
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => 0;
- lfs_file_read(&lfs, &file, buffer, 5) => 5;
- memcmp(buffer, "hola\n", 5) => 0;
- lfs_file_read(&lfs, &file, buffer, 8) => 8;
- memcmp(buffer, "bonjour\n", 8) => 0;
- lfs_file_read(&lfs, &file, buffer, 6) => 6;
- memcmp(buffer, "ohayo\n", 6) => 0;
- lfs_file_close(&lfs, &file) => 0;
- lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # move file after corrupt
- in = "lfs.c"
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
- lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
- lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
- lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
- lfs_file_close(&lfs, &file) => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hello", "c/hello") => 0;
- lfs_unmount(&lfs) => 0;
- // corrupt the source
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_block_t block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- uint8_t bbuffer[LFS_BLOCK_SIZE];
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- int off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- // corrupt the destination
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- // continue move
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hello", "c/hello") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
- lfs_file_read(&lfs, &file, buffer, 5) => 5;
- memcmp(buffer, "hola\n", 5) => 0;
- lfs_file_read(&lfs, &file, buffer, 8) => 8;
- memcmp(buffer, "bonjour\n", 8) => 0;
- lfs_file_read(&lfs, &file, buffer, 6) => 6;
- memcmp(buffer, "ohayo\n", 6) => 0;
- lfs_file_close(&lfs, &file) => 0;
- lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # simple reentrant move file
- reentrant = true
- code = '''
- err = lfs_mount(&lfs, &cfg);
- if (err) {
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- }
- err = lfs_mkdir(&lfs, "a");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "b");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "c");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "d");
- assert(!err || err == LFS_ERR_EXIST);
- lfs_unmount(&lfs) => 0;
- while (true) {
- lfs_mount(&lfs, &cfg) => 0;
- // there should never exist _2_ hello files
- int count = 0;
- if (lfs_stat(&lfs, "a/hello", &info) == 0) {
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6 || info.size == 0);
- count += 1;
- }
- if (lfs_stat(&lfs, "b/hello", &info) == 0) {
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6);
- count += 1;
- }
- if (lfs_stat(&lfs, "c/hello", &info) == 0) {
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6);
- count += 1;
- }
- if (lfs_stat(&lfs, "d/hello", &info) == 0) {
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6);
- count += 1;
- }
- assert(count <= 1);
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- if (lfs_stat(&lfs, "a/hello", &info) == 0 && info.size > 0) {
- lfs_rename(&lfs, "a/hello", "b/hello") => 0;
- } else if (lfs_stat(&lfs, "b/hello", &info) == 0) {
- lfs_rename(&lfs, "b/hello", "c/hello") => 0;
- } else if (lfs_stat(&lfs, "c/hello", &info) == 0) {
- lfs_rename(&lfs, "c/hello", "d/hello") => 0;
- } else if (lfs_stat(&lfs, "d/hello", &info) == 0) {
- // success
- break;
- } else {
- // create file
- lfs_file_open(&lfs, &file, "a/hello",
- LFS_O_WRONLY | LFS_O_CREAT) => 0;
- lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
- lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
- lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
- lfs_file_close(&lfs, &file) => 0;
- }
- lfs_unmount(&lfs) => 0;
- }
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "d") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hello") == 0);
- assert(info.type == LFS_TYPE_REG);
- assert(info.size == 5+8+6);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
- lfs_file_read(&lfs, &file, buffer, 5) => 5;
- memcmp(buffer, "hola\n", 5) => 0;
- lfs_file_read(&lfs, &file, buffer, 8) => 8;
- memcmp(buffer, "bonjour\n", 8) => 0;
- lfs_file_read(&lfs, &file, buffer, 6) => 6;
- memcmp(buffer, "ohayo\n", 6) => 0;
- lfs_file_close(&lfs, &file) => 0;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # move dir
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_mkdir(&lfs, "a/hi") => 0;
- lfs_mkdir(&lfs, "a/hi/hola") => 0;
- lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
- lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hi", "c/hi") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "c/hi") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "bonjour") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hola") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "ohayo") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # move dir corrupt source
- in = "lfs.c"
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_mkdir(&lfs, "a/hi") => 0;
- lfs_mkdir(&lfs, "a/hi/hola") => 0;
- lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
- lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hi", "c/hi") => 0;
- lfs_unmount(&lfs) => 0;
- // corrupt the source
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_block_t block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- uint8_t bbuffer[LFS_BLOCK_SIZE];
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- int off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "c/hi") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "bonjour") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hola") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "ohayo") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # move dir corrupt source and dest
- in = "lfs.c"
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_mkdir(&lfs, "a/hi") => 0;
- lfs_mkdir(&lfs, "a/hi/hola") => 0;
- lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
- lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hi", "c/hi") => 0;
- lfs_unmount(&lfs) => 0;
- // corrupt the source
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_block_t block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- uint8_t bbuffer[LFS_BLOCK_SIZE];
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- int off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- // corrupt the destination
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "a/hi") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "bonjour") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hola") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "ohayo") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # move dir after corrupt
- in = "lfs.c"
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_mkdir(&lfs, "a/hi") => 0;
- lfs_mkdir(&lfs, "a/hi/hola") => 0;
- lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
- lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hi", "c/hi") => 0;
- lfs_unmount(&lfs) => 0;
- // corrupt the source
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_block_t block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- uint8_t bbuffer[LFS_BLOCK_SIZE];
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- int off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- // corrupt the destination
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- block = dir.m.pair[0];
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- off = LFS_BLOCK_SIZE-1;
- while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
- off -= 1;
- }
- memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
- cfg.erase(&cfg, block) => 0;
- cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
- cfg.sync(&cfg) => 0;
- // continue move
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hi", "c/hi") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "c") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "c/hi") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "bonjour") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hola") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "ohayo") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # simple reentrant move dir
- reentrant = true
- code = '''
- err = lfs_mount(&lfs, &cfg);
- if (err) {
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- }
- err = lfs_mkdir(&lfs, "a");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "b");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "c");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "d");
- assert(!err || err == LFS_ERR_EXIST);
- lfs_unmount(&lfs) => 0;
- while (true) {
- lfs_mount(&lfs, &cfg) => 0;
- // there should never exist _2_ hi directories
- int count = 0;
- if (lfs_stat(&lfs, "a/hi", &info) == 0) {
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- count += 1;
- }
- if (lfs_stat(&lfs, "b/hi", &info) == 0) {
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- count += 1;
- }
- if (lfs_stat(&lfs, "c/hi", &info) == 0) {
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- count += 1;
- }
- if (lfs_stat(&lfs, "d/hi", &info) == 0) {
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- count += 1;
- }
- assert(count <= 1);
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- if (lfs_stat(&lfs, "a/hi", &info) == 0) {
- lfs_rename(&lfs, "a/hi", "b/hi") => 0;
- } else if (lfs_stat(&lfs, "b/hi", &info) == 0) {
- lfs_rename(&lfs, "b/hi", "c/hi") => 0;
- } else if (lfs_stat(&lfs, "c/hi", &info) == 0) {
- lfs_rename(&lfs, "c/hi", "d/hi") => 0;
- } else if (lfs_stat(&lfs, "d/hi", &info) == 0) {
- break; // success
- } else {
- // create dir and rename for atomicity
- err = lfs_mkdir(&lfs, "temp");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "temp/hola");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "temp/bonjour");
- assert(!err || err == LFS_ERR_EXIST);
- err = lfs_mkdir(&lfs, "temp/ohayo");
- assert(!err || err == LFS_ERR_EXIST);
- lfs_rename(&lfs, "temp", "a/hi") => 0;
- }
- lfs_unmount(&lfs) => 0;
- }
- lfs_mount(&lfs, &cfg) => 0;
- lfs_dir_open(&lfs, &dir, "a") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "d") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hi") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT;
- lfs_dir_open(&lfs, &dir, "d/hi") => 0;
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, ".") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "..") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "bonjour") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "hola") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 1;
- assert(strcmp(info.name, "ohayo") == 0);
- assert(info.type == LFS_TYPE_DIR);
- lfs_dir_read(&lfs, &dir, &info) => 0;
- lfs_dir_close(&lfs, &dir) => 0;
- lfs_unmount(&lfs) => 0;
- '''
- [[case]] # move state stealing
- code = '''
- lfs_format(&lfs, &cfg) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_mkdir(&lfs, "a") => 0;
- lfs_mkdir(&lfs, "b") => 0;
- lfs_mkdir(&lfs, "c") => 0;
- lfs_mkdir(&lfs, "d") => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
- lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
- lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
- lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
- lfs_file_close(&lfs, &file) => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "a/hello", "b/hello") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "b/hello", "c/hello") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_rename(&lfs, "c/hello", "d/hello") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
- lfs_file_read(&lfs, &file, buffer, 5) => 5;
- memcmp(buffer, "hola\n", 5) => 0;
- lfs_file_read(&lfs, &file, buffer, 8) => 8;
- memcmp(buffer, "bonjour\n", 8) => 0;
- lfs_file_read(&lfs, &file, buffer, 6) => 6;
- memcmp(buffer, "ohayo\n", 6) => 0;
- lfs_file_close(&lfs, &file) => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_remove(&lfs, "b") => 0;
- lfs_remove(&lfs, "c") => 0;
- lfs_unmount(&lfs) => 0;
- lfs_mount(&lfs, &cfg) => 0;
- lfs_stat(&lfs, "a", &info) => 0;
- lfs_stat(&lfs, "b", &info) => LFS_ERR_NOENT;
- lfs_stat(&lfs, "c", &info) => LFS_ERR_NOENT;
- lfs_stat(&lfs, "d", &info) => 0;
- lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
- lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
- lfs_file_read(&lfs, &file, buffer, 5) => 5;
- memcmp(buffer, "hola\n", 5) => 0;
- lfs_file_read(&lfs, &file, buffer, 8) => 8;
- memcmp(buffer, "bonjour\n", 8) => 0;
- lfs_file_read(&lfs, &file, buffer, 6) => 6;
- memcmp(buffer, "ohayo\n", 6) => 0;
- lfs_file_close(&lfs, &file) => 0;
- lfs_unmount(&lfs) => 0;
- '''
|