Either cvs(1) or I forgot this file in my last commit.
Please see commit log for rev 1.4 of src/sbin/mdconfig/mdconfig.c
This commit is contained in:
parent
e6de111aca
commit
637f671a3d
118
sys/dev/md/md.c
118
sys/dev/md/md.c
@ -10,6 +10,53 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* The following functions are based in the vn(4) driver: mdstart_swap(),
|
||||
* mdstart_vnode(), mdcreate_swap(), mdcreate_vnode() and mddestroy(),
|
||||
* and as such under the following copyright:
|
||||
*
|
||||
* Copyright (c) 1988 University of Utah.
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* the Systems Programming Group of the University of Utah Computer
|
||||
* Science Department.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: Utah Hdr: vn.c 1.13 94/04/02
|
||||
*
|
||||
* from: @(#)vn.c 8.6 (Berkeley) 4/1/94
|
||||
* From: src/sys/dev/vn/vn.c,v 1.122 2000/12/16 16:06:03
|
||||
*/
|
||||
|
||||
#include "opt_mfs.h" /* We have adopted some tasks from MFS */
|
||||
#include "opt_md.h"
|
||||
|
||||
@ -150,7 +197,6 @@ mdopen(dev_t dev, int flag, int fmt, struct proc *p)
|
||||
dl = &sc->disk.d_label;
|
||||
bzero(dl, sizeof(*dl));
|
||||
dl->d_secsize = sc->secsize;
|
||||
if (sc->nsect > 1024)
|
||||
dl->d_nsectors = sc->nsect > 1024 ? 1024 : sc->nsect;
|
||||
dl->d_ntracks = 1;
|
||||
dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
|
||||
@ -512,24 +558,35 @@ mdinit(struct md_s *sc)
|
||||
sc->dev->si_drv1 = sc;
|
||||
}
|
||||
|
||||
static void
|
||||
mdcreate_preload(u_char *image, unsigned length)
|
||||
static int
|
||||
mdcreate_preload(struct md_ioctl *mdio)
|
||||
{
|
||||
struct md_s *sc;
|
||||
|
||||
sc = mdnew(-1);
|
||||
if (sc == NULL)
|
||||
return;
|
||||
if (mdio->md_size == 0)
|
||||
return(EINVAL);
|
||||
if (mdio->md_options & ~(MD_AUTOUNIT))
|
||||
return(EINVAL);
|
||||
if (mdio->md_options & MD_AUTOUNIT) {
|
||||
sc = mdnew(-1);
|
||||
if (sc == NULL)
|
||||
return (ENOMEM);
|
||||
mdio->md_unit = sc->unit;
|
||||
} else {
|
||||
sc = mdnew(mdio->md_unit);
|
||||
if (sc == NULL)
|
||||
return (EBUSY);
|
||||
}
|
||||
sc->type = MD_PRELOAD;
|
||||
sc->secsize = DEV_BSIZE;
|
||||
sc->nsect = length / DEV_BSIZE;
|
||||
sc->pl_ptr = image;
|
||||
sc->pl_len = length;
|
||||
if (sc->unit == 0)
|
||||
mdrootready = 1;
|
||||
sc->nsect = mdio->md_size;
|
||||
sc->pl_ptr = (u_char *)mdio->md_base;
|
||||
sc->pl_len = (mdio->md_size << DEV_BSHIFT);
|
||||
mdinit(sc);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
mdcreate_malloc(struct md_ioctl *mdio)
|
||||
{
|
||||
@ -633,14 +690,14 @@ mdcreate_vnode(struct md_ioctl *mdio, struct proc *p)
|
||||
sc->type = MD_VNODE;
|
||||
|
||||
flags = FREAD|FWRITE;
|
||||
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, mdio->md_file, p);
|
||||
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, mdio->md_file, p);
|
||||
error = vn_open(&nd, &flags, 0);
|
||||
if (error) {
|
||||
if (error != EACCES && error != EPERM && error != EROFS)
|
||||
return (error);
|
||||
flags &= ~FWRITE;
|
||||
sc->flags |= MD_READONLY;
|
||||
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, mdio->md_file, p);
|
||||
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, mdio->md_file, p);
|
||||
error = vn_open(&nd, &flags, 0);
|
||||
if (error)
|
||||
return (error);
|
||||
@ -758,18 +815,13 @@ mdctlioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
|
||||
devtoname(dev), cmd, addr, flags, p);
|
||||
|
||||
mdio = (struct md_ioctl *)addr;
|
||||
if (mdio->md_type != MD_VNODE)
|
||||
mdio->md_file[0] = '\0';
|
||||
switch (cmd) {
|
||||
case MDIOCATTACH:
|
||||
printf("A: u %u t %d n %s s %u o %u\n", mdio->md_unit,
|
||||
mdio->md_type, mdio->md_file, mdio->md_size,
|
||||
mdio->md_options);
|
||||
switch (mdio->md_type) {
|
||||
case MD_MALLOC:
|
||||
return(mdcreate_malloc(mdio));
|
||||
case MD_PRELOAD:
|
||||
return (EINVAL);
|
||||
return(mdcreate_preload(mdio));
|
||||
case MD_VNODE:
|
||||
return(mdcreate_vnode(mdio, p));
|
||||
case MD_SWAP:
|
||||
@ -778,10 +830,7 @@ mdctlioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
|
||||
return (EINVAL);
|
||||
}
|
||||
case MDIOCDETACH:
|
||||
printf("D: u %u t %d n %s s %u o %u\n", mdio->md_unit,
|
||||
mdio->md_type, mdio->md_file, mdio->md_size,
|
||||
mdio->md_options);
|
||||
if (*mdio->md_file != '\0')
|
||||
if (mdio->md_file != NULL)
|
||||
return(EINVAL);
|
||||
if (mdio->md_size != 0)
|
||||
return(EINVAL);
|
||||
@ -794,6 +843,7 @@ mdctlioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
|
||||
case MD_VNODE:
|
||||
case MD_SWAP:
|
||||
case MD_MALLOC:
|
||||
case MD_PRELOAD:
|
||||
return(mddestroy(sc, mdio, p));
|
||||
default:
|
||||
return (EOPNOTSUPP);
|
||||
@ -804,6 +854,24 @@ mdctlioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
|
||||
return (ENOIOCTL);
|
||||
}
|
||||
|
||||
static void
|
||||
md_preloaded(u_char *image, unsigned length)
|
||||
{
|
||||
struct md_s *sc;
|
||||
|
||||
sc = mdnew(-1);
|
||||
if (sc == NULL)
|
||||
return;
|
||||
sc->type = MD_PRELOAD;
|
||||
sc->secsize = DEV_BSIZE;
|
||||
sc->nsect = length / DEV_BSIZE;
|
||||
sc->pl_ptr = image;
|
||||
sc->pl_len = length;
|
||||
if (sc->unit == 0)
|
||||
mdrootready = 1;
|
||||
mdinit(sc);
|
||||
}
|
||||
|
||||
static void
|
||||
md_drvinit(void *unused)
|
||||
{
|
||||
@ -814,7 +882,7 @@ md_drvinit(void *unused)
|
||||
unsigned len;
|
||||
|
||||
#ifdef MD_ROOT_SIZE
|
||||
mdcreate_preload(mfs_root, MD_ROOT_SIZE*1024);
|
||||
md_preloaded(mfs_root, MD_ROOT_SIZE*1024);
|
||||
#endif
|
||||
mod = NULL;
|
||||
while ((mod = preload_search_next_name(mod)) != NULL) {
|
||||
@ -832,7 +900,7 @@ md_drvinit(void *unused)
|
||||
len = *(unsigned *)c;
|
||||
printf("md%d: Preloaded image <%s> %d bytes at %p\n",
|
||||
mdunits, name, len, ptr);
|
||||
mdcreate_preload(ptr, len);
|
||||
md_preloaded(ptr, len);
|
||||
}
|
||||
make_dev(&mdctl_cdevsw, 0xffff00ff, UID_ROOT, GID_WHEEL, 0600, "mdctl");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user