diff options
author | kraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-05-21 15:00:39 +0000 |
---|---|---|
committer | kraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2001-05-21 15:00:39 +0000 |
commit | b34b5bfdd7974b4387768907e0f446854b84f527 (patch) | |
tree | cc185648bf940caf94883e473b3de49f65d1ffac /mt.c | |
parent | 95f13f2a3c7b4a8fee5f723be7c5bd73ce644a63 (diff) | |
download | busybox-w32-b34b5bfdd7974b4387768907e0f446854b84f527.tar.gz busybox-w32-b34b5bfdd7974b4387768907e0f446854b84f527.tar.bz2 busybox-w32-b34b5bfdd7974b4387768907e0f446854b84f527.zip |
Fix open mode for IOCTLs which write to the tape.
git-svn-id: svn://busybox.net/trunk/busybox@2678 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'mt.c')
-rw-r--r-- | mt.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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) |