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 _D("mmc search magic : 0x%2x, 0x%2x", buf[0],buf[1]);
85 if (memcmp(buf, ext4_info.magic, ext4_info.magic_sz))
89 _D("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 vconf_set_int(VCONFKEY_SYSMAN_MMC_STATUS, VCONFKEY_SYSMAN_MMC_MOUNTED);
114 vconf_set_int(VCONFKEY_SYSMAN_MMC_MOUNT, VCONFKEY_SYSMAN_MMC_MOUNT_COMPLETED);
115 if (mmc_popup_pid > 0) {
116 _E("will be killed mmc-popup(%d)", mmc_popup_pid);
117 kill(mmc_popup_pid, SIGTERM);
122 static int check_smack_popup(void)
126 struct popup_data *params;
127 static const struct device_ops *apps = NULL;
129 ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &val);
130 if (val == 1 || ret != 0) {
132 apps = find_device("apps");
136 params = malloc(sizeof(struct popup_data));
137 if (params == NULL) {
141 params->name = MMC_POPUP_NAME;
142 params->key = MMC_POPUP_APP_KEY;
143 params->value = MMC_POPUP_SMACK_VALUE;
151 static int ext4_mount(bool smack, const char *devpath, const char *mount_point)
153 int r, retry = RETRY_COUNT;
156 r = mount(devpath, mount_point, "ext4", 0, NULL);
158 _D("Mounted mmc card [ext4]");
161 mmc_check_smack(mount_point);
166 } while (r < 0 && errno == ENOENT && retry-- > 0);
171 static int ext4_format(const char *devpath)
174 argc = ARRAY_SIZE(ext4_arg);
175 ext4_arg[argc - 2] = devpath;
176 return run_child(argc, ext4_arg);
179 static const struct mmc_fs_ops ext4_ops = {
180 .type = FS_TYPE_EXT4,
185 .format = ext4_format,
188 static void __CONSTRUCTOR__ module_init(void)
193 static void __DESTRUCTOR__ module_exit(void)
195 remove_fs(&ext4_ops);