Back to index

lshw  02.16
Functions
cdrom.h File Reference
#include "hw.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool scan_cdrom (hwNode &n)

Function Documentation

bool scan_cdrom ( hwNode n)

Definition at line 47 of file cdrom.cc.

{
  if (n.getLogicalName() == "")
    return false;

  n.addHint("icon", string("cd"));

  int fd = open(n.getLogicalName().c_str(), O_RDONLY | O_NONBLOCK);

  if (fd < 0)
    return false;

  int status = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
  if (status < 0)
  {
    close(fd);
    return false;
  }

  int capabilities = ioctl(fd, CDROM_GET_CAPABILITY);

  if (capabilities < 0)
  {
    close(fd);
    return false;
  }

  if (capabilities & CDC_PLAY_AUDIO)
    n.addCapability("audio", "Audio CD playback");
  if (capabilities & CDC_CD_R)
  {
    n.addCapability("cd-r", "CD-R burning");
    n.setDescription("CD-R writer");
  }
  if (capabilities & CDC_CD_RW)
  {
    n.addCapability("cd-rw", "CD-RW burning");
    n.setDescription("CD-R/CD-RW writer");
  }
  if (capabilities & CDC_DVD)
  {
    n.addCapability("dvd", "DVD playback");
    n.setDescription("DVD reader");
  }
  if (capabilities & CDC_DVD_R)
  {
    n.addCapability("dvd-r", "DVD-R burning");
    n.setDescription("DVD writer");
  }
  if (capabilities & CDC_DVD_RAM)
  {
    n.addCapability("dvd-ram", "DVD-RAM burning");
    n.setDescription("DVD-RAM writer");
  }

  switch(ioctl(fd, CDROM_DRIVE_STATUS, 0))
  {
    case CDS_NO_INFO:
    case CDS_NO_DISC:
      n.setConfig("status", "nodisc");
      break;
    case CDS_TRAY_OPEN:
      n.setConfig("status", "open");
      break;
    case CDS_DRIVE_NOT_READY:
      n.setConfig("status", "busy");
      break;
    case CDS_DISC_OK:
      n.setConfig("status", "ready");
      scan_partitions(n);
      break;
  }
  close(fd);

  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function: