get mount path of sdcard using storage api instead of hard-coded path. 92/80492/14 accepted/tizen/common/20160803.193225 accepted/tizen/ivi/20160804.080805 accepted/tizen/mobile/20160804.080856 accepted/tizen/tv/20160804.080722 accepted/tizen/wearable/20160804.080556 submit/tizen/20160803.012753
authorjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 18 Jul 2016 09:11:24 +0000 (18:11 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Thu, 28 Jul 2016 02:14:56 +0000 (11:14 +0900)
Change-Id: I37061efb63b430f771e8aa2fd00218675c9f429f
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
common/inc/app2ext_utils.h
plugin/app2sd/inc/app2sd_internals.h
plugin/app2sd/src/app2sd_interface.c
plugin/app2sd/src/app2sd_internals.c
plugin/app2sd/src/app2sd_internals_utils.c
src/app2ext_interface.c
test/src/test_app2ext.c

index 7dd62c7..7039f70 100644 (file)
@@ -53,8 +53,7 @@ extern "C" {
 #define OWNER_ROOT 0
 #define REGULAR_USER 5000
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-#define MMC_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1")
-#define APP2SD_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1/app2sd")
+#define EXTIMG_DIR "app2sd"
 
 #define APP2SD_BUS_NAME "org.tizen.app2sd"
 #define APP2SD_OBJECT_PATH "/org/tizen/app2sd"
index 7fbf09f..05f5130 100644 (file)
@@ -71,101 +71,102 @@ typedef enum mount_type_t {
        MOUNT_TYPE_RW_REMOUNT
 } mount_type;
 
-/*Checks whether mmc is present or not*/
-int _app2sd_check_mmc_status(void);
+/* checks whether mmc is present or not */
+/* sd_path should be freed after use */
+int _app2sd_check_mmc_status(char **sd_path);
 
-/*this function is similar to system()*/
+/* this function is similar to system() */
 int _xsystem(const char *argv[]);
 
-/*this function will return the free available memory on the SD Card*/
-int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem);
+/* this function will return the free available memory on the SD Card */
+int _app2sd_get_available_free_memory(char *mmc_path, int *free_mem);
 
-/*Function to move the application from/to SD Card*/
+/* function to move the application from/to SD Card */
 int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_cmd,
-               GList *dir_list, uid_t uid);
+               GList *dir_list, uid_t uid, char *mmc_path);
 
-/*utility to delete symbolic link*/
+/* utility to delete symbolic link */
 void _app2sd_delete_symlink(const char *dirname);
 
-/*utility to calculate the size of a directory in MB*/
+/* utility to calculate the size of a directory in MB */
 unsigned long long _app2sd_calculate_dir_size(char *dirname);
 
-/*utility to calculate the size of a file in MB*/
+/* utility to calculate the size of a file in MB */
 unsigned long long _app2sd_calculate_file_size(const char *filename);
 
-/*Utility to copy a directory*/
+/* utility to copy a directory */
 int _app2sd_copy_dir(const char *src, const char *dest);
 
-/*Utility to rename a directory*/
+/* utility to rename a directory */
 int _app2sd_rename_dir(const char *old_name, const char *new_name);
 
-/* Utility to create symlinks */
+/* utility to create symlinks */
 int _app2sd_create_symlink(char *pkgid);
 
-/*This function finds the associated device node for the app*/
+/* this function finds the associated device node for the app */
 char *_app2sd_find_associated_device_node(const char *loopback_device);
 
-/*This function does the loopback encryption for app*/
+/* this function does the loopback encryption for app */
 char *_app2sd_do_loopback_encryption_setup(const char *pkgid,
                const char *loopback_device, uid_t uid);
 
-/*This function detaches the loopback device*/
+/* this function detaches the loopback device */
 char *_app2sd_detach_loop_device(const char *device);
 
-/*This function finds loopback device associated with the app*/
+/* this function finds loopback device associated with the app */
 char *_app2sd_find_associated_device(const char *loopback_device);
 
