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