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"
35 #include "op_opendir.h"
36 #include "op_readdir.h"
37 #include "op_releasedir.h"
40 #include "op_release.h"
41 #include "op_getattr.h"
44 CaptiveVfsObject *capfuse_captive_vfs_object;
46 static const struct poptOption popt_table[]={
52 static const struct fuse_operations capfuse_operations={
55 fsyncdir: op_fsyncdir,
58 releasedir: op_releasedir,
71 truncate: op_truncate,
77 /* argv[0] expected as the program name. */
78 /* Only options and mountpoint expected here. */
79 static void capfuse_run(int argc,const char **argv)
81 char *capfuse_mountpoint;
82 int capfuse_multithreaded,capfuse_fd;
83 struct fuse *capfuse_fuse;
85 if (!(capfuse_fuse=fuse_setup(
87 (/*de-const; broken fuset_setup()*/char **)argv, /* argv */
88 &capfuse_operations, /* op */
89 sizeof(capfuse_operations), /* op_size */
90 &capfuse_mountpoint, /* mountpoint */
91 &capfuse_multithreaded, /* multithreaded */
92 &capfuse_fd))) /* fd */
93 g_error(_("FUSE fuse_setup() failed"));
94 if (fuse_loop(capfuse_fuse)) {
95 /* Do not: g_error(_("FUSE fuse_loop() error"));
96 * as it is caused on each umount(8).
100 fuse_teardown(capfuse_fuse,capfuse_fd,capfuse_mountpoint);
103 int main(int argc,char **argv)
108 const char **rest_argv,**csp;
109 struct captive_options options;
110 const char **capfuse_argv;
112 g_log_set_always_fatal(~(0
118 /* Prevent output block buffering if redirecting stdout to file. */
119 setvbuf(stdout,(char *)NULL,_IONBF,0);
120 setvbuf(stderr,(char *)NULL,_IONBF,0);
122 /* Initialize the i18n stuff */
123 setlocale(LC_ALL,"");
124 bindtextdomain(PACKAGE,LOCALEDIR);
127 /* Initialize GObject subsystem of GLib. */
130 captive_options_init(&options);
131 captive_options=&options; /* for parsing by 'CAPTIVE_POPT_INCLUDE' */
133 context=poptGetContext(
135 argc,(/*en-const*/const char **)argv, /* argc,argv */
136 popt_table, /* options */
137 POPT_CONTEXT_POSIXMEHARDER); /* flags; && !POPT_CONTEXT_KEEP_FIRST */
139 g_error(_("Error parsing command-line arguments"));
142 errint=poptReadDefaultConfig(context,
145 g_warning(_("Error reading default popt configuration"));
146 errint=poptGetNextOpt(context);
148 g_error(_("Error parsing (dash-prefixed) command-line argument"));
151 rest_argv=poptGetArgs(context);
152 for (csp=rest_argv,rest_argc=0;csp && *csp;csp++)
155 captive_options=NULL; /* already parsed by 'CAPTIVE_POPT_INCLUDE' */
157 /* image_iochannel */
159 g_error(_("File/device disk image pathname command-line argument required"));
162 g_assert(options.image_iochannel==NULL);
163 if (!(options.image_iochannel=g_io_channel_new_file(
164 rest_argv[0], /* filename */
165 (options.rwmode==CAPTIVE_OPTION_RWMODE_RW ? "r+" : "r"), /* mode */
166 NULL))) { /* error */
167 g_error(_("image_iochannel open failed"));
171 if (options.filesystem.type==CAPTIVE_OPTIONS_MODULE_TYPE_EMPTY) {
172 g_error(_("'--filesystem' option required ('ntfs.sys' pathname suggested)"));
175 if (!options.load_module) {
176 g_warning(_("'--load-module' option required ('ntoskrnl.exe' pathname suggested)"));
180 if (GNOME_VFS_OK!=captive_vfs_new(&capfuse_captive_vfs_object,&options)) {
181 g_error(_("captive_vfs_new() failed"));
184 captive_options_free(&options);
188 /* Simulate argv[0] there as it got cut by popt. */
189 captive_newn_alloca(capfuse_argv,1+rest_argc+1);
190 capfuse_argv[0]=argv[0];
191 memcpy(capfuse_argv+1,rest_argv,sizeof(*rest_argv)*(rest_argc+1));
193 /* FIXFUSE: fuse_main()/fuse_main_real() would be enough for Captive fuse but
194 * the public interface of fuse_main() is too broken.
196 capfuse_run(1+rest_argc,capfuse_argv);
198 /* 'rest_argv' gets cleared by 'poptFreeContext(context);' below */
199 poptFreeContext(context);
201 if (capfuse_captive_vfs_object) {
202 g_object_unref(capfuse_captive_vfs_object);
203 capfuse_captive_vfs_object=NULL;