-/*This function creates loopback device*/
+/* this function creates loopback device */
 int _app2sd_create_loopback_device(const char *pkgid,
                const char *loopback_device, int size);
 
-/*This function deletes loopback device associated with the app*/
+/* this function deletes loopback device associated with the app */
 int _app2sd_delete_loopback_device(const char *loopback_device);
 
-/*This function creates ext4 FS on the device path*/
+/* this function creates ext4 FS on the device path */
 int _app2sd_create_file_system(const char *device_path);
 
-/*This function mounts the app content on the device node*/
+/* this function mounts the app content on the device node */
 int _app2sd_mount_app_content(const char *application_path, const char *pkgid,
                const char *dev, int mount_type, GList* dir_list,
                app2sd_cmd cmd, uid_t uid);
 
-/*This function unmounts the app content */
+/* this function unmounts the app content */
 int _app2sd_unmount_app_content(const char *application_path);
 
-/*This function removes the loopbck encryption setup for the app*/
+/* this function removes the loopbck encryption setup for the app */
 int _app2sd_remove_loopback_encryption_setup(const char *loopback_device);
 
-/*This function removes all of loopbck encryption setup for the app*/
+/* this function removes all of loopbck encryption setup for the app */
 int _app2sd_remove_all_loopback_encryption_setups(const char *loopback_device);
 
-/*This function updates loopback device size*/
+/* this function updates loopback device size */
 int _app2sd_update_loopback_device_size(const char *pkgid,
                const char *loopback_device, const char *application_path,
                const char *temp_pkgid, const char *temp_loopback_device,
                const char *temp_application_path, int size, GList* dir_list,
                uid_t uid);
 
-/* This generates password */
+/* this generates password */
 char *_app2sd_generate_password(const char *pkgid);
 
-/*This function encrypts device*/
+/* this function encrypts device */
 char *_app2sd_encrypt_device(const char *device, const char *loopback_device,
                char *passwd);
 
-/*This function finds free device*/
+/* this function finds free device */
 char *_app2sd_find_free_device(void);
 
-/*This function initializes app2sd DB*/
+/* this function initializes app2sd DB */
 int _app2sd_initialize_db();
 
-/*This function is used to get password from db*/
+/* this function is used to get password from db */
 char *_app2sd_get_password_from_db(const char *pkgid, uid_t uid);
 
-/*This function removes info from db */
+/* this function removes info from db */
 int _app2sd_remove_info_from_db(const char *pkgid, uid_t uid);
 
-/* This functions save info in db */
+/* this functions save info in db */
 int _app2sd_set_info_in_db(const char *pkgid, const char *passwd,
                const char *loopback_device, uid_t uid);
 
@@ -179,18 +180,18 @@ int _app2sd_force_clean(const char *pkgid, const char *application_path,
                const char *loopback_device, uid_t uid);
 
 #ifdef TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION
-/*This function setup dmcrypt header in the app2sd file */
+/* this function setup dmcrypt header in the app2sd file */
 int _app2sd_dmcrypt_setup_device(const char *pkgid,
                const char *loopback_device, bool is_dup, uid_t uid);
 
-/*This function maps the app2sd file with a dmcrypt device node */
+/* this function maps the app2sd file with a dmcrypt device node */
 int _app2sd_dmcrypt_open_device(const char *pkgid, const char *loopback_device,
                bool is_dup, uid_t uid, char **dev_node);
 
-/*This function remove dmcrypt device node */
+/* this function remove dmcrypt device node */
 int _app2sd_dmcrypt_close_device(const char *pkgid, uid_t uid);
 
-/*This function find associated dmcrypt device node */
+/* this function find associated dmcrypt device node */
 char *_app2sd_find_associated_dmcrypt_device_node(const char *pkgid, uid_t uid);
 #endif
 
index e769a9d..ecfc3a7 100644 (file)
 
 #include "app2sd_internals.h"
 
