3 * By John Hodge (thePowersGang)
15 extern char *NTFS_ReadDir(tVFS_Node *Node, int Pos);
16 extern tVFS_Node *NTFS_FindDir(tVFS_Node *Node, char *Name);
19 int NTFS_Install(char **Arguments);
20 tVFS_Node *NTFS_InitDevice(char *Devices, char **Options);
21 void NTFS_Unmount(tVFS_Node *Node);
22 void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry);
25 MODULE_DEFINE(0, 0x0A /*v0.1*/, FS_NTFS, NTFS_Install, NULL);
26 tVFS_Driver gNTFS_FSInfo = {"ntfs", 0, NTFS_InitDevice, NTFS_Unmount, NULL};
28 tNTFS_Disk gNTFS_Disks;
32 * \brief Installs the NTFS driver
34 int NTFS_Install(char **Arguments)
36 VFS_AddDriver( &gNTFS_FSInfo );
41 * \brief Mount a NTFS volume
43 tVFS_Node *NTFS_InitDevice(char *Device, char **Options)
48 disk = malloc( sizeof(tNTFS_Disk) );
50 disk->FD = VFS_Open(Device, VFS_OPENFLAG_READ);
56 Log_Debug("FS_NTFS", "&bs = %p", &bs);
57 VFS_ReadAt(disk->FD, 0, 512, &bs);
59 Log_Debug("FS_NTFS", "Jump = %02x%02x%02x",
63 Log_Debug("FS_NTFS", "SystemID = %02x%02x%02x%02x%02x%02x%02x%02x (%8C)",
64 bs.SystemID[0], bs.SystemID[1], bs.SystemID[2], bs.SystemID[3],
65 bs.SystemID[4], bs.SystemID[5], bs.SystemID[6], bs.SystemID[7],
68 Log_Debug("FS_NTFS", "BytesPerSector = %i", bs.BytesPerSector);
69 Log_Debug("FS_NTFS", "SectorsPerCluster = %i", bs.SectorsPerCluster);
70 Log_Debug("FS_NTFS", "MediaDescriptor = 0x%x", bs.MediaDescriptor);
71 Log_Debug("FS_NTFS", "SectorsPerTrack = %i", bs.SectorsPerTrack);
72 Log_Debug("FS_NTFS", "Heads = %i", bs.Heads);
73 Log_Debug("FS_NTFS", "TotalSectorCount = 0x%llx", bs.TotalSectorCount);
74 Log_Debug("FS_NTFS", "MFTStart = 0x%llx", bs.MFTStart);
75 Log_Debug("FS_NTFS", "MFTMirrorStart = 0x%llx", bs.MFTMirrorStart);
76 Log_Debug("FS_NTFS", "ClustersPerMFTRecord = %i", bs.ClustersPerMFTRecord);
77 Log_Debug("FS_NTFS", "ClustersPerIndexRecord = %i", bs.ClustersPerIndexRecord);
78 Log_Debug("FS_NTFS", "ClustersPerIndexRecord = %i", bs.ClustersPerIndexRecord);
79 Log_Debug("FS_NTFS", "SerialNumber = 0x%llx", bs.SerialNumber);
81 disk->ClusterSize = bs.BytesPerSector * bs.SectorsPerCluster;
82 Log_Debug("NTFS", "Cluster Size = %i KiB", disk->ClusterSize/1024);
83 disk->MFTBase = bs.MFTStart;
84 Log_Debug("NTFS", "MFT Base = %i", disk->MFTBase);
85 Log_Debug("NTFS", "TotalSectorCount = 0x%x", bs.TotalSectorCount);
87 disk->RootNode.Inode = 5; // MFT Ent #5 is filesystem root
88 disk->RootNode.ImplPtr = disk;
90 disk->RootNode.UID = 0;
91 disk->RootNode.GID = 0;
93 disk->RootNode.NumACLs = 1;
94 disk->RootNode.ACLs = &gVFS_ACL_EveryoneRX;
96 disk->RootNode.ReadDir = NTFS_ReadDir;
97 disk->RootNode.FindDir = NTFS_FindDir;
98 disk->RootNode.MkNod = NULL;
99 disk->RootNode.Link = NULL;
100 disk->RootNode.Relink = NULL;
101 disk->RootNode.Close = NULL;
103 NTFS_DumpEntry(disk, 5);
105 return &disk->RootNode;
109 * \brief Unmount an NTFS Disk
111 void NTFS_Unmount(tVFS_Node *Node)
117 * \brief Dumps a MFT Entry
119 void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry)
121 void *buf = malloc( Disk->ClusterSize );
122 tNTFS_FILE_Header *hdr = buf;
125 Log_Warning("FS_NTFS", "malloc() fail!");
129 VFS_ReadAt( Disk->FD, Disk->MFTBase*Disk->ClusterSize, Disk->ClusterSize, buf);
131 Log_Debug("FS_NTFS", "MFT Entry #%i", Entry);
132 Log_Debug("FS_NTFS", "- Magic = 0x%08x (%4C)", hdr->Magic, &hdr->Magic);
133 Log_Debug("FS_NTFS", "- UpdateSequenceOfs = 0x%x", hdr->UpdateSequenceOfs);
134 Log_Debug("FS_NTFS", "- UpdateSequenceSize = 0x%x", hdr->UpdateSequenceSize);
135 Log_Debug("FS_NTFS", "- LSN = 0x%x", hdr->LSN);
136 Log_Debug("FS_NTFS", "- SequenceNumber = %i", hdr->SequenceNumber);
137 Log_Debug("FS_NTFS", "- HardLinkCount = %i", hdr->HardLinkCount);
138 Log_Debug("FS_NTFS", "- FirstAttribOfs = 0x%x", hdr->FirstAttribOfs);
139 Log_Debug("FS_NTFS", "- Flags = 0x%x", hdr->Flags);
140 Log_Debug("FS_NTFS", "- RecordSize = 0x%x", hdr->RecordSize);
141 Log_Debug("FS_NTFS", "- RecordSpace = 0x%x", hdr->RecordSpace);
142 Log_Debug("FS_NTFS", "- Reference = 0x%llx", hdr->Reference);
143 Log_Debug("FS_NTFS", "- NextAttribID = 0x%04x", hdr->NextAttribID);