sysfs.h 5.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * sysfs.h - definitions for the device driver filesystem
 *
 * Copyright (c) 2001,2002 Patrick Mochel
 * Copyright (c) 2004 Silicon Graphics, Inc.
 *
 * Please see Documentation/filesystems/sysfs.txt for more information.
 */

#ifndef _SYSFS_H_
#define _SYSFS_H_

13
#include <linux/compiler.h>
14
#include <linux/errno.h>
15
#include <linux/list.h>
L
Linus Torvalds 已提交
16 17 18 19 20
#include <asm/atomic.h>

struct kobject;
struct module;

21 22 23 24
/* FIXME
 * The *owner field is no longer used, but leave around
 * until the tree gets cleaned up fully.
 */
L
Linus Torvalds 已提交
25
struct attribute {
T
Tejun Heo 已提交
26 27
	const char		*name;
	struct module		*owner;
L
Linus Torvalds 已提交
28 29 30 31
	mode_t			mode;
};

struct attribute_group {
T
Tejun Heo 已提交
32 33
	const char		*name;
	struct attribute	**attrs;
L
Linus Torvalds 已提交
34 35 36 37 38 39 40 41 42 43
};



/**
 * Use these macros to make defining attributes easier. See include/linux/device.h
 * for examples..
 */

#define __ATTR(_name,_mode,_show,_store) { \
44
	.attr = {.name = __stringify(_name), .mode = _mode },	\
L
Linus Torvalds 已提交
45 46 47 48 49
	.show	= _show,					\
	.store	= _store,					\
}

#define __ATTR_RO(_name) { \
50 51
	.attr	= { .name = __stringify(_name), .mode = 0444 },	\
	.show	= _name##_show,					\
L
Linus Torvalds 已提交
52 53 54 55 56 57 58 59 60 61 62 63
}

#define __ATTR_NULL { .attr = { .name = NULL } }

#define attr_name(_attr) (_attr).attr.name

struct vm_area_struct;

struct bin_attribute {
	struct attribute	attr;
	size_t			size;
	void			*private;
64 65 66 67
	ssize_t (*read)(struct kobject *, struct bin_attribute *,
			char *, loff_t, size_t);
	ssize_t (*write)(struct kobject *, struct bin_attribute *,
			 char *, loff_t, size_t);
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77 78
	int (*mmap)(struct kobject *, struct bin_attribute *attr,
		    struct vm_area_struct *vma);
};

struct sysfs_ops {
	ssize_t	(*show)(struct kobject *, struct attribute *,char *);
	ssize_t	(*store)(struct kobject *,struct attribute *,const char *, size_t);
};

#ifdef CONFIG_SYSFS

T
Tejun Heo 已提交
79 80
int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
			    void *data, struct module *owner);
L
Linus Torvalds 已提交
81

T
Tejun Heo 已提交
82 83 84 85 86
int __must_check sysfs_create_dir(struct kobject *kobj);
void sysfs_remove_dir(struct kobject *kobj);
int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
int __must_check sysfs_move_dir(struct kobject *kobj,
				struct kobject *new_parent_kobj);
87

T
Tejun Heo 已提交
88 89 90 91 92
int __must_check sysfs_create_file(struct kobject *kobj,
				   const struct attribute *attr);
int __must_check sysfs_chmod_file(struct kobject *kobj, struct attribute *attr,
				  mode_t mode);
void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
L
Linus Torvalds 已提交
93

94
int __must_check sysfs_create_bin_file(struct kobject *kobj,
T
Tejun Heo 已提交
95
				       struct bin_attribute *attr);
96
void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
L
Linus Torvalds 已提交
97

T
Tejun Heo 已提交
98 99 100 101 102 103 104 105
int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
				   const char *name);
void sysfs_remove_link(struct kobject *kobj, const char *name);

int __must_check sysfs_create_group(struct kobject *kobj,
				    const struct attribute_group *grp);
void sysfs_remove_group(struct kobject *kobj,
			const struct attribute_group *grp);
106
int sysfs_add_file_to_group(struct kobject *kobj,
T
Tejun Heo 已提交
107
			const struct attribute *attr, const char *group);
