/* rcopy.c - Copia datos en forma cruda de y hacia un dispositivo Copyright (C) 2000 Luis Carlos Castro Skertchly 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, or (at your option) any later version. 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 Inicio: 15 de Junio de 2000 Uso: rcopy source destin Versiones Corriendo: 1.0 15 de Junio de 2000 */ #define _CRT_SECURE_NO_DEPRECATE #define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN #include #include #include HANDLE hSource; HANDLE hDestin; char *source; char *destin; DWORD dflag; DWORD block_size = 1024; char *szBuffer; DWORD bytes; DWORD fileSize, count; short i; int main(int argc, char **argv) { printf("rcopy - Version 1.2\nCopyright (C) 2000-2007, Luis C. Castro Skertchly\n"); if (argc < 3) { printf("Usage: rcopy [-b] source target\n" "Source can be a special device like:\n" " \\\\.\\A:\n" " \\\\.\\B:\n" " \\\\.\\TAPE0\n" " \\\\.\\CDROM0\n" " \\\\.\\PhysicalDrive0\n" ); exit(1); } i = 1; if (!strncmp(argv[i], "-b", 2)) { block_size = atoi(argv[i] + 2); i++; } source = argv[i]; destin = argv[i + 1]; szBuffer = (char *) malloc(block_size); hSource = CreateFile(source, GENERIC_READ | FILE_SHARE_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hSource == INVALID_HANDLE_VALUE) { printf("\nError opening source file '%s'\n", source); exit(1); } if (!strncmp(destin, "\\\\", 2)) dflag = OPEN_EXISTING; else dflag = CREATE_ALWAYS; hDestin = CreateFile(destin, GENERIC_WRITE | FILE_SHARE_WRITE, 0, NULL, dflag, 0, NULL); if (hDestin == INVALID_HANDLE_VALUE) { printf("\nError opening destination file '%s'\n", destin); exit(1); } fileSize = GetFileSize(hSource, NULL); if (fileSize == INVALID_FILE_SIZE) fprintf(stderr, "WARNING: Can't get source file size\n"); count = 0; printf("Copying %s to %s (block size = %d bytes)\n", source, destin, block_size); while (ReadFile(hSource, szBuffer, block_size, &bytes, NULL)) { if (!bytes) break; WriteFile(hDestin, szBuffer, bytes, &bytes, NULL); count += bytes; if (fileSize == INVALID_FILE_SIZE) printf("\r%ld MB copied...", count / 1048576); else printf("\r%ld of %ld MB copied...", count / 1048576, fileSize / 1048576); } CloseHandle(hSource); CloseHandle(hDestin); free(szBuffer); return 0; }