2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * osi_vfsops.c for DUX
13 #include <afsconfig.h>
14 #include "../afs/param.h"
18 #include "../afs/sysincludes.h" /* Standard vendor system headers */
19 #include "../afs/afsincludes.h" /* Afs-based standard headers */
20 #include "../afs/afs_stats.h" /* statistics stuff */
21 #include <sys/types.h>
22 #include <kern/mach_param.h>
23 #include <sys/sysconfig.h>
24 #include <sys/systm.h>
25 #include <sys/resource.h>
26 #include <sys/errno.h>
28 #include <machine/machlimits.h>
31 struct vcache *afs_globalVp = 0;
32 struct mount *afs_globalVFS = 0;
34 static u_char afs_mntid;
36 udecl_simple_lock_data(, afsmntid_lock)
37 #define AFSMNTID_LOCK() usimple_lock(&afsmntid_lock)
38 #define AFSMNTID_UNLOCK() usimple_unlock(&afsmntid_lock)
39 #define AFSMNTID_LOCK_INIT() usimple_lock_init(&afsmntid_lock)
42 int mp_afs_mount(struct mount *afsp,char * path, caddr_t data,
43 struct nameidata *ndp)
48 struct mount *xmp, *getvfs();
52 AFS_STATCNT(afs_mount);
54 if (afs_globalVFS) { /* Don't allow remounts. */
60 afsp->vfs_bsize = 8192;
62 * Generate a unique afs mount i.d. ( see nfs_mount() ).
64 afsp->m_stat.f_fsid.val[0] = makedev(130, 0);
65 afsp->m_stat.f_fsid.val[1] = MOUNT_AFS;
71 tfsid.val[0] = makedev(130, afs_mntid);
72 tfsid.val[1] = MOUNT_AFS;
73 BM(AFSMNTID_UNLOCK());
75 while (xmp = getvfs(&tfsid)) {
76 UNMOUNT_READ_UNLOCK(xmp);
82 if (major(tfsid.val[0]) != 130) {
86 afsp->m_stat.f_fsid.val[0] = tfsid.val[0];
88 afsp->m_stat.f_mntonname = AFS_KALLOC(MNAMELEN);
89 afsp->m_stat.f_mntfromname = AFS_KALLOC(MNAMELEN);
90 if ( !afsp->m_stat.f_mntonname || !afsp->m_stat.f_mntfromname)
91 panic("malloc failure in afs_mount\n");
93 bzero(afsp->m_stat.f_mntonname, MNAMELEN);
94 bzero(afsp->m_stat.f_mntfromname, MNAMELEN);
95 AFS_COPYINSTR(path, (caddr_t)afsp->m_stat.f_mntonname, MNAMELEN, &size, code);
96 bcopy("AFS", afsp->m_stat.f_mntfromname, 4);
98 (void) mp_afs_statfs(afsp);
100 afs_vfsdev = afsp->m_stat.f_fsid.val[0];
102 #ifndef AFS_NONFSTRANS
103 /* Set up the xlator in case it wasn't done elsewhere */
112 int mp_afs_unmount (struct mount *afsp, int flag)
115 AFS_STATCNT(afs_unmount);
123 int mp_afs_start(struct mount *mp, int flags)
128 int mp_afs_root (struct mount *afsp, struct vnode **avpp)
130 register afs_int32 code = 0;
131 struct vrequest treq;
132 register struct vcache *tvp=0;
135 AFS_STATCNT(afs_root);
136 if (afs_globalVp && (afs_globalVp->states & CStatd)) {
139 if (!(code = afs_InitReq(&treq, cred)) &&
140 !(code = afs_CheckInit())) {
141 tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0,
142 (struct vcache*)0, WRITE_LOCK);
143 /* we really want this to stay around */
152 VN_HOLD((struct vnode *)tvp);
153 VN_LOCK((struct vnode *)tvp);
154 tvp->v.v_flag |= VROOT; /* No-op on Ultrix 2.2 */
155 VN_UNLOCK((struct vnode *)tvp);
158 afs_globalVFS = afsp;
159 *avpp = (struct vnode *) tvp;
162 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *avpp,
163 ICL_TYPE_INT32, code);
169 mp_afs_quotactl(struct mount *mp, int cmd, uid_t uid, caddr_t arg)
174 int mp_afs_statfs(struct mount *afsp)
176 struct nstatfs *abp = &afsp->m_stat;
179 AFS_STATCNT(afs_statfs);
181 abp->f_type = MOUNT_AFS;
182 abp->f_bsize = afsp->vfs_bsize;
184 /* Fake a high number below to satisfy programs that use the statfs call
185 * to make sure that there's enough space in the device partition before
186 * storing something there.
188 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
189 abp->f_ffree = 2000000;
192 abp->f_fsid.val[0] = afsp->m_stat.f_fsid.val[0];
193 abp->f_fsid.val[1] = afsp->m_stat.f_fsid.val[1];
200 int mp_afs_sync(struct mount *mp, int flags)
202 AFS_STATCNT(afs_sync);
207 int mp_afs_fhtovp(struct mount *afsp, struct fid *fidp, struct vnode **avcp)
209 struct vrequest treq;
213 AFS_STATCNT(afs_vget);
217 if ((code = afs_InitReq(&treq, cred)) == 0) {
218 code = afs_osi_vget((struct vcache**)avcp, fidp, &treq);
221 afs_Trace3(afs_iclSetp, CM_TRACE_VGET, ICL_TYPE_POINTER, *avcp,
222 ICL_TYPE_INT32, treq.uid, ICL_TYPE_FID, fidp);
224 code = afs_CheckCode(code, &treq, 42);
233 * afs_vptofh can return two flavors of NFS fid, depending on if submounts are
234 * allowed. The reason for this is that we can't guarantee that we found all
235 * the entry points any OS might use to get the fid for the NFS mountd.
236 * Hence we return a "magic" fid for all but /afs. If it goes through the
237 * translator code, it will get transformed into a SmallFid that we recognize.
238 * So, if submounts are disallowed, and an NFS client tries a submount, it will
239 * get a fid which we don't recognize and the mount will either fail or we
240 * will ignore subsequent requests for that mount.
242 * The Alpha fid is organized differently than for other platforms. Their
243 * intention was to have the data portion of the fid aligned on a 4 byte
244 * boundary. To do so, the fid is organized as:
248 * The len field is the length of the entire fid, from reserved through data.
249 * This length is used by fid_copy to include copying the reserved field.
250 * Alpha's zero the reserved field before handing us the fid, but they use
251 * it in fid_cmp. We use the reserved field to store the 16 bits of the Vnode.
253 * Note that the SmallFid only allows for 8 bits of the cell index and
254 * 16 bits of the vnode.
257 #define AFS_FIDDATASIZE 8
258 #define AFS_SIZEOFSMALLFID 12 /* full size of fid, including len field */
259 extern int afs_NFSRootOnly; /* 1 => only allow NFS mounts of /afs. */
260 int afs_fid_vnodeoverflow=0, afs_fid_uniqueoverflow=0;
262 int mp_afs_vptofh(struct vnode *avn, struct fid *fidp)
264 struct SmallFid Sfid;
266 register struct cell *tcell;
268 struct vcache *avc = (struct vcache *)avn;
271 AFS_STATCNT(afs_fid);
273 if (afs_shuttingdown) {
278 if (afs_NFSRootOnly && (avc == afs_globalVp)) rootvp = 1;
279 if (!afs_NFSRootOnly || rootvp) {
280 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
281 Sfid.Volume = avc->fid.Fid.Volume;
282 fidp->fid_reserved = avc->fid.Fid.Vnode;
283 Sfid.CellAndUnique = ((tcell->cellIndex << 24) +
284 (avc->fid.Fid.Unique & 0xffffff));
285 afs_PutCell(tcell, READ_LOCK);
286 if (avc->fid.Fid.Vnode > 0xffff)
287 afs_fid_vnodeoverflow++;
288 if (avc->fid.Fid.Unique > 0xffffff)
289 afs_fid_uniqueoverflow++;
291 fidp->fid_reserved = AFS_XLATOR_MAGIC;
294 VN_HOLD((struct vnode *)avc);
298 /* Use the fid pointer passed to us. */
299 fidp->fid_len = AFS_SIZEOFSMALLFID;
300 if (afs_NFSRootOnly) {
302 bcopy((caddr_t)&Sfid, fidp->fid_data, AFS_FIDDATASIZE);
304 bcopy((caddr_t)addr, fidp->fid_data, AFS_FIDDATASIZE);
307 bcopy((caddr_t)&Sfid, fidp->fid_data, AFS_FIDDATASIZE);
314 int mp_Afs_init(void); /* vfs_init - defined below */
317 /* This is only called by vfs_mount when afs is going to be mounted as root.
318 * Since we don't support diskless clients we shouldn't come here.
321 int mp_afs_mountroot(struct mount *afsp, struct vnode **vp)
324 AFS_STATCNT(afs_mountroot);
331 /* It's called to setup swapping over the net for diskless clients; again
335 int mp_afs_swapvp(void)
338 AFS_STATCNT(afs_swapvp);
345 struct vfsops afs_vfsops = {
353 mp_afs_fhtovp, /* afs_vget */
362 * System Call Entry Points
364 #define NULL_FUNC (int (*)(int))0
366 int (*afs_syscall_func)() = NULL_FUNC;
367 int (*afs_xsetgroups_func)() = NULL_FUNC;
368 int (*afs_xioctl_func)() = NULL_FUNC;
370 afssyscall(p, args, retval)
379 func = afs_syscall_func;
380 if (func == NULL_FUNC) {
381 code = nosys(p, args, retval);
383 code = (*func)(p, args, retval);
389 afsxsetgroups(p, args, retval)
398 func = afs_xsetgroups_func;
399 if (func == NULL_FUNC) {
400 code = nosys(p, args, retval);
402 code = (*func)(p, args, retval);
408 afsxioctl(p, args, retval)
417 func = afs_xioctl_func;
418 if (func == NULL_FUNC) {
419 code = nosys(p, args, retval);
421 code = (*func)(p, args, retval);
429 * VFS initialization and unload
438 cfg_subsys_attr_t afs_attributes[] = {
439 {"", 0, 0, 0, 0, 0, 0} /* must be the last element */
442 afs_configure(cfg_op_t op, caddr_t indata, size_t indata_size, caddr_t outdata, size_t outdata_size)
444 cfg_attr_t *attributes;
450 case CFG_OP_CONFIGURE:
452 * The indata parameter is a list of attributes to be configured, and
453 * indata_size is the count of attributes.
455 if ((ret = vfssw_add_fsname(MOUNT_AFS, &afs_vfsops, "afs")) != 0)
458 case CFG_OP_UNCONFIGURE:
459 if ((ret = afs_unconfig()) != 0)
470 int mp_Afs_init(void)
472 extern int Afs_xsetgroups(), afs_xioctl(), afs3_syscall();
475 sysent[AFS_SYSCALL].sy_call = afs3_syscall;
476 sysent[AFS_SYSCALL].sy_parallel = 0;
477 sysent[AFS_SYSCALL].sy_narg = 6;
478 sysent[SYS_setgroups].sy_call = Afs_xsetgroups;
479 afs_xioctl_func = afsxioctl;
480 afs_xsetgroups_func = afsxsetgroups;
481 afs_syscall_func = afssyscall;