add --config to provide a configuration file

This commit is contained in:
Laurent Vivier 2008-08-12 13:51:49 +00:00
parent 689316713e
commit b2b8839439

View File

@ -45,6 +45,7 @@ enum {
ARG_APPEND = 'a', ARG_APPEND = 'a',
ARG_APPLEDRIVER = 'd', ARG_APPLEDRIVER = 'd',
ARG_EMILEDRIVER = 'e', ARG_EMILEDRIVER = 'e',
ARG_CONFIG = 'c',
}; };
static struct option long_options[] = static struct option long_options[] =
@ -58,6 +59,7 @@ static struct option long_options[] =
{"append", 1, NULL, ARG_APPEND }, {"append", 1, NULL, ARG_APPEND },
{"appledriver", 1, NULL, ARG_APPLEDRIVER }, {"appledriver", 1, NULL, ARG_APPLEDRIVER },
{"emiledriver", 1, NULL, ARG_EMILEDRIVER }, {"emiledriver", 1, NULL, ARG_EMILEDRIVER },
{"config", 1, NULL, ARG_CONFIG },
{NULL, 0, NULL, 0 }, {NULL, 0, NULL, 0 },
}; };
@ -82,6 +84,8 @@ static void usage(int argc, char** argv)
"appledriver to copy to CDROM\n"); "appledriver to copy to CDROM\n");
fprintf(stderr, " -e, --emiledriver=FILE " fprintf(stderr, " -e, --emiledriver=FILE "
"emiledriver to copy to CDROM\n"); "emiledriver to copy to CDROM\n");
fprintf(stderr, " -c, --config=FILE "
"path of configuration file\n");
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE); fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
} }
@ -257,22 +261,11 @@ static int get_second_position(char *image, char *name, int *second_offset, int
return 0; return 0;
} }
static int set_second(char *image, int second_offset, char *kernel_image, char *cmdline, char *ramdisk) static int set_second(char *image, int second_offset,
char *kernel_image, char *cmdline, char *ramdisk)
{ {
int fd; int fd;
int ret; int ret;
char k[512], r[512];
if (kernel_image)
{
sprintf(k, "iso9660:(sd3)%s", kernel_image);
kernel_image = k;
}
if (ramdisk)
{
sprintf(r, "iso9660:(sd3)%s", ramdisk);
ramdisk = r;
}
fd = open(image, O_RDWR); fd = open(image, O_RDWR);
lseek(fd, second_offset * 512, SEEK_SET); lseek(fd, second_offset * 512, SEEK_SET);
@ -282,6 +275,22 @@ static int set_second(char *image, int second_offset, char *kernel_image, char *
return ret; return ret;
} }
static int set_config(char *image, int second_offset, char *config)
{
int fd;
int ret;
char c[512];
sprintf(c, "configuration %s\n", config);
fd = open(image, O_RDWR);
lseek(fd, second_offset * 512, SEEK_SET);
emile_second_set_configuration(fd, (int8_t*)c);
close(fd);
return ret;
}
static int set_first(char *image, int drive_num, int second_offset, int second_size) static int set_first(char *image, int drive_num, int second_offset, int second_size)
{ {
int fd; int fd;
@ -340,6 +349,7 @@ int main(int argc, char** argv)
char* appledriver = NULL; char* appledriver = NULL;
char* emiledriver = NULL; char* emiledriver = NULL;
char *cmdline = NULL; char *cmdline = NULL;
char *conffile = NULL;
int c; int c;
char temp[256]; char temp[256];
int i; int i;
@ -383,6 +393,9 @@ int main(int argc, char** argv)
case ARG_EMILEDRIVER: case ARG_EMILEDRIVER:
emiledriver = optarg; emiledriver = optarg;
break; break;
case ARG_CONFIG:
conffile = optarg;
break;
} }
} }
@ -396,6 +409,12 @@ int main(int argc, char** argv)
return 1; return 1;
} }
if (conffile && (kernel_image || ramdisk || cmdline)) {
fprintf(stderr, "ERROR: --config cannot be used with --kernel,"
" --ramdisk or --append\n");
usage(argc, argv);
return 1;
}
if (emiledriver == NULL) { if (emiledriver == NULL) {
if (first_level == NULL) if (first_level == NULL)
first_level = FIRST_PATH; first_level = FIRST_PATH;
@ -416,7 +435,11 @@ int main(int argc, char** argv)
return 1; return 1;
} }
set_second(emiledriver, 0, kernel_image, cmdline, ramdisk); if (conffile)
set_config(emiledriver, 0, conffile);
else
set_second(emiledriver, 0,
kernel_image, cmdline, ramdisk);
if (create_apple_driver(temp, emiledriver, first_level)) if (create_apple_driver(temp, emiledriver, first_level))
return 1; return 1;
} }
@ -463,8 +486,11 @@ int main(int argc, char** argv)
set_first(image, 3, second_offset, second_size); set_first(image, 3, second_offset, second_size);
set_second(image, second_offset, if (conffile)
kernel_image, cmdline, ramdisk); set_config(emiledriver, second_offset, conffile);
else
set_second(image, second_offset,
kernel_image, cmdline, ramdisk);
} }
return 0; return 0;