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 | |
parent | 9ffb7dd9a4688161140a4c19221247566886ef55 (diff) | |
download | busybox-13a70ac2ab7cd2b87e7a8618c64b72b84e9fcabc.tar.gz |
Fix open mode for IOCTLs which write to the tape.
-rw-r--r-- | miscutils/mt.c | 17 | ||||
-rw-r--r-- | mt.c | 17 |
2 files changed, 30 insertions, 4 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) const char *file = "/dev/tape"; const struct mt_opcodes *code = opcodes; struct mtop op; - int fd; + int fd, mode; if (argc < 2) { show_usage(); @@ -87,7 +87,20 @@ extern int mt_main(int argc, char **argv) else op.mt_count = 1; /* One, not zero, right? */ - if ((fd = open(file, O_RDONLY, 0)) < 0) + switch (code->value) { + case MTWEOF: + case MTERASE: + case MTWSM: + case MTSETDRVBUFFER: + mode = O_WRONLY; + break; + + default: + mode = O_RDONLY; + break; + } + + if ((fd = open(file, mode, 0)) < 0) perror_msg_and_die("%s", file); if (ioctl(fd, MTIOCTOP, &op) != 0) @@ -55,7 +55,7 @@ extern int mt_main(int argc, char **argv) const char *file = "/dev/tape"; const struct mt_opcodes *code = opcodes; struct mtop op; - int fd; + int fd, mode; if (argc < 2) { show_usage(); @@ -87,7 +87,20 @@ extern int mt_main(int argc, char **argv) else op.mt_count = 1; /* One, not zero, right? */ - if ((fd = open(file, O_RDONLY, 0)) < 0) + switch (code->value) { + case MTWEOF: + case MTERASE: + case MTWSM: + case MTSETDRVBUFFER: + mode = O_WRONLY; + break; + + default: + mode = O_RDONLY; + break; + } + + if ((fd = open(file, mode, 0)) < 0) perror_msg_and_die("%s", file); if (ioctl(fd, MTIOCTOP, &op) != 0) |