#include <unistd.h>
#include <endian.h>
#include "hunk-reloc.h"
+#include "piscsi/piscsi-enums.h"
+#include "piscsi/piscsi.h"
#ifdef FAKESTORM
#define lseek64 lseek
int32_t lsb_ChkSum;
uint32_t lsb_HostID;
uint32_t lsb_Next;
- uint32_t lsb_LoadData[123]; // Assumes 512 byte blocks
+ uint32_t lsb_LoadData[PISCSI_MAX_BLOCK_SIZE / 4];
};
#define LOADSEG_IDENTIFIER 0x4C534547
-int load_lseg(int fd, uint8_t **buf_p, struct hunk_info *i, struct hunk_reloc *relocs) {
+int load_lseg(int fd, uint8_t **buf_p, struct hunk_info *i, struct hunk_reloc *relocs, uint32_t block_size) {
if (fd == -1)
return -1;
+
+ if (block_size == 0)
+ block_size = 512;
- uint8_t *block = malloc(512);
+ uint8_t *block = malloc(block_size);
uint32_t next_blk = 0;
struct LoadSegBlock *lsb = (struct LoadSegBlock *)block;
- read(fd, block, 512);
+ read(fd, block, block_size);
if (BE(lsb->lsb_ID) != LOADSEG_IDENTIFIER) {
DEBUG("[LOAD_LSEG] Attempted to load a non LSEG-block: %.8X", BE(lsb->lsb_ID));
goto fail;
next_blk = BE(lsb->lsb_Next);
do {
next_blk = BE(lsb->lsb_Next);
- fwrite(lsb->lsb_LoadData, 4, 123, out);
- lseek64(fd, next_blk * 512, SEEK_SET);
- read(fd, block, 512);
+ fwrite(lsb->lsb_LoadData, 1, block_size - 20, out);
+ lseek64(fd, next_blk * block_size, SEEK_SET);
+ read(fd, block, block_size);
} while (next_blk != 0xFFFFFFFF);
uint32_t file_size = ftell(out);
return -1;
}
+
+int load_fs(struct piscsi_fs *fs, char *dosID) {
+ char filename[256];
+ memset(filename, 0x00, 256);
+ sprintf(filename, "./data/fs/%c%c%c.%d", dosID[0], dosID[1], dosID[2], dosID[3]);
+
+ FILE *in = fopen(filename, "rb");
+ if (in == NULL)
+ return -1;
+
+ fseek(in, 0, SEEK_END);
+ uint32_t file_size = ftell(in);
+ fseek(in, 0, SEEK_SET);
+
+ fs->binary_data = malloc(file_size);
+ fread(fs->binary_data, file_size, 1, in);
+ process_hunks(in, &fs->h_info, fs->relocs, 0x0);
+ fs->h_info.byte_size = file_size;
+ fs->h_info.alloc_size = file_size + add_size;
+
+ fclose(in);
+
+ return 0;
+}