diff options
Diffstat (limited to 'nfs')
-rw-r--r-- | nfs/ChangeLog | 71 | ||||
-rw-r--r-- | nfs/Makefile | 4 | ||||
-rw-r--r-- | nfs/mount.c | 3 | ||||
-rw-r--r-- | nfs/mount.h | 4 | ||||
-rw-r--r-- | nfs/nfs-spec.h (renamed from nfs/rpcsvc/nfs_prot.h) | 23 | ||||
-rw-r--r-- | nfs/nfs.c | 31 | ||||
-rw-r--r-- | nfs/nfs.h | 3 | ||||
-rw-r--r-- | nfs/ops.c | 531 | ||||
-rw-r--r-- | nfs/rpc.c | 5 | ||||
-rw-r--r-- | nfs/rpcsvc/mount.h | 81 |
10 files changed, 547 insertions, 209 deletions
diff --git a/nfs/ChangeLog b/nfs/ChangeLog index dfe11aa4..e3c5c4a9 100644 --- a/nfs/ChangeLog +++ b/nfs/ChangeLog @@ -1,3 +1,74 @@ +Tue Sep 3 14:00:25 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * nfs-spec.h: Renamed from rpcsvc/nfs_prot.h. + * mount.c: Include "mount.h" instead of <rpcsvc/mount.h>. + * nfs.h: Include "nfs-spec.h" instead of <rpcsvc/nfs_prot.h>. + * rpcsvc/mount.h: Deleted file. + * rpcsvc: Deleted directory. + * mount.h (MOUNTPROG): Renamed from MOUNT_RPC_PROGRAM. + (MOUNTVERS): Renamed from MOUNT_RPC_VERSION. + * Makefile (RPCSVC_FILES): Deleted var. + (lndist, lndist-rpcsvc-files, + $(top_srcdir)/hurd-snap/$(dir)/rpcsvc): Deleted targets. + (LCLHDRS): Added mount.h and nfs-spec.h. + +Thu Aug 29 10:41:27 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * rpcsvc/nfs_prot.h (createmode): Spell EXCLUSIVE correctly. + * nfs.c (hurd_mode_to_nfs_type): New function. + * nfs.h (hurd_mode_to_nfs_type): New decl. + * ops.c (netfs_attempt_rmdir): process_wcc_stat for NP, not DIR. + (netfs_attempt_link): Spell netfs_validate_stat correctly. + (minor, major): New macros. + (netfs_report_access): Don't try and return an error. + + * rpc.c (conduct_rpc): Tolerate and return errors from write. + + * Makefile (RPCSVC_FILES): New variable. + (lndist): Depend on lndist-rpcsvc-files. + (lndist-rpcsvc-files, $(top_srcdir)/hurd-snap/$(dir)/rpcsvc): New + targets. + +Fri Aug 16 11:56:53 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> + + * ops.c (process_wcc_stat): New function. + (netfs_attempt_chown): Use process_wcc_stat instead of + register_fresh_stat. Pack and unpack v3 SETATTR structure if + appropriate. + (netfs_attempt_chmod): Likewise. + (netfs_attempt_utimes): Likewise. + (netfs_attempt_set_size): Likewise. + (netfs_attempt_lookup): Use process_returned_stat instead of + register_fresh state. Unpack v3 LOOKUP structure if appropriate. + (netfs_attempt_link): Likewise. + (verify_nonexistent): Assert that we are v2. + (netfs_report_access): Use NFS3PROC_ACCESS if we are v3. + (netfs_check_open_permissions): Use netfs_report_access. + (netfs_attempt_readlink): Unpack v3 READLINK structure if + appropriate. + (netfs_attempt_read): Pack and unpack v3 READ structure in + appropriate. Use process_returned_stat instead of + register_fresh_stat. + (netfs_attempt_write): Pack and unpack v3 WRITE structure in + appropriate. Use process_wcc_stat instead of + register_fresh_stat. + (netfs_attempt_create_file): Pack and unpack v3 CREATE structure + if appropriate. Use process_returned_stat instead of + register_fresh_stat. + (netfs_attempt_link) [CHRDEV, BLKDEV, FIFO, SOCK]: If v3, use new + MKNOD call instead of CREATE with overloaded mode. + (netfs_attempt_link) [SYMLINK]: If pack and unpack v3 SYMLINK + structure if appropriate. + (netfs_attempt_unlink): Unpack v3 REMOVE structure if appropriate. + (netfs_attempt_rmdir): Unpack v3 RMDIR structure if appropriate. + (netfs_attempt_rename): Unpack v3 RENAME structure if appropriate. + + * rpcsvc/nfs_prot.h (ACCESS3_READ, ACCESS3_LOOKUP, ACCESS3_MODIFY, + ACCESS3_EXTEND, ACCESS3_DELETE, ACCESS3_EXECUTE): New macros. + + * ops.c (netfs_attempt_chown): Bother to read NFS error/success + value. + Thu Aug 15 15:24:29 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> * ops.c (verify_nonexistent): Don't need to lock DIR; it's already diff --git a/nfs/Makefile b/nfs/Makefile index 66ecaeac..da35cc03 100644 --- a/nfs/Makefile +++ b/nfs/Makefile @@ -22,10 +22,12 @@ dir := nfs makemode := server target = nfs -LCLHDRS = nfs.h +LCLHDRS = nfs.h mount.h nfs-spec.h SRCS = ops.c rpc.c mount.c cred.c nfs.c cache.c consts.c main.c OBJS = $(subst .c,.o,$(SRCS)) nfs: $(OBJS) ../libports/libports.a ../libnetfs/libnetfs.a ../libfshelp/libfshelp.a ../libthreads/libthreads.a include ../Makeconf + + diff --git a/nfs/mount.c b/nfs/mount.c index a7ceaf50..ce1329e2 100644 --- a/nfs/mount.c +++ b/nfs/mount.c @@ -20,7 +20,6 @@ #include "nfs.h" -#include <rpcsvc/mount.h> #include <rpc/pmap_prot.h> #include <errno.h> #include <sys/socket.h> @@ -29,6 +28,8 @@ #include <netinet/in.h> #include <stdio.h> +#include "mount.h" + /* Service name for portmapper */ char *pmap_service_name = "sunrpc"; diff --git a/nfs/mount.h b/nfs/mount.h index b1862442..fce8ee4c 100644 --- a/nfs/mount.h +++ b/nfs/mount.h @@ -20,8 +20,8 @@ /* These constants define the RPC mount protocol; see RFC 1094. */ -#define MOUNT_RPC_PROGRAM 100005 -#define MOUNT_RPC_VERSION 1 +#define MOUNTPROG 100005 +#define MOUNTVERS 1 /* Obnoxious arbitrary limits */ #define MOUNT_MNTPATHLEN 1024 diff --git a/nfs/rpcsvc/nfs_prot.h b/nfs/nfs-spec.h index 476c72ef..32f5b09d 100644 --- a/nfs/rpcsvc/nfs_prot.h +++ b/nfs/nfs-spec.h @@ -74,6 +74,29 @@ enum sattr_time_how SET_TO_CLIENT_TIME = 2, }; +/* Construction of ACCESS arg to NFS3PROC_ACCESS. */ +#define ACCESS3_READ 0x01 +#define ACCESS3_LOOKUP 0x02 +#define ACCESS3_MODIFY 0x04 +#define ACCESS3_EXTEND 0x08 +#define ACCESS3_DELETE 0x10 +#define ACCESS3_EXECUTE 0x20 + +/* STABLE arg to NFS3PROC_READ */ +enum stable_how { + UNSTABLE = 0, + DATA_SYNC = 1, + FILE_SYNC = 2, +}; + +/* MODE arg to NFS3PROC_CREATE */ +enum createmode +{ + UNCHECKED = 0, + GUARDED = 1, + EXCLUSIVE = 2, +}; + #define NFS_PROGRAM ((u_long)100003) #define NFS_VERSION ((u_long)2) @@ -97,6 +97,37 @@ hurd_mode_to_nfs_mode (mode_t mode) return mode & 07777; } +/* Convert a Hurd mode to an NFS type */ +int +hurd_mode_to_nfs_type (mode_t mode) +{ + switch (mode & S_IFMT) + { + case S_IFDIR: + return NFDIR; + + case S_IFCHR: + default: + return NFCHR; + + case S_IFBLK: + return NFBLK; + + case S_IFREG: + return NFREG; + + case S_IFLNK: + return NFLNK; + + case S_IFSOCK: + return NFSOCK; + + case S_IFIFO: + return protocol_version == 2 ? NF2FIFO : NF3FIFO; + } +} + + /* Each of the functions on this page copies its second arg to *P, converting it to XDR representation along the way. They then @@ -21,7 +21,7 @@ typedef int bool_t; /* Ick. */ #include <sys/stat.h> #include <sys/types.h> -#include <rpcsvc/nfs_prot.h> +#include "nfs-spec.h" #include <hurd/netfs.h> /* A file handle */ @@ -164,6 +164,7 @@ int cred_has_uid (struct netcred *, uid_t); int cred_has_gid (struct netcred *, gid_t); /* nfs.c */ +int hurd_mode_to_nfs_type (mode_t); int *xdr_encode_fhandle (int *, struct fhandle *); int *xdr_encode_data (int *, char *, size_t); int *xdr_encode_string (int *, char *); @@ -74,6 +74,61 @@ register_fresh_stat (struct node *np, int *p) return ret; } +/* Handle returned wcc information for various calls. In protocol + version 2, this is just register_fresh_stat. In version 3, it + checks to see if stat information is present too. If this follows + an operation that we expect has modified the attributes, MOD should + be set. (This unpacks the post_op_attr XDR type.) */ +int * +process_returned_stat (struct node *np, int *p, int mod) +{ + int attrs_exist; + + if (protocol_version == 2) + return register_fresh_stat (np, p); + else + { + attrs_exist = ntohl (*p++); + if (attrs_exist) + p = register_fresh_stat (np, p); + else if (mod) + /* We know that our values are now wrong */ + np->nn->stat_updated = 0; + return p; + } +} + + +/* Handle returned wcc information for various calls. In protocol + version 2, this is just register_fresh_stat. In version 3, it does + the wcc_data interpretation too. If this follows an operation that + we expect has modified the attributes, MOD should be set. + (This unpacks the wcc_data XDR type.) */ +int * +process_wcc_stat (struct node *np, int *p, int mod) +{ + if (protocol_version == 2) + return register_fresh_stat (np, p); + else + { + int attrs_exist; + + /* First the pre_op_attr */ + attrs_exist = ntohl (*p++); + if (attrs_exist) + { + /* Just skip them for now */ + p += 2 * sizeof (int); /* size */ + p += 2 * sizeof (int); /* mtime */ + p += 2 * sizeof (int); /* atime */ + } + + /* Now the post_op_attr */ + return process_returned_stat (np, p, mod); + } +} + + /* Implement the netfs_validate_stat callback as described in <hurd/netfs.h>. */ error_t @@ -116,11 +171,16 @@ netfs_attempt_chown (struct netcred *cred, struct node *np, cred, 0, &rpcbuf, np, gid); p = xdr_encode_fhandle (p, &np->nn->handle); p = xdr_encode_sattr_ids (p, uid, gid); + if (protocol_version == 3) + *p++ = 0; /* guard_check == 0 */ err = conduct_rpc (&rpcbuf, &p); - if (!err) - register_fresh_stat (np, p); + { + err = nfs_error_trans (ntohl (*p++)); + if (!err || protocol_version == 3) + p = process_wcc_stat (np, p, !err); + } free (rpcbuf); @@ -185,14 +245,17 @@ netfs_attempt_chmod (struct netcred *cred, struct node *np, cred, 0, &rpcbuf, np, -1); p = xdr_encode_fhandle (p, &np->nn->handle); p = xdr_encode_sattr_mode (p, mode); + if (protocol_version == 3) + *p++ = 0; /* guard check == 0 */ err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); + { + err = nfs_error_trans (ntohl (*p++)); + if (!err || protocol_version == 3) + p = process_wcc_stat (np, p, !err); + } - if (!err) - register_fresh_stat (np, p); - free (rpcbuf); return err; } @@ -220,13 +283,16 @@ netfs_attempt_utimes (struct netcred *cred, struct node *np, cred, 0, &rpcbuf, np, -1); p = xdr_encode_fhandle (p, &np->nn->handle); p = xdr_encode_sattr_times (p, atime, mtime); + if (protocol_version == 3) + *p++ = 0; /* guard check == 0 */ err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); - - if (!err) - register_fresh_stat (np, p); + { + err = nfs_error_trans (ntohl (*p++)); + if (!err || protocol_version == 3) + p = process_wcc_stat (np, p, !err); + } free (rpcbuf); return err; @@ -246,14 +312,17 @@ netfs_attempt_set_size (struct netcred *cred, struct node *np, cred, 0, &rpcbuf, np, -1); p = xdr_encode_fhandle (p, &np->nn->handle); p = xdr_encode_sattr_size (p, size); + if (protocol_version == 3) + *p++ = 0; /* guard_check == 0 */ err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); + { + err = nfs_error_trans (ntohl (*p++)); + if (!err || protocol_version == 3) + p = process_wcc_stat (np, p, !err); + } - if (!err) - register_fresh_stat (np, p); - free (rpcbuf); return err; } @@ -324,6 +393,7 @@ netfs_attempt_read (struct netcred *cred, struct node *np, size_t trans_len; error_t err; size_t amt, thisamt; + int eof; for (amt = *len; amt;) { @@ -336,36 +406,44 @@ netfs_attempt_read (struct netcred *cred, struct node *np, p = xdr_encode_fhandle (p, &np->nn->handle); *p++ = htonl (offset); *p++ = htonl (thisamt); - *p++ = 0; + if (protocol_version == 2) + *p++ = 0; err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); - - if (err) { - free (rpcbuf); - return err; - } - - p = register_fresh_stat (np, p); - - trans_len = ntohl (*p++); - if (trans_len > thisamt) - trans_len = thisamt; /* ??? */ + err = nfs_error_trans (ntohl (*p++)); + + if (!err || protocol_version == 3) + p = process_returned_stat (np, p, !err); + + if (err) + { + free (rpcbuf); + return err; + } - bcopy (p, data, trans_len); - free (rpcbuf); + trans_len = ntohl (*p++); + if (trans_len > thisamt) + trans_len = thisamt; /* ??? */ - data += trans_len; - offset += trans_len; - amt -= trans_len; + if (protocol_version == 3) + eof = ntohl (*p++); + else + eof = (trans_len < thisamt); + + bcopy (p, data, trans_len); + free (rpcbuf); + + data += trans_len; + offset += trans_len; + amt -= trans_len; - /* If we got a short count, that means we're all done */ - if (trans_len < thisamt) - { - *len -= amt; - return 0; + if (eof) + { + *len -= amt; + return 0; + } } } return 0; @@ -381,6 +459,7 @@ netfs_attempt_write (struct netcred *cred, struct node *np, void *rpcbuf; error_t err; size_t amt, thisamt; + size_t count; for (amt = *len; amt;) { @@ -391,26 +470,47 @@ netfs_attempt_write (struct netcred *cred, struct node *np, p = nfs_initialize_rpc (NFSPROC_WRITE (protocol_version), cred, thisamt, &rpcbuf, np, -1); p = xdr_encode_fhandle (p, &np->nn->handle); - *p++ = 0; + if (protocol_version == 2) + *p++ = 0; *p++ = htonl (offset); - *p++ = 0; + if (protocol_version == 2) + *p++ = 0; + if (protocol_version == 3) + *p++ = htonl (FILE_SYNC); p = xdr_encode_data (p, data, thisamt); err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); - + { + err = nfs_error_trans (ntohl (*p++)); + if (!err || protocol_version == 3) + p = process_wcc_stat (np, p, !err); + if (!err) + { + if (protocol_version == 3) + { + count = ntohl (*p++); + p++; /* ignore COMMITTED */ + /* ignore verf for now */ + p += NFS3_WRITEVERFSIZE / sizeof (int); + } + else + /* assume it wrote the whole thing */ + count = thisamt; + + free (rpcbuf); + amt -= count; + data += count; + offset += count; + } + } + if (err) { *len = 0; free (rpcbuf); return err; } - register_fresh_stat (np, p); - free (rpcbuf); - amt -= thisamt; - data += thisamt; - offset += thisamt; } return 0; } @@ -424,6 +524,8 @@ verify_nonexistent (struct netcred *cred, struct node *dir, void *rpcbuf; error_t err; + assert (protocol_version == 2); + p = nfs_initialize_rpc (NFSPROC_LOOKUP (protocol_version), cred, 0, &rpcbuf, dir, -1); p = xdr_encode_fhandle (p, &dir->nn->handle); @@ -458,12 +560,25 @@ netfs_attempt_lookup (struct netcred *cred, struct node *np, err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); - - if (!err) { - p = lookup_fhandle (p, newnp); - register_fresh_stat (*newnp, p); + err = nfs_error_trans (ntohl (*p++)); + if (!err) + { + p = lookup_fhandle (p, newnp); + p = process_returned_stat (*newnp, p, 1); + } + if (err) + *newnp = 0; + if (protocol_version == 3) + { + if (*newnp) + mutex_unlock (&(*newnp)->lock); + mutex_lock (&np->lock); + p = process_returned_stat (np, p, 0); + mutex_unlock (&np->lock); + if (*newnp) + mutex_lock (&(*newnp)->lock); + } } else *newnp = 0; @@ -519,7 +634,11 @@ netfs_attempt_rmdir (struct netcred *cred, struct node *np, err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); + { + err = nfs_error_trans (ntohl (*p++)); + if (protocol_version == 3) + p = process_wcc_stat (np, p, !err); + } free (rpcbuf); return err; @@ -586,42 +705,71 @@ netfs_attempt_link (struct netcred *cred, struct node *dir, return err; } - p = xdr_encode_string (p, np->nn->transarg.name); - p = xdr_encode_sattr_stat (p, &np->nn_stat); + if (protocol_version == 2) + { + p = xdr_encode_string (p, np->nn->transarg.name); + p = xdr_encode_sattr_stat (p, &np->nn_stat); + } + else + { + p = xdr_encode_sattr_stat (p, &np->nn_stat); + p = xdr_encode_string (p, np->nn->transarg.name); + } mutex_unlock (&np->lock); mutex_lock (&dir->lock); err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); - - if (!err) { - /* NFSPROC_SYMLINK stupidly does not pass back an - fhandle, so we have to fetch one now. */ - p = nfs_initialize_rpc (NFSPROC_LOOKUP (protocol_version), - cred, 0, &rpcbuf, dir, -1); - p = xdr_encode_fhandle (p, &dir->nn->handle); - p = xdr_encode_string (p, name); + err = nfs_error_trans (ntohl (*p++)); + + if (protocol_version == 2 && !err) + { + free (rpcbuf); + + /* NFSPROC_SYMLINK stupidly does not pass back an + fhandle, so we have to fetch one now. */ + p = nfs_initialize_rpc (NFSPROC_LOOKUP (protocol_version), + cred, 0, &rpcbuf, dir, -1); + p = xdr_encode_fhandle (p, &dir->nn->handle); + p = xdr_encode_string (p, name); - err = conduct_rpc (&rpcbuf, &p); - if (!err) - err = nfs_error_trans (ntohl (*p++)); - - mutex_unlock (&dir->lock); - - if (err) - err = EGRATUITOUS; /* damn */ - else + mutex_unlock (&dir->lock); + + err = conduct_rpc (&rpcbuf, &p); + if (!err) + err = nfs_error_trans (ntohl (*p++)); + if (!err) + { + mutex_lock (&np->lock); + p = recache_handle (p, np); + p = process_returned_stat (np, p, 1); + mutex_unlock (&np->lock); + } + if (err) + err = EGRATUITOUS; /* damn */ + } + else if (protocol_version == 3) { - mutex_lock (&np->lock); - p = recache_handle (p, np); - register_fresh_stat (np, p); - mutex_unlock (&np->lock); + if (!err) + { + mutex_unlock (&dir->lock); + mutex_lock (&np->lock); + p = recache_handle (p, np); + p = process_returned_stat (np, p, 1); + mutex_unlock (&np->lock); + mutex_lock (&dir->lock); + } + p = process_wcc_stat (dir, p, !err); + mutex_unlock (&dir->lock); } + else + mutex_unlock (&dir->lock); } else mutex_unlock (&dir->lock); + + free (rpcbuf); break; case CHRDEV: @@ -629,40 +777,87 @@ netfs_attempt_link (struct netcred *cred, struct node *dir, case FIFO: case SOCK: - mutex_lock (&dir->lock); - err = verify_nonexistent (cred, dir, name); - if (err) - return err; + if (protocol_version == 2) + { + mutex_lock (&dir->lock); + err = verify_nonexistent (cred, dir, name); + if (err) + return err; - p = nfs_initialize_rpc (NFSPROC_CREATE (protocol_version), - cred, 0, &rpcbuf, dir, -1); - p = xdr_encode_fhandle (p, &dir->nn->handle); - p = xdr_encode_string (p, name); - mutex_unlock (&dir->lock); + p = nfs_initialize_rpc (NFSPROC_CREATE (protocol_version), + cred, 0, &rpcbuf, dir, -1); + p = xdr_encode_fhandle (p, &dir->nn->handle); + p = xdr_encode_string (p, name); + mutex_unlock (&dir->lock); + + mutex_lock (&np->lock); + err = netfs_validate_stat (np, cred); + if (err) + { + mutex_unlock (&np->lock); + free (rpcbuf); + return err; + } + + p = xdr_encode_sattr_stat (p, &np->nn_stat); + mutex_unlock (&np->lock); - mutex_lock (&np->lock); - err = netfs_validate_stat (np, cred); - if (err) + mutex_lock (&dir->lock); + err = conduct_rpc (&rpcbuf, &p); + if (!err) + err = nfs_error_trans (ntohl (*p++)); + mutex_unlock (&dir->lock); + + mutex_lock (&np->lock); + p = recache_handle (p, np); + register_fresh_stat (np, p); + mutex_unlock (&np->lock); + free (rpcbuf); + } + else { + mutex_lock (&dir->lock); + p = nfs_initialize_rpc (NFS3PROC_MKNOD, cred, 0, &rpcbuf, dir, -1); + p = xdr_encode_fhandle (p, &dir->nn->handle); + p = xdr_encode_string (p, name); + mutex_unlock (&dir->lock); + + mutex_lock (&np->lock); + err = netfs_validate_stat (np, cred); + if (err) + { + mutex_unlock (&np->lock); + free (rpcbuf); + return err; + } + *p++ = htonl (hurd_mode_to_nfs_type (np->nn_stat.st_mode)); + p = xdr_encode_sattr_stat (p, &np->nn_stat); + if (np->nn->dtrans == BLKDEV || np->nn->dtrans == CHRDEV) + { +#define major(D) (((D)>>8) & 0xff) +#define minor(D) ((D) & 0xff) + *p++ = htonl (major (np->nn_stat.st_rdev)); + *p++ = htonl (minor (np->nn_stat.st_rdev)); + } mutex_unlock (&np->lock); + + err = conduct_rpc (&rpcbuf, &p); + if (!err) + { + err = nfs_error_trans (ntohl (*p++)); + if (!err) + { + mutex_lock (&np->lock); + p = recache_handle (p, np); + p = process_returned_stat (np, p, 1); + mutex_unlock (&np->lock); + } + mutex_lock (&dir->lock); + p = process_wcc_stat (dir, p, !err); + mutex_unlock (&dir->lock); + } free (rpcbuf); - return err; } - - p = xdr_encode_sattr_stat (p, &np->nn_stat); - mutex_unlock (&np->lock); - - mutex_lock (&dir->lock); - err = conduct_rpc (&rpcbuf, &p); - if (!err) - err = nfs_error_trans (ntohl (*p++)); - mutex_unlock (&dir->lock); - - mutex_lock (&np->lock); - p = recache_handle (p, np); - register_fresh_stat (np, p); - mutex_unlock (&np->lock); - break; } @@ -743,26 +938,57 @@ netfs_attempt_create_file (struct netcred *cred, struct node *np, void *rpcbuf; error_t err; - err = verify_nonexistent (cred, np, name); - if (err) - return err; + /* RFC 1094 says that create is always exclusive. But Sun doesn't + actually *implement* the spec. No, of course not. So we have to do + it for them. */ + if (protocol_version == 2) + { + err = verify_nonexistent (cred, np, name); + if (err) + return err; + } p = nfs_initialize_rpc (NFSPROC_CREATE (protocol_version), cred, 0, &rpcbuf, np, -1); p = xdr_encode_fhandle (p, &np->nn->handle); p = xdr_encode_string (p, name); - p = xdr_encode_create_state (p, mode); + if (protocol_version == 3) + { + /* We happen to know this is where the XID is. */ + int verf = *(int *)rpcbuf; + + *p++ = ntohl (EXCLUSIVE); + /* 8 byte verf */ + *p++ = ntohl (verf); + p++; + } + else + p = xdr_encode_create_state (p, mode); err = conduct_rpc (&rpcbuf, &p); - if (!err) - err = nfs_error_trans (ntohl (*p++)); mutex_unlock (&np->lock); if (!err) { - p = lookup_fhandle (p, newnp); - register_fresh_stat (*newnp, p); + err = nfs_error_trans (ntohl (*p++)); + if (!err) + { + p = lookup_fhandle (p, newnp); + p = process_returned_stat (*newnp, p, 1); + } + if (err) + *newnp = 0; + if (protocol_version == 3) + { + if (*newnp) + mutex_unlock (&(*newnp)->lock); + mutex_lock (&np->lock); + p = process_wcc_stat (np, p, 1); + mutex_unlock (&np->lock); + if (*newnp) + mutex_lock (&(*newnp)->lock); + } } else *newnp = 0; @@ -839,7 +1065,11 @@ netfs_attempt_unlink (struct netcred *cred, struct node *dir, err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); + { + err = nfs_error_trans (ntohl (*p++)); + if (protocol_version == 3) + p = process_wcc_stat (dir, p, !err); + } free (rpcbuf); @@ -874,7 +1104,15 @@ netfs_attempt_rename (struct netcred *cred, struct node *fromdir, err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); + { + err = nfs_error_trans (ntohl (*p++)); + if (protocol_version == 3) + { + mutex_lock (&fromdir->lock); + p = process_wcc_stat (fromdir, p, !err); + p = process_wcc_stat (todir, p, !err); + } + } free (rpcbuf); return err; @@ -902,10 +1140,13 @@ netfs_attempt_readlink (struct netcred *cred, struct node *np, err = conduct_rpc (&rpcbuf, &p); if (!err) - err = nfs_error_trans (ntohl (*p++)); - - if (!err) - p = xdr_decode_string (p, buf); + { + err = nfs_error_trans (ntohl (*p++)); + if (protocol_version == 3) + p = process_returned_stat (np, p, 0); + if (!err) + p = xdr_decode_string (p, buf); + } free (rpcbuf); return err; @@ -961,11 +1202,13 @@ error_t netfs_check_open_permissions (struct netcred *cred, struct node *np, int flags, int newnode) { + int modes; + if ((flags & (O_READ|O_WRITE|O_EXEC)) == 0) return 0; - if ((flags & (O_READ|O_WRITE|O_EXEC)) - == (flags & guess_mode_use (np, cred))) + netfs_report_access (cred, np, &modes); + if ((flags & (O_READ|O_WRITE|O_EXEC)) == (flags & modes)) return 0; else return EACCES; @@ -978,9 +1221,53 @@ netfs_report_access (struct netcred *cred, struct node *np, int *types) { - *types = guess_mode_use (np, cred); -} + if (protocol_version == 2) + *types = guess_mode_use (np, cred); + else + { + int *p; + void *rpcbuf; + error_t err; + int ret; + int write_check, execute_check; + err = netfs_validate_stat (np, cred); + if (err) + goto fallback; + if (S_ISDIR (np->nn_stat.st_mode)) + { + write_check = ACCESS3_MODIFY | ACCESS3_DELETE | ACCESS3_EXTEND; + execute_check = ACCESS3_LOOKUP; + } + else + { + write_check = ACCESS3_MODIFY; + execute_check = ACCESS3_EXECUTE; + } + + p = nfs_initialize_rpc (NFS3PROC_ACCESS, cred, 0, &rpcbuf, np, -1); + p = xdr_encode_fhandle (p, &np->nn->handle); + *p++ = htonl (ACCESS3_READ | write_check | execute_check); + + err = conduct_rpc (&rpcbuf, &p); + if (!err) + { + err = nfs_error_trans (ntohl (*p++)); + p = process_returned_stat (np, p, 0); + if (!err) + { + ret = ntohl (*p++); + *types = ((ret & ACCESS3_READ ? O_READ : 0) + | (ret & write_check ? O_WRITE : 0) + | (ret & execute_check ? O_EXEC : 0)); + } + else + /* fall back, sigh. */ + fallback: + *types = guess_mode_use (np, cred); + } + } +} /* These definitions have unfortunate side effects, don't use them, clever though they are. */ @@ -193,7 +193,10 @@ conduct_rpc (void **rpcbuf, int **pp) nc = (void *) *pp - *rpcbuf - sizeof (struct rpc_list); cc = write (main_udp_socket, *rpcbuf + sizeof (struct rpc_list), nc); if (cc == -1) - assert_perror (errno); + { + unlink_rpc (hdr); + return errno; + } else assert (cc == nc); diff --git a/nfs/rpcsvc/mount.h b/nfs/rpcsvc/mount.h deleted file mode 100644 index 2dc3dc88..00000000 --- a/nfs/rpcsvc/mount.h +++ /dev/null @@ -1,81 +0,0 @@ -#define MNTPATHLEN 1024 -#define MNTNAMLEN 255 -#define FHSIZE 32 - -typedef char fhandle[FHSIZE]; -bool_t xdr_fhandle(); - - -struct fhstatus { - u_int fhs_status; - union { - fhandle fhs_fhandle; - } fhstatus_u; -}; -typedef struct fhstatus fhstatus; -bool_t xdr_fhstatus(); - - -typedef char *dirpath; -bool_t xdr_dirpath(); - - -typedef char *name; -bool_t xdr_name(); - - -typedef struct mountbody *mountlist; -bool_t xdr_mountlist(); - - -struct mountbody { - name ml_hostname; - dirpath ml_directory; - mountlist ml_next; -}; -typedef struct mountbody mountbody; -bool_t xdr_mountbody(); - - -typedef struct groupnode *groups; -bool_t xdr_groups(); - - -struct groupnode { - name gr_name; - groups gr_next; -}; -typedef struct groupnode groupnode; -bool_t xdr_groupnode(); - - -typedef struct exportnode *exports; -bool_t xdr_exports(); - - -struct exportnode { - dirpath ex_dir; - groups ex_groups; - exports ex_next; -}; -typedef struct exportnode exportnode; -bool_t xdr_exportnode(); - - -#define MOUNTPROG ((u_long)100005) -#define MOUNTVERS ((u_long)1) -#define MOUNTPROC_NULL ((u_long)0) -extern void *mountproc_null_1(); -#define MOUNTPROC_MNT ((u_long)1) -extern fhstatus *mountproc_mnt_1(); -#define MOUNTPROC_DUMP ((u_long)2) -extern mountlist *mountproc_dump_1(); -#define MOUNTPROC_UMNT ((u_long)3) -extern void *mountproc_umnt_1(); -#define MOUNTPROC_UMNTALL ((u_long)4) -extern void *mountproc_umntall_1(); -#define MOUNTPROC_EXPORT ((u_long)5) -extern exports *mountproc_export_1(); -#define MOUNTPROC_EXPORTALL ((u_long)6) -extern exports *mountproc_exportall_1(); - |