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