*
* Copyright (C) 2010 Sergey Naumov <sknaumov@gmail.com>
*
- * Licensed under GPLv2, see file License in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
*/
-
-//applet:IF_BLOCKDEV(APPLET(blockdev, _BB_DIR_SBIN, _BB_SUID_DROP))
-
-//kbuild:lib-$(CONFIG_BLOCKDEV) += blockdev.o
-
//config:config BLOCKDEV
-//config: bool "blockdev"
+//config: bool "blockdev (2.4 kb)"
//config: default y
//config: help
-//config: Performs some ioctls with block devices.
+//config: Performs some ioctls with block devices.
+
+//applet:IF_BLOCKDEV(APPLET_NOEXEC(blockdev, blockdev, BB_DIR_SBIN, BB_SUID_DROP, blockdev))
+
+//kbuild:lib-$(CONFIG_BLOCKDEV) += blockdev.o
//usage:#define blockdev_trivial_usage
//usage: "OPTION BLOCKDEV"
//usage:#define blockdev_full_usage "\n\n"
-//usage: "Options:"
-//usage: "\n --setro Set ro"
+//usage: " --setro Set ro"
//usage: "\n --setrw Set rw"
//usage: "\n --getro Get ro"
//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"
FL_USRARG = 4, /* argument is provided by user */
FL_NORESULT = 8,
+ FL_SCALE512 = 16,
};
struct bdc {
.name = "setbsz",
.flags = ARG_INT + FL_NORESULT + FL_USRARG,
.argval = 0,
+ },{
+ .ioc = BLKGETSIZE64,
+ .name = "getsz",
+ .flags = ARG_U64 + FL_SCALE512,
+ .argval = -1,
},{
.ioc = BLKGETSIZE,
.name = "getsize",
}
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;
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
/* 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: