Nativelib - Fix clang compilation issues
[tpg/acess2.git] / KernelLand / Kernel / drv / proc.c
index 1e0c6bd..60bf4dd 100644 (file)
@@ -32,8 +32,8 @@ typedef struct sSysFS_Ent
 #endif
 
  int   SysFS_Comm_ReadDir(tVFS_Node *Node, int Id, char Dest[FILENAME_MAX]);
-tVFS_Node      *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename);
-size_t SysFS_Comm_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer);
+tVFS_Node      *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags);
+size_t SysFS_Comm_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags);
 void   SysFS_Comm_CloseFile(tVFS_Node *Node);
 
 // === GLOBALS ===
@@ -50,9 +50,8 @@ tVFS_NodeType gSysFS_DirNodeType = {
        .FindDir = SysFS_Comm_FindDir
        };
 tSysFS_Ent     gSysFS_Version_Kernel = {
-       NULL, NULL,     // Nexts
-       &gSysFS_Version,        // Parent
-       {
+       .Parent = &gSysFS_Version,      // Parent
+       .Node = {
                .Inode = 1,     // File #1
                .ImplPtr = NULL,
                .ImplInt = (Uint)&gSysFS_Version_Kernel,        // Self-Link
@@ -61,12 +60,11 @@ tSysFS_Ent  gSysFS_Version_Kernel = {
                .ACLs = &gVFS_ACL_EveryoneRO,
                .Type = &gSysFS_FileNodeType
        },
-       "Kernel"
+       .Name = {"Kernel"}
 };
 tSysFS_Ent     gSysFS_Version = {
-       NULL, NULL,
-       &gSysFS_Root,
-       {
+       .Parent = &gSysFS_Root,
+       .Node = {
                .Size = 1,
                .ImplPtr = &gSysFS_Version_Kernel,
                .ImplInt = (Uint)&gSysFS_Version,       // Self-Link
@@ -75,7 +73,7 @@ tSysFS_Ent    gSysFS_Version = {
                .Flags = VFS_FFLAG_DIRECTORY,
                .Type = &gSysFS_DirNodeType
        },
-       "Version"
+       .Name = {"Version"}
 };
 // Root of the SysFS tree (just used to keep the code clean)
 tSysFS_Ent     gSysFS_Root = {
@@ -86,7 +84,7 @@ tSysFS_Ent    gSysFS_Root = {
                .ImplPtr = &gSysFS_Version,
                .ImplInt = (Uint)&gSysFS_Root   // Self-Link
        },
-       "/"
+       {"/"}
 };
 tDevFS_Driver  gSysFS_DriverInfo = {
        NULL, "system",
@@ -150,6 +148,10 @@ int SysFS_RegisterFile(const char *Path, const char *Data, int Length)
                if( !child )
                {
                        child = calloc( 1, sizeof(tSysFS_Ent)+tmp+1 );
+                       if( !child ) {
+                               Log_Error("SysFS", "calloc(%i) failure", sizeof(tSysFS_Ent)+tmp+1);
+                               return -1;
+                       }
                        child->Next = NULL;
                        memcpy(child->Name, &Path[start], tmp);
                        child->Name[tmp] = '\0';
@@ -174,7 +176,8 @@ int SysFS_RegisterFile(const char *Path, const char *Data, int Length)
                                ent->Node.Size ++;
                        else
                                gSysFS_DriverInfo.RootNode.Size ++;
-                       Log_Log("SysFS", "Added directory '%s'", child->Name);
+                       Log_Log("SysFS", "Added directory '%.*s'", tmp, &Path[start]);
+                       Log_Log("SysFS", "Added directory '%.*s'", tmp, child->Name);
                }
                
                ent = child;
@@ -197,7 +200,7 @@ int SysFS_RegisterFile(const char *Path, const char *Data, int Length)
                        break;
        }
        if( child ) {
-               Log_Warning("SysFS", "'%s' is taken (in '%s')\n", &Path[start], Path);
+               Log_Warning("SysFS", "'%s' is taken (in '%s')", &Path[start], Path);
                return 0;
        }
        
@@ -276,14 +279,15 @@ int SysFS_RemoveFile(int ID)
        tSysFS_Ent      *ent, *parent, *prev;
        
        prev = NULL;
-       for( ent = gSysFS_FileList; ent; prev = ent, ent = ent->Next )
+       for( ent = gSysFS_FileList; ent; prev = ent, ent = ent->ListNext )
        {
                // It's a reverse sorted list
-               if(ent->Node.Inode < (Uint64)ID)        return 0;
-               if(ent->Node.Inode == (Uint64)ID)       break;
+               if(ent->Node.Inode <= (Uint64)ID)       break;
+       }
+       if( !ent || ent->Node.Inode != (Uint64)ID) {
+               Log_Notice("SysFS", "ID %i not present", ID);
+               return 0;
        }
-       
-       if(!ent)        return 0;
        
        // Set up for next part
        file = ent;
@@ -297,26 +301,37 @@ int SysFS_RemoveFile(int ID)
        file->Node.Size = 0;
        file->Node.ImplPtr = NULL;
        
-       // Search parent directory
-       for( ent = parent->Node.ImplPtr; ent; prev = ent, ent = ent->Next )
+       // Clean out of parent directory
+       while(parent)
        {
-               if( ent == file )       break;
-       }
-       if(!ent) {
-               Log_Warning("SysFS", "Bookkeeping Error: File in list, but not in directory");
-               return 0;
+               for( ent = parent->Node.ImplPtr; ent; prev = ent, ent = ent->Next )
+               {
+                       if( ent == file )       break;
+               }
+               if(!ent) {
+                       Log_Warning("SysFS", "Bookkeeping Error: File in list, but not in directory");
+                       return 0;
+               }
+               
+               // Remove from parent directory
+               if(prev)
+                       prev->Next = ent->Next;
+               else
+                       parent->Node.ImplPtr = ent->Next;
+
+               // Free if not in use
+               if(file->Node.ReferenceCount == 0) {
+                       free(file);
+               }
+
+               if( parent->Node.ImplPtr )
+                       break;
+
+               // Remove parent from the tree
+               file = parent;
+               parent = parent->Parent;
        }
        
-       // Remove from parent directory
-       if(prev)
-               prev->Next = ent->Next;
-       else
-               parent->Node.ImplPtr = ent->Next;
-       
-       // Free if not in use
-       if(file->Node.ReferenceCount == 0)
-               free(file);
-       
        return 1;
 }
 
@@ -344,7 +359,7 @@ int SysFS_Comm_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX])
  * \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, const char *Filename)
+tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename, Uint Flags)
 {
        tSysFS_Ent      *child = (tSysFS_Ent*)Node->ImplPtr;
        
@@ -360,7 +375,7 @@ tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, const char *Filename)
 /**
  * \brief Read from an exposed buffer
  */
-size_t SysFS_Comm_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer)
+size_t SysFS_Comm_ReadFile(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer, Uint Flags)
 {
        if( Offset > Node->Size )       return -1;
        if( Length > Node->Size )       Length = Node->Size;

UCC git Repository :: git.ucc.asn.au