[PATCH 1/2] blkid: add fs-type output

Hans Ulli Kroll elektroman at nas-portal.org
Sat May 30 11:21:42 UTC 2009


Signed-off-by: Hans Ulli Kroll <elektroman at nas-portal.org>
---
 include/usage.h                           |    6 +++-
 include/volume_id.h                       |    2 +-
 util-linux/blkid.c                        |   15 ++++++++++-
 util-linux/volume_id/get_devname.c        |   38 +++++++++++++++++++----------
 util-linux/volume_id/volume_id_internal.h |    8 +++---
 5 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/include/usage.h b/include/usage.h
index e606925..8e23ad7 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1174,9 +1174,11 @@
      "\n	-S SECTORS" \
 
 #define blkid_trivial_usage \
-       ""
+       "[dev ...]\n"
+
 #define blkid_full_usage "\n\n" \
-       "Print UUIDs of all filesystems."
+       "Print UUIDs of all filesystems.\n" \
+       "\n     dev specify device(s) to probe (default: all devices)"
 
 #define findfs_trivial_usage \
        "LABEL=label or UUID=uuid"
diff --git a/include/volume_id.h b/include/volume_id.h
index bba32c0..8389cca 100644
--- a/include/volume_id.h
+++ b/include/volume_id.h
@@ -20,4 +20,4 @@
 
 char *get_devname_from_label(const char *spec);
 char *get_devname_from_uuid(const char *spec);
-void display_uuid_cache(void);
+void display_uuid_cache(const char *dev_name);
diff --git a/util-linux/blkid.c b/util-linux/blkid.c
index ec699d1..a728c1b 100644
--- a/util-linux/blkid.c
+++ b/util-linux/blkid.c
@@ -11,8 +11,19 @@
 #include "volume_id.h"
 
 int blkid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int blkid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+int blkid_main(int argc, char **argv)
 {
-	display_uuid_cache();
+	argv++;
+	argc--;
+
+	if (argc > 1) {
+		while (argc >= 1) {
+			display_uuid_cache (*argv);
+			argv++;
+			argc--;
+		}
+	} else {
+		display_uuid_cache (NULL);
+	}
 	return 0;
 }
diff --git a/util-linux/volume_id/get_devname.c b/util-linux/volume_id/get_devname.c
index ac69f78..e2eebb8 100644
--- a/util-linux/volume_id/get_devname.c
+++ b/util-linux/volume_id/get_devname.c
@@ -18,6 +18,7 @@ static struct uuidCache_s {
 	char *device;
 	char *label;
 	char *uc_uuid; /* prefix makes it easier to grep for */
+	char *type_version;
 } *uuidCache;
 
 /* Returns !0 on error.
@@ -25,7 +26,7 @@ static struct uuidCache_s {
  * (and they can't be NULL, although they can be "").
  * NB: closes fd. */
 static int
-get_label_uuid(int fd, char **label, char **uuid)
+get_label_uuid(int fd, char **label, char **uuid, char **type_version)
 {
 	int rv = 1;
 	uint64_t size;
@@ -43,6 +44,7 @@ get_label_uuid(int fd, char **label, char **uuid)
 	if (vid->label[0] != '\0' || vid->uuid[0] != '\0') {
 		*label = xstrndup(vid->label, sizeof(vid->label));
 		*uuid  = xstrndup(vid->uuid, sizeof(vid->uuid));
+		*type_version = xstrndup(vid->type_version, sizeof(vid->type_version));
 		dbg("found label '%s', uuid '%s' on %s", *label, *uuid, device);
 		rv = 0;
 	}
@@ -53,7 +55,10 @@ get_label_uuid(int fd, char **label, char **uuid)
 
 /* NB: we take ownership of (malloc'ed) label and uuid */
 static void
-uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid)
+uuidcache_addentry(char *device, /*int major, int minor,*/
+		char *label,
+		char *uuid,
+		char *type_version)
 {
 	struct uuidCache_s *last;
 
@@ -71,6 +76,7 @@ uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uu
 	last->device = device;
 	last->label = label;
 	last->uc_uuid = uuid;
+	last->type_version = type_version;
 }
 
 /* If get_label_uuid() on device_name returns success,
@@ -84,6 +90,7 @@ uuidcache_check_device(const char *device,
 {
 	char *uuid = uuid; /* for compiler */
 	char *label = label;
