+file truncate
[captive.git] / src / client / libcaptive-gnomevfs / gnome-vfs-method.c
1 /* $Id$
2  * gnome-vfs init/shutdown implementation of interface to libcaptive
3  * Copyright (C) 2002 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 "giognomevfs.h"
23 #include <libgnomevfs/gnome-vfs-method.h>
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
26 #include "gnome-vfs-module.h"
27 #include "captive/client-directory.h"
28 #include "captive/client-file.h"
29 #include "captive/client.h"
30
31
32 static GnomeVFSMethod GnomeVFSMethod_static;
33 G_LOCK_DEFINE_STATIC(GnomeVFSMethod_static);
34
35
36 /* FIXME: multi-parent */
37 G_LOCK_DEFINE_STATIC(captive_gnomevfs_uri_parent);      /* covers also 'captive_gnomevfs_uri_parent_giognomevfs' */
38 static gchar *captive_gnomevfs_uri_parent;
39 static gchar *captive_gnomevfs_uri_parent_fs_path;
40 static struct captive_gnomevfs_giognomevfs *captive_gnomevfs_uri_parent_giognomevfs;
41
42
43 static GnomeVFSResult captive_gnomevfs_uri_parent_init(GnomeVFSURI *uri)
44 {
45 gchar *uri_parent_string;
46 GnomeVFSResult errvfsresult;
47
48         g_return_val_if_fail(uri!=NULL,GNOME_VFS_ERROR_INVALID_URI);
49
50         if (!uri->parent)
51                 return GNOME_VFS_ERROR_INVALID_URI;
52         if (!uri->text) /* not needed here but we don't permit non-specific fs-image reference */
53                 return GNOME_VFS_ERROR_INVALID_URI;
54         uri_parent_string=gnome_vfs_uri_to_string(uri->parent,GNOME_VFS_URI_HIDE_NONE);
55         g_assert(uri_parent_string!=NULL);
56         /* FIXME: multi-parent */
57         G_LOCK(captive_gnomevfs_uri_parent);
58         if (captive_gnomevfs_uri_parent) {
59                 g_return_val_if_fail(!strcmp(uri_parent_string,captive_gnomevfs_uri_parent),GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES);
60                 g_free(uri_parent_string);
61                 }
62         else {
63                 errvfsresult=captive_gnomevfs_giognomevfs_new(&captive_gnomevfs_uri_parent_giognomevfs,
64                                 captive_gnomevfs_uri_parent_fs_path,uri->parent);
65                 g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
66                 captive_gnomevfs_uri_parent=uri_parent_string;
67                 }
68         G_UNLOCK(captive_gnomevfs_uri_parent);
69
70         return GNOME_VFS_OK;
71 }
72
73
74 static GnomeVFSResult captive_gnomevfs_open_directory(GnomeVFSMethod *method,
75                 GnomeVFSMethodHandle **method_handle,GnomeVFSURI *uri,GnomeVFSFileInfoOptions options,GnomeVFSContext *context)
76 {
77 GnomeVFSResult errvfsresult;
78 CaptiveDirectoryObject *captive_directory_object;
79
80         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
81         g_return_val_if_fail(method_handle!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
82
83         errvfsresult=captive_gnomevfs_uri_parent_init(uri);
84         g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
85
86         G_LOCK(libcaptive);
87         errvfsresult=captive_directory_new_open(
88                         &captive_directory_object,      /* captive_directory_object_return */
89                         uri->text);     /* pathname */
90         G_UNLOCK(libcaptive);
91
92         *method_handle=(GnomeVFSMethodHandle *)captive_directory_object;
93         return errvfsresult;
94 }
95
96
97 static GnomeVFSResult captive_gnomevfs_close_directory(GnomeVFSMethod *method,
98                 GnomeVFSMethodHandle *method_handle,GnomeVFSContext *context)
99 {
100 CaptiveDirectoryObject *captive_directory_object;
101
102         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
103         captive_directory_object=(CaptiveDirectoryObject *)method_handle;
104         g_return_val_if_fail(CAPTIVE_DIRECTORY_IS_OBJECT(captive_directory_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
105
106         G_LOCK(libcaptive);
107         g_object_unref(captive_directory_object);
108         G_UNLOCK(libcaptive);
109
110         return GNOME_VFS_OK;
111 }
112
113
114 static GnomeVFSResult captive_gnomevfs_read_directory(GnomeVFSMethod *method,
115                 GnomeVFSMethodHandle *method_handle,GnomeVFSFileInfo *file_info,GnomeVFSContext *context)
116 {
117 GnomeVFSResult errvfsresult;
118 CaptiveDirectoryObject *captive_directory_object;
119
120         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
121         captive_directory_object=(CaptiveDirectoryObject *)method_handle;
122         g_return_val_if_fail(CAPTIVE_DIRECTORY_IS_OBJECT(captive_directory_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
123         g_return_val_if_fail(file_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
124
125         G_LOCK(libcaptive);
126         errvfsresult=captive_directory_read(captive_directory_object,file_info);
127         G_UNLOCK(libcaptive);
128
129         return errvfsresult;
130 }
131
132
133 static GnomeVFSResult captive_gnomevfs_make_directory(GnomeVFSMethod *method,
134                 GnomeVFSURI *uri,guint perm,GnomeVFSContext *context)
135 {
136 GnomeVFSResult errvfsresult;
137 CaptiveDirectoryObject *captive_directory_object;
138
139         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
140
141         errvfsresult=captive_gnomevfs_uri_parent_init(uri);
142         g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
143
144         G_LOCK(libcaptive);
145         errvfsresult=captive_directory_new_make(
146                         &captive_directory_object,      /* captive_directory_object_return */
147                         uri->text,      /* pathname */
148                         perm);  /* perm */
149         G_UNLOCK(libcaptive);
150         if (errvfsresult!=GNOME_VFS_OK)
151                 return errvfsresult;
152
153         G_LOCK(libcaptive);
154         g_object_unref(captive_directory_object);
155         G_UNLOCK(libcaptive);
156
157         return GNOME_VFS_OK;
158 }
159
160
161 static GnomeVFSResult captive_gnomevfs_remove_directory(GnomeVFSMethod *method,
162                 GnomeVFSURI *uri,GnomeVFSContext *context)
163 {
164 GnomeVFSResult errvfsresult;
165 CaptiveDirectoryObject *captive_directory_object;
166
167         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
168
169         errvfsresult=captive_gnomevfs_uri_parent_init(uri);
170         g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
171
172         G_LOCK(libcaptive);
173         errvfsresult=captive_directory_new_open(
174                         &captive_directory_object,      /* captive_directory_object_return */
175                         uri->text);     /* pathname */
176         G_UNLOCK(libcaptive);
177         if (errvfsresult!=GNOME_VFS_OK)
178                 return errvfsresult;
179
180         G_LOCK(libcaptive);
181         errvfsresult=captive_directory_remove(captive_directory_object);
182         G_UNLOCK(libcaptive);
183
184         G_LOCK(libcaptive);
185         g_object_unref(captive_directory_object);
186         G_UNLOCK(libcaptive);
187
188         return errvfsresult;
189 }
190
191
192 static GnomeVFSResult captive_gnomevfs_open(GnomeVFSMethod *method,
193                 GnomeVFSMethodHandle **method_handle_return,GnomeVFSURI *uri,GnomeVFSOpenMode mode,GnomeVFSContext *context)
194 {
195 GnomeVFSResult errvfsresult;
196 CaptiveFileObject *captive_file_object;
197
198         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
199         g_return_val_if_fail(method_handle_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
200
201         errvfsresult=captive_gnomevfs_uri_parent_init(uri);
202         g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
203
204         G_LOCK(libcaptive);
205         errvfsresult=captive_file_new_open(&captive_file_object,uri->text,mode);
206         G_UNLOCK(libcaptive);
207
208         *method_handle_return=(GnomeVFSMethodHandle *)captive_file_object;
209         return errvfsresult;
210 }
211
212
213 static GnomeVFSResult captive_gnomevfs_create(GnomeVFSMethod *method,
214                 GnomeVFSMethodHandle **method_handle_return,GnomeVFSURI *uri,GnomeVFSOpenMode mode,gboolean exclusive,guint perm,
215                 GnomeVFSContext *context)
216 {
217 GnomeVFSResult errvfsresult;
218 CaptiveFileObject *captive_file_object;
219
220         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
221         g_return_val_if_fail(method_handle_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
222
223         errvfsresult=captive_gnomevfs_uri_parent_init(uri);
224         g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
225
226         G_LOCK(libcaptive);
227         errvfsresult=captive_file_new_create(&captive_file_object,uri->text,mode,exclusive,perm);
228         G_UNLOCK(libcaptive);
229
230         *method_handle_return=(GnomeVFSMethodHandle *)captive_file_object;
231         return errvfsresult;
232 }
233
234
235 GnomeVFSResult captive_gnomevfs_unlink(GnomeVFSMethod *method,
236                 GnomeVFSURI *uri,GnomeVFSContext *context)
237 {
238 GnomeVFSResult errvfsresult;
239 CaptiveFileObject *captive_file_object;
240
241         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
242
243         errvfsresult=captive_gnomevfs_uri_parent_init(uri);
244         g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
245
246         G_LOCK(libcaptive);
247         errvfsresult=captive_file_new_open(&captive_file_object,uri->text,
248                         (GNOME_VFS_OPEN_READ | GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_RANDOM));  /* mode; is it OK? */
249         G_UNLOCK(libcaptive);
250         if (errvfsresult!=GNOME_VFS_OK)
251                 return errvfsresult;
252
253         G_LOCK(libcaptive);
254         errvfsresult=captive_file_remove(captive_file_object);
255         G_UNLOCK(libcaptive);
256
257         G_LOCK(libcaptive);
258         g_object_unref(captive_file_object);
259         G_UNLOCK(libcaptive);
260
261         return errvfsresult;
262 }
263
264
265 static GnomeVFSResult captive_gnomevfs_close(GnomeVFSMethod *method,
266                 GnomeVFSMethodHandle *method_handle,GnomeVFSContext *context)
267 {
268 CaptiveFileObject *captive_file_object;
269
270         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
271         captive_file_object=(CaptiveFileObject *)method_handle;
272         g_return_val_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
273
274         G_LOCK(libcaptive);
275         g_object_unref(captive_file_object);
276         G_UNLOCK(libcaptive);
277
278         return GNOME_VFS_OK;
279 }
280
281
282 static GnomeVFSResult captive_gnomevfs_read(GnomeVFSMethod *method,GnomeVFSMethodHandle *method_handle,
283                 gpointer buffer,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_read_return,GnomeVFSContext *context)
284 {
285 GnomeVFSResult errvfsresult;
286 CaptiveFileObject *captive_file_object;
287
288         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
289         captive_file_object=(CaptiveFileObject *)method_handle;
290         g_return_val_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
291         g_return_val_if_fail(buffer!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
292         g_return_val_if_fail(bytes_read_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
293
294         G_LOCK(libcaptive);
295         errvfsresult=captive_file_read(captive_file_object,buffer,num_bytes,bytes_read_return);
296         G_UNLOCK(libcaptive);
297
298         return errvfsresult;
299 }
300
301
302 static GnomeVFSResult captive_gnomevfs_write(GnomeVFSMethod *method,GnomeVFSMethodHandle *method_handle,
303                 gconstpointer buffer,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_written_return,GnomeVFSContext *context)
304 {
305 GnomeVFSResult errvfsresult;
306 CaptiveFileObject *captive_file_object;
307
308         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
309         captive_file_object=(CaptiveFileObject *)method_handle;
310         g_return_val_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
311         g_return_val_if_fail(buffer!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
312         g_return_val_if_fail(bytes_written_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
313
314         G_LOCK(libcaptive);
315         errvfsresult=captive_file_write(captive_file_object,buffer,num_bytes,bytes_written_return);
316         G_UNLOCK(libcaptive);
317
318         return errvfsresult;
319 }
320
321
322 static GnomeVFSResult captive_gnomevfs_seek(GnomeVFSMethod *method,
323                 GnomeVFSMethodHandle *method_handle,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset,GnomeVFSContext *context)
324 {
325 GnomeVFSResult errvfsresult;
326 CaptiveFileObject *captive_file_object;
327
328         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
329         captive_file_object=(CaptiveFileObject *)method_handle;
330         g_return_val_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
331
332         G_LOCK(libcaptive);
333         errvfsresult=captive_file_seek(captive_file_object,whence,offset);
334         G_UNLOCK(libcaptive);
335
336         return errvfsresult;
337 }
338
339 static GnomeVFSResult captive_gnomevfs_tell(GnomeVFSMethod *method,
340                 GnomeVFSMethodHandle *method_handle,GnomeVFSFileOffset *offset_return)
341 {
342 GnomeVFSResult errvfsresult;
343 CaptiveFileObject *captive_file_object;
344
345         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
346         captive_file_object=(CaptiveFileObject *)method_handle;
347         g_return_val_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
348         g_return_val_if_fail(offset_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
349
350         G_LOCK(libcaptive);
351         errvfsresult=captive_file_tell(captive_file_object,offset_return);
352         G_UNLOCK(libcaptive);
353
354         return errvfsresult;
355 }
356
357
358 static gboolean captive_gnomevfs_is_local(GnomeVFSMethod *method,const GnomeVFSURI *uri)
359 {
360         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
361         g_return_val_if_fail(uri!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
362
363         return gnome_vfs_uri_is_local(uri->parent);
364 }
365
366
367 static GnomeVFSResult captive_gnomevfs_get_file_info(GnomeVFSMethod *method,
368                 GnomeVFSURI *uri,GnomeVFSFileInfo *file_info,GnomeVFSFileInfoOptions options,GnomeVFSContext *context)
369 {
370 GnomeVFSResult errvfsresult;
371 CaptiveFileObject *captive_file_object;
372
373         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
374         g_return_val_if_fail(file_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
375         /* handle 'options & GNOME_VFS_FILE_INFO_GET_MIME_TYPE'? */
376
377         errvfsresult=captive_gnomevfs_uri_parent_init(uri);
378         g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
379
380         G_LOCK(libcaptive);
381         errvfsresult=captive_file_new_open(&captive_file_object,uri->text,
382                         0);     /* mode; 0 means FILE_READ_ATTRIBUTES */
383         G_UNLOCK(libcaptive);
384         if (errvfsresult!=GNOME_VFS_OK)
385                 return errvfsresult;
386
387         G_LOCK(libcaptive);
388         errvfsresult=captive_file_file_info_get(captive_file_object,file_info);
389         G_UNLOCK(libcaptive);
390
391         G_LOCK(libcaptive);
392         g_object_unref(captive_file_object);
393         G_UNLOCK(libcaptive);
394
395         return errvfsresult;
396 }
397
398
399 GnomeVFSResult captive_gnomevfs_get_file_info_from_handle(GnomeVFSMethod *method,
400                 GnomeVFSMethodHandle *method_handle,GnomeVFSFileInfo *file_info,GnomeVFSFileInfoOptions options,GnomeVFSContext *context)
401 {
402 GnomeVFSResult errvfsresult;
403 CaptiveFileObject *captive_file_object;
404
405         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
406         captive_file_object=(CaptiveFileObject *)method_handle;
407         g_return_val_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
408         g_return_val_if_fail(file_info!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
409         /* handle 'options & GNOME_VFS_FILE_INFO_GET_MIME_TYPE'? */
410
411         G_LOCK(libcaptive);
412         errvfsresult=captive_file_file_info_get(captive_file_object,file_info);
413         G_UNLOCK(libcaptive);
414
415         return errvfsresult;
416 }
417
418
419 GnomeVFSResult captive_gnomevfs_truncate_handle(GnomeVFSMethod *method,
420                 GnomeVFSMethodHandle *handle,GnomeVFSFileSize length,GnomeVFSContext *context)
421 {
422 GnomeVFSResult errvfsresult;
423 CaptiveFileObject *captive_file_object;
424
425         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
426         captive_file_object=(CaptiveFileObject *)handle;
427         g_return_val_if_fail(CAPTIVE_FILE_IS_OBJECT(captive_file_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
428
429         G_LOCK(libcaptive);
430         errvfsresult=captive_file_truncate(captive_file_object,length);
431         G_UNLOCK(libcaptive);
432
433         return errvfsresult;
434 }
435
436 GnomeVFSResult captive_gnomevfs_truncate(GnomeVFSMethod *method,
437                 GnomeVFSURI *uri,GnomeVFSFileSize length,GnomeVFSContext *context)
438 {
439 GnomeVFSResult errvfsresult;
440 CaptiveFileObject *captive_file_object;
441
442         g_return_val_if_fail(method==&GnomeVFSMethod_static,GNOME_VFS_ERROR_BAD_PARAMETERS);
443
444         errvfsresult=captive_gnomevfs_uri_parent_init(uri);
445         g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
446
447         G_LOCK(libcaptive);
448         errvfsresult=captive_file_new_open(&captive_file_object,uri->text,
449                         (GNOME_VFS_OPEN_READ | GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_RANDOM));  /* mode; is it OK? */
450         G_UNLOCK(libcaptive);
451         if (errvfsresult!=GNOME_VFS_OK)
452                 return errvfsresult;
453
454         G_LOCK(libcaptive);
455         errvfsresult=captive_file_truncate(captive_file_object,length);
456         G_UNLOCK(libcaptive);
457
458         G_LOCK(libcaptive);
459         g_object_unref(captive_file_object);
460         G_UNLOCK(libcaptive);
461
462         return errvfsresult;
463 }
464
465
466 /**
467  * captive_gnomevfs_init:
468  *
469  * Returns: Initialized structure of #GnomeVFSMethod with static methods of libcaptive-gnomevfs.
470  */
471 GnomeVFSMethod *captive_gnomevfs_method_init(const gchar *fs_path)
472 {
473         G_LOCK(captive_gnomevfs_uri_parent);
474         captive_gnomevfs_uri_parent_fs_path=g_strdup(fs_path);
475         G_UNLOCK(captive_gnomevfs_uri_parent);
476
477         G_LOCK(GnomeVFSMethod_static);
478         CAPTIVE_MEMZERO(&GnomeVFSMethod_static);
479         GnomeVFSMethod_static.method_table_size=sizeof(GnomeVFSMethod_static);
480         GnomeVFSMethod_static.open                     =captive_gnomevfs_open;  /* mandatory */
481         GnomeVFSMethod_static.create                   =captive_gnomevfs_create;        /* mandatory */
482         GnomeVFSMethod_static.close                    =captive_gnomevfs_close;
483         GnomeVFSMethod_static.read                     =captive_gnomevfs_read;
484         GnomeVFSMethod_static.write                    =captive_gnomevfs_write;
485         GnomeVFSMethod_static.seek                     =captive_gnomevfs_seek;
486         GnomeVFSMethod_static.tell                     =captive_gnomevfs_tell;
487         GnomeVFSMethod_static.truncate_handle          =captive_gnomevfs_truncate_handle;
488         GnomeVFSMethod_static.open_directory           =captive_gnomevfs_open_directory;
489         GnomeVFSMethod_static.close_directory          =captive_gnomevfs_close_directory;
490         GnomeVFSMethod_static.read_directory           =captive_gnomevfs_read_directory;
491         GnomeVFSMethod_static.get_file_info            =captive_gnomevfs_get_file_info; /* mandatory */
492         GnomeVFSMethod_static.get_file_info_from_handle=captive_gnomevfs_get_file_info_from_handle;
493         GnomeVFSMethod_static.is_local                 =captive_gnomevfs_is_local;      /* mandatory */
494         GnomeVFSMethod_static.make_directory           =captive_gnomevfs_make_directory;
495         GnomeVFSMethod_static.remove_directory         =captive_gnomevfs_remove_directory;
496         /* TODO: GnomeVFSMethodMoveFunc move; */
497         GnomeVFSMethod_static.unlink                   =captive_gnomevfs_unlink;
498         /* TODO: GnomeVFSMethodCheckSameFSFunc check_same_fs; */
499         /* TODO: GnomeVFSMethodSetFileInfo set_file_info; */
500         GnomeVFSMethod_static.truncate                 =captive_gnomevfs_truncate;
501         /* TODO: GnomeVFSMethodFindDirectoryFunc find_directory; */
502         /* TODO: GnomeVFSMethodCreateSymbolicLinkFunc create_symbolic_link; */
503         /* TODO: GnomeVFSMethodMonitorAddFunc monitor_add; */
504         /* TODO: GnomeVFSMethodMonitorCancelFunc monitor_cancel; */
505         /* TODO: GnomeVFSMethodFileControlFunc file_control; */
506         G_UNLOCK(GnomeVFSMethod_static);
507
508         return &GnomeVFSMethod_static;
509 }
510
511
512 /**
513  * captive_gnomevfs_method_shutdown:
514  * Shutdowns libcaptive-gnomevfs successfuly flushing all caches.
515  *
516  * This operation may not completely clean up the process space
517  * if libcaptive #sandbox is not in use.
518  *
519  * Sad note about gnome-vfs-2.1.5 is that it never calls this function. :-)
520  */ 
521 void captive_gnomevfs_method_shutdown(void)
522 {
523         g_return_if_fail(captive_gnomevfs_uri_parent_giognomevfs!=NULL);
524         g_return_if_fail(captive_image_iochannel==(GIOChannel *)captive_gnomevfs_uri_parent_giognomevfs);
525
526         g_io_channel_unref((GIOChannel *)captive_gnomevfs_uri_parent_giognomevfs);
527         captive_gnomevfs_uri_parent_giognomevfs=NULL;
528         g_return_if_fail(captive_image_iochannel==(GIOChannel *)captive_gnomevfs_uri_parent_giognomevfs);       /* ==NULL */
529 }