# 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)
#ifndef _ARCH_H_
#define _ARCH_H_
-#include <stdint.h>
+//#include <stdint.h>
//#define KERNEL_BASE 0xFFFF8000##00000000
#define KERNEL_BASE 0xFFFFFFFF##80000000
#define BITS 64
-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
#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'
} tNTFS_FILE_Header;
+/**
+ * File Attribute, follows the FILE header
+ */
typedef struct sNTFS_FILE_Attrib
{
Uint32 Type; // See eNTFS_FILE_Attribs
*/
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;
}