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
This commit is contained in:
@@ -8,8 +8,10 @@
|
|||||||
|
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <NodeMonitor.h>
|
#include <NodeMonitor.h>
|
||||||
|
#include <Drivers.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
class DataChange {
|
class DataChange {
|
||||||
@@ -203,11 +205,31 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
|
|||||||
fFile.GetStat(&stat);
|
fFile.GetStat(&stat);
|
||||||
fIsDevice = (stat.st_mode & (S_IFBLK | S_IFCHR)) != 0;
|
fIsDevice = (stat.st_mode & (S_IFBLK | S_IFCHR)) != 0;
|
||||||
|
|
||||||
// ToDo: add support for devices and attributes!
|
fBlockSize = 512;
|
||||||
status = fFile.GetSize(&fSize);
|
|
||||||
if (status < B_OK) {
|
if (fIsDevice) {
|
||||||
fFile.Unset();
|
// ToDo: is there any other possibility to issue a ioctl() from a BFile?
|
||||||
return status;
|
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)
|
if (attribute != NULL)
|
||||||
@@ -216,7 +238,6 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
|
|||||||
fAttribute = NULL;
|
fAttribute = NULL;
|
||||||
|
|
||||||
fView = NULL;
|
fView = NULL;
|
||||||
fBlockSize = 512;
|
|
||||||
fRealViewOffset = 0;
|
fRealViewOffset = 0;
|
||||||
fViewOffset = 0;
|
fViewOffset = 0;
|
||||||
fRealViewSize = fViewSize = fBlockSize;
|
fRealViewSize = fViewSize = fBlockSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user