xref: /kernel/linux/linux-5.10/include/linux/xattr.h (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci  File: linux/xattr.h
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci  Extended attributes handling.
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci  Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
88c2ecf20Sopenharmony_ci  Copyright (c) 2001-2002 Silicon Graphics, Inc.  All Rights Reserved.
98c2ecf20Sopenharmony_ci  Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
108c2ecf20Sopenharmony_ci*/
118c2ecf20Sopenharmony_ci#ifndef _LINUX_XATTR_H
128c2ecf20Sopenharmony_ci#define _LINUX_XATTR_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/slab.h>
168c2ecf20Sopenharmony_ci#include <linux/types.h>
178c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
188c2ecf20Sopenharmony_ci#include <linux/mm.h>
198c2ecf20Sopenharmony_ci#include <uapi/linux/xattr.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct inode;
228c2ecf20Sopenharmony_cistruct dentry;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/*
258c2ecf20Sopenharmony_ci * struct xattr_handler: When @name is set, match attributes with exactly that
268c2ecf20Sopenharmony_ci * name.  When @prefix is set instead, match attributes with that prefix and
278c2ecf20Sopenharmony_ci * with a non-empty suffix.
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_cistruct xattr_handler {
308c2ecf20Sopenharmony_ci	const char *name;
318c2ecf20Sopenharmony_ci	const char *prefix;
328c2ecf20Sopenharmony_ci	int flags;      /* fs private flags */
338c2ecf20Sopenharmony_ci	bool (*list)(struct dentry *dentry);
348c2ecf20Sopenharmony_ci	int (*get)(const struct xattr_handler *, struct dentry *dentry,
358c2ecf20Sopenharmony_ci		   struct inode *inode, const char *name, void *buffer,
368c2ecf20Sopenharmony_ci		   size_t size);
378c2ecf20Sopenharmony_ci	int (*set)(const struct xattr_handler *, struct dentry *dentry,
388c2ecf20Sopenharmony_ci		   struct inode *inode, const char *name, const void *buffer,
398c2ecf20Sopenharmony_ci		   size_t size, int flags);
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciconst char *xattr_full_name(const struct xattr_handler *, const char *);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistruct xattr {
458c2ecf20Sopenharmony_ci	const char *name;
468c2ecf20Sopenharmony_ci	void *value;
478c2ecf20Sopenharmony_ci	size_t value_len;
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cissize_t __vfs_getxattr(struct dentry *, struct inode *, const char *, void *, size_t);
518c2ecf20Sopenharmony_cissize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
528c2ecf20Sopenharmony_cissize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
538c2ecf20Sopenharmony_ciint __vfs_setxattr(struct dentry *, struct inode *, const char *, const void *, size_t, int);
548c2ecf20Sopenharmony_ciint __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
558c2ecf20Sopenharmony_ciint __vfs_setxattr_locked(struct dentry *, const char *, const void *, size_t, int, struct inode **);
568c2ecf20Sopenharmony_ciint vfs_setxattr(struct dentry *, const char *, const void *, size_t, int);
578c2ecf20Sopenharmony_ciint __vfs_removexattr(struct dentry *, const char *);
588c2ecf20Sopenharmony_ciint __vfs_removexattr_locked(struct dentry *, const char *, struct inode **);
598c2ecf20Sopenharmony_ciint vfs_removexattr(struct dentry *, const char *);
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cissize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);
628c2ecf20Sopenharmony_cissize_t vfs_getxattr_alloc(struct dentry *dentry, const char *name,
638c2ecf20Sopenharmony_ci			   char **xattr_value, size_t size, gfp_t flags);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciint xattr_supported_namespace(struct inode *inode, const char *prefix);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic inline const char *xattr_prefix(const struct xattr_handler *handler)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	return handler->prefix ?: handler->name;
708c2ecf20Sopenharmony_ci}
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistruct simple_xattrs {
738c2ecf20Sopenharmony_ci	struct list_head head;
748c2ecf20Sopenharmony_ci	spinlock_t lock;
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistruct simple_xattr {
788c2ecf20Sopenharmony_ci	struct list_head list;
798c2ecf20Sopenharmony_ci	char *name;
808c2ecf20Sopenharmony_ci	size_t size;
818c2ecf20Sopenharmony_ci	char value[];
828c2ecf20Sopenharmony_ci};
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/*
858c2ecf20Sopenharmony_ci * initialize the simple_xattrs structure
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_cistatic inline void simple_xattrs_init(struct simple_xattrs *xattrs)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	INIT_LIST_HEAD(&xattrs->head);
908c2ecf20Sopenharmony_ci	spin_lock_init(&xattrs->lock);
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/*
948c2ecf20Sopenharmony_ci * free all the xattrs
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_cistatic inline void simple_xattrs_free(struct simple_xattrs *xattrs)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	struct simple_xattr *xattr, *node;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	list_for_each_entry_safe(xattr, node, &xattrs->head, list) {
1018c2ecf20Sopenharmony_ci		kfree(xattr->name);
1028c2ecf20Sopenharmony_ci		kvfree(xattr);
1038c2ecf20Sopenharmony_ci	}
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistruct simple_xattr *simple_xattr_alloc(const void *value, size_t size);
1078c2ecf20Sopenharmony_ciint simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
1088c2ecf20Sopenharmony_ci		     void *buffer, size_t size);
1098c2ecf20Sopenharmony_ciint simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
1108c2ecf20Sopenharmony_ci		     const void *value, size_t size, int flags,
1118c2ecf20Sopenharmony_ci		     ssize_t *removed_size);
1128c2ecf20Sopenharmony_cissize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs, char *buffer,
1138c2ecf20Sopenharmony_ci			  size_t size);
1148c2ecf20Sopenharmony_civoid simple_xattr_list_add(struct simple_xattrs *xattrs,
1158c2ecf20Sopenharmony_ci			   struct simple_xattr *new_xattr);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#endif	/* _LINUX_XATTR_H */
118