diff options
| author | Matt Kraai <kraai@debian.org> | 2001-05-21 15:00:39 +0000 |
|---|---|---|
| committer | Matt Kraai <kraai@debian.org> | 2001-05-21 15:00:39 +0000 |
| commit | 13a70ac2ab7cd2b87e7a8618c64b72b84e9fcabc (patch) | |
| tree | cc185648bf940caf94883e473b3de49f65d1ffac /miscutils | |
| parent | 9ffb7dd9a4688161140a4c19221247566886ef55 (diff) | |
| download | busybox-w32-13a70ac2ab7cd2b87e7a8618c64b72b84e9fcabc.tar.gz busybox-w32-13a70ac2ab7cd2b87e7a8618c64b72b84e9fcabc.tar.bz2 busybox-w32-13a70ac2ab7cd2b87e7a8618c64b72b84e9fcabc.zip | |
Fix open mode for IOCTLs which write to the tape.
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/mt.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/miscutils/mt.c b/miscutils/mt.c index 250856f05..cd926272e 100644 --- a/miscutils/mt.c +++ b/miscutils/mt.c | |||
| @@ -55,7 +55,7 @@ extern int mt_main(int argc, char **argv) | |||
| 55 | const char *file = "/dev/tape"; | 55 | const char *file = "/dev/tape"; |
| 56 | const struct mt_opcodes *code = opcodes; | 56 | const struct mt_opcodes *code = opcodes; |
| 57 | struct mtop op; | 57 | struct mtop op; |
| 58 | int fd; | 58 | int fd, mode; |
| 59 | 59 | ||
| 60 | if (argc < 2) { | 60 | if (argc < 2) { |
| 61 | show_usage(); | 61 | show_usage(); |
| @@ -87,7 +87,20 @@ extern int mt_main(int argc, char **argv) | |||
| 87 | else | 87 | else |
| 88 | op.mt_count = 1; /* One, not zero, right? */ | 88 | op.mt_count = 1; /* One, not zero, right? */ |
| 89 | 89 | ||
| 90 | if ((fd = open(file, O_RDONLY, 0)) < 0) | 90 | switch (code->value) { |
| 91 | case MTWEOF: | ||
| 92 | case MTERASE: | ||
| 93 | case MTWSM: | ||
| 94 | case MTSETDRVBUFFER: | ||
| 95 | mode = O_WRONLY; | ||
| 96 | break; | ||
| 97 | |||
| 98 | default: | ||
| 99 | mode = O_RDONLY; | ||
| 100 | break; | ||
| 101 | } | ||
| 102 | |||
| 103 | if ((fd = open(file, mode, 0)) < 0) | ||
| 91 | perror_msg_and_die("%s", file); | 104 | perror_msg_and_die("%s", file); |
| 92 | 105 | ||
| 93 | if (ioctl(fd, MTIOCTOP, &op) != 0) | 106 | if (ioctl(fd, MTIOCTOP, &op) != 0) |
