Blame view

fs/sysfs/file.c 19.3 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
6d66f5cd2   Tejun Heo   sysfs: add copyri...
2
3
4
5
6
7
8
9
10
   * fs/sysfs/file.c - sysfs regular (text) file implementation
   *
   * Copyright (c) 2001-3 Patrick Mochel
   * Copyright (c) 2007 SUSE Linux Products GmbH
   * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
   *
   * This file is released under the GPLv2.
   *
   * Please see Documentation/filesystems/sysfs.txt for more information.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
   */
  
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
  #include <linux/kobject.h>
815d2d50d   Andrew Morton   driver core: debu...
15
  #include <linux/kallsyms.h>
c6f877338   Robert P. J. Day   SYSFS: Explicitly...
16
  #include <linux/slab.h>
93265d13e   Miklos Szeredi   sysfs: don't call...
17
  #include <linux/fsnotify.h>
5f45f1a78   Christoph Hellwig   [PATCH] remove du...
18
  #include <linux/namei.h>
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
19
  #include <linux/poll.h>
94bebf4d1   Oliver Neukum   Driver core: fix ...
20
  #include <linux/list.h>
52e8c209d   Dave Young   sysfs/file.c - us...
21
  #include <linux/mutex.h>
ae87221d3   Andrew Morton   sysfs: crash debu...
22
  #include <linux/limits.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
  #include <asm/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
  
  #include "sysfs.h"
