10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
53898Srsb * Common Development and Distribution License (the "License").
63898Srsb * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*6492Stimh * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <fs/fs_subr.h>
300Sstevel@tonic-gate
310Sstevel@tonic-gate #include <sys/errno.h>
320Sstevel@tonic-gate #include <sys/kmem.h>
330Sstevel@tonic-gate #include <sys/modctl.h>
340Sstevel@tonic-gate #include <sys/objfs.h>
350Sstevel@tonic-gate #include <sys/objfs_impl.h>
363898Srsb #include <sys/vfs_opreg.h>
370Sstevel@tonic-gate #include <sys/systm.h>
380Sstevel@tonic-gate
390Sstevel@tonic-gate extern int last_module_id;
400Sstevel@tonic-gate
415331Samw static int objfs_root_do_lookup(vnode_t *, const char *, vnode_t **, ino64_t *,
42*6492Stimh cred_t *, int, int *, pathname_t *);
435663Sck153898 static int objfs_root_do_readdir(vnode_t *, void *, int *,
445663Sck153898 offset_t *, offset_t *, void *, int);
450Sstevel@tonic-gate
460Sstevel@tonic-gate vnode_t *
objfs_create_root(vfs_t * vfsp)470Sstevel@tonic-gate objfs_create_root(vfs_t *vfsp)
480Sstevel@tonic-gate {
490Sstevel@tonic-gate vnode_t *vp = gfs_root_create(sizeof (objfs_rootnode_t), vfsp,
500Sstevel@tonic-gate objfs_ops_root, OBJFS_INO_ROOT, NULL, NULL, OBJFS_NAME_MAX,
510Sstevel@tonic-gate objfs_root_do_readdir, objfs_root_do_lookup);
520Sstevel@tonic-gate
530Sstevel@tonic-gate return (vp);
540Sstevel@tonic-gate }
550Sstevel@tonic-gate
560Sstevel@tonic-gate /* ARGSUSED */
570Sstevel@tonic-gate static int
objfs_root_getattr(vnode_t * vp,vattr_t * vap,int flags,cred_t * cr,caller_context_t * ct)585331Samw objfs_root_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
595331Samw caller_context_t *ct)
600Sstevel@tonic-gate {
610Sstevel@tonic-gate vap->va_type = VDIR;
620Sstevel@tonic-gate vap->va_mode = 0555;
630Sstevel@tonic-gate vap->va_nodeid = gfs_file_inode(vp);
640Sstevel@tonic-gate vap->va_nlink = objfs_nobjs() + 2;
650Sstevel@tonic-gate vap->va_size = vap->va_nlink;
660Sstevel@tonic-gate vap->va_atime.tv_sec = vp->v_vfsp->vfs_mtime;
670Sstevel@tonic-gate vap->va_atime.tv_nsec = 0;
680Sstevel@tonic-gate vap->va_mtime = vap->va_ctime = vap->va_atime;
690Sstevel@tonic-gate return (objfs_common_getattr(vp, vap));
700Sstevel@tonic-gate }
710Sstevel@tonic-gate
725331Samw /* ARGSUSED */
730Sstevel@tonic-gate static int
objfs_root_do_lookup(vnode_t * vp,const char * nm,vnode_t ** vpp,ino64_t * inop,cred_t * cr,int flags,int * deflags,pathname_t * rpnp)745331Samw objfs_root_do_lookup(vnode_t *vp, const char *nm, vnode_t **vpp, ino64_t *inop,
75*6492Stimh cred_t *cr, int flags, int *deflags, pathname_t *rpnp)
760Sstevel@tonic-gate {
770Sstevel@tonic-gate int result = ENOENT;
780Sstevel@tonic-gate struct modctl *mp;
790Sstevel@tonic-gate
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate * Run through all the loaded modules on the system looking for
820Sstevel@tonic-gate * a matching module name.
830Sstevel@tonic-gate */
840Sstevel@tonic-gate mutex_enter(&mod_lock);
850Sstevel@tonic-gate mp = &modules;
860Sstevel@tonic-gate do {
870Sstevel@tonic-gate if (mp->mod_loaded &&
880Sstevel@tonic-gate strcmp(nm, mp->mod_modname) == 0) {
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate * We drop mod_lock in order to do allocations,
910Sstevel@tonic-gate * as modctls are persistent.
920Sstevel@tonic-gate */
930Sstevel@tonic-gate mutex_exit(&mod_lock);
940Sstevel@tonic-gate *vpp = objfs_create_odirnode(vp, mp);
950Sstevel@tonic-gate *inop = OBJFS_INO_ODIR(mp->mod_id);
960Sstevel@tonic-gate mutex_enter(&mod_lock);
970Sstevel@tonic-gate result = 0;
980Sstevel@tonic-gate break;
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate } while ((mp = mp->mod_next) != &modules);
1010Sstevel@tonic-gate mutex_exit(&mod_lock);
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate return (result);
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate /* ARGSUSED */
1070Sstevel@tonic-gate int
objfs_root_do_readdir(vnode_t * vp,void * dp,int * eofp,offset_t * offp,offset_t * nextp,void * data,int flags)1085663Sck153898 objfs_root_do_readdir(vnode_t *vp, void *dp, int *eofp,
1095663Sck153898 offset_t *offp, offset_t *nextp, void *data, int flags)
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate struct modctl **mpp = data;
1120Sstevel@tonic-gate struct modctl *mp = *mpp;
1135663Sck153898 struct dirent64 *odp = dp;
1145663Sck153898
115*6492Stimh ASSERT(!(flags & V_RDDIR_ENTFLAGS));
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate mutex_enter(&mod_lock);
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate /* Check for EOF */
1200Sstevel@tonic-gate if (*offp >= last_module_id) {
1210Sstevel@tonic-gate *eofp = 1;
1220Sstevel@tonic-gate mutex_exit(&mod_lock);
1230Sstevel@tonic-gate return (0);
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate * Find the appropriate modctl
1280Sstevel@tonic-gate */
1290Sstevel@tonic-gate while (mp->mod_id < *offp) {
1300Sstevel@tonic-gate mp = mp->mod_next;
1310Sstevel@tonic-gate ASSERT(mp != &modules);
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate while (!mp->mod_loaded && mp != &modules)
1350Sstevel@tonic-gate mp = mp->mod_next;
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate if (mp == &modules && *offp != 0) {
1380Sstevel@tonic-gate *eofp = 1;
1390Sstevel@tonic-gate mutex_exit(&mod_lock);
1400Sstevel@tonic-gate return (0);
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate /*
1440Sstevel@tonic-gate * The modctl will not change, as they are persistent.
1450Sstevel@tonic-gate */
1460Sstevel@tonic-gate mutex_exit(&mod_lock);
1470Sstevel@tonic-gate
1485663Sck153898 (void) strncpy(odp->d_name, mp->mod_modname, OBJFS_NAME_MAX);
1495663Sck153898 odp->d_ino = OBJFS_INO_ODIR(mp->mod_id);
1500Sstevel@tonic-gate *offp = mp->mod_id;
1510Sstevel@tonic-gate *nextp = mp->mod_id + 1;
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate return (0);
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate /* ARGSUSED */
1570Sstevel@tonic-gate static int
objfs_root_readdir(vnode_t * vp,uio_t * uiop,cred_t * cr,int * eofp,caller_context_t * ct,int flags)1585331Samw objfs_root_readdir(vnode_t *vp, uio_t *uiop, cred_t *cr, int *eofp,
1595331Samw caller_context_t *ct, int flags)
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate struct modctl *mp = &modules;
1620Sstevel@tonic-gate
1635663Sck153898 return (gfs_dir_readdir(vp, uiop, eofp, &mp, cr, ct, flags));
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate const fs_operation_def_t objfs_tops_root[] = {
1673898Srsb { VOPNAME_OPEN, { .vop_open = objfs_dir_open } },
1683898Srsb { VOPNAME_CLOSE, { .vop_close = objfs_common_close } },
1693898Srsb { VOPNAME_IOCTL, { .error = fs_inval } },
1703898Srsb { VOPNAME_GETATTR, { .vop_getattr = objfs_root_getattr } },
1713898Srsb { VOPNAME_ACCESS, { .vop_access = objfs_dir_access } },
1723898Srsb { VOPNAME_READDIR, { .vop_readdir = objfs_root_readdir } },
1733898Srsb { VOPNAME_LOOKUP, { .vop_lookup = gfs_vop_lookup } },
1743898Srsb { VOPNAME_SEEK, { .vop_seek = fs_seek } },
1753898Srsb { VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } },
1760Sstevel@tonic-gate { NULL }
1770Sstevel@tonic-gate };
178