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 * The kernfs hierarchy this directory belongs to. This fits
31 * better directly in sysfs_dirent but is here to save space.
33 struct kernfs_root *root;
36 struct sysfs_elem_symlink {
37 struct sysfs_dirent *target_sd;
40 struct sysfs_elem_attr {
41 const struct kernfs_ops *ops;
42 struct sysfs_open_dirent *open;
46 struct sysfs_inode_attrs {
47 struct iattr ia_iattr;
53 * sysfs_dirent - the building block of sysfs hierarchy. Each and
54 * every sysfs node is represented by single sysfs_dirent.
56 * As long as s_count reference is held, the sysfs_dirent itself is
57 * accessible. Dereferencing s_elem or any other outer entity
58 * requires s_active reference.
63 #ifdef CONFIG_DEBUG_LOCK_ALLOC
64 struct lockdep_map dep_map;
66 struct sysfs_dirent *s_parent;
72 struct completion *completion;
73 struct sysfs_dirent *removed_list;
76 const void *s_ns; /* namespace tag */
77 unsigned int s_hash; /* ns + name hash */
79 struct sysfs_elem_dir s_dir;
80 struct sysfs_elem_symlink s_symlink;
81 struct sysfs_elem_attr s_attr;
86 unsigned short s_flags;
89 struct sysfs_inode_attrs *s_iattr;
92 #define SD_DEACTIVATED_BIAS INT_MIN
94 #define SYSFS_TYPE_MASK 0x000f
95 #define SYSFS_DIR 0x0001
96 #define SYSFS_KOBJ_ATTR 0x0002
97 #define SYSFS_KOBJ_LINK 0x0004
98 #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
99 #define SYSFS_ACTIVE_REF SYSFS_KOBJ_ATTR
101 #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
102 #define SYSFS_FLAG_REMOVED 0x0010
103 #define SYSFS_FLAG_NS 0x0020
104 #define SYSFS_FLAG_HAS_SEQ_SHOW 0x0040
105 #define SYSFS_FLAG_HAS_MMAP 0x0080
106 #define SYSFS_FLAG_LOCKDEP 0x0100
108 static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
110 return sd->s_flags & SYSFS_TYPE_MASK;
114 * kernfs_root - find out the kernfs_root a sysfs_dirent belongs to
115 * @sd: sysfs_dirent of interest
117 * Return the kernfs_root @sd belongs to.
119 static inline struct kernfs_root *kernfs_root(struct sysfs_dirent *sd)
121 /* if parent exists, it's always a dir; otherwise, @sd is a dir */
124 return sd->s_dir.root;
128 * Context structure to be used while adding/removing nodes.
130 struct sysfs_addrm_cxt {
131 struct sysfs_dirent *removed;
134 #include "../sysfs/sysfs.h"
139 struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
140 void sysfs_evict_inode(struct inode *inode);
141 int sysfs_permission(struct inode *inode, int mask);
142 int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
143 int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
145 int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
146 size_t size, int flags);
147 int sysfs_inode_init(void);
152 extern struct mutex sysfs_mutex;
153 extern const struct dentry_operations sysfs_dentry_ops;
154 extern const struct file_operations sysfs_dir_operations;
155 extern const struct inode_operations sysfs_dir_inode_operations;
157 struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
158 void sysfs_put_active(struct sysfs_dirent *sd);
159 void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
160 int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
161 struct sysfs_dirent *parent_sd);
162 void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
163 struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
168 extern const struct file_operations kernfs_file_operations;
170 void sysfs_unmap_bin_file(struct sysfs_dirent *sd);
175 extern const struct inode_operations sysfs_symlink_inode_operations;
177 #endif /* __KERNFS_INTERNAL_H */