common: apply Tizen Coding Rule
[platform/core/system/libstorage.git] / src / statvfs.c
index 81d323f..52e030c 100644 (file)
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <assert.h>
 #include <mntent.h>
+#include <tzplatform_config.h>
 
 #include "log.h"
 #include "common.h"
@@ -32,8 +33,7 @@
 #define MEMORY_GIGABYTE_VALUE  1073741824
 #define MEMORY_MEGABYTE_VALUE  1048576
 
-#define MEMORY_STATUS_USR_PATH "/opt/usr"
-#define EXTERNAL_MEMORY_PATH   "/opt/storage/sdcard"
+#define EXTERNAL_MEMORY_NODE   "sdcard"
 #define STORAGE_CONF_FILE      "/etc/storage/libstorage.conf"
 
 /* it's for 32bit file offset */
@@ -93,7 +93,7 @@ static inline char *trim_str(char *s)
 }
 
 static int config_parse(const char *file_name, int cb(struct parse_result *result,
-    void *user_data), void *user_data)
+                       void *user_data), void *user_data)
 {
        FILE *f = NULL;
        struct parse_result result;
@@ -192,7 +192,7 @@ static int load_config(struct parse_result *result, void *user_data)
        value = result->value;
 
        if (info->check_size > 0 && check_size < 0)
-               check_size = (storage_info.total_size < info->check_size)? 1 : 0;
+               check_size = (storage_info.total_size < info->check_size) ? 1 : 0;
        if (MATCH(name, "CHECK_SIZE"))
                info->check_size = atoi(value);
        else if (check_size == 0 && MATCH(name, "RESERVE"))
@@ -223,6 +223,8 @@ static int get_memory_size(const char *path, struct statvfs_32 *buf)
        if (ret)
                return -errno;
 
+       memset(buf, 0, sizeof(struct statvfs_32));
+
        buf->f_bsize  = s.f_bsize;
        buf->f_frsize = s.f_frsize;
        buf->f_blocks = (unsigned long)s.f_blocks;
@@ -249,7 +251,7 @@ API int storage_get_internal_memory_size(struct statvfs *buf)
                return -EINVAL;
        }
 
-       ret = get_memory_size(MEMORY_STATUS_USR_PATH, &temp);
+       ret = get_memory_size(tzplatform_getenv(TZ_SYS_HOME), &temp);
        if (ret || temp.f_bsize == 0) {
                _E("fail to get memory size");
                return -errno;
@@ -282,7 +284,7 @@ API int storage_get_internal_memory_size64(struct statvfs *buf)
                return -EINVAL;
        }
 
-       ret = statvfs(MEMORY_STATUS_USR_PATH, buf);
+       ret = statvfs(tzplatform_getenv(TZ_SYS_HOME), buf);
        if (ret) {
                _E("fail to get memory size");
                return -errno;
@@ -303,17 +305,17 @@ API int storage_get_internal_memory_size64(struct statvfs *buf)
        return 0;
 }
 
-static int mount_check(const charpath)
+static int mount_check(const char *path)
 {
        int ret = false;
-       struct mntentmnt;
-       const chartable = "/etc/mtab";
-       FILEfp;
+       struct mntent *mnt;
+       const char *table = "/etc/mtab";
+       FILE *fp;
 
        fp = setmntent(table, "r");
        if (!fp)
                return ret;
-       while ((mnt=getmntent(fp))) {
+       while ((mnt = getmntent(fp))) {
                if (!strcmp(mnt->mnt_dir, path)) {
                        ret = true;
                        break;
@@ -323,6 +325,12 @@ static int mount_check(const char* path)
        return ret;
 }
 
+static const char *get_external_path(void)
+{
+       return tzplatform_mkpath(TZ_SYS_MEDIA,
+                       EXTERNAL_MEMORY_NODE);
+}
+
 API int storage_get_external_memory_size(struct statvfs *buf)
 {
        struct statvfs_32 temp;
@@ -334,12 +342,12 @@ API int storage_get_external_memory_size(struct statvfs *buf)
                return -EINVAL;
        }
 
-       if (!mount_check(EXTERNAL_MEMORY_PATH)) {
+       if (!mount_check(get_external_path())) {
                memset(buf, 0, sizeof(struct statvfs_32));
                return 0;
        }
 
-       ret = get_memory_size(EXTERNAL_MEMORY_PATH, &temp);
+       ret = get_memory_size(get_external_path(), &temp);
        if (ret) {
                _E("fail to get memory size");
                return -errno;
@@ -359,12 +367,12 @@ API int storage_get_external_memory_size64(struct statvfs *buf)
                return -EINVAL;
        }
 
-       if (!mount_check(EXTERNAL_MEMORY_PATH)) {
+       if (!mount_check(get_external_path())) {
                memset(buf, 0, sizeof(struct statvfs));
                return 0;
        }
 
-       ret = statvfs(EXTERNAL_MEMORY_PATH, buf);
+       ret = statvfs(get_external_path(), buf);
        if (ret) {
                _E("fail to get memory size");
                return -errno;