OSDN Git Service

Use exfat_open() instead of calling open() directly.
authorrelan <relan@users.noreply.github.com>
Fri, 22 Apr 2011 19:27:00 +0000 (19:27 +0000)
committerrelan <relan@users.noreply.github.com>
Mon, 24 Aug 2015 05:26:13 +0000 (08:26 +0300)
dump/main.c
libexfat/mount.c
mkfs/main.c

index 98bfe4f..357557d 100644 (file)
@@ -76,12 +76,10 @@ static int dump_sb(const char* spec)
        int fd;
        struct exfat_super_block sb;
 
-       fd = open(spec, O_RDONLY);
+       fd = exfat_open(spec, 1);
        if (fd < 0)
-       {
-               exfat_error("failed to open `%s'", spec);
                return 1;
-       }
+
        if (read(fd, &sb, sizeof(struct exfat_super_block))
                        != sizeof(struct exfat_super_block))
        {
index 847b619..4240f63 100644 (file)
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #define _XOPEN_SOURCE /* for tzset() in Linux */
 #include <time.h>
 
@@ -121,7 +119,6 @@ static int verify_vbr_checksum(void* sector, off_t sector_size, int fd)
 int exfat_mount(struct exfat* ef, const char* spec, const char* options)
 {
        int rc;
-       struct stat stbuf;
 
        tzset();
        memset(ef, 0, sizeof(struct exfat));
@@ -136,26 +133,10 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options)
 
        parse_options(ef, options);
 
-       ef->fd = open(spec, ef->ro ? O_RDONLY : O_RDWR);
+       ef->fd = exfat_open(spec, ef->ro);
        if (ef->fd < 0)
        {
                free(ef->sb);
-               exfat_error("failed to open `%s'", spec);
-               return -EIO;
-       }
-       if (fstat(ef->fd, &stbuf) != 0)
-       {
-               close(ef->fd);
-               free(ef->sb);
-               exfat_error("failed to fstat `%s'", spec);
-               return -EIO;
-       }
-       if (!S_ISBLK(stbuf.st_mode) && !S_ISREG(stbuf.st_mode))
-       {
-               close(ef->fd);
-               free(ef->sb);
-               exfat_error("`%s' is neither a block device, nor a regular file",
-                               spec);
                return -EIO;
        }
 
index bba8019..e6d49e1 100644 (file)
@@ -19,9 +19,7 @@
 */
 
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/time.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <inttypes.h>
 #include <stdio.h>
@@ -285,12 +283,9 @@ static int mkfs(const char* spec, int sector_bits, int spc_bits,
                return 1;
        }
 
-       fd = open(spec_abs, O_RDWR);
+       fd = exfat_open(spec_abs, 0);
        if (fd < 0)
-       {
-               exfat_error("failed to open special file `%s'", spec_abs);
                return 1;
-       }
 
        volume_size = lseek(fd, 0, SEEK_END);
        if (volume_size == (off_t) -1)