~kris/9p

9hist

abf0ec9b801664f280f4c7da37110ac638086fdc — David du Colombier 30 years ago f21be7f
Plan 9 from Bell Labs 1996-02-03
2 files changed, 77 insertions(+), 31 deletions(-)

M pc/main.c
M port/devtinyfs.c
M pc/main.c => pc/main.c +38 -7
@@ 354,29 354,60 @@ romscan(void)
	}
}

static int
getcfields(char *lp, char **fields, int n, char sep)
{
	int i;

	for(i=0; lp && *lp && i<n; i++){
		while(*lp == sep)
			*lp++=0;
		if(*lp == 0)
			break;
		fields[i]=lp;
		while(*lp && *lp != sep){
			if(*lp == '\\' && *(lp+1) == '\n')
				*lp++ = ' ';
			lp++;
		}
	}
	return i;
}

void
confinit(void)
{
	long x, i, j, n;
	int pcnt;
	ulong ktop;
	char *cp;
	char *line[MAXCONF];
	char *cp, *line[MAXCONF], *p, *q;
	extern int defmaxmsg;

	pcnt = 0;


	/*
	 *  parse configuration args from dos file plan9.ini
	 */
	cp = BOOTARGS;	/* where b.com leaves its config */
	cp[BOOTARGSLEN-1] = 0;
	n = getfields(cp, line, MAXCONF, "\n");

	/*
	 * Strip out '\r', change '\t' -> ' '.
	 */
	p = cp;
	for(q = cp; *q; q++){
		if(*q == '\r')
			continue;
		if(*q == '\t')
			*q = ' ';
		*p++ = *q;
	}
	*p = 0;

	n = getcfields(cp, line, MAXCONF, '\n');
	for(j = 0; j < n; j++){
		cp = strchr(line[j], '\r');
		if(cp)
			*cp = 0;
		if(*line[j] == '#')
			continue;
		cp = strchr(line[j], '=');
		if(cp == 0)
			continue;

M port/devtinyfs.c => port/devtinyfs.c +39 -24
@@ 28,6 28,9 @@ enum{

	Notapin=		0xffff,
	Notabno=		0xffff,

	Fcreating=	1,
	Frmonclose=	2,
};

/* representation of a Tdir on medium */


@@ 57,7 60,7 @@ struct Tfile {
	ushort	bno;
	ushort	dbno;
	ushort	pin;
	char	creating;
	uchar	flag;
	ulong	length;
};



@@ 271,7 274,7 @@ newfile(Tfs *fs, char *name)
		expand(fs);
	}

	f->creating = 1;
	f->flag = Fcreating;
	f->dbno = Notabno;
	f->bno = mapalloc(fs);



@@ 553,20 556,31 @@ tinyfsclose(Chan *c)
	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);
		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);
			}
			if(f->flag & Frmonclose){
				freefile(fs, f, Notabno);
		}
	}

	/* dereference fs and remove on zero refs */
	fs->r--;
	unlock(fs);
	qlock(&tinyfs);
	if(fs->ref == 0){
		for(l = &fs->l; *l;){
			if(*l == fs){


@@ 575,30 589,31 @@ tinyfsclose(Chan *c)
			}
			l = &(*l)->next;
		}
		for(f = fs->f; f; f = nf){
			nf = f->next;
			free(f);
		}
		free(fs-f);
		free(fs->map);
		close(fs->c);
		free(fs);
		memset(fs, 0, sizeof(*fs));
	}
	unlock(fs);
	qunlock(&tinyfs);
}

long
tinyfsread(Chan *c, void *a, long n, ulong offset)
{
	switch(c->qid.path & ~CHDIR){
	case Qdir:
	Tfs *fs;
	Tfile *f;
	int sofar, i;

	if(c->qid.path & CHDIR)
		return devdirread(c, a, n, tinyfstab, Ntinyfstab, tinyfsgen);
	case Qdata:
		break;
	default:
		n=0;
		break;
	}

	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;

	return n;
}