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