aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 74b8dbca150e..c2917ffe8bf1 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -44,11 +44,11 @@ static int populate_dir(struct kobject * kobj)
44 return error; 44 return error;
45} 45}
46 46
47static int create_dir(struct kobject * kobj) 47static int create_dir(struct kobject * kobj, struct dentry *shadow_parent)
48{ 48{
49 int error = 0; 49 int error = 0;
50 if (kobject_name(kobj)) { 50 if (kobject_name(kobj)) {
51 error = sysfs_create_dir(kobj); 51 error = sysfs_create_dir(kobj, shadow_parent);
52 if (!error) { 52 if (!error) {
53 if ((error = populate_dir(kobj))) 53 if ((error = populate_dir(kobj)))
54 sysfs_remove_dir(kobj); 54 sysfs_remove_dir(kobj);
@@ -158,9 +158,10 @@ static void unlink(struct kobject * kobj)
158/** 158/**
159 * kobject_add - add an object to the hierarchy. 159 * kobject_add - add an object to the hierarchy.
160 * @kobj: object. 160 * @kobj: object.
161 * @shadow_parent: sysfs directory to add to.
161 */ 162 */
162 163
163int kobject_add(struct kobject * kobj) 164int kobject_shadow_add(struct kobject * kobj, struct dentry *shadow_parent)
164{ 165{
165 int error = 0; 166 int error = 0;
166 struct kobject * parent; 167 struct kobject * parent;
@@ -191,7 +192,7 @@ int kobject_add(struct kobject * kobj)
191 } 192 }
192 kobj->parent = parent; 193 kobj->parent = parent;
193 194
194 error = create_dir(kobj); 195 error = create_dir(kobj, shadow_parent);
195 if (error) { 196 if (error) {
196 /* unlink does the kobject_put() for us */ 197 /* unlink does the kobject_put() for us */
197 unlink(kobj); 198 unlink(kobj);
@@ -212,6 +213,15 @@ int kobject_add(struct kobject * kobj)
212 return error; 213 return error;
213} 214}
214 215
216/**
217 * kobject_add - add an object to the hierarchy.
218 * @kobj: object.
219 */
220int kobject_add(struct kobject * kobj)
221{
222 return kobject_shadow_add(kobj, NULL);
223}
224
215 225
216/** 226/**
217 * kobject_register - initialize and add an object. 227 * kobject_register - initialize and add an object.
@@ -304,7 +314,29 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
304 kobj = kobject_get(kobj); 314 kobj = kobject_get(kobj);
305 if (!kobj) 315 if (!kobj)
306 return -EINVAL; 316 return -EINVAL;
307 error = sysfs_rename_dir(kobj, new_name); 317 if (!kobj->parent)
318 return -EINVAL;
319 error = sysfs_rename_dir(kobj, kobj->parent->dentry, new_name);
320 kobject_put(kobj);
321
322 return error;
323}
324
325/**
326 * kobject_rename - change the name of an object
327 * @kobj: object in question.
328 * @new_name: object's new name
329 */
330
331int kobject_shadow_rename(struct kobject * kobj, struct dentry *new_parent,
332 const char *new_name)
333{
334 int error = 0;
335
336 kobj = kobject_get(kobj);
337 if (!kobj)
338 return -EINVAL;
339 error = sysfs_rename_dir(kobj, new_parent, new_name);
308 kobject_put(kobj); 340 kobject_put(kobj);
309 341
310 return error; 342 return error;