4 * Copyright (c) 2012 - 2015 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.
22 #include <sys/mount.h>
35 #define FS_EXT4_NAME "ext4"
37 static const char *check_smack_arg[] = {
38 "/usr/bin/mmc-smack-label",
42 static const char *ext4_arg[] = {
47 static const char *ext4_check_arg[] = {
49 "-f", "-y", NULL, NULL,
52 static struct fs_check ext4_info = {
60 static bool ext4_match(const char *devpath)
65 fd = open(devpath, O_RDONLY);
67 _E("failed to open fd(%s) : %d", devpath, errno);
71 /* check fs type with magic code */
72 r = lseek(fd, ext4_info.offset, SEEK_SET);
80 _I("ext4 search magic : 0x%2x, 0x%2x", buf[0], buf[1]);
81 if (memcmp(buf, ext4_info.magic, ext4_info.magic_sz))
85 _I("Storage type : %s", ext4_info.name);
90 _E("failed to match with ext4(%s)", devpath);
94 static int ext4_check(const char *devpath)
97 argc = ARRAY_SIZE(ext4_check_arg);
98 ext4_check_arg[argc - 2] = devpath;
99 return run_child(argc, ext4_check_arg);
102 static int mmc_check_smack(const char *mount_point)
104 char buf[NAME_MAX] = {0,};
108 snprintf(buf, sizeof(buf), "%s", mount_point);
110 argc = ARRAY_SIZE(check_smack_arg);
111 check_smack_arg[argc - 2] = buf;
112 ret = run_child(argc, check_smack_arg);
117 static int check_smack_popup(void)
119 /* TODO: show smack popup */
123 static int ext4_mount(bool smack, const char *devpath, const char *mount_point)
125 int r, retry = RETRY_COUNT;
126 struct timespec time = {0,};
127 unsigned long mountflags = MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_DIRSYNC;
130 r = mount(devpath, mount_point, "ext4", mountflags, NULL);
132 _I("Storage Mounted[ext4]");
135 mmc_check_smack(mount_point);
139 _I("mount fail : r = %d, err = %d", r, errno);
140 time.tv_nsec = 100 * NANO_SECOND_MULTIPLIER;
141 nanosleep(&time, NULL);
142 if (r < 0 && errno == EROFS)
143 mountflags |= MS_RDONLY;
144 } while (r < 0 && (errno == ENOENT || errno == EROFS) && retry-- > 0);
149 static int ext4_format(const char *devpath)
152 argc = ARRAY_SIZE(ext4_arg);
153 ext4_arg[argc - 2] = devpath;
154 return run_child(argc, ext4_arg);
157 static const struct block_fs_ops ext4_ops = {
158 .type = FS_TYPE_EXT4,
163 .format = ext4_format,
166 static void __CONSTRUCTOR__ module_init(void)
171 static void __DESTRUCTOR__ module_exit(void)
173 remove_fs(&ext4_ops);