disk.c: support for glob patterns in disk label
This commit is contained in:
parent
34a510f746
commit
1fe7454b84
24
disk.c
24
disk.c
@ -27,6 +27,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include "stage1.h"
|
||||
#include "frontend.h"
|
||||
#include "modules.h"
|
||||
@ -152,7 +153,9 @@ static enum return_type try_with_partition(char *choice);
|
||||
|
||||
static enum return_type try_with_uuidlabel()
|
||||
{
|
||||
char device_fullname[64];
|
||||
char device_fullname[128];
|
||||
char device_pattern[128];
|
||||
glob_t globbuf;
|
||||
char devname[50];
|
||||
struct stat statbuf;
|
||||
int len;
|
||||
@ -165,14 +168,19 @@ static enum return_type try_with_uuidlabel()
|
||||
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);
|
||||
strcpy(device_pattern, "/dev/disk/by-label/");
|
||||
strcat(device_pattern, get_auto_value("label"));
|
||||
/* Allow to use glob match in label, like automatic=method:disk,label:ALT* */
|
||||
if( glob(device_pattern, 0, NULL, &globbuf) == 0 ) {
|
||||
strcpy(device_fullname, globbuf.gl_pathv[0]);
|
||||
if (stat(device_fullname, &statbuf) == 0 && S_ISBLK(statbuf.st_mode) &&
|
||||
(len = readlink(device_fullname, devname, sizeof(devname))) != -1) {
|
||||
devname[len] = 0;
|
||||
globfree(&globbuf);
|
||||
return try_with_partition(strrchr(devname, '/') + 1);
|
||||
}
|
||||
}
|
||||
|
||||
globfree(&globbuf);
|
||||
return RETURN_ERROR;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user