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