diff options
author | jmallett <jmallett@FreeBSD.org> | 2003-02-11 03:06:45 +0000 |
---|---|---|
committer | jmallett <jmallett@FreeBSD.org> | 2003-02-11 03:06:45 +0000 |
commit | 0f7ddd626884fc47570602e01894d31ca7c0ca4c (patch) | |
tree | 0d31cbda8fe59355c1f1ae5601d92e445e6627aa /sbin/newfs/newfs.c | |
parent | 68e4eee3d3189d2ed0be164de53c1b7b991c91a4 (diff) | |
download | FreeBSD-src-0f7ddd626884fc47570602e01894d31ca7c0ca4c.zip FreeBSD-src-0f7ddd626884fc47570602e01894d31ca7c0ca4c.tar.gz |
Convert newfs to libufs (really). Solves one real issue with previous
version of such. Differences in filesystems generated were found to be
from 1) sbwrite with the "all" parameter 2) removal of writecache. The
sbwrite call was made to perform as the original version, and otherwise
this was checked against a version of newfs with the write cache removed.
Diffstat (limited to 'sbin/newfs/newfs.c')
-rw-r--r-- | sbin/newfs/newfs.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index 75832b3..a0dcdf8 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -136,8 +136,8 @@ int maxcontig = 0; /* max contiguous blocks to allocate */ int maxbpg; /* maximum blocks per file in a cyl group */ int avgfilesize = AVFILESIZ;/* expected average file size */ int avgfilesperdir = AFPDIR;/* expected number of files per directory */ -int fso; /* filedescriptor to device */ u_char *volumelabel = NULL; /* volume label for filesystem */ +struct uufsd disk; /* libufs disk structure */ static char device[MAXPATHLEN]; static char *disktype; @@ -276,17 +276,21 @@ main(int argc, char *argv[]) special = device; } - fso = open(special, Nflag ? O_RDONLY : O_RDWR); - if (fso < 0) - err(1, "%s", special); - if (fstat(fso, &st) < 0) + if (ufs_disk_fillout_blank(&disk, special) == -1 || + (!Nflag && ufs_disk_write(&disk) == -1)) { + if (disk.d_error != NULL) + errx(1, "%s: %s", special, disk.d_error); + else + err(1, "%s", special); + } + if (fstat(disk.d_fd, &st) < 0) err(1, "%s", special); if ((st.st_mode & S_IFMT) != S_IFCHR) errx(1, "%s: not a character-special device", special); - if (sectorsize == 0) - ioctl(fso, DIOCGSECTORSIZE, §orsize); - if (sectorsize && !ioctl(fso, DIOCGMEDIASIZE, &mediasize)) { + if (sectorsize == 0) + ioctl(disk.d_fd, DIOCGSECTORSIZE, §orsize); + if (sectorsize && !ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize)) { if (fssize == 0) fssize = mediasize / sectorsize; else if (fssize > mediasize / sectorsize) @@ -365,7 +369,7 @@ main(int argc, char *argv[]) if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition))) rewritelabel(special, lp); } - close(fso); + ufs_disk_close(&disk); exit(0); } @@ -375,7 +379,7 @@ getdisklabel(char *s) static struct disklabel lab; struct disklabel *lp; - if (!ioctl(fso, DIOCGDINFO, (char *)&lab)) + if (!ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab)) return (&lab); unlabeled++; if (disktype) { @@ -393,7 +397,7 @@ rewritelabel(char *s, struct disklabel *lp) return; lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); - if (ioctl(fso, DIOCWDINFO, (char *)lp) < 0) + if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) < 0) warn("ioctl (WDINFO): %s: can't rewrite disk label", s); } |