6 /***************************************************************************
8 MAME compressed hard disk header format. All numbers are stored in
9 Motorola (big-endian) byte ordering. The header is 76 bytes long.
11 [ 0] char tag[8]; // 'MComprHD'
12 [ 8] UINT32 length; // length of header (including tag and length fields)
13 [ 12] UINT32 version; // drive format version
14 [ 16] UINT32 flags; // flags (see below)
15 [ 20] UINT32 compression; // compression type
16 [ 24] UINT32 blocksize; // sectors per block
17 [ 28] UINT32 totalblocks; // total # of block represented
18 [ 32] UINT32 cylinders; // number of cylinders on hard disk
19 [ 36] UINT32 heads; // number of heads on hard disk
20 [ 40] UINT32 sectors; // number of sectors on hard disk
21 [ 44] UINT8 md5[16]; // MD5 checksum for this drive
22 [ 60] UINT8 parentmd5[16]; // MD5 checksum for parent drive
26 0x00000001 - set if this drive has a parent
27 0x00000002 - set if this drive allows writes
29 ***************************************************************************/
31 /*************************************
35 *************************************/
37 #define HARD_DISK_HEADER_SIZE 76
38 #define HARD_DISK_HEADER_VERSION 1
40 #define HARD_DISK_SECTOR_SIZE 512
42 #define HDFLAGS_HAS_PARENT 0x00000001
43 #define HDFLAGS_IS_WRITEABLE 0x00000002
45 #define HDCOMPRESSION_NONE 0
46 #define HDCOMPRESSION_ZLIB 1
47 #define HDCOMPRESSION_MAX 2
55 HDERR_INVALID_PARAMETER,
58 HDERR_REQUIRES_PARENT,
59 HDERR_FILE_NOT_WRITEABLE,
64 HDERR_SECTOR_OUT_OF_RANGE,
65 HDERR_DECOMPRESSION_ERROR,
66 HDERR_COMPRESSION_ERROR,
67 HDERR_CANT_CREATE_FILE,
73 /*************************************
77 *************************************/
79 struct hard_disk_header
81 UINT32 length; /* length of header data */
82 UINT32 version; /* drive format version */
83 UINT32 flags; /* flags field */
84 UINT32 compression; /* compression type */
85 UINT32 blocksize; /* sectors per block */
86 UINT32 totalblocks; /* total # of blocks represented */
87 UINT32 cylinders; /* number of cylinders on hard disk */
88 UINT32 heads; /* number of heads on hard disk */
89 UINT32 sectors; /* number of sectors on hard disk */
90 UINT8 md5[16]; /* MD5 checksum for this drive */
91 UINT8 parentmd5[16]; /* MD5 checksum for parent drive */
95 struct hard_disk_interface
97 void *(*open)(const char *filename, const char *mode);
98 void (*close)(void *file);
99 uint32 (*read)(void *file, UINT64 offset, UINT32 count, void *buffer);
100 uint32 (*write)(void *file, UINT64 offset, UINT32 count, const void *buffer);
103 void hard_disk_set_interface(struct hard_disk_interface *intf);
105 int hard_disk_create(const char *filename, const struct hard_disk_header *header);
106 void *hard_disk_open(const char *filename, int writeable, void *parent);
107 void hard_disk_close(void *disk);
108 void hard_disk_close_all(void);
110 UINT32 hard_disk_read(void *disk, UINT32 lbasector, UINT32 numsectors, void *buffer);
111 UINT32 hard_disk_write(void *disk, UINT32 lbasector, UINT32 numsectors, const void *buffer);
113 int hard_disk_get_last_error(void);
114 const struct hard_disk_header *hard_disk_get_header(void *disk);
115 int hard_disk_set_header(const char *filename, const struct hard_disk_header *header);
117 int hard_disk_compress(const char *rawfile, UINT32 offset, const char *newfile, const struct hard_disk_header *header, const char *difffile, void (*progress)(const char *, ...));
118 int hard_disk_verify(const char *hdfile, void (*progress)(const char *, ...), UINT8 headermd5[16], UINT8 actualmd5[16]);