From: Karel Zak Date: Mon, 3 Feb 2025 10:48:23 +0000 (+0100) Subject: mkswap: fix includes X-Git-Tag: v2.42-start~65^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=457c112475e9cbce4479214652d4fa699bc281ba;p=thirdparty%2Futil-linux.git mkswap: fix includes 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 --- diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 08db89b2c..e1ccc80b6 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -62,6 +62,10 @@ # include #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