]> err.no Git - linux-2.6/blobdiff - fs/sysfs/file.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/joern/misc
[linux-2.6] / fs / sysfs / file.c
index cba4c1c7383c1834692268bd6b6a7e86c41e3777..8d4d839a9d887eb4a753da824e55a98542b26f21 100644 (file)
@@ -54,7 +54,7 @@ static struct sysfs_ops subsys_sysfs_ops = {
 /**
  *     add_to_collection - add buffer to a collection
  *     @buffer:        buffer to be added
- *     @node           inode of set to add to
+ *     @node:          inode of set to add to
  */
 
 static inline void
@@ -83,7 +83,8 @@ remove_from_collection(struct sysfs_buffer *buffer, struct inode *node)
  *     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. 
- *     This is called only once, on the file's first read. 
+ *     This is called only once, on the file's first read unless an error
+ *     is returned.
  */
 static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer)
 {
@@ -101,12 +102,13 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
 
        buffer->event = atomic_read(&sd->s_event);
        count = ops->show(kobj,attr,buffer->page);
-       buffer->needs_read_fill = 0;
        BUG_ON(count > (ssize_t)PAGE_SIZE);
-       if (count >= 0)
+       if (count >= 0) {
+               buffer->needs_read_fill = 0;
                buffer->count = count;
-       else
+       } else {
                ret = count;
+       }
        return ret;
 }
 
@@ -361,7 +363,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
        error = -EACCES;
        module_put(attr->owner);
  Done:
-       if (error && kobj)
+       if (error)
                kobject_put(kobj);
        return error;
 }
@@ -375,8 +377,7 @@ static int sysfs_release(struct inode * inode, struct file * filp)
 
        if (buffer)
                remove_from_collection(buffer, inode);
-       if (kobj) 
-               kobject_put(kobj);
+       kobject_put(kobj);
        /* After this point, attr should not be accessed. */
        module_put(owner);
 
@@ -500,6 +501,30 @@ int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
 }
 
 
+/**
+ * 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)
+{
+       struct dentry *dir;
+       int error;
+
+       dir = lookup_one_len(group, kobj->dentry, strlen(group));
+       if (IS_ERR(dir))
+               error = PTR_ERR(dir);
+       else {
+               error = sysfs_add_file(dir, attr, SYSFS_KOBJ_ATTR);
+               dput(dir);
+       }
+       return error;
+}
+EXPORT_SYMBOL_GPL(sysfs_add_file_to_group);
+
+
 /**
  * sysfs_update_file - update the modified timestamp on an object attribute.
  * @kobj: object we're acting for.
@@ -585,6 +610,26 @@ void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr)
 }
 
 
+/**
+ * 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)
+{
+       struct dentry *dir;
+
+       dir = lookup_one_len(group, kobj->dentry, strlen(group));
+       if (!IS_ERR(dir)) {
+               sysfs_hash_and_remove(dir, attr->name);
+               dput(dir);
+       }
+}
+EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
+
+
 EXPORT_SYMBOL_GPL(sysfs_create_file);
 EXPORT_SYMBOL_GPL(sysfs_remove_file);
 EXPORT_SYMBOL_GPL(sysfs_update_file);