From 03a6bdeb2512420882b49ca3108249b2cfd816ea Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Thu, 4 Oct 2007 20:52:37 +0000 Subject: [PATCH] move emile_map_* to libmap --- libemile/Makefile | 26 +--- libemile/emile_block0_write.c | 25 ---- libemile/emile_map_bootblock_get_type.c | 24 ---- libemile/emile_map_bootblock_is_valid.c | 14 --- libemile/emile_map_bootblock_read.c | 38 ------ libemile/emile_map_bootblock_write.c | 37 ------ libemile/emile_map_close.c | 18 --- libemile/emile_map_dev.c | 19 --- libemile/emile_map_geometry.c | 21 ---- libemile/emile_map_get_bootinfo.c | 29 ----- libemile/emile_map_get_driver_info.c | 26 ---- libemile/emile_map_get_driver_number.c | 18 --- libemile/emile_map_get_driver_signature.c | 20 --- libemile/emile_map_get_number.c | 18 --- libemile/emile_map_get_partition_geometry.c | 21 ---- libemile/emile_map_get_partition_name.c | 19 --- libemile/emile_map_get_partition_type.c | 19 --- libemile/emile_map_has_apple_driver.c | 45 ------- libemile/emile_map_is_valid.c | 15 --- libemile/emile_map_open.c | 57 --------- libemile/emile_map_partition_get_flags.c | 15 --- libemile/emile_map_partition_is_bootable.c | 15 --- libemile/emile_map_partition_is_startup.c | 15 --- libemile/emile_map_partition_is_valid.c | 15 --- libemile/emile_map_partition_set_bootable.c | 27 ---- libemile/emile_map_partition_set_flags.c | 17 --- libemile/emile_map_partition_set_startup.c | 24 ---- libemile/emile_map_read.c | 39 ------ libemile/emile_map_seek_driver_partition.c | 29 ----- libemile/emile_map_set_bootinfo.c | 30 ----- libemile/emile_map_set_driver_info.c | 26 ---- libemile/emile_map_set_driver_number.c | 23 ---- libemile/emile_map_set_partition_name.c | 24 ---- libemile/emile_map_set_partition_type.c | 24 ---- libemile/emile_map_set_startup.c | 60 --------- libemile/emile_map_write.c | 35 ------ libemile/emile_scsi_get_rdev.c | 3 +- libemile/libemile.h | 68 +---------- libemile/partition.h | 129 -------------------- 39 files changed, 11 insertions(+), 1116 deletions(-) delete mode 100644 libemile/emile_block0_write.c delete mode 100644 libemile/emile_map_bootblock_get_type.c delete mode 100644 libemile/emile_map_bootblock_is_valid.c delete mode 100644 libemile/emile_map_bootblock_read.c delete mode 100644 libemile/emile_map_bootblock_write.c delete mode 100644 libemile/emile_map_close.c delete mode 100644 libemile/emile_map_dev.c delete mode 100644 libemile/emile_map_geometry.c delete mode 100644 libemile/emile_map_get_bootinfo.c delete mode 100644 libemile/emile_map_get_driver_info.c delete mode 100644 libemile/emile_map_get_driver_number.c delete mode 100644 libemile/emile_map_get_driver_signature.c delete mode 100644 libemile/emile_map_get_number.c delete mode 100644 libemile/emile_map_get_partition_geometry.c delete mode 100644 libemile/emile_map_get_partition_name.c delete mode 100644 libemile/emile_map_get_partition_type.c delete mode 100644 libemile/emile_map_has_apple_driver.c delete mode 100644 libemile/emile_map_is_valid.c delete mode 100644 libemile/emile_map_open.c delete mode 100644 libemile/emile_map_partition_get_flags.c delete mode 100644 libemile/emile_map_partition_is_bootable.c delete mode 100644 libemile/emile_map_partition_is_startup.c delete mode 100644 libemile/emile_map_partition_is_valid.c delete mode 100644 libemile/emile_map_partition_set_bootable.c delete mode 100644 libemile/emile_map_partition_set_flags.c delete mode 100644 libemile/emile_map_partition_set_startup.c delete mode 100644 libemile/emile_map_read.c delete mode 100644 libemile/emile_map_seek_driver_partition.c delete mode 100644 libemile/emile_map_set_bootinfo.c delete mode 100644 libemile/emile_map_set_driver_info.c delete mode 100644 libemile/emile_map_set_driver_number.c delete mode 100644 libemile/emile_map_set_partition_name.c delete mode 100644 libemile/emile_map_set_partition_type.c delete mode 100644 libemile/emile_map_set_startup.c delete mode 100644 libemile/emile_map_write.c delete mode 100644 libemile/partition.h diff --git a/libemile/Makefile b/libemile/Makefile index 77dae4c..c4ccedb 100644 --- a/libemile/Makefile +++ b/libemile/Makefile @@ -10,35 +10,19 @@ LDFLAGS = $(CROSS_COMPILE_LDFLAGS) LIBRARY = libemile.a -SOURCES = emile_block0_write.c emile_checksum.c emile_first_get_param.c \ +SOURCES = emile_checksum.c emile_first_get_param.c \ emile_first_set_param.c emile_first_set_param_scsi.c \ - emile_floppy_create_image.c \ - emile_map_bootblock_get_type.c emile_map_bootblock_is_valid.c \ - emile_map_bootblock_read.c emile_map_bootblock_write.c \ - emile_map_close.c emile_map_dev.c emile_map_geometry.c \ - emile_map_get_bootinfo.c emile_map_get_driver_info.c \ - emile_map_get_driver_number.c emile_map_get_number.c \ - emile_map_get_partition_geometry.c emile_map_get_partition_name.c \ - emile_map_get_partition_type.c emile_map_has_apple_driver.c \ - emile_map_is_valid.c emile_map_open.c \ - emile_map_partition_get_flags.c emile_map_partition_is_bootable.c \ - emile_map_partition_is_startup.c emile_map_partition_is_valid.c \ - emile_map_partition_set_bootable.c emile_map_partition_set_flags.c \ - emile_map_partition_set_startup.c emile_map_read.c \ - emile_map_seek_driver_partition.c emile_map_set_bootinfo.c \ - emile_map_set_driver_info.c emile_map_set_driver_number.c \ - emile_map_set_partition_name.c emile_map_set_partition_type.c \ - emile_map_set_startup.c emile_map_write.c \ + emile_floppy_create_image.c emile_second_create_mapfile.c \ emile_scsi_create_container.c emile_scsi_get_dev.c \ emile_scsi_get_rdev.c emile_second_get_configuration.c \ - emile_second_set_configuration.c emile_second_create_mapfile.c \ + emile_second_set_configuration.c \ emile_second_set_param.c emile_second_get_param.c \ - emile_first_set_param_scsi_extents.c emile_map_get_driver_signature.c + emile_first_set_param_scsi_extents.c HEADERS = emile.h libemile.h partition.h bootblock.h CFLAGS = -Wall -Werror -g -CPPFLAGS = -I../libmacos -I../libcontainer -I../libstream -I../libconfig +CPPFLAGS = -I../libmacos -I../libcontainer -I../libstream -I../libconfig -I../libmap all: $(LIBRARY) diff --git a/libemile/emile_block0_write.c b/libemile/emile_block0_write.c deleted file mode 100644 index ecf3149..0000000 --- a/libemile/emile_block0_write.c +++ /dev/null @@ -1,25 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include -#include - -#include "partition.h" -#include "libemile.h" - -int emile_block0_write(emile_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)); - - return ret; -} diff --git a/libemile/emile_map_bootblock_get_type.c b/libemile/emile_map_bootblock_get_type.c deleted file mode 100644 index 83e88e6..0000000 --- a/libemile/emile_map_bootblock_get_type.c +++ /dev/null @@ -1,24 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "libemile.h" - -int emile_map_bootblock_get_type(char* bootblock) -{ - if (!emile_map_bootblock_is_valid(bootblock)) - return INVALID_BOOTBLOCK; - - if (strcmp(&bootblock[11], "System") == 0) - return APPLE_BOOTBLOCK; - - if (strcmp(&bootblock[11], "Mac Bootloader") == 0) - return EMILE_BOOTBLOCK; - - return UNKNOWN_BOOTBLOCK; -} diff --git a/libemile/emile_map_bootblock_is_valid.c b/libemile/emile_map_bootblock_is_valid.c deleted file mode 100644 index d590243..0000000 --- a/libemile/emile_map_bootblock_is_valid.c +++ /dev/null @@ -1,14 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" - -int emile_map_bootblock_is_valid(char *bootblock) -{ - return (bootblock[0] == 0x4C) && (bootblock[1] == 0x4B); -} diff --git a/libemile/emile_map_bootblock_read.c b/libemile/emile_map_bootblock_read.c deleted file mode 100644 index 809b893..0000000 --- a/libemile/emile_map_bootblock_read.c +++ /dev/null @@ -1,38 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004-2006 Laurent Vivier - * - */ - -#include -#include -#include -#include -#include - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_bootblock_read(emile_map_t* map, char* bootblock) -{ - off_t offset; - int ret; - int fd; - - if (!emile_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); - - return ret; -} diff --git a/libemile/emile_map_bootblock_write.c b/libemile/emile_map_bootblock_write.c deleted file mode 100644 index f994af3..0000000 --- a/libemile/emile_map_bootblock_write.c +++ /dev/null @@ -1,37 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include -#include -#include -#include -#include - -#include "partition.h" -#include "libemile.h" - -int emile_map_bootblock_write(emile_map_t* map, char* bootblock) -{ - char name[MAP_NAME_LEN]; - int ret; - int fd; - - if (!emile_map_partition_is_valid(map)) - return -1; - - sprintf(name, "%s%d", map->name, map->current + 1); - - fd = open(name, O_WRONLY); - if (fd == -1) - return -1; - - ret = write(fd, bootblock, BOOTBLOCK_SIZE); - - close(fd); - - return ret; -} diff --git a/libemile/emile_map_close.c b/libemile/emile_map_close.c deleted file mode 100644 index 18e3b86..0000000 --- a/libemile/emile_map_close.c +++ /dev/null @@ -1,18 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include -#include - -#include "partition.h" -#include "libemile.h" - -void emile_map_close(emile_map_t *map) -{ - close(map->fd); - free(map); -} diff --git a/libemile/emile_map_dev.c b/libemile/emile_map_dev.c deleted file mode 100644 index 7855010..0000000 --- a/libemile/emile_map_dev.c +++ /dev/null @@ -1,19 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "partition.h" -#include "libemile.h" - -char* emile_map_dev(emile_map_t *map) -{ - if (!emile_map_partition_is_valid(map)) - return NULL; - - return map->name; -} diff --git a/libemile/emile_map_geometry.c b/libemile/emile_map_geometry.c deleted file mode 100644 index 80954e0..0000000 --- a/libemile/emile_map_geometry.c +++ /dev/null @@ -1,21 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_geometry(emile_map_t *map, int *block_size, int *block_count) -{ - if (!emile_map_is_valid(map)) - return -1; - - *block_size = read_short((u_int16_t*)&map->drivers.BlkSize); - *block_count = read_long((u_int32_t*)&map->drivers.BlkCount); - - return 0; -} diff --git a/libemile/emile_map_get_bootinfo.c b/libemile/emile_map_get_bootinfo.c deleted file mode 100644 index 019ac66..0000000 --- a/libemile/emile_map_get_bootinfo.c +++ /dev/null @@ -1,29 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_get_bootinfo(emile_map_t *map, int* bootstart, int *bootsize, - int *bootaddr, int *bootentry, int* checksum, - char* processor) -{ - if (!emile_map_is_valid(map)) - return -1; - - *bootstart = read_long((u_int32_t*)&map->partition.LgBootStart); - *bootsize = read_long((u_int32_t*)&map->partition.BootSize); - *bootaddr = read_long((u_int32_t*)&map->partition.BootAddr); - *bootentry = read_long((u_int32_t*)&map->partition.BootEntry); - *checksum = read_long((u_int32_t*)&map->partition.BootCksum); - strcpy(processor, map->partition.Processor); - - return 0; -} diff --git a/libemile/emile_map_get_driver_info.c b/libemile/emile_map_get_driver_info.c deleted file mode 100644 index 4606f2f..0000000 --- a/libemile/emile_map_get_driver_info.c +++ /dev/null @@ -1,26 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_get_driver_info(emile_map_t *map, int number, - int *block, int *size, int* type) -{ - if (!emile_map_is_valid(map)) - return -1; - - if (number > emile_map_get_driver_number(map)) - return -1; - - *block = read_long((u_int32_t*)&map->drivers.DrvInfo[number].Block); - *size = read_short((u_int16_t*)&map->drivers.DrvInfo[number].Size); - *type = read_short((u_int16_t*)&map->drivers.DrvInfo[number].Type); - - return 0; -} diff --git a/libemile/emile_map_get_driver_number.c b/libemile/emile_map_get_driver_number.c deleted file mode 100644 index 7f96cce..0000000 --- a/libemile/emile_map_get_driver_number.c +++ /dev/null @@ -1,18 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_get_driver_number(emile_map_t *map) -{ - if (!emile_map_is_valid(map)) - return -1; - - return read_short((u_int16_t*)&map->drivers.DrvrCount); -} diff --git a/libemile/emile_map_get_driver_signature.c b/libemile/emile_map_get_driver_signature.c deleted file mode 100644 index f4fc47b..0000000 --- a/libemile/emile_map_get_driver_signature.c +++ /dev/null @@ -1,20 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -unsigned long emile_map_get_driver_signature(emile_map_t* map) -{ - if (!emile_map_partition_is_valid(map)) - return 0; - - return read_long((u_int32_t*)map->partition.Pad); -} diff --git a/libemile/emile_map_get_number.c b/libemile/emile_map_get_number.c deleted file mode 100644 index 98d267d..0000000 --- a/libemile/emile_map_get_number.c +++ /dev/null @@ -1,18 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include -#include - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_get_number(emile_map_t *map) -{ - return read_long((u_int32_t*)&map->partition.MapBlkCnt); -} diff --git a/libemile/emile_map_get_partition_geometry.c b/libemile/emile_map_get_partition_geometry.c deleted file mode 100644 index 272c833..0000000 --- a/libemile/emile_map_get_partition_geometry.c +++ /dev/null @@ -1,21 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_get_partition_geometry(emile_map_t *map, int *start, int *count) -{ - if (!emile_map_partition_is_valid(map)) - return -1; - - *start = read_long((u_int32_t*)&map->partition.PyPartStart); - *count = read_long((u_int32_t*)&map->partition.PartBlkCnt); - - return 0; -} diff --git a/libemile/emile_map_get_partition_name.c b/libemile/emile_map_get_partition_name.c deleted file mode 100644 index e60761f..0000000 --- a/libemile/emile_map_get_partition_name.c +++ /dev/null @@ -1,19 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "partition.h" -#include "libemile.h" - -char* emile_map_get_partition_name(emile_map_t *map) -{ - if (!emile_map_partition_is_valid(map)) - return NULL; - - return map->partition.PartName; -} diff --git a/libemile/emile_map_get_partition_type.c b/libemile/emile_map_get_partition_type.c deleted file mode 100644 index 17e9b46..0000000 --- a/libemile/emile_map_get_partition_type.c +++ /dev/null @@ -1,19 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "partition.h" -#include "libemile.h" - -char* emile_map_get_partition_type(emile_map_t *map) -{ - if (!emile_map_partition_is_valid(map)) - return NULL; - - return map->partition.PartType; -} diff --git a/libemile/emile_map_has_apple_driver.c b/libemile/emile_map_has_apple_driver.c deleted file mode 100644 index f07521a..0000000 --- a/libemile/emile_map_has_apple_driver.c +++ /dev/null @@ -1,45 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -/* - * See http://developer.apple.com/technotes/tn/tn1189.html - * - */ - -#include - -#include "partition.h" -#include "libemile.h" - -int emile_is_apple_driver(emile_map_t *map) -{ - return strncmp(map->partition.PartType, - APPLE_DRIVER, strlen(APPLE_DRIVER)) == 0; -} - -int emile_map_has_apple_driver(emile_map_t *map) -{ - int block, size, type, part; - int i; - int ret; - - for (i = 0; i < emile_map_get_driver_number(map); i++) - { - emile_map_get_driver_info(map, i, &block, &size, &type); - - part = emile_map_seek_driver_partition(map, block); - - ret = emile_map_read(map, part); - if (ret == -1) - return -1; - - if (emile_is_apple_driver(map)) - return 1; - } - - return 0; -} diff --git a/libemile/emile_map_is_valid.c b/libemile/emile_map_is_valid.c deleted file mode 100644 index d4ecc39..0000000 --- a/libemile/emile_map_is_valid.c +++ /dev/null @@ -1,15 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_is_valid(emile_map_t *map) -{ - return read_short((u_int16_t*)&map->drivers.Sig) == DD_SIGNATURE; -} diff --git a/libemile/emile_map_open.c b/libemile/emile_map_open.c deleted file mode 100644 index c1b0857..0000000 --- a/libemile/emile_map_open.c +++ /dev/null @@ -1,57 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include -#include -#include -#include -#include -#include - -#include "partition.h" -#include "libemile.h" - -emile_map_t* emile_map_open(char *dev, int flags) -{ - emile_map_t *map; - int ret; - - ASSERT_DD(printf("INTERNAL ERROR: Bad Block 0 size structure\n"); - return NULL;) - ASSERT_P(printf("INTERNAL ERROR: Bad Partition size structure\n"); - return NULL;) - - map = (emile_map_t*)malloc(sizeof(emile_map_t)); - 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; - - ret = read(map->fd, &map->drivers, sizeof(map->drivers)); - if (ret == -1) - { - free(map); - return NULL; - } - - ret = read(map->fd, &map->partition, sizeof(map->partition)); - if (ret == -1) - { - free(map); - return NULL; - } - map->current = 0; - - return map; -} diff --git a/libemile/emile_map_partition_get_flags.c b/libemile/emile_map_partition_get_flags.c deleted file mode 100644 index 35c75df..0000000 --- a/libemile/emile_map_partition_get_flags.c +++ /dev/null @@ -1,15 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_partition_get_flags(emile_map_t *map) -{ - return read_long((u_int32_t*)&map->partition.PartStatus); -} diff --git a/libemile/emile_map_partition_is_bootable.c b/libemile/emile_map_partition_is_bootable.c deleted file mode 100644 index fa40426..0000000 --- a/libemile/emile_map_partition_is_bootable.c +++ /dev/null @@ -1,15 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" - -int emile_map_partition_is_bootable(emile_map_t *map) -{ - return (emile_map_partition_get_flags(map) & - kPartitionAUXIsBootValid) == kPartitionAUXIsBootValid; -} diff --git a/libemile/emile_map_partition_is_startup.c b/libemile/emile_map_partition_is_startup.c deleted file mode 100644 index d903302..0000000 --- a/libemile/emile_map_partition_is_startup.c +++ /dev/null @@ -1,15 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" - -int emile_map_partition_is_startup(emile_map_t *map) -{ - return (emile_map_partition_get_flags(map) - & kPartitionIsStartup) == kPartitionIsStartup; -} diff --git a/libemile/emile_map_partition_is_valid.c b/libemile/emile_map_partition_is_valid.c deleted file mode 100644 index 02299fa..0000000 --- a/libemile/emile_map_partition_is_valid.c +++ /dev/null @@ -1,15 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_partition_is_valid(emile_map_t *map) -{ - return read_short((u_int16_t*)&map->partition.Sig) == MAP_SIGNATURE; -} diff --git a/libemile/emile_map_partition_set_bootable.c b/libemile/emile_map_partition_set_bootable.c deleted file mode 100644 index fa4555a..0000000 --- a/libemile/emile_map_partition_set_bootable.c +++ /dev/null @@ -1,27 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_partition_set_bootable(emile_map_t *map, int enable) -{ - if (!emile_map_partition_is_valid(map)) - return -1; - - if (enable) - emile_map_partition_set_flags(map, - kPartitionAUXIsValid | kPartitionAUXIsAllocated | - kPartitionAUXIsInUse | kPartitionAUXIsReadable | - kPartitionAUXIsWriteable | kPartitionIsMountedAtStartup | 0x80); - else - emile_map_partition_set_flags(map, - emile_map_partition_get_flags(map) & ~kPartitionIsMountedAtStartup); - - return 0; -} diff --git a/libemile/emile_map_partition_set_flags.c b/libemile/emile_map_partition_set_flags.c deleted file mode 100644 index f21834a..0000000 --- a/libemile/emile_map_partition_set_flags.c +++ /dev/null @@ -1,17 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_partition_set_flags(emile_map_t *map, int flags) -{ - write_long((u_int32_t*)&map->partition.PartStatus, flags); - - return 0; -} diff --git a/libemile/emile_map_partition_set_startup.c b/libemile/emile_map_partition_set_startup.c deleted file mode 100644 index 26b59be..0000000 --- a/libemile/emile_map_partition_set_startup.c +++ /dev/null @@ -1,24 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" - -int emile_map_partition_set_startup(emile_map_t *map, int enable) -{ - if (!emile_map_partition_is_valid(map)) - return -1; - - if (enable) - emile_map_partition_set_flags(map, - emile_map_partition_get_flags(map) | kPartitionIsStartup); - else - emile_map_partition_set_flags(map, - emile_map_partition_get_flags(map) & ~kPartitionIsStartup); - - return 0; -} diff --git a/libemile/emile_map_read.c b/libemile/emile_map_read.c deleted file mode 100644 index b955cd4..0000000 --- a/libemile/emile_map_read.c +++ /dev/null @@ -1,39 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include -#include - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_read(emile_map_t *map, int part) -{ - off_t offset; - int ret; - - if (map->current == part) - return part; - - if (part > read_long((u_int32_t*)&map->partition.MapBlkCnt)) - return -1; - - 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)) - return -1; - - map->current = part; - - return part; -} diff --git a/libemile/emile_map_seek_driver_partition.c b/libemile/emile_map_seek_driver_partition.c deleted file mode 100644 index da19a43..0000000 --- a/libemile/emile_map_seek_driver_partition.c +++ /dev/null @@ -1,29 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "libemile.h" - -int emile_map_seek_driver_partition(emile_map_t *map, int base) -{ - int start; - int count; - int i; - int ret; - - for (i = 0; i < emile_map_get_number(map); i++) - { - ret = emile_map_read(map, i); - if (ret == -1) - return -1; - - emile_map_get_partition_geometry(map, &start, &count); - if (base == start) - return i; - } - - return -1; -} diff --git a/libemile/emile_map_set_bootinfo.c b/libemile/emile_map_set_bootinfo.c deleted file mode 100644 index ca50d66..0000000 --- a/libemile/emile_map_set_bootinfo.c +++ /dev/null @@ -1,30 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_set_bootinfo(emile_map_t *map, int bootstart, int bootsize, - int bootaddr, int bootentry, int checksum, - char* processor) -{ - if (!emile_map_is_valid(map)) - return -1; - - write_long((u_int32_t*)&map->partition.LgBootStart, bootstart); - write_long((u_int32_t*)&map->partition.BootSize, bootsize); - write_long((u_int32_t*)&map->partition.BootAddr, bootaddr); - write_long((u_int32_t*)&map->partition.BootEntry, bootentry); - write_long((u_int32_t*)&map->partition.BootCksum, checksum); - memset(map->partition.Processor, 0, sizeof(map->partition.Processor)); - strcpy(map->partition.Processor, processor); - - return 0; -} diff --git a/libemile/emile_map_set_driver_info.c b/libemile/emile_map_set_driver_info.c deleted file mode 100644 index a8a0817..0000000 --- a/libemile/emile_map_set_driver_info.c +++ /dev/null @@ -1,26 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_set_driver_info(emile_map_t *map, int number, - int block, int size, int type) -{ - if (!emile_map_is_valid(map)) - return -1; - - if (number >= DD_MAX_DRIVER) - return -1; - - write_long((u_int32_t*)&map->drivers.DrvInfo[number].Block, block); - write_short((u_int16_t*)&map->drivers.DrvInfo[number].Size, size); - write_short((u_int16_t*)&map->drivers.DrvInfo[number].Type, type); - - return 0; -} diff --git a/libemile/emile_map_set_driver_number.c b/libemile/emile_map_set_driver_number.c deleted file mode 100644 index 8bef6c1..0000000 --- a/libemile/emile_map_set_driver_number.c +++ /dev/null @@ -1,23 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include "partition.h" -#include "libemile.h" -#include "emile.h" - -int emile_map_set_driver_number(emile_map_t *map, int number) -{ - if (!emile_map_is_valid(map)) - return -1; - - if (number >= DD_MAX_DRIVER) - return -1; - - write_short((u_int16_t*)&map->drivers.DrvrCount, number); - - return 0; -} diff --git a/libemile/emile_map_set_partition_name.c b/libemile/emile_map_set_partition_name.c deleted file mode 100644 index a562f3c..0000000 --- a/libemile/emile_map_set_partition_name.c +++ /dev/null @@ -1,24 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "partition.h" -#include "libemile.h" - -int emile_map_set_partition_name(emile_map_t *map, char* name) -{ - if (!emile_map_partition_is_valid(map)) - return -1; - - if (strlen(name) > 31) - return -1; - - strncpy(map->partition.PartName, name, 32); - - return 0; -} diff --git a/libemile/emile_map_set_partition_type.c b/libemile/emile_map_set_partition_type.c deleted file mode 100644 index f0bdcf5..0000000 --- a/libemile/emile_map_set_partition_type.c +++ /dev/null @@ -1,24 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#include "partition.h" -#include "libemile.h" - -int emile_map_set_partition_type(emile_map_t *map, char* type) -{ - if (!emile_map_partition_is_valid(map)) - return -1; - - if (strlen(type) > 31) - return -1; - - strncpy(map->partition.PartType, type, 32); - - return 0; -} diff --git a/libemile/emile_map_set_startup.c b/libemile/emile_map_set_startup.c deleted file mode 100644 index 9b5bbe3..0000000 --- a/libemile/emile_map_set_startup.c +++ /dev/null @@ -1,60 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include -#include -#include -#include -#include - -#include "partition.h" -#include "libemile.h" - -int emile_map_set_startup(char* dev_name, int partition) -{ - emile_map_t* map; - char *part_type; - int ret; - int i; - - map = emile_map_open(dev_name, O_RDWR); - if (map == NULL) - return -1; - - /* check partition type */ - - ret = emile_map_read(map, partition); - if (ret == -1) - return -1; - - part_type = emile_map_get_partition_type(map); - if (strcmp(part_type, APPLE_HFS) != 0) { - fprintf(stderr, - "ERROR: a startup partition must be of type Apple_HFS\n"); - return -1; - } - - for (i = 0; i < emile_map_get_number(map); i++) - { - ret = emile_map_read(map, i); - if (ret == -1) - return -1; - - part_type = emile_map_get_partition_type(map); - if (strcmp(part_type, APPLE_HFS) == 0) - { - emile_map_partition_set_bootable(map, i == partition); - emile_map_partition_set_startup(map, i == partition); - ret = emile_map_write(map, i); - if (ret == -1) - return -1; - } - } - emile_map_close(map); - - return 0; -} diff --git a/libemile/emile_map_write.c b/libemile/emile_map_write.c deleted file mode 100644 index e3ed68b..0000000 --- a/libemile/emile_map_write.c +++ /dev/null @@ -1,35 +0,0 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include -#include - -#include "partition.h" -#include "libemile.h" - -int emile_map_write(emile_map_t *map, int part) -{ - off_t offset; - int ret; - - if (part > map->partition.MapBlkCnt) - return -1; - - 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)) - return -1; - - map->current = part; - - return part; -} diff --git a/libemile/emile_scsi_get_rdev.c b/libemile/emile_scsi_get_rdev.c index 973b214..24df0d8 100644 --- a/libemile/emile_scsi_get_rdev.c +++ b/libemile/emile_scsi_get_rdev.c @@ -1,11 +1,10 @@ -static __attribute__((used)) char* rcsid = "$CVSHeader$"; /* * * (c) 2004 Laurent Vivier * */ -#include "partition.h" +#include "../libmap/libmap.h" #include "libemile.h" int emile_scsi_get_rdev(char* dev_name, int* driver, int *disk, int *partition) diff --git a/libemile/libemile.h b/libemile/libemile.h index eced52d..bc3bd69 100644 --- a/libemile/libemile.h +++ b/libemile/libemile.h @@ -14,20 +14,15 @@ #include -static __attribute__((used)) char* libemile_header = "$CVSHeader$"; - #define SCSI_SUPPORT #include "../second/head.h" +#include "libmap.h" #define EMILE_FIRST_TUNE_DRIVE 0x0001 #define EMILE_FIRST_TUNE_OFFSET 0x0002 #define EMILE_FIRST_TUNE_SIZE 0x0004 -#define FLOPPY_SECTOR_SIZE 512 -#define FIRST_LEVEL_SIZE (FLOPPY_SECTOR_SIZE * 2) -#define BOOTBLOCK_SIZE (FLOPPY_SECTOR_SIZE * 2) - #define MAJOR_IDE0 3 #define MAJOR_LOOP 7 #define MAJOR_SD 8 @@ -51,25 +46,14 @@ enum { EEMILE_CANNOT_READ_KERNEL = -16, }; -enum { - INVALID_BOOTBLOCK = -1, - APPLE_BOOTBLOCK = 0, - EMILE_BOOTBLOCK, - UNKNOWN_BOOTBLOCK, -}; - -#ifndef _PARTITION_H -typedef void emile_map_t; -#endif - static inline unsigned long emile_file_get_size(char* file) { - struct stat result; + struct stat result; - stat(file, &result); + stat(file, &result); - return (result.st_size + FLOPPY_SECTOR_SIZE - 1) - / FLOPPY_SECTOR_SIZE * FLOPPY_SECTOR_SIZE; + return (result.st_size + FLOPPY_SECTOR_SIZE - 1) + / FLOPPY_SECTOR_SIZE * FLOPPY_SECTOR_SIZE; } extern int emile_first_set_param(int fd, unsigned short tune_mask, @@ -92,49 +76,8 @@ extern int emile_floppy_create_image(char* first_level, char* second_level, char* image); extern int emile_scsi_create_container(int fd, unsigned short *unit_id, struct emile_container* container, int maxbloks); -extern emile_map_t* emile_map_open(char* dev, int flags); -extern void emile_map_close(emile_map_t *map); -extern int emile_map_get_number(emile_map_t *map); -extern int emile_map_read(emile_map_t *map, int part); -extern int emile_map_write(emile_map_t *map, int part); -extern int emile_map_partition_is_valid(emile_map_t *map); -extern int emile_map_get_partition_geometry(emile_map_t *map, int *start, int *count); -extern char* emile_map_get_partition_type(emile_map_t *map); -extern char* emile_map_get_partition_name(emile_map_t *map); -extern int emile_map_partition_is_bootable(emile_map_t *map); -extern int emile_map_partition_is_startup(emile_map_t *map); -extern int emile_map_set_partition_type(emile_map_t *map, char* type); -extern int emile_map_set_partition_name(emile_map_t *map, char* name); -extern int emile_map_partition_set_bootable(emile_map_t *map, int enable); -extern int emile_map_partition_set_startup(emile_map_t *map, int enable); -extern int emile_map_is_valid(emile_map_t *map); -extern int emile_map_partition_get_flags(emile_map_t *map); -extern int emile_map_partition_set_flags(emile_map_t *map, int flags); -extern int emile_map_geometry(emile_map_t *map, int *block_size, - int *block_count); -extern int emile_map_get_driver_number(emile_map_t *map); -extern int emile_map_get_driver_info(emile_map_t *map, int number, - int *block, int *size, int* type); -extern int emile_map_bootblock_read(emile_map_t* map, char* bootblock); -extern int emile_map_bootblock_write(emile_map_t* map, char* bootblock); -extern int emile_map_bootblock_get_type(char* bootblock); -extern int emile_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 emile_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 emile_is_apple_driver(emile_map_t *map); -extern int emile_map_has_apple_driver(emile_map_t *map); -extern int emile_map_seek_driver_partition(emile_map_t *map, int start); -extern int emile_get_uncompressed_size(char *file); extern unsigned short emile_checksum(unsigned char *addr, unsigned int length); extern unsigned short emile_checksum_ATA(unsigned char *addr, unsigned int length); -extern int emile_map_get_bootinfo(emile_map_t* map, int* bootstart, int *bootsize, int *bootaddr, int *bootentry, int* checksum, char* processor); -extern char* emile_map_dev(emile_map_t *map); -extern int emile_map_set_bootinfo(emile_map_t *map, int bootstart, int bootsize, int bootaddr, int bootentry, int checksum, char* processor); -extern int emile_map_set_driver_info(emile_map_t *map, int number, int block, int size, int type); -extern int emile_map_set_driver_number(emile_map_t *map, int number); -extern int emile_block0_write(emile_map_t *map); extern int8_t* emile_second_get_configuration(int fd); extern int emile_second_set_configuration(int fd, int8_t *configuration); extern int emile_second_get_next_property(int8_t *configuration, int index, char *name, char *property); @@ -143,5 +86,4 @@ extern void emile_second_set_property(int8_t *configuration, char *name, char *p extern void emile_second_remove_property(int8_t *configuration, char *name); extern int emile_second_set_param(int fd, char *kernel, char *parameters, char *initrd); extern int emile_second_get_param(int fd, char *kernel, char *parameters, char *initrd); -extern unsigned long emile_map_get_driver_signature(emile_map_t* map); #endif diff --git a/libemile/partition.h b/libemile/partition.h deleted file mode 100644 index aa7e44e..0000000 --- a/libemile/partition.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * - * (c) 2004 Laurent Vivier - * - */ - -#include - -#ifndef _PARTITION_H -#define _PARTITION_H -static __attribute__((used)) char* partition_header = "$CVSHeader$"; - -enum { - kPartitionAUXIsValid= 0x00000001, - kPartitionAUXIsAllocated = 0x00000002, - kPartitionAUXIsInUse= 0x00000004, - kPartitionAUXIsBootValid = 0x00000008, - kPartitionAUXIsReadable = 0x00000010, - kPartitionAUXIsWriteable = 0x00000020, - kPartitionAUXIsBootCodePositionIndependent = 0x00000040, - - kPartitionIsMountedAtStartup = 0x40000000, - kPartitionIsStartup = 0x80000000, - - kPartitionIsChainCompatible = 0x00000100, - kPartitionIsRealDeviceDriver = 0x00000200, - kPartitionCanChainToNext = 0x00000400, -}; - -/* Constants for the Type field */ - -enum { - kDriverTypeMacSCSI = 0x0001, - kDriverTypeMacATA = 0x0701, - kDriverTypeMacSCSIChained = 0xFFFF, - kDriverTypeMacATAChained = 0xF8FF -}; - -struct DriverInfo { - int32_t Block; - int16_t Size; - int16_t Type; -} __attribute__((packed)); - -#define DD_MAX_DRIVER 61 - -struct DriverDescriptor { - int16_t Sig; - int16_t BlkSize; - int32_t BlkCount; - int16_t DevType; - int16_t DevId; - int32_t Data; - int16_t DrvrCount; - struct DriverInfo DrvInfo[DD_MAX_DRIVER]; - int8_t Pad[6]; -} __attribute__((packed)); -#define ASSERT_DD(a) if ( sizeof(struct DriverDescriptor) != 512 ) { a } - -/* Driver signatures, stored in the first four byte of pmPad. */ - -enum { - kPatchDriverSignature = 0x70744452, /* 'ptDR', SCSI and ATA[PI] patch driver */ - kSCSIDriverSignature = 0x00010600, /* SCSI hard disk driver */ - kATADriverSignature = 0x77696b69, /*'wiki', ATA hard disk driver */ - kSCSICDDriverSignature = 0x43447672, /* 'CDvr', SCSI CD-ROM driver */ - kATAPIDriverSignature = 0x41545049, /* 'ATPI', ATAPI CD-ROM driver */ - kDriveSetupHFSSignature = 0x44535531, /* 'DSU1', Drive Setup HFS partition */ -}; - -enum { - kPatchMesh = 0x6d657368, /* 'mesh', fixes MESH bug */ - kPatchSCSI = 0x73637369, /* 'scsi' enable booting from CDROM */ - kPatchRuby = 0x72756279, /* 'ruby', volume larger than 2GB */ - kPatchSnag = 0x736e6167, /* 'snag', enable C key to boot CDROM */ -}; - -struct Partition { - int16_t Sig; - int16_t SigPad; - int32_t MapBlkCnt; - int32_t PyPartStart; - int32_t PartBlkCnt; - char PartName[32]; - char PartType[32]; - int32_t LgDataStart; - int32_t DataCnt; - int32_t PartStatus; - int32_t LgBootStart; - int32_t BootSize; - int32_t BootAddr; - int32_t BootAddr2; - int32_t BootEntry; - int32_t BootEntry2; - int32_t BootCksum; - char Processor[16]; - int16_t Pad[188]; -} __attribute__((packed)); - -#define ASSERT_P(a) if ( sizeof(struct Partition) != 512 ) { a } - -#define DD_SIGNATURE 0x4552 -#define MAP_SIGNATURE 0x504D - -#define APPLE_PARTITION_MAP "Apple_partition_map" -#define APPLE_DRIVER "Apple_Driver" -#define APPLE_DRIVER43 "Apple_Driver43" -#define APPLE_MFS "Apple_MFS" -#define APPLE_HFS "Apple_HFS" -#define APPLE_UNIX_SVR2 "Apple_Unix_SVR2" -#define APPLE_PRODOS "Apple_PRODOS" -#define APPLE_FREE "Apple_Free" -#define APPLE_SCRATCH "Apple_Scratch" -#define APPLE_DRIVER_ATA "Apple_Driver_ATA" -#define APPLE_DRIVER_ATAPI "Apple_Driver_ATAPI" -#define APPLE_DRIVER43_CD "Apple_Driver43_CD" -#define APPLE_FWDRIVER "Apple_FWDriver" -#define APPLE_VOID "Apple_Void" -#define APPLE_PATCHES "Apple_Patches" - -#define MAP_NAME_LEN 256 -typedef struct { - int fd; - char name[MAP_NAME_LEN]; - int current; - struct DriverDescriptor drivers; - struct Partition partition; -} emile_map_t; -#endif