Пример #1
0
 /** 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();
 }
RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf)
{
    AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
    AssertReturn(cbBuf > 0, VERR_INVALID_PARAMETER);
    *pszBuf = '\0';
    AssertReturn(enmString > RTSYSDMISTR_INVALID && enmString < RTSYSDMISTR_END, VERR_INVALID_PARAMETER);

    const char *pszSysFsName;
    switch (enmString)
    {
        case RTSYSDMISTR_PRODUCT_NAME:      pszSysFsName = "id/product_name"; break;
        case RTSYSDMISTR_PRODUCT_VERSION:   pszSysFsName = "id/product_version"; break;
        case RTSYSDMISTR_PRODUCT_UUID:      pszSysFsName = "id/product_uuid"; break;
        case RTSYSDMISTR_PRODUCT_SERIAL:    pszSysFsName = "id/product_serial"; break;
        case RTSYSDMISTR_MANUFACTURER:      pszSysFsName = "id/sys_vendor"; break;
        default:
            return VERR_NOT_SUPPORTED;
    }

    size_t cbRead = 0;
    int rc = RTLinuxSysFsReadStrFile(pszBuf, cbBuf, &cbRead, "devices/virtual/dmi/%s", pszSysFsName);
    if (RT_FAILURE(rc) && rc != VERR_BUFFER_OVERFLOW)
        rc = RTLinuxSysFsReadStrFile(pszBuf, cbBuf, &cbRead, "class/dmi/%s", pszSysFsName);
    if (RT_FAILURE(rc) && rc != VERR_BUFFER_OVERFLOW)
    {
        switch (rc)
        {
            case VINF_SUCCESS:
                AssertFailed();
                break;
            case VERR_FILE_NOT_FOUND:
            case VERR_PATH_NOT_FOUND:
            case VERR_IS_A_DIRECTORY:
                rc = VERR_NOT_SUPPORTED;
                break;
            case VERR_PERMISSION_DENIED:
            case VERR_ACCESS_DENIED:
                rc = VERR_ACCESS_DENIED;
                break;
        }
    }

    return rc;
}