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