blob: 7d5d1ec95c2e4b8dc719c042cc6a178550be3f09 [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23struct attribute {
Dmitry Torokhovd48593b2005-04-29 00:58:46 -050024 const char * name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 struct module * owner;
26 mode_t mode;
27};
28
29struct attribute_group {
Dmitry Torokhovd48593b2005-04-29 00:58:46 -050030 const char * name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 struct attribute ** attrs;
32};
33
34
35
36/**
37 * Use these macros to make defining attributes easier. See include/linux/device.h
38 * for examples..
39 */
40
41#define __ATTR(_name,_mode,_show,_store) { \
42 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
43 .show = _show, \
44 .store = _store, \
45}
46
47#define __ATTR_RO(_name) { \
48 .attr = { .name = __stringify(_name), .mode = 0444, .owner = THIS_MODULE }, \
49 .show = _name##_show, \
50}
51
52#define __ATTR_NULL { .attr = { .name = NULL } }
53
54#define attr_name(_attr) (_attr).attr.name
55
56struct vm_area_struct;
57
58struct bin_attribute {
59 struct attribute attr;
60 size_t size;
61 void *private;
62 ssize_t (*read)(struct kobject *, char *, loff_t, size_t);
63 ssize_t (*write)(struct kobject *, char *, loff_t, size_t);
64 int (*mmap)(struct kobject *, struct bin_attribute *attr,
65 struct vm_area_struct *vma);
66};
67
68struct sysfs_ops {
69 ssize_t (*show)(struct kobject *, struct attribute *,char *);
70 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
71};
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#define SYSFS_ROOT 0x0001
74#define SYSFS_DIR 0x0002
75#define SYSFS_KOBJ_ATTR 0x0004
76#define SYSFS_KOBJ_BIN_ATTR 0x0008
77#define SYSFS_KOBJ_LINK 0x0020
78#define SYSFS_NOT_PINNED (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK)
79
80#ifdef CONFIG_SYSFS
81
Alan Sternd9a9cdf2007-03-15 15:50:34 -040082extern int sysfs_schedule_callback(struct kobject *kobj,
Alan Stern523ded72007-04-26 00:12:04 -070083 void (*func)(void *), void *data, struct module *owner);
Alan Sternd9a9cdf2007-03-15 15:50:34 -040084
Andrew Morton4a7fb632006-08-14 22:43:17 -070085extern int __must_check
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -070086sysfs_create_dir(struct kobject *, struct dentry *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88extern void
89sysfs_remove_dir(struct kobject *);
90
Andrew Morton4a7fb632006-08-14 22:43:17 -070091extern int __must_check
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -070092sysfs_rename_dir(struct kobject *, struct dentry *, const char *new_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Andrew Morton4a7fb632006-08-14 22:43:17 -070094extern int __must_check
Cornelia Huck8a824722006-11-20 17:07:51 +010095sysfs_move_dir(struct kobject *, struct kobject *);
96
97extern int __must_check
Linus Torvalds1da177e2005-04-16 15:20:36 -070098sysfs_create_file(struct kobject *, const struct attribute *);
99
Andrew Morton4a7fb632006-08-14 22:43:17 -0700100extern int __must_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101sysfs_update_file(struct kobject *, const struct attribute *);
102
Andrew Morton4a7fb632006-08-14 22:43:17 -0700103extern int __must_check
Kay Sievers31e5abe2005-04-18 21:57:32 -0700104sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode);
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern void
107sysfs_remove_file(struct kobject *, const struct attribute *);
108
Andrew Morton4a7fb632006-08-14 22:43:17 -0700109extern int __must_check
Dmitry Torokhove3a15db2005-04-26 02:31:08 -0500110sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112extern void
Dmitry Torokhove3a15db2005-04-26 02:31:08 -0500113sysfs_remove_link(struct kobject *, const char * name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Andrew Morton4a7fb632006-08-14 22:43:17 -0700115int __must_check sysfs_create_bin_file(struct kobject *kobj,
116 struct bin_attribute *attr);
Randy.Dunlap995982c2006-07-10 23:05:25 -0700117void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Andrew Morton4a7fb632006-08-14 22:43:17 -0700119int __must_check sysfs_create_group(struct kobject *,
120 const struct attribute_group *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121void sysfs_remove_group(struct kobject *, const struct attribute_group *);
Alan Sterndfa87c82007-02-20 15:02:44 -0500122int sysfs_add_file_to_group(struct kobject *kobj,
123 const struct attribute *attr, const char *group);
124void sysfs_remove_file_from_group(struct kobject *kobj,
125 const struct attribute *attr, const char *group);
126
NeilBrown4508a7a2006-03-20 17:53:53 +1100127void sysfs_notify(struct kobject * k, char *dir, char *attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700129
130extern int sysfs_make_shadowed_dir(struct kobject *kobj,
131 void * (*follow_link)(struct dentry *, struct nameidata *));
132extern struct dentry *sysfs_create_shadow_dir(struct kobject *kobj);
133extern void sysfs_remove_shadow_dir(struct dentry *dir);
134
Andrew Mortonf20a9ea2006-08-14 22:43:23 -0700135extern int __must_check sysfs_init(void);
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#else /* CONFIG_SYSFS */
138
Alan Sternd9a9cdf2007-03-15 15:50:34 -0400139static inline int sysfs_schedule_callback(struct kobject *kobj,
Alan Stern523ded72007-04-26 00:12:04 -0700140 void (*func)(void *), void *data, struct module *owner)
Alan Sternd9a9cdf2007-03-15 15:50:34 -0400141{
142 return -ENOSYS;
143}
144
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700145static inline int sysfs_create_dir(struct kobject * k, struct dentry *shadow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
147 return 0;
148}
149
150static inline void sysfs_remove_dir(struct kobject * k)
151{
152 ;
153}
154
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700155static inline int sysfs_rename_dir(struct kobject * k,
156 struct dentry *new_parent,
157 const char *new_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 return 0;
160}
161
Cornelia Huck8a824722006-11-20 17:07:51 +0100162static inline int sysfs_move_dir(struct kobject * k, struct kobject * new_parent)
163{
164 return 0;
165}
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167static inline int sysfs_create_file(struct kobject * k, const struct attribute * a)
168{
169 return 0;
170}
171
172static inline int sysfs_update_file(struct kobject * k, const struct attribute * a)
173{
174 return 0;
175}
Kay Sievers31e5abe2005-04-18 21:57:32 -0700176static inline int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
177{
178 return 0;
179}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181static inline void sysfs_remove_file(struct kobject * k, const struct attribute * a)
182{
183 ;
184}
185
Dmitry Torokhove3a15db2005-04-26 02:31:08 -0500186static inline int sysfs_create_link(struct kobject * k, struct kobject * t, const char * n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 return 0;
189}
190
Dmitry Torokhove3a15db2005-04-26 02:31:08 -0500191static inline void sysfs_remove_link(struct kobject * k, const char * name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 ;
194}
195
196
197static inline int sysfs_create_bin_file(struct kobject * k, struct bin_attribute * a)
198{
199 return 0;
200}
201
202static inline int sysfs_remove_bin_file(struct kobject * k, struct bin_attribute * a)
203{
204 return 0;
205}
206
207static inline int sysfs_create_group(struct kobject * k, const struct attribute_group *g)
208{
209 return 0;
210}
211
212static inline void sysfs_remove_group(struct kobject * k, const struct attribute_group * g)
213{
214 ;
215}
216
Alan Sterndfa87c82007-02-20 15:02:44 -0500217static inline int sysfs_add_file_to_group(struct kobject *kobj,
218 const struct attribute *attr, const char *group)
219{
220 return 0;
221}
222
223static inline void sysfs_remove_file_from_group(struct kobject *kobj,
Ralf Baechled701d8a2007-03-01 12:40:21 +0000224 const struct attribute *attr, const char *group)
Alan Sterndfa87c82007-02-20 15:02:44 -0500225{
Alan Sterndfa87c82007-02-20 15:02:44 -0500226}
227
NeilBrown4508a7a2006-03-20 17:53:53 +1100228static inline void sysfs_notify(struct kobject * k, char *dir, char *attr)
229{
230}
231
Eric W. Biedermanb592fcf2007-01-24 12:35:52 -0700232static inline int sysfs_make_shadowed_dir(struct kobject *kobj,
233 void * (*follow_link)(struct dentry *, struct nameidata *))
234{
235 return 0;
236}
237
Andrew Mortonf20a9ea2006-08-14 22:43:23 -0700238static inline int __must_check sysfs_init(void)
239{
240 return 0;
241}
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#endif /* CONFIG_SYSFS */
244
245#endif /* _SYSFS_H_ */