plan 9 kernel history: overview | file list | diff list

1996/0217/port/devtinyfs.c (diff list | history)

1996/0206/sys/src/9/port/devtinyfs.c:160,1661996/0217/sys/src/9/port/devtinyfs.c:160,166 (short | long | prev | next)
1996/0201    
} 
 
static Mdata* 
validdata(Tfs *fs, uchar *p) 
1996/0217    
validdata(Tfs *fs, uchar *p, int *lenp) 
1996/0201    
{ 
	Mdata *md; 
	ulong x; 
1996/0206/sys/src/9/port/devtinyfs.c:173,1831996/0217/sys/src/9/port/devtinyfs.c:173,187
1996/0201    
		x = GETS(md->bno); 
		if(x >= fs->nblocks) 
			return 0; 
1996/0217    
		if(lenp) 
			*lenp = Dlen; 
1996/0201    
		break; 
	case Tagend: 
		x = GETS(md->bno); 
		if(x > Blen - 4) 
1996/0217    
		if(x > Dlen) 
1996/0201    
			return 0; 
1996/0217    
		if(lenp) 
			*lenp = x; 
1996/0201    
		break; 
	} 
	return md; 
1996/0206/sys/src/9/port/devtinyfs.c:184,1971996/0217/sys/src/9/port/devtinyfs.c:188,203
1996/0201    
} 
 
1996/0206    
static Mdata* 
readdata(Tfs *fs, ulong bno, uchar *buf) 
1996/0217    
readdata(Tfs *fs, ulong bno, uchar *buf, int *lenp) 
1996/0206    
{ 
1996/0217    
	Mdata *md; 
 
1996/0206    
	if(bno >= fs->nblocks) 
		return 0; 
	n = devtab[fs->c->type].read(fs->c, buf, Blen, Blen*bno); 
	if(n != Blen) 
		return 0; 
	return validdata(fs, buf); 
1996/0217    
	return validdata(fs, buf, lenp); 
1996/0206    
} 
 
1996/0202    
static int 
1996/0206/sys/src/9/port/devtinyfs.c:230,2361996/0217/sys/src/9/port/devtinyfs.c:236,242
1996/0201    
		n = devtab[fs->c->type].read(fs->c, buf, Blen, Blen*bno); 
		if(n != Blen) 
			break; 
		md = validdata(buf); 
1996/0217    
		md = validdata(fs, buf, 0); 
1996/0201    
		if(md == 0) 
			break; 
		if(md->type == Tagend) 
1996/0206/sys/src/9/port/devtinyfs.c:259,2651996/0217/sys/src/9/port/devtinyfs.c:265,271
1996/0201    
	fs->fsize += 8; 
	f = smalloc(fs->fsize*sizeof(*f)); 
 
	memmove(f, fs->f, fs->nf*sizoef(f)); 
1996/0217    
	memmove(f, fs->f, fs->nf*sizeof(f)); 
1996/0201    
	free(fs->f); 
	fs->f = f; 
} 
1996/0206/sys/src/9/port/devtinyfs.c:305,3111996/0217/sys/src/9/port/devtinyfs.c:311,318
1996/0202    
 
1996/0123    
/* 
1996/0202    
 *  Read the whole medium and build a file table and used 
 *  block bitmap.  Inconsistent files are purged. 
1996/0217    
 *  block bitmap.  Inconsistent files are purged.  The medium 
 *  had better be small or this could take a while. 
1996/0123    
 */ 
1996/0201    
static void 
fsinit(Tfs *fs) 
1996/0206/sys/src/9/port/devtinyfs.c:313,3191996/0217/sys/src/9/port/devtinyfs.c:320,326
1996/0131    
	uchar buf[Blen+DIRLEN]; 
1996/0123    
	Dir d; 
1996/0131    
	ulong x, bno; 
1996/0201    
	int n; 
1996/0217    
	int n, done; 
1996/0201    
	Tfile *f; 
	Mdir *mdir; 
	Mdata *mdat; 
1996/0206/sys/src/9/port/devtinyfs.c:341,3471996/0217/sys/src/9/port/devtinyfs.c:348,354
1996/0201    
		if(mdir == 0) 
1996/0131    
			continue; 
1996/0201    
 
		if(fs->nfs <= fs->fsize) 
1996/0217    
		if(fs->nfs >= fs->fsize) 
1996/0201    
			expand(fs); 
1996/0202    
 
1996/0201    
		f = &fs->f[fs->nf++]; 
