]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkswap: fix includes
authorKarel Zak <kzak@redhat.com>
Mon, 3 Feb 2025 10:48:23 +0000 (11:48 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 3 Feb 2025 10:48:23 +0000 (11:48 +0100)
It is preferable to use #ifdefs in code that relies on available
features, rather than solely depending on the presence of header
files. This is especially important if the functionality of FIEMAP
relies on multiple include files. Additionally, note that we also need
linux/fs.h for S_NOCOW_FL, regardless of FIEMAP.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkswap.c

index 08db89b2c38e42c3f991158766380a3c0aae5b4c..e1ccc80b6ae1ac00944cc9264f96ddf86a866baa 100644 (file)
 # include <blkid.h>
 #endif
 
+#if defined(FS_IOC_FIEMAP) && defined(FIEMAP_EXTENT_LAST)
+# define USE_EXTENDS_CHECK 1
+#endif
+
 #define MIN_GOODPAGES  10
 
 #define SELINUX_SWAPFILE_TYPE  "swapfile_t"
@@ -264,7 +268,7 @@ static void check_blocks(struct mkswap_control *ctl)
 }
 
 
-#ifdef HAVE_LINUX_FIEMAP_H
+#ifdef USE_EXTENDS_CHECK
 static void warn_extent(struct mkswap_control *ctl, const char *msg, uint64_t off)
 {
        if (ctl->nbad_extents == 0) {
@@ -351,7 +355,7 @@ done:
        if (ctl->nbad_extents)
                fputc('\n', stderr);
 }
-#endif /* HAVE_LINUX_FIEMAP_H */
+#endif /* USE_EXTENDS_CHECK */
 
 /* return size in pages */
 static unsigned long long get_size(const struct mkswap_control *ctl)
@@ -740,7 +744,7 @@ int main(int argc, char **argv)
 
        if (ctl.check)
                check_blocks(&ctl);
-#ifdef HAVE_LINUX_FIEMAP_H
+#ifdef USE_EXTENDS_CHECK
        if (!ctl.quiet && S_ISREG(ctl.devstat.st_mode))
                check_extents(&ctl);
 #endif