captive_init(): 'image_iochannel' is now optional to just parse 'captive_args'
authorshort <>
Mon, 20 Jan 2003 23:20:19 +0000 (23:20 +0000)
committershort <>
Mon, 20 Jan 2003 23:20:19 +0000 (23:20 +0000)
Support read/write device mode

src/client/libcaptive-gnomevfs/giognomevfs.c

index 5bc4d77..f4af5b7 100644 (file)
@@ -180,7 +180,19 @@ gboolean errbool;
        g_return_val_if_fail(giognomevfsp!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
        g_return_val_if_fail(uri!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
 
-       errvfsresult=gnome_vfs_open_uri(&handle,uri,GNOME_VFS_OPEN_READ);
+       /* Parse 'captive_args' to get at least 'captive_option_rwmode' option value (phase 1). */
+       G_LOCK(libcaptive);
+       errbool=captive_init(
+                       captive_args,   /* captive_args */
+                       NULL);  /* image_iochannel */
+       G_UNLOCK(libcaptive);
+       g_assert(errbool==FALSE);
+
+       errvfsresult=gnome_vfs_open_uri(&handle,uri,
+                       0       /* open_mode */
+                                       | GNOME_VFS_OPEN_RANDOM /* mandatory; otherwise we will get truncation if GNOME_VFS_OPEN_WRITE */
+                                       | GNOME_VFS_OPEN_READ
+                                       | (captive_option_rwmode==CAPTIVE_OPTION_RWMODE_RW ? GNOME_VFS_OPEN_WRITE : 0));
        g_return_val_if_fail(errvfsresult==GNOME_VFS_OK,errvfsresult);
 
        G_LOCK(giochannel_funcs);
@@ -200,12 +212,13 @@ gboolean errbool;
        giognomevfs->iochannel.funcs=&giochannel_funcs;
        giognomevfs->iochannel.is_seekable=TRUE;
        giognomevfs->iochannel.is_readable=TRUE;
-       giognomevfs->iochannel.is_writeable=TRUE;
+       giognomevfs->iochannel.is_writeable=(captive_option_rwmode==CAPTIVE_OPTION_RWMODE_RW);
        giognomevfs->gnomevfshandle=handle;
 
+       /* Initialization for the real this time (phase 2). */
        G_LOCK(libcaptive);
        errbool=captive_init(
-                       captive_args,   /* captive_args */
+                       NULL,   /* captive_args */
                        (GIOChannel *)giognomevfs);     /* image_iochannel */
        G_UNLOCK(libcaptive);
        g_assert(errbool==TRUE);