]> Shamusworld >> Repos - virtualjaguar/blob - src/include/harddisk.h
Mainly source cleanups
[virtualjaguar] / src / include / harddisk.h
1 #ifndef __HARDDISK_H__
2 #define __HARDDISK_H__
3
4 #include "types.h"
5
6 /***************************************************************************
7
8         MAME compressed hard disk header format. All numbers are stored in
9         Motorola (big-endian) byte ordering. The header is 76 bytes long.
10
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
23         [ 76] (header length)
24
25         Flags:
26                 0x00000001 - set if this drive has a parent
27                 0x00000002 - set if this drive allows writes
28
29 ***************************************************************************/
30
31 /*************************************
32  *
33  *      Constants
34  *
35  *************************************/
36
37 #define HARD_DISK_HEADER_SIZE           76
38 #define HARD_DISK_HEADER_VERSION        1
39
40 #define HARD_DISK_SECTOR_SIZE           512
41
42 #define HDFLAGS_HAS_PARENT                      0x00000001
43 #define HDFLAGS_IS_WRITEABLE            0x00000002
44
45 #define HDCOMPRESSION_NONE                      0
46 #define HDCOMPRESSION_ZLIB                      1
47 #define HDCOMPRESSION_MAX                       2
48
49 enum
50 {
51         HDERR_NONE,
52         HDERR_NO_INTERFACE,
53         HDERR_OUT_OF_MEMORY,
54         HDERR_INVALID_FILE,
55         HDERR_INVALID_PARAMETER,
56         HDERR_INVALID_DATA,
57         HDERR_FILE_NOT_FOUND,
58         HDERR_REQUIRES_PARENT,
59         HDERR_FILE_NOT_WRITEABLE,
60         HDERR_READ_ERROR,
61         HDERR_WRITE_ERROR,
62         HDERR_CODEC_ERROR,
63         HDERR_INVALID_PARENT,
64         HDERR_SECTOR_OUT_OF_RANGE,
65         HDERR_DECOMPRESSION_ERROR,
66         HDERR_COMPRESSION_ERROR,
67         HDERR_CANT_CREATE_FILE,
68         HDERR_CANT_VERIFY
69 };
70
71
72
73 /*************************************
74  *
75  *      Type definitions
76  *
77  *************************************/
78
79 struct hard_disk_header
80 {
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 */
92 };
93
94
95 struct hard_disk_interface
96 {
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);
101 };
102
103 void hard_disk_set_interface(struct hard_disk_interface *intf);
104
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);
109
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);
112
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);
116
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]);
119
120 #endif