EMILE/libemile/emile_map_set_startup.c

61 lines
1.2 KiB
C
Raw Normal View History

2004-12-21 16:11:51 +00:00
static __attribute__((used)) char* rcsid = "$CVSHeader$";
/*
*
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
2004-12-21 16:11:51 +00:00
*
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
2004-12-21 16:11:51 +00:00
#include "partition.h"
#include "libemile.h"
int emile_map_set_startup(char* dev_name, int partition)
{
emile_map_t* map;
char *part_type;
2004-12-21 16:11:51 +00:00
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;
}
2004-12-21 16:11:51 +00:00
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;
}
2004-12-21 16:11:51 +00:00
}
emile_map_close(map);
return 0;
2004-12-21 16:11:51 +00:00
}