Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 1 | /* |
| 2 | * fs/kernfs/kernfs-internal.h - kernfs internal header file |
| 3 | * |
| 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> |
| 7 | * |
| 8 | * This file is released under the GPLv2. |
| 9 | */ |
| 10 | |
| 11 | #ifndef __KERNFS_INTERNAL_H |
| 12 | #define __KERNFS_INTERNAL_H |
| 13 | |
| 14 | #include <linux/lockdep.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/rbtree.h> |
Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 17 | #include <linux/mutex.h> |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 18 | |
| 19 | #include <linux/kernfs.h> |
| 20 | |
| 21 | struct sysfs_open_dirent; |
| 22 | |
| 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; |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * The kernfs hierarchy this directory belongs to. This fits |
| 31 | * better directly in sysfs_dirent but is here to save space. |
| 32 | */ |
| 33 | struct kernfs_root *root; |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | struct sysfs_elem_symlink { |
| 37 | struct sysfs_dirent *target_sd; |
| 38 | }; |
| 39 | |
| 40 | struct sysfs_elem_attr { |
| 41 | const struct kernfs_ops *ops; |
| 42 | struct sysfs_open_dirent *open; |
| 43 | loff_t size; |
| 44 | }; |
| 45 | |
| 46 | struct sysfs_inode_attrs { |
| 47 | struct iattr ia_iattr; |
| 48 | void *ia_secdata; |
| 49 | u32 ia_secdata_len; |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | * sysfs_dirent - the building block of sysfs hierarchy. Each and |
| 54 | * every sysfs node is represented by single sysfs_dirent. |
| 55 | * |
| 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. |
| 59 | */ |
| 60 | struct sysfs_dirent { |
| 61 | atomic_t s_count; |
| 62 | atomic_t s_active; |
| 63 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 64 | struct lockdep_map dep_map; |
| 65 | #endif |
| 66 | struct sysfs_dirent *s_parent; |
| 67 | const char *s_name; |
| 68 | |
| 69 | struct rb_node s_rb; |
| 70 | |
| 71 | union { |
| 72 | struct completion *completion; |
| 73 | struct sysfs_dirent *removed_list; |
| 74 | } u; |
| 75 | |
| 76 | const void *s_ns; /* namespace tag */ |
| 77 | unsigned int s_hash; /* ns + name hash */ |
| 78 | union { |
| 79 | struct sysfs_elem_dir s_dir; |
| 80 | struct sysfs_elem_symlink s_symlink; |
| 81 | struct sysfs_elem_attr s_attr; |
| 82 | }; |
| 83 | |
| 84 | void *priv; |
| 85 | |
| 86 | unsigned short s_flags; |
| 87 | umode_t s_mode; |
| 88 | unsigned int s_ino; |
| 89 | struct sysfs_inode_attrs *s_iattr; |
| 90 | }; |
| 91 | |
| 92 | #define SD_DEACTIVATED_BIAS INT_MIN |
| 93 | |
| 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 |
| 100 | |
| 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 |
| 107 | |
| 108 | static inline unsigned int sysfs_type(struct sysfs_dirent *sd) |
| 109 | { |
| 110 | return sd->s_flags & SYSFS_TYPE_MASK; |
| 111 | } |
| 112 | |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 113 | /** |
| 114 | * kernfs_root - find out the kernfs_root a sysfs_dirent belongs to |
| 115 | * @sd: sysfs_dirent of interest |
| 116 | * |
| 117 | * Return the kernfs_root @sd belongs to. |
| 118 | */ |
| 119 | static inline struct kernfs_root *kernfs_root(struct sysfs_dirent *sd) |
| 120 | { |
| 121 | /* if parent exists, it's always a dir; otherwise, @sd is a dir */ |
| 122 | if (sd->s_parent) |
| 123 | sd = sd->s_parent; |
| 124 | return sd->s_dir.root; |
| 125 | } |
| 126 | |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 127 | /* |
| 128 | * Context structure to be used while adding/removing nodes. |
| 129 | */ |
| 130 | struct sysfs_addrm_cxt { |
| 131 | struct sysfs_dirent *removed; |
| 132 | }; |
| 133 | |
| 134 | #include "../sysfs/sysfs.h" |
| 135 | |
Tejun Heo | ffed24e | 2013-11-28 14:54:32 -0500 | [diff] [blame] | 136 | /* |
Tejun Heo | fa736a9 | 2013-11-28 14:54:44 -0500 | [diff] [blame^] | 137 | * mount.c |
| 138 | */ |
| 139 | struct sysfs_super_info { |
| 140 | /* |
| 141 | * The root associated with this super_block. Each super_block is |
| 142 | * identified by the root and ns it's associated with. |
| 143 | */ |
| 144 | struct kernfs_root *root; |
| 145 | |
| 146 | /* |
| 147 | * Each sb is associated with one namespace tag, currently the network |
| 148 | * namespace of the task which mounted this sysfs instance. If multiple |
| 149 | * tags become necessary, make the following an array and compare |
| 150 | * sysfs_dirent tag against every entry. |
| 151 | */ |
| 152 | const void *ns; |
| 153 | }; |
| 154 | #define sysfs_info(SB) ((struct sysfs_super_info *)(SB->s_fs_info)) |
| 155 | |
| 156 | extern struct kmem_cache *sysfs_dir_cachep; |
| 157 | |
| 158 | /* |
Tejun Heo | ffed24e | 2013-11-28 14:54:32 -0500 | [diff] [blame] | 159 | * inode.c |
| 160 | */ |
| 161 | struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd); |
| 162 | void sysfs_evict_inode(struct inode *inode); |
| 163 | int sysfs_permission(struct inode *inode, int mask); |
| 164 | int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); |
| 165 | int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 166 | struct kstat *stat); |
| 167 | int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, |
| 168 | size_t size, int flags); |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 169 | void sysfs_inode_init(void); |
Tejun Heo | ffed24e | 2013-11-28 14:54:32 -0500 | [diff] [blame] | 170 | |
Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 171 | /* |
| 172 | * dir.c |
| 173 | */ |
| 174 | extern struct mutex sysfs_mutex; |
| 175 | extern const struct dentry_operations sysfs_dentry_ops; |
| 176 | extern const struct file_operations sysfs_dir_operations; |
| 177 | extern const struct inode_operations sysfs_dir_inode_operations; |
| 178 | |
| 179 | struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); |
| 180 | void sysfs_put_active(struct sysfs_dirent *sd); |
| 181 | void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt); |
| 182 | int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, |
| 183 | struct sysfs_dirent *parent_sd); |
| 184 | void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); |
Tejun Heo | bc75555 | 2013-11-28 14:54:41 -0500 | [diff] [blame] | 185 | struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, |
| 186 | const char *name, umode_t mode, int type); |
Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 187 | |
Tejun Heo | 414985a | 2013-11-28 14:54:34 -0500 | [diff] [blame] | 188 | /* |
| 189 | * file.c |
| 190 | */ |
| 191 | extern const struct file_operations kernfs_file_operations; |
| 192 | |
| 193 | void sysfs_unmap_bin_file(struct sysfs_dirent *sd); |
| 194 | |
Tejun Heo | 2072f1a | 2013-11-28 14:54:35 -0500 | [diff] [blame] | 195 | /* |
| 196 | * symlink.c |
| 197 | */ |
| 198 | extern const struct inode_operations sysfs_symlink_inode_operations; |
| 199 | |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 200 | #endif /* __KERNFS_INTERNAL_H */ |