Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / sysfs / sysfs.h
bloba8a24a0c0b3bd44b910e2e6fe52daa0a23e4855b
2 extern struct vfsmount * sysfs_mount;
3 extern kmem_cache_t *sysfs_dir_cachep;
5 extern struct inode * sysfs_new_inode(mode_t mode);
6 extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
8 extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *,
9 umode_t, int);
10 extern struct dentry * sysfs_get_dentry(struct dentry *, const char *);
12 extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
13 extern void sysfs_hash_and_remove(struct dentry * dir, const char * name);
15 extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
16 extern void sysfs_remove_subdir(struct dentry *);
18 extern const unsigned char * sysfs_get_name(struct sysfs_dirent *sd);
19 extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent);
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;
29 struct sysfs_symlink {
30 char * link_name;
31 struct kobject * target_kobj;
34 static inline struct kobject * to_kobj(struct dentry * dentry)
36 struct sysfs_dirent * sd = dentry->d_fsdata;
37 return ((struct kobject *) sd->s_element);
40 static inline struct attribute * to_attr(struct dentry * dentry)
42 struct sysfs_dirent * sd = dentry->d_fsdata;
43 return ((struct attribute *) sd->s_element);
46 static inline struct bin_attribute * to_bin_attr(struct dentry * dentry)
48 struct sysfs_dirent * sd = dentry->d_fsdata;
49 return ((struct bin_attribute *) sd->s_element);
52 static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
54 struct kobject * kobj = NULL;
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);
65 spin_unlock(&dcache_lock);
67 return kobj;
70 static inline void release_sysfs_dirent(struct sysfs_dirent * sd)
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);
78 kmem_cache_free(sysfs_dir_cachep, sd);
81 static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
83 if (sd) {
84 WARN_ON(!atomic_read(&sd->s_count));
85 atomic_inc(&sd->s_count);
87 return sd;
90 static inline void sysfs_put(struct sysfs_dirent * sd)
92 if (atomic_dec_and_test(&sd->s_count))
93 release_sysfs_dirent(sd);