2 * captive vfs 'vfs' interface to reactos of sandbox parent
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 "vfs-parent.h" /* self */
23 #include <glib/gmessages.h>
24 #include "captive/macros.h"
25 #include "../sandbox/parent-Vfs.h"
26 #include "directory-parent.h"
27 #include "file-parent.h"
28 #include "marshallers.h"
31 static gpointer captive_vfs_parent_object_parent_class=NULL;
34 static GnomeVFSResult captive_vfs_parent_init(CaptiveVfsObject *captive_vfs_object);
35 static void captive_vfs_parent_object_dispose(CaptiveVfsParentObject *captive_vfs_parent_object);
36 static void captive_vfs_parent_object_handler_detach(CaptiveVfsParentObject *captive_vfs_parent_object);
37 static void captive_vfs_parent_object_handler_cease(CaptiveVfsParentObject *captive_vfs_parent_object);
38 static void captive_vfs_parent_object_handler_abort(CaptiveVfsParentObject *captive_vfs_parent_object);
39 static GnomeVFSResult captive_vfs_parent_close(CaptiveVfsObject *captive_vfs_object);
40 static GnomeVFSResult captive_vfs_parent_commit(CaptiveVfsObject *captive_vfs_object);
41 static GnomeVFSResult captive_vfs_parent_volume_info_get
42 (CaptiveVfsObject *captive_vfs_object,CaptiveVfsVolumeInfo *volume_info);
43 static GnomeVFSResult captive_vfs_parent_object_connect_silent(CaptiveVfsParentObject *captive_vfs_parent_object);
46 /* We need to close the filesystem during custom 'dispose'
47 * as the default GObject g_object_real_dispose() destroys all the signals
48 * first and we would not notify our Connectors during captive_vfs_parent_object_finalize().
50 static void captive_vfs_parent_object_dispose(CaptiveVfsParentObject *captive_vfs_parent_object)
52 g_return_if_fail(captive_vfs_parent_object!=NULL);
54 captive_vfs_parent_close(CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)); /* errors ignored */
56 G_OBJECT_CLASS(captive_vfs_parent_object_parent_class)->dispose((GObject *)captive_vfs_parent_object);
60 static void captive_vfs_parent_object_finalize(CaptiveVfsParentObject *captive_vfs_parent_object)
62 g_return_if_fail(captive_vfs_parent_object!=NULL);
64 G_OBJECT_CLASS(captive_vfs_parent_object_parent_class)->finalize((GObject *)captive_vfs_parent_object);
68 static void captive_vfs_parent_object_class_init(CaptiveVfsParentObjectClass *class)
70 GObjectClass *gobject_class=G_OBJECT_CLASS(class);
71 CaptiveVfsObjectClass *captive_vfs_object_class=CAPTIVE_VFS_OBJECT_CLASS(class);
73 captive_vfs_parent_object_parent_class=g_type_class_ref(g_type_parent(G_TYPE_FROM_CLASS(class)));
74 gobject_class->dispose=(void (*)(GObject *object))captive_vfs_parent_object_dispose;
75 gobject_class->finalize=(void (*)(GObject *object))captive_vfs_parent_object_finalize;
77 captive_vfs_object_class->init=captive_vfs_parent_init;
78 captive_vfs_object_class->commit=captive_vfs_parent_commit;
79 captive_vfs_object_class->volume_info_get=captive_vfs_parent_volume_info_get;
81 captive_vfs_object_class->directory_new_open=captive_directory_parent_new_open;
82 captive_vfs_object_class->directory_new_make=captive_directory_parent_new_make;
84 captive_vfs_object_class->file_new_open=captive_file_parent_new_open;
85 captive_vfs_object_class->file_new_create=captive_file_parent_new_create;
87 class->detach=captive_vfs_parent_object_handler_detach;
89 "detach", /* signal_name */
90 G_TYPE_FROM_CLASS(class), /* itype */
91 G_SIGNAL_RUN_LAST, /* signal_flags */
92 G_STRUCT_OFFSET(CaptiveVfsParentObjectClass,detach), /* class_offset */
93 NULL,NULL, /* accumulator,accu_data */
94 captive_client_VOID__VOID, /* c_marshaller */
95 G_TYPE_NONE,0); /* return_type,n_params */
96 class->cease=captive_vfs_parent_object_handler_cease;
98 "cease", /* signal_name */
99 G_TYPE_FROM_CLASS(class), /* itype */
100 G_SIGNAL_RUN_LAST, /* signal_flags */
101 G_STRUCT_OFFSET(CaptiveVfsParentObjectClass,cease), /* class_offset */
102 NULL,NULL, /* accumulator,accu_data */
103 captive_client_VOID__VOID, /* c_marshaller */
104 G_TYPE_NONE,0); /* return_type,n_params */
105 class->abort=captive_vfs_parent_object_handler_abort;
107 "abort", /* signal_name */
108 G_TYPE_FROM_CLASS(class), /* itype */
109 G_SIGNAL_RUN_LAST, /* signal_flags */
110 G_STRUCT_OFFSET(CaptiveVfsParentObjectClass,abort), /* class_offset */
111 NULL,NULL, /* accumulator,accu_data */
112 captive_client_VOID__VOID, /* c_marshaller */
113 G_TYPE_NONE,0); /* return_type,n_params */
117 static void captive_vfs_parent_object_init(CaptiveVfsParentObject *captive_vfs_parent_object)
119 captive_vfs_parent_object->corba_parent_giochanel_blind=NULL;
123 static void captive_vfs_parent_object_handler_detach(CaptiveVfsParentObject *captive_vfs_parent_object)
125 g_return_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object));
128 static void captive_vfs_parent_object_handler_cease(CaptiveVfsParentObject *captive_vfs_parent_object)
130 g_return_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object));
133 static void captive_vfs_parent_object_handler_abort(CaptiveVfsParentObject *captive_vfs_parent_object)
135 g_return_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object));
139 GType captive_vfs_parent_object_get_type(void)
141 static GType captive_vfs_parent_object_type=0;
143 if (!captive_vfs_parent_object_type) {
144 static const GTypeInfo captive_vfs_parent_object_info={
145 sizeof(CaptiveVfsParentObjectClass),
146 NULL, /* base_init */
147 NULL, /* base_finalize */
148 (GClassInitFunc)captive_vfs_parent_object_class_init,
149 NULL, /* class_finalize */
150 NULL, /* class_data */
151 sizeof(CaptiveVfsParentObject),
153 (GInstanceInitFunc)captive_vfs_parent_object_init,
156 captive_vfs_parent_object_type=g_type_register_static(CAPTIVE_VFS_TYPE_OBJECT,
157 "CaptiveVfsParentObject",&captive_vfs_parent_object_info,0);
160 return captive_vfs_parent_object_type;
164 static GnomeVFSResult captive_vfs_parent_init(CaptiveVfsObject *captive_vfs_object)
166 CaptiveVfsParentObject *captive_vfs_parent_object;
168 g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
170 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(captive_vfs_object);
172 return captive_sandbox_parent_vfs_new(captive_vfs_parent_object);
176 static GnomeVFSResult captive_vfs_parent_close(CaptiveVfsObject *captive_vfs_object)
178 CaptiveVfsParentObject *captive_vfs_parent_object;
181 g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
183 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(captive_vfs_object);
185 if (captive_vfs_parent_object->corba_Vfs_object!=CORBA_OBJECT_NIL) {
186 r=captive_vfs_parent_object_disconnect(captive_vfs_parent_object);
187 g_assert(captive_vfs_parent_object->corba_Vfs_object==CORBA_OBJECT_NIL);
192 if (captive_vfs_parent_object->corba_parent_giochanel_blind_source) {
193 g_io_channel_unref(captive_vfs_parent_object->corba_parent_giochanel_blind_source);
194 captive_vfs_parent_object->corba_parent_giochanel_blind_source=NULL;
201 static GnomeVFSResult captive_vfs_parent_commit(CaptiveVfsObject *captive_vfs_object)
203 CaptiveVfsParentObject *captive_vfs_parent_object;
207 g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
209 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(captive_vfs_object);
212 if (captive_vfs_parent_object->corba_Vfs_object==CORBA_OBJECT_NIL
213 && GNOME_VFS_OK!=(r=captive_vfs_parent_object_connect_silent(captive_vfs_parent_object)))
215 if (GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE
216 !=(r=captive_sandbox_parent_vfs_commit(captive_vfs_parent_object)))
218 } while (!retried++);
223 static GnomeVFSResult captive_vfs_parent_volume_info_get
224 (CaptiveVfsObject *captive_vfs_object,CaptiveVfsVolumeInfo *volume_info)
226 CaptiveVfsParentObject *captive_vfs_parent_object;
230 g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
231 g_return_val_if_fail(volume_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
233 captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(captive_vfs_object);
236 if (captive_vfs_parent_object->corba_Vfs_object==CORBA_OBJECT_NIL
237 && GNOME_VFS_OK!=(r=captive_vfs_parent_object_connect(captive_vfs_parent_object)))
239 if (GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE
240 !=(r=captive_sandbox_parent_vfs_volume_info_get(captive_vfs_parent_object,volume_info)))
242 } while (!retried++);
247 GnomeVFSResult captive_vfs_parent_object_connect(CaptiveVfsParentObject *captive_vfs_parent_object)
249 g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
251 g_return_val_if_fail(captive_vfs_parent_object->corba_Vfs_object==CORBA_OBJECT_NIL,GNOME_VFS_ERROR_BAD_PARAMETERS);
253 return captive_sandbox_parent_vfs_new(captive_vfs_parent_object);
257 static GnomeVFSResult captive_vfs_parent_object_connect_silent(CaptiveVfsParentObject *captive_vfs_parent_object)
259 g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
261 g_return_val_if_fail(captive_vfs_parent_object->corba_Vfs_object==CORBA_OBJECT_NIL,GNOME_VFS_ERROR_BAD_PARAMETERS);
263 return captive_sandbox_parent_vfs_new_silent(captive_vfs_parent_object);
267 GnomeVFSResult captive_vfs_parent_object_disconnect(CaptiveVfsParentObject *captive_vfs_parent_object)
271 g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
273 g_return_val_if_fail(captive_vfs_parent_object->corba_Vfs_object!=CORBA_OBJECT_NIL,GNOME_VFS_ERROR_BAD_PARAMETERS);
275 /* Detach all connectors: */
276 g_signal_emit_by_name(captive_vfs_parent_object,"detach");
278 /* Some connector detaching broke the connection? */
279 if (captive_vfs_parent_object->corba_Vfs_object==CORBA_OBJECT_NIL) {
280 /* "abort" should have been emitted by captive_vfs_parent_object_aborted() */
281 return GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE;
284 if (GNOME_VFS_OK!=(r=captive_sandbox_parent_vfs_close(captive_vfs_parent_object))) {
285 /* Some non-ORBit shutdown error may have occured: */
286 g_signal_emit_by_name(captive_vfs_parent_object,"abort");
291 g_signal_emit_by_name(captive_vfs_parent_object,"cease");
297 GnomeVFSResult captive_vfs_parent_object_aborted(CaptiveVfsParentObject *captive_vfs_parent_object)
299 static gint inside=0;
302 g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
304 g_return_val_if_fail(captive_vfs_parent_object->corba_Vfs_object!=CORBA_OBJECT_NIL,GNOME_VFS_ERROR_BAD_PARAMETERS);
306 /* Prevent looping by COMM_FAILURE of 'unmount' operation
307 * by captive_sandbox_parent_vfs_close().
314 g_signal_emit_by_name(captive_vfs_parent_object,"abort");
316 r=captive_sandbox_parent_vfs_close(captive_vfs_parent_object);