From: John Hodge Date: Tue, 22 Jun 2010 00:37:39 +0000 (+0800) Subject: Trying to fix the string corruption bug, working on NTFS driver X-Git-Tag: rel0.06~133 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=0b9aaf1442259bb14619b92e251f6535b3dc0dd1;p=tpg%2Facess2.git Trying to fix the string corruption bug, working on NTFS driver --- diff --git a/Kernel/arch/x86_64/Makefile b/Kernel/arch/x86_64/Makefile index be7c12d6..f539e250 100644 --- a/Kernel/arch/x86_64/Makefile +++ b/Kernel/arch/x86_64/Makefile @@ -3,12 +3,6 @@ # i386 Architecture Makefile # arch/i386/Makefile -# Assuming build machine is 32-bit ELF -#CC = gcc -#AS = nasm -#LD = ld -#OBJDUMP = objdump - MAX_CPUS := 4 CPPFLAGS := -DMAX_CPUS=$(MAX_CPUS) diff --git a/Kernel/arch/x86_64/include/arch.h b/Kernel/arch/x86_64/include/arch.h index 48d19ca7..41acd883 100644 --- a/Kernel/arch/x86_64/include/arch.h +++ b/Kernel/arch/x86_64/include/arch.h @@ -5,7 +5,7 @@ #ifndef _ARCH_H_ #define _ARCH_H_ -#include +//#include //#define KERNEL_BASE 0xFFFF8000##00000000 #define KERNEL_BASE 0xFFFFFFFF##80000000 #define BITS 64 diff --git a/Makefile.x86_64.cfg b/Makefile.x86_64.cfg index e2b7c31b..3116e74d 100644 --- a/Makefile.x86_64.cfg +++ b/Makefile.x86_64.cfg @@ -1,7 +1,7 @@ -CC = x86_64-linux-gnu-gcc -LD = ld -DISASM = objdump -d -M x86-64 +CC = x86_64-none-elf-gcc +LD = x86_64-none-elf-ld +DISASM = x86_64-none-elf-objdump -d -M x86-64 KERNEL_CFLAGS := -mcmodel=kernel -nostdlib DYNMOD_CFLAGS := -mcmodel=small -fPIC diff --git a/Modules/Filesystems/NTFS/common.h b/Modules/Filesystems/NTFS/common.h index ba25c18a..fb3fe357 100644 --- a/Modules/Filesystems/NTFS/common.h +++ b/Modules/Filesystems/NTFS/common.h @@ -4,11 +4,53 @@ #define _COMMON_H_ // === STRUCTURES === +/** + * In-memory representation of an NTFS Disk + */ typedef struct sNTFS_Disk { - + int FD; + Uint64 MFTOfs; + tVFS_Node RootNode; } tNTFS_Disk; +typedef struct sNTFS_BootSector +{ + // 0 + Uint8 Jump[3]; + Uint8 SystemID[8]; // = "NTFS " + Uint16 BytesPerSector; + Uint8 SectorsPerCluster; + + // 14 + Uint8 Unused[7]; + Uint8 MediaDescriptor; + Uint16 Unused2; + Uint16 SectorsPerTrack; + + Uint64 Unused3; + Uint32 Unknown; + + // 38 + 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 + // If either of these are -ve, the size can be obtained via + // SizeInBytes = 2^(-1 * Value) + Uint32 ClustersPerMFTRecord; + Uint32 ClustersPerIndexRecord; + + Uint64 SerialNumber; + + Uint8 Padding[515-offsetof(tNTFS_BootSector, Padding)]; + +} tNTFS_BootSector; + +/** + * FILE header, an entry in the MFT + */ typedef struct sNTFS_FILE_Header { Uint32 Magic; // 'FILE' @@ -48,6 +90,9 @@ typedef struct sNTFS_FILE_Header } tNTFS_FILE_Header; +/** + * File Attribute, follows the FILE header + */ typedef struct sNTFS_FILE_Attrib { Uint32 Type; // See eNTFS_FILE_Attribs diff --git a/Modules/Filesystems/NTFS/main.c b/Modules/Filesystems/NTFS/main.c index 3fdab017..5ace3333 100644 --- a/Modules/Filesystems/NTFS/main.c +++ b/Modules/Filesystems/NTFS/main.c @@ -37,11 +37,40 @@ int NTFS_Install(char **Arguments) */ tVFS_Node *NTFS_InitDevice(char *Device, char **Options) { - char *path, *host; tNTFS_Disk *disk; + tNTFS_BootSector bs; disk = malloc( sizeof(tNTFS_Disk) ); + disk->FD = VFS_Open(Device, VFS_OPENFLAG_READ); + if(!disk->FD) { + free(disk); + return NULL; + } + + VFS_ReadAt(disk->FD, 0, 512, &bs); + + disk->ClusterSize = bs.BytesPerSector * bs.SectorsPerCluster; + Log_Debug("NTFS", "Cluster Size = %i KiB", disk->ClusterSize/1024); + disk->MFTBase = bs.MFTStart; + Log_Debug("NTFS", "MFT Base = %i", disk->MFTBase); + + disk->RootNode.Inode = 5; // MFT Ent #5 is '.' + disk->RootNode.ImplPtr = disk; + + disk->RootNode.UID = 0; + disk->RootNode.GID = 0; + + disk->RootNode.NumACLs = 1; + disk->RootNode.ACLs = &gVFS_ACL_EveryoneRX; + + disk->RootNode.ReadDir = NTFS_ReadDir; + disk->RootNode.FindDir = NTFS_FindDir; + disk->RootNode.MkNod = NULL; + disk->RootNode.Link = NULL; + disk->RootNode.Relink = NULL; + disk->RootNode.Close = NULL; + return &disk->RootNode; }