-static int __app2sd_create_app2sd_directories(uid_t uid)
+static int __app2sd_create_app2sd_directories(uid_t uid, char *mmc_path)
 {
        int ret = 0;
+       char app2sd_path[FILENAME_MAX] = { 0, };
        mode_t mode = DIR_PERMS;
 
-       ret = mkdir(APP2SD_PATH, mode);
+       snprintf(app2sd_path, FILENAME_MAX - 1, "%s/%s",
+                       mmc_path, EXTIMG_DIR);
+       ret = mkdir(app2sd_path, mode);
        if (ret) {
                if (errno != EEXIST) {
                        _E("create directory failed," \
@@ -47,10 +50,13 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList *dir_list, int size, uid
 {
        int ret = 0;
        int free_mmc_mem = 0;
+       char *sdpath = NULL;
        char *device_node = NULL;
 #if !defined(TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION)
        char *devi = NULL;
+       char *result = NULL;
 #endif
+       char mmc_path[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
        char *encoded_id = NULL;
@@ -63,17 +69,19 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList *dir_list, int size, uid
        }
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
-               _E("MMC not preset OR Not ready (%d)", ret);
+               _E("MMC not present OR Not ready (%d)", ret);
                return APP2EXT_ERROR_MMC_STATUS;
        }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
+       sync();
 
        /* find available free memory in the MMC card */
-       ret = _app2sd_get_available_free_memory(MMC_PATH, &free_mmc_mem);
+       ret = _app2sd_get_available_free_memory(mmc_path, &free_mmc_mem);
        if (ret) {
-               _E("unable to get available free memory in MMC (%d)",
-                       ret);
+               _E("unable to get available free memory in MMC (%d)", ret);
                return APP2EXT_ERROR_MMC_STATUS;
        }
        _D("size details for application installation:" \
@@ -96,19 +104,19 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList *dir_list, int size, uid
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
 
-       ret = __app2sd_create_app2sd_directories(uid);
+       ret = __app2sd_create_app2sd_directories(uid, mmc_path);
        if (ret) {
                _E("failed to create app2sd dirs");
                return ret;
@@ -206,6 +214,7 @@ END:
        }
 #endif
 
+       sync();
        return ret;
 }
 
@@ -213,6 +222,8 @@ int app2sd_usr_post_app_install(const char *pkgid,
                app2ext_status install_status, uid_t uid)
 {
        char *device_name = NULL;
+       char *sdpath = NULL;
+       char mmc_path[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char application_mmc_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
@@ -228,11 +239,13 @@ int app2sd_usr_post_app_install(const char *pkgid,
        }
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
                _E("MMC not present OR Not ready (%d)", ret);
                return APP2EXT_ERROR_MMC_STATUS;
        }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
        sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
@@ -242,14 +255,14 @@ int app2sd_usr_post_app_install(const char *pkgid,
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
@@ -337,14 +350,17 @@ int app2sd_usr_post_app_install(const char *pkgid,
                }
        }
 
+       sync();
        return ret;
 }
 
 int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
+       char mmc_path[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *sdpath = NULL;
        char *encoded_id = NULL;
        char *device_node = NULL;
 #if !defined(TIZEN_FEATURE_APP2SD_DMCRYPT_ENCRYPTION)
@@ -359,11 +375,13 @@ int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
        }
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
-               _E("MMC not preset OR Not ready (%d)", ret);
+               _E("MMC not present OR Not ready (%d)", ret);
                return APP2EXT_ERROR_MMC_STATUS;
        }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
@@ -373,14 +391,14 @@ int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
@@ -509,8 +527,10 @@ static int _app2sd_kill_running_app(const char *pkgid, uid_t uid)
 int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
+       char mmc_path[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *sdpath = NULL;
        char *encoded_id = NULL;
        FILE *fp = NULL;
        int mmc_present = 1;
@@ -524,11 +544,13 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
        _app2sd_kill_running_app(pkgid, uid);
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
-               _W("MMC not preset OR Not ready (%d)", ret);
+               _W("MMC not present OR Not ready (%d)", ret);
                mmc_present = 0;
        }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
@@ -538,14 +560,14 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
@@ -583,8 +605,10 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
 int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
+       char mmc_path[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *sdpath = NULL;
        char *encoded_id = NULL;
        char *device_node = NULL;
        FILE *fp = NULL;
@@ -597,12 +621,15 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
        }
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
-               _E("MMC not preset OR Not ready (%d)", ret);
+               _E("MMC not present OR Not ready (%d)", ret);
                ret = APP2EXT_ERROR_MMC_STATUS;
                goto END;
        }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
+       sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
@@ -611,14 +638,14 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
@@ -691,14 +718,17 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
        }
 
 END:
+       sync();
        return ret;
 }
 
 int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
 {
+       char mmc_path[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char application_mmc_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *sdpath = NULL;
        char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
 
@@ -710,12 +740,15 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
        }
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
-               _E("MMC not preset OR Not ready (%d)", ret);
+               _E("MMC not present OR Not ready (%d)", ret);
                ret = APP2EXT_ERROR_MMC_STATUS;
                goto END;
        }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
