test_move.toml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. [[case]] # move file
  2. code = '''
  3. lfs_format(&lfs, &cfg) => 0;
  4. lfs_mount(&lfs, &cfg) => 0;
  5. lfs_mkdir(&lfs, "a") => 0;
  6. lfs_mkdir(&lfs, "b") => 0;
  7. lfs_mkdir(&lfs, "c") => 0;
  8. lfs_mkdir(&lfs, "d") => 0;
  9. lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  10. lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
  11. lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
  12. lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
  13. lfs_file_close(&lfs, &file) => 0;
  14. lfs_unmount(&lfs) => 0;
  15. lfs_mount(&lfs, &cfg) => 0;
  16. lfs_rename(&lfs, "a/hello", "c/hello") => 0;
  17. lfs_unmount(&lfs) => 0;
  18. lfs_mount(&lfs, &cfg) => 0;
  19. lfs_dir_open(&lfs, &dir, "a") => 0;
  20. lfs_dir_read(&lfs, &dir, &info) => 1;
  21. assert(strcmp(info.name, ".") == 0);
  22. assert(info.type == LFS_TYPE_DIR);
  23. lfs_dir_read(&lfs, &dir, &info) => 1;
  24. assert(strcmp(info.name, "..") == 0);
  25. assert(info.type == LFS_TYPE_DIR);
  26. lfs_dir_read(&lfs, &dir, &info) => 0;
  27. lfs_dir_close(&lfs, &dir) => 0;
  28. lfs_dir_open(&lfs, &dir, "c") => 0;
  29. lfs_dir_read(&lfs, &dir, &info) => 1;
  30. assert(strcmp(info.name, ".") == 0);
  31. assert(info.type == LFS_TYPE_DIR);
  32. lfs_dir_read(&lfs, &dir, &info) => 1;
  33. assert(strcmp(info.name, "..") == 0);
  34. assert(info.type == LFS_TYPE_DIR);
  35. lfs_dir_read(&lfs, &dir, &info) => 1;
  36. assert(strcmp(info.name, "hello") == 0);
  37. assert(info.type == LFS_TYPE_REG);
  38. assert(info.size == 5+8+6);
  39. lfs_dir_read(&lfs, &dir, &info) => 0;
  40. lfs_dir_close(&lfs, &dir) => 0;
  41. lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  42. lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  43. lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
  44. lfs_file_read(&lfs, &file, buffer, 5) => 5;
  45. memcmp(buffer, "hola\n", 5) => 0;
  46. lfs_file_read(&lfs, &file, buffer, 8) => 8;
  47. memcmp(buffer, "bonjour\n", 8) => 0;
  48. lfs_file_read(&lfs, &file, buffer, 6) => 6;
  49. memcmp(buffer, "ohayo\n", 6) => 0;
  50. lfs_file_close(&lfs, &file) => 0;
  51. lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  52. lfs_unmount(&lfs) => 0;
  53. '''
  54. [[case]] # move file corrupt source
  55. in = "lfs.c"
  56. code = '''
  57. lfs_format(&lfs, &cfg) => 0;
  58. lfs_mount(&lfs, &cfg) => 0;
  59. lfs_mkdir(&lfs, "a") => 0;
  60. lfs_mkdir(&lfs, "b") => 0;
  61. lfs_mkdir(&lfs, "c") => 0;
  62. lfs_mkdir(&lfs, "d") => 0;
  63. lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  64. lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
  65. lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
  66. lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
  67. lfs_file_close(&lfs, &file) => 0;
  68. lfs_unmount(&lfs) => 0;
  69. lfs_mount(&lfs, &cfg) => 0;
  70. lfs_rename(&lfs, "a/hello", "c/hello") => 0;
  71. lfs_unmount(&lfs) => 0;
  72. // corrupt the source
  73. lfs_mount(&lfs, &cfg) => 0;
  74. lfs_dir_open(&lfs, &dir, "a") => 0;
  75. lfs_block_t block = dir.m.pair[0];
  76. lfs_dir_close(&lfs, &dir) => 0;
  77. lfs_unmount(&lfs) => 0;
  78. uint8_t bbuffer[LFS_BLOCK_SIZE];
  79. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  80. int off = LFS_BLOCK_SIZE-1;
  81. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  82. off -= 1;
  83. }
  84. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  85. cfg.erase(&cfg, block) => 0;
  86. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  87. cfg.sync(&cfg) => 0;
  88. lfs_mount(&lfs, &cfg) => 0;
  89. lfs_dir_open(&lfs, &dir, "a") => 0;
  90. lfs_dir_read(&lfs, &dir, &info) => 1;
  91. assert(strcmp(info.name, ".") == 0);
  92. assert(info.type == LFS_TYPE_DIR);
  93. lfs_dir_read(&lfs, &dir, &info) => 1;
  94. assert(strcmp(info.name, "..") == 0);
  95. assert(info.type == LFS_TYPE_DIR);
  96. lfs_dir_read(&lfs, &dir, &info) => 0;
  97. lfs_dir_close(&lfs, &dir) => 0;
  98. lfs_dir_open(&lfs, &dir, "c") => 0;
  99. lfs_dir_read(&lfs, &dir, &info) => 1;
  100. assert(strcmp(info.name, ".") == 0);
  101. assert(info.type == LFS_TYPE_DIR);
  102. lfs_dir_read(&lfs, &dir, &info) => 1;
  103. assert(strcmp(info.name, "..") == 0);
  104. assert(info.type == LFS_TYPE_DIR);
  105. lfs_dir_read(&lfs, &dir, &info) => 1;
  106. assert(strcmp(info.name, "hello") == 0);
  107. assert(info.type == LFS_TYPE_REG);
  108. assert(info.size == 5+8+6);
  109. lfs_dir_read(&lfs, &dir, &info) => 0;
  110. lfs_dir_close(&lfs, &dir) => 0;
  111. lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  112. lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  113. lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
  114. lfs_file_read(&lfs, &file, buffer, 5) => 5;
  115. memcmp(buffer, "hola\n", 5) => 0;
  116. lfs_file_read(&lfs, &file, buffer, 8) => 8;
  117. memcmp(buffer, "bonjour\n", 8) => 0;
  118. lfs_file_read(&lfs, &file, buffer, 6) => 6;
  119. memcmp(buffer, "ohayo\n", 6) => 0;
  120. lfs_file_close(&lfs, &file) => 0;
  121. lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  122. lfs_unmount(&lfs) => 0;
  123. '''
  124. [[case]] # move file corrupt source and dest
  125. in = "lfs.c"
  126. code = '''
  127. lfs_format(&lfs, &cfg) => 0;
  128. lfs_mount(&lfs, &cfg) => 0;
  129. lfs_mkdir(&lfs, "a") => 0;
  130. lfs_mkdir(&lfs, "b") => 0;
  131. lfs_mkdir(&lfs, "c") => 0;
  132. lfs_mkdir(&lfs, "d") => 0;
  133. lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  134. lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
  135. lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
  136. lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
  137. lfs_file_close(&lfs, &file) => 0;
  138. lfs_unmount(&lfs) => 0;
  139. lfs_mount(&lfs, &cfg) => 0;
  140. lfs_rename(&lfs, "a/hello", "c/hello") => 0;
  141. lfs_unmount(&lfs) => 0;
  142. // corrupt the source
  143. lfs_mount(&lfs, &cfg) => 0;
  144. lfs_dir_open(&lfs, &dir, "a") => 0;
  145. lfs_block_t block = dir.m.pair[0];
  146. lfs_dir_close(&lfs, &dir) => 0;
  147. lfs_unmount(&lfs) => 0;
  148. uint8_t bbuffer[LFS_BLOCK_SIZE];
  149. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  150. int off = LFS_BLOCK_SIZE-1;
  151. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  152. off -= 1;
  153. }
  154. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  155. cfg.erase(&cfg, block) => 0;
  156. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  157. cfg.sync(&cfg) => 0;
  158. // corrupt the destination
  159. lfs_mount(&lfs, &cfg) => 0;
  160. lfs_dir_open(&lfs, &dir, "c") => 0;
  161. block = dir.m.pair[0];
  162. lfs_dir_close(&lfs, &dir) => 0;
  163. lfs_unmount(&lfs) => 0;
  164. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  165. off = LFS_BLOCK_SIZE-1;
  166. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  167. off -= 1;
  168. }
  169. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  170. cfg.erase(&cfg, block) => 0;
  171. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  172. cfg.sync(&cfg) => 0;
  173. lfs_mount(&lfs, &cfg) => 0;
  174. lfs_dir_open(&lfs, &dir, "a") => 0;
  175. lfs_dir_read(&lfs, &dir, &info) => 1;
  176. assert(strcmp(info.name, ".") == 0);
  177. assert(info.type == LFS_TYPE_DIR);
  178. lfs_dir_read(&lfs, &dir, &info) => 1;
  179. assert(strcmp(info.name, "..") == 0);
  180. assert(info.type == LFS_TYPE_DIR);
  181. lfs_dir_read(&lfs, &dir, &info) => 1;
  182. assert(strcmp(info.name, "hello") == 0);
  183. assert(info.type == LFS_TYPE_REG);
  184. assert(info.size == 5+8+6);
  185. lfs_dir_read(&lfs, &dir, &info) => 0;
  186. lfs_dir_close(&lfs, &dir) => 0;
  187. lfs_dir_open(&lfs, &dir, "c") => 0;
  188. lfs_dir_read(&lfs, &dir, &info) => 1;
  189. assert(strcmp(info.name, ".") == 0);
  190. assert(info.type == LFS_TYPE_DIR);
  191. lfs_dir_read(&lfs, &dir, &info) => 1;
  192. assert(strcmp(info.name, "..") == 0);
  193. assert(info.type == LFS_TYPE_DIR);
  194. lfs_dir_read(&lfs, &dir, &info) => 0;
  195. lfs_dir_close(&lfs, &dir) => 0;
  196. lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => 0;
  197. lfs_file_read(&lfs, &file, buffer, 5) => 5;
  198. memcmp(buffer, "hola\n", 5) => 0;
  199. lfs_file_read(&lfs, &file, buffer, 8) => 8;
  200. memcmp(buffer, "bonjour\n", 8) => 0;
  201. lfs_file_read(&lfs, &file, buffer, 6) => 6;
  202. memcmp(buffer, "ohayo\n", 6) => 0;
  203. lfs_file_close(&lfs, &file) => 0;
  204. lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  205. lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  206. lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  207. lfs_unmount(&lfs) => 0;
  208. '''
  209. [[case]] # move file after corrupt
  210. in = "lfs.c"
  211. code = '''
  212. lfs_format(&lfs, &cfg) => 0;
  213. lfs_mount(&lfs, &cfg) => 0;
  214. lfs_mkdir(&lfs, "a") => 0;
  215. lfs_mkdir(&lfs, "b") => 0;
  216. lfs_mkdir(&lfs, "c") => 0;
  217. lfs_mkdir(&lfs, "d") => 0;
  218. lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  219. lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
  220. lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
  221. lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
  222. lfs_file_close(&lfs, &file) => 0;
  223. lfs_unmount(&lfs) => 0;
  224. lfs_mount(&lfs, &cfg) => 0;
  225. lfs_rename(&lfs, "a/hello", "c/hello") => 0;
  226. lfs_unmount(&lfs) => 0;
  227. // corrupt the source
  228. lfs_mount(&lfs, &cfg) => 0;
  229. lfs_dir_open(&lfs, &dir, "a") => 0;
  230. lfs_block_t block = dir.m.pair[0];
  231. lfs_dir_close(&lfs, &dir) => 0;
  232. lfs_unmount(&lfs) => 0;
  233. uint8_t bbuffer[LFS_BLOCK_SIZE];
  234. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  235. int off = LFS_BLOCK_SIZE-1;
  236. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  237. off -= 1;
  238. }
  239. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  240. cfg.erase(&cfg, block) => 0;
  241. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  242. cfg.sync(&cfg) => 0;
  243. // corrupt the destination
  244. lfs_mount(&lfs, &cfg) => 0;
  245. lfs_dir_open(&lfs, &dir, "c") => 0;
  246. block = dir.m.pair[0];
  247. lfs_dir_close(&lfs, &dir) => 0;
  248. lfs_unmount(&lfs) => 0;
  249. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  250. off = LFS_BLOCK_SIZE-1;
  251. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  252. off -= 1;
  253. }
  254. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  255. cfg.erase(&cfg, block) => 0;
  256. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  257. cfg.sync(&cfg) => 0;
  258. // continue move
  259. lfs_mount(&lfs, &cfg) => 0;
  260. lfs_rename(&lfs, "a/hello", "c/hello") => 0;
  261. lfs_unmount(&lfs) => 0;
  262. lfs_mount(&lfs, &cfg) => 0;
  263. lfs_dir_open(&lfs, &dir, "a") => 0;
  264. lfs_dir_read(&lfs, &dir, &info) => 1;
  265. assert(strcmp(info.name, ".") == 0);
  266. assert(info.type == LFS_TYPE_DIR);
  267. lfs_dir_read(&lfs, &dir, &info) => 1;
  268. assert(strcmp(info.name, "..") == 0);
  269. assert(info.type == LFS_TYPE_DIR);
  270. lfs_dir_read(&lfs, &dir, &info) => 0;
  271. lfs_dir_close(&lfs, &dir) => 0;
  272. lfs_dir_open(&lfs, &dir, "c") => 0;
  273. lfs_dir_read(&lfs, &dir, &info) => 1;
  274. assert(strcmp(info.name, ".") == 0);
  275. assert(info.type == LFS_TYPE_DIR);
  276. lfs_dir_read(&lfs, &dir, &info) => 1;
  277. assert(strcmp(info.name, "..") == 0);
  278. assert(info.type == LFS_TYPE_DIR);
  279. lfs_dir_read(&lfs, &dir, &info) => 1;
  280. assert(strcmp(info.name, "hello") == 0);
  281. assert(info.type == LFS_TYPE_REG);
  282. assert(info.size == 5+8+6);
  283. lfs_dir_read(&lfs, &dir, &info) => 0;
  284. lfs_dir_close(&lfs, &dir) => 0;
  285. lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  286. lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  287. lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0;
  288. lfs_file_read(&lfs, &file, buffer, 5) => 5;
  289. memcmp(buffer, "hola\n", 5) => 0;
  290. lfs_file_read(&lfs, &file, buffer, 8) => 8;
  291. memcmp(buffer, "bonjour\n", 8) => 0;
  292. lfs_file_read(&lfs, &file, buffer, 6) => 6;
  293. memcmp(buffer, "ohayo\n", 6) => 0;
  294. lfs_file_close(&lfs, &file) => 0;
  295. lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  296. lfs_unmount(&lfs) => 0;
  297. '''
  298. [[case]] # simple reentrant move file
  299. reentrant = true
  300. code = '''
  301. err = lfs_mount(&lfs, &cfg);
  302. if (err) {
  303. lfs_format(&lfs, &cfg) => 0;
  304. lfs_mount(&lfs, &cfg) => 0;
  305. }
  306. err = lfs_mkdir(&lfs, "a");
  307. assert(!err || err == LFS_ERR_EXIST);
  308. err = lfs_mkdir(&lfs, "b");
  309. assert(!err || err == LFS_ERR_EXIST);
  310. err = lfs_mkdir(&lfs, "c");
  311. assert(!err || err == LFS_ERR_EXIST);
  312. err = lfs_mkdir(&lfs, "d");
  313. assert(!err || err == LFS_ERR_EXIST);
  314. lfs_unmount(&lfs) => 0;
  315. while (true) {
  316. lfs_mount(&lfs, &cfg) => 0;
  317. // there should never exist _2_ hello files
  318. int count = 0;
  319. if (lfs_stat(&lfs, "a/hello", &info) == 0) {
  320. assert(strcmp(info.name, "hello") == 0);
  321. assert(info.type == LFS_TYPE_REG);
  322. assert(info.size == 5+8+6 || info.size == 0);
  323. count += 1;
  324. }
  325. if (lfs_stat(&lfs, "b/hello", &info) == 0) {
  326. assert(strcmp(info.name, "hello") == 0);
  327. assert(info.type == LFS_TYPE_REG);
  328. assert(info.size == 5+8+6);
  329. count += 1;
  330. }
  331. if (lfs_stat(&lfs, "c/hello", &info) == 0) {
  332. assert(strcmp(info.name, "hello") == 0);
  333. assert(info.type == LFS_TYPE_REG);
  334. assert(info.size == 5+8+6);
  335. count += 1;
  336. }
  337. if (lfs_stat(&lfs, "d/hello", &info) == 0) {
  338. assert(strcmp(info.name, "hello") == 0);
  339. assert(info.type == LFS_TYPE_REG);
  340. assert(info.size == 5+8+6);
  341. count += 1;
  342. }
  343. assert(count <= 1);
  344. lfs_unmount(&lfs) => 0;
  345. lfs_mount(&lfs, &cfg) => 0;
  346. if (lfs_stat(&lfs, "a/hello", &info) == 0 && info.size > 0) {
  347. lfs_rename(&lfs, "a/hello", "b/hello") => 0;
  348. } else if (lfs_stat(&lfs, "b/hello", &info) == 0) {
  349. lfs_rename(&lfs, "b/hello", "c/hello") => 0;
  350. } else if (lfs_stat(&lfs, "c/hello", &info) == 0) {
  351. lfs_rename(&lfs, "c/hello", "d/hello") => 0;
  352. } else if (lfs_stat(&lfs, "d/hello", &info) == 0) {
  353. // success
  354. break;
  355. } else {
  356. // create file
  357. lfs_file_open(&lfs, &file, "a/hello",
  358. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  359. lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
  360. lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
  361. lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
  362. lfs_file_close(&lfs, &file) => 0;
  363. }
  364. lfs_unmount(&lfs) => 0;
  365. }
  366. lfs_mount(&lfs, &cfg) => 0;
  367. lfs_dir_open(&lfs, &dir, "a") => 0;
  368. lfs_dir_read(&lfs, &dir, &info) => 1;
  369. assert(strcmp(info.name, ".") == 0);
  370. assert(info.type == LFS_TYPE_DIR);
  371. lfs_dir_read(&lfs, &dir, &info) => 1;
  372. assert(strcmp(info.name, "..") == 0);
  373. assert(info.type == LFS_TYPE_DIR);
  374. lfs_dir_read(&lfs, &dir, &info) => 0;
  375. lfs_dir_close(&lfs, &dir) => 0;
  376. lfs_dir_open(&lfs, &dir, "d") => 0;
  377. lfs_dir_read(&lfs, &dir, &info) => 1;
  378. assert(strcmp(info.name, ".") == 0);
  379. assert(info.type == LFS_TYPE_DIR);
  380. lfs_dir_read(&lfs, &dir, &info) => 1;
  381. assert(strcmp(info.name, "..") == 0);
  382. assert(info.type == LFS_TYPE_DIR);
  383. lfs_dir_read(&lfs, &dir, &info) => 1;
  384. assert(strcmp(info.name, "hello") == 0);
  385. assert(info.type == LFS_TYPE_REG);
  386. assert(info.size == 5+8+6);
  387. lfs_dir_read(&lfs, &dir, &info) => 0;
  388. lfs_dir_close(&lfs, &dir) => 0;
  389. lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  390. lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  391. lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  392. lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
  393. lfs_file_read(&lfs, &file, buffer, 5) => 5;
  394. memcmp(buffer, "hola\n", 5) => 0;
  395. lfs_file_read(&lfs, &file, buffer, 8) => 8;
  396. memcmp(buffer, "bonjour\n", 8) => 0;
  397. lfs_file_read(&lfs, &file, buffer, 6) => 6;
  398. memcmp(buffer, "ohayo\n", 6) => 0;
  399. lfs_file_close(&lfs, &file) => 0;
  400. lfs_unmount(&lfs) => 0;
  401. '''
  402. [[case]] # move dir
  403. code = '''
  404. lfs_format(&lfs, &cfg) => 0;
  405. lfs_mount(&lfs, &cfg) => 0;
  406. lfs_mkdir(&lfs, "a") => 0;
  407. lfs_mkdir(&lfs, "b") => 0;
  408. lfs_mkdir(&lfs, "c") => 0;
  409. lfs_mkdir(&lfs, "d") => 0;
  410. lfs_mkdir(&lfs, "a/hi") => 0;
  411. lfs_mkdir(&lfs, "a/hi/hola") => 0;
  412. lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
  413. lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
  414. lfs_unmount(&lfs) => 0;
  415. lfs_mount(&lfs, &cfg) => 0;
  416. lfs_rename(&lfs, "a/hi", "c/hi") => 0;
  417. lfs_unmount(&lfs) => 0;
  418. lfs_mount(&lfs, &cfg) => 0;
  419. lfs_dir_open(&lfs, &dir, "a") => 0;
  420. lfs_dir_read(&lfs, &dir, &info) => 1;
  421. assert(strcmp(info.name, ".") == 0);
  422. assert(info.type == LFS_TYPE_DIR);
  423. lfs_dir_read(&lfs, &dir, &info) => 1;
  424. assert(strcmp(info.name, "..") == 0);
  425. assert(info.type == LFS_TYPE_DIR);
  426. lfs_dir_read(&lfs, &dir, &info) => 0;
  427. lfs_dir_close(&lfs, &dir) => 0;
  428. lfs_dir_open(&lfs, &dir, "c") => 0;
  429. lfs_dir_read(&lfs, &dir, &info) => 1;
  430. assert(strcmp(info.name, ".") == 0);
  431. assert(info.type == LFS_TYPE_DIR);
  432. lfs_dir_read(&lfs, &dir, &info) => 1;
  433. assert(strcmp(info.name, "..") == 0);
  434. assert(info.type == LFS_TYPE_DIR);
  435. lfs_dir_read(&lfs, &dir, &info) => 1;
  436. assert(strcmp(info.name, "hi") == 0);
  437. assert(info.type == LFS_TYPE_DIR);
  438. lfs_dir_read(&lfs, &dir, &info) => 0;
  439. lfs_dir_close(&lfs, &dir) => 0;
  440. lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
  441. lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
  442. lfs_dir_open(&lfs, &dir, "c/hi") => 0;
  443. lfs_dir_read(&lfs, &dir, &info) => 1;
  444. assert(strcmp(info.name, ".") == 0);
  445. assert(info.type == LFS_TYPE_DIR);
  446. lfs_dir_read(&lfs, &dir, &info) => 1;
  447. assert(strcmp(info.name, "..") == 0);
  448. assert(info.type == LFS_TYPE_DIR);
  449. lfs_dir_read(&lfs, &dir, &info) => 1;
  450. assert(strcmp(info.name, "bonjour") == 0);
  451. assert(info.type == LFS_TYPE_DIR);
  452. lfs_dir_read(&lfs, &dir, &info) => 1;
  453. assert(strcmp(info.name, "hola") == 0);
  454. assert(info.type == LFS_TYPE_DIR);
  455. lfs_dir_read(&lfs, &dir, &info) => 1;
  456. assert(strcmp(info.name, "ohayo") == 0);
  457. assert(info.type == LFS_TYPE_DIR);
  458. lfs_dir_read(&lfs, &dir, &info) => 0;
  459. lfs_dir_close(&lfs, &dir) => 0;
  460. lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
  461. lfs_unmount(&lfs) => 0;
  462. '''
  463. [[case]] # move dir corrupt source
  464. in = "lfs.c"
  465. code = '''
  466. lfs_format(&lfs, &cfg) => 0;
  467. lfs_mount(&lfs, &cfg) => 0;
  468. lfs_mkdir(&lfs, "a") => 0;
  469. lfs_mkdir(&lfs, "b") => 0;
  470. lfs_mkdir(&lfs, "c") => 0;
  471. lfs_mkdir(&lfs, "d") => 0;
  472. lfs_mkdir(&lfs, "a/hi") => 0;
  473. lfs_mkdir(&lfs, "a/hi/hola") => 0;
  474. lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
  475. lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
  476. lfs_unmount(&lfs) => 0;
  477. lfs_mount(&lfs, &cfg) => 0;
  478. lfs_rename(&lfs, "a/hi", "c/hi") => 0;
  479. lfs_unmount(&lfs) => 0;
  480. // corrupt the source
  481. lfs_mount(&lfs, &cfg) => 0;
  482. lfs_dir_open(&lfs, &dir, "a") => 0;
  483. lfs_block_t block = dir.m.pair[0];
  484. lfs_dir_close(&lfs, &dir) => 0;
  485. lfs_unmount(&lfs) => 0;
  486. uint8_t bbuffer[LFS_BLOCK_SIZE];
  487. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  488. int off = LFS_BLOCK_SIZE-1;
  489. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  490. off -= 1;
  491. }
  492. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  493. cfg.erase(&cfg, block) => 0;
  494. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  495. cfg.sync(&cfg) => 0;
  496. lfs_mount(&lfs, &cfg) => 0;
  497. lfs_dir_open(&lfs, &dir, "a") => 0;
  498. lfs_dir_read(&lfs, &dir, &info) => 1;
  499. assert(strcmp(info.name, ".") == 0);
  500. assert(info.type == LFS_TYPE_DIR);
  501. lfs_dir_read(&lfs, &dir, &info) => 1;
  502. assert(strcmp(info.name, "..") == 0);
  503. assert(info.type == LFS_TYPE_DIR);
  504. lfs_dir_read(&lfs, &dir, &info) => 0;
  505. lfs_dir_close(&lfs, &dir) => 0;
  506. lfs_dir_open(&lfs, &dir, "c") => 0;
  507. lfs_dir_read(&lfs, &dir, &info) => 1;
  508. assert(strcmp(info.name, ".") == 0);
  509. assert(info.type == LFS_TYPE_DIR);
  510. lfs_dir_read(&lfs, &dir, &info) => 1;
  511. assert(strcmp(info.name, "..") == 0);
  512. assert(info.type == LFS_TYPE_DIR);
  513. lfs_dir_read(&lfs, &dir, &info) => 1;
  514. assert(strcmp(info.name, "hi") == 0);
  515. assert(info.type == LFS_TYPE_DIR);
  516. lfs_dir_read(&lfs, &dir, &info) => 0;
  517. lfs_dir_close(&lfs, &dir) => 0;
  518. lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
  519. lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
  520. lfs_dir_open(&lfs, &dir, "c/hi") => 0;
  521. lfs_dir_read(&lfs, &dir, &info) => 1;
  522. assert(strcmp(info.name, ".") == 0);
  523. assert(info.type == LFS_TYPE_DIR);
  524. lfs_dir_read(&lfs, &dir, &info) => 1;
  525. assert(strcmp(info.name, "..") == 0);
  526. assert(info.type == LFS_TYPE_DIR);
  527. lfs_dir_read(&lfs, &dir, &info) => 1;
  528. assert(strcmp(info.name, "bonjour") == 0);
  529. assert(info.type == LFS_TYPE_DIR);
  530. lfs_dir_read(&lfs, &dir, &info) => 1;
  531. assert(strcmp(info.name, "hola") == 0);
  532. assert(info.type == LFS_TYPE_DIR);
  533. lfs_dir_read(&lfs, &dir, &info) => 1;
  534. assert(strcmp(info.name, "ohayo") == 0);
  535. assert(info.type == LFS_TYPE_DIR);
  536. lfs_dir_read(&lfs, &dir, &info) => 0;
  537. lfs_dir_close(&lfs, &dir) => 0;
  538. lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
  539. lfs_unmount(&lfs) => 0;
  540. '''
  541. [[case]] # move dir corrupt source and dest
  542. in = "lfs.c"
  543. code = '''
  544. lfs_format(&lfs, &cfg) => 0;
  545. lfs_mount(&lfs, &cfg) => 0;
  546. lfs_mkdir(&lfs, "a") => 0;
  547. lfs_mkdir(&lfs, "b") => 0;
  548. lfs_mkdir(&lfs, "c") => 0;
  549. lfs_mkdir(&lfs, "d") => 0;
  550. lfs_mkdir(&lfs, "a/hi") => 0;
  551. lfs_mkdir(&lfs, "a/hi/hola") => 0;
  552. lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
  553. lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
  554. lfs_unmount(&lfs) => 0;
  555. lfs_mount(&lfs, &cfg) => 0;
  556. lfs_rename(&lfs, "a/hi", "c/hi") => 0;
  557. lfs_unmount(&lfs) => 0;
  558. // corrupt the source
  559. lfs_mount(&lfs, &cfg) => 0;
  560. lfs_dir_open(&lfs, &dir, "a") => 0;
  561. lfs_block_t block = dir.m.pair[0];
  562. lfs_dir_close(&lfs, &dir) => 0;
  563. lfs_unmount(&lfs) => 0;
  564. uint8_t bbuffer[LFS_BLOCK_SIZE];
  565. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  566. int off = LFS_BLOCK_SIZE-1;
  567. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  568. off -= 1;
  569. }
  570. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  571. cfg.erase(&cfg, block) => 0;
  572. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  573. cfg.sync(&cfg) => 0;
  574. // corrupt the destination
  575. lfs_mount(&lfs, &cfg) => 0;
  576. lfs_dir_open(&lfs, &dir, "c") => 0;
  577. block = dir.m.pair[0];
  578. lfs_dir_close(&lfs, &dir) => 0;
  579. lfs_unmount(&lfs) => 0;
  580. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  581. off = LFS_BLOCK_SIZE-1;
  582. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  583. off -= 1;
  584. }
  585. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  586. cfg.erase(&cfg, block) => 0;
  587. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  588. cfg.sync(&cfg) => 0;
  589. lfs_mount(&lfs, &cfg) => 0;
  590. lfs_dir_open(&lfs, &dir, "a") => 0;
  591. lfs_dir_read(&lfs, &dir, &info) => 1;
  592. assert(strcmp(info.name, ".") == 0);
  593. assert(info.type == LFS_TYPE_DIR);
  594. lfs_dir_read(&lfs, &dir, &info) => 1;
  595. assert(strcmp(info.name, "..") == 0);
  596. assert(info.type == LFS_TYPE_DIR);
  597. lfs_dir_read(&lfs, &dir, &info) => 1;
  598. assert(strcmp(info.name, "hi") == 0);
  599. assert(info.type == LFS_TYPE_DIR);
  600. lfs_dir_read(&lfs, &dir, &info) => 0;
  601. lfs_dir_close(&lfs, &dir) => 0;
  602. lfs_dir_open(&lfs, &dir, "c") => 0;
  603. lfs_dir_read(&lfs, &dir, &info) => 1;
  604. assert(strcmp(info.name, ".") == 0);
  605. assert(info.type == LFS_TYPE_DIR);
  606. lfs_dir_read(&lfs, &dir, &info) => 1;
  607. assert(strcmp(info.name, "..") == 0);
  608. assert(info.type == LFS_TYPE_DIR);
  609. lfs_dir_read(&lfs, &dir, &info) => 0;
  610. lfs_dir_close(&lfs, &dir) => 0;
  611. lfs_dir_open(&lfs, &dir, "a/hi") => 0;
  612. lfs_dir_read(&lfs, &dir, &info) => 1;
  613. assert(strcmp(info.name, ".") == 0);
  614. assert(info.type == LFS_TYPE_DIR);
  615. lfs_dir_read(&lfs, &dir, &info) => 1;
  616. assert(strcmp(info.name, "..") == 0);
  617. assert(info.type == LFS_TYPE_DIR);
  618. lfs_dir_read(&lfs, &dir, &info) => 1;
  619. assert(strcmp(info.name, "bonjour") == 0);
  620. assert(info.type == LFS_TYPE_DIR);
  621. lfs_dir_read(&lfs, &dir, &info) => 1;
  622. assert(strcmp(info.name, "hola") == 0);
  623. assert(info.type == LFS_TYPE_DIR);
  624. lfs_dir_read(&lfs, &dir, &info) => 1;
  625. assert(strcmp(info.name, "ohayo") == 0);
  626. assert(info.type == LFS_TYPE_DIR);
  627. lfs_dir_read(&lfs, &dir, &info) => 0;
  628. lfs_dir_close(&lfs, &dir) => 0;
  629. lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
  630. lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT;
  631. lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
  632. lfs_unmount(&lfs) => 0;
  633. '''
  634. [[case]] # move dir after corrupt
  635. in = "lfs.c"
  636. code = '''
  637. lfs_format(&lfs, &cfg) => 0;
  638. lfs_mount(&lfs, &cfg) => 0;
  639. lfs_mkdir(&lfs, "a") => 0;
  640. lfs_mkdir(&lfs, "b") => 0;
  641. lfs_mkdir(&lfs, "c") => 0;
  642. lfs_mkdir(&lfs, "d") => 0;
  643. lfs_mkdir(&lfs, "a/hi") => 0;
  644. lfs_mkdir(&lfs, "a/hi/hola") => 0;
  645. lfs_mkdir(&lfs, "a/hi/bonjour") => 0;
  646. lfs_mkdir(&lfs, "a/hi/ohayo") => 0;
  647. lfs_unmount(&lfs) => 0;
  648. lfs_mount(&lfs, &cfg) => 0;
  649. lfs_rename(&lfs, "a/hi", "c/hi") => 0;
  650. lfs_unmount(&lfs) => 0;
  651. // corrupt the source
  652. lfs_mount(&lfs, &cfg) => 0;
  653. lfs_dir_open(&lfs, &dir, "a") => 0;
  654. lfs_block_t block = dir.m.pair[0];
  655. lfs_dir_close(&lfs, &dir) => 0;
  656. lfs_unmount(&lfs) => 0;
  657. uint8_t bbuffer[LFS_BLOCK_SIZE];
  658. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  659. int off = LFS_BLOCK_SIZE-1;
  660. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  661. off -= 1;
  662. }
  663. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  664. cfg.erase(&cfg, block) => 0;
  665. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  666. cfg.sync(&cfg) => 0;
  667. // corrupt the destination
  668. lfs_mount(&lfs, &cfg) => 0;
  669. lfs_dir_open(&lfs, &dir, "c") => 0;
  670. block = dir.m.pair[0];
  671. lfs_dir_close(&lfs, &dir) => 0;
  672. lfs_unmount(&lfs) => 0;
  673. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  674. off = LFS_BLOCK_SIZE-1;
  675. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  676. off -= 1;
  677. }
  678. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  679. cfg.erase(&cfg, block) => 0;
  680. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  681. cfg.sync(&cfg) => 0;
  682. // continue move
  683. lfs_mount(&lfs, &cfg) => 0;
  684. lfs_rename(&lfs, "a/hi", "c/hi") => 0;
  685. lfs_unmount(&lfs) => 0;
  686. lfs_mount(&lfs, &cfg) => 0;
  687. lfs_dir_open(&lfs, &dir, "a") => 0;
  688. lfs_dir_read(&lfs, &dir, &info) => 1;
  689. assert(strcmp(info.name, ".") == 0);
  690. assert(info.type == LFS_TYPE_DIR);
  691. lfs_dir_read(&lfs, &dir, &info) => 1;
  692. assert(strcmp(info.name, "..") == 0);
  693. assert(info.type == LFS_TYPE_DIR);
  694. lfs_dir_read(&lfs, &dir, &info) => 0;
  695. lfs_dir_close(&lfs, &dir) => 0;
  696. lfs_dir_open(&lfs, &dir, "c") => 0;
  697. lfs_dir_read(&lfs, &dir, &info) => 1;
  698. assert(strcmp(info.name, ".") == 0);
  699. assert(info.type == LFS_TYPE_DIR);
  700. lfs_dir_read(&lfs, &dir, &info) => 1;
  701. assert(strcmp(info.name, "..") == 0);
  702. assert(info.type == LFS_TYPE_DIR);
  703. lfs_dir_read(&lfs, &dir, &info) => 1;
  704. assert(strcmp(info.name, "hi") == 0);
  705. assert(info.type == LFS_TYPE_DIR);
  706. lfs_dir_read(&lfs, &dir, &info) => 0;
  707. lfs_dir_close(&lfs, &dir) => 0;
  708. lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
  709. lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
  710. lfs_dir_open(&lfs, &dir, "c/hi") => 0;
  711. lfs_dir_read(&lfs, &dir, &info) => 1;
  712. assert(strcmp(info.name, ".") == 0);
  713. assert(info.type == LFS_TYPE_DIR);
  714. lfs_dir_read(&lfs, &dir, &info) => 1;
  715. assert(strcmp(info.name, "..") == 0);
  716. assert(info.type == LFS_TYPE_DIR);
  717. lfs_dir_read(&lfs, &dir, &info) => 1;
  718. assert(strcmp(info.name, "bonjour") == 0);
  719. assert(info.type == LFS_TYPE_DIR);
  720. lfs_dir_read(&lfs, &dir, &info) => 1;
  721. assert(strcmp(info.name, "hola") == 0);
  722. assert(info.type == LFS_TYPE_DIR);
  723. lfs_dir_read(&lfs, &dir, &info) => 1;
  724. assert(strcmp(info.name, "ohayo") == 0);
  725. assert(info.type == LFS_TYPE_DIR);
  726. lfs_dir_read(&lfs, &dir, &info) => 0;
  727. lfs_dir_close(&lfs, &dir) => 0;
  728. lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT;
  729. lfs_unmount(&lfs) => 0;
  730. '''
  731. [[case]] # simple reentrant move dir
  732. reentrant = true
  733. code = '''
  734. err = lfs_mount(&lfs, &cfg);
  735. if (err) {
  736. lfs_format(&lfs, &cfg) => 0;
  737. lfs_mount(&lfs, &cfg) => 0;
  738. }
  739. err = lfs_mkdir(&lfs, "a");
  740. assert(!err || err == LFS_ERR_EXIST);
  741. err = lfs_mkdir(&lfs, "b");
  742. assert(!err || err == LFS_ERR_EXIST);
  743. err = lfs_mkdir(&lfs, "c");
  744. assert(!err || err == LFS_ERR_EXIST);
  745. err = lfs_mkdir(&lfs, "d");
  746. assert(!err || err == LFS_ERR_EXIST);
  747. lfs_unmount(&lfs) => 0;
  748. while (true) {
  749. lfs_mount(&lfs, &cfg) => 0;
  750. // there should never exist _2_ hi directories
  751. int count = 0;
  752. if (lfs_stat(&lfs, "a/hi", &info) == 0) {
  753. assert(strcmp(info.name, "hi") == 0);
  754. assert(info.type == LFS_TYPE_DIR);
  755. count += 1;
  756. }
  757. if (lfs_stat(&lfs, "b/hi", &info) == 0) {
  758. assert(strcmp(info.name, "hi") == 0);
  759. assert(info.type == LFS_TYPE_DIR);
  760. count += 1;
  761. }
  762. if (lfs_stat(&lfs, "c/hi", &info) == 0) {
  763. assert(strcmp(info.name, "hi") == 0);
  764. assert(info.type == LFS_TYPE_DIR);
  765. count += 1;
  766. }
  767. if (lfs_stat(&lfs, "d/hi", &info) == 0) {
  768. assert(strcmp(info.name, "hi") == 0);
  769. assert(info.type == LFS_TYPE_DIR);
  770. count += 1;
  771. }
  772. assert(count <= 1);
  773. lfs_unmount(&lfs) => 0;
  774. lfs_mount(&lfs, &cfg) => 0;
  775. if (lfs_stat(&lfs, "a/hi", &info) == 0) {
  776. lfs_rename(&lfs, "a/hi", "b/hi") => 0;
  777. } else if (lfs_stat(&lfs, "b/hi", &info) == 0) {
  778. lfs_rename(&lfs, "b/hi", "c/hi") => 0;
  779. } else if (lfs_stat(&lfs, "c/hi", &info) == 0) {
  780. lfs_rename(&lfs, "c/hi", "d/hi") => 0;
  781. } else if (lfs_stat(&lfs, "d/hi", &info) == 0) {
  782. break; // success
  783. } else {
  784. // create dir and rename for atomicity
  785. err = lfs_mkdir(&lfs, "temp");
  786. assert(!err || err == LFS_ERR_EXIST);
  787. err = lfs_mkdir(&lfs, "temp/hola");
  788. assert(!err || err == LFS_ERR_EXIST);
  789. err = lfs_mkdir(&lfs, "temp/bonjour");
  790. assert(!err || err == LFS_ERR_EXIST);
  791. err = lfs_mkdir(&lfs, "temp/ohayo");
  792. assert(!err || err == LFS_ERR_EXIST);
  793. lfs_rename(&lfs, "temp", "a/hi") => 0;
  794. }
  795. lfs_unmount(&lfs) => 0;
  796. }
  797. lfs_mount(&lfs, &cfg) => 0;
  798. lfs_dir_open(&lfs, &dir, "a") => 0;
  799. lfs_dir_read(&lfs, &dir, &info) => 1;
  800. assert(strcmp(info.name, ".") == 0);
  801. assert(info.type == LFS_TYPE_DIR);
  802. lfs_dir_read(&lfs, &dir, &info) => 1;
  803. assert(strcmp(info.name, "..") == 0);
  804. assert(info.type == LFS_TYPE_DIR);
  805. lfs_dir_read(&lfs, &dir, &info) => 0;
  806. lfs_dir_close(&lfs, &dir) => 0;
  807. lfs_dir_open(&lfs, &dir, "d") => 0;
  808. lfs_dir_read(&lfs, &dir, &info) => 1;
  809. assert(strcmp(info.name, ".") == 0);
  810. assert(info.type == LFS_TYPE_DIR);
  811. lfs_dir_read(&lfs, &dir, &info) => 1;
  812. assert(strcmp(info.name, "..") == 0);
  813. assert(info.type == LFS_TYPE_DIR);
  814. lfs_dir_read(&lfs, &dir, &info) => 1;
  815. assert(strcmp(info.name, "hi") == 0);
  816. assert(info.type == LFS_TYPE_DIR);
  817. lfs_dir_read(&lfs, &dir, &info) => 0;
  818. lfs_dir_close(&lfs, &dir) => 0;
  819. lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT;
  820. lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT;
  821. lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT;
  822. lfs_dir_open(&lfs, &dir, "d/hi") => 0;
  823. lfs_dir_read(&lfs, &dir, &info) => 1;
  824. assert(strcmp(info.name, ".") == 0);
  825. assert(info.type == LFS_TYPE_DIR);
  826. lfs_dir_read(&lfs, &dir, &info) => 1;
  827. assert(strcmp(info.name, "..") == 0);
  828. assert(info.type == LFS_TYPE_DIR);
  829. lfs_dir_read(&lfs, &dir, &info) => 1;
  830. assert(strcmp(info.name, "bonjour") == 0);
  831. assert(info.type == LFS_TYPE_DIR);
  832. lfs_dir_read(&lfs, &dir, &info) => 1;
  833. assert(strcmp(info.name, "hola") == 0);
  834. assert(info.type == LFS_TYPE_DIR);
  835. lfs_dir_read(&lfs, &dir, &info) => 1;
  836. assert(strcmp(info.name, "ohayo") == 0);
  837. assert(info.type == LFS_TYPE_DIR);
  838. lfs_dir_read(&lfs, &dir, &info) => 0;
  839. lfs_dir_close(&lfs, &dir) => 0;
  840. lfs_unmount(&lfs) => 0;
  841. '''
  842. [[case]] # move state stealing
  843. code = '''
  844. lfs_format(&lfs, &cfg) => 0;
  845. lfs_mount(&lfs, &cfg) => 0;
  846. lfs_mkdir(&lfs, "a") => 0;
  847. lfs_mkdir(&lfs, "b") => 0;
  848. lfs_mkdir(&lfs, "c") => 0;
  849. lfs_mkdir(&lfs, "d") => 0;
  850. lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  851. lfs_file_write(&lfs, &file, "hola\n", 5) => 5;
  852. lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8;
  853. lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6;
  854. lfs_file_close(&lfs, &file) => 0;
  855. lfs_unmount(&lfs) => 0;
  856. lfs_mount(&lfs, &cfg) => 0;
  857. lfs_rename(&lfs, "a/hello", "b/hello") => 0;
  858. lfs_unmount(&lfs) => 0;
  859. lfs_mount(&lfs, &cfg) => 0;
  860. lfs_rename(&lfs, "b/hello", "c/hello") => 0;
  861. lfs_unmount(&lfs) => 0;
  862. lfs_mount(&lfs, &cfg) => 0;
  863. lfs_rename(&lfs, "c/hello", "d/hello") => 0;
  864. lfs_unmount(&lfs) => 0;
  865. lfs_mount(&lfs, &cfg) => 0;
  866. lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  867. lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  868. lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  869. lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
  870. lfs_file_read(&lfs, &file, buffer, 5) => 5;
  871. memcmp(buffer, "hola\n", 5) => 0;
  872. lfs_file_read(&lfs, &file, buffer, 8) => 8;
  873. memcmp(buffer, "bonjour\n", 8) => 0;
  874. lfs_file_read(&lfs, &file, buffer, 6) => 6;
  875. memcmp(buffer, "ohayo\n", 6) => 0;
  876. lfs_file_close(&lfs, &file) => 0;
  877. lfs_unmount(&lfs) => 0;
  878. lfs_mount(&lfs, &cfg) => 0;
  879. lfs_remove(&lfs, "b") => 0;
  880. lfs_remove(&lfs, "c") => 0;
  881. lfs_unmount(&lfs) => 0;
  882. lfs_mount(&lfs, &cfg) => 0;
  883. lfs_stat(&lfs, "a", &info) => 0;
  884. lfs_stat(&lfs, "b", &info) => LFS_ERR_NOENT;
  885. lfs_stat(&lfs, "c", &info) => LFS_ERR_NOENT;
  886. lfs_stat(&lfs, "d", &info) => 0;
  887. lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  888. lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  889. lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT;
  890. lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0;
  891. lfs_file_read(&lfs, &file, buffer, 5) => 5;
  892. memcmp(buffer, "hola\n", 5) => 0;
  893. lfs_file_read(&lfs, &file, buffer, 8) => 8;
  894. memcmp(buffer, "bonjour\n", 8) => 0;
  895. lfs_file_read(&lfs, &file, buffer, 6) => 6;
  896. memcmp(buffer, "ohayo\n", 6) => 0;
  897. lfs_file_close(&lfs, &file) => 0;
  898. lfs_unmount(&lfs) => 0;
  899. '''