2 * captive vfs 'vfs' interface to reactos of sandbox slave
3 * Copyright (C) 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-slave.h" /* self */
23 #include <glib/gmessages.h>
24 #include "captive/client-vfs.h" /* for CaptiveVfsObject */
25 #include "vfs.h" /* for CaptiveVfsObject priv */
26 #include "captive/macros.h"
27 #include "directory.h"
28 #include "reactos/ddk/iotypes.h"
29 #include "captive/client-directory.h"
30 #include "reactos/ntos/zw.h" /* for NtQueryVolumeInformationFile() */
33 #include "directory-slave.h"
34 #include "file-slave.h"
37 struct _CaptiveVfsSlaveObject {
38 CaptiveVfsObject parent_instance;
40 struct _CaptiveVfsSlaveObjectClass {
41 CaptiveVfsObjectClass parent_class;
45 static gpointer captive_vfs_slave_object_parent_class=NULL;
48 static GnomeVFSResult captive_vfs_slave_init(CaptiveVfsObject *captive_vfs_object);
49 static GnomeVFSResult captive_vfs_slave_close(CaptiveVfsObject *captive_vfs_object);
50 static GnomeVFSResult captive_vfs_slave_commit(CaptiveVfsObject *captive_vfs_object);
51 static GnomeVFSResult captive_vfs_slave_volume_info_get
52 (CaptiveVfsObject *captive_vfs_object,CaptiveVfsVolumeInfo *volume_info);
55 static void captive_vfs_slave_object_finalize(CaptiveVfsSlaveObject *captive_vfs_slave_object)
57 g_return_if_fail(captive_vfs_slave_object!=NULL);
59 captive_vfs_slave_close(CAPTIVE_VFS_OBJECT(captive_vfs_slave_object)); /* errors ignored */
61 G_OBJECT_CLASS(captive_vfs_slave_object_parent_class)->finalize((GObject *)captive_vfs_slave_object);
65 static void captive_vfs_slave_object_class_init(CaptiveVfsSlaveObjectClass *class)
67 GObjectClass *gobject_class=G_OBJECT_CLASS(class);
68 CaptiveVfsObjectClass *captive_vfs_object_class=CAPTIVE_VFS_OBJECT_CLASS(class);
70 captive_vfs_slave_object_parent_class=g_type_class_ref(g_type_parent(G_TYPE_FROM_CLASS(class)));
71 gobject_class->finalize=(void (*)(GObject *object))captive_vfs_slave_object_finalize;
73 captive_vfs_object_class->init=captive_vfs_slave_init;
74 captive_vfs_object_class->commit=captive_vfs_slave_commit;
75 captive_vfs_object_class->volume_info_get=captive_vfs_slave_volume_info_get;
77 captive_vfs_object_class->directory_new_open=captive_directory_slave_new_open;
78 captive_vfs_object_class->directory_new_make=captive_directory_slave_new_make;
80 captive_vfs_object_class->file_new_open=captive_file_slave_new_open;
81 captive_vfs_object_class->file_new_create=captive_file_slave_new_create;
85 static void captive_vfs_slave_object_init(CaptiveVfsSlaveObject *captive_vfs_slave_object)
90 GType captive_vfs_slave_object_get_type(void)
92 static GType captive_vfs_slave_object_type=0;
94 if (!captive_vfs_slave_object_type) {
95 static const GTypeInfo captive_vfs_slave_object_info={
96 sizeof(CaptiveVfsSlaveObjectClass),
98 NULL, /* base_finalize */
99 (GClassInitFunc)captive_vfs_slave_object_class_init,
100 NULL, /* class_finalize */
101 NULL, /* class_data */
102 sizeof(CaptiveVfsSlaveObject),
104 (GInstanceInitFunc)captive_vfs_slave_object_init,
107 captive_vfs_slave_object_type=g_type_register_static(CAPTIVE_VFS_TYPE_OBJECT,
108 "CaptiveVfsSlaveObject",&captive_vfs_slave_object_info,0);
111 return captive_vfs_slave_object_type;
115 static GnomeVFSResult captive_vfs_slave_init(CaptiveVfsObject *captive_vfs_object)
117 CaptiveVfsSlaveObject *captive_vfs_slave_object;
120 g_return_val_if_fail(CAPTIVE_VFS_SLAVE_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
122 captive_vfs_slave_object=CAPTIVE_VFS_SLAVE_OBJECT(captive_vfs_object);
124 g_assert(captive_options==NULL);
125 captive_options=&captive_vfs_object->options;
127 errbool=captive_init();
128 g_assert(errbool==TRUE);
134 static GnomeVFSResult captive_vfs_slave_close(CaptiveVfsObject *captive_vfs_object)
136 CaptiveVfsSlaveObject *captive_vfs_slave_object;
139 g_return_val_if_fail(CAPTIVE_VFS_SLAVE_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
141 captive_vfs_slave_object=CAPTIVE_VFS_SLAVE_OBJECT(captive_vfs_object);
143 g_assert(captive_options==&captive_vfs_object->options);
144 errbool=captive_shutdown();
145 g_assert(errbool==TRUE);
147 captive_options=NULL;
153 static GnomeVFSResult captive_vfs_slave_commit(CaptiveVfsObject *captive_vfs_object)
155 CaptiveVfsSlaveObject *captive_vfs_slave_object;
157 g_return_val_if_fail(CAPTIVE_VFS_SLAVE_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
159 captive_vfs_slave_object=CAPTIVE_VFS_SLAVE_OBJECT(captive_vfs_object);
161 /* We do not buffer any data if not in sandboxed mode. */
166 static GnomeVFSResult captive_vfs_slave_volume_info_get
167 (CaptiveVfsObject *captive_vfs_object,CaptiveVfsVolumeInfo *volume_info)
169 CaptiveVfsSlaveObject *captive_vfs_slave_object;
170 FILE_FS_FULL_SIZE_INFORMATION FileFsFullSizeInformation_local;
172 IO_STATUS_BLOCK volume_IoStatusBlock;
173 GnomeVFSResult errvfsresult;
174 CaptiveDirectoryObject *captive_directory_object;
176 g_return_val_if_fail(CAPTIVE_VFS_SLAVE_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
177 g_return_val_if_fail(volume_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
179 captive_vfs_slave_object=CAPTIVE_VFS_SLAVE_OBJECT(captive_vfs_object);
181 if (GNOME_VFS_OK!=(errvfsresult=captive_directory_new_open(&captive_directory_object,captive_vfs_object,"/")))
184 err=NtQueryVolumeInformationFile(
185 CAPTIVE_DIRECTORY_SLAVE_OBJECT(captive_directory_object)->dir_Handle, /* FileHandle */
186 &volume_IoStatusBlock, /* IoStatusBlock */
187 &FileFsFullSizeInformation_local, /* FsInformation */
188 sizeof(FileFsFullSizeInformation_local), /* Length */
189 FileFsFullSizeInformation); /* FsInformationClass */
190 if (NT_SUCCESS(err)!=NT_SUCCESS(volume_IoStatusBlock.Status)) {
191 g_assert_not_reached();
192 goto err_unref_captive_directory_object;
194 if (GNOME_VFS_OK!=(errvfsresult=captive_NTSTATUS_to_GnomeVFSResult(err)))
195 goto err_unref_captive_directory_object;
197 g_object_unref(captive_directory_object);
199 volume_info->block_size=FileFsFullSizeInformation_local.BytesPerSector
200 *FileFsFullSizeInformation_local.SectorsPerAllocationUnit;
201 volume_info->bytes =FileFsFullSizeInformation_local.TotalAllocationUnits.QuadPart *volume_info->block_size;
202 volume_info->bytes_free =FileFsFullSizeInformation_local.ActualAvailableAllocationUnits.QuadPart*volume_info->block_size;
203 volume_info->bytes_available=FileFsFullSizeInformation_local.CallerAvailableAllocationUnits.QuadPart*volume_info->block_size;
207 err_unref_captive_directory_object:
208 g_object_unref(captive_directory_object);