updatepage.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "logfsos.h"
  2. #include "logfs.h"
  3. #include "nandfs.h"
  4. #include "nandecc.h"
  5. #include "local.h"
  6. char *
  7. nandfsupdatepage(Nandfs *nandfs, void *buf, ulong path, uchar tag, long block, int page)
  8. {
  9. uchar tbuf[NandfsFullSize];
  10. ulong ecc1, ecc2;
  11. ulong rawoffset;
  12. NandfsAuxiliary *hdr;
  13. rawoffset = (nandfs->baseblock + block) * nandfs->rawblocksize + page * NandfsFullSize;
  14. memmove(tbuf, buf, NandfsPageSize);
  15. ecc1 = nandecc(tbuf);
  16. ecc2 = nandecc(tbuf + 256);
  17. hdr = (NandfsAuxiliary *)(tbuf + NandfsPageSize);
  18. memset(hdr, 0xff, sizeof(*hdr));
  19. hdr->tag = tag;
  20. if (path < NandfsPathMask) {
  21. ulong tmp = _nandfshamming31_26calc(path << 6) | (1 << 5);
  22. putbig4(hdr->parth, tmp);
  23. }
  24. putlittle3(hdr->ecc1, ecc1);
  25. putlittle3(hdr->ecc2, ecc2);
  26. return (*nandfs->write)(nandfs->magic, tbuf, sizeof(tbuf), rawoffset);
  27. }
  28. char *
  29. nandfswritepage(Nandfs *nandfs, void *buf, long block, int page)
  30. {
  31. ulong writepath = nandfsgetpath(nandfs, block);
  32. uchar writetag = nandfsgettag(nandfs, block);
  33. //print("block %ld writepath 0x%.8lux writetag 0x%.2ux\n", block, writepath, writetag);
  34. return nandfsupdatepage(nandfs, buf, writepath, writetag, block, page);
  35. }