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