move emile_map_* to libmap

This commit is contained in:
Laurent Vivier 2007-10-04 20:52:37 +00:00
parent 37c6ac70c6
commit 03a6bdeb25
39 changed files with 11 additions and 1116 deletions

View File

@ -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)

View File

@ -1,25 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <sys/types.h>
#include <unistd.h>
#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;
}

View File

@ -1,24 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <string.h>
#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;
}

View File

@ -1,14 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_bootblock_is_valid(char *bootblock)
{
return (bootblock[0] == 0x4C) && (bootblock[1] == 0x4B);
}

View File

@ -1,38 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004-2006 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#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;
}

View File

@ -1,37 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#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;
}

View File

@ -1,18 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdlib.h>
#include <unistd.h>
#include "partition.h"
#include "libemile.h"
void emile_map_close(emile_map_t *map)
{
close(map->fd);
free(map);
}

View File

@ -1,19 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdio.h>
#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;
}

View File

@ -1,21 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,29 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <string.h>
#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;
}

View File

@ -1,26 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,18 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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);
}

View File

@ -1,20 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdio.h>
#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);
}

View File

@ -1,18 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdlib.h>
#include <unistd.h>
#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);
}

View File

@ -1,21 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,19 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdio.h>
#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;
}

View File

@ -1,19 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdio.h>
#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;
}

View File

@ -1,45 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
/*
* See http://developer.apple.com/technotes/tn/tn1189.html
*
*/
#include <string.h>
#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;
}

View File

@ -1,15 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,57 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#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;
}

View File

@ -1,15 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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);
}

View File

@ -1,15 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,15 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,15 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,27 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,17 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,24 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,39 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <sys/types.h>
#include <unistd.h>
#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;
}

View File

@ -1,29 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,30 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <string.h>
#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;
}

View File

@ -1,26 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,23 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#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;
}

View File

@ -1,24 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <string.h>
#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;
}

View File

@ -1,24 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <string.h>
#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;
}

View File

@ -1,60 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#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;
}

View File

@ -1,35 +0,0 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <sys/types.h>
#include <unistd.h>
#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;
}

View File

@ -1,11 +1,10 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include "partition.h"
#include "../libmap/libmap.h"
#include "libemile.h"
int emile_scsi_get_rdev(char* dev_name, int* driver, int *disk, int *partition)

View File

@ -14,20 +14,15 @@
#include <libcontainer.h>
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

View File

@ -1,129 +0,0 @@
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <sys/types.h>
#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