xref: /openbmc/linux/fs/xfs/libxfs/xfs_attr_sf.h (revision e01b7eed)
1508578f2SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
284be0ffcSDave Chinner /*
384be0ffcSDave Chinner  * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
484be0ffcSDave Chinner  * All Rights Reserved.
584be0ffcSDave Chinner  */
684be0ffcSDave Chinner #ifndef __XFS_ATTR_SF_H__
784be0ffcSDave Chinner #define	__XFS_ATTR_SF_H__
884be0ffcSDave Chinner 
984be0ffcSDave Chinner /*
1084be0ffcSDave Chinner  * Attribute storage when stored inside the inode.
1184be0ffcSDave Chinner  *
1284be0ffcSDave Chinner  * Small attribute lists are packed as tightly as possible so as
1384be0ffcSDave Chinner  * to fit into the literal area of the inode.
1484be0ffcSDave Chinner  */
1584be0ffcSDave Chinner typedef struct xfs_attr_sf_hdr xfs_attr_sf_hdr_t;
1684be0ffcSDave Chinner 
1784be0ffcSDave Chinner /*
1884be0ffcSDave Chinner  * We generate this then sort it, attr_list() must return things in hash-order.
1984be0ffcSDave Chinner  */
2084be0ffcSDave Chinner typedef struct xfs_attr_sf_sort {
21c8ce540dSDarrick J. Wong 	uint8_t		entno;		/* entry number in original list */
22c8ce540dSDarrick J. Wong 	uint8_t		namelen;	/* length of name value (no null) */
23c8ce540dSDarrick J. Wong 	uint8_t		valuelen;	/* length of value */
24c8ce540dSDarrick J. Wong 	uint8_t		flags;		/* flags bits (see xfs_attr_leaf.h) */
2584be0ffcSDave Chinner 	xfs_dahash_t	hash;		/* this entry's hash value */
2684be0ffcSDave Chinner 	unsigned char	*name;		/* name value, pointer into buffer */
2784be0ffcSDave Chinner } xfs_attr_sf_sort_t;
2884be0ffcSDave Chinner 
2984be0ffcSDave Chinner #define XFS_ATTR_SF_ENTSIZE_MAX			/* max space for name&value */ \
30c8ce540dSDarrick J. Wong 	((1 << (NBBY*(int)sizeof(uint8_t))) - 1)
31e01b7eedSCarlos Maiolino 
32e01b7eedSCarlos Maiolino /* space name/value uses */
xfs_attr_sf_entsize_byname(uint8_t nlen,uint8_t vlen)33e01b7eedSCarlos Maiolino static inline int xfs_attr_sf_entsize_byname(uint8_t nlen, uint8_t vlen)
34e01b7eedSCarlos Maiolino {
35e01b7eedSCarlos Maiolino 	return sizeof(struct xfs_attr_sf_entry) + nlen + vlen;
36e01b7eedSCarlos Maiolino }
37e01b7eedSCarlos Maiolino 
38e01b7eedSCarlos Maiolino /* space an entry uses */
xfs_attr_sf_entsize(struct xfs_attr_sf_entry * sfep)39e01b7eedSCarlos Maiolino static inline int xfs_attr_sf_entsize(struct xfs_attr_sf_entry *sfep)
40e01b7eedSCarlos Maiolino {
41e01b7eedSCarlos Maiolino 	return struct_size(sfep, nameval, sfep->namelen + sfep->valuelen);
42e01b7eedSCarlos Maiolino }
43e01b7eedSCarlos Maiolino 
44e01b7eedSCarlos Maiolino /* next entry in struct */
45e01b7eedSCarlos Maiolino static inline struct xfs_attr_sf_entry *
xfs_attr_sf_nextentry(struct xfs_attr_sf_entry * sfep)46e01b7eedSCarlos Maiolino xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep)
47e01b7eedSCarlos Maiolino {
48e01b7eedSCarlos Maiolino 	return (void *)sfep + xfs_attr_sf_entsize(sfep);
49e01b7eedSCarlos Maiolino }
5084be0ffcSDave Chinner 
5184be0ffcSDave Chinner #endif	/* __XFS_ATTR_SF_H__ */
52