aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/blkid
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2006-03-08 07:03:27 +0000
committerMike Frysinger <vapier@gentoo.org>2006-03-08 07:03:27 +0000
commit874af85d5eb08b65476f406f6a1e7edc127ac210 (patch)
tree1cb4ee52f1592350dd9c4471b2a334957cc42b5e /e2fsprogs/blkid
parent0f2dd9f4eb9007bf44aa3f0cf30a35c36fbbd5b2 (diff)
downloadbusybox-874af85d5eb08b65476f406f6a1e7edc127ac210.tar.gz
import most of e2fsprogs 1.38 updates
Diffstat (limited to 'e2fsprogs/blkid')
-rw-r--r--e2fsprogs/blkid/blkid.h6
-rw-r--r--e2fsprogs/blkid/blkidP.h61
-rw-r--r--e2fsprogs/blkid/cache.c2
-rw-r--r--e2fsprogs/blkid/dev.c99
-rw-r--r--e2fsprogs/blkid/devno.c4
-rw-r--r--e2fsprogs/blkid/probe.c29
-rw-r--r--e2fsprogs/blkid/probe.h31
-rw-r--r--e2fsprogs/blkid/read.c33
-rw-r--r--e2fsprogs/blkid/tag.c101
9 files changed, 286 insertions, 80 deletions
diff --git a/e2fsprogs/blkid/blkid.h b/e2fsprogs/blkid/blkid.h
index 3bb0e78d8..c051b2b85 100644
--- a/e2fsprogs/blkid/blkid.h
+++ b/e2fsprogs/blkid/blkid.h
@@ -55,6 +55,8 @@ extern int blkid_get_cache(blkid_cache *cache, const char *filename);
extern const char *blkid_dev_devname(blkid_dev dev);
extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache);
+extern int blkid_dev_set_search(blkid_dev_iterate iter,
+ char *search_type, char *search_value);
extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
@@ -63,6 +65,7 @@ extern char *blkid_devno_to_devname(dev_t devno);
/* devname.c */
extern int blkid_probe_all(blkid_cache cache);
+extern int blkid_probe_all_new(blkid_cache cache);
extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname,
int flags);
@@ -86,7 +89,8 @@ extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev);
extern int blkid_tag_next(blkid_tag_iterate iterate,
const char **type, const char **value);
extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
-
+extern int blkid_dev_has_tag(blkid_dev dev, const char *type,
+ const char *value);
extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
const char *type,
const char *value);
diff --git a/e2fsprogs/blkid/blkidP.h b/e2fsprogs/blkid/blkidP.h
index 759dfcd87..4ae9763d2 100644
--- a/e2fsprogs/blkid/blkidP.h
+++ b/e2fsprogs/blkid/blkidP.h
@@ -147,65 +147,8 @@ extern int blkid_debug_mask;
#endif
#ifdef CONFIG_BLKID_DEBUG
-static inline void DEB_DUMP_TAG(int mask, blkid_tag tag)
-{
- if (!(mask & blkid_debug_mask))
- return;
-
- if (!tag) {
- printf(" tag: NULL\n");
- return;
- }
-
- printf(" tag: %s=\"%s\"\n", tag->bit_name, tag->bit_val);
-}
-
-static inline void DEB_DUMP_DEV(int mask, blkid_dev dev)
-{
- struct list_head *p;
-
- if (!(mask & blkid_debug_mask))
- return;
-
- if (!dev) {
- printf(" dev: NULL\n");
- return;
- }
-
- printf(" dev: name = %s\n", dev->bid_name);
- printf(" dev: DEVNO=\"0x%0Lx\"\n", dev->bid_devno);
- printf(" dev: TIME=\"%lu\"\n", dev->bid_time);
- printf(" dev: PRI=\"%d\"\n", dev->bid_pri);
- printf(" dev: flags = 0x%08X\n", dev->bid_flags);
-
- list_for_each(p, &dev->bid_tags) {
- blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
- DEB_DUMP_TAG(mask, tag);
- }
- printf("\n");
-}
-
-static inline void DEB_DUMP_CACHE(int mask, blkid_cache cache)
-{
- struct list_head *p;
-
- if (!cache || !(mask & blkid_debug_mask)) {
- printf("cache: NULL\n");
- return;
- }
-
- printf("cache: time = %lu\n", cache->bic_time);
- printf("cache: flags = 0x%08X\n", cache->bic_flags);
-
- list_for_each(p, &cache->bic_devs) {
- blkid_dev dev = list_entry(p, struct blkid_struct_dev, bid_devs);
- DEB_DUMP_DEV(mask, dev);
- }
-}
-#else
-#define DEB_DUMP_TAG(mask, tag) do {} while (0)
-#define DEB_DUMP_DEV(mask, dev) do {} while (0)
-#define DEB_DUMP_CACHE(mask, cache) do {} while (0)
+extern void blkid_debug_dump_dev(blkid_dev dev);
+extern void blkid_debug_dump_tag(blkid_tag tag);
#endif
/* lseek.c */
diff --git a/e2fsprogs/blkid/cache.c b/e2fsprogs/blkid/cache.c
index daccb30b3..9c9b8c7e4 100644
--- a/e2fsprogs/blkid/cache.c
+++ b/e2fsprogs/blkid/cache.c
@@ -63,7 +63,7 @@ void blkid_put_cache(blkid_cache cache)
DBG(DEBUG_CACHE, printf("freeing cache struct\n"));
- /* DEB_DUMP_CACHE(cache); */
+ /* DBG(DEBUG_CACHE, blkid_debug_dump_cache(cache)); */
while (!list_empty(&cache->bic_devs)) {
blkid_dev dev = list_entry(cache->bic_devs.next,
diff --git a/e2fsprogs/blkid/dev.c b/e2fsprogs/blkid/dev.c
index 04cf8b5fa..5d56c5096 100644
--- a/e2fsprogs/blkid/dev.c
+++ b/e2fsprogs/blkid/dev.c
@@ -35,7 +35,7 @@ void blkid_free_dev(blkid_dev dev)
DBG(DEBUG_DEV,
printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type));
- DEB_DUMP_DEV(DEBUG_DEV, dev);
+ DBG(DEBUG_DEV, blkid_debug_dump_dev(dev));
list_del(&dev->bid_devs);
while (!list_empty(&dev->bid_tags)) {
@@ -57,6 +57,34 @@ const char *blkid_dev_devname(blkid_dev dev)
return dev->bid_name;
}
+#ifdef CONFIG_BLKID_DEBUG
+void blkid_debug_dump_dev(blkid_dev dev)
+{
+ struct list_head *p;
+
+ if (!dev) {
+ printf(" dev: NULL\n");
+ return;
+ }
+
+ printf(" dev: name = %s\n", dev->bid_name);
+ printf(" dev: DEVNO=\"0x%0llx\"\n", dev->bid_devno);
+ printf(" dev: TIME=\"%lu\"\n", dev->bid_time);
+ printf(" dev: PRI=\"%d\"\n", dev->bid_pri);
+ printf(" dev: flags = 0x%08X\n", dev->bid_flags);
+
+ list_for_each(p, &dev->bid_tags) {
+ blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
+ if (tag)
+ printf(" tag: %s=\"%s\"\n", tag->bit_name,
+ tag->bit_val);
+ else
+ printf(" tag: NULL\n");
+ }
+ printf("\n");
+}
+#endif
+
/*
* dev iteration routines for the public libblkid interface.
*
@@ -114,3 +142,72 @@ void blkid_dev_iterate_end(blkid_dev_iterate iter)
free(iter);
}
+#ifdef TEST_PROGRAM
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern char *optarg;
+extern int optind;
+#endif
+
+void usage(char *prog)
+{
+ fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask]\n", prog);
+ fprintf(stderr, "\tList all devices and exit\n", prog);
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ blkid_dev_iterate iter;
+ blkid_cache cache = NULL;
+ blkid_dev dev;
+ int c, ret;
+ char *tmp;
+ char *file = NULL;
+ char *search_type = NULL;
+ char *search_value = NULL;
+
+ while ((c = getopt (argc, argv, "m:f:")) != EOF)
+ switch (c) {
+ case 'f':
+ file = optarg;
+ break;
+ case 'm':
+ blkid_debug_mask = strtoul (optarg, &tmp, 0);
+ if (*tmp) {
+ fprintf(stderr, "Invalid debug mask: %d\n",
+ optarg);
+ exit(1);
+ }
+ break;
+ case '?':
+ usage(argv[0]);
+ }
+ if (argc >= optind+2) {
+ search_type = argv[optind];
+ search_value = argv[optind+1];
+ optind += 2;
+ }
+ if (argc != optind)
+ usage(argv[0]);
+
+ if ((ret = blkid_get_cache(&cache, file)) != 0) {
+ fprintf(stderr, "%s: error creating cache (%d)\n",
+ argv[0], ret);
+ exit(1);
+ }
+
+ iter = blkid_dev_iterate_begin(cache);
+ if (search_type)
+ blkid_dev_set_search(iter, search_type, search_value);
+ while (blkid_dev_next(iter, &dev) == 0) {
+ printf("Device: %s\n", blkid_dev_devname(dev));
+ }
+ blkid_dev_iterate_end(iter);
+
+
+ blkid_put_cache(cache);
+ return (0);
+}
+#endif
diff --git a/e2fsprogs/blkid/devno.c b/e2fsprogs/blkid/devno.c
index 2979280f7..89119945c 100644
--- a/e2fsprogs/blkid/devno.c
+++ b/e2fsprogs/blkid/devno.c
@@ -117,7 +117,7 @@ static void scan_dir(char *dir_name, dev_t devno, struct dir_list **list,
else if (S_ISBLK(st.st_mode) && st.st_rdev == devno) {
*devname = blkid_strdup(path);
DBG(DEBUG_DEVNO,
- printf("found 0x%Lx at %s (%p)\n", devno,
+ printf("found 0x%llx at %s (%p)\n", devno,
path, *devname));
break;
}
@@ -175,7 +175,7 @@ char *blkid_devno_to_devname(dev_t devno)
(unsigned long) devno));
} else {
DBG(DEBUG_DEVNO,
- printf("found devno 0x%04Lx as %s\n", devno, devname));
+ printf("found devno 0x%04llx as %s\n", devno, devname));
}
diff --git a/e2fsprogs/blkid/probe.c b/e2fsprogs/blkid/probe.c
index 36f7177b8..5ee8a200e 100644
--- a/e2fsprogs/blkid/probe.c
+++ b/e2fsprogs/blkid/probe.c
@@ -98,7 +98,8 @@ static void get_ext2_info(blkid_dev dev, unsigned char *buf)
static int probe_ext3(int fd __BLKID_ATTR((unused)),
blkid_cache cache __BLKID_ATTR((unused)),
blkid_dev dev,
- const struct blkid_magic *id, unsigned char *buf)
+ struct blkid_magic *id __BLKID_ATTR((unused)),
+ unsigned char *buf)
{
struct ext2_super_block *es;
@@ -124,10 +125,10 @@ static int probe_ext3(int fd __BLKID_ATTR((unused)),
static int probe_ext2(int fd __BLKID_ATTR((unused)),
blkid_cache cache __BLKID_ATTR((unused)),
blkid_dev dev,
- const struct blkid_magic *id, unsigned char *buf)
+ struct blkid_magic *id __BLKID_ATTR((unused)),
+ unsigned char *buf)
{
struct ext2_super_block *es;
-// const char *sec_type = 0, *label = 0;
es = (struct ext2_super_block *)buf;
@@ -303,6 +304,23 @@ static int probe_romfs(int fd __BLKID_ATTR((unused)),
return 0;
}
+static int probe_cramfs(int fd __BLKID_ATTR((unused)),
+ blkid_cache cache __BLKID_ATTR((unused)),
+ blkid_dev dev,
+ struct blkid_magic *id __BLKID_ATTR((unused)),
+ unsigned char *buf)
+{
+ struct cramfs_super_block *csb;
+ const char *label = 0;
+
+ csb = (struct cramfs_super_block *)buf;
+
+ if (strlen((char *) csb->name))
+ label = (char *) csb->name;
+ blkid_set_tag(dev, "LABEL", label, 0);
+ return 0;
+}
+
static int probe_swap0(int fd __BLKID_ATTR((unused)),
blkid_cache cache __BLKID_ATTR((unused)),
blkid_dev dev,
@@ -321,7 +339,6 @@ static int probe_swap1(int fd,
unsigned char *buf __BLKID_ATTR((unused)))
{
struct swap_id_block *sws;
-// const char *label = 0;
probe_swap0(fd, cache, dev, id, buf);
/*
@@ -489,7 +506,7 @@ static const struct blkid_magic type_array[] = {
{ "xfs", 0, 0, 4, "XFSB", probe_xfs },
{ "romfs", 0, 0, 8, "-rom1fs-", probe_romfs },
{ "bfs", 0, 0, 4, "\316\372\173\033", 0 },
- { "cramfs", 0, 0, 4, "E=\315\034", 0 },
+ { "cramfs", 0, 0, 4, "E=\315\050", probe_cramfs },
{ "qnx4", 0, 4, 6, "QNX4FS", 0 },
{ "udf", 32, 1, 5, "BEA01", probe_udf },
{ "udf", 32, 1, 5, "BOOT2", probe_udf },
@@ -647,7 +664,7 @@ found_type:
blkid_set_tag(dev, "TYPE", type, 0);
- DBG(DEBUG_PROBE, printf("%s: devno 0x%04Lx, type %s\n",
+ DBG(DEBUG_PROBE, printf("%s: devno 0x%04llx, type %s\n",
dev->bid_name, st.st_rdev, type));
}
diff --git a/e2fsprogs/blkid/probe.h b/e2fsprogs/blkid/probe.h
index 530b8efe2..134913f59 100644
--- a/e2fsprogs/blkid/probe.h
+++ b/e2fsprogs/blkid/probe.h
@@ -108,13 +108,28 @@ struct romfs_super_block {
unsigned char ros_volume[16];
};
+struct cramfs_super_block {
+ __u8 magic[4];
+ __u32 size;
+ __u32 flags;
+ __u32 future;
+ __u8 signature[16];
+ struct cramfs_info {
+ __u32 crc;
+ __u32 edition;
+ __u32 blocks;
+ __u32 files;
+ } info;
+ __u8 name[16];
+};
+
struct swap_id_block {
/* unsigned char sws_boot[1024]; */
__u32 sws_version;
__u32 sws_lastpage;
__u32 sws_nrbad;
unsigned char sws_uuid[16];
- unsigned char sws_volume[16];
+ char sws_volume[16];
unsigned char sws_pad[117];
__u32 sws_badpg;
};
@@ -216,22 +231,22 @@ struct ocfs_volume_header {
unsigned char minor_version[4];
unsigned char major_version[4];
unsigned char signature[128];
- unsigned char mount[128];
- unsigned char mount_len[2];
+ char mount[128];
+ unsigned char mount_len[2];
};
struct ocfs_volume_label {
unsigned char disk_lock[48];
- unsigned char label[64];
+ char label[64];
unsigned char label_len[2];
unsigned char vol_id[16];
unsigned char vol_id_len[2];
};
#define ocfsmajor(o) ((__u32)o.major_version[0] \
- + (((__u32) o.major_version[1]) << 8) \
- + (((__u32) o.major_version[2]) << 16) \
- + (((__u32) o.major_version[3]) << 24))
+ + (((__u32) o.major_version[1]) << 8) \
+ + (((__u32) o.major_version[2]) << 16) \
+ + (((__u32) o.major_version[3]) << 24))
#define ocfslabellen(o) ((__u32)o.label_len[0] + (((__u32) o.label_len[1]) << 8))
#define ocfsmountlen(o) ((__u32)o.mount_len[0] + (((__u32) o.mount_len[1])<<8))
@@ -241,7 +256,7 @@ struct ocfs2_super_block {
unsigned char signature[8];
unsigned char s_dummy1[184];
unsigned char s_dummy2[80];
- unsigned char s_label[64];
+ char s_label[64];
unsigned char s_uuid[16];
};
diff --git a/e2fsprogs/blkid/read.c b/e2fsprogs/blkid/read.c
index 08a3162f3..5f7422b0c 100644
--- a/e2fsprogs/blkid/read.c
+++ b/e2fsprogs/blkid/read.c
@@ -33,6 +33,11 @@
#include <stdlib.h>
+#ifdef TEST_PROGRAM
+#define blkid_debug_dump_dev(dev) (debug_dump_dev(dev))
+static void debug_dump_dev(blkid_dev dev);
+#endif
+
/*
* File format:
*
@@ -355,7 +360,7 @@ static int blkid_parse_line(blkid_cache cache, blkid_dev *dev_p, char *cp)
blkid_free_dev(dev);
}
- DEB_DUMP_DEV(DEBUG_READ, dev);
+ DBG(DEBUG_READ, blkid_debug_dump_dev(dev));
return ret;
}
@@ -433,6 +438,32 @@ errout:
}
#ifdef TEST_PROGRAM
+static void debug_dump_dev(blkid_dev dev)
+{
+ struct list_head *p;
+
+ if (!dev) {
+ printf(" dev: NULL\n");
+ return;
+ }
+
+ printf(" dev: name = %s\n", dev->bid_name);
+ printf(" dev: DEVNO=\"0x%0llx\"\n", dev->bid_devno);
+ printf(" dev: TIME=\"%lu\"\n", dev->bid_time);
+ printf(" dev: PRI=\"%d\"\n", dev->bid_pri);
+ printf(" dev: flags = 0x%08X\n", dev->bid_flags);
+
+ list_for_each(p, &dev->bid_tags) {
+ blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
+ if (tag)
+ printf(" tag: %s=\"%s\"\n", tag->bit_name,
+ tag->bit_val);
+ else
+ printf(" tag: NULL\n");
+ }
+ printf("\n");
+}
+
int main(int argc, char**argv)
{
blkid_cache cache = NULL;
diff --git a/e2fsprogs/blkid/tag.c b/e2fsprogs/blkid/tag.c
index 51615d4a5..61642464d 100644
--- a/e2fsprogs/blkid/tag.c
+++ b/e2fsprogs/blkid/tag.c
@@ -29,6 +29,18 @@ static blkid_tag blkid_new_tag(void)
return tag;
}
+#ifdef CONFIG_BLKID_DEBUG
+void blkid_debug_dump_tag(blkid_tag tag)
+{
+ if (!tag) {
+ printf(" tag: NULL\n");
+ return;
+ }
+
+ printf(" tag: %s=\"%s\"\n", tag->bit_name, tag->bit_val);
+}
+#endif
+
void blkid_free_tag(blkid_tag tag)
{
if (!tag)
@@ -36,7 +48,7 @@ void blkid_free_tag(blkid_tag tag)
DBG(DEBUG_TAG, printf(" freeing tag %s=%s\n", tag->bit_name,
tag->bit_val ? tag->bit_val : "(NULL)"));
- DEB_DUMP_TAG(DEBUG_TAG, tag);
+ DBG(DEBUG_TAG, blkid_debug_dump_tag(tag));
list_del(&tag->bit_tags); /* list of tags for this device */
list_del(&tag->bit_names); /* list of tags with this type */
@@ -330,3 +342,90 @@ try_again:
}
return dev;
}
+
+#ifdef TEST_PROGRAM
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern char *optarg;
+extern int optind;
+#endif
+
+void usage(char *prog)
+{
+ fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask] device "
+ "[type value]\n",
+ prog);
+ fprintf(stderr, "\tList all tags for a device and exit\n", prog);
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+ blkid_tag_iterate iter;
+ blkid_cache cache = NULL;
+ blkid_dev dev;
+ int c, ret, found;
+ int flags = BLKID_DEV_FIND;
+ char *tmp;
+ char *file = NULL;
+ char *devname = NULL;
+ char *search_type = NULL;
+ char *search_value = NULL;
+ const char *type, *value;
+
+ while ((c = getopt (argc, argv, "m:f:")) != EOF)
+ switch (c) {
+ case 'f':
+ file = optarg;
+ break;
+ case 'm':
+ blkid_debug_mask = strtoul (optarg, &tmp, 0);
+ if (*tmp) {
+ fprintf(stderr, "Invalid debug mask: %d\n",
+ optarg);
+ exit(1);
+ }
+ break;
+ case '?':
+ usage(argv[0]);
+ }
+ if (argc > optind)
+ devname = argv[optind++];
+ if (argc > optind)
+ search_type = argv[optind++];
+ if (argc > optind)
+ search_value = argv[optind++];
+ if (!devname || (argc != optind))
+ usage(argv[0]);
+
+ if ((ret = blkid_get_cache(&cache, file)) != 0) {
+ fprintf(stderr, "%s: error creating cache (%d)\n",
+ argv[0], ret);
+ exit(1);
+ }
+
+ dev = blkid_get_dev(cache, devname, flags);
+ if (!dev) {
+ fprintf(stderr, "%s: Can not find device in blkid cache\n");
+ exit(1);
+ }
+ if (search_type) {
+ found = blkid_dev_has_tag(dev, search_type, search_value);
+ printf("Device %s: (%s, %s) %s\n", blkid_dev_devname(dev),
+ search_type, search_value ? search_value : "NULL",
+ found ? "FOUND" : "NOT FOUND");
+ return(!found);
+ }
+ printf("Device %s...\n", blkid_dev_devname(dev));
+
+ iter = blkid_tag_iterate_begin(dev);
+ while (blkid_tag_next(iter, &type, &value) == 0) {
+ printf("\tTag %s has value %s\n", type, value);
+ }
+ blkid_tag_iterate_end(iter);
+
+ blkid_put_cache(cache);
+ return (0);
+}
+#endif