diff options
author | phk <phk@FreeBSD.org> | 2002-09-15 16:08:52 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 2002-09-15 16:08:52 +0000 |
commit | 2a9f9dcde09b8cceef1fbab364f8c63efe5cb141 (patch) | |
tree | cbd4b880b27c69e0d8128a8d84f18c84c9f7bd44 /sbin | |
parent | fc1f61ef5f36cc7ffda309d97678c3771081374a (diff) | |
download | FreeBSD-src-2a9f9dcde09b8cceef1fbab364f8c63efe5cb141.zip FreeBSD-src-2a9f9dcde09b8cceef1fbab364f8c63efe5cb141.tar.gz |
Try to pick up disk geometry with specific DIOC* ioctls, rather than
expecting a bogo-disklabel to contain them, if possible.
This makes fdisk work with GEOM.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fdisk/fdisk.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 6cf814c..9f0c869 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -29,6 +29,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ +#include <sys/disk.h> #include <sys/disklabel.h> #include <sys/param.h> #include <sys/stat.h> @@ -748,6 +749,9 @@ 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); @@ -756,7 +760,23 @@ get_params() dos_sectors = sectors = 1; dos_cylsecs = cylsecs = heads * sectors; disksecs = cyls * heads * sectors; - return disksecs; + } + 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; |