Fix few bugs and memory leaks
This commit is contained in:
parent
17785932df
commit
2980502850
5 changed files with 75 additions and 33 deletions
|
@ -1940,6 +1940,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
||||||
|
|
||||||
name = grub_xasprintf ("%s,%s", disk->name, partname);
|
name = grub_xasprintf ("%s,%s", disk->name, partname);
|
||||||
free (partname);
|
free (partname);
|
||||||
|
grub_disk_close (disk);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1159,7 +1159,7 @@ grub_util_pull_device (const char *os_dev)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default: /* GRUB_DEV_ABSTRACTION_NONE */
|
default: /* GRUB_DEV_ABSTRACTION_NONE */
|
||||||
grub_util_biosdisk_get_grub_dev (os_dev);
|
free (grub_util_biosdisk_get_grub_dev (os_dev));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ prepare_grub_to_access_device ()
|
||||||
echo "set root='`"${grub_probe}" --device "${device}" --target=compatibility_hint`'"
|
echo "set root='`"${grub_probe}" --device "${device}" --target=compatibility_hint`'"
|
||||||
if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
|
if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
|
||||||
hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`"
|
hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`"
|
||||||
echo "if [ x$feature_platform_search_hint = xy ]; then"
|
echo "if [ x\$feature_platform_search_hint = xy ]; then"
|
||||||
echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
|
echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
|
||||||
echo "else"
|
echo "else"
|
||||||
echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
|
echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
|
||||||
|
|
|
@ -67,7 +67,7 @@ enum {
|
||||||
PRINT_COMPATIBILITY_HINT
|
PRINT_COMPATIBILITY_HINT
|
||||||
};
|
};
|
||||||
|
|
||||||
int print = PRINT_FS;
|
static int print = PRINT_FS;
|
||||||
static unsigned int argument_is_device = 0;
|
static unsigned int argument_is_device = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -253,7 +253,11 @@ static void
|
||||||
print_full_name (const char *drive, grub_device_t dev)
|
print_full_name (const char *drive, grub_device_t dev)
|
||||||
{
|
{
|
||||||
if (dev->disk->partition)
|
if (dev->disk->partition)
|
||||||
printf ("%s,%s", drive, grub_partition_get_name (dev->disk->partition));
|
{
|
||||||
|
char *pname = grub_partition_get_name (dev->disk->partition);
|
||||||
|
printf ("%s,%s", drive, pname);
|
||||||
|
free (pname);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
printf ("%s", drive);
|
printf ("%s", drive);
|
||||||
}
|
}
|
||||||
|
@ -347,14 +351,17 @@ probe (const char *path, char *device_name)
|
||||||
if (print == PRINT_HINT_STR)
|
if (print == PRINT_HINT_STR)
|
||||||
{
|
{
|
||||||
const char *orig_path = grub_util_devname_to_ofpath (device_name);
|
const char *orig_path = grub_util_devname_to_ofpath (device_name);
|
||||||
char *ofpath = escape_of_path (orig_path);
|
|
||||||
char *biosname, *bare, *efi;
|
char *biosname, *bare, *efi;
|
||||||
const char *map;
|
const char *map;
|
||||||
|
|
||||||
printf ("--hint-ieee1275=");
|
if (orig_path)
|
||||||
print_full_name (ofpath, dev);
|
{
|
||||||
printf (" ");
|
char *ofpath = escape_of_path (orig_path);
|
||||||
free (ofpath);
|
printf ("--hint-ieee1275=");
|
||||||
|
print_full_name (ofpath, dev);
|
||||||
|
printf (" ");
|
||||||
|
free (ofpath);
|
||||||
|
}
|
||||||
|
|
||||||
biosname = guess_bios_drive (device_name);
|
biosname = guess_bios_drive (device_name);
|
||||||
if (biosname)
|
if (biosname)
|
||||||
|
@ -381,7 +388,7 @@ probe (const char *path, char *device_name)
|
||||||
print_full_name (bare, dev);
|
print_full_name (bare, dev);
|
||||||
printf (" ");
|
printf (" ");
|
||||||
}
|
}
|
||||||
free (biosname);
|
free (bare);
|
||||||
|
|
||||||
/* FIXME: Add ARC hint. */
|
/* FIXME: Add ARC hint. */
|
||||||
|
|
||||||
|
@ -404,7 +411,8 @@ probe (const char *path, char *device_name)
|
||||||
map = grub_util_biosdisk_get_compatibility_hint (dev->disk);
|
map = grub_util_biosdisk_get_compatibility_hint (dev->disk);
|
||||||
if (map)
|
if (map)
|
||||||
{
|
{
|
||||||
printf ("%s\n", map);
|
print_full_name (map, dev);
|
||||||
|
printf ("\n");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
biosname = guess_bios_drive (device_name);
|
biosname = guess_bios_drive (device_name);
|
||||||
|
|
|
@ -85,8 +85,8 @@ trim_newline (char *path)
|
||||||
|
|
||||||
#define OF_PATH_MAX 256
|
#define OF_PATH_MAX 256
|
||||||
|
|
||||||
static void
|
static int
|
||||||
find_obppath(char *of_path, const char *sysfs_path_orig)
|
find_obppath (char *of_path, const char *sysfs_path_orig)
|
||||||
{
|
{
|
||||||
char *sysfs_path, *path;
|
char *sysfs_path, *path;
|
||||||
|
|
||||||
|
@ -108,8 +108,14 @@ find_obppath(char *of_path, const char *sysfs_path_orig)
|
||||||
{
|
{
|
||||||
kill_trailing_dir(sysfs_path);
|
kill_trailing_dir(sysfs_path);
|
||||||
if (!strcmp(sysfs_path, "/sys"))
|
if (!strcmp(sysfs_path, "/sys"))
|
||||||
grub_util_error(_("'obppath' not found in parent dirs of %s"),
|
{
|
||||||
sysfs_path_orig);
|
grub_util_info (_("'obppath' not found in parent dirs of %s,"
|
||||||
|
" no IEEE1275 name discovery"),
|
||||||
|
sysfs_path_orig);
|
||||||
|
free (path);
|
||||||
|
free (sysfs_path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
memset(of_path, 0, OF_PATH_MAX);
|
memset(of_path, 0, OF_PATH_MAX);
|
||||||
|
@ -122,6 +128,7 @@ find_obppath(char *of_path, const char *sysfs_path_orig)
|
||||||
|
|
||||||
free (path);
|
free (path);
|
||||||
free (sysfs_path);
|
free (sysfs_path);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -159,14 +166,15 @@ trailing_digits (const char *p)
|
||||||
return end + 1;
|
return end + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
__of_path_common(char *of_path, char *sysfs_path,
|
__of_path_common(char *of_path, char *sysfs_path,
|
||||||
const char *device, int devno)
|
const char *device, int devno)
|
||||||
{
|
{
|
||||||
const char *digit_string;
|
const char *digit_string;
|
||||||
char disk[64];
|
char disk[64];
|
||||||
|
|
||||||
find_obppath(of_path, sysfs_path);
|
if (find_obppath(of_path, sysfs_path))
|
||||||
|
return 1;
|
||||||
|
|
||||||
digit_string = trailing_digits (device);
|
digit_string = trailing_digits (device);
|
||||||
if (*digit_string == '\0')
|
if (*digit_string == '\0')
|
||||||
|
@ -181,6 +189,7 @@ __of_path_common(char *of_path, char *sysfs_path,
|
||||||
sprintf(disk, "/disk@%d:%c", devno, 'a' + (part - 1));
|
sprintf(disk, "/disk@%d:%c", devno, 'a' + (part - 1));
|
||||||
}
|
}
|
||||||
strcat(of_path, disk);
|
strcat(of_path, disk);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
@ -198,7 +207,7 @@ get_basename(char *p)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
of_path_of_vdisk(char *of_path,
|
of_path_of_vdisk(char *of_path,
|
||||||
const char *devname __attribute__((unused)),
|
const char *devname __attribute__((unused)),
|
||||||
const char *device,
|
const char *device,
|
||||||
|
@ -207,18 +216,20 @@ of_path_of_vdisk(char *of_path,
|
||||||
{
|
{
|
||||||
char *sysfs_path, *p;
|
char *sysfs_path, *p;
|
||||||
int devno, junk;
|
int devno, junk;
|
||||||
|
int ret;
|
||||||
|
|
||||||
sysfs_path = xmalloc (PATH_MAX);
|
sysfs_path = xmalloc (PATH_MAX);
|
||||||
block_device_get_sysfs_path_and_link(devicenode,
|
block_device_get_sysfs_path_and_link(devicenode,
|
||||||
sysfs_path, PATH_MAX);
|
sysfs_path, PATH_MAX);
|
||||||
p = get_basename (sysfs_path);
|
p = get_basename (sysfs_path);
|
||||||
sscanf(p, "vdc-port-%d-%d", &devno, &junk);
|
sscanf(p, "vdc-port-%d-%d", &devno, &junk);
|
||||||
__of_path_common(of_path, sysfs_path, device, devno);
|
ret = __of_path_common(of_path, sysfs_path, device, devno);
|
||||||
|
|
||||||
free (sysfs_path);
|
free (sysfs_path);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
of_path_of_ide(char *of_path,
|
of_path_of_ide(char *of_path,
|
||||||
const char *devname __attribute__((unused)), const char *device,
|
const char *devname __attribute__((unused)), const char *device,
|
||||||
const char *devnode __attribute__((unused)),
|
const char *devnode __attribute__((unused)),
|
||||||
|
@ -226,6 +237,7 @@ of_path_of_ide(char *of_path,
|
||||||
{
|
{
|
||||||
char *sysfs_path, *p;
|
char *sysfs_path, *p;
|
||||||
int chan, devno;
|
int chan, devno;
|
||||||
|
int ret;
|
||||||
|
|
||||||
sysfs_path = xmalloc (PATH_MAX);
|
sysfs_path = xmalloc (PATH_MAX);
|
||||||
block_device_get_sysfs_path_and_link(devicenode,
|
block_device_get_sysfs_path_and_link(devicenode,
|
||||||
|
@ -233,9 +245,10 @@ of_path_of_ide(char *of_path,
|
||||||
p = get_basename (sysfs_path);
|
p = get_basename (sysfs_path);
|
||||||
sscanf(p, "%d.%d", &chan, &devno);
|
sscanf(p, "%d.%d", &chan, &devno);
|
||||||
|
|
||||||
__of_path_common(of_path, sysfs_path, device, devno);
|
ret = __of_path_common(of_path, sysfs_path, device, devno);
|
||||||
|
|
||||||
free (sysfs_path);
|
free (sysfs_path);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -258,10 +271,13 @@ vendor_is_ATA(const char *path)
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
free (buf);
|
|
||||||
|
|
||||||
if (!strncmp(buf, "ATA", 3))
|
if (!strncmp(buf, "ATA", 3))
|
||||||
return 1;
|
{
|
||||||
|
free (buf);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free (buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +318,7 @@ check_sas (char *sysfs_path, int *tgt)
|
||||||
close (fd);
|
close (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
of_path_of_scsi(char *of_path,
|
of_path_of_scsi(char *of_path,
|
||||||
const char *devname __attribute__((unused)), const char *device,
|
const char *devname __attribute__((unused)), const char *device,
|
||||||
const char *devnode __attribute__((unused)),
|
const char *devnode __attribute__((unused)),
|
||||||
|
@ -311,6 +327,7 @@ of_path_of_scsi(char *of_path,
|
||||||
const char *p, *digit_string, *disk_name;
|
const char *p, *digit_string, *disk_name;
|
||||||
int host, bus, tgt, lun;
|
int host, bus, tgt, lun;
|
||||||
char *sysfs_path, disk[64];
|
char *sysfs_path, disk[64];
|
||||||
|
int ret;
|
||||||
|
|
||||||
sysfs_path = xmalloc (PATH_MAX);
|
sysfs_path = xmalloc (PATH_MAX);
|
||||||
|
|
||||||
|
@ -322,13 +339,15 @@ of_path_of_scsi(char *of_path,
|
||||||
|
|
||||||
if (vendor_is_ATA(sysfs_path))
|
if (vendor_is_ATA(sysfs_path))
|
||||||
{
|
{
|
||||||
__of_path_common(of_path, sysfs_path, device, tgt);
|
ret = __of_path_common(of_path, sysfs_path, device, tgt);
|
||||||
free (sysfs_path);
|
free (sysfs_path);
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
find_obppath(of_path, sysfs_path);
|
ret = find_obppath(of_path, sysfs_path);
|
||||||
free (sysfs_path);
|
free (sysfs_path);
|
||||||
|
if (ret)
|
||||||
|
return 1;
|
||||||
|
|
||||||
if (strstr (of_path, "qlc"))
|
if (strstr (of_path, "qlc"))
|
||||||
strcat (of_path, "/fp@0,0");
|
strcat (of_path, "/fp@0,0");
|
||||||
|
@ -351,6 +370,7 @@ of_path_of_scsi(char *of_path,
|
||||||
sprintf(disk, "/%s@%x,%d:%c", disk_name, tgt, lun, 'a' + (part - 1));
|
sprintf(disk, "/%s@%x,%d:%c", disk_name, tgt, lun, 'a' + (part - 1));
|
||||||
}
|
}
|
||||||
strcat(of_path, disk);
|
strcat(of_path, disk);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
@ -374,6 +394,7 @@ char *
|
||||||
grub_util_devname_to_ofpath (const char *devname)
|
grub_util_devname_to_ofpath (const char *devname)
|
||||||
{
|
{
|
||||||
char *name_buf, *device, *devnode, *devicenode, *ofpath;
|
char *name_buf, *device, *devnode, *devicenode, *ofpath;
|
||||||
|
int ret;
|
||||||
|
|
||||||
name_buf = xmalloc (PATH_MAX);
|
name_buf = xmalloc (PATH_MAX);
|
||||||
name_buf = realpath (devname, name_buf);
|
name_buf = realpath (devname, name_buf);
|
||||||
|
@ -387,25 +408,37 @@ grub_util_devname_to_ofpath (const char *devname)
|
||||||
ofpath = xmalloc (OF_PATH_MAX);
|
ofpath = xmalloc (OF_PATH_MAX);
|
||||||
|
|
||||||
if (device[0] == 'h' && device[1] == 'd')
|
if (device[0] == 'h' && device[1] == 'd')
|
||||||
of_path_of_ide(ofpath, name_buf, device, devnode, devicenode);
|
ret = of_path_of_ide(ofpath, name_buf, device, devnode, devicenode);
|
||||||
else if (device[0] == 's'
|
else if (device[0] == 's'
|
||||||
&& (device[1] == 'd' || device[1] == 'r'))
|
&& (device[1] == 'd' || device[1] == 'r'))
|
||||||
of_path_of_scsi(ofpath, name_buf, device, devnode, devicenode);
|
ret = of_path_of_scsi(ofpath, name_buf, device, devnode, devicenode);
|
||||||
else if (device[0] == 'v' && device[1] == 'd' && device[2] == 'i'
|
else if (device[0] == 'v' && device[1] == 'd' && device[2] == 'i'
|
||||||
&& device[3] == 's' && device[4] == 'k')
|
&& device[3] == 's' && device[4] == 'k')
|
||||||
of_path_of_vdisk(ofpath, name_buf, device, devnode, devicenode);
|
ret = of_path_of_vdisk(ofpath, name_buf, device, devnode, devicenode);
|
||||||
else if (device[0] == 'f' && device[1] == 'd'
|
else if (device[0] == 'f' && device[1] == 'd'
|
||||||
&& device[2] == '0' && device[3] == '\0')
|
&& device[2] == '0' && device[3] == '\0')
|
||||||
/* All the models I've seen have a devalias "floppy".
|
/* All the models I've seen have a devalias "floppy".
|
||||||
New models have no floppy at all. */
|
New models have no floppy at all. */
|
||||||
strcpy (ofpath, "floppy");
|
{
|
||||||
|
strcpy (ofpath, "floppy");
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
grub_util_error (_("unknown device type %s\n"), device);
|
{
|
||||||
|
grub_util_warn (_("unknown device type %s\n"), device);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
free (devnode);
|
free (devnode);
|
||||||
free (devicenode);
|
free (devicenode);
|
||||||
free (name_buf);
|
free (name_buf);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
free (ofpath);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return ofpath;
|
return ofpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue