Fallback to rotational in devpower if sysfs attribute is unknown

This commit is contained in:
Andrea Mazzoleni 2026-08-06 22:56:37 +02:00
parent f3c3265116
commit c4511e28bc

View file

@ -430,7 +430,7 @@ next:
* Read a file from sys. * Read a file from sys.
* Trim spaces. * Trim spaces.
* Always put an ending 0. * Always put an ending 0.
* Do not report error on reading. * Do not log error on reading.
* Return an error if truncated * Return an error if truncated
* *
* Return -1 on error, 0 on success * Return -1 on error, 0 on success
@ -2896,24 +2896,16 @@ static void devattr(dev_t device, uint64_t* info, char* serial, char* family, ch
if (info[INFO_SIZE] == SMART_UNASSIGNED) { if (info[INFO_SIZE] == SMART_UNASSIGNED) {
pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/size", major(device), minor(device)); pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/size", major(device), minor(device));
if (sysattr(path, buf, sizeof(buf)) == 0) { long long v = syslong(path);
char* e; if (v >= 0)
uint64_t v; info[INFO_SIZE] = v * 512;
v = strtoul(buf, &e, 10);
if (*e == 0)
info[INFO_SIZE] = v * 512;
}
} }
if (info[INFO_ROTATION_RATE] == SMART_UNASSIGNED) { if (info[INFO_ROTATION_RATE] == SMART_UNASSIGNED) {
pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/queue/rotational", major(device), minor(device)); pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/queue/rotational", major(device), minor(device));
if (sysattr(path, buf, sizeof(buf)) == 0) { long long v = syslong(path);
char* e; if (v >= 0)
uint64_t v; info[INFO_ROTATION_RATE] = v;
v = strtoul(buf, &e, 10);
if (*e == 0)
info[INFO_ROTATION_RATE] = v;
}
} }
if (*model == 0) { if (*model == 0) {
@ -3200,22 +3192,13 @@ static int devdownifup(dev_t device, const char* name, const char* smartctl, con
static int devpower(dev_t device) static int devpower(dev_t device)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
char buf[512]; long long rotational;
uint64_t rotational;
rotational = SMART_UNASSIGNED;
pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/queue/rotational", major(device), minor(device)); pathprint(path, sizeof(path), "/sys/dev/block/%u:%u/queue/rotational", major(device), minor(device));
if (sysattr(path, buf, sizeof(buf)) == 0) { rotational = syslong(path);
char* e;
uint64_t v;
v = strtoul(buf, &e, 10);
if (*e == 0)
rotational = v;
}
if (rotational == SMART_UNASSIGNED) if (rotational < 0)
return 0; /* assume not rotational */ return 1; /* assume rotational if unknown */
return rotational != 0; return rotational != 0;
} }