diff --git a/tests/test_paths.toml b/tests/test_paths.toml index 08ef3b3e..8a027a7b 100644 --- a/tests/test_paths.toml +++ b/tests/test_paths.toml @@ -4548,6 +4548,1168 @@ code = ''' lfsr_unmount(&lfs) => 0; ''' +# trailing notsup tests +[cases.test_paths_notsup] +in = 'lfs.c' +code = ''' + lfs_t lfs; + lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0; + lfsr_mount(&lfs, LFS_F_RDWR, CFG) => 0; + + // create paths + lfsr_mkdir(&lfs, "coffee") => 0; + // create paths with unknown file types + const char *path; + lfsr_mdir_t mdir; + lfsr_did_t did; + path = "coffee/drip"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/coldbrew"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/turkish"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/tubruk"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/vietnamese"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/thai"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + + // stat paths + struct lfs_info info; + lfsr_stat(&lfs, "coffee/drip", &info) => 0; + assert(strcmp(info.name, "drip") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/coldbrew", &info) => 0; + assert(strcmp(info.name, "coldbrew") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/turkish", &info) => 0; + assert(strcmp(info.name, "turkish") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/tubruk", &info) => 0; + assert(strcmp(info.name, "tubruk") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/vietnamese", &info) => 0; + assert(strcmp(info.name, "vietnamese") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/thai", &info) => 0; + assert(strcmp(info.name, "thai") == 0); + assert(info.type == 0x13); + + // file open paths, only works on files! + lfsr_file_t file; + lfsr_file_open(&lfs, &file, "coffee/drip", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/coldbrew", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/turkish", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/tubruk", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/vietnamese", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/thai", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + + // dir open paths, only works on dirs! + lfsr_dir_t dir; + lfsr_dir_open(&lfs, &dir, "coffee/drip") => LFS_ERR_NOTDIR; + lfsr_dir_open(&lfs, &dir, "coffee/coldbrew") => LFS_ERR_NOTDIR; + lfsr_dir_open(&lfs, &dir, "coffee/turkish") => LFS_ERR_NOTDIR; + lfsr_dir_open(&lfs, &dir, "coffee/tubruk") => LFS_ERR_NOTDIR; + lfsr_dir_open(&lfs, &dir, "coffee/vietnamese") => LFS_ERR_NOTDIR; + lfsr_dir_open(&lfs, &dir, "coffee/thai") => LFS_ERR_NOTDIR; + + // rename paths + lfsr_mkdir(&lfs, "espresso") => 0; + lfsr_rename(&lfs, + "coffee/drip", + "espresso/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew", + "espresso/americano") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish", + "espresso/macchiato") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk", + "espresso/latte") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese", + "espresso/cappuccino") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai", + "espresso/mocha") => LFS_ERR_NOTSUP; + + // here's a weird one, what happens if our rename is also a noop? + lfsr_rename(&lfs, + "coffee/drip", + "coffee/drip") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew", + "coffee/coldbrew") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish", + "coffee/turkish") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk", + "coffee/tubruk") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese", + "coffee/vietnamese") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai", + "coffee/thai") => LFS_ERR_NOTSUP; + + // remove paths + lfsr_remove(&lfs, "coffee/drip") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/coldbrew") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/turkish") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/tubruk") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/vietnamese") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/thai") => LFS_ERR_NOTSUP; + + // stat paths + lfsr_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT; + + lfsr_stat(&lfs, "coffee/drip", &info) => 0; + assert(strcmp(info.name, "drip") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/coldbrew", &info) => 0; + assert(strcmp(info.name, "coldbrew") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/turkish", &info) => 0; + assert(strcmp(info.name, "turkish") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/tubruk", &info) => 0; + assert(strcmp(info.name, "tubruk") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/vietnamese", &info) => 0; + assert(strcmp(info.name, "vietnamese") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/thai", &info) => 0; + assert(strcmp(info.name, "thai") == 0); + assert(info.type == 0x13); + + lfsr_unmount(&lfs) => 0; +''' + +# parent notsup tests +[cases.test_paths_notsup_parent] +defines.DIR = [false, true] +in = 'lfs.c' +code = ''' + lfs_t lfs; + lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0; + lfsr_mount(&lfs, LFS_F_RDWR, CFG) => 0; + + // create paths with unknown file types + const char *path; + lfsr_mdir_t mdir; + lfsr_did_t did; + path = "drip"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coldbrew"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "turkish"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "tubruk"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "vietnamese"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "thai"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + + if (DIR) { + lfsr_mkdir(&lfs, "drip/coffee") => LFS_ERR_NOTSUP; + lfsr_mkdir(&lfs, "coldbrew/coffee") => LFS_ERR_NOTSUP; + lfsr_mkdir(&lfs, "turkish/coffee") => LFS_ERR_NOTSUP; + lfsr_mkdir(&lfs, "tubruk/coffee") => LFS_ERR_NOTSUP; + lfsr_mkdir(&lfs, "vietnamese/coffee") => LFS_ERR_NOTSUP; + lfsr_mkdir(&lfs, "thai/coffee") => LFS_ERR_NOTSUP; + } else { + lfsr_file_t file; + lfsr_file_open(&lfs, &file, "drip/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coldbrew/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "turkish/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "tubruk/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "vietnamese/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "thai/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + } + + // stat paths + struct lfs_info info; + lfsr_stat(&lfs, "drip/coffee", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coldbrew/coffee", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "turkish/coffee", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "tubruk/coffee", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "vietnamese/coffee", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "thai/coffee", &info) => LFS_ERR_NOTSUP; + + // file open paths, only works on files! + lfsr_file_t file; + lfsr_file_open(&lfs, &file, "drip/coffee", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coldbrew/coffee", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "turkish/coffee", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "tubruk/coffee", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "vietnamese/coffee", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "thai/coffee", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + + lfsr_file_open(&lfs, &file, "drip/coffee", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coldbrew/coffee", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "turkish/coffee", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "tubruk/coffee", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "vietnamese/coffee", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "thai/coffee", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + + lfsr_file_open(&lfs, &file, "drip/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coldbrew/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "turkish/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "tubruk/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "vietnamese/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "thai/coffee", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + + // dir open paths, only works on dirs! + lfsr_dir_t dir; + lfsr_dir_open(&lfs, &dir, "drip/coffee") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coldbrew/coffee") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "turkish/coffee") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "tubruk/coffee") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "vietnamese/coffee") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "thai/coffee") => LFS_ERR_NOTSUP; + + // make some normal paths so we have something to rename + lfsr_mkdir(&lfs, "coffee") => 0; + if (DIR) { + lfsr_mkdir(&lfs, "coffee/drip") => 0; + lfsr_mkdir(&lfs, "coffee/coldbrew") => 0; + lfsr_mkdir(&lfs, "coffee/turkish") => 0; + lfsr_mkdir(&lfs, "coffee/tubruk") => 0; + lfsr_mkdir(&lfs, "coffee/vietnamese") => 0; + lfsr_mkdir(&lfs, "coffee/thai") => 0; + } else { + lfsr_file_t file; + lfsr_file_open(&lfs, &file, "coffee/drip", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; + lfsr_file_close(&lfs, &file) => 0; + lfsr_file_open(&lfs, &file, "coffee/coldbrew", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; + lfsr_file_close(&lfs, &file) => 0; + lfsr_file_open(&lfs, &file, "coffee/turkish", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; + lfsr_file_close(&lfs, &file) => 0; + lfsr_file_open(&lfs, &file, "coffee/tubruk", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; + lfsr_file_close(&lfs, &file) => 0; + lfsr_file_open(&lfs, &file, "coffee/vietnamese", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; + lfsr_file_close(&lfs, &file) => 0; + lfsr_file_open(&lfs, &file, "coffee/thai", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; + lfsr_file_close(&lfs, &file) => 0; + } + + // rename paths + lfsr_mkdir(&lfs, "espresso") => 0; + // bad source + lfsr_rename(&lfs, + "drip/coffee", + "espresso/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coldbrew/coffee", + "espresso/americano") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "turkish/coffee", + "espresso/macchiato") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "tubruk/coffee", + "espresso/latte") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "vietnamese/coffee", + "espresso/cappuccino") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "thai/coffee", + "espresso/mocha") => LFS_ERR_NOTSUP; + + // bad destination + lfsr_rename(&lfs, + "coffee/drip", + "drip/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew", + "coldbrew/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish", + "turkish/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk", + "tubruk/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese", + "vietnamese/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai", + "thai/espresso") => LFS_ERR_NOTSUP; + + // bad source and bad destination + lfsr_rename(&lfs, + "drip/coffee", + "drip/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coldbrew/coffee", + "coldbrew/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "turkish/coffee", + "turkish/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "tubruk/coffee", + "tubruk/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "vietnamese/coffee", + "vietnamese/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "thai/coffee", + "thai/espresso") => LFS_ERR_NOTSUP; + + // here's a weird one, what happens if our rename is also a noop? + lfsr_rename(&lfs, + "drip/coffee", + "drip/coffee") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coldbrew/coffee", + "coldbrew/coffee") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "turkish/coffee", + "turkish/coffee") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "tubruk/coffee", + "tubruk/coffee") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "vietnamese/coffee", + "vietnamese/coffee") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "thai/coffee", + "thai/coffee") => LFS_ERR_NOTSUP; + + // remove paths + lfsr_stat(&lfs, "drip/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coldbrew/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "turkish/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "tubruk/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "vietnamese/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "thai/espresso", &info) => LFS_ERR_NOTSUP; + + // stat paths + lfsr_stat(&lfs, "drip/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coldbrew/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "turkish/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "tubruk/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "vietnamese/espresso", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "thai/espresso", &info) => LFS_ERR_NOTSUP; + + lfsr_stat(&lfs, "coffee/drip", &info) => 0; + assert(strcmp(info.name, "drip") == 0); + assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG)); + lfsr_stat(&lfs, "coffee/coldbrew", &info) => 0; + assert(strcmp(info.name, "coldbrew") == 0); + assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG)); + lfsr_stat(&lfs, "coffee/turkish", &info) => 0; + assert(strcmp(info.name, "turkish") == 0); + assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG)); + lfsr_stat(&lfs, "coffee/tubruk", &info) => 0; + assert(strcmp(info.name, "tubruk") == 0); + assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG)); + lfsr_stat(&lfs, "coffee/vietnamese", &info) => 0; + assert(strcmp(info.name, "vietnamese") == 0); + assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG)); + lfsr_stat(&lfs, "coffee/thai", &info) => 0; + assert(strcmp(info.name, "thai") == 0); + assert(info.type == ((DIR) ? LFS_TYPE_DIR : LFS_TYPE_REG)); + + lfsr_unmount(&lfs) => 0; +''' + +# notsup tests with trailing slashes +[cases.test_paths_notsup_trailing_slashes] +in = 'lfs.c' +code = ''' + lfs_t lfs; + lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0; + lfsr_mount(&lfs, LFS_F_RDWR, CFG) => 0; + + // create paths + lfsr_mkdir(&lfs, "coffee") => 0; + // create paths with unknown file types + const char *path; + lfsr_mdir_t mdir; + lfsr_did_t did; + path = "coffee/drip"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/coldbrew"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/turkish"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/tubruk"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/vietnamese"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/thai"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + + // stat paths + struct lfs_info info; + lfsr_stat(&lfs, "coffee/drip//////", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/coldbrew/////", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/turkish////", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/tubruk///", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/vietnamese//", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/thai/", &info) => LFS_ERR_NOTSUP; + + // file open paths, only works on files! + lfsr_file_t file; + lfsr_file_open(&lfs, &file, "coffee/drip/", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/coldbrew//", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/turkish///", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/tubruk////", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/vietnamese/////", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/thai//////", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + + lfsr_file_open(&lfs, &file, "coffee/drip/", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/coldbrew//", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/turkish///", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/tubruk////", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/vietnamese/////", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/thai//////", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + + lfsr_file_open(&lfs, &file, "coffee/drip/", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/coldbrew//", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/turkish///", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/tubruk////", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/vietnamese/////", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/thai//////", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + + // dir open paths, only works on dirs! + lfsr_dir_t dir; + lfsr_dir_open(&lfs, &dir, "coffee/drip/") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/coldbrew//") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/turkish///") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/tubruk////") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/vietnamese/////") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/thai//////") => LFS_ERR_NOTSUP; + + // rename paths + lfsr_mkdir(&lfs, "espresso") => 0; + // bad source + lfsr_rename(&lfs, + "coffee/drip//////", + "espresso/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew/////", + "espresso/americano") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish////", + "espresso/macchiato") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk///", + "espresso/latte") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese//", + "espresso/cappuccino") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai/", + "espresso/mocha") => LFS_ERR_NOTSUP; + + // bad destination + lfsr_rename(&lfs, + "coffee/drip", + "espresso/espresso/") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew", + "espresso/americano//") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish", + "espresso/macchiato///") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk", + "espresso/latte////") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese", + "espresso/cappuccino/////") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai", + "espresso/mocha//////") => LFS_ERR_NOTSUP; + + // bad source and bad destination + lfsr_rename(&lfs, + "coffee/drip//////", + "espresso/espresso/") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew/////", + "espresso/americano//") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish////", + "espresso/macchiato///") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk///", + "espresso/latte////") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese//", + "espresso/cappuccino/////") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai/", + "espresso/mocha//////") => LFS_ERR_NOTSUP; + + // here's a weird one, what happens if our rename is also a noop? + lfsr_rename(&lfs, + "coffee/drip//////", + "coffee/drip//////") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew/////", + "coffee/coldbrew/////") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish////", + "coffee/turkish////") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk///", + "coffee/tubruk///") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese//", + "coffee/vietnamese//") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai/", + "coffee/thai/") => LFS_ERR_NOTSUP; + + // remove paths + lfsr_remove(&lfs, "coffee/drip/") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/coldbrew//") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/turkish///") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/tubruk////") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/vietnamese/////") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/thai//////") => LFS_ERR_NOTSUP; + + // stat paths + lfsr_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT; + + lfsr_stat(&lfs, "coffee/drip", &info) => 0; + assert(strcmp(info.name, "drip") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/coldbrew", &info) => 0; + assert(strcmp(info.name, "coldbrew") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/turkish", &info) => 0; + assert(strcmp(info.name, "turkish") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/tubruk", &info) => 0; + assert(strcmp(info.name, "tubruk") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/vietnamese", &info) => 0; + assert(strcmp(info.name, "vietnamese") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/thai", &info) => 0; + assert(strcmp(info.name, "thai") == 0); + assert(info.type == 0x13); + + lfsr_unmount(&lfs) => 0; +''' + +# notsup tests with trailing dots +[cases.test_paths_notsup_trailing_dots] +in = 'lfs.c' +code = ''' + lfs_t lfs; + lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0; + lfsr_mount(&lfs, LFS_F_RDWR, CFG) => 0; + + // create paths + lfsr_mkdir(&lfs, "coffee") => 0; + // create paths with unknown file types + const char *path; + lfsr_mdir_t mdir; + lfsr_did_t did; + path = "coffee/drip"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/coldbrew"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/turkish"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/tubruk"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/vietnamese"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/thai"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + + // stat paths + struct lfs_info info; + lfsr_stat(&lfs, "coffee/drip/./././././.", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/coldbrew/././././.", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/turkish/./././.", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/tubruk/././.", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/vietnamese/./.", &info) => LFS_ERR_NOTSUP; + lfsr_stat(&lfs, "coffee/thai/.", &info) => LFS_ERR_NOTSUP; + + // file open paths, only works on files! + lfsr_file_t file; + lfsr_file_open(&lfs, &file, "coffee/drip/.", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/coldbrew/./.", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/turkish/././.", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/tubruk/./././.", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/vietnamese/././././.", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/thai/./././././.", + LFS_O_RDONLY) => LFS_ERR_NOTSUP; + + lfsr_file_open(&lfs, &file, "coffee/drip/.", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/coldbrew/./.", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/turkish/././.", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/tubruk/./././.", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/vietnamese/././././.", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/thai/./././././.", + LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NOTSUP; + + lfsr_file_open(&lfs, &file, "coffee/drip/.", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/coldbrew/./.", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/turkish/././.", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/tubruk/./././.", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/vietnamese/././././.", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + lfsr_file_open(&lfs, &file, "coffee/thai/./././././.", + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => LFS_ERR_NOTSUP; + + // dir open paths, only works on dirs! + lfsr_dir_t dir; + lfsr_dir_open(&lfs, &dir, "coffee/drip/.") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/coldbrew/./.") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/turkish/././.") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/tubruk/./././.") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/vietnamese/././././.") => LFS_ERR_NOTSUP; + lfsr_dir_open(&lfs, &dir, "coffee/thai/./././././.") => LFS_ERR_NOTSUP; + + // rename paths + lfsr_mkdir(&lfs, "espresso") => 0; + // bad source + lfsr_rename(&lfs, + "coffee/drip/./././././.", + "espresso/espresso") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew/././././.", + "espresso/americano") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish/./././.", + "espresso/macchiato") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk/././.", + "espresso/latte") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese/./.", + "espresso/cappuccino") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai/.", + "espresso/mocha") => LFS_ERR_NOTSUP; + + // bad destination + lfsr_rename(&lfs, + "coffee/drip", + "espresso/espresso/.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew", + "espresso/americano/./.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish", + "espresso/macchiato/././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk", + "espresso/latte/./././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese", + "espresso/cappuccino/././././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai", + "espresso/mocha/./././././.") => LFS_ERR_NOTSUP; + + // bad source and bad destination + lfsr_rename(&lfs, + "coffee/drip/./././././.", + "espresso/espresso/.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew/././././.", + "espresso/americano/./.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish/./././.", + "espresso/macchiato/././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk/././.", + "espresso/latte/./././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese/./.", + "espresso/cappuccino/././././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai/.", + "espresso/mocha/./././././.") => LFS_ERR_NOTSUP; + + // here's a weird one, what happens if our rename is also a noop? + lfsr_rename(&lfs, + "coffee/drip/./././././.", + "coffee/drip/./././././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew/././././.", + "coffee/coldbrew/././././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish/./././.", + "coffee/turkish/./././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk/././.", + "coffee/tubruk/././.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese/./.", + "coffee/vietnamese/./.") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai/.", + "coffee/thai/.") => LFS_ERR_NOTSUP; + + // remove paths + lfsr_remove(&lfs, "coffee/drip/.") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/coldbrew/./.") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/turkish/././.") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/tubruk/./././.") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/vietnamese/././././.") => LFS_ERR_NOTSUP; + lfsr_remove(&lfs, "coffee/thai/./././././.") => LFS_ERR_NOTSUP; + + // stat paths + lfsr_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT; + + lfsr_stat(&lfs, "coffee/drip", &info) => 0; + assert(strcmp(info.name, "drip") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/coldbrew", &info) => 0; + assert(strcmp(info.name, "coldbrew") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/turkish", &info) => 0; + assert(strcmp(info.name, "turkish") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/tubruk", &info) => 0; + assert(strcmp(info.name, "tubruk") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/vietnamese", &info) => 0; + assert(strcmp(info.name, "vietnamese") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/thai", &info) => 0; + assert(strcmp(info.name, "thai") == 0); + assert(info.type == 0x13); + + lfsr_unmount(&lfs) => 0; +''' + +# notsup tests with trailing dotdots +[cases.test_paths_notsup_trailing_dotdots] +in = 'lfs.c' +code = ''' + lfs_t lfs; + lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0; + lfsr_mount(&lfs, LFS_F_RDWR, CFG) => 0; + + // create paths + lfsr_mkdir(&lfs, "coffee") => 0; + // create paths with unknown file types + const char *path; + lfsr_mdir_t mdir; + lfsr_did_t did; + path = "coffee/drip"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/coldbrew"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/turkish"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/tubruk"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/vietnamese"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + path = "coffee/thai"; + lfsr_mtree_pathlookup(&lfs, &path, + &mdir, NULL, &did) => LFS_ERR_NOENT; + lfsr_mdir_commit(&lfs, &mdir, LFSR_RATS( + LFSR_RAT_NAME( + LFSR_TAG_NAME + 0x13, +1, + did, path, lfsr_path_namelen(path)))) => 0; + + // stat paths + struct lfs_info info; + lfsr_stat(&lfs, "coffee/drip/../../../../../..", &info) => LFS_ERR_INVAL; + lfsr_stat(&lfs, "coffee/coldbrew/../../../../..", &info) => LFS_ERR_INVAL; + lfsr_stat(&lfs, "coffee/turkish/../../../..", &info) => LFS_ERR_INVAL; + lfsr_stat(&lfs, "coffee/tubruk/../../..", &info) => LFS_ERR_INVAL; + lfsr_stat(&lfs, "coffee/vietnamese/../..", &info) => 0; + assert(strcmp(info.name, "/") == 0); + assert(info.type == LFS_TYPE_DIR); + lfsr_stat(&lfs, "coffee/thai/..", &info) => 0; + assert(strcmp(info.name, "coffee") == 0); + assert(info.type == LFS_TYPE_DIR); + + // file open paths, only works on files! + lfsr_file_t file; + lfsr_file_open(&lfs, &file, "coffee/drip/..", + LFS_O_RDONLY) => LFS_ERR_ISDIR; + lfsr_file_open(&lfs, &file, "coffee/coldbrew/../..", + LFS_O_RDONLY) => LFS_ERR_ISDIR; + lfsr_file_open(&lfs, &file, "coffee/turkish/../../..", + LFS_O_RDONLY) => LFS_ERR_INVAL; + lfsr_file_open(&lfs, &file, "coffee/tubruk/../../../..", + LFS_O_RDONLY) => LFS_ERR_INVAL; + lfsr_file_open(&lfs, &file, "coffee/vietnamese/../../../../..", + LFS_O_RDONLY) => LFS_ERR_INVAL; + lfsr_file_open(&lfs, &file, "coffee/thai/../../../../../..", + LFS_O_RDONLY) => LFS_ERR_INVAL; + + // dir open paths, only works on dirs! + lfsr_dir_t dir; + lfsr_dir_open(&lfs, &dir, "coffee/drip/..") => 0; + lfsr_dir_close(&lfs, &dir) => 0; + lfsr_dir_open(&lfs, &dir, "coffee/coldbrew/../..") => 0; + lfsr_dir_close(&lfs, &dir) => 0; + lfsr_dir_open(&lfs, &dir, "coffee/turkish/../../..") => LFS_ERR_INVAL; + lfsr_dir_open(&lfs, &dir, "coffee/tubruk/../../../..") => LFS_ERR_INVAL; + lfsr_dir_open(&lfs, &dir, "coffee/vietnamese/../../../../..") => LFS_ERR_INVAL; + lfsr_dir_open(&lfs, &dir, "coffee/thai/../../../../../..") => LFS_ERR_INVAL; + + // rename paths + lfsr_mkdir(&lfs, "espresso") => 0; + // bad source + lfsr_rename(&lfs, + "coffee/drip/../../../../../..", + "espresso/espresso") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/coldbrew/../../../../..", + "espresso/americano") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/turkish/../../../..", + "espresso/macchiato") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/tubruk/../../..", + "espresso/latte") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/vietnamese/../..", + "espresso/cappuccino") => LFS_ERR_INVAL; + // this one works + lfsr_rename(&lfs, + "coffee/thai/..", + "espresso/mocha") => 0; + lfsr_rename(&lfs, + "espresso/mocha", + "coffee") => 0; + + // bad destination + lfsr_rename(&lfs, + "coffee/drip", + "espresso/espresso/..") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/coldbrew", + "espresso/americano/../..") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/turkish", + "espresso/macchiato/../../..") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/tubruk", + "espresso/latte/../../../..") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/vietnamese", + "espresso/cappuccino/../../../../..") => LFS_ERR_NOTSUP; + lfsr_rename(&lfs, + "coffee/thai", + "espresso/mocha/../../../../../..") => LFS_ERR_NOTSUP; + + // bad source and bad destination + lfsr_rename(&lfs, + "coffee/drip/../../../../../..", + "espresso/espresso/..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/coldbrew/../../../../..", + "espresso/americano/../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/turkish/../../../..", + "espresso/macchiato/../../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/tubruk/../../..", + "espresso/latte/../../../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/vietnamese/../..", + "espresso/cappuccino/../../../../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/thai/..", + "espresso/mocha/../../../../../..") => LFS_ERR_INVAL; + + // here's a weird one, what happens if our rename is also a noop? + lfsr_rename(&lfs, + "coffee/drip/../../../../../..", + "coffee/drip/../../../../../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/coldbrew/../../../../..", + "coffee/coldbrew/../../../../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/turkish/../../../..", + "coffee/turkish/../../../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/tubruk/../../..", + "coffee/tubruk/../../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/vietnamese/../..", + "coffee/vietnamese/../..") => LFS_ERR_INVAL; + lfsr_rename(&lfs, + "coffee/thai/..", + "coffee/thai/..") => 0; + + // remove paths + lfsr_remove(&lfs, "coffee/drip/..") => LFS_ERR_NOTEMPTY; + lfsr_remove(&lfs, "coffee/coldbrew/../..") => LFS_ERR_INVAL; + lfsr_remove(&lfs, "coffee/turkish/../../..") => LFS_ERR_INVAL; + lfsr_remove(&lfs, "coffee/tubruk/../../../..") => LFS_ERR_INVAL; + lfsr_remove(&lfs, "coffee/vietnamese/../../../../..") => LFS_ERR_INVAL; + lfsr_remove(&lfs, "coffee/thai/../../../../../..") => LFS_ERR_INVAL; + + // stat paths + lfsr_stat(&lfs, "espresso/espresso", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/americano", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/macchiato", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/latte", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/cappuccino", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "espresso/mocha", &info) => LFS_ERR_NOENT; + lfsr_stat(&lfs, "coffee/drip", &info) => 0; + + assert(strcmp(info.name, "drip") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/coldbrew", &info) => 0; + assert(strcmp(info.name, "coldbrew") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/turkish", &info) => 0; + assert(strcmp(info.name, "turkish") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/tubruk", &info) => 0; + assert(strcmp(info.name, "tubruk") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/vietnamese", &info) => 0; + assert(strcmp(info.name, "vietnamese") == 0); + assert(info.type == 0x13); + lfsr_stat(&lfs, "coffee/thai", &info) => 0; + assert(strcmp(info.name, "thai") == 0); + assert(info.type == 0x13); + + lfsr_unmount(&lfs) => 0; +''' + # test an empty path, this should error [cases.test_paths_empty] defines.DIR = [false, true]