#include <system_settings.h>
#include <net_connection.h>
#include <tzplatform_config.h>
-#include <sys/statfs.h>
+#include <storage.h>
#include "systeminfo/systeminfo_manager.h"
#include "systeminfo/systeminfo_device_capability.h"
return PlatformResult(ErrorCode::NO_ERROR);
}
-static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojson::object* out) {
+static void CreateStorageInfo(const std::string& type, struct statvfs& fs, picojson::object* out) {
LoggerD("Entered");
out->insert(std::make_pair("type", picojson::value(type)));
out->insert(std::make_pair("capacity", picojson::value(std::to_string(
- static_cast<unsigned long long>(fs.f_bsize) *
+ static_cast<unsigned long long>(fs.f_frsize) *
static_cast<unsigned long long>(fs.f_blocks)))));
out->insert(std::make_pair("availableCapacity", picojson::value(std::to_string(
- static_cast<unsigned long long>(fs.f_bsize) *
+ static_cast<unsigned long long>(fs.f_frsize) *
static_cast<unsigned long long>(fs.f_bavail)))));
bool isRemovable = (type == kTypeInternal) ? false : true;
out->insert(std::make_pair("isRemovable", picojson::value(isRemovable)));
PlatformResult SysteminfoPropertiesManager::ReportStorage(picojson::object* out) {
LoggerD("Entered");
- struct statfs fs;
+ struct statvfs fs;
picojson::value result = picojson::value(picojson::array());
picojson::array& array = result.get<picojson::array>();
LoggerD("Storages found %d", storages.size());
for (auto storage : storages) {
if (storage->state() == common::StorageState::kMounted) {
- if (statfs(storage->path().c_str(), &fs) < 0) {
- LoggerE("Storage unit %s not detected", storage->name().c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Storage unit not detected");
- }
- array.push_back(picojson::value(picojson::object()));
- picojson::object& external_obj = array.back().get<picojson::object>();
- CreateStorageInfo(FromStorageTypeToStringType(storage->type()), fs, &external_obj);
-
//TODO change implementation to support all types of storages and not limited number
if (common::StorageType::kInternal == storage->type()) {
+ if (storage_get_internal_memory_size(&fs) < 0) {
+ LoggerE("Storage unit %s not detected", storage->name().c_str());
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "There are no storage units detected");
+ }
manager_.SetAvailableCapacityInternal(fs.f_bavail);
} else if (common::StorageType::kMmc == storage->type()) {
+ if (storage_get_external_memory_size(&fs) < 0) {
+ LoggerE("Storage unit %s not detected", storage->name().c_str());
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "MMC mounted, but not accessible");
+ }
manager_.SetAvailableCapacityMmc(fs.f_bavail);
}
+
+ array.push_back(picojson::value(picojson::object()));
+ picojson::object& external_obj = array.back().get<picojson::object>();
+ CreateStorageInfo(FromStorageTypeToStringType(storage->type()), fs, &external_obj);
+
}
}