From: John Hodge Date: Sun, 1 Aug 2010 11:46:43 +0000 (+0800) Subject: Cleanup (NTFS fiddling and fixed debug hexdump) X-Git-Tag: rel0.06~67 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=6f1c621ed4d24ddbdc863cd5ef684e919c8f8b55;p=tpg%2Facess2.git Cleanup (NTFS fiddling and fixed debug hexdump) --- diff --git a/Kernel/debug.c b/Kernel/debug.c index 3a776102..8533a9e8 100644 --- a/Kernel/debug.c +++ b/Kernel/debug.c @@ -397,9 +397,10 @@ void Debug_HexDump(char *Header, void *Data, Uint Length) Debug_Puts(1, Header); LogF(" (Hexdump of %p)\r\n", Data); + #define CH(n) ((' '<=cdat[(n)]&&cdat[(n)]<=0x7F) ? cdat[(n)] : '.') + while(Length >= 16) { - #define CH(n) ((' '<=cdat[(n)]&&cdat[(n)]<=0x7F) ? cdat[(n)] : '.') Log("%04x: %02x %02x %02x %02x %02x %02x %02x %02x" " %02x %02x %02x %02x %02x %02x %02x %02x" " %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c", @@ -414,14 +415,22 @@ void Debug_HexDump(char *Header, void *Data, Uint Length) pos += 16; } - LogF("Log: %04x: ", pos); - while(Length) { - Uint byte = *cdat; - LogF("%02x ", byte); - Length--; - cdat ++; + int i ; + LogF("Log: %04x: ", pos); + for(i = 0; i < Length; i ++) + { + LogF("%02x ", cdat[i]); + } + for( ; i < 16; i ++) LogF(" "); + LogF(" "); + for(i = 0; i < Length; i ++) + { + if( i == 8 ) LogF(" "); + LogF("%c", CH(i)); + } } + Debug_Putchar('\r'); Debug_Putchar('\n'); } diff --git a/Modules/Filesystems/NTFS/common.h b/Modules/Filesystems/NTFS/common.h index a51c7d1e..6ed0ac6c 100644 --- a/Modules/Filesystems/NTFS/common.h +++ b/Modules/Filesystems/NTFS/common.h @@ -23,6 +23,7 @@ typedef struct sNTFS_Disk int ClusterSize; Uint64 MFTBase; + Uint32 MFTRecSize; tVFS_Node RootNode; } tNTFS_Disk; @@ -35,26 +36,29 @@ typedef struct sNTFS_BootSector Uint16 BytesPerSector; Uint8 SectorsPerCluster; - // 14 + // 0xE Uint8 Unused[7]; Uint8 MediaDescriptor; Uint16 Unused2; Uint16 SectorsPerTrack; Uint16 Heads; + // 0x1C Uint64 Unused3; - Uint32 HEad; + Uint32 Unkown; // Usually 0x00800080 (according to Linux docs) - // 38 + // 0x28 Uint64 TotalSectorCount; // Size of volume in sectors Uint64 MFTStart; // Logical Cluster Number of Cluster 0 of MFT Uint64 MFTMirrorStart; // Logical Cluster Number of Cluster 0 of MFT Backup - // 60 + // 0x40 // If either of these are -ve, the size can be obtained via // SizeInBytes = 2^(-1 * Value) - Uint32 ClustersPerMFTRecord; - Uint32 ClustersPerIndexRecord; + Sint8 ClustersPerMFTRecord; + Uint8 Unused4[3]; + Sint8 ClustersPerIndexRecord; + Uint8 Unused5[3]; Uint64 SerialNumber; diff --git a/Modules/Filesystems/NTFS/main.c b/Modules/Filesystems/NTFS/main.c index 175e6167..5cdcc667 100644 --- a/Modules/Filesystems/NTFS/main.c +++ b/Modules/Filesystems/NTFS/main.c @@ -75,7 +75,6 @@ tVFS_Node *NTFS_InitDevice(char *Device, char **Options) Log_Debug("FS_NTFS", "MFTMirrorStart = 0x%llx", bs.MFTMirrorStart); Log_Debug("FS_NTFS", "ClustersPerMFTRecord = %i", bs.ClustersPerMFTRecord); Log_Debug("FS_NTFS", "ClustersPerIndexRecord = %i", bs.ClustersPerIndexRecord); - Log_Debug("FS_NTFS", "ClustersPerIndexRecord = %i", bs.ClustersPerIndexRecord); Log_Debug("FS_NTFS", "SerialNumber = 0x%llx", bs.SerialNumber); disk->ClusterSize = bs.BytesPerSector * bs.SectorsPerCluster; @@ -84,6 +83,13 @@ tVFS_Node *NTFS_InitDevice(char *Device, char **Options) Log_Debug("NTFS", "MFT Base = %i", disk->MFTBase); Log_Debug("NTFS", "TotalSectorCount = 0x%x", bs.TotalSectorCount); + if( bs.ClustersPerMFTRecord < 0 ) { + disk->MFTRecSize = 1 << (-bs.ClustersPerMFTRecord); + } + else { + disk->MFTRecSize = bs.ClustersPerMFTRecord * disk->ClusterSize; + } + disk->RootNode.Inode = 5; // MFT Ent #5 is filesystem root disk->RootNode.ImplPtr = disk; @@ -118,15 +124,20 @@ void NTFS_Unmount(tVFS_Node *Node) */ void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry) { - void *buf = malloc( Disk->ClusterSize ); + void *buf = malloc( Disk->MFTRecSize ); tNTFS_FILE_Header *hdr = buf; + tNTFS_FILE_Attrib *attr; + int i; if(!buf) { Log_Warning("FS_NTFS", "malloc() fail!"); return ; } - VFS_ReadAt( Disk->FD, Disk->MFTBase*Disk->ClusterSize, Disk->ClusterSize, buf); + VFS_ReadAt( Disk->FD, + Disk->MFTBase * Disk->ClusterSize + Entry * Disk->MFTRecSize, + Disk->MFTRecSize, + buf); Log_Debug("FS_NTFS", "MFT Entry #%i", Entry); Log_Debug("FS_NTFS", "- Magic = 0x%08x (%4C)", hdr->Magic, &hdr->Magic); @@ -142,5 +153,42 @@ void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry) Log_Debug("FS_NTFS", "- Reference = 0x%llx", hdr->Reference); Log_Debug("FS_NTFS", "- NextAttribID = 0x%04x", hdr->NextAttribID); + attr = (void*)( (char*)hdr + hdr->FirstAttribOfs ); + i = 0; + while( (tVAddr)attr < (tVAddr)hdr + hdr->RecordSize ) + { + if(attr->Type == 0xFFFFFFFF) break; + Log_Debug("FS_NTFS", "- Attribute %i", i ++); + Log_Debug("FS_NTFS", " > Type = 0x%x", attr->Type); + Log_Debug("FS_NTFS", " > Size = 0x%x", attr->Size); + Log_Debug("FS_NTFS", " > ResidentFlag = 0x%x", attr->ResidentFlag); + Log_Debug("FS_NTFS", " > NameLength = %i", attr->NameLength); + Log_Debug("FS_NTFS", " > NameOffset = 0x%x", attr->NameOffset); + Log_Debug("FS_NTFS", " > Flags = 0x%x", attr->Flags); + Log_Debug("FS_NTFS", " > AttributeID = 0x%x", attr->AttributeID); + if( !attr->ResidentFlag ) { + Log_Debug("FS_NTFS", " > AttribLen = 0x%x", attr->Resident.AttribLen); + Log_Debug("FS_NTFS", " > AttribOfs = 0x%x", attr->Resident.AttribOfs); + Log_Debug("FS_NTFS", " > IndexedFlag = 0x%x", attr->Resident.IndexedFlag); + Log_Debug("FS_NTFS", " > Name = '%*C'", attr->NameLength, attr->Resident.Name); + Debug_HexDump("FS_NTFS", + (void*)( (tVAddr)attr + attr->Resident.AttribOfs ), + attr->Resident.AttribLen + ); + } + else { + Log_Debug("FS_NTFS", " > StartingVCN = 0x%llx", attr->NonResident.StartingVCN); + Log_Debug("FS_NTFS", " > LastVCN = 0x%llx", attr->NonResident.LastVCN); + Log_Debug("FS_NTFS", " > DataRunOfs = 0x%x", attr->NonResident.DataRunOfs); + Log_Debug("FS_NTFS", " > CompressionUnitSize = 0x%x", attr->NonResident.CompressionUnitSize); + Log_Debug("FS_NTFS", " > AllocatedSize = 0x%llx", attr->NonResident.AllocatedSize); + Log_Debug("FS_NTFS", " > RealSize = 0x%llx", attr->NonResident.RealSize); + Log_Debug("FS_NTFS", " > InitiatedSize = 0x%llx", attr->NonResident.InitiatedSize); + Log_Debug("FS_NTFS", " > Name = '%*C'", attr->NameLength, attr->NonResident.Name); + } + + attr = (void*)( (tVAddr)attr + attr->Size ); + } + free(buf); }