Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / AIX / osi_misc.c
CommitLineData
805e021f
CE
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/xdr.h"
40#include "h/vmuser.h"
41#include "h/syspest.h"
42
43#include "afs/stds.h"
44#include "afs/afs_osi.h"
45#define RFTP_INTERNALS 1
46#include "afs/volerrors.h"
47#include "afsint.h"
48#include "vldbint.h"
49#include "afs/lock.h"
50#include "afs/exporter.h"
51#include "afs/afs.h"
52#include "afs/afs_stats.h"
53
54/* In Aix one may specify an init routine routine which is called once during
55 * initialization of all gfs; one day we might need to actual do somehing here.
56 */
57Afs_init(gfsp)
58 char *gfsp; /* this is really struct gfs *, but we do not use it */
59{
60 extern int afs_gn_strategy();
61#define AFS_VM_BUFS 50
62
63 /* For now nothing special is required during AFS initialization. */
64 AFS_STATCNT(afs_init);
65
66 (void)vm_mount(D_REMOTE, afs_gn_strategy, AFS_VM_BUFS);
67 return 0;
68}
69
70
71/* Some extra handling is needed when calling the aix's version of the local
72 * RDWR module, particularly the usage of the uio structure to the lower
73 * routine. Note of significant importance to the AFS port is the offset
74 * in/out parameter, which in two cases returns a new value back. The cases
75 * are: (1) when it's a FIFO file (it's reset to zero) which we don't yet
76 * support in AFS and (2) in a regular case when we write
77 * (i.e. rw == UIO_WRITE) and are in appending mode (i.e. FAPPEND bit on)
78 * where offset is set to the file's size. None of these cases apply to us
79 * currently so no problems occur; caution if things change!
80 */
81int
82gop_rdwr(rw, vp, base, len, offset, segflg, unit, aresid)
83 enum uio_rw rw;
84 struct vnode *vp;
85 caddr_t base;
86#ifdef AFS_64BIT_KERNEL
87 offset_t *offset;
88#else
89 off_t *offset;
90#endif
91 int len, segflg;
92 int *aresid;
93 int unit; /* Ignored */
94{
95 struct uio uio_struct;
96 struct iovec uiovector;
97 int code;
98
99 memset(&uio_struct, 0, sizeof(uio_struct));
100 memset(&uiovector, 0, sizeof(uiovector));
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 */
139aix_gnode_rele(vp)
140 struct vnode *vp;
141{
142 struct vnode *tvp;
143 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
170afs_suser(void *credp)
171{
172 int rc;
173 char err;
174
175 rc = suser(&err);
176 return rc;
177}