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
96202fe69c
commit
ad7b493a1a
23
libemile/emile_map_bootblock_get_type.c
Normal file
23
libemile/emile_map_bootblock_get_type.c
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
16
libemile/emile_map_get_number.c
Normal file
16
libemile/emile_map_get_number.c
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "partition.h"
|
||||
#include "libemile.h"
|
||||
|
||||
int emile_map_get_number(emile_map_t *map)
|
||||
{
|
||||
return map->partition.MapBlkCnt;
|
||||
}
|
187
tools/emile_scanbus.c
Normal file
187
tools/emile_scanbus.c
Normal file
@ -0,0 +1,187 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "libemile.h"
|
||||
|
||||
#define EMILE_MAX_DISK 16
|
||||
#define EMILE_MAX_DEVNAME 16
|
||||
|
||||
typedef char device_name_t[EMILE_MAX_DEVNAME];
|
||||
|
||||
extern int verbose;
|
||||
|
||||
int emile_scanbus(device_name_t devices[EMILE_MAX_DISK])
|
||||
{
|
||||
int i,j;
|
||||
int fd;
|
||||
device_name_t dev;
|
||||
|
||||
j = 0;
|
||||
for(i = 0; i < EMILE_MAX_DISK; i++)
|
||||
{
|
||||
sprintf(dev, "/dev/sd%c", 'a' + i);
|
||||
fd = open(dev, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
return j;
|
||||
}
|
||||
close(fd);
|
||||
strncpy(devices[j++], dev, EMILE_MAX_DEVNAME);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
int seek_partition(char *dev, int base)
|
||||
{
|
||||
emile_map_t* map;
|
||||
int i;
|
||||
int start;
|
||||
int count;
|
||||
|
||||
map = emile_map_open(dev, O_RDONLY);
|
||||
for (i = 0; i < emile_map_get_number(map); i++)
|
||||
{
|
||||
emile_map_read(map, i);
|
||||
emile_map_get_partition_geometry(map, &start, &count);
|
||||
if (base == start)
|
||||
{
|
||||
emile_map_close(map);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
emile_map_close(map);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void scanbus(void)
|
||||
{
|
||||
emile_map_t* map;
|
||||
device_name_t devices[EMILE_MAX_DISK];
|
||||
int count;
|
||||
int i;
|
||||
int j;
|
||||
char bootblock[BOOTBLOCK_SIZE];
|
||||
|
||||
count = emile_scanbus(devices);
|
||||
if (count == 0)
|
||||
{
|
||||
if (errno == EACCES)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ERROR: cannot access to devices (you should try as root...)\n");
|
||||
return;
|
||||
}
|
||||
printf("No disk found\n");
|
||||
}
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
int block_size, block_count;
|
||||
|
||||
printf("%s:", devices[i]);
|
||||
map = emile_map_open(devices[i], O_RDONLY);
|
||||
if (verbose)
|
||||
{
|
||||
emile_map_geometry(map, &block_size, &block_count);
|
||||
printf(" block size: %d, blocks number: %d (%d.%d MB)\n",
|
||||
block_size, block_count,
|
||||
(block_count / (1024 / block_size)) / 1024,
|
||||
(block_count / (1024 / block_size)) % 1024);
|
||||
}
|
||||
else putchar('\n');
|
||||
|
||||
if (map == NULL)
|
||||
{
|
||||
printf("\t<No information available>\n");
|
||||
continue;
|
||||
}
|
||||
if (!emile_map_is_valid(map))
|
||||
{
|
||||
printf("\t<No valid partition map found>\n");
|
||||
continue;
|
||||
}
|
||||
if (emile_map_get_driver_number(map) > 0)
|
||||
printf(" Drivers\n");
|
||||
for (j = 0; j < emile_map_get_driver_number(map); j++)
|
||||
{
|
||||
int block, size, type, part;
|
||||
emile_map_get_driver_info(map, j,
|
||||
&block, &size, &type);
|
||||
printf(" %d: base: %d size: %d type: %d",
|
||||
j, block, size, type);
|
||||
part = seek_partition(devices[i], block);
|
||||
if (part == -1)
|
||||
printf(" <invalid>\n");
|
||||
else
|
||||
{
|
||||
emile_map_read(map, part);
|
||||
printf(" <%d: %s [%s]>\n", part,
|
||||
emile_map_get_partition_name(map),
|
||||
emile_map_get_partition_type(map));
|
||||
}
|
||||
}
|
||||
printf(" Partitions\n");
|
||||
for (j = 0; j < emile_map_get_number(map); j++)
|
||||
{
|
||||
emile_map_read(map, j);
|
||||
|
||||
if (emile_map_partition_is_startup(map))
|
||||
printf(" --> ");
|
||||
else
|
||||
printf(" ");
|
||||
printf("%s%-2d: ", devices[i], j + 1);
|
||||
printf("%16s [%-16s] ",
|
||||
emile_map_get_partition_name(map),
|
||||
emile_map_get_partition_type(map));
|
||||
if (emile_map_partition_is_bootable(map))
|
||||
{
|
||||
int boottype;
|
||||
emile_map_bootblock_read(map, bootblock);
|
||||
boottype = emile_map_bootblock_get_type(bootblock);
|
||||
switch(boottype)
|
||||
{
|
||||
case INVALID_BOOTBLOCK:
|
||||
printf(" <no bootblock>\n");
|
||||
break;
|
||||
case APPLE_BOOTBLOCK:
|
||||
printf(" <Apple bootblock>\n");
|
||||
break;
|
||||
case EMILE_BOOTBLOCK:
|
||||
printf(" <EMILE bootblock>\n");
|
||||
break;
|
||||
default:
|
||||
printf(" <unknown bootblock>\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
putchar('\n');
|
||||
if (verbose)
|
||||
{
|
||||
int start, count;
|
||||
|
||||
emile_map_get_partition_geometry(map,
|
||||
&start, &count);
|
||||
printf(" base: %d, count: %d (%d.%d MB)\n",
|
||||
start, count,
|
||||
(count / (1024 / block_size)) / 1024,
|
||||
(count / (1024 / block_size)) % 1024);
|
||||
}
|
||||
}
|
||||
emile_map_close(map);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user