]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: add fsuuid command
authorCatherine Hoang <catherine.hoang@oracle.com>
Thu, 5 Jan 2023 00:36:12 +0000 (16:36 -0800)
committerCarlos Maiolino <cem@kernel.org>
Fri, 20 Jan 2023 13:29:25 +0000 (14:29 +0100)
Add support for the fsuuid command to retrieve the UUID of a mounted
filesystem.

Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
io/Makefile
io/fsuuid.c [new file with mode: 0644]
io/init.c
io/io.h
man/man8/xfs_io.8

index 498174cfc43e32006c751a84883059a319c9706b..53fef09e899cf32fa9833ddf14f852420a0097af 100644 (file)
@@ -10,12 +10,12 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
 HFILES = init.h io.h
 CFILES = init.c \
        attr.c bmap.c bulkstat.c crc32cselftest.c cowextsize.c encrypt.c \
-       file.c freeze.c fsync.c getrusage.c imap.c inject.c label.c link.c \
-       mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \
+       file.c freeze.c fsuuid.c fsync.c getrusage.c imap.c inject.c label.c \
+       link.c mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \
        resblks.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \
        truncate.c utimes.c
 
-LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)
+LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD) $(LIBUUID)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
 
diff --git a/io/fsuuid.c b/io/fsuuid.c
new file mode 100644 (file)
index 0000000..af2f87a
--- /dev/null
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023 Oracle.
+ * All Rights Reserved.
+ */
+
+#include "libxfs.h"
+#include "command.h"
+#include "init.h"
+#include "io.h"
+#include "libfrog/fsgeom.h"
+#include "libfrog/logging.h"
+
+static cmdinfo_t fsuuid_cmd;
+
+static int
+fsuuid_f(
+       int                     argc,
+       char                    **argv)
+{
+       struct xfs_fsop_geom    fsgeo;
+       int                     ret;
+       char                    bp[40];
+
+       ret = -xfrog_geometry(file->fd, &fsgeo);
+
+       if (ret) {
+               xfrog_perror(ret, "XFS_IOC_FSGEOMETRY");
+               exitcode = 1;
+       } else {
+               platform_uuid_unparse((uuid_t *)fsgeo.uuid, bp);
+               printf("UUID = %s\n", bp);
+       }
+
+       return 0;
+}
+
+void
+fsuuid_init(void)
+{
+       fsuuid_cmd.name = "fsuuid";
+       fsuuid_cmd.cfunc = fsuuid_f;
+       fsuuid_cmd.argmin = 0;
+       fsuuid_cmd.argmax = 0;
+       fsuuid_cmd.flags = CMD_FLAG_ONESHOT | CMD_NOMAP_OK;
+       fsuuid_cmd.oneline = _("get mounted filesystem UUID");
+
+       add_command(&fsuuid_cmd);
+}
index 033ed67d455f11bd1a8143657914bafbd6a38809..104cd2c12152374964401eb5af025bb007667fea 100644 (file)
--- a/io/init.c
+++ b/io/init.c
@@ -56,6 +56,7 @@ init_commands(void)
        flink_init();
        freeze_init();
        fsmap_init();
+       fsuuid_init();
        fsync_init();
        getrusage_init();
        help_init();
diff --git a/io/io.h b/io/io.h
index 64b7a663a8cf1a6a868a205c969df50881ee95b5..fe474faf4ad0988e71e2551d106908e7ff1fe25e 100644 (file)
--- a/io/io.h
+++ b/io/io.h
@@ -94,6 +94,7 @@ extern void           encrypt_init(void);
 extern void            file_init(void);
 extern void            flink_init(void);
 extern void            freeze_init(void);
+extern void            fsuuid_init(void);
 extern void            fsync_init(void);
 extern void            getrusage_init(void);
 extern void            help_init(void);
index 223b51523145504b590addb0125250c96f10dd95..ef7087b3d0908e937f7030aa392f4b86d303d3f6 100644 (file)
@@ -1455,6 +1455,9 @@ This option is not compatible with the
 flag.
 .RE
 .PD
+.TP
+.B fsuuid
+Print the mounted filesystem UUID.
 
 
 .SH OTHER COMMANDS