25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: bootblock_iso9660.c,v 1.2 2007/03/16 15:17:55 debug Exp $ |
* $Id: bootblock_iso9660.c,v 1.3 2007/06/15 17:02:39 debug Exp $ |
29 |
* |
* |
30 |
* ISO9660 CD-ROM "bootblock" handling. |
* ISO9660 CD-ROM "bootblock" handling. |
31 |
* |
* |
97 |
int disk_id, int disk_type, int iso_type, unsigned char *buf, |
int disk_id, int disk_type, int iso_type, unsigned char *buf, |
98 |
int *n_loadp, char ***load_namesp) |
int *n_loadp, char ***load_namesp) |
99 |
{ |
{ |
100 |
int filenr, dirlen, res = 0, res2, iadd = DEBUG_INDENTATION; |
int filenr, dirlen, res = 0, res2, iadd = DEBUG_INDENTATION, found_dir; |
101 |
int found_dir; |
uint64_t dirofs, fileofs, filelen; |
102 |
uint64_t dirofs; |
unsigned char *dirbuf = NULL, *dp, *match_entry = NULL, *filebuf = NULL; |
103 |
uint64_t fileofs, filelen; |
char *p, *filename_orig, *filename, *tmpfname = NULL; |
|
unsigned char *dirbuf = NULL, *dp; |
|
|
unsigned char *match_entry = NULL; |
|
|
char *p, *filename_orig; |
|
|
char *filename = strdup(cpu->machine->boot_kernel_filename); |
|
|
unsigned char *filebuf = NULL; |
|
|
char *tmpfname = NULL; |
|
104 |
char **new_array; |
char **new_array; |
105 |
int tmpfile_handle; |
int tmpfile_handle; |
106 |
|
|
107 |
if (filename == NULL) { |
CHECK_ALLOCATION(filename = strdup(cpu->machine->boot_kernel_filename)); |
|
fatal("out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
108 |
filename_orig = filename; |
filename_orig = filename; |
109 |
|
|
110 |
debug("ISO9660 boot:\n"); |
debug("ISO9660 boot:\n"); |
128 |
debug("root = %i bytes at 0x%llx\n", dirlen, (long long)dirofs); |
debug("root = %i bytes at 0x%llx\n", dirlen, (long long)dirofs); |
129 |
#endif |
#endif |
130 |
|
|
131 |
dirbuf = malloc(dirlen); |
CHECK_ALLOCATION(dirbuf = malloc(dirlen)); |
|
if (dirbuf == NULL) { |
|
|
fatal("out of memory in iso_load_bootblock()\n"); |
|
|
exit(1); |
|
|
} |
|
|
|
|
132 |
res2 = diskimage_access(m, disk_id, disk_type, 0, dirofs, dirbuf, |
res2 = diskimage_access(m, disk_id, disk_type, 0, dirofs, dirbuf, |
133 |
dirlen); |
dirlen); |
134 |
if (!res2) { |
if (!res2) { |
213 |
|
|
214 |
/* Free the old dirbuf, and allocate a new one: */ |
/* Free the old dirbuf, and allocate a new one: */ |
215 |
free(dirbuf); |
free(dirbuf); |
216 |
dirbuf = malloc(512); |
CHECK_ALLOCATION(dirbuf = malloc(512)); |
|
if (dirbuf == NULL) { |
|
|
fatal("out of memory in iso_load_bootblock()\n"); |
|
|
exit(1); |
|
|
} |
|
217 |
|
|
218 |
for (;;) { |
for (;;) { |
219 |
size_t len, i; |
size_t len, i; |
266 |
"now... (BUG)\n"); |
"now... (BUG)\n"); |
267 |
exit(1); |
exit(1); |
268 |
} |
} |
269 |
match_entry = malloc(512); |
CHECK_ALLOCATION(match_entry = |
270 |
if (match_entry == NULL) { |
malloc(512)); |
|
fatal("out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
271 |
memcpy(match_entry, dp, 512); |
memcpy(match_entry, dp, 512); |
272 |
break; |
break; |
273 |
} |
} |
301 |
/* debug("filelen=%llx fileofs=%llx\n", (long long)filelen, |
/* debug("filelen=%llx fileofs=%llx\n", (long long)filelen, |
302 |
(long long)fileofs); */ |
(long long)fileofs); */ |
303 |
|
|
304 |
filebuf = malloc(filelen); |
CHECK_ALLOCATION(filebuf = malloc(filelen)); |
|
if (filebuf == NULL) { |
|
|
fatal("could not allocate %lli bytes to read the file" |
|
|
" from the disk image!\n", (long long)filelen); |
|
|
goto ret; |
|
|
} |
|
|
|
|
305 |
tmpfname = strdup("/tmp/gxemul.XXXXXXXXXXXX"); |
tmpfname = strdup("/tmp/gxemul.XXXXXXXXXXXX"); |
306 |
|
|
307 |
res2 = diskimage_access(m, disk_id, disk_type, 0, fileofs, filebuf, |
res2 = diskimage_access(m, disk_id, disk_type, 0, fileofs, filebuf, |
323 |
|
|
324 |
/* Add the temporary filename to the load_namesp array: */ |
/* Add the temporary filename to the load_namesp array: */ |
325 |
(*n_loadp)++; |
(*n_loadp)++; |
326 |
new_array = malloc(sizeof(char *) * (*n_loadp)); |
CHECK_ALLOCATION(new_array = malloc(sizeof(char *) * (*n_loadp))); |
|
if (new_array == NULL) { |
|
|
fatal("out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
327 |
memcpy(new_array, *load_namesp, sizeof(char *) * (*n_loadp)); |
memcpy(new_array, *load_namesp, sizeof(char *) * (*n_loadp)); |
328 |
*load_namesp = new_array; |
*load_namesp = new_array; |
329 |
|
|
330 |
/* This adds a Backspace char in front of the filename; this |
/* This adds a Backspace char in front of the filename; this |
331 |
is a special hack which causes the file to be removed once |
is a special hack which causes the file to be removed once |
332 |
it has been loaded. */ |
it has been loaded. */ |
333 |
tmpfname = realloc(tmpfname, strlen(tmpfname) + 2); |
CHECK_ALLOCATION(tmpfname = realloc(tmpfname, strlen(tmpfname) + 2)); |
334 |
memmove(tmpfname + 1, tmpfname, strlen(tmpfname) + 1); |
memmove(tmpfname + 1, tmpfname, strlen(tmpfname) + 1); |
335 |
tmpfname[0] = 8; |
tmpfname[0] = 8; |
336 |
|
|