test_alloc.toml 18 KB

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