]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkswap: add features list to --version output
authorKarel Zak <kzak@redhat.com>
Mon, 3 Feb 2025 11:03:10 +0000 (12:03 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 3 Feb 2025 11:03:10 +0000 (12:03 +0100)
* Define USE_NOCOW to simplify code
* Add array of features

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

index e1ccc80b6ae1ac00944cc9264f96ddf86a866baa..d73c3f0aa55e6cdd743ae19dc687a12e8ba5764c 100644 (file)
 # define USE_EXTENDS_CHECK 1
 #endif
 
+#if defined(FS_IOC_GETFLAGS) && defined(FS_NOCOW_FL)
+# define USE_NOCOW 1
+#endif
+
 #define MIN_GOODPAGES  10
 
 #define SELINUX_SWAPFILE_TYPE  "swapfile_t"
@@ -417,7 +421,7 @@ static void open_device(struct mkswap_control *ctl)
 
                /* Let's attempt to set the "nocow" attribute for Btrfs, etc.
                 * Ignore if unsupported. */
-#if defined(FS_IOC_GETFLAGS) && defined(FS_NOCOW_FL)
+#ifdef USE_NOCOW
                if (ioctl(ctl->fd, FS_IOC_GETFLAGS, &attr) == 0) {
                        attr |= FS_NOCOW_FL;
                        if (ioctl(ctl->fd, FS_IOC_SETFLAGS, &attr) < 0 &&
@@ -647,8 +651,30 @@ int main(int argc, char **argv)
                        ctl.file = 1;
                        break;
                case 'V':
-                       print_version(EXIT_SUCCESS);
-                       break;
+               {
+                       static const char *const features[] = {
+#ifdef USE_EXTENDS_CHECK
+                               "extends-check",
+#endif
+#ifdef USE_NOCOW
+                               "nocow",
+#endif
+#if defined(HAVE_POSIX_FALLOCATE) || defined(HAVE_FALLOCATE)
+                               "fallocate",
+#endif
+#ifdef HAVE_LIBBLKID
+                               "blkid-check",
+#endif
+#ifdef HAVE_LIBUUID
+                               "uuid",
+#endif
+#ifdef HAVE_LIBSELINUX
+                               "selinux",
+#endif
+                               NULL,
+                       };
+                       print_version_with_features(EXIT_SUCCESS, features);
+               }
                case OPT_LOCK:
                        ctl.lockmode = "1";
                        if (optarg) {