1 struct sysfs_elem_dir { 2 struct kobject * kobj; 3 }; 4 5 struct sysfs_elem_symlink { 6 struct kobject * target_kobj; 7 }; 8 9 struct sysfs_elem_attr { 10 struct attribute * attr; 11 }; 12 13 struct sysfs_elem_bin_attr { 14 struct bin_attribute * bin_attr; 15 }; 16 17 struct sysfs_dirent { 18 atomic_t s_count; 19 struct sysfs_dirent * s_parent; 20 struct list_head s_sibling; 21 struct list_head s_children; 22 const char * s_name; 23 24 union { 25 struct sysfs_elem_dir dir; 26 struct sysfs_elem_symlink symlink; 27 struct sysfs_elem_attr attr; 28 struct sysfs_elem_bin_attr bin_attr; 29 } s_elem; 30 31 int s_type; 32 umode_t s_mode; 33 ino_t s_ino; 34 struct dentry * s_dentry; 35 struct iattr * s_iattr; 36 atomic_t s_event; 37 }; 38 39 extern struct vfsmount * sysfs_mount; 40 extern struct kmem_cache *sysfs_dir_cachep; 41 42 extern void sysfs_delete_inode(struct inode *inode); 43 extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *); 44 extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *)); 45 46 extern void release_sysfs_dirent(struct sysfs_dirent * sd); 47 extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *); 48 extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, 49 int type); 50 extern void sysfs_attach_dirent(struct sysfs_dirent *sd, 51 struct sysfs_dirent *parent_sd, 52 struct dentry *dentry); 53 54 extern int sysfs_add_file(struct dentry *, const struct attribute *, int); 55 extern int sysfs_hash_and_remove(struct dentry * dir, const char * name); 56 extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name); 57 58 extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **); 59 extern void sysfs_remove_subdir(struct dentry *); 60 61 extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent); 62 extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); 63 64 extern spinlock_t sysfs_lock; 65 extern spinlock_t kobj_sysfs_assoc_lock; 66 extern struct rw_semaphore sysfs_rename_sem; 67 extern struct super_block * sysfs_sb; 68 extern const struct file_operations sysfs_dir_operations; 69 extern const struct file_operations sysfs_file_operations; 70 extern const struct file_operations bin_fops; 71 extern const struct inode_operations sysfs_dir_inode_operations; 72 extern const struct inode_operations sysfs_symlink_inode_operations; 73 74 struct sysfs_buffer { 75 struct list_head associates; 76 size_t count; 77 loff_t pos; 78 char * page; 79 struct sysfs_ops * ops; 80 struct semaphore sem; 81 int orphaned; 82 int needs_read_fill; 83 int event; 84 }; 85 86 struct sysfs_buffer_collection { 87 struct list_head associates; 88 }; 89 90 static inline struct kobject * to_kobj(struct dentry * dentry) 91 { 92 struct sysfs_dirent * sd = dentry->d_fsdata; 93 return sd->s_elem.dir.kobj; 94 } 95 96 static inline struct kobject *sysfs_get_kobject(struct dentry *dentry) 97 { 98 struct kobject * kobj = NULL; 99 100 spin_lock(&dcache_lock); 101 if (!d_unhashed(dentry)) { 102 struct sysfs_dirent * sd = dentry->d_fsdata; 103 if (sd->s_type & SYSFS_KOBJ_LINK) 104 kobj = kobject_get(sd->s_elem.symlink.target_kobj); 105 else 106 kobj = kobject_get(sd->s_elem.dir.kobj); 107 } 108 spin_unlock(&dcache_lock); 109 110 return kobj; 111 } 112 113 static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) 114 { 115 if (sd) { 116 WARN_ON(!atomic_read(&sd->s_count)); 117 atomic_inc(&sd->s_count); 118 } 119 return sd; 120 } 121 122 static inline void sysfs_put(struct sysfs_dirent * sd) 123 { 124 if (sd && atomic_dec_and_test(&sd->s_count)) 125 release_sysfs_dirent(sd); 126 } 127 128 static inline int sysfs_is_shadowed_inode(struct inode *inode) 129 { 130 return S_ISDIR(inode->i_mode) && inode->i_op->follow_link; 131 } 132