ae87221d3   Andrew Morton   sysfs: crash debu...
26
27
28
29
30
31
32
  /* used in crash dumps to help with debugging */
  static char last_sysfs_file[PATH_MAX];
  void sysfs_printk_last_file(void)
  {
  	printk(KERN_EMERG "last sysfs file: %s
  ", last_sysfs_file);
  }
85a4ffad3   Tejun Heo   sysfs: implement ...
33
34
35
36
37
38
39
40
41
  /*
   * There's one sysfs_buffer for each open file and one
   * sysfs_open_dirent for each sysfs_dirent with one or more open
   * files.
   *
   * filp->private_data points to sysfs_buffer and
   * sysfs_dirent->s_attr.open points to sysfs_open_dirent.  s_attr.open
   * is protected by sysfs_open_dirent_lock.
   */
d7b378896   Jiri Slaby   sysfs: remove SPI...
42
  static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
85a4ffad3   Tejun Heo   sysfs: implement ...
43
44
45
  
  struct sysfs_open_dirent {
  	atomic_t		refcnt;
a4e8b9125   Tejun Heo   sysfs: move sysfs...
46
47
  	atomic_t		event;
  	wait_queue_head_t	poll;
85a4ffad3   Tejun Heo   sysfs: implement ...
48
49
  	struct list_head	buffers; /* goes through sysfs_buffer.list */
  };
73107cb3a   Tejun Heo   sysfs: kill attri...
50
51
52
53
  struct sysfs_buffer {
  	size_t			count;
  	loff_t			pos;
  	char			* page;
52cf25d0a   Emese Revfy   Driver core: Cons...
54
  	const struct sysfs_ops	* ops;
52e8c209d   Dave Young   sysfs/file.c - us...
55
  	struct mutex		mutex;
73107cb3a   Tejun Heo   sysfs: kill attri...
56
57
  	int			needs_read_fill;
  	int			event;
85a4ffad3   Tejun Heo   sysfs: implement ...
58
  	struct list_head	list;
73107cb3a   Tejun Heo   sysfs: kill attri...
59
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
61
62
63
64
65
66
67
68
  
  /**
   *	fill_read_buffer - allocate and fill buffer from object.
   *	@dentry:	dentry pointer.
   *	@buffer:	data buffer for file.
   *
   *	Allocate @buffer->page, if it hasn't been already, then call the
   *	kobject's show() method to fill the buffer with this attribute's 
   *	data. 
82244b169   Oliver Neukum   sysfs: error hand...
69
70
   *	This is called only once, on the file's first read unless an error
   *	is returned.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
73
   */
  static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer)
  {
0ab66088c   Tejun Heo   sysfs: implement ...
74
  	struct sysfs_dirent *attr_sd = dentry->d_fsdata;
b1fc3d614   Tejun Heo   sysfs: make s_ele...
75
  	struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
52cf25d0a   Emese Revfy   Driver core: Cons...
76
  	const struct sysfs_ops * ops = buffer->ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
78
79
80
81
82
83
  	int ret = 0;
  	ssize_t count;
  
  	if (!buffer->page)
  		buffer->page = (char *) get_zeroed_page(GFP_KERNEL);
  	if (!buffer->page)
  		return -ENOMEM;
0ab66088c   Tejun Heo   sysfs: implement ...
84
  	/* need attr_sd for attr and ops, its parent for kobj */
e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
85
  	if (!sysfs_get_active(attr_sd))
0ab66088c   Tejun Heo   sysfs: implement ...
86
  		return -ENODEV;
a4e8b9125   Tejun Heo   sysfs: move sysfs...
87
  	buffer->event = atomic_read(&attr_sd->s_attr.open->event);
b1fc3d614   Tejun Heo   sysfs: make s_ele...
88
  	count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
0ab66088c   Tejun Heo   sysfs: implement ...
89

e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
90
  	sysfs_put_active(attr_sd);
0ab66088c   Tejun Heo   sysfs: implement ...
91

8118a859d   Miao Xie   sysfs: fix off-by...
92
93
94
95
  	/*
  	 * The code works fine with PAGE_SIZE return but it's likely to
  	 * indicate truncated result or overflow in normal use cases.
  	 */
815d2d50d   Andrew Morton   driver core: debu...
96
97
98
99
100
101
102
  	if (count >= (ssize_t)PAGE_SIZE) {
  		print_symbol("fill_read_buffer: %s returned bad count
  ",
  			(unsigned long)ops->show);
  		/* Try to struggle along */
  		count = PAGE_SIZE - 1;
  	}
82244b169   Oliver Neukum   sysfs: error hand...
103
104
  	if (count >= 0) {
  		buffer->needs_read_fill = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
  		buffer->count = count;
82244b169   Oliver Neukum   sysfs: error hand...
106
  	} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
  		ret = count;
82244b169   Oliver Neukum   sysfs: error hand...
108
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
  	return ret;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  /**
   *	sysfs_read_file - read an attribute. 
   *	@file:	file pointer.
   *	@buf:	buffer to fill.
   *	@count:	number of bytes to read.
   *	@ppos:	starting offset in file.
   *
   *	Userspace wants to read an attribute file. The attribute descriptor
   *	is in the file's ->d_fsdata. The target object is in the directory's
   *	->d_fsdata.
   *
   *	We call fill_read_buffer() to allocate and fill the buffer from the
   *	object's show() method exactly once (if the read is happening from
   *	the beginning of the file). That should fill the entire buffer with
   *	all the data the object has to offer for that attribute.
   *	We then call flush_read_buffer() to copy the buffer to userspace
   *	in the increments specified.
   */
  
  static ssize_t
  sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  {
  	struct sysfs_buffer * buffer = file->private_data;
  	ssize_t retval = 0;
52e8c209d   Dave Young   sysfs/file.c - us...
135
  	mutex_lock(&buffer->mutex);
2424b5dd0   Dan Williams   sysfs: refill att...
136
  	if (buffer->needs_read_fill || *ppos == 0) {
73107cb3a   Tejun Heo   sysfs: kill attri...
137
  		retval = fill_read_buffer(file->f_path.dentry,buffer);
e7b0d26a8   Alan Stern   [PATCH] sysfs: re...
138
  		if (retval)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139
140
  			goto out;
  	}
5c1fdf415   Zach Brown   [PATCH] pr_debug:...
141
142
  	pr_debug("%s: count = %zd, ppos = %lld, buf = %s
  ",
8e24eea72   Harvey Harrison   fs: replace remai...
143
  		 __func__, count, *ppos, buffer->page);
92f4c701a   Akinobu Mita   use simple_read_f...
144
145
  	retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
  					 buffer->count);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146
  out:
52e8c209d   Dave Young   sysfs/file.c - us...
147
  	mutex_unlock(&buffer->mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
149
  	return retval;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
151
152
  /**
   *	fill_write_buffer - copy buffer from userspace.
   *	@buffer:	data buffer for file.
67be2dd1b   Martin Waitz   [PATCH] DocBook: ...
153
   *	@buf:		data from user.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
   *	@count:		number of bytes in @userbuf.
   *
   *	Allocate @buffer->page if it hasn't been already, then
   *	copy the user-supplied buffer into it.
   */
  
  static int 
  fill_write_buffer(struct sysfs_buffer * buffer, const char __user * buf, size_t count)
  {
  	int error;
  
  	if (!buffer->page)
  		buffer->page = (char *)get_zeroed_page(GFP_KERNEL);
  	if (!buffer->page)
  		return -ENOMEM;
  
  	if (count >= PAGE_SIZE)
6e0dd741a   Greg Kroah-Hartman   [PATCH] sysfs: ze...
171
  		count = PAGE_SIZE - 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172
173
  	error = copy_from_user(buffer->page,buf,count);
  	buffer->needs_read_fill = 1;
035ed7a49   Thomas Maier   sysfs: sysfs_writ...
174
175
176
  	/* if buf is assumed to contain a string, terminate it by \0,
  	   so e.g. sscanf() can scan the string easily */
  	buffer->page[count] = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
178
179
180
181
182
  	return error ? -EFAULT : count;
  }
  
  
  /**
   *	flush_write_buffer - push buffer to kobject.
3d41088fa   Martin Waitz   [PATCH] DocBook: ...
183
   *	@dentry:	dentry to the attribute
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
   *	@buffer:	data buffer for file.
3d41088fa   Martin Waitz   [PATCH] DocBook: ...
185
   *	@count:		number of bytes
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
187
188
189
190
   *
   *	Get the correct pointers for the kobject and the attribute we're
   *	dealing with, then call the store() method for the attribute, 
   *	passing the buffer that we acquired in fill_write_buffer().
   */
0ab66088c   Tejun Heo   sysfs: implement ...
191
  static int
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
192
193
  flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t count)
  {
3e5190380   Tejun Heo   sysfs: make sysfs...
194
  	struct sysfs_dirent *attr_sd = dentry->d_fsdata;
b1fc3d614   Tejun Heo   sysfs: make s_ele...
195
  	struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
52cf25d0a   Emese Revfy   Driver core: Cons...
196
  	const struct sysfs_ops * ops = buffer->ops;
0ab66088c   Tejun Heo   sysfs: implement ...
197
198
199
  	int rc;
  
  	/* need attr_sd for attr and ops, its parent for kobj */
e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
200
  	if (!sysfs_get_active(attr_sd))
0ab66088c   Tejun Heo   sysfs: implement ...
201
  		return -ENODEV;
b1fc3d614   Tejun Heo   sysfs: make s_ele...
202
  	rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);
0ab66088c   Tejun Heo   sysfs: implement ...
203

e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
204
  	sysfs_put_active(attr_sd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205

0ab66088c   Tejun Heo   sysfs: implement ...
206
  	return rc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  }
  
  
  /**
   *	sysfs_write_file - write an attribute.
   *	@file:	file pointer
   *	@buf:	data to write
   *	@count:	number of bytes
   *	@ppos:	starting offset
   *
   *	Similar to sysfs_read_file(), though working in the opposite direction.
   *	We allocate and fill the data from the user in fill_write_buffer(),
   *	then push it to the kobject in flush_write_buffer().
   *	There is no easy way for us to know if userspace is only doing a partial
   *	write, so we don't support them. We expect the entire buffer to come
   *	on the first write. 
   *	Hint: if you're writing a value, first read the file, modify only the
   *	the value you're changing, then write entire buffer back. 
   */
  
  static ssize_t
  sysfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
  {
  	struct sysfs_buffer * buffer = file->private_data;
  	ssize_t len;
52e8c209d   Dave Young   sysfs/file.c - us...
232
  	mutex_lock(&buffer->mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
  	len = fill_write_buffer(buffer, buf, count);
  	if (len > 0)
f427f5d5d   Josef "Jeff" Sipek   [PATCH] sysfs: ch...
235
  		len = flush_write_buffer(file->f_path.dentry, buffer, len);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
236
237
  	if (len > 0)
  		*ppos += len;
52e8c209d   Dave Young   sysfs/file.c - us...
238
  	mutex_unlock(&buffer->mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
240
  	return len;
  }
85a4ffad3   Tejun Heo   sysfs: implement ...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
  /**
   *	sysfs_get_open_dirent - get or create sysfs_open_dirent
   *	@sd: target sysfs_dirent
   *	@buffer: sysfs_buffer for this instance of open
   *
   *	If @sd->s_attr.open exists, increment its reference count;
   *	otherwise, create one.  @buffer is chained to the buffers
   *	list.
   *
   *	LOCKING:
   *	Kernel thread context (may sleep).
   *
   *	RETURNS:
   *	0 on success, -errno on failure.
   */
  static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
  				 struct sysfs_buffer *buffer)
  {
  	struct sysfs_open_dirent *od, *new_od = NULL;
  
   retry:
83db93f4d   Neil Brown   sysfs: Allow sysf...
262
  	spin_lock_irq(&sysfs_open_dirent_lock);
85a4ffad3   Tejun Heo   sysfs: implement ...
263
264
265
266
267
268
269
270
271
272
273
  
  	if (!sd->s_attr.open && new_od) {
  		sd->s_attr.open = new_od;
  		new_od = NULL;
  	}
  
  	od = sd->s_attr.open;
  	if (od) {
  		atomic_inc(&od->refcnt);
  		list_add_tail(&buffer->list, &od->buffers);
  	}
83db93f4d   Neil Brown   sysfs: Allow sysf...
274
  	spin_unlock_irq(&sysfs_open_dirent_lock);
85a4ffad3   Tejun Heo   sysfs: implement ...
275
276
277
278
279
280
281
282
283
284
285
286
  
  	if (od) {
  		kfree(new_od);
  		return 0;
  	}
  
  	/* not there, initialize a new one and retry */
  	new_od = kmalloc(sizeof(*new_od), GFP_KERNEL);
  	if (!new_od)
  		return -ENOMEM;
  
  	atomic_set(&new_od->refcnt, 0);
a4e8b9125   Tejun Heo   sysfs: move sysfs...
287
288
  	atomic_set(&new_od->event, 1);
  	init_waitqueue_head(&new_od->poll);
85a4ffad3   Tejun Heo   sysfs: implement ...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
  	INIT_LIST_HEAD(&new_od->buffers);
  	goto retry;
  }
  
  /**
   *	sysfs_put_open_dirent - put sysfs_open_dirent
   *	@sd: target sysfs_dirent
   *	@buffer: associated sysfs_buffer
   *
   *	Put @sd->s_attr.open and unlink @buffer from the buffers list.
   *	If reference count reaches zero, disassociate and free it.
   *
   *	LOCKING:
   *	None.
   */
  static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
  				  struct sysfs_buffer *buffer)
  {
  	struct sysfs_open_dirent *od = sd->s_attr.open;
83db93f4d   Neil Brown   sysfs: Allow sysf...
308
  	unsigned long flags;
85a4ffad3   Tejun Heo   sysfs: implement ...
309

83db93f4d   Neil Brown   sysfs: Allow sysf...
310
  	spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
85a4ffad3   Tejun Heo   sysfs: implement ...
311
312
313
314
315
316
  
  	list_del(&buffer->list);
  	if (atomic_dec_and_test(&od->refcnt))
  		sd->s_attr.open = NULL;
  	else
  		od = NULL;
83db93f4d   Neil Brown   sysfs: Allow sysf...
317
  	spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
85a4ffad3   Tejun Heo   sysfs: implement ...
318
319
320
  
  	kfree(od);
  }
94bebf4d1   Oliver Neukum   Driver core: fix ...
321
  static int sysfs_open_file(struct inode *inode, struct file *file)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322
  {
3e5190380   Tejun Heo   sysfs: make sysfs...
323
  	struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
b1fc3d614   Tejun Heo   sysfs: make s_ele...
324
  	struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
000f2a4d8   Kay Sievers   Driver Core: kill...
325
  	struct sysfs_buffer *buffer;
52cf25d0a   Emese Revfy   Driver core: Cons...
326
  	const struct sysfs_ops *ops;
000f2a4d8   Kay Sievers   Driver Core: kill...
327
  	int error = -EACCES;
ae87221d3   Andrew Morton   sysfs: crash debu...
328
329
330
  	char *p;
  
  	p = d_path(&file->f_path, last_sysfs_file, sizeof(last_sysfs_file));
57f9bdac2   Dan Carpenter   sysfs: checking f...
331
  	if (!IS_ERR(p))
ae87221d3   Andrew Morton   sysfs: crash debu...
332
  		memmove(last_sysfs_file, p, strlen(p) + 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
333

0ab66088c   Tejun Heo   sysfs: implement ...
334
  	/* need attr_sd for attr and ops, its parent for kobj */
e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
335
  	if (!sysfs_get_active(attr_sd))
0ab66088c   Tejun Heo   sysfs: implement ...
336
  		return -ENODEV;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
337

000f2a4d8   Kay Sievers   Driver Core: kill...
338
339
  	/* every kobject with an attribute needs a ktype assigned */
  	if (kobj->ktype && kobj->ktype->sysfs_ops)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340
  		ops = kobj->ktype->sysfs_ops;
000f2a4d8   Kay Sievers   Driver Core: kill...
341
  	else {
99fcd77d1   Arjan van de Ven   Use WARN() in fs/...
342
  		WARN(1, KERN_ERR "missing sysfs attribute operations for "
000f2a4d8   Kay Sievers   Driver Core: kill...
343
344
  		       "kobject: %s
  ", kobject_name(kobj));
7b595756e   Tejun Heo   sysfs: kill unnec...
345
  		goto err_out;
000f2a4d8   Kay Sievers   Driver Core: kill...
346
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
348
349
350
351
352
  
  	/* File needs write support.
  	 * The inode's perms must say it's ok, 
  	 * and we must have a store method.
  	 */
  	if (file->f_mode & FMODE_WRITE) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353
  		if (!(inode->i_mode & S_IWUGO) || !ops->store)
7b595756e   Tejun Heo   sysfs: kill unnec...
354
  			goto err_out;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355
356
357
358
359
360
361
362
  	}
  
  	/* File needs read support.
  	 * The inode's perms must say it's ok, and we there
  	 * must be a show method for it.
  	 */
  	if (file->f_mode & FMODE_READ) {
  		if (!(inode->i_mode & S_IRUGO) || !ops->show)
7b595756e   Tejun Heo   sysfs: kill unnec...
363
  			goto err_out;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364
365
366
367
368
  	}
  
  	/* No error? Great, allocate a buffer for the file, and store it
  	 * it in file->private_data for easy access.
  	 */
0ab66088c   Tejun Heo   sysfs: implement ...
369
  	error = -ENOMEM;
58d49283b   Eric Sesterhenn   [PATCH] sysfs: kz...
370
  	buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL);
0ab66088c   Tejun Heo   sysfs: implement ...
371
  	if (!buffer)
7b595756e   Tejun Heo   sysfs: kill unnec...
372
  		goto err_out;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373

52e8c209d   Dave Young   sysfs/file.c - us...
374
  	mutex_init(&buffer->mutex);
0ab66088c   Tejun Heo   sysfs: implement ...
375
376
  	buffer->needs_read_fill = 1;
  	buffer->ops = ops;
0ab66088c   Tejun Heo   sysfs: implement ...
377
  	file->private_data = buffer;
85a4ffad3   Tejun Heo   sysfs: implement ...
378
379
380
381
  	/* make sure we have open dirent struct */
  	error = sysfs_get_open_dirent(attr_sd, buffer);
  	if (error)
  		goto err_free;
b05f0548d   Tejun Heo   sysfs: kill unnec...
382
  	/* open succeeded, put active references */
e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
383
  	sysfs_put_active(attr_sd);
0ab66088c   Tejun Heo   sysfs: implement ...
384
  	return 0;
85a4ffad3   Tejun Heo   sysfs: implement ...
385
386
   err_free:
  	kfree(buffer);
7b595756e   Tejun Heo   sysfs: kill unnec...
387
   err_out:
e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
388
  	sysfs_put_active(attr_sd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
389
390
  	return error;
  }
85a4ffad3   Tejun Heo   sysfs: implement ...
391
  static int sysfs_release(struct inode *inode, struct file *filp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
392
  {
85a4ffad3   Tejun Heo   sysfs: implement ...
393
  	struct sysfs_dirent *sd = filp->f_path.dentry->d_fsdata;
73107cb3a   Tejun Heo   sysfs: kill attri...
394
  	struct sysfs_buffer *buffer = filp->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
395

85a4ffad3   Tejun Heo   sysfs: implement ...
396
  	sysfs_put_open_dirent(sd, buffer);
50ab1a728   Tejun Heo   sysfs: kill unnec...
397
398
399
  	if (buffer->page)
  		free_page((unsigned long)buffer->page);
  	kfree(buffer);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
401
  	return 0;
  }
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
402
403
404
405
406
407
408
  /* Sysfs attribute files are pollable.  The idea is that you read
   * the content and then you use 'poll' or 'select' to wait for
   * the content to change.  When the content changes (assuming the
   * manager for the kobject supports notification), poll will
   * return POLLERR|POLLPRI, and select will return the fd whether
   * it is waiting for read, write, or exceptions.
   * Once poll/select indicates that the value has changed, you
2424b5dd0   Dan Williams   sysfs: refill att...
409
   * need to close and re-open the file, or seek to 0 and read again.
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
410
411
   * Reminder: this only works for attributes which actively support
   * it, and it is not possible to test an attribute from userspace
a93720eeb   Rolf Eike Beer   sysfs: Fix typos ...
412
   * to see if it supports poll (Neither 'poll' nor 'select' return
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
413
414
415
416
417
   * an appropriate error code).  When in doubt, set a suitable timeout value.
   */
  static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
  {
  	struct sysfs_buffer * buffer = filp->private_data;
0ab66088c   Tejun Heo   sysfs: implement ...
418
  	struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata;
a4e8b9125   Tejun Heo   sysfs: move sysfs...
419
  	struct sysfs_open_dirent *od = attr_sd->s_attr.open;
0ab66088c   Tejun Heo   sysfs: implement ...
420
421
  
  	/* need parent for the kobj, grab both */
e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
422
  	if (!sysfs_get_active(attr_sd))
0ab66088c   Tejun Heo   sysfs: implement ...
423
  		goto trigger;
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
424

a4e8b9125   Tejun Heo   sysfs: move sysfs...
425
  	poll_wait(filp, &od->poll, wait);
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
426

e72ceb8cc   Eric W. Biederman   sysfs: Remove sys...
427
  	sysfs_put_active(attr_sd);
0ab66088c   Tejun Heo   sysfs: implement ...
428

a4e8b9125   Tejun Heo   sysfs: move sysfs...
429
  	if (buffer->event != atomic_read(&od->event))
0ab66088c   Tejun Heo   sysfs: implement ...
430
  		goto trigger;
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
431

1af3557ab   KOSAKI Motohiro   sysfs: sysfs poll...
432
  	return DEFAULT_POLLMASK;
0ab66088c   Tejun Heo   sysfs: implement ...
433
434
435
  
   trigger:
  	buffer->needs_read_fill = 1;
1af3557ab   KOSAKI Motohiro   sysfs: sysfs poll...
436
  	return DEFAULT_POLLMASK|POLLERR|POLLPRI;
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
437
  }
f1282c844   Neil Brown   sysfs: Support sy...
438
439
440
  void sysfs_notify_dirent(struct sysfs_dirent *sd)
  {
  	struct sysfs_open_dirent *od;
83db93f4d   Neil Brown   sysfs: Allow sysf...
441
  	unsigned long flags;
f1282c844   Neil Brown   sysfs: Support sy...
442

83db93f4d   Neil Brown   sysfs: Allow sysf...
443
  	spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
f1282c844   Neil Brown   sysfs: Support sy...
444
445
446
447
448
449
  
  	od = sd->s_attr.open;
  	if (od) {
  		atomic_inc(&od->event);
  		wake_up_interruptible(&od->poll);
  	}
83db93f4d   Neil Brown   sysfs: Allow sysf...
450
  	spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
f1282c844   Neil Brown   sysfs: Support sy...
451
452
  }
  EXPORT_SYMBOL_GPL(sysfs_notify_dirent);
8c0e3998f   Trent Piepho   sysfs: Make dir a...
453
  void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
454
  {
51225039f   Tejun Heo   sysfs: make direc...
455
  	struct sysfs_dirent *sd = k->sd;
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
456

51225039f   Tejun Heo   sysfs: make direc...
457
458
459
  	mutex_lock(&sysfs_mutex);
  
  	if (sd && dir)
3ff195b01   Eric W. Biederman   sysfs: Implement ...
460
461
462
463
  		/* Only directories are tagged, so no need to pass
  		 * a tag explicitly.
  		 */
  		sd = sysfs_find_dirent(sd, NULL, dir);
51225039f   Tejun Heo   sysfs: make direc...
464
  	if (sd && attr)
3ff195b01   Eric W. Biederman   sysfs: Implement ...
465
  		sd = sysfs_find_dirent(sd, NULL, attr);
f1282c844   Neil Brown   sysfs: Support sy...
466
467
  	if (sd)
  		sysfs_notify_dirent(sd);
51225039f   Tejun Heo   sysfs: make direc...
468
469
  
  	mutex_unlock(&sysfs_mutex);
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
470
471
  }
  EXPORT_SYMBOL_GPL(sysfs_notify);
4b6f5d20b   Arjan van de Ven   [PATCH] Make most...
472
  const struct file_operations sysfs_file_operations = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
473
474
475
476
477
  	.read		= sysfs_read_file,
  	.write		= sysfs_write_file,
  	.llseek		= generic_file_llseek,
  	.open		= sysfs_open_file,
  	.release	= sysfs_release,
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
478
  	.poll		= sysfs_poll,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
479
  };
0f4238958   James Bottomley   [SCSI] sysfs: mak...
480
481
  int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
  			const struct attribute *attr, int type, mode_t amode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
482
  {
0f4238958   James Bottomley   [SCSI] sysfs: mak...
483
  	umode_t mode = (amode & S_IALLUGO) | S_IFREG;
fb6896da3   Tejun Heo   sysfs: restructur...
484
  	struct sysfs_addrm_cxt acxt;
a26cd7226   Tejun Heo   sysfs: consolidat...
485
  	struct sysfs_dirent *sd;
23dc27995   Tejun Heo   sysfs: make sysfs...
486
  	int rc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
487

3007e997d   Tejun Heo   sysfs: use sysfs_...
488
489
490
  	sd = sysfs_new_dirent(attr->name, mode, type);
  	if (!sd)
  		return -ENOMEM;
b1fc3d614   Tejun Heo   sysfs: make s_ele...
491
  	sd->s_attr.attr = (void *)attr;
a2db68428   Eric W. Biederman   sysfs: Only take ...
492
  	sysfs_dirent_init_lockdep(sd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493

fb6896da3   Tejun Heo   sysfs: restructur...
494
  	sysfs_addrm_start(&acxt, dir_sd);
23dc27995   Tejun Heo   sysfs: make sysfs...
495
496
  	rc = sysfs_add_one(&acxt, sd);
  	sysfs_addrm_finish(&acxt);
a26cd7226   Tejun Heo   sysfs: consolidat...
497

23dc27995   Tejun Heo   sysfs: make sysfs...
498
  	if (rc)
967e35dcc   Tejun Heo   sysfs: cosmetic c...
499
  		sysfs_put(sd);
3007e997d   Tejun Heo   sysfs: use sysfs_...
500

23dc27995   Tejun Heo   sysfs: make sysfs...
501
  	return rc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
502
  }
0f4238958   James Bottomley   [SCSI] sysfs: mak...
503
504
505
506
507
  int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
  		   int type)
  {
  	return sysfs_add_file_mode(dir_sd, attr, type, attr->mode);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
509
510
  /**
   *	sysfs_create_file - create an attribute file for an object.
   *	@kobj:	object we're creating for. 
3932bf605   Chris Malley   sysfs: trivial: f...
511
   *	@attr:	attribute descriptor.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
512
513
514
515
   */
  
  int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
  {
608e266a2   Tejun Heo   sysfs: make kobj ...
516
  	BUG_ON(!kobj || !kobj->sd || !attr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
517

608e266a2   Tejun Heo   sysfs: make kobj ...
518
  	return sysfs_add_file(kobj->sd, attr, SYSFS_KOBJ_ATTR);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
519
520
  
  }
1c205ae18   Andi Kleen   sysfs: Add sysfs_...
521
522
523
524
525
526
527
528
529
530
531
532
  int sysfs_create_files(struct kobject *kobj, const struct attribute **ptr)
  {
  	int err = 0;
  	int i;
  
  	for (i = 0; ptr[i] && !err; i++)
  		err = sysfs_create_file(kobj, ptr[i]);
  	if (err)
  		while (--i >= 0)
  			sysfs_remove_file(kobj, ptr[i]);
  	return err;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
533
534
  
  /**
dfa87c824   Alan Stern   sysfs: allow attr...
535
536
537
538
539
540
541
542
   * sysfs_add_file_to_group - add an attribute file to a pre-existing group.
   * @kobj: object we're acting for.
   * @attr: attribute descriptor.
   * @group: group name.
   */
  int sysfs_add_file_to_group(struct kobject *kobj,
  		const struct attribute *attr, const char *group)
  {
608e266a2   Tejun Heo   sysfs: make kobj ...
543
  	struct sysfs_dirent *dir_sd;
dfa87c824   Alan Stern   sysfs: allow attr...
544
  	int error;
11f24fbdf   James Bottomley   [SCSI] sysfs: fix...
545
  	if (group)
3ff195b01   Eric W. Biederman   sysfs: Implement ...
546
  		dir_sd = sysfs_get_dirent(kobj->sd, NULL, group);
11f24fbdf   James Bottomley   [SCSI] sysfs: fix...
547
548
  	else
  		dir_sd = sysfs_get(kobj->sd);
608e266a2   Tejun Heo   sysfs: make kobj ...
549
550
551
552
553
  	if (!dir_sd)
  		return -ENOENT;
  
  	error = sysfs_add_file(dir_sd, attr, SYSFS_KOBJ_ATTR);
  	sysfs_put(dir_sd);
dfa87c824   Alan Stern   sysfs: allow attr...
554
555
556
  	return error;
  }
  EXPORT_SYMBOL_GPL(sysfs_add_file_to_group);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557
  /**
31e5abe9a   Kay Sievers   [PATCH] sysfs: ad...
558
559
560
561
562
563
   * sysfs_chmod_file - update the modified mode value on an object attribute.
   * @kobj: object we're acting for.
   * @attr: attribute descriptor.
   * @mode: file permissions.
   *
   */
49c19400f   Jean Delvare   sysfs: sysfs_chmo...
564
565
  int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
  		     mode_t mode)
31e5abe9a   Kay Sievers   [PATCH] sysfs: ad...
566
  {
06fc0d66f   Eric W. Biederman   sysfs: In sysfs_c...
567
  	struct sysfs_dirent *sd;
bc062b1b5   Maneesh Soni   [PATCH] sysfs: fi...
568
  	struct iattr newattrs;
51225039f   Tejun Heo   sysfs: make direc...
569
  	int rc;
06fc0d66f   Eric W. Biederman   sysfs: In sysfs_c...
570
  	mutex_lock(&sysfs_mutex);
51225039f   Tejun Heo   sysfs: make direc...
571

06fc0d66f   Eric W. Biederman   sysfs: In sysfs_c...
572
  	rc = -ENOENT;
3ff195b01   Eric W. Biederman   sysfs: Implement ...
573
  	sd = sysfs_find_dirent(kobj->sd, NULL, attr->name);
06fc0d66f   Eric W. Biederman   sysfs: In sysfs_c...
574
  	if (!sd)
51225039f   Tejun Heo   sysfs: make direc...
575
  		goto out;
f88123eaf   Tejun Heo   sysfs: fix sysfs_...
576

06fc0d66f   Eric W. Biederman   sysfs: In sysfs_c...
577
  	newattrs.ia_mode = (mode & S_IALLUGO) | (sd->s_mode & ~S_IALLUGO);
4c6974f51   Eric W. Biederman   sysfs: Simplify s...
578
  	newattrs.ia_valid = ATTR_MODE;
06fc0d66f   Eric W. Biederman   sysfs: In sysfs_c...
579
  	rc = sysfs_sd_setattr(sd, &newattrs);
f88123eaf   Tejun Heo   sysfs: fix sysfs_...
580

51225039f   Tejun Heo   sysfs: make direc...
581
   out:
06fc0d66f   Eric W. Biederman   sysfs: In sysfs_c...
582
  	mutex_unlock(&sysfs_mutex);
51225039f   Tejun Heo   sysfs: make direc...
583
  	return rc;
31e5abe9a   Kay Sievers   [PATCH] sysfs: ad...
584
585
586
587
588
  }
  EXPORT_SYMBOL_GPL(sysfs_chmod_file);
  
  
  /**
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
589
590
591
592
593
594
595
596
597
   *	sysfs_remove_file - remove an object attribute.
   *	@kobj:	object we're acting for.
   *	@attr:	attribute descriptor.
   *
   *	Hash the attribute name and kill the victim.
   */
  
  void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr)
  {
3ff195b01   Eric W. Biederman   sysfs: Implement ...
598
  	sysfs_hash_and_remove(kobj->sd, NULL, attr->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
599
  }
1c205ae18   Andi Kleen   sysfs: Add sysfs_...
600
601
602
603
604
605
  void sysfs_remove_files(struct kobject * kobj, const struct attribute **ptr)
  {
  	int i;
  	for (i = 0; ptr[i]; i++)
  		sysfs_remove_file(kobj, ptr[i]);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
606

dfa87c824   Alan Stern   sysfs: allow attr...
607
608
609
610
611
612
613
614
615
  /**
   * sysfs_remove_file_from_group - remove an attribute file from a group.
   * @kobj: object we're acting for.
   * @attr: attribute descriptor.
   * @group: group name.
   */
  void sysfs_remove_file_from_group(struct kobject *kobj,
  		const struct attribute *attr, const char *group)
  {
608e266a2   Tejun Heo   sysfs: make kobj ...
616
  	struct sysfs_dirent *dir_sd;
dfa87c824   Alan Stern   sysfs: allow attr...
617

11f24fbdf   James Bottomley   [SCSI] sysfs: fix...
618
  	if (group)
3ff195b01   Eric W. Biederman   sysfs: Implement ...
619
  		dir_sd = sysfs_get_dirent(kobj->sd, NULL, group);
11f24fbdf   James Bottomley   [SCSI] sysfs: fix...
620
621
  	else
  		dir_sd = sysfs_get(kobj->sd);
608e266a2   Tejun Heo   sysfs: make kobj ...
622
  	if (dir_sd) {
3ff195b01   Eric W. Biederman   sysfs: Implement ...
623
  		sysfs_hash_and_remove(dir_sd, NULL, attr->name);
608e266a2   Tejun Heo   sysfs: make kobj ...
624
  		sysfs_put(dir_sd);
dfa87c824   Alan Stern   sysfs: allow attr...
625
626
627
  	}
  }
  EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
628
  struct sysfs_schedule_callback_struct {
669420644   Alex Chiang   sysfs: only allow...
629
630
  	struct list_head	workq_list;
  	struct kobject		*kobj;
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
631
632
  	void			(*func)(void *);
  	void			*data;
523ded71d   Alan Stern   device_schedule_c...
633
  	struct module		*owner;
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
634
635
  	struct work_struct	work;
  };
d110271e1   Alex Chiang   sysfs: don't use ...
636
  static struct workqueue_struct *sysfs_workqueue;
669420644   Alex Chiang   sysfs: only allow...
637
638
  static DEFINE_MUTEX(sysfs_workq_mutex);
  static LIST_HEAD(sysfs_workq);
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
639
640
641
642
643
644
645
  static void sysfs_schedule_callback_work(struct work_struct *work)
  {
  	struct sysfs_schedule_callback_struct *ss = container_of(work,
  			struct sysfs_schedule_callback_struct, work);
  
  	(ss->func)(ss->data);
  	kobject_put(ss->kobj);
523ded71d   Alan Stern   device_schedule_c...
646
  	module_put(ss->owner);
669420644   Alex Chiang   sysfs: only allow...
647
648
649
  	mutex_lock(&sysfs_workq_mutex);
  	list_del(&ss->workq_list);
  	mutex_unlock(&sysfs_workq_mutex);
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
650
651
652
653
654
655
656
657
  	kfree(ss);
  }
  
  /**
   * sysfs_schedule_callback - helper to schedule a callback for a kobject
   * @kobj: object we're acting for.
   * @func: callback function to invoke later.
   * @data: argument to pass to @func.
523ded71d   Alan Stern   device_schedule_c...
658
   * @owner: module owning the callback code
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
659
660
661
662
663
664
665
666
667
668
669
670
   *
   * sysfs attribute methods must not unregister themselves or their parent
   * kobject (which would amount to the same thing).  Attempts to do so will
   * deadlock, since unregistration is mutually exclusive with driver
   * callbacks.
   *
   * Instead methods can call this routine, which will attempt to allocate
   * and schedule a workqueue request to call back @func with @data as its
   * argument in the workqueue's process context.  @kobj will be pinned
   * until @func returns.
   *
   * Returns 0 if the request was submitted, -ENOMEM if storage could not
669420644   Alex Chiang   sysfs: only allow...
671
672
   * be allocated, -ENODEV if a reference to @owner isn't available,
   * -EAGAIN if a callback has already been scheduled for @kobj.
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
673
674
   */
  int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
523ded71d   Alan Stern   device_schedule_c...
675
  		void *data, struct module *owner)
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
676
  {
669420644   Alex Chiang   sysfs: only allow...
677
  	struct sysfs_schedule_callback_struct *ss, *tmp;
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
678

523ded71d   Alan Stern   device_schedule_c...
679
680
  	if (!try_module_get(owner))
  		return -ENODEV;
669420644   Alex Chiang   sysfs: only allow...
681
682
683
684
  
  	mutex_lock(&sysfs_workq_mutex);
  	list_for_each_entry_safe(ss, tmp, &sysfs_workq, workq_list)
  		if (ss->kobj == kobj) {
d110271e1   Alex Chiang   sysfs: don't use ...
685
  			module_put(owner);
669420644   Alex Chiang   sysfs: only allow...
686
687
688
689
  			mutex_unlock(&sysfs_workq_mutex);
  			return -EAGAIN;
  		}
  	mutex_unlock(&sysfs_workq_mutex);
d110271e1   Alex Chiang   sysfs: don't use ...
690
  	if (sysfs_workqueue == NULL) {
086a377ed   Andrew Morton   sysfs: file.c: us...
691
  		sysfs_workqueue = create_singlethread_workqueue("sysfsd");
d110271e1   Alex Chiang   sysfs: don't use ...
692
693
694
695
696
  		if (sysfs_workqueue == NULL) {
  			module_put(owner);
  			return -ENOMEM;
  		}
  	}
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
697
  	ss = kmalloc(sizeof(*ss), GFP_KERNEL);
523ded71d   Alan Stern   device_schedule_c...
698
699
  	if (!ss) {
  		module_put(owner);
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
700
  		return -ENOMEM;
523ded71d   Alan Stern   device_schedule_c...
701
  	}
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
702
703
704
705
  	kobject_get(kobj);
  	ss->kobj = kobj;
  	ss->func = func;
  	ss->data = data;
523ded71d   Alan Stern   device_schedule_c...
706
  	ss->owner = owner;
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
707
  	INIT_WORK(&ss->work, sysfs_schedule_callback_work);
669420644   Alex Chiang   sysfs: only allow...
708
709
710
711
  	INIT_LIST_HEAD(&ss->workq_list);
  	mutex_lock(&sysfs_workq_mutex);
  	list_add_tail(&ss->workq_list, &sysfs_workq);
  	mutex_unlock(&sysfs_workq_mutex);
d110271e1   Alex Chiang   sysfs: don't use ...
712
  	queue_work(sysfs_workqueue, &ss->work);
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
713
714
715
  	return 0;
  }
  EXPORT_SYMBOL_GPL(sysfs_schedule_callback);
dfa87c824   Alan Stern   sysfs: allow attr...
716

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
717
718
  EXPORT_SYMBOL_GPL(sysfs_create_file);
  EXPORT_SYMBOL_GPL(sysfs_remove_file);
1c205ae18   Andi Kleen   sysfs: Add sysfs_...
719
720
  EXPORT_SYMBOL_GPL(sysfs_remove_files);
  EXPORT_SYMBOL_GPL(sysfs_create_files);