merge with mainline

This commit is contained in:
BVK Chaitanya 2010-05-04 09:09:03 +05:30
commit 81827e248c
69 changed files with 2217 additions and 592 deletions

View file

@ -26,6 +26,7 @@
#include <grub/file.h>
#include <grub/device.h>
#include <grub/command.h>
#include <grub/i18n.h>
/* set ENVVAR=VALUE */
static grub_err_t
@ -178,11 +179,13 @@ void
grub_register_core_commands (void)
{
grub_register_command ("set", grub_core_cmd_set,
"[ENVVAR=VALUE]", "Set an environment variable.");
N_("[ENVVAR=VALUE]"),
N_("Set an environment variable."));
grub_register_command ("unset", grub_core_cmd_unset,
"ENVVAR", "Remove an environment variable.");
N_("ENVVAR"),
N_("Remove an environment variable."));
grub_register_command ("ls", grub_core_cmd_ls,
"[ARG]", "List devices or files.");
N_("[ARG]"), N_("List devices or files."));
grub_register_command ("insmod", grub_core_cmd_insmod,
"MODULE", "Insert a module.");
N_("MODULE"), N_("Insert a module."));
}

View file

@ -22,8 +22,10 @@
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef __CYGWIN__
# include <sys/fcntl.h>
@ -83,103 +85,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 *
@ -641,4 +546,3 @@ grub_util_check_char_device (const char *blk_dev)
else
return 0;
}

View file

@ -246,7 +246,7 @@ main (int argc, char *argv[])
if (strcmp (root_dev, "host") == 0)
dir = xstrdup (dir);
else
dir = grub_get_prefix (dir);
dir = grub_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);

View file

@ -3,8 +3,12 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <grub/mm.h>
#include <grub/err.h>
@ -171,3 +175,102 @@ grub_get_rtc (void)
+ (((tv.tv_sec % GRUB_TICKS_PER_SECOND) * 1000000 + tv.tv_usec)
* GRUB_TICKS_PER_SECOND / 1000000));
}
/* This function never prints trailing slashes (so that its output
can be appended a slash unconditionally). */
char *
grub_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. */
p = canonicalize_file_name (path);
if (p == NULL)
grub_util_error ("failed to get canonical path of %s", path);
len = strlen (p) + 1;
buf = xstrdup (p);
free (p);
if (stat (buf, &st) < 0)
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
buf2 = xstrdup (buf);
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)
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
/* buf is another filesystem; we found it. */
if (st.st_dev != num)
{
/* 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. */
if (offset == 0)
{
free (buf);
free (buf2);
return xstrdup ("");
}
else
break;
}
offset = p - buf;
/* offset == 1 means root directory. */
if (offset == 1)
{
/* 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 (len > 0 && buf3[len - 1] == '/')
{
buf3[len - 1] = '\0';
len--;
}
return buf3;
}

View file

@ -117,7 +117,9 @@ grub_machine_init (void)
return 0;
}
#if defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_QEMU)
grub_machine_mmap_init ();
#endif
grub_machine_mmap_iterate (heap_init);
grub_tsc_init ();

View file

@ -57,13 +57,23 @@ signature_found:
(long) table_header->size);
for (; table_item->size;
table_item = (grub_linuxbios_table_item_t) ((long) table_item + (long) table_item->size))
if (hook (table_item))
return 1;
{
if (table_item->tag == GRUB_LINUXBIOS_MEMBER_LINK
&& check_signature ((grub_linuxbios_table_header_t) (grub_addr_t)
*(grub_uint64_t *) (table_item + 1)))
{
table_header = (grub_linuxbios_table_header_t) (grub_addr_t)
*(grub_uint64_t *) (table_item + 1);
goto signature_found;
}
if (hook (table_item))
return 1;
}
return 0;
}
void
grub_err_t
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
{
mem_region_t mem_region;

View file

@ -66,10 +66,12 @@ multiboot_header:
.long -0x1BADB002 - MULTIBOOT_MEMORY_INFO
codestart:
#ifdef GRUB_MACHINE_MULTIBOOT
cmpl $MULTIBOOT_BOOTLOADER_MAGIC, %eax
jne 0f
movl %ebx, EXT_C(startup_multiboot_info)
0:
#endif
/* initialize the stack */
movl $GRUB_MEMORY_MACHINE_PROT_STACK, %esp

View file

@ -102,7 +102,7 @@ grub_load_config (void)
auto int hook (struct grub_module_header *);
int hook (struct grub_module_header *header)
{
/* Not an ELF module, skip. */
/* Not an embedded config, skip. */
if (header->type != OBJ_TYPE_CONFIG)
return 0;

View file

@ -148,15 +148,14 @@ grub_mm_init_region (void *addr, grub_size_t size)
grub_printf ("Using memory for heap: start=%p, end=%p\n", addr, addr + (unsigned int) size);
#endif
/* If this region is too small, ignore it. */
if (size < GRUB_MM_ALIGN * 2)
return;
/* Allocate a region from the head. */
r = (grub_mm_region_t) (((grub_addr_t) addr + GRUB_MM_ALIGN - 1)
& (~(GRUB_MM_ALIGN - 1)));
r = (grub_mm_region_t) ALIGN_UP ((grub_addr_t) addr, GRUB_MM_ALIGN);
size -= (char *) r - (char *) addr + sizeof (*r);
/* If this region is too small, ignore it. */
if (size < GRUB_MM_ALIGN)
return;
h = (grub_mm_header_t) ((char *) r + GRUB_MM_ALIGN);
h->next = h;
h->magic = GRUB_MM_FREE_MAGIC;
@ -221,9 +220,8 @@ grub_real_malloc (grub_mm_header_t *first, grub_size_t n, grub_size_t align)
+---------------+ v
*/
q->next = p->next;
p->magic = GRUB_MM_ALLOC_MAGIC;
}
else if (extra == 0 || p->size == n + extra)
else if (align == 1 || p->size == n + extra)
{
/* There might be alignment requirement, when taking it into
account memory block fits in.
@ -240,10 +238,25 @@ grub_real_malloc (grub_mm_header_t *first, grub_size_t n, grub_size_t align)
| alloc, size=n | |
+---------------+ v
*/
p->size -= n;
p += p->size;
p->size = n;
p->magic = GRUB_MM_ALLOC_MAGIC;
}
else if (extra == 0)
{
grub_mm_header_t r;
r = p + extra + n;
r->magic = GRUB_MM_FREE_MAGIC;
r->size = p->size - extra - n;
r->next = p->next;
q->next = r;
if (q == p)
{
q = r;
r->next = r;
}
}
else
{
@ -276,10 +289,11 @@ grub_real_malloc (grub_mm_header_t *first, grub_size_t n, grub_size_t align)
p->size = extra;
p->next = r;
p += extra;
p->size = n;
p->magic = GRUB_MM_ALLOC_MAGIC;
}
p->magic = GRUB_MM_ALLOC_MAGIC;
p->size = n;
/* Mark find as a start marker for next allocation to fasten it.
This will have side effect of fragmenting memory as small
pieces before this will be un-used. */

View file

@ -249,12 +249,11 @@ grub_parser_execute (char *source)
}
p = grub_strchr (source, '\n');
if (p)
*p = 0;
*line = grub_strdup (source);
if (p)
*p = '\n';
*line = grub_strndup (source, p - source);
else
*line = grub_strdup (source);
source = p ? p + 1 : 0;
return 0;
}