diff options
author | Davidlohr Bueso | 2011-12-20 14:42:10 +0100 |
---|---|---|
committer | Karel Zak | 2012-01-02 13:43:06 +0100 |
commit | 3b622ddd72a783f9b532f1e363093978fe4d340a (patch) | |
tree | 6e9a7f1b9c8b895d447b1451c0b268cca98ae59a /fdisk/fdisk.c | |
parent | mount: append inverting options for mount.<type> (diff) | |
download | kernel-qcow2-util-linux-3b622ddd72a783f9b532f1e363093978fe4d340a.tar.gz kernel-qcow2-util-linux-3b622ddd72a783f9b532f1e363093978fe4d340a.tar.xz kernel-qcow2-util-linux-3b622ddd72a783f9b532f1e363093978fe4d340a.zip |
fdisk: use CDROM_GET_CAPABILITY ioctl
And replace the current archaic logic of is_ide_cdrom_or_tape().
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Diffstat (limited to 'fdisk/fdisk.c')
-rw-r--r-- | fdisk/fdisk.c | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index c41da7a6e..d967d2733 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -2746,37 +2746,16 @@ expert_command_prompt(void) } } -static int -is_ide_cdrom_or_tape(char *device) { - FILE *procf; - char buf[100]; - struct stat statbuf; - int is_ide = 0; - - /* No device was given explicitly, and we are trying some - likely things. But opening /dev/hdc may produce errors like - "hdc: tray open or drive not ready" - if it happens to be a CD-ROM drive. It even happens that - the process hangs on the attempt to read a music CD. - So try to be careful. This only works since 2.1.73. */ +static int is_ide_cdrom_or_tape(char *device) +{ + int fd, ret; - if (strncmp("/dev/hd", device, 7)) + if (fd = open(device, O_RDONLY) < 0) return 0; + ret = blkdev_is_cdrom(fd); - snprintf(buf, sizeof(buf), "/proc/ide/%s/media", device+5); - procf = fopen(buf, "r"); - if (procf != NULL && fgets(buf, sizeof(buf), procf)) - is_ide = (!strncmp(buf, "cdrom", 5) || - !strncmp(buf, "tape", 4)); - else - /* Now when this proc file does not exist, skip the - device when it is read-only. */ - if (stat(device, &statbuf) == 0) - is_ide = ((statbuf.st_mode & 0222) == 0); - - if (procf) - fclose(procf); - return is_ide; + close(fd); + return ret; } static void |