formatblock.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "logfsos.h"
  2. #include "logfs.h"
  3. #include "nandfs.h"
  4. #include "local.h"
  5. char *
  6. nandfsformatblock(Nandfs *nandfs, long absblock, uchar tag, ulong path, long baseblock, long sizeinblocks, int xcount, long *xdata, void *llsave, int *markedbad)
  7. {
  8. int page;
  9. char *rv;
  10. NandfsTags t;
  11. int ppb;
  12. if (markedbad)
  13. *markedbad = 0;
  14. t.tag = tag;
  15. t.magic = LogfsMagic;
  16. t.nerase = *(ulong *)llsave < NandfsNeraseMask ? *(ulong *)llsave + 1 : 1;
  17. ppb = 1 << nandfs->ll.l2pagesperblock;
  18. for (page = 0, rv = nil; rv == nil && page < ppb; page++) {
  19. if (tag == LogfsTboot && page > 0 && page < xcount + 3) {
  20. switch (page) {
  21. case 1:
  22. t.path = baseblock;
  23. break;
  24. case 2:
  25. t.path = sizeinblocks;
  26. break;
  27. default:
  28. t.path = xdata[page - 3];
  29. break;
  30. }
  31. }
  32. else
  33. t.path = path;
  34. rv = nandfswritepageauxiliary(nandfs, &t, absblock, page);
  35. if (rv)
  36. break;
  37. }
  38. if (rv) {
  39. if (strcmp(rv, Eio) != 0)
  40. return rv;
  41. if (markedbad) {
  42. *markedbad = 1;
  43. rv = nandfsmarkabsblockbad(nandfs, absblock);
  44. if (strcmp(rv, Eio) != 0)
  45. return rv;
  46. return nil;
  47. }
  48. return rv;
  49. }
  50. return nil;
  51. }