#include "log.h"
#include "common.h"
+#include "storage-external.h"
#define MEMORY_GIGABYTE_VALUE 1073741824
#define MEMORY_MEGABYTE_VALUE 1048576
}
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;
/* 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;
}
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;
}
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)
ret = get_memory_size(tzplatform_getenv(TZ_SYS_HOME), &temp);
if (ret || temp.f_bsize == 0) {
- _E("fail to get memory size");
+ _E("fail to get memory size"); //LCOV_EXCL_LINE
return -errno;
}
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);
if (ret) {
- _E("fail to get memory size");
+ _E("fail to get memory size"); //LCOV_EXCL_LINE
return -errno;
}
return 0;
}
-static int mount_check(const char *path)
+static int mount_check(char *path)
{
int ret = false;
struct mntent *mnt;
return ret;
}
-static const char *get_external_path(void)
+static int get_external_path(char *path, size_t len)
{
- return tzplatform_mkpath(TZ_SYS_MEDIA,
- EXTERNAL_MEMORY_NODE);
+ return storage_ext_get_primary_mmc_path(path, len);
}
-API int storage_get_external_memory_size(struct statvfs *buf)
+int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf)
{
struct statvfs_32 temp;
int ret;
+ char ext_path[32];
_D("storage_get_external_memory_size");
if (!buf) {
return -EINVAL;
}
- if (!mount_check(get_external_path())) {
- memset(buf, 0, sizeof(struct statvfs_32));
- return 0;
+ if (path)
+ snprintf(ext_path, sizeof(ext_path), "%s", path);
+ else {
+ 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); //LCOV_EXCL_LINE
+ return ret;
+ }
}
- ret = get_memory_size(get_external_path(), &temp);
+ if (!mount_check(ext_path))
+ goto out_nodev;
+
+ ret = get_memory_size(ext_path, &temp);
if (ret) {
- _E("fail to get memory size");
+ _E("fail to get memory size"); //LCOV_EXCL_LINE
return -errno;
}
memcpy(buf, &temp, sizeof(temp));
return 0;
+
+out_nodev:
+ memset(buf, 0, sizeof(struct statvfs_32));
+ return 0;
}
-API int storage_get_external_memory_size64(struct statvfs *buf)
+int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf)
{
int ret;
+ char ext_path[32];
_D("storage_get_external_memory_size64");
if (!buf) {
return -EINVAL;
}
- if (!mount_check(get_external_path())) {
- memset(buf, 0, sizeof(struct statvfs));
- return 0;
+ if (path)
+ snprintf(ext_path, sizeof(ext_path), "%s", path);
+ else {
+ 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);
+ return ret;
+ }
}
- ret = statvfs(get_external_path(), buf);
+ if (!mount_check(ext_path))
+ goto out_nodev;
+
+ ret = statvfs(ext_path, buf);
if (ret) {
_E("fail to get memory size");
return -errno;
}
return 0;
+
+out_nodev:
+ memset(buf, 0, sizeof(struct statvfs));
+ return 0;
+}
+
+API int storage_get_external_memory_size(struct statvfs *buf)
+{
+ return storage_get_external_memory_size_with_path(NULL, buf);
+}
+
+API int storage_get_external_memory_size64(struct statvfs *buf)
+{
+ return storage_get_external_memory_size64_with_path(NULL, buf);
}