blob: 4c43030fae5d7ea2bccc6f941b7dda325095c6f8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysfs.h - definitions for the device driver filesystem
3 *
4 * Copyright (c) 2001,2002 Patrick Mochel
5 * Copyright (c) 2004 Silicon Graphics, Inc.
6 *
7 * Please see Documentation/filesystems/sysfs.txt for more information.
8 */
9
10#ifndef _SYSFS_H_
11#define _SYSFS_H_
12
Andrew Morton4a7fb632006-08-14 22:43:17 -070013#include <linux/compiler.h>
Ralf Baechle5851fad2007-03-18 12:58:08 +000014#include <linux/errno.h>
Frank Haverkampbf0acc32007-01-17 17:51:18 +010015#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/atomic.h>
17
18struct kobject;
19struct module;
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -070020struct nameidata;
Adam J. Richterd56c3ea2007-02-16 21:35:25 +080021struct dentry;
Tejun Heo608e2662007-06-14 04:27:22 +090022struct sysfs_dirent;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Tejun Heo7b595752007-06-14 03:45:17 +090024/* FIXME
25 * The *owner field is no longer used, but leave around
26 * until the tree gets cleaned up fully.
27 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028struct attribute {
Dmitry Torokhovd48593b2005-04-29 00:58:46 -050029 const char * name;
Tejun Heo7b595752007-06-14 03:45:17 +090030 struct module * owner;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 mode_t mode;
32};
33
34struct attribute_group {
Dmitry Torokhovd48593b2005-04-29 00:58:46 -050035 const char * name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 struct attribute ** attrs;
37};
38
39
40
41/**
42 * Use these macros to make defining attributes easier. See include/linux/device.h
43 * for examples..
44 */
45
46#define __ATTR(_name,_mode,_show,_store) { \
Tejun Heo7b595752007-06-14 03:45:17 +090047 .attr = {.name = __stringify(_name), .mode = _mode }, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 .show = _show, \
49 .store = _store, \
50}
51
52#define __ATTR_RO(_name) { \
Tejun Heo7b595752007-06-14 03:45:17 +090053 .attr = { .name = __stringify(_name), .mode = 0444 }, \
54 .show = _name##_show, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
57#define __ATTR_NULL { .attr = { .name = NULL } }
58
59#define attr_name(_attr) (_attr).attr.name
60
61struct vm_area_struct;
62
63struct bin_attribute {
64 struct attribute attr;
65 size_t size;
66 void *private;
67 ssize_t (*read)(struct kobject *, char *, loff_t, size_t);
68 ssize_t (*write)(struct kobject *, char *, loff_t, size_t);
69 int (*mmap)(struct kobject *, struct bin_attribute *attr,
70 struct vm_area_struct *vma);
71};
72
73struct sysfs_ops {
74 ssize_t (*show)(struct kobject *, struct attribute *,char *);
75 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
76};
77
Tejun Heob402d722007-06-14 04:27:21 +090078#define SYSFS_TYPE_MASK 0x00ff
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#define SYSFS_ROOT 0x0001
80#define SYSFS_DIR 0x0002
81#define SYSFS_KOBJ_ATTR 0x0004
82#define SYSFS_KOBJ_BIN_ATTR 0x0008
83#define SYSFS_KOBJ_LINK 0x0020
84#define SYSFS_NOT_PINNED (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK)
Tejun Heo0c096b52007-06-14 03:45:15 +090085#define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Tejun Heob402d722007-06-14 04:27:21 +090087#define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
Tejun Heo380e6fb2007-06-14 04:27:22 +090088#define SYSFS_FLAG_REMOVED 0x0100
Tejun Heob402d722007-06-14 04:27:21 +090089
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#ifdef CONFIG_SYSFS
91
Alan Sternd9a9cdf2007-03-15 15:50:34 -040092extern int sysfs_schedule_callback(struct kobject *kobj,
Alan Stern523ded72007-04-26 00:12:04 -070093 void (*func)(void *), void *data, struct module *owner);
Alan Sternd9a9cdf2007-03-15 15:50:34 -040094
Andrew Morton4a7fb632006-08-14 22:43:17 -070095extern int __must_check
Tejun Heo608e2662007-06-14 04:27:22 +090096sysfs_create_dir(struct kobject *kobj, struct sysfs_dirent *shadow_parent_sd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98extern void
99sysfs_remove_dir(struct kobject *);
100
Andrew Morton4a7fb632006-08-14 22:43:17 -0700101extern int __must_check
Tejun Heo608e2662007-06-14 04:27:22 +0900102sysfs_rename_dir(struct kobject *kobj, struct sysfs_dirent *new_parent_sd,
103 const char *new_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Andrew Morton4a7fb632006-08-14 22:43:17 -0700105extern int __must_check
Cornelia Huck8a824722006-11-20 17:07:51 +0100106sysfs_move_dir(struct kobject *, struct kobject *);
107
108extern int __must_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109sysfs_create_file(struct kobject *, const struct attribute *);
110
Andrew Morton4a7fb632006-08-14 22:43:17 -0700111extern int __must_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112sysfs_update_file(struct kobject *, const struct attribute *);
113
Andrew Morton4a7fb632006-08-14 22:43:17 -0700114extern int __must_check
Kay Sievers31e5abe2005-04-18 21:57:32 -0700115sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode);
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117extern void
118sysfs_remove_file(struct kobject *, const struct attribute *);
119
Andrew Morton4a7fb632006-08-14 22:43:17 -0700120extern int __must_check
Dmitry Torokhove3a15db2005-04-26 02:31:08 -0500121sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123extern void
Dmitry Torokhove3a15db2005-04-26 02:31:08 -0500124sysfs_remove_link(struct kobject *, const char * name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Andrew Morton4a7fb632006-08-14 22:43:17 -0700126int __must_check sysfs_create_bin_file(struct kobject *kobj,
127 struct bin_attribute *attr);
Randy.Dunlap995982c2006-07-10 23:05:25 -0700128void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Andrew Morton4a7fb632006-08-14 22:43:17 -0700130int __must_check sysfs_create_group(struct kobject *,
131 const struct attribute_group *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132void sysfs_remove_group(struct kobject *, const struct attribute_group *);
Alan Sterndfa87c82007-02-20 15:02:44 -0500133int sysfs_add_file_to_group(struct kobject *kobj,
134 const struct attribute *attr, const char *group);
135void sysfs_remove_file_from_group(struct kobject *kobj,
136 const struct attribute *attr, const char *group);
137
NeilBrown4508a7a2006-03-20 17:53:53 +1100138void sysfs_notify(struct kobject * k, char *dir, char *attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700140
141extern int sysfs_make_shadowed_dir(struct kobject *kobj,
142 void * (*follow_link)(struct dentry *, struct nameidata *));
Tejun Heo608e2662007-06-14 04:27:22 +0900143extern struct sysfs_dirent *sysfs_create_shadow_dir(struct kobject *kobj);
144extern void sysfs_remove_shadow_dir(struct sysfs_dirent *shadow_sd);
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700145
Andrew Mortonf20a9ea2006-08-14 22:43:23 -0700146extern int __must_check sysfs_init(void);
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#else /* CONFIG_SYSFS */
149
Alan Sternd9a9cdf2007-03-15 15:50:34 -0400150static inline int sysfs_schedule_callback(struct kobject *kobj,
Alan Stern523ded72007-04-26 00:12:04 -0700151 void (*func)(void *), void *data, struct module *owner)
Alan Sternd9a9cdf2007-03-15 15:50:34 -0400152{
153 return -ENOSYS;
154}
155
Tejun Heo608e2662007-06-14 04:27:22 +0900156static inline int sysfs_create_dir(struct kobject *kobj,
157 struct sysfs_dirent *shadow_parent_sd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 return 0;
160}
161
162static inline void sysfs_remove_dir(struct kobject * k)
163{
164 ;
165}
166
Tejun Heo608e2662007-06-14 04:27:22 +0900167static inline int sysfs_rename_dir(struct kobject *kobj,
168 struct sysfs_dirent *new_parent_sd,
169 const char *new_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
171 return 0;
172}
173
Cornelia Huck8a824722006-11-20 17:07:51 +0100174static inline int sysfs_move_dir(struct kobject * k, struct kobject * new_parent)
175{
176 return 0;
177}
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static inline int sysfs_create_file(struct kobject * k, const struct attribute * a)
180{
181 return 0;
182}
183
184static inline int sysfs_update_file(struct kobject * k, const struct attribute * a)
185{
186 return 0;
187}
Kay Sievers31e5abe2005-04-18 21:57:32 -0700188static inline int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
189{
190 return 0;
191}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193static inline void sysfs_remove_file(struct kobject * k, const struct attribute * a)
194{
195 ;
196}
197
Dmitry Torokhove3a15db2005-04-26 02:31:08 -0500198static inline int sysfs_create_link(struct kobject * k, struct kobject * t, const char * n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
200 return 0;
201}
202
Dmitry Torokhove3a15db2005-04-26 02:31:08 -0500203static inline void sysfs_remove_link(struct kobject * k, const char * name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
205 ;
206}
207
208
209static inline int sysfs_create_bin_file(struct kobject * k, struct bin_attribute * a)
210{
211 return 0;
212}
213
214static inline int sysfs_remove_bin_file(struct kobject * k, struct bin_attribute * a)
215{
216 return 0;
217}
218
219static inline int sysfs_create_group(struct kobject * k, const struct attribute_group *g)
220{
221 return 0;
222}
223
224static inline void sysfs_remove_group(struct kobject * k, const struct attribute_group * g)
225{
226 ;
227}
228
Alan Sterndfa87c82007-02-20 15:02:44 -0500229static inline int sysfs_add_file_to_group(struct kobject *kobj,
230 const struct attribute *attr, const char *group)
231{
232 return 0;
233}
234
235static inline void sysfs_remove_file_from_group(struct kobject *kobj,
Ralf Baechled701d8a2007-03-01 12:40:21 +0000236 const struct attribute *attr, const char *group)
Alan Sterndfa87c82007-02-20 15:02:44 -0500237{
Alan Sterndfa87c82007-02-20 15:02:44 -0500238}
239
NeilBrown4508a7a2006-03-20 17:53:53 +1100240static inline void sysfs_notify(struct kobject * k, char *dir, char *attr)
241{
242}
243
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700244static inline int sysfs_make_shadowed_dir(struct kobject *kobj,
245 void * (*follow_link)(struct dentry *, struct nameidata *))
246{
247 return 0;
248}
249
Andrew Mortonf20a9ea2006-08-14 22:43:23 -0700250static inline int __must_check sysfs_init(void)
251{
252 return 0;
253}
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#endif /* CONFIG_SYSFS */
256
257#endif /* _SYSFS_H_ */