diff options
Diffstat (limited to 'nfsd/xdr.c')
-rw-r--r-- | nfsd/xdr.c | 116 |
1 files changed, 65 insertions, 51 deletions
@@ -1,5 +1,7 @@ -/* XDR packing and unpacking in nfsd - Copyright (C) 1996 Free Software Foundation, Inc. +/* xdr.c - XDR packing and unpacking in nfsd. + + Copyright (C) 1996, 2002, 2007 Free Software Foundation, Inc. + Written by Michael I. Bushnell, p/BSG. This file is part of the GNU Hurd. @@ -23,26 +25,15 @@ #include <string.h> #include "nfsd.h" -/* Return the address of the next thing after the credential at P. */ -int * -skip_cred (int *p) -{ - int size; - - p++; /* TYPE */ - size = ntohl (*p++); - return p + INTSIZE (size); -} - -/* Any better ideas? */ +/* Any better ideas? */ static int hurd_mode_to_nfs_mode (mode_t m) { - return m & 0x177777; + return m & 0177777; } static int -hurd_mode_to_nfs_type (mode_t m) +hurd_mode_to_nfs_type (mode_t m, int version) { switch (m & S_IFMT) { @@ -65,84 +56,93 @@ hurd_mode_to_nfs_type (mode_t m) return NFSOCK; case S_IFIFO: - return NFFIFO; + return (version == 2 ? NF2FIFO : NF3FIFO); default: - return NFNON; + return (version == 2 ? NF2NON : NFREG); } } -/* Encode ST into P and return the next thing to come after it. */ +/* Encode ST into P and return the next thing to come after it. */ int * -encode_fattr (int *p, struct stat *st) +encode_fattr (int *p, struct stat *st, int version) { - *p++ = htonl (hurd_mode_to_nfs_type (st->st_mode)); - *p++ = htonl (hurd_mode_to_nfs_mode (st->st_mode)); - *p++ = htonl (st->st_nlink); - *p++ = htonl (st->st_uid); - *p++ = htonl (st->st_gid); - *p++ = htonl (st->st_size); - *p++ = htonl (st->st_blksize); - *p++ = htonl (st->st_rdev); - *p++ = htonl (st->st_blocks); + *(p++) = htonl (hurd_mode_to_nfs_type (st->st_mode, version)); + *(p++) = htonl (hurd_mode_to_nfs_mode (st->st_mode)); + *(p++) = htonl (st->st_nlink); + *(p++) = htonl (st->st_uid); + *(p++) = htonl (st->st_gid); + *(p++) = htonl (st->st_size); + *(p++) = htonl (st->st_blksize); + *(p++) = htonl (st->st_rdev); + *(p++) = htonl (st->st_blocks); + *(p++) = htonl (st->st_fsid); + *(p++) = htonl (st->st_ino); + *(p++) = htonl (st->st_atim.tv_sec); + *(p++) = htonl (st->st_atim.tv_nsec / 1000); + *(p++) = htonl (st->st_mtim.tv_sec); + *(p++) = htonl (st->st_mtim.tv_nsec / 1000); + *(p++) = htonl (st->st_ctim.tv_sec); + *(p++) = htonl (st->st_ctim.tv_nsec / 1000); return p; } -/* Decode P into NAME and return the next thing to come after it. */ +/* Decode P into NAME and return the next thing to come after it. */ int * decode_name (int *p, char **name) { int len; - len = ntohl (*p++); + len = ntohl (*p); + p++; *name = malloc (len + 1); - bcopy (p, *name, len); + memcpy (*name, p, len); (*name)[len] = '\0'; return p + INTSIZE (len); } -/* Encode HANDLE into P and return the next thing to come after it. */ +/* Encode HANDLE into P and return the next thing to come after it. */ int * encode_fhandle (int *p, char *handle) { - bcopy (handle, p, NFS_FHSIZE); - return p + INTSIZE (NFS_FHSIZE); + memcpy (p, handle, NFS2_FHSIZE); + return p + INTSIZE (NFS2_FHSIZE); } -/* Encode STRING into P and return the next thing to come after it. */ +/* Encode STRING into P and return the next thing to come after it. */ int * encode_string (int *p, char *string) { return encode_data (p, string, strlen (string)); } -/* Encode DATA into P and return the next thing to come after it. */ +/* Encode DATA into P and return the next thing to come after it. */ int * encode_data (int *p, char *data, size_t len) { int nints = INTSIZE (len); p[nints] = 0; - *p++ = htonl (len); - bcopy (data, p, len); + *(p++) = htonl (len); + memcpy (p, data, len); return p + nints; } -/* Encode ST into P and return the next thing to come after it. */ +/* Encode ST into P and return the next thing to come after it. */ int * encode_statfs (int *p, struct statfs *st) { - *p++ = st->f_bsize; - *p++ = st->f_bsize; - *p++ = st->f_blocks; - *p++ = st->f_bfree; - *p++ = st->f_bavail; + *(p++) = st->f_bsize; + *(p++) = st->f_bsize; + *(p++) = st->f_blocks; + *(p++) = st->f_bfree; + *(p++) = st->f_bavail; return p; } -/* Return an NFS error corresponding to Hurd error ERR. */ +/* Return an NFS error corresponding to Hurd error ERR. */ int -nfs_error_trans (error_t err) +nfs_error_trans (error_t err, int version) { switch (err) { @@ -156,7 +156,6 @@ nfs_error_trans (error_t err) return NFSERR_NOENT; case EIO: - default: return NFSERR_IO; case ENXIO: @@ -197,8 +196,23 @@ nfs_error_trans (error_t err) case ESTALE: return NFSERR_STALE; + + default: + if (version == 2) + return NFSERR_IO; + else switch (err) + { + case EXDEV: + return NFSERR_XDEV; + + case EINVAL: + return NFSERR_INVAL; + + case EOPNOTSUPP: + return NFSERR_NOTSUPP; /* Are we sure here? */ + + default: + return NFSERR_IO; + } } } - - - |