diff options
author | Rod Smith <rodsmith@rodsbooks.com> | 2017-07-25 21:33:18 -0400 |
---|---|---|
committer | Rod Smith <rodsmith@rodsbooks.com> | 2017-07-25 21:33:18 -0400 |
commit | fc0e014beaa6935576e93cf440f8b3d960b2d3f7 (patch) | |
tree | c56a222096e64eac963c84b64d4c7bdc47c869ca /diskio-unix.cc | |
parent | 2a6daafeda4876dc694b97a41f5b0d0626a6fa16 (diff) | |
download | sgdisk-fc0e014beaa6935576e93cf440f8b3d960b2d3f7.tar.gz |
Added code to read physical block size on Linux.
Diffstat (limited to 'diskio-unix.cc')
-rw-r--r-- | diskio-unix.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/diskio-unix.cc b/diskio-unix.cc index af71cdb..a7c4724 100644 --- a/diskio-unix.cc +++ b/diskio-unix.cc @@ -177,6 +177,27 @@ int DiskIO::GetBlockSize(void) { return (blockSize); } // DiskIO::GetBlockSize() +// Returns the physical block size of the device, if possible. If this is +// not supported, or if an error occurs, this function returns 0. +// TODO: Get this working in more OSes than Linux. +int DiskIO::GetPhysBlockSize(void) { + int err = -1, physBlockSize = 0; + + // If disk isn't open, try to open it.... + if (!isOpen) { + OpenForRead(); + } // if + + if (isOpen) { +#if defined __linux__ && !defined(EFI) + err = ioctl(fd, BLKPBSZGET, &physBlockSize); +#endif + } // if (isOpen) + if (err == -1) + physBlockSize = 0; + return (physBlockSize); +} // DiskIO::GetPhysBlockSize(void) + // Returns the number of heads, according to the kernel, or 255 if the // correct value can't be determined. uint32_t DiskIO::GetNumHeads(void) { |