sysfs: Implement sysfs_rename_link
[safe/jmp/linux-2.6] / fs / sysfs / symlink.c
index 1d897ad..1b9a3a1 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/kobject.h>
 #include <linux/namei.h>
 #include <linux/mutex.h>
+#include <linux/security.h>
 
 #include "sysfs.h"
 
@@ -122,6 +123,44 @@ void sysfs_remove_link(struct kobject * kobj, const char * name)
        sysfs_hash_and_remove(parent_sd, name);
 }
 
+/**
+ *     sysfs_rename_link - rename symlink in object's directory.
+ *     @kobj:  object we're acting for.
+ *     @targ:  object we're pointing to.
+ *     @old:   previous name of the symlink.
+ *     @new:   new name of the symlink.
+ *
+ *     A helper function for the common rename symlink idiom.
+ */
+int sysfs_rename_link(struct kobject *kobj, struct kobject *targ,
+                       const char *old, const char *new)
+{
+       struct sysfs_dirent *parent_sd, *sd = NULL;
+       int result;
+
+       if (!kobj)
+               parent_sd = &sysfs_root;
+       else
+               parent_sd = kobj->sd;
+
+       result = -ENOENT;
+       sd = sysfs_get_dirent(parent_sd, old);
+       if (!sd)
+               goto out;
+
+       result = -EINVAL;
+       if (sysfs_type(sd) != SYSFS_KOBJ_LINK)
+               goto out;
+       if (sd->s_symlink.target_sd->s_dir.kobj != targ)
+               goto out;
+
+       result = sysfs_rename(sd, parent_sd, new);
+
+out:
+       sysfs_put(sd);
+       return result;
+}
+
 static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
                                 struct sysfs_dirent *target_sd, char *path)
 {
@@ -209,9 +248,13 @@ static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *co
 }
 
 const struct inode_operations sysfs_symlink_inode_operations = {
-       .readlink = generic_readlink,
-       .follow_link = sysfs_follow_link,
-       .put_link = sysfs_put_link,
+       .setxattr       = sysfs_setxattr,
+       .readlink       = generic_readlink,
+       .follow_link    = sysfs_follow_link,
+       .put_link       = sysfs_put_link,
+       .setattr        = sysfs_setattr,
+       .getattr        = sysfs_getattr,
+       .permission     = sysfs_permission,
 };