From 04d3a3dedfb89d1b8f04a428a82cab0a2ca0621c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 18 Feb 2004 02:05:31 +0000 Subject: [PATCH] Now can also retrieve the size of a disk device. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6619 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskprobe/DataEditor.cpp | 33 +++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/apps/diskprobe/DataEditor.cpp b/src/apps/diskprobe/DataEditor.cpp index a6b748ce7f..74f71c7133 100644 --- a/src/apps/diskprobe/DataEditor.cpp +++ b/src/apps/diskprobe/DataEditor.cpp @@ -8,8 +8,10 @@ #include #include +#include #include +#include class DataChange { @@ -203,11 +205,31 @@ DataEditor::SetTo(BEntry &entry, const char *attribute) fFile.GetStat(&stat); fIsDevice = (stat.st_mode & (S_IFBLK | S_IFCHR)) != 0; - // ToDo: add support for devices and attributes! - status = fFile.GetSize(&fSize); - if (status < B_OK) { - fFile.Unset(); - return status; + fBlockSize = 512; + + if (fIsDevice) { + // ToDo: is there any other possibility to issue a ioctl() from a BFile? + device_geometry geometry; + int device = fFile.Dup(); + if (device < 0 || ioctl(device, B_GET_GEOMETRY, &geometry) < 0) { + if (device >= 0) + close(device); + fFile.Unset(); + return B_ERROR; + } + close(device); + + fSize = geometry.head_count * geometry.cylinder_count * geometry.sectors_per_track; + fBlockSize = geometry.bytes_per_sector; + } else if (IsAttribute()) { + // ToDo: add support for attributes! + fSize = 0; + } else { + status = fFile.GetSize(&fSize); + if (status < B_OK) { + fFile.Unset(); + return status; + } } if (attribute != NULL) @@ -216,7 +238,6 @@ DataEditor::SetTo(BEntry &entry, const char *attribute) fAttribute = NULL; fView = NULL; - fBlockSize = 512; fRealViewOffset = 0; fViewOffset = 0; fRealViewSize = fViewSize = fBlockSize;