OSDN Git Service

Update copyright years.
[android-x86/external-exfat.git] / libexfat / mount.c
index 70c8af5..6e7881c 100644 (file)
@@ -3,7 +3,7 @@
        exFAT file system implementation library.
 
        Free exFAT implementation.
-       Copyright (C) 2010-2013  Andrew Nayenko
+       Copyright (C) 2010-2015  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
@@ -84,13 +84,11 @@ static bool match_option(const char* options, const char* option_name)
 
 static void parse_options(struct exfat* ef, const char* options)
 {
-       int sys_umask = umask(0);
        int opt_umask;
 
-       umask(sys_umask); /* restore umask */
-       opt_umask = get_int_option(options, "umask", 8, sys_umask);
-       ef->dmask = get_int_option(options, "dmask", 8, opt_umask) & 0777;
-       ef->fmask = get_int_option(options, "fmask", 8, opt_umask) & 0777;
+       opt_umask = get_int_option(options, "umask", 8, 0);
+       ef->dmask = get_int_option(options, "dmask", 8, opt_umask);
+       ef->fmask = get_int_option(options, "fmask", 8, opt_umask);
 
        ef->uid = get_int_option(options, "uid", 10, geteuid());
        ef->gid = get_int_option(options, "gid", 10, getegid());
@@ -98,7 +96,7 @@ static void parse_options(struct exfat* ef, const char* options)
        ef->noatime = match_option(options, "noatime");
 }
 
-static int verify_vbr_checksum(struct exfat_dev* dev, void* sector,
+static bool verify_vbr_checksum(struct exfat_dev* dev, void* sector,
                off_t sector_size)
 {
        uint32_t vbr_checksum;
@@ -107,7 +105,7 @@ static int verify_vbr_checksum(struct exfat_dev* dev, void* sector,
        if (exfat_pread(dev, sector, sector_size, 0) < 0)
        {
                exfat_error("failed to read boot sector");
-               return 1;
+               return false;
        }
        vbr_checksum = exfat_vbr_start_checksum(sector, sector_size);
        for (i = 1; i < 11; i++)
@@ -115,7 +113,7 @@ static int verify_vbr_checksum(struct exfat_dev* dev, void* sector,
                if (exfat_pread(dev, sector, sector_size, i * sector_size) < 0)
                {
                        exfat_error("failed to read VBR sector");
-                       return 1;
+                       return false;
                }
                vbr_checksum = exfat_vbr_add_checksum(sector, sector_size,
                                vbr_checksum);
@@ -123,16 +121,16 @@ static int verify_vbr_checksum(struct exfat_dev* dev, void* sector,
        if (exfat_pread(dev, sector, sector_size, i * sector_size) < 0)
        {
                exfat_error("failed to read VBR checksum sector");
-               return 1;
+               return false;
        }
        for (i = 0; i < sector_size / sizeof(vbr_checksum); i++)
                if (le32_to_cpu(((const le32_t*) sector)[i]) != vbr_checksum)
                {
                        exfat_error("invalid VBR checksum 0x%x (expected 0x%x)",
                                        le32_to_cpu(((const le32_t*) sector)[i]), vbr_checksum);
-                       return 1;
+                       return false;
                }
-       return 0;
+       return true;
 }
 
 static int commit_super_block(const struct exfat* ef)
@@ -217,8 +215,7 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options)
                return -ENOMEM;
        }
        /* use zero_cluster as a temporary buffer for VBR checksum verification */
-       if (verify_vbr_checksum(ef->dev, ef->zero_cluster,
-                       SECTOR_SIZE(*ef->sb)) != 0)
+       if (!verify_vbr_checksum(ef->dev, ef->zero_cluster, SECTOR_SIZE(*ef->sb)))
        {
                free(ef->zero_cluster);
                exfat_close(ef->dev);
@@ -343,11 +340,12 @@ static void finalize_super_block(struct exfat* ef)
                ef->sb->allocated_percent = ((total - free) * 100 + total / 2) / total;
        }
 
-       commit_super_block(ef);
+       commit_super_block(ef); /* ignore return code */
 }
 
 void exfat_unmount(struct exfat* ef)
 {
+       exfat_flush(ef);        /* ignore return code */
        exfat_put_node(ef, ef->root);
        exfat_reset_cache(ef);
        free(ef->root);