merge mainline into bidi
This commit is contained in:
commit
99bfe57386
109 changed files with 3099 additions and 839 deletions
108
util/getroot.c
108
util/getroot.c
|
@ -79,103 +79,6 @@ xgetcwd (void)
|
|||
return path;
|
||||
}
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
/* Convert POSIX path to Win32 path,
|
||||
remove drive letter, replace backslashes. */
|
||||
static char *
|
||||
get_win32_path (const char *path)
|
||||
{
|
||||
char winpath[PATH_MAX];
|
||||
cygwin_conv_to_full_win32_path (path, winpath);
|
||||
|
||||
int len = strlen (winpath);
|
||||
if (len > 2 && winpath[1] == ':')
|
||||
{
|
||||
len -= 2;
|
||||
memmove (winpath, winpath + 2, len + 1);
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
if (winpath[i] == '\\')
|
||||
winpath[i] = '/';
|
||||
return xstrdup (winpath);
|
||||
}
|
||||
#endif
|
||||
|
||||
char *
|
||||
grub_get_prefix (const char *dir)
|
||||
{
|
||||
char *saved_cwd;
|
||||
char *abs_dir, *prev_dir;
|
||||
char *prefix;
|
||||
struct stat st, prev_st;
|
||||
|
||||
/* Save the current directory. */
|
||||
saved_cwd = xgetcwd ();
|
||||
|
||||
if (chdir (dir) < 0)
|
||||
grub_util_error ("cannot change directory to `%s'", dir);
|
||||
|
||||
abs_dir = xgetcwd ();
|
||||
strip_extra_slashes (abs_dir);
|
||||
prev_dir = xstrdup (abs_dir);
|
||||
|
||||
if (stat (".", &prev_st) < 0)
|
||||
grub_util_error ("cannot stat `%s'", dir);
|
||||
|
||||
if (! S_ISDIR (prev_st.st_mode))
|
||||
grub_util_error ("`%s' is not a directory", dir);
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (chdir ("..") < 0)
|
||||
grub_util_error ("cannot change directory to the parent");
|
||||
|
||||
if (stat (".", &st) < 0)
|
||||
grub_util_error ("cannot stat current directory");
|
||||
|
||||
if (! S_ISDIR (st.st_mode))
|
||||
grub_util_error ("current directory is not a directory???");
|
||||
|
||||
if (prev_st.st_dev != st.st_dev || prev_st.st_ino == st.st_ino)
|
||||
break;
|
||||
|
||||
free (prev_dir);
|
||||
prev_dir = xgetcwd ();
|
||||
prev_st = st;
|
||||
}
|
||||
|
||||
strip_extra_slashes (prev_dir);
|
||||
prefix = xmalloc (strlen (abs_dir) - strlen (prev_dir) + 2);
|
||||
prefix[0] = '/';
|
||||
strcpy (prefix + 1, abs_dir + strlen (prev_dir));
|
||||
strip_extra_slashes (prefix);
|
||||
|
||||
if (chdir (saved_cwd) < 0)
|
||||
grub_util_error ("cannot change directory to `%s'", dir);
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
|
||||
{
|
||||
/* Reached some mount point not below /cygdrive.
|
||||
GRUB does not know Cygwin's emulated mounts,
|
||||
convert to Win32 path. */
|
||||
grub_util_info ("Cygwin prefix = %s", prefix);
|
||||
char * wprefix = get_win32_path (prefix);
|
||||
free (prefix);
|
||||
prefix = wprefix;
|
||||
}
|
||||
#endif
|
||||
|
||||
free (saved_cwd);
|
||||
free (abs_dir);
|
||||
free (prev_dir);
|
||||
|
||||
grub_util_info ("prefix = %s", prefix);
|
||||
return prefix;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
static char *
|
||||
|
@ -264,10 +167,17 @@ find_root_device (const char *dir, dev_t dev)
|
|||
/* Found! */
|
||||
char *res;
|
||||
char *cwd;
|
||||
#if defined(__NetBSD__)
|
||||
/* Convert this block device to its character (raw) device. */
|
||||
const char *template = "%s/r%s";
|
||||
#else
|
||||
/* Keep the device name as it is. */
|
||||
const char *template = "%s/%s";
|
||||
#endif
|
||||
|
||||
cwd = xgetcwd ();
|
||||
res = xmalloc (strlen (cwd) + strlen (ent->d_name) + 2);
|
||||
sprintf (res, "%s/%s", cwd, ent->d_name);
|
||||
res = xmalloc (strlen (cwd) + strlen (ent->d_name) + 3);
|
||||
sprintf (res, template, cwd, ent->d_name);
|
||||
strip_extra_slashes (res);
|
||||
free (cwd);
|
||||
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
#include <grub/partition.h>
|
||||
#include <grub/i18n.h>
|
||||
|
||||
#include <grub_emu_init.h>
|
||||
|
||||
#define ENABLE_RELOCATABLE 0
|
||||
#include "progname.h"
|
||||
|
||||
|
@ -55,6 +53,7 @@ grub_arch_modules_addr (void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if GRUB_NO_MODULES
|
||||
grub_err_t
|
||||
grub_arch_dl_check_header (void *ehdr)
|
||||
{
|
||||
|
@ -71,6 +70,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
|
|||
|
||||
return GRUB_ERR_BAD_MODULE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
grub_reboot (void)
|
||||
|
@ -150,6 +150,10 @@ void grub_hostfs_init (void);
|
|||
void grub_hostfs_fini (void);
|
||||
void grub_host_init (void);
|
||||
void grub_host_fini (void);
|
||||
#if GRUB_NO_MODULES
|
||||
void grub_init_all (void);
|
||||
void grub_fini_all (void);
|
||||
#endif
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
|
@ -215,7 +219,9 @@ main (int argc, char *argv[])
|
|||
/* XXX: This is a bit unportable. */
|
||||
grub_util_biosdisk_init (dev_map);
|
||||
|
||||
#if GRUB_NO_MODULES
|
||||
grub_init_all ();
|
||||
#endif
|
||||
|
||||
/* Make sure that there is a root device. */
|
||||
if (! root_dev)
|
||||
|
@ -233,7 +239,10 @@ main (int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
dir = grub_get_prefix (dir);
|
||||
if (strcmp (root_dev, "host") == 0)
|
||||
dir = xstrdup (dir);
|
||||
else
|
||||
dir = make_system_path_relative_to_its_root (dir);
|
||||
prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1);
|
||||
sprintf (prefix, "(%s)%s", root_dev, dir);
|
||||
free (dir);
|
||||
|
@ -242,7 +251,9 @@ main (int argc, char *argv[])
|
|||
if (setjmp (main_env) == 0)
|
||||
grub_main ();
|
||||
|
||||
#if GRUB_NO_MODULES
|
||||
grub_fini_all ();
|
||||
#endif
|
||||
grub_hostfs_fini ();
|
||||
grub_host_fini ();
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ sbindir=@sbindir@
|
|||
libdir=@libdir@
|
||||
sysconfdir=@sysconfdir@
|
||||
package_version=@PACKAGE_VERSION@
|
||||
host_os=@host_os@
|
||||
datarootdir=@datarootdir@
|
||||
datadir=@datadir@
|
||||
pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`
|
||||
grub_prefix=`echo /boot/grub | sed ${transform}`
|
||||
grub_cfg=""
|
||||
grub_mkconfig_dir=${sysconfdir}/grub.d
|
||||
|
||||
|
@ -75,6 +75,18 @@ done
|
|||
|
||||
. ${libdir}/grub/grub-mkconfig_lib
|
||||
|
||||
case "$host_os" in
|
||||
netbsd* | openbsd*)
|
||||
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
|
||||
# instead of /boot/grub.
|
||||
grub_prefix=`echo /grub | sed ${transform}`
|
||||
;;
|
||||
*)
|
||||
# Use /boot/grub by default.
|
||||
grub_prefix=`echo /boot/grub | sed ${transform}`
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "x$EUID" = "x" ] ; then
|
||||
EUID=`id -u`
|
||||
fi
|
||||
|
@ -141,13 +153,13 @@ if [ "x${GRUB_TERMINAL}" != "x" ] ; then
|
|||
fi
|
||||
|
||||
termoutdefault=0
|
||||
if [ "x${GRUB_TERMINAL_OUTPUT}" == x ]; then
|
||||
if [ "x${GRUB_TERMINAL_OUTPUT}" = "x" ]; then
|
||||
GRUB_TERMINAL_OUTPUT=gfxterm;
|
||||
termoutdefault=1;
|
||||
fi
|
||||
|
||||
for x in ${GRUB_TERMINAL_OUTPUT}; do
|
||||
if [ x${x} == xgfxterm ]; then
|
||||
if [ "x${x}" = "xgfxterm" ]; then
|
||||
# If this platform supports gfxterm, try to use it.
|
||||
if ! test -e ${grub_prefix}/gfxterm.mod ; then
|
||||
if [ "x$termoutdefault" != "x1" ]; then
|
||||
|
@ -227,11 +239,14 @@ export GRUB_DEFAULT \
|
|||
GRUB_DISTRIBUTOR \
|
||||
GRUB_CMDLINE_LINUX \
|
||||
GRUB_CMDLINE_LINUX_DEFAULT \
|
||||
GRUB_CMDLINE_NETBSD \
|
||||
GRUB_CMDLINE_NETBSD_DEFAULT \
|
||||
GRUB_TERMINAL_INPUT \
|
||||
GRUB_TERMINAL_OUTPUT \
|
||||
GRUB_SERIAL_COMMAND \
|
||||
GRUB_DISABLE_LINUX_UUID \
|
||||
GRUB_DISABLE_LINUX_RECOVERY \
|
||||
GRUB_DISABLE_NETBSD_RECOVERY \
|
||||
GRUB_GFXMODE \
|
||||
GRUB_BACKGROUND \
|
||||
GRUB_THEME \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Helper library for grub-mkconfig
|
||||
# Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
#
|
||||
# GRUB is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -31,6 +31,12 @@ if test "x$grub_mkrelpath" = x; then
|
|||
grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
|
||||
fi
|
||||
|
||||
if $(which gettext >/dev/null 2>/dev/null) ; then
|
||||
gettext="gettext"
|
||||
else
|
||||
gettext="echo"
|
||||
fi
|
||||
|
||||
grub_warn ()
|
||||
{
|
||||
echo "Warning: $@" >&2
|
||||
|
@ -38,21 +44,7 @@ grub_warn ()
|
|||
|
||||
make_system_path_relative_to_its_root ()
|
||||
{
|
||||
path="`${grub_mkrelpath} $1`"
|
||||
|
||||
case "`uname 2>/dev/null`" in
|
||||
CYGWIN*)
|
||||
# Cygwin: Check if regular or emulated mount.
|
||||
if [ -z "$dir" ] || [ "`stat -c %D "$dir/.."`" != 620000 ] ; then
|
||||
# Reached some mount point not below /cygdrive.
|
||||
# GRUB does not know Cygwin's emulated mounts,
|
||||
# convert to Win32 path and remove drive letter.
|
||||
path=`cygpath -m "$path" | sed -n 's,^[A-Za-z]:,,p'`
|
||||
test ! -z "$path" || return 1
|
||||
fi ;;
|
||||
esac
|
||||
|
||||
echo "$path"
|
||||
${grub_mkrelpath} $1
|
||||
}
|
||||
|
||||
is_path_readable_by_grub ()
|
||||
|
@ -188,3 +180,7 @@ version_find_latest ()
|
|||
done
|
||||
echo "$a"
|
||||
}
|
||||
|
||||
gettext_quoted () {
|
||||
$gettext "$@" | sed "s/'/'\\\\''/g"
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ target_cpu=@target_cpu@
|
|||
native_platform=@platform@
|
||||
pkglib_DATA="@pkglib_DATA@"
|
||||
|
||||
coreboot_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-coreboot
|
||||
multiboot_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-multiboot
|
||||
pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/${target_cpu}-pc
|
||||
|
||||
# Usage: usage
|
||||
|
@ -122,45 +122,45 @@ process_input_dir ()
|
|||
}
|
||||
|
||||
if [ "${override_dir}" = "" ] ; then
|
||||
if test -e "${coreboot_dir}" ; then
|
||||
process_input_dir ${coreboot_dir} coreboot
|
||||
if test -e "${multiboot_dir}" ; then
|
||||
process_input_dir ${multiboot_dir} multiboot
|
||||
fi
|
||||
if test -e "${pc_dir}" ; then
|
||||
process_input_dir ${pc_dir} pc
|
||||
fi
|
||||
else
|
||||
process_input_dir ${override_dir} ${native_platform}
|
||||
coreboot_dir=
|
||||
multiboot_dir=
|
||||
pc_dir=
|
||||
case "${native_platform}" in
|
||||
coreboot) coreboot_dir=${override_dir} ;;
|
||||
multiboot) multiboot_dir=${override_dir} ;;
|
||||
pc) pc_dir=${override_dir} ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# build coreboot core.img
|
||||
if test -e "${coreboot_dir}" ; then
|
||||
echo "Enabling coreboot support ..."
|
||||
# build multiboot core.img
|
||||
if test -e "${multiboot_dir}" ; then
|
||||
echo "Enabling multiboot support ..."
|
||||
memdisk_img=`mktemp "$MKTEMP_TEMPLATE"`
|
||||
memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
|
||||
mkdir -p ${memdisk_dir}/boot/grub
|
||||
# obtain date-based UUID
|
||||
iso_uuid=$(date -u +%Y-%m-%d-%H-%M-%S-00)
|
||||
|
||||
modules="$(cat ${coreboot_dir}/partmap.lst) ${modules}"
|
||||
modules="$(cat ${multiboot_dir}/partmap.lst) ${modules}"
|
||||
cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
|
||||
search --fs-uuid --set ${iso_uuid}
|
||||
set prefix=(\${root})/boot/grub/${target_cpu}-coreboot
|
||||
set prefix=(\${root})/boot/grub/${target_cpu}-multiboot
|
||||
EOF
|
||||
(for i in ${modules} ; do
|
||||
echo "insmod $i"
|
||||
done ; \
|
||||
echo "source /boot/grub/grub.cfg") \
|
||||
> ${iso9660_dir}/boot/grub/i386-pc/grub.cfg
|
||||
> ${iso9660_dir}/boot/grub/i386-multiboot/grub.cfg
|
||||
|
||||
tar -C ${memdisk_dir} -cf ${memdisk_img} boot
|
||||
rm -rf ${memdisk_dir}
|
||||
grub-mkelfimage -d ${coreboot_dir}/ -m ${memdisk_img} -o ${iso9660_dir}/boot/multiboot.img \
|
||||
grub-mkelfimage -d ${multiboot_dir}/ -m ${memdisk_img} -o ${iso9660_dir}/boot/multiboot.img \
|
||||
memdisk tar search iso9660 configfile sh \
|
||||
ata at_keyboard
|
||||
rm -f ${memdisk_img}
|
||||
|
@ -187,7 +187,7 @@ if test -e "${pc_dir}" ; then
|
|||
echo "source /boot/grub/grub.cfg") \
|
||||
> ${iso9660_dir}/boot/grub/i386-pc/grub.cfg
|
||||
|
||||
grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -boot-info-table \
|
||||
grub_mkisofs_arguments="${grub_mkisofs_arguments} -b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-info-table \
|
||||
--embedded-boot ${embed_img}"
|
||||
fi
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ probe (const char *path, char *device_name)
|
|||
|
||||
if (path == NULL)
|
||||
{
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
|
||||
if (! grub_util_check_char_device (device_name))
|
||||
grub_util_error ("%s is not a character device", device_name);
|
||||
#else
|
||||
|
|
|
@ -132,7 +132,7 @@ Checks GRUB script configuration file for syntax errors.\n\
|
|||
\n\
|
||||
-h, --help display this message and exit\n\
|
||||
-V, --version print version information and exit\n\
|
||||
-v, --verbose print script being processed\n\
|
||||
-v, --verbose print the script as it is being processed\n\
|
||||
\n\
|
||||
Report bugs to <%s>.\n\
|
||||
", program_name,
|
||||
|
|
|
@ -76,13 +76,13 @@ menuentry "${OS}" ${CLASS} {
|
|||
EOF
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
|
||||
cat << EOF
|
||||
echo $(gettext "Loading GNU Mach ...")
|
||||
echo '$(gettext_quoted "Loading GNU Mach ...")'
|
||||
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/}
|
||||
EOF
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
|
||||
cat << EOF
|
||||
echo $(gettext "Loading the Hurd ...")
|
||||
echo '$(gettext_quoted "Loading the Hurd ...")'
|
||||
module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
|
||||
--multiboot-command-line='\${kernel-command-line}' \\
|
||||
--host-priv-port='\${host-port}' \\
|
||||
|
@ -98,13 +98,13 @@ menuentry "${OS} (recovery mode)" {
|
|||
EOF
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
|
||||
cat << EOF
|
||||
echo $(gettext "Loading GNU Mach ...")
|
||||
echo '$(gettext_quoted "Loading GNU Mach ...")'
|
||||
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s
|
||||
EOF
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
|
||||
cat << EOF
|
||||
echo $(gettext "Loading the Hurd ...")
|
||||
echo '$(gettext_quoted "Loading the Hurd ...")'
|
||||
module /hurd/${hurd_fs}.static ${hurd_fs} \\
|
||||
--multiboot-command-line='\${kernel-command-line}' \\
|
||||
--host-priv-port='\${host-port}' \\
|
||||
|
|
|
@ -23,7 +23,7 @@ libdir=@libdir@
|
|||
. ${libdir}/grub/grub-mkconfig_lib
|
||||
|
||||
export TEXTDOMAIN=@PACKAGE@
|
||||
export TEXTDOMAINDIR=@LOCALEDIR@
|
||||
export TEXTDOMAINDIR=@localedir@
|
||||
|
||||
CLASS="--class os"
|
||||
|
||||
|
@ -44,15 +44,15 @@ kfreebsd_entry ()
|
|||
version="$2"
|
||||
recovery="$3" # not used yet
|
||||
args="$4" # not used yet
|
||||
title="$(gettext "%s, with kFreeBSD %s")"
|
||||
printf "menuentry \"${title}\" ${CLASS} {\n" "${os}" "${version}"
|
||||
title="$(gettext_quoted "%s, with kFreeBSD %s")"
|
||||
printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
if [ -z "${prepare_boot_cache}" ]; then
|
||||
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
|
||||
fi
|
||||
printf '%s\n' "${prepare_boot_cache}"
|
||||
cat << EOF
|
||||
echo $(printf "$(gettext "Loading kernel of FreeBSD %s ...")" ${version})
|
||||
echo '$(printf "$(gettext_quoted "Loading kernel of FreeBSD %s ...")" ${version})'
|
||||
kfreebsd ${rel_dirname}/${basename}
|
||||
EOF
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ libdir=@libdir@
|
|||
. ${libdir}/grub/grub-mkconfig_lib
|
||||
|
||||
export TEXTDOMAIN=@PACKAGE@
|
||||
export TEXTDOMAINDIR=@LOCALEDIR@
|
||||
export TEXTDOMAINDIR=@localedir@
|
||||
|
||||
CLASS="--class gnu-linux --class gnu --class os"
|
||||
|
||||
|
@ -56,11 +56,11 @@ linux_entry ()
|
|||
recovery="$3"
|
||||
args="$4"
|
||||
if ${recovery} ; then
|
||||
title="$(gettext "%s, with Linux %s (recovery mode)")"
|
||||
title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
|
||||
else
|
||||
title="$(gettext "%s, with Linux %s")"
|
||||
title="$(gettext_quoted "%s, with Linux %s")"
|
||||
fi
|
||||
printf "menuentry \"${title}\" ${CLASS} {\n" "${os}" "${version}"
|
||||
printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
|
||||
save_default_entry | sed -e "s/^/\t/"
|
||||
|
||||
# Use ELILO's generic "efifb" when it's known to be available.
|
||||
|
@ -83,12 +83,12 @@ EOF
|
|||
fi
|
||||
printf '%s\n' "${prepare_boot_cache}"
|
||||
cat << EOF
|
||||
echo $(printf "$(gettext "Loading Linux %s ...")" ${version})
|
||||
echo '$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})'
|
||||
linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
|
||||
EOF
|
||||
if test -n "${initrd}" ; then
|
||||
cat << EOF
|
||||
echo $(gettext "Loading initial ramdisk ...")
|
||||
echo '$(gettext_quoted "Loading initial ramdisk ...")'
|
||||
initrd ${rel_dirname}/${initrd}
|
||||
EOF
|
||||
fi
|
||||
|
|
86
util/grub.d/10_netbsd.in
Normal file
86
util/grub.d/10_netbsd.in
Normal file
|
@ -0,0 +1,86 @@
|
|||
#! /bin/sh -e
|
||||
|
||||
# grub-mkconfig helper script.
|
||||
# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
#
|
||||
# GRUB is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GRUB is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
bindir=@bindir@
|
||||
libdir=@libdir@
|
||||
. ${libdir}/grub/grub-mkconfig_lib
|
||||
|
||||
export TEXTDOMAIN=@PACKAGE@
|
||||
export TEXTDOMAINDIR=@localedir@
|
||||
|
||||
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
|
||||
OS=NetBSD
|
||||
else
|
||||
OS="${GRUB_DISTRIBUTOR} NetBSD"
|
||||
fi
|
||||
|
||||
netbsd_entry ()
|
||||
{
|
||||
loader="$1" # "knetbsd" or "multiboot"
|
||||
kernel="$2" # absolute path to the kernel file
|
||||
recovery="$3" # is this is a recovery entry?
|
||||
args="$4" # extra arguments appended to loader command
|
||||
|
||||
kroot_device="$(echo ${GRUB_DEVICE} | sed -e 's,^/dev/r,,')"
|
||||
if ${recovery} ; then
|
||||
title="$(gettext_quoted "%s, with kernel %s (via %s, recovery mode)")"
|
||||
else
|
||||
title="$(gettext_quoted "%s, with kernel %s (via %s)")"
|
||||
fi
|
||||
|
||||
printf "menuentry \"${title}\" {\n" \
|
||||
"${OS}" "$(echo ${kernel} | sed -e 's,^.*/,,')" "${loader}"
|
||||
printf "%s\n" "${prepare_boot_cache}"
|
||||
case "${loader}" in
|
||||
knetbsd)
|
||||
printf "\tknetbsd %s -r %s %s\n" \
|
||||
"${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
|
||||
;;
|
||||
multiboot)
|
||||
printf "\tmultiboot %s %s root=%s %s\n" \
|
||||
"${kernel}" "${kernel}" "${kroot_device}" "${GRUB_CMDLINE_NETBSD} ${args}"
|
||||
;;
|
||||
esac
|
||||
printf "}\n"
|
||||
}
|
||||
|
||||
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e 's,^, ,')"
|
||||
|
||||
# We look for NetBSD kernels in / but not in subdirectories. We simply
|
||||
# pick all statically linked ELF executable files (or links) in / with a
|
||||
# name that starts with `netbsd'.
|
||||
pattern="^ELF[^,]*executable.*statically linked"
|
||||
for k in $(ls -t /netbsd*) ; do
|
||||
if ! grub_file_is_not_garbage "$k" ; then
|
||||
continue
|
||||
fi
|
||||
if ! ((file -bL "$k" | grep -q "${pattern}") ||
|
||||
(zcat "$k" | file -bL - | grep -q "${pattern}")) 2>/dev/null ; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Found NetBSD kernel: $k" >&2
|
||||
netbsd_entry "knetbsd" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
|
||||
netbsd_entry "multiboot" "$k" false "${GRUB_CMDLINE_NETBSD_DEFAULT}"
|
||||
if [ "x${GRUB_DISABLE_NETBSD_RECOVERY}" != "xtrue" ]; then
|
||||
netbsd_entry "knetbsd" "$k" true "-s"
|
||||
netbsd_entry "multiboot" "$k" true "-s"
|
||||
fi
|
||||
done
|
160
util/hostdisk.c
160
util/hostdisk.c
|
@ -98,6 +98,18 @@ struct hd_geometry
|
|||
# include <sys/disk.h>
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/disklabel.h> /* struct disklabel */
|
||||
# ifdef HAVE_GETRAWPARTITION
|
||||
# include <util.h> /* getrawpartition */
|
||||
# endif /* HAVE_GETRAWPARTITION */
|
||||
# include <sys/fdio.h>
|
||||
# ifndef RAW_FLOPPY_MAJOR
|
||||
# define RAW_FLOPPY_MAJOR 9
|
||||
# endif /* ! RAW_FLOPPY_MAJOR */
|
||||
#endif /* defined(__NetBSD__) */
|
||||
|
||||
struct
|
||||
{
|
||||
char *drive;
|
||||
|
@ -129,6 +141,31 @@ have_devfs (void)
|
|||
}
|
||||
#endif /* __linux__ */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
/* Adjust device driver parameters. This function should be called just
|
||||
after successfully opening the device. For now, it simply prevents the
|
||||
floppy driver from retrying operations on failure, as otherwise the
|
||||
driver takes a while to abort when there is no floppy in the drive. */
|
||||
static void
|
||||
configure_device_driver (int fd)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
|
||||
return;
|
||||
if (major(st.st_rdev) == RAW_FLOPPY_MAJOR)
|
||||
{
|
||||
int floppy_opts;
|
||||
|
||||
if (ioctl (fd, FDIOCGETOPTS, &floppy_opts) == -1)
|
||||
return;
|
||||
floppy_opts |= FDOPT_NORETRY;
|
||||
if (ioctl (fd, FDIOCSETOPTS, &floppy_opts) == -1)
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif /* defined(__NetBSD__) */
|
||||
|
||||
static int
|
||||
find_grub_drive (const char *name)
|
||||
{
|
||||
|
@ -204,16 +241,20 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__) || \
|
||||
defined(__FreeBSD_kernel__) || defined(__APPLE__)
|
||||
defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
|
||||
{
|
||||
# if defined(__NetBSD__)
|
||||
struct disklabel label;
|
||||
# else
|
||||
unsigned long long nr;
|
||||
# endif
|
||||
int fd;
|
||||
|
||||
fd = open (map[drive].device, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
|
||||
|
||||
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
|
||||
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
|
||||
if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
|
||||
# else
|
||||
if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode))
|
||||
|
@ -227,6 +268,9 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
if (ioctl (fd, DIOCGMEDIASIZE, &nr))
|
||||
# elif defined(__APPLE__)
|
||||
if (ioctl (fd, DKIOCGETBLOCKCOUNT, &nr))
|
||||
# elif defined(__NetBSD__)
|
||||
configure_device_driver (fd);
|
||||
if (ioctl (fd, DIOCGDINFO, &label) == -1)
|
||||
# else
|
||||
if (ioctl (fd, BLKGETSIZE64, &nr))
|
||||
# endif
|
||||
|
@ -237,14 +281,16 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
|
||||
close (fd);
|
||||
|
||||
#if defined (__APPLE__)
|
||||
# if defined (__APPLE__)
|
||||
disk->total_sectors = nr;
|
||||
#else
|
||||
# elif defined(__NetBSD__)
|
||||
disk->total_sectors = label.d_secperunit;
|
||||
# else
|
||||
disk->total_sectors = nr / 512;
|
||||
|
||||
if (nr % 512)
|
||||
grub_util_error ("unaligned device size");
|
||||
#endif
|
||||
# endif
|
||||
|
||||
grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
|
||||
|
||||
|
@ -483,6 +529,10 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
|||
}
|
||||
#endif /* ! __linux__ */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
configure_device_driver (fd);
|
||||
#endif /* defined(__NetBSD__) */
|
||||
|
||||
#if defined(__linux__) && (!defined(__GLIBC__) || \
|
||||
((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))))
|
||||
/* Maybe libc doesn't have large file support. */
|
||||
|
@ -811,7 +861,7 @@ make_device_name (int drive, int dos_part, int bsd_part)
|
|||
dos_part_str = xasprintf (",%d", dos_part + 1);
|
||||
|
||||
if (bsd_part >= 0)
|
||||
bsd_part_str = xasprintf (",%c", dos_part + 'a');
|
||||
bsd_part_str = xasprintf (",%d", bsd_part + 1);
|
||||
|
||||
ret = xasprintf ("%s%s%s", map[drive].drive,
|
||||
dos_part_str ? : "",
|
||||
|
@ -981,6 +1031,27 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
}
|
||||
return path;
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
/* NetBSD uses "/dev/r[wsc]d[0-9]+[a-z]". */
|
||||
char *path = xstrdup (os_dev);
|
||||
if (strncmp ("/dev/rwd", path, 8) == 0 ||
|
||||
strncmp ("/dev/rsd", path, 8) == 0 ||
|
||||
strncmp ("/dev/rcd", path, 8) == 0)
|
||||
{
|
||||
char *q;
|
||||
q = path + strlen(path) - 1; /* last character */
|
||||
if (grub_isalpha(*q) && grub_isdigit(*(q-1)))
|
||||
{
|
||||
int rawpart = -1;
|
||||
# ifdef HAVE_GETRAWPARTITION
|
||||
rawpart = getrawpartition();
|
||||
# endif /* HAVE_GETRAWPARTITION */
|
||||
if (rawpart >= 0)
|
||||
*q = 'a' + rawpart;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
|
||||
#else
|
||||
# warning "The function `convert_system_partition_to_system_disk' might not work on your OS correctly."
|
||||
return xstrdup (os_dev);
|
||||
|
@ -999,6 +1070,26 @@ device_is_wholedisk (const char *os_dev)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
/* Try to determine whether a given device name corresponds to a whole disk.
|
||||
This function should give in most cases a definite answer, but it may
|
||||
actually give an approximate one in the following sense: if the return
|
||||
value is 0 then the device name does not correspond to a whole disk. */
|
||||
static int
|
||||
device_is_wholedisk (const char *os_dev)
|
||||
{
|
||||
int len = strlen (os_dev);
|
||||
int rawpart = -1;
|
||||
|
||||
# ifdef HAVE_GETRAWPARTITION
|
||||
rawpart = getrawpartition();
|
||||
# endif /* HAVE_GETRAWPARTITION */
|
||||
if (rawpart < 0)
|
||||
return 1;
|
||||
return (os_dev[len - 1] == ('a' + rawpart));
|
||||
}
|
||||
#endif /* defined(__NetBSD__) */
|
||||
|
||||
static int
|
||||
find_system_device (const char *os_dev)
|
||||
{
|
||||
|
@ -1042,7 +1133,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
drive = find_system_device (os_dev);
|
||||
if (drive < 0)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
||||
"no mapping exists for `%s'", os_dev);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1051,14 +1142,14 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
== 0)
|
||||
return make_device_name (drive, -1, -1);
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
|
||||
if (! S_ISCHR (st.st_mode))
|
||||
#else
|
||||
if (! S_ISBLK (st.st_mode))
|
||||
#endif
|
||||
return make_device_name (drive, -1, -1);
|
||||
|
||||
#if defined(__linux__) || defined(__CYGWIN__)
|
||||
#if defined(__linux__) || defined(__CYGWIN__) || defined(__NetBSD__)
|
||||
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
|
||||
partition, so mapping them to GRUB devices is not trivial.
|
||||
Here, get the start sector of a partition by HDIO_GETGEO, and
|
||||
|
@ -1066,12 +1157,22 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
|
||||
Cygwin /dev/sdXN emulation uses Windows partition mapping. It
|
||||
does not count the extended partition and missing primary
|
||||
partitions. Use same method as on Linux here. */
|
||||
partitions. Use same method as on Linux here.
|
||||
|
||||
For NetBSD, proceed as for Linux, except that the start sector is
|
||||
obtained from the disk label. */
|
||||
{
|
||||
char *name;
|
||||
grub_disk_t disk;
|
||||
int fd;
|
||||
# if !defined(__NetBSD__)
|
||||
struct hd_geometry hdg;
|
||||
typeof (hdg.start) p_offset;
|
||||
# else /* defined(__NetBSD__) */
|
||||
struct disklabel label;
|
||||
int index;
|
||||
u_int32_t p_offset;
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
int dos_part = -1;
|
||||
int bsd_part = -1;
|
||||
auto int find_partition (grub_disk_t dsk,
|
||||
|
@ -1086,7 +1187,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
|
||||
part_start = grub_partition_get_start (partition);
|
||||
|
||||
if (hdg.start == part_start)
|
||||
if (p_offset == part_start)
|
||||
{
|
||||
if (partition->parent)
|
||||
{
|
||||
|
@ -1107,8 +1208,15 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
|
||||
name = make_device_name (drive, -1, -1);
|
||||
|
||||
# if !defined(__NetBSD__)
|
||||
if (MAJOR (st.st_rdev) == FLOPPY_MAJOR)
|
||||
return name;
|
||||
# else /* defined(__NetBSD__) */
|
||||
/* Since os_dev and convert_system_partition_to_system_disk (os_dev) are
|
||||
* different, we know that os_dev is of the form /dev/r[wsc]d[0-9]+[a-z]
|
||||
* and in particular it cannot be a floppy device. */
|
||||
index = os_dev[strlen(os_dev) - 1] - 'a';
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
|
||||
fd = open (os_dev, O_RDONLY);
|
||||
if (fd == -1)
|
||||
|
@ -1118,10 +1226,15 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
# if !defined(__NetBSD__)
|
||||
if (ioctl (fd, HDIO_GETGEO, &hdg))
|
||||
# else /* defined(__NetBSD__) */
|
||||
configure_device_driver (fd);
|
||||
if (ioctl (fd, DIOCGDINFO, &label) == -1)
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
"cannot get geometry of `%s'", os_dev);
|
||||
"cannot get disk geometry of `%s'", os_dev);
|
||||
close (fd);
|
||||
free (name);
|
||||
return 0;
|
||||
|
@ -1129,9 +1242,22 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
|
||||
close (fd);
|
||||
|
||||
grub_util_info ("%s starts from %lu", os_dev, hdg.start);
|
||||
# if !defined(__NetBSD__)
|
||||
p_offset = hdg.start;
|
||||
# else /* defined(__NetBSD__) */
|
||||
if (index >= label.d_npartitions)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
"no disk label entry for `%s'", os_dev);
|
||||
free (name);
|
||||
return 0;
|
||||
}
|
||||
p_offset = label.d_partitions[index].p_offset;
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
|
||||
if (hdg.start == 0 && device_is_wholedisk (os_dev))
|
||||
grub_util_info ("%s starts from %lu", os_dev, p_offset);
|
||||
|
||||
if (p_offset == 0 && device_is_wholedisk (os_dev))
|
||||
return name;
|
||||
|
||||
grub_util_info ("opening the device %s", name);
|
||||
|
@ -1226,3 +1352,9 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
return make_device_name (drive, -1, -1);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *
|
||||
grub_util_biosdisk_get_osdev (grub_disk_t disk)
|
||||
{
|
||||
return map[disk->id].device;
|
||||
}
|
||||
|
|
|
@ -368,7 +368,7 @@ strip_trailing_digits (const char *p)
|
|||
}
|
||||
|
||||
char *
|
||||
grub_util_devname_to_ofpath (char *devname)
|
||||
grub_util_devname_to_ofpath (const char *devname)
|
||||
{
|
||||
char *name_buf, *device, *devnode, *devicenode, *ofpath;
|
||||
|
||||
|
|
116
util/misc.c
116
util/misc.c
|
@ -35,6 +35,7 @@
|
|||
#endif
|
||||
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/cache.h>
|
||||
#include <grub/util/misc.h>
|
||||
|
@ -52,6 +53,11 @@
|
|||
# include <malloc.h>
|
||||
#endif
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
# include <sys/cygwin.h>
|
||||
# define DEV_CYGDRIVE_MAJOR 98
|
||||
#endif
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <windows.h>
|
||||
#include <winioctl.h>
|
||||
|
@ -262,56 +268,6 @@ grub_util_write_image (const char *img, size_t size, FILE *out)
|
|||
grub_util_error ("write failed");
|
||||
}
|
||||
|
||||
void *
|
||||
grub_malloc (grub_size_t size)
|
||||
{
|
||||
return xmalloc (size);
|
||||
}
|
||||
|
||||
void *
|
||||
grub_zalloc (grub_size_t size)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
ret = xmalloc (size);
|
||||
memset (ret, 0, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
grub_free (void *ptr)
|
||||
{
|
||||
free (ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
grub_realloc (void *ptr, grub_size_t size)
|
||||
{
|
||||
return xrealloc (ptr, size);
|
||||
}
|
||||
|
||||
void *
|
||||
grub_memalign (grub_size_t align, grub_size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
#if defined(HAVE_POSIX_MEMALIGN)
|
||||
if (posix_memalign (&p, align, size) != 0)
|
||||
p = 0;
|
||||
#elif defined(HAVE_MEMALIGN)
|
||||
p = memalign (align, size);
|
||||
#else
|
||||
(void) align;
|
||||
(void) size;
|
||||
grub_util_error ("grub_memalign is not supported");
|
||||
#endif
|
||||
|
||||
if (! p)
|
||||
grub_util_error ("out of memory");
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Some functions that we don't use. */
|
||||
void
|
||||
grub_mm_init_region (void *addr __attribute__ ((unused)),
|
||||
|
@ -319,10 +275,12 @@ grub_mm_init_region (void *addr __attribute__ ((unused)),
|
|||
{
|
||||
}
|
||||
|
||||
#if GRUB_NO_MODULES
|
||||
void
|
||||
grub_register_exported_symbols (void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
grub_exit (void)
|
||||
|
@ -374,7 +332,7 @@ grub_millisleep (grub_uint32_t ms)
|
|||
|
||||
#endif
|
||||
|
||||
#if !(defined (__i386__) || defined (__x86_64__))
|
||||
#if !(defined (__i386__) || defined (__x86_64__)) && GRUB_NO_MODULES
|
||||
void
|
||||
grub_arch_sync_caches (void *address __attribute__ ((unused)),
|
||||
grub_size_t len __attribute__ ((unused)))
|
||||
|
@ -503,6 +461,27 @@ canonicalize_file_name (const char *path)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
/* Convert POSIX path to Win32 path,
|
||||
remove drive letter, replace backslashes. */
|
||||
static char *
|
||||
get_win32_path (const char *path)
|
||||
{
|
||||
char winpath[PATH_MAX];
|
||||
if (cygwin_conv_path (CCP_POSIX_TO_WIN_A, path, winpath, sizeof(winpath)))
|
||||
grub_util_error ("cygwin_conv_path() failed");
|
||||
|
||||
int len = strlen (winpath);
|
||||
int offs = (len > 2 && winpath[1] == ':' ? 2 : 0);
|
||||
|
||||
int i;
|
||||
for (i = offs; i < len; i++)
|
||||
if (winpath[i] == '\\')
|
||||
winpath[i] = '/';
|
||||
return xstrdup (winpath + offs);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function never prints trailing slashes (so that its output
|
||||
can be appended a slash unconditionally). */
|
||||
char *
|
||||
|
@ -568,30 +547,31 @@ make_system_path_relative_to_its_root (const char *path)
|
|||
/* offset == 1 means root directory. */
|
||||
if (offset == 1)
|
||||
{
|
||||
free (buf);
|
||||
len = strlen (buf2);
|
||||
while (buf2[len - 1] == '/' && len > 1)
|
||||
{
|
||||
buf2[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
if (len > 1)
|
||||
return buf2;
|
||||
else
|
||||
{
|
||||
/* This means path given is just a backslash. As above
|
||||
we have to return an empty string. */
|
||||
free (buf2);
|
||||
return xstrdup ("");
|
||||
}
|
||||
/* Include leading slash. */
|
||||
offset = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free (buf);
|
||||
buf3 = xstrdup (buf2 + offset);
|
||||
free (buf2);
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
|
||||
{
|
||||
/* Reached some mount point not below /cygdrive.
|
||||
GRUB does not know Cygwin's emulated mounts,
|
||||
convert to Win32 path. */
|
||||
grub_util_info ("Cygwin path = %s\n", buf3);
|
||||
char * temp = get_win32_path (buf3);
|
||||
free (buf3);
|
||||
buf3 = temp;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Remove trailing slashes, return empty string if root directory. */
|
||||
len = strlen (buf3);
|
||||
while (buf3[len - 1] == '/' && len > 1)
|
||||
while (len > 0 && buf3[len - 1] == '/')
|
||||
{
|
||||
buf3[len - 1] = '\0';
|
||||
len--;
|
||||
|
|
85
util/mm.c
Normal file
85
util/mm.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
grub_malloc (grub_size_t size)
|
||||
{
|
||||
void *ret;
|
||||
ret = malloc (size);
|
||||
if (!ret)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *
|
||||
grub_zalloc (grub_size_t size)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
ret = grub_malloc (size);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
memset (ret, 0, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
grub_free (void *ptr)
|
||||
{
|
||||
free (ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
grub_realloc (void *ptr, grub_size_t size)
|
||||
{
|
||||
void *ret;
|
||||
ret = realloc (ptr, size);
|
||||
if (!ret)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *
|
||||
grub_memalign (grub_size_t align, grub_size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
#if defined(HAVE_POSIX_MEMALIGN)
|
||||
if (align < sizeof (void *))
|
||||
align = sizeof (void *);
|
||||
if (posix_memalign (&p, align, size) != 0)
|
||||
p = 0;
|
||||
#elif defined(HAVE_MEMALIGN)
|
||||
p = memalign (align, size);
|
||||
#else
|
||||
(void) align;
|
||||
(void) size;
|
||||
grub_util_error ("grub_memalign is not supported");
|
||||
#endif
|
||||
|
||||
if (!p)
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
|
||||
return p;
|
||||
}
|
|
@ -35,6 +35,7 @@
|
|||
#include <grub/term.h>
|
||||
#include <grub/util/raid.h>
|
||||
#include <grub/util/lvm.h>
|
||||
#include <grub/util/ofpath.h>
|
||||
|
||||
#include <grub_setup_init.h>
|
||||
|
||||
|
@ -102,28 +103,6 @@ grub_refresh (void)
|
|||
fflush (stdout);
|
||||
}
|
||||
|
||||
static char *compute_dest_ofpath (const char *dest)
|
||||
{
|
||||
int len = strlen (dest);
|
||||
char *res, *p, c;
|
||||
|
||||
res = xmalloc (len);
|
||||
p = res;
|
||||
while ((c = *dest++) != '\0')
|
||||
{
|
||||
if (c == '\\' && *dest == ',')
|
||||
{
|
||||
*p++ = ',';
|
||||
dest++;
|
||||
}
|
||||
else
|
||||
*p++ = c;
|
||||
}
|
||||
*p++ = '\0';
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
setup (const char *prefix, const char *dir,
|
||||
const char *boot_file, const char *core_file,
|
||||
|
@ -134,8 +113,8 @@ setup (const char *prefix, const char *dir,
|
|||
size_t boot_size, core_size;
|
||||
grub_uint16_t core_sectors;
|
||||
grub_device_t root_dev, dest_dev;
|
||||
char *boot_devpath, *dest_ofpath;
|
||||
grub_disk_addr_t *kernel_sector;
|
||||
char *boot_devpath;
|
||||
grub_disk_addr_t *kernel_byte;
|
||||
struct boot_blocklist *first_block, *block;
|
||||
char *tmp_img;
|
||||
int i;
|
||||
|
@ -194,8 +173,6 @@ setup (const char *prefix, const char *dir,
|
|||
last_length = length;
|
||||
}
|
||||
|
||||
dest_ofpath = compute_dest_ofpath (dest);
|
||||
|
||||
/* Read the boot image by the OS service. */
|
||||
boot_path = grub_util_get_path (dir, boot_file);
|
||||
boot_size = grub_util_get_image_size (boot_path);
|
||||
|
@ -209,9 +186,9 @@ setup (const char *prefix, const char *dir,
|
|||
boot_devpath = (char *) (boot_img
|
||||
+ GRUB_BOOT_AOUT_HEADER_SIZE
|
||||
+ GRUB_BOOT_MACHINE_BOOT_DEVPATH);
|
||||
kernel_sector = (grub_disk_addr_t *) (boot_img
|
||||
+ GRUB_BOOT_AOUT_HEADER_SIZE
|
||||
+ GRUB_BOOT_MACHINE_KERNEL_SECTOR);
|
||||
kernel_byte = (grub_disk_addr_t *) (boot_img
|
||||
+ GRUB_BOOT_AOUT_HEADER_SIZE
|
||||
+ GRUB_BOOT_MACHINE_KERNEL_BYTE);
|
||||
|
||||
core_path = grub_util_get_path (dir, core_file);
|
||||
core_size = grub_util_get_image_size (core_path);
|
||||
|
@ -228,8 +205,7 @@ setup (const char *prefix, const char *dir,
|
|||
+ GRUB_DISK_SECTOR_SIZE
|
||||
- sizeof (*block));
|
||||
|
||||
grub_util_info ("root is `%s', dest is `%s', and dest_ofpath is `%s'",
|
||||
root, dest, dest_ofpath);
|
||||
grub_util_info ("root is `%s', dest is `%s'", root, dest);
|
||||
|
||||
/* Open the root device and the destination device. */
|
||||
grub_util_info ("Opening root");
|
||||
|
@ -350,14 +326,30 @@ setup (const char *prefix, const char *dir,
|
|||
!= (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("failed to read the rest sectors of the core image");
|
||||
|
||||
if (file->device->disk->id != dest_dev->disk->id)
|
||||
{
|
||||
const char *dest_ofpath;
|
||||
dest_ofpath
|
||||
= grub_util_devname_to_ofpath (grub_util_biosdisk_get_osdev (file->device->disk));
|
||||
grub_util_info ("dest_ofpath is `%s'", dest_ofpath);
|
||||
strncpy (boot_devpath, dest_ofpath, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
|
||||
- GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1);
|
||||
boot_devpath[GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
|
||||
- GRUB_BOOT_MACHINE_BOOT_DEVPATH - 1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_util_info ("non cross-disk install");
|
||||
memset (boot_devpath, 0, GRUB_BOOT_MACHINE_BOOT_DEVPATH_END
|
||||
- GRUB_BOOT_MACHINE_BOOT_DEVPATH);
|
||||
}
|
||||
|
||||
grub_file_close (file);
|
||||
|
||||
free (core_path);
|
||||
free (tmp_img);
|
||||
|
||||
*kernel_sector = grub_cpu_to_be64 (first_sector);
|
||||
|
||||
strcpy(boot_devpath, dest_ofpath);
|
||||
*kernel_byte = grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS);
|
||||
|
||||
grub_util_info ("boot device path %s, prefix is %s, dest is %s",
|
||||
boot_devpath, prefix, dest);
|
||||
|
@ -634,7 +626,8 @@ main (int argc, char *argv[])
|
|||
|
||||
find_dest_dev (&ginfo, argv);
|
||||
|
||||
ginfo.prefix = grub_get_prefix (ginfo.dir ? : DEFAULT_DIRECTORY);
|
||||
ginfo.prefix = make_system_path_relative_to_its_root (ginfo.dir ?
|
||||
: DEFAULT_DIRECTORY);
|
||||
|
||||
check_root_dev (&ginfo);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue