First revision

This commit is contained in:
Laurent Vivier 2004-12-14 23:49:59 +00:00
parent 1f9af4ecef
commit 81033e78c7
23 changed files with 556 additions and 0 deletions

View File

@ -0,0 +1,13 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_bootblock_is_valid(char *bootblock)
{
return (bootblock[0] == 0x4C) && (bootblock[1] == 0x4B);
}

View File

@ -0,0 +1,17 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#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

@ -0,0 +1,19 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.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 = map->drivers.BlkSize;
*block_count = map->drivers.BlkCount;
return 0;
}

View File

@ -0,0 +1,24 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.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 = map->drivers.DrvInfo[number].Block;
*size = map->drivers.DrvInfo[number].Size;
*type = map->drivers.DrvInfo[number].Type;
return 0;
}

View File

@ -0,0 +1,16 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_get_driver_number(emile_map_t *map)
{
if (!emile_map_is_valid(map))
return -1;
return map->drivers.DrvrCount;
}

View File

@ -0,0 +1,19 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.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 = map->partition.PyPartStart;
*count = map->partition.PartBlkCnt;
return 0;
}

View File

@ -0,0 +1,18 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_get_partition_name(emile_map_t *map, char** name)
{
if (!emile_map_partition_is_valid(map))
return -1;
*name = map->partition.PartName;
return 0;
}

View File

@ -0,0 +1,18 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_get_partition_type(emile_map_t *map, char** type)
{
if (!emile_map_partition_is_valid(map))
return -1;
*type = map->partition.PartType;
return 0;
}

View File

@ -0,0 +1,13 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_is_valid(emile_map_t *map)
{
return map->drivers.Sig == DD_SIGNATURE;
}

55
libemile/emile_map_open.c Normal file
View File

@ -0,0 +1,55 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#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, 16);
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 = 1;
return map;
}

View File

@ -0,0 +1,13 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_partition_is_bootable(emile_map_t *map)
{
return (map->partition.PartStatus & kPartitionAUXIsBootValid) == kPartitionAUXIsBootValid;
}

View File

@ -0,0 +1,13 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_partition_is_startup(emile_map_t *map)
{
return (map->partition.PartStatus & kPartitionIsStartup) == kPartitionIsStartup;
}

View File

@ -0,0 +1,13 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_partition_is_valid(emile_map_t *map)
{
return map->partition.Sig == MAP_SIGNATURE;
}

View File

@ -0,0 +1,21 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include "partition.h"
#include "libemile.h"
int emile_map_partition_set_bootable(emile_map_t *map, int enable)
{
if (!emile_map_partition_is_valid(map))
return -1;
if (enable)
map->partition.PartStatus |= kPartitionAUXIsBootValid;
else
map->partition.PartStatus &= ~kPartitionAUXIsBootValid;
return 0;
}

View File

@ -0,0 +1,21 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#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)
map->partition.PartStatus |= kPartitionIsStartup;
else
map->partition.PartStatus &= ~kPartitionIsStartup;
return 0;
}

37
libemile/emile_map_read.c Normal file
View File

@ -0,0 +1,37 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <sys/types.h>
#include <unistd.h>
#include "partition.h"
#include "libemile.h"
int emile_map_read(emile_map_t *map, int part)
{
off_t offset;
int ret;
if (map->current == part)
return part;
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 = read(map->fd, &map->partition, sizeof(struct Partition));
if (ret != sizeof(struct Partition))
return -1;
map->current = part;
return part;
}

View File

@ -0,0 +1,36 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#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_read_bootblock(emile_map_t* map, char* bootblock)
{
char name[16];
int ret;
int fd;
if (!emile_map_partition_is_valid(map))
return -1;
sprintf(name, "%s%d", map->name, map->current);
fd = open(name, O_RDONLY);
if (fd == -1)
return -1;
ret = read(fd, bootblock, BOOTBLOCK_SIZE);
close(fd);
return ret;
}

View File

@ -0,0 +1,23 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#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

@ -0,0 +1,23 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#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

@ -0,0 +1,40 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <sys/types.h>
#include <unistd.h>
#include "partition.h"
#include "libemile.h"
int emile_map_read(emile_map_t *map, int part)
{
off_t offset;
int ret;
if (map->current == 0)
return -1;
if (map->current == part)
return part;
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

@ -0,0 +1,36 @@
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#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_write_bootblock(emile_map_t* map, char* bootblock)
{
char name[16];
int ret;
int fd;
if (!emile_map_partition_is_valid(map))
return -1;
sprintf(name, "%s%d", map->name, map->current);
fd = open(name, O_RDWR);
if (fd == -1)
return -1;
ret = write(fd, bootblock, BOOTBLOCK_SIZE);
close(fd);
return ret;
}

View File

@ -0,0 +1,27 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include "libemile.h"
#include "emile.h"
int emile_second_get_buffer_size(int fd, u_int32_t *buffer_size)
{
emile_l2_header_t header;
int ret;
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return EEMILE_CANNOT_READ_SECOND;
*buffer_size = read_long(&header.kernel_size);
return 0;
}

View File

@ -0,0 +1,41 @@
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "libemile.h"
#include "emile.h"
#include "bootblock.h"
int emile_second_set_buffer_size(int fd, u_int32_t buffer_size)
{
emile_l2_header_t header;
int ret;
off_t location;
location = lseek(fd, 0, SEEK_CUR);
if (ret == -1)
return EEMILE_CANNOT_READ_SECOND;
ret = read(fd, &header, sizeof(header));
if (ret != sizeof(header))
return EEMILE_CANNOT_READ_SECOND;
write_long(&header.kernel_size, buffer_size);
ret = lseek(fd, location, SEEK_SET);
if (ret == -1)
return EEMILE_CANNOT_WRITE_SECOND;
ret = write(fd, &header, sizeof(header));
if (ret != sizeof(header))
return EEMILE_CANNOT_WRITE_SECOND;
return 0;
}