| plan 9 kernel history: overview | file list | diff list |
1996/0131/port/devtinyfs.c (diff list | history)
| 1996/0123/sys/src/9/port/devtinyfs.c:13,27 – 1996/0131/sys/src/9/port/devtinyfs.c:13,28 (short | long | prev | next) | ||
| 1996/0116 | enum{ Qdir, | |
| 1996/0123 |
| |
| 1996/0120 | Qmedium, | |
| 1996/0123 |
| |
| 1996/0131 | Blen= 48, Tdir= 0, Tdata, Tend, | |
| 1996/0116 | }; | |
| 1996/0122 | typedef struct FS FS; | |
| 1996/0116 | ||
| 1996/0122 | struct FS { | |
| 1996/0116 | QLock; | |
| 1996/0122 | Ref r; | |
| 1996/0123/sys/src/9/port/devtinyfs.c:28,36 – 1996/0131/sys/src/9/port/devtinyfs.c:29,36 | ||
| 1996/0122 | int dev; FS *next; | |
| 1996/0116 | Chan *c; | |
| 1996/0123 |
| |
| 1996/0131 | uchar *map; int nblocks; | |
| 1996/0122 | }; struct { | |
| 1996/0123/sys/src/9/port/devtinyfs.c:39,44 – 1996/0131/sys/src/9/port/devtinyfs.c:39,50 | ||
| 1996/0122 | int hidev; | |
| 1996/0116 | } tinyfs; | |
| 1996/0131 | #define GETS(x) ((x)[0]|((x)[1]<<8)) #define PUTS(x, v) {(x)[0] = (v);(x)[1] = ((v)>>8);} #define GETL(x) (GETS(x)|(GETS(x+2)<<16)) #define PUTL(x, v) {PUTS(x, v);PUTS(x+2, (v)>>16)}; | |
| 1996/0116 | void tinyfsreset(void) { | |
| 1996/0123/sys/src/9/port/devtinyfs.c:49,60 – 1996/0131/sys/src/9/port/devtinyfs.c:55,106 | ||
| 1996/0116 | { } | |
| 1996/0123 |
| |
| 1996/0131 | static uchar checksum(uchar *p) { uchar *e; uchar s; | |
| 1996/0123 |
| |
| 1996/0131 | s = 0; for(e = p + Blen; p < e; p++) s += *p; } | |
| 1996/0123 | ||
| 1996/0131 | static void mapclr(FS *fs, int bno) { fs->map[bno>>3] &= ~(1<<(bno&7)); } static void mapset(FS *fs, int bno) { fs->map[bno>>3] |= 1<<(bno&7); } static int mapalloc(FS *fs) { int i, j, lim; uchar x; qlock(fs); lim = (fs->nblocks + 8 - 1)/8; for(i = 0; i < lim; i++){ x = fs->map[i]; if(x == 0xff) continue; for(j = 0; j < 8; j++) if((x & (1<<j)) == 0){ fs->map[i] = x|(1<<j); qunlock(fs); return i*8 + j; } } qunlock(fs); return -1; } | |
| 1996/0123 | /* * see if we have a reasonable fat/root directory */ | |
| 1996/0123/sys/src/9/port/devtinyfs.c:61,97 – 1996/0131/sys/src/9/port/devtinyfs.c:107,141 | ||
| 1996/0123 | static int fsinit(FS *fs) { | |
| 1996/0131 | uchar buf[Blen+DIRLEN]; | |
| 1996/0123 | Dir d; | |
| 1996/0131 | ulong x, bno; | |
| 1996/0123 |
| |
| 1996/0131 | fs->nblocks = d.length/Blen; if(fs->nblocks < 3) | |
| 1996/0123 | error("tinyfs medium too small"); | |
| 1996/0131 | /* bitmap for block usage */ x = (fs->nblocks + 8 - 1)/8; fs->map = malloc(x); memset(fs->map, 0x0, x); for(bno = fs->nblocks; bno < x*8; bno++) mapset(fs, bno); | |
| 1996/0123 |
| |
| 1996/0131 | for(bno = 0; bno < fs->nblocks; bno++){ n = devtab[fs->c->type].read(fs->c, buf, Blen, Blen*bno); if(n != Blen) break; if(checksum(buf) != 0) continue; switch(buf[0]){ case Tdir: mapset(fs, bno); break; } } | |
| 1996/0123 | } /* | |