1995-09-23 07:36:06 +04:00
|
|
|
/* $NetBSD: nfs.c,v 1.12 1995/09/23 03:36:08 gwr Exp $ */
|
1994-10-26 08:44:32 +03:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1993 John Brezak
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
|
|
|
|
#include <nfs/rpcv2.h>
|
|
|
|
#include <nfs/nfsv2.h>
|
1995-02-20 14:04:00 +03:00
|
|
|
#include <nfs/xdr_subs.h>
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#include "stand.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "netif.h"
|
|
|
|
#include "nfs.h"
|
|
|
|
#include "rpc.h"
|
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
/* Define our own NFS attributes without NQNFS stuff. */
|
|
|
|
struct nfsv2_fattrs {
|
|
|
|
n_long fa_type;
|
|
|
|
n_long fa_mode;
|
|
|
|
n_long fa_nlink;
|
|
|
|
n_long fa_uid;
|
|
|
|
n_long fa_gid;
|
|
|
|
n_long fa_size;
|
|
|
|
n_long fa_blocksize;
|
|
|
|
n_long fa_rdev;
|
|
|
|
n_long fa_blocks;
|
|
|
|
n_long fa_fsid;
|
|
|
|
n_long fa_fileid;
|
|
|
|
struct nfsv2_time fa_atime;
|
|
|
|
struct nfsv2_time fa_mtime;
|
|
|
|
struct nfsv2_time fa_ctime;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct nfs_read_args {
|
1994-05-08 20:11:14 +04:00
|
|
|
u_char fh[NFS_FHSIZE];
|
1995-06-27 19:25:30 +04:00
|
|
|
n_long off;
|
|
|
|
n_long len;
|
|
|
|
n_long xxx; /* XXX what's this for? */
|
1994-05-08 20:11:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Data part of nfs rpc reply (also the largest thing we receive) */
|
1995-06-27 19:25:30 +04:00
|
|
|
#define NFSREAD_SIZE 1024
|
|
|
|
struct nfs_read_repl {
|
|
|
|
n_long errno;
|
|
|
|
struct nfsv2_fattrs fa;
|
|
|
|
n_long count;
|
|
|
|
u_char data[NFSREAD_SIZE];
|
1994-05-08 20:11:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct nfs_iodesc {
|
|
|
|
struct iodesc *iodesc;
|
1995-06-27 19:25:30 +04:00
|
|
|
off_t off;
|
|
|
|
u_char fh[NFS_FHSIZE];
|
|
|
|
struct nfsv2_fattrs fa; /* all in network order */
|
1994-05-08 20:11:14 +04:00
|
|
|
};
|
|
|
|
|
1995-07-03 08:56:33 +04:00
|
|
|
struct nfs_iodesc nfs_root_node;
|
1995-06-27 19:25:30 +04:00
|
|
|
|
|
|
|
|
1995-09-23 07:36:06 +04:00
|
|
|
/*
|
|
|
|
* Fetch the root file handle (call mount daemon)
|
|
|
|
* On error, return non-zero and set errno.
|
|
|
|
*/
|
1995-06-27 19:25:30 +04:00
|
|
|
int
|
|
|
|
nfs_getrootfh(d, path, fhp)
|
1994-05-08 20:11:14 +04:00
|
|
|
register struct iodesc *d;
|
|
|
|
char *path;
|
|
|
|
u_char *fhp;
|
|
|
|
{
|
|
|
|
register int len;
|
1995-06-27 19:25:30 +04:00
|
|
|
struct args {
|
|
|
|
n_long len;
|
1994-05-08 20:11:14 +04:00
|
|
|
char path[FNAME_SIZE];
|
1995-06-27 19:25:30 +04:00
|
|
|
} *args;
|
|
|
|
struct repl {
|
|
|
|
n_long errno;
|
1994-05-08 20:11:14 +04:00
|
|
|
u_char fh[NFS_FHSIZE];
|
1995-06-27 19:25:30 +04:00
|
|
|
} *repl;
|
|
|
|
struct {
|
|
|
|
n_long h[RPC_HEADER_WORDS];
|
|
|
|
struct args d;
|
|
|
|
} sdata;
|
|
|
|
struct {
|
|
|
|
n_long h[RPC_HEADER_WORDS];
|
|
|
|
struct repl d;
|
|
|
|
} rdata;
|
1995-02-20 14:04:00 +03:00
|
|
|
size_t cc;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1995-06-27 19:25:30 +04:00
|
|
|
printf("nfs_getrootfh: %s\n", path);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
1995-02-20 14:04:00 +03:00
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
args = &sdata.d;
|
|
|
|
repl = &rdata.d;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
bzero(args, sizeof(*args));
|
|
|
|
len = strlen(path);
|
|
|
|
if (len > sizeof(args->path))
|
|
|
|
len = sizeof(args->path);
|
|
|
|
args->len = htonl(len);
|
|
|
|
bcopy(path, args->path, len);
|
|
|
|
len = 4 + roundup(len, 4);
|
|
|
|
|
|
|
|
cc = rpc_call(d, RPCPROG_MNT, RPCMNT_VER1, RPCMNT_MOUNT,
|
|
|
|
args, len, repl, sizeof(*repl));
|
1995-09-23 07:36:06 +04:00
|
|
|
if (cc == -1) {
|
|
|
|
/* errno was set by rpc_call */
|
1995-02-20 14:04:00 +03:00
|
|
|
return (-1);
|
1995-09-23 07:36:06 +04:00
|
|
|
}
|
|
|
|
if (cc < 4) {
|
|
|
|
errno = EBADRPC;
|
|
|
|
return (-1);
|
|
|
|
}
|
1995-06-27 19:25:30 +04:00
|
|
|
if (repl->errno) {
|
|
|
|
errno = ntohl(repl->errno);
|
1995-02-20 14:04:00 +03:00
|
|
|
return (-1);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
1995-06-27 19:25:30 +04:00
|
|
|
bcopy(repl->fh, fhp, sizeof(repl->fh));
|
|
|
|
return (0);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
1995-09-23 07:36:06 +04:00
|
|
|
/*
|
|
|
|
* Lookup a file. Store handle and attributes.
|
|
|
|
* Return zero or error number.
|
|
|
|
*/
|
1995-06-27 19:25:30 +04:00
|
|
|
int
|
|
|
|
nfs_lookupfh(d, name, newfd)
|
1994-05-08 20:11:14 +04:00
|
|
|
struct nfs_iodesc *d;
|
|
|
|
char *name;
|
1995-06-27 19:25:30 +04:00
|
|
|
struct nfs_iodesc *newfd;
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
|
|
|
register int len, rlen;
|
1995-06-27 19:25:30 +04:00
|
|
|
struct args {
|
1994-05-08 20:11:14 +04:00
|
|
|
u_char fh[NFS_FHSIZE];
|
1995-06-27 19:25:30 +04:00
|
|
|
n_long len;
|
1994-05-08 20:11:14 +04:00
|
|
|
char name[FNAME_SIZE];
|
1995-06-27 19:25:30 +04:00
|
|
|
} *args;
|
|
|
|
struct repl {
|
|
|
|
n_long errno;
|
1994-05-08 20:11:14 +04:00
|
|
|
u_char fh[NFS_FHSIZE];
|
1995-06-27 19:25:30 +04:00
|
|
|
struct nfsv2_fattrs fa;
|
|
|
|
} *repl;
|
|
|
|
struct {
|
|
|
|
n_long h[RPC_HEADER_WORDS];
|
|
|
|
struct args d;
|
|
|
|
} sdata;
|
|
|
|
struct {
|
|
|
|
n_long h[RPC_HEADER_WORDS];
|
|
|
|
struct repl d;
|
|
|
|
} rdata;
|
1995-09-15 03:45:21 +04:00
|
|
|
ssize_t cc;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1995-02-20 14:04:00 +03:00
|
|
|
printf("lookupfh: called\n");
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
args = &sdata.d;
|
|
|
|
repl = &rdata.d;
|
1995-02-20 14:04:00 +03:00
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
bzero(args, sizeof(*args));
|
|
|
|
bcopy(d->fh, args->fh, sizeof(args->fh));
|
|
|
|
len = strlen(name);
|
|
|
|
if (len > sizeof(args->name))
|
|
|
|
len = sizeof(args->name);
|
|
|
|
bcopy(name, args->name, len);
|
|
|
|
args->len = htonl(len);
|
|
|
|
len = 4 + roundup(len, 4);
|
|
|
|
len += NFS_FHSIZE;
|
|
|
|
|
|
|
|
rlen = sizeof(*repl);
|
|
|
|
|
|
|
|
cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_LOOKUP,
|
|
|
|
args, len, repl, rlen);
|
1995-09-23 07:36:06 +04:00
|
|
|
if (cc == -1)
|
|
|
|
return (errno); /* XXX - from rpc_call */
|
1995-06-27 19:25:30 +04:00
|
|
|
if (cc < 4)
|
|
|
|
return (EIO);
|
|
|
|
if (repl->errno) {
|
1995-09-23 07:36:06 +04:00
|
|
|
/* saerrno.h now matches NFS error numbers. */
|
|
|
|
return (ntohl(repl->errno));
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
1995-06-27 19:25:30 +04:00
|
|
|
bcopy( repl->fh, &newfd->fh, sizeof(newfd->fh));
|
|
|
|
bcopy(&repl->fa, &newfd->fa, sizeof(newfd->fa));
|
1994-05-08 20:11:14 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-09-23 07:36:06 +04:00
|
|
|
/*
|
|
|
|
* Read data from a file.
|
|
|
|
* Return transfer count or -1 (and set errno)
|
|
|
|
*/
|
1995-09-15 03:45:21 +04:00
|
|
|
ssize_t
|
1995-06-27 19:25:30 +04:00
|
|
|
nfs_readdata(d, off, addr, len)
|
|
|
|
struct nfs_iodesc *d;
|
|
|
|
off_t off;
|
|
|
|
void *addr;
|
|
|
|
size_t len;
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
1995-06-27 19:25:30 +04:00
|
|
|
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;
|
1995-02-20 14:04:00 +03:00
|
|
|
size_t cc;
|
1995-09-15 03:45:21 +04:00
|
|
|
long x;
|
|
|
|
int hlen, rlen;
|
1995-06-27 19:25:30 +04:00
|
|
|
|
|
|
|
args = &sdata.d;
|
|
|
|
repl = &rdata.d;
|
1995-02-20 14:04:00 +03:00
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
bcopy(d->fh, args->fh, NFS_FHSIZE);
|
|
|
|
args->off = txdr_unsigned(off);
|
1995-02-20 14:04:00 +03:00
|
|
|
if (len > NFSREAD_SIZE)
|
|
|
|
len = NFSREAD_SIZE;
|
1995-06-27 19:25:30 +04:00
|
|
|
args->len = txdr_unsigned(len);
|
|
|
|
args->xxx = txdr_unsigned(0);
|
|
|
|
hlen = sizeof(*repl) - NFSREAD_SIZE;
|
|
|
|
|
|
|
|
cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READ,
|
|
|
|
args, sizeof(*args),
|
|
|
|
repl, sizeof(*repl));
|
1995-09-23 07:36:06 +04:00
|
|
|
if (cc == -1) {
|
|
|
|
/* errno was already set by rpc_call */
|
|
|
|
return (-1);
|
|
|
|
}
|
1995-09-15 03:45:21 +04:00
|
|
|
if (cc < hlen) {
|
1995-09-23 07:36:06 +04:00
|
|
|
errno = EBADRPC;
|
1995-02-20 14:04:00 +03:00
|
|
|
return (-1);
|
1995-09-15 03:45:21 +04:00
|
|
|
}
|
1995-06-27 19:25:30 +04:00
|
|
|
if (repl->errno) {
|
|
|
|
errno = ntohl(repl->errno);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
rlen = cc - hlen;
|
|
|
|
x = ntohl(repl->count);
|
|
|
|
if (rlen < x) {
|
|
|
|
printf("nfsread: short packet, %d < %d\n", rlen, x);
|
1995-09-15 03:45:21 +04:00
|
|
|
errno = EBADRPC;
|
1995-06-27 19:25:30 +04:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
bcopy(repl->data, addr, x);
|
|
|
|
return (x);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nfs_mount - mount this nfs filesystem to a host
|
1995-09-23 07:36:06 +04:00
|
|
|
* On error, return non-zero and set errno.
|
1994-05-08 20:11:14 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfs_mount(sock, ip, path)
|
|
|
|
int sock;
|
1995-09-19 01:19:18 +04:00
|
|
|
struct in_addr ip;
|
1994-05-08 20:11:14 +04:00
|
|
|
char *path;
|
|
|
|
{
|
|
|
|
struct iodesc *desc;
|
1995-07-03 08:56:33 +04:00
|
|
|
struct nfsv2_fattrs *fa;
|
1995-06-27 19:25:30 +04:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
if (!(desc = socktodesc(sock))) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
/* Bind to a reserved port. */
|
|
|
|
desc->myport = htons(--rpc_port);
|
|
|
|
desc->destip = ip;
|
|
|
|
if (nfs_getrootfh(desc, path, nfs_root_node.fh))
|
|
|
|
return (-1);
|
|
|
|
nfs_root_node.iodesc = desc;
|
1995-07-03 08:56:33 +04:00
|
|
|
/* Fake up attributes for the root dir. */
|
|
|
|
fa = &nfs_root_node.fa;
|
|
|
|
fa->fa_type = htonl(NFDIR);
|
|
|
|
fa->fa_mode = htonl(0755);
|
|
|
|
fa->fa_nlink = htonl(2);
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1995-06-27 19:25:30 +04:00
|
|
|
printf("nfs_mount: got fh for %s\n", path);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a file.
|
1995-09-23 07:36:06 +04:00
|
|
|
* return zero or error number
|
1994-05-08 20:11:14 +04:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfs_open(path, f)
|
|
|
|
char *path;
|
|
|
|
struct open_file *f;
|
|
|
|
{
|
1995-06-27 19:25:30 +04:00
|
|
|
struct nfs_iodesc *newfd;
|
1995-09-23 07:36:06 +04:00
|
|
|
int error = 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("nfs_open: %s\n", path);
|
|
|
|
#endif
|
1995-06-27 19:25:30 +04:00
|
|
|
if (nfs_root_node.iodesc == NULL) {
|
1994-05-08 20:11:14 +04:00
|
|
|
printf("nfs_open: must mount first.\n");
|
1995-09-23 07:36:06 +04:00
|
|
|
return (ENXIO);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate file system specific data structure */
|
1995-06-27 19:25:30 +04:00
|
|
|
newfd = alloc(sizeof(*newfd));
|
|
|
|
newfd->iodesc = nfs_root_node.iodesc;
|
|
|
|
newfd->off = 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
/* lookup a file handle */
|
1995-09-23 07:36:06 +04:00
|
|
|
error = nfs_lookupfh(&nfs_root_node, path, newfd);
|
|
|
|
if (!error) {
|
|
|
|
f->f_fsdata = (void *)newfd;
|
|
|
|
return (0);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
1995-06-27 19:25:30 +04:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1995-09-23 07:36:06 +04:00
|
|
|
printf("nfs_open: %s lookupfh failed: %s\n",
|
|
|
|
path, strerror(error));
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
1995-09-23 07:36:06 +04:00
|
|
|
free(newfd, sizeof(*newfd));
|
|
|
|
return (error);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nfs_close(f)
|
|
|
|
struct open_file *f;
|
|
|
|
{
|
|
|
|
register struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
|
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1995-06-27 19:25:30 +04:00
|
|
|
printf("nfs_close: fp=0x%x\n", fp);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
if (fp)
|
|
|
|
free(fp, sizeof(struct nfs_iodesc));
|
|
|
|
f->f_fsdata = (void *)0;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a portion of a file
|
|
|
|
*/
|
1995-09-17 04:49:37 +04:00
|
|
|
int
|
1995-09-15 03:45:21 +04:00
|
|
|
nfs_read(f, buf, size, resid)
|
1994-05-08 20:11:14 +04:00
|
|
|
struct open_file *f;
|
1995-09-15 03:45:21 +04:00
|
|
|
void *buf;
|
|
|
|
size_t size;
|
|
|
|
size_t *resid; /* out */
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
|
|
|
register struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
|
1995-09-15 03:45:21 +04:00
|
|
|
register ssize_t cc;
|
|
|
|
register char *addr = buf;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1994-08-23 01:55:58 +04:00
|
|
|
printf("nfs_read: size=%d off=%d\n", size, (int)fp->off);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
1995-09-15 03:45:21 +04:00
|
|
|
while ((int)size > 0) {
|
1995-06-27 19:25:30 +04:00
|
|
|
twiddle();
|
|
|
|
cc = nfs_readdata(fp, fp->off, (void *)addr, size);
|
1995-02-20 14:04:00 +03:00
|
|
|
/* XXX maybe should retry on certain errors */
|
|
|
|
if (cc == -1) {
|
1994-05-08 20:11:14 +04:00
|
|
|
#ifdef NFS_DEBUG
|
1995-02-20 14:04:00 +03:00
|
|
|
if (debug)
|
|
|
|
printf("nfs_read: read: %s", strerror(errno));
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
1995-09-23 07:36:06 +04:00
|
|
|
return (errno); /* XXX - from nfs_readdata */
|
1995-02-20 14:04:00 +03:00
|
|
|
}
|
|
|
|
if (cc == 0) {
|
1994-05-08 20:11:14 +04:00
|
|
|
if (debug)
|
|
|
|
printf("nfs_read: hit EOF unexpectantly");
|
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
fp->off += cc;
|
|
|
|
addr += cc;
|
|
|
|
size -= cc;
|
|
|
|
}
|
|
|
|
ret:
|
|
|
|
if (resid)
|
|
|
|
*resid = size;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not implemented.
|
|
|
|
*/
|
1995-09-17 04:49:37 +04:00
|
|
|
int
|
1995-09-15 03:45:21 +04:00
|
|
|
nfs_write(f, buf, size, resid)
|
1994-05-08 20:11:14 +04:00
|
|
|
struct open_file *f;
|
1995-09-15 03:45:21 +04:00
|
|
|
void *buf;
|
|
|
|
size_t size;
|
|
|
|
size_t *resid; /* out */
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
1995-09-17 04:49:37 +04:00
|
|
|
return (EROFS);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
off_t
|
|
|
|
nfs_seek(f, offset, where)
|
|
|
|
struct open_file *f;
|
|
|
|
off_t offset;
|
|
|
|
int where;
|
|
|
|
{
|
1995-06-27 19:25:30 +04:00
|
|
|
register struct nfs_iodesc *d = (struct nfs_iodesc *)f->f_fsdata;
|
|
|
|
n_long size = ntohl(d->fa.fa_size);
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
switch (where) {
|
|
|
|
case SEEK_SET:
|
1995-06-27 19:25:30 +04:00
|
|
|
d->off = offset;
|
1994-05-08 20:11:14 +04:00
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
1995-06-27 19:25:30 +04:00
|
|
|
d->off += offset;
|
1994-05-08 20:11:14 +04:00
|
|
|
break;
|
|
|
|
case SEEK_END:
|
1995-06-27 19:25:30 +04:00
|
|
|
d->off = size - offset;
|
1994-05-08 20:11:14 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (-1);
|
|
|
|
}
|
1995-06-27 19:25:30 +04:00
|
|
|
|
|
|
|
return (d->off);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
/* NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5 */
|
|
|
|
int nfs_stat_types[8] = {
|
|
|
|
0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, 0 };
|
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
int
|
|
|
|
nfs_stat(f, sb)
|
|
|
|
struct open_file *f;
|
|
|
|
struct stat *sb;
|
|
|
|
{
|
1995-06-27 19:25:30 +04:00
|
|
|
struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
|
|
|
|
register n_long ftype, mode;
|
|
|
|
|
|
|
|
ftype = ntohl(fp->fa.fa_type);
|
|
|
|
mode = ntohl(fp->fa.fa_mode);
|
|
|
|
mode |= nfs_stat_types[ftype & 7];
|
|
|
|
|
|
|
|
sb->st_mode = mode;
|
|
|
|
sb->st_nlink = ntohl(fp->fa.fa_nlink);
|
|
|
|
sb->st_uid = ntohl(fp->fa.fa_uid);
|
|
|
|
sb->st_gid = ntohl(fp->fa.fa_gid);
|
|
|
|
sb->st_size = ntohl(fp->fa.fa_size);
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|