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"
43 #include "op_unlink.h"
47 #include "op_truncate.h"
49 #include "op_rename.h"
53 CaptiveVfsObject *capfuse_captive_vfs_object;
55 static const struct poptOption popt_table[]={
61 static const struct fuse_operations capfuse_operations={
64 fsyncdir: op_fsyncdir,
67 releasedir: op_releasedir,
77 truncate: op_truncate,
83 /* argv[0] expected as the program name. */
84 /* Only options and mountpoint expected here. */
85 static void capfuse_run(int argc,const char **argv)
87 char *capfuse_mountpoint;
88 int capfuse_multithreaded,capfuse_fd;
89 struct fuse *capfuse_fuse;
91 if (!(capfuse_fuse=fuse_setup(
93 (/*de-const; broken fuset_setup()*/char **)argv, /* argv */
94 &capfuse_operations, /* op */
95 sizeof(capfuse_operations), /* op_size */
96 &capfuse_mountpoint, /* mountpoint */
97 &capfuse_multithreaded, /* multithreaded */
98 &capfuse_fd))) /* fd */
99 g_error(_("FUSE fuse_setup() failed"));
100 if (fuse_loop(capfuse_fuse)) {
101 /* Do not: g_error(_("FUSE fuse_loop() error"));
102 * as it is caused on each umount(8).
106 fuse_teardown(capfuse_fuse,capfuse_fd,capfuse_mountpoint);
109 int main(int argc,char **argv)
114 const char **rest_argv,**csp;
115 struct captive_options options;
116 const char **capfuse_argv;
118 g_log_set_always_fatal(~(0
124 /* Prevent output block buffering if redirecting stdout to file. */
125 setvbuf(stdout,(char *)NULL,_IONBF,0);
126 setvbuf(stderr,(char *)NULL,_IONBF,0);
128 /* Initialize the i18n stuff */
129 setlocale(LC_ALL,"");
130 bindtextdomain(PACKAGE,LOCALEDIR);
133 /* Initialize GObject subsystem of GLib. */
136 captive_options_init(&options);
137 captive_options=&options; /* for parsing by 'CAPTIVE_POPT_INCLUDE' */
139 context=poptGetContext(
141 argc,(/*en-const*/const char **)argv, /* argc,argv */
142 popt_table, /* options */
143 POPT_CONTEXT_POSIXMEHARDER); /* flags; && !POPT_CONTEXT_KEEP_FIRST */
145 g_error(_("Error parsing command-line arguments"));
148 errint=poptReadDefaultConfig(context,
151 g_warning(_("Error reading default popt configuration"));
152 errint=poptGetNextOpt(context);
154 g_error(_("Error parsing (dash-prefixed) command-line argument"));
157 rest_argv=poptGetArgs(context);
158 for (csp=rest_argv,rest_argc=0;csp && *csp;csp++)
161 captive_options=NULL; /* already parsed by 'CAPTIVE_POPT_INCLUDE' */
163 /* image_iochannel */
165 g_error(_("File/device disk image pathname command-line argument required"));
168 g_assert(options.image_iochannel==NULL);
169 if (!(options.image_iochannel=g_io_channel_new_file(
170 rest_argv[0], /* filename */
171 (options.rwmode==CAPTIVE_OPTION_RWMODE_RW ? "r+" : "r"), /* mode */
172 NULL))) { /* error */
173 g_error(_("image_iochannel open failed"));
177 if (options.filesystem.type==CAPTIVE_OPTIONS_MODULE_TYPE_EMPTY) {
178 g_error(_("'--filesystem' option required ('ntfs.sys' pathname suggested)"));
181 if (!options.load_module) {
182 g_warning(_("'--load-module' option required ('ntoskrnl.exe' pathname suggested)"));
186 if (GNOME_VFS_OK!=captive_vfs_new(&capfuse_captive_vfs_object,&options)) {
187 g_error(_("captive_vfs_new() failed"));
190 captive_options_free(&options);
194 /* Simulate argv[0] there as it got cut by popt. */
195 captive_newn_alloca(capfuse_argv,1+rest_argc+1);
196 capfuse_argv[0]=argv[0];
197 memcpy(capfuse_argv+1,rest_argv,sizeof(*rest_argv)*(rest_argc+1));
199 /* FIXFUSE: fuse_main()/fuse_main_real() would be enough for Captive fuse but
200 * the public interface of fuse_main() is too broken.
202 capfuse_run(1+rest_argc,capfuse_argv);
204 /* 'rest_argv' gets cleared by 'poptFreeContext(context);' below */
205 poptFreeContext(context);
207 if (capfuse_captive_vfs_object) {
208 g_object_unref(capfuse_captive_vfs_object);
209 capfuse_captive_vfs_object=NULL;