You are not logged in.

#1 2011-10-07 11:53:37

dlz
Member
Registered: 2011-04-04
Posts: 18

udev : no "change" action for cd/dvd (optical) - helping tool

i was writing udev rules for usb storage auto-mount and umount. it works great. no other tools than udev is needed.
BUT when it comes to optical drives, udev isn't that great.
on 2 out of my 3 optical drives udev does not perform any "change" action
so, there is no action at all when changing cd/dvd media and watching:

$ udevadm monitor

it seems that either udev or the optical drive is "asleep", not sending media change info
i found a solution.

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/cdrom.h>

int
main(int argc, char *argv[])
{
	if (argc < 2) {
		printf("USAGE: %s DEVICE\n", argv[0]);
		return 1;
	}
	int h;
	for (;;) {
		h = open(argv[1], O_RDONLY | O_NONBLOCK);
		if (h < 0) {
			perror("open");
			return 1;
		}
		close(h);
		sleep(1);
	}
}
$ cdromkeepawake /dev/sr0

this tool opens and closes a handle to the optical drive every second.
it keeps the drive "awake" (i really don't know why this works at all)

with this tool running in the background udev "catches" all changes and sends "change" action like it should.
auto-mount and umount for optical drives using only udev rules is possible now.

i want to hear if this "solves" your udev-optical-drive-problem also?
it would be great if someone could tell the udev developers about that. their site on kernel.org isn't up...

Offline

Board footer

Powered by FluxBB