]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: hoist inode flag conversion functions to libxfs
authorDarrick J. Wong <djwong@kernel.org>
Wed, 2 Oct 2024 01:09:08 +0000 (18:09 -0700)
committerAndrey Albershteyn <aalbersh@redhat.com>
Fri, 4 Oct 2024 10:42:07 +0000 (12:42 +0200)
Source kernel commit: b7c477be396948ce88ea591b91070fa68ac12437

Hoist the inode flag conversion functions into libxfs so that we can
keep them in sync.  Do this by creating a new xfs_inode_util.c file in
libxfs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
include/libxfs.h
include/xfs_inode.h
libxfs/Makefile
libxfs/util.c
libxfs/xfs_bmap.c
libxfs/xfs_inode_util.c [new file with mode: 0644]
libxfs/xfs_inode_util.h [new file with mode: 0644]

index 31d08119150cb9b11fd09b2cc256027b89bef8f3..17cf619f0544aaad4e8cc324d84c945fc8c346f6 100644 (file)
@@ -74,6 +74,7 @@ struct iomap;
 #include "xfs_attr_sf.h"
 #include "xfs_inode_fork.h"
 #include "xfs_inode_buf.h"
+#include "xfs_inode_util.h"
 #include "xfs_alloc.h"
 #include "xfs_btree.h"
 #include "xfs_bmap.h"
index ec4eada81642d44b42e479a894aa73d7e4f2c1c9..17d3da6aee5f64c0434f6c3669f9aff02e1f45f9 100644 (file)
@@ -10,6 +10,7 @@
 /* These match kernel side includes */
 #include "xfs_inode_buf.h"
 #include "xfs_inode_fork.h"
+#include "xfs_inode_util.h"
 
 struct xfs_trans;
 struct xfs_mount;
index 833c65092bb3b0819bffcb6e286012f40beaf287..cc3312b57718ee4346573bb4bd56f6097bb0cc9f 100644 (file)
@@ -52,6 +52,7 @@ HFILES = \
        xfs_ialloc_btree.h \
        xfs_inode_buf.h \
        xfs_inode_fork.h \
+       xfs_inode_util.h \
        xfs_parent.h \
        xfs_quota_defs.h \
        xfs_refcount.h \
@@ -105,6 +106,7 @@ CFILES = buf_mem.c \
        xfs_iext_tree.c \
        xfs_inode_buf.c \
        xfs_inode_fork.c \
+       xfs_inode_util.c \
        xfs_ialloc_btree.c \
        xfs_log_rlimit.c \
        xfs_parent.c \
index 373749457cc1048b619fc44f372fa71bc70681ff..4e96ba5ce076b097b75355ab72af7a4caa768759 100644 (file)
@@ -150,66 +150,6 @@ current_time(struct inode *inode)
        return tv;
 }
 
