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

1993/1015/port/cache.c (diff list | history)

1993/1014/sys/src/9/port/cache.c:58,641993/1015/sys/src/9/port/cache.c:58,64 (short | long | prev | next)
1993/1014    
	cache.head = xalloc(sizeof(Mntcache)*NFILE); 
	m = cache.head; 
	 
	for(i = NFILE; i > 0; i++) { 
1993/1015    
	for(i = 0; i < NFILE; i++) { 
1993/1014    
		m->next = m+1; 
		m->prev = m-1; 
		m++; 
1993/1014/sys/src/9/port/cache.c:95,1071993/1015/sys/src/9/port/cache.c:95,108
1993/1013    
} 
 
void 
1993/1014    
cprint(Mntcache *m) 
1993/1015    
cprint(Mntcache *m, char *s) 
1993/1014    
{ 
	Extent *e; 
1993/1015    
return; 
	print("%s: 0x%lux.0x%lux %d %d\n", 
			s, m->path, m->vers, m->type, m->dev); 
1993/1014    
 
	print("%lux.%lux %d %d\n", m->path, m->vers, m->type, m->dev); 
                 
	while(e) 
1993/1015    
	for(e = m->list; e; e = e->next) 
1993/1014    
		print("\t%4d %5d %4d %lux\n", 
			e->bid, e->start, e->len, e->cache); 
} 
1993/1014/sys/src/9/port/cache.c:129,1401993/1015/sys/src/9/port/cache.c:130,143
1993/1014    
		n = e->next; 
1993/1013    
		free(e); 
	} 
1993/1015    
	m->list = 0; 
1993/1013    
} 
 
void 
ctail(Mntcache *m) 
1993/1015    
ctail(Mntcache *m, int dolock) 
1993/1013    
{ 
	lock(&cache); 
1993/1015    
	if(dolock) 
		lock(&cache); 
1993/1013    
 
	/* Unlink and send to the tail */ 
	if(m->prev)  
1993/1014/sys/src/9/port/cache.c:157,1631993/1015/sys/src/9/port/cache.c:160,167
1993/1013    
		m->prev = m->next = 0; 
	} 
 
	unlock(&cache); 
1993/1015    
	if(dolock) 
		unlock(&cache); 
1993/1013    
} 
 
void 
1993/1014/sys/src/9/port/cache.c:165,1781993/1015/sys/src/9/port/cache.c:169,190
1993/1013    
{ 
	Mntcache *m, *f, **l; 
 
1993/1015    
	if(c->qid.path & CHDIR) 
		return; 
 
1993/1013    
	m = clook(c); 
	if(m != 0) { 
1993/1015    
		c->mcp = m; 
		ctail(m, 1); 
 
1993/1013    
		/* File was updated */ 
1993/1014    
		if(m->vers != c->qid.vers) 
1993/1015    
		if(m->vers != c->qid.vers) { 
cprint(m, "copen mod"); 
1993/1013    
			cnodata(m); 
                 
		ctail(m); 
1993/1015    
			m->vers = c->qid.vers; 
		} 
1993/1013    
		qunlock(m); 
1993/1015    
cprint(m, "copen lru"); 
1993/1013    
		return; 
	} 
 
1993/1014/sys/src/9/port/cache.c:191,2041993/1015/sys/src/9/port/cache.c:203,218
1993/1013    
	l = &cache.hash[c->qid.path%NHASH]; 
	m->hash = *l; 
	*l = m; 
1993/1015    
	ctail(m, 0); 
1993/1014    
	unlock(&cache); 
1993/1015    
 
1993/1014    
	m->Qid = c->qid; 
1993/1013    
	m->dev = c->dev; 
	m->type = c->type; 
	cnodata(m); 
	ctail(m); 
	c->mcp = m; 
	qunlock(m); 
1993/1015    
cprint(m, "copen new"); 
1993/1013    
} 
 
static int 
1993/1014/sys/src/9/port/cache.c:224,2321993/1015/sys/src/9/port/cache.c:238,250
1993/1014    
	Extent *e, **t; 
	int o, l, total, end; 
1993/1013    
 
1993/1015    
	if(c->qid.path & CHDIR) 
		return 0; 
 
1993/1013    
	m = c->mcp; 
	if(m == 0) 
		return 0; 
1993/1015    
 
