7 static char WMAGIC[] = "kfs wren device\n";
8 static char MMAGIC[] = "kfs multi-wren device %4d/%4d\n";
10 typedef struct Wren Wren;
19 static char *wmagic = WMAGIC;
31 for(i = 0; i < maxwren; i++)
32 if(devcmp(dev, wrens[i].dev) == 0)
34 panic("can't find wren for %D", dev);
39 * find out the length of a file
40 * given the mesg version of a stat buffer
41 * we call this because convM2D is different
42 * for the file system than in the os
52 ll = p[0] | (p[1]<<8) | (p[2]<<16) | (p[3]<<24);
53 hl = p[4] | (p[5]<<8) | (p[6]<<16) | (p[7]<<24);
54 return ll | ((uvlong) hl << 32);
58 wrenpartinit(Device dev, int k)
60 char buf[MAXBUFSIZE], d[DIRREC];
61 char file[128], magic[64];
66 wrens = ialloc(MAXWREN * sizeof *wrens);
69 sprint(file, "%s%d", wrenfile, k);
71 strcpy(file, wrenfile);
72 fd = open(file, ORDWR);
74 panic("can't open %s", file);
76 panic("can't stat %s\n", file);
78 i = read(fd, buf, sizeof buf);
80 panic("can't read %s", file);
83 sprint(magic, wmagic, k, nwren);
84 nmagic = strlen(magic);
85 if(strncmp(buf+256, magic, nmagic) == 0){
86 RBUFSIZE = atol(buf+256+nmagic);
88 fprint(2, "kfs: bad buffersize(%d): assuming 1k blocks\n", RBUFSIZE);
94 w->nblocks = statlen(d)/RBUFSIZE;
96 w->nblocks -= 1; /* don't count magic */
110 wrenpartinit(dev, i);
115 wrenpartream(Device dev, int k)
118 char buf[MAXBUFSIZE], magic[64];
122 panic("kfs: bad buffersize(%d): restart a multiple of 512\n", RBUFSIZE);
123 print("kfs: reaming the file system using %d byte blocks\n", RBUFSIZE);
126 memset(buf, 0, sizeof buf);
127 sprint(magic, wmagic, k, nwren);
128 sprint(buf+256, "%s%d\n", magic, RBUFSIZE);
130 i = seek(fd, 0, 0) < 0 || write(fd, buf, RBUFSIZE) != RBUFSIZE;
133 panic("can't ream disk");
143 wrenpartream(dev, i);
148 wrentag(char *p, int tag, long qpath)
152 t = (Tag*)(p+BUFSIZE);
153 return t->tag != tag || (qpath&~QPDIR) != t->path;
157 wrencheck(Device dev)
159 char buf[MAXBUFSIZE];
163 if(RBUFSIZE > sizeof buf)
164 panic("bufsize too big");
165 if(wrenread(dev, wrensuper(dev), buf) || wrentag(buf, Tsuper, QPSUPER)
166 || wrenread(dev, wrenroot(dev), buf) || wrentag(buf, Tdir, QPROOT))
168 if(((Dentry *)buf)[0].mode & DALLOC)
189 wrensuper(Device dev)
203 wrenread(Device dev, long addr, void *b)
209 for(i=0; i<nwren; i++){
210 if(addr < w->nblocks)
219 i = seek(fd, (vlong)addr*RBUFSIZE, 0) == -1 || read(fd, b, RBUFSIZE) != RBUFSIZE;
225 wrenwrite(Device dev, long addr, void *b)
231 for(i=0; i<nwren; i++){
232 if(addr < w->nblocks)
241 i = seek(fd, (vlong)addr*RBUFSIZE, 0) == -1 || write(fd, b, RBUFSIZE) != RBUFSIZE;