aboutsummaryrefslogtreecommitdiff
path: root/toys/pending
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-10-07 15:04:09 -0500
committerRob Landley <rob@landley.net>2013-10-07 15:04:09 -0500
commit907d423f0093b0e31ce103fa7b86348431affb9b (patch)
tree7d14bfe691b53d2df6ab8391ba140f4ed87d420d /toys/pending
parentef13522938025fbc56a1a6fc27c6887965d98630 (diff)
downloadtoybox-907d423f0093b0e31ce103fa7b86348431affb9b.tar.gz
blkid cleanup: more whitespace (including fixing a strange unindented if block), convert strange fstype inclusion to OLDTOY(), use "<1" arg so calling with no arguments doesn't hang, convert typedef to normal struct.
Diffstat (limited to 'toys/pending')
-rw-r--r--toys/pending/blkid.c135
1 files changed, 57 insertions, 78 deletions
diff --git a/toys/pending/blkid.c b/toys/pending/blkid.c
index 295e4a7e..c5d6558b 100644
--- a/toys/pending/blkid.c
+++ b/toys/pending/blkid.c
@@ -4,7 +4,8 @@
*
* See ftp://ftp.kernel.org/pub/linux/utils/util-linux/v2.24/libblkid-docs/api-index-full.html
-USE_BLKID(NEWTOY(blkid, NULL, TOYFLAG_BIN))
+USE_BLKID(NEWTOY(blkid, "<1", TOYFLAG_BIN))
+USE_BLKID(OLDTOY(fstype, blkid, "<1", TOYFLAG_BIN))
config BLKID
bool "blkid"
@@ -12,8 +13,8 @@ config BLKID
help
usage: blkid [block device...]
Prints type, label and UUID of filesystem.
-
*/
+
#define FOR_blkid
#include "toys.h"
@@ -25,15 +26,14 @@ config BLKID
/* may need to check endianess for C2I */
#define C2I(a,b,c,d) (a|(b<<8)|(c<<16)|(d<<24))
-typedef struct fs_info{
+struct fs_info {
unsigned uuid_off;
unsigned lab_off;
short uuid_t;
short lab_len;
-}fs_info_t;
+};
-//#define SET_FS(t) (fs_info_t){t##_UUID,t##_LABEL,t##_UUID_T,t##_LABEL_SZ}
-#define SET_FS(t) (fs_info_t)t##_INFO
+#define SET_FS(t) (struct fs_info)t##_INFO
#define ADFS_MAGIC 0xadf5
#define ADFS_TYPE short
@@ -120,18 +120,20 @@ typedef struct fs_info{
#define XFS_MAGIC C2I('X','F','S','B')
#define XFS_INFO {32,108,16,12}
-#if (CFG_BLKID)
-char *toutf8(unsigned short * ws){ /* hack for NTFS utf16 */
+/* hack for NTFS utf16 */
+char *toutf8(unsigned short *ws)
+{
static char buf[16];
int i=0;
+
while((buf[i++]=*ws++));
return buf;
}
-#endif
/* TODO if no args use proc/partitions */
-void do_blkid(int fd, char *name){
- fs_info_t fs;
+void do_blkid(int fd, char *name)
+{
+ struct fs_info fs;
char *fstype;
unsigned char buf[66560]; /*toybuf is only 4096, could rework logic*/
int sb_read;
@@ -139,102 +141,79 @@ void do_blkid(int fd, char *name){
sb_read = read(fd, &buf, sizeof(buf));
if (sb_read < 1) return;
- if MATCH(buf,ADFS){
+ if MATCH(buf,ADFS) {
fstype="adfs";
if (CFG_BLKID) fs=SET_FS(ADFS);
- }else if MATCH(buf,BFS){
+ } else if MATCH(buf,BFS) {
fstype="bfs";
if (CFG_BLKID) fs=SET_FS(BFS);
- }else if MATCH(buf,CRAMFS){
+ } else if MATCH(buf,CRAMFS) {
fstype="cramfs";
if (CFG_BLKID) fs=SET_FS(CRAMFS);
- }else if MATCH3(buf,EXT){
+ } else if MATCH3(buf,EXT) {
fstype=(buf[EXT3_BYTE]&BIT(2))?((buf[EXT4_BYTE]&BIT(6))?"ext4":"ext3"):"ext2";
if (CFG_BLKID) fs=SET_FS(EXT);
- }else if MATCH(buf,F2FS){
+ } else if MATCH(buf,F2FS) {
fstype="f2fs";
if (CFG_BLKID) fs=SET_FS(F2FS);
- }else if MATCH(buf,NILFS){
+ } else if MATCH(buf,NILFS) {
fstype="nilfs";
if (CFG_BLKID) fs=SET_FS(NILFS);
- }else if MATCH(buf,NTFS){
+ } else if MATCH(buf,NTFS) {
fstype="ntfs";
if (CFG_BLKID) fs=SET_FS(NTFS);
- }else if MATCH(buf,XIAFS){
+ } else if MATCH(buf,XIAFS) {
fstype="xiafs";
if (CFG_BLKID) fs=SET_FS(XIAFS);
/*below here would require more than 1 toybuf*/
- }else if MATCH(buf,REISER){
+ } else if MATCH(buf,REISER) {
fstype="reiserfs";
if (CFG_BLKID) fs=SET_FS(REISER);
- }else if MATCH(buf,JFS){
+ } else if MATCH(buf,JFS) {
fstype="jfs";
if (CFG_BLKID) fs=SET_FS(JFS);
- }else if MATCH(buf,BTRFS){
+ } else if MATCH(buf,BTRFS) {
fstype="btrfs";
if (CFG_BLKID) fs=SET_FS(BTRFS);
- }else if MATCH(buf,REISERB){
+ } else if MATCH(buf,REISERB) {
fstype="reiserfs";
if (CFG_BLKID) fs=SET_FS(REISERB);
- }else return;
-
-if (CFG_BLKID && !strncmp("blkid",toys.which->name,5) ){
- printf("%s:",name);
- if ( fs.lab_len > 0 )
- printf(" LABEL=\"%.*s\"", fs.lab_len, (char *)&buf[fs.lab_off]);
- else if ( fs.lab_len < 0 )
- printf(" LABEL=\"%.*s\"", -fs.lab_len,
- toutf8((unsigned short *)&buf[fs.lab_off]));
- if ( fs.uuid_off > 0 ){
- if ( fs.uuid_t == 16 )
- printf(" UUID=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
- "%02x%02x%02x%02x%02x%02x\"",
- buf[fs.uuid_off], buf[fs.uuid_off+1],
- buf[fs.uuid_off+2], buf[fs.uuid_off+3],
- buf[fs.uuid_off+4], buf[fs.uuid_off+5],
- buf[fs.uuid_off+6], buf[fs.uuid_off+7],
- buf[fs.uuid_off+8], buf[fs.uuid_off+9],
- buf[fs.uuid_off+10], buf[fs.uuid_off+11],
- buf[fs.uuid_off+12], buf[fs.uuid_off+13],
- buf[fs.uuid_off+14], buf[fs.uuid_off+15]);
- if ( fs.uuid_t == 8 )
- printf(" UUID=\"%02X%02X%02X%02X%02X%02X%02X%02X\"",
- buf[fs.uuid_off+7], buf[fs.uuid_off+6],
- buf[fs.uuid_off+5], buf[fs.uuid_off+4],
- buf[fs.uuid_off+3], buf[fs.uuid_off+2],
- buf[fs.uuid_off+1], buf[fs.uuid_off]);
- }
- printf(" TYPE=\"%s\"",fstype);
-}else /* fstype */
- write(1,fstype,strlen(fstype)); /* avoid printf overhead in fstype */
+ } else return;
+
+ if (CFG_BLKID && !strncmp("blkid",toys.which->name,5) ) {
+ printf("%s:",name);
+ if (fs.lab_len > 0)
+ printf(" LABEL=\"%.*s\"", fs.lab_len, (char *)&buf[fs.lab_off]);
+ else if (fs.lab_len < 0)
+ printf(" LABEL=\"%.*s\"", -fs.lab_len,
+ toutf8((unsigned short *)&buf[fs.lab_off]));
+ if (fs.uuid_off > 0) {
+ if (fs.uuid_t == 16)
+ printf(" UUID=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
+ "%02x%02x%02x%02x%02x%02x\"",
+ buf[fs.uuid_off], buf[fs.uuid_off+1],
+ buf[fs.uuid_off+2], buf[fs.uuid_off+3],
+ buf[fs.uuid_off+4], buf[fs.uuid_off+5],
+ buf[fs.uuid_off+6], buf[fs.uuid_off+7],
+ buf[fs.uuid_off+8], buf[fs.uuid_off+9],
+ buf[fs.uuid_off+10], buf[fs.uuid_off+11],
+ buf[fs.uuid_off+12], buf[fs.uuid_off+13],
+ buf[fs.uuid_off+14], buf[fs.uuid_off+15]);
+ if (fs.uuid_t == 8)
+ printf(" UUID=\"%02X%02X%02X%02X%02X%02X%02X%02X\"",
+ buf[fs.uuid_off+7], buf[fs.uuid_off+6],
+ buf[fs.uuid_off+5], buf[fs.uuid_off+4],
+ buf[fs.uuid_off+3], buf[fs.uuid_off+2],
+ buf[fs.uuid_off+1], buf[fs.uuid_off]);
+ }
+ printf(" TYPE=\"%s\"",fstype);
+
+ /* avoid printf overhead in fstype */
+ } else write(1,fstype,strlen(fstype));
putchar('\n');
}
-#if (CFG_BLKID)
void blkid_main(void)
{
loopfiles(toys.optargs, do_blkid);
}
-#endif
-
-
-/* fstype.c - Prints type of filesystem(s).
- *
- * Copyright 2013 Brad Conroy <bconroy@uis.edu>
-
-USE_FSTYPE(NEWTOY(fstype, NULL, TOYFLAG_BIN))
-
-config FSTYPE
- bool "fstype"
- default n
- help
- usage: fstype [block device...]
- Prints type of filesystem.
-*/
-#define FOR_fstype
-#include "toys.h"
-void do_blkid(int fd, char *name);
-void fstype_main(void)
-{
- loopfiles(toys.optargs, do_blkid);
-}