freebsd-50-creds-20030701
[openafs.git] / src / afs / FBSD / osi_module.c
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 #include <afsconfig.h>
12 #include <afs/param.h>
13
14 RCSID("$Header$");
15
16 #include <afs/sysincludes.h>
17 #include <afsincludes.h>
18 #include <sys/module.h>
19 #include <sys/sysproto.h>
20 #include <sys/syscall.h>
21 #include <sys/sysent.h>
22
23 extern struct vfsops afs_vfsops;
24 extern struct vnodeopv_desc afs_vnodeop_opv_desc;
25 extern struct mount *afs_globalVFS;
26 static struct vfsconf afs_vfsconf;
27
28 MALLOC_DEFINE(M_AFS, "afsmisc", "memory used by the AFS filesystem");
29
30 extern int afs3_syscall();
31 extern int Afs_xsetgroups();
32 extern int afs_xioctl();
33
34 int
35 afs_module_handler(module_t mod, int what, void *arg)
36 {
37     static sy_call_t *old_handler;
38     static int inited = 0;
39     int error;
40     error = 0;
41     switch (what) {
42     case MOD_LOAD:
43         if (inited) {
44             printf("afs cannot be MOD_LOAD'd more than once\n");
45             error = -1;
46             break;
47         }
48         if (sysent[AFS_SYSCALL].sy_call != nosys &&
49             sysent[AFS_SYSCALL].sy_call != lkmnosys) {
50             printf("AFS_SYSCALL in use. aborting\n");
51             error = -1;
52             break;
53         }
54         memset(&afs_vfsconf, 0, sizeof(struct vfsconf));
55         strcpy(afs_vfsconf.vfc_name, "AFS");
56         afs_vfsconf.vfc_vfsops = &afs_vfsops;
57         afs_vfsconf.vfc_typenum = -1;   /* set by vfs_register */
58         afs_vfsconf.vfc_flags = VFCF_NETWORK;
59         vfs_register(&afs_vfsconf);     /* doesn't fail */
60         vfs_add_vnodeops(&afs_vnodeop_opv_desc);
61         osi_Init();
62         sysent[SYS_setgroups].sy_call = Afs_xsetgroups;
63         sysent[SYS_ioctl].sy_call = afs_xioctl;
64         old_handler = sysent[AFS_SYSCALL].sy_call;
65         sysent[AFS_SYSCALL].sy_call = afs3_syscall;
66         sysent[AFS_SYSCALL].sy_narg = 5;
67         inited = 1;
68         break;
69     case MOD_UNLOAD:
70 #ifndef RXK_LISTENER_ENV
71         /* shutdown is incomplete unless RXK_LISTENER_ENV */
72         printf("afs: I can't be unloaded yet\n");
73         return -1;
74 #endif
75         if (!inited) {
76             error = 0;
77             break;
78         }
79         if (afs_globalVFS) {
80             error = -1;
81             break;
82         }
83         if (vfs_unregister(&afs_vfsconf)) {
84             error = -1;
85             break;
86         }
87         vfs_rm_vnodeops(&afs_vnodeop_opv_desc);
88         sysent[SYS_ioctl].sy_call = ioctl;
89         sysent[SYS_setgroups].sy_call = setgroups;
90         sysent[AFS_SYSCALL].sy_narg = 0;
91         sysent[AFS_SYSCALL].sy_call = old_handler;
92         break;
93     }
94
95     return (error);
96 }
97
98
99 static moduledata_t afs_mod = {
100     "afs",
101     afs_module_handler,
102     &afs_mod
103 };
104 DECLARE_MODULE(afs, afs_mod, SI_SUB_VFS, SI_ORDER_MIDDLE);