Retire MFS_ROOT and MFS_ROOT_SIZE options from the MFS implementation.

Add MD_ROOT and MD_ROOT_SIZE options to the md driver.

Make the md driver handle MFS_ROOT and MFS_ROOT_SIZE options for compatibility.

Add md driver to GENERIC, PCCARD and LINT.

This is a cleanup which removes the need for some of the worse hacks in
MFS:  We really want to have a rootvnode but MFS on a preloaded image
doesn't really have one.  md is a true device, so it is less trouble.

This has been tested with make release, and if people remember to add
the "md" pseudo-device to their kernels, PicoBSD should be just fine
as well.  If people have no other use for MFS, it can be removed from
the kernel.
This commit is contained in:
Poul-Henning Kamp 1999-11-26 20:08:44 +00:00
parent 7dfec6b427
commit 71e4fff823
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53722
13 changed files with 234 additions and 233 deletions

View file

@ -31,8 +31,8 @@ options MATH_EMULATE #Support for x87 emulation
options INET #InterNETworking options INET #InterNETworking
options FFS #Berkeley Fast Filesystem options FFS #Berkeley Fast Filesystem
options FFS_ROOT #FFS usable as root device [keep this!] options FFS_ROOT #FFS usable as root device [keep this!]
options MD_ROOT #MD is a potential root device
options MFS #Memory Filesystem options MFS #Memory Filesystem
options MFS_ROOT #MFS usable as root device, "MFS" req'ed
options NFS #Network Filesystem options NFS #Network Filesystem
options NFS_ROOT #NFS usable as root device, "NFS" req'ed options NFS_ROOT #NFS usable as root device, "NFS" req'ed
options MSDOSFS #MSDOS Filesystem options MSDOSFS #MSDOS Filesystem
@ -206,6 +206,7 @@ pseudo-device ppp 1 # Kernel PPP
pseudo-device tun # Packet tunnel. pseudo-device tun # Packet tunnel.
pseudo-device pty # Pseudo-ttys (telnet etc) pseudo-device pty # Pseudo-ttys (telnet etc)
pseudo-device gzip # Exec gzipped a.out's pseudo-device gzip # Exec gzipped a.out's
pseudo-device md # Memory "disks"
# The `bpf' pseudo-device enables the Berkeley Packet Filter. # The `bpf' pseudo-device enables the Berkeley Packet Filter.
# Be aware of the administrative consequences of enabling this! # Be aware of the administrative consequences of enabling this!

View file

@ -604,7 +604,6 @@ options UNION #Union filesystem
# The xFS_ROOT options REQUIRE the associated ``options xFS'' # The xFS_ROOT options REQUIRE the associated ``options xFS''
options CD9660_ROOT #CD-ROM usable as root device options CD9660_ROOT #CD-ROM usable as root device
options FFS_ROOT #FFS usable as root device options FFS_ROOT #FFS usable as root device
options MFS_ROOT #MFS usable as root device
options NFS_ROOT #NFS usable as root device options NFS_ROOT #NFS usable as root device
# This code is still experimental (e.g. doesn't handle disk slices well). # This code is still experimental (e.g. doesn't handle disk slices well).
# Also, 'options MFS' is currently incompatible with DEVFS. # Also, 'options MFS' is currently incompatible with DEVFS.
@ -620,9 +619,13 @@ options DEVFS #devices filesystem
# #
#options SOFTUPDATES #options SOFTUPDATES
# Make space in the kernel for a MFS root filesystem. Define to the number # Make space in the kernel for a root filesystem on a md device.
# of kilobytes to reserve for the filesystem. # Define to the number of kilobytes to reserve for the filesystem.
options MFS_ROOT_SIZE=10 options MD_ROOT_SIZE=10
# Make the md device a potential root device, either with preloaded
# images of type mfs_root or md_root.
options MD_ROOT
# Allow this many swap-devices. # Allow this many swap-devices.
options NSWAPDEV=20 options NSWAPDEV=20

View file

@ -55,6 +55,8 @@ DEVFS
HW_WDOG HW_WDOG
KTRACE KTRACE
MD5 MD5
MD_ROOT opt_md.h
MD_ROOT_SIZE opt_md.h
MFS_ROOT opt_mfs.h MFS_ROOT opt_mfs.h
MFS_ROOT_SIZE opt_mfs.h MFS_ROOT_SIZE opt_mfs.h
NTIMECOUNTER opt_ntp.h NTIMECOUNTER opt_ntp.h

