Re: How to recognize hdc as a CD-ROM drive?

Riccardo Facchetti (fizban@tin.it)
Sun, 17 May 1998 12:21:26 +0200 (MET DST)


On Sun, 17 May 1998 Andries.Brouwer@cwi.nl wrote:

>
> For programs like mount and fdisk it is useful
> to be able to find out whether a device is a hard disk
> or a CD-ROM drive or something else.
> However, there seems to be no simple way to do so.

In 2.1.102, having mounted the /proc filesystem:

# cat /proc/ide/hdd/media
cdrom
#

I do not know how to recognize a SCSI CDROM, but I guess it should be
possible in a similar way catting /proc/scsi/scsi that contains the list
of all the scsi devices installed.

Anyway, supposing your /etc/fstab is mantained and up to date, and you
have no strange loops (I mean images mounted as devices) on iso9660 images
or something like that, you can more easily:

{
struct mntent *mne;

FILE *fp = setmntent("/etc/fstab", "r");
while ((nme = getnmtent(fp))) {
if (!strcmp(nme->nmt_type, "iso9660"))
is a cdrom, do something
}
}

But ... if you want to open() the device and don't receive kernel
messages, you can much more easily (with the syslog(2) system call):

syslog(8, NULL, 1);

in fact, from the syslog(2) man page:

...
8 -- Set level of messages printed to console
...

Ciao,
Riccardo.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu