g_return_val_if_fail(captivefs_vfs!=NULL,FALSE);
G_LOCK(libcaptive);
+ g_assert(captivefs_vfs->inits>0);
+ g_assert(captivefs_vfs->mounts>=0);
+ g_assert(captivefs_vfs->mounts<=captivefs_vfs->inits);
if (!captivefs_vfs->captive_vfs_object) {
GnomeVFSResult errvfsresult;
* global_ctx parameter.
*/
struct captivefs_vfs *captivefs_init
- (struct list_head *cfg,struct dir_cache *cache,const struct credentials *cred,void **global_ctx)
+ (struct list_head *cfg,struct dir_cache *cache,const struct credentials *cred,struct captivefs_vfs **global_ctx)
{
struct captivefs_vfs *captivefs_vfs;
const struct poptOption *cpopt;
poptContext context;
int errint;
+ g_return_val_if_fail(global_ctx!=NULL,NULL);
+
/* Do not: g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_init");
* as we do not yet have 'VFS_DEBUG_MESSAGES(captive_vfs_object)' set.
* Generally we make all g_log() conditional here as we do not want to mess
* with overriden GLog handlers of libcaptive itself.
*/
+ G_LOCK(libcaptive);
+ if ((captivefs_vfs=*global_ctx)) {
+ g_assert(captivefs_vfs->inits>0);
+ /* We do not support multiple LUFS threads if they could not be cross-locked. */
+ g_return_val_if_fail(g_thread_supported(),NULL);
+ captivefs_vfs->inits++;
+ G_UNLOCK(libcaptive);
+ return captivefs_vfs;
+ }
+ G_UNLOCK(libcaptive);
+
+ if (!g_thread_supported())
+ g_thread_init(NULL); /* g_thread_init() fails on second initialization */
+
arg_array=g_ptr_array_new();
if (!(cgs=lu_opt_getchar(cfg,"MOUNT","fs")))
cgs="captivefs";
captive_new(captivefs_vfs);
captivefs_vfs->captive_vfs_object=NULL;
captivefs_vfs->parent_pid=getpid();
+ captivefs_vfs->global_ctx=global_ctx;
+ *global_ctx=captivefs_vfs;
+ captivefs_vfs->inits=1;
+ captivefs_vfs->mounts=0;
captive_options_init(&captivefs_vfs->options);
captive_options=&captivefs_vfs->options; /* for parsing by 'CAPTIVE_POPT_INCLUDE' */
void captivefs_free(struct captivefs_vfs *captivefs_vfs)
{
g_return_if_fail(captivefs_vfs_validate(captivefs_vfs));
+ g_return_if_fail(captivefs_vfs->inits>0);
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_free");
+
+ if (--captivefs_vfs->inits>0) {
+ g_assert(captivefs_vfs_validate(captivefs_vfs));
+ return;
+ }
+ g_assert(captivefs_vfs->mounts==0);
+ G_LOCK(libcaptive);
+ *captivefs_vfs->global_ctx=NULL;
+ G_UNLOCK(libcaptive);
g_assert(G_OBJECT(captivefs_vfs->captive_vfs_object)->ref_count==1);
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_mount");
+ captivefs_vfs->mounts++;
+
+ captivefs_vfs_validate(captivefs_vfs); /* It may return FALSE. */
+
return 1; /* NEVER return 0 */
}
void captivefs_umount(struct captivefs_vfs *captivefs_vfs)
{
g_return_if_fail(captivefs_vfs_validate(captivefs_vfs));
+ g_return_if_fail(captivefs_vfs->mounts>0);
if (captivefs_vfs->options.debug_messages)
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_umount");
+
+ captivefs_vfs->mounts--;
+
+ g_assert(captivefs_vfs_validate(captivefs_vfs));
}