Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (13 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/miscutils/eject.c

    r821 r1765  
    1414 */
    1515
    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"
    2117
    2218/* various defines swiped from linux/cdrom.h */
    2319#define CDROMCLOSETRAY            0x5319  /* pendant of CDROMEJECT  */
    2420#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
    2624
     25#define FLAG_CLOSE  1
     26#define FLAG_SMART  2
     27
     28int eject_main(int argc, char **argv);
    2729int eject_main(int argc, char **argv)
    2830{
    2931    unsigned long flags;
    30     char *device;
    31     struct mntent *m;
     32    const char *device;
     33    int dev, cmd;
    3234
    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";
    3538
    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;
    4860}
Note: See TracChangeset for help on using the changeset viewer.