block: Add exfat filesystem for mount 58/206858/7 accepted/tizen/unified/20191219.143628 submit/tizen/20191219.082139
authorYunmi Ha <yunmi.ha@samsung.com>
Tue, 28 May 2019 08:09:53 +0000 (17:09 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Thu, 19 Dec 2019 07:11:57 +0000 (16:11 +0900)
Change-Id: I5874518a24b775a1181cb0e3d1220e0ceac15001
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/block/block.c
src/block/block.h
src/block/exfat.c [new file with mode: 0644]

index acbd1b2..f48dede 100644 (file)
 #define EXTENDEDSD_MOUNT_PATH  "/opt/extendedsd"
 
 #define VFAT_NAME              "vfat"
+#define EXFAT_NAME             "exfat"
 #define EXT4_NAME              "ext4"
 #define LUKS_NAME              "crypto_LUKS"
-#define EXTENDEDSD_NAME                "extendedsd"
+#define EXTENDEDSD_NAME        "extendedsd"
 
 /* Minimum value of block id */
 #define BLOCK_ID_MIN           10
@@ -1498,6 +1499,8 @@ static int block_format(struct block_data *data,
                } else
                        fstype = fs_type;
        }
+       if (!strcmp(fstype, EXFAT_NAME))
+               fstype = VFAT_NAME;
 
        fs = NULL;
        len = strlen(fstype);
@@ -1506,14 +1509,13 @@ static int block_format(struct block_data *data,
                        break;
        }
 
-       if (!fs) {
+       if (!fs || !fs->format) {
                BLOCK_FLAG_SET(data, FS_NOT_SUPPORTED);
                _E("Not supported file system(%s).", fstype);
                return -ENOTSUP;
        }
 
        _I("Format path=%s", data->devnode);
-       fs->check(data->devnode);
        r = fs->format(data->devnode);
        if (r < 0) {
                _E("Failed to format block data for %s.", data->devnode);
index 3736819..2eb76dc 100644 (file)
@@ -29,7 +29,8 @@
 
 enum block_fs_type {
        FS_TYPE_VFAT = 0,
-       FS_TYPE_EXT4,
+       FS_TYPE_EXFAT,
+       FS_TYPE_EXT4
 };
 
 struct block_fs_ops {
diff --git a/src/block/exfat.c b/src/block/exfat.c
new file mode 100644 (file)
index 0000000..4a3f8e1
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * storaged
+ *
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+
+#include "log.h"
+#include "block.h"
+
+/* guid 10001 - group priv_externalstorage */
+#define FS_EXFAT_MOUNT_OPT  "uid=0,gid=10001,dmask=0000,fmask=0111"
+
+static int exfat_mount(bool smack, const char *devpath, const char *mount_point)
+{
+       char options[NAME_MAX];
+       int r, err, retry = RETRY_COUNT;
+       struct timespec time = {0,};
+       unsigned long mountflags = MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_DIRSYNC;
+
+       if (smack)
+               snprintf(options, sizeof(options), "%s,%s", FS_EXFAT_MOUNT_OPT, SMACKFS_MOUNT_OPT);
+       else
+               snprintf(options, sizeof(options), "%s", FS_EXFAT_MOUNT_OPT);
+
+       do {
+               r = mount(devpath, mount_point, "exfat", mountflags, options);
+               if (!r) {
+                       _I("Storage Mounted exfat.");
+                       return 0;
+               }
+
+               err = errno;
+               _I("Failed to mount return=%d: %d", r, err);
+               time.tv_nsec = 100 * NANO_SECOND_MULTIPLIER;
+               nanosleep(&time, NULL);
+               if (r < 0 && err == EROFS)
+                       mountflags |= MS_RDONLY;
+       } while (r < 0 && (err == ENOENT || err == EROFS) && retry-- > 0);
+
+       return -err;
+}
+
+static const struct block_fs_ops exfat_ops = {
+       .type = FS_TYPE_EXFAT,
+       .name = "exfat",
+       .match = NULL,
+       .check = NULL,
+       .mount = exfat_mount,
+       .format = NULL,
+};
+
+static void __CONSTRUCTOR__ module_init(void)
+{
+       add_fs(&exfat_ops);
+}
+/*
+static void __DESTRUCTOR__ module_exit(void)
+{
+       _I("module exit");
+       remove_fs(&exfat_ops);
+}
+*/