From: John Hodge Date: Tue, 25 Jun 2013 01:01:36 +0000 (+0800) Subject: Modules/NTFS - Added _Read, working on _Close cleanup X-Git-Tag: rel0.15~407 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=56864b304e6838c84d3b94e55598b7adf4200a56;p=tpg%2Facess2.git Modules/NTFS - Added _Read, working on _Close cleanup --- diff --git a/KernelLand/Modules/Filesystems/NTFS/Makefile b/KernelLand/Modules/Filesystems/NTFS/Makefile index 22c16773..9c79f723 100644 --- a/KernelLand/Modules/Filesystems/NTFS/Makefile +++ b/KernelLand/Modules/Filesystems/NTFS/Makefile @@ -1,7 +1,7 @@ # # -OBJ = main.o dir.o +OBJ = main.o dir.o io.o NAME = NTFS -include ../Makefile.tpl diff --git a/KernelLand/Modules/Filesystems/NTFS/common.h b/KernelLand/Modules/Filesystems/NTFS/common.h index 80e5bbe0..e8dbe7d0 100644 --- a/KernelLand/Modules/Filesystems/NTFS/common.h +++ b/KernelLand/Modules/Filesystems/NTFS/common.h @@ -85,14 +85,19 @@ struct sNTFS_Attrib extern tVFS_NodeType gNTFS_DirType; extern tVFS_NodeType gNTFS_FileType; +extern void NTFS_Close(tVFS_Node *Node); +extern void NTFS_FreeNode(tVFS_Node *Node); extern int NTFS_int_ApplyUpdateSequence(void *Buf, size_t BufLen, const Uint16 *Sequence, size_t NumEntries); // -- MFT Access / Manipulation extern tNTFS_FILE_Header *NTFS_GetMFT(tNTFS_Disk *Disk, Uint32 MFTEntry); extern void NTFS_ReleaseMFT(tNTFS_Disk *Disk, Uint32 MFTEntry, tNTFS_FILE_Header *Entry); extern tNTFS_Attrib *NTFS_GetAttrib(tNTFS_Disk *Disk, Uint32 MFTEntry, int Type, const char *Name, int DesIdx); +extern void NTFS_FreeAttrib(tNTFS_Attrib *Attrib); extern size_t NTFS_ReadAttribData(tNTFS_Attrib *Attrib, Uint64 Offset, size_t Length, void *Buffer); // -- dir.c extern int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]); extern tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); +// -- io.c +extern size_t NTFS_ReadFile(tVFS_Node *Node, Uint64 Offset, size_t Length, void *Buffer, Uint Flags); #endif diff --git a/KernelLand/Modules/Filesystems/NTFS/dir.c b/KernelLand/Modules/Filesystems/NTFS/dir.c index 617d7db3..dc5fb7c3 100644 --- a/KernelLand/Modules/Filesystems/NTFS/dir.c +++ b/KernelLand/Modules/Filesystems/NTFS/dir.c @@ -319,8 +319,19 @@ tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) if( len == 0 ) break; tNTFS_IndexHeader *hdr = (void*)buf; + + if( memcmp(&hdr->Magic, "INDX", 4) != 0 ) { + Log_Notice("NTFS", "FindDir %p:%X:%x index magic bad %08x", + disk, Node->Inode, ofs / unit_len, hdr->Magic); + break; + } // Apply update sequence - ASSERT(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize <= len); + if(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize > len) { + Log_Notice("NTFS", "FindDir %p:%X:%x index update sequence out of buffer (%x+%x>%x)", + disk, Node->Inode, ofs / unit_len, + hdr->UpdateSequenceOfs, 2*hdr->UpdateSequenceSize, len); + break; + } NTFS_int_ApplyUpdateSequence(buf,len, (void*)(buf+hdr->UpdateSequenceOfs), hdr->UpdateSequenceSize); // Search //mftent = NTFS_BTreeSearch(len, (void*)buf, NTFS_BTreeSearch_CmpI30, name16len*2, name16); @@ -330,7 +341,7 @@ tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) ); } - if( !mftent ) { + if( !mftent || (mftent & (1ULL << 63)) ) { LEAVE('n'); return NULL; } diff --git a/KernelLand/Modules/Filesystems/NTFS/io.c b/KernelLand/Modules/Filesystems/NTFS/io.c new file mode 100644 index 00000000..d0f70889 --- /dev/null +++ b/KernelLand/Modules/Filesystems/NTFS/io.c @@ -0,0 +1,21 @@ +/* + * Acess2 - NTFS Driver + * - By John Hodge (thePowersGang) + * This file is published under the terms of the Acess licence. See the + * file COPYING for details. + * + * io.c + * - File Read/Write + */ +#define DEBUG 1 +#include "common.h" + +// == CODE === +size_t NTFS_ReadFile(tVFS_Node *Node, Uint64 Offset, size_t Length, void *Buffer, Uint Flags) +{ + tNTFS_File *File = (void*)Node; + + return NTFS_ReadAttribData(File->Data, Offset, Length, Buffer); +} + + diff --git a/KernelLand/Modules/Filesystems/NTFS/main.c b/KernelLand/Modules/Filesystems/NTFS/main.c index 8d6a724d..4586e12e 100644 --- a/KernelLand/Modules/Filesystems/NTFS/main.c +++ b/KernelLand/Modules/Filesystems/NTFS/main.c @@ -40,11 +40,12 @@ tVFS_NodeType gNTFS_DirType = { .TypeName = "NTFS-Dir", .ReadDir = NTFS_ReadDir, .FindDir = NTFS_FindDir, - .Close = NULL + .Close = NTFS_Close }; tVFS_NodeType gNTFS_FileType = { .TypeName = "NTFS-File", - .Close = NULL + .Read = NTFS_ReadFile, + .Close = NTFS_Close }; tNTFS_Disk gNTFS_Disks; @@ -177,6 +178,25 @@ void NTFS_Unmount(tVFS_Node *Node) free(Disk); } +void NTFS_Close(tVFS_Node *Node) +{ + tNTFS_Disk *Disk = Node->ImplPtr; + Inode_UncacheNode(Disk->InodeCache, Node->Inode); +} + +void NTFS_FreeNode(tVFS_Node *Node) +{ + if( Node->Type == &gNTFS_DirType ) { + tNTFS_Directory *Dir = (void*)Node; + NTFS_FreeAttrib(Dir->I30Root); + NTFS_FreeAttrib(Dir->I30Allocation); + } + else { + tNTFS_File *File = (void*)Node; + NTFS_FreeAttrib(File->Data); + } +} + int NTFS_int_ApplyUpdateSequence(void *Buffer, size_t BufLen, const Uint16 *Sequence, size_t NumEntries) { Uint16 cksum = Sequence[0]; @@ -387,6 +407,12 @@ tNTFS_Attrib *NTFS_GetAttrib(tNTFS_Disk *Disk, Uint32 MFTEntry, int Type, const return NULL; } +void NTFS_FreeAttrib(tNTFS_Attrib *Attrib) +{ + if( Attrib ) + free(Attrib); +} + size_t NTFS_ReadAttribData(tNTFS_Attrib *Attrib, Uint64 Offset, size_t Length, void *Buffer) { if( !Attrib ) @@ -465,17 +491,13 @@ void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry) tNTFS_FILE_Attrib *attr; int i; - tNTFS_FILE_Header *hdr = malloc( Disk->MFTRecSize ); + + tNTFS_FILE_Header *hdr = NTFS_GetMFT(Disk, Entry); if(!hdr) { Log_Warning("FS_NTFS", "malloc() fail!"); return ; } - VFS_ReadAt( Disk->FD, - Disk->MFTBase * Disk->ClusterSize + Entry * Disk->MFTRecSize, - Disk->MFTRecSize, - hdr); - Log_Debug("FS_NTFS", "MFT Entry #%i", Entry); Log_Debug("FS_NTFS", "- Magic = 0x%08x (%4C)", hdr->Magic, &hdr->Magic); Log_Debug("FS_NTFS", "- UpdateSequenceOfs = 0x%x", hdr->UpdateSequenceOfs); @@ -536,5 +558,5 @@ void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry) attr = (void*)( (tVAddr)attr + attr->Size ); } - free(hdr); + NTFS_ReleaseMFT(Disk, Entry, hdr); }