4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include "core/common.h"
28 #include "mmc-handler.h"
30 #define FS_VFAT_NAME "mkdosfs"
32 #define FS_VFAT_MOUNT_OPT "uid=5000,gid=5000,dmask=0002,fmask=0002,iocharset=iso8859-1,utf8,shortname=mixed"
34 static const char *vfat_arg[] = {
39 static const char *vfat_check_arg[] = {
40 "/usr/bin/fsck_msdosfs",
44 static struct fs_check vfat_info = {
52 static int vfat_check(const char *devpath)
54 int argc, r, pass = 0;
56 argc = ARRAY_SIZE(vfat_check_arg);
57 vfat_check_arg[argc - 2] = devpath;
60 r = run_child(argc, vfat_check_arg);
64 _I("filesystem check completed OK");
67 _I("file system check failed (not a FAT filesystem)");
72 _I("filesystem modified - rechecking (pass : %d)", pass);
75 _I("failing check after rechecks, but file system modified");
78 _I("filesystem check failed (unknown exit code %d)", r);
87 static bool vfat_match(const char *devpath)
91 r = vfat_check(devpath);
93 _E("failed to match with vfat(%s)", devpath);
97 _D("MMC type : %s", vfat_info.name);
101 static int vfat_mount(bool smack, const char *devpath, const char *mount_point)
103 char options[NAME_MAX];
104 int r, retry = RETRY_COUNT;
107 snprintf(options, sizeof(options), "%s,%s", FS_VFAT_MOUNT_OPT, SMACKFS_MOUNT_OPT);
109 snprintf(options, sizeof(options), "%s", FS_VFAT_MOUNT_OPT);
112 r = mount(devpath, mount_point, "vfat", 0, options);
114 _D("Mounted mmc card [vfat]");
117 _D("mount fail : r = %d, err = %d", r, errno);
119 } while (r < 0 && errno == ENOENT && retry-- > 0);
124 static int vfat_format(const char *devpath)
127 argc = ARRAY_SIZE(vfat_arg);
128 vfat_arg[argc - 2] = devpath;
129 return run_child(argc, vfat_arg);
132 static const struct mmc_fs_ops vfat_ops = {
133 .type = FS_TYPE_VFAT,
138 .format = vfat_format,
141 static void __CONSTRUCTOR__ module_init(void)
146 static void __DESTRUCTOR__ module_exit(void)
149 remove_fs(&vfat_ops);