diff options
author | imp <imp@FreeBSD.org> | 2015-01-06 05:28:37 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 2015-01-06 05:28:37 +0000 |
commit | 20163879d8b33bcbcbe0718b7369c9c8d2fd571b (patch) | |
tree | 7642f45fc42d6192ce6b58f0f4c3c598067a0410 /sbin | |
parent | eeb56aacdf8296147b0913525e63370dd76dd574 (diff) | |
download | FreeBSD-src-20163879d8b33bcbcbe0718b7369c9c8d2fd571b.zip FreeBSD-src-20163879d8b33bcbcbe0718b7369c9c8d2fd571b.tar.gz |
Remove old ioctl use and support, once and for all.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fsck_ffs/setup.c | 91 | ||||
-rw-r--r-- | sbin/fsirand/fsirand.c | 11 | ||||
-rw-r--r-- | sbin/newfs/newfs.c | 30 | ||||
-rw-r--r-- | sbin/newfs_msdos/newfs_msdos.c | 38 |
4 files changed, 20 insertions, 150 deletions
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index 85e9548..494e503 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -59,8 +59,6 @@ struct bufarea asblk; #define POWEROF2(num) (((num) & ((num) - 1)) == 0) static void badsb(int listerr, const char *s); -static int calcsb(char *dev, int devfd, struct fs *fs); -static struct disklabel *getdisklabel(char *s, int fd); /* * Read in a superblock finding an alternate if necessary. @@ -178,7 +176,7 @@ setup(char *dev) */ if (readsb(1) == 0) { skipclean = 0; - if (bflag || preen || calcsb(dev, fsreadfd, &proto) == 0) + if (bflag || preen) return(0); if (reply("LOOK FOR ALTERNATE SUPERBLOCKS") == 0) return (0); @@ -437,7 +435,6 @@ badsb(int listerr, const char *s) void sblock_init(void) { - struct disklabel *lp; fswritefd = -1; fsmodified = 0; @@ -448,89 +445,5 @@ sblock_init(void) asblk.b_un.b_buf = Malloc(SBLOCKSIZE); if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL) errx(EEXIT, "cannot allocate space for superblock"); - if ((lp = getdisklabel(NULL, fsreadfd))) - real_dev_bsize = dev_bsize = secsize = lp->d_secsize; - else - dev_bsize = secsize = DEV_BSIZE; -} - -/* - * Calculate a prototype superblock based on information in the disk label. - * When done the cgsblock macro can be calculated and the fs_ncg field - * can be used. Do NOT attempt to use other macros without verifying that - * their needed information is available! - */ -static int -calcsb(char *dev, int devfd, struct fs *fs) -{ - struct disklabel *lp; - struct partition *pp; - char *cp; - int i, nspf; - - cp = strchr(dev, '\0') - 1; - if (cp == (char *)-1 || ((*cp < 'a' || *cp > 'h') && !isdigit(*cp))) { - pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev); - return (0); - } - lp = getdisklabel(dev, devfd); - if (isdigit(*cp)) - pp = &lp->d_partitions[0]; - else - pp = &lp->d_partitions[*cp - 'a']; - if (pp->p_fstype != FS_BSDFFS) { - pfatal("%s: NOT LABELED AS A BSD FILE SYSTEM (%s)\n", - dev, pp->p_fstype < FSMAXTYPES ? - fstypenames[pp->p_fstype] : "unknown"); - return (0); - } - if (pp->p_fsize == 0 || pp->p_frag == 0 || - pp->p_cpg == 0 || pp->p_size == 0) { - pfatal("%s: %s: type %s fsize %d, frag %d, cpg %d, size %d\n", - dev, "INCOMPLETE LABEL", fstypenames[pp->p_fstype], - pp->p_fsize, pp->p_frag, pp->p_cpg, pp->p_size); - return (0); - } - memset(fs, 0, sizeof(struct fs)); - fs->fs_fsize = pp->p_fsize; - fs->fs_frag = pp->p_frag; - fs->fs_size = pp->p_size; - fs->fs_sblkno = roundup( - howmany(lp->d_bbsize + lp->d_sbsize, fs->fs_fsize), - fs->fs_frag); - nspf = fs->fs_fsize / lp->d_secsize; - for (fs->fs_fsbtodb = 0, i = nspf; i > 1; i >>= 1) - fs->fs_fsbtodb++; - dev_bsize = lp->d_secsize; - if (fs->fs_magic == FS_UFS2_MAGIC) { - fs->fs_fpg = pp->p_cpg; - fs->fs_ncg = howmany(fs->fs_size, fs->fs_fpg); - } else /* if (fs->fs_magic == FS_UFS1_MAGIC) */ { - fs->fs_old_cpg = pp->p_cpg; - fs->fs_old_cgmask = 0xffffffff; - for (i = lp->d_ntracks; i > 1; i >>= 1) - fs->fs_old_cgmask <<= 1; - if (!POWEROF2(lp->d_ntracks)) - fs->fs_old_cgmask <<= 1; - fs->fs_old_cgoffset = roundup(howmany(lp->d_nsectors, nspf), - fs->fs_frag); - fs->fs_fpg = (fs->fs_old_cpg * lp->d_secpercyl) / nspf; - fs->fs_ncg = howmany(fs->fs_size / lp->d_secpercyl, - fs->fs_old_cpg); - } - return (1); -} - -static struct disklabel * -getdisklabel(char *s, int fd) -{ - static struct disklabel lab; - - if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { - if (s == NULL) - return ((struct disklabel *)NULL); - pwarn("ioctl (GCINFO): %s\n", strerror(errno)); - errx(EEXIT, "%s: can't read disk label", s); - } - return (&lab); + dev_bsize = secsize = DEV_BSIZE; } diff --git a/sbin/fsirand/fsirand.c b/sbin/fsirand/fsirand.c index c373c5b..0fea239 100644 --- a/sbin/fsirand/fsirand.c +++ b/sbin/fsirand/fsirand.c @@ -36,7 +36,6 @@ static const char rcsid[] = #endif /* not lint */ #include <sys/param.h> -#include <sys/disklabel.h> #include <sys/resource.h> #include <ufs/ufs/dinode.h> @@ -120,22 +119,12 @@ fsirand(char *device) char sbuf[SBLOCKSIZE], sbuftmp[SBLOCKSIZE]; int i, devfd, n, cg; u_int32_t bsize = DEV_BSIZE; - struct disklabel label; if ((devfd = open(device, printonly ? O_RDONLY : O_RDWR)) < 0) { warn("can't open %s", device); return (1); } - /* Get block size (usually 512) from disklabel if possible */ - if (!ignorelabel) { - if (ioctl(devfd, DIOCGDINFO, &label) < 0) - warn("can't read disklabel, using sector size of %d", - bsize); - else - bsize = label.d_secsize; - } - dp1 = NULL; dp2 = NULL; diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c index 59b7e61..658bd42 100644 --- a/sbin/newfs/newfs.c +++ b/sbin/newfs/newfs.c @@ -117,11 +117,9 @@ static u_char bootarea[BBSIZE]; static int is_file; /* work on a file, not a device */ static char *dkname; static char *disktype; -static int unlabeled; static void getfssize(intmax_t *, const char *p, intmax_t, intmax_t); static struct disklabel *getdisklabel(char *s); -static void rewritelabel(char *s, struct disklabel *lp); static void usage(void); static int expand_number_int(const char *buf, int *num); @@ -402,12 +400,6 @@ main(int argc, char *argv[]) pp->p_size *= secperblk; } mkfs(pp, special); - if (!unlabeled) { - if (realsectorsize != DEV_BSIZE) - pp->p_size /= realsectorsize / DEV_BSIZE; - if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition))) - rewritelabel(special, lp); - } ufs_disk_close(&disk); if (!jflag) exit(0); @@ -451,9 +443,6 @@ getdisklabel(char *s) return &lab; } - if (ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab) != -1) - return (&lab); - unlabeled++; if (disktype) { lp = getdiskbyname(disktype); if (lp != NULL) @@ -462,25 +451,6 @@ getdisklabel(char *s) return (NULL); } -void -rewritelabel(char *s, struct disklabel *lp) -{ - if (unlabeled) - return; - lp->d_checksum = 0; - lp->d_checksum = dkcksum(lp); - if (is_file) { - bsd_disklabel_le_enc(bootarea + 0 /* labeloffset */ + - 1 /* labelsoffset */ * sectorsize, lp); - lseek(disk.d_fd, 0, SEEK_SET); - if (write(disk.d_fd, bootarea, BBSIZE) != BBSIZE) - errx(1, "cannot write label"); - return; - } - if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) == -1) - warn("ioctl (WDINFO): %s: can't rewrite disk label", s); -} - static void usage() { diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c index f315d98..4685782 100644 --- a/sbin/newfs_msdos/newfs_msdos.c +++ b/sbin/newfs_msdos/newfs_msdos.c @@ -829,28 +829,26 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, if (lp == NULL) { if (bpb->bpbBytesPerSec) dlp.d_secsize = bpb->bpbBytesPerSec; - if (ioctl(fd, DIOCGDINFO, &dlp) == -1) { - if (bpb->bpbBytesPerSec == 0 && ioctl(fd, DIOCGSECTORSIZE, - &dlp.d_secsize) == -1) - err(1, "cannot get sector size"); + if (bpb->bpbBytesPerSec == 0 && ioctl(fd, DIOCGSECTORSIZE, + &dlp.d_secsize) == -1) + err(1, "cannot get sector size"); - dlp.d_secperunit = ms / dlp.d_secsize; + dlp.d_secperunit = ms / dlp.d_secsize; - if (bpb->bpbSecPerTrack == 0 && ioctl(fd, DIOCGFWSECTORS, - &dlp.d_nsectors) == -1) { - warn("cannot get number of sectors per track"); - dlp.d_nsectors = 63; - } - if (bpb->bpbHeads == 0 && - ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) { - warn("cannot get number of heads"); - if (dlp.d_secperunit <= 63*1*1024) - dlp.d_ntracks = 1; - else if (dlp.d_secperunit <= 63*16*1024) - dlp.d_ntracks = 16; - else - dlp.d_ntracks = 255; - } + if (bpb->bpbSecPerTrack == 0 && ioctl(fd, DIOCGFWSECTORS, + &dlp.d_nsectors) == -1) { + warn("cannot get number of sectors per track"); + dlp.d_nsectors = 63; + } + if (bpb->bpbHeads == 0 && + ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) { + warn("cannot get number of heads"); + if (dlp.d_secperunit <= 63*1*1024) + dlp.d_ntracks = 1; + else if (dlp.d_secperunit <= 63*16*1024) + dlp.d_ntracks = 16; + else + dlp.d_ntracks = 255; } hs = (ms / dlp.d_secsize) - dlp.d_secperunit; |