Change impl about get total / avaiable storage size 00/184700/2 accepted/tizen/unified/20180723.151434 submit/tizen/20180720.091301
authorJihoon Jung <jh8801.jung@samsung.com>
Fri, 20 Jul 2018 06:43:22 +0000 (15:43 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 20 Jul 2018 08:37:17 +0000 (17:37 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
Change-Id: Iaff928591797b98c5f66e7a5b74c11339d4b98ec

CMakeLists.txt
src/util/mtp_fs.c

index 2b384e2..87b74f9 100755 (executable)
@@ -23,7 +23,7 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -Werror-implicit-function-declaration")
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fexceptions -fvisibility=hidden")
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
-SET(CMAKE_EXE_LINKER_FLAGS " -Wl,--as-needed -pie -Wl,--hash-style=both,-z,relro")
+SET(CMAKE_EXE_LINKER_FLAGS " -Wl,--as-needed -pie -Wl,--hash-style=both,-z,relro")
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} pthread rt gcrypt)
index 4085c0e..5723dba 100755 (executable)
@@ -26,6 +26,7 @@
 #include <dirent.h>
 #include <glib.h>
 #include <glib/gprintf.h>
+#include <storage.h>
 #include "mtp_fs.h"
 #include "mtp_util.h"
 #include "mtp_support.h"
@@ -753,7 +754,8 @@ mtp_bool _util_ifind_next(mtp_char *dir_name, DIR *dirp, dir_entry_t *dir_info)
        return TRUE;
 }
 
-mtp_bool _util_get_filesystem_info(mtp_char *storepath, fs_info_t *fs_info)
+mtp_bool _util_get_filesystem_info_ext(mtp_char *storepath,
+       fs_info_t *fs_info)
 {
        struct statfs buf = { 0 };
        mtp_uint64 avail_size = 0;
@@ -761,7 +763,7 @@ mtp_bool _util_get_filesystem_info(mtp_char *storepath, fs_info_t *fs_info)
        mtp_uint64 used_size = 0;
 
        if (statfs(storepath, &buf) != 0) {
-               ERR("statfs Fail");
+               ERR("statfs is failed\n");
                return FALSE;
        }
 
@@ -778,6 +780,45 @@ mtp_bool _util_get_filesystem_info(mtp_char *storepath, fs_info_t *fs_info)
        return TRUE;
 }
 
+mtp_bool _util_get_filesystem_info_int(mtp_char *storepath, fs_info_t *fs_info)
+{
+       struct statvfs s;
+       int ret;
+
+       mtp_uint64 avail_size = 0;
+       mtp_uint64 capacity = 0;
+       mtp_uint64 used_size = 0;
+
+       ret = storage_get_internal_memory_size(&s);
+       if (ret < 0) {
+               ERR("storage_get_internal_memory_size : ret = %d", ret);
+               return FALSE;
+       }
+
+       capacity = (mtp_uint64)s.f_frsize*s.f_blocks;
+       avail_size = (mtp_uint64)s.f_bsize*s.f_bavail;
+       used_size = (capacity - avail_size);
+
+       DBG("total : %llu , avail %llu , used %llu", capacity, avail_size, used_size);
+
+       fs_info->disk_size = capacity;
+       fs_info->reserved_size = used_size;
+       fs_info->avail_size = avail_size;
+
+       return TRUE;
+}
+
+mtp_bool _util_get_filesystem_info(mtp_char *storepath,
+       fs_info_t *fs_info)
+{
+       if (!g_strcmp0(storepath, MTP_EXTERNAL_PATH_CHAR))
+               return _util_get_filesystem_info_ext(storepath, fs_info);
+       else
+               return _util_get_filesystem_info_int(storepath, fs_info);
+
+       return FALSE;
+}
+
 void _util_count_num_lines(FILE* fhandle, mtp_uint32 *num_lines)
 {
        if (fhandle == NULL)