13 #include <linux/module.h>
16 #include <linux/slab.h>
19 #include <linux/poll.h>
20 #include <linux/list.h>
23 #include <asm/uaccess.h>
94 print_symbol(
"fill_read_buffer: %s returned bad count\n",
95 (
unsigned long)ops->
show);
97 count = PAGE_SIZE - 1;
128 sysfs_read_file(
struct file *
file,
char __user *
buf,
size_t count, loff_t *ppos)
135 retval = fill_read_buffer(file->
f_path.dentry,buffer);
139 pr_debug(
"%s: count = %zd, ppos = %lld, buf = %s\n",
140 __func__, count, *ppos, buffer->
page);
159 fill_write_buffer(
struct sysfs_buffer * buffer,
const char __user * buf,
size_t count)
168 if (count >= PAGE_SIZE)
169 count = PAGE_SIZE - 1;
228 sysfs_write_file(
struct file *file,
const char __user *buf,
size_t count, loff_t *ppos)
234 len = fill_write_buffer(buffer, buf, count);
264 spin_lock_irq(&sysfs_open_dirent_lock);
266 if (!sd->
s_attr.open && new_od) {
277 spin_unlock_irq(&sysfs_open_dirent_lock);
292 INIT_LIST_HEAD(&new_od->
buffers);
307 static void sysfs_put_open_dirent(
struct sysfs_dirent *sd,
321 spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
326 static int sysfs_open_file(
struct inode *
inode,
struct file *file)
340 ops = kobj->
ktype->sysfs_ops;
342 WARN(1,
KERN_ERR "missing sysfs attribute operations for "
343 "kobject: %s\n", kobject_name(kobj));
379 error = sysfs_get_open_dirent(attr_sd, buffer);
394 static int sysfs_release(
struct inode *inode,
struct file *filp)
399 sysfs_put_open_dirent(sd, buffer);
421 static unsigned int sysfs_poll(
struct file *filp,
poll_table *
wait)
431 poll_wait(filp, &od->
poll, wait);
458 spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
480 .read = sysfs_read_file,
481 .write = sysfs_write_file,
483 .open = sysfs_open_file,
484 .release = sysfs_release,
503 if (!sysfs_ns_type(dir_sd))
509 ops = kobj->
ktype->sysfs_ops;
519 WARN(1,
KERN_ERR "missing sysfs namespace attribute operation for "
520 "kobject: %s\n", kobject_name(kobj));
544 sd->
s_attr.attr = (
void *)attr;
573 BUG_ON(!kobj || !kobj->
sd || !attr);
584 for (i = 0; ptr[
i] && !
err; i++)
630 struct iattr newattrs;
677 for (i = 0; ptr[
i]; i++)
722 module_put(ss->
owner);
755 if (!try_module_get(owner))
760 if (ss->
kobj == kobj) {
767 if (sysfs_workqueue ==
NULL) {
769 if (sysfs_workqueue ==
NULL) {