From 50897e9d43f61b4ab238d3ebff62cc45d505206a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Sat, 7 Mar 2015 15:55:32 +0100 Subject: [PATCH 13/14] Add compatible ioctl calls for OSX and FreeBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- src/io.c | 2 -- src/mkfs.fat.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 96 insertions(+), 7 deletions(-) diff --git a/src/io.c b/src/io.c index 450432c..7d0d49a 100644 --- a/src/io.c +++ b/src/io.c @@ -36,10 +36,8 @@ #include #include #include -#include #include #include -#include #include "fsck.fat.h" #include "common.h" diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c index 76d40d8..02e0918 100644 --- a/src/mkfs.fat.c +++ b/src/mkfs.fat.c @@ -47,17 +47,13 @@ #include "version.h" #include -#include #include -#include -#include #include #include #include #include #include #include -#include #include #include #include @@ -67,6 +63,40 @@ #include #include +#if defined(__linux__) + #include + #include + #include +#elif defined(__FreeBSD__) || defined(__APPLE__) + #include + + #define BLOCK_SIZE_BITS 10 + #define BLOCK_SIZE (1< floppy later */ case 720: /* 5.25", 2, 9, 40 - 360K */ @@ -651,6 +696,17 @@ floppy_default: { /* Can we get the drive geometry? (Note I'm not too sure about */ /* whether to use HDIO_GETGEO or HDIO_REQ) */ +#if defined(__FreeBSD__) + if (ioctl(dev, DIOCGFWSECTORS, &geometry.sectors) || ioctl(dev, DIOCGFWHEADS, &geometry.heads) || geometry.sectors == 0 + || geometry.heads == 0) { + printf("unable to get drive geometry, using default 255/63\n"); + bs.secs_track = htole16(63); + bs.heads = htole16(255); + } else { + bs.secs_track = htole16(geometry.sectors); /* Set up the geometry information */ + bs.heads = htole16(geometry.heads); + } +#elif defined(__linux__) if (ioctl(dev, HDIO_GETGEO, &geometry) || geometry.sectors == 0 || geometry.heads == 0) { printf("unable to get drive geometry, using default 255/63\n"); @@ -662,6 +718,11 @@ floppy_default: if (!hidden_sectors_by_user) hidden_sectors = htole32(geometry.start); } +#else + printf("unable to get drive geometry, using default 255/63\n"); + bs.secs_track = htole16(63); + bs.heads = htole16(255); +#endif def_hd_params: bs.media = (char)0xf8; /* Set up the media descriptor for a hard drive */ if (!size_fat && blocks * SECTORS_PER_BLOCK > 1064960) { @@ -1693,6 +1754,15 @@ int main(int argc, char **argv) die("Device partition expected, not making filesystem on entire device '%s' (use -I to override)"); if (sector_size_set) { +#if defined(__FreeBSD__) + if (ioctl(dev, DIOCGSECTORSIZE, &min_sector_size) >= 0) + if (sector_size < min_sector_size) { + sector_size = min_sector_size; + fprintf(stderr, + "Warning: sector size was set to %d (minimal for this device)\n", + sector_size); + } +#elif defined(__linux__) if (ioctl(dev, BLKSSZGET, &min_sector_size) >= 0) if (sector_size < min_sector_size) { sector_size = min_sector_size; @@ -1700,11 +1770,32 @@ int main(int argc, char **argv) "Warning: sector size was set to %d (minimal for this device)\n", sector_size); } +#elif defined(__APPLE__) + if (ioctl(dev, DKIOCGETPHYSICALBLOCKSIZE, &min_sector_size) >= 0) + if (sector_size < min_sector_size) { + sector_size = min_sector_size; + fprintf(stderr, + "Warning: sector size was set to %d (minimal for this device)\n", + sector_size); + } +#endif } else { +#if defined(__FreeBSD__) + if (ioctl(dev, DIOCGSECTORSIZE, &min_sector_size) >= 0) { + sector_size = min_sector_size; + sector_size_set = 1; + } +#elif defined(__linux__) if (ioctl(dev, BLKSSZGET, &min_sector_size) >= 0) { sector_size = min_sector_size; sector_size_set = 1; } +#elif defined(__APPLE__) + if (ioctl(dev, DKIOCGETPHYSICALBLOCKSIZE, &min_sector_size) >= 0) { + sector_size = min_sector_size; + sector_size_set = 1; + } +#endif } if (sector_size > 4096) -- 1.9.1