OSDN Git Service

Check that either a block device or a regular file is opened.
authorresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sat, 19 Mar 2011 15:35:55 +0000 (15:35 +0000)
committerresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sat, 19 Mar 2011 15:35:55 +0000 (15:35 +0000)
git-svn-id: http://exfat.googlecode.com/svn/trunk@217 60bc1c72-a15a-11de-b98f-4500b42dc123

libexfat/mount.c

index 93d7950..847b619 100644 (file)
@@ -121,6 +121,7 @@ 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));
@@ -142,6 +143,21 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options)
                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;
+       }
 
        exfat_read_raw(ef->sb, sizeof(struct exfat_super_block), 0, ef->fd);
        if (memcmp(ef->sb->oem_name, "EXFAT   ", 8) != 0)