From 04eb9ba18ee507391d5ca7f1c10e2e14f7b3bbc9 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 21 Apr 2009 10:21:03 +0000 Subject: [PATCH] Patch by "VinDuv" (Vincent Duvert?): Added FSShell support for devices on MacOS X. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30289 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tools/fs_shell/unistd.cpp | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/tools/fs_shell/unistd.cpp b/src/tools/fs_shell/unistd.cpp index 72a3a0441c..8047e2802c 100644 --- a/src/tools/fs_shell/unistd.cpp +++ b/src/tools/fs_shell/unistd.cpp @@ -260,6 +260,66 @@ fssh_ioctl(int fd, unsigned long op, ...) } else error = errno; } + #elif HAIKU_HOST_PLATFORM_DARWIN + { + // Darwin does not seems to provide a way to access disk + // geometry directly + + struct stat status; + + if (fstat(fd, &status) == 0) { + // Do nothing for a regular file + if (S_ISREG(status.st_mode)) + break; + + off_t mediaSize; + + if (ioctl(fd, DKIOCGETBLOCKCOUNT, &mediaSize) != 0) { + error = errno; + break; + } + + geometry->head_count = 4; + geometry->sectors_per_track = 63; + geometry->cylinder_count = mediaSize / geometry->head_count + / geometry->sectors_per_track; + + while (geometry->cylinder_count > 1024 + && geometry->head_count < 256) { + geometry->head_count *= 2; + geometry->cylinder_count /= 2; + } + + if (geometry->head_count == 256) { + geometry->head_count = 255; + geometry->cylinder_count = mediaSize + / geometry->head_count + / geometry->sectors_per_track; + } + + if (ioctl(fd, DKIOCGETBLOCKSIZE, + &geometry->bytes_per_sector) != 0) { + error = errno; + break; + } + + uint32_t isWritable; + if (ioctl(fd, DKIOCISWRITABLE, &isWritable) != 0) { + error = errno; + break; + } + + geometry->read_only = !isWritable; + + // TODO: Get the real values... + geometry->device_type = FSSH_B_DISK; + geometry->removable = false; + geometry->write_once = false; + + error = B_OK; + } else + error = errno; + } #else // Not implemented for this platform, i.e. we won't be able to // deal with disk devices.