]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - lib/kobject.c
sysfs, kobject: allow creating kobject belonging to arbitrary users
[mirror_ubuntu-bionic-kernel.git] / lib / kobject.c
index 34f847252c02116abe3551c78502be24d97d3ac9..4a530e93a0cedcd20c3f5eba807ee3789fef7f7a 100644 (file)
@@ -37,6 +37,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.