| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 |  | 
|  | 2 | extern struct vfsmount * sysfs_mount; | 
|  | 3 | extern kmem_cache_t *sysfs_dir_cachep; | 
|  | 4 |  | 
| Maneesh Soni | 8215534 | 2005-05-31 10:39:52 +0530 | [diff] [blame] | 5 | extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *)); | 
|  | 7 |  | 
|  | 8 | extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *, | 
|  | 9 | umode_t, int); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 |  | 
|  | 11 | extern int sysfs_add_file(struct dentry *, const struct attribute *, int); | 
|  | 12 | extern void sysfs_hash_and_remove(struct dentry * dir, const char * name); | 
|  | 13 |  | 
|  | 14 | extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **); | 
|  | 15 | extern void sysfs_remove_subdir(struct dentry *); | 
|  | 16 |  | 
|  | 17 | extern const unsigned char * sysfs_get_name(struct sysfs_dirent *sd); | 
|  | 18 | extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent); | 
| Maneesh Soni | 988d186 | 2005-05-31 10:39:14 +0530 | [diff] [blame] | 19 | extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 |  | 
|  | 21 | extern struct rw_semaphore sysfs_rename_sem; | 
|  | 22 | extern struct super_block * sysfs_sb; | 
|  | 23 | extern struct file_operations sysfs_dir_operations; | 
|  | 24 | extern struct file_operations sysfs_file_operations; | 
|  | 25 | extern struct file_operations bin_fops; | 
|  | 26 | extern struct inode_operations sysfs_dir_inode_operations; | 
|  | 27 | extern struct inode_operations sysfs_symlink_inode_operations; | 
|  | 28 |  | 
|  | 29 | struct sysfs_symlink { | 
|  | 30 | char * link_name; | 
|  | 31 | struct kobject * target_kobj; | 
|  | 32 | }; | 
|  | 33 |  | 
|  | 34 | static inline struct kobject * to_kobj(struct dentry * dentry) | 
|  | 35 | { | 
|  | 36 | struct sysfs_dirent * sd = dentry->d_fsdata; | 
|  | 37 | return ((struct kobject *) sd->s_element); | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | static inline struct attribute * to_attr(struct dentry * dentry) | 
|  | 41 | { | 
|  | 42 | struct sysfs_dirent * sd = dentry->d_fsdata; | 
|  | 43 | return ((struct attribute *) sd->s_element); | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | static inline struct bin_attribute * to_bin_attr(struct dentry * dentry) | 
|  | 47 | { | 
|  | 48 | struct sysfs_dirent * sd = dentry->d_fsdata; | 
|  | 49 | return ((struct bin_attribute *) sd->s_element); | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | static inline struct kobject *sysfs_get_kobject(struct dentry *dentry) | 
|  | 53 | { | 
|  | 54 | struct kobject * kobj = NULL; | 
|  | 55 |  | 
|  | 56 | spin_lock(&dcache_lock); | 
|  | 57 | if (!d_unhashed(dentry)) { | 
|  | 58 | struct sysfs_dirent * sd = dentry->d_fsdata; | 
|  | 59 | if (sd->s_type & SYSFS_KOBJ_LINK) { | 
|  | 60 | struct sysfs_symlink * sl = sd->s_element; | 
|  | 61 | kobj = kobject_get(sl->target_kobj); | 
|  | 62 | } else | 
|  | 63 | kobj = kobject_get(sd->s_element); | 
|  | 64 | } | 
|  | 65 | spin_unlock(&dcache_lock); | 
|  | 66 |  | 
|  | 67 | return kobj; | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | static inline void release_sysfs_dirent(struct sysfs_dirent * sd) | 
|  | 71 | { | 
|  | 72 | if (sd->s_type & SYSFS_KOBJ_LINK) { | 
|  | 73 | struct sysfs_symlink * sl = sd->s_element; | 
|  | 74 | kfree(sl->link_name); | 
|  | 75 | kobject_put(sl->target_kobj); | 
|  | 76 | kfree(sl); | 
|  | 77 | } | 
| Maneesh Soni | 988d186 | 2005-05-31 10:39:14 +0530 | [diff] [blame] | 78 | kfree(sd->s_iattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | kmem_cache_free(sysfs_dir_cachep, sd); | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) | 
|  | 83 | { | 
|  | 84 | if (sd) { | 
|  | 85 | WARN_ON(!atomic_read(&sd->s_count)); | 
|  | 86 | atomic_inc(&sd->s_count); | 
|  | 87 | } | 
|  | 88 | return sd; | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | static inline void sysfs_put(struct sysfs_dirent * sd) | 
|  | 92 | { | 
|  | 93 | if (atomic_dec_and_test(&sd->s_count)) | 
|  | 94 | release_sysfs_dirent(sd); | 
|  | 95 | } | 
|  | 96 |  |