Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/miscutils/eject.c
- Timestamp:
- Nov 4, 2007, 3:16:40 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.5/mindi-busybox/miscutils/eject.c
r821 r1765 14 14 */ 15 15 16 #include "busybox.h" 17 #include <fcntl.h> 18 #include <sys/ioctl.h> 19 #include <unistd.h> 20 #include <mntent.h> 16 #include "libbb.h" 21 17 22 18 /* various defines swiped from linux/cdrom.h */ 23 19 #define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ 24 20 #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ 25 #define DEFAULT_CDROM "/dev/cdrom" 21 #define CDROM_DRIVE_STATUS 0x5326 /* Get tray position, etc. */ 22 /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ 23 #define CDS_TRAY_OPEN 2 26 24 25 #define FLAG_CLOSE 1 26 #define FLAG_SMART 2 27 28 int eject_main(int argc, char **argv); 27 29 int eject_main(int argc, char **argv) 28 30 { 29 31 unsigned long flags; 30 c har *device;31 struct mntent *m;32 const char *device; 33 int dev, cmd; 32 34 33 flags = bb_getopt_ulflags(argc, argv, "t"); 34 device = argv[optind] ? : DEFAULT_CDROM; 35 opt_complementary = "?1:t--T:T--t"; 36 flags = getopt32(argv, "tT"); 37 device = argv[optind] ? : "/dev/cdrom"; 35 38 36 if ((m = find_mount_point(device, bb_path_mtab_file))) { 37 if (umount(m->mnt_dir)) { 38 bb_error_msg_and_die("Can't umount"); 39 } else if (ENABLE_FEATURE_MTAB_SUPPORT) { 40 erase_mtab(m->mnt_fsname); 41 } 42 } 43 if (ioctl(bb_xopen(device, (O_RDONLY | O_NONBLOCK)), 44 (flags ? CDROMCLOSETRAY : CDROMEJECT))) { 45 bb_perror_msg_and_die("%s", device); 46 } 47 return (EXIT_SUCCESS); 39 // We used to do "umount <device>" here, but it was buggy 40 // if something was mounted OVER cdrom and 41 // if cdrom is mounted many times. 42 // 43 // This works equally well (or better): 44 // #!/bin/sh 45 // umount /dev/cdrom 46 // eject 47 48 dev = xopen(device, O_RDONLY|O_NONBLOCK); 49 cmd = CDROMEJECT; 50 if (flags & FLAG_CLOSE 51 || (flags & FLAG_SMART && ioctl(dev, CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN)) 52 cmd = CDROMCLOSETRAY; 53 54 ioctl_or_perror_and_die(dev, cmd, NULL, "%s", device); 55 56 if (ENABLE_FEATURE_CLEAN_UP) 57 close(dev); 58 59 return EXIT_SUCCESS; 48 60 }
Note:
See TracChangeset
for help on using the changeset viewer.