A more complete removal of MFS related code.

XXX: This program badly needs a style(9) + BDECFLAGS treatment.
This commit is contained in:
Poul-Henning Kamp 2001-05-29 19:40:39 +00:00
parent fb54ac9dc8
commit 80f86e526b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=77420
3 changed files with 59 additions and 312 deletions

View File

@ -6,7 +6,7 @@ SRCS= getmntopts.c newfs.c mkfs.c
MAN= newfs.8
MOUNT= ${.CURDIR}/../mount
CFLAGS+=-DMFS -DFSIRAND -I${MOUNT}
CFLAGS+=-DMFS -DFSIRAND -I${MOUNT} ${BDECFLAGS}
.PATH: ${MOUNT}
LINKS= ${BINDIR}/newfs

View File

@ -90,9 +90,6 @@ extern void srandomdev __P((void));
/*
* variables set up by front end.
*/
extern int mfs; /* run as the memory based filesystem */
extern char *mfs_mtpt; /* mount point for mfs */
extern struct stat mfs_mtstat; /* stat prior to mount */
extern int Nflag; /* run mkfs without writing file system */
extern int Oflag; /* format as an 4.3BSD file system */
extern int Uflag; /* enable soft updates for file system */
@ -159,8 +156,6 @@ void wtfs __P((daddr_t, int, char *));
void wtfsflush __P((void));
#ifndef STANDALONE
void get_memleft __P((void));
void raise_data_limit __P((void));
#else
void free __P((char *));
char * calloc __P((u_long, u_long));
@ -168,8 +163,6 @@ caddr_t malloc __P((u_long));
caddr_t realloc __P((char *, u_long));
#endif
int mfs_ppid = 0;
void
mkfs(pp, fsys, fi, fo)
struct partition *pp;
@ -182,10 +175,8 @@ mkfs(pp, fsys, fi, fo)
off_t usedb;
long mapcramped, inodecramped;
long postblsize, rotblsize, totalsbsize;
int status, fd;
time_t utime;
quad_t sizepb;
void started();
int width;
char tmpbuf[100]; /* XXX this will break in about 2,500 years */
@ -198,55 +189,6 @@ mkfs(pp, fsys, fi, fo)
srandomdev();
}
#endif
if (mfs) {
mfs_ppid = getpid();
(void) signal(SIGUSR1, started);
if ((i = fork())) {
if (i == -1)
err(10, "mfs");
if (waitpid(i, &status, 0) != -1 && WIFEXITED(status))
exit(WEXITSTATUS(status));
exit(11);
/* NOTREACHED */
}
#ifdef STANDALONE
(void)malloc(0);
#else
raise_data_limit();
#endif
if(filename) {
unsigned char buf[BUFSIZ];
unsigned long l,l1;
fd = open(filename,O_RDWR|O_TRUNC|O_CREAT,0644);
if(fd < 0)
err(12, "%s", filename);
for(l=0;l< fssize * sectorsize;l += l1) {
l1 = fssize * sectorsize;
if (BUFSIZ < l1)
l1 = BUFSIZ;
if (l1 != write(fd,buf,l1))
err(12, "%s", filename);
}
membase = mmap(
0,
fssize * sectorsize,
PROT_READ|PROT_WRITE,
MAP_SHARED,
fd,
0);
if(membase == MAP_FAILED)
err(12, "mmap");
close(fd);
} else {
#ifndef STANDALONE
get_memleft();
#endif
if (fssize * sectorsize > (memleft - 131072))
fssize = (memleft - 131072) / sectorsize;
if ((membase = malloc(fssize * sectorsize)) == NULL)
errx(13, "malloc failed");
}
}
fsi = fi;
fso = fo;
if (Oflag) {
@ -637,7 +579,7 @@ mkfs(pp, fsys, fi, fo)
NSPF(&sblock);
warn = 0;
}
if (warn && !mfs) {
if (warn) {
printf("Warning: %d sector(s) in last cylinder unallocated\n",
sblock.fs_spc -
(fssize * NSPF(&sblock) - (sblock.fs_ncyl - 1)
@ -684,32 +626,27 @@ mkfs(pp, fsys, fi, fo)
/*
* Dump out summary information about file system.
*/
if (!mfs) {
printf("%s:\t%d sectors in %d %s of %d tracks, %d sectors\n",
fsys, sblock.fs_size * NSPF(&sblock), sblock.fs_ncyl,
"cylinders", sblock.fs_ntrak, sblock.fs_nsect);
printf("%s:\t%d sectors in %d %s of %d tracks, %d sectors\n",
fsys, sblock.fs_size * NSPF(&sblock), sblock.fs_ncyl,
"cylinders", sblock.fs_ntrak, sblock.fs_nsect);
#define B2MBFACTOR (1 / (1024.0 * 1024.0))
printf(
"\t%.1fMB in %d cyl groups (%d c/g, %.2fMB/g, %d i/g)%s\n",
(float)sblock.fs_size * sblock.fs_fsize * B2MBFACTOR,
sblock.fs_ncg, sblock.fs_cpg,
(float)sblock.fs_fpg * sblock.fs_fsize * B2MBFACTOR,
sblock.fs_ipg,
sblock.fs_flags & FS_DOSOFTDEP ? " SOFTUPDATES" : "");
printf(
"\t%.1fMB in %d cyl groups (%d c/g, %.2fMB/g, %d i/g)%s\n",
(float)sblock.fs_size * sblock.fs_fsize * B2MBFACTOR,
sblock.fs_ncg, sblock.fs_cpg,
(float)sblock.fs_fpg * sblock.fs_fsize * B2MBFACTOR,
sblock.fs_ipg,
sblock.fs_flags & FS_DOSOFTDEP ? " SOFTUPDATES" : "");
#undef B2MBFACTOR
}
/*
* Now build the cylinders group blocks and
* then print out indices of cylinder groups.
*/
if (!mfs)
printf("super-block backups (for fsck -b #) at:\n");
printf("super-block backups (for fsck -b #) at:\n");
i = 0;
width = charsperline();
for (cylno = 0; cylno < sblock.fs_ncg; cylno++) {
initcg(cylno, utime);
if (mfs)
continue;
j = snprintf(tmpbuf, sizeof(tmpbuf), " %ld%s",
fsbtodb(&sblock, cgsblock(&sblock, cylno)),
cylno < (sblock.fs_ncg-1) ? "," : "" );
@ -721,9 +658,8 @@ mkfs(pp, fsys, fi, fo)
printf("%s", tmpbuf);
fflush(stdout);
}
if (!mfs)
printf("\n");
if (Nflag && !mfs)
printf("\n");
if (Nflag)
exit(0);
/*
* Now construct the initial file system,
@ -752,18 +688,6 @@ mkfs(pp, fsys, fi, fo)
pp->p_fsize = sblock.fs_fsize;
pp->p_frag = sblock.fs_frag;
pp->p_cpg = sblock.fs_cpg;
/*
* Notify parent process of success.
* Dissociate from session and tty.
*/
if (mfs) {
kill(mfs_ppid, SIGUSR1);
(void) setsid();
(void) close(0);
(void) close(1);
(void) close(2);
(void) chdir("/");
}
}
/*
@ -1009,10 +933,7 @@ fsinit(utime)
/*
* create the root directory
*/
if (mfs)
node.di_mode = IFDIR | 01777;
else
node.di_mode = IFDIR | UMASK;
node.di_mode = IFDIR | UMASK;
node.di_nlink = PREDEFDIR;
if (Oflag)
node.di_size = makedir((struct direct *)oroot_dir, PREDEFDIR);
@ -1178,34 +1099,6 @@ iput(ip, ino)
wtfs(d, sblock.fs_bsize, (char *)buf);
}
/*
* Notify parent process that the filesystem has created itself successfully.
*
* We have to wait until the mount has actually completed!
*/
void
started()
{
int retry = 100; /* 10 seconds, 100ms */
while (mfs_ppid && retry) {
struct stat st;
if (
stat(mfs_mtpt, &st) < 0 ||
st.st_dev != mfs_mtstat.st_dev
) {
break;
}
usleep(100*1000);
--retry;
}
if (retry == 0) {
fatal("mfs mount failed waiting for mount to go active");
}
exit(0);
}
#ifdef STANDALONE
/*
* Replace libc function with one suited to our needs.
@ -1285,18 +1178,6 @@ free(ptr)
#else /* !STANDALONE */
void
raise_data_limit()
{
struct rlimit rlp;
if (getrlimit(RLIMIT_DATA, &rlp) < 0)
warn("getrlimit");
rlp.rlim_cur = rlp.rlim_max;
if (setrlimit(RLIMIT_DATA, &rlp) < 0)
warn("setrlimit");
}
#ifdef __ELF__
extern char *_etext;
#define etext _etext
@ -1304,23 +1185,6 @@ extern char *_etext;
extern char *etext;
#endif
void
get_memleft()
{
static u_long pgsz;
struct rlimit rlp;
u_long freestart;
u_long dstart;
u_long memused;
pgsz = getpagesize() - 1;
dstart = ((u_long)&etext) &~ pgsz;
freestart = ((u_long)(sbrk(0) + pgsz) &~ pgsz);
if (getrlimit(RLIMIT_DATA, &rlp) < 0)
warn("getrlimit");
memused = freestart - dstart;
memleft = rlp.rlim_cur - memused;
}
#endif /* STANDALONE */
/*
@ -1335,10 +1199,6 @@ rdfs(bno, size, bf)
int n;
wtfsflush();
if (mfs) {
memmove(bf, membase + bno * sectorsize, size);
return;
}
if (lseek(fsi, (off_t)bno * sectorsize, 0) < 0) {
printf("seek error: %ld\n", (long)bno);
err(33, "rdfs");
@ -1388,10 +1248,6 @@ wtfs(bno, size, bf)
int n;
int done;
if (mfs) {
memmove(membase + bno * sectorsize, bf, size);
return;
}
if (Nflag)
return;
done = 0;

View File

@ -69,11 +69,6 @@ static const char rcsid[] =
#include <syslog.h>
#include <unistd.h>
#ifdef MFS
#include <sys/types.h>
#include <sys/mman.h>
#endif
#if __STDC__
#include <stdarg.h>
#else
@ -166,9 +161,6 @@ void fatal();
#define NTRACKS 1 /* number of heads */
#define NSECTORS 4096 /* number of sectors */
int mfs; /* run as the memory based filesystem */
char *mfs_mtpt; /* mount point for mfs */
struct stat mfs_mtstat; /* stat prior to mount */
int Nflag; /* run without writing file system */
int Oflag; /* format as an 4.3BSD file system */
int Uflag; /* enable soft updates for file system */
@ -216,6 +208,7 @@ char *progname;
extern void mkfs __P((struct partition *, char *, int, int));
static void usage __P((void));
static void rewritelabel __P((char *s, int fd, register struct disklabel *lp));
int
main(argc, argv)
@ -225,18 +218,12 @@ main(argc, argv)
register int ch;
register struct partition *pp;
register struct disklabel *lp;
struct disklabel mfsfakelabel;
struct disklabel *getdisklabel();
struct partition oldpartition;
struct stat st;
struct statfs *mp;
int fsi, fso, len, n, vflag;
char *cp, *s1, *s2, *special, *opstring;
#ifdef MFS
struct vfsconf vfc;
int error;
char buf[BUFSIZ];
#endif
vflag = 0;
if ((progname = strrchr(*argv, '/')))
@ -244,18 +231,7 @@ main(argc, argv)
else
progname = *argv;
if (strstr(progname, "mfs")) {
mfs = 1;
Nflag++;
fprintf(stderr,
"WARNING: MFS is being phased out in preference for md devices\n"
"WARNING: Please see mdconfig(8) for details\n");
exit(1);
}
opstring = mfs ?
"NF:T:Ua:b:c:d:e:f:g:h:i:m:o:s:" :
"NOS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:";
opstring = "NOS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:";
while ((ch = getopt(argc, argv, opstring)) != -1)
switch (ch) {
case 'N':
@ -338,16 +314,12 @@ main(argc, argv)
nrpos = 1;
break;
case 'o':
if (mfs)
getmntopts(optarg, mopts, &mntflags, 0);
else {
if (strcmp(optarg, "space") == 0)
opt = FS_OPTSPACE;
else if (strcmp(optarg, "time") == 0)
opt = FS_OPTTIME;
else
if (strcmp(optarg, "space") == 0)
opt = FS_OPTSPACE;
else if (strcmp(optarg, "time") == 0)
opt = FS_OPTTIME;
else
fatal("%s: unknown optimization preference: use `space' or `time'", optarg);
}
break;
case 'p':
if ((trackspares = atoi(optarg)) < 0)
@ -387,39 +359,10 @@ main(argc, argv)
argc -= optind;
argv += optind;
if (argc != 2 && (mfs || argc != 1))
if (argc != 2 && argc != 1)
usage();
special = argv[0];
/* Copy the NetBSD way of faking up a disk label */
if (mfs && !strcmp(special, "swap")) {
/*
* it's an MFS, mounted on "swap." fake up a label.
* XXX XXX XXX
*/
fso = -1; /* XXX; normally done below. */
memset(&mfsfakelabel, 0, sizeof(mfsfakelabel));
mfsfakelabel.d_secsize = 512;
mfsfakelabel.d_nsectors = 64;
mfsfakelabel.d_ntracks = 16;
mfsfakelabel.d_ncylinders = 16;
mfsfakelabel.d_secpercyl = 1024;
mfsfakelabel.d_secperunit = 16384;
mfsfakelabel.d_rpm = 3600;
mfsfakelabel.d_interleave = 1;
mfsfakelabel.d_npartitions = 1;
mfsfakelabel.d_partitions[0].p_size = 16384;
mfsfakelabel.d_partitions[0].p_fsize = 1024;
mfsfakelabel.d_partitions[0].p_frag = 8;
mfsfakelabel.d_partitions[0].p_cpg = 16;
lp = &mfsfakelabel;
pp = &mfsfakelabel.d_partitions[0];
goto havelabel;
}
cp = strrchr(special, '/');
if (cp == 0) {
/*
@ -457,47 +400,39 @@ main(argc, argv)
++mp;
}
}
if (mfs && disktype != NULL) {
lp = (struct disklabel *)getdiskbyname(disktype);
if (lp == NULL)
fatal("%s: unknown disk type", disktype);
pp = &lp->d_partitions[1];
} else {
fsi = open(special, O_RDONLY);
if (fsi < 0)
fatal("%s: %s", special, strerror(errno));
if (fstat(fsi, &st) < 0)
fatal("%s: %s", special, strerror(errno));
if ((st.st_mode & S_IFMT) != S_IFCHR && !mfs)
printf("%s: %s: not a character-special device\n",
progname, special);
cp = strchr(argv[0], '\0');
if (cp == argv[0])
fatal("null special file name");
cp--;
if (!vflag && (*cp < 'a' || *cp > 'h') && !isdigit(*cp))
fatal("%s: can't figure out file system partition",
argv[0]);
fsi = open(special, O_RDONLY);
if (fsi < 0)
fatal("%s: %s", special, strerror(errno));
if (fstat(fsi, &st) < 0)
fatal("%s: %s", special, strerror(errno));
if ((st.st_mode & S_IFMT) != S_IFCHR)
printf("%s: %s: not a character-special device\n",
progname, special);
cp = strchr(argv[0], '\0');
if (cp == argv[0])
fatal("null special file name");
cp--;
if (!vflag && (*cp < 'a' || *cp > 'h') && !isdigit(*cp))
fatal("%s: can't figure out file system partition",
argv[0]);
#ifdef COMPAT
if (!mfs && disktype == NULL)
disktype = argv[1];
if (disktype == NULL)
disktype = argv[1];
#endif
lp = getdisklabel(special, fsi);
if (vflag || isdigit(*cp))
pp = &lp->d_partitions[0];
else
pp = &lp->d_partitions[*cp - 'a'];
if (pp->p_size == 0)
fatal("%s: `%c' partition is unavailable",
argv[0], *cp);
if (pp->p_fstype == FS_BOOT)
fatal("%s: `%c' partition overlaps boot program",
argv[0], *cp);
}
havelabel:
lp = getdisklabel(special, fsi);
if (vflag || isdigit(*cp))
pp = &lp->d_partitions[0];
else
pp = &lp->d_partitions[*cp - 'a'];
if (pp->p_size == 0)
fatal("%s: `%c' partition is unavailable",
argv[0], *cp);
if (pp->p_fstype == FS_BOOT)
fatal("%s: `%c' partition overlaps boot program",
argv[0], *cp);
if (fssize == 0)
fssize = pp->p_size;
if (fssize > pp->p_size && !mfs)
if (fssize > pp->p_size)
fatal("%s: maximum file system size on the `%c' partition is %d",
argv[0], *cp, pp->p_size);
if (rpm == 0) {
@ -610,15 +545,6 @@ main(argc, argv)
pp->p_size *= secperblk;
}
#endif
if (mfs) {
mfs_mtpt = argv[1];
if (
stat(mfs_mtpt, &mfs_mtstat) < 0 ||
!S_ISDIR(mfs_mtstat.st_mode)
) {
fatal("mount point not dir: %s", mfs_mtpt);
}
}
mkfs(pp, special, fsi, fso);
#ifdef tahoe
if (realsectorsize != DEV_BSIZE)
@ -632,37 +558,6 @@ main(argc, argv)
if (!Nflag)
close(fso);
close(fsi);
#ifdef MFS
if (mfs) {
struct mfs_args args;
snprintf(buf, sizeof(buf), "mfs:%d", getpid());
args.fspec = buf;
args.export.ex_root = -2;
if (mntflags & MNT_RDONLY)
args.export.ex_flags = MNT_EXRDONLY;
else
args.export.ex_flags = 0;
args.base = membase;
args.size = fssize * sectorsize;
error = getvfsbyname("mfs", &vfc);
if (error && vfsisloadable("mfs")) {
if (vfsload("mfs"))
fatal("vfsload(mfs)");
endvfsent(); /* flush cache */
error = getvfsbyname("mfs", &vfc);
}
if (error)
fatal("mfs filesystem not available");
if (mount(vfc.vfc_name, argv[1], mntflags, &args) < 0)
fatal("%s: %s", argv[1], strerror(errno));
if(filename) {
munmap(membase,fssize * sectorsize);
}
}
#endif
exit(0);
}
@ -697,6 +592,7 @@ getdisklabel(s, fd)
return (&lab);
}
void
rewritelabel(s, fd, lp)
char *s;
int fd;
@ -746,18 +642,13 @@ fatal(fmt, va_alist)
static void
usage()
{
if (mfs) {
fprintf(stderr,
"usage: %s [ -fsoptions ] special-device mount-point\n",
progname);
} else
fprintf(stderr,
"usage: %s [ -fsoptions ] special-device%s\n",
progname,
fprintf(stderr,
"usage: %s [ -fsoptions ] special-device%s\n",
progname,
#ifdef COMPAT
" [device-type]");
" [device-type]");
#else
"");
"");
#endif
fprintf(stderr, "where fsoptions are:\n");
fprintf(stderr,