aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/sysfs.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-12 18:49:37 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-12 18:49:37 -0400
commitefefc6eb38d43b8e5daef482f575d767b002004e (patch)
tree8a3933db1f8721f9bcc9912c800dc8406f4bdf94 /fs/sysfs/sysfs.h
parent117494a1b65183f0e3fcc817b07944bc5c465050 (diff)
parentcd59abfcc441b2abb4cf2cd62c1eb0f02a60e8dd (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (75 commits) PM: merge device power-management source files sysfs: add copyrights kobject: update the copyrights kset: add some kerneldoc to help describe what these strange things are Driver core: rename ktype_edd and ktype_efivar Driver core: rename ktype_driver Driver core: rename ktype_device Driver core: rename ktype_class driver core: remove subsystem_init() sysfs: move sysfs file poll implementation to sysfs_open_dirent sysfs: implement sysfs_open_dirent sysfs: move sysfs_dirent->s_children into sysfs_dirent->s_dir sysfs: make sysfs_root a regular directory dirent sysfs: open code sysfs_attach_dentry() sysfs: make s_elem an anonymous union sysfs: make bin attr open get active reference of parent too sysfs: kill unnecessary NULL pointer check in sysfs_release() sysfs: kill unnecessary sysfs_get() in open paths sysfs: reposition sysfs_dirent->s_mode. sysfs: kill sysfs_update_file() ...
Diffstat (limited to 'fs/sysfs/sysfs.h')
-rw-r--r--fs/sysfs/sysfs.h184
1 files changed, 111 insertions, 73 deletions
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 6b8c8d76d308..f0326f281d1c 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -1,20 +1,39 @@
1/*
2 * fs/sysfs/sysfs.h - sysfs internal header file
3 *
4 * Copyright (c) 2001-3 Patrick Mochel
5 * Copyright (c) 2007 SUSE Linux Products GmbH
6 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
7 *
8 * This file is released under the GPLv2.
9 */
10
11struct sysfs_open_dirent;
12
13/* type-specific structures for sysfs_dirent->s_* union members */
1struct sysfs_elem_dir { 14struct sysfs_elem_dir {
2 struct kobject * kobj; 15 struct kobject *kobj;
16 /* children list starts here and goes through sd->s_sibling */
17 struct sysfs_dirent *children;
3}; 18};
4 19
5struct sysfs_elem_symlink { 20struct sysfs_elem_symlink {
6 struct sysfs_dirent * target_sd; 21 struct sysfs_dirent *target_sd;
7}; 22};
8 23
9struct sysfs_elem_attr { 24struct sysfs_elem_attr {
10 struct attribute * attr; 25 struct attribute *attr;
26 struct sysfs_open_dirent *open;
11}; 27};
12 28
13struct sysfs_elem_bin_attr { 29struct sysfs_elem_bin_attr {
14 struct bin_attribute * bin_attr; 30 struct bin_attribute *bin_attr;
15}; 31};
16 32
17/* 33/*
34 * sysfs_dirent - the building block of sysfs hierarchy. Each and
35 * every sysfs node is represented by single sysfs_dirent.
36 *
18 * As long as s_count reference is held, the sysfs_dirent itself is 37 * As long as s_count reference is held, the sysfs_dirent itself is
19 * accessible. Dereferencing s_elem or any other outer entity 38 * accessible. Dereferencing s_elem or any other outer entity
20 * requires s_active reference. 39 * requires s_active reference.
@@ -22,28 +41,43 @@ struct sysfs_elem_bin_attr {
22struct sysfs_dirent { 41struct sysfs_dirent {
23 atomic_t s_count; 42 atomic_t s_count;
24 atomic_t s_active; 43 atomic_t s_active;
25 struct sysfs_dirent * s_parent; 44 struct sysfs_dirent *s_parent;
26 struct sysfs_dirent * s_sibling; 45 struct sysfs_dirent *s_sibling;
27 struct sysfs_dirent * s_children; 46 const char *s_name;
28 const char * s_name;
29 47
30 union { 48 union {
31 struct sysfs_elem_dir dir; 49 struct sysfs_elem_dir s_dir;
32 struct sysfs_elem_symlink symlink; 50 struct sysfs_elem_symlink s_symlink;
33 struct sysfs_elem_attr attr; 51 struct sysfs_elem_attr s_attr;
34 struct sysfs_elem_bin_attr bin_attr; 52 struct sysfs_elem_bin_attr s_bin_attr;
35 } s_elem; 53 };
36 54
37 unsigned int s_flags; 55 unsigned int s_flags;
38 umode_t s_mode;
39 ino_t s_ino; 56 ino_t s_ino;
40 struct dentry * s_dentry; 57 umode_t s_mode;
41 struct iattr * s_iattr; 58 struct iattr *s_iattr;
42 atomic_t s_event;
43}; 59};
44 60
45#define SD_DEACTIVATED_BIAS INT_MIN 61#define SD_DEACTIVATED_BIAS INT_MIN
62
63#define SYSFS_TYPE_MASK 0x00ff
64#define SYSFS_DIR 0x0001
65#define SYSFS_KOBJ_ATTR 0x0002
66#define SYSFS_KOBJ_BIN_ATTR 0x0004
67#define SYSFS_KOBJ_LINK 0x0008
68#define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
69
70#define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
71#define SYSFS_FLAG_REMOVED 0x0200
72
73static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
74{
75 return sd->s_flags & SYSFS_TYPE_MASK;
76}
46 77
78/*
79 * Context structure to be used while adding/removing nodes.
80 */
47struct sysfs_addrm_cxt { 81struct sysfs_addrm_cxt {
48 struct sysfs_dirent *parent_sd; 82 struct sysfs_dirent *parent_sd;
49 struct inode *parent_inode; 83 struct inode *parent_inode;
@@ -51,63 +85,47 @@ struct sysfs_addrm_cxt {
51 int cnt; 85 int cnt;
52}; 86};
53 87
54extern struct vfsmount * sysfs_mount; 88/*
89 * mount.c
90 */
55extern struct sysfs_dirent sysfs_root; 91extern struct sysfs_dirent sysfs_root;
92extern struct super_block *sysfs_sb;
56extern struct kmem_cache *sysfs_dir_cachep; 93extern struct kmem_cache *sysfs_dir_cachep;
57 94
58extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd); 95/*
59extern void sysfs_link_sibling(struct sysfs_dirent *sd); 96 * dir.c
60extern void sysfs_unlink_sibling(struct sysfs_dirent *sd); 97 */
61extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
62extern void sysfs_put_active(struct sysfs_dirent *sd);
63extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
64extern void sysfs_put_active_two(struct sysfs_dirent *sd);
65extern void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
66 struct sysfs_dirent *parent_sd);
67extern void sysfs_add_one(struct sysfs_addrm_cxt *acxt,
68 struct sysfs_dirent *sd);
69extern void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
70 struct sysfs_dirent *sd);
71extern int sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
72
73extern void sysfs_delete_inode(struct inode *inode);
74extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd);
75extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode);
76
77extern void release_sysfs_dirent(struct sysfs_dirent * sd);
78extern struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
79 const unsigned char *name);
80extern struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
81 const unsigned char *name);
82extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
83 int type);
84
85extern int sysfs_add_file(struct sysfs_dirent *dir_sd,
86 const struct attribute *attr, int type);
87extern int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
88extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
89
90extern int sysfs_create_subdir(struct kobject *kobj, const char *name,
91 struct sysfs_dirent **p_sd);
92extern void sysfs_remove_subdir(struct sysfs_dirent *sd);
93
94extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
95
96extern spinlock_t sysfs_assoc_lock;
97extern struct mutex sysfs_mutex; 98extern struct mutex sysfs_mutex;
98extern struct super_block * sysfs_sb; 99extern struct mutex sysfs_rename_mutex;
100extern spinlock_t sysfs_assoc_lock;
101
99extern const struct file_operations sysfs_dir_operations; 102extern const struct file_operations sysfs_dir_operations;
100extern const struct file_operations sysfs_file_operations;
101extern const struct file_operations bin_fops;
102extern const struct inode_operations sysfs_dir_inode_operations; 103extern const struct inode_operations sysfs_dir_inode_operations;
103extern const struct inode_operations sysfs_symlink_inode_operations;
104
105static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
106{
107 return sd->s_flags & SYSFS_TYPE_MASK;
108}
109 104
110static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) 105struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
106struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
107void sysfs_put_active(struct sysfs_dirent *sd);
108struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
109void sysfs_put_active_two(struct sysfs_dirent *sd);
110void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
111 struct sysfs_dirent *parent_sd);
112int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
113void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
114void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
115
116struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
117 const unsigned char *name);
118struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
119 const unsigned char *name);
120struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
121
122void release_sysfs_dirent(struct sysfs_dirent *sd);
123
124int sysfs_create_subdir(struct kobject *kobj, const char *name,
125 struct sysfs_dirent **p_sd);
126void sysfs_remove_subdir(struct sysfs_dirent *sd);
127
128static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
111{ 129{
112 if (sd) { 130 if (sd) {
113 WARN_ON(!atomic_read(&sd->s_count)); 131 WARN_ON(!atomic_read(&sd->s_count));
@@ -116,13 +134,33 @@ static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
116 return sd; 134 return sd;
117} 135}
118 136
119static inline void sysfs_put(struct sysfs_dirent * sd) 137static inline void sysfs_put(struct sysfs_dirent *sd)
120{ 138{
121 if (sd && atomic_dec_and_test(&sd->s_count)) 139 if (sd && atomic_dec_and_test(&sd->s_count))
122 release_sysfs_dirent(sd); 140 release_sysfs_dirent(sd);
123} 141}
124 142
125static inline int sysfs_is_shadowed_inode(struct inode *inode) 143/*
126{ 144 * inode.c
127 return S_ISDIR(inode->i_mode) && inode->i_op->follow_link; 145 */
128} 146struct inode *sysfs_get_inode(struct sysfs_dirent *sd);
147int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
148int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
149
150/*
151 * file.c
152 */
153extern const struct file_operations sysfs_file_operations;
154
155int sysfs_add_file(struct sysfs_dirent *dir_sd,
156 const struct attribute *attr, int type);
157
158/*
159 * bin.c
160 */
161extern const struct file_operations bin_fops;
162
163/*
164 * symlink.c
165 */
166extern const struct inode_operations sysfs_symlink_inode_operations;