108
void sysfs_remove_file_from_group(struct kobject *kobj,
T
Tejun Heo 已提交
109
			const struct attribute *attr, const char *group);
110

T
Tejun Heo 已提交
111
void sysfs_notify(struct kobject *kobj, char *dir, char *attr);
L
Linus Torvalds 已提交
112

113 114
extern int __must_check sysfs_init(void);

L
Linus Torvalds 已提交
115 116
#else /* CONFIG_SYSFS */

117
static inline int sysfs_schedule_callback(struct kobject *kobj,
118
		void (*func)(void *), void *data, struct module *owner)
119 120 121 122
{
	return -ENOSYS;
}

T
Tejun Heo 已提交
123
static inline int sysfs_create_dir(struct kobject *kobj)
L
Linus Torvalds 已提交
124 125 126 127
{
	return 0;
}

T
Tejun Heo 已提交
128
static inline void sysfs_remove_dir(struct kobject *kobj)
L
Linus Torvalds 已提交
129 130 131 132
{
	;
}

T
Tejun Heo 已提交
133
static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
L
Linus Torvalds 已提交
134 135 136 137
{
	return 0;
}

T
Tejun Heo 已提交
138 139
static inline int sysfs_move_dir(struct kobject *kobj,
				 struct kobject *new_parent_kobj)
140 141 142 143
{
	return 0;
}

T
Tejun Heo 已提交
144 145
static inline int sysfs_create_file(struct kobject *kobj,
				    const struct attribute *attr)
L
Linus Torvalds 已提交
146 147 148 149
{
	return 0;
}

T
Tejun Heo 已提交
150 151
static inline int sysfs_chmod_file(struct kobject *kobj,
				   struct attribute *attr, mode_t mode)
152 153 154
{
	return 0;
}
L
Linus Torvalds 已提交
155

T
Tejun Heo 已提交
156 157
static inline void sysfs_remove_file(struct kobject *kobj,
				     const struct attribute *attr)
L
Linus Torvalds 已提交
158 159 160 161
{
	;
}

T
Tejun Heo 已提交
162 163
static inline int sysfs_create_bin_file(struct kobject *kobj,
					struct bin_attribute *attr)
L
Linus Torvalds 已提交
164 165 166 167
{
	return 0;
}

T
Tejun Heo 已提交
168 169
static inline int sysfs_remove_bin_file(struct kobject *kobj,
					struct bin_attribute *attr)
L
Linus Torvalds 已提交
170
{
T
Tejun Heo 已提交
171
	return 0;
L
Linus Torvalds 已提交
172 173
}

T
Tejun Heo 已提交
174 175
static inline int sysfs_create_link(struct kobject *kobj,
				    struct kobject *target, const char *name)
L
Linus Torvalds 已提交
176 177 178 179
{
	return 0;
}

T
Tejun Heo 已提交
180
static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
L
Linus Torvalds 已提交
181
{
T
Tejun Heo 已提交
182
	;
L
Linus Torvalds 已提交
183 184
}

T
Tejun Heo 已提交
185 186
static inline int sysfs_create_group(struct kobject *kobj,
				     const struct attribute_group *grp)
L
Linus Torvalds 已提交
187 188 189 190
{
	return 0;
}

T
Tejun Heo 已提交
191 192
static inline void sysfs_remove_group(struct kobject *kobj,
				      const struct attribute_group *grp)
L
Linus Torvalds 已提交
193 194 195 196
{
	;
}

197 198 199 200 201 202 203
static inline int sysfs_add_file_to_group(struct kobject *kobj,
		const struct attribute *attr, const char *group)
{
	return 0;
}

static inline void sysfs_remove_file_from_group(struct kobject *kobj,
204
		const struct attribute *attr, const char *group)
205 206 207
{
}

T
Tejun Heo 已提交
208
static inline void sysfs_notify(struct kobject *kobj, char *dir, char *attr)
209 210 211
{
}

212 213 214 215 216
static inline int __must_check sysfs_init(void)
{
	return 0;
}

L
Linus Torvalds 已提交
217 218 219
#endif /* CONFIG_SYSFS */

#endif /* _SYSFS_H_ */