diff options
Diffstat (limited to 'lib/kobject.c')
| -rw-r--r-- | lib/kobject.c | 30 | 
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index 18989b5b3b56..97d86dc17c42 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -35,6 +35,25 @@ const void *kobject_namespace(struct kobject *kobj)  	return kobj->ktype->namespace(kobj);  } +/** + * kobject_get_ownership - get sysfs ownership data for @kobj + * @kobj: kobject in question + * @uid: kernel user ID for sysfs objects + * @gid: kernel group ID for sysfs objects + * + * Returns initial uid/gid pair that should be used when creating sysfs + * representation of given kobject. Normally used to adjust ownership of + * objects in a container. + */ +void kobject_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid) +{ +	*uid = GLOBAL_ROOT_UID; +	*gid = GLOBAL_ROOT_GID; + +	if (kobj->ktype->get_ownership) +		kobj->ktype->get_ownership(kobj, uid, gid); +} +  /*   * populate_dir - populate directory with attributes.   * @kobj: object we're working on. @@ -125,7 +144,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)  		int cur = strlen(kobject_name(parent));  		/* back up enough to print this name with '/' */  		length -= cur; -		strncpy(path + length, kobject_name(parent), cur); +		memcpy(path + length, kobject_name(parent), cur);  		*(path + --length) = '/';  	} @@ -868,9 +887,16 @@ static void kset_release(struct kobject *kobj)  	kfree(kset);  } +void kset_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid) +{ +	if (kobj->parent) +		kobject_get_ownership(kobj->parent, uid, gid); +} +  static struct kobj_type kset_ktype = {  	.sysfs_ops	= &kobj_sysfs_ops, -	.release = kset_release, +	.release	= kset_release, +	.get_ownership	= kset_get_ownership,  };  /**  |