xref: /inferno-os/libnandfs/readpageauxilliary.c (revision 1e1b493dfc048d301ef6b41377f0a3665ee7f3fc)
1 #include "logfsos.h"
2 #include "logfs.h"
3 #include "nandfs.h"
4 #include "local.h"
5 
6 static int
7 countzeros(uchar byte)
8 {
9 	int b, count;
10 	for (b = 0x80, count = 0; b; b>>= 1)
11 		if ((byte & b) == 0)
12 			count++;
13 	return count;
14 }
15 
16 char *
17 nandfsreadpageauxiliary(Nandfs *nandfs, NandfsTags *tags, long block, int page, int correct, LogfsLowLevelReadResult *result)
18 {
19 	NandfsAuxiliary hdr;
20 	char *rv;
21 
22 	rv = (*nandfs->read)(nandfs->magic, &hdr, sizeof(hdr), nandfs->rawblocksize * (nandfs->baseblock + block) + page * NandfsFullSize + NandfsPageSize);
23 	if (rv)
24 		return rv;
25 	if (countzeros(hdr.blockstatus) > 2) {
26 		*result = LogfsLowLevelReadResultBad;
27 		return nil;
28 	}
29 	if (correct)
30 		*result = _nandfscorrectauxiliary(&hdr);
31 	else
32 		*result = LogfsLowLevelReadResultOk;
33 	_nandfsextracttags(&hdr, tags);
34 	return nil;
35 }
36