diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2015-04-03 19:28:29 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2015-04-06 11:41:48 +0900 |
commit | 60eb73180ee06b5da48400102c13d54b406fbcbc (patch) | |
tree | e19add18a1dbe3ed6b4592b0ec3e9a4a3bb50977 | |
parent | 147a4fe0fdb62e34cad393e5fb658cdc73c8208a (diff) | |
download | deviced-60eb73180ee06b5da48400102c13d54b406fbcbc.tar.gz deviced-60eb73180ee06b5da48400102c13d54b406fbcbc.tar.bz2 deviced-60eb73180ee06b5da48400102c13d54b406fbcbc.zip |
mmc: Change the udev register way
Do not use an extra udev logic.
Instead I shared the core udev logic.
Change-Id: I879f5f7e2fdbcdac46f06e035e058f3db7c2339a
Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
-rwxr-xr-x | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/core/device-notifier.h | 1 | ||||
-rw-r--r-- | src/core/udev.h | 3 | ||||
-rw-r--r-- | src/mmc/mmc-handler.c | 60 | ||||
-rw-r--r-- | src/mmc/mmc-handler.h | 2 | ||||
-rw-r--r-- | src/mmc/uevent.c | 149 |
6 files changed, 39 insertions, 177 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c63f6fdd..9631671c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,6 @@ ENDIF(TIZEN_HALL) SET(SRCS ${SRCS} src/mmc/config.c src/mmc/mmc-handler.c - src/mmc/uevent.c src/mmc/vfat.c ) IF(USE_EMULATOR) diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 719d062e..45fb9646 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -23,7 +23,6 @@ enum device_notifier_type { DEVICE_NOTIFIER_BOOTING_DONE, DEVICE_NOTIFIER_LCD, - DEVICE_NOTIFIER_MMC, DEVICE_NOTIFIER_TA, DEVICE_NOTIFIER_LOWBAT, DEVICE_NOTIFIER_TOUCH_HARDKEY, diff --git a/src/core/udev.h b/src/core/udev.h index c8c846c1..2c560331 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -65,6 +65,9 @@ #define USB_SUBSYSTEM "usb" #define USB_INTERFACE_DEVTYPE "usb_interface" +/* block */ +#define BLOCK_SUBSYSTEM "block" + /* power supply status */ enum { POWER_SUPPLY_STATUS_UNKNOWN = 0, diff --git a/src/mmc/mmc-handler.c b/src/mmc/mmc-handler.c index cd32ee8d..5b2f73d9 100644 --- a/src/mmc/mmc-handler.c +++ b/src/mmc/mmc-handler.c @@ -38,6 +38,7 @@ #include "core/device-notifier.h" #include "core/common.h" #include "core/devices.h" +#include "core/udev.h" #include "mmc-handler.h" #include "config.h" #include "core/edbus-handler.h" @@ -48,6 +49,7 @@ #define MMC_PARENT_PATH tzplatform_getenv(TZ_SYS_STORAGE) #define MMC_DEV "/dev/mmcblk" +#define MMC_PATH "*/mmcblk[0-9]" #define SMACKFS_MAGIC 0x43415d53 #define SMACKFS_MNT "/smack" @@ -698,17 +700,6 @@ static int mmc_removed(void) return 0; } -static int mmc_changed_cb(void *data) -{ - char *devpath = (char*)data; - - /* if MMC is inserted */ - if (devpath) - return mmc_inserted(devpath); - else - return mmc_removed(); -} - static int mmc_booting_done(void* data) { char devpath[NAME_MAX] = {0,}; @@ -723,6 +714,28 @@ static int mmc_booting_done(void* data) return mmc_inserted(devpath); } +static void uevent_block_handler(struct udev_device *dev) +{ + const char *devpath; + const char *action; + const char *devnode; + + devpath = udev_device_get_devpath(dev); + if (fnmatch(MMC_PATH, devpath, 0)) + return; + + action = udev_device_get_action(dev); + devnode = udev_device_get_devnode(dev); + if (!action || !devnode) + return; + + _D("mmc action : %s", action); + if (!strncmp(action, UDEV_ADD, sizeof(UDEV_ADD))) + mmc_inserted(devnode); + else if (!strncmp(action, UDEV_REMOVE, sizeof(UDEV_REMOVE))) + mmc_removed(); +} + static DBusMessage *edbus_request_mount(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; @@ -907,6 +920,11 @@ int get_mmc_devpath(char devpath[]) return 0; } +static struct uevent_handler uh = { + .subsystem = BLOCK_SUBSYSTEM, + .uevent_func = uevent_block_handler, +}; + static const struct edbus_method edbus_methods[] = { { "RequestMount", NULL, "i", edbus_request_mount }, { "RequestUnmount", "i", "i", edbus_request_unmount }, @@ -916,12 +934,6 @@ static const struct edbus_method edbus_methods[] = { { "ChangeStatus", "i", "i", edbus_change_status }, }; -static int mmc_poweroff(void *data) -{ - mmc_uevent_stop(); - return 0; -} - static void mmc_init(void *data) { int ret; @@ -934,25 +946,25 @@ static void mmc_init(void *data) _E("fail to init edbus interface and method(%d)", ret); /* register mmc uevent control routine */ - ret = mmc_uevent_start(); + ret = register_kernel_uevent_control(&uh); if (ret < 0) - _E("fail to mmc uevent start"); + _E("fail to register extcon uevent : %d", ret); /* register notifier if mmc exist or not */ - register_notifier(DEVICE_NOTIFIER_POWEROFF, mmc_poweroff); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, mmc_booting_done); - register_notifier(DEVICE_NOTIFIER_MMC, mmc_changed_cb); } static void mmc_exit(void *data) { + int ret; + /* unregister notifier */ - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, mmc_poweroff); - unregister_notifier(DEVICE_NOTIFIER_MMC, mmc_changed_cb); unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, mmc_booting_done); /* unregister mmc uevent control routine */ - mmc_uevent_stop(); + ret = unregister_kernel_uevent_control(&uh); + if (ret < 0) + _E("fail to unregister extcon uevent : %d", ret); } static int mmc_start(enum device_flags flags) diff --git a/src/mmc/mmc-handler.h b/src/mmc/mmc-handler.h index 1a780faf..4406c881 100644 --- a/src/mmc/mmc-handler.h +++ b/src/mmc/mmc-handler.h @@ -56,8 +56,6 @@ void remove_fs(const struct mmc_fs_ops *fs); int get_mmc_devpath(char devpath[]); bool mmc_check_mounted(const char *mount_point); -int mmc_uevent_start(void); -int mmc_uevent_stop(void); int get_block_number(void); void mmc_mount_done(void); diff --git a/src/mmc/uevent.c b/src/mmc/uevent.c deleted file mode 100644 index 873b2134..00000000 --- a/src/mmc/uevent.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include <stdio.h> -#include <errno.h> -#include <Ecore.h> -#include "core/udev.h" -#include "core/device-notifier.h" -#include "core/log.h" - -/* block device */ -#define BLOCK_SUBSYSTEM "block" -#define MMC_PATH "*/mmcblk[0-9]" -#define BLOCK_DEVPATH "disk" - -static struct udev_monitor *mon; -static struct udev *udev; -static Ecore_Fd_Handler *ufdh; -static int ufd; - -static Eina_Bool mmc_uevent_cb(void *data, Ecore_Fd_Handler *fd_handler) -{ - struct udev_device *dev; - const char *subsystem, *devpath, *action, *devnode; - - dev = udev_monitor_receive_device(mon); - if (!dev) - return EINA_TRUE; - - subsystem = udev_device_get_subsystem(dev); - if (strcmp(subsystem, BLOCK_SUBSYSTEM)) - goto out; - - devpath = udev_device_get_devpath(dev); - if (fnmatch(MMC_PATH, devpath, 0)) - goto out; - - _D("mmc uevent occurs!"); - - action = udev_device_get_action(dev); - devnode = udev_device_get_devnode(dev); - if (!action || !devnode) - goto out; - - if (!strcmp(action, UDEV_ADD)) - device_notify(DEVICE_NOTIFIER_MMC, (void *)devnode); - else if (!strcmp(action, UDEV_REMOVE)) - device_notify(DEVICE_NOTIFIER_MMC, NULL); - -out: - udev_device_unref(dev); - return EINA_TRUE; -} - -int mmc_uevent_start(void) -{ - int r; - - if (udev) { - _D("uevent control is already started"); - return -EPERM; - } - - udev = udev_new(); - if (!udev) - return -EPERM; - - mon = udev_monitor_new_from_netlink(udev, UDEV); - if (!mon) - goto stop; - - r = udev_monitor_set_receive_buffer_size(mon, UDEV_MONITOR_SIZE); - if (r < 0) - goto stop; - - r = udev_monitor_filter_add_match_subsystem_devtype(mon, BLOCK_SUBSYSTEM, NULL); - if (r < 0) - goto stop; - - r = udev_monitor_filter_update(mon); - if (r < 0) - _E("error udev_monitor_filter_update"); - - ufd = udev_monitor_get_fd(mon); - if (ufd < 0) - goto stop; - - ufdh = ecore_main_fd_handler_add(ufd, ECORE_FD_READ, mmc_uevent_cb, NULL, NULL, NULL); - if (!ufdh) - goto stop; - - r = udev_monitor_enable_receiving(mon); - if (r < 0) - goto stop; - - return 0; - -stop: - mmc_uevent_stop(); - return -EPERM; -} - -int mmc_uevent_stop(void) -{ - struct udev_device *dev = NULL; - - if (ufdh) { - ecore_main_fd_handler_del(ufdh); - ufdh = NULL; - } - - if (ufd >= 0) { - close(ufd); - ufd = -1; - } - - if (mon) { - dev = udev_monitor_receive_device(mon); - if (dev) { - udev_device_unref(dev); - dev = NULL; - } - udev_monitor_unref(mon); - mon = NULL; - } - - if (udev) { - udev_unref(udev); - udev = NULL; - } - - return 0; -} |