From: John Hodge Date: Tue, 25 Jun 2013 00:02:24 +0000 (+0800) Subject: Modules/NTFS - Implimented update sequences, fixes bad filenames X-Git-Tag: rel0.15~408 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=2c6ec285c9fd7a3034942e724708e2e65d904e4c;p=tpg%2Facess2.git Modules/NTFS - Implimented update sequences, fixes bad filenames --- diff --git a/KernelLand/Modules/Filesystems/NTFS/common.h b/KernelLand/Modules/Filesystems/NTFS/common.h index db117a6e..80e5bbe0 100644 --- a/KernelLand/Modules/Filesystems/NTFS/common.h +++ b/KernelLand/Modules/Filesystems/NTFS/common.h @@ -85,6 +85,7 @@ struct sNTFS_Attrib extern tVFS_NodeType gNTFS_DirType; extern tVFS_NodeType gNTFS_FileType; +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); diff --git a/KernelLand/Modules/Filesystems/NTFS/dir.c b/KernelLand/Modules/Filesystems/NTFS/dir.c index 17785fb7..617d7db3 100644 --- a/KernelLand/Modules/Filesystems/NTFS/dir.c +++ b/KernelLand/Modules/Filesystems/NTFS/dir.c @@ -76,6 +76,9 @@ int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]) // Check allocation struct sNTFS_IndexHeader *hdr = (void*)buf; ASSERT(hdr->EntriesOffset + 0x18 < len); + // Apply update sequence + ASSERT(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize <= len); + NTFS_int_ApplyUpdateSequence(buf,len, (void*)(buf+hdr->UpdateSequenceOfs), hdr->UpdateSequenceSize); size_t ofs = hdr->EntriesOffset + 0x18; ent = NTFS_int_IterateIndex(buf + ofs, len - ofs, &Pos); vcn ++; @@ -163,6 +166,10 @@ void NTFS_int_DumpIndex(tNTFS_Attrib *Allocation, Uint AttribID) while( (len = NTFS_ReadAttribData(Allocation, vcn*block_size, block_size, buf)) ) { struct sNTFS_IndexHeader *hdr = (void*)buf; + // Apply update sequence + ASSERT(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize <= len); + NTFS_int_ApplyUpdateSequence(buf,len, (void*)(buf+hdr->UpdateSequenceOfs), hdr->UpdateSequenceSize); + LOG("VCN %x: Ofs=%x, Size=%x", vcn, hdr->EntriesOffset, hdr->EntriesSize); if( hdr->ThisVCN != vcn ) { @@ -312,6 +319,10 @@ tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) if( len == 0 ) break; tNTFS_IndexHeader *hdr = (void*)buf; + // Apply update sequence + ASSERT(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize <= len); + NTFS_int_ApplyUpdateSequence(buf,len, (void*)(buf+hdr->UpdateSequenceOfs), hdr->UpdateSequenceSize); + // Search //mftent = NTFS_BTreeSearch(len, (void*)buf, NTFS_BTreeSearch_CmpI30, name16len*2, name16); mftent = NTFS_BTreeSearch( len-(hdr->EntriesOffset+0x18), buf+hdr->EntriesOffset+0x18, diff --git a/KernelLand/Modules/Filesystems/NTFS/main.c b/KernelLand/Modules/Filesystems/NTFS/main.c index 5e1c2aeb..8d6a724d 100644 --- a/KernelLand/Modules/Filesystems/NTFS/main.c +++ b/KernelLand/Modules/Filesystems/NTFS/main.c @@ -177,9 +177,33 @@ void NTFS_Unmount(tVFS_Node *Node) free(Disk); } +int NTFS_int_ApplyUpdateSequence(void *Buffer, size_t BufLen, const Uint16 *Sequence, size_t NumEntries) +{ + Uint16 cksum = Sequence[0]; + LOG("cksum = %04x", cksum); + Sequence ++; + Uint16 *buf16 = Buffer; + for( int i = 0; i < NumEntries-1; i ++ ) + { + size_t ofs = (i+1)*512 - 2; + if( ofs + 2 > BufLen ) { + // Oops? + Log_Warning("NTFS", "%x > %x", ofs+2, BufLen); + } + Uint16 *cksum_word = &buf16[ofs/2]; + LOG("[%i]: %04x => %04x", i, Sequence[i], *cksum_word); + if( *cksum_word != cksum ) { + Log_Warning("NTFS", "Disk corruption detected"); + return 1; + } + *cksum_word = Sequence[i]; + } + return 0; +} + tNTFS_FILE_Header *NTFS_GetMFT(tNTFS_Disk *Disk, Uint32 MFTEntry) { - void *ret = malloc( Disk->MFTRecSize ); + tNTFS_FILE_Header *ret = malloc( Disk->MFTRecSize ); if(!ret) { Log_Warning("FS_NTFS", "malloc() fail!"); return NULL; @@ -195,7 +219,11 @@ tNTFS_FILE_Header *NTFS_GetMFT(tNTFS_Disk *Disk, Uint32 MFTEntry) else { NTFS_ReadAttribData(Disk->MFTDataAttr, MFTEntry * Disk->MFTRecSize, Disk->MFTRecSize, ret); } - + + NTFS_int_ApplyUpdateSequence(ret, Disk->MFTRecSize, + (void*)((char*)ret + ret->UpdateSequenceOfs), ret->UpdateSequenceSize + ); + return ret; }