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