aboutsummaryrefslogtreecommitdiffstats
path: root/libexfat/io.c
diff options
context:
space:
mode:
authorrelan <relan@users.noreply.github.com>2014-01-13 07:17:47 +0000
committerrelan <relan@users.noreply.github.com>2015-08-24 08:26:16 +0300
commitbac8f16c19d3533026c5c17d62d7c1b5ab93df7f (patch)
tree0f1be6784d90e7a75e8832dc51bb9e9dae600ace /libexfat/io.c
parent4f6d158433dd007eb7c78054d0b647461af7939a (diff)
downloadandroid_external_exfat-bac8f16c19d3533026c5c17d62d7c1b5ab93df7f.tar.gz
android_external_exfat-bac8f16c19d3533026c5c17d62d7c1b5ab93df7f.tar.bz2
android_external_exfat-bac8f16c19d3533026c5c17d62d7c1b5ab93df7f.zip
Add OpenBSD support.
Signed-off-by: Helg Bredow <xx404@msn.com>
Diffstat (limited to 'libexfat/io.c')
-rw-r--r--libexfat/io.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/libexfat/io.c b/libexfat/io.c
index d365be4..8c7e2b7 100644
--- a/libexfat/io.c
+++ b/libexfat/io.c
@@ -29,8 +29,13 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
-#ifdef __APPLE__
+#if defined(__APPLE__)
#include <sys/disk.h>
+#elif defined(__OpenBSD__)
+#include <sys/param.h>
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#include <sys/ioctl.h>
#endif
#ifdef USE_UBLIO
#include <sys/uio.h>
@@ -145,7 +150,7 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
return NULL;
}
-#ifdef __APPLE__
+#if defined(__APPLE__)
if (!S_ISREG(stbuf.st_mode))
{
uint32_t block_size = 0;
@@ -168,6 +173,32 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
dev->size = blocks * block_size;
}
else
+#elif defined(__OpenBSD__)
+ if (!S_ISREG(stbuf.st_mode))
+ {
+ struct disklabel lab;
+ struct partition* pp;
+ char* partition;
+
+ if (ioctl(dev->fd, DIOCGDINFO, &lab) == -1)
+ {
+ close(dev->fd);
+ free(dev);
+ exfat_error("failed to get disklabel");
+ return NULL;
+ }
+
+ /* Don't need to check that partition letter is valid as we won't get
+ this far otherwise. */
+ partition = strchr(spec, '\0') - 1;
+ pp = &(lab.d_partitions[*partition - 'a']);
+ dev->size = DL_GETPSIZE(pp) * lab.d_secsize;
+
+ if (pp->p_fstype != FS_NTFS)
+ exfat_warn("partition type is not 0x07 (NTFS/exFAT); "
+ "you can fix this with fdisk(8)");
+ }
+ else
#endif
{
/* works for Linux, FreeBSD, Solaris */