Implemented basic disk write support in EXT2.
[tpg/acess2.git] / Kernel / vfs / fs / ext2.c
index 0c4b527..da941f7 100644 (file)
@@ -270,18 +270,25 @@ Uint64 Ext2_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
        Uint64  allocSize;\r
         int    bNewBlocks = 0;\r
        \r
+       Debug_HexDump("Ext2_Write", Buffer, Length);\r
+       \r
        Ext2_int_GetInode(Node, &inode);\r
        \r
-       // Round size up to block size\r
-       // block size is a power of two, so this will work\r
+       // Get the ammount of space already allocated\r
+       // - Round size up to block size\r
+       // - block size is a power of two, so this will work\r
        allocSize = (inode.i_size + disk->BlockSize) & ~(disk->BlockSize-1);\r
+       \r
+       // Are we writing to inside the allocated space?\r
        if( Offset < allocSize )\r
        {\r
+               // Will we go out of it?\r
                if(Offset + Length > allocSize) {\r
                        bNewBlocks = 1;\r
                        retLen = allocSize - Offset;\r
                } else\r
                        retLen = Length;\r
+               \r
                // Within the allocated space\r
                block = Offset / disk->BlockSize;\r
                Offset %= disk->BlockSize;\r
@@ -290,7 +297,7 @@ Uint64 Ext2_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                // Write only block (if only one)\r
                if(Offset + retLen <= disk->BlockSize) {\r
                        VFS_WriteAt(disk->FD, base+Offset, retLen, Buffer);\r
-                       if(bNewBlocks)  return Length;\r
+                       if(!bNewBlocks) return Length;\r
                        goto addBlocks; // Ugh! A goto, but it seems unavoidable\r
                }\r
                \r
@@ -313,7 +320,7 @@ Uint64 Ext2_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                // Write last block\r
                base = Ext2_int_GetBlockAddr(disk, inode.i_block, block);\r
                VFS_WriteAt(disk->FD, base, retLen, Buffer);\r
-               if(bNewBlocks)  return Length;  // Writing in only allocated space\r
+               if(!bNewBlocks) return Length;  // Writing in only allocated space\r
        }\r
        \r
 addBlocks:\r

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