mirror of
https://github.com/vivier/EMILE.git
synced 2024-12-22 10:29:31 +00:00
First revision
This commit is contained in:
parent
1f9af4ecef
commit
81033e78c7
13
libemile/emile_map_bootblock_is_valid.c
Normal file
13
libemile/emile_map_bootblock_is_valid.c
Normal 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);
|
||||
}
|
17
libemile/emile_map_close.c
Normal file
17
libemile/emile_map_close.c
Normal 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);
|
||||
}
|
19
libemile/emile_map_geometry.c
Normal file
19
libemile/emile_map_geometry.c
Normal 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;
|
||||
}
|
24
libemile/emile_map_get_driver_info.c
Normal file
24
libemile/emile_map_get_driver_info.c
Normal 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;
|
||||
}
|
16
libemile/emile_map_get_driver_number.c
Normal file
16
libemile/emile_map_get_driver_number.c
Normal 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;
|
||||
}
|
19
libemile/emile_map_get_partition_geometry.c
Normal file
19
libemile/emile_map_get_partition_geometry.c
Normal 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;
|
||||
}
|
18
libemile/emile_map_get_partition_name.c
Normal file
18
libemile/emile_map_get_partition_name.c
Normal 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;
|
||||
}
|
18
libemile/emile_map_get_partition_type.c
Normal file
18
libemile/emile_map_get_partition_type.c
Normal 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;
|
||||
}
|
13
libemile/emile_map_is_valid.c
Normal file
13
libemile/emile_map_is_valid.c
Normal 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
55
libemile/emile_map_open.c
Normal 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;
|
||||
}
|
13
libemile/emile_map_partition_is_bootable.c
Normal file
13
libemile/emile_map_partition_is_bootable.c
Normal 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;
|
||||
}
|
13
libemile/emile_map_partition_is_startup.c
Normal file
13
libemile/emile_map_partition_is_startup.c
Normal 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;
|
||||
}
|
13
libemile/emile_map_partition_is_valid.c
Normal file
13
libemile/emile_map_partition_is_valid.c
Normal 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;
|
||||
}
|
21
libemile/emile_map_partition_set_bootable.c
Normal file
21
libemile/emile_map_partition_set_bootable.c
Normal 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;
|
||||
}
|
21
libemile/emile_map_partition_set_startup.c
Normal file
21
libemile/emile_map_partition_set_startup.c
Normal 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
37
libemile/emile_map_read.c
Normal 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;
|
||||
}
|
36
libemile/emile_map_read_bootblock.c
Normal file
36
libemile/emile_map_read_bootblock.c
Normal 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;
|
||||
}
|
23
libemile/emile_map_set_partition_name.c
Normal file
23
libemile/emile_map_set_partition_name.c
Normal 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;
|
||||
}
|
23
libemile/emile_map_set_partition_type.c
Normal file
23
libemile/emile_map_set_partition_type.c
Normal 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;
|
||||
}
|
40
libemile/emile_map_write.c
Normal file
40
libemile/emile_map_write.c
Normal 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;
|
||||
}
|
36
libemile/emile_map_write_bootblock.c
Normal file
36
libemile/emile_map_write_bootblock.c
Normal 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;
|
||||
}
|
27
libemile/emile_second_get_buffer_size.c
Normal file
27
libemile/emile_second_get_buffer_size.c
Normal 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;
|
||||
}
|
41
libemile/emile_second_set_buffer_size.c
Normal file
41
libemile/emile_second_set_buffer_size.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user