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.
29 #include "core/common.h"
30 #include "core/devices.h"
32 #include "mmc-handler.h"
34 #define FS_EXT4_NAME "ext4"
36 #define FS_EXT4_SMACK_LABEL "/usr/bin/mmc-smack-label"
44 static const char *ext4_arg[] = {
49 static const char *ext4_check_arg[] = {
51 "-f", "-y", NULL, NULL,
54 static struct fs_check ext4_info = {
62 static int mmc_popup_pid;
64 static bool ext4_match(const char *devpath)
69 fd = open(devpath, O_RDONLY);
71 _E("failed to open fd(%s) : %s", devpath, strerror(errno));
75 /* check fs type with magic code */
76 r = lseek(fd, ext4_info.offset, SEEK_SET);
84 _I("mmc search magic : 0x%2x, 0x%2x", buf[0],buf[1]);
85 if (memcmp(buf, ext4_info.magic, ext4_info.magic_sz))
89 _I("MMC type : %s", ext4_info.name);
94 _E("failed to match with ext4(%s)", devpath);
98 static int ext4_check(const char *devpath)
101 argc = ARRAY_SIZE(ext4_check_arg);
102 ext4_check_arg[argc - 2] = devpath;
103 return run_child(argc, ext4_check_arg);
106 static int mmc_check_smack(const char *mount_point)
108 char buf[NAME_MAX] = {0,};
110 snprintf(buf, sizeof(buf), "%s", mount_point);
111 launch_evenif_exist(FS_EXT4_SMACK_LABEL, buf);
113 if (mmc_popup_pid > 0) {
114 _E("will be killed mmc-popup(%d)", mmc_popup_pid);
115 kill(mmc_popup_pid, SIGTERM);
120 static int check_smack_popup(void)
124 struct popup_data *params;
125 static const struct device_ops *apps = NULL;
127 ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &val);
128 if (val == 1 || ret != 0) {
130 FIND_DEVICE_INT(apps, "apps");
132 params = malloc(sizeof(struct popup_data));
133 if (params == NULL) {
137 params->name = MMC_POPUP_NAME;
138 params->key = MMC_POPUP_APP_KEY;
139 params->value = MMC_POPUP_SMACK_VALUE;
147 static int ext4_mount(bool smack, const char *devpath, const char *mount_point)
149 int r, retry = RETRY_COUNT;
152 r = mount(devpath, mount_point, "ext4", 0, NULL);
154 _I("Mounted mmc card [ext4]");
157 mmc_check_smack(mount_point);
161 _I("mount fail : r = %d, err = %d", r, errno);
163 } while (r < 0 && errno == ENOENT && retry-- > 0);
168 static int ext4_format(const char *devpath)
171 argc = ARRAY_SIZE(ext4_arg);
172 ext4_arg[argc - 2] = devpath;
173 return run_child(argc, ext4_arg);
176 static const struct mmc_fs_ops ext4_ops = {
177 .type = FS_TYPE_EXT4,
182 .format = ext4_format,
185 static void __CONSTRUCTOR__ module_init(void)
190 static void __DESTRUCTOR__ module_exit(void)
192 remove_fs(&ext4_ops);