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