cdown / rpms / util-linux

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