/** Check whether the sysfs block entry is valid for a DVD device and * initialise the string data members for the object. We try to get all * the information we need from sysfs if possible, to avoid unnecessarily * poking the device, and if that fails we fall back to an SCSI INQUIRY * command. */ void validateAndInitForDVD() { char szVendor[128], szModel[128]; ssize_t cchVendor, cchModel; int64_t type = RTLinuxSysFsReadIntFile(10, "block/%s/device/type", mpcszName); if (type >= 0 && type != TYPE_ROM) return; if (type == TYPE_ROM) { cchVendor = RTLinuxSysFsReadStrFile(szVendor, sizeof(szVendor), "block/%s/device/vendor", mpcszName); if (cchVendor >= 0) { cchModel = RTLinuxSysFsReadStrFile(szModel, sizeof(szModel), "block/%s/device/model", mpcszName); if (cchModel >= 0) { misValid = true; dvdCreateDeviceStrings(szVendor, szModel, mszDesc, sizeof(mszDesc), mszUdi, sizeof(mszUdi)); return; } } } if (!noProbe()) probeAndInitForDVD(); }
/** Check whether the sysfs block entry is valid for a DVD device and * initialise the string data members for the object. We try to get all * the information we need from sysfs if possible, to avoid unnecessarily * poking the device, and if that fails we fall back to an SCSI INQUIRY * command. */ void validateAndInitForDVD() { char szVendor[128], szModel[128]; int64_t type = 0; int rc = RTLinuxSysFsReadIntFile(10, &type, "block/%s/device/type", mpcszName); if (RT_SUCCESS(rc) && type != TYPE_ROM) return; if (type == TYPE_ROM) { rc = RTLinuxSysFsReadStrFile(szVendor, sizeof(szVendor), NULL, "block/%s/device/vendor", mpcszName); if (RT_SUCCESS(rc)) { rc = RTLinuxSysFsReadStrFile(szModel, sizeof(szModel), NULL, "block/%s/device/model", mpcszName); if (RT_SUCCESS(rc)) { misValid = true; dvdCreateDeviceStrings(szVendor, szModel, mszDesc, sizeof(mszDesc), mszUdi, sizeof(mszUdi)); return; } } } if (!noProbe()) probeAndInitForDVD(); }
/** * Check whether a device node points to a valid device and create a UDI and * a description for it, and store the device number, if it does. * @returns true if the device is valid, false otherwise * @param pcszNode the path to the device node * @param isDVD are we looking for a DVD device (or a floppy device)? * @param pDevice where to store the device node (optional) * @param pszDesc where to store the device description (optional) * @param cchDesc the size of the buffer in @a pszDesc * @param pszUdi where to store the device UDI (optional) * @param cchUdi the size of the buffer in @a pszUdi */ static bool devValidateDevice(const char *pcszNode, bool isDVD, dev_t *pDevice, char *pszDesc, size_t cchDesc, char *pszUdi, size_t cchUdi) { AssertPtrReturn(pcszNode, false); AssertPtrNullReturn(pDevice, false); AssertPtrNullReturn(pszDesc, false); AssertReturn(!pszDesc || cchDesc > 0, false); AssertPtrNullReturn(pszUdi, false); AssertReturn(!pszUdi || cchUdi > 0, false); RTFSOBJINFO ObjInfo; if (RT_FAILURE(RTPathQueryInfo(pcszNode, &ObjInfo, RTFSOBJATTRADD_UNIX))) return false; if (!RTFS_IS_DEV_BLOCK(ObjInfo.Attr.fMode)) return false; if (pDevice) *pDevice = ObjInfo.Attr.u.Unix.Device; if (isDVD) { char szVendor[128], szModel[128]; uint8_t u8Type; if (!isCdromDevNum(ObjInfo.Attr.u.Unix.Device)) return false; if (RT_FAILURE(cdromDoInquiry(pcszNode, &u8Type, szVendor, sizeof(szVendor), szModel, sizeof(szModel)))) return false; if (u8Type != TYPE_ROM) return false; dvdCreateDeviceStrings(szVendor, szModel, pszDesc, cchDesc, pszUdi, cchUdi); } else { /* Floppies on Linux are legacy devices with hardcoded majors and * minors */ unsigned Number; floppy_drive_name szName; if (major(ObjInfo.Attr.u.Unix.Device) != FLOPPY_MAJOR) return false; switch (minor(ObjInfo.Attr.u.Unix.Device)) { case 0: case 1: case 2: case 3: Number = minor(ObjInfo.Attr.u.Unix.Device); break; case 128: case 129: case 130: case 131: Number = minor(ObjInfo.Attr.u.Unix.Device) - 128 + 4; break; default: return false; } if (!floppyGetName(pcszNode, Number, szName)) return false; floppyCreateDeviceStrings(szName, Number, pszDesc, cchDesc, pszUdi, cchUdi); } return true; }
/** Try to find out whether a device is a DVD drive by sending it an * SCSI INQUIRY command. If it is, initialise the string and validity * data members for the object based on the returned data. */ void probeAndInitForDVD() { AssertReturnVoid(mszNode[0] != '\0'); uint8_t u8Type = 0; char szVendor[128] = ""; char szModel[128] = ""; int rc = cdromDoInquiry(mszNode, &u8Type, szVendor, sizeof(szVendor), szModel, sizeof(szModel)); if (RT_SUCCESS(rc) && (u8Type == TYPE_ROM)) { misValid = true; dvdCreateDeviceStrings(szVendor, szModel, mszDesc, sizeof(mszDesc), mszUdi, sizeof(mszUdi)); } }