View file

@ -10,6 +10,9 @@
* *
*/ */
#include "opt_mfs.h" /* We have adopted some tasks from MFS */
#include "opt_md.h" /* We have adopted some tasks from MFS */
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/buf.h> #include <sys/buf.h>
@ -28,13 +31,33 @@
MALLOC_DEFINE(M_MD, "MD disk", "Memory Disk"); MALLOC_DEFINE(M_MD, "MD disk", "Memory Disk");
MALLOC_DEFINE(M_MDSECT, "MD sectors", "Memory Disk Sectors"); MALLOC_DEFINE(M_MDSECT, "MD sectors", "Memory Disk Sectors");
static int md_debug = 0; static int md_debug;
SYSCTL_INT(_debug, OID_AUTO, mddebug, CTLFLAG_RW, &md_debug, 0, ""); SYSCTL_INT(_debug, OID_AUTO, mddebug, CTLFLAG_RW, &md_debug, 0, "");
#if defined(MFS_ROOT) && !defined(MD_ROOT)
#define MD_ROOT MFS_ROOT
#warning "option MFS_ROOT has been superceeded by MD_ROOT"
#endif
#if defined(MFS_ROOT_SIZE) && !defined(MD_ROOT_SIZE)
#define MD_ROOT_SIZE MFS_ROOT_SIZE
#warning "option MFS_ROOT_SIZE has been superceeded by MD_ROOT_SIZE"
#endif
#if defined(MD_ROOT) && defined(MD_ROOT_SIZE)
/* Image gets put here: */
static u_char mfs_root[MD_ROOT_SIZE*1024] = "MFS Filesystem goes here";
static u_char end_mfs_root[] __unused = "MFS Filesystem had better STOP here";
#endif
static int mdrootready;
#define CDEV_MAJOR 95 #define CDEV_MAJOR 95
#define BDEV_MAJOR 22 #define BDEV_MAJOR 22
static d_strategy_t mdstrategy; static d_strategy_t mdstrategy;
static d_strategy_t mdstrategy_preload;
static d_strategy_t mdstrategy_malloc;
static d_open_t mdopen; static d_open_t mdopen;
static d_ioctl_t mdioctl; static d_ioctl_t mdioctl;
@ -51,10 +74,9 @@ static struct cdevsw md_cdevsw = {
/* maj */ CDEV_MAJOR, /* maj */ CDEV_MAJOR,
/* dump */ nodump, /* dump */ nodump,
/* psize */ nopsize, /* psize */ nopsize,
/* flags */ D_DISK | D_CANFREE, /* flags */ D_DISK | D_CANFREE | D_MEMDISK,
/* bmaj */ BDEV_MAJOR /* bmaj */ BDEV_MAJOR
}; };
static struct cdevsw mddisk_cdevsw;
struct md_s { struct md_s {
int unit; int unit;
@ -65,6 +87,7 @@ struct md_s {
int busy; int busy;
enum {MD_MALLOC, MD_PRELOAD} type; enum {MD_MALLOC, MD_PRELOAD} type;
unsigned nsect; unsigned nsect;
struct cdevsw devsw;
/* MD_MALLOC related fields */ /* MD_MALLOC related fields */
unsigned nsecp; unsigned nsecp;
@ -113,6 +136,26 @@ mdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
static void static void
mdstrategy(struct buf *bp) mdstrategy(struct buf *bp)
{
struct md_s *sc;
if (md_debug > 1)
printf("mdstrategy(%p) %s %lx, %d, %ld, %p)\n",
bp, devtoname(bp->b_dev), bp->b_flags, bp->b_blkno,
bp->b_bcount / DEV_BSIZE, bp->b_data);
sc = bp->b_dev->si_drv1;
if (sc->type == MD_MALLOC) {
mdstrategy_malloc(bp);
} else {
mdstrategy_preload(bp);
}
return;
}
static void
mdstrategy_malloc(struct buf *bp)
{ {
int s, i; int s, i;
struct md_s *sc; struct md_s *sc;
@ -121,7 +164,7 @@ mdstrategy(struct buf *bp)
unsigned secno, nsec, secval, uc; unsigned secno, nsec, secval, uc;
if (md_debug > 1) if (md_debug > 1)
printf("mdstrategy(%p) %s %lx, %d, %ld, %p)\n", printf("mdstrategy_malloc(%p) %s %lx, %d, %ld, %p)\n",
bp, devtoname(bp->b_dev), bp->b_flags, bp->b_blkno, bp, devtoname(bp->b_dev), bp->b_flags, bp->b_blkno,
bp->b_bcount / DEV_BSIZE, bp->b_data); bp->b_bcount / DEV_BSIZE, bp->b_data);
@ -155,90 +198,79 @@ mdstrategy(struct buf *bp)
else else
dop = DEVSTAT_WRITE; dop = DEVSTAT_WRITE;
if (sc->type == MD_MALLOC) { nsec = bp->b_bcount / DEV_BSIZE;
nsec = bp->b_bcount / DEV_BSIZE; secno = bp->b_pblkno;
secno = bp->b_pblkno; dst = bp->b_data;
dst = bp->b_data; while (nsec--) {
while (nsec--) {
if (secno < sc->nsecp) { if (secno < sc->nsecp) {
secpp = &sc->secp[secno]; secpp = &sc->secp[secno];
if ((u_int)*secpp > 255) { if ((u_int)*secpp > 255) {
secp = *secpp; secp = *secpp;
secval = 0;
} else {
secp = 0;
secval = (u_int) *secpp;
}
} else {
secpp = 0;
secp = 0;
secval = 0; secval = 0;
}
if (md_debug > 2)
printf("%lx %p %p %d\n", bp->b_flags, secpp, secp, secval);
if (bp->b_flags & B_FREEBUF) {
if (secpp) {
if (secp)
FREE(secp, M_MDSECT);
*secpp = 0;
}
} else if (bp->b_flags & B_READ) {
if (secp) {
bcopy(secp, dst, DEV_BSIZE);
} else if (secval) {
for (i = 0; i < DEV_BSIZE; i++)
dst[i] = secval;
} else {
bzero(dst, DEV_BSIZE);
}
} else { } else {
uc = dst[0]; secp = 0;
for (i = 1; i < DEV_BSIZE; i++) secval = (u_int) *secpp;
if (dst[i] != uc) }
break; } else {
if (i == DEV_BSIZE && !uc) { secpp = 0;
secp = 0;
secval = 0;
}
if (md_debug > 2)
printf("%lx %p %p %d\n", bp->b_flags, secpp, secp, secval);
if (bp->b_flags & B_FREEBUF) {
if (secpp) {
if (secp)
FREE(secp, M_MDSECT);
*secpp = 0;
}
} else if (bp->b_flags & B_READ) {
if (secp) {
bcopy(secp, dst, DEV_BSIZE);
} else if (secval) {
for (i = 0; i < DEV_BSIZE; i++)
dst[i] = secval;
} else {
bzero(dst, DEV_BSIZE);
}
} else {
uc = dst[0];
for (i = 1; i < DEV_BSIZE; i++)
if (dst[i] != uc)
break;
if (i == DEV_BSIZE && !uc) {
if (secp)
FREE(secp, M_MDSECT);
if (secpp)
*secpp = (u_char *)uc;
} else {
if (!secpp) {
MALLOC(secpp, u_char **, (secno + nsec + 1) * sizeof(u_char *), M_MD, M_WAITOK);
bzero(secpp, (secno + nsec + 1) * sizeof(u_char *));
bcopy(sc->secp, secpp, sc->nsecp * sizeof(u_char *));
FREE(sc->secp, M_MD);
sc->secp = secpp;
sc->nsecp = secno + nsec + 1;
secpp = &sc->secp[secno];
}
if (i == DEV_BSIZE) {
if (secp) if (secp)
FREE(secp, M_MDSECT); FREE(secp, M_MDSECT);
if (secpp) *secpp = (u_char *)uc;
*secpp = (u_char *)uc;
} else { } else {
if (!secpp) { if (!secp)
MALLOC(secpp, u_char **, (secno + nsec + 1) * sizeof(u_char *), M_MD, M_WAITOK); MALLOC(secp, u_char *, DEV_BSIZE, M_MDSECT, M_WAITOK);
bzero(secpp, (secno + nsec + 1) * sizeof(u_char *)); bcopy(dst, secp, DEV_BSIZE);
bcopy(sc->secp, secpp, sc->nsecp * sizeof(u_char *));
FREE(sc->secp, M_MD);
sc->secp = secpp;
sc->nsecp = secno + nsec + 1;
secpp = &sc->secp[secno];
}
if (i == DEV_BSIZE) {
if (secp)
FREE(secp, M_MDSECT);
*secpp = (u_char *)uc;
} else {
if (!secp)
MALLOC(secp, u_char *, DEV_BSIZE, M_MDSECT, M_WAITOK);
bcopy(dst, secp, DEV_BSIZE);
*secpp = secp; *secpp = secp;
}
} }
} }
secno++;
dst += DEV_BSIZE;
}
} else {
if (bp->b_flags & B_FREEBUF) {
/* nothing */
} else if (bp->b_flags & B_READ) {
bcopy(sc->pl_ptr + (secno << DEV_BSHIFT), bp->b_data, bp->b_bcount);
} else {
bcopy(bp->b_data, sc->pl_ptr + (secno << DEV_BSHIFT), bp->b_bcount);
} }
secno++;
dst += DEV_BSIZE;
} }
bp->b_resid = 0; bp->b_resid = 0;
devstat_end_transaction_buf(&sc->stats, bp); devstat_end_transaction_buf(&sc->stats, bp);
biodone(bp); biodone(bp);
@ -248,8 +280,62 @@ mdstrategy(struct buf *bp)
return; return;
} }
static void static void
mdcreate_preload(u_char *image, unsigned length) mdstrategy_preload(struct buf *bp)
{
int s;
struct md_s *sc;
devstat_trans_flags dop;
if (md_debug > 1)
printf("mdstrategy_preload(%p) %s %lx, %d, %ld, %p)\n",
bp, devtoname(bp->b_dev), bp->b_flags, bp->b_blkno,
bp->b_bcount / DEV_BSIZE, bp->b_data);
sc = bp->b_dev->si_drv1;
s = splbio();
bufqdisksort(&sc->buf_queue, bp);
if (sc->busy) {
splx(s);
return;
}
sc->busy++;
while (1) {
bp = bufq_first(&sc->buf_queue);
if (bp)
bufq_remove(&sc->buf_queue, bp);
splx(s);
if (!bp)
break;
devstat_start_transaction(&sc->stats);
if (bp->b_flags & B_FREEBUF) {
dop = DEVSTAT_NO_DATA;
} else if (bp->b_flags & B_READ) {
dop = DEVSTAT_READ;
bcopy(sc->pl_ptr + (bp->b_pblkno << DEV_BSHIFT), bp->b_data, bp->b_bcount);
} else {
dop = DEVSTAT_WRITE;
bcopy(bp->b_data, sc->pl_ptr + (bp->b_pblkno << DEV_BSHIFT), bp->b_bcount);
}
bp->b_resid = 0;
devstat_end_transaction_buf(&sc->stats, bp);
biodone(bp);
s = splbio();
}
sc->busy = 0;
return;
}
static struct md_s *
mdcreate(struct cdevsw *devsw)
{ {
struct md_s *sc; struct md_s *sc;
@ -260,13 +346,25 @@ mdcreate_preload(u_char *image, unsigned length)
bufq_init(&sc->buf_queue); bufq_init(&sc->buf_queue);
devstat_add_entry(&sc->stats, "md", sc->unit, DEV_BSIZE, devstat_add_entry(&sc->stats, "md", sc->unit, DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS, DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER, 0x190); DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
sc->dev = disk_create(sc->unit, &sc->disk, 0, DEVSTAT_PRIORITY_OTHER);
&md_cdevsw, &mddisk_cdevsw); sc->dev = disk_create(sc->unit, &sc->disk, 0, devsw, &sc->devsw);
sc->dev->si_drv1 = sc; sc->dev->si_drv1 = sc;
return (sc);
}
static void
mdcreate_preload(u_char *image, unsigned length)
{
struct md_s *sc;
sc = mdcreate(&md_cdevsw);
sc->nsect = length / DEV_BSIZE; sc->nsect = length / DEV_BSIZE;
sc->pl_ptr = image; sc->pl_ptr = image;
sc->pl_len = length; sc->pl_len = length;
if (sc->unit == 0)
mdrootready = 1;
} }
static void static void
@ -274,21 +372,8 @@ mdcreate_malloc(void)
{ {
struct md_s *sc; struct md_s *sc;
MALLOC(sc, struct md_s *,sizeof(*sc), M_MD, M_WAITOK); sc = mdcreate(&md_cdevsw);
bzero(sc, sizeof(*sc));
sc->unit = mdunits++;
sc->type = MD_MALLOC;
bufq_init(&sc->buf_queue);
devstat_add_entry(&sc->stats, "md", sc->unit, DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER, 0x190);
sc->dev = disk_create(sc->unit, &sc->disk, 0,
&md_cdevsw, &mddisk_cdevsw);
sc->dev->si_drv1 = sc;
sc->nsect = MDNSECT; /* for now */ sc->nsect = MDNSECT; /* for now */
MALLOC(sc->secp, u_char **, sizeof(u_char *), M_MD, M_WAITOK); MALLOC(sc->secp, u_char **, sizeof(u_char *), M_MD, M_WAITOK);
bzero(sc->secp, sizeof(u_char *)); bzero(sc->secp, sizeof(u_char *));
@ -304,6 +389,9 @@ md_drvinit(void *unused)
u_char *ptr, *name, *type; u_char *ptr, *name, *type;
unsigned len; unsigned len;
#ifdef MD_ROOT_SIZE
mdcreate_preload(mfs_root, MD_ROOT_SIZE*1024);
#endif
mod = NULL; mod = NULL;
while ((mod = preload_search_next_name(mod)) != NULL) { while ((mod = preload_search_next_name(mod)) != NULL) {
name = (char *)preload_search_info(mod, MODINFO_NAME); name = (char *)preload_search_info(mod, MODINFO_NAME);
@ -312,7 +400,7 @@ md_drvinit(void *unused)
continue; continue;
if (type == NULL) if (type == NULL)
continue; continue;
if (strcmp(type, "md_image")) if (strcmp(type, "md_image") && strcmp(type, "mfs_root"))
continue; continue;
c = preload_search_info(mod, MODINFO_ADDR); c = preload_search_info(mod, MODINFO_ADDR);
ptr = *(u_char **)c; ptr = *(u_char **)c;
@ -325,5 +413,15 @@ md_drvinit(void *unused)
mdcreate_malloc(); mdcreate_malloc();
} }
SYSINIT(ptcdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, md_drvinit,NULL) SYSINIT(mddev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, md_drvinit,NULL)
#ifdef MD_ROOT
static void
md_takeroot(void *junk)
{
if (mdrootready)
rootdevnames[0] = "ufs:/dev/md0c";
}
SYSINIT(md_root, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, md_takeroot, NULL);
#endif

View file

@ -31,8 +31,8 @@ options MATH_EMULATE #Support for x87 emulation
options INET #InterNETworking options INET #InterNETworking
options FFS #Berkeley Fast Filesystem options FFS #Berkeley Fast Filesystem
options FFS_ROOT #FFS usable as root device [keep this!] options FFS_ROOT #FFS usable as root device [keep this!]
options MD_ROOT #MD is a potential root device
options MFS #Memory Filesystem options MFS #Memory Filesystem
options MFS_ROOT #MFS usable as root device, "MFS" req'ed
options NFS #Network Filesystem options NFS #Network Filesystem
options NFS_ROOT #NFS usable as root device, "NFS" req'ed options NFS_ROOT #NFS usable as root device, "NFS" req'ed
options MSDOSFS #MSDOS Filesystem options MSDOSFS #MSDOS Filesystem
@ -206,6 +206,7 @@ pseudo-device ppp 1 # Kernel PPP
pseudo-device tun # Packet tunnel. pseudo-device tun # Packet tunnel.
pseudo-device pty # Pseudo-ttys (telnet etc) pseudo-device pty # Pseudo-ttys (telnet etc)
pseudo-device gzip # Exec gzipped a.out's pseudo-device gzip # Exec gzipped a.out's
pseudo-device md # Memory "disks"
# The `bpf' pseudo-device enables the Berkeley Packet Filter. # The `bpf' pseudo-device enables the Berkeley Packet Filter.
# Be aware of the administrative consequences of enabling this! # Be aware of the administrative consequences of enabling this!

View file

@ -604,7 +604,6 @@ options UNION #Union filesystem
# The xFS_ROOT options REQUIRE the associated ``options xFS'' # The xFS_ROOT options REQUIRE the associated ``options xFS''
options CD9660_ROOT #CD-ROM usable as root device options CD9660_ROOT #CD-ROM usable as root device
options FFS_ROOT #FFS usable as root device options FFS_ROOT #FFS usable as root device
options MFS_ROOT #MFS usable as root device
options NFS_ROOT #NFS usable as root device options NFS_ROOT #NFS usable as root device
# This code is still experimental (e.g. doesn't handle disk slices well). # This code is still experimental (e.g. doesn't handle disk slices well).
# Also, 'options MFS' is currently incompatible with DEVFS. # Also, 'options MFS' is currently incompatible with DEVFS.
@ -620,9 +619,13 @@ options DEVFS #devices filesystem
# #
#options SOFTUPDATES #options SOFTUPDATES
# Make space in the kernel for a MFS root filesystem. Define to the number # Make space in the kernel for a root filesystem on a md device.
# of kilobytes to reserve for the filesystem. # Define to the number of kilobytes to reserve for the filesystem.
options MFS_ROOT_SIZE=10 options MD_ROOT_SIZE=10
# Make the md device a potential root device, either with preloaded
# images of type mfs_root or md_root.
options MD_ROOT
# Allow this many swap-devices. # Allow this many swap-devices.
options NSWAPDEV=20 options NSWAPDEV=20

View file

@ -604,7 +604,6 @@ options UNION #Union filesystem
# The xFS_ROOT options REQUIRE the associated ``options xFS'' # The xFS_ROOT options REQUIRE the associated ``options xFS''
options CD9660_ROOT #CD-ROM usable as root device options CD9660_ROOT #CD-ROM usable as root device
options FFS_ROOT #FFS usable as root device options FFS_ROOT #FFS usable as root device
options MFS_ROOT #MFS usable as root device
options NFS_ROOT #NFS usable as root device options NFS_ROOT #NFS usable as root device
# This code is still experimental (e.g. doesn't handle disk slices well). # This code is still experimental (e.g. doesn't handle disk slices well).
# Also, 'options MFS' is currently incompatible with DEVFS. # Also, 'options MFS' is currently incompatible with DEVFS.
@ -620,9 +619,13 @@ options DEVFS #devices filesystem
# #
#options SOFTUPDATES #options SOFTUPDATES
# Make space in the kernel for a MFS root filesystem. Define to the number # Make space in the kernel for a root filesystem on a md device.
# of kilobytes to reserve for the filesystem. # Define to the number of kilobytes to reserve for the filesystem.
options MFS_ROOT_SIZE=10 options MD_ROOT_SIZE=10
# Make the md device a potential root device, either with preloaded
# images of type mfs_root or md_root.
options MD_ROOT
# Allow this many swap-devices. # Allow this many swap-devices.
options NSWAPDEV=20 options NSWAPDEV=20

View file

@ -33,7 +33,7 @@ options INET #InterNETworking
options FFS #Berkeley Fast Filesystem options FFS #Berkeley Fast Filesystem
options FFS_ROOT #FFS usable as root device [keep this!] options FFS_ROOT #FFS usable as root device [keep this!]
options MFS #Memory Filesystem options MFS #Memory Filesystem
options MFS_ROOT #MFS usable as root device, "MFS" req'ed options MD_ROOT #MD is a potential root device
options NFS #Network Filesystem options NFS #Network Filesystem
options NFS_ROOT #NFS usable as root device, "NFS" req'ed options NFS_ROOT #NFS usable as root device, "NFS" req'ed
options MSDOSFS #MSDOS Filesystem options MSDOSFS #MSDOS Filesystem
@ -213,6 +213,7 @@ pseudo-device ppp 1 # Kernel PPP
pseudo-device tun # Packet tunnel. pseudo-device tun # Packet tunnel.
pseudo-device pty # Pseudo-ttys (telnet etc) pseudo-device pty # Pseudo-ttys (telnet etc)
pseudo-device gzip # Exec gzipped a.out's pseudo-device gzip # Exec gzipped a.out's
pseudo-device md # Memory "disks"
# The `bpf' pseudo-device enables the Berkeley Packet Filter. # The `bpf' pseudo-device enables the Berkeley Packet Filter.
# Be aware of the administrative consequences of enabling this! # Be aware of the administrative consequences of enabling this!

View file

@ -197,6 +197,10 @@ vfs_mountroot_try(char *mountfrom)
if ((path[0] != 0) && setrootbyname(path)) if ((path[0] != 0) && setrootbyname(path))
printf("setrootbyname failed\n"); printf("setrootbyname failed\n");
/* If the root device is a type "memory disk", mount RW */
if (devsw(rootdev) && (devsw(rootdev)->d_flags & D_MEMDISK))
mp->mnt_flag &= ~MNT_RDONLY;
strcpy(mp->mnt_stat.f_mntfromname, path); strcpy(mp->mnt_stat.f_mntfromname, path);
error = VFS_MOUNT(mp, NULL, NULL, NULL, curproc); error = VFS_MOUNT(mp, NULL, NULL, NULL, curproc);

View file

@ -197,6 +197,10 @@ vfs_mountroot_try(char *mountfrom)
if ((path[0] != 0) && setrootbyname(path)) if ((path[0] != 0) && setrootbyname(path))
printf("setrootbyname failed\n"); printf("setrootbyname failed\n");
/* If the root device is a type "memory disk", mount RW */
if (devsw(rootdev) && (devsw(rootdev)->d_flags & D_MEMDISK))
mp->mnt_flag &= ~MNT_RDONLY;
strcpy(mp->mnt_stat.f_mntfromname, path); strcpy(mp->mnt_stat.f_mntfromname, path);
error = VFS_MOUNT(mp, NULL, NULL, NULL, curproc); error = VFS_MOUNT(mp, NULL, NULL, NULL, curproc);

View file

@ -151,6 +151,7 @@ typedef void devfs_remove_t __P((dev_t dev));
/* /*
* Flags for d_flags. * Flags for d_flags.
*/ */
#define D_MEMDISK 0x10000 /* memory type disk */
#define D_NAGGED 0x20000 /* nagged about missing make_dev() */ #define D_NAGGED 0x20000 /* nagged about missing make_dev() */
#define D_CANFREE 0x40000 /* can free blocks */ #define D_CANFREE 0x40000 /* can free blocks */
#define D_TRACKCLOSE 0x80000 /* track all closes */ #define D_TRACKCLOSE 0x80000 /* track all closes */

View file

@ -151,6 +151,7 @@ typedef void devfs_remove_t __P((dev_t dev));
/* /*
* Flags for d_flags. * Flags for d_flags.
*/ */
#define D_MEMDISK 0x10000 /* memory type disk */
#define D_NAGGED 0x20000 /* nagged about missing make_dev() */ #define D_NAGGED 0x20000 /* nagged about missing make_dev() */
#define D_CANFREE 0x40000 /* can free blocks */ #define D_CANFREE 0x40000 /* can free blocks */
#define D_TRACKCLOSE 0x80000 /* track all closes */ #define D_TRACKCLOSE 0x80000 /* track all closes */

View file

@ -62,10 +62,6 @@
MALLOC_DEFINE(M_MFSNODE, "MFS node", "MFS vnode private part"); MALLOC_DEFINE(M_MFSNODE, "MFS node", "MFS vnode private part");
#ifdef MFS_ROOT
static caddr_t mfs_rootbase; /* address of mini-root in kernel virtual memory */
static u_long mfs_rootsize; /* size of mini-root in bytes */
#endif
static int mfs_minor; /* used for building internal dev_t */ static int mfs_minor; /* used for building internal dev_t */
@ -78,9 +74,6 @@ static int mfs_start __P((struct mount *mp, int flags, struct proc *p));
static int mfs_statfs __P((struct mount *mp, struct statfs *sbp, static int mfs_statfs __P((struct mount *mp, struct statfs *sbp,
struct proc *p)); struct proc *p));
static int mfs_init __P((struct vfsconf *)); static int mfs_init __P((struct vfsconf *));
#ifdef MFS_ROOT
static void mfs_takeroot __P((void *));
#endif
static struct cdevsw mfs_cdevsw = { static struct cdevsw mfs_cdevsw = {
/* open */ noopen, /* open */ noopen,
@ -119,35 +112,6 @@ static struct vfsops mfs_vfsops = {
VFS_SET(mfs_vfsops, mfs, 0); VFS_SET(mfs_vfsops, mfs, 0);
#ifdef MFS_ROOT
#ifdef MFS_ROOT_SIZE
/* Image was already written into mfs_root */
static u_char mfs_root[MFS_ROOT_SIZE*1024] = "MFS Filesystem goes here";
static u_char end_mfs_root[] __unused = "MFS Filesystem had better STOP here";
#endif
u_char *
mfs_getimage(void)
{
#ifdef MFS_ROOT_SIZE
/* Get it from compiled-in code */
return mfs_root;
#else
caddr_t p;
vm_offset_t *q;
p = preload_search_by_type("mfs_root");
if (!p)
return NULL;
q = (vm_offset_t *)preload_search_info(p, MODINFO_ADDR);
if (!q)
return NULL;
return (u_char *)*q;
#endif
}
#endif /* MFS_ROOT */
/* /*
* mfs_mount * mfs_mount
@ -199,9 +163,6 @@ mfs_mount(mp, path, data, ndp, p)
struct mfs_args args; struct mfs_args args;
struct ufsmount *ump; struct ufsmount *ump;
struct fs *fs; struct fs *fs;
#ifdef MFS_ROOT
u_char *base;
#endif
struct mfsnode *mfsp; struct mfsnode *mfsp;
size_t size; size_t size;
int flags, err; int flags, err;
@ -217,65 +178,8 @@ mfs_mount(mp, path, data, ndp, p)
*** ***
*/ */
#ifdef MFS_ROOT
/* Get it from preload area */
base = mfs_getimage();
if (!base)
panic("No mfs_root image loaded; can't continue!");
fs = (struct fs *)(base + SBOFF);
/* check for valid super block */
if (fs->fs_magic != FS_MAGIC || fs->fs_bsize > MAXBSIZE ||
fs->fs_bsize < sizeof(struct fs)) {
panic("MFS image is invalid!!");
}
mfs_rootbase = base;
mfs_rootsize = fs->fs_fsize * fs->fs_size;
/* remake rootdev, since vfs_mountroot will have it wrong */
rootdev = make_dev(&mfs_cdevsw, mfs_minor,
0, 0, 0, "MFS%d", mfs_minor);
rootdev->si_bsize_phys = DEV_BSIZE;
rootdev->si_iosize_max = DFLTPHYS;
mfs_minor++;
if ((err = bdevvp(rootdev, &rootvp))) {
printf("mfs_mount: can't find rootvp\n");
return (err);
}
/*
* FS specific handling
*/
MALLOC(mfsp, struct mfsnode *, sizeof *mfsp, M_MFSNODE, M_WAITOK);
rootvp->v_data = mfsp;
rootvp->v_op = mfs_vnodeop_p;
rootvp->v_tag = VT_MFS;
mfsp->mfs_baseoff = mfs_rootbase;
mfsp->mfs_size = mfs_rootsize;
mfsp->mfs_vnode = rootvp;
mfsp->mfs_pid = p->p_pid;
mfsp->mfs_active = 1;
bufq_init(&mfsp->buf_queue);
/* MFS wants to be read/write */
mp->mnt_flag &= ~MNT_RDONLY;
/*
* Attempt mount
*/
if( (err = ffs_mountfs(rootvp, mp, p, M_MFSNODE)) != 0 ) {
/* fs specific cleanup (if any)*/
rootvp->v_data = NULL;
FREE(mfsp, M_MFSNODE);
goto error_1;
}
goto dostatfs; /* success*/
#else /* !MFS_ROOT */
/* you loose */ /* you loose */
panic("mfs_mount: mount MFS as root: not configured!"); panic("mfs_mount: mount MFS as root: not configured!");
#endif /* MFS_ROOT */
} }
/* /*
@ -374,9 +278,6 @@ mfs_mount(mp, path, data, ndp, p)
goto error_2; goto error_2;
} }
#ifdef MFS_ROOT
dostatfs:
#endif
/* /*
* Initialize FS stat information in mount struct; uses both * Initialize FS stat information in mount struct; uses both
* mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname * mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname
@ -498,25 +399,3 @@ mfs_init(vfsp)
return (0); return (0);
} }
#ifdef MFS_ROOT
/*
* Just before root is mounted, check to see if we are a candidate
* to supply it. If we have an image available, override the guessed
* defaults.
*/
static void
mfs_takeroot(junk)
void *junk;
{
if (bootverbose)
printf("Considering MFS root f/s...");
if (mfs_getimage()) {
rootdevnames[0] = "mfs:";
printf("preloaded filesystem found.\n");
} else if (bootverbose) {
printf("not found.\n");
}
}
SYSINIT(mfs_root, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, mfs_takeroot, NULL);
#endif