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