Skip to content

Commit

Permalink
Assume media is non-rotational by default
Browse files Browse the repository at this point in the history
  • Loading branch information
zmeyc committed Mar 10, 2021
1 parent f069c53 commit e1e5f98
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/disk_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ namespace DiskUtil {
inline bool IsRotational(const std::string &dir)
{
#if defined(__APPLE__) || defined(_WIN32)
return true;
return false;
#else
struct stat s{};

if (0 != stat(dir.c_str(), &s)) {
std::ostringstream err;
std::cerr << "Unable to find device name for dir " << dir << ": "
<< strerror(errno);
return true;
return false;
}

int major_id = major(s.st_dev);
Expand All @@ -68,20 +68,15 @@ namespace DiskUtil {
std::ostringstream err;
std::cerr << "Unable to open " << filename << " for reading: "
<< strerror(errno);
return true;
return false;
}

std::string line;
getline(file, line);

file.close();

int is_rotational = 1;
if (!line.empty() && line.front() == '0') {
is_rotational = 0;
}

return is_rotational;
return !line.empty() && line.front() == '1';
#endif
}

Expand Down

0 comments on commit e1e5f98

Please sign in to comment.