FreeBSD/lib/libstand/nfs.c
/*
 * Read data from a file.
 * Return transfer count or -1 (and set errno)
 */
Read data from a file.
Return transfer count or -1 (and set errno)
Read data from a file . Return transfer count or - 1 ( and set errno )
ssize_t
nfs_readdata(struct nfs_iodesc *d, off_t off, void *addr, size_t len)
{
	struct nfs_read_args *args;
	struct nfs_read_repl *repl;
	struct {
		n_long	h[RPC_HEADER_WORDS];
		struct nfs_read_args d;
	} sdata;
	struct {
		n_long	h[RPC_HEADER_WORDS];
		struct nfs_read_repl d;
	} rdata;
	size_t cc;
	long x;
	int hlen, rlen;
	args = &sdata.d;
	repl = &rdata.d;
	bcopy(d->fh, args->fh, NFS_FHSIZE);
	args->off = htonl((n_long)off);
	if (len > NFSREAD_SIZE)
		len = NFSREAD_SIZE;
	args->len = htonl((n_long)len);
	args->xxx = htonl((n_long)0);
	hlen = sizeof(*repl) - NFSREAD_SIZE;
	cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READ,
	    args, sizeof(*args),
	    repl, sizeof(*repl));
	if (cc == -1) {
		return (-1);
	}
	if (cc < hlen) {
		errno = EBADRPC;
		return (-1);
	}
	if (repl->errno) {
		errno = ntohl(repl->errno);
		return (-1);
	}
	rlen = cc - hlen;
	x = ntohl(repl->count);
	if (rlen < x) {
		printf("nfsread: short packet, %d < %ld\n", rlen, x);
		errno = EBADRPC;
		return(-1);
	}
	bcopy(repl->data, addr, x);
	return (x);
}
ssize_t nfs_readdata ( struct nfs_iodesc * d , off_t off , void * addr , size_t len ) { struct nfs_read_args * args ; struct nfs_read_repl * repl ; struct { n_long h [ RPC_HEADER_WORDS ] ; struct nfs_read_args d ; } sdata ; struct { n_long h [ RPC_HEADER_WORDS ] ; struct nfs_read_repl d ; } rdata ; size_t cc ; long x ; int hlen , rlen ; args = & sdata . d ; repl = & rdata . d ; bcopy ( d -> fh , args -> fh , NFS_FHSIZE ) ; args -> off = htonl ( ( n_long ) off ) ; if ( len > NFSREAD_SIZE ) len = NFSREAD_SIZE ; args -> len = htonl ( ( n_long ) len ) ; args -> xxx = htonl ( ( n_long ) 0 ) ; hlen = sizeof ( * repl ) - NFSREAD_SIZE ; cc = rpc_call ( d -> iodesc , NFS_PROG , NFS_VER2 , NFSPROC_READ , args , sizeof ( * args ) , repl , sizeof ( * repl ) ) ; if ( cc == -1 ) { return ( -1 ) ; } if ( cc < hlen ) { errno = EBADRPC ; return ( -1 ) ; } if ( repl -> errno ) { errno = ntohl ( repl -> errno ) ; return ( -1 ) ; } rlen = cc - hlen ; x = ntohl ( repl -> count ) ; if ( rlen < x ) { printf ( " \n " , rlen , x ) ; errno = EBADRPC ; return ( -1 ) ; } bcopy ( repl -> data , addr , x ) ; return ( x ) ; }
Read data from a file.
Read data from a file .
/* errno was already set by rpc_call */