diff options
author | Ng Zhi An <zhin@google.com> | 2018-03-09 13:13:12 -0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-03-10 19:33:31 -0600 |
commit | a36cf940366ed0ad303fa25044e9964617e73c22 (patch) | |
tree | 30b02eee22e5650e5424ff17f84c6464ead3c582 /toys | |
parent | 5d61b1cf41719ef6e64746868dba53a085499f64 (diff) | |
download | toybox-a36cf940366ed0ad303fa25044e9964617e73c22.tar.gz |
Add getra and setra to blockdev
Bug: 74390492
Diffstat (limited to 'toys')
-rw-r--r-- | toys/other/blockdev.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/toys/other/blockdev.c b/toys/other/blockdev.c index 38e09935..e5fd0c3c 100644 --- a/toys/other/blockdev.c +++ b/toys/other/blockdev.c @@ -4,7 +4,7 @@ * * No Standard. -USE_BLOCKDEV(NEWTOY(blockdev, "<1>1(setro)(setrw)(getro)(getss)(getbsz)(setbsz)#<0(getsz)(getsize)(getsize64)(flushbufs)(rereadpt)",TOYFLAG_USR|TOYFLAG_BIN)) +USE_BLOCKDEV(NEWTOY(blockdev, "<1>1(setro)(setrw)(getro)(getss)(getbsz)(setbsz)#<0(getsz)(getsize)(getsize64)(getra)(setra)#<0(flushbufs)(rereadpt)",TOYFLAG_USR|TOYFLAG_BIN)) config BLOCKDEV bool "blockdev" @@ -24,6 +24,8 @@ config BLOCKDEV --getsz Get device size in 512-byte sectors --getsize Get device size in sectors (deprecated) --getsize64 Get device size in bytes + --getra Get readahead in 512-byte sectors + --setra <sectors> Set readahead --flushbufs Flush buffers --rereadpt Reread partition table */ @@ -34,11 +36,12 @@ config BLOCKDEV GLOBALS( long bsz; + long ra; ) void blockdev_main(void) { - int cmds[] = {BLKRRPART, BLKFLSBUF, BLKGETSIZE64, BLKGETSIZE, BLKGETSIZE64, + int cmds[] = {BLKRRPART, BLKFLSBUF, BLKRASET, BLKRAGET, BLKGETSIZE64, BLKGETSIZE, BLKGETSIZE64, BLKBSZSET, BLKBSZGET, BLKSSZGET, BLKROGET, BLKROSET, BLKROSET}; char **ss; long long val = 0; @@ -57,10 +60,12 @@ void blockdev_main(void) if (flag & FLAG_setbsz) val = TT.bsz; else val = !!(flag & FLAG_setro); + if (flag & FLAG_setra) val = TT.ra; + xioctl(fd, cmds[i], &val); - flag &= FLAG_setbsz|FLAG_setro|FLAG_flushbufs|FLAG_rereadpt|FLAG_setrw; - if (!flag) printf("%lld\n", (toys.optflags & FLAG_getsz) ? val >> 9: val); + flag &= FLAG_setbsz|FLAG_setro|FLAG_flushbufs|FLAG_rereadpt|FLAG_setrw|FLAG_setbsz; + if (!flag) printf("%lld\n", (toys.optflags & (FLAG_getsz|FLAG_getra)) ? val >> 9: val); } xclose(fd); } |