Modules/NTFS - Implimentation in progress
[tpg/acess2.git] / KernelLand / Modules / Filesystems / NTFS / dir.c
1 /*
2  * Acess2 - NTFS Driver
3  * By John Hodge (thePowersGang)
4  * This file is published under the terms of the Acess licence. See the
5  * file COPYING for details.
6  *
7  * dir.c - Directory Handling
8  */
9 #define DEBUG   1
10 #include "common.h"
11 #include "index.h"
12 #include <utf16.h>
13
14 // === PROTOTYPES ===
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);
18
19 // === CODE ===
20 /**
21  * \brief Get the name of an indexed directory entry
22  */
23 int NTFS_ReadDir(tVFS_Node *Node, int Pos, char Dest[FILENAME_MAX])
24 {
25         tNTFS_Directory *dir = (void*)Node;
26         tNTFS_Disk      *disk = Node->ImplPtr;
27
28         ASSERT(dir->I30Root->IsResident);
29         const tNTFS_Attrib_IndexRoot    *idxroot = dir->I30Root->ResidentData;
30         //const tNTFS_Attrib_IndexEntry *rootents = (void*)(idxroot + 1);
31
32         if( idxroot->Flags & 0x01 )
33         {
34                 // Read from allocation
35                 char buf[disk->ClusterSize];
36                 struct sNTFS_IndexHeader *hdr = (void*)buf;
37                 size_t  ofs = 0;
38                 size_t len = sizeof(buf);
39                 struct sNTFS_IndexEntry_Filename *ent = (void*)(buf + len);
40                 
41                 for(;;)
42                 {
43                         if( (char*)ent == buf + len ) {
44                                 if( len < sizeof(buf))
45                                         break ;
46                                 len = NTFS_ReadAttribData(dir->I30Allocation, ofs, sizeof(buf), buf);
47                                 ofs += sizeof(buf);
48                                 //Debug_HexDump("NTFS_ReadDir", buf, sizeof(*hdr));
49                                 ent = (void*)(buf + (hdr->EntriesOffset + 0x18));
50                         }
51                         if( Pos -- <= 0 )
52                                 break;
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);
61                 }
62
63                 if( Pos < 0 )
64                 {
65                         //Uint16        *name16 = (Uint16*)ent + ent->FilenameOfs/2;
66                         Uint16  *name16 = ent->Filename.Filename;
67                         UTF16_ConvertToUTF8(FILENAME_MAX, Dest, ent->Filename.FilenameLength, name16);
68                         return 0;
69                 }
70         }
71         else
72         {
73                 // Local only
74         }
75
76         return -ENOTIMPL;
77 }
78
79 /**
80  * \brief Get an entry from a directory by name
81  */
82 tVFS_Node *NTFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)
83 {
84         #if 0
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;
89
90         if( idxroot->Flags & 0x01 )
91         {
92                 char buf[disk->ClusterSize];
93                 size_t len = NTFS_ReadAttribData(dir->I30Allocation, 0, sizeof(buf), buf);
94                 struct sNTFS_IndexHeader *hdr = (void*)buf;
95         }
96         #endif
97         
98         return NULL;
99 }
100
101 /**
102  * \brief Scans an index for the requested value and returns the associated ID
103  */
104 Uint64 NTFS_int_IndexLookup(Uint64 Inode, const char *IndexName, const char *Str)
105 {
106         return 0;
107 }

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