Figuring out if a device is used
From: Vilmos Soti (vilmos_at_vilmos.org)
Date: 04/30/04
- Next message: Ingo Strauch: "Re: State of the GnuCash project, a call for help"
- Previous message: nobody_at_nowhere.com: "Re: Compiling windows apps on linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Apr 2004 09:33:48 -0700
Hello,
Is there a way to figure out if a device (cdrom) is in use
regardless how the device is called?
For example, say I have the following lines in my fstab:
(edited for brevity)
/dev/cdrom /mnt/cdrom ...
/dev/cdrom_norock /mnt/norock ...
/dev/cdrom_udf /mnt/udf ...
All three, /dev/cdrom, /dev/cdrom_norock, and /dev/cdrom_udf point
to the same hardware device, /dev/hdd which is a cdrom.
What I want to avoid if say, /dev/cdrom is mounted, then the other
two (and also an additional /dev/cdrom) cannot be mounted. I don't
want to have a situation something like this:
#################### Commands start ####################
# ls -l /dev/cdrom
lrwxrwxrwx 1 root root 3 Jan 9 16:19 /dev/cdrom -> hdd
# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
# mount /dev/hdd /mnt/floppy
mount: block device /dev/hdd is write-protected, mounting read-only
# df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda2 6095840 3275920 2510268 57% /
...
/dev/cdrom 42608 42608 0 100% /mnt/cdrom
/dev/hdd 42608 42608 0 100% /mnt/floppy
#
#################### Commands end ####################
I am writing a perl program which mounts a cdrom, then copies
the contents of it to a local disk. The whole process is
automated as much as possible since it is used by people who
are not computer experts.
The program takes time to start (since it has to do many
things before the actual reading), but apart from the actual
reading of the cdrom, they can run in parallel. So the
operator can start the program many times with different
parameters (which describe the cdrom). The initialization
runs, then it prompts the operator to insert the appropriate
cd and hit enter to start the reading. I am afraid that there
are many terminals up, and in one, the actual reading takes
place, and the operator makes an error and starts the actual
reading process in another window and essentially reads the
wrong cdrom.
One thing I can do is to iterate over all possible names
(/dev/cdrom, /dev/cdrom_norock, /dev/cdrom_udf) to see
if they are present in /proc/mounts and then make sure that
they are not used. Then I can mount it. But I feel this is a
not an elegant solution, and every time a new link to the
actual cdrom is created, I have to update my program.
So anybody knows if it is possible to figure out if a hardware
device is in use regardless its name?
Thanks, Vilmos
- Next message: Ingo Strauch: "Re: State of the GnuCash project, a call for help"
- Previous message: nobody_at_nowhere.com: "Re: Compiling windows apps on linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|