+ clusters++;
+ }
+ while (rootdir_cluster != EXFAT_CLUSTER_END);
+
+ return (uint64_t) clusters * CLUSTER_SIZE(*ef->sb);
+}
+
+static const char* get_option(const char* options, const char* option_name)
+{
+ const char* p;
+ size_t length = strlen(option_name);
+
+ for (p = strstr(options, option_name); p; p = strstr(p + 1, option_name))
+ if ((p == options || p[-1] == ',') && p[length] == '=')
+ return p + length + 1;
+ return NULL;
+}
+
+static int get_int_option(const char* options, const char* option_name,
+ int base, int default_value)
+{
+ const char* p = get_option(options, option_name);
+
+ if (p == NULL)
+ return default_value;
+ return strtol(p, NULL, base);
+}
+
+static bool match_option(const char* options, const char* option_name)
+{
+ const char* p;
+ size_t length = strlen(option_name);
+
+ for (p = strstr(options, option_name); p; p = strstr(p + 1, option_name))
+ if ((p == options || p[-1] == ',') &&
+ (p[length] == ',' || p[length] == '\0'))
+ return true;
+ return false;
+}
+
+static void parse_options(struct exfat* ef, const char* options)
+{
+ int opt_umask;
+
+ 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());
+
+ ef->noatime = match_option(options, "noatime");
+
+ switch (get_int_option(options, "repair", 10, 0))
+ {
+ case 1:
+ ef->repair = EXFAT_REPAIR_ASK;
+ break;
+ case 2:
+ ef->repair = EXFAT_REPAIR_YES;
+ break;
+ default:
+ ef->repair = EXFAT_REPAIR_NO;
+ break;
+ }
+}
+
+static bool verify_vbr_checksum(const struct exfat* ef, void* sector)
+{
+ off_t sector_size = SECTOR_SIZE(*ef->sb);
+ uint32_t vbr_checksum;
+ int i;
+
+ if (exfat_pread(ef->dev, sector, sector_size, 0) < 0)
+ {
+ exfat_error("failed to read boot sector");
+ return false;
+ }
+ vbr_checksum = exfat_vbr_start_checksum(sector, sector_size);
+ for (i = 1; i < 11; i++)
+ {
+ if (exfat_pread(ef->dev, sector, sector_size, i * sector_size) < 0)
+ {
+ exfat_error("failed to read VBR sector");
+ return false;
+ }
+ vbr_checksum = exfat_vbr_add_checksum(sector, sector_size,
+ vbr_checksum);