[PATCH] eject -T support
Tito
farmatito at tiscali.it
Sun Oct 8 12:22:46 PDT 2006
On Sunday 8 October 2006 17:36, Denis Vlasenko wrote:
> On Sunday 08 October 2006 11:18, Tito wrote:
> > On Saturday 7 October 2006 23:14, Denis Vlasenko wrote:
> > > On Saturday 07 October 2006 19:27, Rob Landley wrote:
> > > > On Friday 06 October 2006 12:09 pm, Tito wrote:
> > > > > 1) something mounted OVER our cdrom:
> > > > >
> > > > > /dev/hdd on /media/cdrom1 type iso9660 (ro,noexec,nosuid,nodev)
> > > > > /dev/hdb1 on /media/cdrom1 type reiserfs (rw)
> > > > >
> > > > > ./busybox eject
> > > > > eject: /dev/cdrom: Input/output error
> > > > >
> > > > > /dev/hdd on /media/cdrom1 type iso9660 (ro,noexec,nosuid,nodev)
> > > > >
> > > > > the overmounted block device is unmounted and eject fails.
> > > >
> > > > Doctor, it hurts when I poke myself in the eye with a fork!
> > > >
> > > > Pilot error.
> > > >
> > > > > 2) cdrom is mounted many times:
> > > > >
> > > > > /dev/hdd on /media/cdrom1 type iso9660 (ro)
> > > > > /dev/hdd on /media/cdrom0 type iso9660 (ro)
> > > >
> > > > Pilot error.
> > >
> > > Yes, but we'd better fail instead of unmounting _something else_!
> > > That's my proposal: just (try to) eject the thing, don't
> > > try to do umount job.
> > > --
> > > vda
> >
> > Hi Denis and Rob,
> > This version of eject seems to get the job done!
> > Bloat check is:
> > function old new delta
> > eject_main 193 331 +138
> > ------------------------------------------------------------------------------
> > (add/remove: 0/0 grow/shrink: 1/0 up/down: 138/0) Total: 138 bytes
> >
> > Maybe we can make this umount stuff a config option (CONFIG_EJECT_UMOUNT or add it to CONFIG_DESKTOP)!?
> >
> > It is tested with:
> > 1) unmounted devices
> > 2) mounted devices
> > 3) devices mounted multiple times
> > 4) devices overmounted by other block devices.
> >
> > Hints, improvements, critics are always welcome.
> > Attached is the whole file as drop in replacement for testing
> > and review purpose, if you prefer a diff just ask and I will send
> > one.
>
> const char **mount_points = xmalloc(sizeof(char **));
>
> Shouldn't it be xmalloc(sizeof(char *)) ? And you forgot to xrealloc() it
> as you add stuff to the array. Apart from this loo ks good.
>
> Can you try attached one?
>
> Can you remind me what does not work in shell script solution?
> If umount fails, it needs fixing anyway, and shell script solution
> will be smaller.
The code has a minor error preventing compilation...
CC miscutils/eject.o
miscutils/eject.c: In function ‘eject_main’:
miscutils/eject.c:67: error: syntax error before ‘mount_points’
make[1]: *** [miscutils/eject.o] Error 1
make: *** [miscutils] Error 2
Fixed.
make bloatcheck
CC miscutils/eject.o
AR miscutils/lib.a
LINK busybox_unstripped
function old new delta
eject_main 193 364 +171
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 171/0) Total: 171 bytes
Shell script for me is ok, but it seems that bb's umount doesn't
handle well these corner cases so this problem
will return sooner or later. At least that is what I experienced
with this hazarodous code
int eject_main(int argc, char **argv)
{
int dev, cmd;
unsigned long flags;
char *device;
opt_complementary = "?:?1:t--T:T--t";
flags = getopt32(argc, argv, "tT");
device = argv[optind] ? : "/dev/cdrom";
dev = xopen(device, O_RDONLY|O_NONBLOCK);
cmd = CDROMEJECT;
if (flags & FLAG_CLOSE
|| (flags & FLAG_SMART && ioctl(dev, CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN))
cmd = CDROMCLOSETRAY;
else {
umount_main(argc, argv);
}
if (ioctl(dev, cmd)) {
bb_perror_msg_and_die("%s", device);
}
if (ENABLE_FEATURE_CLEAN_UP) {
close(dev);
}
return EXIT_SUCCESS;
}
Lets remove this mount stuff from eject and amen.
BTW: The program can fail for a lot of strange reasons:
bad sectors in the cd , called to soon after mounting
or loading the cd.......and so on.
Ciao,
Tito
More information about the busybox
mailing list