2002-12-27 08:53:07 +00:00
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-01 20:32:30 +00:00
|
|
|
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
2002-12-27 08:53:07 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2002-12-27 08:53:07 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2002-12-27 08:53:07 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2002-12-27 08:53:07 +00:00
|
|
|
* 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
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2002-12-27 08:53:07 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-13 22:50:01 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2009-11-08 00:49:15 +00:00
|
|
|
#include <errno.h>
|
2009-07-01 13:01:33 +00:00
|
|
|
#include <setjmp.h>
|
2002-12-27 08:53:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2009-11-08 00:49:15 +00:00
|
|
|
#include <stdint.h>
|
2002-12-27 08:53:07 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2005-02-27 21:19:06 +00:00
|
|
|
#include <sys/time.h>
|
2005-01-04 14:01:45 +00:00
|
|
|
#include <unistd.h>
|
2009-03-04 10:25:31 +00:00
|
|
|
#include <time.h>
|
2010-01-25 09:06:55 +00:00
|
|
|
#ifdef HAVE_LIMITS_H
|
|
|
|
#include <limits.h>
|
|
|
|
#endif
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2008-04-06 17:51:56 +00:00
|
|
|
#include <grub/kernel.h>
|
2010-02-07 16:52:11 +00:00
|
|
|
#include <grub/dl.h>
|
2008-04-06 17:51:56 +00:00
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/cache.h>
|
2004-04-04 13:46:03 +00:00
|
|
|
#include <grub/util/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/term.h>
|
2008-08-07 23:48:13 +00:00
|
|
|
#include <grub/time.h>
|
2010-01-01 20:32:30 +00:00
|
|
|
#include <grub/i18n.h>
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2010-02-07 01:37:48 +00:00
|
|
|
#define ENABLE_RELOCATABLE 0
|
2009-11-25 23:10:02 +00:00
|
|
|
#include "progname.h"
|
|
|
|
|
2006-06-13 22:50:01 +00:00
|
|
|
/* Include malloc.h, only if memalign is available. It is known that
|
|
|
|
memalign is declared in malloc.h in all systems, if present. */
|
|
|
|
#ifdef HAVE_MEMALIGN
|
|
|
|
# include <malloc.h>
|
|
|
|
#endif
|
|
|
|
|
2009-03-21 07:48:28 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winioctl.h>
|
|
|
|
#endif
|
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
int verbosity = 0;
|
|
|
|
|
2009-05-04 16:16:03 +00:00
|
|
|
void
|
|
|
|
grub_util_warn (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-01-16 00:26:52 +00:00
|
|
|
fprintf (stderr, _("%s: warn:"), program_name);
|
|
|
|
fprintf (stderr, " ");
|
2009-05-04 16:16:03 +00:00
|
|
|
va_start (ap, fmt);
|
|
|
|
vfprintf (stderr, fmt, ap);
|
|
|
|
va_end (ap);
|
2010-01-16 00:26:52 +00:00
|
|
|
fprintf (stderr, ".\n");
|
2009-05-04 16:16:03 +00:00
|
|
|
fflush (stderr);
|
|
|
|
}
|
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_info (const char *fmt, ...)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
|
|
|
if (verbosity > 0)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-01-16 00:26:52 +00:00
|
|
|
fprintf (stderr, _("%s: info:"), program_name);
|
|
|
|
fprintf (stderr, " ");
|
2002-12-27 08:53:07 +00:00
|
|
|
va_start (ap, fmt);
|
|
|
|
vfprintf (stderr, fmt, ap);
|
|
|
|
va_end (ap);
|
2010-01-17 14:42:19 +00:00
|
|
|
fprintf (stderr, ".\n");
|
2007-10-21 12:29:33 +00:00
|
|
|
fflush (stderr);
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_error (const char *fmt, ...)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-01-16 00:26:52 +00:00
|
|
|
fprintf (stderr, _("%s: error:"), program_name);
|
|
|
|
fprintf (stderr, " ");
|
2002-12-27 08:53:07 +00:00
|
|
|
va_start (ap, fmt);
|
|
|
|
vfprintf (stderr, fmt, ap);
|
|
|
|
va_end (ap);
|
2010-01-16 00:26:52 +00:00
|
|
|
fprintf (stderr, ".\n");
|
2002-12-27 08:53:07 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2010-02-07 03:23:44 +00:00
|
|
|
#ifdef GRUB_UTIL
|
2008-08-14 18:46:47 +00:00
|
|
|
int
|
|
|
|
grub_err_printf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2008-08-14 18:46:47 +00:00
|
|
|
va_start (ap, fmt);
|
|
|
|
ret = vfprintf (stderr, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-02-07 03:23:44 +00:00
|
|
|
#endif
|
2008-08-14 18:46:47 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
void *
|
|
|
|
xmalloc (size_t size)
|
|
|
|
{
|
|
|
|
void *p;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
p = malloc (size);
|
|
|
|
if (! p)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_error ("out of memory");
|
2002-12-27 08:53:07 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2003-01-02 20:12:33 +00:00
|
|
|
void *
|
|
|
|
xrealloc (void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
ptr = realloc (ptr, size);
|
|
|
|
if (! ptr)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_error ("out of memory");
|
2003-01-02 20:12:33 +00:00
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
char *
|
|
|
|
xstrdup (const char *str)
|
|
|
|
{
|
|
|
|
size_t len;
|
2010-02-07 01:37:48 +00:00
|
|
|
char *newstr;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
len = strlen (str);
|
2010-02-07 01:37:48 +00:00
|
|
|
newstr = (char *) xmalloc (len + 1);
|
|
|
|
memcpy (newstr, str, len + 1);
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2010-02-07 01:37:48 +00:00
|
|
|
return newstr;
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_get_path (const char *dir, const char *file)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
|
|
|
char *path;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
path = (char *) xmalloc (strlen (dir) + 1 + strlen (file) + 1);
|
|
|
|
sprintf (path, "%s/%s", dir, file);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2005-01-04 14:01:45 +00:00
|
|
|
size_t
|
|
|
|
grub_util_get_fp_size (FILE *fp)
|
|
|
|
{
|
|
|
|
struct stat st;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-01-04 14:01:45 +00:00
|
|
|
if (fflush (fp) == EOF)
|
|
|
|
grub_util_error ("fflush failed");
|
|
|
|
|
|
|
|
if (fstat (fileno (fp), &st) == -1)
|
|
|
|
grub_util_error ("fstat failed");
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-01-04 14:01:45 +00:00
|
|
|
return st.st_size;
|
|
|
|
}
|
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
size_t
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_get_image_size (const char *path)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
|
|
|
struct stat st;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_info ("getting the size of %s", path);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
if (stat (path, &st) == -1)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_error ("cannot stat %s", path);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
return st.st_size;
|
|
|
|
}
|
|
|
|
|
2005-01-04 14:01:45 +00:00
|
|
|
void
|
|
|
|
grub_util_read_at (void *img, size_t size, off_t offset, FILE *fp)
|
|
|
|
{
|
2008-04-02 01:49:18 +00:00
|
|
|
if (fseeko (fp, offset, SEEK_SET) == -1)
|
|
|
|
grub_util_error ("seek failed");
|
2005-01-04 14:01:45 +00:00
|
|
|
|
|
|
|
if (fread (img, 1, size, fp) != size)
|
|
|
|
grub_util_error ("read failed");
|
|
|
|
}
|
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
char *
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_read_image (const char *path)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
|
|
|
char *img;
|
|
|
|
FILE *fp;
|
|
|
|
size_t size;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_info ("reading %s", path);
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
size = grub_util_get_image_size (path);
|
2002-12-27 08:53:07 +00:00
|
|
|
img = (char *) xmalloc (size);
|
|
|
|
|
|
|
|
fp = fopen (path, "rb");
|
|
|
|
if (! fp)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_error ("cannot open %s", path);
|
2005-01-04 14:01:45 +00:00
|
|
|
|
|
|
|
grub_util_read_at (img, size, 0, fp);
|
2002-12-27 08:53:07 +00:00
|
|
|
|
2003-01-31 03:26:56 +00:00
|
|
|
fclose (fp);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
2003-01-31 03:26:56 +00:00
|
|
|
void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_load_image (const char *path, char *buf)
|
2003-01-31 03:26:56 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
size_t size;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_info ("reading %s", path);
|
2003-01-31 03:26:56 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
size = grub_util_get_image_size (path);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2003-01-31 03:26:56 +00:00
|
|
|
fp = fopen (path, "rb");
|
|
|
|
if (! fp)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_error ("cannot open %s", path);
|
2003-01-31 03:26:56 +00:00
|
|
|
|
|
|
|
if (fread (buf, 1, size, fp) != size)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_error ("cannot read %s", path);
|
2003-01-31 03:26:56 +00:00
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
|
2002-12-27 08:53:07 +00:00
|
|
|
void
|
2005-01-04 14:01:45 +00:00
|
|
|
grub_util_write_image_at (const void *img, size_t size, off_t offset, FILE *out)
|
2002-12-27 08:53:07 +00:00
|
|
|
{
|
2005-01-04 14:01:45 +00:00
|
|
|
grub_util_info ("writing 0x%x bytes at offset 0x%x", size, offset);
|
2008-04-02 01:49:18 +00:00
|
|
|
if (fseeko (out, offset, SEEK_SET) == -1)
|
2005-01-04 14:01:45 +00:00
|
|
|
grub_util_error ("seek failed");
|
2002-12-27 08:53:07 +00:00
|
|
|
if (fwrite (img, 1, size, out) != size)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_util_error ("write failed");
|
2002-12-27 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2005-01-04 14:01:45 +00:00
|
|
|
void
|
|
|
|
grub_util_write_image (const char *img, size_t size, FILE *out)
|
|
|
|
{
|
2005-01-05 13:33:16 +00:00
|
|
|
grub_util_info ("writing 0x%x bytes", size);
|
|
|
|
if (fwrite (img, 1, size, out) != size)
|
|
|
|
grub_util_error ("write failed");
|
2005-01-04 14:01:45 +00:00
|
|
|
}
|
|
|
|
|
2003-11-17 18:07:09 +00:00
|
|
|
/* Some functions that we don't use. */
|
2003-01-02 20:12:33 +00:00
|
|
|
void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_mm_init_region (void *addr __attribute__ ((unused)),
|
|
|
|
grub_size_t size __attribute__ ((unused)))
|
2003-01-02 20:12:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-02-07 14:17:26 +00:00
|
|
|
#if GRUB_NO_MODULES
|
2003-01-02 20:12:33 +00:00
|
|
|
void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_register_exported_symbols (void)
|
2003-01-02 20:12:33 +00:00
|
|
|
{
|
2003-11-17 18:07:09 +00:00
|
|
|
}
|
2010-02-07 14:17:26 +00:00
|
|
|
#endif
|
2003-11-17 18:07:09 +00:00
|
|
|
|
|
|
|
void
|
2006-04-23 13:37:36 +00:00
|
|
|
grub_exit (void)
|
2003-11-17 18:07:09 +00:00
|
|
|
{
|
|
|
|
exit (1);
|
2003-01-02 20:12:33 +00:00
|
|
|
}
|
2003-11-12 20:33:52 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_uint32_t
|
|
|
|
grub_get_rtc (void)
|
2003-11-12 20:33:52 +00:00
|
|
|
{
|
2005-02-27 21:19:06 +00:00
|
|
|
struct timeval tv;
|
2003-11-12 20:33:52 +00:00
|
|
|
|
2005-02-27 21:19:06 +00:00
|
|
|
gettimeofday (&tv, 0);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-27 21:19:06 +00:00
|
|
|
return (tv.tv_sec * GRUB_TICKS_PER_SECOND
|
|
|
|
+ (((tv.tv_sec % GRUB_TICKS_PER_SECOND) * 1000000 + tv.tv_usec)
|
|
|
|
* GRUB_TICKS_PER_SECOND / 1000000));
|
2003-11-12 20:33:52 +00:00
|
|
|
}
|
2004-12-27 Marco Gerards <metgerards@student.han.nl>
* genmk.rb: Handle the `Program' class in the main loop. Written
by Johan Rydberg <jrydberg@gnu.org>.
(Program): New class.
(programs): New variable.
* boot/powerpc/ieee1275/cmain.c: Include <grub/machine/ieee1275.h>
instead of "grub/machine/ieee1275.h". Include <grub/kernel.h>
instead of "grub/kernel.h". Include <grub/machine/init.h>.
(help_arch): Function removed.
* conf/powerpc-ieee1275.rmk (grubof_HEADERS): Add
`powerpc/libgcc.h' and `loader.h'.
(pkgdata_PROGRAMS): New variable.
(sbin_UTILITIES): Variable removed.
(grub_emu_SOURCES): Added kern/powerpc/cache.S.
(grubof_SOURCES): Variable re-defined so it only includes the
core functionality.
(grubof_CFLAGS): Remove `-DGRUBOF'.
(pkgdata_MODULES, fshelp_mod_SOURCES, fshelp_mod_CFLAGS,
(fat_mod_SOURCES, fat_mod_CFLAGS, ext2_mod_SOURCES)
(ext2_mod_CFLAGS, ufs_mod_SOURCES, ufs_mod_CFLAGS)
(minix_mod_SOURCES, minix_mod_CFLAGS, hfs_mod_SOURCES)
(hfs_mod_CFLAGS, jfs_mod_SOURCES, jfs_mod_CFLAGS)
(iso9660_mod_SOURCES, iso9660_mod_CFLAGS, _linux_mod_SOURCES)
(_linux_mod_CFLAGS, linux_mod_SOURCES, linux_mod_CFLAGS)
(normal_mod_SOURCES, normal_mod_CFLAGS, normal_mod_ASFLAGS)
(hello_mod_SOURCES, hello_mod_CFLAGS, boot_mod_SOURCES)
(boot_mod_CFLAGS, terminal_mod_SOURCES, terminal_mod_CFLAGS)
(ls_mod_SOURCES, ls_mod_CFLAGS, cmp_mod_SOURCES, cmp_mod_CFLAGS)
(cat_mod_SOURCES, cat_mod_CFLAGS, font_mod_SOURCES)
(font_mod_CFLAGS, amiga_mod_SOURCES, amiga_mod_CFLAGS)
(apple_mod_SOURCES, apple_mod_CFLAGS, pc_mod_SOURCES)
(pc_mod_CFLAGS): New variables.
* disk/powerpc/ieee1275/ofdisk.c: Include <grub/machine/init.h>.
(grub_ofdisk_iterate): Add a prototype for `dev_iterate'.
* include/grub/dl.h (grub_arch_dl_sync_caches): New prototype.
* include/grub/loader.h (grub_os_area_addr, grub_os_area_size):
Moved from here...
* include/grub/i386/pc/init.h (grub_os_area_addr)
(rub_os_area_size): ... to here.
* include/grub/powerpc/ieee1275/ieee1275.h
(grub_ieee1275_entry_fn): Export symbol.
* include/grub/powerpc/ieee1275/init.h: New file.
* include/grub/powerpc/libgcc.h: Likewise.
* include/grub/cache.h: Likewise.
* kern/powerpc/cache.S: Likewise. Written by Hollis Blanchard
<hollis@penguinppc.org>.
* kern/dl.c: Include <grub/cache.h>.
(grub_dl_flush_cache): New function.
(grub_dl_load_core): Call `grub_dl_flush_cache' to flush the cache
for this module.
* kern/powerpc/ieee1275/init.c (grub_ofdisk_init)
(grub_console_init): Removed prototypes.
(grub_machine_init): Don't initialize the modules anymore.
* kern/powerpc/ieee1275/openfw.c (grub_map): Make the function
static.
* include/grub/powerpc/types.h (GRUB_HOST_WORDS_LITTLEENDIAN):
Macro undef removed.
(GRUB_HOST_WORDS_BIGENDIAN): New macro.
* kern/powerpc/dl.c (grub_arch_dl_relocate_symbols): Add
relocation `R_PPC_REL32'. Return an error when the relocation is
unknown.
* Makefile.in (DATA): Add `$(pkgdata_PROGRAMS)'.
* kern/i386/pc/init.c (grub_arch_sync_caches): New function.
* util/misc.c (grub_arch_sync_caches): Likewise.
2004-12-27 13:46:20 +00:00
|
|
|
|
2008-08-07 23:48:13 +00:00
|
|
|
grub_uint64_t
|
|
|
|
grub_get_time_ms (void)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
gettimeofday (&tv, 0);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2008-08-07 23:48:13 +00:00
|
|
|
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
|
|
|
|
}
|
|
|
|
|
2009-03-21 07:48:28 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
|
|
|
|
void
|
|
|
|
grub_millisleep (grub_uint32_t ms)
|
|
|
|
{
|
|
|
|
Sleep (ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2009-03-04 10:25:31 +00:00
|
|
|
void
|
|
|
|
grub_millisleep (grub_uint32_t ms)
|
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
ts.tv_sec = ms / 1000;
|
|
|
|
ts.tv_nsec = (ms % 1000) * 1000000;
|
|
|
|
nanosleep (&ts, NULL);
|
|
|
|
}
|
|
|
|
|
2009-03-21 07:48:28 +00:00
|
|
|
#endif
|
|
|
|
|
2010-02-07 15:13:59 +00:00
|
|
|
#if !(defined (__i386__) || defined (__x86_64__)) && GRUB_NO_MODULES
|
2009-06-10 21:04:23 +00:00
|
|
|
void
|
2004-12-27 Marco Gerards <metgerards@student.han.nl>
* genmk.rb: Handle the `Program' class in the main loop. Written
by Johan Rydberg <jrydberg@gnu.org>.
(Program): New class.
(programs): New variable.
* boot/powerpc/ieee1275/cmain.c: Include <grub/machine/ieee1275.h>
instead of "grub/machine/ieee1275.h". Include <grub/kernel.h>
instead of "grub/kernel.h". Include <grub/machine/init.h>.
(help_arch): Function removed.
* conf/powerpc-ieee1275.rmk (grubof_HEADERS): Add
`powerpc/libgcc.h' and `loader.h'.
(pkgdata_PROGRAMS): New variable.
(sbin_UTILITIES): Variable removed.
(grub_emu_SOURCES): Added kern/powerpc/cache.S.
(grubof_SOURCES): Variable re-defined so it only includes the
core functionality.
(grubof_CFLAGS): Remove `-DGRUBOF'.
(pkgdata_MODULES, fshelp_mod_SOURCES, fshelp_mod_CFLAGS,
(fat_mod_SOURCES, fat_mod_CFLAGS, ext2_mod_SOURCES)
(ext2_mod_CFLAGS, ufs_mod_SOURCES, ufs_mod_CFLAGS)
(minix_mod_SOURCES, minix_mod_CFLAGS, hfs_mod_SOURCES)
(hfs_mod_CFLAGS, jfs_mod_SOURCES, jfs_mod_CFLAGS)
(iso9660_mod_SOURCES, iso9660_mod_CFLAGS, _linux_mod_SOURCES)
(_linux_mod_CFLAGS, linux_mod_SOURCES, linux_mod_CFLAGS)
(normal_mod_SOURCES, normal_mod_CFLAGS, normal_mod_ASFLAGS)
(hello_mod_SOURCES, hello_mod_CFLAGS, boot_mod_SOURCES)
(boot_mod_CFLAGS, terminal_mod_SOURCES, terminal_mod_CFLAGS)
(ls_mod_SOURCES, ls_mod_CFLAGS, cmp_mod_SOURCES, cmp_mod_CFLAGS)
(cat_mod_SOURCES, cat_mod_CFLAGS, font_mod_SOURCES)
(font_mod_CFLAGS, amiga_mod_SOURCES, amiga_mod_CFLAGS)
(apple_mod_SOURCES, apple_mod_CFLAGS, pc_mod_SOURCES)
(pc_mod_CFLAGS): New variables.
* disk/powerpc/ieee1275/ofdisk.c: Include <grub/machine/init.h>.
(grub_ofdisk_iterate): Add a prototype for `dev_iterate'.
* include/grub/dl.h (grub_arch_dl_sync_caches): New prototype.
* include/grub/loader.h (grub_os_area_addr, grub_os_area_size):
Moved from here...
* include/grub/i386/pc/init.h (grub_os_area_addr)
(rub_os_area_size): ... to here.
* include/grub/powerpc/ieee1275/ieee1275.h
(grub_ieee1275_entry_fn): Export symbol.
* include/grub/powerpc/ieee1275/init.h: New file.
* include/grub/powerpc/libgcc.h: Likewise.
* include/grub/cache.h: Likewise.
* kern/powerpc/cache.S: Likewise. Written by Hollis Blanchard
<hollis@penguinppc.org>.
* kern/dl.c: Include <grub/cache.h>.
(grub_dl_flush_cache): New function.
(grub_dl_load_core): Call `grub_dl_flush_cache' to flush the cache
for this module.
* kern/powerpc/ieee1275/init.c (grub_ofdisk_init)
(grub_console_init): Removed prototypes.
(grub_machine_init): Don't initialize the modules anymore.
* kern/powerpc/ieee1275/openfw.c (grub_map): Make the function
static.
* include/grub/powerpc/types.h (GRUB_HOST_WORDS_LITTLEENDIAN):
Macro undef removed.
(GRUB_HOST_WORDS_BIGENDIAN): New macro.
* kern/powerpc/dl.c (grub_arch_dl_relocate_symbols): Add
relocation `R_PPC_REL32'. Return an error when the relocation is
unknown.
* Makefile.in (DATA): Add `$(pkgdata_PROGRAMS)'.
* kern/i386/pc/init.c (grub_arch_sync_caches): New function.
* util/misc.c (grub_arch_sync_caches): Likewise.
2004-12-27 13:46:20 +00:00
|
|
|
grub_arch_sync_caches (void *address __attribute__ ((unused)),
|
|
|
|
grub_size_t len __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
}
|
2010-02-06 23:52:31 +00:00
|
|
|
#endif
|
2008-08-29 19:55:23 +00:00
|
|
|
|
2009-12-07 16:46:24 +00:00
|
|
|
#ifndef HAVE_VASPRINTF
|
|
|
|
|
|
|
|
int
|
|
|
|
vasprintf (char **buf, const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
/* Should be large enough. */
|
|
|
|
*buf = xmalloc (512);
|
|
|
|
|
|
|
|
return vsprintf (*buf, fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-08-29 19:55:23 +00:00
|
|
|
#ifndef HAVE_ASPRINTF
|
|
|
|
|
|
|
|
int
|
|
|
|
asprintf (char **buf, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
2009-12-07 16:46:24 +00:00
|
|
|
status = vasprintf (*buf, fmt, ap);
|
2008-08-29 19:55:23 +00:00
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-12-07 16:46:24 +00:00
|
|
|
char *
|
|
|
|
xasprintf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
if (vasprintf (&result, fmt, ap) < 0)
|
|
|
|
{
|
|
|
|
if (errno == ENOMEM)
|
|
|
|
grub_util_error ("out of memory");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-08-29 19:55:23 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
|
|
|
|
void sync (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-04-04 07:42:13 +00:00
|
|
|
int fsync (int fno __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-29 19:55:23 +00:00
|
|
|
void sleep (int s)
|
|
|
|
{
|
|
|
|
Sleep (s * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_int64_t
|
|
|
|
grub_util_get_disk_size (char *name)
|
|
|
|
{
|
|
|
|
HANDLE hd;
|
|
|
|
grub_int64_t size = -1LL;
|
|
|
|
|
|
|
|
hd = CreateFile (name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
0, OPEN_EXISTING, 0, 0);
|
|
|
|
|
|
|
|
if (hd == INVALID_HANDLE_VALUE)
|
|
|
|
return size;
|
|
|
|
|
|
|
|
if (((name[0] == '/') || (name[0] == '\\')) &&
|
|
|
|
((name[1] == '/') || (name[1] == '\\')) &&
|
|
|
|
(name[2] == '.') &&
|
|
|
|
((name[3] == '/') || (name[3] == '\\')) &&
|
|
|
|
(! strncasecmp (name + 4, "PHYSICALDRIVE", 13)))
|
|
|
|
{
|
|
|
|
DWORD nr;
|
|
|
|
DISK_GEOMETRY g;
|
|
|
|
|
|
|
|
if (! DeviceIoControl (hd, IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
|
|
|
0, 0, &g, sizeof (g), &nr, 0))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
size = g.Cylinders.QuadPart;
|
|
|
|
size *= g.TracksPerCylinder * g.SectorsPerTrack * g.BytesPerSector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LARGE_INTEGER s;
|
|
|
|
|
|
|
|
s.LowPart = GetFileSize (hd, &s.HighPart);
|
|
|
|
size = s.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
CloseHandle (hd);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2009-07-01 13:01:33 +00:00
|
|
|
#endif /* __MINGW32__ */
|
2009-11-08 00:49:15 +00:00
|
|
|
|
2010-01-11 14:55:20 +00:00
|
|
|
char *
|
|
|
|
canonicalize_file_name (const char *path)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
#ifdef PATH_MAX
|
|
|
|
ret = xmalloc (PATH_MAX);
|
|
|
|
(void) realpath (path, ret);
|
|
|
|
#else
|
|
|
|
ret = realpath (path, NULL);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-11-08 00:49:15 +00:00
|
|
|
/* This function never prints trailing slashes (so that its output
|
|
|
|
can be appended a slash unconditionally). */
|
|
|
|
char *
|
|
|
|
make_system_path_relative_to_its_root (const char *path)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char *p, *buf, *buf2, *buf3;
|
|
|
|
uintptr_t offset = 0;
|
|
|
|
dev_t num;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
/* canonicalize. */
|
2010-01-11 14:55:20 +00:00
|
|
|
p = canonicalize_file_name (path);
|
2009-11-08 00:49:15 +00:00
|
|
|
|
|
|
|
if (p == NULL)
|
2010-01-11 14:55:20 +00:00
|
|
|
grub_util_error ("failed to get canonical path of %s", path);
|
|
|
|
|
2009-11-08 00:49:15 +00:00
|
|
|
len = strlen (p) + 1;
|
2010-01-20 22:53:53 +00:00
|
|
|
buf = xstrdup (p);
|
2009-11-08 00:49:15 +00:00
|
|
|
free (p);
|
|
|
|
|
|
|
|
if (stat (buf, &st) < 0)
|
2009-12-25 00:04:51 +00:00
|
|
|
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
|
2009-11-08 00:49:15 +00:00
|
|
|
|
2010-01-20 22:53:53 +00:00
|
|
|
buf2 = xstrdup (buf);
|
2009-11-08 00:49:15 +00:00
|
|
|
num = st.st_dev;
|
|
|
|
|
|
|
|
/* This loop sets offset to the number of chars of the root
|
|
|
|
directory we're inspecting. */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
p = strrchr (buf, '/');
|
|
|
|
if (p == NULL)
|
|
|
|
/* This should never happen. */
|
|
|
|
grub_util_error ("FIXME: no / in buf. (make_system_path_relative_to_its_root)");
|
|
|
|
if (p != buf)
|
|
|
|
*p = 0;
|
|
|
|
else
|
|
|
|
*++p = 0;
|
|
|
|
|
|
|
|
if (stat (buf, &st) < 0)
|
2009-12-25 00:04:51 +00:00
|
|
|
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
|
2009-11-08 00:49:15 +00:00
|
|
|
|
|
|
|
/* buf is another filesystem; we found it. */
|
|
|
|
if (st.st_dev != num)
|
2009-12-06 09:20:01 +00:00
|
|
|
{
|
2010-01-20 22:53:53 +00:00
|
|
|
/* offset == 0 means path given is the mount point.
|
|
|
|
This works around special-casing of "/" in Un*x. This function never
|
|
|
|
prints trailing slashes (so that its output can be appended a slash
|
|
|
|
unconditionally). Each slash in is considered a preceding slash, and
|
|
|
|
therefore the root directory is an empty string. */
|
2009-12-06 09:20:01 +00:00
|
|
|
if (offset == 0)
|
|
|
|
{
|
|
|
|
free (buf);
|
|
|
|
free (buf2);
|
2010-01-20 22:53:53 +00:00
|
|
|
return xstrdup ("");
|
2009-12-06 09:20:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2009-11-08 00:49:15 +00:00
|
|
|
|
|
|
|
offset = p - buf;
|
|
|
|
/* offset == 1 means root directory. */
|
|
|
|
if (offset == 1)
|
|
|
|
{
|
|
|
|
free (buf);
|
|
|
|
len = strlen (buf2);
|
|
|
|
while (buf2[len - 1] == '/' && len > 1)
|
|
|
|
{
|
|
|
|
buf2[len - 1] = '\0';
|
|
|
|
len--;
|
|
|
|
}
|
2010-01-20 22:53:53 +00:00
|
|
|
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);
|
2010-01-21 12:58:40 +00:00
|
|
|
return xstrdup ("");
|
2010-01-20 22:53:53 +00:00
|
|
|
}
|
2009-11-08 00:49:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free (buf);
|
2010-01-20 22:53:53 +00:00
|
|
|
buf3 = xstrdup (buf2 + offset);
|
2009-11-08 00:49:15 +00:00
|
|
|
free (buf2);
|
|
|
|
|
|
|
|
len = strlen (buf3);
|
2009-11-13 22:08:55 +00:00
|
|
|
while (buf3[len - 1] == '/' && len > 1)
|
2009-11-08 00:49:15 +00:00
|
|
|
{
|
2009-11-13 22:08:55 +00:00
|
|
|
buf3[len - 1] = '\0';
|
2009-11-08 00:49:15 +00:00
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf3;
|
|
|
|
}
|
2010-01-01 20:32:30 +00:00
|
|
|
|
2010-02-07 03:23:44 +00:00
|
|
|
#ifdef GRUB_UTIL
|
2010-01-01 20:32:30 +00:00
|
|
|
void
|
|
|
|
grub_util_init_nls (void)
|
|
|
|
{
|
2010-03-27 11:19:32 +00:00
|
|
|
#if (defined(ENABLE_NLS) && ENABLE_NLS)
|
2010-01-01 20:32:30 +00:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2010-03-27 11:19:32 +00:00
|
|
|
#endif /* (defined(ENABLE_NLS) && ENABLE_NLS) */
|
2010-01-01 20:32:30 +00:00
|
|
|
}
|
2010-02-07 03:23:44 +00:00
|
|
|
#endif
|