2004-12-27 21:39:19 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2004 Laurent Vivier <Laurent@lvivier.info>
|
2004-12-27 21:39:19 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <getopt.h>
|
2005-02-02 14:47:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2004-12-27 21:39:19 +00:00
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
#include "libmap.h"
|
2004-12-27 21:39:19 +00:00
|
|
|
#include "libemile.h"
|
2007-10-09 20:43:05 +00:00
|
|
|
#include "device.h"
|
2004-12-27 21:39:19 +00:00
|
|
|
|
2005-02-01 20:34:00 +00:00
|
|
|
int verbose = 0;
|
|
|
|
|
|
|
|
extern void scanbus(void);
|
2006-05-29 22:17:46 +00:00
|
|
|
extern void diskinfo(char*);
|
2005-02-01 20:34:00 +00:00
|
|
|
|
|
|
|
|
2004-12-27 21:39:19 +00:00
|
|
|
enum {
|
2005-02-01 20:34:00 +00:00
|
|
|
ACTION_NONE = 0x00,
|
|
|
|
ACTION_FLAGS = 0x01,
|
|
|
|
ACTION_TYPE = 0x02,
|
2004-12-27 21:39:19 +00:00
|
|
|
ACTION_STARTUP = 0x04,
|
2005-02-01 20:34:00 +00:00
|
|
|
ACTION_SCANBUS = 0x08,
|
2005-02-02 14:47:49 +00:00
|
|
|
ACTION_GET = 0x10,
|
|
|
|
ACTION_PUT = 0x20,
|
2004-12-27 21:39:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_NONE = 0,
|
2005-02-01 20:34:00 +00:00
|
|
|
ARG_SCANBUS,
|
2004-12-27 21:39:19 +00:00
|
|
|
ARG_HELP = 'h',
|
|
|
|
ARG_FLAGS = 'f',
|
|
|
|
ARG_TYPE ='t',
|
|
|
|
ARG_STARTUP ='s',
|
2005-02-01 20:34:00 +00:00
|
|
|
ARG_VERBOSE = 'v',
|
2005-02-02 14:47:49 +00:00
|
|
|
ARG_GET = 'g',
|
|
|
|
ARG_PUT = 'p',
|
2004-12-27 21:39:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
{"help", 0, NULL, ARG_HELP },
|
|
|
|
{"flags", 1, NULL, ARG_FLAGS },
|
|
|
|
{"type", 1, NULL, ARG_TYPE },
|
|
|
|
{"startup", 0, NULL, ARG_STARTUP },
|
2005-02-01 20:34:00 +00:00
|
|
|
{"scanbus", 0, NULL, ARG_SCANBUS },
|
|
|
|
{"verbose", 0, NULL, ARG_VERBOSE },
|
2005-02-02 14:47:49 +00:00
|
|
|
{"get-driver", 1, NULL, ARG_GET },
|
|
|
|
{"put-driver", 1, NULL, ARG_PUT },
|
2004-12-27 21:39:19 +00:00
|
|
|
{NULL, 0, NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void usage(int argc, char** argv)
|
|
|
|
{
|
2008-07-21 22:16:47 +00:00
|
|
|
fprintf(stderr, "Usage: %s [OPTIONS] [<disk>]\n", argv[0]);
|
|
|
|
fprintf(stderr, " %s [OPTIONS] [<partition>|<disk> <part number>]\n", argv[0]);
|
|
|
|
fprintf(stderr, " -h, --help display this text\n");
|
|
|
|
fprintf(stderr, " -v, --verbose verbose mode\n");
|
|
|
|
fprintf(stderr, " --scanbus "
|
|
|
|
"scan all available SCSI devices\n");
|
|
|
|
fprintf(stderr, " -s, --startup "
|
|
|
|
"set the startup partition\n");
|
|
|
|
fprintf(stderr, " -t, --type=TYPE "
|
|
|
|
"set the type of the partition\n");
|
|
|
|
fprintf(stderr, " -f, --flags=FLAGS "
|
|
|
|
"set the type of the partition\n");
|
|
|
|
fprintf(stderr, " -g, --get-driver=FILE "
|
|
|
|
"get the driver from the partition\n");
|
|
|
|
fprintf(stderr, " -p, --put-driver=FILE "
|
|
|
|
"put the driver to the partition\n");
|
2004-12-27 21:39:19 +00:00
|
|
|
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
static int get_driver(map_t *map, int partition, char* appledriver)
|
2005-02-02 14:47:49 +00:00
|
|
|
{
|
|
|
|
int driver;
|
|
|
|
int block_size, block_count;
|
|
|
|
int driver_number;
|
|
|
|
int block, size, type, part;
|
2006-09-24 22:24:02 +00:00
|
|
|
int partition_base, partition_size;
|
2005-02-02 14:47:49 +00:00
|
|
|
int bootstart, bootsize, bootaddr, bootentry, checksum;
|
|
|
|
char processor[16];
|
2007-02-24 14:02:40 +00:00
|
|
|
unsigned char *code;
|
2005-02-02 14:47:49 +00:00
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_read(map, partition);
|
|
|
|
if (strncmp(map_get_partition_type(map),
|
2005-02-02 14:47:49 +00:00
|
|
|
"Apple_Driver", strlen("Apple_Driver")) != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: the type of the partition must begin with \"Apple_Driver\"\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-04 20:55:52 +00:00
|
|
|
if (strcmp(map_get_partition_name(map), "Macintosh") != 0)
|
2005-02-02 14:47:49 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: the name of the partition must be \"Macintosh\"\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_geometry(map, &block_size, &block_count);
|
2006-05-30 21:21:31 +00:00
|
|
|
printf("block size: %d\n", block_size);
|
2005-02-02 14:47:49 +00:00
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_get_partition_geometry(map, &partition_base, &partition_size);
|
2006-09-24 22:24:02 +00:00
|
|
|
printf("partition base: %d, size %d\n", partition_base, partition_size);
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
driver_number = map_get_driver_number(map);
|
2005-02-02 14:47:49 +00:00
|
|
|
if (driver_number == 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: no driver on this device\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (driver = 0; driver < driver_number; driver++)
|
|
|
|
{
|
2007-10-04 20:55:52 +00:00
|
|
|
map_get_driver_info(map, driver, &block, &size, &type);
|
|
|
|
part = map_seek_driver_partition(map,
|
2005-02-02 14:47:49 +00:00
|
|
|
block * block_size / 512 );
|
|
|
|
if (part == partition)
|
2006-10-16 20:03:22 +00:00
|
|
|
{
|
2007-10-04 20:55:52 +00:00
|
|
|
map_read(map, part);
|
2006-10-16 20:03:22 +00:00
|
|
|
if (emile_is_apple_driver(map))
|
|
|
|
break;
|
|
|
|
}
|
2007-10-04 20:55:52 +00:00
|
|
|
part = map_seek_driver_partition(map, block);
|
2006-10-16 20:03:22 +00:00
|
|
|
if (part == partition)
|
|
|
|
{
|
2007-10-04 20:55:52 +00:00
|
|
|
map_read(map, part);
|
2006-10-16 20:03:22 +00:00
|
|
|
if (emile_is_apple_driver(map))
|
|
|
|
break;
|
|
|
|
}
|
2005-02-02 14:47:49 +00:00
|
|
|
}
|
|
|
|
if (part != partition)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: cannot find partition in driver table\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf("Found driver %d for partition %d\n", driver, partition + 1);
|
2006-05-30 21:21:31 +00:00
|
|
|
printf("base: %d size: %d type: %d\n", block * block_size / 512,
|
|
|
|
size * block_size / 512 , type);
|
2007-10-04 20:55:52 +00:00
|
|
|
map_get_bootinfo(map, &bootstart, &bootsize, &bootaddr,
|
2005-02-02 14:47:49 +00:00
|
|
|
&bootentry, &checksum, processor);
|
|
|
|
printf("Bootstart: %d, Bootsize: %d, Bootaddr: %d, Bootentry: %d\n",
|
|
|
|
bootstart, bootsize, bootaddr, bootentry);
|
|
|
|
printf("Checksum: 0x%04x, Processor: %s\n", checksum, processor);
|
|
|
|
|
|
|
|
if (strcmp(processor, "68000") != 0)
|
|
|
|
{
|
|
|
|
fprintf( stderr,
|
|
|
|
"ERROR: cannot manage processor %s (not 68000)\n", processor);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-02-24 14:02:40 +00:00
|
|
|
code = (unsigned char*)malloc(partition_size * 512);
|
2005-02-02 14:47:49 +00:00
|
|
|
if (code == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot malloc() to load driver in memory\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-10 21:07:52 +00:00
|
|
|
ret = map_read_sector(map, block * block_size, (char*)code, bootsize);
|
2007-10-09 20:43:05 +00:00
|
|
|
if (ret == -1)
|
2005-02-02 14:47:49 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot read driver (read())\n");
|
|
|
|
free(code);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-05-30 21:21:31 +00:00
|
|
|
ret = emile_checksum(code, bootsize);
|
|
|
|
if (ret != checksum)
|
2005-02-02 14:47:49 +00:00
|
|
|
fprintf(stderr, "WARNING: checksum is invalid (0x%x)\n",
|
2006-05-30 21:21:31 +00:00
|
|
|
ret);
|
2005-05-09 22:18:21 +00:00
|
|
|
else
|
|
|
|
printf("Checksum OK\n");
|
2005-02-02 14:47:49 +00:00
|
|
|
|
|
|
|
fd = open(appledriver, O_WRONLY | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR);
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot open %s to save driver\n",
|
|
|
|
appledriver);
|
|
|
|
free(code);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-10-16 20:03:22 +00:00
|
|
|
ret = write(fd, code, bootsize);
|
2005-02-02 14:47:49 +00:00
|
|
|
close(fd);
|
|
|
|
free(code);
|
|
|
|
|
2006-10-16 20:03:22 +00:00
|
|
|
if (ret != bootsize)
|
2005-02-02 14:47:49 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot save driver to %s\n",
|
|
|
|
appledriver);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
static int put_driver(map_t *map, int partition, char* appledriver)
|
2005-05-09 22:18:21 +00:00
|
|
|
{
|
|
|
|
int block_size, block_count;
|
|
|
|
int fd;
|
|
|
|
int ret;
|
2007-02-24 14:02:40 +00:00
|
|
|
unsigned char* code;
|
2005-05-09 22:18:21 +00:00
|
|
|
struct stat st;
|
|
|
|
int driver_number;
|
|
|
|
int block, count, checksum;
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_read(map, partition);
|
2005-05-09 22:18:21 +00:00
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
if (strncmp(map_get_partition_type(map),
|
2005-05-09 22:18:21 +00:00
|
|
|
"Apple_Driver", strlen("Apple_Driver")) != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: the type of the partition must begin with \"Apple_Driver\"\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-04 20:55:52 +00:00
|
|
|
if (strcmp(map_get_partition_name(map), "Macintosh") != 0)
|
2005-05-09 22:18:21 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: the name of the partition must be \"Macintosh\"\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_geometry(map, &block_size, &block_count);
|
2005-05-09 22:18:21 +00:00
|
|
|
|
|
|
|
/* read driver from file */
|
|
|
|
|
|
|
|
fd = open(appledriver, O_RDONLY);
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot open file %s\n", appledriver);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fstat(fd, &st);
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot stat file %s\n", appledriver);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
code = malloc(st.st_size);
|
|
|
|
if (code == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot malloc %ld\n", st.st_size);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = read(fd, code, st.st_size);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (ret != st.st_size)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot read file %s\n", appledriver);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute driver checksum */
|
|
|
|
|
|
|
|
checksum = emile_checksum(code, st.st_size);
|
|
|
|
printf("Driver checksum: 0x%x\n", checksum);
|
|
|
|
|
|
|
|
/* write file in partition */
|
|
|
|
|
2007-10-10 21:07:52 +00:00
|
|
|
ret = map_write_sector(map, block * block_size, (char*)code,
|
|
|
|
st.st_size);
|
2005-05-09 22:18:21 +00:00
|
|
|
free(code);
|
|
|
|
|
2007-10-09 20:43:05 +00:00
|
|
|
if (ret == -1)
|
2005-05-09 22:18:21 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot write driver (write())\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set bootinfo */
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_set_bootinfo(map, 0, st.st_size, 0, 0, checksum, "68000");
|
|
|
|
map_partition_set_flags(map, 0x17F);
|
2005-05-09 22:18:21 +00:00
|
|
|
|
|
|
|
/* add driver in drivers list */
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
driver_number = map_get_driver_number(map);
|
2005-05-09 22:18:21 +00:00
|
|
|
if (driver_number == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot read drivers number\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
ret = map_get_partition_geometry(map, &block, &count);
|
2005-05-09 22:18:21 +00:00
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot read partition geometry\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
ret = map_set_driver_info(map, driver_number,
|
2005-05-09 22:18:21 +00:00
|
|
|
block / (block_size / 512) ,
|
|
|
|
count / (block_size / 512), 1);
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot set driver info\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
ret = map_set_driver_number(map, driver_number + 1);
|
2005-05-09 22:18:21 +00:00
|
|
|
if (driver_number == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot set drivers number\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
ret = map_write(map, partition);
|
2005-05-09 22:18:21 +00:00
|
|
|
if (ret != partition)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot set partition information\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
ret = map_block0_write(map);
|
2005-05-09 22:18:21 +00:00
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot set drivers information\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-12-27 21:39:19 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2007-10-04 20:55:52 +00:00
|
|
|
map_t *map;
|
2004-12-27 21:39:19 +00:00
|
|
|
int ret;
|
|
|
|
int disk;
|
2006-09-13 21:33:49 +00:00
|
|
|
int partition = 0;
|
2006-05-30 21:21:31 +00:00
|
|
|
char *disk_name;
|
|
|
|
char buffer[16];
|
2006-06-01 22:19:52 +00:00
|
|
|
int driver;
|
2004-12-27 21:39:19 +00:00
|
|
|
int action = ACTION_NONE;
|
|
|
|
char *dev_name = NULL;
|
2005-02-02 14:47:49 +00:00
|
|
|
char *appledriver = NULL;
|
2004-12-27 21:39:19 +00:00
|
|
|
int c;
|
|
|
|
int option_index;
|
|
|
|
int flags;
|
|
|
|
char *type;
|
2007-10-09 20:43:05 +00:00
|
|
|
device_io_t device;
|
2004-12-27 21:39:19 +00:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2005-02-02 14:47:49 +00:00
|
|
|
c = getopt_long(argc, argv, "hvg:p:sf:t:", long_options,
|
2004-12-27 21:39:19 +00:00
|
|
|
&option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
switch(c)
|
|
|
|
{
|
2005-02-01 20:34:00 +00:00
|
|
|
case ARG_VERBOSE:
|
|
|
|
verbose++;
|
|
|
|
break;
|
2004-12-27 21:39:19 +00:00
|
|
|
case ARG_HELP:
|
|
|
|
usage(argc, argv);
|
|
|
|
return 0;
|
|
|
|
case ARG_FLAGS:
|
|
|
|
action |= ACTION_FLAGS;
|
2004-12-27 22:34:59 +00:00
|
|
|
flags = strtol(optarg, NULL, 0);
|
2004-12-27 21:39:19 +00:00
|
|
|
break;
|
|
|
|
case ARG_TYPE:
|
|
|
|
action |= ACTION_TYPE;
|
|
|
|
type = optarg;
|
|
|
|
break;
|
|
|
|
case ARG_STARTUP:
|
|
|
|
action |= ACTION_STARTUP;
|
|
|
|
break;
|
2005-02-01 20:34:00 +00:00
|
|
|
case ARG_SCANBUS:
|
|
|
|
action |= ACTION_SCANBUS;
|
|
|
|
break;
|
2005-02-02 14:47:49 +00:00
|
|
|
case ARG_GET:
|
|
|
|
action |= ACTION_GET;
|
|
|
|
appledriver = optarg;
|
|
|
|
break;
|
|
|
|
case ARG_PUT:
|
|
|
|
action |= ACTION_PUT;
|
|
|
|
appledriver = optarg;
|
|
|
|
break;
|
2004-12-27 21:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-29 22:17:46 +00:00
|
|
|
if (optind < argc)
|
2006-05-30 21:21:31 +00:00
|
|
|
dev_name = argv[optind++];
|
2006-09-13 21:33:49 +00:00
|
|
|
if (optind < argc)
|
|
|
|
{
|
|
|
|
partition = strtol(argv[optind++], NULL, 0);
|
|
|
|
if (partition == 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: partition number cannot be 0 !\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2006-05-29 22:17:46 +00:00
|
|
|
|
|
|
|
if ( !action && dev_name)
|
|
|
|
{
|
|
|
|
diskinfo(dev_name);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-02-01 20:34:00 +00:00
|
|
|
if (action & ACTION_SCANBUS) {
|
|
|
|
if (action & ~ACTION_SCANBUS) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: \"--scanbus\" cannot be used with other arguments\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
scanbus();
|
|
|
|
return 0;
|
|
|
|
}
|
2005-02-02 14:47:49 +00:00
|
|
|
if ((action & ACTION_GET) && (action & ACTION_PUT)) {
|
|
|
|
fprintf(stderr, "You should use --get-driver OR --put-driver\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2005-02-01 20:34:00 +00:00
|
|
|
|
2004-12-27 21:39:19 +00:00
|
|
|
if (dev_name == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: you must specify a device\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-09-13 21:33:49 +00:00
|
|
|
if (partition == 0)
|
|
|
|
ret = emile_scsi_get_rdev(dev_name, &driver, &disk, &partition);
|
|
|
|
else
|
|
|
|
ret = emile_scsi_get_rdev(dev_name, &driver, &disk, NULL);
|
2006-05-30 21:21:31 +00:00
|
|
|
if ( (ret == -1) && (optind < argc))
|
|
|
|
{
|
|
|
|
disk_name = dev_name;
|
2006-06-01 22:19:52 +00:00
|
|
|
driver = 0;
|
2006-05-30 21:21:31 +00:00
|
|
|
disk = 0;
|
|
|
|
partition = atoi(argv[optind++]);
|
|
|
|
}
|
|
|
|
else if (ret == -1)
|
2004-12-27 21:39:19 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot find disk of %s\n", dev_name);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-05-30 21:21:31 +00:00
|
|
|
else
|
|
|
|
{
|
2006-06-01 22:19:52 +00:00
|
|
|
emile_get_dev_name(buffer, driver, disk, 0);
|
2006-05-30 21:21:31 +00:00
|
|
|
disk_name = buffer;
|
|
|
|
}
|
2004-12-27 21:39:19 +00:00
|
|
|
|
2004-12-27 22:34:59 +00:00
|
|
|
if (partition == 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: you must provide device of a partition\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-10-09 20:43:05 +00:00
|
|
|
device_sector_size = 512;
|
|
|
|
device.write_sector = (stream_read_sector_t)device_write_sector;
|
|
|
|
device.read_sector = (stream_read_sector_t)device_read_sector;
|
|
|
|
device.close = (stream_close_t)device_close;
|
2007-10-10 16:47:03 +00:00
|
|
|
device.get_blocksize = (stream_get_blocksize_t)device_get_blocksize;
|
2007-10-09 20:43:05 +00:00
|
|
|
device.data = (void*)device_open(disk_name, O_RDONLY);
|
2007-10-10 16:47:03 +00:00
|
|
|
|
2007-10-09 20:43:05 +00:00
|
|
|
map = map_open(&device);
|
|
|
|
if (map == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot open partition map\n");
|
|
|
|
return 4;
|
|
|
|
}
|
2004-12-27 21:39:19 +00:00
|
|
|
|
|
|
|
if (action & ACTION_STARTUP)
|
|
|
|
{
|
|
|
|
if (action & ~ACTION_STARTUP)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: don't use --startup with other flags\n");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2007-10-09 20:43:05 +00:00
|
|
|
ret = map_set_startup(map, partition - 1);
|
2005-02-02 14:47:49 +00:00
|
|
|
if (ret == -1)
|
2004-12-27 21:39:19 +00:00
|
|
|
return 3;
|
2005-02-02 14:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (action & ACTION_GET)
|
|
|
|
{
|
2005-05-09 22:18:21 +00:00
|
|
|
if (appledriver == NULL) {
|
|
|
|
fprintf(stderr, "ERROR: filename missing\n");
|
2007-10-04 20:55:52 +00:00
|
|
|
map_close(map);
|
2005-05-09 22:18:21 +00:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = get_driver(map, partition - 1, appledriver);
|
|
|
|
if (ret == -1) {
|
2005-02-02 14:47:49 +00:00
|
|
|
fprintf(stderr,
|
2005-05-09 22:18:21 +00:00
|
|
|
"ERROR: cannot put driver from partition %d to file %s\n",
|
|
|
|
partition, appledriver);
|
2007-10-04 20:55:52 +00:00
|
|
|
map_close(map);
|
2005-05-09 22:18:21 +00:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_close(map);
|
2005-05-09 22:18:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action & ACTION_PUT)
|
|
|
|
{
|
2005-02-02 14:47:49 +00:00
|
|
|
if (appledriver == NULL) {
|
|
|
|
fprintf(stderr, "ERROR: filename missing\n");
|
2007-10-04 20:55:52 +00:00
|
|
|
map_close(map);
|
2005-02-02 14:47:49 +00:00
|
|
|
return 6;
|
2004-12-27 21:39:19 +00:00
|
|
|
}
|
2005-02-02 14:47:49 +00:00
|
|
|
|
2005-05-09 22:18:21 +00:00
|
|
|
ret = put_driver(map, partition - 1, appledriver);
|
2005-02-02 14:47:49 +00:00
|
|
|
if (ret == -1) {
|
|
|
|
fprintf(stderr,
|
2005-05-09 22:18:21 +00:00
|
|
|
"ERROR: cannot put driver to partition %d from file %s\n",
|
2005-02-02 14:47:49 +00:00
|
|
|
partition, appledriver);
|
2007-10-04 20:55:52 +00:00
|
|
|
map_close(map);
|
2005-02-02 14:47:49 +00:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_close(map);
|
2005-02-02 14:47:49 +00:00
|
|
|
return 0;
|
2004-12-27 21:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
ret = map_read(map, partition - 1);
|
2004-12-27 21:39:19 +00:00
|
|
|
if (ret != partition - 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: cannot read partition %d info\n", partition);
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2004-12-27 22:34:59 +00:00
|
|
|
if (action & ACTION_FLAGS)
|
|
|
|
{
|
2007-10-04 20:55:52 +00:00
|
|
|
map_partition_set_flags(map, flags);
|
2004-12-27 22:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (action & ACTION_TYPE)
|
|
|
|
{
|
2007-10-04 20:55:52 +00:00
|
|
|
ret = map_set_partition_type(map, type);
|
2004-12-27 22:34:59 +00:00
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: cannot set partition type to %s\n", type);
|
2005-02-02 14:47:49 +00:00
|
|
|
return 7;
|
2004-12-27 22:34:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
ret = map_write(map, partition - 1);
|
2004-12-27 21:39:19 +00:00
|
|
|
if (ret != partition - 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: cannot write partition %d info\n", partition);
|
2005-02-02 14:47:49 +00:00
|
|
|
return 8;
|
2004-12-27 21:39:19 +00:00
|
|
|
}
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
map_close(map);
|
2004-12-27 21:39:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|