Modify storage_get_storage_level
[platform/core/system/libstorage.git] / src / statvfs.c
index dd038af..99ed755 100644 (file)
 #define EXTERNAL_MEMORY_NODE   "sdcard"
 #define STORAGE_CONF_FILE      "/etc/storage/libstorage.conf"
 
-/* it's for 32bit file offset */
-struct statvfs_32 {
-       unsigned long int f_bsize;
-       unsigned long int f_frsize;
-       unsigned long int f_blocks;
-       unsigned long int f_bfree;
-       unsigned long int f_bavail;
-       unsigned long int f_files;
-       unsigned long int f_ffree;
-       unsigned long int f_favail;
-       unsigned long int f_fsid;
-#ifdef _STATVFSBUF_F_UNUSED
-       int __f_unused;
-#endif
-       unsigned long int f_flag;
-       unsigned long int f_namemax;
-       int __f_spare[6];
-};
 
 #define MAX_LINE    128
 #define MAX_SECTION 64
@@ -112,7 +94,7 @@ static int config_parse(const char *file_name, int cb(struct parse_result *resul
        /* open conf file */
        f = fopen(file_name, "r");
        if (!f) {
-               _E("Failed to open file %s", file_name);
+               _E("Failed to open file %s", file_name); //LCOV_EXCL_LINE
                ret = -EIO;
                goto error;
        }
@@ -172,7 +154,7 @@ static int config_parse(const char *file_name, int cb(struct parse_result *resul
 error:
        if (f)
                fclose(f);
-       _E("Failed to read %s:%d!", file_name, lineno);
+       _E("Failed to read %s:%d!", file_name, lineno); //LCOV_EXCL_LINE
        return ret;
 }
 
@@ -210,7 +192,7 @@ static void storage_config_load(struct storage_config_info *info)
 
        ret = config_parse(STORAGE_CONF_FILE, load_config, info);
        if (ret < 0)
-               _E("Failed to load %s, %d Use default value!", STORAGE_CONF_FILE, ret);
+               _E("Failed to load %s, %d Use default value!", STORAGE_CONF_FILE, ret); //LCOV_EXCL_LINE
 }
 
 static int get_memory_size(const char *path, struct statvfs_32 *buf)
@@ -222,7 +204,7 @@ static int get_memory_size(const char *path, struct statvfs_32 *buf)
 
        ret = statvfs(path, &s);
        if (ret)
-               return -errno;
+               return -errno; //LCOV_EXCL_LINE System Error
 
        memset(buf, 0, sizeof(struct statvfs_32));
 
@@ -252,10 +234,10 @@ API int storage_get_internal_memory_size(struct statvfs *buf)
                return -EINVAL;
        }
 
-       ret = get_memory_size(tzplatform_getenv(TZ_SYS_HOME), &temp);
+       ret = get_memory_size(tzplatform_getenv(TZ_SYS_USER), &temp);
        if (ret || temp.f_bsize == 0) {
-               _E("fail to get memory size");
-               return -errno;
+               _E("fail to get memory size %d", ret); //LCOV_EXCL_LINE
+               return -errno; //LCOV_EXCL_LINE System Error
        }
 
        if (reserved == 0) {
@@ -281,14 +263,14 @@ API int storage_get_internal_memory_size64(struct statvfs *buf)
        int ret;
 
        if (!buf) {
-               _E("input param error");
+               _E("input param error"); //LCOV_EXCL_LINE
                return -EINVAL;
        }
 
-       ret = statvfs(tzplatform_getenv(TZ_SYS_HOME), buf);
+       ret = statvfs(tzplatform_getenv(TZ_SYS_USER), buf);
        if (ret) {
-               _E("fail to get memory size");
-               return -errno;
+               _E("fail to get memory size"); //LCOV_EXCL_LINE
+               return -errno; //LCOV_EXCL_LINE System Error
        }
 
        if (reserved == 0) {
@@ -346,11 +328,15 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf)
        if (path)
                snprintf(ext_path, sizeof(ext_path), "%s", path);
        else {
+               if (!storage_ext_is_supported()) {
+                       _D("Block module is not enabled");
+                       goto out_nodev;
+               }
                ret = get_external_path(ext_path, sizeof(ext_path));
                if (ret == -ENODEV)
                        goto out_nodev;
                if (ret < 0) {
-                       _E("Failed to get external path(%d)", ret);
+                       _E("Failed to get external path(%d)", ret); //LCOV_EXCL_LINE
                        return ret;
                }
        }
@@ -358,10 +344,10 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf)
        if (!mount_check(ext_path))
                goto out_nodev;
 
-       ret = get_memory_size(ext_path, &temp);
+       ret = storage_ext_get_statvfs(ext_path, &temp);
        if (ret) {
-               _E("fail to get memory size");
-               return -errno;
+               _E("fail to get memory size"); //LCOV_EXCL_LINE
+               return ret; //LCOV_EXCL_LINE System Error
        }
 
        memcpy(buf, &temp, sizeof(temp));
@@ -386,6 +372,10 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf
        if (path)
                snprintf(ext_path, sizeof(ext_path), "%s", path);
        else {
+               if (!storage_ext_is_supported()) {
+                       _D("Block module is not enabled");
+                       goto out_nodev;
+               }
                ret = get_external_path(ext_path, sizeof(ext_path));
                if (ret == -ENODEV)
                        goto out_nodev;
@@ -398,10 +388,12 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf
        if (!mount_check(ext_path))
                goto out_nodev;
 
-       ret = statvfs(ext_path, buf);
+       ret = storage_ext_get_statvfs_size64(ext_path, buf);
        if (ret) {
+       //LCOV_EXCL_START System Error
                _E("fail to get memory size");
                return -errno;
+       //LCOV_EXCL_STOP
        }
 
        return 0;