afs: Zero uninitialized uio structs
[openafs.git] / src / afs / AIX / osi_misc.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Implements:
12  * Afs_init
13  * gop_rdwr
14  * aix_gnode_rele
15  * afs_suser
16  * aix_vattr_null
17  */
18
19 #include <afsconfig.h>
20 #include "afs/param.h"
21
22
23 #include "h/systm.h"
24 #include "h/types.h"
25 #include "h/errno.h"
26 #include "h/stat.h"
27 #include "h/user.h"
28 #include "h/uio.h"
29 #include "h/vattr.h"
30 #include "h/file.h"
31 #include "h/vfs.h"
32 #include "h/chownx.h"
33 #include "h/systm.h"
34 #include "h/access.h"
35 #include "rpc/types.h"
36 #include "osi_vfs.h"
37 #include "netinet/in.h"
38 #include "h/mbuf.h"
39 #include "rpc/types.h"
40 #include "rpc/xdr.h"
41 #include "h/vmuser.h"
42 #include "h/syspest.h"
43
44 #include "afs/stds.h"
45 #include "afs/afs_osi.h"
46 #define RFTP_INTERNALS 1
47 #include "afs/volerrors.h"
48 #include "afsint.h"
49 #include "vldbint.h"
50 #include "afs/lock.h"
51 #include "afs/exporter.h"
52 #include "afs/afs.h"
53 #include "afs/afs_stats.h"
54
55 /* In Aix one may specify an init routine routine which is called once during
56  * initialization of all gfs; one day we might need to actual do somehing here.
57  */
58 Afs_init(gfsp)
59      char *gfsp;                /* this is really struct gfs *, but we do not use it */
60 {
61     extern int afs_gn_strategy();
62 #define AFS_VM_BUFS 50
63
64     /* For now nothing special is required during AFS initialization. */
65     AFS_STATCNT(afs_init);
66
67     (void)vm_mount(D_REMOTE, afs_gn_strategy, AFS_VM_BUFS);
68     return 0;
69 }
70
71
72 /* Some extra handling is needed when calling the aix's version of the local
73  * RDWR module, particularly the usage of the uio structure to the lower
74  *  routine. Note of significant importance to the AFS port is the offset 
75  * in/out parameter, which in two cases returns a new value back. The cases
76  * are: (1) when it's a FIFO file (it's reset to zero) which we don't yet
77  * support in AFS and (2) in a regular case when we write
78  * (i.e. rw == UIO_WRITE) and are in appending mode (i.e. FAPPEND bit on)
79  * where offset is set to the file's size. None of these cases apply to us
80  * currently so no problems occur; caution if things change!
81  */
82 int
83 gop_rdwr(rw, vp, base, len, offset, segflg, unit, aresid)
84      enum uio_rw rw;
85      struct vnode *vp;
86      caddr_t base;
87 #ifdef AFS_64BIT_KERNEL
88      offset_t *offset;
89 #else
90      off_t *offset;
91 #endif
92      int len, segflg;
93      int *aresid;
94      int unit;                  /* Ignored */
95 {
96     struct uio uio_struct;
97     struct iovec uiovector;
98     int code;
99
100     memset(&uio_struct, 0, sizeof(uio_struct));
101     memset(&uiovector, 0, sizeof(uiovector));
102
103     AFS_STATCNT(gop_rdwr);
104     /* Set up the uio structure */
105     uiovector.iov_base = (caddr_t) base;
106     uiovector.iov_len = len;
107
108     uio_struct.uio_iov = &uiovector;
109     uio_struct.uio_iovcnt = 1;
110     uio_struct.uio_offset = *offset;
111     uio_struct.uio_segflg = AFS_UIOSYS;
112     uio_struct.uio_resid = len;
113     uio_struct.uio_fmode = (rw == UIO_READ ? FREAD : FWRITE);
114
115 #ifdef AFS_64BIT_KERNEL
116     code =
117         VNOP_RDWR(vp, rw, (int32long64_t) (rw == UIO_READ ? FREAD : FWRITE),
118                   &uio_struct, (ext_t) 0, (caddr_t) 0, (struct vattr *)0,
119                   &afs_osi_cred);
120 #else
121     code =
122         VNOP_RDWR(vp, rw, (rw == UIO_READ ? FREAD : FWRITE), &uio_struct,
123                   NULL, NULL, NULL, &afs_osi_cred);
124 #endif
125     *aresid = uio_struct.uio_resid;
126     return code;
127 }
128
129
130 /* Since in AIX a vnode is included in linked lists of its associated vfs and
131  * gnode we need to remove these links when removing an AFS vnode (part of the
132  * vcache entry).  Note that since the accompanied gnode was alloced during
133  * vcache creation, we have to free it here too. We don't bother with the
134  * vnode itself since it's part of the vcache entry and it's handled fine by
135  * default.
136  * 
137  * Note that there is a 1-1 mapping from AFS vnodes to gnodes, so there is
138  * no linked list of gnodes to remove this element from.
139  */
140 aix_gnode_rele(vp)
141      struct vnode *vp;
142 {
143     struct vnode *tvp;
144     struct vfs *vfsp = vp->v_vfsp;
145
146     /* Unlink the vnode from the list the vfs has hanging of it */
147     tvp = vfsp->vfs_vnodes;
148     if (tvp == vp)
149         vfsp->vfs_vnodes = vp->v_vfsnext;
150     if (vp->v_vfsnext != NULL)
151         vp->v_vfsnext->v_vfsprev = vp->v_vfsprev;
152     if (vp->v_vfsprev != NULL)
153         vp->v_vfsprev->v_vfsnext = vp->v_vfsnext;
154
155   endgnode:
156     /* Free the allocated gnode that was accompanying the vcache's vnode */
157     if (vp->v_gnode) {
158         osi_FreeSmallSpace(vp->v_gnode);
159         vp->v_gnode = 0;
160     }
161
162     return 0;
163 }
164
165 /*
166  * afs_suser() returns true if the caller is superuser, false otherwise.
167  *
168  * Note that it must NOT set errno.
169  */
170
171 afs_suser(void *credp)
172 {
173     int rc;
174     char err;
175
176     rc = suser(&err);
177     return rc;
178 }