Added '-F file' option of mount_mfs. This allows me to make floppy images

without waiting for my floppy-drive all the time :-)  Might have other
interesting uses too.
This commit is contained in:
Poul-Henning Kamp 1994-10-12 22:04:36 +00:00
parent 2a460312c8
commit 72ab19aeb7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=3550
3 changed files with 59 additions and 8 deletions

View File

@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mkfs.c 8.3 (Berkeley) 2/3/94";
#include <ufs/ufs/dir.h> #include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <sys/disklabel.h> #include <sys/disklabel.h>
#include <sys/file.h>
#include <sys/mman.h>
#ifndef STANDALONE #ifndef STANDALONE
#include <a.out.h> #include <a.out.h>
@ -100,6 +102,7 @@ extern int sbsize; /* superblock size */
extern u_long memleft; /* virtual memory available */ extern u_long memleft; /* virtual memory available */
extern caddr_t membase; /* start address of memory based filesystem */ extern caddr_t membase; /* start address of memory based filesystem */
extern caddr_t malloc(), calloc(); extern caddr_t malloc(), calloc();
extern char * filename;
union { union {
struct fs fs; struct fs fs;
@ -129,7 +132,7 @@ mkfs(pp, fsys, fi, fo)
long used, mincpgcnt, bpcg; long used, mincpgcnt, bpcg;
long mapcramped, inodecramped; long mapcramped, inodecramped;
long postblsize, rotblsize, totalsbsize; long postblsize, rotblsize, totalsbsize;
int ppid, status; int ppid, status, fd;
time_t utime; time_t utime;
quad_t sizepb; quad_t sizepb;
void started(); void started();
@ -151,10 +154,41 @@ mkfs(pp, fsys, fi, fo)
/* NOTREACHED */ /* NOTREACHED */
} }
(void)malloc(0); (void)malloc(0);
if (fssize * sectorsize > memleft) if(filename) {
fssize = (memleft - 16384) / sectorsize; unsigned char buf[BUFSIZ];
if ((membase = malloc(fssize * sectorsize)) == 0) unsigned long l,l1;
exit(12); fd = open(filename,O_RDWR|O_TRUNC|O_CREAT,0644);
if(fd < 0) {
perror(filename);
exit(12);
}
for(l=0;l< fssize * sectorsize;l += l1) {
l1 = fssize * sectorsize;
if (BUFSIZ < l1)
l1 = BUFSIZ;
if (l1 != write(fd,buf,l1)) {
perror(filename);
exit(12);
}
}
membase = mmap(
0,
fssize * sectorsize,
PROT_READ|PROT_WRITE,
MAP_SHARED,
fd,
0);
if((int)membase == -1) {
perror("mmap");
exit(12);
}
close(fd);
} else {
if (fssize * sectorsize > memleft)
fssize = (memleft - 16384) / sectorsize;
if ((membase = malloc(fssize * sectorsize)) == 0)
exit(12);
}
} }
fsi = fi; fsi = fi;
fso = fo; fso = fo;

View File

@ -42,7 +42,7 @@
.Nm newfs .Nm newfs
.Op Fl NO .Op Fl NO
.Op Fl S Ar sector-size .Op Fl S Ar sector-size
.Op Fl a maxcontig .Op Fl a Ar maxcontig
.Op Fl b Ar block-size .Op Fl b Ar block-size
.Op Fl c Ar cylinders .Op Fl c Ar cylinders
.Op Fl d Ar rotdelay .Op Fl d Ar rotdelay
@ -62,7 +62,9 @@
.Ar special .Ar special
.Nm mount_mfs .Nm mount_mfs
.Op Fl N .Op Fl N
.Op Fl a maxcontig .Op Fl F Ar file
.Op Fl T Ar disktype
.Op Fl a Ar maxcontig
.Op Fl b Ar block-size .Op Fl b Ar block-size
.Op Fl c Ar cylinders .Op Fl c Ar cylinders
.Op Fl d Ar rotdelay .Op Fl d Ar rotdelay
@ -116,6 +118,14 @@ the file system has to be paged.
.Pp .Pp
The following options define the general layout policies. The following options define the general layout policies.
.Bl -tag -width Fl .Bl -tag -width Fl
.It Fl T Ar disktype
For backward compatibility and for
.Nm mount_mfs .
.It Fl F Ar file
.Nm mount_mfs
will use this file for the image of the filesystem. When
.Nm mount_mfs
exits, this file will be left behind.
.It Fl N .It Fl N
Causes the file system parameters to be printed out Causes the file system parameters to be printed out
without really creating the file system. without really creating the file system.

View File

@ -180,6 +180,7 @@ int sbsize = SBSIZE; /* superblock size */
int mntflags = MNT_ASYNC; /* flags to be passed to mount */ int mntflags = MNT_ASYNC; /* flags to be passed to mount */
u_long memleft; /* virtual memory available */ u_long memleft; /* virtual memory available */
caddr_t membase; /* start address of memory based filesystem */ caddr_t membase; /* start address of memory based filesystem */
char *filename;
#ifdef COMPAT #ifdef COMPAT
char *disktype; char *disktype;
int unlabeled; int unlabeled;
@ -216,7 +217,7 @@ main(argc, argv)
} }
opstring = mfs ? opstring = mfs ?
"NT:a:b:c:d:e:f:i:m:o:s:" : "NF:T:a:b:c:d:e:f:i:m:o:s:"
"NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:"; "NOS:T:a:b:c:d:e:f:i:k:l:m:n:o:p:r:s:t:u:x:";
while ((ch = getopt(argc, argv, opstring)) != EOF) while ((ch = getopt(argc, argv, opstring)) != EOF)
switch (ch) { switch (ch) {
@ -235,6 +236,9 @@ main(argc, argv)
disktype = optarg; disktype = optarg;
break; break;
#endif #endif
case 'F':
filename = optarg;
break;
case 'a': case 'a':
if ((maxcontig = atoi(optarg)) <= 0) if ((maxcontig = atoi(optarg)) <= 0)
fatal("%s: bad maximum contiguous blocks\n", fatal("%s: bad maximum contiguous blocks\n",
@ -530,6 +534,9 @@ main(argc, argv)
args.size = fssize * sectorsize; args.size = fssize * sectorsize;
if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0) if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0)
fatal("%s: %s", argv[1], strerror(errno)); fatal("%s: %s", argv[1], strerror(errno));
if(filename) {
munmap(membase,fssize * sectorsize);
}
} }
#endif #endif
exit(0); exit(0);