Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/nfs Be more correct with attribute structures for setatt...



details:   https://anonhg.NetBSD.org/src/rev/34b98ebf16bb
branches:  trunk
changeset: 473313:34b98ebf16bb
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Sat May 29 01:22:03 1999 +0000

description:
Be more correct with attribute structures for setattr RPCs and friends,
so that picky servers (e.g. Solaris 7) don't refuse our requests. Move
some code into a macro, and a bit of KNF. From OpenBSD.

diffstat:

 sys/nfs/nfs_vnops.c |  99 ++++++++--------------------------------------------
 sys/nfs/nfsm_subs.h |  73 +++++++++++++++++++++++++++++++++-----
 2 files changed, 78 insertions(+), 94 deletions(-)

diffs (259 lines):

diff -r 58737c5a6eef -r 34b98ebf16bb sys/nfs/nfs_vnops.c
--- a/sys/nfs/nfs_vnops.c       Fri May 28 22:59:40 1999 +0000
+++ b/sys/nfs/nfs_vnops.c       Sat May 29 01:22:03 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs_vnops.c,v 1.100 1999/03/24 05:51:29 mrg Exp $      */
+/*     $NetBSD: nfs_vnops.c,v 1.101 1999/05/29 01:22:03 fvdl Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -675,64 +675,7 @@
        nfsm_reqhead(vp, NFSPROC_SETATTR, NFSX_FH(v3) + NFSX_SATTR(v3));
        nfsm_fhtom(vp, v3);
        if (v3) {
-               if (vap->va_mode != (mode_t)VNOVAL) {
-                       nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
-                       *tl++ = nfs_true;
-                       *tl = txdr_unsigned(vap->va_mode);
-               } else {
-                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
-                       *tl = nfs_false;
-               }
-               if (vap->va_uid != (uid_t)VNOVAL) {
-                       nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
-                       *tl++ = nfs_true;
-                       *tl = txdr_unsigned(vap->va_uid);
-               } else {
-                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
-                       *tl = nfs_false;
-               }
-               if (vap->va_gid != (gid_t)VNOVAL) {
-                       nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
-                       *tl++ = nfs_true;
-                       *tl = txdr_unsigned(vap->va_gid);
-               } else {
-                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
-                       *tl = nfs_false;
-               }
-               if (vap->va_size != VNOVAL) {
-                       nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
-                       *tl++ = nfs_true;
-                       txdr_hyper(vap->va_size, tl);
-               } else {
-                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
-                       *tl = nfs_false;
-               }
-               if (vap->va_atime.tv_sec != VNOVAL) {
-                       if (vap->va_atime.tv_sec != time.tv_sec) {
-                               nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
-                               *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);
-                               txdr_nfsv3time(&vap->va_atime, tl);
-                       } else {
-                               nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
-                               *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);
-                       }
-               } else {
-                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
-                       *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);
-               }
-               if (vap->va_mtime.tv_sec != VNOVAL) {
-                       if (vap->va_mtime.tv_sec != time.tv_sec) {
-                               nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
-                               *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);
-                               txdr_nfsv3time(&vap->va_mtime, tl);
-                       } else {
-                               nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
-                               *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);
-                       }
-               } else {
-                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
-                       *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);
-               }
+               nfsm_v3attrbuild(vap, TRUE);
                nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
                *tl = nfs_false;
        } else {
@@ -1199,7 +1142,6 @@
        register struct vattr *vap;
 {
        register struct nfsv2_sattr *sp;
-       register struct nfsv3_sattr *sp3;
        register u_int32_t *tl;
        register caddr_t cp;
        register int32_t t1, t2;
@@ -1227,10 +1169,9 @@
        nfsm_fhtom(dvp, v3);
        nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
        if (v3) {
-               nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3SRVSATTR);
+               nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
                *tl++ = vtonfsv3_type(vap->va_type);
-               sp3 = (struct nfsv3_sattr *)tl;
-               nfsm_v3sattr(sp3, vap);
+               nfsm_v3attrbuild(vap, FALSE);
                if (vap->va_type == VCHR || vap->va_type == VBLK) {
                        nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
                        *tl++ = txdr_unsigned(major(vap->va_rdev));
@@ -1320,7 +1261,6 @@
        register struct vattr *vap = ap->a_vap;
        register struct componentname *cnp = ap->a_cnp;
        register struct nfsv2_sattr *sp;
-       register struct nfsv3_sattr *sp3;
        register u_int32_t *tl;
        register caddr_t cp;
        register int32_t t1, t2;
@@ -1350,18 +1290,16 @@
        if (v3) {
                nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
                if (fmode & O_EXCL) {
-                   *tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE);
-                   nfsm_build(tl, u_int32_t *, NFSX_V3CREATEVERF);
-                   if (in_ifaddr.tqh_first)
-                       *tl++ = in_ifaddr.tqh_first->ia_addr.sin_addr.s_addr;
-                   else
-                       *tl++ = create_verf;
-                   *tl = ++create_verf;
+                       *tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE);
+                       nfsm_build(tl, u_int32_t *, NFSX_V3CREATEVERF);
+                       if (in_ifaddr.tqh_first)
+                               *tl++ = in_ifaddr.tqh_first->ia_addr.sin_addr.s_addr;
+                       else
+                               *tl++ = create_verf;
+                       *tl = ++create_verf;
                } else {
-                   *tl = txdr_unsigned(NFSV3CREATE_UNCHECKED);
-                   nfsm_build(tl, u_int32_t *, NFSX_V3SRVSATTR);
-                   sp3 = (struct nfsv3_sattr *)tl;
-                   nfsm_v3sattr(sp3, vap);
+                       *tl = txdr_unsigned(NFSV3CREATE_UNCHECKED);
+                       nfsm_v3attrbuild(vap, FALSE);
                }
        } else {
                nfsm_build(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
@@ -1741,7 +1679,6 @@
        register struct vattr *vap = ap->a_vap;
        register struct componentname *cnp = ap->a_cnp;
        register struct nfsv2_sattr *sp;
-       register struct nfsv3_sattr *sp3;
        register u_int32_t *tl;
        register caddr_t cp;
        register int32_t t1, t2;
@@ -1757,10 +1694,8 @@
            nfsm_rndup(cnp->cn_namelen) + nfsm_rndup(slen) + NFSX_SATTR(v3));
        nfsm_fhtom(dvp, v3);
        nfsm_strtom(cnp->cn_nameptr, cnp->cn_namelen, NFS_MAXNAMLEN);
-       if (v3) {
-               nfsm_build(sp3, struct nfsv3_sattr *, NFSX_V3SRVSATTR);
-               nfsm_v3sattr(sp3, vap);
-       }
+       if (v3)
+               nfsm_v3attrbuild(vap, FALSE);
        nfsm_strtom(ap->a_target, slen, NFS_MAXPATHLEN);
        if (!v3) {
                nfsm_build(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
@@ -1810,7 +1745,6 @@
        register struct vattr *vap = ap->a_vap;
        register struct componentname *cnp = ap->a_cnp;
        register struct nfsv2_sattr *sp;
-       register struct nfsv3_sattr *sp3;
        register u_int32_t *tl;
        register caddr_t cp;
        register int32_t t1, t2;
@@ -1830,8 +1764,7 @@
        nfsm_fhtom(dvp, v3);
        nfsm_strtom(cnp->cn_nameptr, len, NFS_MAXNAMLEN);
        if (v3) {
-               nfsm_build(sp3, struct nfsv3_sattr *, NFSX_V3SRVSATTR);
-               nfsm_v3sattr(sp3, vap);
+               nfsm_v3attrbuild(vap, FALSE);
        } else {
                nfsm_build(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
                sp->sa_mode = vtonfsv2_mode(VDIR, vap->va_mode);
diff -r 58737c5a6eef -r 34b98ebf16bb sys/nfs/nfsm_subs.h
--- a/sys/nfs/nfsm_subs.h       Fri May 28 22:59:40 1999 +0000
+++ b/sys/nfs/nfsm_subs.h       Sat May 29 01:22:03 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfsm_subs.h,v 1.19 1999/03/06 05:34:41 fair Exp $      */
+/*     $NetBSD: nfsm_subs.h,v 1.20 1999/05/29 01:22:03 fvdl Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -229,17 +229,68 @@
                        (f) = ttattrf; \
                } }
 
-#define nfsm_v3sattr(s, a) \
-               { (s)->sa_modetrue = nfs_true; \
-               (s)->sa_mode = vtonfsv3_mode((a)->va_mode); \
-               (s)->sa_uidfalse = nfs_false; \
-               (s)->sa_gidfalse = nfs_false; \
-               (s)->sa_sizefalse = nfs_false; \
-               (s)->sa_atimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
-               txdr_nfsv3time(&(a)->va_atime, &(s)->sa_atime); \
-               (s)->sa_mtimetype = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
-               txdr_nfsv3time(&(a)->va_mtime, &(s)->sa_mtime); \
+/* If full is true, set all fields, otherwise just set mode and time fields */
+#define nfsm_v3attrbuild(a, full)                                              \
+               { if ((a)->va_mode != (mode_t)VNOVAL) {                         \
+                       nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);         \
+                       *tl++ = nfs_true;                                       \
+                       *tl = txdr_unsigned((a)->va_mode);                      \
+               } else {                                                        \
+                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);             \
+                       *tl = nfs_false;                                        \
+               }                                                               \
+               if ((full) && (a)->va_uid != (uid_t)VNOVAL) {                   \
+                       nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);         \
+                       *tl++ = nfs_true;                                       \
+                       *tl = txdr_unsigned((a)->va_uid);                       \
+               } else {                                                        \
+                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);             \
+                       *tl = nfs_false;                                        \
+               }                                                               \
+               if ((full) && (a)->va_gid != (gid_t)VNOVAL) {                   \
+                       nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);         \
+                       *tl++ = nfs_true;                                       \
+                       *tl = txdr_unsigned((a)->va_gid);                       \
+               } else {                                                        \
+                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);             \
+                       *tl = nfs_false;                                        \
+               }                                                               \
+               if ((full) && (a)->va_size != VNOVAL) {                         \
+                       nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);         \
+                       *tl++ = nfs_true;                                       \
+                       txdr_hyper((a)->va_size, tl);                           \
+               } else {                                                        \
+                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);             \
+                       *tl = nfs_false;                                        \
+               }                                                               \
+               if ((a)->va_atime.tv_sec != VNOVAL) {                           \
+                       if ((a)->va_atime.tv_sec != time.tv_sec) {              \
+                               nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
+                               *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
+                               txdr_nfsv3time(&(a)->va_atime, tl);             \
+                       } else {                                                \
+                               nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);     \
+                               *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);   \
+                       }                                                       \
+               } else {                                                        \
+                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);             \
+                       *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);         \
+               }                                                               \
+               if ((a)->va_mtime.tv_sec != VNOVAL) {                           \
+                       if ((a)->va_mtime.tv_sec != time.tv_sec) {              \
+                               nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
+                               *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT); \
+                               txdr_nfsv3time(&(a)->va_mtime, tl);             \
+                       } else {                                                \
+                               nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);     \
+                               *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);   \
+                       }                                                       \
+               } else {                                                        \
+                       nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);             \
+                       *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);         \
+               }                                                               \
                }
+                               
 
 #define        nfsm_strsiz(s,m) \
                { nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \



Home | Main Index | Thread Index | Old Index