Merge 13159:13510 from trunk
[reactos.git] / reactos / subsys / smss / initpage.c
1 /* $Id: init.c 13449 2005-02-06 21:55:07Z ea $
2 *
3 * initpage.c -
4 *
5 * ReactOS Operating System
6 *
7 * --------------------------------------------------------------------
8 *
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
22 * MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 */
26 #include "smss.h"
27 #include <rosrtl/string.h>
28 #include <wchar.h>
29
30 #define NDEBUG
31 #include <debug.h>
32
33 static NTSTATUS STDCALL
34 SmpPagingFilesQueryRoutine(PWSTR ValueName,
35 ULONG ValueType,
36 PVOID ValueData,
37 ULONG ValueLength,
38 PVOID Context,
39 PVOID EntryContext)
40 {
41 UNICODE_STRING FileName;
42 LARGE_INTEGER InitialSize;
43 LARGE_INTEGER MaximumSize;
44 NTSTATUS Status;
45 LPWSTR p;
46
47 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength);
48 DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
49
50 if (ValueType != REG_SZ)
51 {
52 return(STATUS_SUCCESS);
53 }
54
55 /*
56 * Format: "<path>[ <initial_size>[ <maximum_size>]]"
57 */
58 if ((p = wcschr(ValueData, ' ')) != NULL)
59 {
60 *p = L'\0';
61 InitialSize.QuadPart = wcstoul(p + 1, &p, 0) * 256 * 4096;
62 if (*p == ' ')
63 {
64 MaximumSize.QuadPart = wcstoul(p + 1, NULL, 0) * 256 * 4096;
65 }
66 else
67 MaximumSize = InitialSize;
68 }
69 else
70 {
71 InitialSize.QuadPart = 50 * 4096;
72 MaximumSize.QuadPart = 80 * 4096;
73 }
74
75 if (!RtlDosPathNameToNtPathName_U ((LPWSTR)ValueData,
76 &FileName,
77 NULL,
78 NULL))
79 {
80 return (STATUS_SUCCESS);
81 }
82
83 DPRINT("SMSS: Created paging file %wZ with size %dKB\n",
84 &FileName, InitialSize.QuadPart / 1024);
85 Status = NtCreatePagingFile(&FileName,
86 &InitialSize,
87 &MaximumSize,
88 0);
89
90 RtlFreeUnicodeString(&FileName);
91
92 return(STATUS_SUCCESS);
93 }
94
95
96 NTSTATUS
97 SmCreatePagingFiles(VOID)
98 {
99 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
100 NTSTATUS Status;
101
102 DPRINT("SM: creating system paging files\n");
103 /*
104 * Disable paging file on MiniNT/Live CD.
105 */
106 if (RtlCheckRegistryKey(RTL_REGISTRY_CONTROL, L"MiniNT") == STATUS_SUCCESS)
107 {
108 return STATUS_SUCCESS;
109 }
110
111 RtlZeroMemory(&QueryTable,
112 sizeof(QueryTable));
113
114 QueryTable[0].Name = L"PagingFiles";
115 QueryTable[0].QueryRoutine = SmpPagingFilesQueryRoutine;
116
117 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
118 L"\\Session Manager\\Memory Management",
119 QueryTable,
120 NULL,
121 NULL);
122
123 return(Status);
124 }
125
126
127 /* EOF */