>From 7210888ded750f87f5509bdd5b95363a476ce307 Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Sat, 17 Oct 2009 12:39:11 +0200 Subject: [PATCH 2/3] Provide per-file private data for bin sysfs files For binary sysfs files, provide a per-file private field in struct bin_buffer. To be easily accessible, it is located on head of the struct. Additionally add a release() callback that may be used to e.g. free the private data on file release. Signed-off-by: Thomas Schlichter --- fs/sysfs/bin.c | 10 +++++++++- include/linux/sysfs.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletions(-) diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c index 60c702b..28c039a 100644 --- a/fs/sysfs/bin.c +++ b/fs/sysfs/bin.c @@ -37,6 +37,7 @@ static DEFINE_MUTEX(sysfs_bin_lock); struct bin_buffer { + void *private; struct mutex mutex; void *buffer; int mmapped; @@ -438,6 +439,13 @@ 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); @@ -445,7 +453,7 @@ static int release(struct inode * inode, struct file * file) 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..751ea68 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -19,6 +19,7 @@ struct kobject; struct module; +struct file; /* FIXME * The *owner field is no longer used. @@ -72,6 +73,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.1