diff options
author | Julian Elischer <julian@FreeBSD.org> | 1998-04-19 23:32:49 +0000 |
---|---|---|
committer | Julian Elischer <julian@FreeBSD.org> | 1998-04-19 23:32:49 +0000 |
commit | 3e425b968d4b5478e0e1edda78ca13e0e91fa7fe (patch) | |
tree | c74ebd0773f9113f68301b0820a6cf92e299233c /sys/miscfs | |
parent | 9d66d1d696cc0606cb896c261846c9fddc0b867d (diff) | |
download | src-3e425b968d4b5478e0e1edda78ca13e0e91fa7fe.tar.gz src-3e425b968d4b5478e0e1edda78ca13e0e91fa7fe.zip |
Add changes and code to implement a functional DEVFS.
This code will be turned on with the TWO options
DEVFS and SLICE. (see LINT)
Two labels PRE_DEVFS_SLICE and POST_DEVFS_SLICE will deliniate these changes.
/dev will be automatically mounted by init (thanks phk)
on bootup. See /sys/dev/slice/slice.4 for more info.
All code should act the same without these options enabled.
Mike Smith, Poul Henning Kamp, Soeren, and a few dozen others
This code does not support the following:
bad144 handling.
Persistance. (My head is still hurting from the last time we discussed this)
ATAPI flopies are not handled by the SLICE code yet.
When this code is running, all major numbers are arbitrary and COULD
be dynamically assigned. (this is not done, for POLA only)
Minor numbers for disk slices ARE arbitray and dynamically assigned.
Notes
Notes:
svn path=/head/; revision=35319
Diffstat (limited to 'sys/miscfs')
-rw-r--r-- | sys/miscfs/devfs/devfs_tree.c | 160 | ||||
-rw-r--r-- | sys/miscfs/devfs/devfs_vfsops.c | 3 | ||||
-rw-r--r-- | sys/miscfs/devfs/devfs_vnops.c | 40 | ||||
-rw-r--r-- | sys/miscfs/devfs/devfsdefs.h | 3 | ||||
-rw-r--r-- | sys/miscfs/specfs/spec_vnops.c | 11 | ||||
-rw-r--r-- | sys/miscfs/specfs/specdev.h | 6 |
6 files changed, 152 insertions, 71 deletions
diff --git a/sys/miscfs/devfs/devfs_tree.c b/sys/miscfs/devfs/devfs_tree.c index c7c561e72e80..6d03fa6192ad 100644 --- a/sys/miscfs/devfs/devfs_tree.c +++ b/sys/miscfs/devfs/devfs_tree.c @@ -1,4 +1,4 @@ -/*#define SPLIT_DEVS 1*/ + /* * Copyright 1997,1998 Julian Elischer. All rights reserved. * julian@freebsd.org @@ -24,15 +24,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: devfs_tree.c,v 1.50 1998/03/26 20:52:05 phk Exp $ + * $Id: devfs_tree.c,v 1.51 1998/04/17 22:36:53 des Exp $ */ + +#define SPLIT_DEVS 1 +/*#define SPLIT_DEVS 1*/ + #include "opt_devfs.h" #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> #include <sys/conf.h> +#include <sys/fcntl.h> #include <sys/malloc.h> #include <sys/mount.h> #include <sys/proc.h> @@ -894,44 +899,6 @@ DBPRINT((" vntodn ")); return(0); } -#ifdef DEVFS_ROOT -static dn_p -findbdev(dev_t dev, dn_p dir) -{ - devnm_p newfp; - dn_p dnp; - - for(newfp = dir->by.Dir.dirlist;newfp;newfp=newfp->next) { - dnp = newfp->dnp; - if (dnp->type == DEV_BDEV && dnp->by.Bdev.dev == dev) { - return (dnp); - } - if (dnp->type == DEV_DIR) { - if (dnp = findbdev(dev, dnp)) - return dnp; - } - } - return (0); -} - -/* - * Create a vnode for a block device. - * Used for mounting the root file system. - */ -int -bdevvp(dev_t dev, struct vnode **vpp) -{ - dn_p dnp = 0; - - if (dev == NODEV) - return(0); - dnp= findbdev(dev, dev_root->dnp); - if (!dnp) - return (ENOENT); - return (devfs_dntovn(dnp, vpp)); -} -#endif /* DEVFS_ROOT */ - /***************************************************************\ * given a dev_node, find the appropriate vnode if one is already* * associated, or get a new one an associate it with the dev_node* @@ -1207,3 +1174,116 @@ devfs_link(void *original, char *fmt, ...) return new_dev; } +/* + * internal kernel call to open a device. Return either 0 or an open vnode. + */ +struct vnode * +devfs_open_device(char *path, int type) +{ + register char *lastslash; + char *nextpart; + devnm_p nm_p; + dn_p dirnode; + struct vnode *vn; + + /* + * If the caller didn't supply a full path, ignore and be + * noisy about it. + */ + if (*path != '/') { + printf (__FUNCTION__ ": caller supplied bad path\n"); + return (NULL); + } + + /* + * find the last '/'. Unfortunatly rindex() while being in + * libkern source, is not being compiled.. do it by hand. + * lastslash = strrchr(path,(int)'c'); + * There will be at LEAST one '/'. + */ + { + register char *p = path; /* don't destroy path */ + + for (lastslash = NULL;*p; ++p) { + if (*p == '/') + lastslash = p; + } + } + dirnode = dev_root->dnp; + if(lastslash != path) { + /* find the directory we need */ + *lastslash = '\0'; + if (dev_finddir(path, dirnode, NULL, &dirnode) != 0) { + *lastslash = '/'; + return (NULL); + } + /* ok we found the directory, put the slash back */ + *lastslash = '/'; + } + nextpart = ++lastslash; + if (*nextpart == '\0') + return (NULL); + /* + * Now only return true if it exists and is the right type. + */ + if ((nm_p = dev_findname(dirnode, nextpart)) == NULL) { + return (NULL); + } + switch(type) { + case DV_BLK: + if( nm_p->dnp->type != DEV_BDEV) + return (NULL); + break; + case DV_CHR: + if( nm_p->dnp->type != DEV_CDEV) + return (NULL); + break; + } + + if ( devfs_dntovn(nm_p->dnp, &vn)) + return (NULL); + +#if 0 + if ( VOP_OPEN(vn, FREAD, proc0.p_cred->pc_ucred, &proc0)) { + vput(vn); + return (NULL); + } +#endif + return (vn); +} + +/* + * internal kernel call to close a devfs device. + * It should have been openned by th ecall above. + * try not mix it with user-openned vnodes. + * Frees the vnode. + */ +void +devfs_close_device(struct vnode *vn) +{ +#if 0 + VOP_CLOSE(vn, 0, proc0.p_cred->pc_ucred, &proc0) ; +#endif + vput(vn); +} + +/* + * Little utility routine for compatibilty. + * Returns the dev_t that a devfs vnode represents. + * should go away after dev_t go away :). + */ +dev_t +devfs_vntodev(struct vnode *vn) +{ + register dn_p dnp; + dnp = (dn_p)vn->v_data; + switch (dnp->type) { + case DEV_BDEV: + return (dnp->by.Bdev.dev); + break; + case DEV_CDEV: + return (dnp->by.Cdev.dev); + break; + } + panic ("bad devfs DEVICE vnode"); +} diff --git a/sys/miscfs/devfs/devfs_vfsops.c b/sys/miscfs/devfs/devfs_vfsops.c index 442dc1bab775..c87ec56fe5f4 100644 --- a/sys/miscfs/devfs/devfs_vfsops.c +++ b/sys/miscfs/devfs/devfs_vfsops.c @@ -23,10 +23,11 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: devfs_vfsops.c,v 1.27 1998/03/01 22:46:08 msmith Exp $ + * $Id: devfs_vfsops.c,v 1.28 1998/04/17 22:36:53 des Exp $ * */ + #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> diff --git a/sys/miscfs/devfs/devfs_vnops.c b/sys/miscfs/devfs/devfs_vnops.c index 773d90395e99..6c9bae79957d 100644 --- a/sys/miscfs/devfs/devfs_vnops.c +++ b/sys/miscfs/devfs/devfs_vnops.c @@ -1,3 +1,4 @@ + /* * Copyright 1997,1998 Julian Elischer. All rights reserved. * julian@freebsd.org @@ -23,9 +24,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: devfs_vnops.c,v 1.52 1998/03/10 09:12:19 julian Exp $ + * $Id: devfs_vnops.c,v 1.53 1998/03/26 20:52:12 phk Exp $ */ + #include <sys/param.h> #include <sys/systm.h> #include <sys/namei.h> @@ -482,33 +484,23 @@ DBPRINT(("getattr\n")); vap->va_fileid = (long)file_node; vap->va_size = file_node->len; /* now a u_quad_t */ vap->va_blocksize = 512; - if(file_node->ctime.tv_sec) - { - vap->va_ctime = file_node->ctime; - } - else - { - TIMEVAL_TO_TIMESPEC(&boottime,&(vap->va_ctime)); - } - if(file_node->mtime.tv_sec) - { - vap->va_mtime = file_node->mtime; - } - else - { - TIMEVAL_TO_TIMESPEC(&boottime,&(vap->va_mtime)); - } - if(file_node->atime.tv_sec) - { - vap->va_atime = file_node->atime; - } - else + /* + * XXX If the node times are in Jan 1, 1970, then + * update them to the boot time. + * When we made the node, the date/time was not yet known. + */ + if(file_node->ctime.tv_sec < (24 * 3600)) { - TIMEVAL_TO_TIMESPEC(&boottime,&(vap->va_atime)); + TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->ctime)); + TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->mtime)); + TIMEVAL_TO_TIMESPEC(&boottime,&(file_node->atime)); } + vap->va_ctime = file_node->ctime; + vap->va_mtime = file_node->mtime; + vap->va_atime = file_node->atime; vap->va_gen = 0; vap->va_flags = 0; - vap->va_bytes = file_node->len; /* u_quad_t */ + vap->va_bytes = file_node->len; /* u_quad_t */ vap->va_filerev = 0; /* XXX */ /* u_quad_t */ vap->va_vaflags = 0; /* XXX */ return 0; diff --git a/sys/miscfs/devfs/devfsdefs.h b/sys/miscfs/devfs/devfsdefs.h index b475e22379a2..ef31dd9ae0d4 100644 --- a/sys/miscfs/devfs/devfsdefs.h +++ b/sys/miscfs/devfs/devfsdefs.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: devfsdefs.h,v 1.12 1997/10/11 18:31:29 phk Exp $ + * $Id: devfsdefs.h,v 1.13 1998/01/02 07:31:07 julian Exp $ */ #ifdef DEVFS_DEBUG #define DBPRINT(A) printf(A) @@ -31,7 +31,6 @@ #define DBPRINT(A) #endif - /* first a couple of defines for compatibility with inodes */ #define ISUID 04000 /* set user identifier when exec'ing */ diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index 666322f65609..82f001d49035 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)spec_vnops.c 8.14 (Berkeley) 5/21/95 - * $Id: spec_vnops.c,v 1.59 1998/03/08 08:46:18 dyson Exp $ + * $Id: spec_vnops.c,v 1.60 1998/03/08 09:57:36 julian Exp $ */ #include <sys/param.h> @@ -761,8 +761,15 @@ spec_getpages(ap) * Round up physical size for real devices, use the * fundamental blocksize of the fs if possible. */ - if (vp && vp->v_mount) + if (vp && vp->v_mount) { + if (vp->v_type != VBLK) { + vprint("Non VBLK", vp); + } blksiz = vp->v_mount->mnt_stat.f_bsize; + if (blksiz < DEV_BSIZE) { + blksiz = DEV_BSIZE; + } + } else blksiz = DEV_BSIZE; size = (ap->a_count + blksiz - 1) & ~(blksiz - 1); diff --git a/sys/miscfs/specfs/specdev.h b/sys/miscfs/specfs/specdev.h index b4c6f7750458..9c225a3832be 100644 --- a/sys/miscfs/specfs/specdev.h +++ b/sys/miscfs/specfs/specdev.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)specdev.h 8.6 (Berkeley) 5/21/95 - * $Id: specdev.h,v 1.13 1997/10/15 13:23:21 phk Exp $ + * $Id: specdev.h,v 1.14 1998/03/08 09:57:40 julian Exp $ */ /* @@ -43,7 +43,8 @@ struct specinfo { struct vnode **si_hashchain; struct vnode *si_specnext; struct mount *si_mountpoint; - dev_t si_rdev; + dev_t si_rdev; + unsigned long si_blksize; /* smallest IO unit */ }; /* * Exported shorthand @@ -52,6 +53,7 @@ struct specinfo { #define v_hashchain v_specinfo->si_hashchain #define v_specnext v_specinfo->si_specnext #define v_specmountpoint v_specinfo->si_mountpoint +#define v_blksize v_specinfo->si_blksize /* * Special device management |