Loading...
--- xnu/xnu-792/bsd/miscfs/devfs/devfs_tree.c
+++ xnu/xnu-201.5/bsd/miscfs/devfs/devfs_tree.c
@@ -82,7 +82,7 @@
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/malloc.h>
-#include <sys/mount_internal.h>
+#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/vnode.h>
#include <stdarg.h>
@@ -90,24 +90,13 @@
#include "devfs.h"
#include "devfsdefs.h"
-static void devfs_release_busy(devnode_t *);
-static void dev_free_hier(devdirent_t *);
-static int devfs_propogate(devdirent_t *, devdirent_t *);
-static int dev_finddir(char *, devnode_t *, int, devnode_t **);
-static int dev_dup_entry(devnode_t *, devdirent_t *, devdirent_t **, struct devfsmount *);
-
-
-lck_grp_t * devfs_lck_grp;
-lck_grp_attr_t * devfs_lck_grp_attr;
-lck_attr_t * devfs_lck_attr;
-lck_mtx_t devfs_mutex;
-
+struct lock__bsd__ devfs_lock; /* the "big switch" */
devdirent_t * dev_root = NULL; /* root of backing tree */
struct devfs_stats devfs_stats; /* hold stats */
#ifdef HIDDEN_MOUNTPOINT
static struct mount *devfs_hidden_mount;
-#endif /* HIDDEN_MOINTPOINT */
+#endif HIDDEN_MOINTPOINT
static int devfs_ready = 0;
@@ -127,42 +116,25 @@
int
devfs_sinit(void)
{
- int error;
-
- devfs_lck_grp_attr = lck_grp_attr_alloc_init();
- lck_grp_attr_setstat(devfs_lck_grp_attr);
- devfs_lck_grp = lck_grp_alloc_init("devfs_lock", devfs_lck_grp_attr);
-
- devfs_lck_attr = lck_attr_alloc_init();
- //lck_attr_setdebug(devfs_lck_attr);
-
- lck_mtx_init(&devfs_mutex, devfs_lck_grp, devfs_lck_attr);
-
- DEVFS_LOCK();
- error = dev_add_entry("root", NULL, DEV_DIR, NULL, NULL, NULL, &dev_root);
- DEVFS_UNLOCK();
-
- if (error) {
+ lockinit(&devfs_lock, PINOD, "devfs", 0, 0);
+ if (dev_add_entry("root", NULL, DEV_DIR, NULL, NULL, NULL,
+ &dev_root)) {
printf("devfs_sinit: dev_add_entry failed ");
- return (ENOTSUP);
+ return (EOPNOTSUPP);
}
#ifdef HIDDEN_MOUNTPOINT
MALLOC(devfs_hidden_mount, struct mount *, sizeof(struct mount),
M_MOUNT, M_WAITOK);
bzero(devfs_hidden_mount,sizeof(struct mount));
- mount_lock_init(devfs_hidden_mount);
- TAILQ_INIT(&devfs_hidden_mount->mnt_vnodelist);
- TAILQ_INIT(&devfs_hidden_mount->mnt_workerqueue);
- TAILQ_INIT(&devfs_hidden_mount->mnt_newvnodes);
-
- /* Initialize the default IO constraints */
- mp->mnt_maxreadcnt = mp->mnt_maxwritecnt = MAXPHYS;
- mp->mnt_segreadcnt = mp->mnt_segwritecnt = 32;
+
+ /* Initialize the default IO constraints */
+ mp->mnt_maxreadcnt = mp->mnt_maxwritecnt = MAXPHYS;
+ mp->mnt_segreadcnt = mp->mnt_segwritecnt = 32;
devfs_mount(devfs_hidden_mount,"dummy",NULL,NULL,NULL);
dev_root->de_dnp->dn_dvm
= (struct devfsmount *)devfs_hidden_mount->mnt_data;
-#endif /* HIDDEN_MOUNTPOINT */
+#endif HIDDEN_MOUNTPOINT
devfs_ready = 1;
return (0);
}
@@ -174,15 +146,13 @@
\***********************************************************************/
-
-/***************************************************************
- * Search down the linked list off a dir to find "name"
- * return the devnode_t * for that node.
- *
- * called with DEVFS_LOCK held
- ***************************************************************/
+/***************************************************************\
+* Search down the linked list off a dir to find "name" *
+* return the devnode_t * for that node.
+\***************************************************************/
+/*proto*/
devdirent_t *
-dev_findname(devnode_t * dir, char *name)
+dev_findname(devnode_t * dir,char *name)
{
devdirent_t * newfp;
if (dir->dn_type != DEV_DIR) return 0;/*XXX*/ /* printf?*/
@@ -200,7 +170,6 @@
}
}
newfp = dir->dn_typeinfo.Dir.dirlist;
-
while(newfp)
{
if(!(strcmp(name,newfp->de_name)))
@@ -210,16 +179,121 @@
return NULL;
}
-/***********************************************************************
- * Given a starting node (0 for root) and a pathname, return the node
- * for the end item on the path. It MUST BE A DIRECTORY. If the 'CREATE'
- * option is true, then create any missing nodes in the path and create
- * and return the final node as well.
- * This is used to set up a directory, before making nodes in it..
- *
- * called with DEVFS_LOCK held
- ***********************************************************************/
-static int
+#if 0
+/***********************************************************************\
+* Given a starting node (0 for root) and a pathname, return the node *
+* for the end item on the path. It MUST BE A DIRECTORY. If the 'CREATE' *
+* option is true, then create any missing nodes in the path and create *
+* and return the final node as well. *
+* This is used to set up a directory, before making nodes in it.. *
+* *
+* Warning: This function is RECURSIVE. *
+\***********************************************************************/
+int
+dev_finddir(char * orig_path, /* find this dir (err if not dir) */
+ devnode_t * dirnode, /* starting point */
+ int create, /* create path? */
+ devnode_t * * dn_pp) /* returned */
+{
+ devdirent_t * dirent_p;
+ devnode_t * dnp = NULL;
+ char pathbuf[DEVMAXPATHSIZE];
+ char *path;
+ char *name;
+ register char *cp;
+ int retval;
+
+
+ /***************************************\
+ * If no parent directory is given *
+ * then start at the root of the tree *
+ \***************************************/
+ if(!dirnode) dirnode = dev_root->de_dnp;
+
+ /***************************************\
+ * Sanity Checks *
+ \***************************************/
+ if (dirnode->dn_type != DEV_DIR) return ENOTDIR;
+ if(strlen(orig_path) > (DEVMAXPATHSIZE - 1)) return ENAMETOOLONG;
+
+
+ path = pathbuf;
+ strcpy(path,orig_path);
+
+ /***************************************\
+ * always absolute, skip leading / *
+ * get rid of / or // or /// etc. *
+ \***************************************/
+ while(*path == '/') path++;
+
+ /***************************************\
+ * If nothing left, then parent was it.. *
+ \***************************************/
+ if ( *path == '\0' ) {
+ *dn_pp = dirnode;
+ return 0;
+ }
+
+ /***************************************\
+ * find the next segment of the name *
+ \***************************************/
+ cp = name = path;
+ while((*cp != '/') && (*cp != 0)) {
+ cp++;
+ }
+
+ /***********************************************\
+ * Check to see if it's the last component *
+ \***********************************************/
+ if(*cp) {
+ path = cp + 1; /* path refers to the rest */
+ *cp = 0; /* name is now a separate string */
+ if(!(*path)) {
+ path = (char *)0; /* was trailing slash */
+ }
+ } else {
+ path = NULL; /* no more to do */
+ }
+
+ /***************************************\
+ * Start scanning along the linked list *
+ \***************************************/
+ dirent_p = dev_findname(dirnode,name);
+ if(dirent_p) { /* check it's a directory */
+ dnp = dirent_p->de_dnp;
+ if(dnp->dn_type != DEV_DIR) return ENOTDIR;
+ } else {
+ /***************************************\
+ * The required element does not exist *
+ * So we will add it if asked to. *
+ \***************************************/
+ if(!create) return ENOENT;
+
+ if((retval = dev_add_entry(name, dirnode,
+ DEV_DIR, NULL, NULL, NULL,
+ &dirent_p)) != 0) {
+ return retval;
+ }
+ dnp = dirent_p->de_dnp;
+ devfs_propogate(dirnode->dn_typeinfo.Dir.myname,dirent_p);
+ }
+ if(path != NULL) { /* decide whether to recurse more or return */
+ return (dev_finddir(path,dnp,create,dn_pp));
+ } else {
+ *dn_pp = dnp;
+ return 0;
+ }
+}
+#endif 0
+/***********************************************************************\
+* Given a starting node (0 for root) and a pathname, return the node *
+* for the end item on the path. It MUST BE A DIRECTORY. If the 'CREATE' *
+* option is true, then create any missing nodes in the path and create *
+* and return the final node as well. *
+* This is used to set up a directory, before making nodes in it.. *
+\***********************************************************************/
+/* proto */
+int
dev_finddir(char * path,
devnode_t * dirnode,
int create,
@@ -261,7 +335,6 @@
scan++;
strncpy(component, start, scan - start);
- component[ scan - start ] = '\0';
if (*scan == '/')
scan++;
@@ -291,17 +364,16 @@
}
-/***********************************************************************
- * Add a new NAME element to the devfs
- * If we're creating a root node, then dirname is NULL
- * Basically this creates a new namespace entry for the device node
- *
- * Creates a name node, and links it to the supplied node
- *
- * called with DEVFS_LOCK held
- ***********************************************************************/
+/***********************************************************************\
+* Add a new NAME element to the devfs *
+* If we're creating a root node, then dirname is NULL *
+* Basically this creates a new namespace entry for the device node *
+* *
+* Creates a name node, and links it to the supplied node *
+\***********************************************************************/
+/*proto*/
int
-dev_add_name(char * name, devnode_t * dirnode, __unused devdirent_t * back,
+dev_add_name(char * name, devnode_t * dirnode, devdirent_t * back,
devnode_t * dnp, devdirent_t * *dirent_pp)
{
devdirent_t * dirent_p = NULL;
@@ -397,6 +469,8 @@
/*
* Put it on the END of the linked list of directory entries
*/
+ int len;
+
dirent_p->de_parent = dirnode; /* null for root */
dirent_p->de_prevp = dirnode->dn_typeinfo.Dir.dirlast;
dirent_p->de_next = *(dirent_p->de_prevp); /* should be NULL */
@@ -413,22 +487,21 @@
}
-/***********************************************************************
- * Add a new element to the devfs plane.
- *
- * Creates a new dev_node to go with it if the prototype should not be
- * reused. (Is a DIR, or we select SPLIT_DEVS at compile time)
- * typeinfo gives us info to make our node if we don't have a prototype.
- * If typeinfo is null and proto exists, then the typeinfo field of
- * the proto is used intead in the CREATE case.
- * note the 'links' count is 0 (except if a dir)
- * but it is only cleared on a transition
- * so this is ok till we link it to something
- * Even in SPLIT_DEVS mode,
- * if the node already exists on the wanted plane, just return it
- *
- * called with DEVFS_LOCK held
-***********************************************************************/
+/***********************************************************************\
+* Add a new element to the devfs plane. *
+* *
+* Creates a new dev_node to go with it if the prototype should not be *
+* reused. (Is a DIR, or we select SPLIT_DEVS at compile time) *
+* typeinfo gives us info to make our node if we don't have a prototype. *
+* If typeinfo is null and proto exists, then the typeinfo field of *
+* the proto is used intead in the CREATE case. *
+* note the 'links' count is 0 (except if a dir) *
+* but it is only cleared on a transition *
+* so this is ok till we link it to something *
+* Even in SPLIT_DEVS mode, *
+* if the node already exists on the wanted plane, just return it *
+\***********************************************************************/
+/*proto*/
int
dev_add_node(int entrytype, devnode_type_t * typeinfo, devnode_t * proto,
devnode_t * *dn_pp, struct devfsmount *dvm)
@@ -471,7 +544,7 @@
* If we have a proto, that means that we are duplicating some
* other device, which can only happen if we are not at the back plane
*/
- if (proto) {
+ if(proto) {
bcopy(proto, dnp, sizeof(devnode_t));
dnp->dn_links = 0;
dnp->dn_linklist = NULL;
@@ -488,8 +561,8 @@
/*
* We have no prototype, so start off with a clean slate
*/
- microtime(&tv);
- bzero(dnp, sizeof(devnode_t));
+ tv = time;
+ bzero(dnp,sizeof(devnode_t));
dnp->dn_type = entrytype;
dnp->dn_nextsibling = dnp;
dnp->dn_prevsiblingp = &(dnp->dn_nextsibling);
@@ -565,29 +638,21 @@
}
-/***********************************************************************
- * called with DEVFS_LOCK held
- **********************************************************************/
+/*proto*/
void
devnode_free(devnode_t * dnp)
{
- if (dnp->dn_lflags & DN_BUSY) {
- dnp->dn_lflags |= DN_DELETE;
- return;
- }
if (dnp->dn_type == DEV_SLNK) {
DEVFS_DECR_STRINGSPACE(dnp->dn_typeinfo.Slnk.namelen + 1);
- FREE(dnp->dn_typeinfo.Slnk.name, M_DEVFSNODE);
+ FREE(dnp->dn_typeinfo.Slnk.name,M_DEVFSNODE);
}
+ FREE(dnp, M_DEVFSNODE);
DEVFS_DECR_NODES();
- FREE(dnp, M_DEVFSNODE);
-}
-
-
-/***********************************************************************
- * called with DEVFS_LOCK held
- **********************************************************************/
-static void
+ return;
+}
+
+/*proto*/
+void
devfs_dn_free(devnode_t * dnp)
{
if(--dnp->dn_links <= 0 ) /* can be -1 for initial free, on error */
@@ -600,9 +665,16 @@
}
if (dnp->dn_vn == NULL) {
+#if 0
+ printf("devfs_dn_free: free'ing %x\n", (unsigned int)dnp);
+#endif 0
devnode_free(dnp); /* no accesses/references */
}
else {
+#if 0
+ printf("devfs_dn_free: marking %x for deletion\n",
+ (unsigned int)dnp);
+#endif 0
dnp->dn_delete = TRUE;
}
}
@@ -613,21 +685,20 @@
* Add or delete a chain of front nodes *
\***********************************************************************/
-
-/***********************************************************************
- * Given a directory backing node, and a child backing node, add the
- * appropriate front nodes to the front nodes of the directory to
- * represent the child node to the user
- *
- * on failure, front nodes will either be correct or not exist for each
- * front dir, however dirs completed will not be stripped of completed
- * frontnodes on failure of a later frontnode
- *
- * This allows a new node to be propogated through all mounted planes
- *
- * called with DEVFS_LOCK held
- ***********************************************************************/
-static int
+/***********************************************************************\
+* Given a directory backing node, and a child backing node, add the *
+* appropriate front nodes to the front nodes of the directory to *
+* represent the child node to the user *
+* *
+* on failure, front nodes will either be correct or not exist for each *
+* front dir, however dirs completed will not be stripped of completed *
+* frontnodes on failure of a later frontnode *
+* *
+* This allows a new node to be propogated through all mounted planes *
+* *
+\***********************************************************************/
+/*proto*/
+int
devfs_propogate(devdirent_t * parent,devdirent_t * child)
{
int error;
@@ -637,9 +708,9 @@
devnode_t * adnp = parent->de_dnp;
int type = child->de_dnp->dn_type;
- /***********************************************
- * Find the other instances of the parent node
- ***********************************************/
+ /***********************************************\
+ * Find the other instances of the parent node *
+ \***********************************************/
for (adnp = pdnp->dn_nextsibling;
adnp != pdnp;
adnp = adnp->dn_nextsibling)
@@ -658,7 +729,6 @@
return 0; /* for now always succeed */
}
-
/***********************************************************************
* remove all instances of this devicename [for backing nodes..]
* note.. if there is another link to the node (non dir nodes only)
@@ -674,17 +744,19 @@
{
devnode_t * dnp = ((devdirent_t *)dirent_p)->de_dnp;
devnode_t * dnp2;
- boolean_t lastlink;
-
- DEVFS_LOCK();
+ boolean_t funnel_state;
+
+ funnel_state = thread_funnel_set(kernel_flock, TRUE);
if (!devfs_ready) {
printf("devfs_remove: not ready for devices!\n");
goto out;
}
+ DEVFS_LOCK(0);
+
/* keep removing the next sibling till only we exist. */
- while ((dnp2 = dnp->dn_nextsibling) != dnp) {
+ while((dnp2 = dnp->dn_nextsibling) != dnp) {
/*
* Keep removing the next front node till no more exist
@@ -693,11 +765,8 @@
dnp->dn_nextsibling->dn_prevsiblingp = &(dnp->dn_nextsibling);
dnp2->dn_nextsibling = dnp2;
dnp2->dn_prevsiblingp = &(dnp2->dn_nextsibling);
- if (dnp2->dn_linklist) {
- do {
- lastlink = (1 == dnp2->dn_links);
- dev_free_name(dnp2->dn_linklist);
- } while (!lastlink);
+ while(dnp2->dn_linklist) {
+ dev_free_name(dnp2->dn_linklist);
}
}
@@ -706,18 +775,14 @@
* If we are not running in SPLIT_DEVS mode, then
* THIS is what gets rid of the propogated nodes.
*/
- if (dnp->dn_linklist) {
- do {
- lastlink = (1 == dnp->dn_links);
- dev_free_name(dnp->dn_linklist);
- } while (!lastlink);
- }
+ while(dnp->dn_linklist) {
+ dev_free_name(dnp->dn_linklist);
+ }
+ DEVFS_UNLOCK(0);
out:
- DEVFS_UNLOCK();
-
+ (void) thread_funnel_set(kernel_flock, funnel_state);
return ;
}
-
/***************************************************************
@@ -725,9 +790,8 @@
* mount point given as the argument. Do this by
* calling dev_dup_entry which recurses all the way
* up the tree..
- *
- * called with DEVFS_LOCK held
**************************************************************/
+/*proto*/
int
dev_dup_plane(struct devfsmount *devfs_mp_p)
{
@@ -735,43 +799,40 @@
int error = 0;
if ((error = dev_dup_entry(NULL, dev_root, &new, devfs_mp_p)))
- return error;
+ return error;
devfs_mp_p->plane_root = new;
return error;
}
-/***************************************************************
- * Free a whole plane
- *
- * called with DEVFS_LOCK held
- ***************************************************************/
+/***************************************************************\
+* Free a whole plane
+\***************************************************************/
+/*proto*/
void
devfs_free_plane(struct devfsmount *devfs_mp_p)
{
devdirent_t * dirent_p;
dirent_p = devfs_mp_p->plane_root;
- if (dirent_p) {
+ if(dirent_p) {
dev_free_hier(dirent_p);
dev_free_name(dirent_p);
}
devfs_mp_p->plane_root = NULL;
}
-
-/***************************************************************
- * Create and link in a new front element..
- * Parent can be 0 for a root node
- * Not presently usable to make a symlink XXX
- * (Ok, symlinks don't propogate)
- * recursively will create subnodes corresponding to equivalent
- * child nodes in the base level
- *
- * called with DEVFS_LOCK held
- ***************************************************************/
-static int
+/***************************************************************\
+* Create and link in a new front element.. *
+* Parent can be 0 for a root node *
+* Not presently usable to make a symlink XXX *
+* (Ok, symlinks don't propogate)
+* recursively will create subnodes corresponding to equivalent *
+* child nodes in the base level *
+\***************************************************************/
+/*proto*/
+int
dev_dup_entry(devnode_t * parent, devdirent_t * back, devdirent_t * *dnm_pp,
struct devfsmount *dvm)
{
@@ -821,16 +882,13 @@
return error;
}
-
-/***************************************************************
- * Free a name node
- * remember that if there are other names pointing to the
- * dev_node then it may not get freed yet
- * can handle if there is no dnp
- *
- * called with DEVFS_LOCK held
- ***************************************************************/
-
+/***************************************************************\
+* Free a name node *
+* remember that if there are other names pointing to the *
+* dev_node then it may not get freed yet *
+* can handle if there is no dnp *
+\***************************************************************/
+/*proto*/
int
dev_free_name(devdirent_t * dirent_p)
{
@@ -886,22 +944,19 @@
}
DEVFS_DECR_ENTRIES();
- FREE(dirent_p, M_DEVFSNAME);
+ FREE(dirent_p,M_DEVFSNAME);
return 0;
}
-
-/***************************************************************
- * Free a hierarchy starting at a directory node name
- * remember that if there are other names pointing to the
- * dev_node then it may not get freed yet
- * can handle if there is no dnp
- * leave the node itself allocated.
- *
- * called with DEVFS_LOCK held
- ***************************************************************/
-
-static void
+/***************************************************************\
+* Free a hierarchy starting at a directory node name *
+* remember that if there are other names pointing to the *
+* dev_node then it may not get freed yet *
+* can handle if there is no dnp *
+* leave the node itself allocated. *
+\***************************************************************/
+/*proto*/
+void
dev_free_hier(devdirent_t * dirent_p)
{
devnode_t * dnp = dirent_p->de_dnp;
@@ -918,155 +973,60 @@
}
}
-
-/***************************************************************
- * given a dev_node, find the appropriate vnode if one is already
- * associated, or get a new one and associate it with the dev_node
- *
- * called with DEVFS_LOCK held
- ***************************************************************/
+/***************************************************************\
+* given a dev_node, find the appropriate vnode if one is already
+* associated, or get a new one and associate it with the dev_node
+\***************************************************************/
+/*proto*/
int
-devfs_dntovn(devnode_t * dnp, struct vnode **vn_pp, __unused struct proc * p)
-{
- struct vnode *vn_p;
+devfs_dntovn(devnode_t * dnp, struct vnode **vn_pp, struct proc * p)
+{
+ struct vnode *vn_p, *nvp;
int error = 0;
- struct vnode_fsparam vfsp;
- enum vtype vtype = 0;
- int markroot = 0;
-
-retry:
+
*vn_pp = NULL;
vn_p = dnp->dn_vn;
-
- dnp->dn_lflags |= DN_BUSY;
-
if (vn_p) { /* already has a vnode */
- uint32_t vid;
-
- vid = vnode_vid(vn_p);
-
- DEVFS_UNLOCK();
-
- error = vnode_getwithvid(vn_p, vid);
-
- DEVFS_LOCK();
-
- if (dnp->dn_lflags & DN_DELETE) {
- /*
- * our BUSY node got marked for
- * deletion while the DEVFS lock
- * was dropped...
- */
- if (error == 0) {
- /*
- * vnode_getwithvid returned a valid ref
- * which we need to drop
- */
- vnode_put(vn_p);
- }
- /*
- * set the error to EAGAIN
- * which will cause devfs_lookup
- * to retry this node
- */
- error = EAGAIN;
- }
- if ( !error)
- *vn_pp = vn_p;
-
- devfs_release_busy(dnp);
-
- return error;
- }
-
- if (dnp->dn_lflags & DN_CREATE) {
- dnp->dn_lflags |= DN_CREATEWAIT;
- msleep(&dnp->dn_lflags, &devfs_mutex, PRIBIO, 0 , 0);
- goto retry;
- }
-
- dnp->dn_lflags |= DN_CREATE;
-
- switch (dnp->dn_type) {
+ *vn_pp = vn_p;
+ return(vget(vn_p, LK_EXCLUSIVE, p));
+ }
+ if (!(error = getnewvnode(VT_DEVFS, dnp->dn_dvm->mount,
+ *(dnp->dn_ops), &vn_p))) {
+ switch(dnp->dn_type) {
case DEV_SLNK:
- vtype = VLNK;
+ vn_p->v_type = VLNK;
break;
case DEV_DIR:
if (dnp->dn_typeinfo.Dir.parent == dnp) {
- markroot = 1;
+ vn_p->v_flag |= VROOT;
}
- vtype = VDIR;
+ vn_p->v_type = VDIR;
break;
case DEV_BDEV:
case DEV_CDEV:
- vtype = (dnp->dn_type == DEV_BDEV) ? VBLK : VCHR;
+ vn_p->v_type
+ = (dnp->dn_type == DEV_BDEV) ? VBLK : VCHR;
+ if ((nvp = checkalias(vn_p, dnp->dn_typeinfo.dev,
+ dnp->dn_dvm->mount)) != NULL) {
+ vput(vn_p);
+ vn_p = nvp;
+ }
break;
- }
- vfsp.vnfs_mp = dnp->dn_dvm->mount;
- vfsp.vnfs_vtype = vtype;
- vfsp.vnfs_str = "devfs";
- vfsp.vnfs_dvp = 0;
- vfsp.vnfs_fsnode = dnp;
- vfsp.vnfs_cnp = 0;
- vfsp.vnfs_vops = *(dnp->dn_ops);
-
- if (vtype == VBLK || vtype == VCHR)
- vfsp.vnfs_rdev = dnp->dn_typeinfo.dev;
- else
- vfsp.vnfs_rdev = 0;
- vfsp.vnfs_filesize = 0;
- vfsp.vnfs_flags = VNFS_NOCACHE | VNFS_CANTCACHE;
- /* Tag system files */
- vfsp.vnfs_marksystem = 0;
- vfsp.vnfs_markroot = markroot;
-
- DEVFS_UNLOCK();
-
- error = vnode_create(VNCREATE_FLAVOR, VCREATESIZE, &vfsp, &vn_p);
-
- DEVFS_LOCK();
-
- if (error == 0) {
- if ((dnp->dn_vn)) {
- panic("devnode already has a vnode?");
- } else {
- dnp->dn_vn = vn_p;
- *vn_pp = vn_p;
- vnode_settag(vn_p, VT_DEVFS);
- }
- }
-
- dnp->dn_lflags &= ~DN_CREATE;
-
- if (dnp->dn_lflags & DN_CREATEWAIT) {
- dnp->dn_lflags &= ~DN_CREATEWAIT;
- wakeup(&dnp->dn_lflags);
- }
-
- devfs_release_busy(dnp);
-
+ }
+ vn_p->v_mount = dnp->dn_dvm->mount;/* XXX Duplicated */
+ *vn_pp = vn_p;
+ vn_p->v_data = (void *)dnp;
+ dnp->dn_vn = vn_p;
+ error = vn_lock(vn_p, LK_EXCLUSIVE | LK_RETRY, p);
+ }
return error;
}
-
-/***********************************************************************
- * called with DEVFS_LOCK held
- ***********************************************************************/
-static void
-devfs_release_busy(devnode_t *dnp) {
-
- dnp->dn_lflags &= ~DN_BUSY;
-
- if (dnp->dn_lflags & DN_DELETE)
- devnode_free(dnp);
-}
-
-/***********************************************************************
- * add a whole device, with no prototype.. make name element and node
- * Used for adding the original device entries
- *
- * called with DEVFS_LOCK held
- ***********************************************************************/
+/***********************************************************************\
+* add a whole device, with no prototype.. make name element and node *
+* Used for adding the original device entries *
+\***********************************************************************/
+/*proto*/
int
dev_add_entry(char *name, devnode_t * parent, int type, devnode_type_t * typeinfo,
devnode_t * proto, struct devfsmount *dvm, devdirent_t * *nm_pp)
@@ -1091,6 +1051,7 @@
return error;
}
+#include <sys/subr_prf.h>
/*
* Function: devfs_make_node
@@ -1109,31 +1070,32 @@
*/
void *
devfs_make_node(dev_t dev, int chrblk, uid_t uid,
- gid_t gid, int perms, const char *fmt, ...)
+ gid_t gid, int perms, char *fmt, ...)
{
devdirent_t * new_dev = NULL;
devnode_t * dnp; /* devnode for parent directory */
devnode_type_t typeinfo;
char *name, *path, buf[256]; /* XXX */
+ char * b_ptr = buf;
+ boolean_t funnel_state;
int i;
va_list ap;
-
- DEVFS_LOCK();
+ funnel_state = thread_funnel_set(kernel_flock, TRUE);
if (!devfs_ready) {
printf("devfs_make_node: not ready for devices!\n");
goto out;
}
+
if (chrblk != DEVFS_CHAR && chrblk != DEVFS_BLOCK)
goto out;
- DEVFS_UNLOCK();
-
va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ prf(fmt, ap, TOSTR, (struct tty *)&b_ptr);
va_end(ap);
+ *b_ptr = 0;
name = NULL;
@@ -1151,8 +1113,8 @@
name = buf;
path = "/";
}
- DEVFS_LOCK();
-
+
+ DEVFS_LOCK(0);
/* find/create directory path ie. mkdir -p */
if (dev_finddir(path, NULL, CREATE, &dnp) == 0) {
typeinfo.dev = dev;
@@ -1165,9 +1127,10 @@
devfs_propogate(dnp->dn_typeinfo.Dir.myname, new_dev);
}
}
+ DEVFS_UNLOCK(0);
+
out:
- DEVFS_UNLOCK();
-
+ (void) thread_funnel_set(kernel_flock, funnel_state);
return new_dev;
}
@@ -1189,47 +1152,46 @@
va_list ap;
char *p, buf[256]; /* XXX */
+ char * b_ptr = buf;
int i;
-
- DEVFS_LOCK();
+ boolean_t funnel_state;
+
+ funnel_state = thread_funnel_set(kernel_flock, TRUE);
if (!devfs_ready) {
printf("devfs_make_link: not ready for devices!\n");
goto out;
}
- DEVFS_UNLOCK();
va_start(ap, fmt);
- vsnprintf(buf, sizeof(buf), fmt, ap);
+ prf(fmt, ap, TOSTR, (struct tty *)&b_ptr);
va_end(ap);
+ *b_ptr = 0;
p = NULL;
- for(i=strlen(buf); i>0; i--) {
+ for(i=strlen(buf); i>0; i--)
if(buf[i] == '/') {
p=&buf[i];
buf[i]=0;
break;
}
- }
- DEVFS_LOCK();
-
+ DEVFS_LOCK(0);
if (p) {
- *p++ = '\0';
-
- if (dev_finddir(buf, NULL, CREATE, &dirnode)
- || dev_add_name(p, dirnode, NULL, orig->de_dnp, &new_dev))
- goto fail;
+ *p++ = '\0';
+ if (dev_finddir(buf, NULL, CREATE, &dirnode)
+ || dev_add_name(p, dirnode, NULL, orig->de_dnp, &new_dev))
+ goto fail;
} else {
- if (dev_finddir("", NULL, CREATE, &dirnode)
- || dev_add_name(buf, dirnode, NULL, orig->de_dnp, &new_dev))
- goto fail;
+ if (dev_finddir("", NULL, CREATE, &dirnode)
+ || dev_add_name(buf, dirnode, NULL, orig->de_dnp, &new_dev))
+ goto fail;
}
devfs_propogate(dirnode->dn_typeinfo.Dir.myname, new_dev);
fail:
+ DEVFS_UNLOCK(0);
out:
- DEVFS_UNLOCK();
-
+ (void) thread_funnel_set(kernel_flock, funnel_state);
return ((new_dev != NULL) ? 0 : -1);
}