diff options
author | Scott Anderson <saa@android.com> | 2013-10-17 15:30:54 -0700 |
---|---|---|
committer | Scott Anderson <saa@android.com> | 2013-10-17 17:20:37 -0700 |
commit | 9e97fee0190307dd38eb2e3cd76b4ec60ab057b7 (patch) | |
tree | e41416661a93b1636f578eba64b6d1b53b0e6664 | |
parent | 8ac7c9f6593f1fcdca5d79297e4d8ba550df19c9 (diff) | |
download | system_core-9e97fee0190307dd38eb2e3cd76b4ec60ab057b7.zip system_core-9e97fee0190307dd38eb2e3cd76b4ec60ab057b7.tar.gz system_core-9e97fee0190307dd38eb2e3cd76b4ec60ab057b7.tar.bz2 |
Enhance the ioctl toolbox command
1) Implement documented but unimplemented read-only option.
2) Allow standard input to be used as the <device> by passing
"-". On some devices, opening the device has side effects.
Allowing standard input can prevent this by using a sequence
of something like:
# Open the device on file descriptor 3
exec 3<> /dev/something
ioctl -d - 0 0 <&3
ioctl -d - 1 0 <&3
dd if=myfile >&3
# Close file descriptor 3
exec 3>&-
Change-Id: If17ac3cffa7ccb159051550724b4ce7d8efa5feb
Signed-off-by: Scott Anderson <saa@android.com>
-rw-r--r-- | toolbox/ioctl.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/toolbox/ioctl.c b/toolbox/ioctl.c index fb555d2..fd24885 100644 --- a/toolbox/ioctl.c +++ b/toolbox/ioctl.c @@ -63,10 +63,14 @@ int ioctl_main(int argc, char *argv[]) exit(1); } - fd = open(argv[optind], O_RDWR | O_SYNC); - if (fd < 0) { - fprintf(stderr, "cannot open %s\n", argv[optind]); - return 1; + if (!strcmp(argv[optind], "-")) { + fd = STDIN_FILENO; + } else { + fd = open(argv[optind], read_only ? O_RDONLY : (O_RDWR | O_SYNC)); + if (fd < 0) { + fprintf(stderr, "cannot open %s\n", argv[optind]); + return 1; + } } optind++; |