fun with linux device parameters
well i think i had a good start with this one. never really did any real interaction with linux device files in assembly. so i decided i’d try some experiments today. my list included doing something with regards to the linux framebuffer, virtual terminals and sound/dsp devices. it seems though that they require considerable effort to learn. after reading some man pages and header files, i decided to begin yet another chapter in my assembly adventure by manipulating the cd rom device in linux. this afternoon, i made my own version on the linux eject command. it only has two functions, that is, to open the cdrom tray, and close it. pretty basic huh? i want to get comfortable with the whole idea of device control first before doing any of the activities i mentioned a while ago.
[ introduction ]
from ioctl(2) manual…DESCRIPTION
The ioctl function manipulates the underlying device parameters of special files. In particular, many operating characteristics of character special files (e.g. terminals) may be controlled with ioctl requests. The argument d must be an open file descriptor.
i started out knowing only that /dev/cdrom is a symlink to /dev/hdc which is consequently, my cdrom drive. and that sys_ioctl is the linux system call responsible for interfacing with character and device files. eventually, i reached the ioctl_list(2) manual page after going thu the ioctl(2) manual a few times over. specially since the later doesn’t have any examples in it.
so now i have something to work with.
a) open a cdrom device (/dev/cdrom) so i can have a file descriptor for it.
b) use the new file descriptor when calling ioctl with the appropriate request and the appropriate structure (if necessary).
i confirmed the those steps above by running /usr/bin/eject under strace. it looked doable so i fired up vim and what do you know? the eject thingy i did works! -t flag closes the tray.