+	char *type_version = type_version;
 	int fd;
 
 	if (!S_ISBLK(statbuf->st_mode))
@@ -94,9 +101,9 @@ uuidcache_check_device(const char *device,
 		return TRUE;
 
 	/* get_label_uuid() closes fd in all cases (success & failure) */
-	if (get_label_uuid(fd, &label, &uuid) == 0) {
+	if (get_label_uuid(fd, &label, &uuid, &type_version) == 0) {
 		/* uuidcache_addentry() takes ownership of all three params */
-		uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid);
+		uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid, type_version);
 	}
 	return TRUE;
 }
@@ -200,20 +207,24 @@ get_spec_by_volume_label(const char *s, int *major, int *minor)
 }
 #endif // UNUSED
 
-/* Used by blkid */
-void display_uuid_cache(void)
+/* Used by blkid, if *dev is NULL show all, otherwise only one */
+void display_uuid_cache(const char *devname)
 {
 	struct uuidCache_s *u;
 
 	uuidcache_init();
 	u = uuidCache;
 	while (u) {
-		printf("%s:", u->device);
-		if (u->label[0])
-			printf(" LABEL=\"%s\"", u->label);
-		if (u->uc_uuid[0])
-			printf(" UUID=\"%s\"", u->uc_uuid);
-		bb_putchar('\n');
+		if (devname == NULL || strcasecmp (devname, u->device) == 0) {
+			printf("%s:", u->device);
+			if (u->label[0])
+				printf(" LABEL=\"%s\"", u->label);
+			if (u->uc_uuid[0])
+				printf(" UUID=\"%s\"", u->uc_uuid);
+			if (u->type_version[0])
+				printf(" TYPE=\"%s\"", u->type_version);
+			bb_putchar('\n');
+		}
 		u = u->next;
 	}
 }
@@ -246,7 +257,8 @@ char *get_devname_from_uuid(const char *spec)
 		if (strcasecmp(spec, uc->uc_uuid) == 0) {
 			return xstrdup(uc->device);
 		}
-		uc = uc->next;
 	}
+	uc = uc->next;
+
 	return NULL;
 }
diff --git a/util-linux/volume_id/volume_id_internal.h b/util-linux/volume_id/volume_id_internal.h
index af58883..d0a56d5 100644
--- a/util-linux/volume_id/volume_id_internal.h
+++ b/util-linux/volume_id/volume_id_internal.h
@@ -77,10 +77,10 @@ struct volume_id {
 //	size_t		uuid_raw_len;
 	/* uuid is stored in ASCII (not binary) form here: */
 	char		uuid[VOLUME_ID_UUID_SIZE+1];
-//	char		type_version[VOLUME_ID_FORMAT_SIZE];
+	char		type_version[VOLUME_ID_FORMAT_SIZE];
 //	smallint	usage_id;
-//	const char	*usage;
-//	const char	*type;
+//	char	usage;
+//	char	*type;
 };
 
 struct volume_id *volume_id_open_node(int fd);
@@ -148,7 +148,7 @@ enum endian {
 };
 
 void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count);
-//void volume_id_set_usage(struct volume_id *id, enum volume_id_usage usage_id);
+// void volume_id_set_usage(struct volume_id *id, enum volume_id_usage usage_id);
 //void volume_id_set_usage_part(struct volume_id_partition *part, enum volume_id_usage usage_id);
 //void volume_id_set_label_raw(struct volume_id *id, const uint8_t *buf, size_t count);
 void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t count);
-- 
1.6.3.1



More information about the busybox mailing list