+       sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
@@ -724,14 +757,14 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
@@ -796,6 +829,7 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
        }
 
 END:
+       sync();
        return ret;
 }
 
@@ -804,6 +838,8 @@ int app2sd_usr_pre_move_installed_app(const char *pkgid,
 {
        int ret = 0;
        int pkgmgr_ret = 0;
+       char *sdpath = NULL;
+       char mmc_path[FILENAME_MAX] = { 0, };
 
        /* validate function arguments */
        if (pkgid == NULL || dir_list == NULL
@@ -813,13 +849,23 @@ int app2sd_usr_pre_move_installed_app(const char *pkgid,
                return APP2EXT_ERROR_INVALID_ARGUMENTS;
        }
 
-       ret = __app2sd_create_app2sd_directories(uid);
+       /* check whether MMC is present or not */
+       ret = _app2sd_check_mmc_status(&sdpath);
+       if (ret) {
+               _E("MMC not present OR Not ready(%d)", ret);
+               return APP2EXT_ERROR_MMC_STATUS;
+       }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
+       sync();
+
+       ret = __app2sd_create_app2sd_directories(uid, mmc_path);
        if (ret) {
                _E("failed to create app2sd dirs");
                return ret;
        }
 
-       ret = _app2sd_usr_move_app(pkgid, move_type, dir_list, uid);
+       ret = _app2sd_usr_move_app(pkgid, move_type, dir_list, uid, mmc_path);
        if (ret) {
                _D("unable to move application");
                return ret;
@@ -854,8 +900,10 @@ int app2sd_usr_post_move_installed_app(const char *pkgid,
                app2ext_move_type move_type, uid_t uid)
 {
        int ret = 0;
+       char mmc_path[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *sdpath = NULL;
        char *encoded_id = NULL;
 
        /* validate function arguments */
@@ -869,18 +917,21 @@ int app2sd_usr_post_move_installed_app(const char *pkgid,
                return APP2EXT_SUCCESS;
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
-               _E("MMC not preset OR Not ready(%d)", ret);
+               _E("MMC not present OR Not ready(%d)", ret);
                return APP2EXT_ERROR_MMC_STATUS;
        }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
+       sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
 
-       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        free(encoded_id);
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
@@ -915,9 +966,11 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                int size, uid_t uid)
 {
        int ret = APP2EXT_SUCCESS;
+       char app2sd_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char temp_uid[32] = { 0, };
+       char *sdpath = NULL;
        char *temp_pkgid = NULL;
        char *temp_loopback_device = NULL;
        char *temp_application_path = NULL;
@@ -936,11 +989,15 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
        }
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
-               _E("MMC not preset OR Not ready (%d)", ret);
+               _E("MMC not present OR Not ready (%d)", ret);
                return APP2EXT_ERROR_MMC_STATUS;
        }
+       snprintf(app2sd_path, FILENAME_MAX - 1, "%s/%s",
+                       sdpath, EXTIMG_DIR);
+       free(sdpath);
+       sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
@@ -950,13 +1007,13 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+                       app2sd_path, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+                       app2sd_path, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
@@ -1002,7 +1059,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                                free(temp_application_path);
                                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                        }
-                       len = strlen(APP2SD_PATH) + strlen(temp_encoded_id) + 1;
+                       len = strlen(app2sd_path) + strlen(temp_encoded_id) + 1;
                        temp_loopback_device = calloc(len + 1, sizeof(char));
                        if (temp_loopback_device == NULL) {
                                _E("memory alloc failed");
@@ -1012,7 +1069,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                        }
                        snprintf(temp_loopback_device, len + 1, "%s/%s",
-                               APP2SD_PATH, temp_encoded_id);
+                               app2sd_path, temp_encoded_id);
                        free(temp_encoded_id);
                } else {
                        tzplatform_set_user(uid);
@@ -1033,7 +1090,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                        }
                        snprintf(temp_uid, 32, "%d", uid);
-                       len = strlen(APP2SD_PATH) + strlen(temp_uid) + strlen(temp_encoded_id) + 2;
+                       len = strlen(app2sd_path) + strlen(temp_uid) + strlen(temp_encoded_id) + 2;
                        temp_loopback_device = calloc(len + 1, sizeof(char));
                        if (temp_loopback_device == NULL) {
                                _E("memory alloc failed");
@@ -1043,7 +1100,7 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
                        }
                        snprintf(temp_loopback_device, len + 1, "%s/%s",
-                               APP2SD_PATH, temp_encoded_id);
+                               app2sd_path, temp_encoded_id);
                        free(temp_encoded_id);
                        tzplatform_reset_user();
                }
