diff options
author | phk <phk@FreeBSD.org> | 2002-09-20 08:12:51 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2002-09-20 08:12:51 +0000 |
commit | d605f099664588b02e2f852b4de0c28eb97babdd (patch) | |
tree | 7edfe85754c4f37adf871bbbc12e31e2c081d118 /sbin/fdisk | |
parent | 42910e6e7c2cec1c38a67b13277b19bfda6288f5 (diff) | |
download | FreeBSD-src-d605f099664588b02e2f852b4de0c28eb97babdd.zip FreeBSD-src-d605f099664588b02e2f852b4de0c28eb97babdd.tar.gz |
Straighten out get_params().
Sponsored by: DARPA & NAI Labs.
Diffstat (limited to 'sbin/fdisk')
-rw-r--r-- | sbin/fdisk/fdisk.c | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 9f0c869..b3145e4 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -749,43 +749,44 @@ write_disk(off_t sector, void *buf) static int get_params() { - int error; - u_int u; - off_t o; - - if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) { - warnx("can't get disk parameters on %s; supplying dummy ones", disk); - dos_cyls = cyls = 1; - dos_heads = heads = 1; - dos_sectors = sectors = 1; + int error; + u_int u; + off_t o; + + if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) { + warnx("can't get disk parameters on %s; supplying dummy ones", disk); + dos_cyls = cyls = 1; + dos_heads = heads = 1; + dos_sectors = sectors = 1; + dos_cylsecs = cylsecs = heads * sectors; + disksecs = cyls * heads * sectors; + } else { + dos_cyls = cyls = disklabel.d_ncylinders; + dos_heads = heads = disklabel.d_ntracks; + dos_sectors = sectors = disklabel.d_nsectors; + } + error = ioctl(fd, DIOCGFWSECTORS, &u); + if (error == 0) + sectors = dos_sectors = u; + error = ioctl(fd, DIOCGFWHEADS, &u); + if (error == 0) + heads = dos_heads = u; + dos_cylsecs = cylsecs = heads * sectors; disksecs = cyls * heads * sectors; - } - error = ioctl(fd, DIOCGFWSECTORS, &u); - if (error == 0) - dos_sectors = u; - error = ioctl(fd, DIOCGFWHEADS, &u); - if (error == 0) - dos_heads = u; - error = ioctl(fd, DIOCGSECTORSIZE, &u); - if (error != 0) { - u = 512; - } - error = ioctl(fd, DIOCGMEDIASIZE, &o); - if (error == 0) { - dos_cylsecs = dos_heads * dos_sectors; - disksecs = o / u; - dos_cyls = o / (u * dos_heads * dos_sectors); - return (o / u); - } - dos_cyls = cyls = disklabel.d_ncylinders; - dos_heads = heads = disklabel.d_ntracks; - dos_sectors = sectors = disklabel.d_nsectors; - dos_cylsecs = cylsecs = heads * sectors; - disksecs = cyls * heads * sectors; + error = ioctl(fd, DIOCGSECTORSIZE, &u); + if (error != 0) + u = 512; + + error = ioctl(fd, DIOCGMEDIASIZE, &o); + if (error == 0) { + disksecs = o / u; + cyls = dos_cyls = o / (u * dos_heads * dos_sectors); + } + - return (disksecs); + return (disksecs); } |