aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/blockdev.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/util-linux/blockdev.c b/util-linux/blockdev.c
index 20a031377..3b550220a 100644
--- a/util-linux/blockdev.c
+++ b/util-linux/blockdev.c
@@ -25,8 +25,11 @@
25//usage: "\n --getbsz Get block size" 25//usage: "\n --getbsz Get block size"
26//usage: "\n --setbsz BYTES Set block size" 26//usage: "\n --setbsz BYTES Set block size"
27//usage: "\n --getsz Get device size in 512-byte sectors" 27//usage: "\n --getsz Get device size in 512-byte sectors"
28/*//usage: "\n --getsize Get device size in sectors (deprecated)"*/ 28///////: "\n --getsize Get device size in sectors (deprecated)"
29///////^^^^^ supported, but not shown in help ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29//usage: "\n --getsize64 Get device size in bytes" 30//usage: "\n --getsize64 Get device size in bytes"
31//usage: "\n --getra Get readahead in 512-byte sectors"
32//usage: "\n --setra SECTORS Set readahead"
30//usage: "\n --flushbufs Flush buffers" 33//usage: "\n --flushbufs Flush buffers"
31//usage: "\n --rereadpt Reread partition table" 34//usage: "\n --rereadpt Reread partition table"
32// util-linux 2.31 also has: 35// util-linux 2.31 also has:
@@ -57,6 +60,9 @@ static const char bdcmd_names[] ALIGN1 =
57 "getsz" "\0" 60 "getsz" "\0"
58 "getsize" "\0" 61 "getsize" "\0"
59 "getsize64" "\0" 62 "getsize64" "\0"
63 "getra" "\0"
64 "setra" "\0"
65#define CMD_SETRA 10
60 "flushbufs" "\0" 66 "flushbufs" "\0"
61 "rereadpt" "\0" 67 "rereadpt" "\0"
62; 68;
@@ -70,6 +76,8 @@ static const uint32_t bdcmd_ioctl[] ALIGN4 = {
70 BLKGETSIZE64, //getsz 76 BLKGETSIZE64, //getsz
71 BLKGETSIZE, //getsize 77 BLKGETSIZE, //getsize
72 BLKGETSIZE64, //getsize64 78 BLKGETSIZE64, //getsize64
79 BLKRAGET, //getra
80 BLKRASET, //setra
73 BLKFLSBUF, //flushbufs 81 BLKFLSBUF, //flushbufs
74 BLKRRPART, //rereadpt 82 BLKRRPART, //rereadpt
75}; 83};
@@ -95,6 +103,8 @@ static const uint8_t bdcmd_flags[] ALIGN1 = {
95 ARG_U64 + FL_SCALE512, //getsz 103 ARG_U64 + FL_SCALE512, //getsz
96 ARG_ULONG, //getsize 104 ARG_ULONG, //getsize
97 ARG_U64, //getsize64 105 ARG_U64, //getsize64
106 ARG_ULONG, //getra
107 ARG_ULONG + FL_NORESULT, //setra
98 ARG_NONE + FL_NORESULT, //flushbufs 108 ARG_NONE + FL_NORESULT, //flushbufs
99 ARG_NONE + FL_NORESULT, //rereadpt 109 ARG_NONE + FL_NORESULT, //rereadpt
100}; 110};
@@ -130,8 +140,9 @@ int blockdev_main(int argc UNUSED_PARAM, char **argv)
130 /* setrw translates to BLKROSET(0), most other ioctls don't care... */ 140 /* setrw translates to BLKROSET(0), most other ioctls don't care... */
131 /* ...setro will do BLKROSET(1) */ 141 /* ...setro will do BLKROSET(1) */
132 u64 = (bdcmd == CMD_SETRO); 142 u64 = (bdcmd == CMD_SETRO);
133 if (bdcmd == CMD_SETBSZ) { 143 if (bdcmd == CMD_SETBSZ || bdcmd == CMD_SETRA) {
134 /* ...setbsz is BLKBSZSET(bytes) */ 144 /* ...setbsz is BLKBSZSET(bytes) */
145 /* ...setra is BLKRASET(512 bytes) */
135 u64 = xatoi_positive(*++argv); 146 u64 = xatoi_positive(*++argv);
136 } 147 }
137 148
@@ -145,8 +156,11 @@ int blockdev_main(int argc UNUSED_PARAM, char **argv)
145#if BB_BIG_ENDIAN 156#if BB_BIG_ENDIAN
146 /* Store data properly wrt data size. 157 /* Store data properly wrt data size.
147 * (1) It's no-op for little-endian. 158 * (1) It's no-op for little-endian.
148 * (2) it's no-op for 0 and -1. Only --setro uses arg != 0 and != -1, 159 * (2) it's no-op for 0 and -1.
149 * and it is ARG_INT. --setbsz USER_VAL is also ARG_INT. 160 * --setro uses arg != 0 and != -1, and it is ARG_INT
161 * --setbsz USER_VAL is also ARG_INT
162 * --setra USER_VAL is ARG_ULONG, but it is passed by value,
163 * not reference (see below in ioctl call).
150 * Thus, we don't need to handle ARG_ULONG. 164 * Thus, we don't need to handle ARG_ULONG.
151 */ 165 */
152 switch (flags & ARG_MASK) { 166 switch (flags & ARG_MASK) {
@@ -161,7 +175,11 @@ int blockdev_main(int argc UNUSED_PARAM, char **argv)
161 } 175 }
162#endif 176#endif
163 177
164 if (ioctl(fd, bdcmd_ioctl[bdcmd], &ioctl_val_on_stack.u64) == -1) 178 if (ioctl(fd, bdcmd_ioctl[bdcmd],
179 bdcmd == CMD_SETRA
180 ? (void*)(uintptr_t)u64 /* BLKRASET passes _value_, not pointer to it */
181 : &ioctl_val_on_stack.u64
182 ) == -1)
165 bb_simple_perror_msg_and_die(*argv); 183 bb_simple_perror_msg_and_die(*argv);
166 184
167 /* Fetch it into register(s) */ 185 /* Fetch it into register(s) */