stos: ob: Implement ObCreateObject() helper
The ObCreateObject() is responsible for creating and allocating new objects, we'll need this to even have directories and such. Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause.
|
||||
*
|
||||
* Description: Object manager
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#include <ob/object.h>
|
||||
#include <ex/pool.h>
|
||||
#include <string.h>
|
||||
|
||||
ST_STATUS
|
||||
ObCreateObject(const CHAR *Name, OBJECT_TYPE Type, VOID *Data, ST_OBJECT **Result)
|
||||
{
|
||||
ST_OBJECT *Object;
|
||||
USIZE NameLen;
|
||||
|
||||
if (Name == NULL || Result == NULL) {
|
||||
return STATUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
NameLen = RtlStrLen(Name);
|
||||
if (NameLen >= OBJECT_NAMESZ - 1) {
|
||||
return STATUS_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
Object = ExAllocatePoolWithTag(
|
||||
POOL_NON_PAGED,
|
||||
sizeof(*Object),
|
||||
OBJECT_POOL_TAG
|
||||
);
|
||||
|
||||
if (Object == NULL) {
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
RtlMemCpy(Object->Name, Name, NameLen);
|
||||
Object->Name[NameLen] = '\0';
|
||||
Object->RefCount = 1;
|
||||
Object->Type = Type;
|
||||
Object->Data = Data;
|
||||
*Result = Object;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user