From: John Hodge Date: Mon, 24 May 2010 14:06:08 +0000 (+0800) Subject: More work on Ext2 write (and fixed an error made earlier) X-Git-Tag: rel0.06~181 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=4f80abddbbc0e7237b0de6f150da4b8b43fbe499;p=tpg%2Facess2.git More work on Ext2 write (and fixed an error made earlier) --- diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 5260c857..d780e7e4 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 2161 +BUILD_NUM = 2164 diff --git a/Makefile.cfg b/Makefile.cfg index 3c8e9f6d..b2957a0d 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -38,4 +38,5 @@ MODULES += Display/BochsGA MODULES += Filesystems/Ext2 MODULES += Filesystems/FAT MODULES += IPStack -DYNMODS := USB/Core Interfaces/UDI +DYNMODS := USB/Core +MODULES += Interfaces/UDI diff --git a/Modules/Filesystems/Ext2/dir.c b/Modules/Filesystems/Ext2/dir.c index cf6fda44..08b413ef 100644 --- a/Modules/Filesystems/Ext2/dir.c +++ b/Modules/Filesystems/Ext2/dir.c @@ -16,7 +16,9 @@ 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); -tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeId, char *Name); + int Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, char *Name); +// --- Helpers --- +tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeId); // === CODE === /** @@ -126,7 +128,7 @@ tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *Filename) namebuf[ dirent.name_len ] = '\0'; // Cap off string // If it matches, create a node and return it if(strcmp(namebuf, Filename) == 0) - return Ext2_int_CreateNode( disk, dirent.inode, namebuf ); + return Ext2_int_CreateNode( disk, dirent.inode ); // Increment pointers ofs += dirent.rec_len; size -= dirent.rec_len; @@ -155,10 +157,31 @@ int Ext2_MkNod(tVFS_Node *Parent, char *Name, Uint Flags) { #if 0 tVFS_Node *child; - child = Ext2_int_AllocateNode(Parent, Flags); + Uint64 inodeNum; + tExt2_Inode inode; + inodeNum = Ext2_int_AllocateInode(Parent->ImplPtr, Parent->Inode); + + memset(&inode, 0, sizeof(tExt2_Inode)); + + // File type + inode.i_mode = 0664; + if( Flags & VFS_FFLAG_READONLY ) + inode.i_mode &= ~0222; + if( Flags & VFS_FFLAG_SYMLINK ) + inode.i_mode |= EXT2_S_IFLNK; + else if( Flags & VFS_FFLAG_DIRECTORY ) + inode.i_mode |= EXT2_S_IFDIR | 0111; + + inode.i_uid = Threads_GetUID(); + inode.i_gid = Threads_GetGID(); + inode.i_ctime = + inode.i_mtime = + inode.i_atime = now() / 1000; + + child = Ext2_int_CreateNode(Parent->ImplPtr, inodeNum); return Ext2_Link(Parent, child, Name); #else - return 0; + return 1; #endif } @@ -176,10 +199,10 @@ int Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, char *Name) // ---- INTERNAL FUNCTIONS ---- /** - * \fn vfs_node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID, char *Name) + * \fn vfs_node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID) * \brief Create a new VFS Node */ -tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID, char *Name) +tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID) { tExt2_Inode inode; tVFS_Node retNode; @@ -227,6 +250,7 @@ tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID, char *Name) retNode.FindDir = Ext2_FindDir; retNode.MkNod = Ext2_MkNod; //retNode.Relink = Ext2_Relink; + retNode.Link = Ext2_Link; retNode.Flags = VFS_FFLAG_DIRECTORY; break; // Unknown, Write protect and hide it to be safe @@ -235,9 +259,6 @@ tVFS_Node *Ext2_int_CreateNode(tExt2_Disk *Disk, Uint InodeID, char *Name) break; } - // Check if the file should be hidden - //if(Name[0] == '.') retNode.Flags |= VFS_FFLAG_HIDDEN; - // Set Timestamps retNode.ATime = inode.i_atime * 1000; retNode.MTime = inode.i_mtime * 1000; diff --git a/Modules/Filesystems/Ext2/ext2.c b/Modules/Filesystems/Ext2/ext2.c index ac3d7e5c..aa15e103 100644 --- a/Modules/Filesystems/Ext2/ext2.c +++ b/Modules/Filesystems/Ext2/ext2.c @@ -320,15 +320,17 @@ void Ext2_int_UpdateSuperblock(tExt2_Disk *Disk) if(ngrp <= 1) return; VFS_WriteAt(Disk->FD, 1*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock); + #define INT_MAX (((long long int)1<<(sizeof(int)*8))-1) + // Powers of 3 - for( i = 3; i < ngrp; i *= 3 ) + for( i = 3; i < ngrp && i < INT_MAX; i *= 3 ) VFS_WriteAt(Disk->FD, i*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock); // Powers of 5 - for( i = 5; i < ngrp; i *= 5 ) + for( i = 5; i < ngrp && i < INT_MAX/5; i *= 5 ) VFS_WriteAt(Disk->FD, i*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock); // Powers of 7 - for( i = 7; i < ngrp; i *= 7 ) + for( i = 7; i < ngrp && i < INT_MAX/7; i *= 7 ) VFS_WriteAt(Disk->FD, i*bpg*Disk->BlockSize, 1024, &Disk->SuperBlock); } diff --git a/Modules/Filesystems/Ext2/ext2_common.h b/Modules/Filesystems/Ext2/ext2_common.h index 877b71d3..290b273b 100644 --- a/Modules/Filesystems/Ext2/ext2_common.h +++ b/Modules/Filesystems/Ext2/ext2_common.h @@ -38,6 +38,7 @@ extern int Ext2_int_WriteInode(tExt2_Disk *Disk, Uint32 InodeId, tExt2_Inode *In extern char *Ext2_ReadDir(tVFS_Node *Node, int Pos); extern tVFS_Node *Ext2_FindDir(tVFS_Node *Node, char *FileName); extern int Ext2_MkNod(tVFS_Node *Node, char *Name, Uint Flags); +extern int Ext2_Link(tVFS_Node *Parent, tVFS_Node *Node, char *Name); // --- Read --- extern Uint64 Ext2_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer); // --- Write ---