2 * client FUSE interface for libcaptive
3 * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
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
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.
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
28 #include <captive/client-vfs.h>
29 #include <captive/macros.h>
31 #include "main.h" /* self */
32 #include "op_statfs.h"
34 #include "op_fsyncdir.h"
37 CaptiveVfsObject *capfuse_captive_vfs_object;
39 static const struct poptOption popt_table[]={
45 static const struct fuse_operations capfuse_operations={
48 fsyncdir: op_fsyncdir,
57 truncate: op_truncate,
66 releasedir: op_releasedir,
70 /* argv[0] expected as the program name. */
71 /* Only options and mountpoint expected here. */
72 static void capfuse_run(int argc,const char **argv)
74 char *capfuse_mountpoint;
75 int capfuse_multithreaded,capfuse_fd;
76 struct fuse *capfuse_fuse;
78 if (!(capfuse_fuse=fuse_setup(
80 (/*de-const; broken fuset_setup()*/char **)argv, /* argv */
81 &capfuse_operations, /* op */
82 sizeof(capfuse_operations), /* op_size */
83 &capfuse_mountpoint, /* mountpoint */
84 &capfuse_multithreaded, /* multithreaded */
85 &capfuse_fd))) /* fd */
86 g_error(_("FUSE fuse_setup() failed"));
87 if (fuse_loop(capfuse_fuse))
88 g_error(_("FUSE fuse_loop() error: %m"));
89 fuse_teardown(capfuse_fuse,capfuse_fd,capfuse_mountpoint);
92 int main(int argc,char **argv)
97 const char **rest_argv,**csp;
98 struct captive_options options;
99 const char **capfuse_argv;
101 g_log_set_always_fatal(~(0
107 /* Prevent output block buffering if redirecting stdout to file. */
108 setvbuf(stdout,(char *)NULL,_IONBF,0);
109 setvbuf(stderr,(char *)NULL,_IONBF,0);
111 /* Initialize the i18n stuff */
112 setlocale(LC_ALL,"");
113 bindtextdomain(PACKAGE,LOCALEDIR);
116 /* Initialize GObject subsystem of GLib. */
119 captive_options_init(&options);
120 captive_options=&options; /* for parsing by 'CAPTIVE_POPT_INCLUDE' */
122 context=poptGetContext(
124 argc,(/*en-const*/const char **)argv, /* argc,argv */
125 popt_table, /* options */
126 POPT_CONTEXT_POSIXMEHARDER); /* flags; && !POPT_CONTEXT_KEEP_FIRST */
128 g_error(_("Error parsing command-line arguments"));
131 errint=poptReadDefaultConfig(context,
134 g_warning(_("Error reading default popt configuration"));
135 errint=poptGetNextOpt(context);
137 g_error(_("Error parsing (dash-prefixed) command-line argument"));
140 rest_argv=poptGetArgs(context);
141 for (csp=rest_argv,rest_argc=0;csp && *csp;csp++)
144 captive_options=NULL; /* already parsed by 'CAPTIVE_POPT_INCLUDE' */
146 /* image_iochannel */
148 g_error(_("File/device disk image pathname command-line argument required"));
151 g_assert(options.image_iochannel==NULL);
152 if (!(options.image_iochannel=g_io_channel_new_file(
153 rest_argv[0], /* filename */
154 (options.rwmode==CAPTIVE_OPTION_RWMODE_RW ? "r+" : "r"), /* mode */
155 NULL))) { /* error */
156 g_error(_("image_iochannel open failed"));
160 if (options.filesystem.type==CAPTIVE_OPTIONS_MODULE_TYPE_EMPTY) {
161 g_error(_("'--filesystem' option required ('ntfs.sys' pathname suggested)"));
164 if (!options.load_module) {
165 g_warning(_("'--load-module' option required ('ntoskrnl.exe' pathname suggested)"));
169 if (GNOME_VFS_OK!=captive_vfs_new(&capfuse_captive_vfs_object,&options)) {
170 g_error(_("captive_vfs_new() failed"));
173 captive_options_free(&options);
177 /* Simulate argv[0] there as it got cut by popt. */
178 captive_newn_alloca(capfuse_argv,1+rest_argc+1);
179 capfuse_argv[0]=argv[0];
180 memcpy(capfuse_argv+1,rest_argv,sizeof(*rest_argv)*(rest_argc+1));
182 /* FIXFUSE: fuse_main()/fuse_main_real() would be enough for Captive fuse but
183 * the public interface of fuse_main() is too broken.
185 capfuse_run(1+rest_argc,capfuse_argv);
187 /* 'rest_argv' gets cleared by 'poptFreeContext(context);' below */
188 poptFreeContext(context);
190 if (capfuse_captive_vfs_object) {
191 g_object_unref(capfuse_captive_vfs_object);
192 capfuse_captive_vfs_object=NULL;