cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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