Example #1
0
__private_extern__ int
readdirs_9p(mount_9p *nmp, fid_9p fid, dir_9p **d, uint32_t *nd)
{
	uint8_t *p, *newp;
	uint32_t n;
	int e, ts;

	TRACE();
	*d = NULL;
	*nd = 0;
	ts = 0;
	p = NULL;
	for (;;) {
		newp = malloc_9p(ts+DIRMAX);
		if (newp == NULL) {
			e = ENOMEM;
			break;
		}
		bcopy(p, newp, ts);
		free_9p(p);
		p = newp;
		if ((e=read_9p(nmp, fid, p+ts, DIRMAX, ts, &n)) || n==0)
			break;
		ts += n;
	}

	if (!e)
		e = dirpackage(p, ts, d, nd, ISSET(nmp->flags, F_DOTU));

	free_9p(p);
	return e;
}
Example #2
0
static int
nread_9p(node_9p *np, uio_t uio)
{
	openfid_9p *op;
	uint32_t n, l, sz;
	char *p;
	int e;

	TRACE();
	op = &np->openfid[OREAD];
	if (op->fid == NOFID)
		op = &np->openfid[ORDWR];
	if (op->fid == NOFID)
		return EBADF;

	sz = np->iounit;
	if (sz == 0)
		sz = np->nmp->msize-IOHDRSZ;

	p = malloc_9p(sz);
	if (p == NULL)
		return ENOMEM;

	e = 0;
	while (uio_resid(uio) > 0) {
		n = MIN(uio_resid(uio), sz);
		if ((e=read_9p(np->nmp, op->fid, p, n, uio_offset(uio), &l)) || l==0)
			break;
		if ((e=uiomove(p, l, uio)))
			break;
	}
	free_9p(p);
	return e;
}
Example #3
0
__private_extern__ int
readdir_9p(mount_9p *nmp, fid_9p fid, off_t off, dir_9p **d, uint32_t *nd, uint32_t *nrd)
{
	void *p;
	int e;
	
	TRACE();
	*d = NULL;
	*nd = 0;
	*nrd = 0;
	p = malloc_9p(DIRMAX);
	if (p == NULL)
		return ENOMEM;

	e = read_9p(nmp, fid, p, DIRMAX, off, nrd);
	if (!e)
		e = dirpackage(p, *nrd, d, nd, ISSET(nmp->flags, F_DOTU));
	free_9p(p);
	return e;
}