1993/1013    
	qlock(m); 
	if(cdev(m, c) == 0) { 
		qunlock(m); 
1993/1014/sys/src/9/port/cache.c:306,3171993/1015/sys/src/9/port/cache.c:324,336
1993/1014    
			free(e); 
			break; 
		} 
		e->cache = p; 
		e->start = offset; 
		l = len; 
		if(l > BY2PG) 
			l = BY2PG; 
 
1993/1015    
		e->cache = p; 
		e->start = offset; 
		e->len = l; 
1993/1014    
		e->bid = incref(&cache); 
		p->daddr = e->bid; 
		k = kmap(p); 
1993/1014/sys/src/9/port/cache.c:341,3461993/1015/sys/src/9/port/cache.c:360,366
1993/1014    
	p = cpage(e); 
	if(p == 0) 
		return 0; 
1993/1015    
 
1993/1014    
	k = kmap(p); 
	memmove((uchar*)VA(k)+boff, buf, len); 
	kunmap(k); 
1993/1014/sys/src/9/port/cache.c:355,3651993/1015/sys/src/9/port/cache.c:375,388
1993/1013    
	Mntcache *m; 
1993/1014    
	Extent *tail; 
	Extent *e, *f, *p; 
	int o, ee, eblock;  
1993/1015    
	int o, ee, eblock; 
1993/1013    
 
	if(offset > MAXCACHE) 
1993/1015    
	if(c->qid.path & CHDIR) 
1993/1013    
		return; 
 
1993/1015    
	if(offset > MAXCACHE || len == 0) 
		return; 
 
1993/1013    
	m = c->mcp; 
	if(m == 0) 
		return; 
1993/1014/sys/src/9/port/cache.c:378,3831993/1015/sys/src/9/port/cache.c:401,407
1993/1014    
			break; 
		p = f; 
	} 
1993/1015    
 
1993/1014    
	if(p == 0) {		/* at the head */ 
		eblock = offset+len; 
		/* trim if there is a successor */ 
1993/1014/sys/src/9/port/cache.c:418,4251993/1015/sys/src/9/port/cache.c:442,449
1993/1014    
			qunlock(m); 
1993/1013    
			return; 
1993/1014    
		} 
		if(cpgmove(e, buf, p->len, o)) { 
			e->len += o; 
1993/1015    
		if(cpgmove(p, buf, p->len, o)) { 
			p->len += o; 
1993/1014    
			buf += o; 
			len -= o; 
			offset += o; 
1993/1014/sys/src/9/port/cache.c:448,4541993/1015/sys/src/9/port/cache.c:472,478
1993/1014    
		len -= o; 
	} 
 
	/* Insert a middle block */ 
1993/1015    
	/* insert a middle block */ 
1993/1014    
	p->next = cchain(buf, offset, len, &tail); 
	if(p->next == 0) 
		p->next = f; 
1993/1014/sys/src/9/port/cache.c:456,4591993/1015/sys/src/9/port/cache.c:480,542
1993/1014    
		tail->next = f; 
 
	qunlock(m); 
1993/1015    
} 
 
void 
cwrite(Chan* c, uchar *buf, int len, ulong offset) 
{ 
	int o; 
	Mntcache *m; 
	ulong eblock, ee; 
	Extent *p, *f, *e, *tail; 
 
	if(offset > MAXCACHE || len == 0) 
		return; 
 
	m = c->mcp; 
	if(m == 0) 
		return; 
 
	qlock(m); 
	if(cdev(m, c) == 0) { 
		qunlock(m); 
		return; 
	} 
 
	m->vers++; 
 
	p = 0; 
	for(f = m->list; f; f = f->next) { 
		if(offset >= f->start) 
			break; 
		p = f;		 
	} 
 
	if(p != 0) { 
		ee = p->start+p->len; 
		if(ee > offset) { 
			o = ee - offset; 
			p->len -= o; 
			if(p->len) 
				panic("del empty extent"); 
		} 
	} 
 
	eblock = offset+len; 
	/* free the overlap - its a rare case */ 
	while(f && f->start < eblock) { 
		e = f->next; 
		free(f); 
		f = e; 
	} 
 
	e = cchain(buf, offset, len, &tail); 
	if(p == 0) 
		m->list = e; 
	else 
		p->next = e; 
	if(tail != 0) 
		tail->next = f; 
	qunlock(m); 
cprint(m, "cwrite"); 
1993/1011    
} 


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