>From 0d7525045927c8056ff28dd9465766862faba227 Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Sat, 17 Oct 2009 12:39:11 +0200 Subject: [PATCH 3/6] Provide per-file private data for bin sysfs files For binary sysfs files, provide a per-file private field in struct bin_buffer. Therefore this modified struct is exported in the header file. Additionally add a release() callback that can be used to free the private data on file release. Signed-off-by: Thomas Schlichter --- fs/sysfs/bin.c | 18 ++++++++---------- include/linux/sysfs.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c index 60c702b..3647b7a 100644 --- a/fs/sysfs/bin.c +++ b/fs/sysfs/bin.c @@ -36,15 +36,6 @@ */ static DEFINE_MUTEX(sysfs_bin_lock); -struct bin_buffer { - struct mutex mutex; - void *buffer; - int mmapped; - const struct vm_operations_struct *vm_ops; - struct file *file; - struct hlist_node list; -}; - static int fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count) { @@ -438,14 +429,21 @@ static int open(struct inode * inode, struct file * file) static int release(struct inode * inode, struct file * file) { struct bin_buffer *bb = file->private_data; + struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; + struct bin_attribute *attr = attr_sd->s_bin_attr.bin_attr; + struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; + int rc = 0; + if (attr->release) + rc = attr->release(kobj, attr, file); + mutex_lock(&sysfs_bin_lock); hlist_del(&bb->list); mutex_unlock(&sysfs_bin_lock); kfree(bb->buffer); kfree(bb); - return 0; + return rc; } const struct file_operations bin_fops = { diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 9d68fed..bcad8ad 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -15,6 +15,7 @@ #include #include #include +#include #include struct kobject; @@ -60,8 +61,19 @@ struct attribute_group { #define attr_name(_attr) (_attr).attr.name +struct file; struct vm_area_struct; +struct bin_buffer { + struct mutex mutex; + void *buffer; + void *private; + int mmapped; + const struct vm_operations_struct *vm_ops; + struct file *file; + struct hlist_node list; +}; + struct bin_attribute { struct attribute attr; size_t size; @@ -72,6 +84,8 @@ struct bin_attribute { char *, loff_t, size_t); int (*mmap)(struct kobject *, struct bin_attribute *attr, struct vm_area_struct *vma); + int (*release)(struct kobject *, struct bin_attribute *attr, + struct file *file); }; struct sysfs_ops { -- 1.6.5