freebsd-50-creds-20030701
[openafs.git] / src / afs / OBSD / osi_vfsops.c
index 6d85df2..3bfca81 100644 (file)
@@ -43,7 +43,7 @@ Reserved.
 You are hereby granted a worldwide, irrevocable, paid-up, right and
 license to use, execute, display, modify, copy and distribute MIT's
 Modifications, provided that (i) you abide by the terms and conditions
-of your Transarc AFS License Agreement, and (ii) you do not use the name
+of the OpenAFS License Agreement, and (ii) you do not use the name
 of MIT in any advertising or publicity without the prior written consent
 of MIT.  MIT disclaims all liability for your use of MIT's
 Modifications.  MIT's Modifications are provided "AS IS" WITHOUT
@@ -109,11 +109,11 @@ RCSID("$Header$");
 /* from /usr/src/sys/kern/vfs_subr.c */
 extern void insmntque(struct vnode *, struct mount *);
 
-#define NBSD_DONTFOLLOW_LINK 0
-#define NBSD_FOLLOW_LINK 1
+extern int sys_lkmnosys(), afs3_syscall(), afs_xioctl(), Afs_xsetgroups();
 
 static int lkmid = -1;
 static int afs_badcall(struct proc *p, void *xx, register_t *yy);
+static struct sysent old_sysent;
 
 char afs_NetBSD_osname[] = "OpenBSD";
 struct osi_vfs *afs_globalVFS;
