2014-03-20 07:13:18 +04:00
|
|
|
/* $NetBSD: nfs.c,v 1.48 2014/03/20 03:13:18 christos 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.
|
2005-02-27 01:58:54 +03:00
|
|
|
*
|
1994-05-08 20:11:14 +04:00
|
|
|
* 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.
|
2005-02-27 01:58:54 +03:00
|
|
|
*
|
1994-05-08 20:11:14 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
Make a bunch of backward-compatible changes to the boot blocks which allow
size to be reduced substantially. (backward compatibility verified
by compiling one of the alpha boot blocks which uses all of the code
before and after, diffing the object files, and manually verifying that
the differences were 'correct'. some differences were "unavoidable,"
it wanting to avoid a double-commit, because e.g. local variables which
were previously used were no longer used.) a README which describes
supported options (or at least the ones mentioned below) is forthcoming.
add support for the preprocessor macro LIBSA_NO_TWIDDLE, which
causes calls to twiddle() to be omitted if it's defined.
add support for the preprocessor macros:
LIBSA_NO_FS_CLOSE
LIBSA_NO_FS_WRITE
LIBSA_NO_FS_SEEK
which, if defined, cause the corresponding file system operations
in the individual file system implementations to be omitted. (note
that all of those macros are not supported by all file systems at
this point. comments were added to individual file system files
to indicate lack of support, and should be cleaned up later. Backward
compatibility options e.g. UFS_NOCLOSE, etc., are supported.)
add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which
removes support for symbolic links from the file system support
functions. (same notes as for the macros above apply.)
add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which
removes all subdirectory and symlink support from the file system
support functions. (same notes as for the macros above apply.)
add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which
causes code relating to libsa file descriptor checks (e.g. range
checking and checking that a file descriptor is valid) to be
omitted if it's defined.
add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which
causes code relating to raw device access to be omitted if it's
defined.
change some structure copies to use bcopy() instead. that way
use of bcopy vs. memcpy() can easily be selected by
LIBSA_USE_MEMCPY. (without changes like these, you could end up
having both bcopy() and memcpy() included. eventually, all
calls to bcopy should be changed to calls to memcpy() or memmove()
as appropriate -- hopefully never the latter -- with an option to
use bcopy instead.)
add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which
causes disklabel() to return '1' as msg rather than a string. Can
be used if the boot blocks don't care about the string, and need to
save the space.
add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which
if defined causes all of the file system switch code to be removed.
Its value should be the name of the file system supported by the
boot block, e.g. "ufs" for the FFS file system. calls to the
file system functions open, close, etc., which were previously
done through a function switch are then done via direct invocation
of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...).
add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which
does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device
switch table. Device entry pointes are expected to be named
<dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE
is set to 'disk' is diskstrategy.
make ufs.c f_nindir array be unsigned ints. the fact that it was signed
caused ufs.c to require signed division routines (which were otherwise
unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
|
|
|
/*
|
|
|
|
* XXX Does not currently implement:
|
|
|
|
* XXX
|
|
|
|
* XXX LIBSA_NO_FS_CLOSE
|
|
|
|
* XXX LIBSA_NO_FS_SEEK
|
|
|
|
* XXX LIBSA_NO_FS_WRITE
|
|
|
|
* XXX LIBSA_NO_FS_SYMLINK (does this even make sense?)
|
|
|
|
* XXX LIBSA_FS_SINGLECOMPONENT (does this even make sense?)
|
|
|
|
*/
|
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
1999-11-14 00:17:56 +03:00
|
|
|
#ifdef _STANDALONE
|
|
|
|
#include <lib/libkern/libkern.h>
|
|
|
|
#else
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
|
1996-02-27 02:05:14 +03:00
|
|
|
#include "rpcv2.h"
|
1996-02-27 00:50:07 +03:00
|
|
|
#include "nfsv2.h"
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#include "stand.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "nfs.h"
|
|
|
|
#include "rpc.h"
|
|
|
|
|
2006-12-29 16:05:48 +03:00
|
|
|
/* Define our own NFS attributes */
|
1995-06-27 19:25:30 +04:00
|
|
|
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
|
|
|
};
|
|
|
|
|
1997-06-17 00:47:11 +04:00
|
|
|
#ifndef NFS_NOSYMLINK
|
1996-09-30 20:01:18 +04:00
|
|
|
struct nfs_readlnk_repl {
|
|
|
|
n_long errno;
|
|
|
|
n_long len;
|
|
|
|
char path[NFS_MAXPATHLEN];
|
|
|
|
};
|
1997-06-17 00:47:11 +04:00
|
|
|
#endif
|
1996-09-30 20:01:18 +04:00
|
|
|
|
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
|
|
|
|
2009-01-17 17:00:36 +03:00
|
|
|
int nfs_getrootfh(struct iodesc *, char *, u_char *);
|
|
|
|
int nfs_lookupfh(struct nfs_iodesc *, const char *, int,
|
|
|
|
struct nfs_iodesc *);
|
|
|
|
int nfs_readlink(struct nfs_iodesc *, char *);
|
|
|
|
ssize_t nfs_readdata(struct nfs_iodesc *, off_t, void *, size_t);
|
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
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
2000-03-30 16:19:46 +04:00
|
|
|
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;
|
2003-09-01 02:40:13 +04:00
|
|
|
ssize_t cc;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1996-10-13 06:28:58 +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
|
|
|
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memset(args, 0, sizeof(*args));
|
1995-06-27 19:25:30 +04:00
|
|
|
len = strlen(path);
|
2003-09-01 02:40:13 +04:00
|
|
|
if ((size_t)len > sizeof(args->path))
|
1995-06-27 19:25:30 +04:00
|
|
|
len = sizeof(args->path);
|
|
|
|
args->len = htonl(len);
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(args->path, path, len);
|
1995-06-27 19:25:30 +04:00
|
|
|
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 */
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1995-09-23 07:36:06 +04:00
|
|
|
}
|
|
|
|
if (cc < 4) {
|
|
|
|
errno = EBADRPC;
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1995-09-23 07:36:06 +04:00
|
|
|
}
|
1995-06-27 19:25:30 +04:00
|
|
|
if (repl->errno) {
|
|
|
|
errno = ntohl(repl->errno);
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(fhp, repl->fh, sizeof(repl->fh));
|
2007-11-24 16:20:53 +03:00
|
|
|
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
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_lookupfh(struct nfs_iodesc *d, const char *name, int len,
|
|
|
|
struct nfs_iodesc *newfd)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
2003-08-18 19:45:27 +04:00
|
|
|
int 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;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1996-10-13 06:28:58 +04: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
|
|
|
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memset(args, 0, sizeof(*args));
|
|
|
|
(void)memcpy(args->fh, d->fh, sizeof(args->fh));
|
2003-09-01 02:40:13 +04:00
|
|
|
if ((size_t)len > sizeof(args->name))
|
1995-06-27 19:25:30 +04:00
|
|
|
len = sizeof(args->name);
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(args->name, name, len);
|
1995-06-27 19:25:30 +04:00
|
|
|
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)
|
2007-11-24 16:20:53 +03:00
|
|
|
return errno; /* XXX - from rpc_call */
|
1995-06-27 19:25:30 +04:00
|
|
|
if (cc < 4)
|
2007-11-24 16:20:53 +03:00
|
|
|
return EIO;
|
1995-06-27 19:25:30 +04:00
|
|
|
if (repl->errno) {
|
1995-09-23 07:36:06 +04:00
|
|
|
/* saerrno.h now matches NFS error numbers. */
|
2007-11-24 16:20:53 +03:00
|
|
|
return ntohl(repl->errno);
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(&newfd->fh, repl->fh, sizeof(newfd->fh));
|
|
|
|
(void)memcpy(&newfd->fa, &repl->fa, sizeof(newfd->fa));
|
2007-11-24 16:20:53 +03:00
|
|
|
return 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
1997-06-17 00:47:11 +04:00
|
|
|
#ifndef NFS_NOSYMLINK
|
1996-09-30 20:01:18 +04:00
|
|
|
/*
|
|
|
|
* Get the destination of a symbolic link.
|
|
|
|
*/
|
|
|
|
int
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_readlink(struct nfs_iodesc *d, char *buf)
|
1996-09-30 20:01:18 +04:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
n_long h[RPC_HEADER_WORDS];
|
|
|
|
u_char fh[NFS_FHSIZE];
|
|
|
|
} sdata;
|
|
|
|
struct {
|
|
|
|
n_long h[RPC_HEADER_WORDS];
|
|
|
|
struct nfs_readlnk_repl d;
|
|
|
|
} rdata;
|
|
|
|
ssize_t cc;
|
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1996-10-13 06:28:58 +04:00
|
|
|
printf("readlink: called\n");
|
1996-09-30 20:01:18 +04:00
|
|
|
#endif
|
|
|
|
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(sdata.fh, d->fh, NFS_FHSIZE);
|
1996-09-30 20:01:18 +04:00
|
|
|
cc = rpc_call(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READLINK,
|
2007-11-24 16:20:53 +03:00
|
|
|
sdata.fh, NFS_FHSIZE,
|
|
|
|
&rdata.d, sizeof(rdata.d));
|
1996-09-30 20:01:18 +04:00
|
|
|
if (cc == -1)
|
2007-11-24 16:20:53 +03:00
|
|
|
return errno;
|
1996-09-30 20:01:18 +04:00
|
|
|
|
|
|
|
if (cc < 4)
|
2007-11-24 16:20:53 +03:00
|
|
|
return EIO;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
if (rdata.d.errno)
|
2007-11-24 16:20:53 +03:00
|
|
|
return ntohl(rdata.d.errno);
|
1996-10-03 00:28:26 +04:00
|
|
|
|
|
|
|
rdata.d.len = ntohl(rdata.d.len);
|
1996-09-30 20:01:18 +04:00
|
|
|
if (rdata.d.len > NFS_MAXPATHLEN)
|
2007-11-24 16:20:53 +03:00
|
|
|
return ENAMETOOLONG;
|
1996-09-30 20:01:18 +04:00
|
|
|
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(buf, rdata.d.path, rdata.d.len);
|
1996-09-30 20:01:18 +04:00
|
|
|
buf[rdata.d.len] = 0;
|
2007-11-24 16:20:53 +03:00
|
|
|
return 0;
|
1996-09-30 20:01:18 +04:00
|
|
|
}
|
1997-06-17 00:47:11 +04:00
|
|
|
#endif
|
1996-09-30 20:01:18 +04:00
|
|
|
|
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
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_readdata(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;
|
2003-09-01 02:40:13 +04:00
|
|
|
ssize_t cc;
|
1995-09-15 03:45:21 +04:00
|
|
|
long x;
|
2003-09-01 02:40:13 +04:00
|
|
|
size_t hlen, rlen;
|
1995-06-27 19:25:30 +04:00
|
|
|
|
|
|
|
args = &sdata.d;
|
|
|
|
repl = &rdata.d;
|
1995-02-20 14:04:00 +03:00
|
|
|
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(args->fh, d->fh, NFS_FHSIZE);
|
1996-02-27 02:05:14 +03:00
|
|
|
args->off = htonl((n_long)off);
|
1995-02-20 14:04:00 +03:00
|
|
|
if (len > NFSREAD_SIZE)
|
|
|
|
len = NFSREAD_SIZE;
|
1996-02-27 02:05:14 +03:00
|
|
|
args->len = htonl((n_long)len);
|
|
|
|
args->xxx = htonl((n_long)0);
|
1995-06-27 19:25:30 +04:00
|
|
|
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 */
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1995-09-23 07:36:06 +04:00
|
|
|
}
|
2003-09-01 02:40:13 +04:00
|
|
|
if (cc < (ssize_t)hlen) {
|
1995-09-23 07:36:06 +04:00
|
|
|
errno = EBADRPC;
|
2007-11-24 16:20:53 +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);
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1995-06-27 19:25:30 +04:00
|
|
|
}
|
|
|
|
rlen = cc - hlen;
|
|
|
|
x = ntohl(repl->count);
|
2003-09-01 02:40:13 +04:00
|
|
|
if (rlen < (size_t)x) {
|
2003-09-04 16:02:10 +04:00
|
|
|
printf("nfsread: short packet, %lu < %ld\n", (u_long) rlen, x);
|
1995-09-15 03:45:21 +04:00
|
|
|
errno = EBADRPC;
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1995-06-27 19:25:30 +04:00
|
|
|
}
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(addr, repl->data, x);
|
2007-11-24 16:20:53 +03:00
|
|
|
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
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_mount(int sock, struct in_addr ip, char *path)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
|
|
|
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;
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
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))
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1995-06-27 19:25:30 +04:00
|
|
|
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)
|
1996-10-13 06:28:58 +04:00
|
|
|
printf("nfs_mount: got fh for %s\n", path);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
|
|
|
|
2007-11-24 16:20:53 +03:00
|
|
|
return 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open a file.
|
1995-09-23 07:36:06 +04:00
|
|
|
* return zero or error number
|
1994-05-08 20:11:14 +04:00
|
|
|
*/
|
2011-06-16 17:27:58 +04:00
|
|
|
__compactcall int
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_open(const char *path, struct open_file *f)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
1996-09-30 20:01:18 +04:00
|
|
|
struct nfs_iodesc *newfd, *currfd;
|
2003-08-18 19:45:27 +04:00
|
|
|
const char *cp;
|
1997-06-17 00:47:11 +04:00
|
|
|
#ifndef NFS_NOSYMLINK
|
2003-08-18 19:45:27 +04:00
|
|
|
const char *ncp;
|
2000-03-30 16:19:46 +04:00
|
|
|
int c;
|
1996-09-30 20:01:18 +04:00
|
|
|
char namebuf[NFS_MAXPATHLEN + 1];
|
|
|
|
char linkbuf[NFS_MAXPATHLEN + 1];
|
|
|
|
int nlinks = 0;
|
1997-06-17 00:47:11 +04:00
|
|
|
#endif
|
1995-09-23 07:36:06 +04:00
|
|
|
int error = 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
2007-11-24 16:20:53 +03:00
|
|
|
printf("nfs_open: %s\n", path);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
1995-06-27 19:25:30 +04:00
|
|
|
if (nfs_root_node.iodesc == NULL) {
|
1996-10-13 06:28:58 +04:00
|
|
|
printf("nfs_open: must mount first.\n");
|
2007-11-24 16:20:53 +03:00
|
|
|
return ENXIO;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
currfd = &nfs_root_node;
|
|
|
|
newfd = 0;
|
1997-06-17 00:47:11 +04:00
|
|
|
|
|
|
|
#ifndef NFS_NOSYMLINK
|
1996-09-30 20:01:18 +04:00
|
|
|
cp = path;
|
|
|
|
while (*cp) {
|
|
|
|
/*
|
|
|
|
* Remove extra separators
|
|
|
|
*/
|
|
|
|
while (*cp == '/')
|
|
|
|
cp++;
|
|
|
|
|
|
|
|
if (*cp == '\0')
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Check that current node is a directory.
|
|
|
|
*/
|
1996-10-03 00:28:26 +04:00
|
|
|
if (currfd->fa.fa_type != htonl(NFDIR)) {
|
1996-09-30 20:01:18 +04:00
|
|
|
error = ENOTDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
/* allocate file system specific data structure */
|
|
|
|
newfd = alloc(sizeof(*newfd));
|
|
|
|
newfd->iodesc = currfd->iodesc;
|
|
|
|
newfd->off = 0;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
/*
|
|
|
|
* Get next component of path name.
|
|
|
|
*/
|
|
|
|
{
|
2000-03-30 16:19:46 +04:00
|
|
|
int len = 0;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
ncp = cp;
|
|
|
|
while ((c = *cp) != '\0' && c != '/') {
|
|
|
|
if (++len > NFS_MAXNAMLEN) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
/* lookup a file handle */
|
2003-08-18 19:45:27 +04:00
|
|
|
error = nfs_lookupfh(currfd, ncp, cp - ncp, newfd);
|
1996-09-30 20:01:18 +04:00
|
|
|
if (error)
|
|
|
|
goto out;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
/*
|
|
|
|
* Check for symbolic link
|
|
|
|
*/
|
1996-10-03 00:28:26 +04:00
|
|
|
if (newfd->fa.fa_type == htonl(NFLNK)) {
|
1996-09-30 20:01:18 +04:00
|
|
|
int link_len, len;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
error = nfs_readlink(newfd, linkbuf);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
link_len = strlen(linkbuf);
|
|
|
|
len = strlen(cp);
|
|
|
|
|
|
|
|
if (link_len + len > MAXPATHLEN
|
|
|
|
|| ++nlinks > MAXSYMLINKS) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-03-26 00:23:50 +03:00
|
|
|
(void)memcpy(&namebuf[link_len], cp, len + 1);
|
|
|
|
(void)memcpy(namebuf, linkbuf, link_len);
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
/*
|
|
|
|
* If absolute pathname, restart at root.
|
|
|
|
* If relative pathname, restart at parent directory.
|
|
|
|
*/
|
|
|
|
cp = namebuf;
|
|
|
|
if (*cp == '/') {
|
|
|
|
if (currfd != &nfs_root_node)
|
2006-01-25 21:27:23 +03:00
|
|
|
dealloc(currfd, sizeof(*currfd));
|
1996-09-30 20:01:18 +04:00
|
|
|
currfd = &nfs_root_node;
|
|
|
|
}
|
|
|
|
|
2006-01-25 21:27:23 +03:00
|
|
|
dealloc(newfd, sizeof(*newfd));
|
1996-09-30 20:01:18 +04:00
|
|
|
newfd = 0;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
continue;
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
if (currfd != &nfs_root_node)
|
2006-01-25 21:27:23 +03:00
|
|
|
dealloc(currfd, sizeof(*currfd));
|
1996-09-30 20:01:18 +04:00
|
|
|
currfd = newfd;
|
|
|
|
newfd = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
1996-09-30 20:01:18 +04:00
|
|
|
out:
|
1997-06-17 00:47:11 +04:00
|
|
|
#else
|
1999-11-23 15:20:53 +03:00
|
|
|
/* allocate file system specific data structure */
|
|
|
|
currfd = alloc(sizeof(*currfd));
|
|
|
|
currfd->iodesc = nfs_root_node.iodesc;
|
|
|
|
currfd->off = 0;
|
1997-06-17 00:47:11 +04:00
|
|
|
|
1999-11-23 15:20:53 +03:00
|
|
|
cp = path;
|
|
|
|
/*
|
|
|
|
* Remove extra separators
|
|
|
|
*/
|
|
|
|
while (*cp == '/')
|
|
|
|
cp++;
|
|
|
|
|
|
|
|
/* XXX: Check for empty path here? */
|
|
|
|
|
2003-08-18 19:45:27 +04:00
|
|
|
error = nfs_lookupfh(&nfs_root_node, cp, strlen(cp), currfd);
|
1997-06-17 00:47:11 +04:00
|
|
|
#endif
|
1995-09-23 07:36:06 +04:00
|
|
|
if (!error) {
|
1996-09-30 20:01:18 +04:00
|
|
|
f->f_fsdata = (void *)currfd;
|
2008-11-19 15:36:41 +03:00
|
|
|
fsmod = "nfs";
|
2007-11-24 16:20:53 +03:00
|
|
|
return 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1996-10-13 06:28:58 +04:00
|
|
|
printf("nfs_open: %s lookupfh failed: %s\n",
|
1996-10-11 02:46:11 +04:00
|
|
|
path, strerror(error));
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
1996-09-30 20:01:18 +04:00
|
|
|
if (currfd != &nfs_root_node)
|
2006-01-25 21:27:23 +03:00
|
|
|
dealloc(currfd, sizeof(*currfd));
|
1996-09-30 20:01:18 +04:00
|
|
|
if (newfd)
|
2006-01-25 21:27:23 +03:00
|
|
|
dealloc(newfd, sizeof(*newfd));
|
1996-09-30 20:01:18 +04:00
|
|
|
|
2007-11-24 16:20:53 +03:00
|
|
|
return error;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
2011-06-16 17:27:58 +04:00
|
|
|
__compactcall int
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_close(struct open_file *f)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
2000-03-30 16:19:46 +04:00
|
|
|
struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
|
1994-05-08 20:11:14 +04:00
|
|
|
|
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1998-01-23 22:27:44 +03:00
|
|
|
printf("nfs_close: fp=0x%lx\n", (u_long)fp);
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
|
|
|
|
1995-06-27 19:25:30 +04:00
|
|
|
if (fp)
|
2006-01-25 21:27:23 +03:00
|
|
|
dealloc(fp, sizeof(struct nfs_iodesc));
|
1995-06-27 19:25:30 +04:00
|
|
|
f->f_fsdata = (void *)0;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2007-11-24 16:20:53 +03:00
|
|
|
return 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read a portion of a file
|
|
|
|
*/
|
2011-06-16 17:27:58 +04:00
|
|
|
__compactcall int
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
2000-03-30 16:19:46 +04:00
|
|
|
struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
|
|
|
|
ssize_t cc;
|
|
|
|
char *addr = buf;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1994-05-08 20:11:14 +04:00
|
|
|
#ifdef NFS_DEBUG
|
|
|
|
if (debug)
|
1998-01-23 22:27:44 +03:00
|
|
|
printf("nfs_read: size=%lu off=%d\n", (u_long)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) {
|
Make a bunch of backward-compatible changes to the boot blocks which allow
size to be reduced substantially. (backward compatibility verified
by compiling one of the alpha boot blocks which uses all of the code
before and after, diffing the object files, and manually verifying that
the differences were 'correct'. some differences were "unavoidable,"
it wanting to avoid a double-commit, because e.g. local variables which
were previously used were no longer used.) a README which describes
supported options (or at least the ones mentioned below) is forthcoming.
add support for the preprocessor macro LIBSA_NO_TWIDDLE, which
causes calls to twiddle() to be omitted if it's defined.
add support for the preprocessor macros:
LIBSA_NO_FS_CLOSE
LIBSA_NO_FS_WRITE
LIBSA_NO_FS_SEEK
which, if defined, cause the corresponding file system operations
in the individual file system implementations to be omitted. (note
that all of those macros are not supported by all file systems at
this point. comments were added to individual file system files
to indicate lack of support, and should be cleaned up later. Backward
compatibility options e.g. UFS_NOCLOSE, etc., are supported.)
add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which
removes support for symbolic links from the file system support
functions. (same notes as for the macros above apply.)
add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which
removes all subdirectory and symlink support from the file system
support functions. (same notes as for the macros above apply.)
add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which
causes code relating to libsa file descriptor checks (e.g. range
checking and checking that a file descriptor is valid) to be
omitted if it's defined.
add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which
causes code relating to raw device access to be omitted if it's
defined.
change some structure copies to use bcopy() instead. that way
use of bcopy vs. memcpy() can easily be selected by
LIBSA_USE_MEMCPY. (without changes like these, you could end up
having both bcopy() and memcpy() included. eventually, all
calls to bcopy should be changed to calls to memcpy() or memmove()
as appropriate -- hopefully never the latter -- with an option to
use bcopy instead.)
add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which
causes disklabel() to return '1' as msg rather than a string. Can
be used if the boot blocks don't care about the string, and need to
save the space.
add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which
if defined causes all of the file system switch code to be removed.
Its value should be the name of the file system supported by the
boot block, e.g. "ufs" for the FFS file system. calls to the
file system functions open, close, etc., which were previously
done through a function switch are then done via direct invocation
of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...).
add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which
does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device
switch table. Device entry pointes are expected to be named
<dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE
is set to 'disk' is diskstrategy.
make ufs.c f_nindir array be unsigned ints. the fact that it was signed
caused ufs.c to require signed division routines (which were otherwise
unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
|
|
|
#if !defined(LIBSA_NO_TWIDDLE)
|
1995-06-27 19:25:30 +04:00
|
|
|
twiddle();
|
Make a bunch of backward-compatible changes to the boot blocks which allow
size to be reduced substantially. (backward compatibility verified
by compiling one of the alpha boot blocks which uses all of the code
before and after, diffing the object files, and manually verifying that
the differences were 'correct'. some differences were "unavoidable,"
it wanting to avoid a double-commit, because e.g. local variables which
were previously used were no longer used.) a README which describes
supported options (or at least the ones mentioned below) is forthcoming.
add support for the preprocessor macro LIBSA_NO_TWIDDLE, which
causes calls to twiddle() to be omitted if it's defined.
add support for the preprocessor macros:
LIBSA_NO_FS_CLOSE
LIBSA_NO_FS_WRITE
LIBSA_NO_FS_SEEK
which, if defined, cause the corresponding file system operations
in the individual file system implementations to be omitted. (note
that all of those macros are not supported by all file systems at
this point. comments were added to individual file system files
to indicate lack of support, and should be cleaned up later. Backward
compatibility options e.g. UFS_NOCLOSE, etc., are supported.)
add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which
removes support for symbolic links from the file system support
functions. (same notes as for the macros above apply.)
add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which
removes all subdirectory and symlink support from the file system
support functions. (same notes as for the macros above apply.)
add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which
causes code relating to libsa file descriptor checks (e.g. range
checking and checking that a file descriptor is valid) to be
omitted if it's defined.
add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which
causes code relating to raw device access to be omitted if it's
defined.
change some structure copies to use bcopy() instead. that way
use of bcopy vs. memcpy() can easily be selected by
LIBSA_USE_MEMCPY. (without changes like these, you could end up
having both bcopy() and memcpy() included. eventually, all
calls to bcopy should be changed to calls to memcpy() or memmove()
as appropriate -- hopefully never the latter -- with an option to
use bcopy instead.)
add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which
causes disklabel() to return '1' as msg rather than a string. Can
be used if the boot blocks don't care about the string, and need to
save the space.
add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which
if defined causes all of the file system switch code to be removed.
Its value should be the name of the file system supported by the
boot block, e.g. "ufs" for the FFS file system. calls to the
file system functions open, close, etc., which were previously
done through a function switch are then done via direct invocation
of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...).
add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which
does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device
switch table. Device entry pointes are expected to be named
<dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE
is set to 'disk' is diskstrategy.
make ufs.c f_nindir array be unsigned ints. the fact that it was signed
caused ufs.c to require signed division routines (which were otherwise
unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
|
|
|
#endif
|
1995-06-27 19:25:30 +04:00
|
|
|
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)
|
2007-02-25 07:46:32 +03:00
|
|
|
printf("nfs_read: read: %s\n",
|
|
|
|
strerror(errno));
|
1994-05-08 20:11:14 +04:00
|
|
|
#endif
|
2007-11-24 16:20:53 +03:00
|
|
|
return errno; /* XXX - from nfs_readdata */
|
1995-02-20 14:04:00 +03:00
|
|
|
}
|
|
|
|
if (cc == 0) {
|
1996-12-27 14:55:58 +03:00
|
|
|
#ifdef NFS_DEBUG
|
1994-05-08 20:11:14 +04:00
|
|
|
if (debug)
|
2007-02-25 07:46:32 +03:00
|
|
|
printf("nfs_read: hit EOF unexpectantly\n");
|
1996-12-27 14:55:58 +03:00
|
|
|
#endif
|
1994-05-08 20:11:14 +04:00
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
fp->off += cc;
|
|
|
|
addr += cc;
|
|
|
|
size -= cc;
|
|
|
|
}
|
|
|
|
ret:
|
|
|
|
if (resid)
|
|
|
|
*resid = size;
|
|
|
|
|
2007-11-24 16:20:53 +03:00
|
|
|
return 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not implemented.
|
|
|
|
*/
|
2011-06-16 17:27:58 +04:00
|
|
|
__compactcall int
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
2007-11-24 16:20:53 +03:00
|
|
|
return EROFS;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
|
|
|
|
2011-06-16 17:27:58 +04:00
|
|
|
__compactcall off_t
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_seek(struct open_file *f, off_t offset, int where)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
2000-03-30 16:19:46 +04:00
|
|
|
struct nfs_iodesc *d = (struct nfs_iodesc *)f->f_fsdata;
|
1995-06-27 19:25:30 +04:00
|
|
|
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:
|
2007-11-24 16:20:53 +03:00
|
|
|
return -1;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
1995-06-27 19:25:30 +04:00
|
|
|
|
2007-11-24 16:20:53 +03: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 */
|
2003-03-18 22:20:09 +03:00
|
|
|
const int nfs_stat_types[8] = {
|
1995-06-27 19:25:30 +04:00
|
|
|
0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, 0 };
|
|
|
|
|
2011-06-16 17:27:58 +04:00
|
|
|
__compactcall int
|
2007-11-24 16:20:53 +03:00
|
|
|
nfs_stat(struct open_file *f, struct stat *sb)
|
1994-05-08 20:11:14 +04:00
|
|
|
{
|
1995-06-27 19:25:30 +04:00
|
|
|
struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
|
2000-03-30 16:19:46 +04:00
|
|
|
n_long ftype, mode;
|
1995-06-27 19:25:30 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
2007-11-24 16:20:53 +03:00
|
|
|
return 0;
|
1994-05-08 20:11:14 +04:00
|
|
|
}
|
2011-12-25 10:09:08 +04:00
|
|
|
|
|
|
|
#if defined(LIBSA_ENABLE_LS_OP)
|
2014-03-20 07:13:18 +04:00
|
|
|
#include "ls.h"
|
2011-12-25 10:09:08 +04:00
|
|
|
__compactcall void
|
|
|
|
nfs_ls(struct open_file *f, const char *pattern)
|
|
|
|
{
|
2014-03-20 07:13:18 +04:00
|
|
|
lsunsup("nfs");
|
2011-12-25 10:09:08 +04:00
|
|
|
}
|
|
|
|
#endif
|