2 * captive vfs utility functions for interface to reactos
3 * Copyright (C) 2002-2003 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "lib.h" /* self */
23 #include <libgnomevfs/gnome-vfs-result.h>
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
26 #include "reactos/ddk/rtl.h" /* for InitializeObjectAttributes() */
27 #include "captive/unicode.h"
28 #include <libgnomevfs/gnome-vfs-utils.h> /* for gnome_vfs_unescape_string() */
29 #include <glib/gprintf.h>
32 /* function will leave g_malloc()ed 'ObjectAttributes->ObjectName'!
34 GnomeVFSResult captive_ObjectAttributes_init(const gchar *pathname,OBJECT_ATTRIBUTES *ObjectAttributes)
36 gchar *w32_path,*s,*d;
38 g_return_val_if_fail(pathname!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
39 g_return_val_if_fail(ObjectAttributes!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
41 /* Do not open "\Cdfs"(anything) as it is just the filesystem implementation.
42 * ntoskrnl/io/fs.c/IoMountVolume() will map
43 * FILE_DEVICE_CD_ROM -> FILE_DEVICE_CD_ROM_FILE_SYSTEM
44 * for us automatically when opening the device itself.
45 * If you put some trailing content (such as "\\.") there
46 * IoCreateFile()->ObCreateObject()->ObFindObject()
47 * will not leave 'ObCreateObject::RemainingPath' as NULL
48 * and later IopCreateFile() would not consider it FO_DIRECT_DEVICE_OPEN (e.g. w/o any direct mount!).
49 * On the other side it will somehow get managed automatically and it works even
50 * without the trailing "\\." for root directory open - don't ask me why. :-)
52 w32_path=(gchar *)/* de-const it as we can modify it but we must not free() it */
53 captive_printf_alloca("\\Device\\CdRom0\\%s",pathname);
54 /* translate '/' -> '\' */
55 for (s=w32_path;(s=strchr(s,'/'));s++)
57 /* collapse multiple sequences of '\' as it is a no-no for W32 */
58 for (s=d=w32_path;*s;s++)
59 if (d==w32_path || !(*s=='\\' && d[-1]=='\\'))
62 InitializeObjectAttributes(
63 ObjectAttributes, /* InitializedAttributes */
64 captive_utf8_to_UnicodeString_malloc(w32_path), /* ObjectName */
65 0, /* Attributes; I hope no OBJ_KERNEL_HANDLE as we are 'system process' */
66 NULL, /* RootDirectory */
67 NULL); /* SecurityDescriptor; ignored */