Add prototypes. Check malloc() return value. Use err(). Remove unused #includes

Do not \n nor dot terminate syslog()/err() messages. -Wall.
This commit is contained in:
Philippe Charnier 1998-07-15 06:28:05 +00:00
parent 7485340223
commit 27750b35a5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=37664
3 changed files with 141 additions and 94 deletions

View File

@ -32,12 +32,21 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95"; static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include <err.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <ufs/ufs/dinode.h> #include <ufs/ufs/dinode.h>
@ -49,9 +58,15 @@ static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#include <sys/ioctl.h> #include <sys/ioctl.h>
#ifndef STANDALONE #ifndef STANDALONE
#include <a.out.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#else
extern int atoi __P((char *));
extern char * getenv __P((char *));
#endif
#ifdef FSIRAND
extern long random __P((void));
extern void srandomdev __P((void));
#endif #endif
/* /*
@ -102,9 +117,6 @@ extern int bbsize; /* boot block size */
extern int sbsize; /* superblock size */ 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 */
#ifdef STANDALONE
extern caddr_t malloc(), calloc();
#endif
extern char * filename; extern char * filename;
union { union {
@ -129,7 +141,27 @@ int randinit;
daddr_t alloc(); daddr_t alloc();
long calcipg(); long calcipg();
static int charsperline(); static int charsperline();
void clrblock __P((struct fs *, unsigned char *, int));
void fsinit __P((time_t));
void initcg __P((int, time_t));
int isblock __P((struct fs *, unsigned char *, int));
void iput __P((struct dinode *, ino_t));
int makedir __P((struct direct *, int));
void rdfs __P((daddr_t, int, char *));
void setblock __P((struct fs *, unsigned char *, int));
void wtfs __P((daddr_t, int, char *));
#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));
caddr_t malloc __P((u_long));
caddr_t realloc __P((char *, u_long));
#endif
void
mkfs(pp, fsys, fi, fo) mkfs(pp, fsys, fi, fo)
struct partition *pp; struct partition *pp;
char *fsys; char *fsys;
@ -141,7 +173,7 @@ mkfs(pp, fsys, fi, fo)
off_t usedb; off_t usedb;
long mapcramped, inodecramped; long mapcramped, inodecramped;
long postblsize, rotblsize, totalsbsize; long postblsize, rotblsize, totalsbsize;
int ppid, status, fd; int ppid = 0, status, fd;
time_t utime; time_t utime;
quad_t sizepb; quad_t sizepb;
void started(); void started();
@ -160,11 +192,9 @@ mkfs(pp, fsys, fi, fo)
if (mfs) { if (mfs) {
ppid = getpid(); ppid = getpid();
(void) signal(SIGUSR1, started); (void) signal(SIGUSR1, started);
if (i = fork()) { if ((i = fork())) {
if (i == -1) { if (i == -1)
perror("mfs"); err(10, "mfs");
exit(10);
}
if (waitpid(i, &status, 0) != -1 && WIFEXITED(status)) if (waitpid(i, &status, 0) != -1 && WIFEXITED(status))
exit(WEXITSTATUS(status)); exit(WEXITSTATUS(status));
exit(11); exit(11);
@ -179,18 +209,14 @@ mkfs(pp, fsys, fi, fo)
unsigned char buf[BUFSIZ]; unsigned char buf[BUFSIZ];
unsigned long l,l1; unsigned long l,l1;
fd = open(filename,O_RDWR|O_TRUNC|O_CREAT,0644); fd = open(filename,O_RDWR|O_TRUNC|O_CREAT,0644);
if(fd < 0) { if(fd < 0)
perror(filename); err(12, "%s", filename);
exit(12);
}
for(l=0;l< fssize * sectorsize;l += l1) { for(l=0;l< fssize * sectorsize;l += l1) {
l1 = fssize * sectorsize; l1 = fssize * sectorsize;
if (BUFSIZ < l1) if (BUFSIZ < l1)
l1 = BUFSIZ; l1 = BUFSIZ;
if (l1 != write(fd,buf,l1)) { if (l1 != write(fd,buf,l1))
perror(filename); err(12, "%s", filename);
exit(12);
}
} }
membase = mmap( membase = mmap(
0, 0,
@ -199,10 +225,8 @@ mkfs(pp, fsys, fi, fo)
MAP_SHARED, MAP_SHARED,
fd, fd,
0); 0);
if(membase == MAP_FAILED) { if(membase == MAP_FAILED)
perror("mmap"); err(12, "mmap");
exit(12);
}
close(fd); close(fd);
} else { } else {
#ifndef STANDALONE #ifndef STANDALONE
@ -210,10 +234,8 @@ mkfs(pp, fsys, fi, fo)
#endif #endif
if (fssize * sectorsize > (memleft - 131072)) if (fssize * sectorsize > (memleft - 131072))
fssize = (memleft - 131072) / sectorsize; fssize = (memleft - 131072) / sectorsize;
if ((membase = malloc(fssize * sectorsize)) == NULL) { if ((membase = malloc(fssize * sectorsize)) == NULL)
perror("malloc"); errx(13, "malloc failed");
exit(13);
}
} }
} }
fsi = fi; fsi = fi;
@ -610,10 +632,8 @@ mkfs(pp, fsys, fi, fo)
for (sblock.fs_csshift = 0; i > 1; i >>= 1) for (sblock.fs_csshift = 0; i > 1; i >>= 1)
sblock.fs_csshift++; sblock.fs_csshift++;
fscs = (struct csum *)calloc(1, sblock.fs_cssize); fscs = (struct csum *)calloc(1, sblock.fs_cssize);
if (fscs == NULL) { if (fscs == NULL)
perror("calloc"); errx(31, "calloc failed");
exit(31);
}
sblock.fs_magic = FS_MAGIC; sblock.fs_magic = FS_MAGIC;
sblock.fs_rotdelay = rotdelay; sblock.fs_rotdelay = rotdelay;
sblock.fs_minfree = minfree; sblock.fs_minfree = minfree;
@ -718,13 +738,17 @@ mkfs(pp, fsys, fi, fo)
/* /*
* Initialize a cylinder group. * Initialize a cylinder group.
*/ */
void
initcg(cylno, utime) initcg(cylno, utime)
int cylno; int cylno;
time_t utime; time_t utime;
{ {
daddr_t cbase, d, dlower, dupper, dmax, blkno; daddr_t cbase, d, dlower, dupper, dmax, blkno;
long i, j, s; long i;
register struct csum *cs; register struct csum *cs;
#ifdef FSIRAND
long j;
#endif
/* /*
* Determine block bounds for cylinder group. * Determine block bounds for cylinder group.
@ -807,7 +831,7 @@ initcg(cylno, utime)
sblock.fs_dsize += dlower; sblock.fs_dsize += dlower;
} }
sblock.fs_dsize += acg.cg_ndblk - dupper; sblock.fs_dsize += acg.cg_ndblk - dupper;
if (i = dupper % sblock.fs_frag) { if ((i = dupper % sblock.fs_frag)) {
acg.cg_frsum[sblock.fs_frag - i]++; acg.cg_frsum[sblock.fs_frag - i]++;
for (d = dupper + sblock.fs_frag - i; dupper < d; dupper++) { for (d = dupper + sblock.fs_frag - i; dupper < d; dupper++) {
setbit(cg_blksfree(&acg), dupper); setbit(cg_blksfree(&acg), dupper);
@ -914,10 +938,13 @@ struct odirect olost_found_dir[] = {
#endif #endif
char buf[MAXBSIZE]; char buf[MAXBSIZE];
void
fsinit(utime) fsinit(utime)
time_t utime; time_t utime;
{ {
#ifdef LOSTDIR
int i; int i;
#endif
/* /*
* initialize the node * initialize the node
@ -970,6 +997,7 @@ fsinit(utime)
* construct a set of directory entries in "buf". * construct a set of directory entries in "buf".
* return size of directory. * return size of directory.
*/ */
int
makedir(protodir, entries) makedir(protodir, entries)
register struct direct *protodir; register struct direct *protodir;
int entries; int entries;
@ -1084,6 +1112,7 @@ calcipg(cpg, bpcg, usedbp)
/* /*
* Allocate an inode on the disk * Allocate an inode on the disk
*/ */
void
iput(ip, ino) iput(ip, ino)
register struct dinode *ip; register struct dinode *ip;
register ino_t ino; register ino_t ino;
@ -1113,9 +1142,9 @@ iput(ip, ino)
exit(32); exit(32);
} }
d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino)); d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino));
rdfs(d, sblock.fs_bsize, buf); rdfs(d, sblock.fs_bsize, (char *)buf);
buf[ino_to_fsbo(&sblock, ino)] = *ip; buf[ino_to_fsbo(&sblock, ino)] = *ip;
wtfs(d, sblock.fs_bsize, buf); wtfs(d, sblock.fs_bsize, (char *)buf);
} }
/* /*
@ -1146,10 +1175,10 @@ malloc(size)
i = (char *)((u_long)(base + pgsz) &~ pgsz); i = (char *)((u_long)(base + pgsz) &~ pgsz);
base = sbrk(i - base); base = sbrk(i - base);
if (getrlimit(RLIMIT_DATA, &rlp) < 0) if (getrlimit(RLIMIT_DATA, &rlp) < 0)
perror("getrlimit"); warn("getrlimit");
rlp.rlim_cur = rlp.rlim_max; rlp.rlim_cur = rlp.rlim_max;
if (setrlimit(RLIMIT_DATA, &rlp) < 0) if (setrlimit(RLIMIT_DATA, &rlp) < 0)
perror("setrlimit"); warn("setrlimit");
memleft = rlp.rlim_max - (u_long)base; memleft = rlp.rlim_max - (u_long)base;
} }
size = (size + pgsz) &~ pgsz; size = (size + pgsz) &~ pgsz;
@ -1188,7 +1217,8 @@ calloc(size, numelm)
caddr_t base; caddr_t base;
size *= numelm; size *= numelm;
base = malloc(size); if ((base = malloc(size)) == NULL);
return (NULL);
memset(base, 0, size); memset(base, 0, size);
return (base); return (base);
} }
@ -1196,6 +1226,7 @@ calloc(size, numelm)
/* /*
* Replace libc function with one suited to our needs. * Replace libc function with one suited to our needs.
*/ */
void
free(ptr) free(ptr)
char *ptr; char *ptr;
{ {
@ -1205,15 +1236,16 @@ free(ptr)
#else /* !STANDALONE */ #else /* !STANDALONE */
void
raise_data_limit() raise_data_limit()
{ {
struct rlimit rlp; struct rlimit rlp;
if (getrlimit(RLIMIT_DATA, &rlp) < 0) if (getrlimit(RLIMIT_DATA, &rlp) < 0)
perror("getrlimit"); warn("getrlimit");
rlp.rlim_cur = rlp.rlim_max; rlp.rlim_cur = rlp.rlim_max;
if (setrlimit(RLIMIT_DATA, &rlp) < 0) if (setrlimit(RLIMIT_DATA, &rlp) < 0)
perror("setrlimit"); warn("setrlimit");
} }
#ifdef __ELF__ #ifdef __ELF__
@ -1223,6 +1255,7 @@ extern char *_etext;
extern char *etext; extern char *etext;
#endif #endif
void
get_memleft() get_memleft()
{ {
static u_long pgsz; static u_long pgsz;
@ -1235,7 +1268,7 @@ get_memleft()
dstart = ((u_long)&etext) &~ pgsz; dstart = ((u_long)&etext) &~ pgsz;
freestart = ((u_long)(sbrk(0) + pgsz) &~ pgsz); freestart = ((u_long)(sbrk(0) + pgsz) &~ pgsz);
if (getrlimit(RLIMIT_DATA, &rlp) < 0) if (getrlimit(RLIMIT_DATA, &rlp) < 0)
perror("getrlimit"); warn("getrlimit");
memused = freestart - dstart; memused = freestart - dstart;
memleft = rlp.rlim_cur - memused; memleft = rlp.rlim_cur - memused;
} }
@ -1244,6 +1277,7 @@ get_memleft()
/* /*
* read a block from the file system * read a block from the file system
*/ */
void
rdfs(bno, size, bf) rdfs(bno, size, bf)
daddr_t bno; daddr_t bno;
int size; int size;
@ -1257,20 +1291,19 @@ rdfs(bno, size, bf)
} }
if (lseek(fsi, (off_t)bno * sectorsize, 0) < 0) { if (lseek(fsi, (off_t)bno * sectorsize, 0) < 0) {
printf("seek error: %ld\n", (long)bno); printf("seek error: %ld\n", (long)bno);
perror("rdfs"); err(33, "rdfs");
exit(33);
} }
n = read(fsi, bf, size); n = read(fsi, bf, size);
if (n != size) { if (n != size) {
printf("read error: %ld\n", (long)bno); printf("read error: %ld\n", (long)bno);
perror("rdfs"); err(34, "rdfs");
exit(34);
} }
} }
/* /*
* write a block to the file system * write a block to the file system
*/ */
void
wtfs(bno, size, bf) wtfs(bno, size, bf)
daddr_t bno; daddr_t bno;
int size; int size;
@ -1286,20 +1319,19 @@ wtfs(bno, size, bf)
return; return;
if (lseek(fso, (off_t)bno * sectorsize, SEEK_SET) < 0) { if (lseek(fso, (off_t)bno * sectorsize, SEEK_SET) < 0) {
printf("seek error: %ld\n", (long)bno); printf("seek error: %ld\n", (long)bno);
perror("wtfs"); err(35, "wtfs");
exit(35);
} }
n = write(fso, bf, size); n = write(fso, bf, size);
if (n != size) { if (n != size) {
printf("write error: %ld\n", (long)bno); printf("write error: %ld\n", (long)bno);
perror("wtfs"); err(36, "wtfs");
exit(36);
} }
} }
/* /*
* check if a block is available * check if a block is available
*/ */
int
isblock(fs, cp, h) isblock(fs, cp, h)
struct fs *fs; struct fs *fs;
unsigned char *cp; unsigned char *cp;
@ -1332,6 +1364,7 @@ isblock(fs, cp, h)
/* /*
* take a block out of the map * take a block out of the map
*/ */
void
clrblock(fs, cp, h) clrblock(fs, cp, h)
struct fs *fs; struct fs *fs;
unsigned char *cp; unsigned char *cp;
@ -1363,6 +1396,7 @@ clrblock(fs, cp, h)
/* /*
* put a block into the map * put a block into the map
*/ */
void
setblock(fs, cp, h) setblock(fs, cp, h)
struct fs *fs; struct fs *fs;
unsigned char *cp; unsigned char *cp;
@ -1402,7 +1436,6 @@ charsperline()
int columns; int columns;
char *cp; char *cp;
struct winsize ws; struct winsize ws;
extern char *getenv();
columns = 0; columns = 0;
if (ioctl(0, TIOCGWINSZ, &ws) != -1) if (ioctl(0, TIOCGWINSZ, &ws) != -1)

