| 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 | /* | 
|  | 137 | * inode.c | 
|  | 138 | */ | 
|  | 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, | 
|  | 144 | struct kstat *stat); | 
|  | 145 | int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, | 
|  | 146 | size_t size, int flags); | 
| Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame^] | 147 | void sysfs_inode_init(void); | 
| Tejun Heo | ffed24e | 2013-11-28 14:54:32 -0500 | [diff] [blame] | 148 |  | 
| Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 149 | /* | 
|  | 150 | * dir.c | 
|  | 151 | */ | 
|  | 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; | 
|  | 156 |  | 
|  | 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); | 
| Tejun Heo | bc75555 | 2013-11-28 14:54:41 -0500 | [diff] [blame] | 163 | struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, | 
|  | 164 | const char *name, umode_t mode, int type); | 
| Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 165 |  | 
| Tejun Heo | 414985a | 2013-11-28 14:54:34 -0500 | [diff] [blame] | 166 | /* | 
|  | 167 | * file.c | 
|  | 168 | */ | 
|  | 169 | extern const struct file_operations kernfs_file_operations; | 
|  | 170 |  | 
|  | 171 | void sysfs_unmap_bin_file(struct sysfs_dirent *sd); | 
|  | 172 |  | 
| Tejun Heo | 2072f1a | 2013-11-28 14:54:35 -0500 | [diff] [blame] | 173 | /* | 
|  | 174 | * symlink.c | 
|  | 175 | */ | 
|  | 176 | extern const struct inode_operations sysfs_symlink_inode_operations; | 
|  | 177 |  | 
| Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 178 | #endif	/* __KERNFS_INTERNAL_H */ |