@@ -1116,15 +1173,19 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList *dir_list,
                free(device_node);
                device_node = NULL;
        }
+
+       sync();
        return ret;
 }
 
 int app2sd_usr_post_app_upgrade(const char *pkgid,
                app2ext_status install_status, uid_t uid)
 {
-       char *device_name = NULL;
+       char mmc_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
+       char *sdpath = NULL;
+       char *device_name = NULL;
        char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
 
@@ -1136,11 +1197,14 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
        }
 
        /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
+       ret = _app2sd_check_mmc_status(&sdpath);
        if (ret) {
-               _E("MMC not preset OR Not ready (%d)", ret);
+               _E("MMC not present OR Not ready (%d)", ret);
                return APP2EXT_ERROR_MMC_STATUS;
        }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
+       sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
@@ -1149,14 +1213,14 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
@@ -1214,13 +1278,16 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
                device_name = NULL;
        }
 
+       sync();
        return ret;
 }
 
 int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
 {
+       char mmc_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
+       char *sdpath = NULL;
        char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
 
@@ -1230,6 +1297,14 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
                return APP2EXT_ERROR_INVALID_ARGUMENTS;
        }
 
+       /* check whether MMC is present or not */
+       ret = _app2sd_check_mmc_status(&sdpath);
+       if (ret) {
+               _E("MMC not present OR Not ready (%d)", ret);
+               return APP2EXT_ERROR_MMC_STATUS;
+       }
+       snprintf(mmc_path, FILENAME_MAX - 1, "%s", sdpath);
+       free(sdpath);
        sync();
 
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
@@ -1239,20 +1314,21 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
                tzplatform_reset_user();
        }
        free(encoded_id);
 
        ret = _app2sd_force_clean(pkgid, application_path, loopback_device, uid);
 
+       sync();
        return ret;
 }
 
@@ -1261,14 +1337,26 @@ int app2sd_enable_full_pkg(void)
        int ret = APP2EXT_SUCCESS;
        int rc = 0;
        char buf[FILENAME_MAX] = { 0, };
+       char app2sd_path[FILENAME_MAX] = { 0, };
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *sdpath = NULL;
+       char *pkgid = NULL;
        DIR *dir = NULL;
        struct dirent entry;
        struct dirent *result = NULL;
-       char *pkgid = NULL;
        uid_t uid = 0;
 
