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

1999/1227/port/cache.c (diff list | history)

1999/1101/sys/src/9/port/cache.c:483,5081999/1227/sys/src/9/port/cache.c:483,508 (short | long | prev | next)
1998/0327    
	offset = off; 
1993/1014    
	p = 0; 
	for(f = m->list; f; f = f->next) { 
		if(f->start >= offset) 
1999/1227    
		if(f->start > offset) 
1993/1014    
			break; 
		p = f; 
	} 
1993/1015    
 
1993/1014    
	if(p == 0) {		/* at the head */ 
		eblock = offset+len; 
		/* trim if there is a successor */ 
		if(f != 0 && eblock >= f->start) { 
			len -= (eblock - f->start); 
			if(len <= 0) { 
				qunlock(m); 
				return; 
			} 
1999/1227    
	/* trim if there is a successor */ 
	eblock = offset+len; 
	if(f != 0 && eblock > f->start) { 
		len -= (eblock - f->start); 
		if(len <= 0) { 
			qunlock(m); 
			return; 
1993/1014    
		} 
1999/1227    
	} 
 
	if(p == 0) {		/* at the head */ 
1993/1014    
		e = cchain(buf, offset, len, &tail); 
1993/1016    
		if(e != 0) { 
			m->list = e; 
			if(tail != 0) 
				tail->next = f; 
1999/1227    
			tail->next = f; 
1993/1016    
		} 
1993/1014    
		qunlock(m); 
		return; 
1999/1101/sys/src/9/port/cache.c:532,5371999/1227/sys/src/9/port/cache.c:532,538
1993/1014    
			len -= o; 
			offset += o; 
			if(len <= 0) { 
1999/1227    
if (f && p->start + p->len > f->start) print("CACHE: p->start=%uld p->len=%d f->start=%uld\n", p->start, p->len, f->start); 
1993/1014    
				qunlock(m); 
				return; 
			} 
1999/1101/sys/src/9/port/cache.c:538,5681999/1227/sys/src/9/port/cache.c:539,549
1993/1014    
		} 
1993/1013    
	} 
1993/1014    
 
	/* append to extent list */ 
	if(f == 0) { 
		p->next = cchain(buf, offset, len, &tail); 
		qunlock(m); 
		return; 
	} 
                 
	/* trim data against successor */ 
	eblock = offset+len; 
	if(eblock > f->start) { 
		o = eblock - f->start; 
1993/1016    
		len -= o; 
		if(len <= 0) { 
1993/1014    
			qunlock(m); 
			return; 
		} 
	} 
                 
1993/1015    
	/* insert a middle block */ 
1993/1014    
	p->next = cchain(buf, offset, len, &tail); 
	if(p->next == 0) 
		p->next = f; 
	else 
1999/1227    
	e = cchain(buf, offset, len, &tail); 
	if(e != 0) { 
		p->next = e; 
1993/1014    
		tail->next = f; 
                 
1999/1227    
	} 
1993/1014    
	qunlock(m); 
1993/1015    
} 
 
1999/1101/sys/src/9/port/cache.c:569,5751999/1227/sys/src/9/port/cache.c:550,556
1993/1015    
void 
1998/0327    
cwrite(Chan* c, uchar *buf, int len, vlong off) 
1993/1015    
{ 
1996/0326    
	int o, n; 
1999/1227    
	int o, eo; 
1993/1015    
	Mntcache *m; 
	ulong eblock, ee; 
	Extent *p, *f, *e, *tail; 
1999/1101/sys/src/9/port/cache.c:599,6481999/1227/sys/src/9/port/cache.c:580,605
1998/0512    
		p = f; 
1996/0326    
	} 
 
1996/0402    
	if(0 && f != 0 && offset < f->start+f->len) { 
1996/0326    
		o = offset - f->start; 
1996/0329    
		n = f->len - o; 
		if(n > len) 
			n = len; 
		if(cpgmove(f, buf, o, n)) { 
			len -= n; 
			if(len == 0) { 
				qunlock(m); 
				return; 
			} 
			offset += n; 
			buf += n; 
1996/0326    
		} 
1993/1015    
	} 
                 
	if(p != 0) { 
		ee = p->start+p->len; 
		if(ee > offset) { 
			o = ee - offset; 
			p->len -= o; 
1993/1016    
			if(p->len == 0) 
1993/1015    
				panic("del empty extent"); 
		} 
1993/1018    
		/* Pack sequential write if there is space */ 
1993/1017    
		if(ee == offset && p->len < BY2PG) { 
1999/1227    
		eo = offset - p->start; 
		/* pack in predecessor if there is space */ 
		if(offset <= ee && eo < BY2PG) { 
1993/1017    
			o = len; 
			if(o > BY2PG - p->len) 
				o = BY2PG - p->len; 
			if(cpgmove(p, buf, p->len, o)) { 
				p->len += o; 
1999/1227    
			if(o > BY2PG - eo) 
				o = BY2PG - eo; 
			if(cpgmove(p, buf, eo, o)) { 
				if(eo+o > p->len) 
					p->len = eo+o; 
1993/1017    
				buf += o; 
				len -= o; 
				offset += o; 
				if(len <= 0) { 
					qunlock(m); 
					return; 
				} 
			} 
		} 
1993/1015    
	} 
 
1999/1227    
	/* free the overlap -- it's a rare case */ 
1993/1015    
	eblock = offset+len; 
	/* free the overlap - its a rare case */ 
	while(f && f->start < eblock) { 
		e = f->next; 
1999/0508    
		extentfree(f); 
1999/1101/sys/src/9/port/cache.c:649,6631999/1227/sys/src/9/port/cache.c:606,621
1993/1015    
		f = e; 
	} 
 
1999/1227    
	/* link the block (if any) into the middle */ 
1993/1015    
	e = cchain(buf, offset, len, &tail); 
1993/1016    
	if(e != 0) { 
		if(p == 0) 
			m->list = e; 
		else 
			p->next = e; 
1993/1022    
                 
1993/1016    
		if(tail != 0) 
			tail->next = f; 
1999/1227    
		tail->next = f; 
		f = e; 
1993/1016    
	} 
1999/1227    
 
	if(p == 0) 
		m->list = f; 
	else 
		p->next = f; 
1993/1015    
	qunlock(m); 
1993/1011    
} 


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