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

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

1996/0202/sys/src/9/port/devtinyfs.c:28,331996/0203/sys/src/9/port/devtinyfs.c:28,36 (short | long | prev | next)
1996/0201    
 
1996/0202    
	Notapin=		0xffff, 
	Notabno=		0xffff, 
1996/0203    
 
	Fcreating=	1, 
	Frmonclose=	2, 
1996/0116    
}; 
 
1996/0202    
/* representation of a Tdir on medium */ 
1996/0202/sys/src/9/port/devtinyfs.c:57,631996/0203/sys/src/9/port/devtinyfs.c:60,66
1996/0201    
	ushort	bno; 
	ushort	dbno; 
	ushort	pin; 
1996/0202    
	char	creating; 
1996/0203    
	uchar	flag; 
1996/0201    
	ulong	length; 
}; 
 
1996/0202/sys/src/9/port/devtinyfs.c:271,2771996/0203/sys/src/9/port/devtinyfs.c:274,280
1996/0202    
		expand(fs); 
	} 
 
	f->creating = 1; 
1996/0203    
	f->flag = Fcreating; 
1996/0202    
	f->dbno = Notabno; 
	f->bno = mapalloc(fs); 
 
1996/0202/sys/src/9/port/devtinyfs.c:553,5721996/0203/sys/src/9/port/devtinyfs.c:556,586
1996/0202    
	if(c->qid.path != CHDIR){ 
		f = &fs->f[c->qid.path]; 
		f->r--; 
		if(f->r == 0 && f->creating){ 
			/* remove all other files with this name */ 
			for(i = 0; i < fs->fsize; i++){ 
				nf = &fs->f[i]; 
				if(f == nf) 
					continue; 
				if(strcmp(nf->name, f->name) == 0) 
					freefile(fs, nf, Notabno); 
1996/0203    
		if(f->r == 0){ 
			if(f->creating){ 
				/* remove all other files with this name */ 
				for(i = 0; i < fs->fsize; i++){ 
					nf = &fs->f[i]; 
					if(f == nf) 
						continue; 
					if(strcmp(nf->name, f->name) == 0){ 
						if(nf->r) 
							nf->flag |= Frmonclose; 
						else 
							freefile(fs, nf, Notabno); 
					} 
				} 
				f->flag &= ~(Frmonclose|Fcreating); 
1996/0202    
			} 
1996/0203    
			if(f->flag & Frmonclose){ 
				freefile(fs, f, Notabno); 
1996/0202    
		} 
	} 
 
	/* dereference fs and remove on zero refs */ 
	fs->r--; 
1996/0203    
	unlock(fs); 
	qlock(&tinyfs); 
1996/0201    
	if(fs->ref == 0){ 
		for(l = &fs->l; *l;){ 
			if(*l == fs){ 
1996/0202/sys/src/9/port/devtinyfs.c:575,5891996/0203/sys/src/9/port/devtinyfs.c:589,599
1996/0201    
			} 
			l = &(*l)->next; 
		} 
		for(f = fs->f; f; f = nf){ 
			nf = f->next; 
			free(f); 
		} 
1996/0203    
		free(fs-f); 
1996/0201    
		free(fs->map); 
		close(fs->c); 
		free(fs); 
1996/0203    
		memset(fs, 0, sizeof(*fs)); 
1996/0201    
	} 
	unlock(fs); 
	qunlock(&tinyfs); 
1996/0116    
} 
 
1996/0202/sys/src/9/port/devtinyfs.c:590,6041996/0203/sys/src/9/port/devtinyfs.c:600,619
1996/0116    
long 
tinyfsread(Chan *c, void *a, long n, ulong offset) 
{ 
	switch(c->qid.path & ~CHDIR){ 
	case Qdir: 
1996/0203    
	Tfs *fs; 
	Tfile *f; 
	int sofar, i; 
 
	if(c->qid.path & CHDIR) 
1996/0201    
		return devdirread(c, a, n, tinyfstab, Ntinyfstab, tinyfsgen); 
1996/0116    
	case Qdata: 
		break; 
	default: 
		n=0; 
		break; 
	} 
1996/0203    
 
	fs = tinyfs.fs[c->dev]; 
	f = &fs->f[c->qid.path]; 
	if(offset >= f->length) 
		return 0; 
	if(n + offset >= f->length) 
		n = f->length - offset; 
 
1996/0116    
	return n; 
} 
 


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