test_alloc.toml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. # allocator tests
  2. # note for these to work there are many constraints on the device geometry
  3. [[case]] # parallel allocation test
  4. define.FILES = 3
  5. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-4)) / FILES)'
  6. code = '''
  7. const char *names[FILES] = {"bacon", "eggs", "pancakes"};
  8. lfs_file_t files[FILES];
  9. lfs_format(&lfs, &cfg) => 0;
  10. lfs_mount(&lfs, &cfg) => 0;
  11. lfs_mkdir(&lfs, "breakfast") => 0;
  12. lfs_unmount(&lfs) => 0;
  13. lfs_mount(&lfs, &cfg) => 0;
  14. for (int n = 0; n < FILES; n++) {
  15. sprintf(path, "breakfast/%s", names[n]);
  16. lfs_file_open(&lfs, &files[n], path,
  17. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
  18. }
  19. for (int n = 0; n < FILES; n++) {
  20. size = strlen(names[n]);
  21. for (lfs_size_t i = 0; i < SIZE; i += size) {
  22. lfs_file_write(&lfs, &files[n], names[n], size) => size;
  23. }
  24. }
  25. for (int n = 0; n < FILES; n++) {
  26. lfs_file_close(&lfs, &files[n]) => 0;
  27. }
  28. lfs_unmount(&lfs) => 0;
  29. lfs_mount(&lfs, &cfg) => 0;
  30. for (int n = 0; n < FILES; n++) {
  31. sprintf(path, "breakfast/%s", names[n]);
  32. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  33. size = strlen(names[n]);
  34. for (lfs_size_t i = 0; i < SIZE; i += size) {
  35. lfs_file_read(&lfs, &file, buffer, size) => size;
  36. assert(memcmp(buffer, names[n], size) == 0);
  37. }
  38. lfs_file_close(&lfs, &file) => 0;
  39. }
  40. lfs_unmount(&lfs) => 0;
  41. '''
  42. [[case]] # serial allocation test
  43. define.FILES = 3
  44. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-4)) / FILES)'
  45. code = '''
  46. const char *names[FILES] = {"bacon", "eggs", "pancakes"};
  47. lfs_format(&lfs, &cfg) => 0;
  48. lfs_mount(&lfs, &cfg) => 0;
  49. lfs_mkdir(&lfs, "breakfast") => 0;
  50. lfs_unmount(&lfs) => 0;
  51. for (int n = 0; n < FILES; n++) {
  52. lfs_mount(&lfs, &cfg) => 0;
  53. sprintf(path, "breakfast/%s", names[n]);
  54. lfs_file_open(&lfs, &file, path,
  55. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
  56. size = strlen(names[n]);
  57. memcpy(buffer, names[n], size);
  58. for (int i = 0; i < SIZE; i += size) {
  59. lfs_file_write(&lfs, &file, buffer, size) => size;
  60. }
  61. lfs_file_close(&lfs, &file) => 0;
  62. lfs_unmount(&lfs) => 0;
  63. }
  64. lfs_mount(&lfs, &cfg) => 0;
  65. for (int n = 0; n < FILES; n++) {
  66. sprintf(path, "breakfast/%s", names[n]);
  67. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  68. size = strlen(names[n]);
  69. for (int i = 0; i < SIZE; i += size) {
  70. lfs_file_read(&lfs, &file, buffer, size) => size;
  71. assert(memcmp(buffer, names[n], size) == 0);
  72. }
  73. lfs_file_close(&lfs, &file) => 0;
  74. }
  75. lfs_unmount(&lfs) => 0;
  76. '''
  77. [[case]] # parallel allocation reuse test
  78. define.FILES = 3
  79. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-4)) / FILES)'
  80. define.CYCLES = [1, 10]
  81. code = '''
  82. const char *names[FILES] = {"bacon", "eggs", "pancakes"};
  83. lfs_file_t files[FILES];
  84. lfs_format(&lfs, &cfg) => 0;
  85. for (int c = 0; c < CYCLES; c++) {
  86. lfs_mount(&lfs, &cfg) => 0;
  87. lfs_mkdir(&lfs, "breakfast") => 0;
  88. lfs_unmount(&lfs) => 0;
  89. lfs_mount(&lfs, &cfg) => 0;
  90. for (int n = 0; n < FILES; n++) {
  91. sprintf(path, "breakfast/%s", names[n]);
  92. lfs_file_open(&lfs, &files[n], path,
  93. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
  94. }
  95. for (int n = 0; n < FILES; n++) {
  96. size = strlen(names[n]);
  97. for (int i = 0; i < SIZE; i += size) {
  98. lfs_file_write(&lfs, &files[n], names[n], size) => size;
  99. }
  100. }
  101. for (int n = 0; n < FILES; n++) {
  102. lfs_file_close(&lfs, &files[n]) => 0;
  103. }
  104. lfs_unmount(&lfs) => 0;
  105. lfs_mount(&lfs, &cfg) => 0;
  106. for (int n = 0; n < FILES; n++) {
  107. sprintf(path, "breakfast/%s", names[n]);
  108. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  109. size = strlen(names[n]);
  110. for (int i = 0; i < SIZE; i += size) {
  111. lfs_file_read(&lfs, &file, buffer, size) => size;
  112. assert(memcmp(buffer, names[n], size) == 0);
  113. }
  114. lfs_file_close(&lfs, &file) => 0;
  115. }
  116. lfs_unmount(&lfs) => 0;
  117. lfs_mount(&lfs, &cfg) => 0;
  118. for (int n = 0; n < FILES; n++) {
  119. sprintf(path, "breakfast/%s", names[n]);
  120. lfs_remove(&lfs, path) => 0;
  121. }
  122. lfs_remove(&lfs, "breakfast") => 0;
  123. lfs_unmount(&lfs) => 0;
  124. }
  125. '''
  126. [[case]] # serial allocation reuse test
  127. define.FILES = 3
  128. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-4)) / FILES)'
  129. define.CYCLES = [1, 10]
  130. code = '''
  131. const char *names[FILES] = {"bacon", "eggs", "pancakes"};
  132. lfs_format(&lfs, &cfg) => 0;
  133. for (int c = 0; c < CYCLES; c++) {
  134. lfs_mount(&lfs, &cfg) => 0;
  135. lfs_mkdir(&lfs, "breakfast") => 0;
  136. lfs_unmount(&lfs) => 0;
  137. for (int n = 0; n < FILES; n++) {
  138. lfs_mount(&lfs, &cfg) => 0;
  139. sprintf(path, "breakfast/%s", names[n]);
  140. lfs_file_open(&lfs, &file, path,
  141. LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
  142. size = strlen(names[n]);
  143. memcpy(buffer, names[n], size);
  144. for (int i = 0; i < SIZE; i += size) {
  145. lfs_file_write(&lfs, &file, buffer, size) => size;
  146. }
  147. lfs_file_close(&lfs, &file) => 0;
  148. lfs_unmount(&lfs) => 0;
  149. }
  150. lfs_mount(&lfs, &cfg) => 0;
  151. for (int n = 0; n < FILES; n++) {
  152. sprintf(path, "breakfast/%s", names[n]);
  153. lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0;
  154. size = strlen(names[n]);
  155. for (int i = 0; i < SIZE; i += size) {
  156. lfs_file_read(&lfs, &file, buffer, size) => size;
  157. assert(memcmp(buffer, names[n], size) == 0);
  158. }
  159. lfs_file_close(&lfs, &file) => 0;
  160. }
  161. lfs_unmount(&lfs) => 0;
  162. lfs_mount(&lfs, &cfg) => 0;
  163. for (int n = 0; n < FILES; n++) {
  164. sprintf(path, "breakfast/%s", names[n]);
  165. lfs_remove(&lfs, path) => 0;
  166. }
  167. lfs_remove(&lfs, "breakfast") => 0;
  168. lfs_unmount(&lfs) => 0;
  169. }
  170. '''
  171. [[case]] # exhaustion test
  172. code = '''
  173. lfs_format(&lfs, &cfg) => 0;
  174. lfs_mount(&lfs, &cfg) => 0;
  175. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  176. size = strlen("exhaustion");
  177. memcpy(buffer, "exhaustion", size);
  178. lfs_file_write(&lfs, &file, buffer, size) => size;
  179. lfs_file_sync(&lfs, &file) => 0;
  180. size = strlen("blahblahblahblah");
  181. memcpy(buffer, "blahblahblahblah", size);
  182. lfs_ssize_t res;
  183. while (true) {
  184. res = lfs_file_write(&lfs, &file, buffer, size);
  185. if (res < 0) {
  186. break;
  187. }
  188. res => size;
  189. }
  190. res => LFS_ERR_NOSPC;
  191. lfs_file_close(&lfs, &file) => 0;
  192. lfs_unmount(&lfs) => 0;
  193. lfs_mount(&lfs, &cfg) => 0;
  194. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY);
  195. size = strlen("exhaustion");
  196. lfs_file_size(&lfs, &file) => size;
  197. lfs_file_read(&lfs, &file, buffer, size) => size;
  198. memcmp(buffer, "exhaustion", size) => 0;
  199. lfs_file_close(&lfs, &file) => 0;
  200. lfs_unmount(&lfs) => 0;
  201. '''
  202. [[case]] # exhaustion wraparound test
  203. define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-4)) / 3)'
  204. code = '''
  205. lfs_format(&lfs, &cfg) => 0;
  206. lfs_mount(&lfs, &cfg) => 0;
  207. lfs_file_open(&lfs, &file, "padding", LFS_O_WRONLY | LFS_O_CREAT);
  208. size = strlen("buffering");
  209. memcpy(buffer, "buffering", size);
  210. for (int i = 0; i < SIZE; i += size) {
  211. lfs_file_write(&lfs, &file, buffer, size) => size;
  212. }
  213. lfs_file_close(&lfs, &file) => 0;
  214. lfs_remove(&lfs, "padding") => 0;
  215. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  216. size = strlen("exhaustion");
  217. memcpy(buffer, "exhaustion", size);
  218. lfs_file_write(&lfs, &file, buffer, size) => size;
  219. lfs_file_sync(&lfs, &file) => 0;
  220. size = strlen("blahblahblahblah");
  221. memcpy(buffer, "blahblahblahblah", size);
  222. lfs_ssize_t res;
  223. while (true) {
  224. res = lfs_file_write(&lfs, &file, buffer, size);
  225. if (res < 0) {
  226. break;
  227. }
  228. res => size;
  229. }
  230. res => LFS_ERR_NOSPC;
  231. lfs_file_close(&lfs, &file) => 0;
  232. lfs_unmount(&lfs) => 0;
  233. lfs_mount(&lfs, &cfg) => 0;
  234. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY);
  235. size = strlen("exhaustion");
  236. lfs_file_size(&lfs, &file) => size;
  237. lfs_file_read(&lfs, &file, buffer, size) => size;
  238. memcmp(buffer, "exhaustion", size) => 0;
  239. lfs_file_close(&lfs, &file) => 0;
  240. lfs_remove(&lfs, "exhaustion") => 0;
  241. lfs_unmount(&lfs) => 0;
  242. '''
  243. [[case]] # dir exhaustion test
  244. code = '''
  245. lfs_format(&lfs, &cfg) => 0;
  246. lfs_mount(&lfs, &cfg) => 0;
  247. // find out max file size
  248. lfs_mkdir(&lfs, "exhaustiondir") => 0;
  249. size = strlen("blahblahblahblah");
  250. memcpy(buffer, "blahblahblahblah", size);
  251. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  252. int count = 0;
  253. while (true) {
  254. err = lfs_file_write(&lfs, &file, buffer, size);
  255. if (err < 0) {
  256. break;
  257. }
  258. count += 1;
  259. }
  260. err => LFS_ERR_NOSPC;
  261. lfs_file_close(&lfs, &file) => 0;
  262. lfs_remove(&lfs, "exhaustion") => 0;
  263. lfs_remove(&lfs, "exhaustiondir") => 0;
  264. // see if dir fits with max file size
  265. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  266. for (int i = 0; i < count; i++) {
  267. lfs_file_write(&lfs, &file, buffer, size) => size;
  268. }
  269. lfs_file_close(&lfs, &file) => 0;
  270. lfs_mkdir(&lfs, "exhaustiondir") => 0;
  271. lfs_remove(&lfs, "exhaustiondir") => 0;
  272. lfs_remove(&lfs, "exhaustion") => 0;
  273. // see if dir fits with > max file size
  274. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  275. for (int i = 0; i < count+1; i++) {
  276. lfs_file_write(&lfs, &file, buffer, size) => size;
  277. }
  278. lfs_file_close(&lfs, &file) => 0;
  279. lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC;
  280. lfs_remove(&lfs, "exhaustion") => 0;
  281. lfs_unmount(&lfs) => 0;
  282. '''
  283. # Below, I don't like these tests. They're fragile and depend _heavily_
  284. # on the geometry of the block device. But they are valuable. Eventually they
  285. # should be removed and replaced with generalized tests.
  286. [[case]] # chained dir exhaustion test
  287. define.LFS_BLOCK_SIZE = 512
  288. define.LFS_BLOCK_COUNT = 1024
  289. if = 'LFS_BLOCK_SIZE == 512 and LFS_BLOCK_COUNT == 1024'
  290. code = '''
  291. lfs_format(&lfs, &cfg) => 0;
  292. lfs_mount(&lfs, &cfg) => 0;
  293. // find out max file size
  294. lfs_mkdir(&lfs, "exhaustiondir") => 0;
  295. for (int i = 0; i < 10; i++) {
  296. sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i);
  297. lfs_mkdir(&lfs, path) => 0;
  298. }
  299. size = strlen("blahblahblahblah");
  300. memcpy(buffer, "blahblahblahblah", size);
  301. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  302. int count = 0;
  303. while (true) {
  304. err = lfs_file_write(&lfs, &file, buffer, size);
  305. if (err < 0) {
  306. break;
  307. }
  308. count += 1;
  309. }
  310. err => LFS_ERR_NOSPC;
  311. lfs_file_close(&lfs, &file) => 0;
  312. lfs_remove(&lfs, "exhaustion") => 0;
  313. lfs_remove(&lfs, "exhaustiondir") => 0;
  314. for (int i = 0; i < 10; i++) {
  315. sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i);
  316. lfs_remove(&lfs, path) => 0;
  317. }
  318. // see that chained dir fails
  319. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  320. for (int i = 0; i < count+1; i++) {
  321. lfs_file_write(&lfs, &file, buffer, size) => size;
  322. }
  323. lfs_file_sync(&lfs, &file) => 0;
  324. for (int i = 0; i < 10; i++) {
  325. sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i);
  326. lfs_mkdir(&lfs, path) => 0;
  327. }
  328. lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC;
  329. // shorten file to try a second chained dir
  330. while (true) {
  331. err = lfs_mkdir(&lfs, "exhaustiondir");
  332. if (err != LFS_ERR_NOSPC) {
  333. break;
  334. }
  335. lfs_ssize_t filesize = lfs_file_size(&lfs, &file);
  336. filesize > 0 => true;
  337. lfs_file_truncate(&lfs, &file, filesize - size) => 0;
  338. lfs_file_sync(&lfs, &file) => 0;
  339. }
  340. err => 0;
  341. lfs_mkdir(&lfs, "exhaustiondir2") => LFS_ERR_NOSPC;
  342. lfs_file_close(&lfs, &file) => 0;
  343. lfs_unmount(&lfs) => 0;
  344. '''
  345. [[case]] # split dir test
  346. define.LFS_BLOCK_SIZE = 512
  347. define.LFS_BLOCK_COUNT = 1024
  348. if = 'LFS_BLOCK_SIZE == 512 and LFS_BLOCK_COUNT == 1024'
  349. code = '''
  350. lfs_format(&lfs, &cfg) => 0;
  351. lfs_mount(&lfs, &cfg) => 0;
  352. // create one block hole for half a directory
  353. lfs_file_open(&lfs, &file, "bump", LFS_O_WRONLY | LFS_O_CREAT) => 0;
  354. for (lfs_size_t i = 0; i < cfg.block_size; i += 2) {
  355. memcpy(&buffer[i], "hi", 2);
  356. }
  357. lfs_file_write(&lfs, &file, buffer, cfg.block_size) => cfg.block_size;
  358. lfs_file_close(&lfs, &file) => 0;
  359. lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
  360. size = strlen("blahblahblahblah");
  361. memcpy(buffer, "blahblahblahblah", size);
  362. for (lfs_size_t i = 0;
  363. i < (cfg.block_count-4)*(cfg.block_size-8);
  364. i += size) {
  365. lfs_file_write(&lfs, &file, buffer, size) => size;
  366. }
  367. lfs_file_close(&lfs, &file) => 0;
  368. // remount to force reset of lookahead
  369. lfs_unmount(&lfs) => 0;
  370. lfs_mount(&lfs, &cfg) => 0;
  371. // open hole
  372. lfs_remove(&lfs, "bump") => 0;
  373. lfs_mkdir(&lfs, "splitdir") => 0;
  374. lfs_file_open(&lfs, &file, "splitdir/bump",
  375. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  376. for (lfs_size_t i = 0; i < cfg.block_size; i += 2) {
  377. memcpy(&buffer[i], "hi", 2);
  378. }
  379. lfs_file_write(&lfs, &file, buffer, 2*cfg.block_size) => LFS_ERR_NOSPC;
  380. lfs_file_close(&lfs, &file) => 0;
  381. lfs_unmount(&lfs) => 0;
  382. '''
  383. [[case]] # outdated lookahead test
  384. define.LFS_BLOCK_SIZE = 512
  385. define.LFS_BLOCK_COUNT = 1024
  386. if = 'LFS_BLOCK_SIZE == 512 and LFS_BLOCK_COUNT == 1024'
  387. code = '''
  388. lfs_format(&lfs, &cfg) => 0;
  389. lfs_mount(&lfs, &cfg) => 0;
  390. // fill completely with two files
  391. lfs_file_open(&lfs, &file, "exhaustion1",
  392. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  393. size = strlen("blahblahblahblah");
  394. memcpy(buffer, "blahblahblahblah", size);
  395. for (lfs_size_t i = 0;
  396. i < ((cfg.block_count-2)/2)*(cfg.block_size-8);
  397. i += size) {
  398. lfs_file_write(&lfs, &file, buffer, size) => size;
  399. }
  400. lfs_file_close(&lfs, &file) => 0;
  401. lfs_file_open(&lfs, &file, "exhaustion2",
  402. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  403. size = strlen("blahblahblahblah");
  404. memcpy(buffer, "blahblahblahblah", size);
  405. for (lfs_size_t i = 0;
  406. i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8);
  407. i += size) {
  408. lfs_file_write(&lfs, &file, buffer, size) => size;
  409. }
  410. lfs_file_close(&lfs, &file) => 0;
  411. // remount to force reset of lookahead
  412. lfs_unmount(&lfs) => 0;
  413. lfs_mount(&lfs, &cfg) => 0;
  414. // rewrite one file
  415. lfs_file_open(&lfs, &file, "exhaustion1",
  416. LFS_O_WRONLY | LFS_O_TRUNC) => 0;
  417. lfs_file_sync(&lfs, &file) => 0;
  418. size = strlen("blahblahblahblah");
  419. memcpy(buffer, "blahblahblahblah", size);
  420. for (lfs_size_t i = 0;
  421. i < ((cfg.block_count-2)/2)*(cfg.block_size-8);
  422. i += size) {
  423. lfs_file_write(&lfs, &file, buffer, size) => size;
  424. }
  425. lfs_file_close(&lfs, &file) => 0;
  426. // rewrite second file, this requires lookahead does not
  427. // use old population
  428. lfs_file_open(&lfs, &file, "exhaustion2",
  429. LFS_O_WRONLY | LFS_O_TRUNC) => 0;
  430. lfs_file_sync(&lfs, &file) => 0;
  431. size = strlen("blahblahblahblah");
  432. memcpy(buffer, "blahblahblahblah", size);
  433. for (lfs_size_t i = 0;
  434. i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8);
  435. i += size) {
  436. lfs_file_write(&lfs, &file, buffer, size) => size;
  437. }
  438. lfs_file_close(&lfs, &file) => 0;
  439. lfs_unmount(&lfs) => 0;
  440. '''
  441. [[case]] # outdated lookahead and split dir test
  442. define.LFS_BLOCK_SIZE = 512
  443. define.LFS_BLOCK_COUNT = 1024
  444. if = 'LFS_BLOCK_SIZE == 512 and LFS_BLOCK_COUNT == 1024'
  445. code = '''
  446. lfs_format(&lfs, &cfg) => 0;
  447. lfs_mount(&lfs, &cfg) => 0;
  448. // fill completely with two files
  449. lfs_file_open(&lfs, &file, "exhaustion1",
  450. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  451. size = strlen("blahblahblahblah");
  452. memcpy(buffer, "blahblahblahblah", size);
  453. for (lfs_size_t i = 0;
  454. i < ((cfg.block_count-2)/2)*(cfg.block_size-8);
  455. i += size) {
  456. lfs_file_write(&lfs, &file, buffer, size) => size;
  457. }
  458. lfs_file_close(&lfs, &file) => 0;
  459. lfs_file_open(&lfs, &file, "exhaustion2",
  460. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  461. size = strlen("blahblahblahblah");
  462. memcpy(buffer, "blahblahblahblah", size);
  463. for (lfs_size_t i = 0;
  464. i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8);
  465. i += size) {
  466. lfs_file_write(&lfs, &file, buffer, size) => size;
  467. }
  468. lfs_file_close(&lfs, &file) => 0;
  469. // remount to force reset of lookahead
  470. lfs_unmount(&lfs) => 0;
  471. lfs_mount(&lfs, &cfg) => 0;
  472. // rewrite one file with a hole of one block
  473. lfs_file_open(&lfs, &file, "exhaustion1",
  474. LFS_O_WRONLY | LFS_O_TRUNC) => 0;
  475. lfs_file_sync(&lfs, &file) => 0;
  476. size = strlen("blahblahblahblah");
  477. memcpy(buffer, "blahblahblahblah", size);
  478. for (lfs_size_t i = 0;
  479. i < ((cfg.block_count-2)/2 - 1)*(cfg.block_size-8);
  480. i += size) {
  481. lfs_file_write(&lfs, &file, buffer, size) => size;
  482. }
  483. lfs_file_close(&lfs, &file) => 0;
  484. // try to allocate a directory, should fail!
  485. lfs_mkdir(&lfs, "split") => LFS_ERR_NOSPC;
  486. // file should not fail
  487. lfs_file_open(&lfs, &file, "notasplit",
  488. LFS_O_WRONLY | LFS_O_CREAT) => 0;
  489. lfs_file_write(&lfs, &file, "hi", 2) => 2;
  490. lfs_file_close(&lfs, &file) => 0;
  491. lfs_unmount(&lfs) => 0;
  492. '''