2 * captive vfs 'vfs' 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 "captive/client-vfs.h" /* self */
23 #include "vfs.h" /* self-priv */
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
27 #include "captive/parent-Vfs.h"
28 #include "../sandbox/server-Vfs.h" /* for captive_corba_child_options */
29 #include "giochannel-blind.h" /* for captive_giochannel_setup() */
32 static gpointer captive_vfs_object_parent_class=NULL;
35 static GnomeVFSResult captive_vfs_close(CaptiveVfsObject *captive_vfs_object);
37 static void captive_vfs_object_finalize(CaptiveVfsObject *captive_vfs_object)
39 g_return_if_fail(captive_vfs_object!=NULL);
41 captive_vfs_close(captive_vfs_object); /* errors ignored */
43 G_OBJECT_CLASS(captive_vfs_object_parent_class)->finalize((GObject *)captive_vfs_object);
47 static void captive_vfs_object_class_init(CaptiveVfsObjectClass *class)
49 GObjectClass *gobject_class=G_OBJECT_CLASS(class);
51 captive_vfs_object_parent_class=g_type_class_ref(G_TYPE_OBJECT);
52 gobject_class->finalize=(void (*)(GObject *object))captive_vfs_object_finalize;
56 static void captive_vfs_object_init(CaptiveVfsObject *captive_vfs_object)
58 CAPTIVE_MEMZERO(&captive_vfs_object->options);
60 captive_vfs_object->corba_parent_giochanel_blind=NULL;
64 GType captive_vfs_object_get_type(void)
66 static GType captive_vfs_object_type=0;
68 if (!captive_vfs_object_type) {
69 static const GTypeInfo captive_vfs_object_info={
70 sizeof(CaptiveVfsObjectClass),
72 NULL, /* base_finalize */
73 (GClassInitFunc)captive_vfs_object_class_init,
74 NULL, /* class_finalize */
75 NULL, /* class_data */
76 sizeof(CaptiveVfsObject),
78 (GInstanceInitFunc)captive_vfs_object_init,
81 captive_vfs_object_type=g_type_register_static(G_TYPE_OBJECT,
82 "CaptiveVfsObject",&captive_vfs_object_info,0);
85 return captive_vfs_object_type;
89 static void log_discard_func(const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,gpointer user_data)
94 GnomeVFSResult captive_vfs_new
95 (CaptiveVfsObject **captive_vfs_object_return,const struct captive_options *options)
97 CaptiveVfsObject *captive_vfs_object;
100 g_return_val_if_fail(captive_vfs_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
101 g_return_val_if_fail(options!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
103 /* Here is the first initializaton point of parent in sandboxed mode. */
104 if (!options->debug_messages) {
106 G_LOG_DOMAIN, /* log_domain; "Captive" */
108 | G_LOG_FLAG_RECURSION
110 /* The same mask is in:
111 * libcaptive/sandbox/server-GLogFunc.c
112 * libcaptive/client/init.c
113 * libcaptive/client/vfs.c
115 | G_LOG_LEVEL_MESSAGE
118 log_discard_func, /* log_func */
119 NULL); /* user_data */
122 *captive_vfs_object_return=NULL;
124 captive_vfs_object=g_object_new(
125 CAPTIVE_VFS_TYPE_OBJECT, /* object_type */
126 NULL); /* first_property_name; FIXME: support properties */
128 captive_options_copy(&captive_vfs_object->options,options);
130 if (captive_vfs_object->options.image_iochannel)
131 captive_giochannel_setup(captive_vfs_object->options.image_iochannel);
133 *captive_vfs_object_return=captive_vfs_object;
135 /* We are sandboxing && we are the master */
136 if (options->sandbox && (options->sandbox_server_argv || options->sandbox_server_ior))
137 return captive_sandbox_parent_vfs_new(captive_vfs_object);
139 g_assert(captive_options==NULL);
140 captive_options=&captive_vfs_object->options;
142 errbool=captive_init();
143 g_assert(errbool==TRUE);
149 static GnomeVFSResult captive_vfs_close(CaptiveVfsObject *captive_vfs_object)
153 g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
155 if (captive_vfs_object->is_sandbox_parent)
156 return captive_sandbox_parent_vfs_close(captive_vfs_object);
158 g_assert(captive_options==&captive_vfs_object->options);
159 errbool=captive_shutdown();
160 g_assert(errbool==TRUE);
162 captive_options=NULL;
163 captive_options_free(&captive_vfs_object->options);
169 GnomeVFSResult captive_vfs_commit(CaptiveVfsObject *captive_vfs_object)
171 g_return_val_if_fail(captive_vfs_object!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
173 if (captive_vfs_object->is_sandbox_parent)
174 return captive_sandbox_parent_vfs_commit(captive_vfs_object);
176 /* We do not buffer any data if not in sandboxed mode. */