-STATIC uint16_t
-xfs_flags2diflags(
-       struct xfs_inode        *ip,
-       unsigned int            xflags)
-{
-       /* can't set PREALLOC this way, just preserve it */
-       uint16_t                di_flags =
-               (ip->i_diflags & XFS_DIFLAG_PREALLOC);
-
-       if (xflags & FS_XFLAG_IMMUTABLE)
-               di_flags |= XFS_DIFLAG_IMMUTABLE;
-       if (xflags & FS_XFLAG_APPEND)
-               di_flags |= XFS_DIFLAG_APPEND;
-       if (xflags & FS_XFLAG_SYNC)
-               di_flags |= XFS_DIFLAG_SYNC;
-       if (xflags & FS_XFLAG_NOATIME)
-               di_flags |= XFS_DIFLAG_NOATIME;
-       if (xflags & FS_XFLAG_NODUMP)
-               di_flags |= XFS_DIFLAG_NODUMP;
-       if (xflags & FS_XFLAG_NODEFRAG)
-               di_flags |= XFS_DIFLAG_NODEFRAG;
-       if (xflags & FS_XFLAG_FILESTREAM)
-               di_flags |= XFS_DIFLAG_FILESTREAM;
-       if (S_ISDIR(VFS_I(ip)->i_mode)) {
-               if (xflags & FS_XFLAG_RTINHERIT)
-                       di_flags |= XFS_DIFLAG_RTINHERIT;
-               if (xflags & FS_XFLAG_NOSYMLINKS)
-                       di_flags |= XFS_DIFLAG_NOSYMLINKS;
-               if (xflags & FS_XFLAG_EXTSZINHERIT)
-                       di_flags |= XFS_DIFLAG_EXTSZINHERIT;
-               if (xflags & FS_XFLAG_PROJINHERIT)
-                       di_flags |= XFS_DIFLAG_PROJINHERIT;
-       } else if (S_ISREG(VFS_I(ip)->i_mode)) {
-               if (xflags & FS_XFLAG_REALTIME)
-                       di_flags |= XFS_DIFLAG_REALTIME;
-               if (xflags & FS_XFLAG_EXTSIZE)
-                       di_flags |= XFS_DIFLAG_EXTSIZE;
-       }
-
-       return di_flags;
-}
-
-STATIC uint64_t
-xfs_flags2diflags2(
-       struct xfs_inode        *ip,
-       unsigned int            xflags)
-{
-       uint64_t                di_flags2 =
-               (ip->i_diflags2 & (XFS_DIFLAG2_REFLINK |
-                                  XFS_DIFLAG2_BIGTIME |
-                                  XFS_DIFLAG2_NREXT64));
-
-       if (xflags & FS_XFLAG_DAX)
-               di_flags2 |= XFS_DIFLAG2_DAX;
-       if (xflags & FS_XFLAG_COWEXTSIZE)
-               di_flags2 |= XFS_DIFLAG2_COWEXTSIZE;
-
-       return di_flags2;
-}
-
 /* Propagate di_flags from a parent inode to a child inode. */
 static void
 xfs_inode_propagate_flags(
index befbe0b0721b3ad06b10fab9c3e439eb24782a07..5f4446104d8e48ae89c3ccb599c5b1b106a1f6f3 100644 (file)
@@ -33,6 +33,7 @@
 #include "xfs_health.h"
 #include "defer_item.h"
 #include "xfs_symlink_remote.h"
+#include "xfs_inode_util.h"
 
 struct kmem_cache              *xfs_bmap_intent_cache;
 
diff --git a/libxfs/xfs_inode_util.c b/libxfs/xfs_inode_util.c
new file mode 100644 (file)
index 0000000..868a77c
--- /dev/null
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2000-2006 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ */
+#include "libxfs_priv.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_log_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_sb.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_inode_util.h"
+
+uint16_t
+xfs_flags2diflags(
+       struct xfs_inode        *ip,
+       unsigned int            xflags)
+{
+       /* can't set PREALLOC this way, just preserve it */
+       uint16_t                di_flags =
+               (ip->i_diflags & XFS_DIFLAG_PREALLOC);
+
+       if (xflags & FS_XFLAG_IMMUTABLE)
+               di_flags |= XFS_DIFLAG_IMMUTABLE;
+       if (xflags & FS_XFLAG_APPEND)
+               di_flags |= XFS_DIFLAG_APPEND;
+       if (xflags & FS_XFLAG_SYNC)
+               di_flags |= XFS_DIFLAG_SYNC;
+       if (xflags & FS_XFLAG_NOATIME)
+               di_flags |= XFS_DIFLAG_NOATIME;
+       if (xflags & FS_XFLAG_NODUMP)
+               di_flags |= XFS_DIFLAG_NODUMP;
+       if (xflags & FS_XFLAG_NODEFRAG)
+               di_flags |= XFS_DIFLAG_NODEFRAG;
+       if (xflags & FS_XFLAG_FILESTREAM)
+               di_flags |= XFS_DIFLAG_FILESTREAM;
+       if (S_ISDIR(VFS_I(ip)->i_mode)) {
+               if (xflags & FS_XFLAG_RTINHERIT)
+                       di_flags |= XFS_DIFLAG_RTINHERIT;
+               if (xflags & FS_XFLAG_NOSYMLINKS)
+                       di_flags |= XFS_DIFLAG_NOSYMLINKS;
+               if (xflags & FS_XFLAG_EXTSZINHERIT)
+                       di_flags |= XFS_DIFLAG_EXTSZINHERIT;
+               if (xflags & FS_XFLAG_PROJINHERIT)
+                       di_flags |= XFS_DIFLAG_PROJINHERIT;
+       } else if (S_ISREG(VFS_I(ip)->i_mode)) {
+               if (xflags & FS_XFLAG_REALTIME)
+                       di_flags |= XFS_DIFLAG_REALTIME;
+               if (xflags & FS_XFLAG_EXTSIZE)
+                       di_flags |= XFS_DIFLAG_EXTSIZE;
+       }
+
+       return di_flags;
+}
+
+uint64_t
+xfs_flags2diflags2(
+       struct xfs_inode        *ip,
+       unsigned int            xflags)
+{
+       uint64_t                di_flags2 =
+               (ip->i_diflags2 & (XFS_DIFLAG2_REFLINK |
+                                  XFS_DIFLAG2_BIGTIME |
+                                  XFS_DIFLAG2_NREXT64));
+
+       if (xflags & FS_XFLAG_DAX)
+               di_flags2 |= XFS_DIFLAG2_DAX;
+       if (xflags & FS_XFLAG_COWEXTSIZE)
+               di_flags2 |= XFS_DIFLAG2_COWEXTSIZE;
+
+       return di_flags2;
+}
+
+uint32_t
+xfs_ip2xflags(
+       struct xfs_inode        *ip)
+{
+       uint32_t                flags = 0;
+
+       if (ip->i_diflags & XFS_DIFLAG_ANY) {
+               if (ip->i_diflags & XFS_DIFLAG_REALTIME)
+                       flags |= FS_XFLAG_REALTIME;
+               if (ip->i_diflags & XFS_DIFLAG_PREALLOC)
+                       flags |= FS_XFLAG_PREALLOC;
+               if (ip->i_diflags & XFS_DIFLAG_IMMUTABLE)
+                       flags |= FS_XFLAG_IMMUTABLE;
+               if (ip->i_diflags & XFS_DIFLAG_APPEND)
+                       flags |= FS_XFLAG_APPEND;
+               if (ip->i_diflags & XFS_DIFLAG_SYNC)
+                       flags |= FS_XFLAG_SYNC;
+               if (ip->i_diflags & XFS_DIFLAG_NOATIME)
+                       flags |= FS_XFLAG_NOATIME;
+               if (ip->i_diflags & XFS_DIFLAG_NODUMP)
+                       flags |= FS_XFLAG_NODUMP;
+               if (ip->i_diflags & XFS_DIFLAG_RTINHERIT)
+                       flags |= FS_XFLAG_RTINHERIT;
+               if (ip->i_diflags & XFS_DIFLAG_PROJINHERIT)
+                       flags |= FS_XFLAG_PROJINHERIT;
+               if (ip->i_diflags & XFS_DIFLAG_NOSYMLINKS)
+                       flags |= FS_XFLAG_NOSYMLINKS;
+               if (ip->i_diflags & XFS_DIFLAG_EXTSIZE)
+                       flags |= FS_XFLAG_EXTSIZE;
+               if (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT)
+                       flags |= FS_XFLAG_EXTSZINHERIT;
+               if (ip->i_diflags & XFS_DIFLAG_NODEFRAG)
+                       flags |= FS_XFLAG_NODEFRAG;
+               if (ip->i_diflags & XFS_DIFLAG_FILESTREAM)
+                       flags |= FS_XFLAG_FILESTREAM;
+       }
+
+       if (ip->i_diflags2 & XFS_DIFLAG2_ANY) {
+               if (ip->i_diflags2 & XFS_DIFLAG2_DAX)
+                       flags |= FS_XFLAG_DAX;
+               if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)
+                       flags |= FS_XFLAG_COWEXTSIZE;
+       }
+
+       if (xfs_inode_has_attr_fork(ip))
+               flags |= FS_XFLAG_HASATTR;
+       return flags;
+}
diff --git a/libxfs/xfs_inode_util.h b/libxfs/xfs_inode_util.h
new file mode 100644 (file)
index 0000000..6ad1898
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ */
+#ifndef        __XFS_INODE_UTIL_H__
+#define        __XFS_INODE_UTIL_H__
+
+uint16_t       xfs_flags2diflags(struct xfs_inode *ip, unsigned int xflags);
+uint64_t       xfs_flags2diflags2(struct xfs_inode *ip, unsigned int xflags);
+uint32_t       xfs_dic2xflags(struct xfs_inode *ip);
+uint32_t       xfs_ip2xflags(struct xfs_inode *ip);
+
+#endif /* __XFS_INODE_UTIL_H__ */