1/* Copyright 1997,2000-2002,2009 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#define LOWERCASE 24 25#include "sysincludes.h" 26#include "msdos.h" 27#include "mtools.h" 28#include "vfat.h" 29#include "mainloop.h" 30#include "plain_io.h" 31#include "nameclash.h" 32#include "file.h" 33#include "fs.h" 34 35 36 37typedef struct Arg_t { 38 char *target; 39 MainParam_t mp; 40 ClashHandling_t ch; 41 Stream_t *sourcefile; 42} Arg_t; 43 44static int dos_showfat(direntry_t *entry, MainParam_t *mp) 45{ 46 Stream_t *File=mp->File; 47 48 fprintPwd(stdout, entry,0); 49 putchar(' '); 50 printFat(File); 51 printf("\n"); 52 return GOT_ONE; 53} 54 55static int unix_showfat(MainParam_t *mp) 56{ 57 fprintf(stderr,"File does not reside on a Dos fs\n"); 58 return ERROR_ONE; 59} 60 61 62static void usage(int ret) NORETURN; 63static void usage(int ret) 64{ 65 fprintf(stderr, 66 "Mtools version %s, dated %s\n", mversion, mdate); 67 fprintf(stderr, 68 "Usage: %s files\n", progname); 69 exit(ret); 70} 71 72void mshowfat(int argc, char **argv, int mtype) 73{ 74 Arg_t arg; 75 int c, ret; 76 77 /* get command line options */ 78 79 init_clash_handling(& arg.ch); 80 81 /* get command line options */ 82 if(helpFlag(argc, argv)) 83 usage(0); 84 while ((c = getopt(argc, argv, "i:h")) != EOF) { 85 switch (c) { 86 case 'i': 87 set_cmd_line_image(optarg, 0); 88 break; 89 case 'h': 90 usage(0); 91 case '?': 92 usage(1); 93 break; 94 } 95 } 96 97 if (argc - optind < 1) 98 usage(1); 99 100 /* only 1 file to copy... */ 101 init_mp(&arg.mp); 102 arg.mp.arg = (void *) &arg; 103 104 arg.mp.callback = dos_showfat; 105 arg.mp.unixcallback = unix_showfat; 106 107 arg.mp.lookupflags = ACCEPT_PLAIN | ACCEPT_DIR | DO_OPEN; 108 ret=main_loop(&arg.mp, argv + optind, argc - optind); 109 exit(ret); 110} 111