OSDN Git Service

Implemented umask, dmask and fmask mount options.
authorresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sun, 20 Dec 2009 15:44:42 +0000 (15:44 +0000)
committerresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sun, 20 Dec 2009 15:44:42 +0000 (15:44 +0000)
git-svn-id: http://exfat.googlecode.com/svn/trunk@82 60bc1c72-a15a-11de-b98f-4500b42dc123

libexfat/exfat.h
libexfat/mount.c
libexfat/utils.c

index 16fef81..b9165af 100644 (file)
@@ -70,6 +70,7 @@ struct exfat
        }
        cmap;
        void* zero_block;
+       int dmask, fmask;
 };
 
 /* in-core nodes iterator */
index 90d53f0..56b78ab 100644 (file)
@@ -9,9 +9,12 @@
 
 #include "exfat.h"
 #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>
 
@@ -30,6 +33,39 @@ static uint64_t rootdir_size(const struct exfat* ef)
        return clusters * CLUSTER_SIZE(*ef->sb);
 }
 
+static const char* get_option(const char* options, const char* option_name)
+{
+       const char* p = strstr(options, option_name);
+       size_t length = strlen(option_name);
+
+       if (p == NULL)
+               return NULL;
+       if ((p != options && p[-1] != ',') || p[length] != '=')
+               return NULL;
+       return p + length + 1;
+}
+
+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 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;
+}
+
 int exfat_mount(struct exfat* ef, const char* spec, const char* options)
 {
        tzset();
@@ -43,6 +79,8 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options)
        }
        memset(ef->sb, 0, sizeof(struct exfat_super_block));
 
+       parse_options(ef, options);
+
        ef->fd = open(spec, O_RDWR);
        if (ef->fd < 0)
        {
index 3181a44..167b5e9 100644 (file)
@@ -17,9 +17,9 @@ void exfat_stat(const struct exfat* ef, const struct exfat_node* node,
 {
        memset(stbuf, 0, sizeof(struct stat));
        if (node->flags & EXFAT_ATTRIB_DIR)
-               stbuf->st_mode = S_IFDIR | 0755;
+               stbuf->st_mode = S_IFDIR | (0777 & ~ef->dmask);
        else
-               stbuf->st_mode = S_IFREG | 0644;
+               stbuf->st_mode = S_IFREG | (0777 & ~ef->fmask);
        stbuf->st_nlink = 1;
        stbuf->st_size = node->size;
        stbuf->st_mtime = node->mtime;