diff options
author | Dima Krasner <dima@dimakrasner.com> | 2015-08-05 23:05:49 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-08-05 23:05:49 -0500 |
commit | 42b7d4b06b55e0090c3be1bc6ca1ed166bd6b2fd (patch) | |
tree | b4b4d462004a5bd321fb209dbb277ab30777bb2b | |
parent | 802642ada1acd23fb4559678a916d2c00f6d1355 (diff) | |
download | toybox-42b7d4b06b55e0090c3be1bc6ca1ed166bd6b2fd.tar.gz toybox-42b7d4b06b55e0090c3be1bc6ca1ed166bd6b2fd.tar.bz2 toybox-42b7d4b06b55e0090c3be1bc6ca1ed166bd6b2fd.zip |
I've added support for running blkid without specifying a partition (so it scans /proc/partitions).
-rw-r--r-- | toys/other/blkid.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/toys/other/blkid.c b/toys/other/blkid.c index c18cc9c..1e1f7ed 100644 --- a/toys/other/blkid.c +++ b/toys/other/blkid.c @@ -4,7 +4,7 @@ * * See ftp://ftp.kernel.org/pub/linux/utils/util-linux/v2.24/libblkid-docs/api-index-full.html -USE_BLKID(NEWTOY(blkid, "<1", TOYFLAG_BIN)) +USE_BLKID(NEWTOY(blkid, NULL, TOYFLAG_BIN)) USE_FSTYPE(NEWTOY(fstype, "<1", TOYFLAG_BIN)) config BLKID @@ -27,6 +27,8 @@ config FSTYPE #define FOR_blkid #include "toys.h" +#define ONE_K 1024 + struct fstype { char *name; uint64_t magic; @@ -56,7 +58,6 @@ static const struct fstype fstypes[] = { {"vfat", 0x31544146, 4, 54, 39+(4<<24), 11, 43} // fat1 }; -/* TODO if no args use proc/partitions */ static void do_blkid(int fd, char *name) { int off, i, j; @@ -134,12 +135,36 @@ static void do_blkid(int fd, char *name) printf(" TYPE=\"%s\"\n", type); } +static void loop_partitions() +{ + unsigned int ma, mi, sz, fd; + char device[14]; + char *name = toybuf, *buffer = toybuf + ONE_K; + FILE* fp = xfopen("/proc/partitions", "r"); + + while (fgets(buffer, ONE_K, fp)) { + name[0] = '\0'; + if (sscanf(buffer, " %u %u %u %[^\n ]", &ma, &mi, &sz, name) != 4) + continue; + + sprintf(device,"/dev/%s",name); + fd = open(device, O_RDONLY); + if (-1 == fd) perror_exit("Could not open %s", device); + do_blkid(fd, device); + close(fd); + } + fclose(fp); +} + void blkid_main(void) { - loopfiles(toys.optargs, do_blkid); + if (*toys.optargs) + loopfiles(toys.optargs, do_blkid); + else + loop_partitions(); } void fstype_main(void) { - blkid_main(); + loopfiles(toys.optargs, do_blkid); } |