3 * By John Hodge (thePowersGang)
4 * This file is published under the terms of the Acess licence. See the
5 * file COPYING for details.
7 * dir.c - Directory Handling
15 int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX]);
16 tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
17 Uint64 NTFS_int_IndexLookup(Uint64 Inode, const char *IndexName, const char *Str);
21 * \brief Get the name of an indexed directory entry
23 int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX])
25 tNTFS_Directory *dir = (void*)Node;
26 tNTFS_Disk *disk = Node->ImplPtr;
28 ASSERT(dir->I30Root->IsResident);
29 const tNTFS_Attrib_IndexRoot *idxroot = dir->I30Root->ResidentData;
30 //const tNTFS_Attrib_IndexEntry *rootents = (void*)(idxroot + 1);
32 if( idxroot->Flags & 0x01 )
34 // Read from allocation
35 char buf[disk->ClusterSize];
36 struct sNTFS_IndexHeader *hdr = (void*)buf;
38 size_t len = sizeof(buf);
39 struct sNTFS_IndexEntry_Filename *ent = (void*)(buf + len);
43 if( (char*)ent == buf + len ) {
44 if( len < sizeof(buf))
46 len = NTFS_ReadAttribData(dir->I30Allocation, ofs, sizeof(buf), buf);
48 //Debug_HexDump("NTFS_ReadDir", buf, sizeof(*hdr));
49 ent = (void*)(buf + (hdr->EntriesOffset + 0x18));
53 LOG("ent = {.MFTEnt=%llx,.FilenameOfs=%x}", ent->MFTReference, ent->FilenameOfs);
54 //Uint16 *name16 = (Uint16*)ent + ent->FilenameOfs/2;
55 Uint16 *name16 = ent->Filename.Filename;
56 size_t nlen = UTF16_ConvertToUTF8(0, NULL, ent->Filename.FilenameLength, name16);
57 char tmpname[ nlen+1 ];
58 UTF16_ConvertToUTF8(nlen+1, tmpname, ent->Filename.FilenameLength, name16);
59 LOG("name = '%s'", tmpname);
60 ent = (void*)((char*)ent + ent->EntrySize);
65 //Uint16 *name16 = (Uint16*)ent + ent->FilenameOfs/2;
66 Uint16 *name16 = ent->Filename.Filename;
67 UTF16_ConvertToUTF8(FILENAME_MAX, Dest, ent->Filename.FilenameLength, name16);
80 * \brief Get an entry from a directory by name
82 tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
85 tNTFS_Directory *dir = (void*)Node;
86 tNTFS_Disk *disk = Node->ImplPtr;
87 ASSERT(dir->I30Root->IsResident);
88 const tNTFS_Attrib_IndexRoot *idxroot = dir->I30Root->ResidentData;
90 if( idxroot->Flags & 0x01 )
92 char buf[disk->ClusterSize];
93 size_t len = NTFS_ReadAttribData(dir->I30Allocation, 0, sizeof(buf), buf);
94 struct sNTFS_IndexHeader *hdr = (void*)buf;
102 * \brief Scans an index for the requested value and returns the associated ID
104 Uint64 NTFS_int_IndexLookup(Uint64 Inode, const char *IndexName, const char *Str)