aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDan Fandrich <dan@coneharvesters.com>2011-02-20 04:15:43 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-20 04:15:43 +0100
commitf303bdd918e762f492068f3127b2f7fdac94bd28 (patch)
tree167b3f86c0c845ff50aacb8a069122bc1479e446 /util-linux
parent5369563bf9b9b5406714a65f9199aaa0b6b53fef (diff)
downloadbusybox-f303bdd918e762f492068f3127b2f7fdac94bd28.tar.gz
blockdev: add --getsz to replace --getsize
function old new delta blockdev_main 255 273 +18 bdcommands 160 176 +16 packed_usage 28142 28107 -35 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 34/-35) Total: -1 bytes Signed-off-by: Dan Fandrich <dan@coneharvesters.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/blockdev.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/util-linux/blockdev.c b/util-linux/blockdev.c
index c2fcaee88..4aed02982 100644
--- a/util-linux/blockdev.c
+++ b/util-linux/blockdev.c
@@ -26,7 +26,8 @@
//usage: "\n --getss Get sector size"
//usage: "\n --getbsz Get block size"
//usage: "\n --setbsz BYTES Set block size"
-//usage: "\n --getsize Get device size in 512-byte sectors"
+//usage: "\n --getsz Get device size in 512-byte sectors"
+/*//usage: "\n --getsize Get device size in sectors (deprecated)"*/
//usage: "\n --getsize64 Get device size in bytes"
//usage: "\n --flushbufs Flush buffers"
//usage: "\n --rereadpt Reread partition table"
@@ -45,6 +46,7 @@ enum {
FL_USRARG = 4, /* argument is provided by user */
FL_NORESULT = 8,
+ FL_SCALE512 = 16,
};
struct bdc {
@@ -86,6 +88,11 @@ static const struct bdc bdcommands[] = {
.flags = ARG_INT + FL_NORESULT + FL_USRARG,
.argval = 0,
},{
+ .ioc = BLKGETSIZE64,
+ .name = "getsz",
+ .flags = ARG_U64 + FL_SCALE512,
+ .argval = -1,
+ },{
.ioc = BLKGETSIZE,
.name = "getsize",
.flags = ARG_ULONG,
@@ -123,7 +130,7 @@ static const struct bdc *find_cmd(const char *s)
}
int blockdev_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int blockdev_main(int argc, char **argv)
+int blockdev_main(int argc UNUSED_PARAM, char **argv)
{
const struct bdc *bdcmd;
int fd;
@@ -134,18 +141,20 @@ int blockdev_main(int argc, char **argv)
uint64_t u64;
} ioctl_val_on_stack;
- if ((unsigned)(argc - 3) > 1) /* must have 2 or 3 args */
+ argv++;
+ if (!argv[0] || !argv[1]) /* must have at least 2 args */
bb_show_usage();
- bdcmd = find_cmd(*++argv);
+ bdcmd = find_cmd(*argv);
u64 = (int)bdcmd->argval;
if (bdcmd->flags & FL_USRARG)
u64 = xatoi_positive(*++argv);
- if (!*++argv || argv[1])
+ argv++;
+ if (!argv[0] || argv[1])
bb_show_usage();
- fd = xopen(*argv, O_RDONLY);
+ fd = xopen(argv[0], O_RDONLY);
ioctl_val_on_stack.u64 = u64;
#if BB_BIG_ENDIAN
@@ -173,6 +182,9 @@ int blockdev_main(int argc, char **argv)
/* Fetch it into register(s) */
u64 = ioctl_val_on_stack.u64;
+ if (bdcmd->flags & FL_SCALE512)
+ u64 >>= 9;
+
/* Zero- or one-extend the value if needed, then print */
switch (bdcmd->flags & (ARG_MASK+FL_NORESULT)) {
case ARG_INT: