cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/2.25-libblkid-Identify-extN-file-system-properly.patch

0b5e55
diff -up util-linux-2.23.2/libblkid/src/superblocks/ext.c.kzak util-linux-2.23.2/libblkid/src/superblocks/ext.c
0b5e55
--- util-linux-2.23.2/libblkid/src/superblocks/ext.c.kzak	2013-06-13 09:46:10.422650639 +0200
0b5e55
+++ util-linux-2.23.2/libblkid/src/superblocks/ext.c	2014-01-23 10:28:51.175358545 +0100
0b5e55
@@ -18,7 +18,6 @@
0b5e55
 #endif
0b5e55
 #include <time.h>
0b5e55
 
0b5e55
-#include "linux_version.h"
0b5e55
 #include "superblocks.h"
0b5e55
 
0b5e55
 struct ext2_super_block {
0b5e55
@@ -132,140 +131,11 @@ struct ext2_super_block {
0b5e55
 #define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED	~EXT3_FEATURE_RO_COMPAT_SUPP
0b5e55
 
0b5e55
 /*
0b5e55
- * Check to see if a filesystem is in /proc/filesystems.
0b5e55
- * Returns 1 if found, 0 if not
0b5e55
- */
0b5e55
-static int fs_proc_check(const char *fs_name)
0b5e55
-{
0b5e55
-	FILE	*f;
0b5e55
-	char	buf[80], *cp, *t;
0b5e55
-
0b5e55
-	f = fopen("/proc/filesystems", "r" UL_CLOEXECSTR);
0b5e55
-	if (!f)
0b5e55
-		return 0;
0b5e55
-	while (!feof(f)) {
0b5e55
-		if (!fgets(buf, sizeof(buf), f))
0b5e55
-			break;
0b5e55
-		cp = buf;
0b5e55
-		if (!isspace(*cp)) {
0b5e55
-			while (*cp && !isspace(*cp))
0b5e55
-				cp++;
0b5e55
-		}
0b5e55
-		while (*cp && isspace(*cp))
0b5e55
-			cp++;
0b5e55
-		if ((t = strchr(cp, '\n')) != NULL)
0b5e55
-			*t = 0;
0b5e55
-		if ((t = strchr(cp, '\t')) != NULL)
0b5e55
-			*t = 0;
0b5e55
-		if ((t = strchr(cp, ' ')) != NULL)
0b5e55
-			*t = 0;
0b5e55
-		if (!strcmp(fs_name, cp)) {
0b5e55
-			fclose(f);
0b5e55
-			return 1;
0b5e55
-		}
0b5e55
-	}
0b5e55
-	fclose(f);
0b5e55
-	return (0);
0b5e55
-}
0b5e55
-
0b5e55
-/*
0b5e55
- * Check to see if a filesystem is available as a module
0b5e55
- * Returns 1 if found, 0 if not
0b5e55
- */
0b5e55
-static int check_for_modules(const char *fs_name)
0b5e55
-{
0b5e55
-#ifdef __linux__
0b5e55
-	struct utsname	uts;
0b5e55
-	FILE		*f;
0b5e55
-	char		buf[1024], *cp;
0b5e55
-	int		namesz;
0b5e55
-
0b5e55
-	if (uname(&uts))
0b5e55
-		return 0;
0b5e55
-	snprintf(buf, sizeof(buf), "/lib/modules/%s/modules.dep", uts.release);
0b5e55
-
0b5e55
-	f = fopen(buf, "r" UL_CLOEXECSTR);
0b5e55
-	if (!f)
0b5e55
-		return 0;
0b5e55
-
0b5e55
-	namesz = strlen(fs_name);
0b5e55
-
0b5e55
-	while (!feof(f)) {
0b5e55
-		if (!fgets(buf, sizeof(buf), f))
0b5e55
-			break;
0b5e55
-		if ((cp = strchr(buf, ':')) != NULL)
0b5e55
-			*cp = 0;
0b5e55
-		else
0b5e55
-			continue;
0b5e55
-		if ((cp = strrchr(buf, '/')) == NULL)
0b5e55
-			continue;
0b5e55
-		cp++;
0b5e55
-
0b5e55
-		if (!strncmp(cp, fs_name, namesz) &&
0b5e55
-		    (!strcmp(cp + namesz, ".ko") ||
0b5e55
-		     !strcmp(cp + namesz, ".ko.gz"))) {
0b5e55
-			fclose(f);
0b5e55
-			return 1;
0b5e55
-		}
0b5e55
-	}
0b5e55
-	fclose(f);
0b5e55
-#endif /* __linux__ */
0b5e55
-	return 0;
0b5e55
-}
0b5e55
-
0b5e55
-/*
0b5e55
  * Starting in 2.6.29, ext4 can be used to support filesystems
0b5e55
  * without a journal.
0b5e55
  */
0b5e55
 #define EXT4_SUPPORTS_EXT2 KERNEL_VERSION(2, 6, 29)
0b5e55
 
0b5e55
-static int system_supports_ext2(void)
0b5e55
-{
0b5e55
-	static time_t	last_check = 0;
0b5e55
-	static int	ret = -1;
0b5e55
-	time_t		now = time(0);
0b5e55
-
0b5e55
-	if (ret != -1 || (now - last_check) < 5)
0b5e55
-		return ret;
0b5e55
-	last_check = now;
0b5e55
-	ret = (fs_proc_check("ext2") || check_for_modules("ext2"));
0b5e55
-	return ret;
0b5e55
-}
0b5e55
-
0b5e55
-static int system_supports_ext4(void)
0b5e55
-{
0b5e55
-	static time_t	last_check = 0;
0b5e55
-	static int	ret = -1;
0b5e55
-	time_t		now = time(0);
0b5e55
-
0b5e55
-	if (ret != -1 || (now - last_check) < 5)
0b5e55
-		return ret;
0b5e55
-	last_check = now;
0b5e55
-	ret = (fs_proc_check("ext4") || check_for_modules("ext4"));
0b5e55
-	return ret;
0b5e55
-}
0b5e55
-
0b5e55
-static int system_supports_ext4dev(void)
0b5e55
-{
0b5e55
-	static time_t	last_check = 0;
0b5e55
-	static int	ret = -1;
0b5e55
-	time_t		now = time(0);
0b5e55
-
0b5e55
-	if (ret != -1 || (now - last_check) < 5)
0b5e55
-		return ret;
0b5e55
-	last_check = now;
0b5e55
-	ret = (fs_proc_check("ext4dev") || check_for_modules("ext4dev"));
0b5e55
-	return ret;
0b5e55
-}
0b5e55
-
0b5e55
-static int system_supports_ext4_ext2(void)
0b5e55
-{
0b5e55
-#ifdef __linux__
0b5e55
-	return get_linux_version() >= EXT4_SUPPORTS_EXT2;
0b5e55
-#else
0b5e55
-	return 0;
0b5e55
-#endif
0b5e55
-}
0b5e55
 /*
0b5e55
  * reads superblock and returns:
0b5e55
  *	fc = feature_compat
0b5e55
@@ -355,15 +225,6 @@ static int probe_ext2(blkid_probe pr,
0b5e55
 	    (fi  & EXT2_FEATURE_INCOMPAT_UNSUPPORTED))
0b5e55
 		return -BLKID_ERR_PARAM;
0b5e55
 
0b5e55
-	/*
0b5e55
-	 * If ext2 is not present, but ext4 or ext4dev are, then
0b5e55
-	 * disclaim we are ext2
0b5e55
-	 */
0b5e55
-	if (!system_supports_ext2() &&
0b5e55
-	    (system_supports_ext4() || system_supports_ext4dev()) &&
0b5e55
-	    system_supports_ext4_ext2())
0b5e55
-		return -BLKID_ERR_PARAM;
0b5e55
-
0b5e55
 	ext_get_info(pr, 2, es);
0b5e55
 	return 0;
0b5e55
 }
0b5e55
@@ -406,34 +267,9 @@ static int probe_ext4dev(blkid_probe pr,
0b5e55
 	if (fi & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
0b5e55
 		return -BLKID_ERR_PARAM;
0b5e55
 
0b5e55
-	/*
0b5e55
-	 * If the filesystem does not have a journal and ext2 and ext4
0b5e55
-	 * is not present, then force this to be detected as an
0b5e55
-	 * ext4dev filesystem.
0b5e55
-	 */
0b5e55
-	if (!(fc & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
0b5e55
-	    !system_supports_ext2() && !system_supports_ext4() &&
0b5e55
-	    system_supports_ext4dev() &&
0b5e55
-	    system_supports_ext4_ext2())
0b5e55
-		goto force_ext4dev;
0b5e55
-
0b5e55
-	/*
0b5e55
-	 * If the filesystem is marked as OK for use by in-development
0b5e55
-	 * filesystem code, but ext4dev is not supported, and ext4 is,
0b5e55
-	 * then don't call ourselves ext4dev, since we should be
0b5e55
-	 * detected as ext4 in that case.
0b5e55
-	 *
0b5e55
-	 * If the filesystem is marked as in use by production
0b5e55
-	 * filesystem, then it can only be used by ext4 and NOT by
0b5e55
-	 * ext4dev, so always disclaim we are ext4dev in that case.
0b5e55
-	 */
0b5e55
-	if (le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS) {
0b5e55
-		if (!system_supports_ext4dev() && system_supports_ext4())
0b5e55
-			return -BLKID_ERR_PARAM;
0b5e55
-	} else
0b5e55
+	if (!(le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS))
0b5e55
 		return -BLKID_ERR_PARAM;
0b5e55
 
0b5e55
-force_ext4dev:
0b5e55
 	ext_get_info(pr, 4, es);
0b5e55
 	return 0;
0b5e55
 }
0b5e55
@@ -452,22 +288,11 @@ static int probe_ext4(blkid_probe pr,
0b5e55
 	if (fi & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)
0b5e55
 		return -BLKID_ERR_PARAM;
0b5e55
 
0b5e55
-	/*
0b5e55
-	 * If the filesystem does not have a journal and ext2 is not
0b5e55
-	 * present, then force this to be detected as an ext2
0b5e55
-	 * filesystem.
0b5e55
-	 */
0b5e55
-	if (!(fc & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
0b5e55
-	    !system_supports_ext2() && system_supports_ext4() &&
0b5e55
-	    system_supports_ext4_ext2())
0b5e55
-		goto force_ext4;
0b5e55
-
0b5e55
 	/* Ext4 has at least one feature which ext3 doesn't understand */
0b5e55
 	if (!(frc & EXT3_FEATURE_RO_COMPAT_UNSUPPORTED) &&
0b5e55
 	    !(fi  & EXT3_FEATURE_INCOMPAT_UNSUPPORTED))
0b5e55
 		return -BLKID_ERR_PARAM;
0b5e55
 
0b5e55
-force_ext4:
0b5e55
 	/*
0b5e55
 	 * If the filesystem is a OK for use by in-development
0b5e55
 	 * filesystem code, and ext4dev is supported or ext4 is not
0b5e55
@@ -478,10 +303,8 @@ force_ext4:
0b5e55
 	 * filesystem, then it can only be used by ext4 and NOT by
0b5e55
 	 * ext4dev.
0b5e55
 	 */
0b5e55
-	if (le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS) {
0b5e55
-		if (system_supports_ext4dev() || !system_supports_ext4())
0b5e55
-			return -BLKID_ERR_PARAM;
0b5e55
-	}
0b5e55
+	if (le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS)
0b5e55
+		return -BLKID_ERR_PARAM;
0b5e55
 
0b5e55
 	ext_get_info(pr, 4, es);
0b5e55
 	return 0;