summaryrefslogtreecommitdiff
path: root/diskman
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-23 01:25:36 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-02-23 01:25:36 -0600
commit542a2d963018429e00c92f9fa1c7d1d852d641b1 (patch)
tree7f521cfc119a5347c2730ae63b28c0a374a9aefa /diskman
parent5575b3475bdbad44f5e05f1b7755859a14f9a84c (diff)
downloadhorizon-542a2d963018429e00c92f9fa1c7d1d852d641b1.tar.gz
horizon-542a2d963018429e00c92f9fa1c7d1d852d641b1.tar.bz2
horizon-542a2d963018429e00c92f9fa1c7d1d852d641b1.tar.xz
horizon-542a2d963018429e00c92f9fa1c7d1d852d641b1.zip
DiskMan: Allow sector size of disk to be retrieved
Diffstat (limited to 'diskman')
-rw-r--r--diskman/disk.cc6
-rw-r--r--diskman/disk.hh5
-rw-r--r--diskman/partition.cc3
3 files changed, 9 insertions, 5 deletions
diff --git a/diskman/disk.cc b/diskman/disk.cc
index 5fd526a..2d67b13 100644
--- a/diskman/disk.cc
+++ b/diskman/disk.cc
@@ -76,8 +76,8 @@ Disk::Disk(void *creation, int type, bool partition) {
if(ctxt != nullptr) {
/* Open the device in read-only mode. We don't need to write to it */
if(fdisk_assign_device(ctxt, _node.c_str(), 1) == 0) {
- unsigned long ssize = fdisk_get_sector_size(ctxt);
- total_mb = (fdisk_get_nsectors(ctxt) * ssize) / 1048576;
+ _sector = fdisk_get_sector_size(ctxt);
+ total_mb = (fdisk_get_nsectors(ctxt) * _sector) / 1048576;
struct fdisk_table *frees = nullptr;
if(fdisk_has_label(ctxt) != 1) {
/* Disk has no label, so consider it empty */
@@ -90,7 +90,7 @@ Disk::Disk(void *creation, int type, bool partition) {
fdisk_table_get_partition(frees, next);
fdisk_sector_t size;
if(!fdisk_partition_has_size(part)) continue;
- size = (fdisk_partition_get_size(part) * ssize) / 1048576;
+ size = (fdisk_partition_get_size(part) * _sector) / 1048576;
free_mb += size;
if(size > contiguous_mb) contiguous_mb = size;
}
diff --git a/diskman/disk.hh b/diskman/disk.hh
index 668f209..bad166f 100644
--- a/diskman/disk.hh
+++ b/diskman/disk.hh
@@ -77,6 +77,9 @@ public:
* disk, in mebibytes (MiB). */
uint32_t contiguous_block() const { return this->contiguous_mb; }
+ /*! Retrieve the sector size of the disk. */
+ uint32_t sector_size() const { return this->_sector; }
+
/*! Retrieve the partitions contained in the label, if any.
* @note You may only call this method if *has_label* is true. */
const std::vector<Partition> partitions() const;
@@ -117,6 +120,8 @@ private:
uint32_t free_mb;
/*! Largest contiguous block of free space on this disk, in mebibytes */
uint32_t contiguous_mb;
+ /*! Size of this disk's sectors, in bytes */
+ uint32_t _sector;
Disk(void *creation, int type, bool partition);
friend class DiskMan;
diff --git a/diskman/partition.cc b/diskman/partition.cc
index ba94258..9aa5d22 100644
--- a/diskman/partition.cc
+++ b/diskman/partition.cc
@@ -27,8 +27,7 @@ Partition::Partition(Disk &d, void *creation, int type) {
case 0: { /* libfdisk */
struct fdisk_partition *part = static_cast<struct fdisk_partition *>(creation);
if(fdisk_partition_has_size(part)) {
- /* XXX BUG FIXME TODO sector size */
- this->_size = fdisk_partition_get_size(part) * 512;
+ this->_size = fdisk_partition_get_size(part) * d.sector_size();
} else {
this->_size = 0;
}