#
#
-OBJ = main.o dir.o
+OBJ = main.o dir.o io.o
NAME = NTFS
-include ../Makefile.tpl
extern tVFS_NodeType gNTFS_DirType;
extern tVFS_NodeType gNTFS_FileType;
+extern void NTFS_Close(tVFS_Node *Node);
+extern void NTFS_FreeNode(tVFS_Node *Node);
extern int NTFS_int_ApplyUpdateSequence(void *Buf, size_t BufLen, const Uint16 *Sequence, size_t NumEntries);
// -- MFT Access / Manipulation
extern tNTFS_FILE_Header *NTFS_GetMFT(tNTFS_Disk *Disk, Uint32 MFTEntry);
extern void NTFS_ReleaseMFT(tNTFS_Disk *Disk, Uint32 MFTEntry, tNTFS_FILE_Header *Entry);
extern tNTFS_Attrib *NTFS_GetAttrib(tNTFS_Disk *Disk, Uint32 MFTEntry, int Type, const char *Name, int DesIdx);
+extern void NTFS_FreeAttrib(tNTFS_Attrib *Attrib);
extern size_t NTFS_ReadAttribData(tNTFS_Attrib *Attrib, Uint64 Offset, size_t Length, void *Buffer);
// -- dir.c
extern int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]);
extern tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
+// -- io.c
+extern size_t NTFS_ReadFile(tVFS_Node *Node, Uint64 Offset, size_t Length, void *Buffer, Uint Flags);
#endif
if( len == 0 )
break;
tNTFS_IndexHeader *hdr = (void*)buf;
+
+ if( memcmp(&hdr->Magic, "INDX", 4) != 0 ) {
+ Log_Notice("NTFS", "FindDir %p:%X:%x index magic bad %08x",
+ disk, Node->Inode, ofs / unit_len, hdr->Magic);
+ break;
+ }
// Apply update sequence
- ASSERT(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize <= len);
+ if(hdr->UpdateSequenceOfs + 2*hdr->UpdateSequenceSize > len) {
+ Log_Notice("NTFS", "FindDir %p:%X:%x index update sequence out of buffer (%x+%x>%x)",
+ disk, Node->Inode, ofs / unit_len,
+ hdr->UpdateSequenceOfs, 2*hdr->UpdateSequenceSize, len);
+ break;
+ }
NTFS_int_ApplyUpdateSequence(buf,len, (void*)(buf+hdr->UpdateSequenceOfs), hdr->UpdateSequenceSize);
// Search
//mftent = NTFS_BTreeSearch(len, (void*)buf, NTFS_BTreeSearch_CmpI30, name16len*2, name16);
);
}
- if( !mftent ) {
+ if( !mftent || (mftent & (1ULL << 63)) ) {
LEAVE('n');
return NULL;
}
--- /dev/null
+/*
+ * Acess2 - NTFS Driver
+ * - By John Hodge (thePowersGang)
+ * This file is published under the terms of the Acess licence. See the
+ * file COPYING for details.
+ *
+ * io.c
+ * - File Read/Write
+ */
+#define DEBUG 1
+#include "common.h"
+
+// == CODE ===
+size_t NTFS_ReadFile(tVFS_Node *Node, Uint64 Offset, size_t Length, void *Buffer, Uint Flags)
+{
+ tNTFS_File *File = (void*)Node;
+
+ return NTFS_ReadAttribData(File->Data, Offset, Length, Buffer);
+}
+
+
.TypeName = "NTFS-Dir",
.ReadDir = NTFS_ReadDir,
.FindDir = NTFS_FindDir,
- .Close = NULL
+ .Close = NTFS_Close
};
tVFS_NodeType gNTFS_FileType = {
.TypeName = "NTFS-File",
- .Close = NULL
+ .Read = NTFS_ReadFile,
+ .Close = NTFS_Close
};
tNTFS_Disk gNTFS_Disks;
free(Disk);
}
+void NTFS_Close(tVFS_Node *Node)
+{
+ tNTFS_Disk *Disk = Node->ImplPtr;
+ Inode_UncacheNode(Disk->InodeCache, Node->Inode);
+}
+
+void NTFS_FreeNode(tVFS_Node *Node)
+{
+ if( Node->Type == &gNTFS_DirType ) {
+ tNTFS_Directory *Dir = (void*)Node;
+ NTFS_FreeAttrib(Dir->I30Root);
+ NTFS_FreeAttrib(Dir->I30Allocation);
+ }
+ else {
+ tNTFS_File *File = (void*)Node;
+ NTFS_FreeAttrib(File->Data);
+ }
+}
+
int NTFS_int_ApplyUpdateSequence(void *Buffer, size_t BufLen, const Uint16 *Sequence, size_t NumEntries)
{
Uint16 cksum = Sequence[0];
return NULL;
}
+void NTFS_FreeAttrib(tNTFS_Attrib *Attrib)
+{
+ if( Attrib )
+ free(Attrib);
+}
+
size_t NTFS_ReadAttribData(tNTFS_Attrib *Attrib, Uint64 Offset, size_t Length, void *Buffer)
{
if( !Attrib )
tNTFS_FILE_Attrib *attr;
int i;
- tNTFS_FILE_Header *hdr = malloc( Disk->MFTRecSize );
+
+ tNTFS_FILE_Header *hdr = NTFS_GetMFT(Disk, Entry);
if(!hdr) {
Log_Warning("FS_NTFS", "malloc() fail!");
return ;
}
- VFS_ReadAt( Disk->FD,
- Disk->MFTBase * Disk->ClusterSize + Entry * Disk->MFTRecSize,
- Disk->MFTRecSize,
- hdr);
-
Log_Debug("FS_NTFS", "MFT Entry #%i", Entry);
Log_Debug("FS_NTFS", "- Magic = 0x%08x (%4C)", hdr->Magic, &hdr->Magic);
Log_Debug("FS_NTFS", "- UpdateSequenceOfs = 0x%x", hdr->UpdateSequenceOfs);
attr = (void*)( (tVAddr)attr + attr->Size );
}
- free(hdr);
+ NTFS_ReleaseMFT(Disk, Entry, hdr);
}