include $(top_srcdir)/Makefile-head.am
-SUBDIRS=cmdline sandbox-server lufs gnomevfs bug-replay
+SUBDIRS=cmdline sandbox-server lufs fuse gnomevfs bug-replay
--- /dev/null
+# $Id$
+# automake source for the fuse module for fuse Makefile
+# Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; exactly version 2 of June 1991 is required
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+include $(top_srcdir)/Makefile-head.am
+include $(top_srcdir)/src/libcaptive/Makefile-libcaptive.am
+
+mount_captive_SOURCES= \
+ op_statfs.c \
+ op_statfs.h \
+ op_fsync.c \
+ op_fsync.h \
+ op_fsyncdir.c \
+ op_fsyncdir.h \
+ gnomevfsresult.c \
+ gnomevfsresult.h \
+ main.c \
+ main.h
+mount_captive_CFLAGS= $(GNOME_VFS_CFLAGS) $(FUSE_CFLAGS)
+mount_captive_LDADD =$(captive_library) $(GNOME_VFS_LIBS) $(FUSE_LIBS) $(INTLLIBS)
+mount_captive_LDFLAGS=$(READLINE_LDFLAGS)
+
+if ENABLE_BUG_REPLAY
+mount_captive_cond=mount.captive
+endif
+bin_PROGRAMS+=$(mount_captive_cond)
--- /dev/null
+/* $Id$
+ * Client fuse interface operation "statfs" for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include <libgnomevfs/gnome-vfs-result.h>
+#include <glib/ghash.h>
+#include <glib/gmessages.h>
+#include <errno.h>
+
+#include "gnomevfsresult.h" /* self */
+
+
+/* Config: */
+#define ERRNO_VALUE_MAX 0x400
+
+
+/* map: GINT_TO_POINTER(GnomeVFSResult) -> GINT_TO_POINTER(errno) */
+static GHashTable *gnomevfsresult_to_errno_hash;
+
+static void gnomevfsresult_to_errno_hash_init(void)
+{
+int errno_i;
+
+ if (gnomevfsresult_to_errno_hash)
+ return;
+ gnomevfsresult_to_errno_hash=g_hash_table_new(g_direct_hash,g_direct_equal);
+ for (errno_i=1;errno_i<ERRNO_VALUE_MAX;errno_i++) {
+GnomeVFSResult gnomevfsresult;
+
+ /* gnome_vfs_result_from_errno_code() returns 'GNOME_VFS_ERROR_GENERIC'
+ * for invalid input values.
+ */
+ gnomevfsresult=gnome_vfs_result_from_errno_code(errno_i);
+ if (GNOME_VFS_ERROR_GENERIC==gnomevfsresult)
+ continue;
+ g_hash_table_insert(
+ gnomevfsresult_to_errno_hash, /* hash_table */
+ GINT_TO_POINTER(gnomevfsresult), /* key */
+ GINT_TO_POINTER(errno_i)); /* value */
+ }
+}
+
+int gnomevfsresult_to_errno(GnomeVFSResult gnomevfsresult)
+{
+int r;
+
+ g_return_val_if_fail(sizeof(GnomeVFSResult)>sizeof(gint),EINVAL);
+
+ /* 'GNOME_VFS_OK' may map to NULL or fallback somehow or whatever weird. */
+ if (GNOME_VFS_OK==gnomevfsresult)
+ return 0;
+
+ gnomevfsresult_to_errno_hash_init();
+ if (!(r=GPOINTER_TO_INT(g_hash_table_lookup(gnomevfsresult_to_errno_hash,GINT_TO_POINTER(gnomevfsresult))))) {
+ g_assert_not_reached();
+ return EINVAL;
+ }
+ return r;
+}
--- /dev/null
+/* $Id$
+ * Include file for client fuse interface operation "statfs" for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_FUSE_GNOMEVFSRESULT_H
+#define _CAPTIVE_CLIENT_FUSE_GNOMEVFSRESULT_H 1
+
+
+#include <libgnomevfs/gnome-vfs-result.h>
+
+
+int gnomevfsresult_to_errno(GnomeVFSResult gnomevfsresult);
+
+
+#endif /* _CAPTIVE_CLIENT_FUSE_GNOMEVFSRESULT_H */
--- /dev/null
+/* $Id$
+ * client FUSE interface for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include <fuse.h>
+#include <popt.h>
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <captive/client-vfs.h>
+#include <captive/macros.h>
+
+#include "main.h" /* self */
+#include "op_statfs.h"
+#include "op_fsync.h"
+#include "op_fsyncdir.h"
+
+
+CaptiveVfsObject *capfuse_captive_vfs_object;
+
+static const struct poptOption popt_table[]={
+ CAPTIVE_POPT_INCLUDE,
+ POPT_AUTOHELP
+ POPT_TABLEEND
+ };
+
+static const struct fuse_operations capfuse_operations={
+ statfs: op_statfs,
+ fsync: op_fsync,
+ fsyncdir: op_fsyncdir,
+#if 0
+ getattr: op_getattr,
+ mknod: op_mknod,
+ mkdir: op_mkdir,
+ unlink: op_unlink,
+ rmdir: op_rmdir,
+ rename: op_rename,
+ chmod: op_chmod,
+ truncate: op_truncate,
+ utime: op_utime,
+ open: op_open,
+ read: op_read,
+ write: op_write,
+ flush: op_flush,
+ release: op_release,
+ opendir: op_opendir,
+ readdir: op_readdir,
+ releasedir: op_releasedir,
+#endif
+ };
+
+/* argv[0] expected as the program name. */
+/* Only options and mountpoint expected here. */
+static void capfuse_run(int argc,const char **argv)
+{
+char *capfuse_mountpoint;
+int capfuse_multithreaded,capfuse_fd;
+struct fuse *capfuse_fuse;
+
+ if (!(capfuse_fuse=fuse_setup(
+ argc, /* argc */
+ (/*de-const; broken fuset_setup()*/char **)argv, /* argv */
+ &capfuse_operations, /* op */
+ sizeof(capfuse_operations), /* op_size */
+ &capfuse_mountpoint, /* mountpoint */
+ &capfuse_multithreaded, /* multithreaded */
+ &capfuse_fd))) /* fd */
+ g_error(_("FUSE fuse_setup() failed"));
+ if (fuse_loop(capfuse_fuse))
+ g_error(_("FUSE fuse_loop() error: %m"));
+ fuse_teardown(capfuse_fuse,capfuse_fd,capfuse_mountpoint);
+}
+
+int main(int argc,char **argv)
+{
+poptContext context;
+int errint;
+int rest_argc;
+const char **rest_argv,**csp;
+struct captive_options options;
+const char **capfuse_argv;
+
+ g_log_set_always_fatal(~(0
+ |G_LOG_LEVEL_MESSAGE
+ |G_LOG_LEVEL_INFO
+ |G_LOG_LEVEL_DEBUG
+ ));
+
+ /* Prevent output block buffering if redirecting stdout to file. */
+ setvbuf(stdout,(char *)NULL,_IONBF,0);
+ setvbuf(stderr,(char *)NULL,_IONBF,0);
+
+ /* Initialize the i18n stuff */
+ setlocale(LC_ALL,"");
+ bindtextdomain(PACKAGE,LOCALEDIR);
+ textdomain(PACKAGE);
+
+ /* Initialize GObject subsystem of GLib. */
+ g_type_init();
+
+ captive_options_init(&options);
+ captive_options=&options; /* for parsing by 'CAPTIVE_POPT_INCLUDE' */
+
+ context=poptGetContext(
+ PACKAGE, /* name */
+ argc,(/*en-const*/const char **)argv, /* argc,argv */
+ popt_table, /* options */
+ POPT_CONTEXT_POSIXMEHARDER); /* flags; && !POPT_CONTEXT_KEEP_FIRST */
+ if (context==NULL) {
+ g_error(_("Error parsing command-line arguments"));
+ return EXIT_FAILURE;
+ }
+ errint=poptReadDefaultConfig(context,
+ TRUE); /* useEnv */
+ if (errint!=0)
+ g_warning(_("Error reading default popt configuration"));
+ errint=poptGetNextOpt(context);
+ if (errint!=-1) {
+ g_error(_("Error parsing (dash-prefixed) command-line argument"));
+ return EXIT_FAILURE;
+ }
+ rest_argv=poptGetArgs(context);
+ for (csp=rest_argv,rest_argc=0;csp && *csp;csp++)
+ rest_argc++;
+
+ captive_options=NULL; /* already parsed by 'CAPTIVE_POPT_INCLUDE' */
+
+ /* image_iochannel */
+ if (rest_argc<1) {
+ g_error(_("File/device disk image pathname command-line argument required"));
+ return EXIT_FAILURE;
+ }
+ g_assert(options.image_iochannel==NULL);
+ if (!(options.image_iochannel=g_io_channel_new_file(
+ rest_argv[0], /* filename */
+ (options.rwmode==CAPTIVE_OPTION_RWMODE_RW ? "r+" : "r"), /* mode */
+ NULL))) { /* error */
+ g_error(_("image_iochannel open failed"));
+ return EXIT_FAILURE;
+ }
+
+ if (options.filesystem.type==CAPTIVE_OPTIONS_MODULE_TYPE_EMPTY) {
+ g_error(_("'--filesystem' option required ('ntfs.sys' pathname suggested)"));
+ return EXIT_FAILURE;
+ }
+ if (!options.load_module) {
+ g_warning(_("'--load-module' option required ('ntoskrnl.exe' pathname suggested)"));
+ return EXIT_FAILURE;
+ }
+
+ if (GNOME_VFS_OK!=captive_vfs_new(&capfuse_captive_vfs_object,&options)) {
+ g_error(_("captive_vfs_new() failed"));
+ return EXIT_FAILURE;
+ }
+ captive_options_free(&options);
+ rest_argc--;
+ rest_argv++;
+
+ /* Simulate argv[0] there as it got cut by popt. */
+ captive_newn_alloca(capfuse_argv,1+rest_argc+1);
+ capfuse_argv[0]=argv[0];
+ memcpy(capfuse_argv+1,rest_argv,sizeof(*rest_argv)*(rest_argc+1));
+
+ /* FIXFUSE: fuse_main()/fuse_main_real() would be enough for Captive fuse but
+ * the public interface of fuse_main() is too broken.
+ */
+ capfuse_run(1+rest_argc,capfuse_argv);
+
+ /* 'rest_argv' gets cleared by 'poptFreeContext(context);' below */
+ poptFreeContext(context);
+
+ if (capfuse_captive_vfs_object) {
+ g_object_unref(capfuse_captive_vfs_object);
+ capfuse_captive_vfs_object=NULL;
+ }
+
+ return EXIT_SUCCESS;
+}
--- /dev/null
+/* $Id$
+ * Include file for client fuse interface control functions for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_FUSE_MAIN_H
+#define _CAPTIVE_CLIENT_FUSE_MAIN_H 1
+
+
+#include <captive/client-vfs.h>
+
+
+extern CaptiveVfsObject *capfuse_captive_vfs_object;
+
+
+#endif /* _CAPTIVE_CLIENT_FUSE_MAIN_H */
--- /dev/null
+/* $Id$
+ * Client fuse interface operation "fsync" for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <fuse.h>
+#include <errno.h>
+
+#include "op_fsync.h" /* self */
+#include "main.h"
+#include "gnomevfsresult.h"
+
+
+int op_fsync(const char *path,int datasync,struct fuse_file_info *fi)
+{
+ g_return_val_if_fail(path!=NULL,-EINVAL);
+
+ return -gnomevfsresult_to_errno(captive_vfs_commit(capfuse_captive_vfs_object));
+}
--- /dev/null
+/* $Id$
+ * Include file for client fuse interface operation "fsync" for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_FUSE_OP_FSYNC_H
+#define _CAPTIVE_CLIENT_FUSE_OP_FSYNC_H 1
+
+
+#include <fuse.h>
+
+
+int op_fsync(const char *path,int datasync,struct fuse_file_info *fi);
+
+
+#endif /* _CAPTIVE_CLIENT_FUSE_OP_FSYNC_H */
--- /dev/null
+/* $Id$
+ * Client fuse interface operation "fsyncdir" for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <fuse.h>
+#include <errno.h>
+
+#include "op_fsyncdir.h" /* self */
+#include "main.h"
+#include "gnomevfsresult.h"
+
+
+int op_fsyncdir(const char *path,int datasync,struct fuse_file_info *fi)
+{
+ g_return_val_if_fail(path!=NULL,-EINVAL);
+
+ return -gnomevfsresult_to_errno(captive_vfs_commit(capfuse_captive_vfs_object));
+}
--- /dev/null
+/* $Id$
+ * Include file for client fuse interface operation "fsyncdir" for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_FUSE_OP_FSYNCDIR_H
+#define _CAPTIVE_CLIENT_FUSE_OP_FSYNCDIR_H 1
+
+
+#include <fuse.h>
+
+
+int op_fsyncdir(const char *path,int datasync,struct fuse_file_info *fi);
+
+
+#endif /* _CAPTIVE_CLIENT_FUSE_OP_FSYNCDIR_H */
--- /dev/null
+/* $Id$
+ * Client fuse interface operation "statfs" for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "config.h"
+
+#include <glib/gmessages.h>
+#include <sys/statfs.h>
+#include <fuse.h>
+#include <libgnomevfs/gnome-vfs-result.h>
+#include <errno.h>
+
+#include "op_statfs.h" /* self */
+#include "main.h"
+#include "gnomevfsresult.h"
+
+
+int op_statfs(const char *path,struct statfs *stbuf)
+{
+CaptiveVfsVolumeInfo volume_info;
+GnomeVFSResult errvfsresult;
+
+ g_return_val_if_fail(path!=NULL,-EINVAL);
+ g_return_val_if_fail(stbuf!=NULL,-EINVAL);
+
+ if (GNOME_VFS_OK!=(errvfsresult=captive_vfs_volume_info_get(capfuse_captive_vfs_object,&volume_info)))
+ return -gnomevfsresult_to_errno(errvfsresult);
+
+ /* <fuse.h>: The 'f_type' and 'f_fsid' fields are ignored */
+ stbuf->f_bsize =volume_info.block_size;
+ /* Some rounding? Which way? */
+ stbuf->f_blocks =volume_info.bytes /volume_info.block_size;
+ stbuf->f_bfree =volume_info.bytes_free /volume_info.block_size;
+ stbuf->f_bavail =volume_info.bytes_available/volume_info.block_size;
+ stbuf->f_files =0;
+ stbuf->f_ffree =0;
+ /* For NTFS: http://en.wikipedia.org/wiki/Comparison_of_file_systems */
+ stbuf->f_namelen=255;
+ return 0;
+}
--- /dev/null
+/* $Id$
+ * Include file for client fuse interface operation "statfs" for libcaptive
+ * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; exactly version 2 of June 1991 is required
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#ifndef _CAPTIVE_CLIENT_FUSE_OP_STATFS_H
+#define _CAPTIVE_CLIENT_FUSE_OP_STATFS_H 1
+
+
+#include <fuse.h>
+
+
+int op_statfs(const char *path,struct statfs *stbuf);
+
+
+#endif /* _CAPTIVE_CLIENT_FUSE_OP_STATFS_H */