Commit 00d330e2 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

fs: unix: Device: Provide a tizen specific isRemovable() implementation

parent d144c7ec
...@@ -206,7 +206,7 @@ Device::DeviceCacheMap Device::populateDeviceCache() ...@@ -206,7 +206,7 @@ Device::DeviceCacheMap Device::populateDeviceCache()
continue; continue;
} }
} }
auto removable = isRemovable( deviceName ); auto removable = isRemovable( deviceName, mountpoint );
LOG_INFO( "Adding device to cache: {", uuid, "} mounted on ", mountpoint, " Removable: ", removable ); LOG_INFO( "Adding device to cache: {", uuid, "} mounted on ", mountpoint, " Removable: ", removable );
res[uuid] = std::make_shared<DeviceBuilder>( uuid, mountpoint, removable ); res[uuid] = std::make_shared<DeviceBuilder>( uuid, mountpoint, removable );
} }
...@@ -248,8 +248,10 @@ std::string Device::deviceFromDeviceMapper( const std::string& devicePath ) ...@@ -248,8 +248,10 @@ std::string Device::deviceFromDeviceMapper( const std::string& devicePath )
return res; return res;
} }
bool Device::isRemovable( const std::string& deviceName ) bool Device::isRemovable( const std::string& deviceName, const std::string& mountpoint )
{ {
#ifndef TIZEN
(void)mountpoint;
std::stringstream removableFilePath; std::stringstream removableFilePath;
removableFilePath << "/sys/block/" << deviceName << "/removable"; removableFilePath << "/sys/block/" << deviceName << "/removable";
std::unique_ptr<FILE, int(*)(FILE*)> removableFile( fopen( removableFilePath.str().c_str(), "r" ), &fclose ); std::unique_ptr<FILE, int(*)(FILE*)> removableFile( fopen( removableFilePath.str().c_str(), "r" ), &fclose );
...@@ -260,6 +262,18 @@ bool Device::isRemovable( const std::string& deviceName ) ...@@ -260,6 +262,18 @@ bool Device::isRemovable( const std::string& deviceName )
fread(&buff, sizeof(buff), 1, removableFile.get() ); fread(&buff, sizeof(buff), 1, removableFile.get() );
return buff == '1'; return buff == '1';
} }
#else
(void)deviceName;
static const std::vector<std::string> SDMountpoints = { "/opt/storage/sdcard" };
auto it = std::find_if( begin( SDMountpoints ), end( SDMountpoints ), [mountpoint]( const std::string& pattern ) {
return mountpoint.length() >= pattern.length() && mountpoint.find( pattern ) == 0;
});
if ( it != end( SDMountpoints ) )
{
LOG_INFO( "Considering mountpoint ", mountpoint, " a removable SDCard" );
return true;
}
#endif
return false; return false;
} }
......
...@@ -59,7 +59,7 @@ private: ...@@ -59,7 +59,7 @@ private:
static MountpointMap listMountpoints(); static MountpointMap listMountpoints();
static DeviceCacheMap populateDeviceCache(); static DeviceCacheMap populateDeviceCache();
static std::string deviceFromDeviceMapper( const std::string& devicePath ); static std::string deviceFromDeviceMapper( const std::string& devicePath );
static bool isRemovable( const std::string& deviceName ); static bool isRemovable( const std::string& deviceName, const std::string& mountpoint );
private: private:
static DeviceMap Devices; static DeviceMap Devices;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment