xref: /linux/fs/xfs/libxfs/xfs_attr_sf.h (revision eed4edda910fe34dfae8c6bfbcf57f4593a54295)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef __XFS_ATTR_SF_H__
7 #define	__XFS_ATTR_SF_H__
8 
9 /*
10  * We generate this then sort it, attr_list() must return things in hash-order.
11  */
12 typedef struct xfs_attr_sf_sort {
13 	uint8_t		entno;		/* entry number in original list */
14 	uint8_t		namelen;	/* length of name value (no null) */
15 	uint8_t		valuelen;	/* length of value */
16 	uint8_t		flags;		/* flags bits (see xfs_attr_leaf.h) */
17 	xfs_dahash_t	hash;		/* this entry's hash value */
18 	unsigned char	*name;		/* name value, pointer into buffer */
19 } xfs_attr_sf_sort_t;
20 
21 #define XFS_ATTR_SF_ENTSIZE_MAX			/* max space for name&value */ \
22 	((1 << (NBBY*(int)sizeof(uint8_t))) - 1)
23 
24 /* space name/value uses */
25 static inline int xfs_attr_sf_entsize_byname(uint8_t nlen, uint8_t vlen)
26 {
27 	return sizeof(struct xfs_attr_sf_entry) + nlen + vlen;
28 }
29 
30 /* space an entry uses */
31 static inline int xfs_attr_sf_entsize(struct xfs_attr_sf_entry *sfep)
32 {
33 	return struct_size(sfep, nameval, sfep->namelen + sfep->valuelen);
34 }
35 
36 /* first entry in the SF attr fork */
37 static inline struct xfs_attr_sf_entry *
38 xfs_attr_sf_firstentry(struct xfs_attr_sf_hdr *hdr)
39 {
40 	return (struct xfs_attr_sf_entry *)(hdr + 1);
41 }
42 
43 /* next entry after sfep */
44 static inline struct xfs_attr_sf_entry *
45 xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep)
46 {
47 	return (void *)sfep + xfs_attr_sf_entsize(sfep);
48 }
49 
50 /* pointer to the space after the last entry, e.g. for adding a new one */
51 static inline struct xfs_attr_sf_entry *
52 xfs_attr_sf_endptr(struct xfs_attr_sf_hdr *sf)
53 {
54 	return (void *)sf + be16_to_cpu(sf->totsize);
55 }
56 
57 #endif	/* __XFS_ATTR_SF_H__ */
58