diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 398f36961f60..4ca25a23f495 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 #include #include +#include +#include #ifndef STANDALONE #include @@ -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 90be62daca7b..e342516bc048 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 c419c302624f..88ee0736c1a5 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);