diff options
author | srs5694 <srs5694@users.sourceforge.net> | 2011-03-12 01:23:12 -0500 |
---|---|---|
committer | srs5694 <srs5694@users.sourceforge.net> | 2011-03-12 01:23:12 -0500 |
commit | bf8950cad0285ee6ab8a896e8d0a30c5fb62c7af (patch) | |
tree | ca6eaedd03128249d84544d6ad077f1498d66e41 /diskio-unix.cc | |
parent | 96312236d7f0c857efc95871a31857e24ecdc81b (diff) | |
download | sgdisk-bf8950cad0285ee6ab8a896e8d0a30c5fb62c7af.tar.gz |
Version 0.7.0
Diffstat (limited to 'diskio-unix.cc')
-rw-r--r-- | diskio-unix.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/diskio-unix.cc b/diskio-unix.cc index d65a644..238e529 100644 --- a/diskio-unix.cc +++ b/diskio-unix.cc @@ -22,6 +22,11 @@ #include <errno.h> #include <fcntl.h> #include <sys/stat.h> + +#ifdef __linux__ +#include "linux/hdreg.h" +#endif + #include <iostream> #include "diskio.h" @@ -160,6 +165,42 @@ int DiskIO::GetBlockSize(void) { return (blockSize); } // DiskIO::GetBlockSize() +// Returns the number of heads, according to the kernel, or 255 if the +// correct value can't be determined. +uint32_t DiskIO::GetNumHeads(void) { + uint32_t numHeads = 255; + +#ifdef HDIO_GETGEO + struct hd_geometry geometry; + + // If disk isn't open, try to open it.... + if (!isOpen) + OpenForRead(); + + if (!ioctl(fd, HDIO_GETGEO, &geometry)) + numHeads = (uint32_t) geometry.heads; +#endif + return numHeads; +} // DiskIO::GetNumHeads(); + +// Returns the number of sectors per track, according to the kernel, or 63 +// if the correct value can't be determined. +uint32_t DiskIO::GetNumSecsPerTrack(void) { + uint32_t numSecs = 63; + + #ifdef HDIO_GETGEO + struct hd_geometry geometry; + + // If disk isn't open, try to open it.... + if (!isOpen) + OpenForRead(); + + if (!ioctl(fd, HDIO_GETGEO, &geometry)) + numSecs = (uint32_t) geometry.sectors; + #endif + return numSecs; +} // DiskIO::GetNumSecsPerTrack() + // Resync disk caches so the OS uses the new partition table. This code varies // a lot from one OS to another. void DiskIO::DiskSync(void) { |