2 * fs/kernfs/kernfs-internal.h - kernfs internal header file
4 * Copyright (c) 2001-3 Patrick Mochel
5 * Copyright (c) 2007 SUSE Linux Products GmbH
6 * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de>
8 * This file is released under the GPLv2.
11 #ifndef __KERNFS_INTERNAL_H
12 #define __KERNFS_INTERNAL_H
14 #include <linux/lockdep.h>
16 #include <linux/rbtree.h>
17 #include <linux/mutex.h>
19 #include <linux/kernfs.h>
21 struct sysfs_open_dirent;
23 /* type-specific structures for sysfs_dirent->s_* union members */
24 struct sysfs_elem_dir {
25 unsigned long subdirs;
26 /* children rbtree starts here and goes through sd->s_rb */
27 struct rb_root children;
30 struct sysfs_elem_symlink {
31 struct sysfs_dirent *target_sd;
34 struct sysfs_elem_attr {
35 const struct kernfs_ops *ops;
36 struct sysfs_open_dirent *open;
40 struct sysfs_inode_attrs {
41 struct iattr ia_iattr;
47 * sysfs_dirent - the building block of sysfs hierarchy. Each and
48 * every sysfs node is represented by single sysfs_dirent.
50 * As long as s_count reference is held, the sysfs_dirent itself is
51 * accessible. Dereferencing s_elem or any other outer entity
52 * requires s_active reference.
57 #ifdef CONFIG_DEBUG_LOCK_ALLOC
58 struct lockdep_map dep_map;
60 struct sysfs_dirent *s_parent;
66 struct completion *completion;
67 struct sysfs_dirent *removed_list;
70 const void *s_ns; /* namespace tag */
71 unsigned int s_hash; /* ns + name hash */
73 struct sysfs_elem_dir s_dir;
74 struct sysfs_elem_symlink s_symlink;
75 struct sysfs_elem_attr s_attr;
80 unsigned short s_flags;
83 struct sysfs_inode_attrs *s_iattr;
86 #define SD_DEACTIVATED_BIAS INT_MIN
88 #define SYSFS_TYPE_MASK 0x000f
89 #define SYSFS_DIR 0x0001
90 #define SYSFS_KOBJ_ATTR 0x0002
91 #define SYSFS_KOBJ_LINK 0x0004
92 #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
93 #define SYSFS_ACTIVE_REF SYSFS_KOBJ_ATTR
95 #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
96 #define SYSFS_FLAG_REMOVED 0x0010
97 #define SYSFS_FLAG_NS 0x0020
98 #define SYSFS_FLAG_HAS_SEQ_SHOW 0x0040
99 #define SYSFS_FLAG_HAS_MMAP 0x0080
100 #define SYSFS_FLAG_LOCKDEP 0x0100
102 static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
104 return sd->s_flags & SYSFS_TYPE_MASK;
108 * Context structure to be used while adding/removing nodes.
110 struct sysfs_addrm_cxt {
111 struct sysfs_dirent *removed;
114 #include "../sysfs/sysfs.h"
119 struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
120 void sysfs_evict_inode(struct inode *inode);
121 int sysfs_permission(struct inode *inode, int mask);
122 int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
123 int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
125 int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
126 size_t size, int flags);
127 int sysfs_inode_init(void);
132 extern struct mutex sysfs_mutex;
133 extern const struct dentry_operations sysfs_dentry_ops;
134 extern const struct file_operations sysfs_dir_operations;
135 extern const struct inode_operations sysfs_dir_inode_operations;
137 struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
138 void sysfs_put_active(struct sysfs_dirent *sd);
139 void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
140 int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
141 struct sysfs_dirent *parent_sd);
142 void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
143 struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
145 #endif /* __KERNFS_INTERNAL_H */