summaryrefslogtreecommitdiffstats
path: root/exfat/libexfat/io.c
diff options
context:
space:
mode:
authorbigbiff <bigbiff@teamw.in>2014-11-01 14:34:57 +0100
committerDees Troy <dees_troy@teamw.in>2014-11-04 15:37:42 +0100
commitc40c1c52d68049434b1379c3a6d8652a1363bb07 (patch)
tree08321140321dd893136fa2fb30b896ce2027cb24 /exfat/libexfat/io.c
parentadd "done" after "Updating partition details..." (diff)
downloadandroid_bootable_recovery-c40c1c52d68049434b1379c3a6d8652a1363bb07.tar
android_bootable_recovery-c40c1c52d68049434b1379c3a6d8652a1363bb07.tar.gz
android_bootable_recovery-c40c1c52d68049434b1379c3a6d8652a1363bb07.tar.bz2
android_bootable_recovery-c40c1c52d68049434b1379c3a6d8652a1363bb07.tar.lz
android_bootable_recovery-c40c1c52d68049434b1379c3a6d8652a1363bb07.tar.xz
android_bootable_recovery-c40c1c52d68049434b1379c3a6d8652a1363bb07.tar.zst
android_bootable_recovery-c40c1c52d68049434b1379c3a6d8652a1363bb07.zip
Diffstat (limited to 'exfat/libexfat/io.c')
-rw-r--r--exfat/libexfat/io.c86
1 files changed, 21 insertions, 65 deletions
diff --git a/exfat/libexfat/io.c b/exfat/libexfat/io.c
index a861bddd7..306c5dd06 100644
--- a/exfat/libexfat/io.c
+++ b/exfat/libexfat/io.c
@@ -3,7 +3,7 @@
exFAT file system implementation library.
Free exFAT implementation.
- Copyright (C) 2010-2014 Andrew Nayenko
+ Copyright (C) 2010-2013 Andrew Nayenko
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,19 +24,13 @@
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/mount.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
-#include <errno.h>
-#if defined(__APPLE__)
+#ifdef __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
-#include <sys/mount.h>
#ifdef USE_UBLIO
#include <sys/uio.h>
#include <ublio.h>
@@ -71,7 +65,6 @@ static int open_rw(const char* spec)
if (fd != -1 && ioctl(fd, BLKROGET, &ro) == 0 && ro)
{
close(fd);
- errno = EROFS;
return -1;
}
#endif
@@ -100,8 +93,7 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
if (dev->fd == -1)
{
free(dev);
- exfat_error("failed to open '%s' in read-only mode: %s", spec,
- strerror(errno));
+ exfat_error("failed to open `%s' in read-only mode", spec);
return NULL;
}
dev->mode = EXFAT_MODE_RO;
@@ -111,8 +103,7 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
if (dev->fd == -1)
{
free(dev);
- exfat_error("failed to open '%s' in read-write mode: %s", spec,
- strerror(errno));
+ exfat_error("failed to open `%s' in read-write mode", spec);
return NULL;
}
dev->mode = EXFAT_MODE_RW;
@@ -128,11 +119,11 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
if (dev->fd != -1)
{
dev->mode = EXFAT_MODE_RO;
- exfat_warn("'%s' is write-protected, mounting read-only", spec);
+ exfat_warn("`%s' is write-protected, mounting read-only", spec);
break;
}
free(dev);
- exfat_error("failed to open '%s': %s", spec, strerror(errno));
+ exfat_error("failed to open `%s'", spec);
return NULL;
}
@@ -140,7 +131,7 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
{
close(dev->fd);
free(dev);
- exfat_error("failed to fstat '%s'", spec);
+ exfat_error("failed to fstat `%s'", spec);
return NULL;
}
if (!S_ISBLK(stbuf.st_mode) &&
@@ -149,11 +140,11 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
{
close(dev->fd);
free(dev);
- exfat_error("'%s' is neither a device, nor a regular file", spec);
+ exfat_error("`%s' is neither a device, nor a regular file", spec);
return NULL;
}
-#if defined(__APPLE__)
+#ifdef __APPLE__
if (!S_ISREG(stbuf.st_mode))
{
uint32_t block_size = 0;
@@ -176,32 +167,6 @@ 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 */
@@ -210,14 +175,14 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
{
close(dev->fd);
free(dev);
- exfat_error("failed to get size of '%s'", spec);
+ exfat_error("failed to get size of `%s'", spec);
return NULL;
}
if (exfat_seek(dev, 0, SEEK_SET) == -1)
{
close(dev->fd);
free(dev);
- exfat_error("failed to seek to the beginning of '%s'", spec);
+ exfat_error("failed to seek to the beginning of `%s'", spec);
return NULL;
}
}
@@ -245,41 +210,32 @@ struct exfat_dev* exfat_open(const char* spec, enum exfat_mode mode)
int exfat_close(struct exfat_dev* dev)
{
- int rc = 0;
-
#ifdef USE_UBLIO
if (ublio_close(dev->ufh) != 0)
- {
exfat_error("failed to close ublio");
- rc = -EIO;
- }
#endif
if (close(dev->fd) != 0)
{
- exfat_error("failed to close device: %s", strerror(errno));
- rc = -EIO;
+ free(dev);
+ exfat_error("failed to close device");
+ return 1;
}
free(dev);
- return rc;
+ return 0;
}
int exfat_fsync(struct exfat_dev* dev)
{
- int rc = 0;
-
#ifdef USE_UBLIO
if (ublio_fsync(dev->ufh) != 0)
- {
- exfat_error("ublio fsync failed");
- rc = -EIO;
- }
-#endif
+#else
if (fsync(dev->fd) != 0)
+#endif
{
- exfat_error("fsync failed: %s", strerror(errno));
- rc = -EIO;
+ exfat_error("fsync failed");
+ return 1;
}
- return rc;
+ return 0;
}
enum exfat_mode exfat_get_mode(const struct exfat_dev* dev)