[monero-project/monero] is_hdd update for windows and linux (#4278)

moneromooo-monero commented on this pull request.

Please make commit message first line informative (like this PR’s title for example).

Also, since you change the is_hdd code completely, I think it might be a good occasion to move this into a separate file as it’s becoming a bit crowded here.

> @@ -74,6 +75,11 @@ using namespace epee;
#include
#include

+#ifdef WIN32

I think we had problems with WIN32 before, and _WIN32 was the «best» one to use.

> + else
+ {
+ return false;
+ }
+ std::string attr_path = prefix + «/queue/rotational»;
+ FILE *f = fopen(attr_path.c_str(), «r»);
+ if(f == nullptr)
+ {
+ attr_path = prefix + «/../queue/rotational»;
+ f = fopen(attr_path.c_str(), «r»);
+ if(f == nullptr)
+ {
+ return false;
+ }
+ }
+ uint16_t val = 0xdead;

Probably best to make it a unsigned short if using %hu below.

>
— std::string sys_path = «/sys/block/» + device + «/queue/rotational»;
— FILE *f = fopen(sys_path.c_str(), «r»);
— if (!f)
+ bool win_device_has_seek_penalny(const char *pv, bool &result)

penalty

> + };
+ DEVICE_SEEK_PENALTY_DESCRIPTOR r;
+ DWORD r_size = 0;
+ BOOL success = DeviceIoControl(
+ h,
+ IOCTL_STORAGE_QUERY_PROPERTY,
+ &q,
+ sizeof(q),
+ &r,
+ sizeof(r),
+ &r_size,
+ nullptr
+ );
+ if(success and r_size == sizeof(r))
+ {
+ result = r.IncursSeekPenalty;

That path seems to leak h.

> — if (!ptr)
— return 0;
— s[sizeof(s) — 1] = 0;
— int n = atoi(s); // returns 0 on parse error
— return n == 1;
-#else
— return 0;
+ }
+ std::vector pvs;
+ bool pv_success = lv2pv(lv.c_str(), pvs);
+ if(not pv_success)
+ {
+ return false;
+ }
+ bool a_result = 0;
+ bool a_success = 0;

false

> #endif
+ bool is_hdd(const char *path, bool &result)
+ {
+ #if defined(_WIN32) and (_WIN32_WINNT >= 0x0601)
+ return is_hdd_win_ioctl(path, result);
+ #elif defined(__GLIBC__)
+ return is_hdd_sysfs(path, result);
+ #else
+ return 0;

false

> + return is_hdd_sysfs(path, result);
+ #else
+ return 0;
+ #endif
+ }
+
+ bool is_hdd(const char *path)
+ {
+ bool result;
+ if(is_hdd(path, result))
+ {
+ return result;
+ }
+ else
+ {
+ return 0;

false

> @@ -72,6 +72,7 @@ set(unit_tests_sources
ringct.cpp
output_selection.cpp
vercmp.cpp
+ test_a.cpp

Rename to something sane

Добавить комментарий