X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fdrv%2Fproc.c;h=3283c864ae0565792dab10f3fa3fe36e7660a074;hb=0542d0b19b79f6439ace9c0f9e35ec29a8af91f9;hp=898deee32a56915c5d2dfd0b4e56eb1e5c937786;hpb=b71ce3a65f255d487f1f869ba88c6924b11ad7e5;p=tpg%2Facess2.git diff --git a/Kernel/drv/proc.c b/Kernel/drv/proc.c index 898deee3..3283c864 100644 --- a/Kernel/drv/proc.c +++ b/Kernel/drv/proc.c @@ -3,14 +3,13 @@ * - Kernel Status Driver */ #define DEBUG 1 -#include +#include #include #include #include // === CONSTANTS === #define VERSION ((0 << 8) | (1)) // 0.01 -#define KERNEL_VERSION_STRING ("Acess2 " EXPAND_STR(KERNEL_VERSION) " build " EXPAND_STR(BUILD_NUM)) // === TYPES === typedef struct sSysFS_Ent @@ -18,20 +17,22 @@ typedef struct sSysFS_Ent struct sSysFS_Ent *Next; struct sSysFS_Ent *ListNext; struct sSysFS_Ent *Parent; - char *Name; tVFS_Node Node; + char Name[]; } tSysFS_Ent; // === PROTOTYPES === int SysFS_Install(char **Arguments); int SysFS_IOCtl(tVFS_Node *Node, int Id, void *Data); - int SysFS_RegisterFile(char *Path, char *Data, int Length); - int SysFS_UpdateFile(int ID, char *Data, int Length); +#if 0 + int SysFS_RegisterFile(const char *Path, const char *Data, int Length); + int SysFS_UpdateFile(int ID, const char *Data, int Length); int SysFS_RemoveFile(int ID); +#endif char *SysFS_Comm_ReadDir(tVFS_Node *Node, int Id); -tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename); +tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename); Uint64 SysFS_Comm_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); void SysFS_Comm_CloseFile(tVFS_Node *Node); @@ -42,21 +43,20 @@ MODULE_DEFINE(0, VERSION, SysFS, SysFS_Install, NULL, NULL); tSysFS_Ent gSysFS_Version_Kernel = { NULL, NULL, // Nexts &gSysFS_Version, // Parent - "Kernel", { .Inode = 1, // File #1 - .ImplPtr = KERNEL_VERSION_STRING, + .ImplPtr = NULL, .ImplInt = (Uint)&gSysFS_Version_Kernel, // Self-Link - .Size = sizeof(KERNEL_VERSION_STRING)-1, + .Size = 0, .NumACLs = 1, .ACLs = &gVFS_ACL_EveryoneRO, .Read = SysFS_Comm_ReadFile - } + }, + "Kernel" }; tSysFS_Ent gSysFS_Version = { NULL, NULL, &gSysFS_Root, - "Version", { .Size = 1, .ImplPtr = &gSysFS_Version_Kernel, @@ -66,23 +66,19 @@ tSysFS_Ent gSysFS_Version = { .Flags = VFS_FFLAG_DIRECTORY, .ReadDir = SysFS_Comm_ReadDir, .FindDir = SysFS_Comm_FindDir - } + }, + "Version" }; -// Root of the SysFS tree (just used for clean code) +// Root of the SysFS tree (just used to keep the code clean) tSysFS_Ent gSysFS_Root = { NULL, NULL, NULL, - "/", { .Size = 1, .ImplPtr = &gSysFS_Version, .ImplInt = (Uint)&gSysFS_Root // Self-Link - // .NumACLs = 1, - // .ACLs = &gVFS_ACL_EveryoneRX, - // .Flags = VFS_FFLAG_DIRECTORY, - // .ReadDir = SysFS_Comm_ReadDir, - // .FindDir = SysFS_Comm_FindDir - } + }, + "/" }; tDevFS_Driver gSysFS_DriverInfo = { NULL, "system", @@ -107,8 +103,15 @@ tSysFS_Ent *gSysFS_FileList; */ int SysFS_Install(char **Options) { + { + const char *fmt = "Acess2 "EXPAND_STR(KERNEL_VERSION)" "EXPAND_STR(ARCHDIR)" build %i, hash %s"; + gSysFS_Version_Kernel.Node.Size = sprintf(NULL, fmt, BUILD_NUM, gsGitHash); + gSysFS_Version_Kernel.Node.ImplPtr = malloc( gSysFS_Version_Kernel.Node.Size + 1 ); + sprintf(gSysFS_Version_Kernel.Node.ImplPtr, fmt, BUILD_NUM, gsGitHash); + } + DevFS_AddDevice( &gSysFS_DriverInfo ); - return MODULE_INIT_SUCCESS; + return MODULE_ERR_OK; } /** @@ -119,7 +122,7 @@ int SysFS_Install(char **Options) * \param Length Length of the data buffer * \return The file's identifier */ -int SysFS_RegisterFile(char *Path, char *Data, int Length) +int SysFS_RegisterFile(const char *Path, const char *Data, int Length) { int start = 0; int tmp; @@ -144,9 +147,8 @@ int SysFS_RegisterFile(char *Path, char *Data, int Length) // Need a new directory? if( !child ) { - child = calloc( 1, sizeof(tSysFS_Ent) ); + child = calloc( 1, sizeof(tSysFS_Ent)+tmp+1 ); child->Next = NULL; - child->Name = malloc(tmp+1); memcpy(child->Name, &Path[start], tmp); child->Name[tmp] = '\0'; child->Parent = ent; @@ -159,11 +161,11 @@ int SysFS_RegisterFile(char *Path, char *Data, int Length) child->Node.ReadDir = SysFS_Comm_ReadDir; child->Node.FindDir = SysFS_Comm_FindDir; if( !prev ) { - //if(ent) + if(ent) ent->Node.ImplPtr = child; - //else - // gSysFS_DriverInfo.RootNode.ImplPtr = child; - // ^^^ Impossible (There is already /Version + else + gSysFS_DriverInfo.RootNode.ImplPtr = child; + // ^^^ Impossible (There is already /Version) } else prev->Next = child; @@ -171,7 +173,7 @@ int SysFS_RegisterFile(char *Path, char *Data, int Length) ent->Node.Size ++; else gSysFS_DriverInfo.RootNode.Size ++; - LOG("Added directory '%s'", child->Name); + Log_Log("SysFS", "Added directory '%s'", child->Name); } ent = child; @@ -188,24 +190,24 @@ int SysFS_RegisterFile(char *Path, char *Data, int Length) child = ent->Node.ImplPtr; else child = gSysFS_DriverInfo.RootNode.ImplPtr; - for( child = ent->Node.ImplPtr; child; prev = child, child = child->Next ) + for( ; child; child = child->Next ) { if( strcmp( &Path[start], child->Name ) == 0 ) break; } if( child ) { - Warning("[SYSFS] '%s' is taken (in '%s')\n", &Path[start], Path); + Log_Warning("SysFS", "'%s' is taken (in '%s')\n", &Path[start], Path); return 0; } // Create new node - child = calloc( 1, sizeof(tSysFS_Ent) ); + child = calloc( 1, sizeof(tSysFS_Ent)+strlen(&Path[start])+1 ); child->Next = NULL; - child->Name = strdup(&Path[start]); + strcpy(child->Name, &Path[start]); child->Parent = ent; child->Node.Inode = giSysFS_NextFileID++; - child->Node.ImplPtr = Data; + child->Node.ImplPtr = (void*)Data; child->Node.ImplInt = (Uint)child; // Uplink child->Node.Size = Length; child->Node.NumACLs = 1; @@ -228,7 +230,7 @@ int SysFS_RegisterFile(char *Path, char *Data, int Length) child->ListNext = gSysFS_FileList; gSysFS_FileList = child; - Log("[SYSFS] Added '%s' (%p)", Path, Data); + Log_Log("SysFS", "Added '%s' (%p)", Path, Data); return child->Node.Inode; } @@ -241,7 +243,7 @@ int SysFS_RegisterFile(char *Path, char *Data, int Length) * \param Length Length of the data buffer * \return Boolean Success */ -int SysFS_UpdateFile(int ID, char *Data, int Length) +int SysFS_UpdateFile(int ID, const char *Data, int Length) { tSysFS_Ent *ent; @@ -251,7 +253,7 @@ int SysFS_UpdateFile(int ID, char *Data, int Length) if(ent->Node.Inode < ID) return 0; if(ent->Node.Inode == ID) { - ent->Node.ImplPtr = Data; + ent->Node.ImplPtr = (void*)Data; ent->Node.Size = Length; return 1; } @@ -287,7 +289,10 @@ int SysFS_RemoveFile(int ID) parent = file->Parent; // Remove from file list - prev->ListNext = file->ListNext; + if(prev) + prev->ListNext = file->ListNext; + else + gSysFS_FileList = file->ListNext; file->Node.Size = 0; file->Node.ImplPtr = NULL; @@ -297,12 +302,15 @@ int SysFS_RemoveFile(int ID) if( ent == file ) break; } if(!ent) { - Warning("[SYSFS] Bookkeeping Error: File in list, but not in directory"); + Log_Warning("SysFS", "Bookkeeping Error: File in list, but not in directory"); return 0; } // Remove from parent directory - prev->Next = ent->Next; + if(prev) + prev->Next = ent->Next; + else + parent->Node.ImplPtr = ent->Next; // Free if not in use if(file->Node.ReferenceCount == 0) @@ -328,10 +336,10 @@ char *SysFS_Comm_ReadDir(tVFS_Node *Node, int Pos) } /** - * \fn tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename) + * \fn tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename) * \brief Find a file in a SysFS directory */ -tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename) +tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename) { tSysFS_Ent *child = (tSysFS_Ent*)Node->ImplPtr;