mirror of
https://github.com/vivier/EMILE.git
synced 2025-01-22 00:32:15 +00:00
move from stdio to device_io_t
This commit is contained in:
parent
ce59576cf7
commit
0139be9609
@ -13,11 +13,12 @@ ifeq ($(TARGET), m68k-linux)
|
||||
68000FLAGS = -m68000 -Wa,-m68000
|
||||
CFLAGS += -fpic -O2 -Os
|
||||
endif
|
||||
CPPFLAGS += -I$(TOP)/../libstream -I$(TOP)/../libemile
|
||||
|
||||
LIBRARY = libmap.a
|
||||
|
||||
SOURCES = map_bootblock_get_type.c map_bootblock_is_valid.c \
|
||||
map_bootblock_read.c map_bootblock_write.c map_close.c map_dev.c \
|
||||
map_bootblock_read.c map_bootblock_write.c map_close.c \
|
||||
map_geometry.c map_get_bootinfo.c map_get_driver_info.c \
|
||||
map_get_driver_number.c map_get_driver_signature.c map_get_number.c \
|
||||
map_get_partition_geometry.c map_get_partition_name.c \
|
||||
|
@ -8,7 +8,9 @@
|
||||
#define _LIBMAP_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "../libemile/emile.h"
|
||||
|
||||
#include "libstream.h"
|
||||
#include "emile.h"
|
||||
|
||||
enum {
|
||||
kPartitionAUXIsValid= 0x00000001,
|
||||
@ -120,8 +122,7 @@ struct Partition {
|
||||
|
||||
#define MAP_NAME_LEN 256
|
||||
typedef struct {
|
||||
int fd;
|
||||
char name[MAP_NAME_LEN];
|
||||
device_io_t *device;
|
||||
int current;
|
||||
struct DriverDescriptor drivers;
|
||||
struct Partition partition;
|
||||
@ -138,7 +139,7 @@ enum {
|
||||
#define FIRST_LEVEL_SIZE (FLOPPY_SECTOR_SIZE * 2)
|
||||
#define BOOTBLOCK_SIZE (FLOPPY_SECTOR_SIZE * 2)
|
||||
|
||||
extern map_t* map_open(char* dev, int flags);
|
||||
extern map_t* map_open(device_io_t *device);
|
||||
extern void map_close(map_t *map);
|
||||
extern int map_get_number(map_t *map);
|
||||
extern int map_read(map_t *map, int part);
|
||||
@ -165,16 +166,11 @@ extern int map_bootblock_read(map_t* map, char* bootblock);
|
||||
extern int map_bootblock_write(map_t* map, char* bootblock);
|
||||
extern int map_bootblock_get_type(char* bootblock);
|
||||
extern int map_bootblock_is_valid(char *bootblock);
|
||||
extern int emile_scsi_get_dev(int fd, int* driver, int *disk, int *partition);
|
||||
extern int emile_get_dev_name(char *s, int driver, int disk, int partition);
|
||||
extern int map_set_startup(char* dev_name, int partition);
|
||||
extern int emile_scsi_get_rdev(char* dev_name, int* driver, int *disk, int *partition);
|
||||
extern int map_set_startup(map_t *map, int partition);
|
||||
extern int emile_is_apple_driver(map_t *map);
|
||||
extern int map_has_apple_driver(map_t *map);
|
||||
extern int map_seek_driver_partition(map_t *map, int start);
|
||||
extern int emile_get_uncompressed_size(char *file);
|
||||
extern int map_get_bootinfo(map_t* map, int* bootstart, int *bootsize, int *bootaddr, int *bootentry, int* checksum, char* processor);
|
||||
extern char* map_dev(map_t *map);
|
||||
extern int map_set_bootinfo(map_t *map, int bootstart, int bootsize, int bootaddr, int bootentry, int checksum, char* processor);
|
||||
extern int map_set_driver_info(map_t *map, int number, int block, int size, int type);
|
||||
extern int map_set_driver_number(map_t *map, int number);
|
||||
|
@ -13,11 +13,8 @@ int map_block0_write(map_t *map)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = lseek(map->fd, 0, SEEK_SET);
|
||||
if (ret != 0)
|
||||
return -1;
|
||||
|
||||
ret = write(map->fd, &map->drivers, sizeof(map->drivers));
|
||||
ret = map->device->write_sector(map->device, 0,
|
||||
&map->drivers, sizeof(map->drivers));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -16,20 +16,14 @@ int map_bootblock_read(map_t* map, char* bootblock)
|
||||
{
|
||||
off_t offset;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
if (!map_partition_is_valid(map))
|
||||
return -1;
|
||||
|
||||
fd = open(map->name, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
offset = read_long((u_int32_t*)&map->partition.PyPartStart) * 512;
|
||||
lseek(fd, offset, SEEK_SET);
|
||||
|
||||
ret = read(fd, bootblock, BOOTBLOCK_SIZE);
|
||||
|
||||
close(fd);
|
||||
ret = map->device->read_sector(map->device,
|
||||
offset, bootblock, BOOTBLOCK_SIZE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -14,22 +14,16 @@
|
||||
|
||||
int map_bootblock_write(map_t* map, char* bootblock)
|
||||
{
|
||||
char name[MAP_NAME_LEN];
|
||||
off_t offset;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
if (!map_partition_is_valid(map))
|
||||
return -1;
|
||||
|
||||
sprintf(name, "%s%d", map->name, map->current + 1);
|
||||
offset = read_long((u_int32_t*)&map->partition.PyPartStart) * 512;
|
||||
|
||||
fd = open(name, O_WRONLY);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
ret = write(fd, bootblock, BOOTBLOCK_SIZE);
|
||||
|
||||
close(fd);
|
||||
ret = map->device->write_sector(map->device,
|
||||
offset, bootblock, BOOTBLOCK_SIZE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -11,6 +11,5 @@
|
||||
|
||||
void map_close(map_t *map)
|
||||
{
|
||||
close(map->fd);
|
||||
free(map);
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libmap.h"
|
||||
|
||||
char* map_dev(map_t *map)
|
||||
{
|
||||
if (!map_partition_is_valid(map))
|
||||
return NULL;
|
||||
|
||||
return map->name;
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include "libmap.h"
|
||||
|
||||
map_t* map_open(char *dev, int flags)
|
||||
map_t* map_open(device_io_t *device)
|
||||
{
|
||||
map_t *map;
|
||||
int ret;
|
||||
@ -27,23 +27,18 @@ map_t* map_open(char *dev, int flags)
|
||||
if (map == NULL)
|
||||
return NULL;
|
||||
|
||||
map->fd = open(dev, flags);
|
||||
if (map->fd == -1)
|
||||
{
|
||||
free(map);
|
||||
return NULL;
|
||||
}
|
||||
strncpy(map->name, dev, MAP_NAME_LEN);
|
||||
map->name[MAP_NAME_LEN - 1] = 0;
|
||||
map->device = device;
|
||||
|
||||
ret = read(map->fd, &map->drivers, sizeof(map->drivers));
|
||||
ret = device->read_sector(map->device, 0,
|
||||
&map->drivers, sizeof(map->drivers));
|
||||
if (ret == -1)
|
||||
{
|
||||
free(map);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = read(map->fd, &map->partition, sizeof(map->partition));
|
||||
ret = device->read_sector(map->device, sizeof(map->drivers),
|
||||
&map->partition, sizeof(map->partition));
|
||||
if (ret == -1)
|
||||
{
|
||||
free(map);
|
||||
|
@ -22,12 +22,9 @@ int map_read(map_t *map, int part)
|
||||
|
||||
offset = part * sizeof(struct Partition) + sizeof(struct DriverDescriptor);
|
||||
|
||||
ret = lseek(map->fd, offset, SEEK_SET);
|
||||
if (ret != offset)
|
||||
return -1;
|
||||
|
||||
ret = read(map->fd, &map->partition, sizeof(struct Partition));
|
||||
if (ret != sizeof(struct Partition))
|
||||
ret = map->device->read_sector(map->device, offset, &map->partition,
|
||||
sizeof(struct Partition));
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
|
||||
map->current = part;
|
||||
|
@ -12,17 +12,12 @@
|
||||
|
||||
#include "libmap.h"
|
||||
|
||||
int map_set_startup(char* dev_name, int partition)
|
||||
int map_set_startup(map_t *map, int partition)
|
||||
{
|
||||
map_t* map;
|
||||
char *part_type;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
map = map_open(dev_name, O_RDWR);
|
||||
if (map == NULL)
|
||||
return -1;
|
||||
|
||||
/* check partition type */
|
||||
|
||||
ret = map_read(map, partition);
|
||||
@ -52,7 +47,6 @@ int map_set_startup(char* dev_name, int partition)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
map_close(map);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -17,14 +17,12 @@ int map_write(map_t *map, int part)
|
||||
if (part > map->partition.MapBlkCnt)
|
||||
return -1;
|
||||
|
||||
offset = part * sizeof(struct Partition) + sizeof(struct DriverDescriptor);
|
||||
offset = part * sizeof(struct Partition) +
|
||||
sizeof(struct DriverDescriptor);
|
||||
|
||||
ret = lseek(map->fd, offset, SEEK_SET);
|
||||
if (ret != offset)
|
||||
return -1;
|
||||
|
||||
ret = write(map->fd, &map->partition, sizeof(struct Partition));
|
||||
if (ret != sizeof(struct Partition))
|
||||
ret = map->device->write_sector(map->device, offset, &map->partition,
|
||||
sizeof(struct Partition));
|
||||
if (ret != -1)
|
||||
return -1;
|
||||
|
||||
map->current = part;
|
||||
|
Loading…
x
Reference in New Issue
Block a user