#include <errno.h>
#include <assert.h>
#include <mntent.h>
+#include <tzplatform_config.h>
#include "log.h"
#include "common.h"
#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 */
}
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;
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"))
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;
return -EINVAL;
}
- ret = get_memory_size(MEMORY_STATUS_USR_PATH, &temp);
- if (ret) {
+ ret = get_memory_size(tzplatform_getenv(TZ_SYS_HOME), &temp);
+ if (ret || temp.f_bsize == 0) {
_E("fail to get memory size");
return -errno;
}
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;
return 0;
}
-static int mount_check(const char* path)
+static int mount_check(const char *path)
{
int ret = false;
- struct mntent* mnt;
- const char* table = "/etc/mtab";
- FILE* fp;
+ 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;
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;
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;
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;