From ba5e38494e6b42d77f76d9ad18744388958eca7c Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 10 Mar 2006 18:11:35 -0500 Subject: [PATCH] Add EXT_JOURNAL to the blkid tag of ext3 filesystems. If the filesystem has an external journal, store the UUID of the external journal in the tag EXT_JOURNAL. If the filesystem type has changed, clear all the tags on the device, not just a preset list of LABEL, UUID, TYPE, and SEC_TYPE. Fix a bug so that blkid_set_tag will work correctly when freeing a tag when the input name parameter comes from the tag that we are freeing. Signed-off-by: "Theodore Ts'o" --- lib/blkid/ChangeLog | 13 +++++++++++++ lib/blkid/probe.c | 41 +++++++++++++++++++++++------------------ lib/blkid/probe.h | 18 ++++++++++++++++++ lib/blkid/tag.c | 17 +++++++++-------- 4 files changed, 63 insertions(+), 26 deletions(-) diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog index 099b4f1..094f922 100644 --- a/lib/blkid/ChangeLog +++ b/lib/blkid/ChangeLog @@ -1,3 +1,16 @@ +2006-03-10 Theodore Ts'o + + * probe.c (probe_ext3): If the filesystem has an external journal, + store the UUID of the external journal in the tag + EXT_JOURNAL. + (blkid_verify): If the filesystem type has changed, clear + all the tags on the device, not just a preset list of + LABEL, UUID, TYPE, and SEC_TYPE. + + * tag.c (blkid_set_tag): Fix a bug so that blkid_set_tag will work + correctly when freeing a tag when the input name parameter + comes from the tag that we are freeing. + 2005-12-29 Theodore Ts'o * tag.c (main): Add missing parameter in error-handling printf of diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index c0ae2d5..f689bc1 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -121,13 +121,13 @@ static int check_mdraid(int fd, unsigned char *ret_uuid) return 0; } -static void set_uuid(blkid_dev dev, uuid_t uuid) +static void set_uuid(blkid_dev dev, uuid_t uuid, char *tag) { char str[37]; if (!uuid_is_null(uuid)) { uuid_unparse(uuid, str); - blkid_set_tag(dev, "UUID", str, sizeof(str)); + blkid_set_tag(dev, tag ? tag : "UUID", str, sizeof(str)); } } @@ -145,7 +145,7 @@ static void get_ext2_info(blkid_dev dev, unsigned char *buf) label = es->s_volume_name; blkid_set_tag(dev, "LABEL", label, sizeof(es->s_volume_name)); - set_uuid(dev, es->s_uuid); + set_uuid(dev, es->s_uuid, 0); } static int probe_ext3(struct blkid_probe *probe, @@ -153,7 +153,7 @@ static int probe_ext3(struct blkid_probe *probe, unsigned char *buf) { struct ext2_super_block *es; - + char uuid[37]; es = (struct ext2_super_block *)buf; /* Distinguish between jbd and ext2/3 fs */ @@ -168,6 +168,10 @@ static int probe_ext3(struct blkid_probe *probe, get_ext2_info(probe->dev, buf); + if ((es->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) && + !uuid_is_null(es->s_journal_uuid)) + set_uuid(probe->dev, es->s_journal_uuid, "EXT_JOURNAL"); + blkid_set_tag(probe->dev, "SEC_TYPE", "ext2", sizeof("ext2")); return 0; @@ -404,7 +408,7 @@ static int probe_xfs(struct blkid_probe *probe, if (strlen(xs->xs_fname)) label = xs->xs_fname; blkid_set_tag(probe->dev, "LABEL", label, sizeof(xs->xs_fname)); - set_uuid(probe->dev, xs->xs_uuid); + set_uuid(probe->dev, xs->xs_uuid, 0); return 0; } @@ -425,7 +429,7 @@ static int probe_reiserfs(struct blkid_probe *probe, if (id->bim_magic[6] == '2' || id->bim_magic[6] == '3') { if (strlen(rs->rs_label)) label = rs->rs_label; - set_uuid(probe->dev, rs->rs_uuid); + set_uuid(probe->dev, rs->rs_uuid, 0); } blkid_set_tag(probe->dev, "LABEL", label, sizeof(rs->rs_label)); @@ -441,7 +445,7 @@ static int probe_reiserfs4(struct blkid_probe *probe, if (strlen((char *) rs4->rs4_label)) label = rs4->rs4_label; - set_uuid(probe->dev, rs4->rs4_uuid); + set_uuid(probe->dev, rs4->rs4_uuid, 0); blkid_set_tag(probe->dev, "LABEL", (const char *) label, sizeof(rs4->rs4_label)); @@ -460,7 +464,7 @@ static int probe_jfs(struct blkid_probe *probe, if (strlen((char *) js->js_label)) label = (char *) js->js_label; blkid_set_tag(probe->dev, "LABEL", label, sizeof(js->js_label)); - set_uuid(probe->dev, js->js_uuid); + set_uuid(probe->dev, js->js_uuid, 0); return 0; } @@ -526,7 +530,7 @@ static int probe_swap1(struct blkid_probe *probe, blkid_set_tag(probe->dev, "LABEL", sws->sws_volume, sizeof(sws->sws_volume)); if (sws->sws_uuid[0]) - set_uuid(probe->dev, sws->sws_uuid); + set_uuid(probe->dev, sws->sws_uuid, 0); } return 0; } @@ -613,7 +617,7 @@ static int probe_ocfs(struct blkid_probe *probe, blkid_set_tag(probe->dev, "LABEL", ovl.label, ocfslabellen(ovl)); blkid_set_tag(probe->dev, "MOUNT", ovh.mount, ocfsmountlen(ovh)); - set_uuid(probe->dev, ovl.vol_id); + set_uuid(probe->dev, ovl.vol_id, 0); return 0; } @@ -626,7 +630,7 @@ static int probe_ocfs2(struct blkid_probe *probe, osb = (struct ocfs2_super_block *)buf; blkid_set_tag(probe->dev, "LABEL", osb->s_label, sizeof(osb->s_label)); - set_uuid(probe->dev, osb->s_uuid); + set_uuid(probe->dev, osb->s_uuid, 0); return 0; } @@ -741,8 +745,9 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev) { struct blkid_magic *id; struct blkid_probe probe; + blkid_tag_iterate iter; unsigned char *buf; - const char *type; + const char *type, *value; struct stat st; time_t diff, now; int idx; @@ -794,7 +799,7 @@ try_again: uuid_t uuid; if (check_mdraid(probe.fd, uuid) == 0) { - set_uuid(dev, uuid); + set_uuid(dev, uuid, 0); type = "mdraid"; goto found_type; } @@ -822,12 +827,12 @@ try_again: if (!id->bim_type && dev->bid_type) { /* - * Zap the device filesystem type and try again + * Zap the device filesystem information and try again */ - blkid_set_tag(dev, "TYPE", 0, 0); - blkid_set_tag(dev, "SEC_TYPE", 0, 0); - blkid_set_tag(dev, "LABEL", 0, 0); - blkid_set_tag(dev, "UUID", 0, 0); + iter = blkid_tag_iterate_begin(dev); + while (blkid_tag_next(iter, &type, &value) == 0) + blkid_set_tag(dev, type, 0, 0); + blkid_tag_iterate_end(iter); goto try_again; } diff --git a/lib/blkid/probe.h b/lib/blkid/probe.h index a55dbb3..010ffe2 100644 --- a/lib/blkid/probe.h +++ b/lib/blkid/probe.h @@ -65,6 +65,24 @@ struct ext2_super_block { __u32 s_feature_ro_compat; unsigned char s_uuid[16]; char s_volume_name[16]; + char s_last_mounted[64]; + __u32 s_algorithm_usage_bitmap; + __u8 s_prealloc_blocks; + __u8 s_prealloc_dir_blocks; + __u16 s_reserved_gdt_blocks; + __u8 s_journal_uuid[16]; + __u32 s_journal_inum; + __u32 s_journal_dev; + __u32 s_last_orphan; + __u32 s_hash_seed[4]; + __u8 s_def_hash_version; + __u8 s_jnl_backup_type; + __u16 s_reserved_word_pad; + __u32 s_default_mount_opts; + __u32 s_first_meta_bg; + __u32 s_mkfs_time; + __u32 s_jnl_blocks[17]; + __u32 s_reserved[172]; }; #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x00000004 #define EXT3_FEATURE_INCOMPAT_RECOVER 0x00000004 diff --git a/lib/blkid/tag.c b/lib/blkid/tag.c index a5f0c67..b6539a8 100644 --- a/lib/blkid/tag.c +++ b/lib/blkid/tag.c @@ -138,6 +138,15 @@ int blkid_set_tag(blkid_dev dev, const char *name, if (!(val = blkid_strndup(value, vlength)) && value) return -BLKID_ERR_MEM; + + /* Link common tags directly to the device struct */ + if (!strcmp(name, "TYPE")) + dev->bid_type = val; + else if (!strcmp(name, "LABEL")) + dev->bid_label = val; + else if (!strcmp(name, "UUID")) + dev->bid_uuid = val; + t = blkid_find_tag_dev(dev, name); if (!value) { if (t) @@ -180,14 +189,6 @@ int blkid_set_tag(blkid_dev dev, const char *name, } } - /* Link common tags directly to the device struct */ - if (!strcmp(name, "TYPE")) - dev->bid_type = val; - else if (!strcmp(name, "LABEL")) - dev->bid_label = val; - else if (!strcmp(name, "UUID")) - dev->bid_uuid = val; - if (dev->bid_cache) dev->bid_cache->bic_flags |= BLKID_BIC_FL_CHANGED; return 0; -- 1.8.3.1