tizen 2.3 release
[framework/system/deviced.git] / src / usb / usb-host-storage-exfat.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #include <stdio.h>
21 #include <fcntl.h>
22 #include <string.h>
23 #include <sys/mount.h>
24
25 #include "core/common.h"
26 #include "usb-host.h"
27
28 #define EXFAT_MOUNT_OPT "uid=5000,gid=5000,dmask=0002,fmask=0002"
29 #define SMACK_MOUNT_OPT "smackfsroot=*,smackfsdef=*"
30
31 static const char *exfat_check_arg[] = {
32         "/sbin/fsck.exfat",
33         "-f", "-R", NULL, NULL,
34 };
35
36 static const char *exfat_arg[] = {
37         "/sbin/mkfs.exfat",
38         "-t", "exfat", "-s", "9", "-c", "8", "-b", "11", "-f", "1", "-l", "tizen", NULL, NULL,
39 };
40
41 static int exfat_check(const char *devname)
42 {
43         int argc;
44         argc = ARRAY_SIZE(exfat_check_arg);
45         exfat_check_arg[argc - 2] = devname;
46         return run_child(argc, exfat_check_arg);
47 }
48
49 static void get_mount_options(bool smack, char *options, int len)
50 {
51         if (smack)
52                 snprintf(options, len, "%s,%s", EXFAT_MOUNT_OPT, SMACK_MOUNT_OPT);
53         else
54                 snprintf(options, len, "%s", EXFAT_MOUNT_OPT);
55 }
56
57 static int exfat_mount(bool smack, const char *devpath, const char *mount_point)
58 {
59         char options[NAME_MAX];
60         get_mount_options(smack, options, sizeof(options));
61         return mount(devpath, mount_point, "exfat", 0, options);
62 }
63
64 static int exfat_mount_rdonly(bool smack, const char *devpath, const char *mount_point)
65 {
66         char options[NAME_MAX];
67         get_mount_options(smack, options, sizeof(options));
68         return mount(devpath, mount_point, "exfat", MS_RDONLY, options);
69 }
70
71 static int exfat_format(const char *path)
72 {
73         int argc;
74         argc = ARRAY_SIZE(exfat_arg);
75         exfat_arg[argc - 2] = path;
76         return run_child(argc, exfat_arg);
77 }
78
79 static const struct storage_fs_ops exfat_ops = {
80         .name         = "exfat",
81         .check        = exfat_check,
82         .mount        = exfat_mount,
83         .mount_rdonly = exfat_mount_rdonly,
84         .format       = exfat_format,
85 };
86
87 static void __CONSTRUCTOR__ exfat_init(void)
88 {
89         register_fs(&exfat_ops);
90 }