@@ -166,7 +166,7 @@ afs_nbsd_lookupname(char *fnamep,
      * pathname is user or system space.
      */
     /* XXX LOCKLEAF ? */
-    niflag =  (followlink == NBSD_FOLLOW_LINK) ? FOLLOW : NOFOLLOW;
+    niflag = followlink ? FOLLOW : NOFOLLOW;
     if (dirvpp)
        niflag |= WANTPARENT;           /* XXX LOCKPARENT? */
     NDINIT(&nd, LOOKUP,
@@ -196,7 +196,7 @@ afs_sysctl()
 int
 afs_checkexp()
 {
-       return EOPNOTSUPP;
+    return EOPNOTSUPP;
 }
 
 int
@@ -247,7 +247,6 @@ struct proc *p;
        return EBUSY;
     }
 
-    AFS_GLOCK();
     AFS_STATCNT(afs_mount);
 
 #ifdef AFS_DISCON_ENV
@@ -261,8 +260,6 @@ struct proc *p;
     mp->osi_vfs_fsid.val[0] = AFS_VFSMAGIC; /* magic */
     mp->osi_vfs_fsid.val[1] = (int) AFS_VFSFSID; 
 
-    AFS_GUNLOCK();
-
     (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size);
     bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
     bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
@@ -296,15 +293,11 @@ struct proc *p;
 
     vflush(afsp, NULLVP, 0); /* don't support forced */
     afsp->mnt_data = NULL;
-#ifdef  AFS_GLOBAL_SUNLOCK
-    mutex_enter(&afs_global_lock);
-#endif
+    AFS_GLOCK();
     afs_globalVFS = 0;
     afs_cold_shutdown = 1;
     afs_shutdown();                    /* XXX */
-#ifdef  AFS_GLOBAL_SUNLOCK
-    mutex_exit(&afs_global_lock);
-#endif
+    AFS_GUNLOCK();
 
     /* give up syscall entries for ioctl & setgroups, which we've stolen */
     sysent[SYS_ioctl].sy_call = sys_ioctl;
@@ -344,9 +337,7 @@ afs_root(struct mount *mp,
 
     AFS_STATCNT(afs_root);
 
-#ifdef  AFS_GLOBAL_SUNLOCK
-    mutex_enter(&afs_global_lock);
-#endif
+    AFS_GLOCK();
     if (!(code = afs_InitReq(&treq, osi_curcred())) &&
        !(code = afs_CheckInit())) {
        tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
@@ -367,9 +358,7 @@ afs_root(struct mount *mp,
        } else
            code = ENOENT;
     }
-#ifdef  AFS_GLOBAL_SUNLOCK
-    mutex_exit(&afs_global_lock);
-#endif
+    AFS_GUNLOCK();
 
     if (!code)
        vn_lock(*vpp, LK_EXCLUSIVE | LK_RETRY, curproc); /* return it locked */
@@ -380,17 +369,17 @@ int
 afs_statfs(struct osi_vfs *afsp, struct statfs *abp)
 {
     AFS_STATCNT(afs_statfs);
-#ifdef  AFS_GLOBAL_SUNLOCK
-    mutex_enter(&afs_global_lock);
-#endif
     abp->f_bsize = afsp->osi_vfs_bsize;
-    /* Fake a high number below to satisfy programs that use the ustat (for AIX), or statfs (for the rest) call to make sure that there's enough space in the device partition before storing something there (like ed(1)) */
-    abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = abp->f_ffree  = 9000000; /* XXX */
+
+    /*
+     * Fake a high number below to satisfy programs that use the ustat (for
+     * * AIX), or statfs (for the rest) call to make sure that there's
+     * enough * space in the device partition before storing something there
+     * (like * ed(1))
+     */
+    abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files = abp->f_ffree  = 9000000;
     abp->f_fsid.val[0] = AFS_VFSMAGIC; /* magic */
     abp->f_fsid.val[1] = (int) AFS_VFSFSID;
-#ifdef  AFS_GLOBAL_SUNLOCK
-    mutex_exit(&afs_global_lock);
-#endif
     return 0;
 }
 
@@ -465,13 +454,14 @@ static char afsbfrmem[] = "afsbfrmem";
 int
 afsinit()
 {
-    extern int afs3_syscall(), afs_xioctl(), Afs_xsetgroups(), afs_xflock();
+    old_sysent = sysent[AFS_SYSCALL];
 
     sysent[AFS_SYSCALL].sy_call = afs3_syscall;
     sysent[AFS_SYSCALL].sy_narg = 6;
     sysent[AFS_SYSCALL].sy_argsize = 6 * sizeof(long);
     sysent[54].sy_call = afs_xioctl;
     sysent[80].sy_call = Afs_xsetgroups;
+    osi_Init();
 
     return 0;
 }
@@ -498,11 +488,9 @@ afs_vfs_load(struct lkm_table *lkmtp,
 }
 
 int
-afs_vfs_unload(struct lkm_table *lktmp,
-            int cmd)
+afs_vfs_unload(struct lkm_table *lktmp, int cmd)
 {
     extern char *memname[];
-    extern int sys_lkmnosys();
 
     if (afs_globalVp)
        return EBUSY;
@@ -518,30 +506,24 @@ afs_vfs_unload(struct lkm_table *lktmp,
     if (memname[M_AFSBUFFER] == afsbfrmem)
        memname[M_AFSBUFFER] = NULL;
 
-    sysent[AFS_SYSCALL].sy_call = sys_lkmnosys;
+    sysent[AFS_SYSCALL] = old_sysent;
     printf("OpenAFS unloaded\n");
     return 0;
 }
 
-
-
 int
-afsmodload(struct lkm_table *lkmtp,
-          int cmd,
-          int ver)
+libafs_lkmentry(struct lkm_table *lkmtp, int cmd, int ver)
 {
-    extern int sys_lkmnosys();
-
     if (cmd == LKM_E_LOAD) {
-       if (strcmp(ostype,afs_NetBSD_osname)) {
+       if (strcmp(ostype, afs_NetBSD_osname)) {
            printf("This is %s version %s\n", ostype, osrelease);
            printf("This version of AFS is only for %s\n",
                   afs_NetBSD_osname);
-/*         return EPROGMISMATCH;*/
+           return EPROGMISMATCH;
        }
-       if (sysent[AFS_SYSCALL].sy_call != sys_lkmnosys) {
-           printf("AFS must be loaded with syscall %d assigned to sys_lkmnosys\nIs AFS already loaded?\n",
-                  AFS_SYSCALL);
+       if (sysent[AFS_SYSCALL].sy_call == afs3_syscall
+           || sysent[AFS_SYSCALL].sy_call == afs_badcall) {
+           printf("AFS already loaded\n");
            return EINVAL;
        }
     }