insert mmc fs register function 57/15157/1
authorgiyeol.ok <giyeol.ok@samsung.com>
Wed, 29 May 2013 11:47:40 +0000 (20:47 +0900)
committerKrzysztof Sasiak <k.sasiak@samsung.com>
Thu, 16 Jan 2014 13:37:25 +0000 (14:37 +0100)
Change-Id: I83679966a90bcd9fd5c2c6e11edc3c5dfa091434
Signed-off-by: giyeol.ok <giyeol.ok@samsung.com>
CMakeLists.txt
src/core/common.h
src/mmc/ext4.c
src/mmc/mmc-handler.c
src/mmc/mmc-handler.h
src/mmc/vfat.c

index 233ff51..f771336 100755 (executable)
@@ -3,8 +3,8 @@ PROJECT(system_server C)
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(EXEC_PREFIX "${PREFIX}/bin")
-SET(INCLUDEDIR "${PREFIX}/include/${PROJECT_NAME}")
 SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "${PREFIX}/include/${PROJECT_NAME}")
 
 # deviced
 SET(DEVICED_NAME deviced)
@@ -29,7 +29,6 @@ SET(SRCS
        src/core/edbus-handler.c
        src/cpu/cpu-handler.c
        src/mmc/mmc-handler.c
-       src/mmc/ext4.c
        src/mmc/vfat.c
        src/power/power-handler.c
        src/proc/lowmem-handler.c
@@ -40,6 +39,13 @@ SET(SRCS
        src/usb/usb-handler.c
        src/vibrator/vibrator.c
 )
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" STREQUAL "emulated")
+SET(SRCS ${SRCS}
+       src/mmc/ext4.c
+       )
+ENDIF("${ARCH}" STREQUAL "emulated")
 
 SET(SRCS ${SRCS}
        src/display/util.c
index 691fcbc..2e30062 100644 (file)
 #include <unistd.h>
 
 #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
+#ifndef __CONSTRUCTOR__
+#define __CONSTRUCTOR__ __attribute__ ((constructor))
+#endif
 
+#ifndef __DESTRUCTOR__
+#define __DESTRUCTOR__ __attribute__ ((destructor))
+#endif
 #ifndef max
 #define max(a,b) ((a) > (b) ? (a) : (b))
 #endif
index 624d5a3..4af256d 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "mmc-handler.h"
+#include "core/common.h"
 
 #define FS_EXT4_SMACK_LABEL "mmc-smack-label "MMC_MOUNT_POINT
 
@@ -88,7 +89,7 @@ static int ext4_init(void *data)
        }
        /* check fs type with magic code */
        ret = lseek(fd, fs_ext4_type.offset, SEEK_SET);
-       if (ret != 0) {
+       if (ret < 0) {
                _E("fail to check offset of ext4");
                goto out;
        }
@@ -131,9 +132,14 @@ static const char **ext4_format(void *data)
        return ext4_arg;
 }
 
-const struct mmc_filesystem_ops ext4_ops = {
-       .init = ext4_init,
-       .check = ext4_check,
-       .mount = ext4_mount,
-       .format = ext4_format,
+static const struct mmc_filesystem_ops ext4_ops = {
+       ext4_init,
+       ext4_check,
+       ext4_mount,
+       ext4_format,
 };
+
+static void __CONSTRUCTOR__ ext4_register(void)
+{
+       register_mmc_handler("ext4", ext4_ops);
+}
index f95813d..a824545 100644 (file)
 
 #define MMC_32GB_SIZE           61315072
 
+#define get_mmc_fs(ptr, type, member) \
+((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+
+#define mmc_fs_search(pos, head) \
+for (pos = (head)->next; pos != (head); \
+pos = pos->next)
+
 typedef enum {
        FS_MOUNT_ERR = -1,
        FS_MOUNT_FAIL = 0,
@@ -71,14 +78,12 @@ static int mmc_popup_pid = 0;
 static enum mmc_fs_type inserted_type;
 static bool mmc_disabled = false;
 static char mmc_node[PATH_MAX];
-static const struct mmc_filesystem_ops *filesystem_type[] = {
-       &vfat_ops,
-       &ext4_ops,
-};
 
 static struct mmc_filesystem_ops *mmc_filesystem;
 
-static void __attribute__ ((constructor)) smack_check(void)
+static struct mmc_list mmc_handler_list = { &(mmc_handler_list), &(mmc_handler_list)};
+
+static void __CONSTRUCTOR__ smack_check(void)
 {
        struct statfs sfs;
        int ret;
@@ -92,6 +97,19 @@ static void __attribute__ ((constructor)) smack_check(void)
        _I("smackfs check %d", smack);
 }
 
+static void mmc_list_add(struct mmc_list *new, struct mmc_list *prev, struct mmc_list *next)
+{
+       next->prev = new;
+       new->next = next;
+       new->prev = prev;
+       prev->next = new;
+}
+
+static void mmc_fs_add(struct mmc_list *new, struct mmc_list *head)
+{
+       mmc_list_add(new, head->prev, head);
+}
+
 static int exec_process(const char **argv)
 {
        int pid;
@@ -232,38 +250,37 @@ static int mmc_umount(int option)
 
 static int mmc_check_fs_type(void)
 {
-       int ret, i;
-       struct mmc_filesystem_ops *filesystem;
+       int ret;
+       struct mmc_filesystem_info *filesystem = NULL;
+       struct mmc_list *tmp;
        inserted_type = FS_TYPE_NONE;
 
-       for (i = 0; i < ARRAY_SIZE(filesystem_type); i++) {
-               filesystem = filesystem_type[i];
-               if (!filesystem)
-                       continue;
-               ret = filesystem->init((void *)mmc_node);
+       mmc_fs_search(tmp, &mmc_handler_list) {
+               filesystem = get_mmc_fs(tmp, struct mmc_filesystem_info, list);
+               ret = filesystem->fs_ops->init((void *)mmc_node);
                if (ret == -EINVAL)
                        continue;
                inserted_type = ret;
-               mmc_filesystem = filesystem;
+               mmc_filesystem = filesystem->fs_ops;
                return 0;
        }
 
        if (inserted_type == FS_TYPE_NONE) {
                _D("set default file system");
                inserted_type = FS_TYPE_FAT;
-               mmc_filesystem = &vfat_ops;
-               if (!mmc_filesystem) {
-                       _E("fail to init mmc file system");
-                       return -EINVAL;
-               }
+               mmc_filesystem =  filesystem->fs_ops;
                mmc_filesystem->init((void *)mmc_node);
+               return 0;
        }
-       return 0;
+       _E("fail to init mmc file system");
+       return -EINVAL;
 }
 
 static int get_format_type(void)
 {
        unsigned int size;
+       struct mmc_list *tmp;
+       struct mmc_filesystem_info *filesystem = NULL;
 
        if (mmc_check_fs_type())
                return -EINVAL;
@@ -271,7 +288,8 @@ static int get_format_type(void)
        if (inserted_type == FS_TYPE_EXT4)
                return 0;
 
-       return 0;
+       _E("fail to init mmc file system");
+       return -EINVAL;
 }
 
 static int check_mount_state(void)
@@ -634,6 +652,45 @@ error:
        return r;
 }
 
+int register_mmc_handler(const char *name, const struct mmc_filesystem_ops filesystem_type)
+{
+       struct mmc_list *tmp;
+       struct mmc_filesystem_info *entry;
+
+       entry = malloc(sizeof(struct mmc_filesystem_info));
+
+       if (!entry) {
+               _E("Malloc failed");
+               return -1;
+       }
+
+       entry->name = strndup(name, strlen(name));
+
+       if (!entry->name) {
+               _E("Malloc failed");
+               free(entry);
+               return -1;
+       }
+
+       entry->fs_ops = malloc(sizeof(struct mmc_filesystem_ops));
+       if (!entry->fs_ops) {
+               _E("Malloc failed");
+               return -1;
+       }
+
+       entry->fs_ops->init = filesystem_type.init;
+       entry->fs_ops->check = filesystem_type.check;
+       entry->fs_ops->mount = filesystem_type.mount;
+       entry->fs_ops->format = filesystem_type.format;
+
+       mmc_fs_add(&entry->list, &mmc_handler_list);
+
+       mmc_fs_search(tmp, &mmc_handler_list) {
+               entry = get_mmc_fs(tmp, struct mmc_filesystem_info, list);
+       }
+       return 0;
+}
+
 static void mmc_init(void *data)
 {
        action_entry_add_internal(PREDEF_MOUNT_MMC, ss_mmc_inserted, NULL, NULL);
index 906f295..960df73 100644 (file)
 #define SMACKFS_MOUNT_OPT              "smackfsroot=*,smackfsdef=*"
 #define MMC_MOUNT_POINT                "/opt/storage/sdcard"
 
+struct mmc_list {
+struct mmc_list *prev, *next;
+};
+
 enum mmc_fs_type {
        FS_TYPE_NONE,
        FS_TYPE_FAT,
@@ -65,10 +69,13 @@ struct mmc_filesystem_ops {
        const char ** (*format) (void *data);
 };
 
-extern const struct mmc_filesystem_ops exfat_ops;
-extern const struct mmc_filesystem_ops vfat_ops;
-extern const struct mmc_filesystem_ops ext4_ops;
+struct mmc_filesystem_info {
+       char *name;
+       struct mmc_filesystem_ops *fs_ops;
+       struct mmc_list list;
+};
 
 int mount_fs(char *path, const char *fs_name, const char *mount_data);
+int register_mmc_handler(const char *name, struct mmc_filesystem_ops filesystem_type);
 
 #endif /* __MMC_HANDLER_H__ */
index 7b43c15..d4a930b 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "mmc-handler.h"
+#include "core/common.h"
 
 #define FS_VFAT_MOUNT_OPT  "uid=0,gid=0,dmask=0000,fmask=0111,iocharset=iso8859-1,utf8,shortname=mixed"
 
@@ -53,7 +54,7 @@ static int vfat_init(void *data)
        }
        /* check fs type with magic code */
        ret = lseek(fd, fs_vfat_type.offset, SEEK_SET);
-       if (ret != 0) {
+       if (ret < 0) {
                _E("fail to check offset of vfat");
                goto out;
        }
@@ -97,10 +98,15 @@ static const char **vfat_format(void *data)
        return vfat_arg;
 }
 
-const struct mmc_filesystem_ops vfat_ops = {
-       .init = vfat_init,
-       .check = vfat_check,
-       .mount = vfat_mount,
-       .format = vfat_format,
+static const struct mmc_filesystem_ops vfat_ops = {
+       vfat_init,
+       vfat_check,
+       vfat_mount,
+       vfat_format,
 };
 
+static void __CONSTRUCTOR__ vfat_register(void)
+{
+       register_mmc_handler("vfat", vfat_ops);
+}
+