[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Libcdio-devel] [Patch] Umount drive before ejecting
From: |
plaum |
Subject: |
[Libcdio-devel] [Patch] Umount drive before ejecting |
Date: |
Sat, 21 Oct 2006 00:14:48 +0200 (CEST) |
Hi,
I made a patch, which does the following:
- Before ejecting, we test if the device is mounted. This is done by
reading /proc/mounts (or /etc/mtab as fallback) with a routine
inspired by libunieject
- If the drive is mounted, we try to umount it. This is done by forking and
exec'ing pumount (umount as fallback). My attempts to use the umount()
system call failed, since it triggers an EPERM error if we aren't root,
even if we would be allowed to umount the disc (the umount command
is setuid root and seems to check for proper permissions itself).
The umount code was inspired by the linux eject command.
- After umounting, the filedescriptor is closed and opened again. This
is needed for eject to work (also tried sync() and sleep(2), without
success).
- Ejecting then happens with the ioctl or mmc command like before.
- At the end, we close() the filedescriptor (before it was just set to
-1) but only, if is wasn't open before the call to eject_media_linux().
- Also attached an ultra lightweight program cdio-eject.c I use for
testing. It's modelled after the linux eject command, but only
the -t option (close tray) is supported. I can put this into the
libcdio tree as well, if there is interest.
My remaining questions are:
1. Are any objections against using fork() inside libcdio? I doubt that
umounting a drive from a userspace app can be done in a better way.
2. The solution is linux only. I think libcdio should behave similar on
all supported platforms with respect to eject/umount. Maybe my
mechanism can be ported to other systems as well, but I don't know.
If these questions are clarified, I'll apply it.
Cheers
Burkhard
cdio_eject.patch
Description: Text Data
cdio-eject.c
Description: Text Data