mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-03 11:44:18 +01:00
PhysicalDisk (OpenBSD): fixes issues found later
This commit is contained in:
@@ -27,17 +27,14 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
|
||||
}
|
||||
|
||||
char* devPath = NULL;
|
||||
bool readOnly = false;
|
||||
FF_AUTO_CLOSE_FD int f = opendev(diskName, O_RDWR, OPENDEV_PART, &devPath);
|
||||
FF_AUTO_CLOSE_FD int f = opendev(diskName, O_RDONLY, OPENDEV_PART, &devPath);
|
||||
if (f < 0) {
|
||||
if (errno == EACCES) {
|
||||
return "Permission denied; root required";
|
||||
} else if (errno == EBUSY) {
|
||||
readOnly = true;
|
||||
f = opendev(diskName, O_RDONLY, OPENDEV_PART, &devPath);
|
||||
} else {
|
||||
continue; // Unknown error
|
||||
}
|
||||
}
|
||||
if (f < 0) continue; // Unknown error
|
||||
|
||||
struct disklabel dl;
|
||||
if (ioctl(f, DIOCGPDINFO, &dl) < 0) {
|
||||
@@ -53,44 +50,63 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
|
||||
ffStrbufInit(&device->revision);
|
||||
ffStrbufInitS(&device->interconnect, dl.d_typename);
|
||||
device->type = (!isVirtual ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_VIRTUAL) |
|
||||
(!isUnknown ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_UNKNOWN) |
|
||||
(!readOnly ? FF_PHYSICALDISK_TYPE_READWRITE : FF_PHYSICALDISK_TYPE_READONLY);
|
||||
(!isUnknown ? FF_PHYSICALDISK_TYPE_NONE : FF_PHYSICALDISK_TYPE_UNKNOWN);
|
||||
device->size = DL_GETDSIZE(&dl) * dl.d_secsize;
|
||||
device->temperature = FF_PHYSICALDISK_TEMP_UNSET;
|
||||
|
||||
struct scsi_inquiry_data inquiry;
|
||||
if (ioctl(f, SCIOCCOMMAND, &(struct scsireq) {
|
||||
.cmd = { [0] = INQUIRY, [4] = sizeof(inquiry) },
|
||||
.cmdlen = 6,
|
||||
.databuf = (caddr_t) &inquiry,
|
||||
.datalen = sizeof(inquiry),
|
||||
.timeout = 1000,
|
||||
.flags = SCCMD_READ,
|
||||
}) == 0) {
|
||||
struct scsi_inquiry_data inquiry = {};
|
||||
struct scsireq req = {
|
||||
.cmd = { [0] = INQUIRY, [4] = sizeof(inquiry) },
|
||||
.cmdlen = 6,
|
||||
.databuf = (caddr_t) &inquiry,
|
||||
.datalen = sizeof(inquiry),
|
||||
.timeout = 1000,
|
||||
.flags = SCCMD_READ,
|
||||
};
|
||||
if (ioctl(f, SCIOCCOMMAND, &req) == 0 && req.retsts == SCCMD_OK) {
|
||||
ffStrbufClear(&device->name);
|
||||
ffStrbufAppendNS(&device->name, (uint32_t) ARRAY_SIZE(inquiry.vendor), inquiry.vendor);
|
||||
ffStrbufTrimRight(&device->name, '\0');
|
||||
ffStrbufTrimRight(&device->name, ' ');
|
||||
ffStrbufAppendC(&device->name, ' ');
|
||||
ffStrbufAppendNS(&device->name, (uint32_t) ARRAY_SIZE(inquiry.product), inquiry.product);
|
||||
ffStrbufTrimRight(&device->name, '\0');
|
||||
ffStrbufTrimRight(&device->name, ' ');
|
||||
|
||||
ffStrbufSetNS(&device->revision, (uint32_t) ARRAY_SIZE(inquiry.revision), inquiry.revision);
|
||||
ffStrbufTrimRight(&device->revision, '\0');
|
||||
ffStrbufTrimRight(&device->revision, ' ');
|
||||
device->type |= inquiry.dev_qual2 & SID_REMOVABLE ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED;
|
||||
}
|
||||
|
||||
struct scsi_vpd_serial vpdSerial;
|
||||
if (ioctl(f, SCIOCCOMMAND, &(struct scsireq) {
|
||||
.cmd = { [0] = INQUIRY, [1] = SI_EVPD, [2] = SI_PG_SERIAL, [4] = sizeof(vpdSerial) },
|
||||
.cmdlen = 6,
|
||||
.databuf = (caddr_t) &vpdSerial,
|
||||
.datalen = sizeof(vpdSerial),
|
||||
.timeout = 1000,
|
||||
.flags = SCCMD_READ,
|
||||
}) == 0 && vpdSerial.hdr.page_code == SI_PG_SERIAL) {
|
||||
ffStrbufSetNS(&device->serial, vpdSerial.hdr.page_length[1], vpdSerial.serial);
|
||||
struct scsi_vpd_serial evpd = {};
|
||||
req = (struct scsireq) {
|
||||
.cmd = { [0] = INQUIRY, [1] = SI_EVPD, [2] = SI_PG_SERIAL, [4] = sizeof(evpd) },
|
||||
.cmdlen = 6,
|
||||
.databuf = (caddr_t) &evpd,
|
||||
.datalen = sizeof(evpd),
|
||||
.timeout = 1000,
|
||||
.flags = SCCMD_READ,
|
||||
};
|
||||
if (ioctl(f, SCIOCCOMMAND, &req) == 0 && req.retsts == SCCMD_OK && evpd.hdr.page_code == SI_PG_SERIAL) {
|
||||
for (uint8_t i = 0; i < evpd.hdr.page_length[1]; ++i) {
|
||||
ffStrbufAppendF(&device->serial, "%02X", evpd.serial[i]);
|
||||
}
|
||||
ffStrbufTrimSpace(&device->serial);
|
||||
}
|
||||
|
||||
struct scsi_mode_header mode = {};
|
||||
req = (scsireq_t) {
|
||||
.cmd = { [0] = MODE_SENSE, [2] = SMS_PAGE_CODE, [4] = sizeof(mode) },
|
||||
.cmdlen = 6,
|
||||
.databuf = (caddr_t) &mode,
|
||||
.datalen = sizeof(mode),
|
||||
.timeout = 1000,
|
||||
.flags = SCCMD_READ,
|
||||
};
|
||||
if (ioctl(f, SCIOCCOMMAND, &req) == 0 && req.retsts == SCCMD_OK && mode.data_length > 0) {
|
||||
device->type |= mode.dev_spec & 0x80 ? FF_PHYSICALDISK_TYPE_READONLY : FF_PHYSICALDISK_TYPE_READWRITE;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user