1 /* Copyright 1997,2000-2002,2009,2011 Alain Knaff.
2 * This file is part of mtools.
3 *
4 * Mtools is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Mtools 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.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * mcopy.c
18 * Copy an MSDOS files to and from Unix
19 *
20 */
21
22
23 #include "sysincludes.h"
24 #include "msdos.h"
25 #include "mtools.h"
26 #include "vfat.h"
27 #include "mainloop.h"
28 #include "plain_io.h"
29 #include "nameclash.h"
30 #include "file.h"
31 #include "fs.h"
32
33 typedef struct Arg_t {
34 MainParam_t mp;
35 off_t offset;
36 } Arg_t;
37
dos_showfat(direntry_t * entry,MainParam_t * mp)38 static int dos_showfat(direntry_t *entry, MainParam_t *mp)
39 {
40 Stream_t *File=mp->File;
41 Arg_t *arg = (Arg_t *) mp->arg;
42 fprintPwd(stdout, entry,0);
43 putchar(' ');
44 if(arg->offset == -1) {
45 printFat(File);
46 } else {
47 printFatWithOffset(File, arg->offset);
48 }
49 printf("\n");
50 return GOT_ONE;
51 }
52
unix_showfat(MainParam_t * mp UNUSEDP)53 static int unix_showfat(MainParam_t *mp UNUSEDP)
54 {
55 fprintf(stderr,"File does not reside on a Dos fs\n");
56 return ERROR_ONE;
57 }
58
59
60 static void usage(int ret) NORETURN;
usage(int ret)61 static void usage(int ret)
62 {
63 fprintf(stderr,
64 "Mtools version %s, dated %s\n", mversion, mdate);
65 fprintf(stderr,
66 "Usage: %s files\n", progname);
67 exit(ret);
68 }
69
70 void mshowfat(int argc, char **argv, int mtype UNUSEDP) NORETURN;
mshowfat(int argc,char ** argv,int mtype UNUSEDP)71 void mshowfat(int argc, char **argv, int mtype UNUSEDP)
72 {
73 Arg_t arg;
74 int c, ret;
75
76 /* get command line options */
77 if(helpFlag(argc, argv))
78 usage(0);
79 arg.offset = -1;
80 while ((c = getopt(argc, argv, "i:ho:")) != EOF) {
81 switch (c) {
82 case 'o':
83 arg.offset = str_to_offset(optarg);
84 break;
85 case 'i':
86 set_cmd_line_image(optarg);
87 break;
88 case 'h':
89 usage(0);
90 case '?':
91 usage(1);
92 }
93 }
94
95 if (argc - optind < 1)
96 usage(1);
97
98 /* only 1 file to handle... */
99 init_mp(&arg.mp);
100 arg.mp.arg = (void *) &arg;
101
102 arg.mp.callback = dos_showfat;
103 arg.mp.unixcallback = unix_showfat;
104
105 arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN;
106 ret=main_loop(&arg.mp, argv + optind, argc - optind);
107 exit(ret);
108 }
109