blob: 3e97a935e7121f0d169701a9d79976f9d85fb3d7 [file] [log] [blame]
Olivier Deprez157378f2022-04-04 15:47:50 +02001/* SPDX-License-Identifier: GPL-2.0 */
David Brazdil0f672f62019-12-10 10:32:29 +00002/*
3 * Copyright (c) 2000,2002-2003,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6#ifndef __XFS_ATTR_H__
7#define __XFS_ATTR_H__
8
9struct xfs_inode;
10struct xfs_da_args;
11struct xfs_attr_list_context;
12
13/*
14 * Large attribute lists are structured around Btrees where all the data
15 * elements are in the leaf nodes. Attribute names are hashed into an int,
16 * then that int is used as the index into the Btree. Since the hashval
17 * of an attribute name may not be unique, we may have duplicate keys.
18 * The internal links in the Btree are logical block offsets into the file.
19 *
20 * Small attribute lists use a different format and are packed as tightly
21 * as possible so as to fit into the literal area of the inode.
22 */
23
David Brazdil0f672f62019-12-10 10:32:29 +000024/*
25 * The maximum size (into the kernel or returned from the kernel) of an
26 * attribute value or the buffer used for an attr_list() call. Larger
27 * sizes will result in an ERANGE return code.
28 */
29#define ATTR_MAX_VALUELEN (64*1024) /* max length of a value */
30
31/*
David Brazdil0f672f62019-12-10 10:32:29 +000032 * Kernel-internal version of the attrlist cursor.
33 */
Olivier Deprez157378f2022-04-04 15:47:50 +020034struct xfs_attrlist_cursor_kern {
David Brazdil0f672f62019-12-10 10:32:29 +000035 __u32 hashval; /* hash value of next entry to add */
36 __u32 blkno; /* block containing entry (suggestion) */
37 __u32 offset; /* offset in list of equal-hashvals */
38 __u16 pad1; /* padding to match user-level */
39 __u8 pad2; /* padding to match user-level */
40 __u8 initted; /* T/F: cursor has been initialized */
Olivier Deprez157378f2022-04-04 15:47:50 +020041};
David Brazdil0f672f62019-12-10 10:32:29 +000042
43
44/*========================================================================
45 * Structure used to pass context around among the routines.
46 *========================================================================*/
47
48
49/* void; state communicated via *context */
50typedef void (*put_listent_func_t)(struct xfs_attr_list_context *, int,
51 unsigned char *, int, int);
52
Olivier Deprez157378f2022-04-04 15:47:50 +020053struct xfs_attr_list_context {
54 struct xfs_trans *tp;
55 struct xfs_inode *dp; /* inode */
56 struct xfs_attrlist_cursor_kern cursor; /* position in list */
57 void *buffer; /* output buffer */
David Brazdil0f672f62019-12-10 10:32:29 +000058
59 /*
60 * Abort attribute list iteration if non-zero. Can be used to pass
61 * error values to the xfs_attr_list caller.
62 */
Olivier Deprez157378f2022-04-04 15:47:50 +020063 int seen_enough;
64 bool allow_incomplete;
David Brazdil0f672f62019-12-10 10:32:29 +000065
Olivier Deprez157378f2022-04-04 15:47:50 +020066 ssize_t count; /* num used entries */
67 int dupcnt; /* count dup hashvals seen */
68 int bufsize; /* total buffer size */
69 int firstu; /* first used byte in buffer */
70 unsigned int attr_filter; /* XFS_ATTR_{ROOT,SECURE} */
71 int resynch; /* T/F: resynch with cursor */
72 put_listent_func_t put_listent; /* list output fmt function */
73 int index; /* index into output buffer */
74};
David Brazdil0f672f62019-12-10 10:32:29 +000075
76
77/*========================================================================
78 * Function prototypes for the kernel.
79 *========================================================================*/
80
81/*
82 * Overall external interface routines.
83 */
84int xfs_attr_inactive(struct xfs_inode *dp);
Olivier Deprez157378f2022-04-04 15:47:50 +020085int xfs_attr_list_ilocked(struct xfs_attr_list_context *);
86int xfs_attr_list(struct xfs_attr_list_context *);
David Brazdil0f672f62019-12-10 10:32:29 +000087int xfs_inode_hasattr(struct xfs_inode *ip);
Olivier Deprez157378f2022-04-04 15:47:50 +020088int xfs_attr_get_ilocked(struct xfs_da_args *args);
89int xfs_attr_get(struct xfs_da_args *args);
90int xfs_attr_set(struct xfs_da_args *args);
David Brazdil0f672f62019-12-10 10:32:29 +000091int xfs_attr_set_args(struct xfs_da_args *args);
Olivier Deprez157378f2022-04-04 15:47:50 +020092int xfs_has_attr(struct xfs_da_args *args);
David Brazdil0f672f62019-12-10 10:32:29 +000093int xfs_attr_remove_args(struct xfs_da_args *args);
David Brazdil0f672f62019-12-10 10:32:29 +000094bool xfs_attr_namecheck(const void *name, size_t length);
95
96#endif /* __XFS_ATTR_H__ */