summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1994-10-12 22:04:36 +0000
committerphk <phk@FreeBSD.org>1994-10-12 22:04:36 +0000
commit2718983b3c0ca45e1f935561746c24925db4f69d (patch)
treec46dbc121b78416a2719c48ea20fbb919301a103 /sbin
parent5da143143431c5fc39b10c75c20e03ab613bbc74 (diff)
downloadFreeBSD-src-2718983b3c0ca45e1f935561746c24925db4f69d.zip
FreeBSD-src-2718983b3c0ca45e1f935561746c24925db4f69d.tar.gz
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.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/newfs/mkfs.c44
-rw-r--r--sbin/newfs/newfs.814
-rw-r--r--sbin/newfs/newfs.c9
3 files changed, 59 insertions, 8 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index 398f369..4ca25a2 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -44,6 +44,8 @@ static char sccsid[] = "@(#)mkfs.c 8.3 (Berkeley) 2/3/94";
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#include <sys/disklabel.h>
+#include <sys/file.h>
+#include <sys/mman.h>
#ifndef STANDALONE
#include <a.out.h>
@@ -100,6 +102,7 @@ extern int sbsize; /* superblock size */
extern u_long memleft; /* virtual memory available */
extern caddr_t membase; /* start address of memory based filesystem */
extern caddr_t malloc(), calloc();
+extern char * filename;
union {
struct fs fs;
@@ -129,7 +132,7 @@ mkfs(pp, fsys, fi, fo)
long used, mincpgcnt, bpcg;
long mapcramped, inodecramped;
long postblsize, rotblsize, totalsbsize;
- int ppid, status;
+ int ppid, status, fd;
time_t utime;
quad_t sizepb;
void started();
@@ -151,10 +154,41 @@ mkfs(pp, fsys, fi, fo)
/* NOTREACHED */
}
(void)malloc(0);
- if (fssize * sectorsize > memleft)
- fssize = (memleft - 16384) / sectorsize;
- if ((membase = malloc(fssize * sectorsize)) == 0)
- exit(12);
+ if(filename) {
+ unsigned char buf[BUFSIZ];
+ unsigned long l,l1;
+ 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;
fso = fo;
diff --git a/sbin/newfs/newfs.8 b/sbin/newfs/newfs.8
index 90be62d..e342516 100644
--- a/sbin/newfs/newfs.8
+++ b/sbin/newfs/newfs.8
@@ -42,7 +42,7 @@
.Nm newfs
.Op Fl NO
.Op Fl S Ar sector-size
-.Op Fl a maxcontig
+.Op Fl a Ar maxcontig
.Op Fl b Ar block-size
.Op Fl c Ar cylinders
.Op Fl d Ar rotdelay
@@ -62,7 +62,9 @@
.Ar special
.Nm mount_mfs
.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 c Ar cylinders
.Op Fl d Ar rotdelay
@@ -116,6 +118,14 @@ the file system has to be paged.
.Pp
The following options define the general layout policies.
.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
Causes the file system parameters to be printed out
without really creating the file system.
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c
index c419c30..88ee073 100644
--- a/sbin/newfs/newfs.c
+++ b/sbin/newfs/newfs.c
@@ -180,6 +180,7 @@ int sbsize = SBSIZE; /* superblock size */
int mntflags = MNT_ASYNC; /* flags to be passed to mount */
u_long memleft; /* virtual memory available */
caddr_t membase; /* start address of memory based filesystem */
+char *filename;
#ifdef COMPAT
char *disktype;
int unlabeled;
@@ -216,7 +217,7 @@ main(argc, argv)
}
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:";
while ((ch = getopt(argc, argv, opstring)) != EOF)
switch (ch) {
@@ -235,6 +236,9 @@ main(argc, argv)
disktype = optarg;
break;
#endif
+ case 'F':
+ filename = optarg;
+ break;
case 'a':
if ((maxcontig = atoi(optarg)) <= 0)
fatal("%s: bad maximum contiguous blocks\n",
@@ -530,6 +534,9 @@ main(argc, argv)
args.size = fssize * sectorsize;
if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0)
fatal("%s: %s", argv[1], strerror(errno));
+ if(filename) {
+ munmap(membase,fssize * sectorsize);
+ }
}
#endif
exit(0);
OpenPOWER on IntegriCloud