1c2c66affSColin Finck /*
2c2c66affSColin Finck * COPYRIGHT: See COPYING in the top level directory
3c2c66affSColin Finck * PROJECT: File Management IFS Utility functions
4c2c66affSColin Finck * FILE: reactos/dll/win32/fmifs/init.c
5c2c66affSColin Finck * PURPOSE: Initialisation
6c2c66affSColin Finck *
7c2c66affSColin Finck * PROGRAMMERS: Emanuele Aliberti
8c2c66affSColin Finck * Herv� Poussineau (hpoussin@reactos.org)
9c2c66affSColin Finck */
10c2c66affSColin Finck
11c2c66affSColin Finck #include "precomp.h"
12c2c66affSColin Finck
13c2c66affSColin Finck #include <winreg.h>
14c2c66affSColin Finck
15c2c66affSColin Finck #define NTOS_MODE_USER
16c2c66affSColin Finck #include <ndk/cmfuncs.h>
17c2c66affSColin Finck #include <ndk/obfuncs.h>
18c2c66affSColin Finck
19c2c66affSColin Finck static BOOLEAN FmIfsInitialized = FALSE;
20c2c66affSColin Finck LIST_ENTRY ProviderListHead;
21c2c66affSColin Finck
22c2c66affSColin Finck PIFS_PROVIDER
GetProvider(IN PWCHAR FileSystem)23c2c66affSColin Finck GetProvider(
24c2c66affSColin Finck IN PWCHAR FileSystem)
25c2c66affSColin Finck {
26c2c66affSColin Finck PLIST_ENTRY ListEntry;
27c2c66affSColin Finck PIFS_PROVIDER Provider;
28c2c66affSColin Finck
29c2c66affSColin Finck ListEntry = ProviderListHead.Flink;
30c2c66affSColin Finck while (ListEntry != &ProviderListHead)
31c2c66affSColin Finck {
32c2c66affSColin Finck Provider = CONTAINING_RECORD(ListEntry, IFS_PROVIDER, ListEntry);
33c2c66affSColin Finck if (_wcsicmp(Provider->Name, FileSystem) == 0)
34c2c66affSColin Finck return Provider;
35c2c66affSColin Finck ListEntry = ListEntry->Flink;
36c2c66affSColin Finck }
37c2c66affSColin Finck
38c2c66affSColin Finck /* Provider not found */
39c2c66affSColin Finck return NULL;
40c2c66affSColin Finck }
41c2c66affSColin Finck
42c2c66affSColin Finck
43c2c66affSColin Finck static
44c2c66affSColin Finck BOOLEAN
AddProvider(IN PCUNICODE_STRING FileSystem,IN PWCHAR DllFile)45c2c66affSColin Finck AddProvider(
46c2c66affSColin Finck IN PCUNICODE_STRING FileSystem,
47c2c66affSColin Finck IN PWCHAR DllFile)
48c2c66affSColin Finck {
49c2c66affSColin Finck PIFS_PROVIDER Provider = NULL;
50c2c66affSColin Finck ULONG RequiredSize;
51c2c66affSColin Finck HMODULE hMod = NULL;
52c2c66affSColin Finck BOOLEAN ret = FALSE;
53c2c66affSColin Finck
54c2c66affSColin Finck hMod = LoadLibraryW(DllFile);
55c2c66affSColin Finck if (!hMod)
56c2c66affSColin Finck goto cleanup;
57c2c66affSColin Finck
58c2c66affSColin Finck RequiredSize = FIELD_OFFSET(IFS_PROVIDER, Name)
59c2c66affSColin Finck + FileSystem->Length + sizeof(UNICODE_NULL);
60c2c66affSColin Finck Provider = (PIFS_PROVIDER)RtlAllocateHeap(
61c2c66affSColin Finck RtlGetProcessHeap(),
62c2c66affSColin Finck 0,
63c2c66affSColin Finck RequiredSize);
64c2c66affSColin Finck if (!Provider)
65c2c66affSColin Finck goto cleanup;
66c2c66affSColin Finck RtlZeroMemory(Provider, RequiredSize);
67c2c66affSColin Finck
68c2c66affSColin Finck /* Get function pointers */
69*8d3e80e4SHermès Bélusca-Maïto Provider->Chkdsk = (PULIB_CHKDSK)GetProcAddress(hMod, "Chkdsk");
70*8d3e80e4SHermès Bélusca-Maïto //Provider->ChkdskEx = (PULIB_CHKDSKEX)GetProcAddress(hMod, "ChkdskEx");
71*8d3e80e4SHermès Bélusca-Maïto //Provider->Extend = (PULIB_EXTEND)GetProcAddress(hMod, "Extend");
72*8d3e80e4SHermès Bélusca-Maïto Provider->Format = (PULIB_FORMAT)GetProcAddress(hMod, "Format");
73*8d3e80e4SHermès Bélusca-Maïto //Provider->FormatEx = (PULIB_FORMATEX)GetProcAddress(hMod, "FormatEx");
74c2c66affSColin Finck
75c2c66affSColin Finck RtlCopyMemory(Provider->Name, FileSystem->Buffer, FileSystem->Length);
76c2c66affSColin Finck
77c2c66affSColin Finck InsertTailList(&ProviderListHead, &Provider->ListEntry);
78c2c66affSColin Finck ret = TRUE;
79c2c66affSColin Finck
80c2c66affSColin Finck cleanup:
81c2c66affSColin Finck if (!ret)
82c2c66affSColin Finck {
83c2c66affSColin Finck if (hMod)
84c2c66affSColin Finck FreeLibrary(hMod);
85c2c66affSColin Finck if (Provider)
86c2c66affSColin Finck RtlFreeHeap(RtlGetProcessHeap(), 0, Provider);
87c2c66affSColin Finck }
88c2c66affSColin Finck return ret;
89c2c66affSColin Finck }
90c2c66affSColin Finck
91c2c66affSColin Finck static
92c2c66affSColin Finck BOOLEAN
InitializeFmIfsOnce(VOID)93c2c66affSColin Finck InitializeFmIfsOnce(VOID)
94c2c66affSColin Finck {
95c2c66affSColin Finck OBJECT_ATTRIBUTES ObjectAttributes;
96c2c66affSColin Finck UNICODE_STRING RegistryPath
97c2c66affSColin Finck = RTL_CONSTANT_STRING(L"\\REGISTRY\\Machine\\SOFTWARE\\ReactOS\\ReactOS\\CurrentVersion\\IFS");
98c2c66affSColin Finck HANDLE hKey = NULL;
99c2c66affSColin Finck PKEY_VALUE_FULL_INFORMATION Buffer;
100c2c66affSColin Finck ULONG BufferSize = sizeof(KEY_VALUE_FULL_INFORMATION) + MAX_PATH;
101c2c66affSColin Finck ULONG RequiredSize;
102c2c66affSColin Finck ULONG i = 0;
103c2c66affSColin Finck UNICODE_STRING Name;
104c2c66affSColin Finck UNICODE_STRING Data;
105c2c66affSColin Finck NTSTATUS Status;
106c2c66affSColin Finck
107c2c66affSColin Finck InitializeListHead(&ProviderListHead);
108c2c66affSColin Finck
109c2c66affSColin Finck /* Read IFS providers from HKLM\SOFTWARE\ReactOS\ReactOS\CurrentVersion\IFS */
110c2c66affSColin Finck InitializeObjectAttributes(&ObjectAttributes, &RegistryPath, 0, NULL, NULL);
111c2c66affSColin Finck Status = NtOpenKey(&hKey, KEY_QUERY_VALUE, &ObjectAttributes);
112c2c66affSColin Finck if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
113c2c66affSColin Finck return TRUE;
114c2c66affSColin Finck else if (!NT_SUCCESS(Status))
115c2c66affSColin Finck return FALSE;
116c2c66affSColin Finck
117c2c66affSColin Finck Buffer = (PKEY_VALUE_FULL_INFORMATION)RtlAllocateHeap(
118c2c66affSColin Finck RtlGetProcessHeap(),
119c2c66affSColin Finck 0,
120c2c66affSColin Finck BufferSize);
121c2c66affSColin Finck if (!Buffer)
122c2c66affSColin Finck {
123c2c66affSColin Finck NtClose(hKey);
124c2c66affSColin Finck return FALSE;
125c2c66affSColin Finck }
126c2c66affSColin Finck
127c2c66affSColin Finck while (TRUE)
128c2c66affSColin Finck {
129c2c66affSColin Finck Status = NtEnumerateValueKey(
130c2c66affSColin Finck hKey,
131c2c66affSColin Finck i++,
132c2c66affSColin Finck KeyValueFullInformation,
133c2c66affSColin Finck Buffer,
134c2c66affSColin Finck BufferSize,
135c2c66affSColin Finck &RequiredSize);
136c2c66affSColin Finck if (Status == STATUS_BUFFER_OVERFLOW)
137c2c66affSColin Finck continue;
138c2c66affSColin Finck else if (!NT_SUCCESS(Status))
139c2c66affSColin Finck break;
140c2c66affSColin Finck else if (Buffer->Type != REG_SZ)
141c2c66affSColin Finck continue;
142c2c66affSColin Finck
143c2c66affSColin Finck Name.Length = Name.MaximumLength = Buffer->NameLength;
144c2c66affSColin Finck Name.Buffer = Buffer->Name;
145c2c66affSColin Finck Data.Length = Data.MaximumLength = Buffer->DataLength;
146c2c66affSColin Finck Data.Buffer = (PWCHAR)((ULONG_PTR)Buffer + Buffer->DataOffset);
147c2c66affSColin Finck if (Data.Length > sizeof(WCHAR) && Data.Buffer[Data.Length / sizeof(WCHAR) - 1] == UNICODE_NULL)
148c2c66affSColin Finck Data.Length -= sizeof(WCHAR);
149c2c66affSColin Finck
150c2c66affSColin Finck AddProvider(&Name, Data.Buffer);
151c2c66affSColin Finck }
152c2c66affSColin Finck
153c2c66affSColin Finck NtClose(hKey);
154c2c66affSColin Finck RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
155c2c66affSColin Finck return TRUE;
156c2c66affSColin Finck }
157c2c66affSColin Finck
158c2c66affSColin Finck /* FMIFS.8 */
159c2c66affSColin Finck BOOLEAN
160c2c66affSColin Finck NTAPI
InitializeFmIfs(IN PVOID hinstDll,IN DWORD dwReason,IN PVOID reserved)161c2c66affSColin Finck InitializeFmIfs(
162c2c66affSColin Finck IN PVOID hinstDll,
163c2c66affSColin Finck IN DWORD dwReason,
164c2c66affSColin Finck IN PVOID reserved)
165c2c66affSColin Finck {
166c2c66affSColin Finck switch (dwReason)
167c2c66affSColin Finck {
168c2c66affSColin Finck case DLL_PROCESS_ATTACH:
169c2c66affSColin Finck if (FmIfsInitialized == FALSE)
170c2c66affSColin Finck {
171c2c66affSColin Finck if (InitializeFmIfsOnce() == FALSE)
172c2c66affSColin Finck return FALSE;
173c2c66affSColin Finck
174c2c66affSColin Finck FmIfsInitialized = TRUE;
175c2c66affSColin Finck }
176c2c66affSColin Finck break;
177c2c66affSColin Finck
178c2c66affSColin Finck case DLL_THREAD_ATTACH:
179c2c66affSColin Finck break;
180c2c66affSColin Finck
181c2c66affSColin Finck case DLL_THREAD_DETACH:
182c2c66affSColin Finck break;
183c2c66affSColin Finck
184c2c66affSColin Finck case DLL_PROCESS_DETACH:
185c2c66affSColin Finck break;
186c2c66affSColin Finck }
187c2c66affSColin Finck
188c2c66affSColin Finck return TRUE;
189c2c66affSColin Finck }
190c2c66affSColin Finck
191c2c66affSColin Finck /* EOF */
192