View File

@ -30,6 +30,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" @(#)newfs.8 8.6 (Berkeley) 5/3/95 .\" @(#)newfs.8 8.6 (Berkeley) 5/3/95
.\" $Id$
.\" .\"
.Dd May 3, 1995 .Dd May 3, 1995
.Dt NEWFS 8 .Dt NEWFS 8
@ -84,7 +85,7 @@ replaces the more obtuse
.Xr mkfs 8 .Xr mkfs 8
program. program.
Before running Before running
.Nm newfs .Nm
or or
.Nm mount_mfs , .Nm mount_mfs ,
the disk must be labeled using the disk must be labeled using
@ -92,7 +93,7 @@ the disk must be labeled using
.Nm Newfs .Nm Newfs
builds a file system on the specified special device. builds a file system on the specified special device.
Typically the defaults are reasonable, however Typically the defaults are reasonable, however
.Nm newfs .Nm
has numerous options to allow the defaults to be selectively overridden. has numerous options to allow the defaults to be selectively overridden.
.Pp .Pp
.Nm Mount_mfs .Nm Mount_mfs
@ -110,7 +111,7 @@ corresponding file system.
The parameters to The parameters to
.Nm mount_mfs .Nm mount_mfs
are the same as those to are the same as those to
.Nm newfs . .Nm Ns .
If the If the
.Fl T .Fl T
flag is specified (see below), the special file is unused. flag is specified (see below), the special file is unused.
@ -121,33 +122,35 @@ since that is where the file system will be backed up when
free memory gets low and the memory supporting free memory gets low and the memory supporting
the file system has to be paged. 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 indent
.It Fl T Ar disktype .It Fl T Ar disktype
For backward compatibility and for For backward compatibility and for
.Nm mount_mfs . .Nm mount_mfs .
.It Fl F Ar file .It Fl F Ar file
.Nm mount_mfs .Nm Mount_mfs
will use this file for the image of the filesystem. When will use this file for the image of the filesystem. When
.Nm mount_mfs .Nm mount_mfs
exits, this file will be left behind. exits, this file will be left behind.
.It Fl N .It Fl N
Causes the file system parameters to be printed out Cause the file system parameters to be printed out
without really creating the file system. without really creating the file system.
.It Fl O .It Fl O
Creates a 4.3BSD format filesystem. Create a
.Bx 4.3
format filesystem.
This options is primarily used to build root filesystems This options is primarily used to build root filesystems
that can be understood by older boot ROMs. that can be understood by older boot ROMs.
.It Fl T .It Fl T
Uses information for the specified disk from Use information for the specified disk from
.Pa /etc/disktab .Pa /etc/disktab
instead of trying to get the information from a disklabel. instead of trying to get the information from a disklabel.
.It Fl a Ar maxcontig .It Fl a Ar maxcontig
This specifies the maximum number of contiguous blocks that will be Specify the maximum number of contiguous blocks that will be
laid out before forcing a rotational delay (see the laid out before forcing a rotational delay (see the
.Fl d .Fl d
option). option).
The default value is one. The default value is 1.
See See
.Xr tunefs 8 .Xr tunefs 8
for more details on how to set this option. for more details on how to set this option.
@ -157,7 +160,7 @@ The block size of the file system, in bytes.
The number of cylinders per cylinder group in a file system. The number of cylinders per cylinder group in a file system.
The default value is 16. The default value is 16.
.It Fl d Ar rotdelay .It Fl d Ar rotdelay
This specifies the expected time (in milliseconds) to service a transfer Specify the expected time (in milliseconds) to service a transfer
completion interrupt and initiate a new transfer on the same disk. completion interrupt and initiate a new transfer on the same disk.
The default is 0 milliseconds. The default is 0 milliseconds.
See See
@ -165,7 +168,7 @@ See
for more details on how to set this option. for more details on how to set this option.
.ne 1i .ne 1i
.It Fl e Ar maxbpg .It Fl e Ar maxbpg
This indicates the maximum number of blocks any single file can Indicate the maximum number of blocks any single file can
allocate out of a cylinder group before it is forced to begin allocate out of a cylinder group before it is forced to begin
allocating blocks from another cylinder group. allocating blocks from another cylinder group.
The default is about one quarter of the total blocks in a cylinder group. The default is about one quarter of the total blocks in a cylinder group.
@ -176,7 +179,7 @@ for more details on how to set this option.
The fragment size of the file system in bytes. The fragment size of the file system in bytes.
The default is 1024 bytes. The default is 1024 bytes.
.It Fl i Ar number of bytes per inode .It Fl i Ar number of bytes per inode
This specifies the density of inodes in the file system. Specify the density of inodes in the file system.
The default is to create an inode for every (4 * frag-size) bytes of data space. The default is to create an inode for every (4 * frag-size) bytes of data space.
If fewer inodes are desired, a larger number should be used; If fewer inodes are desired, a larger number should be used;
to create more inodes a smaller number should be given. to create more inodes a smaller number should be given.
@ -193,8 +196,9 @@ See
.Xr tunefs 8 .Xr tunefs 8
for more details on how to set this option. for more details on how to set this option.
.It Fl n Ar number of distinguished rotational positions .It Fl n Ar number of distinguished rotational positions
Determines how many rotational time slots there are in one revolution of Determine how many rotational time slots there are in one revolution of
the disk. Defaults to 1, which essentially disables the rotational position table. the disk. Defaults to 1, which essentially disables the rotational position
table.
.It Fl o Ar optimization\ preference .It Fl o Ar optimization\ preference
.Pq ``space'' or ``time'' .Pq ``space'' or ``time''
The file system can either be instructed to try to minimize the time spent The file system can either be instructed to try to minimize the time spent
@ -213,15 +217,15 @@ The size of the file system in sectors.
The following options override the standard sizes for the disk geometry. The following options override the standard sizes for the disk geometry.
Their default values are taken from the disk label. Their default values are taken from the disk label.
Changing these defaults is useful only when using Changing these defaults is useful only when using
.Nm newfs .Nm
to build a file system whose raw image will eventually be used on a to build a file system whose raw image will eventually be used on a
different type of disk than the one on which it is initially created different type of disk than the one on which it is initially created
(for example on a write-once disk). (for example on a write-once disk).
Note that changing any of these values from their defaults will make Note that changing any of these values from their defaults will make
it impossible for it impossible for
.Xr fsck .Xr fsck 8
to find the alternate superblocks if the standard superblock is lost. to find the alternate superblocks if the standard superblock is lost.
.Bl -tag -width Fl .Bl -tag -width indent
.It Fl S Ar sector-size .It Fl S Ar sector-size
The size of a sector in bytes (almost never anything but 512). The size of a sector in bytes (almost never anything but 512).
.It Fl k Ar sector \&0 skew , per track .It Fl k Ar sector \&0 skew , per track
@ -259,7 +263,7 @@ If zero is specified, the value from the disklabel will be used.
This does not include sectors reserved at the end of each track for bad This does not include sectors reserved at the end of each track for bad
block replacement (see the block replacement (see the
.Fl p .Fl p
option.) option).
.It Fl x Ar spare sectors per cylinder .It Fl x Ar spare sectors per cylinder
Spare sectors (bad sector replacements) are physical sectors that occupy Spare sectors (bad sector replacements) are physical sectors that occupy
space at the end of the last track in the cylinder. space at the end of the last track in the cylinder.
@ -272,7 +276,7 @@ system for data allocation.
The options to the The options to the
.Nm mount_mfs .Nm mount_mfs
command are as described for the command are as described for the
.Nm newfs .Nm
command, except for the command, except for the
.Fl o .Fl o
option. option.
@ -295,7 +299,9 @@ Mount a 64 MB large memory file system on /tmp, with
.Xr mount 8 .Xr mount 8
options nosuid and nodev. options nosuid and nodev.
.Sh BUGS .Sh BUGS
The boot code of FreeBSD assumes that the file system that carries the The boot code of
.Bx Free
assumes that the file system that carries the
kernel has blocks of 8 kilobytes and fragments of 1 kilobyte. You will kernel has blocks of 8 kilobytes and fragments of 1 kilobyte. You will
not be able to boot from a file system that uses another size. not be able to boot from a file system that uses another size.
.Sh SEE ALSO .Sh SEE ALSO

