block: Create default directory for mmc 62/172162/3
authorpr.jung <pr.jung@samsung.com>
Mon, 12 Mar 2018 08:59:35 +0000 (17:59 +0900)
committerpr.jung <pr.jung@samsung.com>
Tue, 13 Mar 2018 01:54:19 +0000 (10:54 +0900)
- Create default directories (Images, Videos, Sountds, Downloads) for primary sdcard

Change-Id: If3cb0d66ad41d13c05a00dfc85256f8eabafc8b3
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/block/block.c

index a6267af..7a11e3d 100644 (file)
@@ -41,6 +41,7 @@
 #include <libmount.h>
 #include <blkid/blkid.h>
 #include <ode/luks.h>
+#include <glib/gstdio.h>
 
 #include "log.h"
 #include "config-parser.h"
 
 #define ARRAY_SIZE(name)       (sizeof(name)/sizeof(name[0]))
 
+#define FILE_NAME_LEN_MAX      255
+
 enum block_dev_operation {
        BLOCK_DEV_MOUNT,
        BLOCK_DEV_UNMOUNT,
@@ -179,6 +182,15 @@ static struct manage_thread {
        bool start_th;
 } th_manager[THREAD_MAX];
 
+char mmc_default_path[][FILE_NAME_LEN_MAX + 1] = {
+       {"Images"},
+       {"Videos"},
+       {"Sounds"},
+       {"Downloads"},
+};
+
+#define DIR_NUM ((int)(sizeof(mmc_default_path)/sizeof(mmc_default_path[0])))
+
 static dd_list *fs_head;
 static dd_list *block_ops_list;
 static bool smack;
@@ -877,6 +889,30 @@ static const char *get_operation_char(enum block_dev_operation op)
        return "unknown";
 }
 
+void mmc_make_default_path(const char *mount_path)
+{
+       int i = 0;
+       int ret = 0;
+       char mmc_path[FILE_NAME_LEN_MAX + 1] = {0, };
+
+       for (i = 0; i < DIR_NUM; ++i) {
+               memset(mmc_path, 0, sizeof(mmc_path));
+               snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, mmc_default_path[i]);
+               if (!g_file_test(mmc_path, G_FILE_TEST_IS_DIR)) {
+                       _D("%s path did not exist", mmc_path);
+                       ret = mkdir(mmc_path, 0770);
+                       if (ret != 0)
+                               _E("mkdir failed: %d", errno);
+
+                       /*this fuction for emulator*/
+                       /*at the first time, the directroies are made permission 755*/
+                       ret = chmod(mmc_path, 0770);
+                       if (ret != 0)
+                               _E("chmod failed: %d", errno);
+               }
+       }
+}
+
 static void create_external_apps_directory(void)
 {
        int ret;
@@ -941,8 +977,10 @@ static bool pipe_cb(int fd, void *data)
        if (pdata.op == BLOCK_DEV_MOUNT &&
                pdata.bdev->data->state == BLOCK_MOUNT &&
                pdata.bdev->data->block_type == BLOCK_MMC_DEV &&
-               pdata.bdev->data->primary)
+               pdata.bdev->data->primary) {
                create_external_apps_directory();
+               mmc_make_default_path(pdata.bdev->data->mount_point);
+       }
        if (pdata.op == BLOCK_DEV_UNMOUNT) {
                /* Remove file for block device /run/xxxxxx/id */
                remove_file(pdata.bdev->data->id, pdata.bdev->data->block_type == BLOCK_EXTENDEDSD_DEV);