jscript: Don't list LexicalDeclaration in Statement.
[wine.git] / server / directory.c
blob30d6945998474486146aaf2bacc69df8569d809a
1 /*
2 * Server-side directory object management
4 * Copyright (C) 2005 Vitaliy Margolen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <sys/types.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "winternl.h"
34 #include "ddk/wdm.h"
36 #include "handle.h"
37 #include "request.h"
38 #include "process.h"
39 #include "file.h"
40 #include "unicode.h"
42 #define HASH_SIZE 7 /* default hash size */
44 static const WCHAR objtype_name[] = {'T','y','p','e'};
46 struct type_descr objtype_type =
48 { objtype_name, sizeof(objtype_name) }, /* name */
49 STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1, /* valid_access */
50 { /* mapping */
51 STANDARD_RIGHTS_READ,
52 STANDARD_RIGHTS_WRITE,
53 STANDARD_RIGHTS_EXECUTE,
54 STANDARD_RIGHTS_REQUIRED | 0x1
58 struct object_type
60 struct object obj; /* object header */
63 static void object_type_dump( struct object *obj, int verbose );
65 static const struct object_ops object_type_ops =
67 sizeof(struct object_type), /* size */
68 &objtype_type, /* type */
69 object_type_dump, /* dump */
70 no_add_queue, /* add_queue */
71 NULL, /* remove_queue */
72 NULL, /* signaled */
73 NULL, /* satisfied */
74 no_signal, /* signal */
75 no_get_fd, /* get_fd */
76 default_map_access, /* map_access */
77 default_get_sd, /* get_sd */
78 default_set_sd, /* set_sd */
79 default_get_full_name, /* get_full_name */
80 no_lookup_name, /* lookup_name */
81 directory_link_name, /* link_name */
82 default_unlink_name, /* unlink_name */
83 no_open_file, /* open_file */
84 no_kernel_obj_list, /* get_kernel_obj_list */
85 no_close_handle, /* close_handle */
86 no_destroy /* destroy */
90 static const WCHAR directory_name[] = {'D','i','r','e','c','t','o','r','y'};
92 struct type_descr directory_type =
94 { directory_name, sizeof(directory_name) }, /* name */
95 DIRECTORY_ALL_ACCESS, /* valid_access */
96 { /* mapping */
97 STANDARD_RIGHTS_READ | DIRECTORY_TRAVERSE | DIRECTORY_QUERY,
98 STANDARD_RIGHTS_WRITE | DIRECTORY_CREATE_SUBDIRECTORY | DIRECTORY_CREATE_OBJECT,
99 STANDARD_RIGHTS_EXECUTE | DIRECTORY_TRAVERSE | DIRECTORY_QUERY,
100 DIRECTORY_ALL_ACCESS
104 struct directory
106 struct object obj; /* object header */
107 struct namespace *entries; /* directory's name space */
110 static void directory_dump( struct object *obj, int verbose );
111 static struct object *directory_lookup_name( struct object *obj, struct unicode_str *name,
112 unsigned int attr, struct object *root );
113 static void directory_destroy( struct object *obj );
115 static const struct object_ops directory_ops =
117 sizeof(struct directory), /* size */
118 &directory_type, /* type */
119 directory_dump, /* dump */
120 no_add_queue, /* add_queue */
121 NULL, /* remove_queue */
122 NULL, /* signaled */
123 NULL, /* satisfied */
124 no_signal, /* signal */
125 no_get_fd, /* get_fd */
126 default_map_access, /* map_access */
127 default_get_sd, /* get_sd */
128 default_set_sd, /* set_sd */
129 default_get_full_name, /* get_full_name */
130 directory_lookup_name, /* lookup_name */
131 directory_link_name, /* link_name */
132 default_unlink_name, /* unlink_name */
133 no_open_file, /* open_file */
134 no_kernel_obj_list, /* get_kernel_obj_list */
135 no_close_handle, /* close_handle */
136 directory_destroy /* destroy */
139 static struct directory *root_directory;
140 static struct directory *dir_objtype;
143 static struct type_descr *types[] =
145 &objtype_type,
146 &directory_type,
147 &symlink_type,
148 &token_type,
149 &job_type,
150 &process_type,
151 &thread_type,
152 &debug_obj_type,
153 &event_type,
154 &mutex_type,
155 &semaphore_type,
156 &timer_type,
157 &keyed_event_type,
158 &winstation_type,
159 &desktop_type,
160 &device_type,
161 &completion_type,
162 &file_type,
163 &mapping_type,
164 &key_type,
167 static void object_type_dump( struct object *obj, int verbose )
169 fputs( "Object type\n", stderr );
172 static struct object_type *create_object_type( struct object *root, unsigned int index,
173 unsigned int attr, const struct security_descriptor *sd )
175 struct type_descr *descr = types[index];
176 struct object_type *type;
178 if ((type = create_named_object( root, &object_type_ops, &descr->name, attr, sd )))
180 descr->index = index;
182 return type;
185 static void directory_dump( struct object *obj, int verbose )
187 fputs( "Directory\n", stderr );
190 static struct object *directory_lookup_name( struct object *obj, struct unicode_str *name,
191 unsigned int attr, struct object *root )
193 struct directory *dir = (struct directory *)obj;
194 struct object *found;
195 struct unicode_str tmp;
197 assert( obj->ops == &directory_ops );
199 if (!name) return NULL; /* open the directory itself */
201 tmp.str = name->str;
202 tmp.len = get_path_element( name->str, name->len );
204 if ((found = find_object( dir->entries, &tmp, attr )))
206 /* Skip trailing \\ and move to the next element */
207 if (tmp.len < name->len)
209 tmp.len += sizeof(WCHAR);
210 name->str += tmp.len / sizeof(WCHAR);
211 name->len -= tmp.len;
213 else
215 name->str = NULL;
216 name->len = 0;
218 return found;
221 if (name->str) /* not the last element */
223 if (tmp.len == 0) /* Double backslash */
224 set_error( STATUS_OBJECT_NAME_INVALID );
225 else if (tmp.len < name->len) /* Path still has backslashes */
226 set_error( STATUS_OBJECT_PATH_NOT_FOUND );
228 return NULL;
231 int directory_link_name( struct object *obj, struct object_name *name, struct object *parent )
233 struct directory *dir = (struct directory *)parent;
235 if (parent->ops != &directory_ops)
237 set_error( STATUS_OBJECT_TYPE_MISMATCH );
238 return 0;
240 namespace_add( dir->entries, name );
241 name->parent = grab_object( parent );
242 return 1;
245 static void directory_destroy( struct object *obj )
247 struct directory *dir = (struct directory *)obj;
248 assert( obj->ops == &directory_ops );
249 free( dir->entries );
252 static struct directory *create_directory( struct object *root, const struct unicode_str *name,
253 unsigned int attr, unsigned int hash_size,
254 const struct security_descriptor *sd )
256 struct directory *dir;
258 if ((dir = create_named_object( root, &directory_ops, name, attr, sd )) &&
259 get_error() != STATUS_OBJECT_NAME_EXISTS)
261 if (!(dir->entries = create_namespace( hash_size )))
263 release_object( dir );
264 return NULL;
267 return dir;
270 struct object *get_root_directory(void)
272 return grab_object( root_directory );
275 /* return a directory object for creating/opening some object; no access rights are required */
276 struct object *get_directory_obj( struct process *process, obj_handle_t handle )
278 return get_handle_obj( process, handle, 0, &directory_ops );
281 /* Global initialization */
283 static void create_session( unsigned int id )
285 /* directories */
286 static const WCHAR dir_sessionsW[] = {'S','e','s','s','i','o','n','s'};
287 static const WCHAR dir_bnolinksW[] = {'B','N','O','L','I','N','K','S'};
288 static const WCHAR dir_bnoW[] = {'B','a','s','e','N','a','m','e','d','O','b','j','e','c','t','s'};
289 static const WCHAR dir_dosdevicesW[] = {'D','o','s','D','e','v','i','c','e','s'};
290 static const WCHAR dir_windowsW[] = {'W','i','n','d','o','w','s'};
291 static const WCHAR dir_winstationsW[] = {'W','i','n','d','o','w','S','t','a','t','i','o','n','s'};
292 static const struct unicode_str dir_sessions_str = {dir_sessionsW, sizeof(dir_sessionsW)};
293 static const struct unicode_str dir_bnolinks_str = {dir_bnolinksW, sizeof(dir_bnolinksW)};
294 static const struct unicode_str dir_bno_str = {dir_bnoW, sizeof(dir_bnoW)};
295 static const struct unicode_str dir_dosdevices_str = {dir_dosdevicesW, sizeof(dir_dosdevicesW)};
296 static const struct unicode_str dir_windows_str = {dir_windowsW, sizeof(dir_windowsW)};
297 static const struct unicode_str dir_winstations_str = {dir_winstationsW, sizeof(dir_winstationsW)};
299 /* symlinks */
300 static const WCHAR link_globalW[] = {'G','l','o','b','a','l'};
301 static const WCHAR link_localW[] = {'L','o','c','a','l'};
302 static const WCHAR link_sessionW[] = {'S','e','s','s','i','o','n'};
303 static const struct unicode_str link_global_str = {link_globalW, sizeof(link_globalW)};
304 static const struct unicode_str link_local_str = {link_localW, sizeof(link_localW)};
305 static const struct unicode_str link_session_str = {link_sessionW, sizeof(link_sessionW)};
307 static struct directory *dir_bno_global, *dir_sessions, *dir_bnolinks;
308 struct directory *dir_id, *dir_bno, *dir_dosdevices, *dir_windows, *dir_winstation;
309 struct object *link_global, *link_local, *link_session, *link_bno, *link_windows;
310 struct unicode_str id_str;
311 char id_strA[10];
312 WCHAR *id_strW;
314 if (!id)
316 dir_bno_global = create_directory( &root_directory->obj, &dir_bno_str, OBJ_PERMANENT, HASH_SIZE, NULL );
317 dir_sessions = create_directory( &root_directory->obj, &dir_sessions_str, OBJ_PERMANENT, HASH_SIZE, NULL );
318 dir_bnolinks = create_directory( &dir_sessions->obj, &dir_bnolinks_str, OBJ_PERMANENT, HASH_SIZE, NULL );
319 release_object( dir_bno_global );
320 release_object( dir_bnolinks );
321 release_object( dir_sessions );
324 sprintf( id_strA, "%u", id );
325 id_strW = ascii_to_unicode_str( id_strA, &id_str );
326 dir_id = create_directory( &dir_sessions->obj, &id_str, 0, HASH_SIZE, NULL );
327 dir_dosdevices = create_directory( &dir_id->obj, &dir_dosdevices_str, OBJ_PERMANENT, HASH_SIZE, NULL );
329 /* for session 0, directories are created under the root */
330 if (!id)
332 dir_bno = (struct directory *)grab_object( dir_bno_global );
333 dir_windows = create_directory( &root_directory->obj, &dir_windows_str, 0, HASH_SIZE, NULL );
334 link_bno = create_obj_symlink( &dir_id->obj, &dir_bno_str, OBJ_PERMANENT, &dir_bno->obj, NULL );
335 link_windows = create_obj_symlink( &dir_id->obj, &dir_windows_str, OBJ_PERMANENT, &dir_windows->obj, NULL );
336 release_object( link_bno );
337 release_object( link_windows );
339 else
341 /* use a larger hash table for this one since it can contain a lot of objects */
342 dir_bno = create_directory( &dir_id->obj, &dir_bno_str, 0, 37, NULL );
343 dir_windows = create_directory( &dir_id->obj, &dir_windows_str, 0, HASH_SIZE, NULL );
345 dir_winstation = create_directory( &dir_windows->obj, &dir_winstations_str, OBJ_PERMANENT, HASH_SIZE, NULL );
347 link_global = create_obj_symlink( &dir_bno->obj, &link_global_str, OBJ_PERMANENT, &dir_bno_global->obj, NULL );
348 link_local = create_obj_symlink( &dir_bno->obj, &link_local_str, OBJ_PERMANENT, &dir_bno->obj, NULL );
349 link_session = create_obj_symlink( &dir_bno->obj, &link_session_str, OBJ_PERMANENT, &dir_bnolinks->obj, NULL );
350 link_bno = create_obj_symlink( &dir_bnolinks->obj, &id_str, OBJ_PERMANENT, &dir_bno->obj, NULL );
351 release_object( link_global );
352 release_object( link_local );
353 release_object( link_session );
354 release_object( link_bno );
356 release_object( dir_dosdevices );
357 release_object( dir_winstation );
358 release_object( dir_windows );
359 release_object( dir_bno );
360 release_object( dir_id );
361 free( id_strW );
364 void init_directories( struct fd *intl_fd )
366 /* Directories */
367 static const WCHAR dir_globalW[] = {'?','?'};
368 static const WCHAR dir_driverW[] = {'D','r','i','v','e','r'};
369 static const WCHAR dir_deviceW[] = {'D','e','v','i','c','e'};
370 static const WCHAR dir_objtypeW[] = {'O','b','j','e','c','t','T','y','p','e','s'};
371 static const WCHAR dir_kernelW[] = {'K','e','r','n','e','l','O','b','j','e','c','t','s'};
372 static const WCHAR dir_nlsW[] = {'N','L','S'};
373 static const struct unicode_str dir_global_str = {dir_globalW, sizeof(dir_globalW)};
374 static const struct unicode_str dir_driver_str = {dir_driverW, sizeof(dir_driverW)};
375 static const struct unicode_str dir_device_str = {dir_deviceW, sizeof(dir_deviceW)};
376 static const struct unicode_str dir_objtype_str = {dir_objtypeW, sizeof(dir_objtypeW)};
377 static const struct unicode_str dir_kernel_str = {dir_kernelW, sizeof(dir_kernelW)};
378 static const struct unicode_str dir_nls_str = {dir_nlsW, sizeof(dir_nlsW)};
380 /* symlinks */
381 static const WCHAR link_dosdevW[] = {'D','o','s','D','e','v','i','c','e','s'};
382 static const WCHAR link_globalW[] = {'G','l','o','b','a','l'};
383 static const WCHAR link_nulW[] = {'N','U','L'};
384 static const WCHAR link_pipeW[] = {'P','I','P','E'};
385 static const WCHAR link_mailslotW[] = {'M','A','I','L','S','L','O','T'};
386 static const WCHAR link_coninW[] = {'C','O','N','I','N','$'};
387 static const WCHAR link_conoutW[] = {'C','O','N','O','U','T','$'};
388 static const WCHAR link_conW[] = {'C','O','N'};
389 static const WCHAR link_currentinW[] = {'\\','D','e','v','i','c','e','\\','C','o','n','D','r','v',
390 '\\','C','u','r','r','e','n','t','I','n'};
391 static const WCHAR link_currentoutW[] = {'\\','D','e','v','i','c','e','\\','C','o','n','D','r','v',
392 '\\','C','u','r','r','e','n','t','O','u','t'};
393 static const WCHAR link_consoleW[] = {'\\','D','e','v','i','c','e','\\','C','o','n','D','r','v',
394 '\\','C','o','n','s','o','l','e'};
395 static const struct unicode_str link_dosdev_str = {link_dosdevW, sizeof(link_dosdevW)};
396 static const struct unicode_str link_global_str = {link_globalW, sizeof(link_globalW)};
397 static const struct unicode_str link_nul_str = {link_nulW, sizeof(link_nulW)};
398 static const struct unicode_str link_pipe_str = {link_pipeW, sizeof(link_pipeW)};
399 static const struct unicode_str link_mailslot_str = {link_mailslotW, sizeof(link_mailslotW)};
400 static const struct unicode_str link_con_str = {link_conW, sizeof(link_conW)};
401 static const struct unicode_str link_conin_str = {link_coninW, sizeof(link_coninW)};
402 static const struct unicode_str link_conout_str = {link_conoutW, sizeof(link_conoutW)};
403 static const struct unicode_str link_currentin_str = {link_currentinW, sizeof(link_currentinW)};
404 static const struct unicode_str link_currentout_str = {link_currentoutW, sizeof(link_currentoutW)};
405 static const struct unicode_str link_console_str = {link_consoleW, sizeof(link_consoleW)};
407 /* devices */
408 static const WCHAR named_pipeW[] = {'N','a','m','e','d','P','i','p','e'};
409 static const WCHAR mailslotW[] = {'M','a','i','l','S','l','o','t'};
410 static const WCHAR condrvW[] = {'C','o','n','D','r','v'};
411 static const WCHAR nullW[] = {'N','u','l','l'};
412 static const WCHAR afdW[] = {'A','f','d'};
413 static const struct unicode_str named_pipe_str = {named_pipeW, sizeof(named_pipeW)};
414 static const struct unicode_str mailslot_str = {mailslotW, sizeof(mailslotW)};
415 static const struct unicode_str condrv_str = {condrvW, sizeof(condrvW)};
416 static const struct unicode_str null_str = {nullW, sizeof(nullW)};
417 static const struct unicode_str afd_str = {afdW, sizeof(afdW)};
419 /* events */
420 static const WCHAR event_low_memW[] = {'L','o','w','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n'};
421 static const WCHAR event_low_pagedW[] = {'L','o','w','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
422 static const WCHAR event_low_nonpgW[] = {'L','o','w','N','o','n','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
423 static const WCHAR event_high_memW[] = {'H','i','g','h','M','e','m','o','r','y','C','o','n','d','i','t','i','o','n'};
424 static const WCHAR event_high_pagedW[] = {'H','i','g','h','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
425 static const WCHAR event_high_nonpgW[] = {'H','i','g','h','N','o','n','P','a','g','e','d','P','o','o','l','C','o','n','d','i','t','i','o','n'};
426 static const WCHAR keyed_event_crit_sectW[] = {'C','r','i','t','S','e','c','O','u','t','O','f','M','e','m','o','r','y','E','v','e','n','t'};
427 static const struct unicode_str kernel_events[] =
429 { event_low_memW, sizeof(event_low_memW) },
430 { event_low_pagedW, sizeof(event_low_pagedW) },
431 { event_low_nonpgW, sizeof(event_low_nonpgW) },
432 { event_high_memW, sizeof(event_high_memW) },
433 { event_high_pagedW, sizeof(event_high_pagedW) },
434 { event_high_nonpgW, sizeof(event_high_nonpgW) }
436 static const struct unicode_str keyed_event_crit_sect_str = {keyed_event_crit_sectW, sizeof(keyed_event_crit_sectW)};
438 /* mappings */
439 static const WCHAR intlW[] = {'N','l','s','S','e','c','t','i','o','n','L','A','N','G','_','I','N','T','L'};
440 static const WCHAR user_dataW[] = {'_','_','w','i','n','e','_','u','s','e','r','_','s','h','a','r','e','d','_','d','a','t','a'};
441 static const struct unicode_str intl_str = {intlW, sizeof(intlW)};
442 static const struct unicode_str user_data_str = {user_dataW, sizeof(user_dataW)};
444 struct directory *dir_driver, *dir_device, *dir_global, *dir_kernel, *dir_nls;
445 struct object *named_pipe_device, *mailslot_device, *null_device;
446 unsigned int i;
448 root_directory = create_directory( NULL, NULL, OBJ_PERMANENT, HASH_SIZE, NULL );
449 dir_driver = create_directory( &root_directory->obj, &dir_driver_str, OBJ_PERMANENT, HASH_SIZE, NULL );
450 dir_device = create_directory( &root_directory->obj, &dir_device_str, OBJ_PERMANENT, HASH_SIZE, NULL );
451 dir_objtype = create_directory( &root_directory->obj, &dir_objtype_str, OBJ_PERMANENT, HASH_SIZE, NULL );
452 dir_kernel = create_directory( &root_directory->obj, &dir_kernel_str, OBJ_PERMANENT, HASH_SIZE, NULL );
453 dir_global = create_directory( &root_directory->obj, &dir_global_str, OBJ_PERMANENT, HASH_SIZE, NULL );
454 dir_nls = create_directory( &root_directory->obj, &dir_nls_str, OBJ_PERMANENT, HASH_SIZE, NULL );
456 /* devices */
457 named_pipe_device = create_named_pipe_device( &dir_device->obj, &named_pipe_str, OBJ_PERMANENT, NULL );
458 mailslot_device = create_mailslot_device( &dir_device->obj, &mailslot_str, OBJ_PERMANENT, NULL );
459 null_device = create_unix_device( &dir_device->obj, &null_str, OBJ_PERMANENT, NULL, "/dev/null" );
460 release_object( create_console_device( &dir_device->obj, &condrv_str, OBJ_PERMANENT, NULL ));
461 release_object( create_socket_device( &dir_device->obj, &afd_str, OBJ_PERMANENT, NULL ));
463 /* sessions */
464 create_session( 0 );
465 create_session( 1 );
467 /* object types */
469 for (i = 0; i < ARRAY_SIZE(types); i++)
470 release_object( create_object_type( &dir_objtype->obj, i, OBJ_PERMANENT, NULL ));
472 /* symlinks */
473 release_object( create_obj_symlink( &root_directory->obj, &link_dosdev_str, OBJ_PERMANENT, &dir_global->obj, NULL ));
474 release_object( create_obj_symlink( &dir_global->obj, &link_global_str, OBJ_PERMANENT, &dir_global->obj, NULL ));
475 release_object( create_obj_symlink( &dir_global->obj, &link_nul_str, OBJ_PERMANENT, null_device, NULL ));
476 release_object( create_obj_symlink( &dir_global->obj, &link_pipe_str, OBJ_PERMANENT, named_pipe_device, NULL ));
477 release_object( create_obj_symlink( &dir_global->obj, &link_mailslot_str, OBJ_PERMANENT, mailslot_device, NULL ));
478 release_object( create_symlink( &dir_global->obj, &link_conin_str, OBJ_PERMANENT, &link_currentin_str, NULL ));
479 release_object( create_symlink( &dir_global->obj, &link_conout_str, OBJ_PERMANENT, &link_currentout_str, NULL ));
480 release_object( create_symlink( &dir_global->obj, &link_con_str, OBJ_PERMANENT, &link_console_str, NULL ));
482 /* events */
483 for (i = 0; i < ARRAY_SIZE( kernel_events ); i++)
484 release_object( create_event( &dir_kernel->obj, &kernel_events[i], OBJ_PERMANENT, 1, 0, NULL ));
485 release_object( create_keyed_event( &dir_kernel->obj, &keyed_event_crit_sect_str, OBJ_PERMANENT, NULL ));
487 /* mappings */
488 release_object( create_fd_mapping( &dir_nls->obj, &intl_str, intl_fd, OBJ_PERMANENT, NULL ));
489 release_object( create_user_data_mapping( &dir_kernel->obj, &user_data_str, OBJ_PERMANENT, NULL ));
490 release_object( intl_fd );
492 release_object( named_pipe_device );
493 release_object( mailslot_device );
494 release_object( null_device );
495 release_object( root_directory );
496 release_object( dir_driver );
497 release_object( dir_device );
498 release_object( dir_objtype );
499 release_object( dir_kernel );
500 release_object( dir_nls );
501 release_object( dir_global );
504 /* create a directory object */
505 DECL_HANDLER(create_directory)
507 struct unicode_str name;
508 struct object *root;
509 struct directory *dir;
510 const struct security_descriptor *sd;
511 const struct object_attributes *objattr = get_req_object_attributes( &sd, &name, &root );
513 if (!objattr) return;
515 if ((dir = create_directory( root, &name, objattr->attributes, HASH_SIZE, sd )))
517 reply->handle = alloc_handle( current->process, dir, req->access, objattr->attributes );
518 release_object( dir );
521 if (root) release_object( root );
524 /* open a directory object */
525 DECL_HANDLER(open_directory)
527 struct unicode_str name = get_req_unicode_str();
529 reply->handle = open_object( current->process, req->rootdir, req->access,
530 &directory_ops, &name, req->attributes );
533 /* get a directory entry by index */
534 DECL_HANDLER(get_directory_entry)
536 struct directory *dir = (struct directory *)get_handle_obj( current->process, req->handle,
537 DIRECTORY_QUERY, &directory_ops );
538 if (dir)
540 struct object *obj = find_object_index( dir->entries, req->index );
541 if (obj)
543 data_size_t name_len;
544 const struct unicode_str *type_name = &obj->ops->type->name;
545 const WCHAR *name = get_object_name( obj, &name_len );
547 if (name_len + type_name->len <= get_reply_max_size())
549 void *ptr = set_reply_data_size( name_len + type_name->len );
550 if (ptr)
552 reply->name_len = name_len;
553 memcpy( ptr, name, name_len );
554 memcpy( (char *)ptr + name_len, type_name->str, type_name->len );
557 else set_error( STATUS_BUFFER_OVERFLOW );
559 release_object( obj );
561 release_object( dir );
565 /* query object type name information */
566 DECL_HANDLER(get_object_type)
568 struct object *obj;
569 struct type_descr *type;
570 struct object_type_info *info;
572 if (!(obj = get_handle_obj( current->process, req->handle, 0, NULL ))) return;
574 type = obj->ops->type;
575 if (sizeof(*info) + type->name.len <= get_reply_max_size())
577 if ((info = set_reply_data_size( sizeof(*info) + type->name.len )))
579 info->name_len = type->name.len;
580 info->index = type->index;
581 info->obj_count = type->obj_count;
582 info->handle_count = type->handle_count;
583 info->obj_max = type->obj_max;
584 info->handle_max = type->handle_max;
585 info->valid_access = type->valid_access;
586 info->mapping = type->mapping;
587 memcpy( info + 1, type->name.str, type->name.len );
590 else set_error( STATUS_BUFFER_OVERFLOW );
592 release_object( obj );
595 /* query type information for all types */
596 DECL_HANDLER(get_object_types)
598 struct object_type_info *info;
599 data_size_t size = ARRAY_SIZE(types) * sizeof(*info);
600 unsigned int i;
601 char *next;
603 for (i = 0; i < ARRAY_SIZE(types); i++) size += (types[i]->name.len + 3) & ~3;
605 if (size <= get_reply_max_size())
607 if ((info = set_reply_data_size( size )))
609 for (i = 0; i < ARRAY_SIZE(types); i++)
611 info->name_len = types[i]->name.len;
612 info->index = types[i]->index;
613 info->obj_count = types[i]->obj_count;
614 info->handle_count = types[i]->handle_count;
615 info->obj_max = types[i]->obj_max;
616 info->handle_max = types[i]->handle_max;
617 info->valid_access = types[i]->valid_access;
618 info->mapping = types[i]->mapping;
619 memcpy( info + 1, types[i]->name.str, types[i]->name.len );
620 next = (char *)(info + 1) + types[i]->name.len;
621 if (types[i]->name.len & 3)
623 memset( next, 0, 4 - (types[i]->name.len & 3) );
624 next += 4 - (types[i]->name.len & 3);
626 info = (struct object_type_info *)next;
628 reply->count = i;
631 else set_error( STATUS_BUFFER_OVERFLOW );