Mercurial > hg > toybox
changeset 1445:8b7ddefcf28c draft
Promote blockdev to other.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 23 Aug 2014 23:08:59 -0500 |
parents | 07e74271655e |
children | f46ccbcf3f13 |
files | toys/other/blockdev.c toys/pending/blockdev.c |
diffstat | 2 files changed, 70 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toys/other/blockdev.c Sat Aug 23 23:08:59 2014 -0500 @@ -0,0 +1,70 @@ +/* blockdev.c -show/set blockdev information. + * + * Copyright 2014 Sameer Prakash Pradhan <sameer.p.pradhan@gmail.com> + * + * No Standard. + +USE_BLOCKDEV(NEWTOY(blockdev, "<1>1(setro)(setrw)(getro)(getss)(getbsz)(setbsz)#<0(getsz)(getsize)(getsize64)(flushbufs)(rereadpt)",TOYFLAG_USR|TOYFLAG_BIN)) + +config BLOCKDEV + bool "blockdev" + default y + help + usage: blockdev --OPTION... BLOCKDEV... + + Call ioctl(s) on each listed block device + + OPTIONs: + --setro Set read only + --setrw Set read write + --getro Get read only + --getss Get sector size + --getbsz Get block size + --setbsz BYTES Set block size + --getsz Get device size in 512-byte sectors + --getsize Get device size in sectors (deprecated) + --getsize64 Get device size in bytes + --flushbufs Flush buffers + --rereadpt Reread partition table +*/ + +#define FOR_blockdev +#include "toys.h" +#include <linux/fs.h> + +GLOBALS( + long bsz; +) + +void blockdev_main(void) +{ + int cmds[] = {BLKRRPART, BLKFLSBUF, BLKGETSIZE64, BLKGETSIZE, BLKGETSIZE64, + BLKBSZSET, BLKBSZGET, BLKSSZGET, BLKROGET, BLKROSET, BLKROSET}; + char **ss; + long long val = 0; + + if (!toys.optflags) { + toys.exithelp = 1; + error_exit("need --option"); + } + + for (ss = toys.optargs; *ss; ss++) { + int fd = xopen(*ss, O_RDONLY), i; + + // Command line order discarded so perform multiple operations in flag order + for (i = 0; i < 32; i++) { + long flag = toys.optflags & (1<<i); + + if (!flag) continue; + + if (flag & FLAG_setbsz) val = TT.bsz; + else val = !!(flag & FLAG_setro); + + 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); + } + xclose(fd); + } +}
--- a/toys/pending/blockdev.c Sat Aug 23 23:08:04 2014 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* blockdev.c -show/set blockdev information. - * - * Copyright 2014 Sameer Prakash Pradhan <sameer.p.pradhan@gmail.com> - * - * No Standard. - -USE_BLOCKDEV(NEWTOY(blockdev, "<1>1(setro)(setrw)(getro)(getss)(getbsz)(setbsz)#<0(getsz)(getsize)(getsize64)(flushbufs)(rereadpt)",TOYFLAG_USR|TOYFLAG_BIN)) - -config BLOCKDEV - bool "blockdev" - default n - help - usage: blockdev --OPTION... BLOCKDEV... - - Call ioctl(s) on each listed block device - - OPTIONs: - --setro Set read only - --setrw Set read write - --getro Get read only - --getss Get sector size - --getbsz Get block size - --setbsz BYTES Set block size - --getsz Get device size in 512-byte sectors - --getsize Get device size in sectors (deprecated) - --getsize64 Get device size in bytes - --flushbufs Flush buffers - --rereadpt Reread partition table -*/ - -#define FOR_blockdev -#include "toys.h" -#include <linux/fs.h> - -GLOBALS( - long bsz; -) - -void blockdev_main(void) -{ - int cmds[] = {BLKRRPART, BLKFLSBUF, BLKGETSIZE64, BLKGETSIZE, BLKGETSIZE64, - BLKBSZSET, BLKBSZGET, BLKSSZGET, BLKROGET, BLKROSET, BLKROSET}; - char **ss; - long long val = 0; - - if (!toys.optflags) { - toys.exithelp = 1; - error_exit("need --option"); - } - - for (ss = toys.optargs; *ss; ss++) { - int fd = xopen(*ss, O_RDONLY), i; - - // Command line order discarded so perform multiple operations in flag order - for (i = 0; i < 32; i++) { - long flag = toys.optflags & (1<<i); - - if (!flag) continue; - - if (flag & FLAG_setbsz) val = TT.bsz; - else val = !!(flag & FLAG_setro); - - 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); - } - xclose(fd); - } -}