-       dir = opendir(APP2SD_PATH);
+       /* check whether MMC is present or not */
+       ret = _app2sd_check_mmc_status(&sdpath);
+       if (ret) {
+               _E("MMC not present OR Not ready (%d)", ret);
+               return APP2EXT_ERROR_MMC_STATUS;
+       }
+       snprintf(app2sd_path, FILENAME_MAX - 1, "%s/%s",
+                       sdpath, EXTIMG_DIR);
+       free(sdpath);
+
+       dir = opendir(app2sd_path);
        if (!dir) {
                strerror_r(errno, buf, sizeof(buf));
                _E("failed to opendir (%s)", buf);
@@ -1289,7 +1377,7 @@ int app2sd_enable_full_pkg(void)
                        strcmp(entry.d_name, "..") == 0)
                        continue;
                snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, entry.d_name);
+                       app2sd_path, entry.d_name);
                ret = _app2sd_get_info_from_db(loopback_device,
                        &pkgid, &uid);
                if (ret) {
@@ -1314,6 +1402,7 @@ int app2sd_enable_full_pkg(void)
        }
        closedir(dir);
 
+       sync();
        return ret;
 }
 
@@ -1345,5 +1434,6 @@ int app2sd_disable_full_pkg(void)
        if (ret)
                _E("disable full pkg error(%d)", ret);
 
+       sync();
        return ret;
 }
index 4b90113..b2cba3e 100644 (file)
@@ -848,7 +848,8 @@ static int _app2sd_move_to_archive(const char *src_path, const char *arch_path)
        return ret;
 }
 
