blob: 39ab0481379c8674235817dcc3124ea6e066a731 [file] [log] [blame]
Tejun Heo3e519032007-06-14 03:45:15 +09001struct sysfs_elem_dir {
2 struct kobject * kobj;
3};
4
5struct sysfs_elem_symlink {
6 struct kobject * target_kobj;
7};
8
9struct sysfs_elem_attr {
10 struct attribute * attr;
11};
12
13struct sysfs_elem_bin_attr {
14 struct bin_attribute * bin_attr;
15};
16
Adam J. Richterd56c3ea2007-02-16 21:35:25 +080017struct sysfs_dirent {
18 atomic_t s_count;
Tejun Heo13b30862007-06-14 03:45:14 +090019 struct sysfs_dirent * s_parent;
Adam J. Richterd56c3ea2007-02-16 21:35:25 +080020 struct list_head s_sibling;
21 struct list_head s_children;
Tejun Heo0c096b52007-06-14 03:45:15 +090022 const char * s_name;
Tejun Heo3e519032007-06-14 03:45:15 +090023
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
Adam J. Richterd56c3ea2007-02-16 21:35:25 +080031 int s_type;
32 umode_t s_mode;
Eric Sandeendc351252007-06-11 14:02:45 +090033 ino_t s_ino;
Adam J. Richterd56c3ea2007-02-16 21:35:25 +080034 struct dentry * s_dentry;
35 struct iattr * s_iattr;
36 atomic_t s_event;
37};
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39extern struct vfsmount * sysfs_mount;
Christoph Lametere18b8902006-12-06 20:33:20 -080040extern struct kmem_cache *sysfs_dir_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -070042extern void sysfs_delete_inode(struct inode *inode);
Maneesh Soni82155342005-05-31 10:39:52 +053043extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
45
Tejun Heofa7f9122007-06-14 03:45:13 +090046extern void release_sysfs_dirent(struct sysfs_dirent * sd);
Maneesh Sonic5168652006-03-09 19:40:14 +053047extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *);
Tejun Heo3e519032007-06-14 03:45:15 +090048extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
49 int type);
Tejun Heoa26cd722007-06-14 03:45:14 +090050extern void sysfs_attach_dirent(struct sysfs_dirent *sd,
51 struct sysfs_dirent *parent_sd,
52 struct dentry *dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
Randy.Dunlap995982c2006-07-10 23:05:25 -070055extern int sysfs_hash_and_remove(struct dentry * dir, const char * name);
NeilBrown4508a7a2006-03-20 17:53:53 +110056extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
59extern void sysfs_remove_subdir(struct dentry *);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent);
Maneesh Soni988d1862005-05-31 10:39:14 +053062extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Tejun Heodd14cbc2007-06-11 14:04:01 +090064extern spinlock_t sysfs_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065extern struct rw_semaphore sysfs_rename_sem;
66extern struct super_block * sysfs_sb;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080067extern const struct file_operations sysfs_dir_operations;
68extern const struct file_operations sysfs_file_operations;
69extern const struct file_operations bin_fops;
Arjan van de Venc5ef1c42007-02-12 00:55:40 -080070extern const struct inode_operations sysfs_dir_inode_operations;
71extern const struct inode_operations sysfs_symlink_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Oliver Neukum94bebf42006-12-20 10:52:44 +010073struct sysfs_buffer {
74 struct list_head associates;
75 size_t count;
76 loff_t pos;
77 char * page;
78 struct sysfs_ops * ops;
79 struct semaphore sem;
80 int orphaned;
81 int needs_read_fill;
82 int event;
83};
84
85struct sysfs_buffer_collection {
86 struct list_head associates;
87};
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static inline struct kobject * to_kobj(struct dentry * dentry)
90{
91 struct sysfs_dirent * sd = dentry->d_fsdata;
Tejun Heo3e519032007-06-14 03:45:15 +090092 return sd->s_elem.dir.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
95static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
96{
97 struct kobject * kobj = NULL;
98
99 spin_lock(&dcache_lock);
100 if (!d_unhashed(dentry)) {
101 struct sysfs_dirent * sd = dentry->d_fsdata;
Tejun Heo3e519032007-06-14 03:45:15 +0900102 if (sd->s_type & SYSFS_KOBJ_LINK)
103 kobj = kobject_get(sd->s_elem.symlink.target_kobj);
104 else
105 kobj = kobject_get(sd->s_elem.dir.kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 }
107 spin_unlock(&dcache_lock);
108
109 return kobj;
110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
113{
114 if (sd) {
115 WARN_ON(!atomic_read(&sd->s_count));
116 atomic_inc(&sd->s_count);
117 }
118 return sd;
119}
120
121static inline void sysfs_put(struct sysfs_dirent * sd)
122{
Tejun Heo7a23ad42007-06-14 03:45:13 +0900123 if (sd && atomic_dec_and_test(&sd->s_count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 release_sysfs_dirent(sd);
125}
126
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700127static inline int sysfs_is_shadowed_inode(struct inode *inode)
128{
129 return S_ISDIR(inode->i_mode) && inode->i_op->follow_link;
130}