Now look at how we can already do these things with devfs. Let's say
I've opened /dev/cdroms/cdrom0 and it's sitting on fd=3.
% ls -lF /proc/self/fd/3
lrwx------ 1 root root 64 May 15 13:24 /proc/self/fd/3 -> /dev/ide/host0/bus0/target1/lun0/cd
So, in my application I do:
len = readlink ("/proc/self/3", buffer, buflen);
if (strcmp (buffer + len - 2, "cd") != 0) {
fprintf (stderr, "Not a CD-ROM! Bugger off.\n");
exit (1);
}
if (strncmp (buffer, "/dev/ide", 8) == 0) do_ide (fd);
else if (strncmp (buffer, "/dev/scsi", 9) == 0) do_scsi (fd);
else do_generic (fd);
That's a lot cleaner than relying on magic numbers, IMNSHO.
Regards,
Richard....
Permanent: rgooch@atnf.csiro.au
Current: rgooch@ras.ucalgary.ca
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/