diff options
-rw-r--r-- | diskman/disk.cc | 6 | ||||
-rw-r--r-- | diskman/disk.hh | 5 | ||||
-rw-r--r-- | diskman/partition.cc | 3 |
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; } |