test_orphan.toml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. [[case]] # orphan test
  2. in = "lfs.c"
  3. code = '''
  4. lfs_format(&lfs, &cfg) => 0;
  5. lfs_mount(&lfs, &cfg) => 0;
  6. lfs_mkdir(&lfs, "parent") => 0;
  7. lfs_mkdir(&lfs, "parent/orphan") => 0;
  8. lfs_mkdir(&lfs, "parent/child") => 0;
  9. lfs_remove(&lfs, "parent/orphan") => 0;
  10. lfs_unmount(&lfs) => 0;
  11. // corrupt the child's most recent commit, this should be the update
  12. // to the linked-list entry, which should orphan the orphan. Note this
  13. // makes a lot of assumptions about the remove operation.
  14. lfs_mount(&lfs, &cfg) => 0;
  15. lfs_dir_open(&lfs, &dir, "parent/child") => 0;
  16. lfs_block_t block = dir.m.pair[0];
  17. lfs_dir_close(&lfs, &dir) => 0;
  18. lfs_unmount(&lfs) => 0;
  19. uint8_t bbuffer[LFS_BLOCK_SIZE];
  20. cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  21. int off = LFS_BLOCK_SIZE-1;
  22. while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) {
  23. off -= 1;
  24. }
  25. memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3);
  26. cfg.erase(&cfg, block) => 0;
  27. cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0;
  28. cfg.sync(&cfg) => 0;
  29. lfs_mount(&lfs, &cfg) => 0;
  30. lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT;
  31. lfs_stat(&lfs, "parent/child", &info) => 0;
  32. lfs_fs_size(&lfs) => 8;
  33. lfs_unmount(&lfs) => 0;
  34. lfs_mount(&lfs, &cfg) => 0;
  35. lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT;
  36. lfs_stat(&lfs, "parent/child", &info) => 0;
  37. lfs_fs_size(&lfs) => 8;
  38. // this mkdir should both create a dir and deorphan, so size
  39. // should be unchanged
  40. lfs_mkdir(&lfs, "parent/otherchild") => 0;
  41. lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT;
  42. lfs_stat(&lfs, "parent/child", &info) => 0;
  43. lfs_stat(&lfs, "parent/otherchild", &info) => 0;
  44. lfs_fs_size(&lfs) => 8;
  45. lfs_unmount(&lfs) => 0;
  46. lfs_mount(&lfs, &cfg) => 0;
  47. lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT;
  48. lfs_stat(&lfs, "parent/child", &info) => 0;
  49. lfs_stat(&lfs, "parent/otherchild", &info) => 0;
  50. lfs_fs_size(&lfs) => 8;
  51. lfs_unmount(&lfs) => 0;
  52. '''