lkml.org 
[lkml]   [1999]   [Feb]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectaccessing media_changed() for CDROMs
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
|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|+|

#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);

}
\
 
 \ /
  Last update: 2005-03-22 13:50    [W:0.044 / U:0.984 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site