Kernel - Slight reworks to timer code
[tpg/acess2.git] / Modules / Filesystems / Ext2 / dir.c
index b0d8531..5eb476f 100644 (file)
 
 // === PROTOTYPES ===
 char   *Ext2_ReadDir(tVFS_Node *Node, int Pos);
-tVFS_Node      *Ext2_FindDir(tVFS_Node *Node, char *FileName);
- int   Ext2_MkNod(tVFS_Node *Node, char *Name, Uint Flags);
- int   Ext2_Relink(tVFS_Node *Node, char *OldName, char *NewName);
- int   Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, char *Name);
+tVFS_Node      *Ext2_FindDir(tVFS_Node *Node, const char *FileName);
+ int   Ext2_MkNod(tVFS_Node *Node, const char *Name, Uint Flags);
+ int   Ext2_Relink(tVFS_Node *Node, const char *OldName, const char *NewName);
+ int   Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, const char *Name);
 // --- Helpers ---
 tVFS_Node      *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeId);
 
+// === GLOBALS ===
+tVFS_NodeType  gExt2_DirType = {
+       .TypeName = "ext2-dir",
+       .ReadDir = Ext2_ReadDir,
+       .FindDir = Ext2_FindDir,
+       .MkNod = Ext2_MkNod,
+       .Relink = Ext2_Relink,
+       .Link = Ext2_Link,
+       .Close = Ext2_CloseFile
+       };
+tVFS_NodeType  gExt2_FileType = {
+       .TypeName = "ext2-file",
+       .Read = Ext2_Read,
+       .Write = Ext2_Write,
+       .Close = Ext2_CloseFile
+       };
+
 // === CODE ===
 /**
  * \brief Reads a directory entry
@@ -34,7 +51,8 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos)
        tExt2_Inode     inode;
        tExt2_DirEnt    dirent;
        Uint64  Base;   // Block's Base Address
-        int    block = 0, ofs = 0;
+        int    block = 0;
+       Uint    ofs = 0;
         int    entNum = 0;
        tExt2_Disk      *disk = Node->ImplPtr;
        Uint    size;
@@ -102,13 +120,14 @@ char *Ext2_ReadDir(tVFS_Node *Node, int Pos)
  * \param Filename     Name of wanted file
  * \return VFS Node of file
  */
-tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *Filename)
+tVFS_Node *Ext2_FindDir(tVFS_Node *Node, const char *Filename)
 {
        tExt2_Disk      *disk = Node->ImplPtr;
        tExt2_Inode     inode;
        tExt2_DirEnt    dirent;
        Uint64  Base;   // Block's Base Address
-        int    block = 0, ofs = 0;
+        int    block = 0;
+       Uint    ofs = 0;
         int    entNum = 0;
        Uint    size;
         int    filenameLen = strlen(Filename);
@@ -149,10 +168,10 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *Filename)
 }
 
 /**
- * \fn int Ext2_MkNod(tVFS_Node *Parent, char *Name, Uint Flags)
+ * \fn int Ext2_MkNod(tVFS_Node *Parent, const char *Name, Uint Flags)
  * \brief Create a new node
  */
-int Ext2_MkNod(tVFS_Node *Parent, char *Name, Uint Flags)
+int Ext2_MkNod(tVFS_Node *Parent, const char *Name, Uint Flags)
 {
        #if 0
        tVFS_Node       *child;
@@ -191,7 +210,7 @@ int Ext2_MkNod(tVFS_Node *Parent, char *Name, Uint Flags)
  * \param NewName      New name for file
  * \return Boolean Failure - See ::tVFS_Node.Relink for info
  */
-int Ext2_Relink(tVFS_Node *Node, char *OldName, char *NewName)
+int Ext2_Relink(tVFS_Node *Node, const char *OldName, const char *NewName)
 {
        return 1;
 }
@@ -203,7 +222,7 @@ int Ext2_Relink(tVFS_Node *Node, char *OldName, char *NewName)
  * \param Name New name for the node
  * \return Boolean Failure - See ::tVFS_Node.Link for info
  */
-int Ext2_Link(tVFS_Node *Node, tVFS_Node *Child, char *Name)
+int Ext2_Link(tVFS_Node *Node, tVFS_Node *Child, const char *Name)
 {      
        #if 0
        tExt2_Disk      *disk = Node->ImplPtr;
@@ -281,7 +300,7 @@ int Ext2_Link(tVFS_Node *Node, tVFS_Node *Child, char *Name)
                        BLOCK_DIR_OFS(Node->Data, block) = nEntries;
                        block ++;
                        ofs = 0;
-                       base = Ext2_int_GetBlockAddr(disk, inode.i_blocks, block);
+                       base = Ext2_int_GetBlockAddr(disk, inode.i_block, block);
                        VFS_ReadAt( disk->FD, base, disk->BlockSize, blockData );
                }
        }
@@ -289,7 +308,7 @@ int Ext2_Link(tVFS_Node *Node, tVFS_Node *Child, char *Name)
        // Check if a free slot was found
        if( bestMatch >= 0 ) {
                // Read-Modify-Write
-               bestBlock = Ext2_int_GetBlockAddr(disk, inode.i_blocks, bestBlock);
+               bestBlock = Ext2_int_GetBlockAddr(disk, inode.i_block, bestBlock);
                if( block > 0 )
                        bestMatch = BLOCK_DIR_OFS(Node->Data, bestBlock);
                VFS_ReadAt( disk->FD, base, disk->BlockSize, blockData );
@@ -343,9 +362,7 @@ tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID)
        retNode.ACLs = VFS_UnixToAcessACL(inode.i_mode & 0777, inode.i_uid, inode.i_gid);
        
        //  Set Function Pointers
-       retNode.Read = Ext2_Read;
-       retNode.Write = Ext2_Write;
-       retNode.Close = Ext2_CloseFile;
+       retNode.Type = &gExt2_FileType;
        
        switch(inode.i_mode & EXT2_S_IFMT)
        {
@@ -360,11 +377,7 @@ tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID)
                break;
        // Directory
        case EXT2_S_IFDIR:
-               retNode.ReadDir = Ext2_ReadDir;
-               retNode.FindDir = Ext2_FindDir;
-               retNode.MkNod = Ext2_MkNod;
-               retNode.Relink = Ext2_Relink;
-               retNode.Link = Ext2_Link;
+               retNode.Type = &gExt2_DirType;
                retNode.Flags = VFS_FFLAG_DIRECTORY;
                retNode.Data = calloc( sizeof(Uint16), DivUp(retNode.Size, Disk->BlockSize) );
                break;

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