View File

@ -32,13 +32,17 @@
*/ */
#ifndef lint #ifndef lint
static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95"; static const char copyright[] =
"@(#) Copyright (c) 1983, 1989, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
static char copyright[] = #if 0
"@(#) Copyright (c) 1983, 1989, 1993, 1994\n\ static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
The Regents of the University of California. All rights reserved.\n"; #endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
/* /*
@ -46,17 +50,15 @@ static char copyright[] =
*/ */
#include <sys/param.h> #include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/disklabel.h> #include <sys/disklabel.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <ufs/ufs/dir.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h> #include <ufs/ffs/fs.h>
#include <ufs/ufs/ufsmount.h> #include <ufs/ufs/ufsmount.h>
#include <ctype.h> #include <ctype.h>
#include <err.h>
#include <errno.h> #include <errno.h>
#include <paths.h> #include <paths.h>
#include <stdio.h> #include <stdio.h>
@ -65,10 +67,13 @@ static char copyright[] =
#include <syslog.h> #include <syslog.h>
#include <unistd.h> #include <unistd.h>
#ifdef MFS
#include <sys/types.h>
#include <sys/mman.h>
#endif
#if __STDC__ #if __STDC__
#include <stdarg.h> #include <stdarg.h>
#else
#include <varargs.h>
#endif #endif
#include "mntopts.h" #include "mntopts.h"
@ -201,13 +206,14 @@ int unlabeled;
char device[MAXPATHLEN]; char device[MAXPATHLEN];
char *progname; char *progname;
extern void mkfs __P((struct partition *, char *, int, int));
static void usage __P((void));
int int
main(argc, argv) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
extern char *optarg;
extern int optind;
register int ch; register int ch;
register struct partition *pp; register struct partition *pp;
register struct disklabel *lp; register struct disklabel *lp;
@ -217,13 +223,14 @@ main(argc, argv)
struct stat st; struct stat st;
struct statfs *mp; struct statfs *mp;
int fsi, fso, len, n; int fsi, fso, len, n;
char *cp, *s1, *s2, *special, *opstring, buf[BUFSIZ]; char *cp, *s1, *s2, *special, *opstring;
#ifdef MFS #ifdef MFS
struct vfsconf vfc; struct vfsconf vfc;
int error; int error;
char buf[BUFSIZ];
#endif #endif
if (progname = strrchr(*argv, '/')) if ((progname = strrchr(*argv, '/')))
++progname; ++progname;
else else
progname = *argv; progname = *argv;
@ -258,7 +265,7 @@ main(argc, argv)
break; 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",
optarg); optarg);
break; break;
case 'b': case 'b':
@ -272,11 +279,11 @@ main(argc, argv)
break; break;
case 'd': case 'd':
if ((rotdelay = atoi(optarg)) < 0) if ((rotdelay = atoi(optarg)) < 0)
fatal("%s: bad rotational delay\n", optarg); fatal("%s: bad rotational delay", optarg);
break; break;
case 'e': case 'e':
if ((maxbpg = atoi(optarg)) <= 0) if ((maxbpg = atoi(optarg)) <= 0)
fatal("%s: bad blocks per file in a cylinder group\n", fatal("%s: bad blocks per file in a cylinder group",
optarg); optarg);
break; break;
case 'f': case 'f':
@ -285,7 +292,7 @@ main(argc, argv)
break; break;
case 'i': case 'i':
if ((density = atoi(optarg)) <= 0) if ((density = atoi(optarg)) <= 0)
fatal("%s: bad bytes per inode\n", optarg); fatal("%s: bad bytes per inode", optarg);
break; break;
case 'k': case 'k':
if ((trackskew = atoi(optarg)) < 0) if ((trackskew = atoi(optarg)) < 0)
@ -297,11 +304,11 @@ main(argc, argv)
break; break;
case 'm': case 'm':
if ((minfree = atoi(optarg)) < 0 || minfree > 99) if ((minfree = atoi(optarg)) < 0 || minfree > 99)
fatal("%s: bad free space %%\n", optarg); fatal("%s: bad free space %%", optarg);
break; break;
case 'n': case 'n':
if ((nrpos = atoi(optarg)) < 0) if ((nrpos = atoi(optarg)) < 0)
fatal("%s: bad rotational layout count\n", fatal("%s: bad rotational layout count",
optarg); optarg);
if (nrpos == 0) if (nrpos == 0)
nrpos = 1; nrpos = 1;
@ -315,7 +322,7 @@ main(argc, argv)
else if (strcmp(optarg, "time") == 0) else if (strcmp(optarg, "time") == 0)
opt = FS_OPTTIME; opt = FS_OPTTIME;
else else
fatal("%s: unknown optimization preference: use `space' or `time'."); fatal("%s: unknown optimization preference: use `space' or `time'");
} }
break; break;
case 'p': case 'p':
@ -325,7 +332,7 @@ main(argc, argv)
break; break;
case 'r': case 'r':
if ((rpm = atoi(optarg)) <= 0) if ((rpm = atoi(optarg)) <= 0)
fatal("%s: bad revolutions/minute\n", optarg); fatal("%s: bad revolutions/minute", optarg);
break; break;
case 's': case 's':
if ((fssize = atoi(optarg)) <= 0) if ((fssize = atoi(optarg)) <= 0)
@ -441,7 +448,7 @@ main(argc, argv)
progname, special); progname, special);
cp = strchr(argv[0], '\0') - 1; cp = strchr(argv[0], '\0') - 1;
if (cp == (char *)-1 || if (cp == (char *)-1 ||
(*cp < 'a' || *cp > 'h') && !isdigit(*cp)) ((*cp < 'a' || *cp > 'h') && !isdigit(*cp)))
fatal("%s: can't figure out file system partition", fatal("%s: can't figure out file system partition",
argv[0]); argv[0]);
#ifdef COMPAT #ifdef COMPAT
@ -681,6 +688,7 @@ fatal(fmt, va_alist)
/*NOTREACHED*/ /*NOTREACHED*/
} }
static void
usage() usage()
{ {
if (mfs) { if (mfs) {