~ubuntu-branches/ubuntu/saucy/fuse-umfuse-ext2/saucy

« back to all changes in this revision

Viewing changes to v2fuseutils.c

  • Committer: Package Import Robot
  • Author(s): Ludovico Gardenghi, Filippo Giunchedi, Ludovico Gardenghi
  • Date: 2012-06-24 20:58:20 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120624205820-d9avp9pa6zgiyac7
Tags: 0.4-1
[ Filippo Giunchedi ]
* Add DM-Upload-Allowed field

[ Ludovico Gardenghi ]
* New upstream release
  + Source code completely changed, now it's a fork of fuse-ext2 by
    Alper Akcan
  + Update copyright file accordingly
  + Resolve old codebase issues (Closes: #562177, #670622)
* Update to S-V 3.9.3
* Switch to machine-readable copyright file
* Update mail address for Ludovico Gardenghi
* Add compatibility symlinks (old version used fuseext2, this one uses
  fuse-ext2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/*   This is part of um-ViewOS
3
 
 *   The user-mode implementation of OSVIEW -- A Process with a View
4
 
 *
5
 
 *   v2fuseutils utility functions for fuse
6
 
 *   
7
 
 *   Copyright 2007 Renzo Davoli University of Bologna - Italy
8
 
 *   
9
 
 *   This program is free software; you can redistribute it and/or modify
10
 
 *   it under the terms of the GNU General Public License as published by
11
 
 *   the Free Software Foundation; either version 2 of the License.
12
 
 *
13
 
 *   This program is distributed in the hope that it will be useful,
14
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 *   GNU General Public License for more details.
17
 
 *
18
 
 *   You should have received a copy of the GNU General Public License along
19
 
 *   with this program; if not, write to the Free Software Foundation, Inc.,
20
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 
 *
22
 
 */
23
 
 
24
 
#include <config.h>
25
 
#include <fuse.h>
26
 
#include <stdio.h>
27
 
#include <string.h>
28
 
#include <unistd.h>
29
 
#include <stdlib.h>
30
 
#include "v2fuseutils.h"
31
 
 
32
 
void v2f_usage(char *progname,struct fuse_operations *ops)
33
 
{
34
 
          int argc = 2;
35
 
                static char *argv[] = {"...", "-h"};
36
 
                fprintf(stderr,
37
 
                                "Usage: %s imagefile mountpoint [options]\n"
38
 
                                "or at your choice:\n"
39
 
                                "       %s [options] imagefile mountpoint\n", progname,progname);
40
 
                fprintf(stderr,"valid fuse options follow:\n");
41
 
#if FUSE_USE_VERSION < 26
42
 
                fuse_main( argc, argv, ops);
43
 
#else
44
 
                fuse_main( argc, argv, ops, NULL);
45
 
#endif
46
 
                exit(1);
47
 
}
48
 
 
49
 
void v2f_rearrangeargv(int argc, char *argv[])
50
 
{
51
 
          int i,sourcearg,dasho;
52
 
                  for (i=1,dasho=sourcearg=0;i<argc && sourcearg==0;i++) {
53
 
                                    if (*argv[i] != '-' && !dasho)
54
 
                                                              sourcearg=i;
55
 
                                                    dasho=(strcmp(argv[i],"-o")==0);
56
 
                                                                  }
57
 
                          if (sourcearg > 1 && sourcearg < argc-1) {
58
 
                                            char *sourcepath=argv[sourcearg];
59
 
                                                            char *mountpoint=argv[sourcearg+1];
60
 
                                                                            for (i=sourcearg; i>1; i--)
61
 
                                                                                                      argv[i+1]=argv[i-1];
62
 
                                                                                            argv[1]=sourcepath;
63
 
                                                                                                            argv[2]=mountpoint;
64
 
                                                                                                                          }
65
 
}
66
 
 
67
 
int v2f_checkrorwplus(int argc, char *argv[])
68
 
{
69
 
        int i,result=0;
70
 
        for (i=0;i<argc;i++)
71
 
                if (strcmp(argv[i],"-o")==0) {
72
 
                        char *s=argv[i+1];
73
 
                        char *t=s;
74
 
                        int status=0;
75
 
                        while (*s) {
76
 
                                //printf("%c %d\n",*s,status);
77
 
                                switch(status) {
78
 
                                        case 0: /* beginning of token */
79
 
                                                if (*s=='r')
80
 
                                                        status=1;
81
 
                                                else
82
 
                                                        status=2;
83
 
                                                *(t++)=*(s++);
84
 
                                                break;
85
 
                                        case 1: /* leading r */
86
 
                                                if (*s=='o')
87
 
                                                        status=3;
88
 
                                                else if (*s=='w')
89
 
                                                        status=4;
90
 
                                                else if (*s==',')
91
 
                                                        status=0;
92
 
                                                else
93
 
                                                        status=2;
94
 
                                                *(t++)=*(s++);
95
 
                                                break;
96
 
                                        case 2: /* no match */
97
 
                                                if (*s==',')
98
 
                                                        status=0;
99
 
                                                *(t++)=*(s++);
100
 
                                                break;
101
 
                                        case 3: /* ro */
102
 
                                                if (*s==',') {
103
 
                                                        result |= FLRO;
104
 
                                                        status=0;
105
 
                                                } else
106
 
                                                        status = 2;
107
 
                                                *(t++)=*(s++);
108
 
                                                break;
109
 
                                        case 4:
110
 
                                                *t=*s;
111
 
                                                if (*s=='+') 
112
 
                                                        status=5;
113
 
                                                else if (*s==',') {
114
 
                                                        result |= FLRW;
115
 
                                                        *t='o';
116
 
                                                        status = 0;
117
 
                                                } else
118
 
                                                        status = 2;
119
 
                                                t++;s++;
120
 
                                                break;
121
 
                                        case 5:
122
 
                                                if (*s==',') {
123
 
                                                        result |= FLRWPLUS;
124
 
                                                        status = 0;
125
 
                                                        t--;
126
 
                                                } else 
127
 
                                                        status = 2;
128
 
                                                *(t++)=*(s++);
129
 
                                                break;
130
 
                                }
131
 
                        }
132
 
                        switch (status) {
133
 
                                case 3: result |= FLRO; break;
134
 
                                case 4: result |= FLRW; break;
135
 
                                case 5: result |= FLRWPLUS; t--;break;
136
 
                        }
137
 
                        *t=0;
138
 
                }
139
 
        return result;
140
 
}
141
 
 
142
 
int v2f_printwarning(int rorwplus) {
143
 
        if (!rorwplus || (rorwplus & FLRW)) {
144
 
                fprintf(stderr,"This is experimental code, opening rw a real file system could be\n"
145
 
                                "dangerous for your data. Please add \"-o ro\" if you want to open the file\n"
146
 
                                "system image in read-only mode, or \"-o rw+\" if you accept the risk to test\n"
147
 
                                "this module\n");
148
 
                return 1;
149
 
        } else
150
 
                return 0;
151
 
}
152
 
 
153