]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - lib/support/plausible.c
mmp: abstract out repeated 'sizeof(buf), buf' usage
[thirdparty/e2fsprogs.git] / lib / support / plausible.c
index e2b7ff4a698d2dd4ff2f7189c79c4250edb609ed..024f205e8cd4f0370b0b0715b1d9714200730312 100644 (file)
@@ -43,6 +43,17 @@ static const char *(*dl_magic_file)(magic_t, const char *);
 static int (*dl_magic_load)(magic_t, const char *);
 static void (*dl_magic_close)(magic_t);
 
+/*
+ * NO_CHECK functionality was only added in file 4.20.
+ * Older systems like RHEL 5.x still have file 4.17
+ */
+#ifndef MAGIC_NO_CHECK_COMPRESS
+#define MAGIC_NO_CHECK_COMPRESS 0x0001000
+#endif
+#ifndef MAGIC_NO_CHECK_ELF
+#define MAGIC_NO_CHECK_ELF 0x0010000
+#endif
+
 #ifdef HAVE_DLOPEN
 #include <dlfcn.h>
 
@@ -55,10 +66,14 @@ static int magic_library_available(void)
                if (!magic_handle)
                        return 0;
 
-               dl_magic_open = dlsym(magic_handle, "magic_open");
-               dl_magic_file = dlsym(magic_handle, "magic_file");
-               dl_magic_load = dlsym(magic_handle, "magic_load");
-               dl_magic_close = dlsym(magic_handle, "magic_close");
+               dl_magic_open = (magic_t (*)(int))
+                       dlsym(magic_handle, "magic_open");
+               dl_magic_file = (const char *(*)(magic_t, const char *))
+                       dlsym(magic_handle, "magic_file");
+               dl_magic_load = (int (*)(magic_t, const char *))
+                       dlsym(magic_handle, "magic_load");
+               dl_magic_close = (void (*)(magic_t))
+                       dlsym(magic_handle, "magic_close");
        }
 
        if (!dl_magic_open || !dl_magic_file ||
@@ -86,7 +101,6 @@ static void print_ext2_info(const char *device)
        ext2_filsys             fs;
        errcode_t               retval;
        time_t                  tm;
-       char                    buf[80];
 
        retval = ext2fs_open2(device, 0, EXT2_FLAG_64BITS, 0, 0,
                              unix_io_manager, &fs);
@@ -96,13 +110,10 @@ static void print_ext2_info(const char *device)
 
        if (sb->s_mtime) {
                tm = sb->s_mtime;
-               if (sb->s_last_mounted[0]) {
-                       memset(buf, 0, sizeof(buf));
-                       strncpy(buf, sb->s_last_mounted,
-                               sizeof(sb->s_last_mounted));
-                       printf(_("\tlast mounted on %s on %s"), buf,
-                              ctime(&tm));
-               } else
+               if (sb->s_last_mounted[0])
+                       printf(_("\tlast mounted on %.*s on %s"),
+                              EXT2_LEN_STR(sb->s_last_mounted), ctime(&tm));
+               else
                        printf(_("\tlast mounted on %s"), ctime(&tm));
        } else if (sb->s_mkfs_time) {
                tm = sb->s_mkfs_time;
@@ -118,9 +129,9 @@ static void print_ext2_info(const char *device)
  * return 1 if there is no partition table, 0 if a partition table is
  * detected, and -1 on an error.
  */
+#ifdef HAVE_BLKID_PROBE_ENABLE_PARTITIONS
 static int check_partition_table(const char *device)
 {
-#ifdef HAVE_BLKID_PROBE_ENABLE_PARTITIONS
        blkid_probe pr;
        const char *value;
        int ret;
@@ -151,10 +162,13 @@ static int check_partition_table(const char *device)
 errout:
        blkid_free_probe(pr);
        return ret;
+}
 #else
+static int check_partition_table(const char *device EXT2FS_ATTR((unused)))
+{
        return -1;
-#endif
 }
+#endif
 
 /*
  * return 1 if the device looks plausible, creating the file if necessary
@@ -228,8 +242,8 @@ int check_plausibility(const char *device, int flags, int *ret_is_dev)
 
        if (fs_type) {
                if (fs_label)
-                       printf(_("%s contains a %s file system "
-                                "labelled '%s'\n"), device, fs_type, fs_label);
+                       printf(_("%s contains a %s file system labelled '%s'\n"),
+                              device, fs_type, fs_label);
                else
                        printf(_("%s contains a %s file system\n"), device,
                               fs_type);
@@ -241,7 +255,9 @@ int check_plausibility(const char *device, int flags, int *ret_is_dev)
        }
 
 #ifdef HAVE_MAGIC_H
-       if ((flags & CHECK_FS_EXIST) && magic_library_available()) {
+       if ((flags & CHECK_FS_EXIST) &&
+           !getenv("E2FSPROGS_LIBMAGIC_SUPPRESS") &&
+           magic_library_available()) {
                const char *msg;
                magic_t mag;
                int has_magic = 0;