Initial revision
[linux-2.6.git] / include / linux / sysfs.h
1 /*
2  * sysfs.h - definitions for the device driver filesystem
3  *
4  * Copyright (c) 2001,2002 Patrick Mochel
5  *
6  * Please see Documentation/filesystems/sysfs.txt for more information.
7  */
8
9 #ifndef _SYSFS_H_
10 #define _SYSFS_H_
11
12 #include <asm/atomic.h>
13
14 #define SYSFS_SUPER_MAGIC       0x62656572
15
16 struct kobject;
17 struct module;
18
19 struct attribute {
20         char                    * name;
21         struct module           * owner;
22         mode_t                  mode;
23 };
24
25 struct attribute_group {
26         char                    * name;
27         struct attribute        ** attrs;
28 };
29
30
31
32 /**
33  * Use these macros to make defining attributes easier. See include/linux/device.h
34  * for examples..
35  */
36
37 #define __ATTR(_name,_mode,_show,_store) { \
38         .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
39         .show   = _show,                                        \
40         .store  = _store,                                       \
41 }
42
43 #define __ATTR_RO(_name) { \
44         .attr   = { .name = __stringify(_name), .mode = 0444, .owner = THIS_MODULE },   \
45         .show   = _name##_show, \
46 }
47
48 #define __ATTR_NULL { .attr = { .name = NULL } }
49
50 #define attr_name(_attr) (_attr).attr.name
51
52 struct bin_attribute {
53         struct attribute        attr;
54         size_t                  size;
55         ssize_t (*read)(struct kobject *, char *, loff_t, size_t);
56         ssize_t (*write)(struct kobject *, char *, loff_t, size_t);
57 };
58
59 struct sysfs_ops {
60         ssize_t (*show)(struct kobject *, struct attribute *,char *);
61         ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
62 };
63
64 struct sysfs_dirent {
65         atomic_t                s_count;
66         struct list_head        s_sibling;
67         struct list_head        s_children;
68         void                    * s_element;
69         int                     s_type;
70         umode_t                 s_mode;
71         struct dentry           * s_dentry;
72 };
73
74 #define SYSFS_ROOT              0x0001
75 #define SYSFS_DIR               0x0002
76 #define SYSFS_KOBJ_ATTR         0x0004
77 #define SYSFS_KOBJ_BIN_ATTR     0x0008
78 #define SYSFS_KOBJ_LINK         0x0020
79 #define SYSFS_NOT_PINNED        (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK)
80
81 #ifdef CONFIG_SYSFS
82
83 extern int
84 sysfs_create_dir(struct kobject *);
85
86 extern void
87 sysfs_remove_dir(struct kobject *);
88
89 extern int
90 sysfs_rename_dir(struct kobject *, const char *new_name);
91
92 extern int
93 sysfs_create_file(struct kobject *, const struct attribute *);
94
95 extern int
96 sysfs_update_file(struct kobject *, const struct attribute *);
97
98 extern void
99 sysfs_remove_file(struct kobject *, const struct attribute *);
100
101 extern int 
102 sysfs_create_link(struct kobject * kobj, struct kobject * target, char * name);
103
104 extern void
105 sysfs_remove_link(struct kobject *, char * name);
106
107 int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr);
108 int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr);
109
110 int sysfs_create_group(struct kobject *, const struct attribute_group *);
111 void sysfs_remove_group(struct kobject *, const struct attribute_group *);
112
113 #else /* CONFIG_SYSFS */
114
115 static inline int sysfs_create_dir(struct kobject * k)
116 {
117         return 0;
118 }
119
120 static inline void sysfs_remove_dir(struct kobject * k)
121 {
122         ;
123 }
124
125 static inline int sysfs_rename_dir(struct kobject * k, const char *new_name)
126 {
127         return 0;
128 }
129
130 static inline int sysfs_create_file(struct kobject * k, const struct attribute * a)
131 {
132         return 0;
133 }
134
135 static inline int sysfs_update_file(struct kobject * k, const struct attribute * a)
136 {
137         return 0;
138 }
139
140 static inline void sysfs_remove_file(struct kobject * k, const struct attribute * a)
141 {
142         ;
143 }
144
145 static inline int sysfs_create_link(struct kobject * k, struct kobject * t, char * n)
146 {
147         return 0;
148 }
149
150 static inline void sysfs_remove_link(struct kobject * k, char * name)
151 {
152         ;
153 }
154
155
156 static inline int sysfs_create_bin_file(struct kobject * k, struct bin_attribute * a)
157 {
158         return 0;
159 }
160
161 static inline int sysfs_remove_bin_file(struct kobject * k, struct bin_attribute * a)
162 {
163         return 0;
164 }
165
166 static inline int sysfs_create_group(struct kobject * k, const struct attribute_group *g)
167 {
168         return 0;
169 }
170
171 static inline void sysfs_remove_group(struct kobject * k, const struct attribute_group * g)
172 {
173         ;
174 }
175
176 #endif /* CONFIG_SYSFS */
177
178 #endif /* _SYSFS_H_ */