4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/atomic.h>
26 #include <sys/cmn_err.h>
27 #include <sys/errno.h>
28 #include <sys/mount.h>
29 #include <sys/objfs.h>
30 #include <sys/objfs_impl.h>
32 #include <sys/policy.h>
33 #include <sys/sunddi.h>
34 #include <sys/sysmacros.h>
35 #include <sys/systm.h>
38 * Kernel object filesystem.
40 * This is a pseudo filesystem which exports information about currently loaded
41 * kernel objects. The root directory contains one directory for each loaded
42 * object, indexed by module name. Within each object directory is an ELF file,
43 * 'object', that contains information about the currently loaded module.
45 * This file contains functions that interact with the VFS layer. Each
46 * filesystem element is represented by a a different node.
48 * / objfs_rootnode_t objfs_root.c
49 * /<obj> objfs_odirnode_t objfs_odir.c
50 * /<obj>/object objfs_datanode_t objfs_data.c
52 * In addition, some common routines are found in the 'objfs_common.c' file.
55 static const struct vfsops objfs_vfsops
;
57 static int objfs_init(int, char *);
62 static mntopts_t objfs_mntopts
= {
67 static vfsdef_t vfw
= {
71 VSW_HASPROTO
| VSW_ZMOUNT
,
75 extern struct mod_ops mod_fsops
;
77 static struct modlfs modlfs
= {
78 &mod_fsops
, "kernel object filesystem", &vfw
81 static struct modlinkage modlinkage
= {
82 MODREV_1
, (void *)&modlfs
, NULL
88 return (mod_install(&modlinkage
));
92 _info(struct modinfo
*modinfop
)
94 return (mod_info(&modlinkage
, modinfop
));
101 * The object filesystem cannot be unloaded.
107 * Filesystem initialization.
110 static int objfs_fstype
;
111 static major_t objfs_major
;
112 static minor_t objfs_minor
;
116 objfs_init(int fstype
, char *name
)
120 objfs_fstype
= fstype
;
121 if (error
= vfs_setfsops(fstype
, &objfs_vfsops
)) {
122 cmn_err(CE_WARN
, "objfs_init: bad fstype");
126 if ((objfs_major
= getudev()) == (major_t
)-1) {
127 cmn_err(CE_WARN
, "objfs_init: can't get unique device number");
140 objfs_mount(vfs_t
*vfsp
, vnode_t
*mvp
, struct mounta
*uap
, cred_t
*cr
)
145 if (secpolicy_fs_mount(cr
, mvp
, vfsp
) != 0)
148 if (mvp
->v_type
!= VDIR
)
151 if ((uap
->flags
& MS_OVERLAY
) == 0 &&
152 (mvp
->v_count
> 1 || (mvp
->v_flag
& VROOT
)))
155 data
= kmem_alloc(sizeof (objfs_vfs_t
), KM_SLEEP
);
158 * Initialize vfs fields
160 vfsp
->vfs_bsize
= DEV_BSIZE
;
161 vfsp
->vfs_fstype
= objfs_fstype
;
163 dev
= makedevice(objfs_major
,
164 atomic_inc_32_nv(&objfs_minor
) & L_MAXMIN32
);
165 } while (vfs_devismounted(dev
));
166 vfs_make_fsid(&vfsp
->vfs_fsid
, dev
, objfs_fstype
);
167 vfsp
->vfs_data
= data
;
173 data
->objfs_vfs_root
= objfs_create_root(vfsp
);
179 objfs_unmount(vfs_t
*vfsp
, int flag
, struct cred
*cr
)
183 if (secpolicy_fs_unmount(cr
, vfsp
) != 0)
187 * We do not currently support forced unmounts
193 * We should never have a reference count of less than 2: one for the
194 * caller, one for the root vnode.
196 ASSERT(vfsp
->vfs_count
>= 2);
199 * Any active vnodes will result in a hold on the root vnode
201 data
= vfsp
->vfs_data
;
202 if (data
->objfs_vfs_root
->v_count
> 1)
206 * Release the last hold on the root vnode
208 VN_RELE(data
->objfs_vfs_root
);
210 kmem_free(data
, sizeof (objfs_vfs_t
));
216 objfs_root(vfs_t
*vfsp
, vnode_t
**vpp
)
218 objfs_vfs_t
*data
= vfsp
->vfs_data
;
220 *vpp
= data
->objfs_vfs_root
;
227 objfs_statvfs(vfs_t
*vfsp
, statvfs64_t
*sp
)
230 int total
= objfs_nobjs();
232 bzero(sp
, sizeof (*sp
));
233 sp
->f_bsize
= DEV_BSIZE
;
234 sp
->f_frsize
= DEV_BSIZE
;
236 sp
->f_ffree
= sp
->f_favail
= INT_MAX
- total
;
237 (void) cmpldev(&d32
, vfsp
->vfs_dev
);
239 (void) strlcpy(sp
->f_basetype
, vfssw
[vfsp
->vfs_fstype
].vsw_name
,
240 sizeof (sp
->f_basetype
));
241 sp
->f_flag
= vf_to_stf(vfsp
->vfs_flag
);
242 sp
->f_namemax
= OBJFS_NAME_MAX
;
243 (void) strlcpy(sp
->f_fstr
, "object", sizeof (sp
->f_fstr
));
248 static const struct vfsops objfs_vfsops
= {
249 .vfs_mount
= objfs_mount
,
250 .vfs_unmount
= objfs_unmount
,
251 .vfs_root
= objfs_root
,
252 .vfs_statvfs
= objfs_statvfs
,