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