-int _app2sd_move_app_to_external(const char *pkgid, GList *dir_list, uid_t uid)
+static int _app2sd_move_app_to_external(const char *pkgid, GList *dir_list,
+               uid_t uid, char *mmc_path)
 {
        int ret = APP2EXT_SUCCESS;
        mode_t mode = DIR_PERMS;
@@ -871,19 +872,12 @@ int _app2sd_move_app_to_external(const char *pkgid, GList *dir_list, uid_t uid)
        char err_buf[1024] = { 0,};
        char *encoded_id = NULL;
 
-       /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
-       if (ret) {
-               _E("MMC not preset OR Not ready(%d)", ret);
-               return APP2EXT_ERROR_MMC_STATUS;
-       }
-
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
 
-       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        free(encoded_id);
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
@@ -948,7 +942,7 @@ int _app2sd_move_app_to_external(const char *pkgid, GList *dir_list, uid_t uid)
        reqd_disk_size = reqd_size + ceil(reqd_size * 0.2);
 
        /* find avialable free memory in the MMC card */
-       ret = _app2sd_get_available_free_memory(MMC_PATH, &free_mmc_mem);
+       ret = _app2sd_get_available_free_memory(mmc_path, &free_mmc_mem);
        if (ret) {
                _E("unable to get available free memory in MMC (%d)", ret);
                return APP2EXT_ERROR_MMC_STATUS;
@@ -1102,7 +1096,8 @@ ERR:
        return ret;
 }
 
-int _app2sd_move_app_to_internal(const char *pkgid, GList *dir_list, uid_t uid)
+static int _app2sd_move_app_to_internal(const char *pkgid, GList *dir_list,
+               uid_t uid, char *mmc_path)
 {
        int ret = APP2EXT_SUCCESS;
        mode_t mode = DIR_PERMS;
@@ -1122,19 +1117,12 @@ int _app2sd_move_app_to_internal(const char *pkgid, GList *dir_list, uid_t uid)
        char err_buf[1024] = {0,};
        char *encoded_id = NULL;
 
-       /* check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
-       if (ret) {
-               _E("MMC not preset OR Not ready(%d)", ret);
-               return APP2EXT_ERROR_MMC_STATUS;
-       }
-
        encoded_id = _app2sd_get_encoded_name(pkgid, uid);
        if (encoded_id == NULL)
                return APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
 
-       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, encoded_id);
+       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
+                       mmc_path, EXTIMG_DIR, encoded_id);
        free(encoded_id);
        if (_is_global(uid)) {
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
@@ -1378,27 +1366,22 @@ ERR:
 }
 
 int _app2sd_usr_move_app(const char *pkgid, app2ext_move_type move_type,
-               GList *dir_list, uid_t uid)
+               GList *dir_list, uid_t uid, char *mmc_path)
 {
        int ret = APP2EXT_SUCCESS;
 
-       /* Check whether MMC is present or not */
-       ret = _app2sd_check_mmc_status();
-       if (ret) {
-               _E("MMC not preset OR Not ready(%d)", ret);
-               return APP2EXT_ERROR_MMC_STATUS;
-       }
-
        switch (move_type) {
        case APP2EXT_MOVE_TO_EXT:
-               ret = _app2sd_move_app_to_external(pkgid, dir_list, uid);
+               ret = _app2sd_move_app_to_external(pkgid, dir_list,
+                       uid, mmc_path);
                if (ret) {
                        _E("move app to external memory failed(%d)", ret);
                        return ret;
                }
                break;
        case APP2EXT_MOVE_TO_PHONE:
-               ret = _app2sd_move_app_to_internal(pkgid, dir_list, uid);
+               ret = _app2sd_move_app_to_internal(pkgid, dir_list,
+                       uid, mmc_path);
                if (ret) {
                        _E("move app to internal memory failed(%d)", ret);
                        return ret;
index f0cd8f2..1640af3 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <dirent.h>
 #include <time.h>
+#include <storage-internal.h>
 
 #include "app2sd_internals.h"
 
@@ -75,32 +76,36 @@ int _xsystem(const char *argv[])
 
 
 /*
- * @_app2sd_check_mmc_status
  * This function checks and returns MMC status
  */
-/* TODO : another possible way ? */
-int _app2sd_check_mmc_status(void)
+int _app2sd_check_mmc_status(char **sdpath)
 {
-       FILE *fp1 = NULL;
-       char line[512];
-       fp1 = fopen("/etc/mtab", "r");
-       if (fp1 == NULL) {
-               fprintf(stderr, "failed to open file\n");
-               _E("failed to open file /etc/mtab");
+       int ret = 0;
+       int storage_id = 0;
+       char *sd_mount_path = NULL;
+
+       ret = storage_get_primary_sdcard(&storage_id, &sd_mount_path);
+       if (ret != STORAGE_ERROR_NONE) {
+               _E("failed to get primary sdcard (%d)", ret);
+               if (sd_mount_path)
+                       free(sd_mount_path);
                return APP2EXT_ERROR_MMC_STATUS;
        }
-       while (fgets(line, 512, fp1) != NULL) {
-               if (strstr(line, MMC_PATH) != NULL) {
-                       fclose(fp1);
-                       return APP2EXT_SUCCESS;
-               }
+       if (sd_mount_path) {
+               _D("primary sdcard: id(%d), mount_path(%s)",
+                       storage_id, sd_mount_path);
+               *sdpath = sd_mount_path;
+               return APP2EXT_SUCCESS;
        }
-       fclose(fp1);
+
+       _E("there is no primary sdcard");
+       if (sd_mount_path)
+               free(sd_mount_path);
+
        return APP2EXT_ERROR_MMC_STATUS;
 }
 
 /*
- * @_app2sd_get_available_free_memory
  * This function returns the available free memory in the SD Card.
  * param [in]: sd_path: This is sd card access path.
  * param [out]: free_mem: Result will be available in this.
@@ -108,20 +113,20 @@ int _app2sd_check_mmc_status(void)
  * return: On success, it will return 0.
  * Else, appropriate error no will be returned.
  */
-int _app2sd_get_available_free_memory(const char *sd_path, int *free_mem)
+int _app2sd_get_available_free_memory(char *mmc_path, int *free_mem)
 {
        struct statvfs buf;
        int ret = 0;
        unsigned long long temp = 0;
 
-       if (sd_path == NULL || free_mem == NULL) {
+       if (mmc_path == NULL || free_mem == NULL) {
                _E("invalid input parameter");
                return -1;
        }
 
        memset((void *)&buf, '\0', sizeof(struct statvfs));
 
-       ret = statvfs(sd_path, &buf);
+       ret = statvfs(mmc_path, &buf);
        if (ret) {
                _E("unable to get SD Card memory information");
                return APP2EXT_ERROR_MMC_INFORMATION;
index 6595282..3407a7a 100644 (file)
@@ -107,10 +107,7 @@ int app2ext_deinit(app2ext_handle *handle)
 
 int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
 {
-       FILE *fp = NULL;
        app2ext_handle *handle = NULL;
-       char loopback_device[FILENAME_MAX] = { 0, };
-       char *encoded_id = NULL;
 
        /* validate the function parameter received */
        if (pkgid == NULL) {
@@ -118,30 +115,15 @@ int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
                return -1;
        }
 
-       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL)
+       handle = app2ext_init(APP2EXT_SD_CARD);
+       if (handle == NULL) {
+               _E("app2ext init failed");
                return -1;
-
-       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-               APP2SD_PATH, encoded_id);
-       free(encoded_id);
-
-       /* check whether application is in external memory or not */
-       fp = fopen(loopback_device, "r");
-       if (fp != NULL) {
-               fclose(fp);
-               fp = NULL;
-
-               handle = app2ext_init(APP2EXT_SD_CARD);
-               if (handle == NULL) {
-                       _E("app2ext init failed");
-                       return -1;
-               }
-
-               handle->interface.client_usr_enable(pkgid, uid);
-               app2ext_deinit(handle);
        }
 
+       handle->interface.client_usr_enable(pkgid, uid);
+       app2ext_deinit(handle);
+
        return 0;
 }
 
@@ -156,10 +138,7 @@ int app2ext_enable_external_pkg(const char *pkgid)
 
 int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
 {
-       FILE *fp = NULL;
        app2ext_handle *handle = NULL;
-       char loopback_device[FILENAME_MAX] = { 0, };
-       char *encoded_id = NULL;
 
        /* validate the function parameter received */
        if (pkgid == NULL) {
@@ -167,29 +146,13 @@ int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
                return -1;
        }
 
-       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
-       if (encoded_id == NULL)
+       handle = app2ext_init(APP2EXT_SD_CARD);
+       if (handle == NULL) {
+               _E("app2ext init failed");
                return -1;
-
-       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-               APP2SD_PATH, encoded_id);
-       free(encoded_id);
-
-       /* check whether application is in external memory or not */
-       fp = fopen(loopback_device, "r");
-       if (fp != NULL) {
-               fclose(fp);
-               fp = NULL;
-
-               handle = app2ext_init(APP2EXT_SD_CARD);
-               if (handle == NULL) {
-                       _E("app2ext init failed");
-                       return -1;
-               }
-
-               handle->interface.client_usr_disable(pkgid, uid);
-               app2ext_deinit(handle);
        }
+       handle->interface.client_usr_disable(pkgid, uid);
+       app2ext_deinit(handle);
 
        return 0;
 }
index 5c7c85b..737d486 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/types.h>
 #include <getopt.h>
 #include <unzip.h>
+#include <storage-internal.h>
 
 #include "app2ext_interface.h"
 #include "app2ext_utils.h"
@@ -504,6 +505,8 @@ int main(int argc, char **argv)
        int ret = 0;
        int opt_idx = 0;
        int c;
+       int storage_id = 0;
+       char *sd_mount_path = NULL;
        uid_t uid = getuid();
 
        /* check user */
@@ -516,6 +519,22 @@ int main(int argc, char **argv)
                printf("test for user(%d) app\n", uid);
        }
 
+       /* check sdcard info */
+       ret = storage_get_primary_sdcard(&storage_id, &sd_mount_path);
+       if (ret != STORAGE_ERROR_NONE) {
+               printf("failed to get primary sdcard (%d)\n", ret);
+               if (sd_mount_path)
+                       free(sd_mount_path);
+               return -1;
+       }
+       if (sd_mount_path) {
+               printf("primary sdcard: id(%d), mount_path(%s)\n",
+               storage_id, sd_mount_path);
+               free(sd_mount_path);
+       } else {
+               printf("there is no primary sdcard\n");
+       }
+
        handle = app2ext_init(APP2EXT_SD_CARD);
        if (handle == NULL) {
                ret = APP2EXT_ERROR_PLUGIN_INIT_FAILED;