implemented uuid' and label' automatic parms

is is possible to set these parameters for `disk' method
instead of old `disk' and 'partition' ones, i.e:
automatic=method:disk,label:altlnx or
automatic=method:disk,uuid:5fbe7d46-fc41-48c5-bac7-5114b9446efd
This commit is contained in:
Sergey Bolshakov 2008-05-07 20:41:57 +04:00
parent 1bbdd06c8e
commit 126c343130
2 changed files with 60 additions and 26 deletions

View File

@ -24,6 +24,7 @@
#include "stage1.h"
void grab_automatic_params(char * line);
char * get_auto_value(char * auto_param);
enum return_type ask_from_list_auto(char *msg, char ** elems, char ** choice, char * auto_param, char ** elems_auto);
enum return_type ask_from_list_comments_auto(char *msg, char ** elems, char ** elems_comments, char ** choice, char * auto_param, char ** elems_auto);

85
disk.c
View File

@ -148,14 +148,36 @@ static char * disk_extract_list_directory(char * direct)
return strdup(tmp);
}
static enum return_type try_with_partition(char *choice);
static enum return_type try_with_uuidlabel()
{
char device_fullname[64];
char devname[50];
struct stat statbuf;
int len;
strcpy(device_fullname, "/dev/disk/by-uuid/");
strcat(device_fullname, get_auto_value("uuid"));
if (stat(device_fullname, &statbuf) == 0 && S_ISBLK(statbuf.st_mode) &&
(len = readlink(device_fullname, devname, sizeof(devname))) != -1) {
devname[len] = 0;
return try_with_partition(strrchr(devname, '/') + 1);
}
strcpy(device_fullname, "/dev/disk/by-label/");
strcat(device_fullname, get_auto_value("label"));
if (stat(device_fullname, &statbuf) == 0 && S_ISBLK(statbuf.st_mode) &&
(len = readlink(device_fullname, devname, sizeof(devname))) != -1) {
devname[len] = 0;
return try_with_partition(strrchr(devname, '/') + 1);
}
return RETURN_ERROR;
}
static enum return_type try_with_device(char *dev_name)
{
char * questions_location[] = { "Directory or ISO image", NULL };
char * questions_location_auto[] = { "directory", NULL };
static char ** answers_location = NULL;
char device_fullname[50];
char location_full[500];
int major, minor, blocks;
char name[100];
@ -163,11 +185,9 @@ static enum return_type try_with_device(char *dev_name)
FILE * f;
char * parts[50];
char * parts_comments[50];
struct stat statbuf;
int i = 0;
enum return_type results;
char * choice;
int iso = 0;
if (!(f = fopen("/proc/partitions", "rb")) || !fgets(buf, sizeof(buf), f) || !fgets(buf, sizeof(buf), f)) {
log_perror(dev_name);
@ -203,6 +223,25 @@ static enum return_type try_with_device(char *dev_name)
if (results != RETURN_OK)
return results;
if (try_with_partition(choice) != RETURN_OK)
return try_with_device(dev_name);
else
return RETURN_OK;
}
static enum return_type try_with_partition(char *choice)
{
char * questions_location[] = { "Directory or ISO image", NULL };
char * questions_location_auto[] = { "directory", NULL };
static char ** answers_location = NULL;
char device_fullname[50];
char location_full[500];
char buf[512];
struct stat statbuf;
int iso = 0;
strcpy(device_fullname, "/dev/");
strcat(device_fullname, choice);
@ -211,13 +250,13 @@ static enum return_type try_with_device(char *dev_name)
my_mount(device_fullname, IMAGE_LOCATION, "ntfs", 0) == -1 &&
my_mount(device_fullname, IMAGE_LOCATION, "reiserfs", 0) == -1) {
stg1_error_message("I can't find a valid filesystem (tried: ext2, vfat, ntfs, reiserfs).");
return try_with_device(dev_name);
return RETURN_ERROR;
}
snprintf(buf, sizeof(buf), "Please enter the directory (or ISO image file) containing the %s Distribution.", version);
if (ask_from_entries_auto(buf, questions_location, &answers_location, 24, questions_location_auto, NULL) != RETURN_OK) {
umount(IMAGE_LOCATION);
return try_with_device(dev_name);
return RETURN_ERROR;
}
strcpy(location_full, IMAGE_LOCATION);
@ -229,7 +268,7 @@ static enum return_type try_with_device(char *dev_name)
"Here's a short extract of the files in the root of the partition:\n"
"%s", disk_extract_list_directory(IMAGE_LOCATION));
umount(IMAGE_LOCATION);
return try_with_device(dev_name);
return RETURN_ERROR;
}
if (!stat(location_full, &statbuf) && !S_ISDIR(statbuf.st_mode)) {
@ -237,7 +276,7 @@ static enum return_type try_with_device(char *dev_name)
if (lomount(location_full, IMAGE_LOCATION)) {
stg1_error_message("Could not mount file %s as an ISO image of the %s Distribution.", answers_location[0], version);
umount(IMAGE_LOCATION);
return try_with_device(dev_name);
return RETURN_ERROR;
}
iso = 1;
add_to_env("PIGGYBACK", "1");
@ -249,7 +288,7 @@ static enum return_type try_with_device(char *dev_name)
"%s", version, disk_extract_list_directory(IMAGE_LOCATION));
loumount();
umount(IMAGE_LOCATION);
return try_with_device(dev_name);
return RETURN_ERROR;
}
log_message("found the %s Installation, good news!", version);
@ -259,16 +298,15 @@ static enum return_type try_with_device(char *dev_name)
stg1_error_message("Could not load program into memory.");
loumount();
umount(IMAGE_LOCATION);
return try_with_device(dev_name);
return RETURN_ERROR;
}
} else {
do_losetup(LIVE_DEVICE, get_ramdisk_path(iso ? NULL : location_full));
my_mount(LIVE_DEVICE, STAGE2_LOCATION, (IS_LIVE) ? LIVEFS : STAGE2FS, 0);
}
method_name = strdup("disk");
add_to_env("DEVICE", choice);
add_to_env("METHOD", method_name);
add_to_env("METHOD", strdup("disk"));
add_to_env("PREFIX", answers_location[0]);
return RETURN_OK;
@ -292,20 +330,15 @@ enum return_type disk_prepare(void)
if (count == 0) {
stg1_error_message("No DISK drive found.");
i = ask_insmod();
if (i == RETURN_BACK)
return RETURN_BACK;
return disk_prepare();
return RETURN_BACK;
}
if (try_with_uuidlabel() == RETURN_OK)
return RETURN_OK;
if (count == 1) {
results = try_with_device(*medias);
if (results == RETURN_OK)
return RETURN_OK;
i = ask_insmod();
if (i == RETURN_BACK)
return RETURN_BACK;
return disk_prepare();
return (results == RETURN_OK) ? RETURN_OK : RETURN_BACK;
}
snprintf(msg, sizeof(msg), "Please choose the DISK drive on which you copied the %s Distribution.", version);