Hi,
I would have sent this to the linux-c-programming list, but it appears to
be down.
I'm pretty new to programming on Linux, especially when it involves trying
to interface with the kernel. I have a test program attached that basically
just trying to get status of media_changed(), so I can tell if a CDROM has
changed. The grand plan is to set up a daemon that can monitor media
changed events for various types of media, and do operations like automatic
mounting, kind of like mediad on IRIX. But right now I don't have much
clue. So can anyone point me in the right direction? Am I even doing the
ioctl() call right? One thing for sure is that the call to media_changed()
generates a segmetation violation.
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Dale Harris <rodmur@csuchico.edu> http://www.ecst.csuchico.edu/~rodmur/ GPG-Fingerprint: 8849 BC4F 3DF0 F0A8 3355 E94C 537C 3E1D EEE5 2AB2 |+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|
--0OAP2g/MAC+5xKAE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="cdrom.c"
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/ioctl.h> #include <string.h> #include <errno.h> #define __KERNEL__ #include <linux/kdev_t.h> #include <linux/cdrom.h> #undef __KERNEL__
main() {
int drive, strucsize, changed; struct cdrom_device_info cd_info; struct cdrom_device_ops cd_ops;
if ((drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) < 0) { fprintf(stderr, "Unable to open CDROM device file: %s\n", strerror(errno)); exit(1); }
if (ioctl(drive, CDROM_MEDIA_CHANGED, &cd_info) < 0) { fprintf(stderr, "Ioctl error: %s\n",strerror(errno)); exit(1); }
changed = (*(cd_ops.media_changed))(&cd_info, 0); printf("changed: %d\n", changed);
}
--0OAP2g/MAC+5xKAE--
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/