blob: 60717660ac55e1386bc88480c101d8ff76a8f8d9 [file] [log] [blame]
Tejun Heo3e519032007-06-14 03:45:15 +09001struct sysfs_elem_dir {
2 struct kobject * kobj;
3};
4
5struct sysfs_elem_symlink {
Tejun Heo2b29ac22007-06-14 03:45:15 +09006 struct sysfs_dirent * target_sd;
Tejun Heo3e519032007-06-14 03:45:15 +09007};
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;
Tejun Heoaecdced2007-06-14 03:45:15 +090065extern spinlock_t kobj_sysfs_assoc_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern struct rw_semaphore sysfs_rename_sem;
67extern struct super_block * sysfs_sb;
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080068extern const struct file_operations sysfs_dir_operations;
69extern const struct file_operations sysfs_file_operations;
70extern const struct file_operations bin_fops;
Arjan van de Venc5ef1c42007-02-12 00:55:40 -080071extern const struct inode_operations sysfs_dir_inode_operations;
72extern const struct inode_operations sysfs_symlink_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Oliver Neukum94bebf42006-12-20 10:52:44 +010074struct 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
86struct sysfs_buffer_collection {
87 struct list_head associates;
88};
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static inline struct kobject * to_kobj(struct dentry * dentry)
91{
92 struct sysfs_dirent * sd = dentry->d_fsdata;
Tejun Heo3e519032007-06-14 03:45:15 +090093 return sd->s_elem.dir.kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
96static 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;
Tejun Heo2b29ac22007-06-14 03:45:15 +0900103
Tejun Heo3e519032007-06-14 03:45:15 +0900104 if (sd->s_type & SYSFS_KOBJ_LINK)
Tejun Heo2b29ac22007-06-14 03:45:15 +0900105 sd = sd->s_elem.symlink.target_sd;
106
107 kobj = kobject_get(sd->s_elem.dir.kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 }
109 spin_unlock(&dcache_lock);
110
111 return kobj;
112}
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
115{
116 if (sd) {
117 WARN_ON(!atomic_read(&sd->s_count));
118 atomic_inc(&sd->s_count);
119 }
120 return sd;
121}
122
123static inline void sysfs_put(struct sysfs_dirent * sd)
124{
Tejun Heo7a23ad42007-06-14 03:45:13 +0900125 if (sd && atomic_dec_and_test(&sd->s_count))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 release_sysfs_dirent(sd);
127}
128
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700129static inline int sysfs_is_shadowed_inode(struct inode *inode)
130{
131 return S_ISDIR(inode->i_mode) && inode->i_op->follow_link;
132}