Sunday, May 17, 2009

AutoFS: The linux's kernel automounter

Last night i began to build CSD and CSR development system, use Debian Lenny with Linux's kernel-2.6.26. The CSD and CSR cartridge has a USB disk to write some useful infos such as cartridge's usage, cartridge id, and a list of smartcards data that filled in the cartridge.

Autofs or the kernel automounter is actually a additional module to linux kernel, it's work by mounting a filesystem when they are accessed and unmounting them when they are no longer in use.

I use autofs version 4 fetched from a Debian repo server, write some autofs's configuration files.

# The fs should be mounted on /mnt directroy
# and i'll need 3 secs timeout before autofs unmount the fs
/mnt /etc/auto.mnt --timeout=3

disk -fstype=auto,rw,nosuid,nodev :/dev/sda

Restart autofs daemon and write a small demonstration codes, i know when the disk already mounted or not by polling a file in the disk with open() system call (ENOENT error code), but the real problem is: how does my codes receive a kernel's event when disk is plugged.