]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/xattr.h
ACPI: fix acpi_find_child_device() invocation in acpi_preset_companion()
[mirror_ubuntu-bionic-kernel.git] / include / linux / xattr.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2/*
3 File: linux/xattr.h
4
5 Extended attributes handling.
6
7 Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
8 Copyright (c) 2001-2002 Silicon Graphics, Inc. All Rights Reserved.
9 Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
10*/
11#ifndef _LINUX_XATTR_H
12#define _LINUX_XATTR_H
13
1dbe3942 14
38f38657 15#include <linux/slab.h>
1dbe3942 16#include <linux/types.h>
38f38657 17#include <linux/spinlock.h>
607ca46e 18#include <uapi/linux/xattr.h>
1dbe3942 19
5b0a2075
AB
20struct inode;
21struct dentry;
1da177e4 22
98e9cb57
AG
23/*
24 * struct xattr_handler: When @name is set, match attributes with exactly that
25 * name. When @prefix is set instead, match attributes with that prefix and
26 * with a non-empty suffix.
27 */
1da177e4 28struct xattr_handler {
98e9cb57 29 const char *name;
bb435453 30 const char *prefix;
e409de99 31 int flags; /* fs private flags */
764a5c6b 32 bool (*list)(struct dentry *dentry);
e409de99 33 int (*get)(const struct xattr_handler *, struct dentry *dentry,
b296821a
AV
34 struct inode *inode, const char *name, void *buffer,
35 size_t size);
e409de99 36 int (*set)(const struct xattr_handler *, struct dentry *dentry,
59301226
AV
37 struct inode *inode, const char *name, const void *buffer,
38 size_t size, int flags);
1da177e4
LT
39};
40
e409de99
AG
41const char *xattr_full_name(const struct xattr_handler *, const char *);
42
9d8f13ba 43struct xattr {
9548906b 44 const char *name;
9d8f13ba
MZ
45 void *value;
46 size_t value_len;
47};
48
42492594 49ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
5d6c3191 50ssize_t __vfs_getxattr(struct dentry *, struct inode *, const char *, void *, size_t);
8f0cfa52 51ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
659564c8 52ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
5d6c3191 53int __vfs_setxattr(struct dentry *, struct inode *, const char *, const void *, size_t, int);
b1ab7e4b 54int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
8f0cfa52 55int vfs_setxattr(struct dentry *, const char *, const void *, size_t, int);
5d6c3191 56int __vfs_removexattr(struct dentry *, const char *);
d3d00ed4 57int __vfs_removexattr_noperm(struct dentry *dentry, const char *name);
8f0cfa52 58int vfs_removexattr(struct dentry *, const char *);
5be196e5 59
1da177e4 60ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);
1601fbad
MZ
61ssize_t vfs_getxattr_alloc(struct dentry *dentry, const char *name,
62 char **xattr_value, size_t size, gfp_t flags);
38f38657 63
98e9cb57
AG
64static inline const char *xattr_prefix(const struct xattr_handler *handler)
65{
66 return handler->prefix ?: handler->name;
67}
68
38f38657
AR
69struct simple_xattrs {
70 struct list_head head;
71 spinlock_t lock;
72};
73
74struct simple_xattr {
75 struct list_head list;
76 char *name;
77 size_t size;
78 char value[0];
79};
80
81/*
82 * initialize the simple_xattrs structure
83 */
84static inline void simple_xattrs_init(struct simple_xattrs *xattrs)
85{
86 INIT_LIST_HEAD(&xattrs->head);
87 spin_lock_init(&xattrs->lock);
88}
89
90/*
91 * free all the xattrs
92 */
93static inline void simple_xattrs_free(struct simple_xattrs *xattrs)
94{
95 struct simple_xattr *xattr, *node;
96
97 list_for_each_entry_safe(xattr, node, &xattrs->head, list) {
98 kfree(xattr->name);
99 kfree(xattr);
100 }
101}
102
103struct simple_xattr *simple_xattr_alloc(const void *value, size_t size);
104int simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
105 void *buffer, size_t size);
106int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
107 const void *value, size_t size, int flags);
786534b9
AG
108ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs, char *buffer,
109 size_t size);
38f38657
AR
110void simple_xattr_list_add(struct simple_xattrs *xattrs,
111 struct simple_xattr *new_xattr);
112
1da177e4 113#endif /* _LINUX_XATTR_H */