7 #define FIDMOD 127 /* prime */
10 static Xfile *xfiles[FIDMOD], *freelist;
11 static MLock xlock, xlocks[FIDMOD], freelock;
14 getxfs(char *user, char *name)
24 if(name==nil || name[0]==0)
32 * If the name passed is of the form 'name:offset' then
33 * offset is used to prime xf->offset. This allows accessing
34 * a FAT-based filesystem anywhere within a partition.
35 * Typical use would be to mount a filesystem in the presence
36 * of a boot manager programme at the beginning of the disc.
39 if(p = strrchr(name, ':')){
41 offset = strtoll(p, &q, 0);
42 chat("name %s, offset %lld\n", p, offset);
43 if(offset < 0 || p == q){
54 fd = open(name, omode);
56 if(fd < 0 && omode==ORDWR){
58 fd = open(name, omode);
62 chat("can't open %s: %r\n", name);
76 for(fxf=0,xf=xhead; xf; xf=xf->next){
82 if(!eqqid(xf->qid, dqid))
84 if(strcmp(xf->name, name) != 0 || xf->dev < 0)
86 if(devcheck(xf) < 0) /* look for media change */
88 if(offset && xf->offset != offset)
90 chat("incref \"%s\", dev=%d...", xf->name, xf->dev);
97 fxf = malloc(sizeof(Xfs));
107 chat("alloc \"%s\", dev=%d...", name, fd);
108 fxf->name = strdup(name);
113 fxf->offset = offset;
122 refxfs(Xfs *xf, int delta)
127 chat("free \"%s\", dev=%d...", xf->name, xf->dev);
140 xfile(int fid, int flag)
145 k = ((ulong)fid) % FIDMOD;
149 for(f=*hp; f; f=f->next){
164 return (f && f->xf && f->xf->dev < 0) ? nil : f;
184 if(f = freelist){ /* assign = */
189 f = malloc(sizeof(Xfile));
201 f->qid = (Qid){0,0,0};
219 f->qid = (Qid){0,0,0};
224 * the file at <addr, offset> has moved
225 * relocate the dos entries of all fids in the same file
228 dosptrreloc(Xfile *f, Dosptr *dp, vlong addr, ulong offset)
234 for(i=0; i < FIDMOD; i++){
235 for(p = xfiles[i]; p != nil; p = p->next){
237 if(p != f && p->xf == f->xf
238 && xdp != nil && xdp->addr == addr && xdp->offset == offset){
239 memmove(xdp, dp, sizeof(Dosptr));
242 p->qid.path = QIDPATH(xdp);