cdrom.c: check if it's a hybrid iso on a flashdrive

The implementation is a rough port of
http://svn.mandriva.com/cgi-bin/viewvc.cgi/soft/drakx/trunk/mdk-stage1/cdrom.c?view=patch&r1=256657&r2=256656&pathrev=256657
taking into account the difference in underlying early userspace.
This commit is contained in:
Michael Shigorin 2011-12-16 12:27:46 +02:00
parent 5e3a8c51a3
commit a3a24b8891

85
cdrom.c
View File

@ -65,15 +65,15 @@ static enum return_type do_with_device(char * dev_name, char * dev_model)
if (test_that_cd()) {
enum return_type results;
umount(IMAGE_LOCATION);
snprintf(msg, sizeof(msg), "That CDROM disc does not seem to be a %s"
" Installation CDROM.\nRetry with another disc?", version);
snprintf(msg, sizeof(msg), "That ISO does not seem like proper %s"
" media.\nRetry with another one?", version);
results = ask_yes_no(msg);
if (results == RETURN_OK)
return try_with_device(dev_name, dev_model);
return results;
}
log_message("found a %s CDROM, good news!", version);
log_message("found %s ISO9660 media, good news!", version);
if (IS_RESCUE) {
load_ramdisk(NULL);
@ -98,7 +98,7 @@ static enum return_type do_with_device(char * dev_name, char * dev_model)
static enum return_type try_with_device(char * dev_name, char * dev_model)
{
wait_message("Trying to access a CDROM disc (drive %s)", dev_model);
wait_message("Trying to access media in drive %s", dev_model);
if (mount_that_cd_device(dev_name) == -1) {
enum return_type results;
@ -106,7 +106,7 @@ static enum return_type try_with_device(char * dev_name, char * dev_model)
unset_param(MODE_AUTOMATIC); /* we are in a fallback mode */
remove_wait_message();
snprintf(msg, sizeof(msg), "I can't access a %s Installation disc in your CDROM drive (%s).\nRetry?", version, dev_model);
snprintf(msg, sizeof(msg), "I can't access %s media in drive %s.\nRetry?", version, dev_model);
results = ask_yes_no(msg);
if (results == RETURN_OK)
return try_with_device(dev_name, dev_model);
@ -117,6 +117,39 @@ static enum return_type try_with_device(char * dev_name, char * dev_model)
return do_with_device(dev_name, dev_model);
}
int try_automatic(char ** medias, char ** medias_models)
{
static char * already_tried[50] = { NULL };
char ** model = medias_models;
char ** ptr = medias;
int i = 0;
while (ptr && *ptr) {
char ** p;
for (p = already_tried; p && *p; p++)
if (streq(*p, *ptr))
goto try_automatic_already_tried;
*p = strdup(*ptr);
*(p+1) = NULL;
wait_message("Trying to access media in drive %s", *model);
if (mount_that_cd_device(*ptr) != -1) {
if (!test_that_cd()) {
remove_wait_message();
return i;
}
else
umount(IMAGE_LOCATION);
}
remove_wait_message();
try_automatic_already_tried:
ptr++;
model++;
i++;
}
return -1;
}
enum return_type cdrom_prepare(void)
{
char ** medias, ** ptr, ** medias_models;
@ -137,14 +170,30 @@ enum return_type cdrom_prepare(void)
update_splash("wait_media");
get_medias(CDROM, &medias, &medias_models);
if (IS_AUTOMATIC) {
ptr = medias;
while (ptr && *ptr) {
count++;
ptr++;
}
if ((i = try_automatic(medias, medias_models)) != -1)
return do_with_device(medias[i], medias_models[i]);
/* detect hybrid iso images (those dumped to a USB stick) */
get_medias(DISK, &medias, &medias_models);
if ((i = try_automatic(medias, medias_models)) != -1) {
return do_with_device(medias[i], medias_models[i]);
}
if (count == 0) {
stg1_error_message("No CDROM device found.");
/* too bad, let's recount one more time */
ptr = medias;
while (ptr && *ptr) {
count++;
ptr++;
}
if (count == 0)
stg1_error_message("No CD/DVD/Pendrive found.");
i = ask_insmod();
if (i == RETURN_BACK)
return RETURN_BACK;
@ -161,28 +210,10 @@ enum return_type cdrom_prepare(void)
return cdrom_prepare();
}
if (IS_AUTOMATIC) {
char ** model = medias_models;
ptr = medias;
while (ptr && *ptr) {
wait_message("Trying to access %s CDROM disc (drive %s)", version, *model);
if (mount_that_cd_device(*ptr) != -1) {
if (!test_that_cd()) {
remove_wait_message();
return do_with_device(*ptr, *model);
}
else
umount(IMAGE_LOCATION);
}
remove_wait_message();
ptr++;
model++;
}
unset_param(MODE_AUTOMATIC);
return cdrom_prepare();
}
else {
results = ask_from_list_comments("Please choose the CDROM drive to use for the installation.", medias, medias_models, &choice);
results = ask_from_list_comments("Please choose the drive to use for the installation.", medias, medias_models, &choice);
if (results == RETURN_OK) {
char ** model = medias_models;
ptr = medias;
@ -195,8 +226,6 @@ enum return_type cdrom_prepare(void)
results = try_with_device(choice, *model);
} else
return results;
}
if (results == RETURN_OK)
{
update_splash("found_media");