obj: implement object_namespace_get_object()
This commit is contained in:
@@ -60,11 +60,6 @@ struct object_namespace *object_namespace_create(void)
|
|||||||
return ns;
|
return ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
kern_status_t object_namespace_get_object(struct object_namespace *ns, const char *path, struct object **out)
|
|
||||||
{
|
|
||||||
return KERN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanup_object_path(char *path, size_t len, size_t *parts)
|
static void cleanup_object_path(char *path, size_t len, size_t *parts)
|
||||||
{
|
{
|
||||||
while (path[len - 1] == '/') {
|
while (path[len - 1] == '/') {
|
||||||
@@ -102,6 +97,58 @@ struct object *ns_header(struct object_namespace *ns)
|
|||||||
return &ns->ns_base;
|
return &ns->ns_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kern_status_t object_namespace_get_object(struct object_namespace *ns, const char *path, struct object **out)
|
||||||
|
{
|
||||||
|
if (*path != '/') {
|
||||||
|
return KERN_INVALID_ARGUMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*path == '/') {
|
||||||
|
path++;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t path_len = strlen(path);
|
||||||
|
if (path_len == 0) {
|
||||||
|
*out = object_ref(ns->ns_root);
|
||||||
|
return KERN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t parts = 0;
|
||||||
|
char *rpath = kmalloc(path_len, 0);
|
||||||
|
if (!rpath) {
|
||||||
|
return KERN_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(rpath, path, path_len);
|
||||||
|
cleanup_object_path(rpath, path_len, &parts);
|
||||||
|
|
||||||
|
char *sp;
|
||||||
|
char *tok = strtok_r(rpath, "/", &sp);
|
||||||
|
struct object *cur = ns->ns_root;
|
||||||
|
|
||||||
|
unsigned long flags;
|
||||||
|
while (tok) {
|
||||||
|
object_lock(cur, &flags);
|
||||||
|
|
||||||
|
struct object *next;
|
||||||
|
kern_status_t status = object_get_child_named(cur, tok, &next);
|
||||||
|
if (status != KERN_OK) {
|
||||||
|
object_unlock(cur, flags);
|
||||||
|
kfree(rpath);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
object_unlock(cur, flags);
|
||||||
|
cur = next;
|
||||||
|
tok = strtok_r(NULL, "/", &sp);
|
||||||
|
}
|
||||||
|
|
||||||
|
kfree(rpath);
|
||||||
|
|
||||||
|
*out = object_ref(cur);
|
||||||
|
return KERN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
kern_status_t object_publish(struct object_namespace *ns, const char *path, struct object *obj)
|
kern_status_t object_publish(struct object_namespace *ns, const char *path, struct object *obj)
|
||||||
{
|
{
|
||||||
if (*path != '/') {
|
if (*path != '/') {
|
||||||
|
|||||||
Reference in New Issue
Block a user