5 #include <afs/sysincludes.h> /* Standard vendor system headers */
6 #include <afsincludes.h> /* Afs-based standard headers */
7 #include <afs/afs_stats.h> /* statistics */
8 #include <sys/malloc.h>
11 #include <sys/module.h>
12 #include <sys/sysproto.h>
13 #include <sys/syscall.h>
14 #include <sys/sysent.h>
16 struct vcache *afs_globalVp = NULL;
17 struct mount *afs_globalVFS = NULL;
18 int afs_pbuf_freecnt = -1;
21 #define THREAD_OR_PROC struct thread *p
23 #define THREAD_OR_PROC struct proc *p
26 extern int afs3_syscall();
27 extern int Afs_xsetgroups();
28 extern int afs_xioctl();
30 static sy_call_t *old_handler;
34 afs_init(struct vfsconf *vfc)
36 if (sysent[AFS_SYSCALL].sy_call != nosys
37 && sysent[AFS_SYSCALL].sy_call != lkmnosys) {
38 printf("AFS_SYSCALL in use. aborting\n");
42 afs_pbuf_freecnt = nswbuf / 2 + 1;
44 sysent[SYS_setgroups].sy_call = Afs_xsetgroups;
45 sysent[SYS_ioctl].sy_call = afs_xioctl;
47 old_handler = sysent[AFS_SYSCALL].sy_call;
48 sysent[AFS_SYSCALL].sy_call = afs3_syscall;
49 sysent[AFS_SYSCALL].sy_narg = 5;
54 afs_uninit(struct vfsconf *vfc)
59 sysent[SYS_ioctl].sy_call = ioctl;
60 sysent[SYS_setgroups].sy_call = setgroups;
62 sysent[AFS_SYSCALL].sy_narg = 0;
63 sysent[AFS_SYSCALL].sy_call = old_handler;
68 afs_start(struct mount *mp, int flags, THREAD_OR_PROC)
70 return (0); /* nothing to do. ? */
75 afs_omount(struct mount *mp, char *path, caddr_t data, struct thread *p)
77 afs_omount(struct mount *mp, char *path, caddr_t data, struct nameidata *ndp,
81 /* ndp contains the mounted-from device. Just ignore it.
82 * we also don't care about our proc struct. */
85 if (mp->mnt_flag & MNT_UPDATE)
89 AFS_STATCNT(afs_mount);
91 if (afs_globalVFS) { /* Don't allow remounts. */
99 #ifdef AFS_FBSD70_ENV /* XXX 70? */
101 mp->mnt_flag &= ~MNT_LOCAL;
102 mp->mnt_kern_flag |= MNTK_MPSAFE; /* solid steel */
104 mp->mnt_stat.f_iosize = 8192;
107 copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
109 bcopy("/afs", mp->mnt_stat.f_mntonname, size = 4);
110 memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
111 memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
112 strcpy(mp->mnt_stat.f_mntfromname, "AFS");
113 /* null terminated string "AFS" will fit, just leave it be. */
114 strcpy(mp->mnt_stat.f_fstypename, "afs");
115 #ifdef AFS_FBSD70_ENV
119 afs_statfs(mp, &mp->mnt_stat, p);
124 #ifdef AFS_FBSD53_ENV
126 afs_mount(struct mount *mp, struct thread *td)
128 return afs_omount(mp, NULL, NULL, td);
132 #ifdef AFS_FBSD60_ENV
134 afs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td)
136 return kernel_mount(ma, flags);
141 afs_unmount(struct mount *mp, int flags, THREAD_OR_PROC)
145 * Release any remaining vnodes on this mount point.
146 * The `1' means that we hold one extra reference on
147 * the root vnode (this is just a guess right now).
148 * This has to be done outside the global lock.
150 #if defined(AFS_FBSD80_ENV)
152 #elif defined(AFS_FBSD53_ENV)
153 vflush(mp, 1, (flags & MNT_FORCE) ? FORCECLOSE : 0, p);
155 vflush(mp, 1, (flags & MNT_FORCE) ? FORCECLOSE : 0);
158 AFS_STATCNT(afs_unmount);
167 #if defined(AFS_FBSD80_ENV)
168 afs_root(struct mount *mp, int flags, struct vnode **vpp)
169 #elif defined(AFS_FBSD60_ENV)
170 afs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
171 #elif defined(AFS_FBSD53_ENV)
172 afs_root(struct mount *mp, struct vnode **vpp, struct thread *td)
174 afs_root(struct mount *mp, struct vnode **vpp)
178 struct vrequest treq;
179 register struct vcache *tvp = 0;
180 #ifdef AFS_FBSD50_ENV
181 #if !defined(AFS_FBSD53_ENV) || defined(AFS_FBSD80_ENV)
182 struct thread *td = curthread;
184 struct ucred *cr = osi_curcred();
186 struct proc *p = curproc;
187 struct ucred *cr = p->p_cred->pc_ucred;
191 AFS_STATCNT(afs_root);
193 if (afs_globalVp && (afs_globalVp->f.states & CStatd)) {
198 #ifndef AFS_FBSD80_ENV
200 afs_PutVCache(afs_globalVp);
201 /* vrele() needed here or not? */
205 if (!(error = afs_InitReq(&treq, cr)) && !(error = afs_CheckInit())) {
206 tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
207 /* we really want this to stay around */
215 struct vnode *vp = AFSTOV(tvp);
217 #ifdef AFS_FBSD50_ENV
218 ASSERT_VI_UNLOCKED(vp, "afs_root");
222 * I'm uncomfortable about this. Shouldn't this happen at a
223 * higher level, and shouldn't we busy the top-level directory
224 * to prevent recycling?
226 #ifdef AFS_FBSD50_ENV
227 error = vget(vp, LK_EXCLUSIVE | LK_RETRY, td);
228 vp->v_vflag |= VV_ROOT;
230 error = vget(vp, LK_EXCLUSIVE | LK_RETRY, p);
241 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, tvp ? AFSTOV(tvp) : NULL,
242 ICL_TYPE_INT32, error);
249 afs_statfs(struct mount *mp, struct statfs *abp, THREAD_OR_PROC)
252 AFS_STATCNT(afs_statfs);
254 abp->f_bsize = mp->vfs_bsize;
255 abp->f_iosize = mp->vfs_bsize;
257 /* Fake a high number below to satisfy programs that use the statfs call
258 * to make sure that there's enough space in the device partition before
259 * storing something there.
261 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
262 abp->f_ffree = 2000000;
264 abp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0];
265 abp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1];
266 if (abp != &mp->mnt_stat) {
267 abp->f_type = mp->mnt_vfc->vfc_typenum;
268 memcpy((caddr_t) & abp->f_mntonname[0],
269 (caddr_t) mp->mnt_stat.f_mntonname, MNAMELEN);
270 memcpy((caddr_t) & abp->f_mntfromname[0],
271 (caddr_t) mp->mnt_stat.f_mntfromname, MNAMELEN);
279 #ifdef AFS_FBSD60_ENV
280 afs_sync(struct mount *mp, int waitfor, struct thread *td)
282 afs_sync(struct mount *mp, int waitfor, struct ucred *cred, THREAD_OR_PROC)
288 #ifdef AFS_FBSD60_ENV
289 struct vfsops afs_vfsops = {
290 .vfs_init = afs_init,
291 .vfs_mount = afs_mount,
292 .vfs_cmount = afs_cmount,
293 .vfs_root = afs_root,
294 .vfs_statfs = afs_statfs,
295 .vfs_sync = afs_sync,
296 .vfs_uninit = afs_uninit,
297 .vfs_unmount = afs_unmount,
298 .vfs_sysctl = vfs_stdsysctl,
301 struct vfsops afs_vfsops = {
302 #ifdef AFS_FBSD53_ENV
319 #ifdef AFS_FBSD50_ENV