/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* vnode ops for the devfs
*
* For leaf vnode special files (VCHR|VBLK) specfs will always see the VOP
* first because dv_find always performs leaf vnode substitution, returning
* a specfs vnode with an s_realvp pointing to the devfs leaf vnode. This
* means that the only leaf special file VOP operations that devfs will see
* after VOP_LOOKUP are the ones that specfs forwards.
*/
#include <sys/sysmacros.h>
#include <sys/vfs_opreg.h>
#include <sys/pathname.h>
/*
* Open of devices (leaf nodes) is handled by specfs.
* There is nothing to do to open a directory
*/
/*ARGSUSED*/
static int
{
return (0);
}
/*
* Close of devices (leaf nodes) is handled by specfs.
* There is nothing much to do inorder to close a directory.
*/
/*ARGSUSED1*/
static int
{
return (0);
}
/*
* Read of devices (leaf nodes) is handled by specfs.
* Read of directories is not supported.
*/
/*ARGSUSED*/
static int
struct caller_context *ct)
{
return (EISDIR);
}
/*
* Write of devices (leaf nodes) is handled by specfs.
* Write of directories is not supported.
*/
/*ARGSUSED*/
static int
struct caller_context *ct)
{
return (EISDIR);
}
/*
* Ioctls to device (leaf nodes) is handled by specfs.
* Ioctl to directories is not supported.
*/
/*ARGSUSED*/
static int
{
return (ENOTTY); /* no ioctls supported */
}
/*
* We can be asked directly about the attributes of directories, or
* (via sp->s_realvp) about the filesystem attributes of special files.
*
* For directories, we just believe the attribute store
* though we mangle the nodeid, fsid, and rdev to convince userland we
* really are a different filesystem.
*
* For special files, a little more fakery is required.
*
* If the attribute store is not there (read only root), we believe our
* memory based attributes.
*/
static int
{
int error = 0;
/*
* Message goes to console only. Otherwise, the message
* causes devfs_getattr to be invoked again... infinite loop
*/
return (ENOENT);
}
/*
* obtain from the memory version of attribute.
* preserve mask for those that optimize.
* devfs specific fields are already merged on creation.
*/
} else {
/* obtain from attribute store and merge */
}
/*
* Restrict the permissions of the node fronting the console
* to 0600 with root as the owner. This prevents a non-root
*/
}
return (error);
}
static int devfs_unlocked_access(void *, int, struct cred *);
/*ARGSUSED4*/
static int
int flags,
{
int error = 0;
return (EINVAL);
/* to ensure consistency, single thread setting of attributes */
if (error)
goto out;
/*
* Apply changes to the memory based attribute. This code
* is modeled after the tmpfs implementation of memory
* based vnodes
*/
/* Change file access modes. */
}
} else {
/* use the backing attribute store */
/*
* See if we are changing something we care about
* the persistence of - return success if we don't care.
*/
/* Set the attributes */
/*
* Some file systems may return EROFS for a setattr
* on a readonly file system. In this case we create
* our own memory based attribute.
*/
/*
* obtain attributes from existing file
* that we will modify and switch to memory
* based attribute until attribute store is
*/
goto again;
}
}
}
}
out:
return (error);
}
/*
* operation with the same details of a node's default minor
* perm information. Return 0 if identical.
*/
static int
{
return (1);
return (1);
return (1);
return (0);
}
/*ARGSUSED4*/
static int
int flags,
{
int error = 0;
int persist;
/*
* Message goes to console only. Otherwise, the message
* causes devfs_getattr to be invoked again... infinite loop
*/
return (ENOENT);
}
return (EINVAL);
/*
* If we are changing something we don't care about
* the persistence of, return success.
*/
return (0);
/*
* If driver overrides fs perm, disallow chmod
* and do not create attribute nodes.
*/
return (EPERM);
return (0);
return (0);
}
/*
* Directories are always created but device nodes are
* only used to persist non-default permissions.
*/
}
/*
* Allocate now before we take any locks
*/
/* to ensure consistency, single thread setting of attributes */
/*
* We don't need to create an attribute node
* to persist access or modification times.
*/
/*
* If persisting something, get the default permissions
* for this minor to compare against what the attributes
* are now being set to. Default ordering is:
* - minor_perm match for this minor
* - mode supplied by ddi_create_priv_minor_node
* - devfs defaults
*/
if (persist) {
dcmn_err5(("%s: setattr priv default 0%o\n",
} else {
dcmn_err5(("%s: setattr devfs default 0%o\n",
}
} else {
dcmn_err5(("%s: setattr minor perm default 0%o\n",
}
}
/*
* If we don't have a vattr for this node, construct one.
*/
free_vattr = vattrp;
} else {
*vattrp = dv_vattr_file;
if (error)
goto out;
}
if (error) {
goto out;
}
/*
* Apply changes to the memory based attribute. This code
* is modeled after the tmpfs implementation of memory
* based vnodes
*/
/* Change file access modes. */
}
}
/*
* A setattr to defaults means we no longer need the
* shadow node as a persistent store, unless there
* are ACLs. Otherwise create a shadow node if one
* doesn't exist yet.
*/
if (persist) {
("vop_remove %s %s %d\n",
error = 0;
}
} else {
dcmn_err5(("%s persisting mode 0%o\n",
dcmn_err5(("%s persisting uid %d\n",
dcmn_err5(("%s persisting gid %d\n",
}
/* If map still valid do TIME for free. */
} else {
}
}
/*
* Some file systems may return EROFS for a setattr
* on a readonly file system. In this case save
* as our own memory based attribute.
* NOTE: ufs is NOT one of these (see ufs_iupdat).
*/
error = 0;
}
}
out:
if (vattrp)
if (free_vattr)
return (error);
}
static int
{
switch (cmd) {
case _PC_ACL_ENABLED:
/*
* We rely on the underlying filesystem for ACLs,
* so direct the query for ACL support there.
* ACL support isn't relative to the file
* and we can't guarantee that the dv node
* has an attribute node, so any valid
* attribute node will suffice.
*/
/*NOTREACHED*/
}
}
/*
* Let avp handle security attributes (acl's).
*/
static int
{
int error;
/* fabricate the acl */
return (error);
}
return (error);
}
/*
* Set security attributes (acl's)
*
* Note that the dv_contents lock has already been acquired
* by the caller's VOP_RWLOCK.
*/
static int
{
int error;
/*
* Not a supported operation on drivers not providing
* file system based permissions.
*/
return (ENOTSUP);
/*
* To complete, the setsecattr requires an underlying attribute node.
*/
}
dcmn_err2(("devfs_setsecattr %s: "
return (fs_nosys());
}
/*
* The acl(2) system call issues a VOP_RWLOCK before setting an ACL.
* Since backing file systems expect the lock to be held before seeing
* a VOP_SETSECATTR ACL, we need to issue the VOP_RWLOCK to the backing
* store before forwarding the ACL.
*/
/*
* Set DV_ACL if we have a non-trivial set of ACLs. It is not
* necessary to hold VOP_RWLOCK since fs_acl_nontrivial only does
* VOP_GETSECATTR calls.
*/
return (error);
}
/*
* This function is used for secpolicy_setattr(). It must call an
* access() like function while it is already holding the
* dv_contents lock. We only care about this when dv_attr != NULL;
* so the unlocked access call only concerns itself with that
* particular branch of devfs_access().
*/
static int
{
int shift = 0;
/* Check access based on owner, group and public permissions. */
shift += 3;
shift += 3;
}
}
static int
{
int res;
/* restrict console access to privileged processes */
return (EACCES);
}
} else {
}
return (res);
}
/*
* Lookup
*
* Given the directory vnode and the name of the component, return
* the corresponding held vnode for that component.
*
* Of course in these fictional filesystems, nothing's ever quite
* -that- simple.
*
* devfs name type shadow (fs attributes) type comments
* -------------------------------------------------------------------------
* drv[@addr] VDIR drv[@addr] VDIR nexus driver
* -------------------------------------------------------------------------
*
* The following names are reserved for the attribute filesystem (which
* could easily be another layer on top of this one - we simply need to
* hold the vnode of the thing we're looking at)
*
* attr name type shadow (fs attributes) type comments
* -------------------------------------------------------------------------
* drv[@addr] VDIR - - attribute dir
* minorname VDIR - - minorname
* attribute VREG - - attribute
* -------------------------------------------------------------------------
*
* Examples:
*
* devfs:/devices/.../mm@0:zero VCHR
* shadow:/.devices/.../mm@0:zero VREG, fs attrs
*
* devfs:/devices/.../sd@0,0:a VBLK
* shadow:/.devices/.../sd@0,0:a VREG, fs attrs
* devfs:/devices/.../sd@0,0:/a/.type VREG, "ddi_block:chan"
*
* devfs:/devices/.../mm@0 VCHR
* shadow:/.devices/.../mm@0:.default VREG, fs attrs
* devfs:/devices/.../mm@0:/.default/.type VREG, "ddi_pseudo"
*
* devfs:/devices/.../obio VDIR
* shadow:/devices/.../obio VDIR, needed for fs attrs.
*
* We also need to be able deal with "old" devices that have gone away,
* though I think that provided we return them with readdir, they can
* be removed (i.e. they don't have to respond to lookup, though it might
* be weird if they didn't ;-)
*
* Lookup has side-effects.
*
* - It will create directories and fs attribute files in the shadow hierarchy.
* - It should cause non-SID devices to be probed (ask the parent nexi).
*/
/*ARGSUSED3*/
static int
{
}
/*
* devfs nodes can't really be created directly by userland - however,
* we do allow creates to find existing nodes:
*
* - any create fails if the node doesn't exist - EROFS.
* - creating an existing directory read-only succeeds, otherwise EISDIR.
* - exclusive creates fail if the node already exists - EEXIST.
* - failure to create the snode for an existing device - ENOSYS.
*/
/*ARGSUSED2*/
static int
{
int error;
if (error == 0) {
else
if (error) {
} else
return (error);
}
/*
* If DV_BUILD is set, we call into nexus driver to do a BUS_CONFIG_ALL.
* Otherwise, simply return cached dv_node's. Hotplug code always call
* devfs_clean() to invalid the dv_node cache.
*/
/*ARGSUSED5*/
static int
{
int error;
dcmn_err2(("devfs_readdir %s: offset %lld len %ld\n",
if (eofp)
*eofp = 1;
return (0);
}
return (EINVAL);
return (ENOTDIR);
/* Load the initial contents */
}
/* recheck and fill */
}
movesz = 0;
/*
* Move as many entries into the uio structure as it will take.
* Special case "." and "..".
*/
diroff = 0;
if (soff == 0) { /* . */
goto full;
/* use strncpy(9f) to zero out uninitialized bytes */
dcmn_err3(("devfs_readdir: A: diroff %lld, soff %lld: '%s' "
}
diroff++;
goto full;
/* use strncpy(9f) to zero out uninitialized bytes */
dcmn_err3(("devfs_readdir: B: diroff %lld, soff %lld: '%s' "
}
diroff++;
/* skip entries until at correct directory offset */
continue;
/*
* hidden nodes are skipped (but they still occupy a
* directory offset).
*/
continue;
/*
* DDM_INTERNAL_PATH minor nodes are skipped for readdirs
* outside the kernel (but they still occupy a directory
* offset).
*/
continue;
dcmn_err3(("devfs_readdir: C: diroff "
"%lld, soff %lld: '%s' reclen %lu\n",
goto full;
}
/* use strncpy(9f) to zero out uninitialized bytes */
dcmn_err4(("devfs_readdir: D: diroff "
}
/* the buffer is full, or we exhausted everything */
"diroff %lld, soff %lld, dv %p\n",
else {
if (error == 0) {
if (eofp)
}
}
return (error);
}
/*ARGSUSED*/
static int
{
/*
* Message goes to console only. Otherwise, the message
* causes devfs_fsync to be invoked again... infinite loop
*/
return (0);
}
/*
* Normally, we leave the dv_node here at count of 0.
* The node will be destroyed when dv_cleandir() is called.
*
* Stale dv_node's are already unlinked from the fs tree,
* so dv_cleandir() won't find them. We destroy such nodes
* immediately.
*/
/*ARGSUSED1*/
static void
{
int destroy;
/* stale nodes cannot be rediscovered, destroy it here */
if (destroy)
dv_destroy(dv, 0);
}
/*
* XXX Why do we need this? NFS mounted /dev directories?
* XXX Talk to peter staubach about this.
*/
/*ARGSUSED2*/
static int
{
return (ENOSPC);
}
/* dv_fid->dvfid_gen = dv->tn_gen; XXX ? */
return (0);
}
/*
* This pair of routines bracket all VOP_READ, VOP_WRITE
* and VOP_READDIR requests. The contents lock stops things
* moving around while we're looking at them.
*
* Also used by file and record locking.
*/
/*ARGSUSED2*/
static int
{
return (write_flag);
}
/*ARGSUSED1*/
static void
{
}
/*
* XXX Should probably do a better job of computing the maximum
* offset available in the directory.
*/
/*ARGSUSED1*/
static int
{
}
};