+Workaround Linux kernel last device block inaccessibility.
[captive.git] / src / libcaptive / client / vfs.c
1 /* $Id$
2  * captive vfs 'vfs' interface to reactos
3  * Copyright (C) 2002-2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
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
8  * 
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.
13  * 
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
17  */
18
19
20 #include "config.h"
21
22 #include "captive/client-vfs.h" /* self */
23 #include "vfs.h"        /* self-priv */
24 #include <glib/gmessages.h>
25 #include "vfs-parent.h"
26 #include "vfs-slave.h"
27 #include "init.h"
28 #include "lib.h"        /* for captive_giochannel_setup() */
29 #include <unistd.h>
30 #include <string.h>
31
32
33 static gpointer captive_vfs_object_parent_class=NULL;
34
35
36 static GnomeVFSResult captive_vfs_close(CaptiveVfsObject *captive_vfs_object);
37
38 static void captive_vfs_object_finalize(CaptiveVfsObject *captive_vfs_object)
39 {
40         g_return_if_fail(captive_vfs_object!=NULL);
41
42         captive_vfs_close(captive_vfs_object);  /* errors ignored */
43
44         G_OBJECT_CLASS(captive_vfs_object_parent_class)->finalize((GObject *)captive_vfs_object);
45 }
46
47
48 static void captive_vfs_object_class_init(CaptiveVfsObjectClass *class)
49 {
50 GObjectClass *gobject_class=G_OBJECT_CLASS(class);
51
52         captive_vfs_object_parent_class=g_type_class_ref(g_type_parent(G_TYPE_FROM_CLASS(class)));
53         gobject_class->finalize=(void (*)(GObject *object))captive_vfs_object_finalize;
54 }
55
56
57 static void captive_vfs_object_init(CaptiveVfsObject *captive_vfs_object)
58 {
59         captive_options_init(&captive_vfs_object->options);
60 }
61
62
63 GType captive_vfs_object_get_type(void)
64 {
65 static GType captive_vfs_object_type=0;
66
67         if (!captive_vfs_object_type) {
68 static const GTypeInfo captive_vfs_object_info={
69                                 sizeof(CaptiveVfsObjectClass),
70                                 NULL,   /* base_init */
71                                 NULL,   /* base_finalize */
72                                 (GClassInitFunc)captive_vfs_object_class_init,
73                                 NULL,   /* class_finalize */
74                                 NULL,   /* class_data */
75                                 sizeof(CaptiveVfsObject),
76                                 5,      /* n_preallocs */
77                                 (GInstanceInitFunc)captive_vfs_object_init,
78                                 };
79
80                 captive_vfs_object_type=g_type_register_static(G_TYPE_OBJECT,
81                                 "CaptiveVfsObject",&captive_vfs_object_info,G_TYPE_FLAG_ABSTRACT);
82                 }
83
84         return captive_vfs_object_type;
85 }
86
87
88 GnomeVFSResult captive_vfs_new
89                 (CaptiveVfsObject **captive_vfs_object_return,const struct captive_options *options)
90 {
91 CaptiveVfsObject *captive_vfs_object;
92
93         g_return_val_if_fail(captive_vfs_object_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
94         g_return_val_if_fail(options!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
95
96 #ifndef MAINTAINER_MODE
97         /* We are not sandboxing || we are the master */
98         if (!options->sandbox || (options->sandbox_server_argv || options->sandbox_server_ior)) {
99 int fd;
100
101                 /* Shameless advertisement: */
102                 for (fd=2 /* STDERR */;fd>=1 /* STDOUT */;fd--) {
103                         if (isatty(fd)) {
104 const gchar *msg="Captive NTFS v" VERSION ".  Check a new version at: http://www.jankratochvil.net/\n";
105
106                                 write(fd,msg,strlen(msg));
107                                 break;
108                                 }
109                         }
110                 }
111 #endif /* !MAINTAINER_MODE */
112
113         /* Here is the first initializaton point of parent in sandboxed mode. */
114         captive_log_init(options);
115
116         *captive_vfs_object_return=NULL;
117
118         /* We are sandboxing && we are the master */
119         if (options->sandbox && (options->sandbox_server_argv || options->sandbox_server_ior))
120                 captive_vfs_object=g_object_new(
121                                 CAPTIVE_VFS_PARENT_TYPE_OBJECT, /* object_type */
122                                 NULL);  /* first_property_name; FIXME: support properties */
123         else
124                 captive_vfs_object=g_object_new(
125                                 CAPTIVE_VFS_SLAVE_TYPE_OBJECT,  /* object_type */
126                                 NULL);  /* first_property_name; FIXME: support properties */
127
128         captive_options_copy(&captive_vfs_object->options,options);
129
130         if (captive_vfs_object->options.image_iochannel)
131                 captive_giochannel_setup(captive_vfs_object->options.image_iochannel);
132
133         *captive_vfs_object_return=captive_vfs_object;
134
135         return (*CAPTIVE_VFS_OBJECT_GET_CLASS(captive_vfs_object)->init)(captive_vfs_object);
136 }
137
138
139 static GnomeVFSResult captive_vfs_close(CaptiveVfsObject *captive_vfs_object)
140 {
141         g_return_val_if_fail(CAPTIVE_VFS_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
142
143         captive_options_free(&captive_vfs_object->options);
144
145         return GNOME_VFS_OK;
146 }
147
148
149 GnomeVFSResult captive_vfs_commit(CaptiveVfsObject *captive_vfs_object)
150 {
151         g_return_val_if_fail(CAPTIVE_VFS_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
152
153         return (*CAPTIVE_VFS_OBJECT_GET_CLASS(captive_vfs_object)->commit)(captive_vfs_object);
154 }
155
156
157 GnomeVFSResult captive_vfs_volume_info_get(CaptiveVfsObject *captive_vfs_object,CaptiveVfsVolumeInfo *volume_info)
158 {
159         g_return_val_if_fail(CAPTIVE_VFS_IS_OBJECT(captive_vfs_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
160         g_return_val_if_fail(volume_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
161
162         return (*CAPTIVE_VFS_OBJECT_GET_CLASS(captive_vfs_object)->volume_info_get)(captive_vfs_object,volume_info);
163 }