| 1 |
/*************************************************************************** |
| 2 |
|
| 3 |
Hard disk compression frontend |
| 4 |
|
| 5 |
***************************************************************************/ |
| 6 |
|
| 7 |
#include "harddisk.h" |
| 8 |
#include <stdarg.h> |
| 9 |
#include <stdio.h> |
| 10 |
|
| 11 |
|
| 12 |
static void *hdcomp_open(const char *filename, const char *mode); |
| 13 |
static void hdcomp_close(void *file); |
| 14 |
static UINT32 hdcomp_read(void *file, UINT64 offset, UINT32 count, void *buffer); |
| 15 |
static UINT32 hdcomp_write(void *file, UINT64 offset, UINT32 count, const void *buffer); |
| 16 |
|
| 17 |
static struct hard_disk_interface hdcomp_interface = |
| 18 |
{ |
| 19 |
hdcomp_open, |
| 20 |
hdcomp_close, |
| 21 |
hdcomp_read, |
| 22 |
hdcomp_write |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
static void progress(const char *fmt, ...) |
| 27 |
{ |
| 28 |
va_list arg; |
| 29 |
|
| 30 |
/* standard vfprintf stuff here */ |
| 31 |
va_start(arg, fmt); |
| 32 |
vprintf(fmt, arg); |
| 33 |
va_end(arg); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
int main(int argc, char **argv) |
| 38 |
{ |
| 39 |
struct hard_disk_header header = { 0 }; |
| 40 |
int offset, err; |
| 41 |
FILE *temp; |
| 42 |
|
| 43 |
/* cheesy for now: require all args */ |
| 44 |
if (argc != 7) |
| 45 |
{ |
| 46 |
fprintf(stderr, "usage: hdcomp inputfile outputfile inputoffs cylinders heads sectors\n"); |
| 47 |
return 1; |
| 48 |
} |
| 49 |
|
| 50 |
/* extract the data */ |
| 51 |
offset = atoi(argv[3]); |
| 52 |
header.cylinders = atoi(argv[4]); |
| 53 |
header.heads = atoi(argv[5]); |
| 54 |
header.sectors = atoi(argv[6]); |
| 55 |
|
| 56 |
/* fill in the rest of the header */ |
| 57 |
header.flags = 0; |
| 58 |
header.compression = HDCOMPRESSION_ZLIB; |
| 59 |
header.blocksize = 8; |
| 60 |
|
| 61 |
/* print some info */ |
| 62 |
printf("Input file: %s\n", argv[1]); |
| 63 |
printf("Output file: %s\n", argv[2]); |
| 64 |
printf("Input offset: %d\n", offset); |
| 65 |
printf("Cylinders: %d\n", header.cylinders); |
| 66 |
printf("Heads: %d\n", header.heads); |
| 67 |
printf("Sectors: %d\n", header.sectors); |
| 68 |
|
| 69 |
/* verify the file size */ |
| 70 |
temp = fopen(argv[1], "rb"); |
| 71 |
if (!temp) |
| 72 |
{ |
| 73 |
fprintf(stderr, "Can't open source file %s!\n", argv[1]); |
| 74 |
return 1; |
| 75 |
} |
| 76 |
|
| 77 |
/* compress the hard drive */ |
| 78 |
hard_disk_set_interface(&hdcomp_interface); |
| 79 |
err = hard_disk_compress(argv[1], offset, argv[2], &header, NULL, progress); |
| 80 |
if (err != HDERR_NONE) |
| 81 |
{ |
| 82 |
printf("Error during compression: %d\n", err); |
| 83 |
return 1; |
| 84 |
} |
| 85 |
|
| 86 |
return 0; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
static void *hdcomp_open(const char *filename, const char *mode) |
| 91 |
{ |
| 92 |
return fopen(filename, mode); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
static void hdcomp_close(void *file) |
| 97 |
{ |
| 98 |
fclose(file); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
static UINT32 hdcomp_read(void *file, UINT64 offset, UINT32 count, void *buffer) |
| 103 |
{ |
| 104 |
fseek(file, offset, SEEK_SET); |
| 105 |
return fread(buffer, 1, count, file); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
static UINT32 hdcomp_write(void *file, UINT64 offset, UINT32 count, const void *buffer) |
| 110 |
{ |
| 111 |
fseek(file, offset, SEEK_SET); |
| 112 |
return fwrite(buffer, 1, count, file); |
| 113 |
} |
| 114 |
|