obj: add set and namespace object callbacks
This commit is contained in:
@@ -1,17 +1,42 @@
|
||||
#include <socks/object.h>
|
||||
#include <socks/printk.h>
|
||||
|
||||
static object_namespace_t *global_ns;
|
||||
|
||||
struct object_namespace {
|
||||
/* root directory set object */
|
||||
object_t *ns_root;
|
||||
};
|
||||
|
||||
static kern_status_t ns_query_name(object_t *obj, char out[OBJECT_NAME_MAX])
|
||||
{
|
||||
out[0] = '/';
|
||||
out[1] = 0;
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
static kern_status_t ns_get_child_at(object_t *obj, size_t at, object_t **out)
|
||||
{
|
||||
object_namespace_t *ns = object_data(obj);
|
||||
return object_get_child_at(ns->ns_root, at, out);
|
||||
}
|
||||
|
||||
static kern_status_t ns_get_child_named(object_t *obj, const char *name, object_t **out)
|
||||
{
|
||||
object_namespace_t *ns = object_data(obj);
|
||||
return object_get_child_named(ns->ns_root, name, out);
|
||||
}
|
||||
|
||||
static object_type_t ns_type = {
|
||||
.ob_name = "namespace",
|
||||
.ob_size = sizeof(object_namespace_t),
|
||||
.ob_ops = {
|
||||
.query_name = ns_query_name,
|
||||
.get_named = ns_get_child_named,
|
||||
.get_at = ns_get_child_at,
|
||||
},
|
||||
};
|
||||
|
||||
static object_namespace_t *global_ns;
|
||||
|
||||
void init_global_namespace(void)
|
||||
{
|
||||
@@ -100,21 +125,30 @@ kern_status_t object_publish(object_namespace_t *ns, const char *path, object_t
|
||||
|
||||
unsigned long flags;
|
||||
while (tok) {
|
||||
set_lock(cur, &flags);
|
||||
object_lock(cur, &flags);
|
||||
|
||||
object_t *next = object_get_child_named(cur, tok);
|
||||
if (!next) {
|
||||
object_t *next;
|
||||
kern_status_t status = object_get_child_named(cur, tok, &next);
|
||||
if (status == KERN_NO_ENTRY) {
|
||||
next = set_create(tok);
|
||||
if (!next) {
|
||||
object_unlock(cur, flags);
|
||||
kfree(rpath);
|
||||
return KERN_NO_MEMORY;
|
||||
}
|
||||
|
||||
set_add_object(cur, next);
|
||||
status = set_add_object(cur, next);
|
||||
}
|
||||
|
||||
set_unlock(cur, flags);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user