2004-04-04 Yoshinori K. Okuji <okuji@enbug.org>

All symbols prefixed with PUPA_ and pupa_ are renamed to GRUB_
	and grub_, respectively. Because the conversion is trivial and
	mechanical, I omit the details here. Please refer to the CVS
	if you need more information.
This commit is contained in:
okuji 2004-04-04 13:46:03 +00:00
parent 6a1425510d
commit 4b13b216f4
125 changed files with 6198 additions and 6181 deletions

View file

@ -1,6 +1,6 @@
/* console.c -- Ncurses console for PUPA. */
/* console.c -- Ncurses console for GRUB. */
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
@ -19,31 +19,31 @@
*/
#include <curses.h>
#include <pupa/machine/console.h>
#include <pupa/term.h>
#include <pupa/types.h>
#include <grub/machine/console.h>
#include <grub/term.h>
#include <grub/types.h>
static int pupa_console_attr = A_NORMAL;
static int grub_console_attr = A_NORMAL;
static void
pupa_ncurses_putchar (pupa_uint32_t c)
grub_ncurses_putchar (grub_uint32_t c)
{
addch (c | pupa_console_attr);
addch (c | grub_console_attr);
}
static void
pupa_ncurses_setcolorstate (pupa_term_color_state state)
grub_ncurses_setcolorstate (grub_term_color_state state)
{
switch (state)
{
case PUPA_TERM_COLOR_STANDARD:
pupa_console_attr = A_NORMAL;
case GRUB_TERM_COLOR_STANDARD:
grub_console_attr = A_NORMAL;
break;
case PUPA_TERM_COLOR_NORMAL:
pupa_console_attr = A_NORMAL;
case GRUB_TERM_COLOR_NORMAL:
grub_console_attr = A_NORMAL;
break;
case PUPA_TERM_COLOR_HIGHLIGHT:
pupa_console_attr = A_STANDOUT;
case GRUB_TERM_COLOR_HIGHLIGHT:
grub_console_attr = A_STANDOUT;
break;
default:
break;
@ -52,77 +52,77 @@ pupa_ncurses_setcolorstate (pupa_term_color_state state)
/* XXX: This function is never called. */
static void
pupa_ncurses_setcolor (pupa_uint8_t normal_color, pupa_uint8_t highlight_color)
grub_ncurses_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
{
color_set (normal_color << 8 | highlight_color, 0);
}
static int
pupa_ncurses_checkkey (void)
grub_ncurses_checkkey (void)
{
return 1;
}
static int
pupa_ncurses_getkey (void)
grub_ncurses_getkey (void)
{
int c = getch ();
switch (c)
{
case KEY_LEFT:
c = PUPA_CONSOLE_KEY_LEFT;
c = GRUB_CONSOLE_KEY_LEFT;
break;
case KEY_RIGHT:
c = PUPA_CONSOLE_KEY_RIGHT;
c = GRUB_CONSOLE_KEY_RIGHT;
break;
case KEY_UP:
c = PUPA_CONSOLE_KEY_UP;
c = GRUB_CONSOLE_KEY_UP;
break;
case KEY_DOWN:
c = PUPA_CONSOLE_KEY_DOWN;
c = GRUB_CONSOLE_KEY_DOWN;
break;
case KEY_IC:
c = PUPA_CONSOLE_KEY_IC;
c = GRUB_CONSOLE_KEY_IC;
break;
case KEY_DC:
c = PUPA_CONSOLE_KEY_DC;
c = GRUB_CONSOLE_KEY_DC;
break;
case KEY_BACKSPACE:
/* XXX: For some reason ncurses on xterm does not return
KEY_BACKSPACE. */
case 127:
c = PUPA_CONSOLE_KEY_BACKSPACE;
c = GRUB_CONSOLE_KEY_BACKSPACE;
break;
case KEY_HOME:
c = PUPA_CONSOLE_KEY_HOME;
c = GRUB_CONSOLE_KEY_HOME;
break;
case KEY_END:
c = PUPA_CONSOLE_KEY_END;
c = GRUB_CONSOLE_KEY_END;
break;
case KEY_NPAGE:
c = PUPA_CONSOLE_KEY_NPAGE;
c = GRUB_CONSOLE_KEY_NPAGE;
break;
case KEY_PPAGE:
c = PUPA_CONSOLE_KEY_PPAGE;
c = GRUB_CONSOLE_KEY_PPAGE;
break;
}
return c;
}
static pupa_uint16_t
pupa_ncurses_getxy (void)
static grub_uint16_t
grub_ncurses_getxy (void)
{
int x;
int y;
@ -133,32 +133,32 @@ pupa_ncurses_getxy (void)
}
static void
pupa_ncurses_gotoxy (pupa_uint8_t x, pupa_uint8_t y)
grub_ncurses_gotoxy (grub_uint8_t x, grub_uint8_t y)
{
move (y, x);
}
static void
pupa_ncurses_cls (void)
grub_ncurses_cls (void)
{
clear ();
refresh ();
}
static void
pupa_ncurses_setcursor (int on)
grub_ncurses_setcursor (int on)
{
curs_set (on ? 1 : 0);
}
static void
pupa_ncurses_refresh (void)
grub_ncurses_refresh (void)
{
refresh ();
}
static pupa_err_t
pupa_ncurses_init (void)
static grub_err_t
grub_ncurses_init (void)
{
initscr ();
cbreak ();
@ -173,36 +173,36 @@ pupa_ncurses_init (void)
return 0;
}
static pupa_err_t
pupa_ncurses_fini (void)
static grub_err_t
grub_ncurses_fini (void)
{
endwin ();
return 0;
}
static struct pupa_term pupa_ncurses_term =
static struct grub_term grub_ncurses_term =
{
.name = "console",
.init = pupa_ncurses_init,
.fini = pupa_ncurses_fini,
.putchar = pupa_ncurses_putchar,
.checkkey = pupa_ncurses_checkkey,
.getkey = pupa_ncurses_getkey,
.getxy = pupa_ncurses_getxy,
.gotoxy = pupa_ncurses_gotoxy,
.cls = pupa_ncurses_cls,
.setcolorstate = pupa_ncurses_setcolorstate,
.setcolor = pupa_ncurses_setcolor,
.setcursor = pupa_ncurses_setcursor,
.refresh = pupa_ncurses_refresh,
.init = grub_ncurses_init,
.fini = grub_ncurses_fini,
.putchar = grub_ncurses_putchar,
.checkkey = grub_ncurses_checkkey,
.getkey = grub_ncurses_getkey,
.getxy = grub_ncurses_getxy,
.gotoxy = grub_ncurses_gotoxy,
.cls = grub_ncurses_cls,
.setcolorstate = grub_ncurses_setcolorstate,
.setcolor = grub_ncurses_setcolor,
.setcursor = grub_ncurses_setcursor,
.refresh = grub_ncurses_refresh,
.flags = 0,
.next = 0
};
void
pupa_console_init (void)
grub_console_init (void)
{
pupa_term_register (&pupa_ncurses_term);
pupa_term_set_current (&pupa_ncurses_term);
grub_term_register (&grub_ncurses_term);
grub_term_set_current (&grub_ncurses_term);
}

View file

@ -1,5 +1,5 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify

View file

@ -1,8 +1,8 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003 Free Software Foundation, Inc.
*
* PUPA is free software; you can redistribute it and/or modify
* 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 2 of the License, or
* (at your option) any later version.
@ -13,7 +13,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PUPA; if not, write to the Free Software
* along with GRUB; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
@ -23,64 +23,64 @@
#include <argp.h>
#include <string.h>
#include <pupa/mm.h>
#include <pupa/setjmp.h>
#include <pupa/fs.h>
#include <pupa/i386/pc/util/biosdisk.h>
#include <pupa/dl.h>
#include <pupa/machine/console.h>
#include <pupa/util/misc.h>
#include <pupa/kernel.h>
#include <pupa/normal.h>
#include <pupa/util/getroot.h>
#include <pupa/env.h>
#include <grub/mm.h>
#include <grub/setjmp.h>
#include <grub/fs.h>
#include <grub/i386/pc/util/biosdisk.h>
#include <grub/dl.h>
#include <grub/machine/console.h>
#include <grub/util/misc.h>
#include <grub/kernel.h>
#include <grub/normal.h>
#include <grub/util/getroot.h>
#include <grub/env.h>
#ifdef __NetBSD__
/* NetBSD uses /boot for its boot block. */
# define DEFAULT_DIRECTORY "/pupa"
# define DEFAULT_DIRECTORY "/grub"
#else
# define DEFAULT_DIRECTORY "/boot/pupa"
# define DEFAULT_DIRECTORY "/boot/grub"
#endif
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
/* XXX. */
pupa_addr_t pupa_end_addr = -1;
pupa_addr_t pupa_total_module_size = 0;
grub_addr_t grub_end_addr = -1;
grub_addr_t grub_total_module_size = 0;
int
pupa_arch_dl_check_header (void *ehdr, pupa_size_t size)
grub_arch_dl_check_header (void *ehdr, grub_size_t size)
{
(void) ehdr;
(void) size;
return PUPA_ERR_BAD_MODULE;
return GRUB_ERR_BAD_MODULE;
}
pupa_err_t
pupa_arch_dl_relocate_symbols (pupa_dl_t mod, void *ehdr)
grub_err_t
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
(void) mod;
(void) ehdr;
return PUPA_ERR_BAD_MODULE;
return GRUB_ERR_BAD_MODULE;
}
void
pupa_machine_init (void)
grub_machine_init (void)
{
pupa_console_init ();
grub_console_init ();
}
const char *argp_program_version = PACKAGE_STRING;
const char *argp_program_bug_address = PACKAGE_BUGREPORT;
static char doc[] = "PUPA emulator";
static char doc[] = "GRUB emulator";
static struct argp_option options[] = {
{"root-device", 'r', "DEV", 0, "use DEV as the root device [default=guessed]", 0},
{"device-map", 'm', "FILE", 0, "use FILE as the device map", 0},
{"directory", 'd', "DIR", 0, "use PUPA files in the directory DIR", 0},
{"directory", 'd', "DIR", 0, "use GRUB files in the directory DIR", 0},
{"verbose", 'v', 0 , 0, "print verbose messages", 0},
{ 0, 0, 0, 0, 0, 0 }
};
@ -138,46 +138,46 @@ main (int argc, char *argv[])
/* More sure there is a root device. */
if (! args.root_dev)
{
args.root_dev = pupa_guess_root_device (args.dir ? : DEFAULT_DIRECTORY);
args.root_dev = grub_guess_root_device (args.dir ? : DEFAULT_DIRECTORY);
if (! args.root_dev)
{
pupa_util_info ("guessing the root device failed, because of `%s'",
pupa_errmsg);
pupa_util_error ("Cannot guess the root device. Specify the option ``--root-device''.");
grub_util_info ("guessing the root device failed, because of `%s'",
grub_errmsg);
grub_util_error ("Cannot guess the root device. Specify the option ``--root-device''.");
}
}
prefix = pupa_get_prefix (args.dir ? : DEFAULT_DIRECTORY);
prefix = grub_get_prefix (args.dir ? : DEFAULT_DIRECTORY);
sprintf (rootprefix, "%s%s", args.root_dev, prefix);
pupa_env_set ("prefix", rootprefix);
grub_env_set ("prefix", rootprefix);
/* XXX: This is a bit unportable. */
pupa_util_biosdisk_init (args.dev_map);
grub_util_biosdisk_init (args.dev_map);
/* Initialize the default modules. */
pupa_fat_init ();
pupa_ext2_init ();
pupa_ls_init ();
pupa_boot_init ();
pupa_cmp_init ();
pupa_cat_init ();
pupa_terminal_init ();
grub_fat_init ();
grub_ext2_init ();
grub_ls_init ();
grub_boot_init ();
grub_cmp_init ();
grub_cat_init ();
grub_terminal_init ();
/* XXX: Should normal mode be started by default? */
pupa_normal_init ();
grub_normal_init ();
/* Start PUPA! */
pupa_main ();
/* Start GRUB! */
grub_main ();
pupa_util_biosdisk_fini ();
pupa_normal_fini ();
pupa_ext2_fini ();
pupa_fat_fini ();
pupa_boot_fini ();
pupa_cmp_fini ();
pupa_cat_fini ();
pupa_terminal_fini ();
grub_util_biosdisk_fini ();
grub_normal_fini ();
grub_ext2_fini ();
grub_fat_fini ();
grub_boot_fini ();
grub_cmp_fini ();
grub_cat_fini ();
grub_terminal_fini ();
return 0;
}

