diskimage.h Source File

Back to the index.

diskimage.h
Go to the documentation of this file.
1 #ifndef DISKIMAGE_H
2 #define DISKIMAGE_H
3 
4 /*
5  * Copyright (C) 2003-2011 Anders Gavare. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *
31  * Generic disk image functions. (See diskimage.c for more info.)
32  */
33 
34 #include <stdio.h>
35 #include <sys/types.h>
36 
37 #include "misc.h"
38 
39 /* Diskimage types: */
40 #define DISKIMAGE_SCSI 1
41 #define DISKIMAGE_IDE 2
42 #define DISKIMAGE_FLOPPY 3
43 
44 #define DISKIMAGE_TYPES { "(NONE)", "SCSI", "IDE", "FLOPPY" }
45 
46 
47 /* 512 bytes per overlay block. Don't change this. */
48 #define OVERLAY_BLOCK_SIZE 512
49 
52  FILE *f_data;
53  FILE *f_bitmap;
54 };
55 
56 struct diskimage {
57  struct diskimage *next;
58  int type; /* DISKIMAGE_SCSI, etc */
59  int id; /* SCSI id */
60 
61  /* Filename in host's file system: */
62  char *fname;
63  FILE *f;
64 
65  /* Overlays: */
68 
70  int cylinders;
71  int heads;
73 
74  off_t total_size;
77 
78  int writable;
81 
82  int is_a_tape;
83  uint64_t tape_offset;
85  int filemark;
86 
87  int rpms;
88  int ncyls;
89 };
90 
91 
92 /* Transfer command, sent from a SCSI controller device to a disk: */
93 struct scsi_transfer {
95 
96  /* These should be set by the SCSI controller before the call: */
97  unsigned char *msg_out;
98  size_t msg_out_len;
99  unsigned char *cmd;
100  size_t cmd_len;
101 
102  /* data_out_len is set by the SCSI disk, if it needs data_out,
103  which is then filled in during a second pass in the controller. */
104  unsigned char *data_out;
105  size_t data_out_len;
107 
108  /* These should be set by the SCSI (disk) device before returning: */
109  unsigned char *data_in;
110  size_t data_in_len;
111  unsigned char *msg_in;
112  size_t msg_in_len;
113  unsigned char *status;
114  size_t status_len;
115 };
116 
117 
118 struct machine;
119 
120 
121 /* diskimage_scsicmd.c: */
122 struct scsi_transfer *scsi_transfer_alloc(void);
123 void scsi_transfer_free(struct scsi_transfer *);
124 void scsi_transfer_allocbuf(size_t *lenp, unsigned char **pp,
125  size_t want_len, int clearflag);
126 int diskimage_scsicommand(struct cpu *cpu, int id, int type,
127  struct scsi_transfer *);
128 
129 
130 /* diskimage.c: */
131 int64_t diskimage_getsize(struct machine *machine, int id, int type);
132 int64_t diskimage_get_baseoffset(struct machine *machine, int id, int type);
133 void diskimage_set_baseoffset(struct machine *machine, int id, int type, int64_t offset);
134 void diskimage_getchs(struct machine *machine, int id, int type,
135  int *c, int *h, int *s);
136 int diskimage__internal_access(struct diskimage *d, int writeflag,
137  off_t offset, unsigned char *buf, size_t len);
138 int diskimage_access(struct machine *machine, int id, int type, int writeflag,
139  off_t offset, unsigned char *buf, size_t len);
140 void diskimage_add_overlay(struct diskimage *d, char *overlay_basename);
141 void diskimage_recalc_size(struct diskimage *d);
142 int diskimage_exist(struct machine *machine, int id, int type);
143 int diskimage_bootdev(struct machine *machine, int *typep);
144 int diskimage_add(struct machine *machine, char *fname);
145 int diskimage_getname(struct machine *machine, int id, int type,
146  char *buf, size_t bufsize);
147 int diskimage_is_a_cdrom(struct machine *machine, int id, int type);
148 int diskimage_is_a_tape(struct machine *machine, int id, int type);
149 void diskimage_dump_info(struct machine *machine);
150 
151 
152 /*
153  * SCSI commands:
154  */
155 #define SCSICMD_TEST_UNIT_READY 0x00 /* Mandatory */
156 #define SCSICMD_REQUEST_SENSE 0x03 /* Mandatory */
157 #define SCSICMD_INQUIRY 0x12 /* Mandatory */
158 
159 #define SCSICMD_READ 0x08
160 #define SCSICMD_READ_10 0x28
161 #define SCSICMD_WRITE 0x0a
162 #define SCSICMD_WRITE_10 0x2a
163 #define SCSICMD_MODE_SELECT 0x15
164 #define SCSICMD_MODE_SENSE 0x1a
165 #define SCSICMD_START_STOP_UNIT 0x1b
166 #define SCSICMD_PREVENT_ALLOW_REMOVE 0x1e
167 #define SCSICMD_MODE_SENSE10 0x5a
168 
169 #define SCSICMD_SYNCHRONIZE_CACHE 0x35
170 
171 /* SCSI block device commands: */
172 #define SCSIBLOCKCMD_READ_CAPACITY 0x25
173 
174 /* SCSI CD-ROM commands: */
175 #define SCSICDROM_READ_SUBCHANNEL 0x42
176 #define SCSICDROM_READ_TOC 0x43
177 #define SCSICDROM_READ_DISCINFO 0x51
178 #define SCSICDROM_READ_TRACKINFO 0x52
179 
180 /* SCSI tape commands: */
181 #define SCSICMD_REWIND 0x01
182 #define SCSICMD_READ_BLOCK_LIMITS 0x05
183 #define SCSICMD_SPACE 0x11
184 
185 
186 #endif /* DISKIMAGE_H */
int diskimage__internal_access(struct diskimage *d, int writeflag, off_t offset, unsigned char *buf, size_t len)
Definition: diskimage.cc:547
int is_a_cdrom
Definition: diskimage.h:79
size_t data_out_len
Definition: diskimage.h:105
size_t cmd_len
Definition: diskimage.h:100
size_t msg_out_len
Definition: diskimage.h:98
int diskimage_scsicommand(struct cpu *cpu, int id, int type, struct scsi_transfer *)
int rpms
Definition: diskimage.h:87
void diskimage_recalc_size(struct diskimage *d)
Definition: diskimage.cc:165
int filemark
Definition: diskimage.h:85
void diskimage_dump_info(struct machine *machine)
Definition: diskimage.cc:1081
int logical_block_size
Definition: diskimage.h:76
size_t data_in_len
Definition: diskimage.h:110
int diskimage_bootdev(struct machine *machine, int *typep)
Definition: diskimage.cc:983
char * overlay_basename
Definition: diskimage.h:51
int is_a_tape
Definition: diskimage.h:82
int chs_override
Definition: diskimage.h:69
unsigned char * data_out
Definition: diskimage.h:104
size_t status_len
Definition: diskimage.h:114
size_t data_out_offset
Definition: diskimage.h:106
int diskimage_exist(struct machine *machine, int id, int type)
Definition: diskimage.cc:106
int heads
Definition: diskimage.h:71
int64_t diskimage_get_baseoffset(struct machine *machine, int id, int type)
Definition: diskimage.cc:222
struct scsi_transfer * scsi_transfer_alloc(void)
unsigned char * status
Definition: diskimage.h:113
int diskimage_access(struct machine *machine, int id, int type, int writeflag, off_t offset, unsigned char *buf, size_t len)
Definition: diskimage.cc:605
int id
Definition: diskimage.h:59
struct scsi_transfer * next_free
Definition: diskimage.h:94
unsigned char * data_in
Definition: diskimage.h:109
int64_t override_base_offset
Definition: diskimage.h:75
void diskimage_set_baseoffset(struct machine *machine, int id, int type, int64_t offset)
Definition: diskimage.cc:242
int writable
Definition: diskimage.h:78
struct diskimage * next
Definition: diskimage.h:57
unsigned char * msg_out
Definition: diskimage.h:97
int nr_of_overlays
Definition: diskimage.h:66
off_t total_size
Definition: diskimage.h:74
FILE * f
Definition: diskimage.h:63
size_t msg_in_len
Definition: diskimage.h:112
int type
Definition: diskimage.h:58
uint64_t tape_offset
Definition: diskimage.h:83
void diskimage_add_overlay(struct diskimage *d, char *overlay_basename)
Definition: diskimage.cc:125
int diskimage_add(struct machine *machine, char *fname)
Definition: diskimage.cc:659
Definition: cpu.h:326
int cylinders
Definition: diskimage.h:70
struct diskimage_overlay * overlays
Definition: diskimage.h:67
int diskimage_is_a_cdrom(struct machine *machine, int id, int type)
Definition: diskimage.cc:1042
void scsi_transfer_free(struct scsi_transfer *)
int tape_filenr
Definition: diskimage.h:84
unsigned char * msg_in
Definition: diskimage.h:111
void diskimage_getchs(struct machine *machine, int id, int type, int *c, int *h, int *s)
Definition: diskimage.cc:266
void scsi_transfer_allocbuf(size_t *lenp, unsigned char **pp, size_t want_len, int clearflag)
int diskimage_getname(struct machine *machine, int id, int type, char *buf, size_t bufsize)
Definition: diskimage.cc:1013
int64_t diskimage_getsize(struct machine *machine, int id, int type)
Definition: diskimage.cc:203
char * fname
Definition: diskimage.h:62
unsigned char * cmd
Definition: diskimage.h:99
int diskimage_is_a_tape(struct machine *machine, int id, int type)
Definition: diskimage.cc:1063
int is_boot_device
Definition: diskimage.h:80
int sectors_per_track
Definition: diskimage.h:72
int ncyls
Definition: diskimage.h:88

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13