From fb2d716a991fb0d64f1850074564e27a0ad8b3b3 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 21 Jul 2010 15:29:29 +0000 Subject: [PATCH] Added support for using underlying devices -- we need to get the size with the B_GET_GEOMETRY ioctl instead. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37658 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../driver/checksum_device.cpp | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/tests/system/kernel/file_corruption/driver/checksum_device.cpp b/src/tests/system/kernel/file_corruption/driver/checksum_device.cpp index 98f479bd6a..9610efcb76 100644 --- a/src/tests/system/kernel/file_corruption/driver/checksum_device.cpp +++ b/src/tests/system/kernel/file_corruption/driver/checksum_device.cpp @@ -326,7 +326,7 @@ struct RawDevice : Device, DoublyLinkedListLinkImpl { status_t Init(const char* fileName) { - // open and stat file + // open file/device fFD = open(fileName, O_RDWR | O_NOCACHE); // TODO: The O_NOCACHE is a work-around for a page writer problem. // Since it collects pages for writing back without regard for @@ -336,11 +336,32 @@ struct RawDevice : Device, DoublyLinkedListLinkImpl { if (fFD < 0) return errno; + // get the size struct stat st; if (fstat(fFD, &st) < 0) return errno; - fFileSize = st.st_size / B_PAGE_SIZE * B_PAGE_SIZE; + switch (st.st_mode & S_IFMT) { + case S_IFREG: + fFileSize = st.st_size; + break; + case S_IFCHR: + case S_IFBLK: + { + device_geometry geometry; + if (ioctl(fFD, B_GET_GEOMETRY, &geometry, sizeof(geometry)) < 0) + return errno; + + fFileSize = (off_t)geometry.bytes_per_sector + * geometry.sectors_per_track + * geometry.cylinder_count * geometry.head_count; + break; + } + default: + return B_BAD_VALUE; + } + + fFileSize = fFileSize / B_PAGE_SIZE * B_PAGE_SIZE; fDeviceSize = fFileSize / (B_PAGE_SIZE + kCheckSumLength) * B_PAGE_SIZE; // find a free slot