]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: check dirents have parent pointers
authorDarrick J. Wong <djwong@kernel.org>
Tue, 9 Jan 2024 17:41:46 +0000 (09:41 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 10 Apr 2024 00:21:31 +0000 (17:21 -0700)
If the fs has parent pointers, we need to check that each child dirent
points to a file that has a parent pointer pointing back at us.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/xfs_parent.c
libxfs/xfs_parent.h

index 2f5fe3e557ec280264ca46cafa127440316cdd44..a13c41de189c0c5376af5af929658331016bc519 100644 (file)
@@ -296,3 +296,25 @@ xfs_parent_from_xattr(
                *parent_gen = be32_to_cpu(rec->p_gen);
        return 1;
 }
+
+/*
+ * Look up a parent pointer record (@parent_name -> @pptr) of @ip.
+ *
+ * Caller must hold at least ILOCK_SHARED.  The scratchpad need not be
+ * initialized.
+ *
+ * Returns 0 if the pointer is found, -ENOATTR if there is no match, or a
+ * negative errno.
+ */
+int
+xfs_parent_lookup(
+       struct xfs_trans                *tp,
+       struct xfs_inode                *ip,
+       const struct xfs_name           *parent_name,
+       struct xfs_parent_rec           *pptr,
+       struct xfs_da_args              *scratch)
+{
+       memset(scratch, 0, sizeof(struct xfs_da_args));
+       xfs_parent_da_args_init(scratch, tp, pptr, ip, ip->i_ino, parent_name);
+       return xfs_attr_get_ilocked(scratch);
+}
index 3003ab496f8548dbdd0f656afd9746f47bdaed5d..b063312a61acbcb4b6b232d5f574a8562830173c 100644 (file)
@@ -96,4 +96,9 @@ int xfs_parent_from_xattr(struct xfs_mount *mp, unsigned int attr_flags,
                const void *value, unsigned int valuelen,
                xfs_ino_t *parent_ino, uint32_t *parent_gen);
 
+/* Repair functions */
+int xfs_parent_lookup(struct xfs_trans *tp, struct xfs_inode *ip,
+               const struct xfs_name *name, struct xfs_parent_rec *pptr,
+               struct xfs_da_args *scratch);
+
 #endif /* __XFS_PARENT_H__ */