1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2022-2024 Oracle.
6 #ifndef __XFS_PARENT_H__
7 #define __XFS_PARENT_H__
9 /* Metadata validators */
10 bool xfs_parent_namecheck(unsigned int attr_flags
, const void *name
,
12 bool xfs_parent_valuecheck(struct xfs_mount
*mp
, const void *value
,
15 xfs_dahash_t
xfs_parent_hashval(struct xfs_mount
*mp
, const uint8_t *name
,
16 int namelen
, xfs_ino_t parent_ino
);
17 xfs_dahash_t
xfs_parent_hashattr(struct xfs_mount
*mp
, const uint8_t *name
,
18 int namelen
, const void *value
, int valuelen
);
20 /* Initializes a xfs_parent_rec to be stored as an attribute name. */
23 struct xfs_parent_rec
*rec
,
27 rec
->p_ino
= cpu_to_be64(ino
);
28 rec
->p_gen
= cpu_to_be32(gen
);
31 /* Initializes a xfs_parent_rec to be stored as an attribute name. */
33 xfs_inode_to_parent_rec(
34 struct xfs_parent_rec
*rec
,
35 const struct xfs_inode
*dp
)
37 xfs_parent_rec_init(rec
, dp
->i_ino
, VFS_IC(dp
)->i_generation
);
40 extern struct kmem_cache
*xfs_parent_args_cache
;
43 * Parent pointer information needed to pass around the deferred xattr update
46 struct xfs_parent_args
{
47 struct xfs_parent_rec rec
;
48 struct xfs_parent_rec new_rec
;
49 struct xfs_da_args args
;
53 * Start a parent pointer update by allocating the context object we need to
54 * perform a parent pointer update.
59 struct xfs_parent_args
**ppargsp
)
61 if (!xfs_has_parent(mp
)) {
66 *ppargsp
= kmem_cache_zalloc(xfs_parent_args_cache
, GFP_KERNEL
);
72 /* Finish a parent pointer update by freeing the context object. */
76 struct xfs_parent_args
*ppargs
)
79 kmem_cache_free(xfs_parent_args_cache
, ppargs
);
82 int xfs_parent_addname(struct xfs_trans
*tp
, struct xfs_parent_args
*ppargs
,
83 struct xfs_inode
*dp
, const struct xfs_name
*parent_name
,
84 struct xfs_inode
*child
);
85 int xfs_parent_removename(struct xfs_trans
*tp
, struct xfs_parent_args
*ppargs
,
86 struct xfs_inode
*dp
, const struct xfs_name
*parent_name
,
87 struct xfs_inode
*child
);
88 int xfs_parent_replacename(struct xfs_trans
*tp
,
89 struct xfs_parent_args
*ppargs
,
90 struct xfs_inode
*old_dp
, const struct xfs_name
*old_name
,
91 struct xfs_inode
*new_dp
, const struct xfs_name
*new_name
,
92 struct xfs_inode
*child
);
94 int xfs_parent_from_attr(struct xfs_mount
*mp
, unsigned int attr_flags
,
95 const unsigned char *name
, unsigned int namelen
,
96 const void *value
, unsigned int valuelen
,
97 xfs_ino_t
*parent_ino
, uint32_t *parent_gen
);
99 /* Repair functions */
100 int xfs_parent_lookup(struct xfs_trans
*tp
, struct xfs_inode
*ip
,
101 const struct xfs_name
*name
, struct xfs_parent_rec
*pptr
,
102 struct xfs_da_args
*scratch
);
103 int xfs_parent_set(struct xfs_inode
*ip
, xfs_ino_t owner
,
104 const struct xfs_name
*name
, struct xfs_parent_rec
*pptr
,
105 struct xfs_da_args
*scratch
);
106 int xfs_parent_unset(struct xfs_inode
*ip
, xfs_ino_t owner
,
107 const struct xfs_name
*name
, struct xfs_parent_rec
*pptr
,
108 struct xfs_da_args
*scratch
);
110 #endif /* __XFS_PARENT_H__ */