1996/0206/sys/src/9/port/devtinyfs.c:355,3631996/0217/sys/src/9/port/devtinyfs.c:362,370
1996/0201    
	} 
 
	/* follow files */ 
	for(f = fs->f; f; f = f->next){ 
1996/0217    
	for(f = fs->f; f < &(fs->f[fs->nf]); f++){ 
1996/0201    
		bno = fs->dbno; 
		for(;;) { 
1996/0217    
		for(done = 0; !done;) { 
1996/0201    
			if(isalloced(fs, bno)){ 
				freefile(f, bno); 
				break; 
1996/0206/sys/src/9/port/devtinyfs.c:367,3731996/0217/sys/src/9/port/devtinyfs.c:374,380
1996/0201    
				freefile(fs, f, bno); 
				break; 
			} 
			mdata = validdata(fs, buf); 
1996/0217    
			mdata = validdata(fs, buf, 0); 
1996/0201    
			if(mdata == 0){ 
				freefile(fs, f, bno); 
				break; 
1996/0206/sys/src/9/port/devtinyfs.c:380,3871996/0217/sys/src/9/port/devtinyfs.c:387,397
1996/0201    
				break; 
			case Tagend: 
				f->len += GETS(mdata->bno); 
1996/0217    
				done = 1; 
1996/0201    
				break; 
			} 
1996/0217    
			if(done) 
				f->flag &= ~Fcreating; 
1996/0131    
		} 
	} 
1996/0123    
} 
1996/0206/sys/src/9/port/devtinyfs.c:569,5751996/0217/sys/src/9/port/devtinyfs.c:579,585
1996/0202    
		f = &fs->f[c->qid.path]; 
		f->r--; 
1996/0203    
		if(f->r == 0){ 
			if(f->creating){ 
1996/0217    
			if(f->flag & Fcreating){ 
1996/0203    
				/* remove all other files with this name */ 
				for(i = 0; i < fs->fsize; i++){ 
					nf = &fs->f[i]; 
1996/0206/sys/src/9/port/devtinyfs.c:601,6071996/0217/sys/src/9/port/devtinyfs.c:611,617
1996/0201    
			} 
			l = &(*l)->next; 
		} 
1996/0203    
		free(fs-f); 
1996/0217    
		free(fs->f); 
1996/0201    
		free(fs->map); 
		close(fs->c); 
1996/0203    
		memset(fs, 0, sizeof(*fs)); 
1996/0206/sys/src/9/port/devtinyfs.c:618,6261996/0217/sys/src/9/port/devtinyfs.c:628,637
1996/0206    
	ulong bno, tbno; 
	Mdata *md; 
	uchar buf[Blen]; 
1996/0217    
	uchar *p = a; 
1996/0203    
 
	if(c->qid.path & CHDIR) 
1996/0201    
		return devdirread(c, a, n, tinyfstab, Ntinyfstab, tinyfsgen); 
1996/0217    
		return devdirread(c, a, n, 0, 0, tinyfsgen); 
1996/0203    
 
	fs = tinyfs.fs[c->dev]; 
	f = &fs->f[c->qid.path]; 
1996/0206/sys/src/9/port/devtinyfs.c:629,6511996/0217/sys/src/9/port/devtinyfs.c:640,672
1996/0203    
	if(n + offset >= f->length) 
		n = f->length - offset; 
1996/0206    
 
	/* walk to first data block */ 
1996/0217    
	/* walk to starting data block */ 
1996/0206    
	bno = f->dbno; 
	for(sofar = 0; sofar < offset; sofar += Blen){ 
		md = readdata(fs, bno, buf); 
1996/0217    
	for(sofar = 0; sofar + Blen < offset; sofar += Blen){ 
		md = readdata(fs, bno, buf, 0); 
1996/0206    
		if(md == 0) 
			error(Eio); 
		bno = GETS(md->bno); 
	} 
 
	/* read first block */ 
	i = offset%Blen; 
                 
	/* read data */ 
	for(sofar = 0; sofar+Blen < offset; sofar += Blen){ 
	                 
1996/0217    
	offset = offset%Blen; 
	for(sofar = 0; sofar < n; sofar += i){ 
		md = readdata(fs, bno, buf, &i); 
		if(md == 0) 
			error(Eio); 
		i -= offset; 
		if(i > n) 
			i = n; 
		if(i < 0) 
			break; 
		memmove(p, md->data, i); 
		p += i; 
		bno = GETS(md->bno); 
		offset = 0; 
	} 
1996/0203    
 
1996/0116    
	return n; 
1996/0217    
	return sofar; 
1996/0116    
} 
 
Block* 
1996/0206/sys/src/9/port/devtinyfs.c:657,6761996/0217/sys/src/9/port/devtinyfs.c:678,721
1996/0116    
long 
tinyfswrite(Chan *c, char *a, long n, ulong offset) 
{ 
	if(waserror()){ 
		qunlock(&tinyfs); 
		nexterror(); 
1996/0217    
	Tfs *fs; 
	Tfile *f; 
	int sofar, i; 
	ulong bno, tbno; 
	Mdata *md; 
	uchar buf[Blen]; 
	uchar *p = a; 
 
	if(c->qid.path & CHDIR) 
		error(Eperm); 
 
	fs = tinyfs.fs[c->dev]; 
	f = &fs->f[c->qid.path]; 
 
	/* walk to first data block */ 
	bno = f->dbno; 
	for(sofar = 0; sofar + Blen < offset; sofar += Blen){ 
		md = readdata(fs, bno, buf, 0); 
		if(md == 0) 
			error(Eio); 
		bno = GETS(md->bno); 
1996/0116    
	} 
	qlock(&tinyfs); 
	qunlock(&tinyfs); 
 
	switch(c->qid.path & ~CHDIR){ 
	case Qdata: 
		break; 
	default: 
		error(Ebadusefd); 
1996/0217    
	/* write data */ 
	offset = offset%Blen; 
	for(sofar = 0; sofar < n; sofar += i){ 
		md = readdata(fs, bno, buf, 0); 
		if(md == 0) 
			error(Eio); 
		i = Blen - offset; 
		if(i > n) 
			i = n; 
		memmove(p, a, i); 
		bno = GETS(md->bno); 
		offset = 0; 
1996/0116    
	} 
	return n; 
1996/0217    
 
	return sofar; 
1996/0116    
} 
 
long 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)