File: v2fuseutils.c

package info (click to toggle)
fuse-umfuse-iso9660 0.3-1.3
  • links: PTS
  • area: main
  • in suites: buster, sid
  • size: 1,392 kB
  • sloc: sh: 11,081; ansic: 1,614; makefile: 25
file content (153 lines) | stat: -rw-r--r-- 3,732 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

/*   This is part of um-ViewOS
 *   The user-mode implementation of OSVIEW -- A Process with a View
 *
 *   v2fuseutils utility functions for fuse
 *   
 *   Copyright 2007 Renzo Davoli University of Bologna - Italy
 *   
 *   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; either version 2 of the License.
 *
 *   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 <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "v2fuseutils.h"

void v2f_usage(char *progname,struct fuse_operations *ops)
{
	  int argc = 2;
		static char *argv[] = {"...", "-h"};
		fprintf(stderr,
				"Usage: %s imagefile mountpoint [options]\n"
				"or at your choice:\n"
				"       %s [options] imagefile mountpoint\n", progname,progname);
		fprintf(stderr,"valid fuse options follow:\n");
#if FUSE_USE_VERSION < 26
		fuse_main( argc, argv, ops);
#else
		fuse_main( argc, argv, ops, NULL);
#endif
		exit(1);
}

void v2f_rearrangeargv(int argc, char *argv[])
{
	int i,sourcearg,dasho;
	for (i=1,dasho=sourcearg=0;i<argc && sourcearg==0;i++) {
		if (*argv[i] != '-' && !dasho)
			sourcearg=i;
		dasho=(strcmp(argv[i],"-o")==0);
	}
	if (sourcearg > 1 && sourcearg < argc-1) {
		char *sourcepath=argv[sourcearg];
		char *mountpoint=argv[sourcearg+1];
		for (i=sourcearg; i>1; i--)
			argv[i+1]=argv[i-1];
		argv[1]=sourcepath;
		argv[2]=mountpoint;
	}
}

int v2f_checkrorwplus(int argc, char *argv[])
{
	int i,result=0;
	for (i=0;i<argc;i++)
		if (strcmp(argv[i],"-o")==0) {
			char *s=argv[i+1];
			char *t=s;
			int status=0;
			while (*s) {
				//printf("%c %d\n",*s,status);
				switch(status) {
					case 0: /* beginning of token */
						if (*s=='r')
							status=1;
						else
							status=2;
						*(t++)=*(s++);
						break;
					case 1: /* leading r */
						if (*s=='o')
							status=3;
						else if (*s=='w')
							status=4;
						else if (*s==',')
							status=0;
						else
							status=2;
						*(t++)=*(s++);
						break;
					case 2: /* no match */
						if (*s==',')
							status=0;
						*(t++)=*(s++);
						break;
					case 3: /* ro */
						if (*s==',') {
							result |= FLRO;
							status=0;
						} else
							status = 2;
						*(t++)=*(s++);
						break;
					case 4:
						*t=*s;
						if (*s=='+') 
							status=5;
						else if (*s==',') {
							result |= FLRW;
							*t='o';
							status = 0;
						} else
							status = 2;
						t++;s++;
						break;
					case 5:
						if (*s==',') {
							result |= FLRWPLUS;
							status = 0;
							t--;
						} else 
							status = 2;
						*(t++)=*(s++);
						break;
				}
			}
			switch (status) {
				case 3: result |= FLRO; break;
				case 4: result |= FLRW; break;
				case 5: result |= FLRWPLUS; t--;break;
			}
			*t=0;
		}
	return result;
}

int v2f_printwarning(int rorwplus) {
	if (!rorwplus || (rorwplus & FLRW)) {
		fprintf(stderr,"This is experimental code, opening rw a real file system could be\n"
				"dangerous for your data. Please add \"-o ro\" if you want to open the file\n"
				"system image in read-only mode, or \"-o rw+\" if you accept the risk to test\n"
				"this module\n");
		return 1;
	} else
		return 0;
}