d316f00cf8af3f5e50e9ceb1fec9b309b106561a
[tpg/acess2.git] / Modules / Filesystems / NTFS / main.c
1 /*
2  * Acess2 - NTFS Driver
3  * By John Hodge (thePowersGang)
4  *
5  * main.c - Driver core
6  */
7 #define DEBUG   1
8 #define VERBOSE 0
9 #include <acess.h>
10 #include <vfs.h>
11 #include "common.h"
12 #include <modules.h>
13
14 // === IMPORTS ===
15 extern char     *NTFS_ReadDir(tVFS_Node *Node, int Pos);
16 extern tVFS_Node        *NTFS_FindDir(tVFS_Node *Node, char *Name);
17
18 // === PROTOTYPES ===
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);
23
24 // === GLOBALS ===
25 MODULE_DEFINE(0, 0x0A /*v0.1*/, FS_NTFS, NTFS_Install, NULL);
26 tVFS_Driver     gNTFS_FSInfo = {"ntfs", 0, NTFS_InitDevice, NTFS_Unmount, NULL};
27
28 tNTFS_Disk      gNTFS_Disks;
29
30 // === CODE ===
31 /**
32  * \brief Installs the NTFS driver
33  */
34 int NTFS_Install(char **Arguments)
35 {
36         VFS_AddDriver( &gNTFS_FSInfo );
37         return 0;
38 }
39
40 /**
41  * \brief Mount a NTFS volume
42  */
43 tVFS_Node *NTFS_InitDevice(char *Device, char **Options)
44 {
45         tNTFS_Disk      *disk;
46         tNTFS_BootSector        bs;
47         
48         disk = malloc( sizeof(tNTFS_Disk) );
49         
50         disk->FD = VFS_Open(Device, VFS_OPENFLAG_READ);
51         if(!disk->FD) {
52                 free(disk);
53                 return NULL;
54         }
55         
56         Log_Debug("FS_NTFS", "&bs = %p", &bs);
57         VFS_ReadAt(disk->FD, 0, 512, &bs);
58         
59         Log_Debug("FS_NTFS", "Jump = %02x%02x%02x",
60                 bs.Jump[0],
61                 bs.Jump[1],
62                 bs.Jump[2]);
63         Log_Debug("FS_NTFS", "SystemID = %02x%02x%02x%02x%02x%02x%02x%02x",
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]
66                 );
67         
68         disk->ClusterSize = bs.BytesPerSector * bs.SectorsPerCluster;
69         Log_Debug("NTFS", "Cluster Size = %i KiB", disk->ClusterSize/1024);
70         disk->MFTBase = bs.MFTStart;
71         Log_Debug("NTFS", "MFT Base = %i", disk->MFTBase);
72         Log_Debug("NTFS", "TotalSectorCount = 0x%x", bs.TotalSectorCount);
73         
74         disk->RootNode.Inode = 5;       // MFT Ent #5 is filesystem root
75         disk->RootNode.ImplPtr = disk;
76         
77         disk->RootNode.UID = 0;
78         disk->RootNode.GID = 0;
79         
80         disk->RootNode.NumACLs = 1;
81         disk->RootNode.ACLs = &gVFS_ACL_EveryoneRX;
82         
83         disk->RootNode.ReadDir = NTFS_ReadDir;
84         disk->RootNode.FindDir = NTFS_FindDir;
85         disk->RootNode.MkNod = NULL;
86         disk->RootNode.Link = NULL;
87         disk->RootNode.Relink = NULL;
88         disk->RootNode.Close = NULL;
89         
90         NTFS_DumpEntry(disk, 5);
91         
92         return &disk->RootNode;
93 }
94
95 /**
96  * \brief Unmount an NTFS Disk
97  */
98 void NTFS_Unmount(tVFS_Node *Node)
99 {
100         
101 }
102
103 /**
104  * \brief Dumps a MFT Entry
105  */
106 void NTFS_DumpEntry(tNTFS_Disk *Disk, Uint32 Entry)
107 {
108         void    *buf = malloc( Disk->ClusterSize );
109         tNTFS_FILE_Header       *hdr = buf;
110         
111         if(!buf) {
112                 Log_Warning("FS_NTFS", "malloc() fail!");
113                 return ;
114         }
115         
116         VFS_ReadAt( Disk->FD, Disk->MFTBase*Disk->ClusterSize, Disk->ClusterSize, buf);
117         
118         Log_Debug("FS_NTFS", "MFT Entry #%i", Entry);
119         Log_Debug("FS_NTFS", "- Magic = 0x%08x", hdr->Magic);
120         Log_Debug("FS_NTFS", "- UpdateSequenceOfs = 0x%x", hdr->UpdateSequenceOfs);
121         Log_Debug("FS_NTFS", "- UpdateSequenceSize = 0x%x", hdr->UpdateSequenceSize);
122         Log_Debug("FS_NTFS", "- LSN = 0x%x", hdr->LSN);
123         Log_Debug("FS_NTFS", "- SequenceNumber = %i", hdr->SequenceNumber);
124         Log_Debug("FS_NTFS", "- HardLinkCount = %i", hdr->HardLinkCount);
125         Log_Debug("FS_NTFS", "- FirstAttribOfs = 0x%x", hdr->FirstAttribOfs);
126         Log_Debug("FS_NTFS", "- Flags = 0x%x", hdr->Flags);
127         Log_Debug("FS_NTFS", "- RecordSize = 0x%x", hdr->RecordSize);
128         Log_Debug("FS_NTFS", "- RecordSpace = 0x%x", hdr->RecordSpace);
129         Log_Debug("FS_NTFS", "- Reference = 0x%llx", hdr->Reference);
130         Log_Debug("FS_NTFS", "- NextAttribID = 0x%04x", hdr->NextAttribID);
131         
132         free(buf);
133 }

UCC git Repository :: git.ucc.asn.au