Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003   File: linux/xattr.h
0004 
0005   Extended attributes handling.
0006 
0007   Copyright (C) 2001 by Andreas Gruenbacher <a.gruenbacher@computer.org>
0008   Copyright (c) 2001-2002 Silicon Graphics, Inc.  All Rights Reserved.
0009   Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
0010 */
0011 #ifndef _LINUX_XATTR_H
0012 #define _LINUX_XATTR_H
0013 
0014 
0015 #include <linux/slab.h>
0016 #include <linux/types.h>
0017 #include <linux/spinlock.h>
0018 #include <linux/mm.h>
0019 #include <linux/user_namespace.h>
0020 #include <uapi/linux/xattr.h>
0021 
0022 struct inode;
0023 struct dentry;
0024 
0025 /*
0026  * struct xattr_handler: When @name is set, match attributes with exactly that
0027  * name.  When @prefix is set instead, match attributes with that prefix and
0028  * with a non-empty suffix.
0029  */
0030 struct xattr_handler {
0031     const char *name;
0032     const char *prefix;
0033     int flags;      /* fs private flags */
0034     bool (*list)(struct dentry *dentry);
0035     int (*get)(const struct xattr_handler *, struct dentry *dentry,
0036            struct inode *inode, const char *name, void *buffer,
0037            size_t size);
0038     int (*set)(const struct xattr_handler *,
0039            struct user_namespace *mnt_userns, struct dentry *dentry,
0040            struct inode *inode, const char *name, const void *buffer,
0041            size_t size, int flags);
0042 };
0043 
0044 const char *xattr_full_name(const struct xattr_handler *, const char *);
0045 
0046 struct xattr {
0047     const char *name;
0048     void *value;
0049     size_t value_len;
0050 };
0051 
0052 ssize_t __vfs_getxattr(struct dentry *, struct inode *, const char *, void *, size_t);
0053 ssize_t vfs_getxattr(struct user_namespace *, struct dentry *, const char *,
0054              void *, size_t);
0055 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
0056 int __vfs_setxattr(struct user_namespace *, struct dentry *, struct inode *,
0057            const char *, const void *, size_t, int);
0058 int __vfs_setxattr_noperm(struct user_namespace *, struct dentry *,
0059               const char *, const void *, size_t, int);
0060 int __vfs_setxattr_locked(struct user_namespace *, struct dentry *,
0061               const char *, const void *, size_t, int,
0062               struct inode **);
0063 int vfs_setxattr(struct user_namespace *, struct dentry *, const char *,
0064          void *, size_t, int);
0065 int __vfs_removexattr(struct user_namespace *, struct dentry *, const char *);
0066 int __vfs_removexattr_locked(struct user_namespace *, struct dentry *,
0067                  const char *, struct inode **);
0068 int vfs_removexattr(struct user_namespace *, struct dentry *, const char *);
0069 
0070 ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);
0071 ssize_t vfs_getxattr_alloc(struct user_namespace *mnt_userns,
0072                struct dentry *dentry, const char *name,
0073                char **xattr_value, size_t size, gfp_t flags);
0074 
0075 int xattr_supported_namespace(struct inode *inode, const char *prefix);
0076 
0077 static inline const char *xattr_prefix(const struct xattr_handler *handler)
0078 {
0079     return handler->prefix ?: handler->name;
0080 }
0081 
0082 struct simple_xattrs {
0083     struct list_head head;
0084     spinlock_t lock;
0085 };
0086 
0087 struct simple_xattr {
0088     struct list_head list;
0089     char *name;
0090     size_t size;
0091     char value[];
0092 };
0093 
0094 /*
0095  * initialize the simple_xattrs structure
0096  */
0097 static inline void simple_xattrs_init(struct simple_xattrs *xattrs)
0098 {
0099     INIT_LIST_HEAD(&xattrs->head);
0100     spin_lock_init(&xattrs->lock);
0101 }
0102 
0103 /*
0104  * free all the xattrs
0105  */
0106 static inline void simple_xattrs_free(struct simple_xattrs *xattrs)
0107 {
0108     struct simple_xattr *xattr, *node;
0109 
0110     list_for_each_entry_safe(xattr, node, &xattrs->head, list) {
0111         kfree(xattr->name);
0112         kvfree(xattr);
0113     }
0114 }
0115 
0116 struct simple_xattr *simple_xattr_alloc(const void *value, size_t size);
0117 int simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
0118              void *buffer, size_t size);
0119 int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
0120              const void *value, size_t size, int flags,
0121              ssize_t *removed_size);
0122 ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs, char *buffer,
0123               size_t size);
0124 void simple_xattr_list_add(struct simple_xattrs *xattrs,
0125                struct simple_xattr *new_xattr);
0126 
0127 #endif  /* _LINUX_XATTR_H */