freebsd-20050429
[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
23 extern struct vfsops afs_vfsops;
24 extern struct vnodeopv_desc afs_vnodeop_opv_desc;
25 extern struct mount *afs_globalVFS;
26
27 MALLOC_DEFINE(M_AFS, "afsmisc", "memory used by the AFS filesystem");
28
29 #ifdef AFS_FBSD60_ENV
30 VFS_SET(afs_vfsops, afs, VFCF_NETWORK);
31 #else
32 int afs_module_handler(module_t mod, int what, void *arg);
33
34 static struct vfsconf afs_vfsconf;
35 static moduledata_t afs_mod = {
36     "afs",
37     afs_module_handler,
38     &afs_mod
39 };
40
41 DECLARE_MODULE(afs, afs_mod, SI_SUB_VFS, SI_ORDER_MIDDLE);
42 #endif
43
44 #ifndef AFS_FBSD60_ENV
45 int
46 afs_module_handler(module_t mod, int what, void *arg)
47 {
48     static int inited = 0;
49     int error = 0;
50
51     switch (what) {
52     case MOD_LOAD:
53         if (inited) {
54             printf("afs cannot be MOD_LOAD'd more than once\n");
55             error = EBUSY;
56             break;
57         }
58         memset(&afs_vfsconf, 0, sizeof(struct vfsconf));
59 #ifdef AFS_FBSD53_ENV
60         afs_vfsconf.vfc_version = VFS_VERSION;
61 #endif
62         strcpy(afs_vfsconf.vfc_name, "AFS");
63         afs_vfsconf.vfc_vfsops = &afs_vfsops;
64         afs_vfsconf.vfc_typenum = -1;   /* set by vfs_register */
65         afs_vfsconf.vfc_flags = VFCF_NETWORK;
66         if ((error = vfs_register(&afs_vfsconf)) != 0)
67             break;
68         vfs_add_vnodeops(&afs_vnodeop_opv_desc);
69         inited = 1;
70         break;
71     case MOD_UNLOAD:
72 #ifndef RXK_LISTENER_ENV
73         /* shutdown is incomplete unless RXK_LISTENER_ENV */
74         printf("afs: I can't be unloaded yet\n");
75         return -1;
76 #endif
77         if (!inited) {
78             error = 0;
79             break;
80         }
81         if ((error = vfs_unregister(&afs_vfsconf)) != 0) {
82             break;
83         }
84         vfs_rm_vnodeops(&afs_vnodeop_opv_desc);
85         break;
86     }
87
88     return (error);
89 }
90 #endif