]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: cleanup xfs_dir2_data_entsize
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)
Source kernel commit: 711c7dbf5fdafdbb2fb906b38cefb113bfdd4a79

Remove the XFS_DIR2_DATA_ENTSIZE and XFS_DIR3_DATA_ENTSIZE and open
code them in their only caller, which now becomes so simple that
we can turn it into an inline function.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/libxfs.h
libxfs/xfs_da_format.c
libxfs/xfs_dir2_priv.h

index 6462c7a74a01be39efaf5f23a506d26fff7d2c13..dc8a5d4f81042c83016f1bd94ffd4631e01d3887 100644 (file)
@@ -38,6 +38,9 @@ extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
 struct iomap;
 #include "xfs_cksum.h"
 
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+
 /*
  * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
  * every files via a similar include in the kernel xfs_linux.h.
index e5e1947f2ab97b5a4f37347fc4f077443673f6d7..999fc0c275735a21d4e75fe19487d50c6dc26920 100644 (file)
  * Directory data block operations
  */
 
-/*
- * For special situations, the dirent size ends up fixed because we always know
- * what the size of the entry is. That's true for the "." and "..", and
- * therefore we know that they are a fixed size and hence their offsets are
- * constant, as is the first entry.
- *
- * Hence, this calculation is written as a macro to be able to be calculated at
- * compile time and so certain offsets can be calculated directly in the
- * structure initaliser via the macro. There are two macros - one for dirents
- * with ftype and without so there are no unresolvable conditionals in the
- * calculations. We also use round_up() as XFS_DIR2_DATA_ALIGN is always a power
- * of 2 and the compiler doesn't reject it (unlike roundup()).
- */
-#define XFS_DIR2_DATA_ENTSIZE(n)                                       \
-       round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
-                sizeof(xfs_dir2_data_off_t)), XFS_DIR2_DATA_ALIGN)
-
-#define XFS_DIR3_DATA_ENTSIZE(n)                                       \
-       round_up((offsetof(struct xfs_dir2_data_entry, name[0]) + (n) + \
-                sizeof(xfs_dir2_data_off_t) + sizeof(uint8_t)),        \
-               XFS_DIR2_DATA_ALIGN)
-
-int
-xfs_dir2_data_entsize(
-       struct xfs_mount        *mp,
-       int                     n)
-{
-       if (xfs_sb_version_hasftype(&mp->m_sb))
-               return XFS_DIR3_DATA_ENTSIZE(n);
-       else
-               return XFS_DIR2_DATA_ENTSIZE(n);
-}
-
 static uint8_t
 xfs_dir2_data_get_ftype(
        struct xfs_dir2_data_entry *dep)
index ca92a41027d8ec46a66463eb926e10d9e5916790..5e938cd61c5334aadc608b22f43bd1bf8caa2728 100644 (file)
@@ -57,7 +57,6 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,
                struct xfs_buf *lbp, struct xfs_buf *dbp);
 
 /* xfs_dir2_data.c */
-int xfs_dir2_data_entsize(struct xfs_mount *mp, int n);
 __be16 *xfs_dir2_data_entry_tag_p(struct xfs_mount *mp,
                struct xfs_dir2_data_entry *dep);
 
@@ -178,4 +177,18 @@ extern xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_inode *ip);
 extern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp,
                       struct dir_context *ctx, size_t bufsize);
 
+static inline unsigned int
+xfs_dir2_data_entsize(
+       struct xfs_mount        *mp,
+       unsigned int            namelen)
+{
+       unsigned int            len;
+
+       len = offsetof(struct xfs_dir2_data_entry, name[0]) + namelen +
+                       sizeof(xfs_dir2_data_off_t) /* tag */;
+       if (xfs_sb_version_hasftype(&mp->m_sb))
+               len += sizeof(uint8_t);
+       return round_up(len, XFS_DIR2_DATA_ALIGN);
+}
+
 #endif /* __XFS_DIR2_PRIV_H__ */