summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2005-01-05 17:45:32 -0500
committerTheodore Ts'o <tytso@mit.edu>2005-01-05 17:45:32 -0500
commit2e6a9febb48ea0e57d32cacb5e67220443c0e059 (patch)
tree37fb70f32818fe1c552de96fd182f4b2863dd1fa
parent22dcccdd1aa295db6fa2696d63c60902aabbbfff (diff)
downloade2fsprogs-2e6a9febb48ea0e57d32cacb5e67220443c0e059.tar.gz
Adjust blkid library so that it returns vfat in preference to msdos so
that mount will try to use the vfat filesystem. (Addresses Debian bug #287455) Similarly, the blkid library will now return an ext3 type for ext 2/3 filesystems that have the journal capability set. We allow files to be probed by the blkid library, to make it easier to test the library. However, we also added safety checks to avoid saving relative pathnames to blkid.tab, and probe_one() will only check block device files.
-rw-r--r--lib/blkid/ChangeLog16
-rw-r--r--lib/blkid/devname.c3
-rw-r--r--lib/blkid/probe.c79
-rw-r--r--lib/blkid/save.c2
4 files changed, 75 insertions, 25 deletions
diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog
index 32dca3bf..c4be87fc 100644
--- a/lib/blkid/ChangeLog
+++ b/lib/blkid/ChangeLog
@@ -1,3 +1,19 @@
+2005-01-05 Theodore Ts'o <tytso@mit.edu>
+
+ * save.c (save_dev): Don't save relative pathnames since they
+ won't be useful to another process.
+
+ * devname.c (probe_one): Make sure the device is a block device
+ before checking st_rdev.
+
+ * probe.c (probe_msdos): Mark msdos filesystems as type vfat, with
+ a SEC_TYPE of msdos, so that mount will use vfat to mount
+ msdos filesystems. (Addresses Debian bug #287455)
+ (probe_ext3): For ext3 filesystems, return a type of ext3
+ and a SEC_TYPE of ext2, for similar reasons as above.
+ (blkid_verify_devname): Allow non-block devices to be
+ verified, for testing purposes.
+
2004-12-14 Theodore Ts'o <tytso@mit.edu>
* Makefile.in: Use Linux-kernel-style makefile output for "make
diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c
index 3a00146f..ab1db6f6 100644
--- a/lib/blkid/devname.c
+++ b/lib/blkid/devname.c
@@ -113,7 +113,8 @@ static void probe_one(blkid_cache cache, const char *ptname,
dev->bid_devno == devno)
goto set_pri;
- if (stat(device, &st) == 0 && st.st_rdev == devno) {
+ if (stat(device, &st) == 0 && S_ISBLK(st.st_mode) &&
+ st.st_rdev == devno) {
devname = blkid_strdup(device);
break;
}
diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c
index 48edb956..c014580c 100644
--- a/lib/blkid/probe.c
+++ b/lib/blkid/probe.c
@@ -78,37 +78,66 @@ static void set_uuid(blkid_dev dev, uuid_t uuid)
}
}
-static int probe_ext2(int fd __BLKID_ATTR((unused)),
+static void get_ext2_info(blkid_dev dev, unsigned char *buf)
+{
+ struct ext2_super_block *es = (struct ext2_super_block *) buf;
+ const char *label = 0;
+
+ DBG(DEBUG_PROBE, printf("ext2_sb.compat = %08X:%08X:%08X\n",
+ blkid_le32(es->s_feature_compat),
+ blkid_le32(es->s_feature_incompat),
+ blkid_le32(es->s_feature_ro_compat)));
+
+ if (strlen(es->s_volume_name)) {
+ label = es->s_volume_name;
+ blkid_set_tag(dev, "LABEL", label, sizeof(es->s_volume_name));
+ }
+
+ set_uuid(dev, es->s_uuid);
+}
+
+static int probe_ext3(int fd __BLKID_ATTR((unused)),
blkid_cache cache __BLKID_ATTR((unused)),
blkid_dev dev,
struct blkid_magic *id, unsigned char *buf)
{
struct ext2_super_block *es;
- const char *sec_type = 0, *label = 0;
es = (struct ext2_super_block *)buf;
- DBG(DEBUG_PROBE, printf("ext2_sb.compat = %08X:%08X:%08X\n",
- blkid_le32(es->s_feature_compat),
- blkid_le32(es->s_feature_incompat),
- blkid_le32(es->s_feature_ro_compat)));
-
/* Distinguish between jbd and ext2/3 fs */
- if (id && (blkid_le32(es->s_feature_incompat) &
- EXT3_FEATURE_INCOMPAT_JOURNAL_DEV))
+ if (blkid_le32(es->s_feature_incompat) &
+ EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
return -BLKID_ERR_PARAM;
- if (strlen(es->s_volume_name))
- label = es->s_volume_name;
- blkid_set_tag(dev, "LABEL", label, sizeof(es->s_volume_name));
+ /* Distinguish between ext3 and ext2 */
+ if (!(blkid_le32(es->s_feature_compat) &
+ EXT3_FEATURE_COMPAT_HAS_JOURNAL))
+ return -BLKID_ERR_PARAM;
- set_uuid(dev, es->s_uuid);
+ get_ext2_info(dev, buf);
- if (blkid_le32(es->s_feature_compat) &
- EXT3_FEATURE_COMPAT_HAS_JOURNAL)
- sec_type = "ext3";
-
- blkid_set_tag(dev, "SEC_TYPE", sec_type, 0);
+ blkid_set_tag(dev, "SEC_TYPE", "ext2", sizeof("ext2"));
+
+ return 0;
+}
+
+static int probe_ext2(int fd __BLKID_ATTR((unused)),
+ blkid_cache cache __BLKID_ATTR((unused)),
+ blkid_dev dev,
+ struct blkid_magic *id, unsigned char *buf)
+{
+ struct ext2_super_block *es;
+ const char *sec_type = 0, *label = 0;
+
+ es = (struct ext2_super_block *)buf;
+
+ /* Distinguish between jbd and ext2/3 fs */
+ if (blkid_le32(es->s_feature_incompat) &
+ EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
+ return -BLKID_ERR_PARAM;
+
+ get_ext2_info(dev, buf);
return 0;
}
@@ -125,7 +154,9 @@ static int probe_jbd(int fd __BLKID_ATTR((unused)),
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV))
return -BLKID_ERR_PARAM;
- return (probe_ext2(fd, cache, dev, 0, buf));
+ get_ext2_info(dev, buf);
+
+ return 0;
}
static int probe_vfat(int fd __BLKID_ATTR((unused)),
@@ -182,6 +213,7 @@ static int probe_msdos(int fd __BLKID_ATTR((unused)),
sprintf(serno, "%02X%02X-%02X%02X", ms->ms_serno[3], ms->ms_serno[2],
ms->ms_serno[1], ms->ms_serno[0]);
blkid_set_tag(dev, "UUID", serno, 0);
+ blkid_set_tag(dev, "SEC_TYPE", "msdos", sizeof("msdos"));
return 0;
}
@@ -369,6 +401,7 @@ static int probe_ocfs2(int fd __BLKID_ATTR((unused)),
static struct blkid_magic type_array[] = {
/* type kboff sboff len magic probe */
{ "jbd", 1, 0x38, 2, "\123\357", probe_jbd },
+ { "ext3", 1, 0x38, 2, "\123\357", probe_ext3 },
{ "ext2", 1, 0x38, 2, "\123\357", probe_ext2 },
{ "reiserfs", 8, 0x34, 8, "ReIsErFs", probe_reiserfs },
{ "reiserfs", 64, 0x34, 9, "ReIsEr2Fs", probe_reiserfs },
@@ -378,9 +411,9 @@ static struct blkid_magic type_array[] = {
{ "ntfs", 0, 3, 8, "NTFS ", 0 },
{ "vfat", 0, 0x52, 5, "MSWIN", probe_vfat },
{ "vfat", 0, 0x52, 8, "FAT32 ", probe_vfat },
- { "msdos", 0, 0x36, 5, "MSDOS", probe_msdos },
- { "msdos", 0, 0x36, 8, "FAT16 ", probe_msdos },
- { "msdos", 0, 0x36, 8, "FAT12 ", probe_msdos },
+ { "vfat", 0, 0x36, 5, "MSDOS", probe_msdos },
+ { "vfat", 0, 0x36, 8, "FAT16 ", probe_msdos },
+ { "vfat", 0, 0x36, 8, "FAT12 ", probe_msdos },
{ "minix", 1, 0x10, 2, "\177\023", 0 },
{ "minix", 1, 0x10, 2, "\217\023", 0 },
{ "minix", 1, 0x10, 2, "\150\044", 0 },
@@ -454,7 +487,7 @@ blkid_dev blkid_verify_devname(blkid_cache cache, blkid_dev dev)
dev->bid_name, diff));
if (((fd = open(dev->bid_name, O_RDONLY)) < 0) ||
- (fstat(fd, &st) < 0) || !S_ISBLK(st.st_mode)) {
+ (fstat(fd, &st) < 0)) {
if (errno == ENXIO || errno == ENODEV || errno == ENOENT) {
blkid_free_dev(dev);
return NULL;
diff --git a/lib/blkid/save.c b/lib/blkid/save.c
index bed211a1..a2fbd7b4 100644
--- a/lib/blkid/save.c
+++ b/lib/blkid/save.c
@@ -30,7 +30,7 @@ static int save_dev(blkid_dev dev, FILE *file)
{
struct list_head *p;
- if (!dev)
+ if (!dev || dev->bid_name[0] != '/')
return 0;
DBG(DEBUG_SAVE,