d3d9/tests: Use a separate device for clear_test().
[wine.git] / dlls / wbemprox / builtin.c
blob8f4b36208ae0e8fbfbe2fc2670e40db72645244e
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
23 #include "config.h"
24 #include <stdarg.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "initguid.h"
31 #include "wbemcli.h"
32 #include "wbemprov.h"
33 #include "winsock2.h"
34 #include "iphlpapi.h"
35 #include "tlhelp32.h"
36 #include "d3d10.h"
37 #include "winternl.h"
38 #include "winioctl.h"
39 #include "winsvc.h"
40 #include "winver.h"
42 #include "wine/debug.h"
43 #include "wbemprox_private.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
47 static const WCHAR class_baseboardW[] =
48 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
49 static const WCHAR class_biosW[] =
50 {'W','i','n','3','2','_','B','I','O','S',0};
51 static const WCHAR class_cdromdriveW[] =
52 {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
53 static const WCHAR class_compsysW[] =
54 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
55 static const WCHAR class_datafileW[] =
56 {'C','I','M','_','D','a','t','a','F','i','l','e',0};
57 static const WCHAR class_directoryW[] =
58 {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
59 static const WCHAR class_diskdriveW[] =
60 {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
61 static const WCHAR class_diskpartitionW[] =
62 {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
63 static const WCHAR class_logicaldiskW[] =
64 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
65 static const WCHAR class_logicaldisk2W[] =
66 {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
67 static const WCHAR class_networkadapterW[] =
68 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
69 static const WCHAR class_networkadapterconfigW[] =
70 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
71 'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
72 static const WCHAR class_osW[] =
73 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
74 static const WCHAR class_paramsW[] =
75 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
76 static const WCHAR class_physicalmediaW[] =
77 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
78 static const WCHAR class_physicalmemoryW[] =
79 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
80 static const WCHAR class_qualifiersW[] =
81 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
82 static const WCHAR class_process_getowner_outW[] =
83 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
84 'N','E','R','_','O','U','T',0};
85 static const WCHAR class_processorW[] =
86 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
87 static const WCHAR class_sounddeviceW[] =
88 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
89 static const WCHAR class_videocontrollerW[] =
90 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
92 static const WCHAR prop_acceptpauseW[] =
93 {'A','c','c','e','p','t','P','a','u','s','e',0};
94 static const WCHAR prop_acceptstopW[] =
95 {'A','c','c','e','p','t','S','t','o','p',0};
96 static const WCHAR prop_accessmaskW[] =
97 {'A','c','c','e','s','s','M','a','s','k',0};
98 static const WCHAR prop_adapterdactypeW[] =
99 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
100 static const WCHAR prop_adapterramW[] =
101 {'A','d','a','p','t','e','r','R','A','M',0};
102 static const WCHAR prop_adaptertypeW[] =
103 {'A','d','a','p','t','e','r','T','y','p','e',0};
104 static const WCHAR prop_addresswidthW[] =
105 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
106 static const WCHAR prop_availabilityW[] =
107 {'A','v','a','i','l','a','b','i','l','i','t','y',0};
108 static const WCHAR prop_bootableW[] =
109 {'B','o','o','t','a','b','l','e',0};
110 static const WCHAR prop_bootpartitionW[] =
111 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
112 static const WCHAR prop_buildnumberW[] =
113 {'B','u','i','l','d','N','u','m','b','e','r',0};
114 static const WCHAR prop_capacityW[] =
115 {'C','a','p','a','c','i','t','y',0};
116 static const WCHAR prop_captionW[] =
117 {'C','a','p','t','i','o','n',0};
118 static const WCHAR prop_classW[] =
119 {'C','l','a','s','s',0};
120 static const WCHAR prop_codesetW[] =
121 {'C','o','d','e','S','e','t',0};
122 static const WCHAR prop_commandlineW[] =
123 {'C','o','m','m','a','n','d','L','i','n','e',0};
124 static const WCHAR prop_countrycodeW[] =
125 {'C','o','u','n','t','r','y','C','o','d','e',0};
126 static const WCHAR prop_cpustatusW[] =
127 {'C','p','u','S','t','a','t','u','s',0};
128 static const WCHAR prop_csdversionW[] =
129 {'C','S','D','V','e','r','s','i','o','n',0};
130 static const WCHAR prop_currentbitsperpixelW[] =
131 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
132 static const WCHAR prop_currenthorizontalresW[] =
133 {'C','u','r','r','e','n','t','H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
134 static const WCHAR prop_currentverticalresW[] =
135 {'C','u','r','r','e','n','t','V','e','r','t','i','c','a','l','R','e','s','o','l','u','t','i','o','n',0};
136 static const WCHAR prop_defaultvalueW[] =
137 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
138 static const WCHAR prop_descriptionW[] =
139 {'D','e','s','c','r','i','p','t','i','o','n',0};
140 static const WCHAR prop_deviceidW[] =
141 {'D','e','v','i','c','e','I','d',0};
142 static const WCHAR prop_directionW[] =
143 {'D','i','r','e','c','t','i','o','n',0};
144 static const WCHAR prop_displaynameW[] =
145 {'D','i','s','p','l','a','y','N','a','m','e',0};
146 static const WCHAR prop_diskindexW[] =
147 {'D','i','s','k','I','n','d','e','x',0};
148 static const WCHAR prop_domainW[] =
149 {'D','o','m','a','i','n',0};
150 static const WCHAR prop_domainroleW[] =
151 {'D','o','m','a','i','n','R','o','l','e',0};
152 static const WCHAR prop_driveW[] =
153 {'D','r','i','v','e',0};
154 static const WCHAR prop_drivetypeW[] =
155 {'D','r','i','v','e','T','y','p','e',0};
156 static const WCHAR prop_familyW[] =
157 {'F','a','m','i','l','y',0};
158 static const WCHAR prop_filesystemW[] =
159 {'F','i','l','e','S','y','s','t','e','m',0};
160 static const WCHAR prop_flavorW[] =
161 {'F','l','a','v','o','r',0};
162 static const WCHAR prop_freespaceW[] =
163 {'F','r','e','e','S','p','a','c','e',0};
164 static const WCHAR prop_handleW[] =
165 {'H','a','n','d','l','e',0};
166 static const WCHAR prop_idW[] =
167 {'I','D',0};
168 static const WCHAR prop_identificationcodeW[] =
169 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
170 static const WCHAR prop_indexW[] =
171 {'I','n','d','e','x',0};
172 static const WCHAR prop_installdateW[] =
173 {'I','n','s','t','a','l','l','D','a','t','e',0};
174 static const WCHAR prop_interfaceindexW[] =
175 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
176 static const WCHAR prop_interfacetypeW[] =
177 {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
178 static const WCHAR prop_intvalueW[] =
179 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
180 static const WCHAR prop_ipconnectionmetricW[] =
181 {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
182 static const WCHAR prop_ipenabledW[] =
183 {'I','P','E','n','a','b','l','e','d',0};
184 static const WCHAR prop_lastbootuptimeW[] =
185 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
186 static const WCHAR prop_localdatetimeW[] =
187 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
188 static const WCHAR prop_localeW[] =
189 {'L','o','c','a','l','e',0};
190 static const WCHAR prop_macaddressW[] =
191 {'M','A','C','A','d','d','r','e','s','s',0};
192 static const WCHAR prop_manufacturerW[] =
193 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
194 static const WCHAR prop_maxclockspeedW[] =
195 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
196 static const WCHAR prop_mediatypeW[] =
197 {'M','e','d','i','a','T','y','p','e',0};
198 static const WCHAR prop_memberW[] =
199 {'M','e','m','b','e','r',0};
200 static const WCHAR prop_methodW[] =
201 {'M','e','t','h','o','d',0};
202 static const WCHAR prop_modelW[] =
203 {'M','o','d','e','l',0};
204 static const WCHAR prop_netconnectionstatusW[] =
205 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
206 static const WCHAR prop_numcoresW[] =
207 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
208 static const WCHAR prop_numlogicalprocessorsW[] =
209 {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
210 static const WCHAR prop_numprocessorsW[] =
211 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
212 static const WCHAR prop_osarchitectureW[] =
213 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
214 static const WCHAR prop_oslanguageW[] =
215 {'O','S','L','a','n','g','u','a','g','e',0};
216 static const WCHAR prop_osproductsuiteW[] =
217 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
218 static const WCHAR prop_ostypeW[] =
219 {'O','S','T','y','p','e',0};
220 static const WCHAR prop_parameterW[] =
221 {'P','a','r','a','m','e','t','e','r',0};
222 static const WCHAR prop_physicaladapterW[] =
223 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
224 static const WCHAR prop_pnpdeviceidW[] =
225 {'P','N','P','D','e','v','i','c','e','I','D',0};
226 static const WCHAR prop_pprocessidW[] =
227 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
228 static const WCHAR prop_processidW[] =
229 {'P','r','o','c','e','s','s','I','D',0};
230 static const WCHAR prop_processoridW[] =
231 {'P','r','o','c','e','s','s','o','r','I','d',0};
232 static const WCHAR prop_productnameW[] =
233 {'P','r','o','d','u','c','t','N','a','m','e',0};
234 static const WCHAR prop_releasedateW[] =
235 {'R','e','l','e','a','s','e','D','a','t','e',0};
236 static const WCHAR prop_serialnumberW[] =
237 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
238 static const WCHAR prop_servicepackmajorW[] =
239 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
240 static const WCHAR prop_servicepackminorW[] =
241 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
242 static const WCHAR prop_servicetypeW[] =
243 {'S','e','r','v','i','c','e','T','y','p','e',0};
244 static const WCHAR prop_smbiosbiosversionW[] =
245 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
246 static const WCHAR prop_startmodeW[] =
247 {'S','t','a','r','t','M','o','d','e',0};
248 static const WCHAR prop_sizeW[] =
249 {'S','i','z','e',0};
250 static const WCHAR prop_speedW[] =
251 {'S','p','e','e','d',0};
252 static const WCHAR prop_startingoffsetW[] =
253 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
254 static const WCHAR prop_stateW[] =
255 {'S','t','a','t','e',0};
256 static const WCHAR prop_strvalueW[] =
257 {'S','t','r','i','n','g','V','a','l','u','e',0};
258 static const WCHAR prop_suitemaskW[] =
259 {'S','u','i','t','e','M','a','s','k',0};
260 static const WCHAR prop_systemdirectoryW[] =
261 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
262 static const WCHAR prop_systemnameW[] =
263 {'S','y','s','t','e','m','N','a','m','e',0};
264 static const WCHAR prop_tagW[] =
265 {'T','a','g',0};
266 static const WCHAR prop_threadcountW[] =
267 {'T','h','r','e','a','d','C','o','u','n','t',0};
268 static const WCHAR prop_totalphysicalmemoryW[] =
269 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
270 static const WCHAR prop_typeW[] =
271 {'T','y','p','e',0};
272 static const WCHAR prop_uniqueidW[] =
273 {'U','n','i','q','u','e','I','d',0};
274 static const WCHAR prop_varianttypeW[] =
275 {'V','a','r','i','a','n','t','T','y','p','e',0};
276 static const WCHAR prop_versionW[] =
277 {'V','e','r','s','i','o','n',0};
278 static const WCHAR prop_volumeserialnumberW[] =
279 {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
281 /* column definitions must be kept in sync with record structures below */
282 static const struct column col_baseboard[] =
284 { prop_manufacturerW, CIM_STRING },
285 { prop_modelW, CIM_STRING },
286 { prop_nameW, CIM_STRING },
287 { prop_serialnumberW, CIM_STRING },
288 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
290 static const struct column col_bios[] =
292 { prop_descriptionW, CIM_STRING },
293 { prop_identificationcodeW, CIM_STRING },
294 { prop_manufacturerW, CIM_STRING },
295 { prop_releasedateW, CIM_DATETIME },
296 { prop_serialnumberW, CIM_STRING },
297 { prop_smbiosbiosversionW, CIM_STRING },
298 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
300 static const struct column col_cdromdrive[] =
302 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
303 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
304 { prop_mediatypeW, CIM_STRING },
305 { prop_nameW, CIM_STRING },
306 { prop_pnpdeviceidW, CIM_STRING }
308 static const struct column col_compsys[] =
310 { prop_descriptionW, CIM_STRING },
311 { prop_domainW, CIM_STRING },
312 { prop_domainroleW, CIM_UINT16 },
313 { prop_manufacturerW, CIM_STRING },
314 { prop_modelW, CIM_STRING },
315 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
316 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
317 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
318 { prop_totalphysicalmemoryW, CIM_UINT64 }
320 static const struct column col_datafile[] =
322 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
323 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
325 static const struct column col_directory[] =
327 { prop_accessmaskW, CIM_UINT32 },
328 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
330 static const struct column col_diskdrive[] =
332 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
333 { prop_indexW, CIM_UINT32, VT_I4 },
334 { prop_interfacetypeW, CIM_STRING },
335 { prop_manufacturerW, CIM_STRING },
336 { prop_mediatypeW, CIM_STRING },
337 { prop_modelW, CIM_STRING },
338 { prop_serialnumberW, CIM_STRING },
339 { prop_sizeW, CIM_UINT64 }
341 static const struct column col_diskpartition[] =
343 { prop_bootableW, CIM_BOOLEAN },
344 { prop_bootpartitionW, CIM_BOOLEAN },
345 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
346 { prop_diskindexW, CIM_UINT32, VT_I4 },
347 { prop_indexW, CIM_UINT32, VT_I4 },
348 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
349 { prop_sizeW, CIM_UINT64 },
350 { prop_startingoffsetW, CIM_UINT64 },
351 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
353 static const struct column col_logicaldisk[] =
355 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
356 { prop_drivetypeW, CIM_UINT32, VT_I4 },
357 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
358 { prop_freespaceW, CIM_UINT64 },
359 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
360 { prop_sizeW, CIM_UINT64 },
361 { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
363 static const struct column col_networkadapter[] =
365 { prop_adaptertypeW, CIM_STRING },
366 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
367 { prop_indexW, CIM_UINT32, VT_I4 },
368 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
369 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
370 { prop_manufacturerW, CIM_STRING },
371 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
372 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
373 { prop_physicaladapterW, CIM_BOOLEAN },
374 { prop_pnpdeviceidW, CIM_STRING },
375 { prop_speedW, CIM_UINT64 }
377 static const struct column col_networkadapterconfig[] =
379 { prop_indexW, CIM_UINT32|COL_FLAG_KEY },
380 { prop_ipconnectionmetricW, CIM_UINT32 },
381 { prop_ipenabledW, CIM_BOOLEAN },
382 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC }
384 static const struct column col_os[] =
386 { prop_buildnumberW, CIM_STRING },
387 { prop_captionW, CIM_STRING },
388 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
389 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
390 { prop_csdversionW, CIM_STRING },
391 { prop_installdateW, CIM_DATETIME },
392 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
393 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
394 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
395 { prop_nameW, CIM_STRING },
396 { prop_osarchitectureW, CIM_STRING },
397 { prop_oslanguageW, CIM_UINT32, VT_I4 },
398 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
399 { prop_ostypeW, CIM_UINT16, VT_I4 },
400 { prop_serialnumberW, CIM_STRING },
401 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
402 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
403 { prop_suitemaskW, CIM_UINT32, VT_I4 },
404 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
405 { prop_versionW, CIM_STRING }
407 static const struct column col_param[] =
409 { prop_classW, CIM_STRING },
410 { prop_methodW, CIM_STRING },
411 { prop_directionW, CIM_SINT32 },
412 { prop_parameterW, CIM_STRING },
413 { prop_typeW, CIM_UINT32 },
414 { prop_varianttypeW, CIM_UINT32 },
415 { prop_defaultvalueW, CIM_UINT32 }
417 static const struct column col_physicalmedia[] =
419 { prop_serialnumberW, CIM_STRING },
420 { prop_tagW, CIM_STRING }
422 static const struct column col_physicalmemory[] =
424 { prop_capacityW, CIM_UINT64 }
426 static const struct column col_process[] =
428 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
429 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
430 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
431 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
432 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
433 { prop_pprocessidW, CIM_UINT32, VT_I4 },
434 { prop_processidW, CIM_UINT32, VT_I4 },
435 { prop_threadcountW, CIM_UINT32, VT_I4 },
436 /* methods */
437 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
439 static const struct column col_processor[] =
441 { prop_addresswidthW, CIM_UINT16, VT_I4 },
442 { prop_cpustatusW, CIM_UINT16 },
443 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
444 { prop_familyW, CIM_UINT16, VT_I4 },
445 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
446 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
447 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
448 { prop_numcoresW, CIM_UINT32, VT_I4 },
449 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
450 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
451 { prop_uniqueidW, CIM_STRING }
453 static const struct column col_qualifier[] =
455 { prop_classW, CIM_STRING },
456 { prop_memberW, CIM_STRING },
457 { prop_typeW, CIM_UINT32 },
458 { prop_flavorW, CIM_SINT32 },
459 { prop_nameW, CIM_STRING },
460 { prop_intvalueW, CIM_SINT32 },
461 { prop_strvalueW, CIM_STRING }
463 static const struct column col_service[] =
465 { prop_acceptpauseW, CIM_BOOLEAN },
466 { prop_acceptstopW, CIM_BOOLEAN },
467 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
468 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
469 { prop_processidW, CIM_UINT32 },
470 { prop_servicetypeW, CIM_STRING },
471 { prop_startmodeW, CIM_STRING },
472 { prop_stateW, CIM_STRING },
473 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
474 /* methods */
475 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
476 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
477 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
478 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
480 static const struct column col_sounddevice[] =
482 { prop_nameW, CIM_STRING },
483 { prop_productnameW, CIM_STRING }
485 static const struct column col_stdregprov[] =
487 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
488 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
489 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
491 static const struct column col_videocontroller[] =
493 { prop_adapterdactypeW, CIM_STRING },
494 { prop_adapterramW, CIM_UINT32, VT_I4 },
495 { prop_availabilityW, CIM_UINT16 },
496 { prop_currentbitsperpixelW, CIM_UINT32 },
497 { prop_currenthorizontalresW, CIM_UINT32 },
498 { prop_currentverticalresW, CIM_UINT32 },
499 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
500 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
501 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
502 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
505 static const WCHAR baseboard_manufacturerW[] =
506 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
507 static const WCHAR baseboard_serialnumberW[] =
508 {'N','o','n','e',0};
509 static const WCHAR baseboard_tagW[] =
510 {'B','a','s','e',' ','B','o','a','r','d',0};
511 static const WCHAR bios_descriptionW[] =
512 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
513 static const WCHAR bios_manufacturerW[] =
514 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
515 static const WCHAR bios_releasedateW[] =
516 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
517 static const WCHAR bios_serialnumberW[] =
518 {'0',0};
519 static const WCHAR bios_smbiosbiosversionW[] =
520 {'W','i','n','e',0};
521 static const WCHAR bios_versionW[] =
522 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
523 static const WCHAR cdromdrive_mediatypeW[] =
524 {'C','D','-','R','O','M',0};
525 static const WCHAR cdromdrive_nameW[] =
526 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
527 static const WCHAR cdromdrive_pnpdeviceidW[]=
528 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
529 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
530 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
531 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
532 static const WCHAR compsys_descriptionW[] =
533 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
534 static const WCHAR compsys_domainW[] =
535 {'W','O','R','K','G','R','O','U','P',0};
536 static const WCHAR compsys_manufacturerW[] =
537 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
538 static const WCHAR compsys_modelW[] =
539 {'W','i','n','e',0};
540 static const WCHAR diskdrive_interfacetypeW[] =
541 {'I','D','E',0};
542 static const WCHAR diskdrive_manufacturerW[] =
543 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
544 static const WCHAR diskdrive_mediatype_fixedW[] =
545 {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
546 static const WCHAR diskdrive_mediatype_removableW[] =
547 {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
548 static const WCHAR diskdrive_modelW[] =
549 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
550 static const WCHAR diskdrive_serialW[] =
551 {'W','I','N','E','H','D','I','S','K',0};
552 static const WCHAR networkadapter_pnpdeviceidW[]=
553 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
554 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
555 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
556 static const WCHAR os_32bitW[] =
557 {'3','2','-','b','i','t',0};
558 static const WCHAR os_64bitW[] =
559 {'6','4','-','b','i','t',0};
560 static const WCHAR os_buildnumberW[] =
561 {'2','6','0','0',0};
562 static const WCHAR os_captionW[] =
563 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
564 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
565 static const WCHAR os_csdversionW[] =
566 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
567 static const WCHAR os_installdateW[] =
568 {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
569 static const WCHAR os_nameW[] =
570 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
571 'P','r','o','f','e','s','s','i','o','n','a','l','|','C',':','\\','W','I','N','D','O','W','S',
572 '|','\\','D','e','v','i','c','e','\\','H','a','r','d','d','i','s','k','0',
573 '\\','P','a','r','t','i','t','i','o','n','1',0};
574 static const WCHAR os_serialnumberW[] =
575 {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
576 static const WCHAR os_versionW[] =
577 {'5','.','1','.','2','6','0','0',0};
578 static const WCHAR physicalmedia_tagW[] =
579 {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
580 static const WCHAR sounddevice_productnameW[] =
581 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
582 static const WCHAR videocontroller_dactypeW[] =
583 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
584 static const WCHAR videocontroller_deviceidW[] =
585 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
587 #include "pshpack1.h"
588 struct record_baseboard
590 const WCHAR *manufacturer;
591 const WCHAR *model;
592 const WCHAR *name;
593 const WCHAR *serialnumber;
594 const WCHAR *tag;
596 struct record_bios
598 const WCHAR *description;
599 const WCHAR *identificationcode;
600 const WCHAR *manufacturer;
601 const WCHAR *releasedate;
602 const WCHAR *serialnumber;
603 const WCHAR *smbiosbiosversion;
604 const WCHAR *version;
606 struct record_cdromdrive
608 const WCHAR *device_id;
609 const WCHAR *drive;
610 const WCHAR *mediatype;
611 const WCHAR *name;
612 const WCHAR *pnpdevice_id;
614 struct record_computersystem
616 const WCHAR *description;
617 const WCHAR *domain;
618 UINT16 domainrole;
619 const WCHAR *manufacturer;
620 const WCHAR *model;
621 const WCHAR *name;
622 UINT32 num_logical_processors;
623 UINT32 num_processors;
624 UINT64 total_physical_memory;
626 struct record_datafile
628 const WCHAR *name;
629 const WCHAR *version;
631 struct record_directory
633 UINT32 accessmask;
634 const WCHAR *name;
636 struct record_diskdrive
638 const WCHAR *device_id;
639 UINT32 index;
640 const WCHAR *interfacetype;
641 const WCHAR *manufacturer;
642 const WCHAR *mediatype;
643 const WCHAR *model;
644 const WCHAR *serialnumber;
645 UINT64 size;
647 struct record_diskpartition
649 int bootable;
650 int bootpartition;
651 const WCHAR *device_id;
652 UINT32 diskindex;
653 UINT32 index;
654 const WCHAR *pnpdevice_id;
655 UINT64 size;
656 UINT64 startingoffset;
657 const WCHAR *type;
659 struct record_logicaldisk
661 const WCHAR *device_id;
662 UINT32 drivetype;
663 const WCHAR *filesystem;
664 UINT64 freespace;
665 const WCHAR *name;
666 UINT64 size;
667 const WCHAR *volumeserialnumber;
669 struct record_networkadapter
671 const WCHAR *adaptertype;
672 const WCHAR *device_id;
673 UINT32 index;
674 UINT32 interface_index;
675 const WCHAR *mac_address;
676 const WCHAR *manufacturer;
677 const WCHAR *name;
678 UINT16 netconnection_status;
679 int physicaladapter;
680 const WCHAR *pnpdevice_id;
681 UINT64 speed;
683 struct record_networkadapterconfig
685 UINT32 index;
686 UINT32 ipconnectionmetric;
687 int ipenabled;
688 const WCHAR *mac_address;
690 struct record_operatingsystem
692 const WCHAR *buildnumber;
693 const WCHAR *caption;
694 const WCHAR *codeset;
695 const WCHAR *countrycode;
696 const WCHAR *csdversion;
697 const WCHAR *installdate;
698 const WCHAR *lastbootuptime;
699 const WCHAR *localdatetime;
700 const WCHAR *locale;
701 const WCHAR *name;
702 const WCHAR *osarchitecture;
703 UINT32 oslanguage;
704 UINT32 osproductsuite;
705 UINT16 ostype;
706 const WCHAR *serialnumber;
707 UINT16 servicepackmajor;
708 UINT16 servicepackminor;
709 UINT32 suitemask;
710 const WCHAR *systemdirectory;
711 const WCHAR *version;
713 struct record_param
715 const WCHAR *class;
716 const WCHAR *method;
717 INT32 direction;
718 const WCHAR *parameter;
719 UINT32 type;
720 UINT32 varianttype;
721 UINT32 defaultvalue;
723 struct record_physicalmedia
725 const WCHAR *serialnumber;
726 const WCHAR *tag;
728 struct record_physicalmemory
730 UINT64 capacity;
732 struct record_process
734 const WCHAR *caption;
735 const WCHAR *commandline;
736 const WCHAR *description;
737 const WCHAR *handle;
738 const WCHAR *name;
739 UINT32 pprocess_id;
740 UINT32 process_id;
741 UINT32 thread_count;
742 /* methods */
743 class_method *get_owner;
745 struct record_processor
747 UINT16 addresswidth;
748 UINT16 cpu_status;
749 const WCHAR *device_id;
750 UINT16 family;
751 const WCHAR *manufacturer;
752 UINT32 maxclockspeed;
753 const WCHAR *name;
754 UINT32 num_cores;
755 UINT32 num_logical_processors;
756 const WCHAR *processor_id;
757 const WCHAR *unique_id;
759 struct record_qualifier
761 const WCHAR *class;
762 const WCHAR *member;
763 UINT32 type;
764 INT32 flavor;
765 const WCHAR *name;
766 INT32 intvalue;
767 const WCHAR *strvalue;
769 struct record_service
771 int accept_pause;
772 int accept_stop;
773 const WCHAR *displayname;
774 const WCHAR *name;
775 UINT32 process_id;
776 const WCHAR *servicetype;
777 const WCHAR *startmode;
778 const WCHAR *state;
779 const WCHAR *systemname;
780 /* methods */
781 class_method *pause_service;
782 class_method *resume_service;
783 class_method *start_service;
784 class_method *stop_service;
786 struct record_sounddevice
788 const WCHAR *name;
789 const WCHAR *productname;
791 struct record_stdregprov
793 class_method *enumkey;
794 class_method *enumvalues;
795 class_method *getstringvalue;
797 struct record_videocontroller
799 const WCHAR *adapter_dactype;
800 UINT32 adapter_ram;
801 UINT16 availability;
802 UINT32 current_bitsperpixel;
803 UINT32 current_horizontalres;
804 UINT32 current_verticalres;
805 const WCHAR *description;
806 const WCHAR *device_id;
807 const WCHAR *name;
808 const WCHAR *pnpdevice_id;
810 #include "poppack.h"
812 static const struct record_baseboard data_baseboard[] =
814 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_tagW }
816 static const struct record_bios data_bios[] =
818 { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
819 bios_smbiosbiosversionW, bios_versionW }
821 static const struct record_param data_param[] =
823 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
824 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
825 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
826 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
827 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
828 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
829 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
830 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
831 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
832 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
833 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
834 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
835 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
836 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
837 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
838 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
839 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
840 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
841 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
842 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
843 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
846 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
847 WBEM_FLAVOR_ORIGIN_PROPAGATED)
849 static const struct record_physicalmedia data_physicalmedia[] =
851 { diskdrive_serialW, physicalmedia_tagW }
853 static const struct record_qualifier data_qualifier[] =
855 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
856 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
858 static const struct record_sounddevice data_sounddevice[] =
860 { sounddevice_productnameW, sounddevice_productnameW }
862 static const struct record_stdregprov data_stdregprov[] =
864 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
867 /* check if row matches condition and update status */
868 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
870 LONGLONG val;
871 UINT type;
873 if (!cond)
875 *status = FILL_STATUS_UNFILTERED;
876 return TRUE;
878 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
880 *status = FILL_STATUS_FAILED;
881 return FALSE;
883 *status = FILL_STATUS_FILTERED;
884 return val != 0;
887 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
889 if (!table->num_rows_allocated)
891 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
892 table->num_rows_allocated = row_count;
893 return TRUE;
895 if (row_count >= table->num_rows_allocated)
897 BYTE *data;
898 UINT count = table->num_rows_allocated * 2;
899 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
900 table->data = data;
901 table->num_rows_allocated = count;
903 return TRUE;
906 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
908 static const WCHAR fmtW[] = {'%','c',':',0};
909 WCHAR drive[3], root[] = {'A',':','\\',0};
910 struct record_cdromdrive *rec;
911 UINT i, row = 0, offset = 0;
912 DWORD drives = GetLogicalDrives();
913 enum fill_status status = FILL_STATUS_UNFILTERED;
915 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
917 for (i = 0; i < sizeof(drives); i++)
919 if (drives & (1 << i))
921 root[0] = 'A' + i;
922 if (GetDriveTypeW( root ) != DRIVE_CDROM)
923 continue;
925 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
927 rec = (struct record_cdromdrive *)(table->data + offset);
928 rec->device_id = cdromdrive_pnpdeviceidW;
929 sprintfW( drive, fmtW, 'A' + i );
930 rec->drive = heap_strdupW( drive );
931 rec->mediatype = cdromdrive_mediatypeW;
932 rec->name = cdromdrive_nameW;
933 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
934 if (!match_row( table, row, cond, &status ))
936 free_row_values( table, row );
937 continue;
939 offset += sizeof(*rec);
940 row++;
943 TRACE("created %u rows\n", row);
944 table->num_rows = row;
945 return status;
948 static UINT get_processor_count(void)
950 SYSTEM_BASIC_INFORMATION info;
952 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
953 return info.NumberOfProcessors;
956 static UINT get_logical_processor_count( UINT *num_cores )
958 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
959 UINT i, j, count = 0;
960 NTSTATUS status;
961 ULONG len;
963 if (num_cores) *num_cores = get_processor_count();
964 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
965 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
967 if (!(info = heap_alloc( len ))) return get_processor_count();
968 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
969 if (status != STATUS_SUCCESS)
971 heap_free( info );
972 return get_processor_count();
974 if (num_cores) *num_cores = 0;
975 for (i = 0; i < len / sizeof(*info); i++)
977 if (info[i].Relationship == RelationProcessorCore)
979 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
981 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
983 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
986 heap_free( info );
987 return count;
990 static UINT64 get_total_physical_memory(void)
992 MEMORYSTATUSEX status;
994 status.dwLength = sizeof(status);
995 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
996 return status.ullTotalPhys;
999 static WCHAR *get_computername(void)
1001 WCHAR *ret;
1002 DWORD size = MAX_COMPUTERNAME_LENGTH;
1004 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1005 GetComputerNameW( ret, &size );
1006 return ret;
1009 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1011 struct record_computersystem *rec;
1012 enum fill_status status = FILL_STATUS_UNFILTERED;
1013 UINT row = 0;
1015 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1017 rec = (struct record_computersystem *)table->data;
1018 rec->description = compsys_descriptionW;
1019 rec->domain = compsys_domainW;
1020 rec->domainrole = 0; /* standalone workstation */
1021 rec->manufacturer = compsys_manufacturerW;
1022 rec->model = compsys_modelW;
1023 rec->name = get_computername();
1024 rec->num_logical_processors = get_logical_processor_count( NULL );
1025 rec->num_processors = get_processor_count();
1026 rec->total_physical_memory = get_total_physical_memory();
1027 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1028 else row++;
1030 TRACE("created %u rows\n", row);
1031 table->num_rows = row;
1032 return status;
1035 struct dirstack
1037 WCHAR **dirs;
1038 UINT *len_dirs;
1039 UINT num_dirs;
1040 UINT num_allocated;
1043 static struct dirstack *alloc_dirstack( UINT size )
1045 struct dirstack *dirstack;
1047 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
1048 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
1050 heap_free( dirstack );
1051 return NULL;
1053 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1055 heap_free( dirstack->dirs );
1056 heap_free( dirstack );
1057 return NULL;
1059 dirstack->num_dirs = 0;
1060 dirstack->num_allocated = size;
1061 return dirstack;
1064 static void clear_dirstack( struct dirstack *dirstack )
1066 UINT i;
1067 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1068 dirstack->num_dirs = 0;
1071 static void free_dirstack( struct dirstack *dirstack )
1073 clear_dirstack( dirstack );
1074 heap_free( dirstack->dirs );
1075 heap_free( dirstack->len_dirs );
1076 heap_free( dirstack );
1079 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1081 UINT size, i = dirstack->num_dirs;
1083 if (!dir) return FALSE;
1085 if (i == dirstack->num_allocated)
1087 WCHAR **tmp;
1088 UINT *len_tmp;
1090 size = dirstack->num_allocated * 2;
1091 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1092 dirstack->dirs = tmp;
1093 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1094 dirstack->len_dirs = len_tmp;
1095 dirstack->num_allocated = size;
1097 dirstack->dirs[i] = dir;
1098 dirstack->len_dirs[i] = len;
1099 dirstack->num_dirs++;
1100 return TRUE;
1103 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1105 if (!dirstack->num_dirs)
1107 *len = 0;
1108 return NULL;
1110 dirstack->num_dirs--;
1111 *len = dirstack->len_dirs[dirstack->num_dirs];
1112 return dirstack->dirs[dirstack->num_dirs];
1115 static const WCHAR *peek_dir( struct dirstack *dirstack )
1117 if (!dirstack->num_dirs) return NULL;
1118 return dirstack->dirs[dirstack->num_dirs - 1];
1121 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1123 UINT i = 0;
1124 WCHAR *ret;
1126 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1127 ret[i++] = drive;
1128 ret[i++] = ':';
1129 ret[i++] = '\\';
1130 if (path && len)
1132 memcpy( ret + i, path, len * sizeof(WCHAR) );
1133 i += len;
1134 ret[i++] = '\\';
1136 ret[i++] = '*';
1137 ret[i] = 0;
1138 return ret;
1141 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1143 UINT i = 0, len = 0;
1144 const WCHAR *p;
1145 WCHAR *ret;
1147 for (p = path; *p; p++)
1149 if (*p == '\\') len += 2;
1150 else len++;
1152 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1153 ret[i++] = drive;
1154 ret[i++] = ':';
1155 ret[i++] = '\\';
1156 ret[i++] = '\\';
1157 for (p = path; *p; p++)
1159 if (*p != '\\') ret[i++] = *p;
1160 else
1162 ret[i++] = '\\';
1163 ret[i++] = '\\';
1166 ret[i] = 0;
1167 return ret;
1170 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1172 const WCHAR *p = path, *start;
1173 UINT len, i;
1174 WCHAR *ret;
1176 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1177 start = path + 4;
1178 len = strlenW( start );
1179 p = start + len - 1;
1180 if (*p == '\\') return NULL;
1182 while (p >= start && *p != '\\') { len--; p--; };
1183 while (p >= start && *p == '\\') { len--; p--; };
1185 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1186 for (i = 0, p = start; p < start + len; p++)
1188 if (p[0] == '\\' && p[1] == '\\')
1190 ret[i++] = '\\';
1191 p++;
1193 else ret[i++] = *p;
1195 ret[i] = 0;
1196 *ret_len = i;
1197 return ret;
1200 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1202 UINT i;
1203 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1204 return FALSE;
1207 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1208 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1210 const struct expr *left, *right;
1212 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1214 left = cond->u.expr.left;
1215 right = cond->u.expr.right;
1216 if (cond->u.expr.op == OP_EQ)
1218 UINT len;
1219 WCHAR *path;
1220 const WCHAR *str = NULL;
1222 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1223 !strcmpW( left->u.propval->name, prop_nameW ) &&
1224 toupperW( right->u.sval[0] ) == toupperW( root ))
1226 str = right->u.sval;
1228 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1229 !strcmpW( right->u.propval->name, prop_nameW ) &&
1230 toupperW( left->u.sval[0] ) == toupperW( root ))
1232 str = left->u.sval;
1234 if (str && (path = build_dirname( str, &len )))
1236 if (seen_dir( dirstack, path ))
1238 heap_free( path );
1239 return ++*count;
1241 else if (push_dir( dirstack, path, len )) return ++*count;
1242 heap_free( path );
1243 return *count = 0;
1246 else if (cond->u.expr.op == OP_OR)
1248 UINT left_count = 0, right_count = 0;
1250 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1251 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1252 return *count += left_count + right_count;
1254 return *count = 0;
1257 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1259 UINT len_path = 0, len_segment = strlenW( segment );
1260 WCHAR *ret;
1262 *len = 0;
1263 if (path) len_path = strlenW( path );
1264 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1265 if (path && len_path)
1267 memcpy( ret, path, len_path * sizeof(WCHAR) );
1268 ret[len_path] = '\\';
1269 *len += len_path + 1;
1271 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1272 *len += len_segment;
1273 ret[*len] = 0;
1274 return ret;
1277 static WCHAR *get_file_version( const WCHAR *filename )
1279 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1280 VS_FIXEDFILEINFO *info;
1281 DWORD size;
1282 void *block;
1283 WCHAR *ret;
1285 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1286 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1288 heap_free( ret );
1289 return NULL;
1291 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1292 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1294 heap_free( block );
1295 heap_free( ret );
1296 return NULL;
1298 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1299 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1300 heap_free( block );
1301 return ret;
1304 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1306 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1307 struct record_datafile *rec;
1308 UINT i, len, row = 0, offset = 0, num_expected_rows;
1309 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1310 DWORD drives = GetLogicalDrives();
1311 WIN32_FIND_DATAW data;
1312 HANDLE handle;
1313 struct dirstack *dirstack;
1314 enum fill_status status = FILL_STATUS_UNFILTERED;
1316 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1318 dirstack = alloc_dirstack(2);
1320 for (i = 0; i < sizeof(drives); i++)
1322 if (!(drives & (1 << i))) continue;
1324 root[0] = 'A' + i;
1325 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1327 num_expected_rows = 0;
1328 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1330 for (;;)
1332 path = pop_dir( dirstack, &len );
1333 if (!(glob = build_glob( root[0], path, len )))
1335 status = FILL_STATUS_FAILED;
1336 goto done;
1338 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1342 if (!resize_table( table, row + 1, sizeof(*rec) ))
1344 status = FILL_STATUS_FAILED;
1345 FindClose( handle );
1346 goto done;
1348 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1349 new_path = append_path( path, data.cFileName, &len );
1351 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1353 if (push_dir( dirstack, new_path, len )) continue;
1354 heap_free( new_path );
1355 FindClose( handle );
1356 status = FILL_STATUS_FAILED;
1357 goto done;
1359 rec = (struct record_datafile *)(table->data + offset);
1360 rec->name = build_name( root[0], new_path );
1361 rec->version = get_file_version( rec->name );
1362 if (!match_row( table, row, cond, &status ))
1364 free_row_values( table, row );
1365 continue;
1367 else if (num_expected_rows && row == num_expected_rows - 1)
1369 row++;
1370 FindClose( handle );
1371 status = FILL_STATUS_FILTERED;
1372 goto done;
1374 offset += sizeof(*rec);
1375 row++;
1377 while (FindNextFileW( handle, &data ));
1378 FindClose( handle );
1380 if (!peek_dir( dirstack )) break;
1381 heap_free( glob );
1382 heap_free( path );
1386 done:
1387 free_dirstack( dirstack );
1388 heap_free( glob );
1389 heap_free( path );
1391 TRACE("created %u rows\n", row);
1392 table->num_rows = row;
1393 return status;
1396 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1398 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1399 struct record_directory *rec;
1400 UINT i, len, row = 0, offset = 0, num_expected_rows;
1401 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1402 DWORD drives = GetLogicalDrives();
1403 WIN32_FIND_DATAW data;
1404 HANDLE handle;
1405 struct dirstack *dirstack;
1406 enum fill_status status = FILL_STATUS_UNFILTERED;
1408 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1410 dirstack = alloc_dirstack(2);
1412 for (i = 0; i < sizeof(drives); i++)
1414 if (!(drives & (1 << i))) continue;
1416 root[0] = 'A' + i;
1417 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1419 num_expected_rows = 0;
1420 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1422 for (;;)
1424 path = pop_dir( dirstack, &len );
1425 if (!(glob = build_glob( root[0], path, len )))
1427 status = FILL_STATUS_FAILED;
1428 goto done;
1430 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1434 if (!resize_table( table, row + 1, sizeof(*rec) ))
1436 FindClose( handle );
1437 status = FILL_STATUS_FAILED;
1438 goto done;
1440 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1441 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1442 continue;
1444 new_path = append_path( path, data.cFileName, &len );
1445 if (!(push_dir( dirstack, new_path, len )))
1447 heap_free( new_path );
1448 FindClose( handle );
1449 status = FILL_STATUS_FAILED;
1450 goto done;
1452 rec = (struct record_directory *)(table->data + offset);
1453 rec->accessmask = FILE_ALL_ACCESS;
1454 rec->name = build_name( root[0], new_path );
1455 if (!match_row( table, row, cond, &status ))
1457 free_row_values( table, row );
1458 continue;
1460 else if (num_expected_rows && row == num_expected_rows - 1)
1462 row++;
1463 FindClose( handle );
1464 status = FILL_STATUS_FILTERED;
1465 goto done;
1467 offset += sizeof(*rec);
1468 row++;
1470 while (FindNextFileW( handle, &data ));
1471 FindClose( handle );
1473 if (!peek_dir( dirstack )) break;
1474 heap_free( glob );
1475 heap_free( path );
1479 done:
1480 free_dirstack( dirstack );
1481 heap_free( glob );
1482 heap_free( path );
1484 TRACE("created %u rows\n", row);
1485 table->num_rows = row;
1486 return status;
1489 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1491 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1492 ULARGE_INTEGER free;
1493 DISK_GEOMETRY_EX info;
1494 HANDLE handle;
1496 free.QuadPart = 512 * 1024 * 1024;
1497 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1499 root[4] = dir[0];
1500 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1501 if (handle != INVALID_HANDLE_VALUE)
1503 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
1504 *disksize = info.DiskSize.QuadPart;
1505 CloseHandle( handle );
1507 return free.QuadPart;
1510 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
1512 static const WCHAR fmtW[] =
1513 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
1514 WCHAR device_id[sizeof(fmtW)/sizeof(fmtW[0]) + 10], root[] = {'A',':','\\',0};
1515 struct record_diskdrive *rec;
1516 UINT i, row = 0, offset = 0, index = 0, type;
1517 UINT64 size = 1024 * 1024 * 1024;
1518 DWORD drives = GetLogicalDrives();
1519 enum fill_status status = FILL_STATUS_UNFILTERED;
1521 if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
1523 for (i = 0; i < sizeof(drives); i++)
1525 if (drives & (1 << i))
1527 root[0] = 'A' + i;
1528 type = GetDriveTypeW( root );
1529 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1530 continue;
1532 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1534 rec = (struct record_diskdrive *)(table->data + offset);
1535 sprintfW( device_id, fmtW, index );
1536 rec->device_id = heap_strdupW( device_id );
1537 rec->index = index;
1538 rec->interfacetype = diskdrive_interfacetypeW;
1539 rec->manufacturer = diskdrive_manufacturerW;
1540 if (type == DRIVE_FIXED)
1541 rec->mediatype = diskdrive_mediatype_fixedW;
1542 else
1543 rec->mediatype = diskdrive_mediatype_removableW;
1544 rec->model = diskdrive_modelW;
1545 rec->serialnumber = diskdrive_serialW;
1546 get_freespace( root, &size );
1547 rec->size = size;
1548 if (!match_row( table, row, cond, &status ))
1550 free_row_values( table, row );
1551 continue;
1553 offset += sizeof(*rec);
1554 index++;
1555 row++;
1558 TRACE("created %u rows\n", row);
1559 table->num_rows = row;
1560 return status;
1563 static WCHAR *get_filesystem( const WCHAR *root )
1565 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1566 WCHAR buffer[MAX_PATH + 1];
1568 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1569 return heap_strdupW( buffer );
1570 return heap_strdupW( ntfsW );
1573 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1575 static const WCHAR fmtW[] =
1576 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1577 WCHAR device_id[32], root[] = {'A',':','\\',0};
1578 struct record_diskpartition *rec;
1579 UINT i, row = 0, offset = 0, type, index = 0;
1580 UINT64 size = 1024 * 1024 * 1024;
1581 DWORD drives = GetLogicalDrives();
1582 enum fill_status status = FILL_STATUS_UNFILTERED;
1584 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1586 for (i = 0; i < sizeof(drives); i++)
1588 if (drives & (1 << i))
1590 root[0] = 'A' + i;
1591 type = GetDriveTypeW( root );
1592 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1593 continue;
1595 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1597 rec = (struct record_diskpartition *)(table->data + offset);
1598 rec->bootable = (i == 2) ? -1 : 0;
1599 rec->bootpartition = (i == 2) ? -1 : 0;
1600 sprintfW( device_id, fmtW, index );
1601 rec->device_id = heap_strdupW( device_id );
1602 rec->diskindex = index;
1603 rec->index = 0;
1604 rec->pnpdevice_id = heap_strdupW( device_id );
1605 get_freespace( root, &size );
1606 rec->size = size;
1607 rec->startingoffset = 0;
1608 rec->type = get_filesystem( root );
1609 if (!match_row( table, row, cond, &status ))
1611 free_row_values( table, row );
1612 continue;
1614 offset += sizeof(*rec);
1615 row++;
1616 index++;
1619 TRACE("created %u rows\n", row);
1620 table->num_rows = row;
1621 return status;
1624 static WCHAR *get_volumeserialnumber( const WCHAR *root )
1626 static const WCHAR fmtW[] = {'%','0','8','X',0};
1627 DWORD serial = 0;
1628 WCHAR buffer[9];
1630 GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
1631 sprintfW( buffer, fmtW, serial );
1632 return heap_strdupW( buffer );
1635 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1637 static const WCHAR fmtW[] = {'%','c',':',0};
1638 WCHAR device_id[3], root[] = {'A',':','\\',0};
1639 struct record_logicaldisk *rec;
1640 UINT i, row = 0, offset = 0, type;
1641 UINT64 size = 1024 * 1024 * 1024;
1642 DWORD drives = GetLogicalDrives();
1643 enum fill_status status = FILL_STATUS_UNFILTERED;
1645 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1647 for (i = 0; i < sizeof(drives); i++)
1649 if (drives & (1 << i))
1651 root[0] = 'A' + i;
1652 type = GetDriveTypeW( root );
1653 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1654 continue;
1656 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1658 rec = (struct record_logicaldisk *)(table->data + offset);
1659 sprintfW( device_id, fmtW, 'A' + i );
1660 rec->device_id = heap_strdupW( device_id );
1661 rec->drivetype = type;
1662 rec->filesystem = get_filesystem( root );
1663 rec->freespace = get_freespace( root, &size );
1664 rec->name = heap_strdupW( device_id );
1665 rec->size = size;
1666 rec->volumeserialnumber = get_volumeserialnumber( root );
1667 if (!match_row( table, row, cond, &status ))
1669 free_row_values( table, row );
1670 continue;
1672 offset += sizeof(*rec);
1673 row++;
1676 TRACE("created %u rows\n", row);
1677 table->num_rows = row;
1678 return status;
1681 static UINT16 get_connection_status( IF_OPER_STATUS status )
1683 switch (status)
1685 case IfOperStatusDown:
1686 return 0; /* Disconnected */
1687 case IfOperStatusUp:
1688 return 2; /* Connected */
1689 default:
1690 ERR("unhandled status %u\n", status);
1691 break;
1693 return 0;
1695 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1697 static const WCHAR fmtW[] =
1698 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1699 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1700 WCHAR *ret;
1702 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1703 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1704 return ret;
1706 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1708 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1709 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1710 static const WCHAR firewireW[] = {'1','3','9','4',0};
1711 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1713 switch (type)
1715 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1716 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1717 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1718 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1719 default: *physical = 0; return NULL;
1723 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1725 static const WCHAR fmtW[] = {'%','u',0};
1726 WCHAR device_id[11];
1727 struct record_networkadapter *rec;
1728 IP_ADAPTER_ADDRESSES *aa, *buffer;
1729 UINT row = 0, offset = 0, count = 0;
1730 DWORD size = 0, ret;
1731 int physical;
1732 enum fill_status status = FILL_STATUS_UNFILTERED;
1734 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1735 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1737 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1738 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1740 heap_free( buffer );
1741 return FILL_STATUS_FAILED;
1743 for (aa = buffer; aa; aa = aa->Next)
1745 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1747 if (!resize_table( table, count, sizeof(*rec) ))
1749 heap_free( buffer );
1750 return FILL_STATUS_FAILED;
1752 for (aa = buffer; aa; aa = aa->Next)
1754 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1756 rec = (struct record_networkadapter *)(table->data + offset);
1757 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1758 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1759 rec->device_id = heap_strdupW( device_id );
1760 rec->index = aa->u.s.IfIndex;
1761 rec->interface_index = aa->u.s.IfIndex;
1762 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1763 rec->manufacturer = compsys_manufacturerW;
1764 rec->name = heap_strdupW( aa->FriendlyName );
1765 rec->netconnection_status = get_connection_status( aa->OperStatus );
1766 rec->physicaladapter = physical;
1767 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1768 rec->speed = 1000000;
1769 if (!match_row( table, row, cond, &status ))
1771 free_row_values( table, row );
1772 continue;
1774 offset += sizeof(*rec);
1775 row++;
1777 TRACE("created %u rows\n", row);
1778 table->num_rows = row;
1780 heap_free( buffer );
1781 return status;
1784 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1786 struct record_networkadapterconfig *rec;
1787 IP_ADAPTER_ADDRESSES *aa, *buffer;
1788 UINT row = 0, offset = 0, count = 0;
1789 DWORD size = 0, ret;
1790 enum fill_status status = FILL_STATUS_UNFILTERED;
1792 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1793 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1795 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1796 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1798 heap_free( buffer );
1799 return FILL_STATUS_FAILED;
1801 for (aa = buffer; aa; aa = aa->Next)
1803 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1805 if (!resize_table( table, count, sizeof(*rec) ))
1807 heap_free( buffer );
1808 return FILL_STATUS_FAILED;
1810 for (aa = buffer; aa; aa = aa->Next)
1812 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1814 rec = (struct record_networkadapterconfig *)(table->data + offset);
1815 rec->index = aa->u.s.IfIndex;
1816 rec->ipconnectionmetric = 20;
1817 rec->ipenabled = -1;
1818 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1819 if (!match_row( table, row, cond, &status ))
1821 free_row_values( table, row );
1822 continue;
1824 offset += sizeof(*rec);
1825 row++;
1827 TRACE("created %u rows\n", row);
1828 table->num_rows = row;
1830 heap_free( buffer );
1831 return status;
1834 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
1836 struct record_physicalmemory *rec;
1837 enum fill_status status = FILL_STATUS_UNFILTERED;
1838 UINT row = 0;
1840 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1842 rec = (struct record_physicalmemory *)table->data;
1843 rec->capacity = get_total_physical_memory();
1844 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1845 else row++;
1847 TRACE("created %u rows\n", row);
1848 table->num_rows = row;
1849 return status;
1852 static WCHAR *get_cmdline( DWORD process_id )
1854 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1855 return NULL; /* FIXME handle different process case */
1858 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1860 static const WCHAR fmtW[] = {'%','u',0};
1861 WCHAR handle[11];
1862 struct record_process *rec;
1863 PROCESSENTRY32W entry;
1864 HANDLE snap;
1865 enum fill_status status = FILL_STATUS_FAILED;
1866 UINT row = 0, offset = 0;
1868 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1869 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1871 entry.dwSize = sizeof(entry);
1872 if (!Process32FirstW( snap, &entry )) goto done;
1873 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1877 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1879 rec = (struct record_process *)(table->data + offset);
1880 rec->caption = heap_strdupW( entry.szExeFile );
1881 rec->commandline = get_cmdline( entry.th32ProcessID );
1882 rec->description = heap_strdupW( entry.szExeFile );
1883 sprintfW( handle, fmtW, entry.th32ProcessID );
1884 rec->handle = heap_strdupW( handle );
1885 rec->name = heap_strdupW( entry.szExeFile );
1886 rec->process_id = entry.th32ProcessID;
1887 rec->pprocess_id = entry.th32ParentProcessID;
1888 rec->thread_count = entry.cntThreads;
1889 rec->get_owner = process_get_owner;
1890 if (!match_row( table, row, cond, &status ))
1892 free_row_values( table, row );
1893 continue;
1895 offset += sizeof(*rec);
1896 row++;
1897 } while (Process32NextW( snap, &entry ));
1899 TRACE("created %u rows\n", row);
1900 table->num_rows = row;
1901 status = FILL_STATUS_UNFILTERED;
1903 done:
1904 CloseHandle( snap );
1905 return status;
1908 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1910 #ifdef __i386__
1911 __asm__("pushl %%ebx\n\t"
1912 "cpuid\n\t"
1913 "movl %%ebx, %%esi\n\t"
1914 "popl %%ebx"
1915 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1916 : "0" (ax));
1917 #endif
1920 static void get_processor_id( WCHAR *processor_id )
1922 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1923 unsigned int regs[4] = {0, 0, 0, 0};
1925 do_cpuid( 1, regs );
1926 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1928 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1930 unsigned int i;
1931 unsigned char *p = (unsigned char *)regs;
1933 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1934 buffer[i] = 0;
1936 static void get_processor_manufacturer( WCHAR *manufacturer )
1938 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1940 do_cpuid( 0, regs );
1941 tmp = regs[2]; /* swap edx and ecx */
1942 regs[2] = regs[3];
1943 regs[3] = tmp;
1945 regs_to_str( regs + 1, 12, manufacturer );
1947 static void get_processor_name( WCHAR *name )
1949 unsigned int regs[4] = {0, 0, 0, 0};
1951 do_cpuid( 0x80000000, regs );
1952 if (regs[0] >= 0x80000004)
1954 do_cpuid( 0x80000002, regs );
1955 regs_to_str( regs, 16, name );
1956 do_cpuid( 0x80000003, regs );
1957 regs_to_str( regs, 16, name + 16 );
1958 do_cpuid( 0x80000004, regs );
1959 regs_to_str( regs, 16, name + 32 );
1962 static UINT get_processor_maxclockspeed( void )
1964 PROCESSOR_POWER_INFORMATION *info;
1965 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1966 NTSTATUS status;
1968 if ((info = heap_alloc( size )))
1970 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1971 if (!status) ret = info[0].MaxMhz;
1972 heap_free( info );
1974 return ret;
1976 static const WCHAR *get_osarchitecture(void)
1978 SYSTEM_INFO info;
1979 GetNativeSystemInfo( &info );
1980 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1981 return os_32bitW;
1984 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
1986 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
1987 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
1988 struct record_processor *rec;
1989 UINT i, offset = 0, maxclockspeed, num_cores, num_logical_processors, count = get_processor_count();
1990 enum fill_status status = FILL_STATUS_UNFILTERED;
1992 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
1994 get_processor_id( processor_id );
1995 get_processor_manufacturer( manufacturer );
1996 get_processor_name( name );
1998 maxclockspeed = get_processor_maxclockspeed();
1999 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
2000 num_cores /= count;
2002 for (i = 0; i < count; i++)
2004 rec = (struct record_processor *)(table->data + offset);
2005 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
2006 rec->cpu_status = 1; /* CPU Enabled */
2007 sprintfW( device_id, fmtW, i );
2008 rec->device_id = heap_strdupW( device_id );
2009 rec->family = 2; /* Unknown */
2010 rec->manufacturer = heap_strdupW( manufacturer );
2011 rec->maxclockspeed = maxclockspeed;
2012 rec->name = heap_strdupW( name );
2013 rec->num_cores = num_cores;
2014 rec->num_logical_processors = num_logical_processors;
2015 rec->processor_id = heap_strdupW( processor_id );
2016 rec->unique_id = NULL;
2017 if (!match_row( table, i, cond, &status ))
2019 free_row_values( table, i );
2020 continue;
2022 offset += sizeof(*rec);
2025 TRACE("created %u rows\n", count);
2026 table->num_rows = count;
2027 return status;
2030 static WCHAR *get_lastbootuptime(void)
2032 static const WCHAR fmtW[] =
2033 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2034 '.','%','0','6','u','+','0','0','0',0};
2035 SYSTEM_TIMEOFDAY_INFORMATION ti;
2036 TIME_FIELDS tf;
2037 WCHAR *ret;
2039 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2041 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
2042 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
2043 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
2044 return ret;
2046 static WCHAR *get_localdatetime(void)
2048 static const WCHAR fmtW[] =
2049 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
2050 '.','%','0','6','u','%','+','0','3','d',0};
2051 TIME_ZONE_INFORMATION tzi;
2052 SYSTEMTIME st;
2053 WCHAR *ret;
2054 DWORD Status;
2055 LONG Bias;
2057 Status = GetTimeZoneInformation(&tzi);
2059 if(Status == TIME_ZONE_ID_INVALID) return NULL;
2060 Bias = tzi.Bias;
2061 if(Status == TIME_ZONE_ID_DAYLIGHT)
2062 Bias+= tzi.DaylightBias;
2063 else
2064 Bias+= tzi.StandardBias;
2065 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
2067 GetLocalTime(&st);
2068 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
2069 return ret;
2071 static WCHAR *get_systemdirectory(void)
2073 void *redir;
2074 WCHAR *ret;
2076 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
2077 Wow64DisableWow64FsRedirection( &redir );
2078 GetSystemDirectoryW( ret, MAX_PATH );
2079 Wow64RevertWow64FsRedirection( redir );
2080 return ret;
2082 static WCHAR *get_codeset(void)
2084 static const WCHAR fmtW[] = {'%','u',0};
2085 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
2086 if (ret) sprintfW( ret, fmtW, GetACP() );
2087 return ret;
2089 static WCHAR *get_countrycode(void)
2091 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
2092 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
2093 return ret;
2095 static WCHAR *get_locale(void)
2097 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
2098 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
2099 return ret;
2102 static enum fill_status fill_os( struct table *table, const struct expr *cond )
2104 struct record_operatingsystem *rec;
2105 enum fill_status status = FILL_STATUS_UNFILTERED;
2106 UINT row = 0;
2108 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2110 rec = (struct record_operatingsystem *)table->data;
2111 rec->buildnumber = os_buildnumberW;
2112 rec->caption = os_captionW;
2113 rec->codeset = get_codeset();
2114 rec->countrycode = get_countrycode();
2115 rec->csdversion = os_csdversionW;
2116 rec->installdate = os_installdateW;
2117 rec->lastbootuptime = get_lastbootuptime();
2118 rec->localdatetime = get_localdatetime();
2119 rec->locale = get_locale();
2120 rec->name = os_nameW;
2121 rec->osarchitecture = get_osarchitecture();
2122 rec->oslanguage = GetSystemDefaultLangID();
2123 rec->osproductsuite = 2461140; /* Windows XP Professional */
2124 rec->ostype = 18; /* WINNT */
2125 rec->serialnumber = os_serialnumberW;
2126 rec->servicepackmajor = 3;
2127 rec->servicepackminor = 0;
2128 rec->suitemask = 272; /* Single User + Terminal */
2129 rec->systemdirectory = get_systemdirectory();
2130 rec->version = os_versionW;
2131 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2132 else row++;
2134 TRACE("created %u rows\n", row);
2135 table->num_rows = row;
2136 return status;
2139 static const WCHAR *get_service_type( DWORD type )
2141 static const WCHAR filesystem_driverW[] =
2142 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
2143 static const WCHAR kernel_driverW[] =
2144 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2145 static const WCHAR own_processW[] =
2146 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2147 static const WCHAR share_processW[] =
2148 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2150 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2151 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2152 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2153 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2154 else ERR("unhandled type 0x%08x\n", type);
2155 return NULL;
2157 static const WCHAR *get_service_state( DWORD state )
2159 static const WCHAR runningW[] =
2160 {'R','u','n','n','i','n','g',0};
2161 static const WCHAR start_pendingW[] =
2162 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2163 static const WCHAR stop_pendingW[] =
2164 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2165 static const WCHAR stoppedW[] =
2166 {'S','t','o','p','p','e','d',0};
2167 static const WCHAR unknownW[] =
2168 {'U','n','k','n','o','w','n',0};
2170 switch (state)
2172 case SERVICE_STOPPED: return stoppedW;
2173 case SERVICE_START_PENDING: return start_pendingW;
2174 case SERVICE_STOP_PENDING: return stop_pendingW;
2175 case SERVICE_RUNNING: return runningW;
2176 default:
2177 ERR("unknown state %u\n", state);
2178 return unknownW;
2181 static const WCHAR *get_service_startmode( DWORD mode )
2183 static const WCHAR bootW[] = {'B','o','o','t',0};
2184 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2185 static const WCHAR autoW[] = {'A','u','t','o',0};
2186 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2187 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2188 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2190 switch (mode)
2192 case SERVICE_BOOT_START: return bootW;
2193 case SERVICE_SYSTEM_START: return systemW;
2194 case SERVICE_AUTO_START: return autoW;
2195 case SERVICE_DEMAND_START: return manualW;
2196 case SERVICE_DISABLED: return disabledW;
2197 default:
2198 ERR("unknown mode 0x%x\n", mode);
2199 return unknownW;
2202 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2204 QUERY_SERVICE_CONFIGW *config = NULL;
2205 SC_HANDLE service;
2206 DWORD size;
2208 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2209 QueryServiceConfigW( service, NULL, 0, &size );
2210 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2211 if (!(config = heap_alloc( size ))) goto done;
2212 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2213 heap_free( config );
2214 config = NULL;
2216 done:
2217 CloseServiceHandle( service );
2218 return config;
2221 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2223 struct record_service *rec;
2224 SC_HANDLE manager;
2225 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2226 SERVICE_STATUS_PROCESS *status;
2227 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2228 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2229 UINT i, row = 0, offset = 0, size = 256, needed, count;
2230 enum fill_status fill_status = FILL_STATUS_FAILED;
2231 BOOL ret;
2233 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2234 if (!(services = heap_alloc( size ))) goto done;
2236 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2237 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2238 &count, NULL, NULL );
2239 if (!ret)
2241 if (GetLastError() != ERROR_MORE_DATA) goto done;
2242 size = needed;
2243 if (!(tmp = heap_realloc( services, size ))) goto done;
2244 services = tmp;
2245 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2246 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2247 &count, NULL, NULL );
2248 if (!ret) goto done;
2250 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2252 GetComputerNameW( sysnameW, &len );
2253 fill_status = FILL_STATUS_UNFILTERED;
2255 for (i = 0; i < count; i++)
2257 QUERY_SERVICE_CONFIGW *config;
2259 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2261 status = &services[i].ServiceStatusProcess;
2262 rec = (struct record_service *)(table->data + offset);
2263 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2264 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2265 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2266 rec->name = heap_strdupW( services[i].lpServiceName );
2267 rec->process_id = status->dwProcessId;
2268 rec->servicetype = get_service_type( status->dwServiceType );
2269 rec->startmode = get_service_startmode( config->dwStartType );
2270 rec->state = get_service_state( status->dwCurrentState );
2271 rec->systemname = heap_strdupW( sysnameW );
2272 rec->pause_service = service_pause_service;
2273 rec->resume_service = service_resume_service;
2274 rec->start_service = service_start_service;
2275 rec->stop_service = service_stop_service;
2276 heap_free( config );
2277 if (!match_row( table, row, cond, &fill_status ))
2279 free_row_values( table, row );
2280 continue;
2282 offset += sizeof(*rec);
2283 row++;
2286 TRACE("created %u rows\n", row);
2287 table->num_rows = row;
2289 done:
2290 CloseServiceHandle( manager );
2291 heap_free( services );
2292 return fill_status;
2295 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2297 HDC hdc = GetDC( NULL );
2298 UINT32 ret;
2300 if (!hdc) return 32;
2301 ret = GetDeviceCaps( hdc, BITSPIXEL );
2302 *hres = GetDeviceCaps( hdc, HORZRES );
2303 *vres = GetDeviceCaps( hdc, VERTRES );
2304 ReleaseDC( NULL, hdc );
2305 return ret;
2307 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2309 static const WCHAR fmtW[] =
2310 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2311 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2312 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2313 WCHAR *ret;
2315 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2316 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2317 return ret;
2320 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2323 struct record_videocontroller *rec;
2324 HRESULT hr;
2325 IDXGIFactory *factory = NULL;
2326 IDXGIAdapter *adapter = NULL;
2327 DXGI_ADAPTER_DESC desc;
2328 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2329 const WCHAR *name = videocontroller_deviceidW;
2330 enum fill_status status = FILL_STATUS_UNFILTERED;
2331 UINT row = 0;
2333 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2335 memset (&desc, 0, sizeof(desc));
2336 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2337 if (FAILED(hr)) goto done;
2339 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2340 if (FAILED(hr)) goto done;
2342 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2343 if (SUCCEEDED(hr))
2345 vidmem = desc.DedicatedVideoMemory;
2346 name = desc.Description;
2349 done:
2350 rec = (struct record_videocontroller *)table->data;
2351 rec->adapter_dactype = videocontroller_dactypeW;
2352 rec->adapter_ram = vidmem;
2353 rec->availability = 3; /* Running or Full Power */
2354 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2355 rec->current_horizontalres = hres;
2356 rec->current_verticalres = vres;
2357 rec->description = heap_strdupW( name );
2358 rec->device_id = videocontroller_deviceidW;
2359 rec->name = heap_strdupW( name );
2360 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2361 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2362 else row++;
2364 TRACE("created %u rows\n", row);
2365 table->num_rows = row;
2367 if (adapter) IDXGIAdapter_Release( adapter );
2368 if (factory) IDXGIFactory_Release( factory );
2369 return status;
2372 static struct table builtin_classes[] =
2374 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2375 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2376 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2377 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2378 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2379 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2380 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
2381 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2382 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2383 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2384 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2385 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2386 fill_networkadapterconfig },
2387 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2388 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2389 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
2390 { class_physicalmemoryW, SIZEOF(col_physicalmemory), col_physicalmemory, 0, 0, NULL, fill_physicalmemory },
2391 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2392 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2393 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2394 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2395 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2396 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2397 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2400 void init_table_list( void )
2402 static struct list tables = LIST_INIT( tables );
2403 UINT i;
2405 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2406 table_list = &tables;