View file

@ -1,9 +1,9 @@
/* biosdisk.c - emulate biosdisk */
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
*
* PUPA is free software; you can redistribute it and/or modify
* 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 2 of the License, or
* (at your option) any later version.
@ -14,16 +14,16 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PUPA; if not, write to the Free Software
* along with GRUB; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <pupa/machine/biosdisk.h>
#include <pupa/disk.h>
#include <pupa/machine/partition.h>
#include <pupa/types.h>
#include <pupa/err.h>
#include <pupa/util/misc.h>
#include <grub/machine/biosdisk.h>
#include <grub/disk.h>
#include <grub/machine/partition.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/util/misc.h>
#include <stdio.h>
#include <stdlib.h>
@ -119,7 +119,7 @@ get_drive (const char *name)
return (int) drive;
fail:
pupa_error (PUPA_ERR_UNKNOWN_DEVICE, "not a biosdisk");
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a biosdisk");
return -1;
}
@ -133,7 +133,7 @@ call_hook (int (*hook) (const char *name), int drive)
}
static int
pupa_util_biosdisk_iterate (int (*hook) (const char *name))
grub_util_biosdisk_iterate (int (*hook) (const char *name))
{
unsigned i;
@ -144,18 +144,18 @@ pupa_util_biosdisk_iterate (int (*hook) (const char *name))
return 0;
}
static pupa_err_t
pupa_util_biosdisk_open (const char *name, pupa_disk_t disk)
static grub_err_t
grub_util_biosdisk_open (const char *name, grub_disk_t disk)
{
int drive;
struct stat st;
drive = get_drive (name);
if (drive < 0)
return pupa_errno;
return grub_errno;
if (! map[drive])
return pupa_error (PUPA_ERR_BAD_DEVICE,
return grub_error (GRUB_ERR_BAD_DEVICE,
"no mapping exists for `%s'", name);
disk->has_partitions = (drive & 0x80);
@ -169,7 +169,7 @@ pupa_util_biosdisk_open (const char *name, pupa_disk_t disk)
fd = open (map[drive], O_RDONLY);
if (! fd)
return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode))
{
@ -186,9 +186,9 @@ pupa_util_biosdisk_open (const char *name, pupa_disk_t disk)
close (fd);
disk->total_sectors = nr;
pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
grub_util_info ("the size of %s is %lu", name, disk->total_sectors);
return PUPA_ERR_NONE;
return GRUB_ERR_NONE;
}
fail:
@ -197,13 +197,13 @@ pupa_util_biosdisk_open (const char *name, pupa_disk_t disk)
# warning "No special routine to get the size of a block device is implemented for your OS. This is not possibly fatal."
#endif
if (stat (map[drive], &st) < 0)
return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive]);
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive]);
disk->total_sectors = st.st_size >> PUPA_DISK_SECTOR_BITS;
disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS;
pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
grub_util_info ("the size of %s is %lu", name, disk->total_sectors);
return PUPA_ERR_NONE;
return GRUB_ERR_NONE;
}
#ifdef __linux__
@ -284,7 +284,7 @@ linux_find_partition (char *dev, unsigned long sector)
#endif /* __linux__ */
static int
open_device (const pupa_disk_t disk, unsigned long sector, int flags)
open_device (const grub_disk_t disk, unsigned long sector, int flags)
{
int fd;
@ -310,11 +310,11 @@ open_device (const pupa_disk_t disk, unsigned long sector, int flags)
is_partition = linux_find_partition (dev, disk->partition->start);
/* Open the partition. */
pupa_util_info ("opening the device `%s'", dev);
grub_util_info ("opening the device `%s'", dev);
fd = open (dev, flags);
if (fd < 0)
{
pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", dev);
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", dev);
return -1;
}
@ -328,7 +328,7 @@ open_device (const pupa_disk_t disk, unsigned long sector, int flags)
fd = open (map[disk->id], flags);
if (fd < 0)
{
pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[disk->id]);
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", map[disk->id]);
return -1;
}
#endif /* ! __linux__ */
@ -343,21 +343,21 @@ open_device (const pupa_disk_t disk, unsigned long sector, int flags)
_syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo,
loff_t *, res, uint, wh);
offset = (loff_t) sector << PUPA_DISK_SECTOR_BITS;
offset = (loff_t) sector << GRUB_DISK_SECTOR_BITS;
if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
{
pupa_error (PUPA_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id]);
grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id]);
close (fd);
return -1;
}
}
#else
{
off_t offset = (off_t) sector << PUPA_DISK_SECTOR_BITS;
off_t offset = (off_t) sector << GRUB_DISK_SECTOR_BITS;
if (lseek (fd, offset, SEEK_SET) != offset)
{
pupa_error (PUPA_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id]);
grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id]);
close (fd);
return -1;
}
@ -419,15 +419,15 @@ nwrite (int fd, const char *buf, size_t len)
return size;
}
static pupa_err_t
pupa_util_biosdisk_read (pupa_disk_t disk, unsigned long sector,
static grub_err_t
grub_util_biosdisk_read (grub_disk_t disk, unsigned long sector,
unsigned long size, char *buf)
{
int fd;
fd = open_device (disk, sector, O_RDONLY);
if (fd < 0)
return pupa_errno;
return grub_errno;
#ifdef __linux__
if (sector == 0 && size > 1)
@ -436,52 +436,52 @@ pupa_util_biosdisk_read (pupa_disk_t disk, unsigned long sector,
sectors that are read together with the MBR in one read. It
should only remap the MBR, so we split the read in two
parts. -jochen */
if (nread (fd, buf, PUPA_DISK_SECTOR_SIZE) != PUPA_DISK_SECTOR_SIZE)
if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE)
{
pupa_error (PUPA_ERR_READ_ERROR, "cannot read `%s'", map[disk->id]);
grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id]);
close (fd);
return pupa_errno;
return grub_errno;
}
buf += PUPA_DISK_SECTOR_SIZE;
buf += GRUB_DISK_SECTOR_SIZE;
size--;
}
#endif /* __linux__ */
if (nread (fd, buf, size << PUPA_DISK_SECTOR_BITS)
!= (ssize_t) (size << PUPA_DISK_SECTOR_BITS))
pupa_error (PUPA_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id]);
if (nread (fd, buf, size << GRUB_DISK_SECTOR_BITS)
!= (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id]);
close (fd);
return pupa_errno;
return grub_errno;
}
static pupa_err_t
pupa_util_biosdisk_write (pupa_disk_t disk, unsigned long sector,
static grub_err_t
grub_util_biosdisk_write (grub_disk_t disk, unsigned long sector,
unsigned long size, const char *buf)
{
int fd;
fd = open_device (disk, sector, O_WRONLY);
if (fd < 0)
return pupa_errno;
return grub_errno;
if (nwrite (fd, buf, size << PUPA_DISK_SECTOR_BITS)
!= (ssize_t) (size << PUPA_DISK_SECTOR_BITS))
pupa_error (PUPA_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id]);
if (nwrite (fd, buf, size << GRUB_DISK_SECTOR_BITS)
!= (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id]);
close (fd);
return pupa_errno;
return grub_errno;
}
static struct pupa_disk_dev pupa_util_biosdisk_dev =
static struct grub_disk_dev grub_util_biosdisk_dev =
{
.name = "biosdisk",
.iterate = pupa_util_biosdisk_iterate,
.open = pupa_util_biosdisk_open,
.iterate = grub_util_biosdisk_iterate,
.open = grub_util_biosdisk_open,
.close = 0,
.read = pupa_util_biosdisk_read,
.write = pupa_util_biosdisk_write,
.read = grub_util_biosdisk_read,
.write = grub_util_biosdisk_write,
.next = 0
};
@ -495,12 +495,12 @@ read_device_map (const char *dev_map)
void show_error (const char *msg)
{
pupa_util_error ("%s:%d: %s", dev_map, lineno, msg);
grub_util_error ("%s:%d: %s", dev_map, lineno, msg);
}
fp = fopen (dev_map, "r");
if (! fp)
pupa_util_error ("Cannot open `%s'", dev_map);
grub_util_error ("Cannot open `%s'", dev_map);
while (fgets (buf, sizeof (buf), fp))
{
@ -554,7 +554,7 @@ read_device_map (const char *dev_map)
symbolic links. */
map[drive] = xmalloc (PATH_MAX);
if (! realpath (p, map[drive]))
pupa_util_error ("Cannot get the real path of `%s'", p);
grub_util_error ("Cannot get the real path of `%s'", p);
#else
map[drive] = xstrdup (p);
#endif
@ -564,21 +564,21 @@ read_device_map (const char *dev_map)
}
void
pupa_util_biosdisk_init (const char *dev_map)
grub_util_biosdisk_init (const char *dev_map)
{
read_device_map (dev_map);
pupa_disk_dev_register (&pupa_util_biosdisk_dev);
grub_disk_dev_register (&grub_util_biosdisk_dev);
}
void
pupa_util_biosdisk_fini (void)
grub_util_biosdisk_fini (void)
{
unsigned i;
for (i = 0; i < sizeof (map) / sizeof (map[0]); i++)
free (map[i]);
pupa_disk_dev_unregister (&pupa_util_biosdisk_dev);
grub_disk_dev_unregister (&grub_util_biosdisk_dev);
}
static char *
@ -697,21 +697,21 @@ find_drive (const char *os_dev)
}
char *
pupa_util_biosdisk_get_pupa_dev (const char *os_dev)
grub_util_biosdisk_get_grub_dev (const char *os_dev)
{
struct stat st;
int drive;
if (stat (os_dev, &st) < 0)
{
pupa_error (PUPA_ERR_BAD_DEVICE, "cannot stat `%s'", os_dev);
grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", os_dev);
return 0;
}
drive = find_drive (os_dev);
if (drive < 0)
{
pupa_error (PUPA_ERR_BAD_DEVICE,
grub_error (GRUB_ERR_BAD_DEVICE,
"no mapping exists for `%s'", os_dev);
return 0;
}
@ -721,25 +721,25 @@ pupa_util_biosdisk_get_pupa_dev (const char *os_dev)
#if defined(__linux__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
partition, so mapping them to PUPA devices is not trivial.
partition, so mapping them to GRUB devices is not trivial.
Here, get the start sector of a partition by HDIO_GETGEO, and
compare it with each partition PUPA recognizes. */
compare it with each partition GRUB recognizes. */
{
char *name;
pupa_disk_t disk;
grub_disk_t disk;
int fd;
struct hd_geometry hdg;
int dos_part = -1;
int bsd_part = -1;
auto int find_partition (const pupa_partition_t partition);
auto int find_partition (const grub_partition_t partition);
int find_partition (const pupa_partition_t partition)
int find_partition (const grub_partition_t partition)
{
if (partition->bsd_part < 0)
pupa_util_info ("DOS partition %d starts from %lu",
grub_util_info ("DOS partition %d starts from %lu",
partition->dos_part, partition->start);
else
pupa_util_info ("BSD partition %d,%c starts from %lu",
grub_util_info ("BSD partition %d,%c starts from %lu",
partition->dos_part, partition->bsd_part + 'a',
partition->start);
@ -761,14 +761,14 @@ pupa_util_biosdisk_get_pupa_dev (const char *os_dev)
fd = open (os_dev, O_RDONLY);
if (! fd)
{
pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", os_dev);
grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s'", os_dev);
free (name);
return 0;
}
if (ioctl (fd, HDIO_GETGEO, &hdg))
{
pupa_error (PUPA_ERR_BAD_DEVICE,
grub_error (GRUB_ERR_BAD_DEVICE,
"cannot get geometry of `%s'", os_dev);
close (fd);
free (name);
@ -777,28 +777,28 @@ pupa_util_biosdisk_get_pupa_dev (const char *os_dev)
close (fd);
pupa_util_info ("%s starts from %lu", os_dev, hdg.start);
grub_util_info ("%s starts from %lu", os_dev, hdg.start);
if (hdg.start == 0)
return name;
pupa_util_info ("opening the device %s", name);
disk = pupa_disk_open (name);
grub_util_info ("opening the device %s", name);
disk = grub_disk_open (name);
free (name);
if (! disk)
return 0;
if (pupa_partition_iterate (disk, find_partition) != PUPA_ERR_NONE)
if (grub_partition_iterate (disk, find_partition) != GRUB_ERR_NONE)
{
pupa_disk_close (disk);
grub_disk_close (disk);
return 0;
}
if (dos_part < 0)
{
pupa_disk_close (disk);
pupa_error (PUPA_ERR_BAD_DEVICE,
grub_disk_close (disk);
grub_error (GRUB_ERR_BAD_DEVICE,
"cannot find the partition of `%s'", os_dev);
return 0;
}
@ -834,7 +834,7 @@ pupa_util_biosdisk_get_pupa_dev (const char *os_dev)
}
#else
# warning "The function `pupa_util_biosdisk_get_pupa_dev' might not work on your OS correctly."
# warning "The function `grub_util_biosdisk_get_grub_dev' might not work on your OS correctly."
return make_device_name (drive, -1, -1);
#endif
}

View file

@ -1,9 +1,9 @@
/* getroot.c - Get root device */
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003 Free Software Foundation, Inc.
*
* PUPA is free software; you can redistribute it and/or modify
* 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 2 of the License, or
* (at your option) any later version.
@ -14,7 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PUPA; if not, write to the Free Software
* along with GRUB; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
@ -23,8 +23,8 @@
#include <string.h>
#include <dirent.h>
#include <pupa/util/misc.h>
#include <pupa/i386/pc/util/biosdisk.h>
#include <grub/util/misc.h>
#include <grub/i386/pc/util/biosdisk.h>
static void
strip_extra_slashes (char *dir)
@ -65,7 +65,7 @@ xgetcwd (void)
}
char *
pupa_get_prefix (const char *dir)
grub_get_prefix (const char *dir)
{
char *saved_cwd;
char *abs_dir, *prev_dir;
@ -76,28 +76,28 @@ pupa_get_prefix (const char *dir)
saved_cwd = xgetcwd ();
if (chdir (dir) < 0)
pupa_util_error ("Cannot change directory to `%s'", dir);
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)
pupa_util_error ("Cannot stat `%s'", dir);
grub_util_error ("Cannot stat `%s'", dir);
if (! S_ISDIR (prev_st.st_mode))
pupa_util_error ("`%s' is not a directory", dir);
grub_util_error ("`%s' is not a directory", dir);
while (1)
{
if (chdir ("..") < 0)
pupa_util_error ("Cannot change directory to the parent");
grub_util_error ("Cannot change directory to the parent");
if (stat (".", &st) < 0)
pupa_util_error ("Cannot stat current directory");
grub_util_error ("Cannot stat current directory");
if (! S_ISDIR (st.st_mode))
pupa_util_error ("Current directory is not a directory???");
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;
@ -114,13 +114,13 @@ pupa_get_prefix (const char *dir)
strip_extra_slashes (prefix);
if (chdir (saved_cwd) < 0)
pupa_util_error ("Cannot change directory to `%s'", dir);
grub_util_error ("Cannot change directory to `%s'", dir);
free (saved_cwd);
free (abs_dir);
free (prev_dir);
pupa_util_info ("prefix = %s", prefix);
grub_util_info ("prefix = %s", prefix);
return prefix;
}
@ -137,7 +137,7 @@ find_root_device (const char *dir, dev_t dev)
saved_cwd = xgetcwd ();
pupa_util_info ("changing current directory to %s", dir);
grub_util_info ("changing current directory to %s", dir);
if (chdir (dir) < 0)
{
free (saved_cwd);
@ -170,7 +170,7 @@ find_root_device (const char *dir, dev_t dev)
if (res)
{
if (chdir (saved_cwd) < 0)
pupa_util_error ("Cannot restore the original directory");
grub_util_error ("Cannot restore the original directory");
free (saved_cwd);
closedir (dp);
@ -191,7 +191,7 @@ find_root_device (const char *dir, dev_t dev)
free (cwd);
if (chdir (saved_cwd) < 0)
pupa_util_error ("Cannot restore the original directory");
grub_util_error ("Cannot restore the original directory");
free (saved_cwd);
closedir (dp);
@ -200,7 +200,7 @@ find_root_device (const char *dir, dev_t dev)
}
if (chdir (saved_cwd) < 0)
pupa_util_error ("Cannot restore the original directory");
grub_util_error ("Cannot restore the original directory");
free (saved_cwd);
closedir (dp);
@ -208,18 +208,18 @@ find_root_device (const char *dir, dev_t dev)
}
char *
pupa_guess_root_device (const char *dir)
grub_guess_root_device (const char *dir)
{
struct stat st;
char *os_dev;
if (stat (dir, &st) < 0)
pupa_util_error ("Cannot stat `%s'", dir);
grub_util_error ("Cannot stat `%s'", dir);
/* This might be truly slow, but is there any better way? */
os_dev = find_root_device ("/dev", st.st_dev);
if (! os_dev)
return 0;
return pupa_util_biosdisk_get_pupa_dev (os_dev);
return grub_util_biosdisk_get_grub_dev (os_dev);
}

View file

@ -1,9 +1,9 @@
/* pupa-mkimage.c - make a bootable image */
/* grub-mkimage.c - make a bootable image */
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003,2004 Free Software Foundation, Inc.
*
* PUPA is free software; you can redistribute it and/or modify
* 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 2 of the License, or
* (at your option) any later version.
@ -14,18 +14,18 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PUPA; if not, write to the Free Software
* along with GRUB; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <pupa/types.h>
#include <pupa/machine/boot.h>
#include <pupa/machine/kernel.h>
#include <pupa/kernel.h>
#include <pupa/disk.h>
#include <pupa/util/misc.h>
#include <pupa/util/resolve.h>
#include <grub/types.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
#include <grub/kernel.h>
#include <grub/disk.h>
#include <grub/util/misc.h>
#include <grub/util/resolve.h>
#include <stdio.h>
#include <unistd.h>
@ -44,69 +44,69 @@ compress_kernel (char *kernel_img, size_t kernel_size,
lzo_uint size;
char *wrkmem;
pupa_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
if (kernel_size < PUPA_KERNEL_MACHINE_RAW_SIZE)
pupa_util_error ("the core image is too small");
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
grub_util_error ("the core image is too small");
if (lzo_init () != LZO_E_OK)
pupa_util_error ("cannot initialize LZO");
grub_util_error ("cannot initialize LZO");
*core_img = xmalloc (kernel_size + kernel_size / 64 + 16 + 3);
wrkmem = xmalloc (LZO1X_999_MEM_COMPRESS);
memcpy (*core_img, kernel_img, PUPA_KERNEL_MACHINE_RAW_SIZE);
memcpy (*core_img, kernel_img, GRUB_KERNEL_MACHINE_RAW_SIZE);
pupa_util_info ("compressing the core image");
if (lzo1x_999_compress (kernel_img + PUPA_KERNEL_MACHINE_RAW_SIZE,
kernel_size - PUPA_KERNEL_MACHINE_RAW_SIZE,
*core_img + PUPA_KERNEL_MACHINE_RAW_SIZE,
grub_util_info ("compressing the core image");
if (lzo1x_999_compress (kernel_img + GRUB_KERNEL_MACHINE_RAW_SIZE,
kernel_size - GRUB_KERNEL_MACHINE_RAW_SIZE,
*core_img + GRUB_KERNEL_MACHINE_RAW_SIZE,
&size, wrkmem)
!= LZO_E_OK)
pupa_util_error ("cannot compress the kernel image");
grub_util_error ("cannot compress the kernel image");
free (wrkmem);
*core_size = (size_t) size + PUPA_KERNEL_MACHINE_RAW_SIZE;
*core_size = (size_t) size + GRUB_KERNEL_MACHINE_RAW_SIZE;
}
static void
generate_image (const char *dir, FILE *out, char *mods[])
{
pupa_addr_t module_addr = 0;
grub_addr_t module_addr = 0;
char *kernel_img, *boot_img, *core_img;
size_t kernel_size, boot_size, total_module_size, core_size;
char *kernel_path, *boot_path;
unsigned num;
size_t offset;
struct pupa_util_path_list *path_list, *p, *next;
struct grub_util_path_list *path_list, *p, *next;
path_list = pupa_util_resolve_dependencies (dir, "moddep.lst", mods);
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
kernel_path = pupa_util_get_path (dir, "kernel.img");
kernel_size = pupa_util_get_image_size (kernel_path);
kernel_path = grub_util_get_path (dir, "kernel.img");
kernel_size = grub_util_get_image_size (kernel_path);
total_module_size = 0;
for (p = path_list; p; p = p->next)
total_module_size += (pupa_util_get_image_size (p->name)
+ sizeof (struct pupa_module_header));
total_module_size += (grub_util_get_image_size (p->name)
+ sizeof (struct grub_module_header));
pupa_util_info ("the total module size is 0x%x", total_module_size);
grub_util_info ("the total module size is 0x%x", total_module_size);
kernel_img = xmalloc (kernel_size + total_module_size);
pupa_util_load_image (kernel_path, kernel_img);
grub_util_load_image (kernel_path, kernel_img);
offset = kernel_size;
for (p = path_list; p; p = p->next)
{
struct pupa_module_header *header;
struct grub_module_header *header;
size_t mod_size;
mod_size = pupa_util_get_image_size (p->name);
mod_size = grub_util_get_image_size (p->name);
header = (struct pupa_module_header *) (kernel_img + offset);
header->offset = pupa_cpu_to_le32 (sizeof (*header));
header->size = pupa_cpu_to_le32 (mod_size + sizeof (*header));
header = (struct grub_module_header *) (kernel_img + offset);
header->offset = grub_cpu_to_le32 (sizeof (*header));
header->size = grub_cpu_to_le32 (mod_size + sizeof (*header));
pupa_util_load_image (p->name, kernel_img + offset + sizeof (*header));
grub_util_load_image (p->name, kernel_img + offset + sizeof (*header));
offset += sizeof (*header) + mod_size;
}
@ -114,42 +114,42 @@ generate_image (const char *dir, FILE *out, char *mods[])
compress_kernel (kernel_img, kernel_size + total_module_size,
&core_img, &core_size);
pupa_util_info ("the core size is 0x%x", core_size);
grub_util_info ("the core size is 0x%x", core_size);
num = ((core_size + PUPA_DISK_SECTOR_SIZE - 1) >> PUPA_DISK_SECTOR_BITS);
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
if (num > 0xffff)
pupa_util_error ("the core image is too big");
grub_util_error ("the core image is too big");
boot_path = pupa_util_get_path (dir, "diskboot.img");
boot_size = pupa_util_get_image_size (boot_path);
if (boot_size != PUPA_DISK_SECTOR_SIZE)
pupa_util_error ("diskboot.img is not one sector size");
boot_path = grub_util_get_path (dir, "diskboot.img");
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("diskboot.img is not one sector size");
boot_img = pupa_util_read_image (boot_path);
boot_img = grub_util_read_image (boot_path);
/* i386 is a little endian architecture. */
*((pupa_uint16_t *) (boot_img + PUPA_DISK_SECTOR_SIZE
- PUPA_BOOT_MACHINE_LIST_SIZE + 4))
= pupa_cpu_to_le16 (num);
*((grub_uint16_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
- GRUB_BOOT_MACHINE_LIST_SIZE + 4))
= grub_cpu_to_le16 (num);
pupa_util_write_image (boot_img, boot_size, out);
grub_util_write_image (boot_img, boot_size, out);
free (boot_img);
free (boot_path);
module_addr = (path_list
? (PUPA_BOOT_MACHINE_KERNEL_ADDR + PUPA_DISK_SECTOR_SIZE
? (GRUB_BOOT_MACHINE_KERNEL_ADDR + GRUB_DISK_SECTOR_SIZE
+ kernel_size)
: 0);
pupa_util_info ("the first module address is 0x%x", module_addr);
*((pupa_uint32_t *) (core_img + PUPA_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
= pupa_cpu_to_le32 (total_module_size);
*((pupa_uint32_t *) (core_img + PUPA_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
= pupa_cpu_to_le32 (kernel_size);
*((pupa_uint32_t *) (core_img + PUPA_KERNEL_MACHINE_COMPRESSED_SIZE))
= pupa_cpu_to_le32 (core_size - PUPA_KERNEL_MACHINE_RAW_SIZE);
grub_util_info ("the first module address is 0x%x", module_addr);
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
= grub_cpu_to_le32 (total_module_size);
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
= grub_cpu_to_le32 (kernel_size);
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
= grub_cpu_to_le32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
pupa_util_write_image (core_img, core_size, out);
grub_util_write_image (core_img, core_size, out);
free (kernel_img);
free (core_img);
free (kernel_path);
@ -179,12 +179,12 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``pupa-mkimage --help'' for more information.\n");
fprintf (stderr, "Try ``grub-mkimage --help'' for more information.\n");
else
printf ("\
Usage: pupa-mkimage [OPTION]... [MODULES]\n\
Usage: grub-mkimage [OPTION]... [MODULES]\n\
\n\
Make a bootable image of PUPA.\n\
Make a bootable image of GRUB.\n\
\n\
-d, --directory=DIR use images and modules under DIR [default=%s]\n\
-o, --output=FILE output a generated image to FILE [default=stdout]\n\
@ -193,7 +193,7 @@ Make a bootable image of PUPA.\n\
-v, --verbose print verbose messages\n\
\n\
Report bugs to <%s>.\n\
", PUPA_DATADIR, PACKAGE_BUGREPORT);
", GRUB_DATADIR, PACKAGE_BUGREPORT);
exit (status);
}
@ -205,7 +205,7 @@ main (int argc, char *argv[])
char *dir = 0;
FILE *fp = stdout;
progname = "pupa-mkimage";
progname = "grub-mkimage";
while (1)
{
@ -235,7 +235,7 @@ main (int argc, char *argv[])
break;
case 'V':
printf ("pupa-mkimage (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
printf ("grub-mkimage (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
return 0;
case 'v':
@ -252,10 +252,10 @@ main (int argc, char *argv[])
{
fp = fopen (output, "wb");
if (! fp)
pupa_util_error ("cannot open %s", output);
grub_util_error ("cannot open %s", output);
}
generate_image (dir ? : PUPA_DATADIR, fp, argv + optind);
generate_image (dir ? : GRUB_DATADIR, fp, argv + optind);
fclose (fp);

View file

@ -1,9 +1,9 @@
/* pupa-setup.c - make PUPA usable */
/* grub-setup.c - make GRUB usable */
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
*
* PUPA is free software; you can redistribute it and/or modify
* 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 2 of the License, or
* (at your option) any later version.
@ -14,21 +14,21 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PUPA; if not, write to the Free Software
* along with GRUB; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <pupa/types.h>
#include <pupa/util/misc.h>
#include <pupa/device.h>
#include <pupa/disk.h>
#include <pupa/file.h>
#include <pupa/fs.h>
#include <pupa/machine/partition.h>
#include <pupa/machine/util/biosdisk.h>
#include <pupa/machine/boot.h>
#include <pupa/machine/kernel.h>
#include <grub/types.h>
#include <grub/util/misc.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/fs.h>
#include <grub/machine/partition.h>
#include <grub/machine/util/biosdisk.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
#include <stdio.h>
#include <unistd.h>
@ -37,7 +37,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pupa/util/getroot.h>
#include <grub/util/getroot.h>
#define _GNU_SOURCE 1
#include <getopt.h>
@ -47,9 +47,9 @@
#ifdef __NetBSD__
/* NetBSD uses /boot for its boot block. */
# define DEFAULT_DIRECTORY "/pupa"
# define DEFAULT_DIRECTORY "/grub"
#else
# define DEFAULT_DIRECTORY "/boot/pupa"
# define DEFAULT_DIRECTORY "/boot/grub"
#endif
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
@ -57,19 +57,19 @@
/* This is the blocklist used in the diskboot image. */
struct boot_blocklist
{
pupa_uint32_t start;
pupa_uint16_t len;
pupa_uint16_t segment;
grub_uint32_t start;
grub_uint16_t len;
grub_uint16_t segment;
} __attribute__ ((packed));
void
pupa_putchar (int c)
grub_putchar (int c)
{
putchar (c);
}
void
pupa_refresh (void)
grub_refresh (void)
{
}
@ -81,20 +81,20 @@ setup (const char *prefix, const char *dir,
char *boot_path, *core_path;
char *boot_img, *core_img;
size_t boot_size, core_size;
pupa_uint16_t core_sectors;
pupa_device_t root_dev, dest_dev;
pupa_uint8_t *boot_drive;
pupa_uint32_t *kernel_sector;
grub_uint16_t core_sectors;
grub_device_t root_dev, dest_dev;
grub_uint8_t *boot_drive;
grub_uint32_t *kernel_sector;
struct boot_blocklist *first_block, *block;
pupa_int32_t *install_dos_part, *install_bsd_part;
grub_int32_t *install_dos_part, *install_bsd_part;
char *install_prefix;
char *tmp_img;
int i;
unsigned long first_sector;
pupa_uint16_t current_segment
= PUPA_BOOT_MACHINE_KERNEL_SEG + (PUPA_DISK_SECTOR_SIZE >> 4);
pupa_uint16_t last_length = PUPA_DISK_SECTOR_SIZE;
pupa_file_t file;
grub_uint16_t current_segment
= GRUB_BOOT_MACHINE_KERNEL_SEG + (GRUB_DISK_SECTOR_SIZE >> 4);
grub_uint16_t last_length = GRUB_DISK_SECTOR_SIZE;
grub_file_t file;
FILE *fp;
unsigned long first_start = ~0UL;
@ -103,12 +103,12 @@ setup (const char *prefix, const char *dir,
auto void save_blocklists (unsigned long sector, unsigned offset,
unsigned length);
auto int find_first_partition_start (const pupa_partition_t p);
auto int find_first_partition_start (const grub_partition_t p);
int find_first_partition_start (const pupa_partition_t p)
int find_first_partition_start (const grub_partition_t p)
{
if (! pupa_partition_is_empty (p->dos_type)
&& ! pupa_partition_is_bsd (p->dos_type)
if (! grub_partition_is_empty (p->dos_type)
&& ! grub_partition_is_bsd (p->dos_type)
&& first_start > p->start)
first_start = p->start;
@ -118,11 +118,11 @@ setup (const char *prefix, const char *dir,
void save_first_sector (unsigned long sector, unsigned offset,
unsigned length)
{
pupa_util_info ("the fist sector is <%lu,%u,%u>",
grub_util_info ("the fist sector is <%lu,%u,%u>",
sector, offset, length);
if (offset != 0 || length != PUPA_DISK_SECTOR_SIZE)
pupa_util_error ("The first sector of the core file is not sector-aligned");
if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("The first sector of the core file is not sector-aligned");
first_sector = sector;
}
@ -131,97 +131,97 @@ setup (const char *prefix, const char *dir,
{
struct boot_blocklist *prev = block + 1;
pupa_util_info ("saving <%lu,%u,%u> with the segment 0x%x",
grub_util_info ("saving <%lu,%u,%u> with the segment 0x%x",
sector, offset, length, (unsigned) current_segment);
if (offset != 0 || last_length != PUPA_DISK_SECTOR_SIZE)
pupa_util_error ("Non-sector-aligned data is found in the core file");
if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("Non-sector-aligned data is found in the core file");
if (block != first_block
&& (pupa_le_to_cpu32 (prev->start)
+ pupa_le_to_cpu16 (prev->len)) == sector)
prev->len = pupa_cpu_to_le16 (pupa_le_to_cpu16 (prev->len) + 1);
&& (grub_le_to_cpu32 (prev->start)
+ grub_le_to_cpu16 (prev->len)) == sector)
prev->len = grub_cpu_to_le16 (grub_le_to_cpu16 (prev->len) + 1);
else
{
block->start = pupa_cpu_to_le32 (sector);
block->len = pupa_cpu_to_le16 (1);
block->segment = pupa_cpu_to_le16 (current_segment);
block->start = grub_cpu_to_le32 (sector);
block->len = grub_cpu_to_le16 (1);
block->segment = grub_cpu_to_le16 (current_segment);
block--;
if (block->len)
pupa_util_error ("The sectors of the core file are too fragmented");
grub_util_error ("The sectors of the core file are too fragmented");
}
last_length = length;
current_segment += PUPA_DISK_SECTOR_SIZE >> 4;
current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
}
/* Read the boot image by the OS service. */
boot_path = pupa_util_get_path (dir, boot_file);
boot_size = pupa_util_get_image_size (boot_path);
if (boot_size != PUPA_DISK_SECTOR_SIZE)
pupa_util_error ("The size of `%s' is not %d",
boot_path, PUPA_DISK_SECTOR_SIZE);
boot_img = pupa_util_read_image (boot_path);
boot_path = grub_util_get_path (dir, boot_file);
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("The size of `%s' is not %d",
boot_path, GRUB_DISK_SECTOR_SIZE);
boot_img = grub_util_read_image (boot_path);
free (boot_path);
/* Set the addresses of BOOT_DRIVE and KERNEL_SECTOR. */
boot_drive = (pupa_uint8_t *) (boot_img + PUPA_BOOT_MACHINE_BOOT_DRIVE);
kernel_sector = (pupa_uint32_t *) (boot_img
+ PUPA_BOOT_MACHINE_KERNEL_SECTOR);
boot_drive = (grub_uint8_t *) (boot_img + GRUB_BOOT_MACHINE_BOOT_DRIVE);
kernel_sector = (grub_uint32_t *) (boot_img
+ GRUB_BOOT_MACHINE_KERNEL_SECTOR);
core_path = pupa_util_get_path (dir, core_file);
core_size = pupa_util_get_image_size (core_path);
core_sectors = ((core_size + PUPA_DISK_SECTOR_SIZE - 1)
>> PUPA_DISK_SECTOR_BITS);
if (core_size < PUPA_DISK_SECTOR_SIZE)
pupa_util_error ("The size of `%s' is too small", core_path);
else if (core_size > 0xFFFF * PUPA_DISK_SECTOR_SIZE)
pupa_util_error ("The size of `%s' is too large", core_path);
core_path = grub_util_get_path (dir, core_file);
core_size = grub_util_get_image_size (core_path);
core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
>> GRUB_DISK_SECTOR_BITS);
if (core_size < GRUB_DISK_SECTOR_SIZE)
grub_util_error ("The size of `%s' is too small", core_path);
else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
grub_util_error ("The size of `%s' is too large", core_path);
core_img = pupa_util_read_image (core_path);
core_img = grub_util_read_image (core_path);
free (core_path);
/* Have FIRST_BLOCK to point to the first blocklist. */
first_block = (struct boot_blocklist *) (core_img
+ PUPA_DISK_SECTOR_SIZE
+ GRUB_DISK_SECTOR_SIZE
- sizeof (*block));
install_dos_part = (pupa_int32_t *) (core_img + PUPA_DISK_SECTOR_SIZE
+ PUPA_KERNEL_MACHINE_INSTALL_DOS_PART);
install_bsd_part = (pupa_int32_t *) (core_img + PUPA_DISK_SECTOR_SIZE
+ PUPA_KERNEL_MACHINE_INSTALL_BSD_PART);
install_prefix = (core_img + PUPA_DISK_SECTOR_SIZE
+ PUPA_KERNEL_MACHINE_PREFIX);
install_dos_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_MACHINE_INSTALL_DOS_PART);
install_bsd_part = (grub_int32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_MACHINE_INSTALL_BSD_PART);
install_prefix = (core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_MACHINE_PREFIX);
/* Open the root device and the destination device. */
root_dev = pupa_device_open (root);
root_dev = grub_device_open (root);
if (! root_dev)
pupa_util_error ("%s", pupa_errmsg);
grub_util_error ("%s", grub_errmsg);
dest_dev = pupa_device_open (dest);
dest_dev = grub_device_open (dest);
if (! dest_dev)
pupa_util_error ("%s", pupa_errmsg);
grub_util_error ("%s", grub_errmsg);
pupa_util_info ("setting the root device to `%s'", root);
if (pupa_device_set_root (root) != PUPA_ERR_NONE)
pupa_util_error ("%s", pupa_errmsg);
grub_util_info ("setting the root device to `%s'", root);
if (grub_device_set_root (root) != GRUB_ERR_NONE)
grub_util_error ("%s", grub_errmsg);
/* Read the original sector from the disk. */
tmp_img = xmalloc (PUPA_DISK_SECTOR_SIZE);
if (pupa_disk_read (dest_dev->disk, 0, 0, PUPA_DISK_SECTOR_SIZE, tmp_img))
pupa_util_error ("%s", pupa_errmsg);
tmp_img = xmalloc (GRUB_DISK_SECTOR_SIZE);
if (grub_disk_read (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, tmp_img))
grub_util_error ("%s", grub_errmsg);
/* Copy the possible DOS BPB. */
memcpy (boot_img + PUPA_BOOT_MACHINE_BPB_START,
tmp_img + PUPA_BOOT_MACHINE_BPB_START,
PUPA_BOOT_MACHINE_BPB_END - PUPA_BOOT_MACHINE_BPB_START);
memcpy (boot_img + GRUB_BOOT_MACHINE_BPB_START,
tmp_img + GRUB_BOOT_MACHINE_BPB_START,
GRUB_BOOT_MACHINE_BPB_END - GRUB_BOOT_MACHINE_BPB_START);
/* Copy the possible partition table. */
if (dest_dev->disk->has_partitions)
memcpy (boot_img + PUPA_BOOT_MACHINE_WINDOWS_NT_MAGIC,
tmp_img + PUPA_BOOT_MACHINE_WINDOWS_NT_MAGIC,
PUPA_BOOT_MACHINE_PART_END - PUPA_BOOT_MACHINE_WINDOWS_NT_MAGIC);
memcpy (boot_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
tmp_img + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC,
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
free (tmp_img);
@ -229,19 +229,19 @@ setup (const char *prefix, const char *dir,
try to embed the core image into after the MBR. */
if (dest_dev->disk->has_partitions && ! dest_dev->disk->partition)
{
pupa_partition_iterate (dest_dev->disk, find_first_partition_start);
grub_partition_iterate (dest_dev->disk, find_first_partition_start);
/* If there is enough space... */
if ((unsigned long) core_sectors + 1 <= first_start)
{
pupa_util_info ("will embed the core image into after the MBR");
grub_util_info ("will embed the core image into after the MBR");
/* The first blocklist contains the whole sectors. */
first_block->start = pupa_cpu_to_le32 (2);
first_block->len = pupa_cpu_to_le16 (core_sectors - 1);
first_block->start = grub_cpu_to_le32 (2);
first_block->len = grub_cpu_to_le16 (core_sectors - 1);
first_block->segment
= pupa_cpu_to_le16 (PUPA_BOOT_MACHINE_KERNEL_SEG
+ (PUPA_DISK_SECTOR_SIZE >> 4));
= grub_cpu_to_le16 (GRUB_BOOT_MACHINE_KERNEL_SEG
+ (GRUB_DISK_SECTOR_SIZE >> 4));
/* Make sure that the second blocklist is a terminator. */
block = first_block - 1;
@ -253,39 +253,39 @@ setup (const char *prefix, const char *dir,
if (root_dev->disk->partition)
{
*install_dos_part
= pupa_cpu_to_le32 (root_dev->disk->partition->dos_part);
= grub_cpu_to_le32 (root_dev->disk->partition->dos_part);
*install_bsd_part
= pupa_cpu_to_le32 (root_dev->disk->partition->bsd_part);
= grub_cpu_to_le32 (root_dev->disk->partition->bsd_part);
}
else
*install_dos_part = *install_bsd_part = pupa_cpu_to_le32 (-1);
*install_dos_part = *install_bsd_part = grub_cpu_to_le32 (-1);
strcpy (install_prefix, prefix);
/* Write the core image onto the disk. */
if (pupa_disk_write (dest_dev->disk, 1, 0, core_size, core_img))
pupa_util_error ("%s", pupa_errmsg);
if (grub_disk_write (dest_dev->disk, 1, 0, core_size, core_img))
grub_util_error ("%s", grub_errmsg);
/* The boot image and the core image are on the same drive,
so there is no need to specify the boot drive explicitly. */
*boot_drive = 0xff;
*kernel_sector = pupa_cpu_to_le32 (1);
*kernel_sector = grub_cpu_to_le32 (1);
/* Write the boot image onto the disk. */
if (pupa_disk_write (dest_dev->disk, 0, 0, PUPA_DISK_SECTOR_SIZE,
if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE,
boot_img))
pupa_util_error ("%s", pupa_errmsg);
grub_util_error ("%s", grub_errmsg);
goto finish;
}
}
/* The core image must be put on a filesystem unfortunately. */
pupa_util_info ("will leave the core image on the filesystem");
grub_util_info ("will leave the core image on the filesystem");
/* Make sure that PUPA reads the identical image as the OS. */
/* Make sure that GRUB reads the identical image as the OS. */
tmp_img = xmalloc (core_size);
core_path = pupa_util_get_path (prefix, core_file);
core_path = grub_util_get_path (prefix, core_file);
/* It is a Good Thing to sync two times. */
sync ();
@ -295,20 +295,20 @@ setup (const char *prefix, const char *dir,
for (i = 0; i < MAX_TRIES; i++)
{
pupa_util_info ("attempting to read the core image `%s' from PUPA%s",
grub_util_info ("attempting to read the core image `%s' from GRUB%s",
core_path, (i == 0) ? "" : " again");
pupa_disk_cache_invalidate_all ();
grub_disk_cache_invalidate_all ();
file = pupa_file_open (core_path);
file = grub_file_open (core_path);
if (file)
{
if (pupa_file_size (file) != (pupa_ssize_t) core_size)
pupa_util_info ("succeeded in opening the core image but the size is different (%d != %d)",
(int) pupa_file_size (file), (int) core_size);
else if (pupa_file_read (file, tmp_img, core_size)
!= (pupa_ssize_t) core_size)
pupa_util_info ("succeeded in opening the core image but cannot read %d bytes",
if (grub_file_size (file) != (grub_ssize_t) core_size)
grub_util_info ("succeeded in opening the core image but the size is different (%d != %d)",
(int) grub_file_size (file), (int) core_size);
else if (grub_file_read (file, tmp_img, core_size)
!= (grub_ssize_t) core_size)
grub_util_info ("succeeded in opening the core image but cannot read %d bytes",
(int) core_size);
else if (memcmp (core_img, tmp_img, core_size) != 0)
{
@ -331,29 +331,29 @@ setup (const char *prefix, const char *dir,
}
#endif
pupa_util_info ("succeeded in opening the core image but the data is different");
grub_util_info ("succeeded in opening the core image but the data is different");
}
else
{
pupa_file_close (file);
grub_file_close (file);
break;
}
pupa_file_close (file);
grub_file_close (file);
}
else
pupa_util_info ("couldn't open the core image");
grub_util_info ("couldn't open the core image");
if (pupa_errno)
pupa_util_info ("error message = %s", pupa_errmsg);
if (grub_errno)
grub_util_info ("error message = %s", grub_errmsg);
pupa_errno = PUPA_ERR_NONE;
grub_errno = GRUB_ERR_NONE;
sync ();
sleep (1);
}
if (i == MAX_TRIES)
pupa_util_error ("Cannot read `%s' correctly", core_path);
grub_util_error ("Cannot read `%s' correctly", core_path);
/* Clean out the blocklists. */
block = first_block;
@ -366,34 +366,34 @@ setup (const char *prefix, const char *dir,
block--;
if ((char *) block <= core_img)
pupa_util_error ("No terminator in the core image");
grub_util_error ("No terminator in the core image");
}
/* Now read the core image to determine where the sectors are. */
file = pupa_file_open (core_path);
file = grub_file_open (core_path);
if (! file)
pupa_util_error ("%s", pupa_errmsg);
grub_util_error ("%s", grub_errmsg);
file->read_hook = save_first_sector;
if (pupa_file_read (file, tmp_img, PUPA_DISK_SECTOR_SIZE)
!= PUPA_DISK_SECTOR_SIZE)
pupa_util_error ("Failed to read the first sector of the core image");
if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
!= GRUB_DISK_SECTOR_SIZE)
grub_util_error ("Failed to read the first sector of the core image");
block = first_block;
file->read_hook = save_blocklists;
if (pupa_file_read (file, tmp_img, core_size - PUPA_DISK_SECTOR_SIZE)
!= (pupa_ssize_t) core_size - PUPA_DISK_SECTOR_SIZE)
pupa_util_error ("Failed to read the rest sectors of the core image");
if (grub_file_read (file, tmp_img, core_size - GRUB_DISK_SECTOR_SIZE)
!= (grub_ssize_t) core_size - GRUB_DISK_SECTOR_SIZE)
grub_util_error ("Failed to read the rest sectors of the core image");
free (core_path);
free (tmp_img);
*kernel_sector = pupa_cpu_to_le32 (first_sector);
*kernel_sector = grub_cpu_to_le32 (first_sector);
/* If the destination device is different from the root device,
it is necessary to embed the boot drive explicitly. */
if (root_dev->disk->id != dest_dev->disk->id)
*boot_drive = (pupa_uint8_t) root_dev->disk->id;
*boot_drive = (grub_uint8_t) root_dev->disk->id;
else
*boot_drive = 0xFF;
@ -401,29 +401,29 @@ setup (const char *prefix, const char *dir,
if (root_dev->disk->partition)
{
*install_dos_part
= pupa_cpu_to_le32 (root_dev->disk->partition->dos_part);
= grub_cpu_to_le32 (root_dev->disk->partition->dos_part);
*install_bsd_part
= pupa_cpu_to_le32 (root_dev->disk->partition->bsd_part);
= grub_cpu_to_le32 (root_dev->disk->partition->bsd_part);
}
else
*install_dos_part = *install_bsd_part = pupa_cpu_to_le32 (-1);
*install_dos_part = *install_bsd_part = grub_cpu_to_le32 (-1);
strcpy (install_prefix, prefix);
/* Write the first two sectors of the core image onto the disk. */
core_path = pupa_util_get_path (dir, core_file);
pupa_util_info ("opening the core image `%s'", core_path);
core_path = grub_util_get_path (dir, core_file);
grub_util_info ("opening the core image `%s'", core_path);
fp = fopen (core_path, "r+b");
if (! fp)
pupa_util_error ("Cannot open `%s'", core_path);
grub_util_error ("Cannot open `%s'", core_path);
pupa_util_write_image (core_img, PUPA_DISK_SECTOR_SIZE * 2, fp);
grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
fclose (fp);
free (core_path);
/* Write the boot image onto the disk. */
if (pupa_disk_write (dest_dev->disk, 0, 0, PUPA_DISK_SECTOR_SIZE, boot_img))
pupa_util_error ("%s", pupa_errmsg);
if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, boot_img))
grub_util_error ("%s", grub_errmsg);
finish:
@ -432,8 +432,8 @@ setup (const char *prefix, const char *dir,
free (core_img);
free (boot_img);
pupa_device_close (dest_dev);
pupa_device_close (root_dev);
grub_device_close (dest_dev);
grub_device_close (root_dev);
}
static struct option options[] =
@ -453,17 +453,17 @@ static void
usage (int status)
{
if (status)
fprintf (stderr, "Try ``pupa-setup --help'' for more information.\n");
fprintf (stderr, "Try ``grub-setup --help'' for more information.\n");
else
printf ("\
Usage: pupa-setup [OPTION]... DEVICE\n\
Usage: grub-setup [OPTION]... DEVICE\n\
\n\
Set up images to boot from DEVICE.\n\
DEVICE must be a PUPA device (e.g. ``(hd0,0)'').\n\
DEVICE must be a GRUB device (e.g. ``(hd0,0)'').\n\
\n\
-b, --boot-file=FILE use FILE as the boot file [default=%s]\n\
-c, --core-file=FILE use FILE as the core file [default=%s]\n\
-d, --directory=DIR use PUPA files in the directory DIR [default=%s]\n\
-d, --directory=DIR use GRUB files in the directory DIR [default=%s]\n\
-m, --device-map=FILE use FILE as the device map [default=%s]\n\
-r, --root-device=DEV use DEV as the root device [default=guessed]\n\
-h, --help display this message and exit\n\
@ -501,7 +501,7 @@ main (int argc, char *argv[])
char *prefix;
char *dest_dev;
progname = "pupa-setup";
progname = "grub-setup";
/* Check for options. */
while (1)
@ -553,7 +553,7 @@ main (int argc, char *argv[])
break;
case 'V':
printf ("pupa-setup (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
printf ("grub-setup (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION);
return 0;
case 'v':
@ -587,21 +587,21 @@ main (int argc, char *argv[])
usage (1);
}
prefix = pupa_get_prefix (dir ? : DEFAULT_DIRECTORY);
prefix = grub_get_prefix (dir ? : DEFAULT_DIRECTORY);
/* Initialize the emulated biosdisk driver. */
pupa_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
/* Initialize filesystems. */
pupa_fat_init ();
pupa_ext2_init ();
grub_fat_init ();
grub_ext2_init ();
if (root_dev)
{
char *tmp = get_device_name (root_dev);
if (! tmp)
pupa_util_error ("Invalid root device `%s'", root_dev);
grub_util_error ("Invalid root device `%s'", root_dev);
tmp = xstrdup (tmp);
free (root_dev);
@ -609,12 +609,12 @@ main (int argc, char *argv[])
}
else
{
root_dev = pupa_guess_root_device (dir ? : DEFAULT_DIRECTORY);
root_dev = grub_guess_root_device (dir ? : DEFAULT_DIRECTORY);
if (! root_dev)
{
pupa_util_info ("guessing the root device failed, because of `%s'",
pupa_errmsg);
pupa_util_error ("Cannot guess the root device. Specify the option ``--root-device''.");
grub_util_info ("guessing the root device failed, because of `%s'",
grub_errmsg);
grub_util_error ("Cannot guess the root device. Specify the option ``--root-device''.");
}
}
@ -626,10 +626,10 @@ main (int argc, char *argv[])
root_dev, dest_dev);
/* Free resources. */
pupa_ext2_fini ();
pupa_fat_fini ();
grub_ext2_fini ();
grub_fat_fini ();
pupa_util_biosdisk_fini ();
grub_util_biosdisk_fini ();
free (boot_file);
free (core_file);

View file

@ -1,8 +1,8 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003 Free Software Foundation, Inc.
*
* PUPA is free software; you can redistribute it and/or modify
* 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 2 of the License, or
* (at your option) any later version.
@ -13,7 +13,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PUPA; if not, write to the Free Software
* along with GRUB; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
@ -26,15 +26,15 @@
#include <sys/times.h>
#include <malloc.h>
#include <pupa/util/misc.h>
#include <pupa/mm.h>
#include <pupa/term.h>
#include <grub/util/misc.h>
#include <grub/mm.h>
#include <grub/term.h>
char *progname = 0;
int verbosity = 0;
void
pupa_util_info (const char *fmt, ...)
grub_util_info (const char *fmt, ...)
{
if (verbosity > 0)
{
@ -49,7 +49,7 @@ pupa_util_info (const char *fmt, ...)
}
void
pupa_util_error (const char *fmt, ...)
grub_util_error (const char *fmt, ...)
{
va_list ap;
@ -68,7 +68,7 @@ xmalloc (size_t size)
p = malloc (size);
if (! p)
pupa_util_error ("out of memory");
grub_util_error ("out of memory");
return p;
}
@ -78,7 +78,7 @@ xrealloc (void *ptr, size_t size)
{
ptr = realloc (ptr, size);
if (! ptr)
pupa_util_error ("out of memory");
grub_util_error ("out of memory");
return ptr;
}
@ -97,7 +97,7 @@ xstrdup (const char *str)
}
char *
pupa_util_get_path (const char *dir, const char *file)
grub_util_get_path (const char *dir, const char *file)
{
char *path;
@ -107,36 +107,36 @@ pupa_util_get_path (const char *dir, const char *file)
}
size_t
pupa_util_get_image_size (const char *path)
grub_util_get_image_size (const char *path)
{
struct stat st;
pupa_util_info ("getting the size of %s", path);
grub_util_info ("getting the size of %s", path);
if (stat (path, &st) == -1)
pupa_util_error ("cannot stat %s", path);
grub_util_error ("cannot stat %s", path);
return st.st_size;
}
char *
pupa_util_read_image (const char *path)
grub_util_read_image (const char *path)
{
char *img;
FILE *fp;
size_t size;
pupa_util_info ("reading %s", path);
grub_util_info ("reading %s", path);
size = pupa_util_get_image_size (path);
size = grub_util_get_image_size (path);
img = (char *) xmalloc (size);
fp = fopen (path, "rb");
if (! fp)
pupa_util_error ("cannot open %s", path);
grub_util_error ("cannot open %s", path);
if (fread (img, 1, size, fp) != size)
pupa_util_error ("cannot read %s", path);
grub_util_error ("cannot read %s", path);
fclose (fp);
@ -144,83 +144,83 @@ pupa_util_read_image (const char *path)
}
void
pupa_util_load_image (const char *path, char *buf)
grub_util_load_image (const char *path, char *buf)
{
FILE *fp;
size_t size;
pupa_util_info ("reading %s", path);
grub_util_info ("reading %s", path);
size = pupa_util_get_image_size (path);
size = grub_util_get_image_size (path);
fp = fopen (path, "rb");
if (! fp)
pupa_util_error ("cannot open %s", path);
grub_util_error ("cannot open %s", path);
if (fread (buf, 1, size, fp) != size)
pupa_util_error ("cannot read %s", path);
grub_util_error ("cannot read %s", path);
fclose (fp);
}
void
pupa_util_write_image (const char *img, size_t size, FILE *out)
grub_util_write_image (const char *img, size_t size, FILE *out)
{
pupa_util_info ("writing 0x%x bytes", size);
grub_util_info ("writing 0x%x bytes", size);
if (fwrite (img, 1, size, out) != size)
pupa_util_error ("write failed");
grub_util_error ("write failed");
}
void *
pupa_malloc (unsigned size)
grub_malloc (unsigned size)
{
return xmalloc (size);
}
void
pupa_free (void *ptr)
grub_free (void *ptr)
{
free (ptr);
}
void *
pupa_realloc (void *ptr, unsigned size)
grub_realloc (void *ptr, unsigned size)
{
return xrealloc (ptr, size);
}
void *
pupa_memalign (pupa_size_t align, pupa_size_t size)
grub_memalign (grub_size_t align, grub_size_t size)
{
void *p;
p = memalign (align, size);
if (! p)
pupa_util_error ("out of memory");
grub_util_error ("out of memory");
return p;
}
/* Some functions that we don't use. */
void
pupa_mm_init_region (void *addr __attribute__ ((unused)),
pupa_size_t size __attribute__ ((unused)))
grub_mm_init_region (void *addr __attribute__ ((unused)),
grub_size_t size __attribute__ ((unused)))
{
}
void
pupa_register_exported_symbols (void)
grub_register_exported_symbols (void)
{
}
void
pupa_stop (void)
grub_stop (void)
{
exit (1);
}
pupa_uint32_t
pupa_get_rtc (void)
grub_uint32_t
grub_get_rtc (void)
{
struct tms currtime;

View file

@ -1,8 +1,8 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002 Free Software Foundation, Inc.
*
* PUPA is free software; you can redistribute it and/or modify
* 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 2 of the License, or
* (at your option) any later version.
@ -13,7 +13,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PUPA; if not, write to the Free Software
* along with GRUB; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
@ -22,8 +22,8 @@
#include <stdlib.h>
#include <ctype.h>
#include <pupa/util/resolve.h>
#include <pupa/util/misc.h>
#include <grub/util/resolve.h>
#include <grub/util/misc.h>
/* Module. */
struct mod_list
@ -85,7 +85,7 @@ read_dep_list (FILE *fp)
/* Get the target name. */
p = strchr (buf, ':');
if (! p)
pupa_util_error ("invalid line format: %s", buf);
grub_util_error ("invalid line format: %s", buf);
*p++ = '\0';
@ -174,7 +174,7 @@ get_module_path (const char *prefix, const char *str)
if (dir)
return base;
ret = pupa_util_get_path (prefix, base);
ret = grub_util_get_path (prefix, base);
free (base);
return ret;
}
@ -183,11 +183,11 @@ static void
add_module (const char *dir,
struct dep_list *dep_list,
struct mod_list **mod_head,
struct pupa_util_path_list **path_head,
struct grub_util_path_list **path_head,
const char *name)
{
char *mod_name;
struct pupa_util_path_list *path;
struct grub_util_path_list *path;
struct mod_list *mod;
struct dep_list *dep;
@ -218,14 +218,14 @@ add_module (const char *dir,
*mod_head = mod;
/* Add this path. */
path = (struct pupa_util_path_list *) xmalloc (sizeof (*path));
path = (struct grub_util_path_list *) xmalloc (sizeof (*path));
path->name = get_module_path (dir, name);
path->next = *path_head;
*path_head = path;
}
struct pupa_util_path_list *
pupa_util_resolve_dependencies (const char *prefix,
struct grub_util_path_list *
grub_util_resolve_dependencies (const char *prefix,
const char *dep_list_file,
char *modules[])
{
@ -233,12 +233,12 @@ pupa_util_resolve_dependencies (const char *prefix,
FILE *fp;
struct dep_list *dep_list;
struct mod_list *mod_list = 0;
struct pupa_util_path_list *path_list = 0;
struct grub_util_path_list *path_list = 0;
path = pupa_util_get_path (prefix, dep_list_file);
path = grub_util_get_path (prefix, dep_list_file);
fp = fopen (path, "r");
if (! fp)
pupa_util_error ("cannot open %s", path);
grub_util_error ("cannot open %s", path);
free (path);
dep_list = read_dep_list (fp);
@ -254,7 +254,7 @@ pupa_util_resolve_dependencies (const char *prefix,
free_mod_list (mod_list);
{ /* Reverse the path_list */
struct pupa_util_path_list *p, *prev, *next;
struct grub_util_path_list *p, *prev, *next;
for (p = path_list, prev = NULL; p; p = next)
{