remove all trailing whitespace

This commit is contained in:
fzielcke 2009-06-10 21:04:23 +00:00
parent d2d4966571
commit b39f9d20a9
222 changed files with 3286 additions and 3286 deletions

View file

@ -124,7 +124,7 @@ PROGRAMS = $(bin_UTILITIES) $(sbin_UTILITIES)
SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(grub-mkconfig_SCRIPTS) SCRIPTS = $(bin_SCRIPTS) $(sbin_SCRIPTS) $(grub-mkconfig_SCRIPTS)
CLEANFILES = CLEANFILES =
MOSTLYCLEANFILES = MOSTLYCLEANFILES =
DISTCLEANFILES = config.status config.cache config.log config.h \ DISTCLEANFILES = config.status config.cache config.log config.h \
Makefile stamp-h include/grub/cpu include/grub/machine \ Makefile stamp-h include/grub/cpu include/grub/machine \
gensymlist.sh genkernsyms.sh build_env.mk gensymlist.sh genkernsyms.sh build_env.mk

2
aclocal.m4 vendored
View file

@ -232,7 +232,7 @@ AC_MSG_CHECKING(dnl
[whether an absolute indirect call/jump must not be prefixed with an asterisk]) [whether an absolute indirect call/jump must not be prefixed with an asterisk])
AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk, AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
[cat > conftest.s <<\EOF [cat > conftest.s <<\EOF
lcall *(offset) lcall *(offset)
offset: offset:
.long 0 .long 0
.word 0 .word 0

View file

@ -19,7 +19,7 @@
#include <grub/boot.h> #include <grub/boot.h>
#include <grub/machine/boot.h> #include <grub/machine/boot.h>
/* /*
* defines for the code go here * defines for the code go here
*/ */
@ -44,7 +44,7 @@
in real mode. */ in real mode. */
.code16 .code16
.globl _start, start; .globl _start, start;
_start: _start:
start: start:
/* /*
@ -70,7 +70,7 @@ start:
/* scratch space */ /* scratch space */
mode: mode:
.byte 0 .byte 0
disk_address_packet: disk_address_packet:
sectors: sectors:
.long 0 .long 0
heads: heads:
@ -91,7 +91,7 @@ cylinder_start:
* End of BIOS parameter block. * End of BIOS parameter block.
*/ */
boot_version: boot_version:
.byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR .byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
kernel_address: kernel_address:
.word GRUB_BOOT_MACHINE_KERNEL_ADDR .word GRUB_BOOT_MACHINE_KERNEL_ADDR
@ -99,7 +99,7 @@ kernel_segment:
.word GRUB_BOOT_MACHINE_KERNEL_SEG .word GRUB_BOOT_MACHINE_KERNEL_SEG
kernel_sector: kernel_sector:
.long 1, 0 .long 1, 0
boot_drive: boot_drive:
.byte 0xff /* the disk to load kernel from */ .byte 0xff /* the disk to load kernel from */
/* 0xff means use the boot drive */ /* 0xff means use the boot drive */
root_drive: root_drive:
@ -124,7 +124,7 @@ boot_drive_check:
jnz 1f jnz 1f
movb $0x80, %dl movb $0x80, %dl
1: 1:
/* /*
* ljmp to the next instruction because some bogus BIOSes * ljmp to the next instruction because some bogus BIOSes
* jump to 07C0:0000 instead of 0000:7C00. * jump to 07C0:0000 instead of 0000:7C00.
@ -136,7 +136,7 @@ boot_drive_check:
ljmp $0, $ABS(real_start) ljmp $0, $ABS(real_start)
#endif #endif
real_start: real_start:
/* set up %ds and %ss as offset from 0 */ /* set up %ds and %ss as offset from 0 */
xorw %ax, %ax xorw %ax, %ax
@ -176,17 +176,17 @@ real_start:
#else #else
movw $ABS(disk_address_packet), %si movw $ABS(disk_address_packet), %si
#endif #endif
/* do not probe LBA if the drive is a floppy */ /* do not probe LBA if the drive is a floppy */
testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl testb $GRUB_BOOT_MACHINE_BIOS_HD_FLAG, %dl
jz chs_mode jz chs_mode
/* check if LBA is supported */ /* check if LBA is supported */
movb $0x41, %ah movb $0x41, %ah
movw $0x55aa, %bx movw $0x55aa, %bx
int $0x13 int $0x13
/* /*
* %dl may have been clobbered by INT 13, AH=41H. * %dl may have been clobbered by INT 13, AH=41H.
* This happens, for example, with AST BIOS 1.04. * This happens, for example, with AST BIOS 1.04.
*/ */
@ -200,15 +200,15 @@ real_start:
andw $1, %cx andw $1, %cx
jz chs_mode jz chs_mode
lba_mode: lba_mode:
xorw %ax, %ax xorw %ax, %ax
movw %ax, 4(%si) movw %ax, 4(%si)
incw %ax incw %ax
/* set the mode to non-zero */ /* set the mode to non-zero */
movb %al, -1(%si) movb %al, -1(%si)
/* the blocks */ /* the blocks */
movw %ax, 2(%si) movw %ax, 2(%si)
@ -249,8 +249,8 @@ lba_mode:
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
jmp copy_buffer jmp copy_buffer
chs_mode: chs_mode:
/* /*
* Determine the hard disk geometry from the BIOS! * Determine the hard disk geometry from the BIOS!
* We do this first, so that LS-120 IDE floppies work correctly. * We do this first, so that LS-120 IDE floppies work correctly.
@ -272,7 +272,7 @@ final_init:
/* set the mode to zero */ /* set the mode to zero */
movzbl %dh, %eax movzbl %dh, %eax
movb %ah, -1(%si) movb %ah, -1(%si)
/* save number of heads */ /* save number of heads */
incw %ax incw %ax
movl %eax, 4(%si) movl %eax, 4(%si)
@ -303,7 +303,7 @@ setup_sectors:
orl %eax, %eax orl %eax, %eax
jnz geometry_error jnz geometry_error
/* load logical sector start (bottom half) */ /* load logical sector start (bottom half) */
#ifdef APPLE_CC #ifdef APPLE_CC
movl (kernel_sector_abs), %eax movl (kernel_sector_abs), %eax
@ -371,7 +371,7 @@ setup_sectors:
jc read_error jc read_error
movw %es, %bx movw %es, %bx
copy_buffer: copy_buffer:
#ifdef APPLE_CC #ifdef APPLE_CC
kernel_segment_abs = ABS (kernel_segment) kernel_segment_abs = ABS (kernel_segment)
@ -386,14 +386,14 @@ copy_buffer:
*/ */
pusha pusha
pushw %ds pushw %ds
movw $0x100, %cx movw $0x100, %cx
movw %bx, %ds movw %bx, %ds
xorw %si, %si xorw %si, %si
xorw %di, %di xorw %di, %di
cld cld
rep rep
movsw movsw
@ -472,7 +472,7 @@ message:
*/ */
. = _start + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC . = _start + GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC
nt_magic: nt_magic:
.long 0 .long 0
.word 0 .word 0
@ -482,7 +482,7 @@ nt_magic:
* sneaky, huh? * sneaky, huh?
*/ */
part_start: part_start:
. = _start + GRUB_BOOT_MACHINE_PART_START . = _start + GRUB_BOOT_MACHINE_PART_START
probe_values: probe_values:

View file

@ -88,7 +88,7 @@ bi_reserved:
/* Root drive will default to boot drive */ /* Root drive will default to boot drive */
movb $0xFF, %dh movb $0xFF, %dh
ljmp $(DATA_ADDR >> 4), $0 ljmp $(DATA_ADDR >> 4), $0
/* /*

View file

@ -17,7 +17,7 @@
*/ */
#include <grub/machine/boot.h> #include <grub/machine/boot.h>
/* /*
* defines for the code go here * defines for the code go here
*/ */
@ -26,7 +26,7 @@
This makes the assembler generate the address without support This makes the assembler generate the address without support
from the linker. (ELF can't relocate 16-bit addresses!) */ from the linker. (ELF can't relocate 16-bit addresses!) */
#define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR) #define ABS(x) (x-_start+GRUB_BOOT_MACHINE_KERNEL_ADDR)
/* Print message string */ /* Print message string */
#ifdef APPLE_CC #ifdef APPLE_CC
#define MSG(x) x ## _abs = ABS(x); mov $x ## _abs, %esi; call message #define MSG(x) x ## _abs = ABS(x); mov $x ## _abs, %esi; call message
@ -44,18 +44,18 @@
.globl start, _start .globl start, _start
start: start:
_start: _start:
/* /*
* _start is loaded at 0x2000 and is jumped to with * _start is loaded at 0x2000 and is jumped to with
* CS:IP 0:0x2000 in kernel. * CS:IP 0:0x2000 in kernel.
*/ */
/* /*
* we continue to use the stack for boot.img and assume that * we continue to use the stack for boot.img and assume that
* some registers are set to correct values. See boot.S * some registers are set to correct values. See boot.S
* for more information. * for more information.
*/ */
/* save drive reference first thing! */ /* save drive reference first thing! */
pushw %dx pushw %dx
@ -63,7 +63,7 @@ _start:
pushw %si pushw %si
MSG(notification_string) MSG(notification_string)
popw %si popw %si
/* this sets up for the first run through "bootloop" */ /* this sets up for the first run through "bootloop" */
#ifdef APPLE_CC #ifdef APPLE_CC
firstlist_off_abs = ABS (firstlist - GRUB_BOOT_MACHINE_LIST_SIZE) firstlist_off_abs = ABS (firstlist - GRUB_BOOT_MACHINE_LIST_SIZE)
@ -84,14 +84,14 @@ bootloop:
/* if zero, go to the start function */ /* if zero, go to the start function */
je bootit je bootit
setup_sectors: setup_sectors:
/* check if we use LBA or CHS */ /* check if we use LBA or CHS */
cmpb $0, -1(%si) cmpb $0, -1(%si)
/* jump to chs_mode if zero */ /* jump to chs_mode if zero */
je chs_mode je chs_mode
lba_mode: lba_mode:
/* load logical sector start */ /* load logical sector start */
movl (%di), %ebx movl (%di), %ebx
movl 4(%di), %ecx movl 4(%di), %ecx
@ -109,7 +109,7 @@ lba_mode:
/* if less than, set to total */ /* if less than, set to total */
movw 8(%di), %ax movw 8(%di), %ax
1: 1:
/* subtract from total */ /* subtract from total */
subw %ax, 8(%di) subw %ax, 8(%di)
@ -154,8 +154,8 @@ lba_mode:
movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx movw $GRUB_BOOT_MACHINE_BUFFER_SEG, %bx
jmp copy_buffer jmp copy_buffer
chs_mode: chs_mode:
/* load logical sector start (top half) */ /* load logical sector start (top half) */
movl 4(%di), %eax movl 4(%di), %eax
orl %eax, %eax orl %eax, %eax
@ -202,7 +202,7 @@ chs_mode:
/* if less than, set to total */ /* if less than, set to total */
movw 8(%di), %ax movw 8(%di), %ax
2: 2:
/* subtract from total */ /* subtract from total */
subw %ax, 8(%di) subw %ax, 8(%di)
@ -258,8 +258,8 @@ chs_mode:
/* save source segment */ /* save source segment */
movw %es, %bx movw %es, %bx
copy_buffer: copy_buffer:
/* load addresses for copy from disk buffer to destination */ /* load addresses for copy from disk buffer to destination */
movw 10(%di), %es /* load destination segment */ movw 10(%di), %es /* load destination segment */
@ -291,7 +291,7 @@ copy_buffer:
rep /* sets a repeat */ rep /* sets a repeat */
movsw /* this runs the actual copy */ movsw /* this runs the actual copy */
/* restore addressing regs and print a dot with correct DS /* restore addressing regs and print a dot with correct DS
(MSG modifies SI, which is saved, and unused AX and BX) */ (MSG modifies SI, which is saved, and unused AX and BX) */
popw %ds popw %ds
MSG(notification_step) MSG(notification_step)
@ -339,7 +339,7 @@ notification_string: .asciz "loading"
notification_step: .asciz "." notification_step: .asciz "."
notification_done: .asciz "\r\n" notification_done: .asciz "\r\n"
geometry_error_string: .asciz "Geom" geometry_error_string: .asciz "Geom"
read_error_string: .asciz "Read" read_error_string: .asciz "Read"
general_error_string: .asciz " Error" general_error_string: .asciz " Error"
@ -379,7 +379,7 @@ lastlist:
.word 0 .word 0
. = _start + 0x200 - GRUB_BOOT_MACHINE_LIST_SIZE . = _start + 0x200 - GRUB_BOOT_MACHINE_LIST_SIZE
/* fill the first data listing with the default */ /* fill the first data listing with the default */
blocklist_default_start: blocklist_default_start:
/* this is the sector start parameter, in logical sectors from /* this is the sector start parameter, in logical sectors from
@ -392,5 +392,5 @@ blocklist_default_len:
blocklist_default_seg: blocklist_default_seg:
/* this is the segment of the starting address to load the data into */ /* this is the segment of the starting address to load the data into */
.word (GRUB_BOOT_MACHINE_KERNEL_SEG + 0x20) .word (GRUB_BOOT_MACHINE_KERNEL_SEG + 0x20)
firstlist: /* this label has to be after the list data!!! */ firstlist: /* this label has to be after the list data!!! */

View file

@ -24,7 +24,7 @@
#include <multiboot.h> #include <multiboot.h>
.file "lnxboot.S" .file "lnxboot.S"
#ifdef APPLE_CC #ifdef APPLE_CC
#error Building lnxboot.img with Apple's as results in an unusable image #error Building lnxboot.img with Apple's as results in an unusable image
#endif #endif
@ -50,7 +50,7 @@ data_start:
. = data_start + 0x1F1 . = data_start + 0x1F1
setup_sects: setup_sects:
/* Apple's cc can't fill this value. */ /* Apple's cc can't fill this value. */
#ifdef APPLE_CC #ifdef APPLE_CC
.byte 0 .byte 0
#else #else
@ -135,8 +135,8 @@ data_leng:
linux_init: linux_init:
#ifdef APPLE_CC #ifdef APPLE_CC
reg_edx_rel = reg_edx - start reg_edx_rel = reg_edx - start
code32_start_rel = code32_start - start code32_start_rel = code32_start - start
movw %cs:(reg_edx_rel), %dx movw %cs:(reg_edx_rel), %dx
movl %cs:(code32_start_rel), %ebp movl %cs:(code32_start_rel), %ebp
#else #else

View file

@ -21,16 +21,16 @@
/* Start with the prehistoric environment... */ /* Start with the prehistoric environment... */
.code16 .code16
/* Let's go */ /* Let's go */
.globl start, _start; .globl start, _start;
_start: _start:
start: start:
/* Root drive will default to boot drive */ /* Root drive will default to boot drive */
movb $0xFF, %dh movb $0xFF, %dh
movb $0x7F, %dl movb $0x7F, %dl
/* Jump to the real world */ /* Jump to the real world */
ljmp $0, $0x8200 ljmp $0, $0x8200

View file

@ -180,13 +180,13 @@ grub_ohci_pci_iter (int bus, int device, int func,
/* Setup the HCCA. */ /* Setup the HCCA. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_HCCA, (grub_uint32_t) o->hcca); grub_ohci_writereg32 (o, GRUB_OHCI_REG_HCCA, (grub_uint32_t) o->hcca);
grub_dprintf ("ohci", "OHCI HCCA\n"); grub_dprintf ("ohci", "OHCI HCCA\n");
/* Enable the OHCI. */ /* Enable the OHCI. */
grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL, grub_ohci_writereg32 (o, GRUB_OHCI_REG_CONTROL,
(2 << 6)); (2 << 6));
grub_dprintf ("ohci", "OHCI enable: 0x%02x\n", grub_dprintf ("ohci", "OHCI enable: 0x%02x\n",
(grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) >> 6) & 3); (grub_ohci_readreg32 (o, GRUB_OHCI_REG_CONTROL) >> 6) & 3);
/* Link to ohci now that initialisation is successful. */ /* Link to ohci now that initialisation is successful. */
o->next = ohci; o->next = ohci;
ohci = o; ohci = o;
@ -227,7 +227,7 @@ grub_ohci_iterate (int (*hook) (grub_usb_controller_t dev))
} }
static void static void
grub_ohci_transaction (grub_ohci_td_t td, grub_ohci_transaction (grub_ohci_td_t td,
grub_transfer_type_t type, unsigned int toggle, grub_transfer_type_t type, unsigned int toggle,
grub_size_t size, char *data) grub_size_t size, char *data)
{ {
@ -305,7 +305,7 @@ grub_ohci_transfer (grub_usb_controller_t dev,
grub_usb_transaction_t tr = &transfer->transactions[i]; grub_usb_transaction_t tr = &transfer->transactions[i];
grub_ohci_transaction (&td_list[i], tr->pid, tr->toggle, grub_ohci_transaction (&td_list[i], tr->pid, tr->toggle,
tr->size, tr->data); tr->size, tr->data);
td_list[i].next_td = grub_cpu_to_le32 (&td_list[i + 1]); td_list[i].next_td = grub_cpu_to_le32 (&td_list[i + 1]);
} }
@ -607,5 +607,5 @@ GRUB_MOD_INIT(ohci)
GRUB_MOD_FINI(ohci) GRUB_MOD_FINI(ohci)
{ {
grub_usb_controller_dev_unregister (&usb_controller); grub_usb_controller_dev_unregister (&usb_controller);
} }

View file

@ -450,7 +450,7 @@ grub_uhci_transfer (grub_usb_controller_t dev,
td = grub_uhci_transaction (u, transfer->endpoint, tr->pid, td = grub_uhci_transaction (u, transfer->endpoint, tr->pid,
transfer->devaddr, tr->toggle, transfer->devaddr, tr->toggle,
tr->size, tr->data); tr->size, tr->data);
if (! td) if (! td)
{ {
/* Terminate and free. */ /* Terminate and free. */
@ -517,7 +517,7 @@ grub_uhci_transfer (grub_usb_controller_t dev,
/* Check if a babble error occurred. */ /* Check if a babble error occurred. */
if (errtd->ctrl_status & (1 << 20)) if (errtd->ctrl_status & (1 << 20))
err = GRUB_USB_ERR_BABBLE; err = GRUB_USB_ERR_BABBLE;
/* Check if a NAK occurred. */ /* Check if a NAK occurred. */
if (errtd->ctrl_status & (1 << 19)) if (errtd->ctrl_status & (1 << 19))
err = GRUB_USB_ERR_NAK; err = GRUB_USB_ERR_NAK;

View file

@ -236,7 +236,7 @@ grub_usb_device_initialize (grub_usb_device_t dev)
/* Skip the configuration descriptor. */ /* Skip the configuration descriptor. */
pos = sizeof (struct grub_usb_desc_config); pos = sizeof (struct grub_usb_desc_config);
/* Read all interfaces. */ /* Read all interfaces. */
for (currif = 0; currif < dev->config[i].descconf->numif; currif++) for (currif = 0; currif < dev->config[i].descconf->numif; currif++)
{ {

View file

@ -54,7 +54,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
max = 64; max = 64;
datablocks = (size + max - 1) / max; datablocks = (size + max - 1) / max;
/* XXX: Discriminate between different types of control /* XXX: Discriminate between different types of control
messages. */ messages. */
transfer->transcnt = datablocks + 2; transfer->transcnt = datablocks + 2;
@ -110,7 +110,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_OUT; transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_OUT;
else else
transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_IN; transfer->transactions[datablocks + 1].pid = GRUB_USB_TRANSFER_TYPE_IN;
transfer->transactions[datablocks + 1].toggle = 1; transfer->transactions[datablocks + 1].toggle = 1;
err = dev->controller.dev->transfer (&dev->controller, transfer); err = dev->controller.dev->transfer (&dev->controller, transfer);
@ -184,7 +184,7 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
tr->data = &data[i * max]; tr->data = &data[i * max];
size -= tr->size; size -= tr->size;
} }
err = dev->controller.dev->transfer (&dev->controller, transfer); err = dev->controller.dev->transfer (&dev->controller, transfer);
grub_dprintf ("usb", "toggle=%d\n", toggle); grub_dprintf ("usb", "toggle=%d\n", toggle);
dev->toggle[endpoint] = toggle; dev->toggle[endpoint] = toggle;

View file

@ -36,22 +36,22 @@
#endif #endif
static const struct grub_arg_option options[] = { static const struct grub_arg_option options[] = {
{"exclude", 'x', 0, {"exclude", 'x', 0,
"Don't load host tables specified by comma-separated list", "Don't load host tables specified by comma-separated list",
0, ARG_TYPE_STRING}, 0, ARG_TYPE_STRING},
{"load-only", 'n', 0, {"load-only", 'n', 0,
"Load only tables specified by comma-separated list", 0, ARG_TYPE_STRING}, "Load only tables specified by comma-separated list", 0, ARG_TYPE_STRING},
{"v1", '1', 0, "Expose v1 tables", 0, ARG_TYPE_NONE}, {"v1", '1', 0, "Expose v1 tables", 0, ARG_TYPE_NONE},
{"v2", '2', 0, "Expose v2 and v3 tables", 0, ARG_TYPE_NONE}, {"v2", '2', 0, "Expose v2 and v3 tables", 0, ARG_TYPE_NONE},
{"oemid", 'o', 0, "Set OEMID of RSDP, XSDT and RSDT", 0, ARG_TYPE_STRING}, {"oemid", 'o', 0, "Set OEMID of RSDP, XSDT and RSDT", 0, ARG_TYPE_STRING},
{"oemtable", 't', 0, {"oemtable", 't', 0,
"Set OEMTABLE ID of RSDP, XSDT and RSDT", 0, ARG_TYPE_STRING}, "Set OEMTABLE ID of RSDP, XSDT and RSDT", 0, ARG_TYPE_STRING},
{"oemtablerev", 'r', 0, {"oemtablerev", 'r', 0,
"Set OEMTABLE revision of RSDP, XSDT and RSDT", 0, ARG_TYPE_INT}, "Set OEMTABLE revision of RSDP, XSDT and RSDT", 0, ARG_TYPE_INT},
{"oemtablecreator", 'c', 0, {"oemtablecreator", 'c', 0,
"Set creator field of RSDP, XSDT and RSDT", 0, ARG_TYPE_STRING}, "Set creator field of RSDP, XSDT and RSDT", 0, ARG_TYPE_STRING},
{"oemtablecreatorrev", 'd', 0, {"oemtablecreatorrev", 'd', 0,
"Set creator revision of RSDP, XSDT and RSDT", 0, ARG_TYPE_INT}, "Set creator revision of RSDP, XSDT and RSDT", 0, ARG_TYPE_INT},
{"no-ebda", 'e', 0, "Don't update EBDA. May fix failures or hangs on some" {"no-ebda", 'e', 0, "Don't update EBDA. May fix failures or hangs on some"
" BIOSes but makes it ineffective with OS not receiving RSDP from GRUB", " BIOSes but makes it ineffective with OS not receiving RSDP from GRUB",
0, ARG_TYPE_NONE}, 0, ARG_TYPE_NONE},
@ -59,7 +59,7 @@ static const struct grub_arg_option options[] = {
}; };
/* Simple checksum by summing all bytes. Used by ACPI and SMBIOS. */ /* Simple checksum by summing all bytes. Used by ACPI and SMBIOS. */
grub_uint8_t grub_uint8_t
grub_byte_checksum (void *base, grub_size_t size) grub_byte_checksum (void *base, grub_size_t size)
{ {
grub_uint8_t *ptr; grub_uint8_t *ptr;
@ -70,7 +70,7 @@ grub_byte_checksum (void *base, grub_size_t size)
return ret; return ret;
} }
/* rev1 is 1 if ACPIv1 is to be generated, 0 otherwise. /* rev1 is 1 if ACPIv1 is to be generated, 0 otherwise.
rev2 contains the revision of ACPIv2+ to generate or 0 if none. */ rev2 contains the revision of ACPIv2+ to generate or 0 if none. */
static int rev1, rev2; static int rev1, rev2;
/* OEMID of RSDP, RSDT and XSDT. */ /* OEMID of RSDP, RSDT and XSDT. */
@ -128,7 +128,7 @@ grub_acpi_get_rsdpv1 (void)
return grub_machine_acpi_get_rsdpv1 (); return grub_machine_acpi_get_rsdpv1 ();
} }
static inline int static inline int
iszero (grub_uint8_t *reg, int size) iszero (grub_uint8_t *reg, int size)
{ {
int i; int i;
@ -138,7 +138,7 @@ iszero (grub_uint8_t *reg, int size)
return 1; return 1;
} }
grub_err_t grub_err_t
grub_acpi_create_ebda (void) grub_acpi_create_ebda (void)
{ {
int ebda_kb_len; int ebda_kb_len;
@ -149,9 +149,9 @@ grub_acpi_create_ebda (void)
grub_uint8_t *targetebda, *target; grub_uint8_t *targetebda, *target;
struct grub_acpi_rsdp_v10 *v1; struct grub_acpi_rsdp_v10 *v1;
struct grub_acpi_rsdp_v20 *v2; struct grub_acpi_rsdp_v20 *v2;
auto int NESTED_FUNC_ATTR find_hook (grub_uint64_t, grub_uint64_t, auto int NESTED_FUNC_ATTR find_hook (grub_uint64_t, grub_uint64_t,
grub_uint32_t); grub_uint32_t);
int NESTED_FUNC_ATTR find_hook (grub_uint64_t start, grub_uint64_t size, int NESTED_FUNC_ATTR find_hook (grub_uint64_t start, grub_uint64_t size,
grub_uint32_t type) grub_uint32_t type)
{ {
grub_uint64_t end = start + size; grub_uint64_t end = start + size;
@ -164,7 +164,7 @@ grub_acpi_create_ebda (void)
highestlow = (end - ebda_len) & (~0xf); highestlow = (end - ebda_len) & (~0xf);
return 0; return 0;
} }
ebda = (grub_uint8_t *) UINT_TO_PTR ((*((grub_uint16_t *)0x40e)) << 4); ebda = (grub_uint8_t *) UINT_TO_PTR ((*((grub_uint16_t *)0x40e)) << 4);
ebda_kb_len = *(grub_uint16_t *) ebda; ebda_kb_len = *(grub_uint16_t *) ebda;
if (! ebda || ebda_kb_len > 16) if (! ebda || ebda_kb_len > 16)
@ -177,10 +177,10 @@ grub_acpi_create_ebda (void)
grub_dprintf ("acpi", "creating ebda @%llx\n", grub_dprintf ("acpi", "creating ebda @%llx\n",
(unsigned long long) highestlow); (unsigned long long) highestlow);
if (! highestlow) if (! highestlow)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't find space for the new EBDA"); "couldn't find space for the new EBDA");
mmapregion = grub_mmap_register (PTR_TO_UINT64 (targetebda), ebda_len, mmapregion = grub_mmap_register (PTR_TO_UINT64 (targetebda), ebda_len,
GRUB_MACHINE_MEMORY_RESERVED); GRUB_MACHINE_MEMORY_RESERVED);
if (! mmapregion) if (! mmapregion)
return grub_errno; return grub_errno;
@ -198,13 +198,13 @@ grub_acpi_create_ebda (void)
if (v2 && v2->length > 40) if (v2 && v2->length > 40)
v2 = 0; v2 = 0;
/* First try to replace already existing rsdp. */ /* First try to replace already existing rsdp. */
if (v2) if (v2)
{ {
grub_dprintf ("acpi", "Scanning EBDA for old rsdpv2\n"); grub_dprintf ("acpi", "Scanning EBDA for old rsdpv2\n");
for (; target < targetebda + 0x400 - v2->length; target += 0x10) for (; target < targetebda + 0x400 - v2->length; target += 0x10)
if (grub_memcmp (target, "RSD PTR ", 8) == 0 if (grub_memcmp (target, "RSD PTR ", 8) == 0
&& grub_byte_checksum (target, && grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0 sizeof (struct grub_acpi_rsdp_v10)) == 0
&& ((struct grub_acpi_rsdp_v10 *) target)->revision != 0 && ((struct grub_acpi_rsdp_v10 *) target)->revision != 0
&& ((struct grub_acpi_rsdp_v20 *) target)->length <= v2->length) && ((struct grub_acpi_rsdp_v20 *) target)->length <= v2->length)
@ -222,10 +222,10 @@ grub_acpi_create_ebda (void)
if (v1) if (v1)
{ {
grub_dprintf ("acpi", "Scanning EBDA for old rsdpv1\n"); grub_dprintf ("acpi", "Scanning EBDA for old rsdpv1\n");
for (; target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10); for (; target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10) target += 0x10)
if (grub_memcmp (target, "RSD PTR ", 8) == 0 if (grub_memcmp (target, "RSD PTR ", 8) == 0
&& grub_byte_checksum (target, && grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0) sizeof (struct grub_acpi_rsdp_v10)) == 0)
{ {
grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10)); grub_memcpy (target, v1, sizeof (struct grub_acpi_rsdp_v10));
@ -260,7 +260,7 @@ grub_acpi_create_ebda (void)
if (v1) if (v1)
{ {
grub_dprintf ("acpi", "Scanning EBDA for block of zeros\n"); grub_dprintf ("acpi", "Scanning EBDA for block of zeros\n");
for (; target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10); for (; target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10) target += 0x10)
if (iszero (target, sizeof (struct grub_acpi_rsdp_v10))) if (iszero (target, sizeof (struct grub_acpi_rsdp_v10)))
{ {
@ -277,16 +277,16 @@ grub_acpi_create_ebda (void)
if (v1 || v2) if (v1 || v2)
{ {
grub_mmap_unregister (mmapregion); grub_mmap_unregister (mmapregion);
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't find suitable spot in EBDA"); "Couldn't find suitable spot in EBDA");
} }
/* Remove any other RSDT. */ /* Remove any other RSDT. */
for (target = targetebda; for (target = targetebda;
target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10); target < targetebda + 0x400 - sizeof (struct grub_acpi_rsdp_v10);
target += 0x10) target += 0x10)
if (grub_memcmp (target, "RSD PTR ", 8) == 0 if (grub_memcmp (target, "RSD PTR ", 8) == 0
&& grub_byte_checksum (target, && grub_byte_checksum (target,
sizeof (struct grub_acpi_rsdp_v10)) == 0 sizeof (struct grub_acpi_rsdp_v10)) == 0
&& target != v1inebda && target != v2inebda) && target != v1inebda && target != v2inebda)
*target = 0; *target = 0;
@ -312,7 +312,7 @@ setup_common_tables (void)
grub_free (table_dsdt); grub_free (table_dsdt);
table_dsdt = playground_ptr; table_dsdt = playground_ptr;
playground_ptr += dsdt_size; playground_ptr += dsdt_size;
/* Treat other tables. */ /* Treat other tables. */
for (cur = acpi_tables; cur; cur = cur->next) for (cur = acpi_tables; cur; cur = cur->next)
{ {
@ -342,7 +342,7 @@ setup_common_tables (void)
fadt->hdr.checksum = 1 + ~grub_byte_checksum (fadt, fadt->hdr.length); fadt->hdr.checksum = 1 + ~grub_byte_checksum (fadt, fadt->hdr.length);
} }
} }
/* Fill RSDT entries. */ /* Fill RSDT entries. */
numoftables = 0; numoftables = 0;
for (cur = acpi_tables; cur; cur = cur->next) for (cur = acpi_tables; cur; cur = cur->next)
@ -365,7 +365,7 @@ setup_common_tables (void)
for (cur = acpi_tables; cur; cur = cur->next) for (cur = acpi_tables; cur; cur = cur->next)
*(rsdt_entry++) = PTR_TO_UINT32 (cur->addr); *(rsdt_entry++) = PTR_TO_UINT32 (cur->addr);
/* Recompute checksum. */ /* Recompute checksum. */
rsdt->checksum = 0; rsdt->checksum = 0;
rsdt->checksum = 1 + ~grub_byte_checksum (rsdt, rsdt->length); rsdt->checksum = 1 + ~grub_byte_checksum (rsdt, rsdt->length);
@ -383,8 +383,8 @@ setv1table (void)
rsdpv1_new->revision = 0; rsdpv1_new->revision = 0;
rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr); rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr);
rsdpv1_new->checksum = 0; rsdpv1_new->checksum = 0;
rsdpv1_new->checksum = 1 + ~grub_byte_checksum (rsdpv1_new, rsdpv1_new->checksum = 1 + ~grub_byte_checksum (rsdpv1_new,
sizeof (*rsdpv1_new)); sizeof (*rsdpv1_new));
grub_dprintf ("acpi", "Generated ACPIv1 tables\n"); grub_dprintf ("acpi", "Generated ACPIv1 tables\n");
} }
@ -421,19 +421,19 @@ setv2table (void)
/* Create RSDPv2. */ /* Create RSDPv2. */
rsdpv2_new = (struct grub_acpi_rsdp_v20 *) playground_ptr; rsdpv2_new = (struct grub_acpi_rsdp_v20 *) playground_ptr;
playground_ptr += sizeof (struct grub_acpi_rsdp_v20); playground_ptr += sizeof (struct grub_acpi_rsdp_v20);
grub_memcpy (&(rsdpv2_new->rsdpv1.signature), "RSD PTR ", grub_memcpy (&(rsdpv2_new->rsdpv1.signature), "RSD PTR ",
sizeof (rsdpv2_new->rsdpv1.signature)); sizeof (rsdpv2_new->rsdpv1.signature));
grub_memcpy (&(rsdpv2_new->rsdpv1.oemid), root_oemid, grub_memcpy (&(rsdpv2_new->rsdpv1.oemid), root_oemid,
sizeof (rsdpv2_new->rsdpv1.oemid)); sizeof (rsdpv2_new->rsdpv1.oemid));
rsdpv2_new->rsdpv1.revision = rev2; rsdpv2_new->rsdpv1.revision = rev2;
rsdpv2_new->rsdpv1.rsdt_addr = PTR_TO_UINT32 (rsdt_addr); rsdpv2_new->rsdpv1.rsdt_addr = PTR_TO_UINT32 (rsdt_addr);
rsdpv2_new->rsdpv1.checksum = 0; rsdpv2_new->rsdpv1.checksum = 0;
rsdpv2_new->rsdpv1.checksum = 1 + ~grub_byte_checksum rsdpv2_new->rsdpv1.checksum = 1 + ~grub_byte_checksum
(&(rsdpv2_new->rsdpv1), sizeof (rsdpv2_new->rsdpv1)); (&(rsdpv2_new->rsdpv1), sizeof (rsdpv2_new->rsdpv1));
rsdpv2_new->length = sizeof (*rsdpv2_new); rsdpv2_new->length = sizeof (*rsdpv2_new);
rsdpv2_new->xsdt_addr = PTR_TO_UINT64 (xsdt); rsdpv2_new->xsdt_addr = PTR_TO_UINT64 (xsdt);
rsdpv2_new->checksum = 0; rsdpv2_new->checksum = 0;
rsdpv2_new->checksum = 1 + ~grub_byte_checksum (rsdpv2_new, rsdpv2_new->checksum = 1 + ~grub_byte_checksum (rsdpv2_new,
rsdpv2_new->length); rsdpv2_new->length);
grub_dprintf ("acpi", "Generated ACPIv2 tables\n"); grub_dprintf ("acpi", "Generated ACPIv2 tables\n");
} }
@ -465,7 +465,7 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
grub_err_t err; grub_err_t err;
int i, mmapregion; int i, mmapregion;
int numoftables; int numoftables;
/* Default values if no RSDP is found. */ /* Default values if no RSDP is found. */
rev1 = 1; rev1 = 1;
rev2 = 3; rev2 = 3;
@ -473,7 +473,7 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
facs_addr = 0; facs_addr = 0;
playground = playground_ptr = 0; playground = playground_ptr = 0;
playground_size = 0; playground_size = 0;
rsdp = (struct grub_acpi_rsdp_v10 *) grub_machine_acpi_get_rsdpv2 (); rsdp = (struct grub_acpi_rsdp_v10 *) grub_machine_acpi_get_rsdpv2 ();
if (! rsdp) if (! rsdp)
@ -508,37 +508,37 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
rsdt = (struct grub_acpi_table_header *) UINT_TO_PTR (rsdp->rsdt_addr); rsdt = (struct grub_acpi_table_header *) UINT_TO_PTR (rsdp->rsdt_addr);
/* Load host tables. */ /* Load host tables. */
for (entry_ptr = (grub_uint32_t *) (rsdt + 1); for (entry_ptr = (grub_uint32_t *) (rsdt + 1);
entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt) entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt)
+ rsdt->length); + rsdt->length);
entry_ptr++) entry_ptr++)
{ {
char signature[5]; char signature[5];
struct efiemu_acpi_table *table; struct efiemu_acpi_table *table;
struct grub_acpi_table_header *curtable struct grub_acpi_table_header *curtable
= (struct grub_acpi_table_header *) UINT_TO_PTR (*entry_ptr); = (struct grub_acpi_table_header *) UINT_TO_PTR (*entry_ptr);
signature[4] = 0; signature[4] = 0;
for (i = 0; i < 4;i++) for (i = 0; i < 4;i++)
signature[i] = grub_tolower (curtable->signature[i]); signature[i] = grub_tolower (curtable->signature[i]);
/* If it's FADT it contains addresses of DSDT and FACS. */ /* If it's FADT it contains addresses of DSDT and FACS. */
if (grub_strcmp (signature, "facp") == 0) if (grub_strcmp (signature, "facp") == 0)
{ {
struct grub_acpi_table_header *dsdt; struct grub_acpi_table_header *dsdt;
struct grub_acpi_fadt *fadt = (struct grub_acpi_fadt *) curtable; struct grub_acpi_fadt *fadt = (struct grub_acpi_fadt *) curtable;
/* Set root header variables to the same values /* Set root header variables to the same values
as FACP by default. */ as FACP by default. */
grub_memcpy (&root_oemid, &(fadt->hdr.oemid), grub_memcpy (&root_oemid, &(fadt->hdr.oemid),
sizeof (root_oemid)); sizeof (root_oemid));
grub_memcpy (&root_oemtable, &(fadt->hdr.oemtable), grub_memcpy (&root_oemtable, &(fadt->hdr.oemtable),
sizeof (root_oemtable)); sizeof (root_oemtable));
root_oemrev = fadt->hdr.oemrev; root_oemrev = fadt->hdr.oemrev;
grub_memcpy (&root_creator_id, &(fadt->hdr.creator_id), grub_memcpy (&root_creator_id, &(fadt->hdr.creator_id),
sizeof (root_creator_id)); sizeof (root_creator_id));
root_creator_rev = fadt->hdr.creator_rev; root_creator_rev = fadt->hdr.creator_rev;
/* Load DSDT if not excluded. */ /* Load DSDT if not excluded. */
dsdt = (struct grub_acpi_table_header *) dsdt = (struct grub_acpi_table_header *)
UINT_TO_PTR (fadt->dsdt_addr); UINT_TO_PTR (fadt->dsdt_addr);
if (dsdt && (! exclude || ! grub_strword (exclude, "dsdt")) if (dsdt && (! exclude || ! grub_strword (exclude, "dsdt"))
&& (! load_only || grub_strword (load_only, "dsdt")) && (! load_only || grub_strword (load_only, "dsdt"))
@ -551,7 +551,7 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
free_tables (); free_tables ();
grub_free (exclude); grub_free (exclude);
grub_free (load_only); grub_free (load_only);
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Could allocate table"); "Could allocate table");
} }
grub_memcpy (table_dsdt, dsdt, dsdt->length); grub_memcpy (table_dsdt, dsdt, dsdt->length);
@ -560,7 +560,7 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
/* Save FACS address. FACS shouldn't be overridden. */ /* Save FACS address. FACS shouldn't be overridden. */
facs_addr = fadt->facs_addr; facs_addr = fadt->facs_addr;
} }
/* Skip excluded tables. */ /* Skip excluded tables. */
if (exclude && grub_strword (exclude, signature)) if (exclude && grub_strword (exclude, signature))
continue; continue;
@ -570,15 +570,15 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
/* Sanity check. */ /* Sanity check. */
if (curtable->length < sizeof (*curtable)) if (curtable->length < sizeof (*curtable))
continue; continue;
table = (struct efiemu_acpi_table *) grub_malloc table = (struct efiemu_acpi_table *) grub_malloc
(sizeof (struct efiemu_acpi_table)); (sizeof (struct efiemu_acpi_table));
if (! table) if (! table)
{ {
free_tables (); free_tables ();
grub_free (exclude); grub_free (exclude);
grub_free (load_only); grub_free (load_only);
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Could allocate table structure"); "Could allocate table structure");
} }
table->size = curtable->length; table->size = curtable->length;
@ -587,7 +587,7 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
if (! table->addr) if (! table->addr)
{ {
free_tables (); free_tables ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Could allocate table"); "Could allocate table");
} }
table->next = acpi_tables; table->next = acpi_tables;
@ -595,7 +595,7 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
grub_memcpy (table->addr, curtable, table->size); grub_memcpy (table->addr, curtable, table->size);
} }
grub_free (exclude); grub_free (exclude);
grub_free (load_only); grub_free (load_only);
} }
/* Does user specify versions to generate? */ /* Does user specify versions to generate? */
@ -647,7 +647,7 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
{ {
grub_file_close (file); grub_file_close (file);
free_tables (); free_tables ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't read file %s", args[i]); "couldn't read file %s", args[i]);
} }
@ -657,9 +657,9 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
free_tables (); free_tables ();
return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[i]); return grub_error (GRUB_ERR_BAD_OS, "couldn't read file %s", args[i]);
} }
grub_file_close (file); grub_file_close (file);
if (grub_memcmp (((struct grub_acpi_table_header *) buf)->signature, if (grub_memcmp (((struct grub_acpi_table_header *) buf)->signature,
"DSDT", 4) == 0) "DSDT", 4) == 0)
{ {
grub_free (table_dsdt); grub_free (table_dsdt);
@ -669,12 +669,12 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
else else
{ {
struct efiemu_acpi_table *table; struct efiemu_acpi_table *table;
table = (struct efiemu_acpi_table *) grub_malloc table = (struct efiemu_acpi_table *) grub_malloc
(sizeof (struct efiemu_acpi_table)); (sizeof (struct efiemu_acpi_table));
if (! table) if (! table)
{ {
free_tables (); free_tables ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Could allocate table structure"); "Could allocate table structure");
} }
@ -698,15 +698,15 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
playground_size += sizeof (struct grub_acpi_table_header) + 8 * numoftables; playground_size += sizeof (struct grub_acpi_table_header) + 8 * numoftables;
/* RSDPv2. */ /* RSDPv2. */
playground_size += sizeof (struct grub_acpi_rsdp_v20); playground_size += sizeof (struct grub_acpi_rsdp_v20);
playground = playground_ptr playground = playground_ptr
= grub_mmap_malign_and_register (1, playground_size, &mmapregion, = grub_mmap_malign_and_register (1, playground_size, &mmapregion,
GRUB_MACHINE_MEMORY_ACPI, 0); GRUB_MACHINE_MEMORY_ACPI, 0);
if (! playground) if (! playground)
{ {
free_tables (); free_tables ();
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't allocate space for ACPI tables"); "Couldn't allocate space for ACPI tables");
} }
@ -741,9 +741,9 @@ grub_cmd_acpi (struct grub_extcmd *cmd,
struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID; struct grub_efi_guid acpi = GRUB_EFI_ACPI_TABLE_GUID;
struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID; struct grub_efi_guid acpi20 = GRUB_EFI_ACPI_20_TABLE_GUID;
grub_efi_system_table->boot_services->install_configuration_table grub_efi_system_table->boot_services->install_configuration_table
(&acpi20, grub_acpi_get_rsdpv2 ()); (&acpi20, grub_acpi_get_rsdpv2 ());
grub_efi_system_table->boot_services->install_configuration_table grub_efi_system_table->boot_services->install_configuration_table
(&acpi, grub_acpi_get_rsdpv1 ()); (&acpi, grub_acpi_get_rsdpv1 ());
} }
#endif #endif
@ -755,13 +755,13 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(acpi) GRUB_MOD_INIT(acpi)
{ {
cmd = grub_register_extcmd ("acpi", grub_cmd_acpi, cmd = grub_register_extcmd ("acpi", grub_cmd_acpi,
GRUB_COMMAND_FLAG_BOTH, GRUB_COMMAND_FLAG_BOTH,
"acpi [-1|-2] [--exclude=table1,table2|" "acpi [-1|-2] [--exclude=table1,table2|"
"--load-only=table1,table2] filename1 " "--load-only=table1,table2] filename1 "
" [filename2] [...]", " [filename2] [...]",
"Load host acpi tables and tables " "Load host acpi tables and tables "
"specified by arguments", "specified by arguments",
options); options);
} }

View file

@ -39,7 +39,7 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
unsigned length); unsigned length);
auto void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num, auto void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num,
unsigned offset, unsigned length); unsigned offset, unsigned length);
void NESTED_FUNC_ATTR read_blocklist (grub_disk_addr_t sector, unsigned offset, void NESTED_FUNC_ATTR read_blocklist (grub_disk_addr_t sector, unsigned offset,
unsigned length) unsigned length)
{ {
@ -51,7 +51,7 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
num_sectors++; num_sectors++;
return; return;
} }
print_blocklist (start_sector, num_sectors, 0, 0); print_blocklist (start_sector, num_sectors, 0, 0);
num_sectors = 0; num_sectors = 0;
} }
@ -64,7 +64,7 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
else else
print_blocklist (sector, 0, offset, length); print_blocklist (sector, 0, offset, length);
} }
void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num, void NESTED_FUNC_ATTR print_blocklist (grub_disk_addr_t sector, unsigned num,
unsigned offset, unsigned length) unsigned offset, unsigned length)
{ {
@ -77,7 +77,7 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
if (offset != 0 || length != 0) if (offset != 0 || length != 0)
grub_printf ("[%u-%u]", offset, offset + length); grub_printf ("[%u-%u]", offset, offset + length);
} }
if (argc < 1) if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
@ -91,7 +91,7 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
if (file->device->disk->partition) if (file->device->disk->partition)
part_start = grub_partition_get_start (file->device->disk->partition); part_start = grub_partition_get_start (file->device->disk->partition);
file->read_hook = read_blocklist; file->read_hook = read_blocklist;
while (grub_file_read (file, buf, sizeof (buf)) > 0) while (grub_file_read (file, buf, sizeof (buf)) > 0)
@ -99,7 +99,7 @@ grub_cmd_blocklist (grub_command_t cmd __attribute__ ((unused)),
if (num_sectors > 0) if (num_sectors > 0)
print_blocklist (start_sector, num_sectors, 0, 0); print_blocklist (start_sector, num_sectors, 0, 0);
grub_file_close (file); grub_file_close (file);
return grub_errno; return grub_errno;

View file

@ -38,7 +38,7 @@ struct grub_preboot_t
}; };
static int grub_loader_loaded; static int grub_loader_loaded;
static struct grub_preboot_t *preboots_head = 0, static struct grub_preboot_t *preboots_head = 0,
*preboots_tail = 0; *preboots_tail = 0;
int int
@ -58,7 +58,7 @@ grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noreturn),
if (! preboot_func && ! preboot_rest_func) if (! preboot_func && ! preboot_rest_func)
return 0; return 0;
new_preboot = (struct grub_preboot_t *) new_preboot = (struct grub_preboot_t *)
grub_malloc (sizeof (struct grub_preboot_t)); grub_malloc (sizeof (struct grub_preboot_t));
if (! new_preboot) if (! new_preboot)
{ {
@ -92,7 +92,7 @@ grub_loader_register_preboot_hook (grub_err_t (*preboot_func) (int noreturn),
return new_preboot; return new_preboot;
} }
void void
grub_loader_unregister_preboot_hook (void *hnd) grub_loader_unregister_preboot_hook (void *hnd)
{ {
struct grub_preboot_t *preb = hnd; struct grub_preboot_t *preb = hnd;
@ -116,11 +116,11 @@ grub_loader_set (grub_err_t (*boot) (void),
{ {
if (grub_loader_loaded && grub_loader_unload_func) if (grub_loader_loaded && grub_loader_unload_func)
grub_loader_unload_func (); grub_loader_unload_func ();
grub_loader_boot_func = boot; grub_loader_boot_func = boot;
grub_loader_unload_func = unload; grub_loader_unload_func = unload;
grub_loader_noreturn = noreturn; grub_loader_noreturn = noreturn;
grub_loader_loaded = 1; grub_loader_loaded = 1;
} }
@ -129,7 +129,7 @@ grub_loader_unset(void)
{ {
if (grub_loader_loaded && grub_loader_unload_func) if (grub_loader_loaded && grub_loader_unload_func)
grub_loader_unload_func (); grub_loader_unload_func ();
grub_loader_boot_func = 0; grub_loader_boot_func = 0;
grub_loader_unload_func = 0; grub_loader_unload_func = 0;
@ -161,7 +161,7 @@ grub_loader_boot (void)
err = (grub_loader_boot_func) (); err = (grub_loader_boot_func) ();
for (cur = preboots_tail; cur; cur = cur->prev) for (cur = preboots_tail; cur; cur = cur->prev)
if (! err) if (! err)
err = cur->preboot_rest_func (); err = cur->preboot_rest_func ();
else else
cur->preboot_rest_func (); cur->preboot_rest_func ();

View file

@ -41,16 +41,16 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
file = grub_gzfile_open (args[0], 1); file = grub_gzfile_open (args[0], 1);
if (! file) if (! file)
return 0; return 0;
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0 while ((size = grub_file_read (file, buf, sizeof (buf))) > 0
&& key != GRUB_TERM_ESC) && key != GRUB_TERM_ESC)
{ {
int i; int i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
unsigned char c = buf[i]; unsigned char c = buf[i];
if ((grub_isprint (c) || grub_isspace (c)) && c != '\r') if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
grub_putchar (c); grub_putchar (c);
else else
@ -69,7 +69,7 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
grub_putchar ('\n'); grub_putchar ('\n');
grub_refresh (); grub_refresh ();
grub_file_close (file); grub_file_close (file);
return 0; return 0;
} }

View file

@ -49,7 +49,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
goto cleanup; goto cleanup;
if (grub_file_size (file1) != grub_file_size (file2)) if (grub_file_size (file1) != grub_file_size (file2))
grub_printf ("Differ in size: %llu [%s], %llu [%s]\n", grub_printf ("Differ in size: %llu [%s], %llu [%s]\n",
(unsigned long long) grub_file_size (file1), args[0], (unsigned long long) grub_file_size (file1), args[0],
(unsigned long long) grub_file_size (file2), args[1]); (unsigned long long) grub_file_size (file2), args[1]);
else else
@ -58,14 +58,14 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
buf1 = grub_malloc (BUFFER_SIZE); buf1 = grub_malloc (BUFFER_SIZE);
buf2 = grub_malloc (BUFFER_SIZE); buf2 = grub_malloc (BUFFER_SIZE);
if (! buf1 || ! buf2) if (! buf1 || ! buf2)
goto cleanup; goto cleanup;
do do
{ {
int i; int i;
rd1 = grub_file_read (file1, buf1, BUFFER_SIZE); rd1 = grub_file_read (file1, buf1, BUFFER_SIZE);
rd2 = grub_file_read (file2, buf2, BUFFER_SIZE); rd2 = grub_file_read (file2, buf2, BUFFER_SIZE);
@ -83,15 +83,15 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)),
} }
} }
pos += BUFFER_SIZE; pos += BUFFER_SIZE;
} }
while (rd2); while (rd2);
grub_printf ("The files are identical.\n"); grub_printf ("The files are identical.\n");
} }
cleanup: cleanup:
if (buf1) if (buf1)
grub_free (buf1); grub_free (buf1);
if (buf2) if (buf2)

View file

@ -90,7 +90,7 @@ grub_cmd_echo (grub_extcmd_t cmd, int argc, char **args)
arg++; arg++;
continue; continue;
} }
/* This was not an escaped character, or escaping is not /* This was not an escaped character, or escaping is not
enabled. */ enabled. */
grub_printf ("%c", *arg); grub_printf ("%c", *arg);

View file

@ -34,7 +34,7 @@ grub_machine_acpi_get_rsdpv1 (void)
&grub_efi_system_table->configuration_table[i].vendor_guid; &grub_efi_system_table->configuration_table[i].vendor_guid;
if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t))) if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t)))
return (struct grub_acpi_rsdp_v10 *) return (struct grub_acpi_rsdp_v10 *)
grub_efi_system_table->configuration_table[i].vendor_table; grub_efi_system_table->configuration_table[i].vendor_table;
} }
return 0; return 0;
@ -52,7 +52,7 @@ grub_machine_acpi_get_rsdpv2 (void)
&grub_efi_system_table->configuration_table[i].vendor_guid; &grub_efi_system_table->configuration_table[i].vendor_guid;
if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_efi_guid_t))) if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_efi_guid_t)))
return (struct grub_acpi_rsdp_v20 *) return (struct grub_acpi_rsdp_v20 *)
grub_efi_system_table->configuration_table[i].vendor_table; grub_efi_system_table->configuration_table[i].vendor_table;
} }
return 0; return 0;

View file

@ -30,33 +30,33 @@
/* Convert a LBA address to a CHS address in the INT 13 format. */ /* Convert a LBA address to a CHS address in the INT 13 format. */
/* Taken from grub1. */ /* Taken from grub1. */
/* XXX: use hardcoded geometry of C = 1024, H = 255, S = 63. /* XXX: use hardcoded geometry of C = 1024, H = 255, S = 63.
Is it a problem? Is it a problem?
*/ */
static void static void
lba_to_chs (int lba, grub_uint8_t *cl, grub_uint8_t *ch, lba_to_chs (int lba, grub_uint8_t *cl, grub_uint8_t *ch,
grub_uint8_t *dh) grub_uint8_t *dh)
{ {
int cylinder, head, sector; int cylinder, head, sector;
int sectors = 63, heads = 255, cylinders = 1024; int sectors = 63, heads = 255, cylinders = 1024;
sector = lba % sectors + 1; sector = lba % sectors + 1;
head = (lba / sectors) % heads; head = (lba / sectors) % heads;
cylinder = lba / (sectors * heads); cylinder = lba / (sectors * heads);
if (cylinder >= cylinders) if (cylinder >= cylinders)
{ {
*cl = *ch = *dh = 0xff; *cl = *ch = *dh = 0xff;
return; return;
} }
*cl = sector | ((cylinder & 0x300) >> 2); *cl = sector | ((cylinder & 0x300) >> 2);
*ch = cylinder & 0xFF; *ch = cylinder & 0xFF;
*dh = head; *dh = head;
} }
static grub_err_t static grub_err_t
grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)), grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
int argc, char **args) int argc, char **args)
{ {
grub_device_t dev; grub_device_t dev;
@ -74,11 +74,11 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')') if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')')
{ {
args[0][grub_strlen (args[0]) - 1] = 0; args[0][grub_strlen (args[0]) - 1] = 0;
dev = grub_device_open (args[0] + 1); dev = grub_device_open (args[0] + 1);
args[0][grub_strlen (args[0])] = ')'; args[0][grub_strlen (args[0])] = ')';
} }
else else
dev = grub_device_open (args[0]); dev = grub_device_open (args[0]);
if (! dev) if (! dev)
return grub_errno; return grub_errno;
@ -99,7 +99,7 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
/* Check if it is valid. */ /* Check if it is valid. */
if (mbr.signature != grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE)) if (mbr.signature != grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE))
{ {
grub_device_close (dev); grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
} }
@ -109,7 +109,7 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
grub_device_close (dev); grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found"); return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found");
} }
int i; int i;
first_sector = dev->disk->total_sectors; first_sector = dev->disk->total_sectors;
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
@ -128,19 +128,19 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
if (separator) if (separator)
*separator = csep; *separator = csep;
if (! partition) if (! partition)
{ {
grub_device_close (dev); grub_device_close (dev);
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such partition"); return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such partition");
} }
if (partition->start + partition->len > 0xffffffff) if (partition->start + partition->len > 0xffffffff)
{ {
grub_device_close (dev); grub_device_close (dev);
return grub_error (GRUB_ERR_OUT_OF_RANGE, return grub_error (GRUB_ERR_OUT_OF_RANGE,
"only partitions resding in the first 2TB " "only partitions resding in the first 2TB "
"can be presen in hybrid MBR"); "can be presen in hybrid MBR");
} }
if (first_sector > partition->start) if (first_sector > partition->start)
first_sector = partition->start; first_sector = partition->start;
@ -182,17 +182,17 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
if (numactive == 2) if (numactive == 2)
{ {
grub_device_close (dev); grub_device_close (dev);
return grub_error (GRUB_ERR_BAD_ARGUMENT, return grub_error (GRUB_ERR_BAD_ARGUMENT,
"only one partition can be active"); "only one partition can be active");
} }
} }
mbr.entries[i].type = type; mbr.entries[i].type = type;
mbr.entries[i].start = grub_cpu_to_le32 (partition->start); mbr.entries[i].start = grub_cpu_to_le32 (partition->start);
lba_to_chs (partition->start, lba_to_chs (partition->start,
&(mbr.entries[i].start_sector), &(mbr.entries[i].start_sector),
&(mbr.entries[i].start_cylinder), &(mbr.entries[i].start_cylinder),
&(mbr.entries[i].start_head)); &(mbr.entries[i].start_head));
lba_to_chs (partition->start + partition->len - 1, lba_to_chs (partition->start + partition->len - 1,
&(mbr.entries[i].end_sector), &(mbr.entries[i].end_sector),
&(mbr.entries[i].end_cylinder), &(mbr.entries[i].end_cylinder),
&(mbr.entries[i].end_head)); &(mbr.entries[i].end_head));
@ -210,11 +210,11 @@ grub_cmd_gptsync (grub_command_t cmd __attribute__ ((unused)),
mbr.entries[0].flag = 0; mbr.entries[0].flag = 0;
mbr.entries[0].type = GRUB_PC_PARTITION_TYPE_GPT_DISK; mbr.entries[0].type = GRUB_PC_PARTITION_TYPE_GPT_DISK;
mbr.entries[0].start = grub_cpu_to_le32 (1); mbr.entries[0].start = grub_cpu_to_le32 (1);
lba_to_chs (1, lba_to_chs (1,
&(mbr.entries[0].start_sector), &(mbr.entries[0].start_sector),
&(mbr.entries[0].start_cylinder), &(mbr.entries[0].start_cylinder),
&(mbr.entries[0].start_head)); &(mbr.entries[0].start_head));
lba_to_chs (first_sector, lba_to_chs (first_sector,
&(mbr.entries[0].end_sector), &(mbr.entries[0].end_sector),
&(mbr.entries[0].end_cylinder), &(mbr.entries[0].end_cylinder),
&(mbr.entries[0].end_head)); &(mbr.entries[0].end_head));
@ -239,8 +239,8 @@ static grub_command_t cmd;
GRUB_MOD_INIT(gptsync) GRUB_MOD_INIT(gptsync)
{ {
(void) mod; /* To stop warning. */ (void) mod; /* To stop warning. */
cmd = grub_register_command ("gptsync", grub_cmd_gptsync, cmd = grub_register_command ("gptsync", grub_cmd_gptsync,
"gptsync DEVICE [PARTITION[+/-[TYPE]]] ...", "gptsync DEVICE [PARTITION[+/-[TYPE]]] ...",
"Fill hybrid MBR of GPT drive DEVICE. " "Fill hybrid MBR of GPT drive DEVICE. "
"specified partitions will be a part " "specified partitions will be a part "
"of hybrid mbr. Up to 3 partitions are " "of hybrid mbr. Up to 3 partitions are "

View file

@ -28,7 +28,7 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
{ {
int cnt = 0; int cnt = 0;
char *currarg; char *currarg;
auto int print_command_info (grub_command_t cmd); auto int print_command_info (grub_command_t cmd);
auto int print_command_help (grub_command_t cmd); auto int print_command_help (grub_command_t cmd);
@ -61,7 +61,7 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
{ {
if (cnt++ > 0) if (cnt++ > 0)
grub_printf ("\n\n"); grub_printf ("\n\n");
if (cmd->flags & GRUB_COMMAND_FLAG_EXTCMD) if (cmd->flags & GRUB_COMMAND_FLAG_EXTCMD)
grub_arg_show_help ((grub_extcmd_t) cmd->data); grub_arg_show_help ((grub_extcmd_t) cmd->data);
else else
@ -71,20 +71,20 @@ grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc,
} }
return 0; return 0;
} }
if (argc == 0) if (argc == 0)
grub_command_iterate (print_command_info); grub_command_iterate (print_command_info);
else else
{ {
int i; int i;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
currarg = args[i]; currarg = args[i];
grub_command_iterate (print_command_help); grub_command_iterate (print_command_help);
} }
} }
return 0; return 0;
} }

View file

@ -26,7 +26,7 @@ grub_machine_acpi_get_rsdpv1 (void)
int ebda_len; int ebda_len;
grub_uint8_t *ebda, *ptr; grub_uint8_t *ebda, *ptr;
grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n"); grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n");
ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4); ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4);
ebda_len = * (grub_uint16_t *) ebda; ebda_len = * (grub_uint16_t *) ebda;
if (! ebda_len) if (! ebda_len)
@ -37,7 +37,7 @@ grub_machine_acpi_get_rsdpv1 (void)
&& ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0) && ((struct grub_acpi_rsdp_v10 *) ptr)->revision == 0)
return (struct grub_acpi_rsdp_v10 *) ptr; return (struct grub_acpi_rsdp_v10 *) ptr;
grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n"); grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n");
for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000; for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000;
ptr += 16) ptr += 16)
if (grub_memcmp (ptr, "RSD PTR ", 8) == 0 if (grub_memcmp (ptr, "RSD PTR ", 8) == 0
@ -53,7 +53,7 @@ grub_machine_acpi_get_rsdpv2 (void)
int ebda_len; int ebda_len;
grub_uint8_t *ebda, *ptr; grub_uint8_t *ebda, *ptr;
grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n"); grub_dprintf ("acpi", "Looking for RSDP. Scanning EBDA\n");
ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4); ebda = (grub_uint8_t *) ((* ((grub_uint16_t *) 0x40e)) << 4);
ebda_len = * (grub_uint16_t *) ebda; ebda_len = * (grub_uint16_t *) ebda;
if (! ebda_len) if (! ebda_len)
@ -67,7 +67,7 @@ grub_machine_acpi_get_rsdpv2 (void)
== 0) == 0)
return (struct grub_acpi_rsdp_v20 *) ptr; return (struct grub_acpi_rsdp_v20 *) ptr;
grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n"); grub_dprintf ("acpi", "Looking for RSDP. Scanning BIOS\n");
for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000; for (ptr = (grub_uint8_t *) 0xe0000; ptr < (grub_uint8_t *) 0x100000;
ptr += 16) ptr += 16)
if (grub_memcmp (ptr, "RSD PTR ", 8) == 0 if (grub_memcmp (ptr, "RSD PTR ", 8) == 0

View file

@ -184,7 +184,7 @@ list_mappings (void)
{ {
grub_printf ("%cD #%-3u (0x%02x) %cd%d\n", grub_printf ("%cD #%-3u (0x%02x) %cd%d\n",
(curnode->newdrive & 0x80) ? 'H' : 'F', (curnode->newdrive & 0x80) ? 'H' : 'F',
curnode->newdrive & 0x7F, curnode->newdrive, curnode->newdrive & 0x7F, curnode->newdrive,
(curnode->redirto & 0x80) ? 'h' : 'f', (curnode->redirto & 0x80) ? 'h' : 'f',
curnode->redirto & 0x7F curnode->redirto & 0x7F
); );

View file

@ -171,7 +171,7 @@ grub_cmd_play (grub_command_t cmd __attribute__ ((unused)),
sizeof (struct note)) == sizeof (struct note) sizeof (struct note)) == sizeof (struct note)
&& buf.pitch != T_FINE && grub_checkkey () < 0) && buf.pitch != T_FINE && grub_checkkey () < 0)
{ {
grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch, grub_dprintf ("play", "pitch = %d, duration = %d\n", buf.pitch,
buf.duration); buf.duration);

View file

@ -66,14 +66,14 @@ grub_cmd_vbeinfo (grub_command_t cmd __attribute__ ((unused)),
p = video_mode_list = real2pm (controller_info.video_mode_ptr); p = video_mode_list = real2pm (controller_info.video_mode_ptr);
while (*p++ != 0xFFFF) while (*p++ != 0xFFFF)
; ;
video_mode_list_size = (grub_addr_t) p - (grub_addr_t) video_mode_list; video_mode_list_size = (grub_addr_t) p - (grub_addr_t) video_mode_list;
saved_video_mode_list = grub_malloc (video_mode_list_size); saved_video_mode_list = grub_malloc (video_mode_list_size);
if (! saved_video_mode_list) if (! saved_video_mode_list)
return grub_errno; return grub_errno;
grub_memcpy (saved_video_mode_list, video_mode_list, video_mode_list_size); grub_memcpy (saved_video_mode_list, video_mode_list, video_mode_list_size);
grub_printf ("List of compatible video modes:\n"); grub_printf ("List of compatible video modes:\n");
grub_printf ("Legend: P=Packed pixel, D=Direct color, " grub_printf ("Legend: P=Packed pixel, D=Direct color, "
"mask/pos=R/G/B/reserved\n"); "mask/pos=R/G/B/reserved\n");
@ -83,7 +83,7 @@ grub_cmd_vbeinfo (grub_command_t cmd __attribute__ ((unused)),
{ {
const char *memory_model = 0; const char *memory_model = 0;
grub_uint32_t mode = (grub_uint32_t) *p; grub_uint32_t mode = (grub_uint32_t) *p;
err = grub_vbe_get_video_mode_info (mode, &mode_info_tmp); err = grub_vbe_get_video_mode_info (mode, &mode_info_tmp);
if (err != GRUB_ERR_NONE) if (err != GRUB_ERR_NONE)
{ {
@ -127,7 +127,7 @@ grub_cmd_vbeinfo (grub_command_t cmd __attribute__ ((unused)),
if (! memory_model) if (! memory_model)
continue; continue;
grub_printf ("0x%03x: %4d x %4d x %2d %s", grub_printf ("0x%03x: %4d x %4d x %2d %s",
mode, mode,
mode_info_tmp.x_resolution, mode_info_tmp.x_resolution,
mode_info_tmp.y_resolution, mode_info_tmp.y_resolution,
@ -149,7 +149,7 @@ grub_cmd_vbeinfo (grub_command_t cmd __attribute__ ((unused)),
} }
grub_free (saved_video_mode_list); grub_free (saved_video_mode_list);
/* Check existence of vbe_mode environment variable. */ /* Check existence of vbe_mode environment variable. */
modevar = grub_env_get ("vbe_mode"); modevar = grub_env_get ("vbe_mode");

View file

@ -73,7 +73,7 @@ grub_cmd_vbetest (grub_command_t cmd __attribute__ ((unused)),
grub_printf ("Old video mode = %04x\n", old_mode); grub_printf ("Old video mode = %04x\n", old_mode);
else else
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
/* Check existence of vbe_mode environment variable. */ /* Check existence of vbe_mode environment variable. */
modevar = grub_env_get ("vbe_mode"); modevar = grub_env_get ("vbe_mode");
if (modevar != 0) if (modevar != 0)
@ -90,7 +90,7 @@ grub_cmd_vbetest (grub_command_t cmd __attribute__ ((unused)),
err = grub_vbe_get_video_mode_info (use_mode, &mode_info); err = grub_vbe_get_video_mode_info (use_mode, &mode_info);
if (err != GRUB_ERR_NONE) if (err != GRUB_ERR_NONE)
return err; return err;
/* Dump out details about the mode being tested. */ /* Dump out details about the mode being tested. */
grub_printf ("mode: 0x%03x\n", grub_printf ("mode: 0x%03x\n",
use_mode); use_mode);

View file

@ -51,7 +51,7 @@ open_envblk_file (char *filename)
filename = grub_malloc (len + 1 + sizeof (GRUB_ENVBLK_DEFCFG)); filename = grub_malloc (len + 1 + sizeof (GRUB_ENVBLK_DEFCFG));
if (! filename) if (! filename)
return 0; return 0;
grub_strcpy (filename, prefix); grub_strcpy (filename, prefix);
filename[len] = '/'; filename[len] = '/';
grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG); grub_strcpy (filename + len + 1, GRUB_ENVBLK_DEFCFG);
@ -80,7 +80,7 @@ read_envblk_file (grub_file_t file)
buf = grub_malloc (size); buf = grub_malloc (size);
if (! buf) if (! buf)
return 0; return 0;
while (size > 0) while (size > 0)
{ {
grub_ssize_t ret; grub_ssize_t ret;
@ -124,7 +124,7 @@ grub_cmd_load_env (grub_extcmd_t cmd,
grub_env_set (name, value); grub_env_set (name, value);
return 0; return 0;
} }
file = open_envblk_file ((state[0].set) ? state[0].arg : 0); file = open_envblk_file ((state[0].set) ? state[0].arg : 0);
if (! file) if (! file)
return grub_errno; return grub_errno;
@ -135,7 +135,7 @@ grub_cmd_load_env (grub_extcmd_t cmd,
grub_envblk_iterate (envblk, set_var); grub_envblk_iterate (envblk, set_var);
grub_envblk_close (envblk); grub_envblk_close (envblk);
fail: fail:
grub_file_close (file); grub_file_close (file);
return grub_errno; return grub_errno;
@ -157,7 +157,7 @@ grub_cmd_list_env (grub_extcmd_t cmd,
grub_printf ("%s=%s\n", name, value); grub_printf ("%s=%s\n", name, value);
return 0; return 0;
} }
file = open_envblk_file ((state[0].set) ? state[0].arg : 0); file = open_envblk_file ((state[0].set) ? state[0].arg : 0);
if (! file) if (! file)
return grub_errno; return grub_errno;
@ -168,7 +168,7 @@ grub_cmd_list_env (grub_extcmd_t cmd,
grub_envblk_iterate (envblk, print_var); grub_envblk_iterate (envblk, print_var);
grub_envblk_close (envblk); grub_envblk_close (envblk);
fail: fail:
grub_file_close (file); grub_file_close (file);
return grub_errno; return grub_errno;
@ -205,7 +205,7 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
grub_disk_addr_t part_start; grub_disk_addr_t part_start;
struct blocklist *p; struct blocklist *p;
char *buf; char *buf;
/* Sanity checks. */ /* Sanity checks. */
total_length = 0; total_length = 0;
for (p = blocklists; p; p = p->next) for (p = blocklists; p; p = p->next)
@ -222,10 +222,10 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
return 0; return 0;
} }
} }
total_length += p->length; total_length += p->length;
} }
if (total_length != grub_file_size (file)) if (total_length != grub_file_size (file))
{ {
/* Maybe sparse, unallocated sectors. No way in GRUB. */ /* Maybe sparse, unallocated sectors. No way in GRUB. */
@ -245,7 +245,7 @@ check_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
for (p = blocklists, index = 0; p; p = p->next, index += p->length) for (p = blocklists, index = 0; p; p = p->next, index += p->length)
{ {
char blockbuf[GRUB_DISK_SECTOR_SIZE]; char blockbuf[GRUB_DISK_SECTOR_SIZE];
if (grub_disk_read (disk, p->sector - part_start, if (grub_disk_read (disk, p->sector - part_start,
p->offset, p->length, blockbuf)) p->offset, p->length, blockbuf))
return 0; return 0;
@ -269,7 +269,7 @@ write_blocklists (grub_envblk_t envblk, struct blocklist *blocklists,
grub_disk_addr_t part_start; grub_disk_addr_t part_start;
struct blocklist *p; struct blocklist *p;
grub_size_t index; grub_size_t index;
buf = grub_envblk_buffer (envblk); buf = grub_envblk_buffer (envblk);
disk = file->device->disk; disk = file->device->disk;
if (disk->partition) if (disk->partition)
@ -296,7 +296,7 @@ grub_cmd_save_env (grub_extcmd_t cmd, int argc, char **args)
grub_envblk_t envblk; grub_envblk_t envblk;
struct blocklist *head = 0; struct blocklist *head = 0;
struct blocklist *tail = 0; struct blocklist *tail = 0;
/* Store blocklists in a linked list. */ /* Store blocklists in a linked list. */
auto void NESTED_FUNC_ATTR read_hook (grub_disk_addr_t sector, auto void NESTED_FUNC_ATTR read_hook (grub_disk_addr_t sector,
unsigned offset, unsigned offset,
@ -309,7 +309,7 @@ grub_cmd_save_env (grub_extcmd_t cmd, int argc, char **args)
if (offset + length > GRUB_DISK_SECTOR_SIZE) if (offset + length > GRUB_DISK_SECTOR_SIZE)
/* Seemingly a bug. */ /* Seemingly a bug. */
return; return;
block = grub_malloc (sizeof (*block)); block = grub_malloc (sizeof (*block));
if (! block) if (! block)
return; return;
@ -348,7 +348,7 @@ grub_cmd_save_env (grub_extcmd_t cmd, int argc, char **args)
if (! check_blocklists (envblk, head, file)) if (! check_blocklists (envblk, head, file))
goto fail; goto fail;
while (argc) while (argc)
{ {
char *value; char *value;
@ -368,7 +368,7 @@ grub_cmd_save_env (grub_extcmd_t cmd, int argc, char **args)
} }
write_blocklists (envblk, head, file); write_blocklists (envblk, head, file);
fail: fail:
if (envblk) if (envblk)
grub_envblk_close (envblk); grub_envblk_close (envblk);

View file

@ -51,10 +51,10 @@ grub_ls_list_devices (int longlist)
grub_normal_print_device_info (name); grub_normal_print_device_info (name);
else else
grub_printf ("(%s) ", name); grub_printf ("(%s) ", name);
return 0; return 0;
} }
grub_device_iterate (grub_ls_print_devices); grub_device_iterate (grub_ls_print_devices);
grub_putchar ('\n'); grub_putchar ('\n');
grub_refresh (); grub_refresh ();
@ -70,20 +70,20 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
const char *path; const char *path;
grub_device_t dev; grub_device_t dev;
auto int print_files (const char *filename, auto int print_files (const char *filename,
const struct grub_dirhook_info *info); const struct grub_dirhook_info *info);
auto int print_files_long (const char *filename, auto int print_files_long (const char *filename,
const struct grub_dirhook_info *info); const struct grub_dirhook_info *info);
int print_files (const char *filename, const struct grub_dirhook_info *info) int print_files (const char *filename, const struct grub_dirhook_info *info)
{ {
if (all || filename[0] != '.') if (all || filename[0] != '.')
grub_printf ("%s%s ", filename, info->dir ? "/" : ""); grub_printf ("%s%s ", filename, info->dir ? "/" : "");
return 0; return 0;
} }
int print_files_long (const char *filename, int print_files_long (const char *filename,
const struct grub_dirhook_info *info) const struct grub_dirhook_info *info)
{ {
char pathname[grub_strlen (dirname) + grub_strlen (filename) + 1]; char pathname[grub_strlen (dirname) + grub_strlen (filename) + 1];
@ -94,7 +94,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
if (! info->dir) if (! info->dir)
{ {
grub_file_t file; grub_file_t file;
if (dirname[grub_strlen (dirname) - 1] == '/') if (dirname[grub_strlen (dirname) - 1] == '/')
grub_sprintf (pathname, "%s%s", dirname, filename); grub_sprintf (pathname, "%s%s", dirname, filename);
else else
@ -117,7 +117,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
int fsz = file->size; int fsz = file->size;
int units = 0; int units = 0;
char buf[20]; char buf[20];
while (fsz / 1024) while (fsz / 1024)
{ {
fsize = (fsize + 512) / 1024; fsize = (fsize + 512) / 1024;
@ -136,7 +136,7 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
} }
else else
grub_printf ("%-12llu", (unsigned long long) file->size); grub_printf ("%-12llu", (unsigned long long) file->size);
} }
grub_file_close (file); grub_file_close (file);
} }
@ -150,13 +150,13 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
if (human) if (human)
grub_printf (" %d-%02d-%02d %02d:%02d:%02d %-11s ", grub_printf (" %d-%02d-%02d %02d:%02d:%02d %-11s ",
datetime.year, datetime.month, datetime.day, datetime.year, datetime.month, datetime.day,
datetime.hour, datetime.minute, datetime.hour, datetime.minute,
datetime.second, datetime.second,
grub_get_weekday_name (&datetime)); grub_get_weekday_name (&datetime));
else else
grub_printf (" %04d%02d%02d%02d%02d%02d ", grub_printf (" %04d%02d%02d%02d%02d%02d ",
datetime.year, datetime.month, datetime.year, datetime.month,
datetime.day, datetime.hour, datetime.day, datetime.hour,
datetime.minute, datetime.second); datetime.minute, datetime.second);
} }
grub_printf ("%s%s\n", filename, info->dir ? "/" : ""); grub_printf ("%s%s\n", filename, info->dir ? "/" : "");
@ -175,13 +175,13 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
path = dirname; path = dirname;
else else
path++; path++;
if (! path && ! device_name) if (! path && ! device_name)
{ {
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument"); grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
goto fail; goto fail;
} }
if (! *path) if (! *path)
{ {
if (grub_errno == GRUB_ERR_UNKNOWN_FS) if (grub_errno == GRUB_ERR_UNKNOWN_FS)
@ -204,13 +204,13 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
grub_file_t file; grub_file_t file;
struct grub_dirhook_info info; struct grub_dirhook_info info;
grub_errno = 0; grub_errno = 0;
file = grub_file_open (dirname); file = grub_file_open (dirname);
if (! file) if (! file)
goto fail; goto fail;
grub_file_close (file); grub_file_close (file);
p = grub_strrchr (dirname, '/') + 1; p = grub_strrchr (dirname, '/') + 1;
dirname = grub_strndup (dirname, p - dirname); dirname = grub_strndup (dirname, p - dirname);
if (! dirname) if (! dirname)
@ -228,14 +228,14 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
if (grub_errno == GRUB_ERR_NONE) if (grub_errno == GRUB_ERR_NONE)
grub_putchar ('\n'); grub_putchar ('\n');
grub_refresh (); grub_refresh ();
} }
fail: fail:
if (dev) if (dev)
grub_device_close (dev); grub_device_close (dev);
grub_free (device_name); grub_free (device_name);
return 0; return 0;

View file

@ -38,8 +38,8 @@ static char helpmsg[] =
"Use \"parttool PARTITION help\" for the list " "Use \"parttool PARTITION help\" for the list "
"of available commands"; "of available commands";
int int
grub_parttool_register(const char *part_name, grub_parttool_register(const char *part_name,
const grub_parttool_function_t func, const grub_parttool_function_t func,
const struct grub_parttool_argdesc *args) const struct grub_parttool_argdesc *args)
{ {
@ -55,11 +55,11 @@ grub_parttool_register(const char *part_name,
cur->handle = curhandle++; cur->handle = curhandle++;
for (nargs = 0; args[nargs].name != 0; nargs++); for (nargs = 0; args[nargs].name != 0; nargs++);
cur->nargs = nargs; cur->nargs = nargs;
cur->args = (struct grub_parttool_argdesc *) cur->args = (struct grub_parttool_argdesc *)
grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc)); grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc));
grub_memcpy (cur->args, args, grub_memcpy (cur->args, args,
(nargs + 1) * sizeof (struct grub_parttool_argdesc)); (nargs + 1) * sizeof (struct grub_parttool_argdesc));
cur->func = func; cur->func = func;
parts = cur; parts = cur;
return cur->handle; return cur->handle;
@ -113,22 +113,22 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
for (curarg = cur->args; curarg->name; curarg++) for (curarg = cur->args; curarg->name; curarg++)
{ {
int spacing = 20; int spacing = 20;
spacing -= grub_strlen (curarg->name); spacing -= grub_strlen (curarg->name);
grub_printf ("%s", curarg->name); grub_printf ("%s", curarg->name);
switch (curarg->type) switch (curarg->type)
{ {
case GRUB_PARTTOOL_ARG_BOOL: case GRUB_PARTTOOL_ARG_BOOL:
grub_printf ("+/-"); grub_printf ("+/-");
spacing -= 3; spacing -= 3;
break; break;
case GRUB_PARTTOOL_ARG_VAL: case GRUB_PARTTOOL_ARG_VAL:
grub_printf ("=VAL"); grub_printf ("=VAL");
spacing -= 4; spacing -= 4;
break; break;
case GRUB_PARTTOOL_ARG_END: case GRUB_PARTTOOL_ARG_END:
break; break;
} }
@ -138,7 +138,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
} }
} }
if (! found) if (! found)
grub_printf ("Sorry no parttool is available for %s\n", grub_printf ("Sorry no parttool is available for %s\n",
dev->disk->partition->partmap->name); dev->disk->partition->partmap->name);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -152,11 +152,11 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')') if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')')
{ {
args[0][grub_strlen (args[0]) - 1] = 0; args[0][grub_strlen (args[0]) - 1] = 0;
dev = grub_device_open (args[0] + 1); dev = grub_device_open (args[0] + 1);
args[0][grub_strlen (args[0]) - 1] = ')'; args[0][grub_strlen (args[0]) - 1] = ')';
} }
else else
dev = grub_device_open (args[0]); dev = grub_device_open (args[0]);
if (! dev) if (! dev)
return grub_errno; return grub_errno;
@ -186,7 +186,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
if (filename) if (filename)
{ {
grub_file_t file; grub_file_t file;
grub_sprintf (filename, "%s/parttool.lst", prefix); grub_sprintf (filename, "%s/parttool.lst", prefix);
file = grub_file_open (filename); file = grub_file_open (filename);
if (file) if (file)
@ -197,36 +197,36 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
char *p, *name; char *p, *name;
buf = grub_file_getline (file); buf = grub_file_getline (file);
if (! buf) if (! buf)
break; break;
name = buf; name = buf;
if (! grub_isgraph (name[0])) if (! grub_isgraph (name[0]))
continue; continue;
p = grub_strchr (name, ':'); p = grub_strchr (name, ':');
if (! p) if (! p)
continue; continue;
*p = '\0'; *p = '\0';
while (*++p == ' ') while (*++p == ' ')
; ;
if (! grub_isgraph (*p)) if (! grub_isgraph (*p))
continue; continue;
if (grub_strcmp (name, dev->disk->partition->partmap->name) if (grub_strcmp (name, dev->disk->partition->partmap->name)
!= 0) != 0)
continue; continue;
grub_dl_load (p); grub_dl_load (p);
} }
grub_file_close (file); grub_file_close (file);
} }
grub_free (filename); grub_free (filename);
} }
} }
@ -254,15 +254,15 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
if (grub_strcmp (dev->disk->partition->partmap->name, cur->name) == 0) if (grub_strcmp (dev->disk->partition->partmap->name, cur->name) == 0)
{ {
for (curarg = cur->args; curarg->name; curarg++) for (curarg = cur->args; curarg->name; curarg++)
if (grub_strncmp (curarg->name, args[i], if (grub_strncmp (curarg->name, args[i],
grub_strlen (curarg->name)) == 0 grub_strlen (curarg->name)) == 0
&& ((curarg->type == GRUB_PARTTOOL_ARG_BOOL && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL
&& (args[i][grub_strlen (curarg->name)] == '+' && (args[i][grub_strlen (curarg->name)] == '+'
|| args[i][grub_strlen (curarg->name)] == '-' || args[i][grub_strlen (curarg->name)] == '-'
|| args[i][grub_strlen (curarg->name)] == 0)) || args[i][grub_strlen (curarg->name)] == 0))
|| (curarg->type == GRUB_PARTTOOL_ARG_VAL || (curarg->type == GRUB_PARTTOOL_ARG_VAL
&& args[i][grub_strlen (curarg->name)] == '='))) && args[i][grub_strlen (curarg->name)] == '=')))
break; break;
if (curarg->name) if (curarg->name)
break; break;
@ -271,18 +271,18 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised argument %s", return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised argument %s",
args[i]); args[i]);
ptool = cur; ptool = cur;
pargs = (struct grub_parttool_args *) pargs = (struct grub_parttool_args *)
grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args)); grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args));
grub_memset (pargs, 0, grub_memset (pargs, 0,
ptool->nargs * sizeof (struct grub_parttool_args)); ptool->nargs * sizeof (struct grub_parttool_args));
for (j = i; j < argc; j++) for (j = i; j < argc; j++)
if (! parsed[j]) if (! parsed[j])
{ {
for (curarg = ptool->args; curarg->name; curarg++) for (curarg = ptool->args; curarg->name; curarg++)
if (grub_strncmp (curarg->name, args[i], if (grub_strncmp (curarg->name, args[i],
grub_strlen (curarg->name)) == 0 grub_strlen (curarg->name)) == 0
&& ((curarg->type == GRUB_PARTTOOL_ARG_BOOL && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL
&& (args[j][grub_strlen (curarg->name)] == '+' && (args[j][grub_strlen (curarg->name)] == '+'
|| args[j][grub_strlen (curarg->name)] == '-' || args[j][grub_strlen (curarg->name)] == '-'
|| args[j][grub_strlen (curarg->name)] == 0)) || args[j][grub_strlen (curarg->name)] == 0))
|| (curarg->type == GRUB_PARTTOOL_ARG_VAL || (curarg->type == GRUB_PARTTOOL_ARG_VAL
@ -293,15 +293,15 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
switch (curarg->type) switch (curarg->type)
{ {
case GRUB_PARTTOOL_ARG_BOOL: case GRUB_PARTTOOL_ARG_BOOL:
pargs[curarg - ptool->args].bool pargs[curarg - ptool->args].bool
= (args[j][grub_strlen (curarg->name)] != '-'); = (args[j][grub_strlen (curarg->name)] != '-');
break; break;
case GRUB_PARTTOOL_ARG_VAL: case GRUB_PARTTOOL_ARG_VAL:
pargs[curarg - ptool->args].str pargs[curarg - ptool->args].str
= (args[j] + grub_strlen (curarg->name) + 1); = (args[j] + grub_strlen (curarg->name) + 1);
break; break;
case GRUB_PARTTOOL_ARG_END: case GRUB_PARTTOOL_ARG_END:
break; break;
} }
@ -324,8 +324,8 @@ static grub_command_t cmd;
GRUB_MOD_INIT(parttool) GRUB_MOD_INIT(parttool)
{ {
mymod = mod; mymod = mod;
cmd = grub_register_command ("parttool", grub_cmd_parttool, cmd = grub_register_command ("parttool", grub_cmd_parttool,
"parttool PARTITION COMMANDS", "parttool PARTITION COMMANDS",
helpmsg); helpmsg);
} }

View file

@ -42,7 +42,7 @@ search_fs (const char *key, const char *var, int no_floppy, int is_uuid)
{ {
int count = 0; int count = 0;
auto int iterate_device (const char *name); auto int iterate_device (const char *name);
int iterate_device (const char *name) int iterate_device (const char *name)
{ {
grub_device_t dev; grub_device_t dev;
@ -53,12 +53,12 @@ search_fs (const char *key, const char *var, int no_floppy, int is_uuid)
name[0] == 'f' && name[1] == 'd' && name[0] == 'f' && name[1] == 'd' &&
name[2] >= '0' && name[2] <= '9') name[2] >= '0' && name[2] <= '9')
return 0; return 0;
dev = grub_device_open (name); dev = grub_device_open (name);
if (dev) if (dev)
{ {
grub_fs_t fs; grub_fs_t fs;
fs = grub_fs_probe (dev); fs = grub_fs_probe (dev);
#define QUID(x) (is_uuid ? (x)->uuid : (x)->label) #define QUID(x) (is_uuid ? (x)->uuid : (x)->label)
@ -66,7 +66,7 @@ search_fs (const char *key, const char *var, int no_floppy, int is_uuid)
if (fs && QUID(fs)) if (fs && QUID(fs))
{ {
char *quid; char *quid;
(QUID(fs)) (dev, &quid); (QUID(fs)) (dev, &quid);
if (grub_errno == GRUB_ERR_NONE && quid) if (grub_errno == GRUB_ERR_NONE && quid)
{ {
@ -82,20 +82,20 @@ search_fs (const char *key, const char *var, int no_floppy, int is_uuid)
else else
grub_printf (" %s", name); grub_printf (" %s", name);
} }
grub_free (quid); grub_free (quid);
} }
} }
grub_device_close (dev); grub_device_close (dev);
} }
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
return abort; return abort;
} }
grub_device_iterate (iterate_device); grub_device_iterate (iterate_device);
if (count == 0) if (count == 0)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key); grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
} }
@ -113,13 +113,13 @@ search_file (const char *key, const char *var, int no_floppy)
char *p; char *p;
grub_file_t file; grub_file_t file;
int abort = 0; int abort = 0;
/* Skip floppy drives when requested. */ /* Skip floppy drives when requested. */
if (no_floppy && if (no_floppy &&
name[0] == 'f' && name[1] == 'd' && name[0] == 'f' && name[1] == 'd' &&
name[2] >= '0' && name[2] <= '9') name[2] >= '0' && name[2] <= '9')
return 0; return 0;
len = grub_strlen (name) + 2 + grub_strlen (key) + 1; len = grub_strlen (name) + 2 + grub_strlen (key) + 1;
p = grub_realloc (buf, len); p = grub_realloc (buf, len);
if (! p) if (! p)
@ -127,7 +127,7 @@ search_file (const char *key, const char *var, int no_floppy)
buf = p; buf = p;
grub_sprintf (buf, "(%s)%s", name, key); grub_sprintf (buf, "(%s)%s", name, key);
file = grub_file_open (buf); file = grub_file_open (buf);
if (file) if (file)
{ {
@ -143,15 +143,15 @@ search_file (const char *key, const char *var, int no_floppy)
grub_file_close (file); grub_file_close (file);
} }
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
return abort; return abort;
} }
grub_device_iterate (iterate_device); grub_device_iterate (iterate_device);
grub_free (buf); grub_free (buf);
if (grub_errno == GRUB_ERR_NONE && count == 0) if (grub_errno == GRUB_ERR_NONE && count == 0)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device"); grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device");
} }
@ -161,13 +161,13 @@ grub_cmd_search (grub_extcmd_t cmd, int argc, char **args)
{ {
struct grub_arg_list *state = cmd->state; struct grub_arg_list *state = cmd->state;
const char *var = 0; const char *var = 0;
if (argc == 0) if (argc == 0)
return grub_error (GRUB_ERR_INVALID_COMMAND, "no argument specified"); return grub_error (GRUB_ERR_INVALID_COMMAND, "no argument specified");
if (state[3].set) if (state[3].set)
var = state[3].arg ? state[3].arg : "root"; var = state[3].arg ? state[3].arg : "root";
if (state[1].set) if (state[1].set)
search_fs (args[0], var, state[4].set, 0); search_fs (args[0], var, state[4].set, 0);
else if (state[2].set) else if (state[2].set)

View file

@ -63,9 +63,9 @@ test_parse (char **args, int *argn, int argc)
grub_device_t dev; grub_device_t dev;
/* A hook for iterating directories. */ /* A hook for iterating directories. */
auto int find_file (const char *cur_filename, auto int find_file (const char *cur_filename,
const struct grub_dirhook_info *info); const struct grub_dirhook_info *info);
int find_file (const char *cur_filename, int find_file (const char *cur_filename,
const struct grub_dirhook_info *info) const struct grub_dirhook_info *info)
{ {
if ((info->case_insensitive ? grub_strcasecmp (cur_filename, filename) if ((info->case_insensitive ? grub_strcasecmp (cur_filename, filename)
@ -77,7 +77,7 @@ test_parse (char **args, int *argn, int argc)
} }
return 0; return 0;
} }
file_exists = 0; file_exists = 0;
device_name = grub_file_get_device_name (path); device_name = grub_file_get_device_name (path);
dev = grub_device_open (device_name); dev = grub_device_open (device_name);
@ -93,7 +93,7 @@ test_parse (char **args, int *argn, int argc)
pathname = path; pathname = path;
else else
pathname++; pathname++;
/* Remove trailing '/'. */ /* Remove trailing '/'. */
while (*pathname && pathname[grub_strlen (pathname) - 1] == '/') while (*pathname && pathname[grub_strlen (pathname) - 1] == '/')
pathname[grub_strlen (pathname) - 1] = 0; pathname[grub_strlen (pathname) - 1] = 0;
@ -132,7 +132,7 @@ test_parse (char **args, int *argn, int argc)
else else
(fs->dir) (dev, path, find_file); (fs->dir) (dev, path, find_file);
grub_device_close (dev); grub_device_close (dev);
grub_free (path); grub_free (path);
grub_free (device_name); grub_free (device_name);
} }
@ -158,7 +158,7 @@ test_parse (char **args, int *argn, int argc)
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
/* GRUB extension: lexicographical sorting. */ /* GRUB extension: lexicographical sorting. */
if (grub_strcmp (args[*argn + 1], "<") == 0) if (grub_strcmp (args[*argn + 1], "<") == 0)
{ {
@ -166,21 +166,21 @@ test_parse (char **args, int *argn, int argc)
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
if (grub_strcmp (args[*argn + 1], "<=") == 0) if (grub_strcmp (args[*argn + 1], "<=") == 0)
{ {
update_val (grub_strcmp (args[*argn], args[*argn + 2]) <= 0); update_val (grub_strcmp (args[*argn], args[*argn + 2]) <= 0);
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
if (grub_strcmp (args[*argn + 1], ">") == 0) if (grub_strcmp (args[*argn + 1], ">") == 0)
{ {
update_val (grub_strcmp (args[*argn], args[*argn + 2]) > 0); update_val (grub_strcmp (args[*argn], args[*argn + 2]) > 0);
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
if (grub_strcmp (args[*argn + 1], ">=") == 0) if (grub_strcmp (args[*argn + 1], ">=") == 0)
{ {
update_val (grub_strcmp (args[*argn], args[*argn + 2]) >= 0); update_val (grub_strcmp (args[*argn], args[*argn + 2]) >= 0);
@ -191,7 +191,7 @@ test_parse (char **args, int *argn, int argc)
/* Number tests. */ /* Number tests. */
if (grub_strcmp (args[*argn + 1], "-eq") == 0) if (grub_strcmp (args[*argn + 1], "-eq") == 0)
{ {
update_val (grub_strtosl (args[*argn], 0, 0) update_val (grub_strtosl (args[*argn], 0, 0)
== grub_strtosl (args[*argn + 2], 0, 0)); == grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3; (*argn) += 3;
continue; continue;
@ -199,15 +199,15 @@ test_parse (char **args, int *argn, int argc)
if (grub_strcmp (args[*argn + 1], "-ge") == 0) if (grub_strcmp (args[*argn + 1], "-ge") == 0)
{ {
update_val (grub_strtosl (args[*argn], 0, 0) update_val (grub_strtosl (args[*argn], 0, 0)
>= grub_strtosl (args[*argn + 2], 0, 0)); >= grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
if (grub_strcmp (args[*argn + 1], "-gt") == 0) if (grub_strcmp (args[*argn + 1], "-gt") == 0)
{ {
update_val (grub_strtosl (args[*argn], 0, 0) update_val (grub_strtosl (args[*argn], 0, 0)
> grub_strtosl (args[*argn + 2], 0, 0)); > grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3; (*argn) += 3;
continue; continue;
@ -215,55 +215,55 @@ test_parse (char **args, int *argn, int argc)
if (grub_strcmp (args[*argn + 1], "-le") == 0) if (grub_strcmp (args[*argn + 1], "-le") == 0)
{ {
update_val (grub_strtosl (args[*argn], 0, 0) update_val (grub_strtosl (args[*argn], 0, 0)
<= grub_strtosl (args[*argn + 2], 0, 0)); <= grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
if (grub_strcmp (args[*argn + 1], "-lt") == 0) if (grub_strcmp (args[*argn + 1], "-lt") == 0)
{ {
update_val (grub_strtosl (args[*argn], 0, 0) update_val (grub_strtosl (args[*argn], 0, 0)
< grub_strtosl (args[*argn + 2], 0, 0)); < grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
if (grub_strcmp (args[*argn + 1], "-ne") == 0) if (grub_strcmp (args[*argn + 1], "-ne") == 0)
{ {
update_val (grub_strtosl (args[*argn], 0, 0) update_val (grub_strtosl (args[*argn], 0, 0)
!= grub_strtosl (args[*argn + 2], 0, 0)); != grub_strtosl (args[*argn + 2], 0, 0));
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
/* GRUB extension: compare numbers skipping prefixes. /* GRUB extension: compare numbers skipping prefixes.
Useful for comparing versions. E.g. vmlinuz-2 -plt vmlinuz-11. */ Useful for comparing versions. E.g. vmlinuz-2 -plt vmlinuz-11. */
if (grub_strcmp (args[*argn + 1], "-pgt") == 0 if (grub_strcmp (args[*argn + 1], "-pgt") == 0
|| grub_strcmp (args[*argn + 1], "-plt") == 0) || grub_strcmp (args[*argn + 1], "-plt") == 0)
{ {
int i; int i;
/* Skip common prefix. */ /* Skip common prefix. */
for (i = 0; args[*argn][i] == args[*argn + 2][i] for (i = 0; args[*argn][i] == args[*argn + 2][i]
&& args[*argn][i]; i++); && args[*argn][i]; i++);
/* Go the digits back. */ /* Go the digits back. */
i--; i--;
while (grub_isdigit (args[*argn][i]) && i > 0) while (grub_isdigit (args[*argn][i]) && i > 0)
i--; i--;
i++; i++;
if (grub_strcmp (args[*argn + 1], "-pgt") == 0) if (grub_strcmp (args[*argn + 1], "-pgt") == 0)
update_val (grub_strtoul (args[*argn] + i, 0, 0) update_val (grub_strtoul (args[*argn] + i, 0, 0)
> grub_strtoul (args[*argn + 2] + i, 0, 0)); > grub_strtoul (args[*argn + 2] + i, 0, 0));
else else
update_val (grub_strtoul (args[*argn] + i, 0, 0) update_val (grub_strtoul (args[*argn] + i, 0, 0)
< grub_strtoul (args[*argn + 2] + i, 0, 0)); < grub_strtoul (args[*argn + 2] + i, 0, 0));
(*argn) += 3; (*argn) += 3;
continue; continue;
} }
/* -nt and -ot tests. GRUB extension: when doing -?t<bias> bias /* -nt and -ot tests. GRUB extension: when doing -?t<bias> bias
will be added to the first mtime. */ will be added to the first mtime. */
if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0 if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0
|| grub_memcmp (args[*argn + 1], "-ot", 3) == 0) || grub_memcmp (args[*argn + 1], "-ot", 3) == 0)
@ -271,16 +271,16 @@ test_parse (char **args, int *argn, int argc)
struct grub_dirhook_info file1; struct grub_dirhook_info file1;
int file1exists; int file1exists;
int bias = 0; int bias = 0;
/* Fetch fileinfo. */ /* Fetch fileinfo. */
get_fileinfo (args[*argn]); get_fileinfo (args[*argn]);
file1 = file_info; file1 = file_info;
file1exists = file_exists; file1exists = file_exists;
get_fileinfo (args[*argn + 2]); get_fileinfo (args[*argn + 2]);
if (args[*argn + 1][3]) if (args[*argn + 1][3])
bias = grub_strtosl (args[*argn + 1] + 3, 0, 0); bias = grub_strtosl (args[*argn + 1] + 3, 0, 0);
if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0) if (grub_memcmp (args[*argn + 1], "-nt", 3) == 0)
update_val ((file1exists && ! file_exists) update_val ((file1exists && ! file_exists)
|| (file1.mtimeset && file_info.mtimeset || (file1.mtimeset && file_info.mtimeset
@ -305,7 +305,7 @@ test_parse (char **args, int *argn, int argc)
(*argn) += 2; (*argn) += 2;
return ret; return ret;
} }
if (grub_strcmp (args[*argn], "-e") == 0) if (grub_strcmp (args[*argn], "-e") == 0)
{ {
get_fileinfo (args[*argn + 1]); get_fileinfo (args[*argn + 1]);
@ -322,7 +322,7 @@ test_parse (char **args, int *argn, int argc)
(*argn) += 2; (*argn) += 2;
return ret; return ret;
} }
if (grub_strcmp (args[*argn], "-s") == 0) if (grub_strcmp (args[*argn], "-s") == 0)
{ {
grub_file_t file; grub_file_t file;
@ -334,12 +334,12 @@ test_parse (char **args, int *argn, int argc)
(*argn) += 2; (*argn) += 2;
return ret; return ret;
} }
/* String tests. */ /* String tests. */
if (grub_strcmp (args[*argn], "-n") == 0) if (grub_strcmp (args[*argn], "-n") == 0)
{ {
update_val (args[*argn + 1][0]); update_val (args[*argn + 1][0]);
(*argn) += 2; (*argn) += 2;
continue; continue;
} }
@ -352,7 +352,7 @@ test_parse (char **args, int *argn, int argc)
} }
/* Special modifiers. */ /* Special modifiers. */
/* End of expression. return to parent. */ /* End of expression. return to parent. */
if (grub_strcmp (args[*argn], ")") == 0) if (grub_strcmp (args[*argn], ")") == 0)
{ {
@ -366,7 +366,7 @@ test_parse (char **args, int *argn, int argc)
update_val (test_parse (args, argn, argc)); update_val (test_parse (args, argn, argc));
continue; continue;
} }
if (grub_strcmp (args[*argn], "!") == 0) if (grub_strcmp (args[*argn], "!") == 0)
{ {
invert = ! invert; invert = ! invert;
@ -404,7 +404,7 @@ grub_cmd_test (grub_command_t cmd __attribute__ ((unused)),
if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0) if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0)
argc--; argc--;
return test_parse (args, &argn, argc) ? GRUB_ERR_NONE return test_parse (args, &argn, argc) ? GRUB_ERR_NONE
: grub_error (GRUB_ERR_TEST_FAILURE, "false"); : grub_error (GRUB_ERR_TEST_FAILURE, "false");
} }

View file

@ -51,7 +51,7 @@ static const char *usb_endp_type[] =
"Interrupt" "Interrupt"
}; };
static const char *usb_devspeed[] = static const char *usb_devspeed[] =
{ {
"", "",
"Low", "Low",
@ -84,7 +84,7 @@ usb_iterate (grub_usb_device_t dev)
usb_print_str ("Product", dev, descdev->strprod); usb_print_str ("Product", dev, descdev->strprod);
usb_print_str ("Vendor", dev, descdev->strvendor); usb_print_str ("Vendor", dev, descdev->strvendor);
usb_print_str ("Serial", dev, descdev->strserial); usb_print_str ("Serial", dev, descdev->strserial);
if (descdev->class > 0 && descdev->class <= 0x0E) if (descdev->class > 0 && descdev->class <= 0x0E)
grub_printf ("Class: (0x%02x) %s, Subclass: 0x%02x, Protocol: 0x%02x\n", grub_printf ("Class: (0x%02x) %s, Subclass: 0x%02x, Protocol: 0x%02x\n",
descdev->class, usb_classes[descdev->class], descdev->class, usb_classes[descdev->class],

View file

@ -162,7 +162,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \
commands/parttool.c parttool/pcpart.c \ commands/parttool.c parttool/pcpart.c \
grub_emu_init.c grub_emu_init.c
grub_emu_LDFLAGS = $(LIBCURSES) grub_emu_LDFLAGS = $(LIBCURSES)
ifeq ($(enable_grub_emu_usb), yes) ifeq ($(enable_grub_emu_usb), yes)
grub_emu_SOURCES += disk/usbms.c util/usb.c bus/usb/usb.c \ grub_emu_SOURCES += disk/usbms.c util/usb.c bus/usb/usb.c \

View file

@ -33,7 +33,7 @@ sbin_UTILITIES = grub-mkdevicemap
ifeq ($(enable_grub_emu), yes) ifeq ($(enable_grub_emu), yes)
sbin_UTILITIES += grub-emu sbin_UTILITIES += grub-emu
endif endif
# For grub-mkdevicemap. # For grub-mkdevicemap.
grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/deviceiter.c \ grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/deviceiter.c \
util/devicemap.c util/misc.c util/devicemap.c util/misc.c
@ -144,7 +144,7 @@ multiboot_mod_SOURCES = loader/ieee1275/multiboot2.c \
loader/multiboot2.c \ loader/multiboot2.c \
loader/multiboot_loader.c loader/multiboot_loader.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS) multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS) multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
# For memdisk.mod. # For memdisk.mod.
memdisk_mod_SOURCES = disk/memdisk.c memdisk_mod_SOURCES = disk/memdisk.c

View file

@ -66,7 +66,7 @@ endif
# For grub-mkimage. # For grub-mkimage.
grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \ grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \
util/resolve.c util/resolve.c
# For grub-setup. # For grub-setup.
util/sparc64/ieee1275/grub-setup.c_DEPENDENCIES = grub_setup_init.h util/sparc64/ieee1275/grub-setup.c_DEPENDENCIES = grub_setup_init.h

View file

@ -354,7 +354,7 @@ if test "$target_cpu"-"$platform" = x86_64-efi; then
]) ])
if test "x$grub_cv_cc_mcmodel" = xno; then if test "x$grub_cv_cc_mcmodel" = xno; then
CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1" CFLAGS="$SAVED_CFLAGS -m64 -DMCMODEL_SMALL=1"
TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1" TARGET_CFLAGS="$TARGET_CFLAGS -DMCMODEL_SMALL=1"
AC_MSG_WARN([-mcmodel=large not supported. You wan't be able to use the memory over 4GiB. Upgrade your gcc]) AC_MSG_WARN([-mcmodel=large not supported. You wan't be able to use the memory over 4GiB. Upgrade your gcc])
else else
TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large" TARGET_CFLAGS="$TARGET_CFLAGS -mcmodel=large"
@ -451,7 +451,7 @@ LIBS="$tmp_LIBS"
# #
# Memory manager debugging. # Memory manager debugging.
AC_ARG_ENABLE([mm-debug], AC_ARG_ENABLE([mm-debug],
AS_HELP_STRING([--enable-mm-debug], AS_HELP_STRING([--enable-mm-debug],
[include memory manager debugging]), [include memory manager debugging]),
[AC_DEFINE([MM_DEBUG], [1], [AC_DEFINE([MM_DEBUG], [1],

View file

@ -357,7 +357,7 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2)
/* Try to detect if the port is in use by writing to it, /* Try to detect if the port is in use by writing to it,
waiting for a while and reading it again. If the value waiting for a while and reading it again. If the value
was preserved, there is a device connected. */ was preserved, there is a device connected. */
grub_ata_regset (dev, GRUB_ATA_REG_SECTORS, 0x5A); grub_ata_regset (dev, GRUB_ATA_REG_SECTORS, 0x5A);
grub_ata_wait (); grub_ata_wait ();
grub_uint8_t sec = grub_ata_regget (dev, GRUB_ATA_REG_SECTORS); grub_uint8_t sec = grub_ata_regget (dev, GRUB_ATA_REG_SECTORS);
grub_dprintf ("ata", "sectors=0x%x\n", sec); grub_dprintf ("ata", "sectors=0x%x\n", sec);
@ -435,7 +435,7 @@ grub_ata_pciinit (int bus, int device, int func,
bar2 = grub_pci_read (addr); bar2 = grub_pci_read (addr);
/* Check if the BARs describe an IO region. */ /* Check if the BARs describe an IO region. */
if ((bar1 & 1) && (bar2 & 1)) if ((bar1 & 1) && (bar2 & 1))
{ {
rega = bar1 & ~3; rega = bar1 & ~3;
regb = bar2 & ~3; regb = bar2 & ~3;
@ -682,7 +682,7 @@ grub_ata_open (const char *name, grub_disk_t disk)
disk->total_sectors = dev->size; disk->total_sectors = dev->size;
disk->id = (unsigned long) dev; disk->id = (unsigned long) dev;
disk->has_partitions = 1; disk->has_partitions = 1;
disk->data = dev; disk->data = dev;
@ -692,7 +692,7 @@ grub_ata_open (const char *name, grub_disk_t disk)
static void static void
grub_ata_close (grub_disk_t disk __attribute__((unused))) grub_ata_close (grub_disk_t disk __attribute__((unused)))
{ {
} }
static grub_err_t static grub_err_t
@ -841,7 +841,7 @@ static struct grub_scsi_dev grub_atapi_dev =
.close = grub_atapi_close, .close = grub_atapi_close,
.read = grub_atapi_read, .read = grub_atapi_read,
.write = grub_atapi_write .write = grub_atapi_write
}; };
@ -854,7 +854,7 @@ GRUB_MOD_INIT(ata)
grub_disk_firmware_fini (); grub_disk_firmware_fini ();
grub_disk_firmware_fini = NULL; grub_disk_firmware_fini = NULL;
} }
/* ATA initialization. */ /* ATA initialization. */
grub_ata_initialize (); grub_ata_initialize ();

View file

@ -51,7 +51,7 @@ duplicate_device_path (const grub_efi_device_path_t *dp)
{ {
grub_efi_device_path_t *p; grub_efi_device_path_t *p;
grub_size_t total_size = 0; grub_size_t total_size = 0;
for (p = (grub_efi_device_path_t *) dp; for (p = (grub_efi_device_path_t *) dp;
; ;
p = GRUB_EFI_NEXT_DEVICE_PATH (p)) p = GRUB_EFI_NEXT_DEVICE_PATH (p))
@ -94,14 +94,14 @@ compare_device_paths (const grub_efi_device_path_t *dp1,
if (! dp1 || ! dp2) if (! dp1 || ! dp2)
/* Return non-zero. */ /* Return non-zero. */
return 1; return 1;
while (1) while (1)
{ {
grub_efi_uint8_t type1, type2; grub_efi_uint8_t type1, type2;
grub_efi_uint8_t subtype1, subtype2; grub_efi_uint8_t subtype1, subtype2;
grub_efi_uint16_t len1, len2; grub_efi_uint16_t len1, len2;
int ret; int ret;
type1 = GRUB_EFI_DEVICE_PATH_TYPE (dp1); type1 = GRUB_EFI_DEVICE_PATH_TYPE (dp1);
type2 = GRUB_EFI_DEVICE_PATH_TYPE (dp2); type2 = GRUB_EFI_DEVICE_PATH_TYPE (dp2);
@ -110,7 +110,7 @@ compare_device_paths (const grub_efi_device_path_t *dp1,
subtype1 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp1); subtype1 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp1);
subtype2 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp2); subtype2 = GRUB_EFI_DEVICE_PATH_SUBTYPE (dp2);
if (subtype1 != subtype2) if (subtype1 != subtype2)
return (int) subtype1 - (int) subtype2; return (int) subtype1 - (int) subtype2;
@ -141,7 +141,7 @@ make_devices (void)
grub_efi_handle_t *handles; grub_efi_handle_t *handles;
grub_efi_handle_t *handle; grub_efi_handle_t *handle;
struct grub_efidisk_data *devices = 0; struct grub_efidisk_data *devices = 0;
/* Find handles which support the disk io interface. */ /* Find handles which support the disk io interface. */
handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &disk_io_guid, handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &disk_io_guid,
0, &num_handles); 0, &num_handles);
@ -156,7 +156,7 @@ make_devices (void)
struct grub_efidisk_data *d; struct grub_efidisk_data *d;
grub_efi_block_io_t *bio; grub_efi_block_io_t *bio;
grub_efi_disk_io_t *dio; grub_efi_disk_io_t *dio;
dp = grub_efi_get_device_path (*handle); dp = grub_efi_get_device_path (*handle);
if (! dp) if (! dp)
continue; continue;
@ -165,7 +165,7 @@ make_devices (void)
if (! ldp) if (! ldp)
/* This is empty. Why? */ /* This is empty. Why? */
continue; continue;
bio = grub_efi_open_protocol (*handle, &block_io_guid, bio = grub_efi_open_protocol (*handle, &block_io_guid,
GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
dio = grub_efi_open_protocol (*handle, &disk_io_guid, dio = grub_efi_open_protocol (*handle, &disk_io_guid,
@ -173,7 +173,7 @@ make_devices (void)
if (! bio || ! dio) if (! bio || ! dio)
/* This should not happen... Why? */ /* This should not happen... Why? */
continue; continue;
d = grub_malloc (sizeof (*d)); d = grub_malloc (sizeof (*d));
if (! d) if (! d)
{ {
@ -192,7 +192,7 @@ make_devices (void)
} }
grub_free (handles); grub_free (handles);
return devices; return devices;
} }
@ -203,7 +203,7 @@ find_parent_device (struct grub_efidisk_data *devices,
{ {
grub_efi_device_path_t *dp, *ldp; grub_efi_device_path_t *dp, *ldp;
struct grub_efidisk_data *parent; struct grub_efidisk_data *parent;
dp = duplicate_device_path (d->device_path); dp = duplicate_device_path (d->device_path);
if (! dp) if (! dp)
return 0; return 0;
@ -219,13 +219,13 @@ find_parent_device (struct grub_efidisk_data *devices,
/* Ignore itself. */ /* Ignore itself. */
if (parent == d) if (parent == d)
continue; continue;
if (compare_device_paths (parent->device_path, dp) == 0) if (compare_device_paths (parent->device_path, dp) == 0)
{ {
/* Found. */ /* Found. */
if (! parent->last_device_path) if (! parent->last_device_path)
parent = 0; parent = 0;
break; break;
} }
} }
@ -240,7 +240,7 @@ iterate_child_devices (struct grub_efidisk_data *devices,
int (*hook) (struct grub_efidisk_data *child)) int (*hook) (struct grub_efidisk_data *child))
{ {
struct grub_efidisk_data *p; struct grub_efidisk_data *p;
for (p = devices; p; p = p->next) for (p = devices; p; p = p->next)
{ {
grub_efi_device_path_t *dp, *ldp; grub_efi_device_path_t *dp, *ldp;
@ -248,13 +248,13 @@ iterate_child_devices (struct grub_efidisk_data *devices,
dp = duplicate_device_path (p->device_path); dp = duplicate_device_path (p->device_path);
if (! dp) if (! dp)
return 0; return 0;
ldp = find_last_device_path (dp); ldp = find_last_device_path (dp);
ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE; ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
ldp->length[0] = sizeof (*ldp); ldp->length[0] = sizeof (*ldp);
ldp->length[1] = 0; ldp->length[1] = 0;
if (compare_device_paths (dp, d->device_path) == 0) if (compare_device_paths (dp, d->device_path) == 0)
if (hook (p)) if (hook (p))
{ {
@ -304,7 +304,7 @@ static void
name_devices (struct grub_efidisk_data *devices) name_devices (struct grub_efidisk_data *devices)
{ {
struct grub_efidisk_data *d; struct grub_efidisk_data *d;
/* First, identify devices by media device paths. */ /* First, identify devices by media device paths. */
for (d = devices; d; d = d->next) for (d = devices; d; d = d->next)
{ {
@ -313,11 +313,11 @@ name_devices (struct grub_efidisk_data *devices)
dp = d->last_device_path; dp = d->last_device_path;
if (! dp) if (! dp)
continue; continue;
if (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE) if (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE)
{ {
int is_hard_drive = 0; int is_hard_drive = 0;
switch (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp)) switch (GRUB_EFI_DEVICE_PATH_SUBTYPE (dp))
{ {
case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE: case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE:
@ -346,7 +346,7 @@ name_devices (struct grub_efidisk_data *devices)
#endif #endif
add_device (&cd_devices, parent); add_device (&cd_devices, parent);
} }
/* Mark the parent as used. */ /* Mark the parent as used. */
parent->last_device_path = 0; parent->last_device_path = 0;
} }
@ -367,7 +367,7 @@ name_devices (struct grub_efidisk_data *devices)
{ {
grub_efi_device_path_t *dp; grub_efi_device_path_t *dp;
grub_efi_block_io_media_t *m; grub_efi_block_io_media_t *m;
dp = d->last_device_path; dp = d->last_device_path;
if (! dp) if (! dp)
continue; continue;
@ -409,7 +409,7 @@ static void
free_devices (struct grub_efidisk_data *devices) free_devices (struct grub_efidisk_data *devices)
{ {
struct grub_efidisk_data *p, *q; struct grub_efidisk_data *p, *q;
for (p = devices; p; p = q) for (p = devices; p; p = q)
{ {
q = p->next; q = p->next;
@ -422,11 +422,11 @@ static void
enumerate_disks (void) enumerate_disks (void)
{ {
struct grub_efidisk_data *devices; struct grub_efidisk_data *devices;
devices = make_devices (); devices = make_devices ();
if (! devices) if (! devices)
return; return;
name_devices (devices); name_devices (devices);
free_devices (devices); free_devices (devices);
} }
@ -437,7 +437,7 @@ grub_efidisk_iterate (int (*hook) (const char *name))
struct grub_efidisk_data *d; struct grub_efidisk_data *d;
char buf[16]; char buf[16];
int count; int count;
for (d = fd_devices, count = 0; d; d = d->next, count++) for (d = fd_devices, count = 0; d; d = d->next, count++)
{ {
grub_sprintf (buf, "fd%d", count); grub_sprintf (buf, "fd%d", count);
@ -445,7 +445,7 @@ grub_efidisk_iterate (int (*hook) (const char *name))
if (hook (buf)) if (hook (buf))
return 1; return 1;
} }
for (d = hd_devices, count = 0; d; d = d->next, count++) for (d = hd_devices, count = 0; d; d = d->next, count++)
{ {
grub_sprintf (buf, "hd%d", count); grub_sprintf (buf, "hd%d", count);
@ -453,7 +453,7 @@ grub_efidisk_iterate (int (*hook) (const char *name))
if (hook (buf)) if (hook (buf))
return 1; return 1;
} }
for (d = cd_devices, count = 0; d; d = d->next, count++) for (d = cd_devices, count = 0; d; d = d->next, count++)
{ {
grub_sprintf (buf, "cd%d", count); grub_sprintf (buf, "cd%d", count);
@ -506,7 +506,7 @@ grub_efidisk_open (const char *name, struct grub_disk *disk)
grub_efi_block_io_media_t *m; grub_efi_block_io_media_t *m;
grub_dprintf ("efidisk", "opening %s\n", name); grub_dprintf ("efidisk", "opening %s\n", name);
num = get_drive_number (name); num = get_drive_number (name);
if (num < 0) if (num < 0)
return grub_errno; return grub_errno;
@ -565,7 +565,7 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
grub_efi_disk_io_t *dio; grub_efi_disk_io_t *dio;
grub_efi_block_io_t *bio; grub_efi_block_io_t *bio;
grub_efi_status_t status; grub_efi_status_t status;
d = disk->data; d = disk->data;
dio = d->disk_io; dio = d->disk_io;
bio = d->block_io; bio = d->block_io;
@ -573,14 +573,14 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
grub_dprintf ("efidisk", grub_dprintf ("efidisk",
"reading 0x%lx sectors at the sector 0x%llx from %s\n", "reading 0x%lx sectors at the sector 0x%llx from %s\n",
(unsigned long) size, (unsigned long long) sector, disk->name); (unsigned long) size, (unsigned long long) sector, disk->name);
status = efi_call_5 (dio->read, dio, bio->media->media_id, status = efi_call_5 (dio->read, dio, bio->media->media_id,
(grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS, (grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS,
(grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS, (grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS,
buf); buf);
if (status != GRUB_EFI_SUCCESS) if (status != GRUB_EFI_SUCCESS)
return grub_error (GRUB_ERR_READ_ERROR, "efidisk read error"); return grub_error (GRUB_ERR_READ_ERROR, "efidisk read error");
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -593,22 +593,22 @@ grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector,
grub_efi_disk_io_t *dio; grub_efi_disk_io_t *dio;
grub_efi_block_io_t *bio; grub_efi_block_io_t *bio;
grub_efi_status_t status; grub_efi_status_t status;
d = disk->data; d = disk->data;
dio = d->disk_io; dio = d->disk_io;
bio = d->block_io; bio = d->block_io;
grub_dprintf ("efidisk", grub_dprintf ("efidisk",
"writing 0x%lx sectors at the sector 0x%llx to %s\n", "writing 0x%lx sectors at the sector 0x%llx to %s\n",
(unsigned long) size, (unsigned long long) sector, disk->name); (unsigned long) size, (unsigned long long) sector, disk->name);
status = efi_call_5 (dio->write, dio, bio->media->media_id, status = efi_call_5 (dio->write, dio, bio->media->media_id,
(grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS, (grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS,
(grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS, (grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS,
(void *) buf); (void *) buf);
if (status != GRUB_EFI_SUCCESS) if (status != GRUB_EFI_SUCCESS)
return grub_error (GRUB_ERR_WRITE_ERROR, "efidisk write error"); return grub_error (GRUB_ERR_WRITE_ERROR, "efidisk write error");
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -646,13 +646,13 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
{ {
struct grub_efidisk_data *d; struct grub_efidisk_data *d;
char type; char type;
if (disk->dev->id != GRUB_DISK_DEVICE_EFIDISK_ID) if (disk->dev->id != GRUB_DISK_DEVICE_EFIDISK_ID)
return 0; return 0;
d = disk->data; d = disk->data;
type = disk->name[0]; type = disk->name[0];
switch (type) switch (type)
{ {
case 'f': case 'f':
@ -679,7 +679,7 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
grub_efi_hard_drive_device_path_t hd; grub_efi_hard_drive_device_path_t hd;
grub_memcpy (&hd, c->last_device_path, sizeof (hd)); grub_memcpy (&hd, c->last_device_path, sizeof (hd));
if ((GRUB_EFI_DEVICE_PATH_TYPE (c->last_device_path) if ((GRUB_EFI_DEVICE_PATH_TYPE (c->last_device_path)
== GRUB_EFI_MEDIA_DEVICE_PATH_TYPE) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE)
&& (GRUB_EFI_DEVICE_PATH_SUBTYPE (c->last_device_path) && (GRUB_EFI_DEVICE_PATH_SUBTYPE (c->last_device_path)
@ -692,14 +692,14 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
handle = c->handle; handle = c->handle;
return 1; return 1;
} }
return 0; return 0;
} }
devices = make_devices (); devices = make_devices ();
iterate_child_devices (devices, d, find_partition); iterate_child_devices (devices, d, find_partition);
free_devices (devices); free_devices (devices);
if (handle != 0) if (handle != 0)
return handle; return handle;
} }
@ -708,7 +708,7 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
default: default:
break; break;
} }
return 0; return 0;
} }
@ -750,7 +750,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID) if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID)
{ {
struct grub_efidisk_data *d; struct grub_efidisk_data *d;
d = disk->data; d = disk->data;
if (compare_device_paths (d->device_path, dup_dp) == 0) if (compare_device_paths (d->device_path, dup_dp) == 0)
{ {
@ -798,7 +798,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
/* Find a partition which matches the hard drive device path. */ /* Find a partition which matches the hard drive device path. */
grub_memcpy (&hd, ldp, sizeof (hd)); grub_memcpy (&hd, ldp, sizeof (hd));
grub_partition_iterate (parent, find_partition); grub_partition_iterate (parent, find_partition);
if (! partition_name) if (! partition_name)
{ {
grub_disk_close (parent); grub_disk_close (parent);
@ -824,11 +824,11 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
/* This should be an entire disk. */ /* This should be an entire disk. */
auto int find_disk (const char *name); auto int find_disk (const char *name);
char *device_name = 0; char *device_name = 0;
int find_disk (const char *name) int find_disk (const char *name)
{ {
grub_disk_t disk; grub_disk_t disk;
disk = grub_disk_open (name); disk = grub_disk_open (name);
if (! disk) if (! disk)
return 1; return 1;
@ -836,7 +836,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
if (disk->id == GRUB_DISK_DEVICE_EFIDISK_ID) if (disk->id == GRUB_DISK_DEVICE_EFIDISK_ID)
{ {
struct grub_efidisk_data *d; struct grub_efidisk_data *d;
d = disk->data; d = disk->data;
if (compare_device_paths (d->device_path, dp) == 0) if (compare_device_paths (d->device_path, dp) == 0)
{ {
@ -848,9 +848,9 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
grub_disk_close (disk); grub_disk_close (disk);
return 0; return 0;
} }
grub_efidisk_iterate (find_disk); grub_efidisk_iterate (find_disk);
return device_name; return device_name;
} }

View file

@ -42,12 +42,12 @@ search_fs_uuid (const char *key, unsigned long *count)
if (dev) if (dev)
{ {
grub_fs_t fs; grub_fs_t fs;
fs = grub_fs_probe (dev); fs = grub_fs_probe (dev);
if (fs && fs->uuid) if (fs && fs->uuid)
{ {
char *uuid; char *uuid;
(fs->uuid) (dev, &uuid); (fs->uuid) (dev, &uuid);
if (grub_errno == GRUB_ERR_NONE && uuid) if (grub_errno == GRUB_ERR_NONE && uuid)
{ {
@ -62,16 +62,16 @@ search_fs_uuid (const char *key, unsigned long *count)
grub_free (uuid); grub_free (uuid);
} }
} }
grub_device_close (dev); grub_device_close (dev);
} }
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
return 0; return 0;
} }
grub_device_iterate (iterate_device); grub_device_iterate (iterate_device);
return ret; return ret;
} }

View file

@ -42,7 +42,7 @@ grub_host_open (const char *name, grub_disk_t disk)
disk->total_sectors = 0; disk->total_sectors = 0;
disk->id = (unsigned long) "host"; disk->id = (unsigned long) "host";
disk->has_partitions = 0; disk->has_partitions = 0;
disk->data = 0; disk->data = 0;

View file

@ -36,14 +36,14 @@ grub_biosdisk_get_drive (const char *name)
if ((name[0] != 'f' && name[0] != 'h') || name[1] != 'd') if ((name[0] != 'f' && name[0] != 'h') || name[1] != 'd')
goto fail; goto fail;
drive = grub_strtoul (name + 2, 0, 10); drive = grub_strtoul (name + 2, 0, 10);
if (grub_errno != GRUB_ERR_NONE) if (grub_errno != GRUB_ERR_NONE)
goto fail; goto fail;
if (name[0] == 'h') if (name[0] == 'h')
drive += 0x80; drive += 0x80;
return (int) drive ; return (int) drive ;
fail: fail:
@ -75,7 +75,7 @@ grub_biosdisk_iterate (int (*hook) (const char *name))
grub_dprintf ("disk", "Read error when probing drive 0x%2x\n", drive); grub_dprintf ("disk", "Read error when probing drive 0x%2x\n", drive);
break; break;
} }
if (grub_biosdisk_call_hook (hook, drive)) if (grub_biosdisk_call_hook (hook, drive))
return 1; return 1;
} }
@ -108,11 +108,11 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
disk->has_partitions = ((drive & 0x80) && (drive != cd_drive)); disk->has_partitions = ((drive & 0x80) && (drive != cd_drive));
disk->id = drive; disk->id = drive;
data = (struct grub_biosdisk_data *) grub_malloc (sizeof (*data)); data = (struct grub_biosdisk_data *) grub_malloc (sizeof (*data));
if (! data) if (! data)
return grub_errno; return grub_errno;
data->drive = drive; data->drive = drive;
data->flags = 0; data->flags = 0;
@ -126,7 +126,7 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
{ {
/* HDD */ /* HDD */
int version; int version;
version = grub_biosdisk_check_int13_extensions (drive); version = grub_biosdisk_check_int13_extensions (drive);
if (version) if (version)
{ {
@ -162,9 +162,9 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
{ {
data->sectors = 63; data->sectors = 63;
data->heads = 255; data->heads = 255;
data->cylinders data->cylinders
= grub_divmod64 (total_sectors = grub_divmod64 (total_sectors
+ data->heads * data->sectors - 1, + data->heads * data->sectors - 1,
data->heads * data->sectors, 0); data->heads * data->sectors, 0);
} }
else else
@ -180,7 +180,7 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
disk->total_sectors = total_sectors; disk->total_sectors = total_sectors;
disk->data = data; disk->data = data;
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -202,11 +202,11 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
unsigned segment) unsigned segment)
{ {
struct grub_biosdisk_data *data = disk->data; struct grub_biosdisk_data *data = disk->data;
if (data->flags & GRUB_BIOSDISK_FLAG_LBA) if (data->flags & GRUB_BIOSDISK_FLAG_LBA)
{ {
struct grub_biosdisk_dap *dap; struct grub_biosdisk_dap *dap;
dap = (struct grub_biosdisk_dap *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR dap = (struct grub_biosdisk_dap *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR
+ (data->sectors + (data->sectors
<< GRUB_DISK_SECTOR_BITS)); << GRUB_DISK_SECTOR_BITS));
@ -246,7 +246,7 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk,
{ {
unsigned coff, hoff, soff; unsigned coff, hoff, soff;
unsigned head; unsigned head;
/* It is impossible to reach over 8064 MiB (a bit less than LBA24) with /* It is impossible to reach over 8064 MiB (a bit less than LBA24) with
the traditional CHS access. */ the traditional CHS access. */
if (sector > if (sector >

View file

@ -251,7 +251,7 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
if (actual != actual) if (actual != actual)
return grub_error (GRUB_ERR_READ_ERROR, "Read error on block: %llu", return grub_error (GRUB_ERR_READ_ERROR, "Read error on block: %llu",
(long long) sector); (long long) sector);
return 0; return 0;
} }

View file

@ -32,7 +32,7 @@ struct grub_loopback
struct grub_loopback *next; struct grub_loopback *next;
}; };
static struct grub_loopback *loopback_list; static struct grub_loopback *loopback_list;
static const struct grub_arg_option options[] = static const struct grub_arg_option options[] =
{ {
@ -54,17 +54,17 @@ delete_loopback (const char *name)
prev = &dev->next, dev = dev->next) prev = &dev->next, dev = dev->next)
if (grub_strcmp (dev->devname, name) == 0) if (grub_strcmp (dev->devname, name) == 0)
break; break;
if (! dev) if (! dev)
return grub_error (GRUB_ERR_BAD_DEVICE, "Device not found"); return grub_error (GRUB_ERR_BAD_DEVICE, "Device not found");
/* Remove the device from the list. */ /* Remove the device from the list. */
*prev = dev->next; *prev = dev->next;
grub_free (dev->devname); grub_free (dev->devname);
grub_free (dev->filename); grub_free (dev->filename);
grub_free (dev); grub_free (dev);
return 0; return 0;
} }
@ -75,56 +75,56 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
struct grub_arg_list *state = state = cmd->state; struct grub_arg_list *state = state = cmd->state;
grub_file_t file; grub_file_t file;
struct grub_loopback *newdev; struct grub_loopback *newdev;
if (argc < 1) if (argc < 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
/* Check if `-d' was used. */ /* Check if `-d' was used. */
if (state[0].set) if (state[0].set)
return delete_loopback (args[0]); return delete_loopback (args[0]);
if (argc < 2) if (argc < 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required"); return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
file = grub_file_open (args[1]); file = grub_file_open (args[1]);
if (! file) if (! file)
return grub_errno; return grub_errno;
/* Close the file, the only reason for opening it is validation. */ /* Close the file, the only reason for opening it is validation. */
grub_file_close (file); grub_file_close (file);
/* First try to replace the old device. */ /* First try to replace the old device. */
for (newdev = loopback_list; newdev; newdev = newdev->next) for (newdev = loopback_list; newdev; newdev = newdev->next)
if (grub_strcmp (newdev->devname, args[0]) == 0) if (grub_strcmp (newdev->devname, args[0]) == 0)
break; break;
if (newdev) if (newdev)
{ {
char *newname = grub_strdup (args[1]); char *newname = grub_strdup (args[1]);
if (! newname) if (! newname)
return grub_errno; return grub_errno;
grub_free (newdev->filename); grub_free (newdev->filename);
newdev->filename = newname; newdev->filename = newname;
/* Set has_partitions when `--partitions' was used. */ /* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set; newdev->has_partitions = state[1].set;
return 0; return 0;
} }
/* Unable to replace it, make a new entry. */ /* Unable to replace it, make a new entry. */
newdev = grub_malloc (sizeof (struct grub_loopback)); newdev = grub_malloc (sizeof (struct grub_loopback));
if (! newdev) if (! newdev)
return grub_errno; return grub_errno;
newdev->devname = grub_strdup (args[0]); newdev->devname = grub_strdup (args[0]);
if (! newdev->devname) if (! newdev->devname)
{ {
grub_free (newdev); grub_free (newdev);
return grub_errno; return grub_errno;
} }
newdev->filename = grub_strdup (args[1]); newdev->filename = grub_strdup (args[1]);
if (! newdev->filename) if (! newdev->filename)
{ {
@ -132,14 +132,14 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
grub_free (newdev); grub_free (newdev);
return grub_errno; return grub_errno;
} }
/* Set has_partitions when `--partitions' was used. */ /* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set; newdev->has_partitions = state[1].set;
/* Add the new entry to the list. */ /* Add the new entry to the list. */
newdev->next = loopback_list; newdev->next = loopback_list;
loopback_list = newdev; loopback_list = newdev;
return 0; return 0;
} }
@ -161,26 +161,26 @@ grub_loopback_open (const char *name, grub_disk_t disk)
{ {
grub_file_t file; grub_file_t file;
struct grub_loopback *dev; struct grub_loopback *dev;
for (dev = loopback_list; dev; dev = dev->next) for (dev = loopback_list; dev; dev = dev->next)
if (grub_strcmp (dev->devname, name) == 0) if (grub_strcmp (dev->devname, name) == 0)
break; break;
if (! dev) if (! dev)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Can't open device"); return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Can't open device");
file = grub_file_open (dev->filename); file = grub_file_open (dev->filename);
if (! file) if (! file)
return grub_errno; return grub_errno;
/* Use the filesize for the disk size, round up to a complete sector. */ /* Use the filesize for the disk size, round up to a complete sector. */
disk->total_sectors = ((file->size + GRUB_DISK_SECTOR_SIZE - 1) disk->total_sectors = ((file->size + GRUB_DISK_SECTOR_SIZE - 1)
/ GRUB_DISK_SECTOR_SIZE); / GRUB_DISK_SECTOR_SIZE);
disk->id = (unsigned long) dev; disk->id = (unsigned long) dev;
disk->has_partitions = dev->has_partitions; disk->has_partitions = dev->has_partitions;
disk->data = file; disk->data = file;
return 0; return 0;
} }
@ -188,7 +188,7 @@ static void
grub_loopback_close (grub_disk_t disk) grub_loopback_close (grub_disk_t disk)
{ {
grub_file_t file = (grub_file_t) disk->data; grub_file_t file = (grub_file_t) disk->data;
grub_file_close (file); grub_file_close (file);
} }
@ -198,13 +198,13 @@ grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector,
{ {
grub_file_t file = (grub_file_t) disk->data; grub_file_t file = (grub_file_t) disk->data;
grub_off_t pos; grub_off_t pos;
grub_file_seek (file, sector << GRUB_DISK_SECTOR_BITS); grub_file_seek (file, sector << GRUB_DISK_SECTOR_BITS);
grub_file_read (file, buf, size << GRUB_DISK_SECTOR_BITS); grub_file_read (file, buf, size << GRUB_DISK_SECTOR_BITS);
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
/* In case there is more data read than there is available, in case /* In case there is more data read than there is available, in case
of files that are not a multiple of GRUB_DISK_SECTOR_SIZE, fill of files that are not a multiple of GRUB_DISK_SECTOR_SIZE, fill
the rest with zeros. */ the rest with zeros. */
@ -214,7 +214,7 @@ grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t amount = pos - file->size; grub_size_t amount = pos - file->size;
grub_memset (buf + (size << GRUB_DISK_SECTOR_BITS) - amount, 0, amount); grub_memset (buf + (size << GRUB_DISK_SECTOR_BITS) - amount, 0, amount);
} }
return 0; return 0;
} }

View file

@ -101,7 +101,7 @@ grub_lvm_open (const char *name, grub_disk_t disk)
disk->id = lv->number; disk->id = lv->number;
disk->data = lv; disk->data = lv;
disk->total_sectors = lv->size; disk->total_sectors = lv->size;
return 0; return 0;
} }
@ -174,7 +174,7 @@ grub_lvm_read (grub_disk_t disk, grub_disk_addr_t sector,
stripe += stripenr; stripe += stripenr;
pv = stripe->pv; pv = stripe->pv;
seg_offset = ((grub_uint64_t) stripe->start seg_offset = ((grub_uint64_t) stripe->start
* (grub_uint64_t) vg->extent_size) + pv->start; * (grub_uint64_t) vg->extent_size) + pv->start;
@ -189,7 +189,7 @@ grub_lvm_read (grub_disk_t disk, grub_disk_addr_t sector,
else else
err = grub_error (GRUB_ERR_UNKNOWN_DEVICE, err = grub_error (GRUB_ERR_UNKNOWN_DEVICE,
"Physical volume %s not found", pv->name); "Physical volume %s not found", pv->name);
return err; return err;
} }
@ -220,7 +220,7 @@ grub_lvm_scan_device (const char *name)
unsigned int i, j, vgname_len; unsigned int i, j, vgname_len;
struct grub_lvm_vg *vg; struct grub_lvm_vg *vg;
struct grub_lvm_pv *pv; struct grub_lvm_pv *pv;
disk = grub_disk_open (name); disk = grub_disk_open (name);
if (!disk) if (!disk)
return 0; return 0;
@ -231,7 +231,7 @@ grub_lvm_scan_device (const char *name)
err = grub_disk_read (disk, i, 0, sizeof(buf), buf); err = grub_disk_read (disk, i, 0, sizeof(buf), buf);
if (err) if (err)
goto fail; goto fail;
if ((! grub_strncmp ((char *)lh->id, GRUB_LVM_LABEL_ID, if ((! grub_strncmp ((char *)lh->id, GRUB_LVM_LABEL_ID,
sizeof (lh->id))) sizeof (lh->id)))
&& (! grub_strncmp ((char *)lh->type, GRUB_LVM_LVM2_LABEL, && (! grub_strncmp ((char *)lh->type, GRUB_LVM_LVM2_LABEL,
@ -242,7 +242,7 @@ grub_lvm_scan_device (const char *name)
/* Return if we didn't find a label. */ /* Return if we didn't find a label. */
if (i == GRUB_LVM_LABEL_SCAN_SECTORS) if (i == GRUB_LVM_LABEL_SCAN_SECTORS)
goto fail; goto fail;
pvh = (struct grub_lvm_pv_header *) (buf + grub_le_to_cpu32(lh->offset_xl)); pvh = (struct grub_lvm_pv_header *) (buf + grub_le_to_cpu32(lh->offset_xl));
for (i = 0, j = 0; i < GRUB_LVM_ID_LEN; i++) for (i = 0, j = 0; i < GRUB_LVM_ID_LEN; i++)
@ -264,7 +264,7 @@ grub_lvm_scan_device (const char *name)
{ {
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"We don't support multiple LVM data areas"); "We don't support multiple LVM data areas");
goto fail; goto fail;
} }
@ -272,12 +272,12 @@ grub_lvm_scan_device (const char *name)
mda_offset = grub_le_to_cpu64 (dlocn->offset); mda_offset = grub_le_to_cpu64 (dlocn->offset);
mda_size = grub_le_to_cpu64 (dlocn->size); mda_size = grub_le_to_cpu64 (dlocn->size);
dlocn++; dlocn++;
if (dlocn->offset) if (dlocn->offset)
{ {
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"We don't support multiple LVM metadata areas"); "We don't support multiple LVM metadata areas");
goto fail; goto fail;
} }
@ -361,39 +361,39 @@ grub_lvm_scan_device (const char *name)
if (p) if (p)
{ {
p += sizeof ("physical_volumes {") - 1; p += sizeof ("physical_volumes {") - 1;
/* Add all the pvs to the volume group. */ /* Add all the pvs to the volume group. */
while (1) while (1)
{ {
int s; int s;
while (grub_isspace (*p)) while (grub_isspace (*p))
p++; p++;
if (*p == '}') if (*p == '}')
break; break;
pv = grub_malloc (sizeof (*pv)); pv = grub_malloc (sizeof (*pv));
q = p; q = p;
while (*q != ' ') while (*q != ' ')
q++; q++;
s = q - p; s = q - p;
pv->name = grub_malloc (s + 1); pv->name = grub_malloc (s + 1);
grub_memcpy (pv->name, p, s); grub_memcpy (pv->name, p, s);
pv->name[s] = '\0'; pv->name[s] = '\0';
p = grub_strstr (p, "id = \""); p = grub_strstr (p, "id = \"");
if (p == NULL) if (p == NULL)
goto pvs_fail; goto pvs_fail;
p += sizeof("id = \"") - 1; p += sizeof("id = \"") - 1;
grub_memcpy (pv->id, p, GRUB_LVM_ID_STRLEN); grub_memcpy (pv->id, p, GRUB_LVM_ID_STRLEN);
pv->id[GRUB_LVM_ID_STRLEN] = '\0'; pv->id[GRUB_LVM_ID_STRLEN] = '\0';
pv->start = grub_lvm_getvalue (&p, "pe_start = "); pv->start = grub_lvm_getvalue (&p, "pe_start = ");
if (p == NULL) if (p == NULL)
goto pvs_fail; goto pvs_fail;
p = grub_strchr (p, '}'); p = grub_strchr (p, '}');
if (p == NULL) if (p == NULL)
goto pvs_fail; goto pvs_fail;
@ -402,7 +402,7 @@ grub_lvm_scan_device (const char *name)
pv->disk = NULL; pv->disk = NULL;
pv->next = vg->pvs; pv->next = vg->pvs;
vg->pvs = pv; vg->pvs = pv;
continue; continue;
pvs_fail: pvs_fail:
grub_free (pv->name); grub_free (pv->name);
@ -415,49 +415,49 @@ grub_lvm_scan_device (const char *name)
if (p) if (p)
{ {
p += 18; p += 18;
/* And add all the lvs to the volume group. */ /* And add all the lvs to the volume group. */
while (1) while (1)
{ {
int s; int s;
struct grub_lvm_lv *lv; struct grub_lvm_lv *lv;
struct grub_lvm_segment *seg; struct grub_lvm_segment *seg;
while (grub_isspace (*p)) while (grub_isspace (*p))
p++; p++;
if (*p == '}') if (*p == '}')
break; break;
lv = grub_malloc (sizeof (*lv)); lv = grub_malloc (sizeof (*lv));
q = p; q = p;
while (*q != ' ') while (*q != ' ')
q++; q++;
s = q - p; s = q - p;
lv->name = grub_malloc (vgname_len + 1 + s + 1); lv->name = grub_malloc (vgname_len + 1 + s + 1);
grub_memcpy (lv->name, vgname, vgname_len); grub_memcpy (lv->name, vgname, vgname_len);
lv->name[vgname_len] = '-'; lv->name[vgname_len] = '-';
grub_memcpy (lv->name + vgname_len + 1, p, s); grub_memcpy (lv->name + vgname_len + 1, p, s);
lv->name[vgname_len + 1 + s] = '\0'; lv->name[vgname_len + 1 + s] = '\0';
lv->size = 0; lv->size = 0;
lv->segment_count = grub_lvm_getvalue (&p, "segment_count = "); lv->segment_count = grub_lvm_getvalue (&p, "segment_count = ");
if (p == NULL) if (p == NULL)
goto lvs_fail; goto lvs_fail;
lv->segments = grub_malloc (sizeof (*seg) * lv->segment_count); lv->segments = grub_malloc (sizeof (*seg) * lv->segment_count);
seg = lv->segments; seg = lv->segments;
for (i = 0; i < lv->segment_count; i++) for (i = 0; i < lv->segment_count; i++)
{ {
struct grub_lvm_stripe *stripe; struct grub_lvm_stripe *stripe;
p = grub_strstr (p, "segment"); p = grub_strstr (p, "segment");
if (p == NULL) if (p == NULL)
goto lvs_segment_fail; goto lvs_segment_fail;
seg->start_extent = grub_lvm_getvalue (&p, "start_extent = "); seg->start_extent = grub_lvm_getvalue (&p, "start_extent = ");
if (p == NULL) if (p == NULL)
goto lvs_segment_fail; goto lvs_segment_fail;
@ -467,25 +467,25 @@ grub_lvm_scan_device (const char *name)
seg->stripe_count = grub_lvm_getvalue (&p, "stripe_count = "); seg->stripe_count = grub_lvm_getvalue (&p, "stripe_count = ");
if (p == NULL) if (p == NULL)
goto lvs_segment_fail; goto lvs_segment_fail;
lv->size += seg->extent_count * vg->extent_size; lv->size += seg->extent_count * vg->extent_size;
if (seg->stripe_count != 1) if (seg->stripe_count != 1)
seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = ");
seg->stripes = grub_malloc (sizeof (*stripe) seg->stripes = grub_malloc (sizeof (*stripe)
* seg->stripe_count); * seg->stripe_count);
stripe = seg->stripes; stripe = seg->stripes;
p = grub_strstr (p, "stripes = ["); p = grub_strstr (p, "stripes = [");
if (p == NULL) if (p == NULL)
goto lvs_segment_fail2; goto lvs_segment_fail2;
p += sizeof("stripes = [") - 1; p += sizeof("stripes = [") - 1;
for (j = 0; j < seg->stripe_count; j++) for (j = 0; j < seg->stripe_count; j++)
{ {
char *pvname; char *pvname;
p = grub_strchr (p, '"'); p = grub_strchr (p, '"');
if (p == NULL) if (p == NULL)
continue; continue;
@ -494,14 +494,14 @@ grub_lvm_scan_device (const char *name)
q++; q++;
s = q - p; s = q - p;
pvname = grub_malloc (s + 1); pvname = grub_malloc (s + 1);
if (pvname == NULL) if (pvname == NULL)
goto lvs_segment_fail2; goto lvs_segment_fail2;
grub_memcpy (pvname, p, s); grub_memcpy (pvname, p, s);
pvname[s] = '\0'; pvname[s] = '\0';
if (vg->pvs) if (vg->pvs)
for (pv = vg->pvs; pv; pv = pv->next) for (pv = vg->pvs; pv; pv = pv->next)
{ {
@ -511,16 +511,16 @@ grub_lvm_scan_device (const char *name)
break; break;
} }
} }
grub_free(pvname); grub_free(pvname);
stripe->start = grub_lvm_getvalue (&p, ","); stripe->start = grub_lvm_getvalue (&p, ",");
if (p == NULL) if (p == NULL)
continue; continue;
stripe++; stripe++;
} }
seg++; seg++;
continue; continue;
@ -535,7 +535,7 @@ grub_lvm_scan_device (const char *name)
if (p == NULL) if (p == NULL)
goto lvs_fail; goto lvs_fail;
p += 3; p += 3;
lv->number = lv_count++; lv->number = lv_count++;
lv->vg = vg; lv->vg = vg;
lv->next = vg->lvs; lv->next = vg->lvs;

View file

@ -104,7 +104,7 @@ GRUB_MOD_INIT(memdisk)
return 0; return 0;
} }
grub_module_iterate (hook); grub_module_iterate (hook);
} }

View file

@ -77,7 +77,7 @@ static int
grub_raid_iterate (int (*hook) (const char *name)) grub_raid_iterate (int (*hook) (const char *name))
{ {
struct grub_raid_array *array; struct grub_raid_array *array;
for (array = array_list; array != NULL; array = array->next) for (array = array_list; array != NULL; array = array->next)
{ {
if (grub_is_array_readable (array)) if (grub_is_array_readable (array))
@ -95,7 +95,7 @@ grub_raid_memberlist (grub_disk_t disk)
struct grub_raid_array *array = disk->data; struct grub_raid_array *array = disk->data;
grub_disk_memberlist_t list = NULL, tmp; grub_disk_memberlist_t list = NULL, tmp;
unsigned int i; unsigned int i;
for (i = 0; i < array->total_devs; i++) for (i = 0; i < array->total_devs; i++)
if (array->device[i]) if (array->device[i])
{ {
@ -104,7 +104,7 @@ grub_raid_memberlist (grub_disk_t disk)
tmp->next = list; tmp->next = list;
list = tmp; list = tmp;
} }
return list; return list;
} }
#endif #endif
@ -114,7 +114,7 @@ grub_raid_open (const char *name, grub_disk_t disk)
{ {
struct grub_raid_array *array; struct grub_raid_array *array;
unsigned n; unsigned n;
for (array = array_list; array != NULL; array = array->next) for (array = array_list; array != NULL; array = array->next)
{ {
if (!grub_strcmp (array->name, name)) if (!grub_strcmp (array->name, name))
@ -161,7 +161,7 @@ grub_raid_open (const char *name, grub_disk_t disk)
grub_dprintf ("raid", "%s: level=%d, total_sectors=%lld\n", name, grub_dprintf ("raid", "%s: level=%d, total_sectors=%lld\n", name,
array->level, (unsigned long long) disk->total_sectors); array->level, (unsigned long long) disk->total_sectors);
return 0; return 0;
} }
@ -348,7 +348,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
p = array->total_devs - n; p = array->total_devs - n;
read_sector *= array->chunk_size; read_sector *= array->chunk_size;
while (1) while (1)
{ {
grub_size_t read_size; grub_size_t read_size;
@ -405,7 +405,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
if (err) if (err)
break; break;
} }
buf += read_size << GRUB_DISK_SECTOR_BITS; buf += read_size << GRUB_DISK_SECTOR_BITS;
size -= read_size; size -= read_size;
if (! size) if (! size)
@ -460,7 +460,7 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
} }
break; break;
} }
return err; return err;
} }
@ -478,7 +478,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
const char *scanner_name) const char *scanner_name)
{ {
struct grub_raid_array *array = 0, *p; struct grub_raid_array *array = 0, *p;
/* See whether the device is part of an array we have already seen a /* See whether the device is part of an array we have already seen a
device from. */ device from. */
for (p = array_list; p != NULL; p = p->next) for (p = array_list; p != NULL; p = p->next)
@ -524,7 +524,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
*array = *new_array; *array = *new_array;
array->nr_devs = 0; array->nr_devs = 0;
grub_memset (&array->device, 0, sizeof (array->device)); grub_memset (&array->device, 0, sizeof (array->device));
/* Check whether we don't have multiple arrays with the same number. */ /* Check whether we don't have multiple arrays with the same number. */
for (p = array_list; p != NULL; p = p->next) for (p = array_list; p != NULL; p = p->next)
{ {
@ -635,7 +635,7 @@ grub_raid_scan_device (int head_only)
return 0; return 0;
} }
grub_device_iterate (&hook); grub_device_iterate (&hook);
} }
@ -649,7 +649,7 @@ free_array (void)
{ {
struct grub_raid_array *p; struct grub_raid_array *p;
int i; int i;
p = array; p = array;
array = array->next; array = array->next;
@ -664,7 +664,7 @@ free_array (void)
array_list = 0; array_list = 0;
} }
void void
grub_raid_register (grub_raid_t raid) grub_raid_register (grub_raid_t raid)
{ {

View file

@ -301,7 +301,7 @@ grub_scsi_open (const char *name, grub_disk_t disk)
<< GRUB_DISK_SECTOR_BITS); << GRUB_DISK_SECTOR_BITS);
grub_dprintf ("scsi", "capacity=%llu, blksize=%d\n", grub_dprintf ("scsi", "capacity=%llu, blksize=%d\n",
(unsigned long long) disk->total_sectors, (unsigned long long) disk->total_sectors,
scsi->blocksize); scsi->blocksize);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;

View file

@ -267,7 +267,7 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
"can't read from USB Mass Storage device"); "can't read from USB Mass Storage device");
} }
} }
else else
{ {
err = grub_usb_bulk_write (dev->dev, dev->in->endp_addr & 15, size, buf); err = grub_usb_bulk_write (dev->dev, dev->in->endp_addr & 15, size, buf);
grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL); grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL);
@ -379,7 +379,7 @@ static struct grub_scsi_dev grub_usbms_dev =
.close = grub_usbms_close, .close = grub_usbms_close,
.read = grub_usbms_read, .read = grub_usbms_read,
.write = grub_usbms_write .write = grub_usbms_write
}; };
GRUB_MOD_INIT(usbms) GRUB_MOD_INIT(usbms)
{ {

View file

@ -664,7 +664,7 @@ from GRUB and you don't have to make a floppy or hard disk image file,
which can cause compatibility problems. which can cause compatibility problems.
For booting from a CD-ROM, GRUB uses a special Stage 2 called For booting from a CD-ROM, GRUB uses a special Stage 2 called
@file{stage2_eltorito}. The only GRUB files you need to have in your @file{stage2_eltorito}. The only GRUB files you need to have in your
bootable CD-ROM are this @file{stage2_eltorito} and optionally a config file bootable CD-ROM are this @file{stage2_eltorito} and optionally a config file
@file{menu.lst}. You don't need to use @file{stage1} or @file{stage2}, @file{menu.lst}. You don't need to use @file{stage1} or @file{stage2},
because El Torito is quite different from the standard boot process. because El Torito is quite different from the standard boot process.
@ -702,13 +702,13 @@ $ @kbd{mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot \
This produces a file named @file{grub.iso}, which then can be burned This produces a file named @file{grub.iso}, which then can be burned
into a CD (or a DVD). @kbd{mkisofs} has already set up the disc to boot into a CD (or a DVD). @kbd{mkisofs} has already set up the disc to boot
from the @kbd{boot/grub/stage2_eltorito} file, so there is no need to from the @kbd{boot/grub/stage2_eltorito} file, so there is no need to
setup GRUB on the disc. (Note that the @kbd{-boot-load-size 4} bit is setup GRUB on the disc. (Note that the @kbd{-boot-load-size 4} bit is
required for compatibility with the BIOS on many older machines.) required for compatibility with the BIOS on many older machines.)
You can use the device @samp{(cd)} to access a CD-ROM in your You can use the device @samp{(cd)} to access a CD-ROM in your
config file. This is not required; GRUB automatically sets the root device config file. This is not required; GRUB automatically sets the root device
to @samp{(cd)} when booted from a CD-ROM. It is only necessary to refer to to @samp{(cd)} when booted from a CD-ROM. It is only necessary to refer to
@samp{(cd)} if you want to access other drives as well. @samp{(cd)} if you want to access other drives as well.
@ -2414,7 +2414,7 @@ is to be found; if specified it takes precedence over @var{unit}.
be in the range 5-8 and stop bits must be 1 or 2. Default is 8 data be in the range 5-8 and stop bits must be 1 or 2. Default is 8 data
bits and one stop bit. @var{parity} is one of @samp{no}, @samp{odd}, bits and one stop bit. @var{parity} is one of @samp{no}, @samp{odd},
@samp{even} and defaults to @samp{no}. The option @option{--device} @samp{even} and defaults to @samp{no}. The option @option{--device}
can only be used in the grub shell and is used to specify the can only be used in the grub shell and is used to specify the
tty device to be used in the host operating system (@pxref{Invoking the tty device to be used in the host operating system (@pxref{Invoking the
grub shell}). grub shell}).
@ -2431,8 +2431,8 @@ support. See also @ref{Serial terminal}.
@deffn Command setkey [to_key from_key] @deffn Command setkey [to_key from_key]
Change the keyboard map. The key @var{from_key} is mapped to the key Change the keyboard map. The key @var{from_key} is mapped to the key
@var{to_key}. If no argument is specified, reset key mappings. Note that @var{to_key}. If no argument is specified, reset key mappings. Note that
this command @emph{does not} exchange the keys. If you want to exchange this command @emph{does not} exchange the keys. If you want to exchange
the keys, run this command again with the arguments exchanged, like this: the keys, run this command again with the arguments exchanged, like this:
@example @example

View file

@ -354,7 +354,7 @@
% We don't want .vr (or whatever) entries like this: % We don't want .vr (or whatever) entries like this:
% \entry{{\tt \indexbackslash }acronym}{32}{\code {\acronym}} % \entry{{\tt \indexbackslash }acronym}{32}{\code {\acronym}}
% "\acronym" won't work when it's read back in; % "\acronym" won't work when it's read back in;
% it needs to be % it needs to be
% {\code {{\tt \backslashcurfont }acronym} % {\code {{\tt \backslashcurfont }acronym}
\shipout\vbox{% \shipout\vbox{%
% Do this early so pdf references go to the beginning of the page. % Do this early so pdf references go to the beginning of the page.
@ -705,7 +705,7 @@
\def\?{?\spacefactor=\endofsentencespacefactor\space} \def\?{?\spacefactor=\endofsentencespacefactor\space}
% @frenchspacing on|off says whether to put extra space after punctuation. % @frenchspacing on|off says whether to put extra space after punctuation.
% %
\def\onword{on} \def\onword{on}
\def\offword{off} \def\offword{off}
% %
@ -1260,7 +1260,7 @@ where each line of input produces a line of output.}
% that's what we do). % that's what we do).
% double active backslashes. % double active backslashes.
% %
{\catcode`\@=0 \catcode`\\=\active {\catcode`\@=0 \catcode`\\=\active
@gdef@activebackslashdouble{% @gdef@activebackslashdouble{%
@catcode`@\=@active @catcode`@\=@active
@ -1272,11 +1272,11 @@ where each line of input produces a line of output.}
% us) handles it with this amazing macro to replace tokens, with minor % us) handles it with this amazing macro to replace tokens, with minor
% changes for Texinfo. It is included here under the GPL by permission % changes for Texinfo. It is included here under the GPL by permission
% from the author, Heiko Oberdiek. % from the author, Heiko Oberdiek.
% %
% #1 is the tokens to replace. % #1 is the tokens to replace.
% #2 is the replacement. % #2 is the replacement.
% #3 is the control sequence with the string. % #3 is the control sequence with the string.
% %
\def\HyPsdSubst#1#2#3{% \def\HyPsdSubst#1#2#3{%
\def\HyPsdReplace##1#1##2\END{% \def\HyPsdReplace##1#1##2\END{%
##1% ##1%
@ -1542,7 +1542,7 @@ output) for that.)}
% tried to figure out what each command should do in the context % tried to figure out what each command should do in the context
% of @url. for now, just make @/ a no-op, that's the only one % of @url. for now, just make @/ a no-op, that's the only one
% people have actually reported a problem with. % people have actually reported a problem with.
% %
\normalturnoffactive \normalturnoffactive
\def\@{@}% \def\@{@}%
\let\/=\empty \let\/=\empty
@ -1939,7 +1939,7 @@ end
% Definitions for a main text size of 11pt. This is the default in % Definitions for a main text size of 11pt. This is the default in
% Texinfo. % Texinfo.
% %
\def\definetextfontsizexi{% \def\definetextfontsizexi{%
% Text fonts (11.2pt, magstep1). % Text fonts (11.2pt, magstep1).
\def\textnominalsize{11pt} \def\textnominalsize{11pt}
@ -2072,7 +2072,7 @@ end
% section, chapter, etc., sizes following suit. This is for the GNU % section, chapter, etc., sizes following suit. This is for the GNU
% Press printing of the Emacs 22 manual. Maybe other manuals in the % Press printing of the Emacs 22 manual. Maybe other manuals in the
% future. Used with @smallbook, which sets the leading to 12pt. % future. Used with @smallbook, which sets the leading to 12pt.
% %
\def\definetextfontsizex{% \def\definetextfontsizex{%
% Text fonts (10pt). % Text fonts (10pt).
\def\textnominalsize{10pt} \def\textnominalsize{10pt}
@ -2163,7 +2163,7 @@ end
\setfont\secsf\sfbshape{12}{1000}{OT1} \setfont\secsf\sfbshape{12}{1000}{OT1}
\let\secbf\secrm \let\secbf\secrm
\setfont\secsc\scbshape{10}{\magstep1}{OT1} \setfont\secsc\scbshape{10}{\magstep1}{OT1}
\font\seci=cmmi12 \font\seci=cmmi12
\font\secsy=cmsy10 scaled \magstep1 \font\secsy=cmsy10 scaled \magstep1
\def\sececsize{1200} \def\sececsize{1200}
@ -2207,7 +2207,7 @@ end
% We provide the user-level command % We provide the user-level command
% @fonttextsize 10 % @fonttextsize 10
% (or 11) to redefine the text font size. pt is assumed. % (or 11) to redefine the text font size. pt is assumed.
% %
\def\xword{10} \def\xword{10}
\def\xiword{11} \def\xiword{11}
% %
@ -2217,7 +2217,7 @@ end
% %
% Set \globaldefs so that documents can use this inside @tex, since % Set \globaldefs so that documents can use this inside @tex, since
% makeinfo 4.8 does not support it, but we need it nonetheless. % makeinfo 4.8 does not support it, but we need it nonetheless.
% %
\begingroup \globaldefs=1 \begingroup \globaldefs=1
\ifx\textsizearg\xword \definetextfontsizex \ifx\textsizearg\xword \definetextfontsizex
\else \ifx\textsizearg\xiword \definetextfontsizexi \else \ifx\textsizearg\xiword \definetextfontsizexi
@ -2503,7 +2503,7 @@ end
% each of the four underscores in __typeof__. This is undesirable in % each of the four underscores in __typeof__. This is undesirable in
% some manuals, especially if they don't have long identifiers in % some manuals, especially if they don't have long identifiers in
% general. @allowcodebreaks provides a way to control this. % general. @allowcodebreaks provides a way to control this.
% %
\newif\ifallowcodebreaks \allowcodebreakstrue \newif\ifallowcodebreaks \allowcodebreakstrue
\def\keywordtrue{true} \def\keywordtrue{true}
@ -2634,7 +2634,7 @@ end
% @acronym for "FBI", "NATO", and the like. % @acronym for "FBI", "NATO", and the like.
% We print this one point size smaller, since it's intended for % We print this one point size smaller, since it's intended for
% all-uppercase. % all-uppercase.
% %
\def\acronym#1{\doacronym #1,,\finish} \def\acronym#1{\doacronym #1,,\finish}
\def\doacronym#1,#2,#3\finish{% \def\doacronym#1,#2,#3\finish{%
{\selectfonts\lsize #1}% {\selectfonts\lsize #1}%
@ -2646,7 +2646,7 @@ end
% @abbr for "Comput. J." and the like. % @abbr for "Comput. J." and the like.
% No font change, but don't do end-of-sentence spacing. % No font change, but don't do end-of-sentence spacing.
% %
\def\abbr#1{\doabbr #1,,\finish} \def\abbr#1{\doabbr #1,,\finish}
\def\doabbr#1,#2,#3\finish{% \def\doabbr#1,#2,#3\finish{%
{\plainfrenchspacing #1}% {\plainfrenchspacing #1}%
@ -2665,43 +2665,43 @@ end
% Theiling, which support regular, slanted, bold and bold slanted (and % Theiling, which support regular, slanted, bold and bold slanted (and
% "outlined" (blackboard board, sort of) versions, which we don't need). % "outlined" (blackboard board, sort of) versions, which we don't need).
% It is available from http://www.ctan.org/tex-archive/fonts/eurosym. % It is available from http://www.ctan.org/tex-archive/fonts/eurosym.
% %
% Although only regular is the truly official Euro symbol, we ignore % Although only regular is the truly official Euro symbol, we ignore
% that. The Euro is designed to be slightly taller than the regular % that. The Euro is designed to be slightly taller than the regular
% font height. % font height.
% %
% feymr - regular % feymr - regular
% feymo - slanted % feymo - slanted
% feybr - bold % feybr - bold
% feybo - bold slanted % feybo - bold slanted
% %
% There is no good (free) typewriter version, to my knowledge. % There is no good (free) typewriter version, to my knowledge.
% A feymr10 euro is ~7.3pt wide, while a normal cmtt10 char is ~5.25pt wide. % A feymr10 euro is ~7.3pt wide, while a normal cmtt10 char is ~5.25pt wide.
% Hmm. % Hmm.
% %
% Also doesn't work in math. Do we need to do math with euro symbols? % Also doesn't work in math. Do we need to do math with euro symbols?
% Hope not. % Hope not.
% %
% %
\def\euro{{\eurofont e}} \def\euro{{\eurofont e}}
\def\eurofont{% \def\eurofont{%
% We set the font at each command, rather than predefining it in % We set the font at each command, rather than predefining it in
% \textfonts and the other font-switching commands, so that % \textfonts and the other font-switching commands, so that
% installations which never need the symbol don't have to have the % installations which never need the symbol don't have to have the
% font installed. % font installed.
% %
% There is only one designed size (nominal 10pt), so we always scale % There is only one designed size (nominal 10pt), so we always scale
% that to the current nominal size. % that to the current nominal size.
% %
% By the way, simply using "at 1em" works for cmr10 and the like, but % By the way, simply using "at 1em" works for cmr10 and the like, but
% does not work for cmbx10 and other extended/shrunken fonts. % does not work for cmbx10 and other extended/shrunken fonts.
% %
\def\eurosize{\csname\curfontsize nominalsize\endcsname}% \def\eurosize{\csname\curfontsize nominalsize\endcsname}%
% %
\ifx\curfontstyle\bfstylename \ifx\curfontstyle\bfstylename
% bold: % bold:
\font\thiseurofont = \ifusingit{feybo10}{feybr10} at \eurosize \font\thiseurofont = \ifusingit{feybo10}{feybr10} at \eurosize
\else \else
% regular: % regular:
\font\thiseurofont = \ifusingit{feymo10}{feymr10} at \eurosize \font\thiseurofont = \ifusingit{feymo10}{feymr10} at \eurosize
\fi \fi
@ -2754,7 +2754,7 @@ end
% Laurent Siebenmann reports \Orb undefined with: % Laurent Siebenmann reports \Orb undefined with:
% Textures 1.7.7 (preloaded format=plain 93.10.14) (68K) 16 APR 2004 02:38 % Textures 1.7.7 (preloaded format=plain 93.10.14) (68K) 16 APR 2004 02:38
% so we'll define it if necessary. % so we'll define it if necessary.
% %
\ifx\Orb\undefined \ifx\Orb\undefined
\def\Orb{\mathhexbox20D} \def\Orb{\mathhexbox20D}
\fi \fi
@ -3102,7 +3102,7 @@ end
% cause the example and the item to crash together. So we use this % cause the example and the item to crash together. So we use this
% bizarre value of 10001 as a signal to \aboveenvbreak to insert % bizarre value of 10001 as a signal to \aboveenvbreak to insert
% \parskip glue after all. Section titles are handled this way also. % \parskip glue after all. Section titles are handled this way also.
% %
\penalty 10001 \penalty 10001
\endgroup \endgroup
\itemxneedsnegativevskipfalse \itemxneedsnegativevskipfalse
@ -3898,7 +3898,7 @@ end
% processing continues to some further point. On the other hand, it % processing continues to some further point. On the other hand, it
% seems \endinput does not hurt in the printed index arg, since that % seems \endinput does not hurt in the printed index arg, since that
% is still getting written without apparent harm. % is still getting written without apparent harm.
% %
% Sample source (mac-idx3.tex, reported by Graham Percival to % Sample source (mac-idx3.tex, reported by Graham Percival to
% help-texinfo, 22may06): % help-texinfo, 22may06):
% @macro funindex {WORD} % @macro funindex {WORD}
@ -3906,12 +3906,12 @@ end
% @end macro % @end macro
% ... % ...
% @funindex commtest % @funindex commtest
% %
% The above is not enough to reproduce the bug, but it gives the flavor. % The above is not enough to reproduce the bug, but it gives the flavor.
% %
% Sample whatsit resulting: % Sample whatsit resulting:
% .@write3{\entry{xyz}{@folio }{@code {xyz@endinput }}} % .@write3{\entry{xyz}{@folio }{@code {xyz@endinput }}}
% %
% So: % So:
\let\endinput = \empty \let\endinput = \empty
% %
@ -4167,11 +4167,11 @@ end
% makeinfo does not expand macros in the argument to @deffn, which ends up % makeinfo does not expand macros in the argument to @deffn, which ends up
% writing an index entry, and texindex isn't prepared for an index sort entry % writing an index entry, and texindex isn't prepared for an index sort entry
% that starts with \. % that starts with \.
% %
% Since macro invocations are followed by braces, we can just redefine them % Since macro invocations are followed by braces, we can just redefine them
% to take a single TeX argument. The case of a macro invocation that % to take a single TeX argument. The case of a macro invocation that
% goes to end-of-line is not handled. % goes to end-of-line is not handled.
% %
\macrolist \macrolist
} }
@ -4299,7 +4299,7 @@ end
% to re-insert the same penalty (values >10000 are used for various % to re-insert the same penalty (values >10000 are used for various
% signals); since we just inserted a non-discardable item, any % signals); since we just inserted a non-discardable item, any
% following glue (such as a \parskip) would be a breakpoint. For example: % following glue (such as a \parskip) would be a breakpoint. For example:
% %
% @deffn deffn-whatever % @deffn deffn-whatever
% @vindex index-whatever % @vindex index-whatever
% Description. % Description.
@ -5365,11 +5365,11 @@ end
% glue accumulate. (Not a breakpoint because it's preceded by a % glue accumulate. (Not a breakpoint because it's preceded by a
% discardable item.) % discardable item.)
\vskip-\parskip \vskip-\parskip
% %
% This is purely so the last item on the list is a known \penalty > % This is purely so the last item on the list is a known \penalty >
% 10000. This is so \startdefun can avoid allowing breakpoints after % 10000. This is so \startdefun can avoid allowing breakpoints after
% section headings. Otherwise, it would insert a valid breakpoint between: % section headings. Otherwise, it would insert a valid breakpoint between:
% %
% @section sec-whatever % @section sec-whatever
% @deffn def-whatever % @deffn def-whatever
\penalty 10001 \penalty 10001
@ -5427,7 +5427,7 @@ end
% These characters do not print properly in the Computer Modern roman % These characters do not print properly in the Computer Modern roman
% fonts, so we must take special care. This is more or less redundant % fonts, so we must take special care. This is more or less redundant
% with the Texinfo input format setup at the end of this file. % with the Texinfo input format setup at the end of this file.
% %
\def\activecatcodes{% \def\activecatcodes{%
\catcode`\"=\active \catcode`\"=\active
\catcode`\$=\active \catcode`\$=\active
@ -5477,7 +5477,7 @@ end
% redefined for the two-volume lispref. We always output on % redefined for the two-volume lispref. We always output on
% \jobname.toc even if this is redefined. % \jobname.toc even if this is redefined.
% %
\def\tocreadfilename{\jobname.toc} \def\tocreadfilename{\jobname.toc}
% Normal (long) toc. % Normal (long) toc.
@ -6032,8 +6032,8 @@ end
% from cmtt (char 0x0d). The undirected quote is ugly, so don't make it % from cmtt (char 0x0d). The undirected quote is ugly, so don't make it
% the default, but it works for pasting with more pdf viewers (at least % the default, but it works for pasting with more pdf viewers (at least
% evince), the lilypond developers report. xpdf does work with the % evince), the lilypond developers report. xpdf does work with the
% regular 0x27. % regular 0x27.
% %
\def\codequoteright{% \def\codequoteright{%
\expandafter\ifx\csname SETtxicodequoteundirected\endcsname\relax \expandafter\ifx\csname SETtxicodequoteundirected\endcsname\relax
\expandafter\ifx\csname SETcodequoteundirected\endcsname\relax \expandafter\ifx\csname SETcodequoteundirected\endcsname\relax
@ -6045,7 +6045,7 @@ end
% and a similar option for the left quote char vs. a grave accent. % and a similar option for the left quote char vs. a grave accent.
% Modern fonts display ASCII 0x60 as a grave accent, so some people like % Modern fonts display ASCII 0x60 as a grave accent, so some people like
% the code environments to do likewise. % the code environments to do likewise.
% %
\def\codequoteleft{% \def\codequoteleft{%
\expandafter\ifx\csname SETtxicodequotebacktick\endcsname\relax \expandafter\ifx\csname SETtxicodequotebacktick\endcsname\relax
\expandafter\ifx\csname SETcodequotebacktick\endcsname\relax \expandafter\ifx\csname SETcodequotebacktick\endcsname\relax
@ -6576,7 +6576,7 @@ end
% This does \let #1 = #2, with \csnames; that is, % This does \let #1 = #2, with \csnames; that is,
% \let \csname#1\endcsname = \csname#2\endcsname % \let \csname#1\endcsname = \csname#2\endcsname
% (except of course we have to play expansion games). % (except of course we have to play expansion games).
% %
\def\cslet#1#2{% \def\cslet#1#2{%
\expandafter\let \expandafter\let
\csname#1\expandafter\endcsname \csname#1\expandafter\endcsname
@ -7734,7 +7734,7 @@ end
% %
% If they passed de_DE, and txi-de_DE.tex doesn't exist, % If they passed de_DE, and txi-de_DE.tex doesn't exist,
% try txi-de.tex. % try txi-de.tex.
% %
\def\documentlanguagetrywithoutunderscore#1_#2\finish{% \def\documentlanguagetrywithoutunderscore#1_#2\finish{%
\openin 1 txi-#1.tex \openin 1 txi-#1.tex
\ifeof 1 \ifeof 1
@ -7790,7 +7790,7 @@ should work if nowhere else does.}
\setnonasciicharscatcode\active \setnonasciicharscatcode\active
\lattwochardefs \lattwochardefs
% %
\else \ifx \declaredencoding \latone \else \ifx \declaredencoding \latone
\setnonasciicharscatcode\active \setnonasciicharscatcode\active
\latonechardefs \latonechardefs
% %
@ -7802,7 +7802,7 @@ should work if nowhere else does.}
\setnonasciicharscatcode\active \setnonasciicharscatcode\active
\utfeightchardefs \utfeightchardefs
% %
\else \else
\message{Unknown document encoding #1, ignoring.}% \message{Unknown document encoding #1, ignoring.}%
% %
\fi % utfeight \fi % utfeight
@ -7814,7 +7814,7 @@ should work if nowhere else does.}
% A message to be logged when using a character that isn't available % A message to be logged when using a character that isn't available
% the default font encoding (OT1). % the default font encoding (OT1).
% %
\def\missingcharmsg#1{\message{Character missing in OT1 encoding: #1.}} \def\missingcharmsg#1{\message{Character missing in OT1 encoding: #1.}}
% Take account of \c (plain) vs. \, (Texinfo) difference. % Take account of \c (plain) vs. \, (Texinfo) difference.
@ -7827,21 +7827,21 @@ should work if nowhere else does.}
% %
% Latin1 (ISO-8859-1) character definitions. % Latin1 (ISO-8859-1) character definitions.
\def\latonechardefs{% \def\latonechardefs{%
\gdef^^a0{~} \gdef^^a0{~}
\gdef^^a1{\exclamdown} \gdef^^a1{\exclamdown}
\gdef^^a2{\missingcharmsg{CENT SIGN}} \gdef^^a2{\missingcharmsg{CENT SIGN}}
\gdef^^a3{{\pounds}} \gdef^^a3{{\pounds}}
\gdef^^a4{\missingcharmsg{CURRENCY SIGN}} \gdef^^a4{\missingcharmsg{CURRENCY SIGN}}
\gdef^^a5{\missingcharmsg{YEN SIGN}} \gdef^^a5{\missingcharmsg{YEN SIGN}}
\gdef^^a6{\missingcharmsg{BROKEN BAR}} \gdef^^a6{\missingcharmsg{BROKEN BAR}}
\gdef^^a7{\S} \gdef^^a7{\S}
\gdef^^a8{\"{}} \gdef^^a8{\"{}}
\gdef^^a9{\copyright} \gdef^^a9{\copyright}
\gdef^^aa{\ordf} \gdef^^aa{\ordf}
\gdef^^ab{\missingcharmsg{LEFT-POINTING DOUBLE ANGLE QUOTATION MARK}} \gdef^^ab{\missingcharmsg{LEFT-POINTING DOUBLE ANGLE QUOTATION MARK}}
\gdef^^ac{$\lnot$} \gdef^^ac{$\lnot$}
\gdef^^ad{\-} \gdef^^ad{\-}
\gdef^^ae{\registeredsymbol} \gdef^^ae{\registeredsymbol}
\gdef^^af{\={}} \gdef^^af{\={}}
% %
\gdef^^b0{\textdegree} \gdef^^b0{\textdegree}
@ -7868,7 +7868,7 @@ should work if nowhere else does.}
\gdef^^c2{\^A} \gdef^^c2{\^A}
\gdef^^c3{\~A} \gdef^^c3{\~A}
\gdef^^c4{\"A} \gdef^^c4{\"A}
\gdef^^c5{\ringaccent A} \gdef^^c5{\ringaccent A}
\gdef^^c6{\AE} \gdef^^c6{\AE}
\gdef^^c7{\cedilla C} \gdef^^c7{\cedilla C}
\gdef^^c8{\`E} \gdef^^c8{\`E}
@ -8009,7 +8009,7 @@ should work if nowhere else does.}
\gdef^^d6{\"O} \gdef^^d6{\"O}
\gdef^^d7{$\times$} \gdef^^d7{$\times$}
\gdef^^d8{\v R} \gdef^^d8{\v R}
\gdef^^d9{\ringaccent U} \gdef^^d9{\ringaccent U}
\gdef^^da{\'U} \gdef^^da{\'U}
\gdef^^db{\H U} \gdef^^db{\H U}
\gdef^^dc{\"U} \gdef^^dc{\"U}
@ -8053,11 +8053,11 @@ should work if nowhere else does.}
} }
% UTF-8 character definitions. % UTF-8 character definitions.
% %
% This code to support UTF-8 is based on LaTeX's utf8.def, with some % This code to support UTF-8 is based on LaTeX's utf8.def, with some
% changes for Texinfo conventions. It is included here under the GPL by % changes for Texinfo conventions. It is included here under the GPL by
% permission from Frank Mittelbach and the LaTeX team. % permission from Frank Mittelbach and the LaTeX team.
% %
\newcount\countUTFx \newcount\countUTFx
\newcount\countUTFy \newcount\countUTFy
\newcount\countUTFz \newcount\countUTFz
@ -8897,7 +8897,7 @@ should work if nowhere else does.}
% Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of % Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
% the literal character `\'. % the literal character `\'.
% %
@def@normalturnoffactive{% @def@normalturnoffactive{%
@let\=@normalbackslash @let\=@normalbackslash
@let"=@normaldoublequote @let"=@normaldoublequote

View file

@ -38,7 +38,7 @@ grub_arch_efiemu_check_header32 (void *ehdr)
/* Relocate symbols. */ /* Relocate symbols. */
grub_err_t grub_err_t
grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs, grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs,
struct grub_efiemu_elf_sym *elfsyms, struct grub_efiemu_elf_sym *elfsyms,
void *ehdr) void *ehdr)
{ {
@ -66,7 +66,7 @@ grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs,
if (seg) if (seg)
{ {
Elf32_Rel *rel, *max; Elf32_Rel *rel, *max;
for (rel = (Elf32_Rel *) ((char *) e + s->sh_offset), for (rel = (Elf32_Rel *) ((char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize; max = rel + s->sh_size / s->sh_entsize;
rel < max; rel < max;
@ -77,31 +77,31 @@ grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs,
if (seg->size < rel->r_offset) if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE, return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment"); "reloc offset is out of the segment");
addr = (Elf32_Word *) addr = (Elf32_Word *)
((char *) grub_efiemu_mm_obtain_request (seg->handle) ((char *) grub_efiemu_mm_obtain_request (seg->handle)
+ seg->off + rel->r_offset); + seg->off + rel->r_offset);
sym = elfsyms[ELF32_R_SYM (rel->r_info)]; sym = elfsyms[ELF32_R_SYM (rel->r_info)];
switch (ELF32_R_TYPE (rel->r_info)) switch (ELF32_R_TYPE (rel->r_info))
{ {
case R_386_32: case R_386_32:
if ((err = grub_efiemu_write_value if ((err = grub_efiemu_write_value
(addr, sym.off + *addr, sym.handle, 0, (addr, sym.off + *addr, sym.handle, 0,
seg->ptv_rel_needed, sizeof (grub_uint32_t)))) seg->ptv_rel_needed, sizeof (grub_uint32_t))))
return err; return err;
break; break;
case R_386_PC32: case R_386_PC32:
if ((err = grub_efiemu_write_value if ((err = grub_efiemu_write_value
(addr, sym.off + *addr - rel->r_offset (addr, sym.off + *addr - rel->r_offset
- seg->off, sym.handle, seg->handle, - seg->off, sym.handle, seg->handle,
seg->ptv_rel_needed, sizeof (grub_uint32_t)))) seg->ptv_rel_needed, sizeof (grub_uint32_t))))
return err; return err;
break; break;
default: default:
return grub_error (GRUB_ERR_BAD_OS, return grub_error (GRUB_ERR_BAD_OS,
"unrecognised relocation"); "unrecognised relocation");
} }
} }

View file

@ -37,7 +37,7 @@ grub_arch_efiemu_check_header64 (void *ehdr)
/* Relocate symbols. */ /* Relocate symbols. */
grub_err_t grub_err_t
grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs, grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
struct grub_efiemu_elf_sym *elfsyms, struct grub_efiemu_elf_sym *elfsyms,
void *ehdr) void *ehdr)
{ {
@ -62,9 +62,9 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
if (seg) if (seg)
{ {
Elf64_Rela *rel, *max; Elf64_Rela *rel, *max;
for (rel = (Elf64_Rela *) ((char *) e + s->sh_offset), for (rel = (Elf64_Rela *) ((char *) e + s->sh_offset),
max = rel + (unsigned long) s->sh_size max = rel + (unsigned long) s->sh_size
/ (unsigned long)s->sh_entsize; / (unsigned long)s->sh_entsize;
rel < max; rel < max;
rel++) rel++)
@ -76,40 +76,40 @@ grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
if (seg->size < rel->r_offset) if (seg->size < rel->r_offset)
return grub_error (GRUB_ERR_BAD_MODULE, return grub_error (GRUB_ERR_BAD_MODULE,
"reloc offset is out of the segment"); "reloc offset is out of the segment");
addr = addr =
((char *) grub_efiemu_mm_obtain_request (seg->handle) ((char *) grub_efiemu_mm_obtain_request (seg->handle)
+ seg->off + rel->r_offset); + seg->off + rel->r_offset);
addr32 = (grub_uint32_t *) addr; addr32 = (grub_uint32_t *) addr;
addr64 = (grub_uint64_t *) addr; addr64 = (grub_uint64_t *) addr;
sym = elfsyms[ELF64_R_SYM (rel->r_info)]; sym = elfsyms[ELF64_R_SYM (rel->r_info)];
switch (ELF64_R_TYPE (rel->r_info)) switch (ELF64_R_TYPE (rel->r_info))
{ {
case R_X86_64_64: case R_X86_64_64:
if ((err = grub_efiemu_write_value if ((err = grub_efiemu_write_value
(addr, *addr64 + rel->r_addend + sym.off, sym.handle, (addr, *addr64 + rel->r_addend + sym.off, sym.handle,
0, seg->ptv_rel_needed, sizeof (grub_uint64_t)))) 0, seg->ptv_rel_needed, sizeof (grub_uint64_t))))
return err; return err;
break; break;
case R_X86_64_PC32: case R_X86_64_PC32:
if ((err = grub_efiemu_write_value if ((err = grub_efiemu_write_value
(addr, *addr32 + rel->r_addend + sym.off (addr, *addr32 + rel->r_addend + sym.off
- rel->r_offset - seg->off, sym.handle, seg->handle, - rel->r_offset - seg->off, sym.handle, seg->handle,
seg->ptv_rel_needed, sizeof (grub_uint32_t)))) seg->ptv_rel_needed, sizeof (grub_uint32_t))))
return err; return err;
break; break;
case R_X86_64_32: case R_X86_64_32:
case R_X86_64_32S: case R_X86_64_32S:
if ((err = grub_efiemu_write_value if ((err = grub_efiemu_write_value
(addr, *addr32 + rel->r_addend + sym.off, sym.handle, (addr, *addr32 + rel->r_addend + sym.off, sym.handle,
0, seg->ptv_rel_needed, sizeof (grub_uint32_t)))) 0, seg->ptv_rel_needed, sizeof (grub_uint32_t))))
return err; return err;
break; break;
default: default:
return grub_error (GRUB_ERR_BAD_OS, return grub_error (GRUB_ERR_BAD_OS,
"unrecognised relocation"); "unrecognised relocation");
} }
} }

View file

@ -59,7 +59,7 @@ grub_machine_efiemu_init_tables ()
return err; return err;
} }
for (ptr = (grub_uint8_t *) 0xf0000; ptr < (grub_uint8_t *) 0x100000; for (ptr = (grub_uint8_t *) 0xf0000; ptr < (grub_uint8_t *) 0x100000;
ptr += 16) ptr += 16)
if (grub_memcmp (ptr, "_SM_", 4) == 0 if (grub_memcmp (ptr, "_SM_", 4) == 0
&& grub_byte_checksum (ptr, *(ptr + 5)) == 0) && grub_byte_checksum (ptr, *(ptr + 5)) == 0)

View file

@ -40,7 +40,7 @@ grub_efiemu_get_section_addr (grub_efiemu_segment_t segs, unsigned n,
if (seg->section == n) if (seg->section == n)
{ {
*handle = seg->handle; *handle = seg->handle;
*off = seg->off; *off = seg->off;
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -86,7 +86,7 @@ grub_efiemu_load_segments (grub_efiemu_segment_t segs, const Elf_Ehdr *e)
grub_efiemu_segment_t cur; grub_efiemu_segment_t cur;
grub_dprintf ("efiemu", "loading segments\n"); grub_dprintf ("efiemu", "loading segments\n");
for (cur=segs; cur; cur = cur->next) for (cur=segs; cur; cur = cur->next)
{ {
s = (Elf_Shdr *)cur->srcptr; s = (Elf_Shdr *)cur->srcptr;
@ -94,10 +94,10 @@ grub_efiemu_load_segments (grub_efiemu_segment_t segs, const Elf_Ehdr *e)
if ((s->sh_flags & SHF_ALLOC) && s->sh_size) if ((s->sh_flags & SHF_ALLOC) && s->sh_size)
{ {
void *addr; void *addr;
addr = (grub_uint8_t *) grub_efiemu_mm_obtain_request (cur->handle) addr = (grub_uint8_t *) grub_efiemu_mm_obtain_request (cur->handle)
+ cur->off; + cur->off;
switch (s->sh_type) switch (s->sh_type)
{ {
case SHT_PROGBITS: case SHT_PROGBITS:
@ -145,11 +145,11 @@ grub_efiemu_init_segments (grub_efiemu_segment_t *segs, const Elf_Ehdr *e)
seg = (grub_efiemu_segment_t) grub_malloc (sizeof (*seg)); seg = (grub_efiemu_segment_t) grub_malloc (sizeof (*seg));
if (! seg) if (! seg)
return grub_errno; return grub_errno;
if (s->sh_size) if (s->sh_size)
{ {
seg->handle seg->handle
= grub_efiemu_request_memalign = grub_efiemu_request_memalign
(s->sh_addralign, s->sh_size, (s->sh_addralign, s->sh_size,
s->sh_flags & SHF_EXECINSTR ? GRUB_EFI_RUNTIME_SERVICES_CODE s->sh_flags & SHF_EXECINSTR ? GRUB_EFI_RUNTIME_SERVICES_CODE
: GRUB_EFI_RUNTIME_SERVICES_DATA); : GRUB_EFI_RUNTIME_SERVICES_DATA);
@ -157,12 +157,12 @@ grub_efiemu_init_segments (grub_efiemu_segment_t *segs, const Elf_Ehdr *e)
return grub_errno; return grub_errno;
seg->off = 0; seg->off = 0;
} }
/* /*
.text-physical doesn't need to be relocated when switching to .text-physical doesn't need to be relocated when switching to
virtual mode virtual mode
*/ */
if (!grub_strcmp (grub_efiemu_get_string (s->sh_name, e), if (!grub_strcmp (grub_efiemu_get_string (s->sh_name, e),
".text-physical")) ".text-physical"))
seg->ptv_rel_needed = 0; seg->ptv_rel_needed = 0;
else else
@ -174,7 +174,7 @@ grub_efiemu_init_segments (grub_efiemu_segment_t *segs, const Elf_Ehdr *e)
*segs = seg; *segs = seg;
} }
} }
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -185,7 +185,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e)
unsigned i; unsigned i;
Elf_Shdr *s; Elf_Shdr *s;
int num = 0; int num = 0;
/* Symbols */ /* Symbols */
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
i < e->e_shnum; i < e->e_shnum;
@ -197,7 +197,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e)
return grub_error (GRUB_ERR_BAD_OS, "no symbol table"); return grub_error (GRUB_ERR_BAD_OS, "no symbol table");
grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize; grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize;
grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *) grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *)
grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms); grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms);
/* Relocators */ /* Relocators */
@ -221,7 +221,7 @@ grub_efiemu_resolve_symbols (grub_efiemu_segment_t segs, Elf_Ehdr *e)
Elf_Sym *sym; Elf_Sym *sym;
const char *str; const char *str;
Elf_Word size, entsize; Elf_Word size, entsize;
grub_dprintf ("efiemu", "resolving symbols\n"); grub_dprintf ("efiemu", "resolving symbols\n");
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
@ -267,7 +267,7 @@ grub_efiemu_resolve_symbols (grub_efiemu_segment_t segs, Elf_Ehdr *e)
break; break;
case STT_OBJECT: case STT_OBJECT:
if ((err = grub_efiemu_get_section_addr if ((err = grub_efiemu_get_section_addr
(segs, sym->st_shndx, &handle, &off))) (segs, sym->st_shndx, &handle, &off)))
return err; return err;
@ -280,7 +280,7 @@ grub_efiemu_resolve_symbols (grub_efiemu_segment_t segs, Elf_Ehdr *e)
break; break;
case STT_FUNC: case STT_FUNC:
if ((err = grub_efiemu_get_section_addr if ((err = grub_efiemu_get_section_addr
(segs, sym->st_shndx, &handle, &off))) (segs, sym->st_shndx, &handle, &off)))
return err; return err;
@ -293,12 +293,12 @@ grub_efiemu_resolve_symbols (grub_efiemu_segment_t segs, Elf_Ehdr *e)
break; break;
case STT_SECTION: case STT_SECTION:
if ((err = grub_efiemu_get_section_addr if ((err = grub_efiemu_get_section_addr
(segs, sym->st_shndx, &handle, &off))) (segs, sym->st_shndx, &handle, &off)))
{ {
grub_efiemu_elfsyms[i].handle = 0; grub_efiemu_elfsyms[i].handle = 0;
grub_efiemu_elfsyms[i].off = 0; grub_efiemu_elfsyms[i].off = 0;
grub_errno = GRUB_ERR_NONE; grub_errno = GRUB_ERR_NONE;
break; break;
} }
@ -346,8 +346,8 @@ SUFFIX (grub_efiemu_loadcore_init) (void *core, grub_size_t core_size,
/* Load runtime definitively */ /* Load runtime definitively */
grub_err_t grub_err_t
SUFFIX (grub_efiemu_loadcore_load) (void *core, SUFFIX (grub_efiemu_loadcore_load) (void *core,
grub_size_t core_size grub_size_t core_size
__attribute__ ((unused)), __attribute__ ((unused)),
grub_efiemu_segment_t segments) grub_efiemu_segment_t segments)
{ {
@ -356,10 +356,10 @@ SUFFIX (grub_efiemu_loadcore_load) (void *core,
return err; return err;
if ((err = grub_efiemu_resolve_symbols (segments, core))) if ((err = grub_efiemu_resolve_symbols (segments, core)))
return err; return err;
if ((err = SUFFIX (grub_arch_efiemu_relocate_symbols) (segments, if ((err = SUFFIX (grub_arch_efiemu_relocate_symbols) (segments,
grub_efiemu_elfsyms, grub_efiemu_elfsyms,
core))) core)))
return err; return err;
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }

View file

@ -45,7 +45,7 @@ grub_efiemu_sizeof_uintn_t (void)
/* Check the header and set mode */ /* Check the header and set mode */
static grub_err_t static grub_err_t
grub_efiemu_check_header (void *ehdr, grub_size_t size, grub_efiemu_check_header (void *ehdr, grub_size_t size,
grub_efiemu_mode_t *mode) grub_efiemu_mode_t *mode)
{ {
/* Check the magic numbers. */ /* Check the magic numbers. */
@ -91,7 +91,7 @@ grub_efiemu_loadcore_unload(void)
case GRUB_EFIEMU64: case GRUB_EFIEMU64:
grub_efiemu_loadcore_unload64 (); grub_efiemu_loadcore_unload64 ();
break; break;
default: default:
break; break;
} }
@ -109,7 +109,7 @@ grub_efiemu_loadcore_unload(void)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
/* Load runtime file and do some initial preparations */ /* Load runtime file and do some initial preparations */
grub_err_t grub_err_t
grub_efiemu_loadcore_init (grub_file_t file) grub_efiemu_loadcore_init (grub_file_t file)
{ {
@ -121,7 +121,7 @@ grub_efiemu_loadcore_init (grub_file_t file)
if (! efiemu_core) if (! efiemu_core)
return grub_errno; return grub_errno;
if (grub_file_read (file, efiemu_core, efiemu_core_size) if (grub_file_read (file, efiemu_core, efiemu_core_size)
!= (int) efiemu_core_size) != (int) efiemu_core_size)
{ {
grub_free (efiemu_core); grub_free (efiemu_core);
@ -129,7 +129,7 @@ grub_efiemu_loadcore_init (grub_file_t file)
return grub_errno; return grub_errno;
} }
if (grub_efiemu_check_header (efiemu_core, efiemu_core_size, if (grub_efiemu_check_header (efiemu_core, efiemu_core_size,
&grub_efiemu_mode)) &grub_efiemu_mode))
{ {
grub_free (efiemu_core); grub_free (efiemu_core);
@ -160,7 +160,7 @@ grub_efiemu_loadcore_init (grub_file_t file)
return err; return err;
} }
break; break;
default: default:
return grub_error (GRUB_ERR_BAD_OS, "unknown EFI runtime"); return grub_error (GRUB_ERR_BAD_OS, "unknown EFI runtime");
} }

View file

@ -17,8 +17,8 @@
*/ */
/* This is an emulation of EFI runtime services. /* This is an emulation of EFI runtime services.
This allows a more uniform boot on i386 machines. This allows a more uniform boot on i386 machines.
As it emulates only runtime service it isn't able As it emulates only runtime service it isn't able
to chainload EFI bootloader on non-EFI system. */ to chainload EFI bootloader on non-EFI system. */
@ -112,7 +112,7 @@ grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid)
grub_err_t grub_err_t
grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data), grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),
void (*unload) (void *data), void (*unload) (void *data),
void *data) void *data)
{ {
struct grub_efiemu_prepare_hook *nhook; struct grub_efiemu_prepare_hook *nhook;
@ -129,20 +129,20 @@ grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
/* Register a configuration table either supplying the address directly /* Register a configuration table either supplying the address directly
or with a hook or with a hook
*/ */
grub_err_t grub_err_t
grub_efiemu_register_configuration_table (grub_efi_guid_t guid, grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
void * (*get_table) (void *data), void * (*get_table) (void *data),
void (*unload) (void *data), void (*unload) (void *data),
void *data) void *data)
{ {
struct grub_efiemu_configuration_table *tbl; struct grub_efiemu_configuration_table *tbl;
grub_err_t err; grub_err_t err;
if (! get_table && ! data) if (! get_table && ! data)
return grub_error (GRUB_ERR_BAD_ARGUMENT, return grub_error (GRUB_ERR_BAD_ARGUMENT,
"you must set at least get_table or data"); "you must set at least get_table or data");
if ((err = grub_efiemu_unregister_configuration_table (guid))) if ((err = grub_efiemu_unregister_configuration_table (guid)))
return err; return err;
@ -163,7 +163,7 @@ grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
static grub_err_t static grub_err_t
grub_cmd_efiemu_unload (grub_command_t cmd __attribute__ ((unused)), grub_cmd_efiemu_unload (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char *args[] __attribute__ ((unused))) char *args[] __attribute__ ((unused)))
{ {
return grub_efiemu_unload (); return grub_efiemu_unload ();
@ -171,7 +171,7 @@ grub_cmd_efiemu_unload (grub_command_t cmd __attribute__ ((unused)),
static grub_err_t static grub_err_t
grub_cmd_efiemu_prepare (grub_command_t cmd __attribute__ ((unused)), grub_cmd_efiemu_prepare (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char *args[] __attribute__ ((unused))) char *args[] __attribute__ ((unused)))
{ {
return grub_efiemu_prepare (); return grub_efiemu_prepare ();
@ -180,15 +180,15 @@ grub_cmd_efiemu_prepare (grub_command_t cmd __attribute__ ((unused)),
int int
grub_efiemu_exit_boot_services (grub_efi_uintn_t map_key grub_efiemu_exit_boot_services (grub_efi_uintn_t map_key
__attribute__ ((unused))) __attribute__ ((unused)))
{ {
/* Nothing to do here yet */ /* Nothing to do here yet */
return 1; return 1;
} }
int int
grub_efiemu_finish_boot_services (void) grub_efiemu_finish_boot_services (void)
{ {
/* Nothing to do here yet */ /* Nothing to do here yet */
@ -201,11 +201,11 @@ grub_efiemu_load_file (const char *filename)
{ {
grub_file_t file; grub_file_t file;
grub_err_t err; grub_err_t err;
file = grub_file_open (filename); file = grub_file_open (filename);
if (! file) if (! file)
return 0; return 0;
err = grub_efiemu_mm_init (); err = grub_efiemu_mm_init ();
if (err) if (err)
{ {
@ -244,19 +244,19 @@ grub_efiemu_autocore (void)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
prefix = grub_env_get ("prefix"); prefix = grub_env_get ("prefix");
if (! prefix) if (! prefix)
return grub_error (GRUB_ERR_FILE_NOT_FOUND, return grub_error (GRUB_ERR_FILE_NOT_FOUND,
"couldn't find efiemu core because prefix " "couldn't find efiemu core because prefix "
"isn't set"); "isn't set");
suffix = grub_efiemu_get_default_core_name (); suffix = grub_efiemu_get_default_core_name ();
filename = grub_malloc (grub_strlen (prefix) + grub_strlen (suffix) + 2); filename = grub_malloc (grub_strlen (prefix) + grub_strlen (suffix) + 2);
if (! filename) if (! filename)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate temporary space"); "couldn't allocate temporary space");
grub_sprintf (filename, "%s/%s", prefix, suffix); grub_sprintf (filename, "%s/%s", prefix, suffix);
err = grub_efiemu_load_file (filename); err = grub_efiemu_load_file (filename);
@ -277,7 +277,7 @@ grub_efiemu_prepare (void)
{ {
grub_err_t err; grub_err_t err;
grub_dprintf ("efiemu", "Preparing %d-bit efiemu\n", grub_dprintf ("efiemu", "Preparing %d-bit efiemu\n",
8 * grub_efiemu_sizeof_uintn_t ()); 8 * grub_efiemu_sizeof_uintn_t ());
err = grub_efiemu_autocore (); err = grub_efiemu_autocore ();
@ -321,16 +321,16 @@ grub_efiemu_pnvram_cmd_register (void);
GRUB_MOD_INIT(efiemu) GRUB_MOD_INIT(efiemu)
{ {
cmd_loadcore = grub_register_command ("efiemu_loadcore", cmd_loadcore = grub_register_command ("efiemu_loadcore",
grub_cmd_efiemu_load, grub_cmd_efiemu_load,
"efiemu_loadcore FILE", "efiemu_loadcore FILE",
"Load and initialize EFI emulator"); "Load and initialize EFI emulator");
cmd_prepare = grub_register_command ("efiemu_prepare", cmd_prepare = grub_register_command ("efiemu_prepare",
grub_cmd_efiemu_prepare, grub_cmd_efiemu_prepare,
"efiemu_prepare", "efiemu_prepare",
"Finalize loading of EFI emulator"); "Finalize loading of EFI emulator");
cmd_unload = grub_register_command ("efiemu_unload", grub_cmd_efiemu_unload, cmd_unload = grub_register_command ("efiemu_unload", grub_cmd_efiemu_unload,
"efiemu_unload", "efiemu_unload",
"Unload EFI emulator"); "Unload EFI emulator");
grub_efiemu_pnvram_cmd_register (); grub_efiemu_pnvram_cmd_register ();
} }

View file

@ -17,10 +17,10 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* /*
To keep efiemu runtime contiguous this mm is special. To keep efiemu runtime contiguous this mm is special.
It uses deferred allocation. It uses deferred allocation.
In the first stage you may request memory with grub_efiemu_request_memalign In the first stage you may request memory with grub_efiemu_request_memalign
It will give you a handle with which in the second phase you can access your It will give you a handle with which in the second phase you can access your
memory with grub_efiemu_mm_obtain_request (handle). It's guaranteed that memory with grub_efiemu_mm_obtain_request (handle). It's guaranteed that
subsequent calls with the same handle return the same result. You can't request any additional memory once you're in the second phase subsequent calls with the same handle return the same result. You can't request any additional memory once you're in the second phase
*/ */
@ -32,7 +32,7 @@
#include <grub/machine/memory.h> #include <grub/machine/memory.h>
#include <grub/efiemu/efiemu.h> #include <grub/efiemu/efiemu.h>
struct grub_efiemu_memrequest struct grub_efiemu_memrequest
{ {
struct grub_efiemu_memrequest *next; struct grub_efiemu_memrequest *next;
grub_efi_memory_type_t type; grub_efi_memory_type_t type;
@ -54,7 +54,7 @@ static int mmap_reserved_size = 0, mmap_num = 0;
/* Add a memory region to map*/ /* Add a memory region to map*/
static grub_err_t static grub_err_t
grub_efiemu_add_to_mmap (grub_uint64_t start, grub_uint64_t size, grub_efiemu_add_to_mmap (grub_uint64_t start, grub_uint64_t size,
grub_efi_memory_type_t type) grub_efi_memory_type_t type)
{ {
grub_uint64_t page_start, npages; grub_uint64_t page_start, npages;
@ -63,10 +63,10 @@ grub_efiemu_add_to_mmap (grub_uint64_t start, grub_uint64_t size,
if (mmap_num >= mmap_reserved_size) if (mmap_num >= mmap_reserved_size)
{ {
efiemu_mmap = (grub_efi_memory_descriptor_t *) efiemu_mmap = (grub_efi_memory_descriptor_t *)
grub_realloc (efiemu_mmap, (++mmap_reserved_size) grub_realloc (efiemu_mmap, (++mmap_reserved_size)
* sizeof (grub_efi_memory_descriptor_t)); * sizeof (grub_efi_memory_descriptor_t));
if (!efiemu_mmap) if (!efiemu_mmap)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Not enough space for memory map"); "Not enough space for memory map");
} }
@ -74,9 +74,9 @@ grub_efiemu_add_to_mmap (grub_uint64_t start, grub_uint64_t size,
page_start = start - (start % GRUB_EFIEMU_PAGESIZE); page_start = start - (start % GRUB_EFIEMU_PAGESIZE);
npages = (size + (start % GRUB_EFIEMU_PAGESIZE) + GRUB_EFIEMU_PAGESIZE - 1) npages = (size + (start % GRUB_EFIEMU_PAGESIZE) + GRUB_EFIEMU_PAGESIZE - 1)
/ GRUB_EFIEMU_PAGESIZE; / GRUB_EFIEMU_PAGESIZE;
efiemu_mmap[mmap_num].physical_start = page_start; efiemu_mmap[mmap_num].physical_start = page_start;
efiemu_mmap[mmap_num].virtual_start = page_start; efiemu_mmap[mmap_num].virtual_start = page_start;
efiemu_mmap[mmap_num].num_pages = npages; efiemu_mmap[mmap_num].num_pages = npages;
efiemu_mmap[mmap_num].type = type; efiemu_mmap[mmap_num].type = type;
mmap_num++; mmap_num++;
@ -84,11 +84,11 @@ grub_efiemu_add_to_mmap (grub_uint64_t start, grub_uint64_t size,
} }
/* Request a resident memory of type TYPE of size SIZE aligned at ALIGN /* Request a resident memory of type TYPE of size SIZE aligned at ALIGN
ALIGN must be a divisor of page size (if it's a divisor of 4096 ALIGN must be a divisor of page size (if it's a divisor of 4096
it should be ok on all platforms) it should be ok on all platforms)
*/ */
int int
grub_efiemu_request_memalign (grub_size_t align, grub_size_t size, grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
grub_efi_memory_type_t type) grub_efi_memory_type_t type)
{ {
grub_size_t align_overhead; grub_size_t align_overhead;
@ -113,8 +113,8 @@ grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
ret->val = 0; ret->val = 0;
ret->next = 0; ret->next = 0;
prev = 0; prev = 0;
/* Add request to the end of the chain. /* Add request to the end of the chain.
It should be at the end because otherwise alignment isn't guaranteed */ It should be at the end because otherwise alignment isn't guaranteed */
for (cur = memrequests; cur; prev = cur, cur = cur->next); for (cur = memrequests; cur; prev = cur, cur = cur->next);
if (prev) if (prev)
@ -155,20 +155,20 @@ efiemu_alloc_requests (void)
GRUB_EFI_RUNTIME_SERVICES_CODE, GRUB_EFI_RUNTIME_SERVICES_CODE,
GRUB_EFI_RUNTIME_SERVICES_DATA, GRUB_EFI_RUNTIME_SERVICES_DATA,
GRUB_EFI_ACPI_MEMORY_NVS, GRUB_EFI_ACPI_MEMORY_NVS,
/* And then unavailable memory types. This is more for a completeness. /* And then unavailable memory types. This is more for a completeness.
You should double think before allocating memory of any of these types You should double think before allocating memory of any of these types
*/ */
GRUB_EFI_UNUSABLE_MEMORY, GRUB_EFI_UNUSABLE_MEMORY,
GRUB_EFI_MEMORY_MAPPED_IO, GRUB_EFI_MEMORY_MAPPED_IO,
GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE, GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE,
GRUB_EFI_PAL_CODE GRUB_EFI_PAL_CODE
}; };
/* Compute total memory needed */ /* Compute total memory needed */
for (i = 0; i < sizeof (reqorder) / sizeof (reqorder[0]); i++) for (i = 0; i < sizeof (reqorder) / sizeof (reqorder[0]); i++)
{ {
align_overhead = GRUB_EFIEMU_PAGESIZE align_overhead = GRUB_EFIEMU_PAGESIZE
- (requested_memory[reqorder[i]] % GRUB_EFIEMU_PAGESIZE); - (requested_memory[reqorder[i]] % GRUB_EFIEMU_PAGESIZE);
if (align_overhead == GRUB_EFIEMU_PAGESIZE) if (align_overhead == GRUB_EFIEMU_PAGESIZE)
align_overhead = 0; align_overhead = 0;
@ -178,7 +178,7 @@ efiemu_alloc_requests (void)
/* Allocate the whole memory in one block */ /* Allocate the whole memory in one block */
resident_memory = grub_memalign (GRUB_EFIEMU_PAGESIZE, total_alloc); resident_memory = grub_memalign (GRUB_EFIEMU_PAGESIZE, total_alloc);
if (!resident_memory) if (!resident_memory)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate resident memory"); "couldn't allocate resident memory");
/* Split the memory into blocks by type */ /* Split the memory into blocks by type */
@ -199,14 +199,14 @@ efiemu_alloc_requests (void)
} }
/* Ensure that the regions are page-aligned */ /* Ensure that the regions are page-aligned */
align_overhead = GRUB_EFIEMU_PAGESIZE align_overhead = GRUB_EFIEMU_PAGESIZE
- (requested_memory[reqorder[i]] % GRUB_EFIEMU_PAGESIZE); - (requested_memory[reqorder[i]] % GRUB_EFIEMU_PAGESIZE);
if (align_overhead == GRUB_EFIEMU_PAGESIZE) if (align_overhead == GRUB_EFIEMU_PAGESIZE)
align_overhead = 0; align_overhead = 0;
curptr = ((grub_uint8_t *)curptr) + align_overhead; curptr = ((grub_uint8_t *)curptr) + align_overhead;
/* Add the region to memory map */ /* Add the region to memory map */
grub_efiemu_add_to_mmap (PTR_TO_UINT64 (typestart), grub_efiemu_add_to_mmap (PTR_TO_UINT64 (typestart),
curptr - typestart, reqorder[i]); curptr - typestart, reqorder[i]);
} }
@ -270,7 +270,7 @@ grub_efiemu_mm_return_request (int handle)
static grub_err_t static grub_err_t
grub_efiemu_mmap_init (void) grub_efiemu_mmap_init (void)
{ {
auto int NESTED_FUNC_ATTR bounds_hook (grub_uint64_t, grub_uint64_t, auto int NESTED_FUNC_ATTR bounds_hook (grub_uint64_t, grub_uint64_t,
grub_uint32_t); grub_uint32_t);
int NESTED_FUNC_ATTR bounds_hook (grub_uint64_t addr __attribute__ ((unused)), int NESTED_FUNC_ATTR bounds_hook (grub_uint64_t addr __attribute__ ((unused)),
grub_uint64_t size __attribute__ ((unused)), grub_uint64_t size __attribute__ ((unused)),
@ -302,7 +302,7 @@ grub_efiemu_get_memory_map (grub_efi_uintn_t *memory_map_size,
{ {
if (!efiemu_mmap) if (!efiemu_mmap)
{ {
grub_error (GRUB_ERR_INVALID_COMMAND, grub_error (GRUB_ERR_INVALID_COMMAND,
"you need to first launch efiemu_prepare"); "you need to first launch efiemu_prepare");
return -1; return -1;
} }
@ -373,26 +373,26 @@ grub_efiemu_mmap_fill (void)
switch (type) switch (type)
{ {
case GRUB_MACHINE_MEMORY_AVAILABLE: case GRUB_MACHINE_MEMORY_AVAILABLE:
return grub_efiemu_add_to_mmap (addr, size, return grub_efiemu_add_to_mmap (addr, size,
GRUB_EFI_CONVENTIONAL_MEMORY); GRUB_EFI_CONVENTIONAL_MEMORY);
#ifdef GRUB_MACHINE_MEMORY_ACPI #ifdef GRUB_MACHINE_MEMORY_ACPI
case GRUB_MACHINE_MEMORY_ACPI: case GRUB_MACHINE_MEMORY_ACPI:
return grub_efiemu_add_to_mmap (addr, size, return grub_efiemu_add_to_mmap (addr, size,
GRUB_EFI_ACPI_RECLAIM_MEMORY); GRUB_EFI_ACPI_RECLAIM_MEMORY);
#endif #endif
#ifdef GRUB_MACHINE_MEMORY_NVS #ifdef GRUB_MACHINE_MEMORY_NVS
case GRUB_MACHINE_MEMORY_NVS: case GRUB_MACHINE_MEMORY_NVS:
return grub_efiemu_add_to_mmap (addr, size, return grub_efiemu_add_to_mmap (addr, size,
GRUB_EFI_ACPI_MEMORY_NVS); GRUB_EFI_ACPI_MEMORY_NVS);
#endif #endif
default: default:
grub_printf ("Unknown memory type %d. Marking as unusable\n", type); grub_printf ("Unknown memory type %d. Marking as unusable\n", type);
case GRUB_MACHINE_MEMORY_RESERVED: case GRUB_MACHINE_MEMORY_RESERVED:
return grub_efiemu_add_to_mmap (addr, size, return grub_efiemu_add_to_mmap (addr, size,
GRUB_EFI_UNUSABLE_MEMORY); GRUB_EFI_UNUSABLE_MEMORY);
} }
} }
@ -404,8 +404,8 @@ grub_efiemu_mmap_fill (void)
} }
grub_err_t grub_err_t
grub_efiemu_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_efiemu_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
grub_uint64_t, grub_uint64_t,
grub_uint32_t)) grub_uint32_t))
{ {
unsigned i; unsigned i;
@ -414,10 +414,10 @@ grub_efiemu_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
switch (efiemu_mmap[i].type) switch (efiemu_mmap[i].type)
{ {
case GRUB_EFI_RUNTIME_SERVICES_CODE: case GRUB_EFI_RUNTIME_SERVICES_CODE:
hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096, hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096,
GRUB_EFIEMU_MEMORY_CODE); GRUB_EFIEMU_MEMORY_CODE);
break; break;
case GRUB_EFI_RESERVED_MEMORY_TYPE: case GRUB_EFI_RESERVED_MEMORY_TYPE:
case GRUB_EFI_RUNTIME_SERVICES_DATA: case GRUB_EFI_RUNTIME_SERVICES_DATA:
case GRUB_EFI_UNUSABLE_MEMORY: case GRUB_EFI_UNUSABLE_MEMORY:
@ -425,30 +425,30 @@ grub_efiemu_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
case GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE: case GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE:
case GRUB_EFI_PAL_CODE: case GRUB_EFI_PAL_CODE:
case GRUB_EFI_MAX_MEMORY_TYPE: case GRUB_EFI_MAX_MEMORY_TYPE:
hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096, hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096,
GRUB_EFIEMU_MEMORY_RESERVED); GRUB_EFIEMU_MEMORY_RESERVED);
break; break;
case GRUB_EFI_LOADER_CODE: case GRUB_EFI_LOADER_CODE:
case GRUB_EFI_LOADER_DATA: case GRUB_EFI_LOADER_DATA:
case GRUB_EFI_BOOT_SERVICES_CODE: case GRUB_EFI_BOOT_SERVICES_CODE:
case GRUB_EFI_BOOT_SERVICES_DATA: case GRUB_EFI_BOOT_SERVICES_DATA:
case GRUB_EFI_CONVENTIONAL_MEMORY: case GRUB_EFI_CONVENTIONAL_MEMORY:
hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096, hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096,
GRUB_EFIEMU_MEMORY_AVAILABLE); GRUB_EFIEMU_MEMORY_AVAILABLE);
break; break;
case GRUB_EFI_ACPI_RECLAIM_MEMORY: case GRUB_EFI_ACPI_RECLAIM_MEMORY:
hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096, hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096,
GRUB_EFIEMU_MEMORY_ACPI); GRUB_EFIEMU_MEMORY_ACPI);
break; break;
case GRUB_EFI_ACPI_MEMORY_NVS: case GRUB_EFI_ACPI_MEMORY_NVS:
hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096, hook (efiemu_mmap[i].physical_start, efiemu_mmap[i].num_pages * 4096,
GRUB_EFIEMU_MEMORY_NVS); GRUB_EFIEMU_MEMORY_NVS);
break; break;
} }
return 0; return 0;
} }
@ -459,8 +459,8 @@ grub_efiemu_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
static grub_err_t static grub_err_t
grub_efiemu_mmap_sort_and_uniq (void) grub_efiemu_mmap_sort_and_uniq (void)
{ {
/* If same page is used by multiple types it's resolved /* If same page is used by multiple types it's resolved
according to priority according to priority
0 - free memory 0 - free memory
1 - memory immediately usable after ExitBootServices 1 - memory immediately usable after ExitBootServices
2 - memory usable after loading ACPI tables 2 - memory usable after loading ACPI tables
@ -512,20 +512,20 @@ grub_efiemu_mmap_sort_and_uniq (void)
/* Initialize variables*/ /* Initialize variables*/
grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE); grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE);
scanline_events = (struct grub_efiemu_mmap_scan *) scanline_events = (struct grub_efiemu_mmap_scan *)
grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num); grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num);
/* Number of chunks can't increase more than by factor of 2 */ /* Number of chunks can't increase more than by factor of 2 */
result = (grub_efi_memory_descriptor_t *) result = (grub_efi_memory_descriptor_t *)
grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num); grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num);
if (!result || !scanline_events) if (!result || !scanline_events)
{ {
grub_free (result); grub_free (result);
grub_free (scanline_events); grub_free (scanline_events);
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"couldn't allocate space for new memory map"); "couldn't allocate space for new memory map");
} }
/* Register scanline events */ /* Register scanline events */
for (i = 0; i < mmap_num; i++) for (i = 0; i < mmap_num; i++)
{ {
@ -538,8 +538,8 @@ grub_efiemu_mmap_sort_and_uniq (void)
scanline_events[2 * i + 1].memtype = efiemu_mmap[i].type; scanline_events[2 * i + 1].memtype = efiemu_mmap[i].type;
} }
/* Primitive bubble sort. It has complexity O(n^2) but since we're /* Primitive bubble sort. It has complexity O(n^2) but since we're
unlikely to have more than 100 chunks it's probably one of the unlikely to have more than 100 chunks it's probably one of the
fastest for one purpose */ fastest for one purpose */
done = 1; done = 1;
while (done) while (done)
@ -574,29 +574,29 @@ grub_efiemu_mmap_sort_and_uniq (void)
curtype = k; curtype = k;
/* Add memory region to resulting map if necessary */ /* Add memory region to resulting map if necessary */
if ((curtype == -1 || curtype != lasttype) if ((curtype == -1 || curtype != lasttype)
&& lastaddr != scanline_events[i].pos && lastaddr != scanline_events[i].pos
&& lasttype != -1) && lasttype != -1)
{ {
result[j].virtual_start = result[j].physical_start = lastaddr; result[j].virtual_start = result[j].physical_start = lastaddr;
result[j].num_pages = (scanline_events[i].pos - lastaddr) result[j].num_pages = (scanline_events[i].pos - lastaddr)
/ GRUB_EFIEMU_PAGESIZE; / GRUB_EFIEMU_PAGESIZE;
result[j].type = lasttype; result[j].type = lasttype;
/* We set runtime attribute on pages we need to be mapped */ /* We set runtime attribute on pages we need to be mapped */
result[j].attribute result[j].attribute
= (lasttype == GRUB_EFI_RUNTIME_SERVICES_CODE = (lasttype == GRUB_EFI_RUNTIME_SERVICES_CODE
|| lasttype == GRUB_EFI_RUNTIME_SERVICES_DATA) || lasttype == GRUB_EFI_RUNTIME_SERVICES_DATA)
? GRUB_EFI_MEMORY_RUNTIME : 0; ? GRUB_EFI_MEMORY_RUNTIME : 0;
grub_dprintf ("efiemu", grub_dprintf ("efiemu",
"mmap entry: type %d start 0x%llx 0x%llx pages\n", "mmap entry: type %d start 0x%llx 0x%llx pages\n",
result[j].type, result[j].type,
result[j].physical_start, result[j].num_pages); result[j].physical_start, result[j].num_pages);
j++; j++;
} }
/* Update last values if necessary */ /* Update last values if necessary */
if (curtype == -1 || curtype != lasttype) if (curtype == -1 || curtype != lasttype)
{ {
lasttype = curtype; lasttype = curtype;
lastaddr = scanline_events[i].pos; lastaddr = scanline_events[i].pos;
@ -605,7 +605,7 @@ grub_efiemu_mmap_sort_and_uniq (void)
grub_free (scanline_events); grub_free (scanline_events);
/* Shrink resulting memory map to really used size and replace efiemu_mmap /* Shrink resulting memory map to really used size and replace efiemu_mmap
by new value */ by new value */
grub_free (efiemu_mmap); grub_free (efiemu_mmap);
efiemu_mmap = grub_realloc (result, j * sizeof (*result)); efiemu_mmap = grub_realloc (result, j * sizeof (*result));
@ -619,7 +619,7 @@ grub_efiemu_mm_do_alloc (void)
grub_err_t err; grub_err_t err;
/* Preallocate mmap */ /* Preallocate mmap */
efiemu_mmap = (grub_efi_memory_descriptor_t *) efiemu_mmap = (grub_efi_memory_descriptor_t *)
grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t)); grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t));
if (!efiemu_mmap) if (!efiemu_mmap)
{ {
@ -632,4 +632,4 @@ grub_efiemu_mm_do_alloc (void)
if ((err = grub_efiemu_mmap_fill ())) if ((err = grub_efiemu_mmap_fill ()))
return err; return err;
return grub_efiemu_mmap_sort_and_uniq (); return grub_efiemu_mmap_sort_and_uniq ();
} }

View file

@ -45,13 +45,13 @@ static grub_uint32_t accuracy;
static const struct grub_arg_option options[] = { static const struct grub_arg_option options[] = {
{"size", 's', 0, "number of bytes to reserve for pseudo NVRAM", 0, {"size", 's', 0, "number of bytes to reserve for pseudo NVRAM", 0,
ARG_TYPE_INT}, ARG_TYPE_INT},
{"high-monotonic-count", 'm', 0, {"high-monotonic-count", 'm', 0,
"Initial value of high monotonic count", 0, ARG_TYPE_INT}, "Initial value of high monotonic count", 0, ARG_TYPE_INT},
{"timezone", 't', 0, {"timezone", 't', 0,
"Timezone, offset in minutes from GMT", 0, ARG_TYPE_INT}, "Timezone, offset in minutes from GMT", 0, ARG_TYPE_INT},
{"accuracy", 'a', 0, {"accuracy", 'a', 0,
"Accuracy of clock, in 1e-12 units", 0, ARG_TYPE_INT}, "Accuracy of clock, in 1e-12 units", 0, ARG_TYPE_INT},
{"daylight", 'd', 0, {"daylight", 'd', 0,
"Daylight value, as per EFI specifications", 0, ARG_TYPE_INT}, "Daylight value, as per EFI specifications", 0, ARG_TYPE_INT},
{0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0}
}; };
@ -68,14 +68,14 @@ grub_strtosl (char *arg, char **end, int base)
/* Export stuff for efiemu */ /* Export stuff for efiemu */
static grub_err_t static grub_err_t
nvram_set (void * data __attribute__ ((unused))) nvram_set (void * data __attribute__ ((unused)))
{ {
/* Take definitive pointers */ /* Take definitive pointers */
grub_uint8_t *nvram_def = grub_efiemu_mm_obtain_request (nvram_handle); grub_uint8_t *nvram_def = grub_efiemu_mm_obtain_request (nvram_handle);
grub_uint32_t *nvramsize_def grub_uint32_t *nvramsize_def
= grub_efiemu_mm_obtain_request (nvramsize_handle); = grub_efiemu_mm_obtain_request (nvramsize_handle);
grub_uint32_t *high_monotonic_count_def grub_uint32_t *high_monotonic_count_def
= grub_efiemu_mm_obtain_request (high_monotonic_count_handle); = grub_efiemu_mm_obtain_request (high_monotonic_count_handle);
grub_int16_t *timezone_def grub_int16_t *timezone_def
= grub_efiemu_mm_obtain_request (timezone_handle); = grub_efiemu_mm_obtain_request (timezone_handle);
grub_uint8_t *daylight_def grub_uint8_t *daylight_def
= grub_efiemu_mm_obtain_request (daylight_handle); = grub_efiemu_mm_obtain_request (daylight_handle);
@ -94,11 +94,11 @@ nvram_set (void * data __attribute__ ((unused)))
/* Register symbols */ /* Register symbols */
grub_efiemu_register_symbol ("efiemu_variables", nvram_handle, 0); grub_efiemu_register_symbol ("efiemu_variables", nvram_handle, 0);
grub_efiemu_register_symbol ("efiemu_varsize", nvramsize_handle, 0); grub_efiemu_register_symbol ("efiemu_varsize", nvramsize_handle, 0);
grub_efiemu_register_symbol ("efiemu_high_monotonic_count", grub_efiemu_register_symbol ("efiemu_high_monotonic_count",
high_monotonic_count_handle, 0); high_monotonic_count_handle, 0);
grub_efiemu_register_symbol ("efiemu_time_zone", timezone_handle, 0); grub_efiemu_register_symbol ("efiemu_time_zone", timezone_handle, 0);
grub_efiemu_register_symbol ("efiemu_time_daylight", daylight_handle, 0); grub_efiemu_register_symbol ("efiemu_time_daylight", daylight_handle, 0);
grub_efiemu_register_symbol ("efiemu_time_accuracy", grub_efiemu_register_symbol ("efiemu_time_accuracy",
accuracy_handle, 0); accuracy_handle, 0);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
@ -134,7 +134,7 @@ read_pnvram (char *filename)
struct efi_variable *efivar; struct efi_variable *efivar;
grub_size_t guidlen, datalen; grub_size_t guidlen, datalen;
unsigned i, j; unsigned i, j;
file = grub_file_open (filename); file = grub_file_open (filename);
if (!file) if (!file)
return grub_error (GRUB_ERR_BAD_OS, "couldn't read pnvram"); return grub_error (GRUB_ERR_BAD_OS, "couldn't read pnvram");
@ -157,17 +157,17 @@ read_pnvram (char *filename)
efivar = (struct efi_variable *) nvramptr; efivar = (struct efi_variable *) nvramptr;
if (nvramptr - nvram + sizeof (struct efi_variable) > nvramsize) if (nvramptr - nvram + sizeof (struct efi_variable) > nvramsize)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"file is too large for reserved variable space"); "file is too large for reserved variable space");
nvramptr += sizeof (struct efi_variable); nvramptr += sizeof (struct efi_variable);
/* look ahow long guid field is*/ /* look ahow long guid field is*/
guidlen = 0; guidlen = 0;
for (ptr2 = ptr; (grub_isspace (*ptr2) for (ptr2 = ptr; (grub_isspace (*ptr2)
|| (*ptr2 >= '0' && *ptr2 <= '9') || (*ptr2 >= '0' && *ptr2 <= '9')
|| (*ptr2 >= 'a' && *ptr2 <= 'f') || (*ptr2 >= 'a' && *ptr2 <= 'f')
|| (*ptr2 >= 'A' && *ptr2 <= 'F')); || (*ptr2 >= 'A' && *ptr2 <= 'F'));
ptr2++) ptr2++)
if (!grub_isspace (*ptr2)) if (!grub_isspace (*ptr2))
guidlen++; guidlen++;
@ -175,7 +175,7 @@ read_pnvram (char *filename)
/* Read guid */ /* Read guid */
if (guidlen != sizeof (efivar->guid)) if (guidlen != sizeof (efivar->guid))
{ {
grub_free (buf); grub_free (buf);
return grub_error (GRUB_ERR_BAD_OS, "can't parse %s", filename); return grub_error (GRUB_ERR_BAD_OS, "can't parse %s", filename);
} }
@ -190,14 +190,14 @@ read_pnvram (char *filename)
hex = *ptr - 'a' + 10; hex = *ptr - 'a' + 10;
if (*ptr >= 'A' && *ptr <= 'F') if (*ptr >= 'A' && *ptr <= 'F')
hex = *ptr - 'A' + 10; hex = *ptr - 'A' + 10;
if (i%2 == 0) if (i%2 == 0)
((grub_uint8_t *)&(efivar->guid))[i/2] = hex << 4; ((grub_uint8_t *)&(efivar->guid))[i/2] = hex << 4;
else else
((grub_uint8_t *)&(efivar->guid))[i/2] |= hex; ((grub_uint8_t *)&(efivar->guid))[i/2] |= hex;
ptr++; ptr++;
} }
while (grub_isspace (*ptr)) while (grub_isspace (*ptr))
ptr++; ptr++;
if (*ptr != ':') if (*ptr != ':')
@ -230,23 +230,23 @@ read_pnvram (char *filename)
{ {
/* Look the length */ /* Look the length */
datalen = 0; datalen = 0;
for (ptr2 = ptr; *ptr2 && (grub_isspace (*ptr2) for (ptr2 = ptr; *ptr2 && (grub_isspace (*ptr2)
|| (*ptr2 >= '0' && *ptr2 <= '9') || (*ptr2 >= '0' && *ptr2 <= '9')
|| (*ptr2 >= 'a' && *ptr2 <= 'f') || (*ptr2 >= 'a' && *ptr2 <= 'f')
|| (*ptr2 >= 'A' && *ptr2 <= 'F')); || (*ptr2 >= 'A' && *ptr2 <= 'F'));
ptr2++) ptr2++)
if (!grub_isspace (*ptr2)) if (!grub_isspace (*ptr2))
datalen++; datalen++;
datalen /= 2; datalen /= 2;
if (nvramptr - nvram + datalen > nvramsize) if (nvramptr - nvram + datalen > nvramsize)
{ {
grub_free (buf); grub_free (buf);
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"file is too large for reserved " "file is too large for reserved "
" variable space"); " variable space");
} }
for (i = 0; i < 2 * datalen; i++) for (i = 0; i < 2 * datalen; i++)
{ {
int hex = 0; int hex = 0;
@ -258,7 +258,7 @@ read_pnvram (char *filename)
hex = *ptr - 'a' + 10; hex = *ptr - 'a' + 10;
if (*ptr >= 'A' && *ptr <= 'F') if (*ptr >= 'A' && *ptr <= 'F')
hex = *ptr - 'A' + 10; hex = *ptr - 'A' + 10;
if (i%2 == 0) if (i%2 == 0)
nvramptr[i/2] = hex << 4; nvramptr[i/2] = hex << 4;
else else
@ -278,7 +278,7 @@ read_pnvram (char *filename)
efivar->size = datalen; efivar->size = datalen;
else else
efivar->namelen = datalen; efivar->namelen = datalen;
ptr++; ptr++;
} }
} }
@ -304,23 +304,23 @@ grub_efiemu_make_nvram (void)
grub_free (nvram); grub_free (nvram);
return err; return err;
} }
nvram_handle nvram_handle
= grub_efiemu_request_memalign (1, nvramsize, = grub_efiemu_request_memalign (1, nvramsize,
GRUB_EFI_RUNTIME_SERVICES_DATA); GRUB_EFI_RUNTIME_SERVICES_DATA);
nvramsize_handle nvramsize_handle
= grub_efiemu_request_memalign (1, sizeof (grub_uint32_t), = grub_efiemu_request_memalign (1, sizeof (grub_uint32_t),
GRUB_EFI_RUNTIME_SERVICES_DATA); GRUB_EFI_RUNTIME_SERVICES_DATA);
high_monotonic_count_handle high_monotonic_count_handle
= grub_efiemu_request_memalign (1, sizeof (grub_uint32_t), = grub_efiemu_request_memalign (1, sizeof (grub_uint32_t),
GRUB_EFI_RUNTIME_SERVICES_DATA); GRUB_EFI_RUNTIME_SERVICES_DATA);
timezone_handle timezone_handle
= grub_efiemu_request_memalign (1, sizeof (grub_uint16_t), = grub_efiemu_request_memalign (1, sizeof (grub_uint16_t),
GRUB_EFI_RUNTIME_SERVICES_DATA); GRUB_EFI_RUNTIME_SERVICES_DATA);
daylight_handle daylight_handle
= grub_efiemu_request_memalign (1, sizeof (grub_uint8_t), = grub_efiemu_request_memalign (1, sizeof (grub_uint8_t),
GRUB_EFI_RUNTIME_SERVICES_DATA); GRUB_EFI_RUNTIME_SERVICES_DATA);
accuracy_handle accuracy_handle
= grub_efiemu_request_memalign (1, sizeof (grub_uint32_t), = grub_efiemu_request_memalign (1, sizeof (grub_uint32_t),
GRUB_EFI_RUNTIME_SERVICES_DATA); GRUB_EFI_RUNTIME_SERVICES_DATA);
grub_efiemu_request_symbols (6); grub_efiemu_request_symbols (6);
@ -341,7 +341,7 @@ grub_efiemu_pnvram (void)
nvram = grub_malloc (nvramsize); nvram = grub_malloc (nvramsize);
if (!nvram) if (!nvram)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't allocate space for temporary pnvram storage"); "Couldn't allocate space for temporary pnvram storage");
grub_memset (nvram, 0, nvramsize); grub_memset (nvram, 0, nvramsize);
@ -360,16 +360,16 @@ grub_cmd_efiemu_pnvram (struct grub_extcmd *cmd,
nvramsize = state[0].set ? grub_strtoul (state[0].arg, 0, 0) : 2048; nvramsize = state[0].set ? grub_strtoul (state[0].arg, 0, 0) : 2048;
high_monotonic_count = state[1].set ? grub_strtoul (state[1].arg, 0, 0) : 1; high_monotonic_count = state[1].set ? grub_strtoul (state[1].arg, 0, 0) : 1;
timezone = state[2].set ? grub_strtosl (state[2].arg, 0, 0) timezone = state[2].set ? grub_strtosl (state[2].arg, 0, 0)
: GRUB_EFI_UNSPECIFIED_TIMEZONE; : GRUB_EFI_UNSPECIFIED_TIMEZONE;
accuracy = state[3].set ? grub_strtoul (state[3].arg, 0, 0) : 50000000; accuracy = state[3].set ? grub_strtoul (state[3].arg, 0, 0) : 50000000;
daylight = state[4].set ? grub_strtoul (state[4].arg, 0, 0) : 0; daylight = state[4].set ? grub_strtoul (state[4].arg, 0, 0) : 0;
nvram = grub_malloc (nvramsize); nvram = grub_malloc (nvramsize);
if (!nvram) if (!nvram)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't allocate space for temporary pnvram storage"); "Couldn't allocate space for temporary pnvram storage");
grub_memset (nvram, 0, nvramsize); grub_memset (nvram, 0, nvramsize);
if (argc == 1 && (err = read_pnvram (args[0]))) if (argc == 1 && (err = read_pnvram (args[0])))
{ {
@ -387,11 +387,11 @@ void grub_efiemu_pnvram_cmd_unregister (void);
void void
grub_efiemu_pnvram_cmd_register (void) grub_efiemu_pnvram_cmd_register (void)
{ {
cmd = grub_register_extcmd ("efiemu_pnvram", grub_cmd_efiemu_pnvram, cmd = grub_register_extcmd ("efiemu_pnvram", grub_cmd_efiemu_pnvram,
GRUB_COMMAND_FLAG_BOTH, GRUB_COMMAND_FLAG_BOTH,
"efiemu_pnvram [FILENAME]", "efiemu_pnvram [FILENAME]",
"Initialise pseudo-NVRAM and load variables " "Initialise pseudo-NVRAM and load variables "
"from FILE", "from FILE",
options); options);
} }

View file

@ -1,4 +1,4 @@
/* Prepare efiemu. E.g. allocate memory, load the runtime /* Prepare efiemu. E.g. allocate memory, load the runtime
to appropriate place, etc */ to appropriate place, etc */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
@ -26,7 +26,7 @@
grub_err_t grub_err_t
SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks, SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
struct grub_efiemu_configuration_table struct grub_efiemu_configuration_table
*config_tables) *config_tables)
{ {
grub_err_t err; grub_err_t err;
@ -46,8 +46,8 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
/* Request space for the list of configuration tables */ /* Request space for the list of configuration tables */
for (cur = config_tables; cur; cur = cur->next) for (cur = config_tables; cur; cur = cur->next)
cntconftables++; cntconftables++;
conftable_handle conftable_handle
= grub_efiemu_request_memalign (GRUB_EFIEMU_PAGESIZE, = grub_efiemu_request_memalign (GRUB_EFIEMU_PAGESIZE,
cntconftables * sizeof (*conftables), cntconftables * sizeof (*conftables),
GRUB_EFI_RUNTIME_SERVICES_DATA); GRUB_EFI_RUNTIME_SERVICES_DATA);
@ -69,31 +69,31 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
return err; return err;
} }
if ((err = grub_efiemu_resolve_symbol ("efiemu_system_table", if ((err = grub_efiemu_resolve_symbol ("efiemu_system_table",
&handle, &off))) &handle, &off)))
{ {
grub_efiemu_unload (); grub_efiemu_unload ();
return err; return err;
} }
SUFFIX (grub_efiemu_system_table) SUFFIX (grub_efiemu_system_table)
= (TYPE (grub_efi_system_table) *) = (TYPE (grub_efi_system_table) *)
((grub_uint8_t *)grub_efiemu_mm_obtain_request (handle) + off); ((grub_uint8_t *)grub_efiemu_mm_obtain_request (handle) + off);
/* compute CRC32 of runtime_services */ /* compute CRC32 of runtime_services */
if ((err = grub_efiemu_resolve_symbol ("efiemu_runtime_services", if ((err = grub_efiemu_resolve_symbol ("efiemu_runtime_services",
&handle, &off))) &handle, &off)))
return err; return err;
runtime_services = (TYPE (grub_efiemu_runtime_services) *) runtime_services = (TYPE (grub_efiemu_runtime_services) *)
((grub_uint8_t *)grub_efiemu_mm_obtain_request (handle) + off); ((grub_uint8_t *)grub_efiemu_mm_obtain_request (handle) + off);
runtime_services->hdr.crc32 = 0; runtime_services->hdr.crc32 = 0;
runtime_services->hdr.crc32 = grub_getcrc32 runtime_services->hdr.crc32 = grub_getcrc32
(0, runtime_services, runtime_services->hdr.header_size); (0, runtime_services, runtime_services->hdr.header_size);
/* Put pointer to the list of configuration tables in system table */ /* Put pointer to the list of configuration tables in system table */
grub_efiemu_write_value grub_efiemu_write_value
(&(SUFFIX (grub_efiemu_system_table)->configuration_table), 0, (&(SUFFIX (grub_efiemu_system_table)->configuration_table), 0,
conftable_handle, 0, 1, conftable_handle, 0, 1,
sizeof (SUFFIX (grub_efiemu_system_table)->configuration_table)); sizeof (SUFFIX (grub_efiemu_system_table)->configuration_table));
SUFFIX(grub_efiemu_system_table)->num_table_entries = cntconftables; SUFFIX(grub_efiemu_system_table)->num_table_entries = cntconftables;
@ -103,7 +103,7 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
i = 0; i = 0;
for (cur = config_tables; cur; cur = cur->next, i++) for (cur = config_tables; cur; cur = cur->next, i++)
{ {
grub_memcpy (&(conftables[i].vendor_guid), &(cur->guid), grub_memcpy (&(conftables[i].vendor_guid), &(cur->guid),
sizeof (cur->guid)); sizeof (cur->guid));
if (cur->get_table) if (cur->get_table)
conftables[i].vendor_table conftables[i].vendor_table
@ -114,13 +114,13 @@ SUFFIX (grub_efiemu_prepare) (struct grub_efiemu_prepare_hook *prepare_hooks,
/* compute CRC32 of system table */ /* compute CRC32 of system table */
SUFFIX (grub_efiemu_system_table)->hdr.crc32 = 0; SUFFIX (grub_efiemu_system_table)->hdr.crc32 = 0;
SUFFIX (grub_efiemu_system_table)->hdr.crc32 SUFFIX (grub_efiemu_system_table)->hdr.crc32
= grub_getcrc32 (0, SUFFIX (grub_efiemu_system_table), = grub_getcrc32 (0, SUFFIX (grub_efiemu_system_table),
SUFFIX (grub_efiemu_system_table)->hdr.header_size); SUFFIX (grub_efiemu_system_table)->hdr.header_size);
grub_dprintf ("efiemu","system_table = %p, runtime_services = %p," grub_dprintf ("efiemu","system_table = %p, runtime_services = %p,"
" conftables = %p (%d entries)\n", " conftables = %p (%d entries)\n",
SUFFIX (grub_efiemu_system_table), runtime_services, SUFFIX (grub_efiemu_system_table), runtime_services,
conftables, cntconftables); conftables, cntconftables);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;

View file

@ -29,10 +29,10 @@
* %rcx, %rdx, %r8, %r9, 32(%rsp), 40(%rsp), 48(%rsp), ... * %rcx, %rdx, %r8, %r9, 32(%rsp), 40(%rsp), 48(%rsp), ...
* *
*/ */
.file "efiemu.S" .file "efiemu.S"
.text .text
FUNCTION (efiemu_get_time) FUNCTION (efiemu_get_time)
push %rdi push %rdi
push %rsi push %rsi
@ -104,7 +104,7 @@ FUNCTION (efiemu_set_variable)
mov %rcx, %rdi mov %rcx, %rdi
mov %rdx, %rsi mov %rdx, %rsi
mov %r8, %rdx mov %r8, %rdx
mov %r9, %rcx mov %r9, %rcx
mov 56(%rsp), %r8 mov 56(%rsp), %r8
call efiemu_set_variable_real call efiemu_set_variable_real
pop %rsi pop %rsi
@ -133,8 +133,8 @@ FUNCTION (efiemu_reset_system)
ret ret
/* The following functions are always called in physical mode */ /* The following functions are always called in physical mode */
.section ".text-physical", "ax" .section ".text-physical", "ax"
FUNCTION (efiemu_set_virtual_address_map) FUNCTION (efiemu_set_virtual_address_map)
push %rdi push %rdi
push %rsi push %rsi

View file

@ -17,8 +17,8 @@
*/ */
/* This is an emulation of EFI runtime services. /* This is an emulation of EFI runtime services.
This allows a more uniform boot on i386 machines. This allows a more uniform boot on i386 machines.
As it emulates only runtime serviceit isn't able As it emulates only runtime serviceit isn't able
to chainload EFI bootloader on non-EFI system (TODO) */ to chainload EFI bootloader on non-EFI system (TODO) */
#include <grub/symbol.h> #include <grub/symbol.h>
@ -26,7 +26,7 @@
#include <grub/efi/api.h> #include <grub/efi/api.h>
#include <grub/efiemu/runtime.h> #include <grub/efiemu/runtime.h>
grub_efi_status_t grub_efi_status_t
efiemu_get_time (grub_efi_time_t *time, efiemu_get_time (grub_efi_time_t *time,
grub_efi_time_capabilities_t *capabilities); grub_efi_time_capabilities_t *capabilities);
grub_efi_status_t grub_efi_status_t
@ -54,7 +54,7 @@ efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
PHYSICAL_ATTRIBUTE; PHYSICAL_ATTRIBUTE;
grub_efi_status_t grub_efi_status_t
efiemu_convert_pointer (grub_efi_uintn_t debug_disposition, efiemu_convert_pointer (grub_efi_uintn_t debug_disposition,
void **address) void **address)
PHYSICAL_ATTRIBUTE; PHYSICAL_ATTRIBUTE;
@ -84,14 +84,14 @@ efiemu_reset_system (grub_efi_reset_type_t reset_type,
grub_efi_uintn_t data_size, grub_efi_uintn_t data_size,
grub_efi_char16_t *reset_data); grub_efi_char16_t *reset_data);
grub_efi_status_t grub_efi_status_t
EFI_FUNC (efiemu_set_virtual_address_map) (grub_efi_uintn_t, EFI_FUNC (efiemu_set_virtual_address_map) (grub_efi_uintn_t,
grub_efi_uintn_t, grub_efi_uintn_t,
grub_efi_uint32_t, grub_efi_uint32_t,
grub_efi_memory_descriptor_t *) grub_efi_memory_descriptor_t *)
PHYSICAL_ATTRIBUTE; PHYSICAL_ATTRIBUTE;
grub_efi_status_t grub_efi_status_t
EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition, EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
void **address) void **address)
PHYSICAL_ATTRIBUTE; PHYSICAL_ATTRIBUTE;
static grub_uint32_t static grub_uint32_t
@ -100,15 +100,15 @@ efiemu_getcrc32 (grub_uint32_t crc, void *buf, int size)
static void static void
init_crc32_table (void) init_crc32_table (void)
PHYSICAL_ATTRIBUTE; PHYSICAL_ATTRIBUTE;
static grub_uint32_t static grub_uint32_t
reflect (grub_uint32_t ref, int len) reflect (grub_uint32_t ref, int len)
PHYSICAL_ATTRIBUTE; PHYSICAL_ATTRIBUTE;
/* /*
The log. It's used when examining memory dump The log. It's used when examining memory dump
*/ */
static grub_uint8_t loge[1000] = "EFIEMULOG"; static grub_uint8_t loge[1000] = "EFIEMULOG";
static int logn = 9; static int logn = 9;
#define LOG(x) { if (logn<900) loge[logn++]=x; } #define LOG(x) { if (logn<900) loge[logn++]=x; }
static int ptv_relocated = 0; static int ptv_relocated = 0;
@ -189,7 +189,7 @@ int __stack_chk_fail ()
return 0; return 0;
} }
/* The function that implement runtime services as specified in /* The function that implement runtime services as specified in
EFI specification */ EFI specification */
static inline grub_uint8_t static inline grub_uint8_t
bcd_to_hex (grub_uint8_t in) bcd_to_hex (grub_uint8_t in)
@ -197,7 +197,7 @@ bcd_to_hex (grub_uint8_t in)
return 10 * ((in & 0xf0) >> 4) + (in & 0x0f); return 10 * ((in & 0xf0) >> 4) + (in & 0x0f);
} }
grub_efi_status_t grub_efi_status_t
EFI_FUNC (efiemu_get_time) (grub_efi_time_t *time, EFI_FUNC (efiemu_get_time) (grub_efi_time_t *time,
grub_efi_time_capabilities_t *capabilities) grub_efi_time_capabilities_t *capabilities)
{ {
@ -279,19 +279,19 @@ EFI_FUNC (efiemu_set_wakeup_time) (grub_efi_boolean_t enabled,
static grub_uint32_t crc32_table [256]; static grub_uint32_t crc32_table [256];
static grub_uint32_t static grub_uint32_t
reflect (grub_uint32_t ref, int len) reflect (grub_uint32_t ref, int len)
{ {
grub_uint32_t result = 0; grub_uint32_t result = 0;
int i; int i;
for (i = 1; i <= len; i++) for (i = 1; i <= len; i++)
{ {
if (ref & 1) if (ref & 1)
result |= 1 << (len - i); result |= 1 << (len - i);
ref >>= 1; ref >>= 1;
} }
return result; return result;
} }
@ -332,7 +332,7 @@ efiemu_getcrc32 (grub_uint32_t crc, void *buf, int size)
} }
grub_efi_status_t EFI_FUNC grub_efi_status_t EFI_FUNC
(efiemu_set_virtual_address_map) (grub_efi_uintn_t memory_map_size, (efiemu_set_virtual_address_map) (grub_efi_uintn_t memory_map_size,
grub_efi_uintn_t descriptor_size, grub_efi_uintn_t descriptor_size,
grub_efi_uint32_t descriptor_version, grub_efi_uint32_t descriptor_version,
@ -341,12 +341,12 @@ grub_efi_status_t EFI_FUNC
struct grub_efiemu_ptv_rel *cur_relloc; struct grub_efiemu_ptv_rel *cur_relloc;
LOG ('e'); LOG ('e');
/* Ensure that we are called only once */ /* Ensure that we are called only once */
if (ptv_relocated) if (ptv_relocated)
return GRUB_EFI_UNSUPPORTED; return GRUB_EFI_UNSUPPORTED;
ptv_relocated = 1; ptv_relocated = 1;
/* Correct addresses using information supplied by grub */ /* Correct addresses using information supplied by grub */
for (cur_relloc = efiemu_ptv_relloc; cur_relloc->size;cur_relloc++) for (cur_relloc = efiemu_ptv_relloc; cur_relloc->size;cur_relloc++)
{ {
@ -354,8 +354,8 @@ grub_efi_status_t EFI_FUNC
grub_efi_memory_descriptor_t *descptr; grub_efi_memory_descriptor_t *descptr;
/* Compute correction */ /* Compute correction */
for (descptr = virtual_map; for (descptr = virtual_map;
((grub_uint8_t *) descptr - (grub_uint8_t *) virtual_map) ((grub_uint8_t *) descptr - (grub_uint8_t *) virtual_map)
< memory_map_size; < memory_map_size;
descptr = (grub_efi_memory_descriptor_t *) descptr = (grub_efi_memory_descriptor_t *)
((grub_uint8_t *) descptr + descriptor_size)) ((grub_uint8_t *) descptr + descriptor_size))
@ -386,27 +386,27 @@ grub_efi_status_t EFI_FUNC
/* Recompute crc32 of system table and runtime services */ /* Recompute crc32 of system table and runtime services */
efiemu_system_table.hdr.crc32 = 0; efiemu_system_table.hdr.crc32 = 0;
efiemu_system_table.hdr.crc32 = efiemu_getcrc32 efiemu_system_table.hdr.crc32 = efiemu_getcrc32
(0, &efiemu_system_table, sizeof (efiemu_system_table)); (0, &efiemu_system_table, sizeof (efiemu_system_table));
efiemu_runtime_services.hdr.crc32 = 0; efiemu_runtime_services.hdr.crc32 = 0;
efiemu_runtime_services.hdr.crc32 = efiemu_getcrc32 efiemu_runtime_services.hdr.crc32 = efiemu_getcrc32
(0, &efiemu_runtime_services, sizeof (efiemu_runtime_services)); (0, &efiemu_runtime_services, sizeof (efiemu_runtime_services));
return GRUB_EFI_SUCCESS; return GRUB_EFI_SUCCESS;
} }
/* since efiemu_set_virtual_address_map corrects all the pointers /* since efiemu_set_virtual_address_map corrects all the pointers
we don't need efiemu_convert_pointer */ we don't need efiemu_convert_pointer */
grub_efi_status_t grub_efi_status_t
EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition, EFI_FUNC (efiemu_convert_pointer) (grub_efi_uintn_t debug_disposition,
void **address) void **address)
{ {
LOG ('f'); LOG ('f');
return GRUB_EFI_UNSUPPORTED; return GRUB_EFI_UNSUPPORTED;
} }
/* Next comes variable services. Because we have no vendor-independent /* Next comes variable services. Because we have no vendor-independent
way to store these variables we have no non-volatility */ way to store these variables we have no non-volatility */
/* Find variable by name and GUID. */ /* Find variable by name and GUID. */
@ -423,7 +423,7 @@ find_variable (grub_efi_guid_t *vendor_guid,
if (!efivar->namelen) if (!efivar->namelen)
return 0; return 0;
if (efiemu_str16equal((grub_efi_char16_t *)(efivar + 1), variable_name) if (efiemu_str16equal((grub_efi_char16_t *)(efivar + 1), variable_name)
&& efiemu_memequal (&(efivar->guid), vendor_guid, && efiemu_memequal (&(efivar->guid), vendor_guid,
sizeof (efivar->guid))) sizeof (efivar->guid)))
return efivar; return efivar;
ptr += efivar->namelen + efivar->size + sizeof (*efivar); ptr += efivar->namelen + efivar->size + sizeof (*efivar);
@ -452,11 +452,11 @@ EFI_FUNC (efiemu_get_variable) (grub_efi_char16_t *variable_name,
efiemu_memcpy (data, (grub_uint8_t *)(efivar + 1) + efivar->namelen, efiemu_memcpy (data, (grub_uint8_t *)(efivar + 1) + efivar->namelen,
efivar->size); efivar->size);
*attributes = efivar->attributes; *attributes = efivar->attributes;
return GRUB_EFI_SUCCESS; return GRUB_EFI_SUCCESS;
} }
grub_efi_status_t EFI_FUNC grub_efi_status_t EFI_FUNC
(efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size, (efiemu_get_next_variable_name) (grub_efi_uintn_t *variable_name_size,
grub_efi_char16_t *variable_name, grub_efi_char16_t *variable_name,
grub_efi_guid_t *vendor_guid) grub_efi_guid_t *vendor_guid)
@ -471,15 +471,15 @@ grub_efi_status_t EFI_FUNC
efivar = find_variable (vendor_guid, variable_name); efivar = find_variable (vendor_guid, variable_name);
if (!efivar) if (!efivar)
return GRUB_EFI_NOT_FOUND; return GRUB_EFI_NOT_FOUND;
efivar = (struct efi_variable *)((grub_uint8_t *)efivar efivar = (struct efi_variable *)((grub_uint8_t *)efivar
+ efivar->namelen + efivar->namelen
+ efivar->size + sizeof (*efivar)); + efivar->size + sizeof (*efivar));
} }
else else
efivar = (struct efi_variable *) (efiemu_variables); efivar = (struct efi_variable *) (efiemu_variables);
LOG ('m'); LOG ('m');
if ((grub_uint8_t *)efivar >= efiemu_variables + efiemu_varsize if ((grub_uint8_t *)efivar >= efiemu_variables + efiemu_varsize
|| !efivar->namelen) || !efivar->namelen)
return GRUB_EFI_NOT_FOUND; return GRUB_EFI_NOT_FOUND;
if (*variable_name_size < efivar->namelen) if (*variable_name_size < efivar->namelen)
@ -489,7 +489,7 @@ grub_efi_status_t EFI_FUNC
} }
efiemu_memcpy (variable_name, efivar + 1, efivar->namelen); efiemu_memcpy (variable_name, efivar + 1, efivar->namelen);
efiemu_memcpy (vendor_guid, &(efivar->guid), efiemu_memcpy (vendor_guid, &(efivar->guid),
sizeof (efivar->guid)); sizeof (efivar->guid));
LOG('h'); LOG('h');
@ -513,12 +513,12 @@ EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
/* Delete variable if any */ /* Delete variable if any */
if (efivar) if (efivar)
{ {
efiemu_memcpy (efivar, (grub_uint8_t *)(efivar + 1) efiemu_memcpy (efivar, (grub_uint8_t *)(efivar + 1)
+ efivar->namelen + efivar->size, + efivar->namelen + efivar->size,
(efiemu_variables + efiemu_varsize) (efiemu_variables + efiemu_varsize)
- ((grub_uint8_t *)(efivar + 1) - ((grub_uint8_t *)(efivar + 1)
+ efivar->namelen + efivar->size)); + efivar->namelen + efivar->size));
efiemu_memset (efiemu_variables + efiemu_varsize efiemu_memset (efiemu_variables + efiemu_varsize
- (sizeof (*efivar) + efivar->namelen + efivar->size), - (sizeof (*efivar) + efivar->namelen + efivar->size),
0, (sizeof (*efivar) + efivar->namelen + efivar->size)); 0, (sizeof (*efivar) + efivar->namelen + efivar->size));
} }
@ -533,8 +533,8 @@ EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
if (!efivar->namelen) if (!efivar->namelen)
break; break;
} }
if ((grub_uint8_t *)(efivar + 1) + data_size if ((grub_uint8_t *)(efivar + 1) + data_size
+ 2 * (efiemu_str16len (variable_name) + 1) + 2 * (efiemu_str16len (variable_name) + 1)
>= efiemu_variables + efiemu_varsize) >= efiemu_variables + efiemu_varsize)
return GRUB_EFI_OUT_OF_RESOURCES; return GRUB_EFI_OUT_OF_RESOURCES;
@ -542,16 +542,16 @@ EFI_FUNC (efiemu_set_variable) (grub_efi_char16_t *variable_name,
efivar->namelen = 2 * (efiemu_str16len (variable_name) + 1); efivar->namelen = 2 * (efiemu_str16len (variable_name) + 1);
efivar->size = data_size; efivar->size = data_size;
efivar->attributes = attributes; efivar->attributes = attributes;
efiemu_memcpy (efivar + 1, variable_name, efiemu_memcpy (efivar + 1, variable_name,
2 * (efiemu_str16len (variable_name) + 1)); 2 * (efiemu_str16len (variable_name) + 1));
efiemu_memcpy ((grub_uint8_t *)(efivar + 1) efiemu_memcpy ((grub_uint8_t *)(efivar + 1)
+ 2 * (efiemu_str16len (variable_name) + 1), + 2 * (efiemu_str16len (variable_name) + 1),
data, data_size); data, data_size);
return GRUB_EFI_SUCCESS; return GRUB_EFI_SUCCESS;
} }
grub_efi_status_t EFI_FUNC grub_efi_status_t EFI_FUNC
(efiemu_get_next_high_monotonic_count) (grub_efi_uint32_t *high_count) (efiemu_get_next_high_monotonic_count) (grub_efi_uint32_t *high_count)
{ {
LOG ('j'); LOG ('j');
@ -574,9 +574,9 @@ EFI_FUNC (efiemu_reset_system) (grub_efi_reset_type_t reset_type,
LOG ('k'); LOG ('k');
} }
struct grub_efi_runtime_services efiemu_runtime_services = struct grub_efi_runtime_services efiemu_runtime_services =
{ {
.hdr = .hdr =
{ {
.signature = GRUB_EFIEMU_RUNTIME_SERVICES_SIGNATURE, .signature = GRUB_EFIEMU_RUNTIME_SERVICES_SIGNATURE,
.revision = 0x0001000a, .revision = 0x0001000a,
@ -596,18 +596,18 @@ struct grub_efi_runtime_services efiemu_runtime_services =
.get_next_variable_name = efiemu_get_next_variable_name, .get_next_variable_name = efiemu_get_next_variable_name,
.set_variable = efiemu_set_variable, .set_variable = efiemu_set_variable,
.get_next_high_monotonic_count = efiemu_get_next_high_monotonic_count, .get_next_high_monotonic_count = efiemu_get_next_high_monotonic_count,
.reset_system = efiemu_reset_system .reset_system = efiemu_reset_system
}; };
static grub_uint16_t efiemu_vendor[] = static grub_uint16_t efiemu_vendor[] =
{'G', 'R', 'U', 'B', ' ', 'E', 'F', 'I', ' ', {'G', 'R', 'U', 'B', ' ', 'E', 'F', 'I', ' ',
'R', 'U', 'N', 'T', 'I', 'M', 'E', 0}; 'R', 'U', 'N', 'T', 'I', 'M', 'E', 0};
struct grub_efi_system_table efiemu_system_table = struct grub_efi_system_table efiemu_system_table =
{ {
.hdr = .hdr =
{ {
.signature = GRUB_EFIEMU_SYSTEM_TABLE_SIGNATURE, .signature = GRUB_EFIEMU_SYSTEM_TABLE_SIGNATURE,
.revision = 0x0001000a, .revision = 0x0001000a,

View file

@ -1,4 +1,4 @@
gcc -c -m32 -DELF32 -o efiemu32.o ./efiemu.c -Wall -Werror -nostdlib -O2 -I. -I../../include gcc -c -m32 -DELF32 -o efiemu32.o ./efiemu.c -Wall -Werror -nostdlib -O2 -I. -I../../include
gcc -c -m64 -DELF64 -o efiemu64_c.o ./efiemu.c -Wall -Werror -mcmodel=large -O2 -I. -I../../include gcc -c -m64 -DELF64 -o efiemu64_c.o ./efiemu.c -Wall -Werror -mcmodel=large -O2 -I. -I../../include
gcc -c -m64 -DELF64 -o efiemu64_s.o ./efiemu.S -Wall -Werror -mcmodel=large -O2 -I. -I../../include gcc -c -m64 -DELF64 -o efiemu64_s.o ./efiemu.S -Wall -Werror -mcmodel=large -O2 -I. -I../../include
ld -o efiemu64.o -r efiemu64_s.o efiemu64_c.o -nostdlib ld -o efiemu64.o -r efiemu64_s.o efiemu64_c.o -nostdlib

View file

@ -57,16 +57,16 @@ grub_efiemu_free_syms (void)
} }
/* Announce that the module will need NUM allocators */ /* Announce that the module will need NUM allocators */
/* Because of deferred memory allocation all the relocators have to be /* Because of deferred memory allocation all the relocators have to be
announced during phase 1*/ announced during phase 1*/
grub_err_t grub_err_t
grub_efiemu_request_symbols (int num) grub_efiemu_request_symbols (int num)
{ {
if (ptv_alloc) if (ptv_alloc)
return grub_error (GRUB_ERR_BAD_ARGUMENT, return grub_error (GRUB_ERR_BAD_ARGUMENT,
"symbols have already been allocated"); "symbols have already been allocated");
if (num < 0) if (num < 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, return grub_error (GRUB_ERR_BAD_ARGUMENT,
"can't request negative symbols"); "can't request negative symbols");
ptv_requested += num; ptv_requested += num;
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
@ -111,15 +111,15 @@ grub_err_t
grub_efiemu_alloc_syms (void) grub_efiemu_alloc_syms (void)
{ {
ptv_alloc = ptv_requested; ptv_alloc = ptv_requested;
ptv_handle = grub_efiemu_request_memalign ptv_handle = grub_efiemu_request_memalign
(1, (ptv_requested + 1) * sizeof (struct grub_efiemu_ptv_rel), (1, (ptv_requested + 1) * sizeof (struct grub_efiemu_ptv_rel),
GRUB_EFI_RUNTIME_SERVICES_DATA); GRUB_EFI_RUNTIME_SERVICES_DATA);
grub_efiemu_register_symbol ("efiemu_ptv_relloc", ptv_handle, 0); grub_efiemu_register_symbol ("efiemu_ptv_relloc", ptv_handle, 0);
return grub_errno; return grub_errno;
} }
/* Write value (pointer to memory PLUS_HANDLE) /* Write value (pointer to memory PLUS_HANDLE)
- (pointer to memory MINUS_HANDLE) + VALUE to ADDR assuming that the - (pointer to memory MINUS_HANDLE) + VALUE to ADDR assuming that the
size SIZE bytes. If PTV_NEEDED is 1 then announce it to runtime that this size SIZE bytes. If PTV_NEEDED is 1 then announce it to runtime that this
value needs to be recomputed before going to virtual mode value needs to be recomputed before going to virtual mode
*/ */
@ -130,22 +130,22 @@ grub_efiemu_write_value (void *addr, grub_uint32_t value, int plus_handle,
/* Announce relocator to runtime */ /* Announce relocator to runtime */
if (ptv_needed) if (ptv_needed)
{ {
struct grub_efiemu_ptv_rel *ptv_rels struct grub_efiemu_ptv_rel *ptv_rels
= grub_efiemu_mm_obtain_request (ptv_handle); = grub_efiemu_mm_obtain_request (ptv_handle);
if (ptv_needed && ptv_written >= ptv_alloc) if (ptv_needed && ptv_written >= ptv_alloc)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"your module didn't declare efiemu " "your module didn't declare efiemu "
" relocators correctly"); " relocators correctly");
if (minus_handle) if (minus_handle)
ptv_rels[ptv_written].minustype ptv_rels[ptv_written].minustype
= grub_efiemu_mm_get_type (minus_handle); = grub_efiemu_mm_get_type (minus_handle);
else else
ptv_rels[ptv_written].minustype = 0; ptv_rels[ptv_written].minustype = 0;
if (plus_handle) if (plus_handle)
ptv_rels[ptv_written].plustype ptv_rels[ptv_written].plustype
= grub_efiemu_mm_get_type (plus_handle); = grub_efiemu_mm_get_type (plus_handle);
else else
ptv_rels[ptv_written].plustype = 0; ptv_rels[ptv_written].plustype = 0;
@ -153,7 +153,7 @@ grub_efiemu_write_value (void *addr, grub_uint32_t value, int plus_handle,
ptv_rels[ptv_written].addr = PTR_TO_UINT64 (addr); ptv_rels[ptv_written].addr = PTR_TO_UINT64 (addr);
ptv_rels[ptv_written].size = size; ptv_rels[ptv_written].size = size;
ptv_written++; ptv_written++;
/* memset next value to zero to mark the end */ /* memset next value to zero to mark the end */
grub_memset (&ptv_rels[ptv_written], 0, sizeof (ptv_rels[ptv_written])); grub_memset (&ptv_rels[ptv_written], 0, sizeof (ptv_rels[ptv_written]));
} }

View file

@ -36,7 +36,7 @@ struct char_index_entry
grub_uint32_t code; grub_uint32_t code;
grub_uint8_t storage_flags; grub_uint8_t storage_flags;
grub_uint32_t offset; grub_uint32_t offset;
/* Glyph if loaded, or NULL otherwise. */ /* Glyph if loaded, or NULL otherwise. */
struct grub_font_glyph *glyph; struct grub_font_glyph *glyph;
}; };
@ -72,13 +72,13 @@ struct font_file_section
{ {
/* The file this section is in. */ /* The file this section is in. */
grub_file_t file; grub_file_t file;
/* FOURCC name of the section. */ /* FOURCC name of the section. */
char name[4]; char name[4];
/* Length of the section contents. */ /* Length of the section contents. */
grub_uint32_t length; grub_uint32_t length;
/* Set by open_section() on EOF. */ /* Set by open_section() on EOF. */
int eof; int eof;
}; };
@ -170,10 +170,10 @@ font_init (grub_font_t font)
font->family = 0; font->family = 0;
font->point_size = 0; font->point_size = 0;
font->weight = 0; font->weight = 0;
/* Default leading value, not in font file yet. */ /* Default leading value, not in font file yet. */
font->leading = 1; font->leading = 1;
font->max_char_width = 0; font->max_char_width = 0;
font->max_char_height = 0; font->max_char_height = 0;
font->ascent = 0; font->ascent = 0;
@ -646,7 +646,7 @@ grub_font_get_glyph_internal (grub_font_t font, grub_uint32_t code)
if (! font->file) if (! font->file)
/* No open file, can't load any glyphs. */ /* No open file, can't load any glyphs. */
return 0; return 0;
/* Make sure we can find glyphs for error messages. Push active /* Make sure we can find glyphs for error messages. Push active
error message to error stack and reset error message. */ error message to error stack and reset error message. */
@ -900,7 +900,7 @@ get_font_diversity(grub_font_t a, grub_font_t b)
else else
/* Penalty for missing attributes. */ /* Penalty for missing attributes. */
d += 50; d += 50;
/* Weight is a minor factor. */ /* Weight is a minor factor. */
d += (a->weight != b->weight) ? 5 : 0; d += (a->weight != b->weight) ? 5 : 0;
@ -991,13 +991,13 @@ grub_font_draw_glyph (struct grub_font_glyph *glyph,
| GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP; | GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP;
glyph_bitmap.mode_info.blit_format = GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED; glyph_bitmap.mode_info.blit_format = GRUB_VIDEO_BLIT_FORMAT_1BIT_PACKED;
glyph_bitmap.mode_info.bpp = 1; glyph_bitmap.mode_info.bpp = 1;
/* Really 1 bit per pixel. */ /* Really 1 bit per pixel. */
glyph_bitmap.mode_info.bytes_per_pixel = 0; glyph_bitmap.mode_info.bytes_per_pixel = 0;
/* Packed densely as bits. */ /* Packed densely as bits. */
glyph_bitmap.mode_info.pitch = glyph->width; glyph_bitmap.mode_info.pitch = glyph->width;
glyph_bitmap.mode_info.number_of_colors = 2; glyph_bitmap.mode_info.number_of_colors = 2;
glyph_bitmap.mode_info.bg_red = 0; glyph_bitmap.mode_info.bg_red = 0;
glyph_bitmap.mode_info.bg_green = 0; glyph_bitmap.mode_info.bg_green = 0;

View file

@ -71,7 +71,7 @@ GRUB_MOD_INIT(font_manager)
GRUB_MOD_FINI(font_manager) GRUB_MOD_FINI(font_manager)
{ {
/* TODO: Determine way to free allocated resources. /* TODO: Determine way to free allocated resources.
Warning: possible pointer references could be in use. */ Warning: possible pointer references could be in use. */
grub_unregister_command (cmd_loadfont); grub_unregister_command (cmd_loadfont);

View file

@ -127,7 +127,7 @@ grub_affs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
sizeof (file), &file); sizeof (file), &file);
if (grub_errno) if (grub_errno)
return 0; return 0;
block = grub_be_to_cpu32 (file.extension); block = grub_be_to_cpu32 (file.extension);
} }
@ -139,7 +139,7 @@ grub_affs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
sizeof (pos), &pos); sizeof (pos), &pos);
if (grub_errno) if (grub_errno)
return 0; return 0;
return grub_be_to_cpu32 (pos); return grub_be_to_cpu32 (pos);
} }
@ -353,7 +353,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
sizeof (file), (char *) &file); sizeof (file), (char *) &file);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
file.name[file.namelen] = '\0'; file.name[file.namelen] = '\0';
if ((int) grub_be_to_cpu32 (file.type) == GRUB_AFFS_FILETYPE_DIR) if ((int) grub_be_to_cpu32 (file.type) == GRUB_AFFS_FILETYPE_DIR)
@ -370,7 +370,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir,
return 1; return 1;
next = grub_be_to_cpu32 (file.next); next = grub_be_to_cpu32 (file.next);
} }
} }
grub_free (hashtable); grub_free (hashtable);
@ -389,18 +389,18 @@ grub_affs_open (struct grub_file *file, const char *name)
{ {
struct grub_affs_data *data; struct grub_affs_data *data;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_affs_mount (file->device->disk); data = grub_affs_mount (file->device->disk);
if (!data) if (!data)
goto fail; goto fail;
grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_affs_iterate_dir, grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_affs_iterate_dir,
grub_affs_read_symlink, GRUB_FSHELP_REG); grub_affs_read_symlink, GRUB_FSHELP_REG);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
file->size = fdiro->size; file->size = fdiro->size;
data->diropen = *fdiro; data->diropen = *fdiro;
grub_free (fdiro); grub_free (fdiro);
@ -414,7 +414,7 @@ grub_affs_open (struct grub_file *file, const char *name)
if (data && fdiro != &data->diropen) if (data && fdiro != &data->diropen)
grub_free (fdiro); grub_free (fdiro);
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
@ -436,7 +436,7 @@ grub_affs_close (grub_file_t file)
static grub_ssize_t static grub_ssize_t
grub_affs_read (grub_file_t file, char *buf, grub_size_t len) grub_affs_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_affs_data *data = struct grub_affs_data *data =
(struct grub_affs_data *) file->data; (struct grub_affs_data *) file->data;
int size = grub_affs_read_file (&data->diropen, file->read_hook, int size = grub_affs_read_file (&data->diropen, file->read_hook,
@ -447,13 +447,13 @@ grub_affs_read (grub_file_t file, char *buf, grub_size_t len)
static grub_err_t static grub_err_t
grub_affs_dir (grub_device_t device, const char *path, grub_affs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_affs_data *data = 0; struct grub_affs_data *data = 0;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
auto int NESTED_FUNC_ATTR iterate (const char *filename, auto int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype, enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node); grub_fshelp_node_t node);
@ -470,18 +470,18 @@ grub_affs_dir (grub_device_t device, const char *path,
} }
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_affs_mount (device->disk); data = grub_affs_mount (device->disk);
if (!data) if (!data)
goto fail; goto fail;
grub_fshelp_find_file (path, &data->diropen, &fdiro, grub_affs_iterate_dir, grub_fshelp_find_file (path, &data->diropen, &fdiro, grub_affs_iterate_dir,
grub_affs_read_symlink, GRUB_FSHELP_DIR); grub_affs_read_symlink, GRUB_FSHELP_DIR);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
grub_affs_iterate_dir (fdiro, iterate); grub_affs_iterate_dir (fdiro, iterate);
fail: fail:
if (data && fdiro != &data->diropen) if (data && fdiro != &data->diropen)
grub_free (fdiro); grub_free (fdiro);

View file

@ -554,7 +554,7 @@ grub_afs_close (grub_file_t file)
static grub_err_t static grub_err_t
grub_afs_dir (grub_device_t device, const char *path, grub_afs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_afs_data *data = 0;; struct grub_afs_data *data = 0;;

View file

@ -181,7 +181,7 @@ fail:
static grub_err_t static grub_err_t
grub_cpio_dir (grub_device_t device, const char *path, grub_cpio_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_cpio_data *data; struct grub_cpio_data *data;
@ -286,13 +286,13 @@ grub_cpio_open (grub_file_t file, const char *name)
{ {
if (name[i] != fn[j]) if (name[i] != fn[j])
goto no_match; goto no_match;
if (name[i] == '\0') if (name[i] == '\0')
break; break;
if (name[i] == '/' && name[i+1] == '/') if (name[i] == '/' && name[i+1] == '/')
i++; i++;
i++; i++;
j++; j++;
} }
@ -304,7 +304,7 @@ grub_cpio_open (grub_file_t file, const char *name)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
no_match: no_match:
grub_free (fn); grub_free (fn);
data->hofs = ofs; data->hofs = ofs;
} }

View file

@ -54,7 +54,7 @@
/* Log2 size of ext2 block in 512 blocks. */ /* Log2 size of ext2 block in 512 blocks. */
#define LOG2_EXT2_BLOCK_SIZE(data) \ #define LOG2_EXT2_BLOCK_SIZE(data) \
(grub_le_to_cpu32 (data->sblock.log2_block_size) + 1) (grub_le_to_cpu32 (data->sblock.log2_block_size) + 1)
/* Log2 size of ext2 block in bytes. */ /* Log2 size of ext2 block in bytes. */
#define LOG2_BLOCK_SIZE(data) \ #define LOG2_BLOCK_SIZE(data) \
(grub_le_to_cpu32 (data->sblock.log2_block_size) + 10) (grub_le_to_cpu32 (data->sblock.log2_block_size) + 10)
@ -324,7 +324,7 @@ static grub_dl_t my_mod;
/* Read into BLKGRP the blockgroup descriptor of blockgroup GROUP of /* Read into BLKGRP the blockgroup descriptor of blockgroup GROUP of
the mounted filesystem DATA. */ the mounted filesystem DATA. */
inline static grub_err_t inline static grub_err_t
grub_ext2_blockgroup (struct grub_ext2_data *data, int group, grub_ext2_blockgroup (struct grub_ext2_data *data, int group,
struct grub_ext2_block_group *blkgrp) struct grub_ext2_block_group *blkgrp)
{ {
return grub_disk_read (data->disk, return grub_disk_read (data->disk,
@ -382,7 +382,7 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
int blknr = -1; int blknr = -1;
unsigned int blksz = EXT2_BLOCK_SIZE (data); unsigned int blksz = EXT2_BLOCK_SIZE (data);
int log2_blksz = LOG2_EXT2_BLOCK_SIZE (data); int log2_blksz = LOG2_EXT2_BLOCK_SIZE (data);
if (grub_le_to_cpu32(inode->flags) & EXT4_EXTENTS_FLAG) if (grub_le_to_cpu32(inode->flags) & EXT4_EXTENTS_FLAG)
{ {
char buf[EXT2_BLOCK_SIZE(data)]; char buf[EXT2_BLOCK_SIZE(data)];
@ -440,14 +440,14 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
<< log2_blksz, << log2_blksz,
0, blksz, indir)) 0, blksz, indir))
return grub_errno; return grub_errno;
blknr = grub_le_to_cpu32 (indir[fileblock - INDIRECT_BLOCKS]); blknr = grub_le_to_cpu32 (indir[fileblock - INDIRECT_BLOCKS]);
} }
/* Double indirect. */ /* Double indirect. */
else if (fileblock < INDIRECT_BLOCKS + blksz / 4 * (blksz / 4 + 1)) else if (fileblock < INDIRECT_BLOCKS + blksz / 4 * (blksz / 4 + 1))
{ {
unsigned int perblock = blksz / 4; unsigned int perblock = blksz / 4;
unsigned int rblock = fileblock - (INDIRECT_BLOCKS unsigned int rblock = fileblock - (INDIRECT_BLOCKS
+ blksz / 4); + blksz / 4);
grub_uint32_t indir[blksz / 4]; grub_uint32_t indir[blksz / 4];
@ -463,7 +463,7 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
0, blksz, indir)) 0, blksz, indir))
return grub_errno; return grub_errno;
blknr = grub_le_to_cpu32 (indir[rblock % perblock]); blknr = grub_le_to_cpu32 (indir[rblock % perblock]);
} }
/* triple indirect. */ /* triple indirect. */
@ -488,7 +488,7 @@ grub_ext2_read_file (grub_fshelp_node_t node,
pos, len, buf, grub_ext2_read_block, pos, len, buf, grub_ext2_read_block,
node->inode.size, node->inode.size,
LOG2_EXT2_BLOCK_SIZE (node->data)); LOG2_EXT2_BLOCK_SIZE (node->data));
} }
@ -505,7 +505,7 @@ grub_ext2_read_inode (struct grub_ext2_data *data,
/* It is easier to calculate if the first inode is 0. */ /* It is easier to calculate if the first inode is 0. */
ino--; ino--;
grub_ext2_blockgroup (data, grub_ext2_blockgroup (data,
ino / grub_le_to_cpu32 (sblock->inodes_per_group), ino / grub_le_to_cpu32 (sblock->inodes_per_group),
&blkgrp); &blkgrp);
@ -525,7 +525,7 @@ grub_ext2_read_inode (struct grub_ext2_data *data,
EXT2_INODE_SIZE (data) * blkoff, EXT2_INODE_SIZE (data) * blkoff,
sizeof (struct grub_ext2_inode), inode)) sizeof (struct grub_ext2_inode), inode))
return grub_errno; return grub_errno;
return 0; return 0;
} }
@ -550,7 +550,7 @@ grub_ext2_mount (grub_disk_t disk)
grub_error (GRUB_ERR_BAD_FS, "not an ext2 filesystem"); grub_error (GRUB_ERR_BAD_FS, "not an ext2 filesystem");
goto fail; goto fail;
} }
/* Check the FS doesn't have feature bits enabled that we don't support. */ /* Check the FS doesn't have feature bits enabled that we don't support. */
if (grub_le_to_cpu32 (data->sblock.feature_incompat) if (grub_le_to_cpu32 (data->sblock.feature_incompat)
& ~(EXT2_DRIVER_SUPPORTED_INCOMPAT | EXT2_DRIVER_IGNORED_INCOMPAT)) & ~(EXT2_DRIVER_SUPPORTED_INCOMPAT | EXT2_DRIVER_IGNORED_INCOMPAT))
@ -558,8 +558,8 @@ grub_ext2_mount (grub_disk_t disk)
grub_error (GRUB_ERR_BAD_FS, "filesystem has unsupported incompatible features"); grub_error (GRUB_ERR_BAD_FS, "filesystem has unsupported incompatible features");
goto fail; goto fail;
} }
data->disk = disk; data->disk = disk;
data->diropen.data = data; data->diropen.data = data;
@ -571,7 +571,7 @@ grub_ext2_mount (grub_disk_t disk)
grub_ext2_read_inode (data, 2, data->inode); grub_ext2_read_inode (data, 2, data->inode);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
return data; return data;
fail: fail:
@ -587,23 +587,23 @@ grub_ext2_read_symlink (grub_fshelp_node_t node)
{ {
char *symlink; char *symlink;
struct grub_fshelp_node *diro = node; struct grub_fshelp_node *diro = node;
if (! diro->inode_read) if (! diro->inode_read)
{ {
grub_ext2_read_inode (diro->data, diro->ino, &diro->inode); grub_ext2_read_inode (diro->data, diro->ino, &diro->inode);
if (grub_errno) if (grub_errno)
return 0; return 0;
} }
symlink = grub_malloc (grub_le_to_cpu32 (diro->inode.size) + 1); symlink = grub_malloc (grub_le_to_cpu32 (diro->inode.size) + 1);
if (! symlink) if (! symlink)
return 0; return 0;
/* If the filesize of the symlink is bigger than /* If the filesize of the symlink is bigger than
60 the symlink is stored in a separate block, 60 the symlink is stored in a separate block,
otherwise it is stored in the inode. */ otherwise it is stored in the inode. */
if (grub_le_to_cpu32 (diro->inode.size) <= 60) if (grub_le_to_cpu32 (diro->inode.size) <= 60)
grub_strncpy (symlink, grub_strncpy (symlink,
diro->inode.symlink, diro->inode.symlink,
grub_le_to_cpu32 (diro->inode.size)); grub_le_to_cpu32 (diro->inode.size));
else else
@ -617,7 +617,7 @@ grub_ext2_read_symlink (grub_fshelp_node_t node)
return 0; return 0;
} }
} }
symlink[grub_le_to_cpu32 (diro->inode.size)] = '\0'; symlink[grub_le_to_cpu32 (diro->inode.size)] = '\0';
return symlink; return symlink;
} }
@ -631,14 +631,14 @@ grub_ext2_iterate_dir (grub_fshelp_node_t dir,
{ {
unsigned int fpos = 0; unsigned int fpos = 0;
struct grub_fshelp_node *diro = (struct grub_fshelp_node *) dir; struct grub_fshelp_node *diro = (struct grub_fshelp_node *) dir;
if (! diro->inode_read) if (! diro->inode_read)
{ {
grub_ext2_read_inode (diro->data, diro->ino, &diro->inode); grub_ext2_read_inode (diro->data, diro->ino, &diro->inode);
if (grub_errno) if (grub_errno)
return 0; return 0;
} }
/* Search the file. */ /* Search the file. */
while (fpos < grub_le_to_cpu32 (diro->inode.size)) while (fpos < grub_le_to_cpu32 (diro->inode.size))
{ {
@ -648,25 +648,25 @@ grub_ext2_iterate_dir (grub_fshelp_node_t dir,
(char *) &dirent); (char *) &dirent);
if (grub_errno) if (grub_errno)
return 0; return 0;
if (dirent.namelen != 0) if (dirent.namelen != 0)
{ {
char filename[dirent.namelen + 1]; char filename[dirent.namelen + 1];
struct grub_fshelp_node *fdiro; struct grub_fshelp_node *fdiro;
enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN; enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN;
grub_ext2_read_file (diro, 0, fpos + sizeof (struct ext2_dirent), grub_ext2_read_file (diro, 0, fpos + sizeof (struct ext2_dirent),
dirent.namelen, filename); dirent.namelen, filename);
if (grub_errno) if (grub_errno)
return 0; return 0;
fdiro = grub_malloc (sizeof (struct grub_fshelp_node)); fdiro = grub_malloc (sizeof (struct grub_fshelp_node));
if (! fdiro) if (! fdiro)
return 0; return 0;
fdiro->data = diro->data; fdiro->data = diro->data;
fdiro->ino = grub_le_to_cpu32 (dirent.inode); fdiro->ino = grub_le_to_cpu32 (dirent.inode);
filename[dirent.namelen] = '\0'; filename[dirent.namelen] = '\0';
if (dirent.filetype != FILETYPE_UNKNOWN) if (dirent.filetype != FILETYPE_UNKNOWN)
@ -692,9 +692,9 @@ grub_ext2_iterate_dir (grub_fshelp_node_t dir,
grub_free (fdiro); grub_free (fdiro);
return 0; return 0;
} }
fdiro->inode_read = 1; fdiro->inode_read = 1;
if ((grub_le_to_cpu16 (fdiro->inode.mode) if ((grub_le_to_cpu16 (fdiro->inode.mode)
& FILETYPE_INO_MASK) == FILETYPE_INO_DIRECTORY) & FILETYPE_INO_MASK) == FILETYPE_INO_DIRECTORY)
type = GRUB_FSHELP_DIR; type = GRUB_FSHELP_DIR;
@ -705,14 +705,14 @@ grub_ext2_iterate_dir (grub_fshelp_node_t dir,
& FILETYPE_INO_MASK) == FILETYPE_INO_REG) & FILETYPE_INO_MASK) == FILETYPE_INO_REG)
type = GRUB_FSHELP_REG; type = GRUB_FSHELP_REG;
} }
if (hook (filename, type, fdiro)) if (hook (filename, type, fdiro))
return 1; return 1;
} }
fpos += grub_le_to_cpu16 (dirent.direntlen); fpos += grub_le_to_cpu16 (dirent.direntlen);
} }
return 0; return 0;
} }
@ -722,25 +722,25 @@ grub_ext2_open (struct grub_file *file, const char *name)
{ {
struct grub_ext2_data *data; struct grub_ext2_data *data;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_ext2_mount (file->device->disk); data = grub_ext2_mount (file->device->disk);
if (! data) if (! data)
goto fail; goto fail;
grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_ext2_iterate_dir, grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_ext2_iterate_dir,
grub_ext2_read_symlink, GRUB_FSHELP_REG); grub_ext2_read_symlink, GRUB_FSHELP_REG);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
if (! fdiro->inode_read) if (! fdiro->inode_read)
{ {
grub_ext2_read_inode (data, fdiro->ino, &fdiro->inode); grub_ext2_read_inode (data, fdiro->ino, &fdiro->inode);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
} }
grub_memcpy (data->inode, &fdiro->inode, sizeof (struct grub_ext2_inode)); grub_memcpy (data->inode, &fdiro->inode, sizeof (struct grub_ext2_inode));
grub_free (fdiro); grub_free (fdiro);
@ -754,7 +754,7 @@ grub_ext2_open (struct grub_file *file, const char *name)
if (fdiro != &data->diropen) if (fdiro != &data->diropen)
grub_free (fdiro); grub_free (fdiro);
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
@ -775,20 +775,20 @@ static grub_ssize_t
grub_ext2_read (grub_file_t file, char *buf, grub_size_t len) grub_ext2_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_ext2_data *data = (struct grub_ext2_data *) file->data; struct grub_ext2_data *data = (struct grub_ext2_data *) file->data;
return grub_ext2_read_file (&data->diropen, file->read_hook, return grub_ext2_read_file (&data->diropen, file->read_hook,
file->offset, len, buf); file->offset, len, buf);
} }
static grub_err_t static grub_err_t
grub_ext2_dir (grub_device_t device, const char *path, grub_ext2_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_ext2_data *data = 0;; struct grub_ext2_data *data = 0;;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
auto int NESTED_FUNC_ATTR iterate (const char *filename, auto int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype, enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node); grub_fshelp_node_t node);
@ -818,18 +818,18 @@ grub_ext2_dir (grub_device_t device, const char *path,
} }
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_ext2_mount (device->disk); data = grub_ext2_mount (device->disk);
if (! data) if (! data)
goto fail; goto fail;
grub_fshelp_find_file (path, &data->diropen, &fdiro, grub_ext2_iterate_dir, grub_fshelp_find_file (path, &data->diropen, &fdiro, grub_ext2_iterate_dir,
grub_ext2_read_symlink, GRUB_FSHELP_DIR); grub_ext2_read_symlink, GRUB_FSHELP_DIR);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
grub_ext2_iterate_dir (fdiro, iterate); grub_ext2_iterate_dir (fdiro, iterate);
fail: fail:
if (fdiro != &data->diropen) if (fdiro != &data->diropen)
grub_free (fdiro); grub_free (fdiro);
@ -890,7 +890,7 @@ grub_ext2_uuid (grub_device_t device, char **uuid)
} }
/* Get mtime. */ /* Get mtime. */
static grub_err_t static grub_err_t
grub_ext2_mtime (grub_device_t device, grub_int32_t *tm) grub_ext2_mtime (grub_device_t device, grub_int32_t *tm)
{ {
struct grub_ext2_data *data; struct grub_ext2_data *data;
@ -901,7 +901,7 @@ grub_ext2_mtime (grub_device_t device, grub_int32_t *tm)
data = grub_ext2_mount (disk); data = grub_ext2_mount (disk);
if (!data) if (!data)
*tm = 0; *tm = 0;
else else
*tm = grub_le_to_cpu32 (data->sblock.utime); *tm = grub_le_to_cpu32 (data->sblock.utime);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);

View file

@ -126,15 +126,15 @@ struct grub_fat_data
{ {
int logical_sector_bits; int logical_sector_bits;
grub_uint32_t num_sectors; grub_uint32_t num_sectors;
grub_uint16_t fat_sector; grub_uint16_t fat_sector;
grub_uint32_t sectors_per_fat; grub_uint32_t sectors_per_fat;
int fat_size; int fat_size;
grub_uint32_t root_cluster; grub_uint32_t root_cluster;
grub_uint32_t root_sector; grub_uint32_t root_sector;
grub_uint32_t num_root_sectors; grub_uint32_t num_root_sectors;
int cluster_bits; int cluster_bits;
grub_uint32_t cluster_eof_mark; grub_uint32_t cluster_eof_mark;
grub_uint32_t cluster_sector; grub_uint32_t cluster_sector;
@ -155,7 +155,7 @@ static int
fat_log2 (unsigned x) fat_log2 (unsigned x)
{ {
int i; int i;
if (x == 0) if (x == 0)
return -1; return -1;
@ -190,14 +190,14 @@ grub_fat_mount (grub_disk_t disk)
&& grub_strncmp((const char *) bpb.version_specific.fat12_or_fat16.fstype, "FAT16", 5) && grub_strncmp((const char *) bpb.version_specific.fat12_or_fat16.fstype, "FAT16", 5)
&& grub_strncmp((const char *) bpb.version_specific.fat32.fstype, "FAT32", 5)) && grub_strncmp((const char *) bpb.version_specific.fat32.fstype, "FAT32", 5))
goto fail; goto fail;
/* Get the sizes of logical sectors and clusters. */ /* Get the sizes of logical sectors and clusters. */
data->logical_sector_bits = data->logical_sector_bits =
fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector)); fat_log2 (grub_le_to_cpu16 (bpb.bytes_per_sector));
if (data->logical_sector_bits < GRUB_DISK_SECTOR_BITS) if (data->logical_sector_bits < GRUB_DISK_SECTOR_BITS)
goto fail; goto fail;
data->logical_sector_bits -= GRUB_DISK_SECTOR_BITS; data->logical_sector_bits -= GRUB_DISK_SECTOR_BITS;
data->cluster_bits = fat_log2 (bpb.sectors_per_cluster); data->cluster_bits = fat_log2 (bpb.sectors_per_cluster);
if (data->cluster_bits < 0) if (data->cluster_bits < 0)
goto fail; goto fail;
@ -248,16 +248,16 @@ grub_fat_mount (grub_disk_t disk)
{ {
/* FAT32. */ /* FAT32. */
grub_uint16_t flags = grub_le_to_cpu16 (bpb.version_specific.fat32.extended_flags); grub_uint16_t flags = grub_le_to_cpu16 (bpb.version_specific.fat32.extended_flags);
data->root_cluster = grub_le_to_cpu32 (bpb.version_specific.fat32.root_cluster); data->root_cluster = grub_le_to_cpu32 (bpb.version_specific.fat32.root_cluster);
data->fat_size = 32; data->fat_size = 32;
data->cluster_eof_mark = 0x0ffffff8; data->cluster_eof_mark = 0x0ffffff8;
if (flags & 0x80) if (flags & 0x80)
{ {
/* Get an active FAT. */ /* Get an active FAT. */
unsigned active_fat = flags & 0xf; unsigned active_fat = flags & 0xf;
if (active_fat > bpb.num_fats) if (active_fat > bpb.num_fats)
goto fail; goto fail;
@ -320,7 +320,7 @@ grub_fat_mount (grub_disk_t disk)
data->uuid = grub_le_to_cpu32 (bpb.version_specific.fat12_or_fat16.num_serial); data->uuid = grub_le_to_cpu32 (bpb.version_specific.fat12_or_fat16.num_serial);
else else
data->uuid = grub_le_to_cpu32 (bpb.version_specific.fat32.num_serial); data->uuid = grub_le_to_cpu32 (bpb.version_specific.fat32.num_serial);
/* Ignore the 3rd bit, because some BIOSes assigns 0xF0 to the media /* Ignore the 3rd bit, because some BIOSes assigns 0xF0 to the media
descriptor, even if it is a so-called superfloppy (e.g. an USB key). descriptor, even if it is a so-called superfloppy (e.g. an USB key).
The check may be too strict for this kind of stupid BIOSes, as The check may be too strict for this kind of stupid BIOSes, as
@ -352,7 +352,7 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data,
unsigned logical_cluster_bits; unsigned logical_cluster_bits;
grub_ssize_t ret = 0; grub_ssize_t ret = 0;
unsigned long sector; unsigned long sector;
/* This is a special case. FAT12 and FAT16 doesn't have the root directory /* This is a special case. FAT12 and FAT16 doesn't have the root directory
in clusters. */ in clusters. */
if (data->file_cluster == ~0U) if (data->file_cluster == ~0U)
@ -417,7 +417,7 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data,
case 12: case 12:
if (data->cur_cluster & 1) if (data->cur_cluster & 1)
next_cluster >>= 4; next_cluster >>= 4;
next_cluster &= 0x0FFF; next_cluster &= 0x0FFF;
break; break;
} }
@ -426,7 +426,7 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data,
grub_printf ("%s:%d: fat_size=%d, next_cluster=%u\n", grub_printf ("%s:%d: fat_size=%d, next_cluster=%u\n",
__FILE__, __LINE__, data->fat_size, next_cluster); __FILE__, __LINE__, data->fat_size, next_cluster);
#endif #endif
/* Check the end. */ /* Check the end. */
if (next_cluster >= data->cluster_eof_mark) if (next_cluster >= data->cluster_eof_mark)
return ret; return ret;
@ -468,7 +468,7 @@ grub_fat_read_data (grub_disk_t disk, struct grub_fat_data *data,
static grub_err_t static grub_err_t
grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data, grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
int (*hook) (const char *filename, int (*hook) (const char *filename,
struct grub_fat_dir_entry *dir)) struct grub_fat_dir_entry *dir))
{ {
struct grub_fat_dir_entry dir; struct grub_fat_dir_entry dir;
@ -477,10 +477,10 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
int slot = -1, slots = -1; int slot = -1, slots = -1;
int checksum = -1; int checksum = -1;
grub_ssize_t offset = -sizeof(dir); grub_ssize_t offset = -sizeof(dir);
if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY)) if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY))
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
/* Allocate space enough to hold a long name. */ /* Allocate space enough to hold a long name. */
filename = grub_malloc (0x40 * 13 * 4 + 1); filename = grub_malloc (0x40 * 13 * 4 + 1);
unibuf = (grub_uint16_t *) grub_malloc (0x40 * 13 * 2); unibuf = (grub_uint16_t *) grub_malloc (0x40 * 13 * 2);
@ -490,7 +490,7 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
grub_free (unibuf); grub_free (unibuf);
return 0; return 0;
} }
while (1) while (1)
{ {
unsigned i; unsigned i;
@ -509,7 +509,7 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
struct grub_fat_long_name_entry *long_name struct grub_fat_long_name_entry *long_name
= (struct grub_fat_long_name_entry *) &dir; = (struct grub_fat_long_name_entry *) &dir;
grub_uint8_t id = long_name->id; grub_uint8_t id = long_name->id;
if (id & 0x40) if (id & 0x40)
{ {
id &= 0x3f; id &= 0x3f;
@ -537,11 +537,11 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
/* This is a workaround for Japanese. */ /* This is a workaround for Japanese. */
if (dir.name[0] == 0x05) if (dir.name[0] == 0x05)
dir.name[0] = 0xe5; dir.name[0] = 0xe5;
if (checksum != -1 && slot == 0) if (checksum != -1 && slot == 0)
{ {
grub_uint8_t sum; grub_uint8_t sum;
for (sum = 0, i = 0; i < sizeof (dir.name); i++) for (sum = 0, i = 0; i < sizeof (dir.name); i++)
sum = ((sum >> 1) | (sum << 7)) + dir.name[i]; sum = ((sum >> 1) | (sum << 7)) + dir.name[i];
@ -551,13 +551,13 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
for (u = 0; u < slots * 13; u++) for (u = 0; u < slots * 13; u++)
unibuf[u] = grub_le_to_cpu16 (unibuf[u]); unibuf[u] = grub_le_to_cpu16 (unibuf[u]);
*grub_utf16_to_utf8 ((grub_uint8_t *) filename, unibuf, *grub_utf16_to_utf8 ((grub_uint8_t *) filename, unibuf,
slots * 13) = '\0'; slots * 13) = '\0';
if (hook (filename, &dir)) if (hook (filename, &dir))
break; break;
checksum = -1; checksum = -1;
continue; continue;
} }
@ -569,7 +569,7 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
filep = filename; filep = filename;
if (dir.attr & GRUB_FAT_ATTR_VOLUME_ID) if (dir.attr & GRUB_FAT_ATTR_VOLUME_ID)
{ {
for (i = 0; i < sizeof (dir.name) && dir.name[i] for (i = 0; i < sizeof (dir.name) && dir.name[i]
&& ! grub_isspace (dir.name[i]); i++) && ! grub_isspace (dir.name[i]); i++)
*filep++ = dir.name[i]; *filep++ = dir.name[i];
} }
@ -577,9 +577,9 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
{ {
for (i = 0; i < 8 && dir.name[i] && ! grub_isspace (dir.name[i]); i++) for (i = 0; i < 8 && dir.name[i] && ! grub_isspace (dir.name[i]); i++)
*filep++ = grub_tolower (dir.name[i]); *filep++ = grub_tolower (dir.name[i]);
*filep = '.'; *filep = '.';
for (i = 8; i < 11 && dir.name[i] && ! grub_isspace (dir.name[i]); i++) for (i = 8; i < 11 && dir.name[i] && ! grub_isspace (dir.name[i]); i++)
*++filep = grub_tolower (dir.name[i]); *++filep = grub_tolower (dir.name[i]);
@ -604,7 +604,7 @@ grub_fat_iterate_dir (grub_disk_t disk, struct grub_fat_data *data,
static char * static char *
grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data, grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
const char *path, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
char *dirname, *dirp; char *dirname, *dirp;
@ -636,18 +636,18 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
if (call_hook) if (call_hook)
hook (filename, &info); hook (filename, &info);
return 1; return 1;
} }
return 0; return 0;
} }
if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY)) if (! (data->attr & GRUB_FAT_ATTR_DIRECTORY))
{ {
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
return 0; return 0;
} }
/* Extract a directory name. */ /* Extract a directory name. */
while (*path == '/') while (*path == '/')
path++; path++;
@ -656,7 +656,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
if (dirp) if (dirp)
{ {
unsigned len = dirp - path; unsigned len = dirp - path;
dirname = grub_malloc (len + 1); dirname = grub_malloc (len + 1);
if (! dirname) if (! dirname)
return 0; return 0;
@ -669,7 +669,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
dirname = grub_strdup (path); dirname = grub_strdup (path);
call_hook = (! dirp && hook); call_hook = (! dirp && hook);
grub_fat_iterate_dir (disk, data, iter_hook); grub_fat_iterate_dir (disk, data, iter_hook);
if (grub_errno == GRUB_ERR_NONE && ! found && !call_hook) if (grub_errno == GRUB_ERR_NONE && ! found && !call_hook)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
@ -681,7 +681,7 @@ grub_fat_find_dir (grub_disk_t disk, struct grub_fat_data *data,
static grub_err_t static grub_err_t
grub_fat_dir (grub_device_t device, const char *path, grub_fat_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_fat_data *data = 0; struct grub_fat_data *data = 0;
@ -691,7 +691,7 @@ grub_fat_dir (grub_device_t device, const char *path,
char *p; char *p;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_fat_mount (disk); data = grub_fat_mount (disk);
if (! data) if (! data)
goto fail; goto fail;
@ -707,7 +707,7 @@ grub_fat_dir (grub_device_t device, const char *path,
*p++ = '/'; *p++ = '/';
*p = '\0'; *p = '\0';
p = dirname; p = dirname;
do do
{ {
p = grub_fat_find_dir (disk, data, p, hook); p = grub_fat_find_dir (disk, data, p, hook);
@ -718,9 +718,9 @@ grub_fat_dir (grub_device_t device, const char *path,
grub_free (dirname); grub_free (dirname);
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
} }
@ -731,7 +731,7 @@ grub_fat_open (grub_file_t file, const char *name)
char *p = (char *) name; char *p = (char *) name;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_fat_mount (file->device->disk); data = grub_fat_mount (file->device->disk);
if (! data) if (! data)
goto fail; goto fail;
@ -752,15 +752,15 @@ grub_fat_open (grub_file_t file, const char *name)
file->data = data; file->data = data;
file->size = data->file_size; file->size = data->file_size;
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
fail: fail:
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
} }
@ -775,9 +775,9 @@ static grub_err_t
grub_fat_close (grub_file_t file) grub_fat_close (grub_file_t file)
{ {
grub_free (file->data); grub_free (file->data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
} }
@ -799,7 +799,7 @@ grub_fat_label (grub_device_t device, char **label)
} }
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_fat_mount (disk); data = grub_fat_mount (disk);
if (! data) if (! data)
goto fail; goto fail;
@ -811,7 +811,7 @@ grub_fat_label (grub_device_t device, char **label)
} }
*label = 0; *label = 0;
grub_fat_iterate_dir (disk, data, iter_hook); grub_fat_iterate_dir (disk, data, iter_hook);
fail: fail:

View file

@ -47,7 +47,7 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
grub_err_t err; grub_err_t err;
enum grub_fshelp_filetype foundtype = GRUB_FSHELP_DIR; enum grub_fshelp_filetype foundtype = GRUB_FSHELP_DIR;
int symlinknest = 0; int symlinknest = 0;
auto grub_err_t NESTED_FUNC_ATTR find_file (const char *currpath, auto grub_err_t NESTED_FUNC_ATTR find_file (const char *currpath,
grub_fshelp_node_t currroot, grub_fshelp_node_t currroot,
grub_fshelp_node_t *currfound); grub_fshelp_node_t *currfound);
@ -69,13 +69,13 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
grub_fshelp_node_t node); grub_fshelp_node_t node);
auto void free_node (grub_fshelp_node_t node); auto void free_node (grub_fshelp_node_t node);
void free_node (grub_fshelp_node_t node) void free_node (grub_fshelp_node_t node)
{ {
if (node != rootnode && node != currroot) if (node != rootnode && node != currroot)
grub_free (node); grub_free (node);
} }
int NESTED_FUNC_ATTR iterate (const char *filename, int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype, enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node) grub_fshelp_node_t node)
@ -88,31 +88,31 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
grub_free (node); grub_free (node);
return 0; return 0;
} }
/* The node is found, stop iterating over the nodes. */ /* The node is found, stop iterating over the nodes. */
type = filetype & ~GRUB_FSHELP_CASE_INSENSITIVE; type = filetype & ~GRUB_FSHELP_CASE_INSENSITIVE;
oldnode = currnode; oldnode = currnode;
currnode = node; currnode = node;
return 1; return 1;
} }
grub_strncpy (fpath, currpath, grub_strlen (currpath) + 1); grub_strncpy (fpath, currpath, grub_strlen (currpath) + 1);
/* Remove all leading slashes. */ /* Remove all leading slashes. */
while (*name == '/') while (*name == '/')
name++; name++;
if (! *name) if (! *name)
{ {
*currfound = currnode; *currfound = currnode;
return 0; return 0;
} }
for (;;) for (;;)
{ {
int found; int found;
/* Extract the actual part from the pathname. */ /* Extract the actual part from the pathname. */
next = grub_strchr (name, '/'); next = grub_strchr (name, '/');
if (next) if (next)
@ -121,7 +121,7 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
while (*next == '/') while (*next == '/')
*(next++) = '\0'; *(next++) = '\0';
} }
/* At this point it is expected that the current node is a /* At this point it is expected that the current node is a
directory, check if this is true. */ directory, check if this is true. */
if (type != GRUB_FSHELP_DIR) if (type != GRUB_FSHELP_DIR)
@ -129,22 +129,22 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
free_node (currnode); free_node (currnode);
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
} }
/* Iterate over the directory. */ /* Iterate over the directory. */
found = iterate_dir (currnode, iterate); found = iterate_dir (currnode, iterate);
if (! found) if (! found)
{ {
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
break; break;
} }
/* Read in the symlink and follow it. */ /* Read in the symlink and follow it. */
if (type == GRUB_FSHELP_SYMLINK) if (type == GRUB_FSHELP_SYMLINK)
{ {
char *symlink; char *symlink;
/* Test if the symlink does not loop. */ /* Test if the symlink does not loop. */
if (++symlinknest == 8) if (++symlinknest == 8)
{ {
@ -153,37 +153,37 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
return grub_error (GRUB_ERR_SYMLINK_LOOP, return grub_error (GRUB_ERR_SYMLINK_LOOP,
"too deep nesting of symlinks"); "too deep nesting of symlinks");
} }
symlink = read_symlink (currnode); symlink = read_symlink (currnode);
free_node (currnode); free_node (currnode);
if (!symlink) if (!symlink)
{ {
free_node (oldnode); free_node (oldnode);
return grub_errno; return grub_errno;
} }
/* The symlink is an absolute path, go back to the root inode. */ /* The symlink is an absolute path, go back to the root inode. */
if (symlink[0] == '/') if (symlink[0] == '/')
{ {
free_node (oldnode); free_node (oldnode);
oldnode = rootnode; oldnode = rootnode;
} }
/* Lookup the node the symlink points to. */ /* Lookup the node the symlink points to. */
find_file (symlink, oldnode, &currnode); find_file (symlink, oldnode, &currnode);
type = foundtype; type = foundtype;
grub_free (symlink); grub_free (symlink);
if (grub_errno) if (grub_errno)
{ {
free_node (oldnode); free_node (oldnode);
return grub_errno; return grub_errno;
} }
} }
free_node (oldnode); free_node (oldnode);
/* Found the node! */ /* Found the node! */
if (! next || *next == '\0') if (! next || *next == '\0')
{ {
@ -191,10 +191,10 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
foundtype = type; foundtype = type;
return 0; return 0;
} }
name = next; name = next;
} }
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
} }
@ -203,17 +203,17 @@ grub_fshelp_find_file (const char *path, grub_fshelp_node_t rootnode,
grub_error (GRUB_ERR_BAD_FILENAME, "bad filename"); grub_error (GRUB_ERR_BAD_FILENAME, "bad filename");
return grub_errno; return grub_errno;
} }
err = find_file (path, rootnode, foundnode); err = find_file (path, rootnode, foundnode);
if (err) if (err)
return err; return err;
/* Check if the node that was found was of the expected type. */ /* Check if the node that was found was of the expected type. */
if (expecttype == GRUB_FSHELP_REG && foundtype != expecttype) if (expecttype == GRUB_FSHELP_REG && foundtype != expecttype)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a regular file"); return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a regular file");
else if (expecttype == GRUB_FSHELP_DIR && foundtype != expecttype) else if (expecttype == GRUB_FSHELP_DIR && foundtype != expecttype)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
return 0; return 0;
} }
@ -252,14 +252,14 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node,
blknr = get_block (node, i); blknr = get_block (node, i);
if (grub_errno) if (grub_errno)
return -1; return -1;
blknr = blknr << log2blocksize; blknr = blknr << log2blocksize;
/* Last block. */ /* Last block. */
if (i == blockcnt - 1) if (i == blockcnt - 1)
{ {
blockend = (len + pos) & (blocksize - 1); blockend = (len + pos) & (blocksize - 1);
/* The last portion is exactly blocksize. */ /* The last portion is exactly blocksize. */
if (! blockend) if (! blockend)
blockend = blocksize; blockend = blocksize;
@ -271,12 +271,12 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node,
skipfirst = blockoff; skipfirst = blockoff;
blockend -= skipfirst; blockend -= skipfirst;
} }
/* If the block number is 0 this block is not stored on disk but /* If the block number is 0 this block is not stored on disk but
is zero filled instead. */ is zero filled instead. */
if (blknr) if (blknr)
{ {
disk->read_hook = read_hook; disk->read_hook = read_hook;
grub_disk_read (disk, blknr, skipfirst, grub_disk_read (disk, blknr, skipfirst,
blockend, buf); blockend, buf);
@ -297,7 +297,7 @@ unsigned int
grub_fshelp_log2blksize (unsigned int blksize, unsigned int *pow) grub_fshelp_log2blksize (unsigned int blksize, unsigned int *pow)
{ {
int mod; int mod;
*pow = 0; *pow = 0;
while (blksize > 1) while (blksize > 1)
{ {

200
fs/hfs.c
View file

@ -103,7 +103,7 @@ struct grub_hfs_catalog_key
{ {
grub_uint8_t unused; grub_uint8_t unused;
grub_uint32_t parent_dir; grub_uint32_t parent_dir;
/* Filename length. */ /* Filename length. */
grub_uint8_t strlen; grub_uint8_t strlen;
@ -174,28 +174,28 @@ grub_hfs_block (struct grub_hfs_data *data, grub_hfs_datarecord_t dat,
grub_hfs_datarecord_t dr; grub_hfs_datarecord_t dr;
int pos = 0; int pos = 0;
struct grub_hfs_extent_key key; struct grub_hfs_extent_key key;
int tree = 0; int tree = 0;
static int cache_file = 0; static int cache_file = 0;
static int cache_pos = 0; static int cache_pos = 0;
static grub_hfs_datarecord_t cache_dr; static grub_hfs_datarecord_t cache_dr;
grub_memcpy (dr, dat, sizeof (dr)); grub_memcpy (dr, dat, sizeof (dr));
key.forktype = 0; key.forktype = 0;
key.fileid = grub_cpu_to_be32 (file); key.fileid = grub_cpu_to_be32 (file);
if (cache && cache_file == file && block > cache_pos) if (cache && cache_file == file && block > cache_pos)
{ {
pos = cache_pos; pos = cache_pos;
key.first_block = grub_cpu_to_be16 (pos); key.first_block = grub_cpu_to_be16 (pos);
grub_memcpy (dr, cache_dr, sizeof (cache_dr)); grub_memcpy (dr, cache_dr, sizeof (cache_dr));
} }
for (;;) for (;;)
{ {
int i; int i;
/* Try all 3 extents. */ /* Try all 3 extents. */
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
@ -203,7 +203,7 @@ grub_hfs_block (struct grub_hfs_data *data, grub_hfs_datarecord_t dat,
if (grub_be_to_cpu16 (dr[i].count) + pos > block) if (grub_be_to_cpu16 (dr[i].count) + pos > block)
{ {
int first = grub_be_to_cpu16 (dr[i].first_block); int first = grub_be_to_cpu16 (dr[i].first_block);
/* If the cache is enabled, store the current position /* If the cache is enabled, store the current position
in the tree. */ in the tree. */
if (tree && cache) if (tree && cache)
@ -212,15 +212,15 @@ grub_hfs_block (struct grub_hfs_data *data, grub_hfs_datarecord_t dat,
cache_pos = pos; cache_pos = pos;
grub_memcpy (cache_dr, dr, sizeof (cache_dr)); grub_memcpy (cache_dr, dr, sizeof (cache_dr));
} }
return (grub_be_to_cpu16 (data->sblock.first_block) return (grub_be_to_cpu16 (data->sblock.first_block)
+ (first + block - pos) * GRUB_HFS_BLKS); + (first + block - pos) * GRUB_HFS_BLKS);
} }
/* Try the next extent. */ /* Try the next extent. */
pos += grub_be_to_cpu16 (dr[i].count); pos += grub_be_to_cpu16 (dr[i].count);
} }
/* Lookup the block in the extent overflow file. */ /* Lookup the block in the extent overflow file. */
key.first_block = grub_cpu_to_be16 (pos); key.first_block = grub_cpu_to_be16 (pos);
tree = 1; tree = 1;
@ -247,7 +247,7 @@ grub_hfs_read_file (struct grub_hfs_data *data,
if (len > grub_le_to_cpu32 (data->size)) if (len > grub_le_to_cpu32 (data->size))
len = grub_le_to_cpu32 (data->size); len = grub_le_to_cpu32 (data->size);
blockcnt = ((len + pos) blockcnt = ((len + pos)
+ data->blksz - 1) / data->blksz; + data->blksz - 1) / data->blksz;
for (i = pos / data->blksz; i < blockcnt; i++) for (i = pos / data->blksz; i < blockcnt; i++)
@ -257,16 +257,16 @@ grub_hfs_read_file (struct grub_hfs_data *data,
int blockend = data->blksz; int blockend = data->blksz;
int skipfirst = 0; int skipfirst = 0;
blknr = grub_hfs_block (data, data->extents, data->fileid, i, 1); blknr = grub_hfs_block (data, data->extents, data->fileid, i, 1);
if (grub_errno) if (grub_errno)
return -1; return -1;
/* Last block. */ /* Last block. */
if (i == blockcnt - 1) if (i == blockcnt - 1)
{ {
blockend = (len + pos) % data->blksz; blockend = (len + pos) % data->blksz;
/* The last portion is exactly EXT2_BLOCK_SIZE (data). */ /* The last portion is exactly EXT2_BLOCK_SIZE (data). */
if (! blockend) if (! blockend)
blockend = data->blksz; blockend = data->blksz;
@ -283,17 +283,17 @@ grub_hfs_read_file (struct grub_hfs_data *data,
is zero filled instead. */ is zero filled instead. */
if (blknr) if (blknr)
{ {
data->disk->read_hook = read_hook; data->disk->read_hook = read_hook;
grub_disk_read (data->disk, blknr, skipfirst, grub_disk_read (data->disk, blknr, skipfirst,
blockend, buf); blockend, buf);
data->disk->read_hook = 0; data->disk->read_hook = 0;
if (grub_errno) if (grub_errno)
return -1; return -1;
} }
buf += data->blksz - skipfirst; buf += data->blksz - skipfirst;
} }
return len; return len;
} }
@ -306,13 +306,13 @@ grub_hfs_mount (grub_disk_t disk)
struct grub_hfs_catalog_key key; struct grub_hfs_catalog_key key;
struct grub_hfs_dirrec dir; struct grub_hfs_dirrec dir;
int first_block; int first_block;
struct struct
{ {
struct grub_hfs_node node; struct grub_hfs_node node;
struct grub_hfs_treeheader head; struct grub_hfs_treeheader head;
} treehead; } treehead;
data = grub_malloc (sizeof (struct grub_hfs_data)); data = grub_malloc (sizeof (struct grub_hfs_data));
if (!data) if (!data)
return 0; return 0;
@ -321,7 +321,7 @@ grub_hfs_mount (grub_disk_t disk)
if (grub_disk_read (disk, GRUB_HFS_SBLOCK, 0, if (grub_disk_read (disk, GRUB_HFS_SBLOCK, 0,
sizeof (struct grub_hfs_sblock), &data->sblock)) sizeof (struct grub_hfs_sblock), &data->sblock))
goto fail; goto fail;
/* Check if this is a HFS filesystem. */ /* Check if this is a HFS filesystem. */
if (grub_be_to_cpu16 (data->sblock.magic) != GRUB_HFS_MAGIC) if (grub_be_to_cpu16 (data->sblock.magic) != GRUB_HFS_MAGIC)
{ {
@ -335,23 +335,23 @@ grub_hfs_mount (grub_disk_t disk)
grub_error (GRUB_ERR_BAD_FS, "embedded HFS+ filesystem"); grub_error (GRUB_ERR_BAD_FS, "embedded HFS+ filesystem");
goto fail; goto fail;
} }
data->blksz = grub_be_to_cpu32 (data->sblock.blksz); data->blksz = grub_be_to_cpu32 (data->sblock.blksz);
data->disk = disk; data->disk = disk;
/* Lookup the root node of the extent overflow tree. */ /* Lookup the root node of the extent overflow tree. */
first_block = ((grub_be_to_cpu16 (data->sblock.extent_recs[0].first_block) first_block = ((grub_be_to_cpu16 (data->sblock.extent_recs[0].first_block)
* GRUB_HFS_BLKS) * GRUB_HFS_BLKS)
+ grub_be_to_cpu16 (data->sblock.first_block)); + grub_be_to_cpu16 (data->sblock.first_block));
if (grub_disk_read (data->disk, first_block, 0, if (grub_disk_read (data->disk, first_block, 0,
sizeof (treehead), &treehead)) sizeof (treehead), &treehead))
goto fail; goto fail;
data->ext_root = grub_be_to_cpu32 (treehead.head.root_node); data->ext_root = grub_be_to_cpu32 (treehead.head.root_node);
data->ext_size = grub_be_to_cpu16 (treehead.head.node_size); data->ext_size = grub_be_to_cpu16 (treehead.head.node_size);
/* Lookup the root node of the catalog tree. */ /* Lookup the root node of the catalog tree. */
first_block = ((grub_be_to_cpu16 (data->sblock.catalog_recs[0].first_block) first_block = ((grub_be_to_cpu16 (data->sblock.catalog_recs[0].first_block)
* GRUB_HFS_BLKS) * GRUB_HFS_BLKS)
+ grub_be_to_cpu16 (data->sblock.first_block)); + grub_be_to_cpu16 (data->sblock.first_block));
if (grub_disk_read (data->disk, first_block, 0, if (grub_disk_read (data->disk, first_block, 0,
@ -359,32 +359,32 @@ grub_hfs_mount (grub_disk_t disk)
goto fail; goto fail;
data->cat_root = grub_be_to_cpu32 (treehead.head.root_node); data->cat_root = grub_be_to_cpu32 (treehead.head.root_node);
data->cat_size = grub_be_to_cpu16 (treehead.head.node_size); data->cat_size = grub_be_to_cpu16 (treehead.head.node_size);
/* Lookup the root directory node in the catalog tree using the /* Lookup the root directory node in the catalog tree using the
volume name. */ volume name. */
key.parent_dir = grub_cpu_to_be32 (1); key.parent_dir = grub_cpu_to_be32 (1);
key.strlen = data->sblock.volname[0]; key.strlen = data->sblock.volname[0];
grub_strcpy ((char *) key.str, (char *) (data->sblock.volname + 1)); grub_strcpy ((char *) key.str, (char *) (data->sblock.volname + 1));
if (grub_hfs_find_node (data, (char *) &key, data->cat_root, if (grub_hfs_find_node (data, (char *) &key, data->cat_root,
0, (char *) &dir, sizeof (dir)) == 0) 0, (char *) &dir, sizeof (dir)) == 0)
{ {
grub_error (GRUB_ERR_BAD_FS, "can not find the hfs root directory"); grub_error (GRUB_ERR_BAD_FS, "can not find the hfs root directory");
goto fail; goto fail;
} }
if (grub_errno) if (grub_errno)
goto fail; goto fail;
data->rootdir = grub_be_to_cpu32 (dir.dirid); data->rootdir = grub_be_to_cpu32 (dir.dirid);
return data; return data;
fail: fail:
grub_free (data); grub_free (data);
if (grub_errno == GRUB_ERR_OUT_OF_RANGE) if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_error (GRUB_ERR_BAD_FS, "not a hfs filesystem"); grub_error (GRUB_ERR_BAD_FS, "not a hfs filesystem");
return 0; return 0;
} }
@ -641,7 +641,7 @@ grub_hfs_cmp_extkeys (struct grub_hfs_extent_key *k1,
if (cmp == 0) if (cmp == 0)
cmp = grub_be_to_cpu32 (k1->fileid) - grub_be_to_cpu32 (k2->fileid); cmp = grub_be_to_cpu32 (k1->fileid) - grub_be_to_cpu32 (k2->fileid);
if (cmp == 0) if (cmp == 0)
cmp = (grub_be_to_cpu16 (k1->first_block) cmp = (grub_be_to_cpu16 (k1->first_block)
- grub_be_to_cpu16 (k2->first_block)); - grub_be_to_cpu16 (k2->first_block));
return cmp; return cmp;
} }
@ -657,24 +657,24 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
struct grub_hfs_record *)) struct grub_hfs_record *))
{ {
int nodesize = type == 0 ? data->cat_size : data->ext_size; int nodesize = type == 0 ? data->cat_size : data->ext_size;
union union
{ {
struct grub_hfs_node node; struct grub_hfs_node node;
char rawnode[nodesize]; char rawnode[nodesize];
grub_uint16_t offsets[nodesize / 2]; grub_uint16_t offsets[nodesize / 2];
} node; } node;
do do
{ {
int i; int i;
struct grub_hfs_extent *dat; struct grub_hfs_extent *dat;
int blk; int blk;
dat = (struct grub_hfs_extent *) (type == 0 dat = (struct grub_hfs_extent *) (type == 0
? (&data->sblock.catalog_recs) ? (&data->sblock.catalog_recs)
: (&data->sblock.extent_recs)); : (&data->sblock.extent_recs));
/* Read the node into memory. */ /* Read the node into memory. */
blk = grub_hfs_block (data, dat, blk = grub_hfs_block (data, dat,
(type == 0) ? GRUB_HFS_CNID_CAT : GRUB_HFS_CNID_EXT, (type == 0) ? GRUB_HFS_CNID_CAT : GRUB_HFS_CNID_EXT,
@ -682,11 +682,11 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
blk += (idx % (data->blksz / nodesize)); blk += (idx % (data->blksz / nodesize));
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
if (grub_disk_read (data->disk, blk, 0, if (grub_disk_read (data->disk, blk, 0,
sizeof (node), &node)) sizeof (node), &node))
return grub_errno; return grub_errno;
/* Iterate over all records in this node. */ /* Iterate over all records in this node. */
for (i = 0; i < grub_be_to_cpu16 (node.node.reccnt); i++) for (i = 0; i < grub_be_to_cpu16 (node.node.reccnt); i++)
{ {
@ -698,23 +698,23 @@ grub_hfs_iterate_records (struct grub_hfs_data *data, int type, int idx,
} __attribute__ ((packed)) *pnt; } __attribute__ ((packed)) *pnt;
pnt = (struct pointer *) (grub_be_to_cpu16 (node.offsets[pos]) pnt = (struct pointer *) (grub_be_to_cpu16 (node.offsets[pos])
+ node.rawnode); + node.rawnode);
struct grub_hfs_record rec = struct grub_hfs_record rec =
{ {
&pnt->key, &pnt->key,
pnt->keylen, pnt->keylen,
&pnt->key + pnt->keylen +(pnt->keylen + 1) % 2, &pnt->key + pnt->keylen +(pnt->keylen + 1) % 2,
nodesize - grub_be_to_cpu16 (node.offsets[pos]) nodesize - grub_be_to_cpu16 (node.offsets[pos])
- pnt->keylen - 1 - pnt->keylen - 1
}; };
if (node_hook (&node.node, &rec)) if (node_hook (&node.node, &rec))
return 0; return 0;
} }
idx = grub_be_to_cpu32 (node.node.next); idx = grub_be_to_cpu32 (node.node.next);
} while (idx && this); } while (idx && this);
return 0; return 0;
} }
@ -730,18 +730,18 @@ grub_hfs_find_node (struct grub_hfs_data *data, char *key,
int found = -1; int found = -1;
int isleaf = 0; int isleaf = 0;
int done = 0; int done = 0;
auto int node_found (struct grub_hfs_node *, struct grub_hfs_record *); auto int node_found (struct grub_hfs_node *, struct grub_hfs_record *);
int node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec) int node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec)
{ {
int cmp = 1; int cmp = 1;
if (type == 0) if (type == 0)
cmp = grub_hfs_cmp_catkeys (rec->key, (void *) key); cmp = grub_hfs_cmp_catkeys (rec->key, (void *) key);
else else
cmp = grub_hfs_cmp_extkeys (rec->key, (void *) key); cmp = grub_hfs_cmp_extkeys (rec->key, (void *) key);
/* If the key is smaller or equal to the current node, mark the /* If the key is smaller or equal to the current node, mark the
entry. In case of a non-leaf mode it will be used to lookup entry. In case of a non-leaf mode it will be used to lookup
the rest of the tree. */ the rest of the tree. */
@ -752,12 +752,12 @@ grub_hfs_find_node (struct grub_hfs_data *data, char *key,
} }
else /* The key can not be found in the tree. */ else /* The key can not be found in the tree. */
return 1; return 1;
/* Check if this node is a leaf node. */ /* Check if this node is a leaf node. */
if (hnd->type == GRUB_HFS_NODE_LEAF) if (hnd->type == GRUB_HFS_NODE_LEAF)
{ {
isleaf = 1; isleaf = 1;
/* Found it!!!! */ /* Found it!!!! */
if (cmp == 0) if (cmp == 0)
{ {
@ -768,23 +768,23 @@ grub_hfs_find_node (struct grub_hfs_data *data, char *key,
return 1; return 1;
} }
} }
return 0; return 0;
} }
do do
{ {
found = -1; found = -1;
if (grub_hfs_iterate_records (data, type, idx, 0, node_found)) if (grub_hfs_iterate_records (data, type, idx, 0, node_found))
return 0; return 0;
if (found == -1) if (found == -1)
return 0; return 0;
idx = found; idx = found;
} while (! isleaf); } while (! isleaf);
return done; return done;
} }
@ -799,7 +799,7 @@ grub_hfs_iterate_dir (struct grub_hfs_data *data, grub_uint32_t root_idx,
int found = -1; int found = -1;
int isleaf = 0; int isleaf = 0;
int next = 0; int next = 0;
/* The lowest key possible with DIR as root directory. */ /* The lowest key possible with DIR as root directory. */
struct grub_hfs_catalog_key key = {0, grub_cpu_to_be32 (dir), 0, ""}; struct grub_hfs_catalog_key key = {0, grub_cpu_to_be32 (dir), 0, ""};
@ -807,51 +807,51 @@ grub_hfs_iterate_dir (struct grub_hfs_data *data, grub_uint32_t root_idx,
auto int it_dir (struct grub_hfs_node * __attribute ((unused)), auto int it_dir (struct grub_hfs_node * __attribute ((unused)),
struct grub_hfs_record *); struct grub_hfs_record *);
int node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec) int node_found (struct grub_hfs_node *hnd, struct grub_hfs_record *rec)
{ {
struct grub_hfs_catalog_key *ckey = rec->key; struct grub_hfs_catalog_key *ckey = rec->key;
if (grub_hfs_cmp_catkeys (rec->key, (void *) &key) <= 0) if (grub_hfs_cmp_catkeys (rec->key, (void *) &key) <= 0)
found = grub_be_to_cpu32 (*(grub_uint32_t *) rec->data); found = grub_be_to_cpu32 (*(grub_uint32_t *) rec->data);
if (hnd->type == 0xFF && ckey->strlen > 0) if (hnd->type == 0xFF && ckey->strlen > 0)
{ {
isleaf = 1; isleaf = 1;
next = grub_be_to_cpu32 (hnd->next); next = grub_be_to_cpu32 (hnd->next);
/* An entry was found. */ /* An entry was found. */
if (grub_be_to_cpu32 (ckey->parent_dir) == dir) if (grub_be_to_cpu32 (ckey->parent_dir) == dir)
return hook (rec); return hook (rec);
} }
return 0; return 0;
} }
int it_dir (struct grub_hfs_node *hnd __attribute ((unused)), int it_dir (struct grub_hfs_node *hnd __attribute ((unused)),
struct grub_hfs_record *rec) struct grub_hfs_record *rec)
{ {
struct grub_hfs_catalog_key *ckey = rec->key; struct grub_hfs_catalog_key *ckey = rec->key;
struct grub_hfs_catalog_key *origkey = &key; struct grub_hfs_catalog_key *origkey = &key;
/* Stop when the entries do not match anymore. */ /* Stop when the entries do not match anymore. */
if (grub_be_to_cpu32 (ckey->parent_dir) if (grub_be_to_cpu32 (ckey->parent_dir)
!= grub_be_to_cpu32 ((origkey)->parent_dir)) != grub_be_to_cpu32 ((origkey)->parent_dir))
return 1; return 1;
return hook (rec); return hook (rec);
} }
do do
{ {
found = -1; found = -1;
if (grub_hfs_iterate_records (data, 0, root_idx, 0, node_found)) if (grub_hfs_iterate_records (data, 0, root_idx, 0, node_found))
return grub_errno; return grub_errno;
if (found == -1) if (found == -1)
return 0; return 0;
root_idx = found; root_idx = found;
} while (! isleaf); } while (! isleaf);
@ -878,21 +878,21 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path,
} fdrec; } fdrec;
fdrec.frec.type = GRUB_HFS_FILETYPE_DIR; fdrec.frec.type = GRUB_HFS_FILETYPE_DIR;
if (path[0] != '/') if (path[0] != '/')
{ {
grub_error (GRUB_ERR_BAD_FILENAME, "bad filename"); grub_error (GRUB_ERR_BAD_FILENAME, "bad filename");
return 0; return 0;
} }
origpath = grub_strdup (path); origpath = grub_strdup (path);
if (!origpath) if (!origpath)
return grub_errno; return grub_errno;
path = origpath; path = origpath;
while (*path == '/') while (*path == '/')
path++; path++;
while (path && grub_strlen (path)) while (path && grub_strlen (path))
{ {
if (fdrec.frec.type != GRUB_HFS_FILETYPE_DIR) if (fdrec.frec.type != GRUB_HFS_FILETYPE_DIR)
@ -900,7 +900,7 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path,
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
goto fail; goto fail;
} }
/* Isolate a part of the path. */ /* Isolate a part of the path. */
next = grub_strchr (path, '/'); next = grub_strchr (path, '/');
if (next) if (next)
@ -908,13 +908,13 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path,
while (*next == '/') while (*next == '/')
*(next++) = '\0'; *(next++) = '\0';
} }
struct grub_hfs_catalog_key key; struct grub_hfs_catalog_key key;
key.parent_dir = grub_cpu_to_be32 (inode); key.parent_dir = grub_cpu_to_be32 (inode);
key.strlen = grub_strlen (path); key.strlen = grub_strlen (path);
grub_strcpy ((char *) (key.str), path); grub_strcpy ((char *) (key.str), path);
/* Lookup this node. */ /* Lookup this node. */
if (! grub_hfs_find_node (data, (char *) &key, data->cat_root, if (! grub_hfs_find_node (data, (char *) &key, data->cat_root,
0, (char *) &fdrec.frec, sizeof (fdrec.frec))) 0, (char *) &fdrec.frec, sizeof (fdrec.frec)))
@ -925,17 +925,17 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path,
if (grub_errno) if (grub_errno)
goto fail; goto fail;
inode = grub_be_to_cpu32 (fdrec.dir.dirid); inode = grub_be_to_cpu32 (fdrec.dir.dirid);
path = next; path = next;
} }
if (retdata) if (retdata)
grub_memcpy (retdata, &fdrec.frec, sizeof (fdrec.frec)); grub_memcpy (retdata, &fdrec.frec, sizeof (fdrec.frec));
if (retinode) if (retinode)
*retinode = inode; *retinode = inode;
fail: fail:
grub_free (origpath); grub_free (origpath);
return grub_errno; return grub_errno;
@ -944,7 +944,7 @@ grub_hfs_find_dir (struct grub_hfs_data *data, const char *path,
static grub_err_t static grub_err_t
grub_hfs_dir (grub_device_t device, const char *path, grub_hfs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
@ -959,10 +959,10 @@ grub_hfs_dir (grub_device_t device, const char *path,
struct grub_hfs_catalog_key *ckey = rec->key; struct grub_hfs_catalog_key *ckey = rec->key;
struct grub_dirhook_info info; struct grub_dirhook_info info;
grub_memset (&info, 0, sizeof (info)); grub_memset (&info, 0, sizeof (info));
grub_strncpy (fname, (char *) (ckey->str), ckey->strlen); grub_strncpy (fname, (char *) (ckey->str), ckey->strlen);
if (*filetype == GRUB_HFS_FILETYPE_DIR if (*filetype == GRUB_HFS_FILETYPE_DIR
|| *filetype == GRUB_HFS_FILETYPE_FILE) || *filetype == GRUB_HFS_FILETYPE_FILE)
{ {
info.dir = (*filetype == GRUB_HFS_FILETYPE_DIR); info.dir = (*filetype == GRUB_HFS_FILETYPE_DIR);
@ -970,16 +970,16 @@ grub_hfs_dir (grub_device_t device, const char *path,
} }
return 0; return 0;
} }
struct grub_hfs_data *data; struct grub_hfs_data *data;
struct grub_hfs_filerec frec; struct grub_hfs_filerec frec;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_hfs_mount (device->disk); data = grub_hfs_mount (device->disk);
if (!data) if (!data)
goto fail; goto fail;
/* First the directory ID for the directory. */ /* First the directory ID for the directory. */
if (grub_hfs_find_dir (data, path, &frec, &inode)) if (grub_hfs_find_dir (data, path, &frec, &inode))
goto fail; goto fail;
@ -989,14 +989,14 @@ grub_hfs_dir (grub_device_t device, const char *path,
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
goto fail; goto fail;
} }
grub_hfs_iterate_dir (data, data->cat_root, inode, dir_hook); grub_hfs_iterate_dir (data, data->cat_root, inode, dir_hook);
fail: fail:
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
} }
@ -1007,18 +1007,18 @@ grub_hfs_open (struct grub_file *file, const char *name)
{ {
struct grub_hfs_data *data; struct grub_hfs_data *data;
struct grub_hfs_filerec frec; struct grub_hfs_filerec frec;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_hfs_mount (file->device->disk); data = grub_hfs_mount (file->device->disk);
if (grub_hfs_find_dir (data, name, &frec, 0)) if (grub_hfs_find_dir (data, name, &frec, 0))
{ {
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
} }
if (frec.type != GRUB_HFS_FILETYPE_FILE) if (frec.type != GRUB_HFS_FILETYPE_FILE)
{ {
grub_free (data); grub_free (data);
@ -1026,7 +1026,7 @@ grub_hfs_open (struct grub_file *file, const char *name)
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
} }
grub_memcpy (data->extents, frec.extents, sizeof (grub_hfs_datarecord_t)); grub_memcpy (data->extents, frec.extents, sizeof (grub_hfs_datarecord_t));
file->size = grub_be_to_cpu32 (frec.size); file->size = grub_be_to_cpu32 (frec.size);
data->size = grub_be_to_cpu32 (frec.size); data->size = grub_be_to_cpu32 (frec.size);
@ -1034,16 +1034,16 @@ grub_hfs_open (struct grub_file *file, const char *name)
file->offset = 0; file->offset = 0;
file->data = data; file->data = data;
return 0; return 0;
} }
static grub_ssize_t static grub_ssize_t
grub_hfs_read (grub_file_t file, char *buf, grub_size_t len) grub_hfs_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_hfs_data *data = struct grub_hfs_data *data =
(struct grub_hfs_data *) file->data; (struct grub_hfs_data *) file->data;
return grub_hfs_read_file (data, file->read_hook, file->offset, len, buf); return grub_hfs_read_file (data, file->read_hook, file->offset, len, buf);
} }
@ -1065,7 +1065,7 @@ grub_hfs_label (grub_device_t device, char **label)
struct grub_hfs_data *data; struct grub_hfs_data *data;
data = grub_hfs_mount (device->disk); data = grub_hfs_mount (device->disk);
if (data) if (data)
*label = grub_strndup ((char *) (data->sblock.volname + 1), *label = grub_strndup ((char *) (data->sblock.volname + 1),
*data->sblock.volname); *data->sblock.volname);

View file

@ -321,7 +321,7 @@ grub_hfsplus_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
code above used this memory, it can be freed now. */ code above used this memory, it can be freed now. */
grub_free (nnode); grub_free (nnode);
nnode = 0; nnode = 0;
if (blk != -1) if (blk != -1)
return (blk return (blk
+ (node->data->embedded_offset >> (node->data->log2blksize + (node->data->embedded_offset >> (node->data->log2blksize
@ -455,7 +455,7 @@ grub_hfsplus_mount (grub_disk_t disk)
grub_memcpy (&data->catalog_tree.file.extents, grub_memcpy (&data->catalog_tree.file.extents,
data->volheader.catalog_file.extents, data->volheader.catalog_file.extents,
sizeof data->volheader.catalog_file.extents); sizeof data->volheader.catalog_file.extents);
data->catalog_tree.file.size = data->catalog_tree.file.size =
grub_be_to_cpu64 (data->volheader.catalog_file.size); grub_be_to_cpu64 (data->volheader.catalog_file.size);
/* Make a new node for the extent overflow file. */ /* Make a new node for the extent overflow file. */
@ -465,7 +465,7 @@ grub_hfsplus_mount (grub_disk_t disk)
data->volheader.extents_file.extents, data->volheader.extents_file.extents,
sizeof data->volheader.catalog_file.extents); sizeof data->volheader.catalog_file.extents);
data->extoverflow_tree.file.size = data->extoverflow_tree.file.size =
grub_be_to_cpu64 (data->volheader.extents_file.size); grub_be_to_cpu64 (data->volheader.extents_file.size);
/* Read the essential information about the trees. */ /* Read the essential information about the trees. */
@ -518,10 +518,10 @@ grub_hfsplus_cmp_catkey (struct grub_hfsplus_key *keya,
char *filename; char *filename;
int i; int i;
int diff; int diff;
diff = grub_be_to_cpu32 (catkey_a->parent) - catkey_b->parent; diff = grub_be_to_cpu32 (catkey_a->parent) - catkey_b->parent;
if (diff) if (diff)
return diff; return diff;
/* Change the filename in keya so the endianness is correct. */ /* Change the filename in keya so the endianness is correct. */
for (i = 0; i < grub_be_to_cpu16 (catkey_a->namelen); i++) for (i = 0; i < grub_be_to_cpu16 (catkey_a->namelen); i++)
@ -592,7 +592,7 @@ grub_hfsplus_btree_iterate_node (struct grub_hfsplus_btree *btree,
int first_rec, int first_rec,
int (*hook) (void *record)) int (*hook) (void *record))
{ {
int rec; int rec;
for (;;) for (;;)
{ {
@ -661,8 +661,8 @@ grub_hfsplus_btree_search (struct grub_hfsplus_btree *btree,
for (rec = 0; rec < grub_be_to_cpu16 (nodedesc->count); rec++) for (rec = 0; rec < grub_be_to_cpu16 (nodedesc->count); rec++)
{ {
struct grub_hfsplus_key *currkey; struct grub_hfsplus_key *currkey;
currkey = grub_hfsplus_btree_recptr (btree, nodedesc, rec); currkey = grub_hfsplus_btree_recptr (btree, nodedesc, rec);
/* The action that has to be taken depend on the type of /* The action that has to be taken depend on the type of
record. */ record. */
if (nodedesc->type == GRUB_HFSPLUS_BTNODE_TYPE_LEAF if (nodedesc->type == GRUB_HFSPLUS_BTNODE_TYPE_LEAF
@ -716,7 +716,7 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
grub_fshelp_node_t node)) grub_fshelp_node_t node))
{ {
int ret = 0; int ret = 0;
auto int list_nodes (void *record); auto int list_nodes (void *record);
int list_nodes (void *record) int list_nodes (void *record)
{ {
@ -730,7 +730,7 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
catkey = (struct grub_hfsplus_catkey *) record; catkey = (struct grub_hfsplus_catkey *) record;
fileinfo = fileinfo =
(struct grub_hfsplus_catfile *) ((char *) record (struct grub_hfsplus_catfile *) ((char *) record
+ grub_be_to_cpu16 (catkey->keylen) + grub_be_to_cpu16 (catkey->keylen)
+ 2 + (grub_be_to_cpu16(catkey->keylen) + 2 + (grub_be_to_cpu16(catkey->keylen)
% 2)); % 2));
@ -796,7 +796,7 @@ grub_hfsplus_iterate_dir (grub_fshelp_node_t dir,
callback function. */ callback function. */
node = grub_malloc (sizeof (*node)); node = grub_malloc (sizeof (*node));
node->data = dir->data; node->data = dir->data;
grub_memcpy (node->extents, fileinfo->data.extents, grub_memcpy (node->extents, fileinfo->data.extents,
sizeof (node->extents)); sizeof (node->extents));
node->mtime = grub_be_to_cpu32 (fileinfo->mtime) - 2082844800; node->mtime = grub_be_to_cpu32 (fileinfo->mtime) - 2082844800;
@ -839,9 +839,9 @@ grub_hfsplus_open (struct grub_file *file, const char *name)
{ {
struct grub_hfsplus_data *data; struct grub_hfsplus_data *data;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_hfsplus_mount (file->device->disk); data = grub_hfsplus_mount (file->device->disk);
if (!data) if (!data)
goto fail; goto fail;
@ -865,7 +865,7 @@ grub_hfsplus_open (struct grub_file *file, const char *name)
if (data && fdiro != &data->dirroot) if (data && fdiro != &data->dirroot)
grub_free (fdiro); grub_free (fdiro);
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
@ -887,7 +887,7 @@ grub_hfsplus_close (grub_file_t file)
static grub_ssize_t static grub_ssize_t
grub_hfsplus_read (grub_file_t file, char *buf, grub_size_t len) grub_hfsplus_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_hfsplus_data *data = struct grub_hfsplus_data *data =
(struct grub_hfsplus_data *) file->data; (struct grub_hfsplus_data *) file->data;
int size = grub_hfsplus_read_file (&data->opened_file, file->read_hook, int size = grub_hfsplus_read_file (&data->opened_file, file->read_hook,
@ -898,13 +898,13 @@ grub_hfsplus_read (grub_file_t file, char *buf, grub_size_t len)
static grub_err_t static grub_err_t
grub_hfsplus_dir (grub_device_t device, const char *path, grub_hfsplus_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_hfsplus_data *data = 0; struct grub_hfsplus_data *data = 0;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
auto int NESTED_FUNC_ATTR iterate (const char *filename, auto int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype, enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node); grub_fshelp_node_t node);
@ -924,7 +924,7 @@ grub_hfsplus_dir (grub_device_t device, const char *path,
} }
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_hfsplus_mount (device->disk); data = grub_hfsplus_mount (device->disk);
if (!data) if (!data)
goto fail; goto fail;
@ -938,7 +938,7 @@ grub_hfsplus_dir (grub_device_t device, const char *path,
/* Iterate over all entries in this directory. */ /* Iterate over all entries in this directory. */
grub_hfsplus_iterate_dir (fdiro, iterate); grub_hfsplus_iterate_dir (fdiro, iterate);
fail: fail:
if (data && fdiro != &data->dirroot) if (data && fdiro != &data->dirroot)
grub_free (fdiro); grub_free (fdiro);
@ -961,7 +961,7 @@ grub_hfsplus_label (grub_device_t device __attribute__((unused))
} }
/* Get mtime. */ /* Get mtime. */
static grub_err_t static grub_err_t
grub_hfsplus_mtime (grub_device_t device, grub_int32_t *tm) grub_hfsplus_mtime (grub_device_t device, grub_int32_t *tm)
{ {
struct grub_hfsplus_data *data; struct grub_hfsplus_data *data;
@ -972,7 +972,7 @@ grub_hfsplus_mtime (grub_device_t device, grub_int32_t *tm)
data = grub_hfsplus_mount (disk); data = grub_hfsplus_mount (disk);
if (!data) if (!data)
*tm = 0; *tm = 0;
else else
*tm = grub_be_to_cpu32 (data->volheader.utime) - 2082844800; *tm = grub_be_to_cpu32 (data->volheader.utime) - 2082844800;
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
@ -995,8 +995,8 @@ grub_hfsplus_uuid (grub_device_t device, char **uuid)
if (data) if (data)
{ {
*uuid = grub_malloc (16 + sizeof ('\0')); *uuid = grub_malloc (16 + sizeof ('\0'));
grub_sprintf (*uuid, "%016llx", grub_sprintf (*uuid, "%016llx",
(unsigned long long) (unsigned long long)
grub_be_to_cpu64 (data->volheader.num_serial)); grub_be_to_cpu64 (data->volheader.num_serial));
} }
else else

View file

@ -164,27 +164,27 @@ grub_iso9660_susp_iterate (struct grub_iso9660_data *data,
{ {
char *sua; char *sua;
struct grub_iso9660_susp_entry *entry; struct grub_iso9660_susp_entry *entry;
auto grub_err_t load_sua (void); auto grub_err_t load_sua (void);
/* Load a part of the System Usage Area. */ /* Load a part of the System Usage Area. */
grub_err_t load_sua (void) grub_err_t load_sua (void)
{ {
sua = grub_malloc (sua_size); sua = grub_malloc (sua_size);
if (!sua) if (!sua)
return grub_errno; return grub_errno;
if (grub_disk_read (data->disk, sua_block, sua_pos, if (grub_disk_read (data->disk, sua_block, sua_pos,
sua_size, sua)) sua_size, sua))
return grub_errno; return grub_errno;
entry = (struct grub_iso9660_susp_entry *) sua; entry = (struct grub_iso9660_susp_entry *) sua;
return 0; return 0;
} }
if (load_sua ()) if (load_sua ())
return grub_errno; return grub_errno;
for (; (char *) entry < (char *) sua + sua_size - 1; for (; (char *) entry < (char *) sua + sua_size - 1;
entry = (struct grub_iso9660_susp_entry *) entry = (struct grub_iso9660_susp_entry *)
((char *) entry + entry->len)) ((char *) entry + entry->len))
@ -192,29 +192,29 @@ grub_iso9660_susp_iterate (struct grub_iso9660_data *data,
/* The last entry. */ /* The last entry. */
if (grub_strncmp ((char *) entry->sig, "ST", 2) == 0) if (grub_strncmp ((char *) entry->sig, "ST", 2) == 0)
break; break;
/* Additional entries are stored elsewhere. */ /* Additional entries are stored elsewhere. */
if (grub_strncmp ((char *) entry->sig, "CE", 2) == 0) if (grub_strncmp ((char *) entry->sig, "CE", 2) == 0)
{ {
struct grub_iso9660_susp_ce *ce; struct grub_iso9660_susp_ce *ce;
ce = (struct grub_iso9660_susp_ce *) entry; ce = (struct grub_iso9660_susp_ce *) entry;
sua_size = grub_le_to_cpu32 (ce->len); sua_size = grub_le_to_cpu32 (ce->len);
sua_pos = grub_le_to_cpu32 (ce->off); sua_pos = grub_le_to_cpu32 (ce->off);
sua_block = grub_le_to_cpu32 (ce->blk) << GRUB_ISO9660_LOG2_BLKSZ; sua_block = grub_le_to_cpu32 (ce->blk) << GRUB_ISO9660_LOG2_BLKSZ;
grub_free (sua); grub_free (sua);
if (load_sua ()) if (load_sua ())
return grub_errno; return grub_errno;
} }
if (hook (entry)) if (hook (entry))
{ {
grub_free (sua); grub_free (sua);
return 0; return 0;
} }
} }
grub_free (sua); grub_free (sua);
return 0; return 0;
} }
@ -248,9 +248,9 @@ grub_iso9660_mount (grub_disk_t disk)
struct grub_iso9660_susp_entry *entry; struct grub_iso9660_susp_entry *entry;
struct grub_iso9660_primary_voldesc voldesc; struct grub_iso9660_primary_voldesc voldesc;
int block; int block;
auto grub_err_t susp_iterate (struct grub_iso9660_susp_entry *); auto grub_err_t susp_iterate (struct grub_iso9660_susp_entry *);
grub_err_t susp_iterate (struct grub_iso9660_susp_entry *susp_entry) grub_err_t susp_iterate (struct grub_iso9660_susp_entry *susp_entry)
{ {
/* The "ER" entry is used to detect extensions. The /* The "ER" entry is used to detect extensions. The
@ -262,11 +262,11 @@ grub_iso9660_mount (grub_disk_t disk)
} }
return 0; return 0;
} }
data = grub_malloc (sizeof (struct grub_iso9660_data)); data = grub_malloc (sizeof (struct grub_iso9660_data));
if (! data) if (! data)
return 0; return 0;
data->disk = disk; data->disk = disk;
data->rockridge = 0; data->rockridge = 0;
data->joliet = 0; data->joliet = 0;
@ -319,7 +319,7 @@ grub_iso9660_mount (grub_disk_t disk)
grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem"); grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem");
goto fail; goto fail;
} }
sua_pos = (sizeof (rootdir) + rootdir.namelen sua_pos = (sizeof (rootdir) + rootdir.namelen
+ (rootdir.namelen % 2) - 1); + (rootdir.namelen % 2) - 1);
sua_size = rootdir.len - sua_pos; sua_size = rootdir.len - sua_pos;
@ -327,7 +327,7 @@ grub_iso9660_mount (grub_disk_t disk)
sua = grub_malloc (sua_size); sua = grub_malloc (sua_size);
if (! sua) if (! sua)
goto fail; goto fail;
if (grub_disk_read (disk, (grub_le_to_cpu32 (data->voldesc.rootdir.first_sector) if (grub_disk_read (disk, (grub_le_to_cpu32 (data->voldesc.rootdir.first_sector)
<< GRUB_ISO9660_LOG2_BLKSZ), sua_pos, << GRUB_ISO9660_LOG2_BLKSZ), sua_pos,
sua_size, sua)) sua_size, sua))
@ -335,9 +335,9 @@ grub_iso9660_mount (grub_disk_t disk)
grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem"); grub_error (GRUB_ERR_BAD_FS, "not a iso9660 filesystem");
goto fail; goto fail;
} }
entry = (struct grub_iso9660_susp_entry *) sua; entry = (struct grub_iso9660_susp_entry *) sua;
/* Test if the SUSP protocol is used on this filesystem. */ /* Test if the SUSP protocol is used on this filesystem. */
if (grub_strncmp ((char *) entry->sig, "SP", 2) == 0) if (grub_strncmp ((char *) entry->sig, "SP", 2) == 0)
{ {
@ -345,7 +345,7 @@ grub_iso9660_mount (grub_disk_t disk)
to get to the SUA (System Usage Area). */ to get to the SUA (System Usage Area). */
data->susp_skip = entry->data[2]; data->susp_skip = entry->data[2];
entry = (struct grub_iso9660_susp_entry *) ((char *) entry + entry->len); entry = (struct grub_iso9660_susp_entry *) ((char *) entry + entry->len);
/* Iterate over the entries in the SUA area to detect /* Iterate over the entries in the SUA area to detect
extensions. */ extensions. */
if (grub_iso9660_susp_iterate (data, if (grub_iso9660_susp_iterate (data,
@ -354,9 +354,9 @@ grub_iso9660_mount (grub_disk_t disk)
sua_pos, sua_size, susp_iterate)) sua_pos, sua_size, susp_iterate))
goto fail; goto fail;
} }
return data; return data;
fail: fail:
grub_free (data); grub_free (data);
return 0; return 0;
@ -371,7 +371,7 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node)
int sua_size; int sua_size;
char *symlink = 0; char *symlink = 0;
int addslash = 0; int addslash = 0;
auto void add_part (const char *part, int len); auto void add_part (const char *part, int len);
auto grub_err_t susp_iterate_sl (struct grub_iso9660_susp_entry *); auto grub_err_t susp_iterate_sl (struct grub_iso9660_susp_entry *);
@ -379,14 +379,14 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node)
void add_part (const char *part, int len) void add_part (const char *part, int len)
{ {
int size = grub_strlen (symlink); int size = grub_strlen (symlink);
symlink = grub_realloc (symlink, size + len + 1); symlink = grub_realloc (symlink, size + len + 1);
if (! symlink) if (! symlink)
return; return;
grub_strncat (symlink, part, len); grub_strncat (symlink, part, len);
} }
/* Read in a symlink. */ /* Read in a symlink. */
grub_err_t susp_iterate_sl (struct grub_iso9660_susp_entry *entry) grub_err_t susp_iterate_sl (struct grub_iso9660_susp_entry *entry)
{ {
@ -402,7 +402,7 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node)
add_part ("/", 1); add_part ("/", 1);
addslash = 0; addslash = 0;
} }
/* The current position is the `Component Flag'. */ /* The current position is the `Component Flag'. */
switch (entry->data[pos] & 30) switch (entry->data[pos] & 30)
{ {
@ -418,15 +418,15 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node)
break; break;
} }
case 2: case 2:
add_part ("./", 2); add_part ("./", 2);
break; break;
case 4: case 4:
add_part ("../", 3); add_part ("../", 3);
break; break;
case 8: case 8:
add_part ("/", 1); add_part ("/", 1);
break; break;
@ -435,29 +435,29 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node)
stored. */ stored. */
pos += entry->data[pos + 1] + 2; pos += entry->data[pos + 1] + 2;
} }
/* Check if `grub_realloc' failed. */ /* Check if `grub_realloc' failed. */
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
} }
return 0; return 0;
} }
if (grub_disk_read (node->data->disk, node->dir_blk, node->dir_off, if (grub_disk_read (node->data->disk, node->dir_blk, node->dir_off,
sizeof (dirent), (char *) &dirent)) sizeof (dirent), (char *) &dirent))
return 0; return 0;
sua_off = (sizeof (dirent) + dirent.namelen + 1 - (dirent.namelen % 2) sua_off = (sizeof (dirent) + dirent.namelen + 1 - (dirent.namelen % 2)
+ node->data->susp_skip); + node->data->susp_skip);
sua_size = dirent.len - sua_off; sua_size = dirent.len - sua_off;
symlink = grub_malloc (1); symlink = grub_malloc (1);
if (!symlink) if (!symlink)
return 0; return 0;
*symlink = '\0'; *symlink = '\0';
if (grub_iso9660_susp_iterate (node->data, node->dir_blk, if (grub_iso9660_susp_iterate (node->data, node->dir_blk,
node->dir_off + sua_off, node->dir_off + sua_off,
sua_size, susp_iterate_sl)) sua_size, susp_iterate_sl))
@ -465,7 +465,7 @@ grub_iso9660_read_symlink (grub_fshelp_node_t node)
grub_free (symlink); grub_free (symlink);
return 0; return 0;
} }
return symlink; return symlink;
} }
@ -482,7 +482,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
char *filename; char *filename;
int filename_alloc = 0; int filename_alloc = 0;
enum grub_fshelp_filetype type; enum grub_fshelp_filetype type;
auto grub_err_t susp_iterate_dir (struct grub_iso9660_susp_entry *); auto grub_err_t susp_iterate_dir (struct grub_iso9660_susp_entry *);
grub_err_t susp_iterate_dir (struct grub_iso9660_susp_entry *entry) grub_err_t susp_iterate_dir (struct grub_iso9660_susp_entry *entry)
@ -540,7 +540,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
type = GRUB_FSHELP_UNKNOWN; type = GRUB_FSHELP_UNKNOWN;
} }
} }
return 0; return 0;
} }
@ -552,14 +552,14 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
offset % GRUB_DISK_SECTOR_SIZE, offset % GRUB_DISK_SECTOR_SIZE,
sizeof (dirent), (char *) &dirent)) sizeof (dirent), (char *) &dirent))
return 0; return 0;
/* The end of the block, skip to the next one. */ /* The end of the block, skip to the next one. */
if (!dirent.len) if (!dirent.len)
{ {
offset = (offset / GRUB_ISO9660_BLKSZ + 1) * GRUB_ISO9660_BLKSZ; offset = (offset / GRUB_ISO9660_BLKSZ + 1) * GRUB_ISO9660_BLKSZ;
continue; continue;
} }
{ {
char name[dirent.namelen + 1]; char name[dirent.namelen + 1];
int nameoffset = offset + sizeof (dirent); int nameoffset = offset + sizeof (dirent);
@ -567,9 +567,9 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
int sua_off = (sizeof (dirent) + dirent.namelen + 1 int sua_off = (sizeof (dirent) + dirent.namelen + 1
- (dirent.namelen % 2));; - (dirent.namelen % 2));;
int sua_size = dirent.len - sua_off; int sua_size = dirent.len - sua_off;
sua_off += offset + dir->data->susp_skip; sua_off += offset + dir->data->susp_skip;
filename = 0; filename = 0;
filename_alloc = 0; filename_alloc = 0;
type = GRUB_FSHELP_UNKNOWN; type = GRUB_FSHELP_UNKNOWN;
@ -582,7 +582,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
sua_off % GRUB_DISK_SECTOR_SIZE, sua_off % GRUB_DISK_SECTOR_SIZE,
sua_size, susp_iterate_dir)) sua_size, susp_iterate_dir))
return 0; return 0;
/* Read the name. */ /* Read the name. */
if (grub_disk_read (dir->data->disk, if (grub_disk_read (dir->data->disk,
(dir->blk << GRUB_ISO9660_LOG2_BLKSZ) (dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
@ -590,11 +590,11 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
nameoffset % GRUB_DISK_SECTOR_SIZE, nameoffset % GRUB_DISK_SECTOR_SIZE,
dirent.namelen, (char *) name)) dirent.namelen, (char *) name))
return 0; return 0;
node = grub_malloc (sizeof (struct grub_fshelp_node)); node = grub_malloc (sizeof (struct grub_fshelp_node));
if (!node) if (!node)
return 0; return 0;
/* Setup a new node. */ /* Setup a new node. */
node->data = dir->data; node->data = dir->data;
node->size = grub_le_to_cpu32 (dirent.size); node->size = grub_le_to_cpu32 (dirent.size);
@ -602,7 +602,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
node->dir_blk = ((dir->blk << GRUB_ISO9660_LOG2_BLKSZ) node->dir_blk = ((dir->blk << GRUB_ISO9660_LOG2_BLKSZ)
+ offset / GRUB_DISK_SECTOR_SIZE); + offset / GRUB_DISK_SECTOR_SIZE);
node->dir_off = offset % GRUB_DISK_SECTOR_SIZE; node->dir_off = offset % GRUB_DISK_SECTOR_SIZE;
/* If the filetype was not stored using rockridge, use /* If the filetype was not stored using rockridge, use
whatever is stored in the iso9660 filesystem. */ whatever is stored in the iso9660 filesystem. */
if (type == GRUB_FSHELP_UNKNOWN) if (type == GRUB_FSHELP_UNKNOWN)
@ -612,7 +612,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
else else
type = GRUB_FSHELP_REG; type = GRUB_FSHELP_REG;
} }
/* The filename was not stored in a rock ridge entry. Read it /* The filename was not stored in a rock ridge entry. Read it
from the iso9660 filesystem. */ from the iso9660 filesystem. */
if (!filename) if (!filename)
@ -621,7 +621,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
filename = grub_strrchr (name, ';'); filename = grub_strrchr (name, ';');
if (filename) if (filename)
*filename = '\0'; *filename = '\0';
if (dirent.namelen == 1 && name[0] == 0) if (dirent.namelen == 1 && name[0] == 0)
filename = "."; filename = ".";
else if (dirent.namelen == 1 && name[0] == 1) else if (dirent.namelen == 1 && name[0] == 1)
@ -629,7 +629,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
else else
filename = name; filename = name;
} }
if (dir->data->joliet) if (dir->data->joliet)
{ {
char *oldname; char *oldname;
@ -653,24 +653,24 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
if (filename_alloc) if (filename_alloc)
grub_free (filename); grub_free (filename);
} }
offset += dirent.len; offset += dirent.len;
} }
return 0; return 0;
} }
static grub_err_t static grub_err_t
grub_iso9660_dir (grub_device_t device, const char *path, grub_iso9660_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_iso9660_data *data = 0; struct grub_iso9660_data *data = 0;
struct grub_fshelp_node rootnode; struct grub_fshelp_node rootnode;
struct grub_fshelp_node *foundnode; struct grub_fshelp_node *foundnode;
auto int NESTED_FUNC_ATTR iterate (const char *filename, auto int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype, enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node); grub_fshelp_node_t node);
@ -691,11 +691,11 @@ grub_iso9660_dir (grub_device_t device, const char *path,
data = grub_iso9660_mount (device->disk); data = grub_iso9660_mount (device->disk);
if (! data) if (! data)
goto fail; goto fail;
rootnode.data = data; rootnode.data = data;
rootnode.blk = grub_le_to_cpu32 (data->voldesc.rootdir.first_sector); rootnode.blk = grub_le_to_cpu32 (data->voldesc.rootdir.first_sector);
rootnode.size = grub_le_to_cpu32 (data->voldesc.rootdir.size); rootnode.size = grub_le_to_cpu32 (data->voldesc.rootdir.size);
/* Use the fshelp function to traverse the path. */ /* Use the fshelp function to traverse the path. */
if (grub_fshelp_find_file (path, &rootnode, if (grub_fshelp_find_file (path, &rootnode,
&foundnode, &foundnode,
@ -703,13 +703,13 @@ grub_iso9660_dir (grub_device_t device, const char *path,
grub_iso9660_read_symlink, grub_iso9660_read_symlink,
GRUB_FSHELP_DIR)) GRUB_FSHELP_DIR))
goto fail; goto fail;
/* List the files in the directory. */ /* List the files in the directory. */
grub_iso9660_iterate_dir (foundnode, iterate); grub_iso9660_iterate_dir (foundnode, iterate);
if (foundnode != &rootnode) if (foundnode != &rootnode)
grub_free (foundnode); grub_free (foundnode);
fail: fail:
grub_free (data); grub_free (data);
@ -726,17 +726,17 @@ grub_iso9660_open (struct grub_file *file, const char *name)
struct grub_iso9660_data *data; struct grub_iso9660_data *data;
struct grub_fshelp_node rootnode; struct grub_fshelp_node rootnode;
struct grub_fshelp_node *foundnode; struct grub_fshelp_node *foundnode;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_iso9660_mount (file->device->disk); data = grub_iso9660_mount (file->device->disk);
if (!data) if (!data)
goto fail; goto fail;
rootnode.data = data; rootnode.data = data;
rootnode.blk = grub_le_to_cpu32 (data->voldesc.rootdir.first_sector); rootnode.blk = grub_le_to_cpu32 (data->voldesc.rootdir.first_sector);
rootnode.size = grub_le_to_cpu32 (data->voldesc.rootdir.size); rootnode.size = grub_le_to_cpu32 (data->voldesc.rootdir.size);
/* Use the fshelp function to traverse the path. */ /* Use the fshelp function to traverse the path. */
if (grub_fshelp_find_file (name, &rootnode, if (grub_fshelp_find_file (name, &rootnode,
&foundnode, &foundnode,
@ -744,21 +744,21 @@ grub_iso9660_open (struct grub_file *file, const char *name)
grub_iso9660_read_symlink, grub_iso9660_read_symlink,
GRUB_FSHELP_REG)) GRUB_FSHELP_REG))
goto fail; goto fail;
data->first_sector = foundnode->blk; data->first_sector = foundnode->blk;
data->length = foundnode->size; data->length = foundnode->size;
file->data = data; file->data = data;
file->size = foundnode->size; file->size = foundnode->size;
file->offset = 0; file->offset = 0;
return 0; return 0;
fail: fail:
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
grub_free (data); grub_free (data);
return grub_errno;; return grub_errno;;
} }
@ -766,17 +766,17 @@ grub_iso9660_open (struct grub_file *file, const char *name)
static grub_ssize_t static grub_ssize_t
grub_iso9660_read (grub_file_t file, char *buf, grub_size_t len) grub_iso9660_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_iso9660_data *data = struct grub_iso9660_data *data =
(struct grub_iso9660_data *) file->data; (struct grub_iso9660_data *) file->data;
/* XXX: The file is stored in as a single extent. */ /* XXX: The file is stored in as a single extent. */
data->disk->read_hook = file->read_hook; data->disk->read_hook = file->read_hook;
grub_disk_read (data->disk, grub_disk_read (data->disk,
data->first_sector << GRUB_ISO9660_LOG2_BLKSZ, data->first_sector << GRUB_ISO9660_LOG2_BLKSZ,
file->offset, file->offset,
len, buf); len, buf);
data->disk->read_hook = 0; data->disk->read_hook = 0;
return len; return len;
} }
@ -785,9 +785,9 @@ static grub_err_t
grub_iso9660_close (grub_file_t file) grub_iso9660_close (grub_file_t file)
{ {
grub_free (file->data); grub_free (file->data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -797,7 +797,7 @@ grub_iso9660_label (grub_device_t device, char **label)
{ {
struct grub_iso9660_data *data; struct grub_iso9660_data *data;
data = grub_iso9660_mount (device->disk); data = grub_iso9660_mount (device->disk);
if (data) if (data)
{ {
if (data->joliet) if (data->joliet)
@ -837,11 +837,11 @@ grub_iso9660_uuid (grub_device_t device, char **uuid)
grub_error (GRUB_ERR_BAD_NUMBER, "No creation date in filesystem to generate UUID."); grub_error (GRUB_ERR_BAD_NUMBER, "No creation date in filesystem to generate UUID.");
*uuid = NULL; *uuid = NULL;
} }
else else
{ {
*uuid = grub_malloc (sizeof ("YYYY-MM-DD-HH-mm-ss-hh")); *uuid = grub_malloc (sizeof ("YYYY-MM-DD-HH-mm-ss-hh"));
grub_sprintf (*uuid, "%c%c%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c", grub_sprintf (*uuid, "%c%c%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c",
data->voldesc.modified.year[0], data->voldesc.modified.year[1], data->voldesc.modified.year[0], data->voldesc.modified.year[1],
data->voldesc.modified.year[2], data->voldesc.modified.year[3], data->voldesc.modified.year[2], data->voldesc.modified.year[3],
data->voldesc.modified.month[0], data->voldesc.modified.month[1], data->voldesc.modified.month[0], data->voldesc.modified.month[1],
data->voldesc.modified.day[0], data->voldesc.modified.day[1], data->voldesc.modified.day[0], data->voldesc.modified.day[1],

186
fs/jfs.c
View file

@ -43,14 +43,14 @@ struct grub_jfs_sblock
grub_uint8_t magic[4]; grub_uint8_t magic[4];
grub_uint32_t version; grub_uint32_t version;
grub_uint64_t ag_size; grub_uint64_t ag_size;
/* The size of a filesystem block in bytes. XXX: currently only /* The size of a filesystem block in bytes. XXX: currently only
4096 was tested. */ 4096 was tested. */
grub_uint32_t blksz; grub_uint32_t blksz;
grub_uint16_t log2_blksz; grub_uint16_t log2_blksz;
grub_uint8_t unused[71]; grub_uint8_t unused[71];
grub_uint8_t volname[11]; grub_uint8_t volname[11];
}; };
struct grub_jfs_extent struct grub_jfs_extent
@ -58,7 +58,7 @@ struct grub_jfs_extent
/* The length of the extent in filesystem blocks. */ /* The length of the extent in filesystem blocks. */
grub_uint16_t length; grub_uint16_t length;
grub_uint8_t length2; grub_uint8_t length2;
/* The physical offset of the first block on the disk. */ /* The physical offset of the first block on the disk. */
grub_uint8_t blk1; grub_uint8_t blk1;
grub_uint32_t blk2; grub_uint32_t blk2;
@ -76,10 +76,10 @@ struct grub_jfs_treehead
{ {
grub_uint64_t next; grub_uint64_t next;
grub_uint64_t prev; grub_uint64_t prev;
grub_uint8_t flags; grub_uint8_t flags;
grub_uint8_t unused; grub_uint8_t unused;
grub_uint16_t count; grub_uint16_t count;
grub_uint16_t max; grub_uint16_t max;
grub_uint8_t unused2[10]; grub_uint8_t unused2[10];
@ -94,7 +94,7 @@ struct grub_jfs_tree_extent
/* The offset is the key used to lookup an extent. */ /* The offset is the key used to lookup an extent. */
grub_uint8_t offset1; grub_uint8_t offset1;
grub_uint32_t offset2; grub_uint32_t offset2;
struct grub_jfs_extent extent; struct grub_jfs_extent extent;
} __attribute__ ((packed)); } __attribute__ ((packed));
@ -105,15 +105,15 @@ struct grub_jfs_tree_dir
this level. */ this level. */
grub_uint64_t nextb; grub_uint64_t nextb;
grub_uint64_t prevb; grub_uint64_t prevb;
grub_uint8_t flags; grub_uint8_t flags;
/* The amount of dirents in this node. */ /* The amount of dirents in this node. */
grub_uint8_t count; grub_uint8_t count;
grub_uint8_t freecnt; grub_uint8_t freecnt;
grub_uint8_t freelist; grub_uint8_t freelist;
grub_uint8_t maxslot; grub_uint8_t maxslot;
/* The location of the sorted array of pointers to dirents. */ /* The location of the sorted array of pointers to dirents. */
grub_uint8_t sindex; grub_uint8_t sindex;
grub_uint8_t unused[10]; grub_uint8_t unused[10];
@ -161,7 +161,7 @@ struct grub_jfs_inode
grub_uint32_t mode; grub_uint32_t mode;
grub_uint8_t unused3[72]; grub_uint8_t unused3[72];
grub_uint8_t unused4[96]; grub_uint8_t unused4[96];
union union
{ {
/* The tree describing the extents of the file. */ /* The tree describing the extents of the file. */
@ -177,7 +177,7 @@ struct grub_jfs_inode
{ {
grub_uint8_t unused[16]; grub_uint8_t unused[16];
grub_uint8_t flags; grub_uint8_t flags;
/* Amount of dirents in this node. */ /* Amount of dirents in this node. */
grub_uint8_t count; grub_uint8_t count;
grub_uint8_t freecnt; grub_uint8_t freecnt;
@ -222,7 +222,7 @@ struct grub_jfs_diropen
char *sorted; char *sorted;
struct grub_jfs_leaf_dirent *leaf; struct grub_jfs_leaf_dirent *leaf;
struct grub_jfs_leaf_next_dirent *next_leaf; struct grub_jfs_leaf_next_dirent *next_leaf;
/* The filename and inode of the last read dirent. */ /* The filename and inode of the last read dirent. */
char name[255]; char name[255];
grub_uint32_t ino; grub_uint32_t ino;
@ -241,19 +241,19 @@ grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode,
{ {
auto int getblk (struct grub_jfs_treehead *treehead, auto int getblk (struct grub_jfs_treehead *treehead,
struct grub_jfs_tree_extent *extents); struct grub_jfs_tree_extent *extents);
int getblk (struct grub_jfs_treehead *treehead, int getblk (struct grub_jfs_treehead *treehead,
struct grub_jfs_tree_extent *extents) struct grub_jfs_tree_extent *extents)
{ {
int found = -1; int found = -1;
int i; int i;
for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2; i++) for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2; i++)
{ {
if (treehead->flags & GRUB_JFS_TREE_LEAF) if (treehead->flags & GRUB_JFS_TREE_LEAF)
{ {
/* Read the leafnode. */ /* Read the leafnode. */
if (grub_le_to_cpu32 (extents[i].offset2) <= blk if (grub_le_to_cpu32 (extents[i].offset2) <= blk
&& ((grub_le_to_cpu16 (extents[i].extent.length)) && ((grub_le_to_cpu16 (extents[i].extent.length))
+ (extents[i].extent.length2 << 8) + (extents[i].extent.length2 << 8)
+ grub_le_to_cpu32 (extents[i].offset2)) > blk) + grub_le_to_cpu32 (extents[i].offset2)) > blk)
@ -264,7 +264,7 @@ grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode,
if (blk >= grub_le_to_cpu32 (extents[i].offset2)) if (blk >= grub_le_to_cpu32 (extents[i].offset2))
found = i; found = i;
} }
if (found != -1) if (found != -1)
{ {
struct struct
@ -272,20 +272,20 @@ grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode,
struct grub_jfs_treehead treehead; struct grub_jfs_treehead treehead;
struct grub_jfs_tree_extent extents[254]; struct grub_jfs_tree_extent extents[254];
} tree; } tree;
if (grub_disk_read (data->disk, if (grub_disk_read (data->disk,
grub_le_to_cpu32 (extents[found].extent.blk2) grub_le_to_cpu32 (extents[found].extent.blk2)
<< (grub_le_to_cpu16 (data->sblock.log2_blksz) << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS), 0, - GRUB_DISK_SECTOR_BITS), 0,
sizeof (tree), (char *) &tree)) sizeof (tree), (char *) &tree))
return -1; return -1;
return getblk (&tree.treehead, &tree.extents[0]); return getblk (&tree.treehead, &tree.extents[0]);
} }
return -1; return -1;
} }
return getblk (&inode->file.tree, &inode->file.extents[0]); return getblk (&inode->file.tree, &inode->file.extents[0]);
} }
@ -311,12 +311,12 @@ grub_jfs_read_inode (struct grub_jfs_data *data, int ino,
- GRUB_DISK_SECTOR_BITS), 0, - GRUB_DISK_SECTOR_BITS), 0,
sizeof (struct grub_jfs_iag), &iag)) sizeof (struct grub_jfs_iag), &iag))
return grub_errno; return grub_errno;
inoblk = grub_le_to_cpu32 (iag.inodes[inoext].blk2); inoblk = grub_le_to_cpu32 (iag.inodes[inoext].blk2);
inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS); - GRUB_DISK_SECTOR_BITS);
inoblk += inonum; inoblk += inonum;
if (grub_disk_read (data->disk, inoblk, 0, if (grub_disk_read (data->disk, inoblk, 0,
sizeof (struct grub_jfs_inode), inode)) sizeof (struct grub_jfs_inode), inode))
return grub_errno; return grub_errno;
@ -338,13 +338,13 @@ grub_jfs_mount (grub_disk_t disk)
if (grub_disk_read (disk, GRUB_JFS_SBLOCK, 0, if (grub_disk_read (disk, GRUB_JFS_SBLOCK, 0,
sizeof (struct grub_jfs_sblock), &data->sblock)) sizeof (struct grub_jfs_sblock), &data->sblock))
goto fail; goto fail;
if (grub_strncmp ((char *) (data->sblock.magic), "JFS1", 4)) if (grub_strncmp ((char *) (data->sblock.magic), "JFS1", 4))
{ {
grub_error (GRUB_ERR_BAD_FS, "not a jfs filesystem"); grub_error (GRUB_ERR_BAD_FS, "not a jfs filesystem");
goto fail; goto fail;
} }
data->disk = disk; data->disk = disk;
data->pos = 0; data->pos = 0;
data->linknest = 0; data->linknest = 0;
@ -353,15 +353,15 @@ grub_jfs_mount (grub_disk_t disk)
if (grub_disk_read (data->disk, GRUB_JFS_FS1_INODE_BLK, 0, if (grub_disk_read (data->disk, GRUB_JFS_FS1_INODE_BLK, 0,
sizeof (struct grub_jfs_inode), &data->fileset)) sizeof (struct grub_jfs_inode), &data->fileset))
goto fail; goto fail;
return data; return data;
fail: fail:
grub_free (data); grub_free (data);
if (grub_errno == GRUB_ERR_OUT_OF_RANGE) if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_error (GRUB_ERR_BAD_FS, "not a jfs filesystem"); grub_error (GRUB_ERR_BAD_FS, "not a jfs filesystem");
return 0; return 0;
} }
@ -372,20 +372,20 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
struct grub_jfs_internal_dirent *de; struct grub_jfs_internal_dirent *de;
struct grub_jfs_diropen *diro; struct grub_jfs_diropen *diro;
int blk; int blk;
de = (struct grub_jfs_internal_dirent *) inode->dir.dirents; de = (struct grub_jfs_internal_dirent *) inode->dir.dirents;
if (!((grub_le_to_cpu32 (inode->mode) if (!((grub_le_to_cpu32 (inode->mode)
& GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR)) & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR))
{ {
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
return 0; return 0;
} }
diro = grub_malloc (sizeof (struct grub_jfs_diropen)); diro = grub_malloc (sizeof (struct grub_jfs_diropen));
if (!diro) if (!diro)
return 0; return 0;
diro->index = 0; diro->index = 0;
diro->data = data; diro->data = data;
diro->inode = inode; diro->inode = inode;
@ -408,10 +408,10 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
grub_free (diro); grub_free (diro);
return 0; return 0;
} }
blk = grub_le_to_cpu32 (de[inode->dir.header.sorted[0]].ex.blk2); blk = grub_le_to_cpu32 (de[inode->dir.header.sorted[0]].ex.blk2);
blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS); blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS);
/* Read in the nodes until we are on the leaf node level. */ /* Read in the nodes until we are on the leaf node level. */
do do
{ {
@ -436,7 +436,7 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
diro->next_leaf = diro->dirpage->next_dirent; diro->next_leaf = diro->dirpage->next_dirent;
diro->sorted = &diro->dirpage->sorted[diro->dirpage->header.sindex * 32]; diro->sorted = &diro->dirpage->sorted[diro->dirpage->header.sindex * 32];
diro->count = diro->dirpage->header.count; diro->count = diro->dirpage->header.count;
return diro; return diro;
} }
@ -461,31 +461,31 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
int len; int len;
int nextent; int nextent;
grub_uint16_t filename[255]; grub_uint16_t filename[255];
auto void addstr (grub_uint16_t *uname, int ulen); auto void addstr (grub_uint16_t *uname, int ulen);
/* Add the unicode string to the utf16 filename buffer. */ /* Add the unicode string to the utf16 filename buffer. */
void addstr (grub_uint16_t *name, int ulen) void addstr (grub_uint16_t *name, int ulen)
{ {
while (ulen--) while (ulen--)
filename[strpos++] = *(name++); filename[strpos++] = *(name++);
} }
/* The last node, read in more. */ /* The last node, read in more. */
if (diro->index == diro->count) if (diro->index == diro->count)
{ {
unsigned int next; unsigned int next;
/* If the inode contains the entry tree or if this was the last /* If the inode contains the entry tree or if this was the last
node, there is nothing to read. */ node, there is nothing to read. */
if ((diro->inode->file.tree.flags & GRUB_JFS_TREE_LEAF) if ((diro->inode->file.tree.flags & GRUB_JFS_TREE_LEAF)
|| !grub_le_to_cpu64 (diro->dirpage->header.nextb)) || !grub_le_to_cpu64 (diro->dirpage->header.nextb))
return GRUB_ERR_OUT_OF_RANGE; return GRUB_ERR_OUT_OF_RANGE;
next = grub_le_to_cpu64 (diro->dirpage->header.nextb); next = grub_le_to_cpu64 (diro->dirpage->header.nextb);
next <<= (grub_le_to_cpu16 (diro->data->sblock.log2_blksz) next <<= (grub_le_to_cpu16 (diro->data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS); - GRUB_DISK_SECTOR_BITS);
if (grub_disk_read (diro->data->disk, next, 0, if (grub_disk_read (diro->data->disk, next, 0,
grub_le_to_cpu32 (diro->data->sblock.blksz), grub_le_to_cpu32 (diro->data->sblock.blksz),
diro->dirpage->sorted)) diro->dirpage->sorted))
@ -500,18 +500,18 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
leaf = &diro->leaf[(int) diro->sorted[diro->index]]; leaf = &diro->leaf[(int) diro->sorted[diro->index]];
next_leaf = &diro->next_leaf[diro->index]; next_leaf = &diro->next_leaf[diro->index];
len = leaf->len; len = leaf->len;
if (!len) if (!len)
{ {
diro->index++; diro->index++;
return grub_jfs_getent (diro); return grub_jfs_getent (diro);
} }
addstr (leaf->namepart, len < 11 ? len : 11); addstr (leaf->namepart, len < 11 ? len : 11);
diro->ino = grub_le_to_cpu32 (leaf->inode); diro->ino = grub_le_to_cpu32 (leaf->inode);
len -= 11; len -= 11;
/* Move down to the leaf level. */ /* Move down to the leaf level. */
nextent = leaf->next; nextent = leaf->next;
if (leaf->next != 255) if (leaf->next != 255)
@ -519,7 +519,7 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
{ {
next_leaf = &diro->next_leaf[nextent]; next_leaf = &diro->next_leaf[nextent];
addstr (next_leaf->namepart, len < 15 ? len : 15 ); addstr (next_leaf->namepart, len < 15 ? len : 15 );
len -= 15; len -= 15;
nextent = next_leaf->next; nextent = next_leaf->next;
} while (next_leaf->next != 255 && len > 0); } while (next_leaf->next != 255 && len > 0);
@ -528,7 +528,7 @@ grub_jfs_getent (struct grub_jfs_diropen *diro)
/* Convert the temporary UTF16 filename to UTF8. */ /* Convert the temporary UTF16 filename to UTF8. */
*grub_utf16_to_utf8 ((grub_uint8_t *) (diro->name), filename, strpos) = '\0'; *grub_utf16_to_utf8 ((grub_uint8_t *) (diro->name), filename, strpos) = '\0';
return 0; return 0;
} }
@ -550,15 +550,15 @@ grub_jfs_read_file (struct grub_jfs_data *data,
blockcnt = ((len + pos + grub_le_to_cpu32 (data->sblock.blksz) - 1) blockcnt = ((len + pos + grub_le_to_cpu32 (data->sblock.blksz) - 1)
/ grub_le_to_cpu32 (data->sblock.blksz)); / grub_le_to_cpu32 (data->sblock.blksz));
for (i = pos / grub_le_to_cpu32 (data->sblock.blksz); i < blockcnt; i++) for (i = pos / grub_le_to_cpu32 (data->sblock.blksz); i < blockcnt; i++)
{ {
int blknr; int blknr;
int blockoff = pos % grub_le_to_cpu32 (data->sblock.blksz); int blockoff = pos % grub_le_to_cpu32 (data->sblock.blksz);
int blockend = grub_le_to_cpu32 (data->sblock.blksz); int blockend = grub_le_to_cpu32 (data->sblock.blksz);
int skipfirst = 0; int skipfirst = 0;
blknr = grub_jfs_blkno (data, &data->currinode, i); blknr = grub_jfs_blkno (data, &data->currinode, i);
if (grub_errno) if (grub_errno)
return -1; return -1;
@ -567,31 +567,31 @@ grub_jfs_read_file (struct grub_jfs_data *data,
if (i == blockcnt - 1) if (i == blockcnt - 1)
{ {
blockend = (len + pos) % grub_le_to_cpu32 (data->sblock.blksz); blockend = (len + pos) % grub_le_to_cpu32 (data->sblock.blksz);
if (!blockend) if (!blockend)
blockend = grub_le_to_cpu32 (data->sblock.blksz); blockend = grub_le_to_cpu32 (data->sblock.blksz);
} }
/* First block. */ /* First block. */
if (i == (pos / (int) grub_le_to_cpu32 (data->sblock.blksz))) if (i == (pos / (int) grub_le_to_cpu32 (data->sblock.blksz)))
{ {
skipfirst = blockoff; skipfirst = blockoff;
blockend -= skipfirst; blockend -= skipfirst;
} }
data->disk->read_hook = read_hook; data->disk->read_hook = read_hook;
grub_disk_read (data->disk, grub_disk_read (data->disk,
blknr << (grub_le_to_cpu16 (data->sblock.log2_blksz) blknr << (grub_le_to_cpu16 (data->sblock.log2_blksz)
- GRUB_DISK_SECTOR_BITS), - GRUB_DISK_SECTOR_BITS),
skipfirst, blockend, buf); skipfirst, blockend, buf);
data->disk->read_hook = 0; data->disk->read_hook = 0;
if (grub_errno) if (grub_errno)
return -1; return -1;
buf += grub_le_to_cpu32 (data->sblock.blksz) - skipfirst; buf += grub_le_to_cpu32 (data->sblock.blksz) - skipfirst;
} }
return len; return len;
} }
@ -606,9 +606,9 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
char *next; char *next;
unsigned int pos = 0; unsigned int pos = 0;
struct grub_jfs_diropen *diro; struct grub_jfs_diropen *diro;
grub_strncpy (fpath, path, grub_strlen (path) + 1); grub_strncpy (fpath, path, grub_strlen (path) + 1);
if (grub_jfs_read_inode (data, GRUB_JFS_AGGR_INODE, &data->currinode)) if (grub_jfs_read_inode (data, GRUB_JFS_AGGR_INODE, &data->currinode))
return grub_errno; return grub_errno;
@ -633,28 +633,28 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
diro = grub_jfs_opendir (data, &data->currinode); diro = grub_jfs_opendir (data, &data->currinode);
if (!diro) if (!diro)
return grub_errno; return grub_errno;
for (;;) for (;;)
{ {
if (grub_strlen (name) == 0) if (grub_strlen (name) == 0)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
if (grub_jfs_getent (diro) == GRUB_ERR_OUT_OF_RANGE) if (grub_jfs_getent (diro) == GRUB_ERR_OUT_OF_RANGE)
break; break;
/* Check if the current direntry matches the current part of the /* Check if the current direntry matches the current part of the
pathname. */ pathname. */
if (!grub_strcmp (name, diro->name)) if (!grub_strcmp (name, diro->name))
{ {
int ino = diro->ino; int ino = diro->ino;
int dirino = grub_le_to_cpu32 (data->currinode.inode); int dirino = grub_le_to_cpu32 (data->currinode.inode);
grub_jfs_closedir (diro); grub_jfs_closedir (diro);
diro = 0; diro = 0;
if (grub_jfs_read_inode (data, ino, &data->currinode)) if (grub_jfs_read_inode (data, ino, &data->currinode))
break; break;
/* Check if this is a symlink. */ /* Check if this is a symlink. */
if ((grub_le_to_cpu32 (data->currinode.mode) if ((grub_le_to_cpu32 (data->currinode.mode)
& GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_LNK) & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_LNK)
@ -663,12 +663,12 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
} }
if (!next) if (!next)
return 0; return 0;
pos = 0; pos = 0;
name = next; name = next;
next = grub_strchr (name, '/'); next = grub_strchr (name, '/');
if (next) if (next)
@ -676,12 +676,12 @@ grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
next[0] = '\0'; next[0] = '\0';
next++; next++;
} }
/* Open this directory for reading dirents. */ /* Open this directory for reading dirents. */
diro = grub_jfs_opendir (data, &data->currinode); diro = grub_jfs_opendir (data, &data->currinode);
if (!diro) if (!diro)
return grub_errno; return grub_errno;
continue; continue;
} }
} }
@ -700,33 +700,33 @@ grub_jfs_lookup_symlink (struct grub_jfs_data *data, int ino)
if (++data->linknest > GRUB_JFS_MAX_SYMLNK_CNT) if (++data->linknest > GRUB_JFS_MAX_SYMLNK_CNT)
return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks"); return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks");
if (size <= 128) if (size <= 128)
grub_strncpy (symlink, (char *) (data->currinode.symlink.path), 128); grub_strncpy (symlink, (char *) (data->currinode.symlink.path), 128);
else if (grub_jfs_read_file (data, 0, 0, size, symlink) < 0) else if (grub_jfs_read_file (data, 0, 0, size, symlink) < 0)
return grub_errno; return grub_errno;
symlink[size] = '\0'; symlink[size] = '\0';
/* The symlink is an absolute path, go back to the root inode. */ /* The symlink is an absolute path, go back to the root inode. */
if (symlink[0] == '/') if (symlink[0] == '/')
ino = 2; ino = 2;
/* Now load in the old inode. */ /* Now load in the old inode. */
if (grub_jfs_read_inode (data, ino, &data->currinode)) if (grub_jfs_read_inode (data, ino, &data->currinode))
return grub_errno; return grub_errno;
grub_jfs_find_file (data, symlink); grub_jfs_find_file (data, symlink);
if (grub_errno) if (grub_errno)
grub_error (grub_errno, "Can not follow symlink `%s'.", symlink); grub_error (grub_errno, "Can not follow symlink `%s'.", symlink);
return grub_errno; return grub_errno;
} }
static grub_err_t static grub_err_t
grub_jfs_dir (grub_device_t device, const char *path, grub_jfs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_jfs_data *data = 0; struct grub_jfs_data *data = 0;
@ -740,7 +740,7 @@ grub_jfs_dir (grub_device_t device, const char *path,
if (grub_jfs_find_file (data, path)) if (grub_jfs_find_file (data, path))
goto fail; goto fail;
diro = grub_jfs_opendir (data, &data->currinode); diro = grub_jfs_opendir (data, &data->currinode);
if (!diro) if (!diro)
goto fail; goto fail;
@ -751,16 +751,16 @@ grub_jfs_dir (grub_device_t device, const char *path,
struct grub_jfs_inode inode; struct grub_jfs_inode inode;
struct grub_dirhook_info info; struct grub_dirhook_info info;
grub_memset (&info, 0, sizeof (info)); grub_memset (&info, 0, sizeof (info));
if (grub_jfs_read_inode (data, diro->ino, &inode)) if (grub_jfs_read_inode (data, diro->ino, &inode))
goto fail; goto fail;
info.dir = (grub_le_to_cpu32 (inode.mode) info.dir = (grub_le_to_cpu32 (inode.mode)
& GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR; & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR;
if (hook (diro->name, &info)) if (hook (diro->name, &info))
goto fail; goto fail;
} }
/* XXX: GRUB_ERR_OUT_OF_RANGE is used for the last dirent. */ /* XXX: GRUB_ERR_OUT_OF_RANGE is used for the last dirent. */
if (grub_errno == GRUB_ERR_OUT_OF_RANGE) if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_errno = 0; grub_errno = 0;
@ -786,11 +786,11 @@ grub_jfs_open (struct grub_file *file, const char *name)
data = grub_jfs_mount (file->device->disk); data = grub_jfs_mount (file->device->disk);
if (!data) if (!data)
goto fail; goto fail;
grub_jfs_find_file (data, name); grub_jfs_find_file (data, name);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
/* It is only possible for open regular files. */ /* It is only possible for open regular files. */
if (! ((grub_le_to_cpu32 (data->currinode.mode) if (! ((grub_le_to_cpu32 (data->currinode.mode)
& GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_REG)) & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_REG))
@ -798,18 +798,18 @@ grub_jfs_open (struct grub_file *file, const char *name)
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a regular file"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a regular file");
goto fail; goto fail;
} }
file->data = data; file->data = data;
file->size = grub_le_to_cpu64 (data->currinode.size); file->size = grub_le_to_cpu64 (data->currinode.size);
return 0; return 0;
fail: fail:
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
grub_free (data); grub_free (data);
return grub_errno;; return grub_errno;;
} }
@ -817,9 +817,9 @@ grub_jfs_open (struct grub_file *file, const char *name)
static grub_ssize_t static grub_ssize_t
grub_jfs_read (grub_file_t file, char *buf, grub_size_t len) grub_jfs_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_jfs_data *data = struct grub_jfs_data *data =
(struct grub_jfs_data *) file->data; (struct grub_jfs_data *) file->data;
return grub_jfs_read_file (data, file->read_hook, file->offset, len, buf); return grub_jfs_read_file (data, file->read_hook, file->offset, len, buf);
} }
@ -828,9 +828,9 @@ static grub_err_t
grub_jfs_close (grub_file_t file) grub_jfs_close (grub_file_t file)
{ {
grub_free (file->data); grub_free (file->data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -840,12 +840,12 @@ grub_jfs_label (grub_device_t device, char **label)
{ {
struct grub_jfs_data *data; struct grub_jfs_data *data;
data = grub_jfs_mount (device->disk); data = grub_jfs_mount (device->disk);
if (data) if (data)
*label = grub_strndup ((char *) (data->sblock.volname), 11); *label = grub_strndup ((char *) (data->sblock.volname), 11);
else else
*label = 0; *label = 0;
return grub_errno; return grub_errno;
} }

View file

@ -96,7 +96,7 @@ struct grub_minix2_inode
grub_uint32_t indir_zone; grub_uint32_t indir_zone;
grub_uint32_t double_indir_zone; grub_uint32_t double_indir_zone;
grub_uint32_t unused; grub_uint32_t unused;
}; };
/* Information about a "mounted" minix filesystem. */ /* Information about a "mounted" minix filesystem. */
@ -147,11 +147,11 @@ grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk)
return grub_le_to_cpu32 (indir32); return grub_le_to_cpu32 (indir32);
} }
} }
/* Direct block. */ /* Direct block. */
if (blk < 7) if (blk < 7)
return GRUB_MINIX_INODE_DIR_ZONES (data, blk); return GRUB_MINIX_INODE_DIR_ZONES (data, blk);
/* Indirect block. */ /* Indirect block. */
blk -= 7; blk -= 7;
if (blk < GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data)) if (blk < GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data))
@ -159,23 +159,23 @@ grub_minix_get_file_block (struct grub_minix_data *data, unsigned int blk)
indir = grub_get_indir (GRUB_MINIX_INODE_INDIR_ZONE (data), blk); indir = grub_get_indir (GRUB_MINIX_INODE_INDIR_ZONE (data), blk);
return indir; return indir;
} }
/* Double indirect block. */ /* Double indirect block. */
blk -= GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data); blk -= GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data);
if (blk < (GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data)) if (blk < (GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data))
* (GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data))) * (GRUB_MINIX_ZONESZ / GRUB_MINIX_INODE_BLKSZ (data)))
{ {
indir = grub_get_indir (GRUB_MINIX_INODE_DINDIR_ZONE (data), indir = grub_get_indir (GRUB_MINIX_INODE_DINDIR_ZONE (data),
blk / GRUB_MINIX_ZONESZ); blk / GRUB_MINIX_ZONESZ);
indir = grub_get_indir (indir, blk % GRUB_MINIX_ZONESZ); indir = grub_get_indir (indir, blk % GRUB_MINIX_ZONESZ);
return indir; return indir;
} }
/* This should never happen. */ /* This should never happen. */
grub_error (GRUB_ERR_OUT_OF_RANGE, "file bigger than maximum size"); grub_error (GRUB_ERR_OUT_OF_RANGE, "file bigger than maximum size");
return 0; return 0;
} }
@ -197,46 +197,46 @@ grub_minix_read_file (struct grub_minix_data *data,
len = GRUB_MINIX_INODE_SIZE (data); len = GRUB_MINIX_INODE_SIZE (data);
blockcnt = (len + pos + GRUB_MINIX_BSIZE - 1) / GRUB_MINIX_BSIZE; blockcnt = (len + pos + GRUB_MINIX_BSIZE - 1) / GRUB_MINIX_BSIZE;
for (i = pos / GRUB_MINIX_BSIZE; i < blockcnt; i++) for (i = pos / GRUB_MINIX_BSIZE; i < blockcnt; i++)
{ {
int blknr; int blknr;
int blockoff = pos % GRUB_MINIX_BSIZE; int blockoff = pos % GRUB_MINIX_BSIZE;
int blockend = GRUB_MINIX_BSIZE; int blockend = GRUB_MINIX_BSIZE;
int skipfirst = 0; int skipfirst = 0;
blknr = grub_minix_get_file_block (data, i); blknr = grub_minix_get_file_block (data, i);
if (grub_errno) if (grub_errno)
return -1; return -1;
/* Last block. */ /* Last block. */
if (i == blockcnt - 1) if (i == blockcnt - 1)
{ {
blockend = (len + pos) % GRUB_MINIX_BSIZE; blockend = (len + pos) % GRUB_MINIX_BSIZE;
if (!blockend) if (!blockend)
blockend = GRUB_MINIX_BSIZE; blockend = GRUB_MINIX_BSIZE;
} }
/* First block. */ /* First block. */
if (i == (pos / (int) GRUB_MINIX_BSIZE)) if (i == (pos / (int) GRUB_MINIX_BSIZE))
{ {
skipfirst = blockoff; skipfirst = blockoff;
blockend -= skipfirst; blockend -= skipfirst;
} }
data->disk->read_hook = read_hook; data->disk->read_hook = read_hook;
grub_disk_read (data->disk, blknr << GRUB_MINIX_LOG2_ZONESZ, grub_disk_read (data->disk, blknr << GRUB_MINIX_LOG2_ZONESZ,
skipfirst, blockend, buf); skipfirst, blockend, buf);
data->disk->read_hook = 0; data->disk->read_hook = 0;
if (grub_errno) if (grub_errno)
return -1; return -1;
buf += GRUB_MINIX_BSIZE - skipfirst; buf += GRUB_MINIX_BSIZE - skipfirst;
} }
return len; return len;
} }
@ -254,33 +254,33 @@ grub_minix_read_inode (struct grub_minix_data *data, int ino)
/* The first inode in minix is inode 1. */ /* The first inode in minix is inode 1. */
ino--; ino--;
block = ((2 + grub_le_to_cpu16 (sblock->inode_bmap_size) block = ((2 + grub_le_to_cpu16 (sblock->inode_bmap_size)
+ grub_le_to_cpu16 (sblock->zone_bmap_size)) + grub_le_to_cpu16 (sblock->zone_bmap_size))
<< GRUB_MINIX_LOG2_BSIZE); << GRUB_MINIX_LOG2_BSIZE);
if (data->version == 1) if (data->version == 1)
{ {
block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode)); block += ino / (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix_inode));
int offs = (ino % (GRUB_DISK_SECTOR_SIZE int offs = (ino % (GRUB_DISK_SECTOR_SIZE
/ sizeof (struct grub_minix_inode)) / sizeof (struct grub_minix_inode))
* sizeof (struct grub_minix_inode)); * sizeof (struct grub_minix_inode));
grub_disk_read (data->disk, block, offs, grub_disk_read (data->disk, block, offs,
sizeof (struct grub_minix_inode), &data->inode); sizeof (struct grub_minix_inode), &data->inode);
} }
else else
{ {
block += ino / (GRUB_DISK_SECTOR_SIZE block += ino / (GRUB_DISK_SECTOR_SIZE
/ sizeof (struct grub_minix2_inode)); / sizeof (struct grub_minix2_inode));
int offs = (ino int offs = (ino
% (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix2_inode)) % (GRUB_DISK_SECTOR_SIZE / sizeof (struct grub_minix2_inode))
* sizeof (struct grub_minix2_inode)); * sizeof (struct grub_minix2_inode));
grub_disk_read (data->disk, block, offs, grub_disk_read (data->disk, block, offs,
sizeof (struct grub_minix2_inode),&data->inode2); sizeof (struct grub_minix2_inode),&data->inode2);
} }
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -291,28 +291,28 @@ static grub_err_t
grub_minix_lookup_symlink (struct grub_minix_data *data, int ino) grub_minix_lookup_symlink (struct grub_minix_data *data, int ino)
{ {
char symlink[GRUB_MINIX_INODE_SIZE (data) + 1]; char symlink[GRUB_MINIX_INODE_SIZE (data) + 1];
if (++data->linknest > GRUB_MINIX_MAX_SYMLNK_CNT) if (++data->linknest > GRUB_MINIX_MAX_SYMLNK_CNT)
return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks"); return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks");
if (grub_minix_read_file (data, 0, 0, if (grub_minix_read_file (data, 0, 0,
GRUB_MINIX_INODE_SIZE (data), symlink) < 0) GRUB_MINIX_INODE_SIZE (data), symlink) < 0)
return grub_errno; return grub_errno;
symlink[GRUB_MINIX_INODE_SIZE (data)] = '\0'; symlink[GRUB_MINIX_INODE_SIZE (data)] = '\0';
/* The symlink is an absolute path, go back to the root inode. */ /* The symlink is an absolute path, go back to the root inode. */
if (symlink[0] == '/') if (symlink[0] == '/')
ino = GRUB_MINIX_ROOT_INODE; ino = GRUB_MINIX_ROOT_INODE;
/* Now load in the old inode. */ /* Now load in the old inode. */
if (grub_minix_read_inode (data, ino)) if (grub_minix_read_inode (data, ino))
return grub_errno; return grub_errno;
grub_minix_find_file (data, symlink); grub_minix_find_file (data, symlink);
if (grub_errno) if (grub_errno)
grub_error (grub_errno, "Can not follow symlink `%s'.", symlink); grub_error (grub_errno, "Can not follow symlink `%s'.", symlink);
return grub_errno; return grub_errno;
} }
@ -327,9 +327,9 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
char *next; char *next;
unsigned int pos = 0; unsigned int pos = 0;
int dirino; int dirino;
grub_strcpy (fpath, path); grub_strcpy (fpath, path);
/* Skip the first slash. */ /* Skip the first slash. */
if (name[0] == '/') if (name[0] == '/')
{ {
@ -345,15 +345,15 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
next[0] = '\0'; next[0] = '\0';
next++; next++;
} }
do do
{ {
grub_uint16_t ino; grub_uint16_t ino;
char filename[data->filename_size + 1]; char filename[data->filename_size + 1];
if (grub_strlen (name) == 0) if (grub_strlen (name) == 0)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
if (grub_minix_read_file (data, 0, pos, sizeof (ino), if (grub_minix_read_file (data, 0, pos, sizeof (ino),
(char *) &ino) < 0) (char *) &ino) < 0)
return grub_errno; return grub_errno;
@ -362,28 +362,28 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
return grub_errno; return grub_errno;
filename[data->filename_size] = '\0'; filename[data->filename_size] = '\0';
/* Check if the current direntry matches the current part of the /* Check if the current direntry matches the current part of the
pathname. */ pathname. */
if (!grub_strcmp (name, filename)) if (!grub_strcmp (name, filename))
{ {
dirino = data->ino; dirino = data->ino;
grub_minix_read_inode (data, grub_le_to_cpu16 (ino)); grub_minix_read_inode (data, grub_le_to_cpu16 (ino));
/* Follow the symlink. */ /* Follow the symlink. */
if ((GRUB_MINIX_INODE_MODE (data) if ((GRUB_MINIX_INODE_MODE (data)
& GRUB_MINIX_IFLNK) == GRUB_MINIX_IFLNK) & GRUB_MINIX_IFLNK) == GRUB_MINIX_IFLNK)
{ {
grub_minix_lookup_symlink (data, dirino); grub_minix_lookup_symlink (data, dirino);
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
} }
if (!next) if (!next)
return 0; return 0;
pos = 0; pos = 0;
name = next; name = next;
next = grub_strchr (name, '/'); next = grub_strchr (name, '/');
if (next) if (next)
@ -391,17 +391,17 @@ grub_minix_find_file (struct grub_minix_data *data, const char *path)
next[0] = '\0'; next[0] = '\0';
next++; next++;
} }
if ((GRUB_MINIX_INODE_MODE (data) if ((GRUB_MINIX_INODE_MODE (data)
& GRUB_MINIX_IFDIR) != GRUB_MINIX_IFDIR) & GRUB_MINIX_IFDIR) != GRUB_MINIX_IFDIR)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
continue; continue;
} }
pos += sizeof (ino) + data->filename_size; pos += sizeof (ino) + data->filename_size;
} while (pos < GRUB_MINIX_INODE_SIZE (data)); } while (pos < GRUB_MINIX_INODE_SIZE (data));
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
return grub_errno; return grub_errno;
} }
@ -412,11 +412,11 @@ static struct grub_minix_data *
grub_minix_mount (grub_disk_t disk) grub_minix_mount (grub_disk_t disk)
{ {
struct grub_minix_data *data; struct grub_minix_data *data;
data = grub_malloc (sizeof (struct grub_minix_data)); data = grub_malloc (sizeof (struct grub_minix_data));
if (!data) if (!data)
return 0; return 0;
/* Read the superblock. */ /* Read the superblock. */
grub_disk_read (disk, GRUB_MINIX_SBLOCK, 0, grub_disk_read (disk, GRUB_MINIX_SBLOCK, 0,
sizeof (struct grub_minix_sblock),&data->sblock); sizeof (struct grub_minix_sblock),&data->sblock);
@ -458,34 +458,34 @@ grub_minix_mount (grub_disk_t disk)
} }
static grub_err_t static grub_err_t
grub_minix_dir (grub_device_t device, const char *path, grub_minix_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_minix_data *data = 0; struct grub_minix_data *data = 0;
struct grub_minix_sblock *sblock; struct grub_minix_sblock *sblock;
unsigned int pos = 0; unsigned int pos = 0;
data = grub_minix_mount (device->disk); data = grub_minix_mount (device->disk);
if (!data) if (!data)
return grub_errno; return grub_errno;
grub_minix_read_inode (data, GRUB_MINIX_ROOT_INODE); grub_minix_read_inode (data, GRUB_MINIX_ROOT_INODE);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
sblock = &data->sblock; sblock = &data->sblock;
grub_minix_find_file (data, path); grub_minix_find_file (data, path);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
if ((GRUB_MINIX_INODE_MODE (data) & GRUB_MINIX_IFDIR) != GRUB_MINIX_IFDIR) if ((GRUB_MINIX_INODE_MODE (data) & GRUB_MINIX_IFDIR) != GRUB_MINIX_IFDIR)
{ {
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
goto fail; goto fail;
} }
while (pos < GRUB_MINIX_INODE_SIZE (data)) while (pos < GRUB_MINIX_INODE_SIZE (data))
{ {
grub_uint16_t ino; grub_uint16_t ino;
@ -494,31 +494,31 @@ grub_minix_dir (grub_device_t device, const char *path,
struct grub_dirhook_info info; struct grub_dirhook_info info;
grub_memset (&info, 0, sizeof (info)); grub_memset (&info, 0, sizeof (info));
if (grub_minix_read_file (data, 0, pos, sizeof (ino), if (grub_minix_read_file (data, 0, pos, sizeof (ino),
(char *) &ino) < 0) (char *) &ino) < 0)
return grub_errno; return grub_errno;
if (grub_minix_read_file (data, 0, pos + sizeof (ino), if (grub_minix_read_file (data, 0, pos + sizeof (ino),
data->filename_size, data->filename_size,
(char *) filename) < 0) (char *) filename) < 0)
return grub_errno; return grub_errno;
filename[data->filename_size] = '\0'; filename[data->filename_size] = '\0';
/* The filetype is not stored in the dirent. Read the inode to /* The filetype is not stored in the dirent. Read the inode to
find out the filetype. This *REALLY* sucks. */ find out the filetype. This *REALLY* sucks. */
grub_minix_read_inode (data, grub_le_to_cpu16 (ino)); grub_minix_read_inode (data, grub_le_to_cpu16 (ino));
info.dir = ((GRUB_MINIX_INODE_MODE (data) info.dir = ((GRUB_MINIX_INODE_MODE (data)
& GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR); & GRUB_MINIX_IFDIR) == GRUB_MINIX_IFDIR);
if (hook (filename, &info) ? 1 : 0) if (hook (filename, &info) ? 1 : 0)
break; break;
/* Load the old inode back in. */ /* Load the old inode back in. */
grub_minix_read_inode (data, dirino); grub_minix_read_inode (data, dirino);
pos += sizeof (ino) + data->filename_size; pos += sizeof (ino) + data->filename_size;
} }
fail: fail:
grub_free (data); grub_free (data);
return grub_errno; return grub_errno;
@ -541,13 +541,13 @@ grub_minix_open (struct grub_file *file, const char *name)
grub_free (data); grub_free (data);
return grub_errno; return grub_errno;
} }
if (!name || name[0] != '/') if (!name || name[0] != '/')
{ {
grub_error (GRUB_ERR_BAD_FILENAME, "bad filename"); grub_error (GRUB_ERR_BAD_FILENAME, "bad filename");
return grub_errno; return grub_errno;
} }
/* Traverse the directory tree to the node that should be /* Traverse the directory tree to the node that should be
opened. */ opened. */
grub_minix_find_file (data, name); grub_minix_find_file (data, name);
@ -556,10 +556,10 @@ grub_minix_open (struct grub_file *file, const char *name)
grub_free (data); grub_free (data);
return grub_errno; return grub_errno;
} }
file->data = data; file->data = data;
file->size = GRUB_MINIX_INODE_SIZE (data); file->size = GRUB_MINIX_INODE_SIZE (data);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -567,9 +567,9 @@ grub_minix_open (struct grub_file *file, const char *name)
static grub_ssize_t static grub_ssize_t
grub_minix_read (grub_file_t file, char *buf, grub_size_t len) grub_minix_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_minix_data *data = struct grub_minix_data *data =
(struct grub_minix_data *) file->data; (struct grub_minix_data *) file->data;
return grub_minix_read_file (data, file->read_hook, file->offset, len, buf); return grub_minix_read_file (data, file->read_hook, file->offset, len, buf);
} }
@ -578,7 +578,7 @@ static grub_err_t
grub_minix_close (grub_file_t file) grub_minix_close (grub_file_t file)
{ {
grub_free (file->data); grub_free (file->data);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }

View file

@ -862,7 +862,7 @@ fail:
static grub_err_t static grub_err_t
grub_ntfs_dir (grub_device_t device, const char *path, grub_ntfs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_ntfs_data *data = 0; struct grub_ntfs_data *data = 0;

View file

@ -319,7 +319,7 @@ grub_reiserfs_print_key (const struct grub_reiserfs_key *key)
"any ", "any ",
"unknown " "unknown "
}; };
for (a = 0; a < sizeof (struct grub_reiserfs_key); a++) for (a = 0; a < sizeof (struct grub_reiserfs_key); a++)
grub_printf ("%02x ", ((unsigned int) ((unsigned char *) key)[a]) & 0xFF); grub_printf ("%02x ", ((unsigned int) ((unsigned char *) key)[a]) & 0xFF);
grub_printf ("parent id = 0x%08x, self id = 0x%08x, type = %s, offset = ", grub_printf ("parent id = 0x%08x, self id = 0x%08x, type = %s, offset = ",
@ -376,7 +376,7 @@ grub_reiserfs_set_key_type (struct grub_reiserfs_key *key,
int version) int version)
{ {
grub_uint32_t type; grub_uint32_t type;
switch (grub_type) switch (grub_type)
{ {
case GRUB_REISERFS_STAT: case GRUB_REISERFS_STAT:
@ -397,14 +397,14 @@ grub_reiserfs_set_key_type (struct grub_reiserfs_key *key,
default: default:
return; return;
} }
if (version == 1) if (version == 1)
key->u.v1.type = grub_cpu_to_le32 (type); key->u.v1.type = grub_cpu_to_le32 (type);
else else
key->u.v2.offset_type key->u.v2.offset_type
= ((key->u.v2.offset_type & grub_cpu_to_le64 (~0ULL >> 4)) = ((key->u.v2.offset_type & grub_cpu_to_le64 (~0ULL >> 4))
| grub_cpu_to_le64 ((grub_uint64_t) type << 60)); | grub_cpu_to_le64 ((grub_uint64_t) type << 60));
assert (grub_reiserfs_get_key_type (key) == grub_type); assert (grub_reiserfs_get_key_type (key) == grub_type);
} }
@ -418,31 +418,31 @@ grub_reiserfs_compare_keys (const struct grub_reiserfs_key *key1,
grub_uint64_t offset1, offset2; grub_uint64_t offset1, offset2;
enum grub_reiserfs_item_type type1, type2; enum grub_reiserfs_item_type type1, type2;
grub_uint32_t id1, id2; grub_uint32_t id1, id2;
if (! key1 || ! key2) if (! key1 || ! key2)
return -2; return -2;
id1 = grub_le_to_cpu32 (key1->directory_id); id1 = grub_le_to_cpu32 (key1->directory_id);
id2 = grub_le_to_cpu32 (key2->directory_id); id2 = grub_le_to_cpu32 (key2->directory_id);
if (id1 < id2) if (id1 < id2)
return -1; return -1;
if (id1 > id2) if (id1 > id2)
return 1; return 1;
id1 = grub_le_to_cpu32 (key1->object_id); id1 = grub_le_to_cpu32 (key1->object_id);
id2 = grub_le_to_cpu32 (key2->object_id); id2 = grub_le_to_cpu32 (key2->object_id);
if (id1 < id2) if (id1 < id2)
return -1; return -1;
if (id1 > id2) if (id1 > id2)
return 1; return 1;
offset1 = grub_reiserfs_get_key_offset (key1); offset1 = grub_reiserfs_get_key_offset (key1);
offset2 = grub_reiserfs_get_key_offset (key2); offset2 = grub_reiserfs_get_key_offset (key2);
if (offset1 < offset2) if (offset1 < offset2)
return -1; return -1;
if (offset1 > offset2) if (offset1 > offset2)
return 1; return 1;
type1 = grub_reiserfs_get_key_type (key1); type1 = grub_reiserfs_get_key_type (key1);
type2 = grub_reiserfs_get_key_type (key2); type2 = grub_reiserfs_get_key_type (key2);
if ((type1 == GRUB_REISERFS_ANY if ((type1 == GRUB_REISERFS_ANY
@ -456,7 +456,7 @@ grub_reiserfs_compare_keys (const struct grub_reiserfs_key *key1,
return -1; return -1;
if (type1 > type2) if (type1 > type2)
return 1; return 1;
return 0; return 0;
} }
@ -474,7 +474,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data,
grub_uint16_t i; grub_uint16_t i;
grub_uint16_t previous_level = ~0; grub_uint16_t previous_level = ~0;
struct grub_reiserfs_item_header *item_headers = 0; struct grub_reiserfs_item_header *item_headers = 0;
if (! data) if (! data)
{ {
grub_error (GRUB_ERR_TEST_FAILURE, "data is NULL"); grub_error (GRUB_ERR_TEST_FAILURE, "data is NULL");
@ -492,7 +492,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data,
grub_error (GRUB_ERR_TEST_FAILURE, "item is NULL"); grub_error (GRUB_ERR_TEST_FAILURE, "item is NULL");
goto fail; goto fail;
} }
block_size = grub_le_to_cpu16 (data->superblock.block_size); block_size = grub_le_to_cpu16 (data->superblock.block_size);
block_number = grub_le_to_cpu32 (data->superblock.root_block); block_number = grub_le_to_cpu32 (data->superblock.root_block);
#ifdef GRUB_REISERFS_DEBUG #ifdef GRUB_REISERFS_DEBUG
@ -502,7 +502,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data,
block_header = grub_malloc (block_size); block_header = grub_malloc (block_size);
if (! block_header) if (! block_header)
goto fail; goto fail;
item->next_offset = 0; item->next_offset = 0;
do do
{ {
@ -534,7 +534,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data,
struct grub_reiserfs_disk_child *children struct grub_reiserfs_disk_child *children
= ((struct grub_reiserfs_disk_child *) = ((struct grub_reiserfs_disk_child *)
(keys + item_count)); (keys + item_count));
for (i = 0; for (i = 0;
i < item_count i < item_count
&& grub_reiserfs_compare_keys (key, &(keys[i])) >= 0; && grub_reiserfs_compare_keys (key, &(keys[i])) >= 0;
@ -620,7 +620,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data,
grub_reiserfs_print_key (block_key); grub_reiserfs_print_key (block_key);
#endif #endif
} }
assert (grub_errno == GRUB_ERR_NONE); assert (grub_errno == GRUB_ERR_NONE);
grub_free (block_header); grub_free (block_header);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
@ -740,7 +740,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
struct grub_fshelp_node directory_item; struct grub_fshelp_node directory_item;
grub_uint16_t entry_count, entry_number; grub_uint16_t entry_count, entry_number;
struct grub_reiserfs_item_header *item_headers; struct grub_reiserfs_item_header *item_headers;
grub_disk_read (data->disk, grub_disk_read (data->disk,
block_number * (block_size >> GRUB_DISK_SECTOR_BITS), block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
(((grub_off_t) block_number * block_size) (((grub_off_t) block_number * block_size)
@ -758,7 +758,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
goto fail; goto fail;
} }
#endif #endif
item_headers = (struct grub_reiserfs_item_header *) (block_header + 1); item_headers = (struct grub_reiserfs_item_header *) (block_header + 1);
directory_headers directory_headers
= ((struct grub_reiserfs_directory_header *) = ((struct grub_reiserfs_directory_header *)
@ -772,7 +772,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
= &directory_headers[entry_number]; = &directory_headers[entry_number];
grub_uint16_t entry_state grub_uint16_t entry_state
= grub_le_to_cpu16 (directory_header->state); = grub_le_to_cpu16 (directory_header->state);
if (entry_state & GRUB_REISERFS_VISIBLE_MASK) if (entry_state & GRUB_REISERFS_VISIBLE_MASK)
{ {
grub_fshelp_node_t entry_item; grub_fshelp_node_t entry_item;
@ -792,14 +792,14 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
entry_item = grub_malloc (sizeof (*entry_item)); entry_item = grub_malloc (sizeof (*entry_item));
if (! entry_item) if (! entry_item)
goto fail; goto fail;
if (grub_reiserfs_get_item (data, &entry_key, entry_item) if (grub_reiserfs_get_item (data, &entry_key, entry_item)
!= GRUB_ERR_NONE) != GRUB_ERR_NONE)
{ {
grub_free (entry_item); grub_free (entry_item);
goto fail; goto fail;
} }
if (entry_item->type == GRUB_REISERFS_DIRECTORY) if (entry_item->type == GRUB_REISERFS_DIRECTORY)
entry_type = GRUB_FSHELP_DIR; entry_type = GRUB_FSHELP_DIR;
else else
@ -945,7 +945,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
the current one. */ the current one. */
} }
} }
if (next_offset == 0) if (next_offset == 0)
break; break;
@ -1096,7 +1096,7 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len)
while (current_position < final_position) while (current_position < final_position)
{ {
grub_reiserfs_set_key_offset (&key, current_key_offset); grub_reiserfs_set_key_offset (&key, current_key_offset);
if (grub_reiserfs_get_item (data, &key, &found) != GRUB_ERR_NONE) if (grub_reiserfs_get_item (data, &key, &found) != GRUB_ERR_NONE)
goto fail; goto fail;
if (found.block_number == 0) if (found.block_number == 0)
@ -1186,7 +1186,7 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len)
} }
current_key_offset = current_position + 1; current_key_offset = current_position + 1;
} }
grub_dprintf ("reiserfs", grub_dprintf ("reiserfs",
"Have successfully read %lld bytes (%ld requested)\n", "Have successfully read %lld bytes (%ld requested)\n",
(unsigned long long) (current_position - initial_position), (unsigned long long) (current_position - initial_position),
@ -1258,7 +1258,7 @@ grub_reiserfs_close (grub_file_t file)
/* Call HOOK with each file under DIR. */ /* Call HOOK with each file under DIR. */
static grub_err_t static grub_err_t
grub_reiserfs_dir (grub_device_t device, const char *path, grub_reiserfs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_reiserfs_data *data = 0; struct grub_reiserfs_data *data = 0;

View file

@ -194,7 +194,7 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block,
/* We found a correct leaf. */ /* We found a correct leaf. */
*size = grub_be_to_cpu16 (extent->size); *size = grub_be_to_cpu16 (extent->size);
*nextext = grub_be_to_cpu32 (extent->next); *nextext = grub_be_to_cpu32 (extent->next);
grub_free (treeblock); grub_free (treeblock);
return 0; return 0;
} }
@ -370,7 +370,7 @@ grub_sfs_iterate_dir (grub_fshelp_node_t dir,
node->data = data; node->data = data;
node->size = size; node->size = size;
node->block = block; node->block = block;
return hook (name, type, node); return hook (name, type, node);
} }
@ -451,18 +451,18 @@ grub_sfs_open (struct grub_file *file, const char *name)
{ {
struct grub_sfs_data *data; struct grub_sfs_data *data;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_sfs_mount (file->device->disk); data = grub_sfs_mount (file->device->disk);
if (!data) if (!data)
goto fail; goto fail;
grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_sfs_iterate_dir, grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_sfs_iterate_dir,
grub_sfs_read_symlink, GRUB_FSHELP_REG); grub_sfs_read_symlink, GRUB_FSHELP_REG);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
file->size = fdiro->size; file->size = fdiro->size;
data->diropen = *fdiro; data->diropen = *fdiro;
grub_free (fdiro); grub_free (fdiro);
@ -478,7 +478,7 @@ grub_sfs_open (struct grub_file *file, const char *name)
if (data) if (data)
grub_free (data->label); grub_free (data->label);
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
@ -510,13 +510,13 @@ grub_sfs_read (grub_file_t file, char *buf, grub_size_t len)
static grub_err_t static grub_err_t
grub_sfs_dir (grub_device_t device, const char *path, grub_sfs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_sfs_data *data = 0; struct grub_sfs_data *data = 0;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
auto int NESTED_FUNC_ATTR iterate (const char *filename, auto int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype, enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node); grub_fshelp_node_t node);
@ -533,7 +533,7 @@ grub_sfs_dir (grub_device_t device, const char *path,
} }
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_sfs_mount (device->disk); data = grub_sfs_mount (device->disk);
if (!data) if (!data)
goto fail; goto fail;
@ -544,7 +544,7 @@ grub_sfs_dir (grub_device_t device, const char *path,
goto fail; goto fail;
grub_sfs_iterate_dir (fdiro, iterate); grub_sfs_iterate_dir (fdiro, iterate);
fail: fail:
if (data && fdiro != &data->diropen) if (data && fdiro != &data->diropen)
grub_free (fdiro); grub_free (fdiro);

View file

@ -766,7 +766,7 @@ grub_udf_iterate_dir (grub_fshelp_node_t dir,
static grub_err_t static grub_err_t
grub_udf_dir (grub_device_t device, const char *path, grub_udf_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_udf_data *data = 0; struct grub_udf_data *data = 0;

154
fs/ufs.c
View file

@ -71,30 +71,30 @@ struct grub_ufs_sblock
grub_uint8_t unused[16]; grub_uint8_t unused[16];
/* The offset of the inodes in the cylinder group. */ /* The offset of the inodes in the cylinder group. */
grub_uint32_t inoblk_offs; grub_uint32_t inoblk_offs;
grub_uint8_t unused2[4]; grub_uint8_t unused2[4];
/* The start of the cylinder group. */ /* The start of the cylinder group. */
grub_uint32_t cylg_offset; grub_uint32_t cylg_offset;
grub_uint8_t unused3[4]; grub_uint8_t unused3[4];
grub_uint32_t mtime; grub_uint32_t mtime;
grub_uint8_t unused4[12]; grub_uint8_t unused4[12];
/* The size of a block in bytes. */ /* The size of a block in bytes. */
grub_int32_t bsize; grub_int32_t bsize;
grub_uint8_t unused5[48]; grub_uint8_t unused5[48];
/* The size of filesystem blocks to disk blocks. */ /* The size of filesystem blocks to disk blocks. */
grub_uint32_t log2_blksz; grub_uint32_t log2_blksz;
grub_uint8_t unused6[80]; grub_uint8_t unused6[80];
/* Inodes stored per cylinder group. */ /* Inodes stored per cylinder group. */
grub_uint32_t ino_per_group; grub_uint32_t ino_per_group;
/* The frags per cylinder group. */ /* The frags per cylinder group. */
grub_uint32_t frags_per_group; grub_uint32_t frags_per_group;
grub_uint8_t unused7[488]; grub_uint8_t unused7[488];
/* Volume name for UFS2. */ /* Volume name for UFS2. */
@ -103,7 +103,7 @@ struct grub_ufs_sblock
grub_uint64_t mtime2; grub_uint64_t mtime2;
grub_uint8_t unused9[420]; grub_uint8_t unused9[420];
/* Magic value to check if this is really a UFS filesystem. */ /* Magic value to check if this is really a UFS filesystem. */
grub_uint32_t magic; grub_uint32_t magic;
}; };
@ -182,7 +182,7 @@ struct grub_ufs_dirent
struct struct
{ {
grub_uint8_t filetype_bsd; grub_uint8_t filetype_bsd;
grub_uint8_t namelen_bsd; grub_uint8_t namelen_bsd;
}; };
}; };
} __attribute__ ((packed)); } __attribute__ ((packed));
@ -219,16 +219,16 @@ grub_ufs_get_file_block (struct grub_ufs_data *data, unsigned int blk)
{ {
struct grub_ufs_sblock *sblock = &data->sblock; struct grub_ufs_sblock *sblock = &data->sblock;
unsigned int indirsz; unsigned int indirsz;
int log2_blksz; int log2_blksz;
/* Direct. */ /* Direct. */
if (blk < GRUB_UFS_DIRBLKS) if (blk < GRUB_UFS_DIRBLKS)
return INODE_DIRBLOCKS (data, blk); return INODE_DIRBLOCKS (data, blk);
log2_blksz = grub_le_to_cpu32 (data->sblock.log2_blksz); log2_blksz = grub_le_to_cpu32 (data->sblock.log2_blksz);
blk -= GRUB_UFS_DIRBLKS; blk -= GRUB_UFS_DIRBLKS;
indirsz = UFS_BLKSZ (sblock) / INODE_BLKSZ (data); indirsz = UFS_BLKSZ (sblock) / INODE_BLKSZ (data);
/* Single indirect block. */ /* Single indirect block. */
if (blk < indirsz) if (blk < indirsz)
@ -239,20 +239,20 @@ grub_ufs_get_file_block (struct grub_ufs_data *data, unsigned int blk)
return (data->ufs_type == UFS1) ? indir[blk] : indir[blk << 1]; return (data->ufs_type == UFS1) ? indir[blk] : indir[blk << 1];
} }
blk -= indirsz; blk -= indirsz;
/* Double indirect block. */ /* Double indirect block. */
if (blk < indirsz * indirsz) if (blk < indirsz * indirsz)
{ {
grub_uint32_t indir[UFS_BLKSZ (sblock) >> 2]; grub_uint32_t indir[UFS_BLKSZ (sblock) >> 2];
grub_disk_read (data->disk, INODE_INDIRBLOCKS (data, 1) << log2_blksz, grub_disk_read (data->disk, INODE_INDIRBLOCKS (data, 1) << log2_blksz,
0, sizeof (indir), indir); 0, sizeof (indir), indir);
grub_disk_read (data->disk, grub_disk_read (data->disk,
((data->ufs_type == UFS1) ? ((data->ufs_type == UFS1) ?
indir[blk / indirsz] : indir [(blk / indirsz) << 1]) indir[blk / indirsz] : indir [(blk / indirsz) << 1])
<< log2_blksz, << log2_blksz,
0, sizeof (indir), indir); 0, sizeof (indir), indir);
return (data->ufs_type == UFS1) ? return (data->ufs_type == UFS1) ?
indir[blk % indirsz] : indir[(blk % indirsz) << 1]; indir[blk % indirsz] : indir[(blk % indirsz) << 1];
} }
@ -281,35 +281,35 @@ grub_ufs_read_file (struct grub_ufs_data *data,
len = INODE_SIZE (data); len = INODE_SIZE (data);
blockcnt = (len + pos + UFS_BLKSZ (sblock) - 1) / UFS_BLKSZ (sblock); blockcnt = (len + pos + UFS_BLKSZ (sblock) - 1) / UFS_BLKSZ (sblock);
for (i = pos / UFS_BLKSZ (sblock); i < blockcnt; i++) for (i = pos / UFS_BLKSZ (sblock); i < blockcnt; i++)
{ {
int blknr; int blknr;
int blockoff = pos % UFS_BLKSZ (sblock); int blockoff = pos % UFS_BLKSZ (sblock);
int blockend = UFS_BLKSZ (sblock); int blockend = UFS_BLKSZ (sblock);
int skipfirst = 0; int skipfirst = 0;
blknr = grub_ufs_get_file_block (data, i); blknr = grub_ufs_get_file_block (data, i);
if (grub_errno) if (grub_errno)
return -1; return -1;
/* Last block. */ /* Last block. */
if (i == blockcnt - 1) if (i == blockcnt - 1)
{ {
blockend = (len + pos) % UFS_BLKSZ (sblock); blockend = (len + pos) % UFS_BLKSZ (sblock);
if (!blockend) if (!blockend)
blockend = UFS_BLKSZ (sblock); blockend = UFS_BLKSZ (sblock);
} }
/* First block. */ /* First block. */
if (i == (pos / (int) UFS_BLKSZ (sblock))) if (i == (pos / (int) UFS_BLKSZ (sblock)))
{ {
skipfirst = blockoff; skipfirst = blockoff;
blockend -= skipfirst; blockend -= skipfirst;
} }
/* XXX: If the block number is 0 this block is not stored on /* XXX: If the block number is 0 this block is not stored on
disk but is zero filled instead. */ disk but is zero filled instead. */
if (blknr) if (blknr)
@ -327,7 +327,7 @@ grub_ufs_read_file (struct grub_ufs_data *data,
buf += UFS_BLKSZ (sblock) - skipfirst; buf += UFS_BLKSZ (sblock) - skipfirst;
} }
return len; return len;
} }
@ -338,16 +338,16 @@ static grub_err_t
grub_ufs_read_inode (struct grub_ufs_data *data, int ino, char *inode) grub_ufs_read_inode (struct grub_ufs_data *data, int ino, char *inode)
{ {
struct grub_ufs_sblock *sblock = &data->sblock; struct grub_ufs_sblock *sblock = &data->sblock;
/* Determine the group the inode is in. */ /* Determine the group the inode is in. */
int group = ino / grub_le_to_cpu32 (sblock->ino_per_group); int group = ino / grub_le_to_cpu32 (sblock->ino_per_group);
/* Determine the inode within the group. */ /* Determine the inode within the group. */
int grpino = ino % grub_le_to_cpu32 (sblock->ino_per_group); int grpino = ino % grub_le_to_cpu32 (sblock->ino_per_group);
/* The first block of the group. */ /* The first block of the group. */
int grpblk = group * (grub_le_to_cpu32 (sblock->frags_per_group)); int grpblk = group * (grub_le_to_cpu32 (sblock->frags_per_group));
if (data->ufs_type == UFS1) if (data->ufs_type == UFS1)
{ {
if (!inode) if (!inode)
@ -380,7 +380,7 @@ grub_ufs_read_inode (struct grub_ufs_data *data, int ino, char *inode)
sizeof (struct grub_ufs2_inode), sizeof (struct grub_ufs2_inode),
inode); inode);
} }
return grub_errno; return grub_errno;
} }
@ -391,16 +391,16 @@ static grub_err_t
grub_ufs_lookup_symlink (struct grub_ufs_data *data, int ino) grub_ufs_lookup_symlink (struct grub_ufs_data *data, int ino)
{ {
char symlink[INODE_SIZE (data)]; char symlink[INODE_SIZE (data)];
if (++data->linknest > GRUB_UFS_MAX_SYMLNK_CNT) if (++data->linknest > GRUB_UFS_MAX_SYMLNK_CNT)
return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks"); return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks");
if (INODE_NBLOCKS (data) == 0) if (INODE_NBLOCKS (data) == 0)
grub_strcpy (symlink, (char *) INODE (data, symlink)); grub_strcpy (symlink, (char *) INODE (data, symlink));
else else
{ {
grub_disk_read (data->disk, grub_disk_read (data->disk,
(INODE_DIRBLOCKS (data, 0) (INODE_DIRBLOCKS (data, 0)
<< grub_le_to_cpu32 (data->sblock.log2_blksz)), << grub_le_to_cpu32 (data->sblock.log2_blksz)),
0, INODE_SIZE (data), symlink); 0, INODE_SIZE (data), symlink);
symlink[INODE_SIZE (data)] = '\0'; symlink[INODE_SIZE (data)] = '\0';
@ -409,15 +409,15 @@ grub_ufs_lookup_symlink (struct grub_ufs_data *data, int ino)
/* The symlink is an absolute path, go back to the root inode. */ /* The symlink is an absolute path, go back to the root inode. */
if (symlink[0] == '/') if (symlink[0] == '/')
ino = GRUB_UFS_INODE; ino = GRUB_UFS_INODE;
/* Now load in the old inode. */ /* Now load in the old inode. */
if (grub_ufs_read_inode (data, ino, 0)) if (grub_ufs_read_inode (data, ino, 0))
return grub_errno; return grub_errno;
grub_ufs_find_file (data, symlink); grub_ufs_find_file (data, symlink);
if (grub_errno) if (grub_errno)
grub_error (grub_errno, "Can not follow symlink `%s'.", symlink); grub_error (grub_errno, "Can not follow symlink `%s'.", symlink);
return grub_errno; return grub_errno;
} }
@ -432,9 +432,9 @@ grub_ufs_find_file (struct grub_ufs_data *data, const char *path)
char *next; char *next;
unsigned int pos = 0; unsigned int pos = 0;
int dirino; int dirino;
grub_strcpy (fpath, path); grub_strcpy (fpath, path);
/* Skip the first slash. */ /* Skip the first slash. */
if (name[0] == '/') if (name[0] == '/')
{ {
@ -450,31 +450,31 @@ grub_ufs_find_file (struct grub_ufs_data *data, const char *path)
next[0] = '\0'; next[0] = '\0';
next++; next++;
} }
do do
{ {
struct grub_ufs_dirent dirent; struct grub_ufs_dirent dirent;
int namelen; int namelen;
if (grub_strlen (name) == 0) if (grub_strlen (name) == 0)
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
if (grub_ufs_read_file (data, 0, pos, sizeof (dirent), if (grub_ufs_read_file (data, 0, pos, sizeof (dirent),
(char *) &dirent) < 0) (char *) &dirent) < 0)
return grub_errno; return grub_errno;
namelen = (data->ufs_type == UFS2) namelen = (data->ufs_type == UFS2)
? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen); ? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen);
{ {
char filename[namelen + 1]; char filename[namelen + 1];
if (grub_ufs_read_file (data, 0, pos + sizeof (dirent), if (grub_ufs_read_file (data, 0, pos + sizeof (dirent),
namelen, filename) < 0) namelen, filename) < 0)
return grub_errno; return grub_errno;
filename[namelen] = '\0'; filename[namelen] = '\0';
if (!grub_strcmp (name, filename)) if (!grub_strcmp (name, filename))
{ {
dirino = data->ino; dirino = data->ino;
@ -500,17 +500,17 @@ grub_ufs_find_file (struct grub_ufs_data *data, const char *path)
next[0] = '\0'; next[0] = '\0';
next++; next++;
} }
if ((INODE_MODE(data) & GRUB_UFS_ATTR_TYPE) != GRUB_UFS_ATTR_DIR) if ((INODE_MODE(data) & GRUB_UFS_ATTR_TYPE) != GRUB_UFS_ATTR_DIR)
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
continue; continue;
} }
} }
pos += grub_le_to_cpu16 (dirent.direntlen); pos += grub_le_to_cpu16 (dirent.direntlen);
} while (pos < INODE_SIZE (data)); } while (pos < INODE_SIZE (data));
grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
return grub_errno; return grub_errno;
} }
@ -522,11 +522,11 @@ grub_ufs_mount (grub_disk_t disk)
{ {
struct grub_ufs_data *data; struct grub_ufs_data *data;
int *sblklist = sblocklist; int *sblklist = sblocklist;
data = grub_malloc (sizeof (struct grub_ufs_data)); data = grub_malloc (sizeof (struct grub_ufs_data));
if (!data) if (!data)
return 0; return 0;
/* Find a UFS1 or UFS2 sblock. */ /* Find a UFS1 or UFS2 sblock. */
data->ufs_type = UNKNOWN; data->ufs_type = UNKNOWN;
while (*sblklist != -1) while (*sblklist != -1)
@ -535,7 +535,7 @@ grub_ufs_mount (grub_disk_t disk)
&data->sblock); &data->sblock);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
if (grub_le_to_cpu32 (data->sblock.magic) == GRUB_UFS_MAGIC) if (grub_le_to_cpu32 (data->sblock.magic) == GRUB_UFS_MAGIC)
{ {
data->ufs_type = UFS1; data->ufs_type = UFS1;
@ -560,17 +560,17 @@ grub_ufs_mount (grub_disk_t disk)
fail: fail:
grub_free (data); grub_free (data);
if (grub_errno == GRUB_ERR_OUT_OF_RANGE) if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_error (GRUB_ERR_BAD_FS, "not a ufs filesystem"); grub_error (GRUB_ERR_BAD_FS, "not a ufs filesystem");
return 0; return 0;
} }
static grub_err_t static grub_err_t
grub_ufs_dir (grub_device_t device, const char *path, grub_ufs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_ufs_data *data; struct grub_ufs_data *data;
@ -580,50 +580,50 @@ grub_ufs_dir (grub_device_t device, const char *path,
data = grub_ufs_mount (device->disk); data = grub_ufs_mount (device->disk);
if (!data) if (!data)
return grub_errno; return grub_errno;
grub_ufs_read_inode (data, GRUB_UFS_INODE, 0); grub_ufs_read_inode (data, GRUB_UFS_INODE, 0);
if (grub_errno) if (grub_errno)
return grub_errno; return grub_errno;
sblock = &data->sblock; sblock = &data->sblock;
if (!path || path[0] != '/') if (!path || path[0] != '/')
{ {
grub_error (GRUB_ERR_BAD_FILENAME, "bad filename"); grub_error (GRUB_ERR_BAD_FILENAME, "bad filename");
return grub_errno; return grub_errno;
} }
grub_ufs_find_file (data, path); grub_ufs_find_file (data, path);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
if ((INODE_MODE (data) & GRUB_UFS_ATTR_TYPE) != GRUB_UFS_ATTR_DIR) if ((INODE_MODE (data) & GRUB_UFS_ATTR_TYPE) != GRUB_UFS_ATTR_DIR)
{ {
grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
goto fail; goto fail;
} }
while (pos < INODE_SIZE (data)) while (pos < INODE_SIZE (data))
{ {
struct grub_ufs_dirent dirent; struct grub_ufs_dirent dirent;
int namelen; int namelen;
if (grub_ufs_read_file (data, 0, pos, sizeof (dirent), if (grub_ufs_read_file (data, 0, pos, sizeof (dirent),
(char *) &dirent) < 0) (char *) &dirent) < 0)
break; break;
namelen = (data->ufs_type == UFS2) namelen = (data->ufs_type == UFS2)
? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen); ? dirent.namelen_bsd : grub_le_to_cpu16 (dirent.namelen);
{ {
char filename[namelen + 1]; char filename[namelen + 1];
struct grub_dirhook_info info; struct grub_dirhook_info info;
grub_memset (&info, 0, sizeof (info)); grub_memset (&info, 0, sizeof (info));
if (grub_ufs_read_file (data, 0, pos + sizeof (dirent), if (grub_ufs_read_file (data, 0, pos + sizeof (dirent),
namelen, filename) < 0) namelen, filename) < 0)
break; break;
filename[namelen] = '\0'; filename[namelen] = '\0';
if (data->ufs_type == UFS1) if (data->ufs_type == UFS1)
{ {
@ -647,7 +647,7 @@ grub_ufs_dir (grub_device_t device, const char *path,
if (hook (filename, &info)) if (hook (filename, &info))
break; break;
} }
pos += grub_le_to_cpu16 (dirent.direntlen); pos += grub_le_to_cpu16 (dirent.direntlen);
} }
@ -666,27 +666,27 @@ grub_ufs_open (struct grub_file *file, const char *name)
data = grub_ufs_mount (file->device->disk); data = grub_ufs_mount (file->device->disk);
if (!data) if (!data)
return grub_errno; return grub_errno;
grub_ufs_read_inode (data, 2, 0); grub_ufs_read_inode (data, 2, 0);
if (grub_errno) if (grub_errno)
{ {
grub_free (data); grub_free (data);
return grub_errno; return grub_errno;
} }
if (!name || name[0] != '/') if (!name || name[0] != '/')
{ {
grub_error (GRUB_ERR_BAD_FILENAME, "bad filename"); grub_error (GRUB_ERR_BAD_FILENAME, "bad filename");
return grub_errno; return grub_errno;
} }
grub_ufs_find_file (data, name); grub_ufs_find_file (data, name);
if (grub_errno) if (grub_errno)
{ {
grub_free (data); grub_free (data);
return grub_errno; return grub_errno;
} }
file->data = data; file->data = data;
file->size = INODE_SIZE (data); file->size = INODE_SIZE (data);
@ -697,9 +697,9 @@ grub_ufs_open (struct grub_file *file, const char *name)
static grub_ssize_t static grub_ssize_t
grub_ufs_read (grub_file_t file, char *buf, grub_size_t len) grub_ufs_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_ufs_data *data = struct grub_ufs_data *data =
(struct grub_ufs_data *) file->data; (struct grub_ufs_data *) file->data;
return grub_ufs_read_file (data, file->read_hook, file->offset, len, buf); return grub_ufs_read_file (data, file->read_hook, file->offset, len, buf);
} }
@ -708,7 +708,7 @@ static grub_err_t
grub_ufs_close (grub_file_t file) grub_ufs_close (grub_file_t file)
{ {
grub_free (file->data); grub_free (file->data);
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
@ -737,7 +737,7 @@ grub_ufs_label (grub_device_t device, char **label)
} }
/* Get mtime. */ /* Get mtime. */
static grub_err_t static grub_err_t
grub_ufs_mtime (grub_device_t device, grub_int32_t *tm) grub_ufs_mtime (grub_device_t device, grub_int32_t *tm)
{ {
struct grub_ufs_data *data = 0; struct grub_ufs_data *data = 0;

View file

@ -42,7 +42,7 @@ struct grub_xfs_sblock
grub_uint8_t unused2[8]; grub_uint8_t unused2[8];
grub_uint64_t rootino; grub_uint64_t rootino;
grub_uint8_t unused3[20]; grub_uint8_t unused3[20];
grub_uint32_t agsize; grub_uint32_t agsize;
grub_uint8_t unused4[20]; grub_uint8_t unused4[20];
grub_uint8_t label[12]; grub_uint8_t label[12];
grub_uint8_t log2_bsize; grub_uint8_t log2_bsize;
@ -395,7 +395,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
{ {
struct grub_fshelp_node *diro = (struct grub_fshelp_node *) dir; struct grub_fshelp_node *diro = (struct grub_fshelp_node *) dir;
auto int NESTED_FUNC_ATTR call_hook (grub_uint64_t ino, char *filename); auto int NESTED_FUNC_ATTR call_hook (grub_uint64_t ino, char *filename);
int NESTED_FUNC_ATTR call_hook (grub_uint64_t ino, char *filename) int NESTED_FUNC_ATTR call_hook (grub_uint64_t ino, char *filename)
{ {
struct grub_fshelp_node *fdiro; struct grub_fshelp_node *fdiro;
@ -403,7 +403,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
fdiro = grub_malloc (sizeof (struct grub_fshelp_node)); fdiro = grub_malloc (sizeof (struct grub_fshelp_node));
if (!fdiro) if (!fdiro)
return 0; return 0;
/* The inode should be read, otherwise the filetype can /* The inode should be read, otherwise the filetype can
not be determined. */ not be determined. */
fdiro->ino = ino; fdiro->ino = ino;
@ -415,7 +415,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
grub_xfs_mode_to_filetype (fdiro->inode.mode), grub_xfs_mode_to_filetype (fdiro->inode.mode),
fdiro); fdiro);
} }
switch (diro->inode.format) switch (diro->inode.format)
{ {
case XFS_INODE_FORMAT_INO: case XFS_INODE_FORMAT_INO:
@ -453,7 +453,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
+ sizeof (struct grub_xfs_dir_entry) + sizeof (struct grub_xfs_dir_entry)
+ de->len - 1); + de->len - 1);
char name[de->len + 1]; char name[de->len + 1];
if (smallino) if (smallino)
{ {
ino = grub_be_to_cpu32 (*(grub_uint32_t *) inopos); ino = grub_be_to_cpu32 (*(grub_uint32_t *) inopos);
@ -467,7 +467,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
if (call_hook (ino, name)) if (call_hook (ino, name))
return 1; return 1;
de = ((struct grub_xfs_dir_entry *) de = ((struct grub_xfs_dir_entry *)
(((char *) de)+ sizeof (struct grub_xfs_dir_entry) + de->len (((char *) de)+ sizeof (struct grub_xfs_dir_entry) + de->len
+ ((smallino ? sizeof (grub_uint32_t) + ((smallino ? sizeof (grub_uint32_t)
: sizeof (grub_uint64_t))) - 1)); : sizeof (grub_uint64_t))) - 1));
@ -493,7 +493,7 @@ grub_xfs_iterate_dir (grub_fshelp_node_t dir,
/* Iterate over every block the directory has. */ /* Iterate over every block the directory has. */
for (blk = 0; for (blk = 0;
blk < (grub_be_to_cpu64 (dir->inode.size) blk < (grub_be_to_cpu64 (dir->inode.size)
>> dirblk_log2); >> dirblk_log2);
blk++) blk++)
{ {
@ -585,7 +585,7 @@ grub_xfs_mount (grub_disk_t disk)
if (grub_disk_read (disk, 0, 0, if (grub_disk_read (disk, 0, 0,
sizeof (struct grub_xfs_sblock), &data->sblock)) sizeof (struct grub_xfs_sblock), &data->sblock))
goto fail; goto fail;
if (grub_strncmp ((char *) (data->sblock.magic), "XFSB", 4)) if (grub_strncmp ((char *) (data->sblock.magic), "XFSB", 4))
{ {
grub_error (GRUB_ERR_BAD_FS, "not a xfs filesystem"); grub_error (GRUB_ERR_BAD_FS, "not a xfs filesystem");
@ -606,24 +606,24 @@ grub_xfs_mount (grub_disk_t disk)
return data; return data;
fail: fail:
if (grub_errno == GRUB_ERR_OUT_OF_RANGE) if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_error (GRUB_ERR_BAD_FS, "not an xfs filesystem"); grub_error (GRUB_ERR_BAD_FS, "not an xfs filesystem");
grub_free (data); grub_free (data);
return 0; return 0;
} }
static grub_err_t static grub_err_t
grub_xfs_dir (grub_device_t device, const char *path, grub_xfs_dir (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)) const struct grub_dirhook_info *info))
{ {
struct grub_xfs_data *data = 0;; struct grub_xfs_data *data = 0;;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
auto int NESTED_FUNC_ATTR iterate (const char *filename, auto int NESTED_FUNC_ATTR iterate (const char *filename,
enum grub_fshelp_filetype filetype, enum grub_fshelp_filetype filetype,
grub_fshelp_node_t node); grub_fshelp_node_t node);
@ -640,18 +640,18 @@ grub_xfs_dir (grub_device_t device, const char *path,
} }
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_xfs_mount (device->disk); data = grub_xfs_mount (device->disk);
if (!data) if (!data)
goto fail; goto fail;
grub_fshelp_find_file (path, &data->diropen, &fdiro, grub_xfs_iterate_dir, grub_fshelp_find_file (path, &data->diropen, &fdiro, grub_xfs_iterate_dir,
grub_xfs_read_symlink, GRUB_FSHELP_DIR); grub_xfs_read_symlink, GRUB_FSHELP_DIR);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
grub_xfs_iterate_dir (fdiro, iterate); grub_xfs_iterate_dir (fdiro, iterate);
fail: fail:
if (fdiro != &data->diropen) if (fdiro != &data->diropen)
grub_free (fdiro); grub_free (fdiro);
@ -671,25 +671,25 @@ grub_xfs_open (struct grub_file *file, const char *name)
{ {
struct grub_xfs_data *data; struct grub_xfs_data *data;
struct grub_fshelp_node *fdiro = 0; struct grub_fshelp_node *fdiro = 0;
grub_dl_ref (my_mod); grub_dl_ref (my_mod);
data = grub_xfs_mount (file->device->disk); data = grub_xfs_mount (file->device->disk);
if (!data) if (!data)
goto fail; goto fail;
grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_xfs_iterate_dir, grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_xfs_iterate_dir,
grub_xfs_read_symlink, GRUB_FSHELP_REG); grub_xfs_read_symlink, GRUB_FSHELP_REG);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
if (!fdiro->inode_read) if (!fdiro->inode_read)
{ {
grub_xfs_read_inode (data, fdiro->ino, &fdiro->inode); grub_xfs_read_inode (data, fdiro->ino, &fdiro->inode);
if (grub_errno) if (grub_errno)
goto fail; goto fail;
} }
grub_memcpy (data->inode, grub_memcpy (data->inode,
&fdiro->inode, &fdiro->inode,
sizeof (struct grub_xfs_inode)); sizeof (struct grub_xfs_inode));
@ -705,7 +705,7 @@ grub_xfs_open (struct grub_file *file, const char *name)
if (fdiro != &data->diropen) if (fdiro != &data->diropen)
grub_free (fdiro); grub_free (fdiro);
grub_free (data); grub_free (data);
grub_dl_unref (my_mod); grub_dl_unref (my_mod);
return grub_errno; return grub_errno;
@ -715,7 +715,7 @@ grub_xfs_open (struct grub_file *file, const char *name)
static grub_ssize_t static grub_ssize_t
grub_xfs_read (grub_file_t file, char *buf, grub_size_t len) grub_xfs_read (grub_file_t file, char *buf, grub_size_t len)
{ {
struct grub_xfs_data *data = struct grub_xfs_data *data =
(struct grub_xfs_data *) file->data; (struct grub_xfs_data *) file->data;
return grub_xfs_read_file (&data->diropen, file->read_hook, return grub_xfs_read_file (&data->diropen, file->read_hook,

View file

@ -52,7 +52,7 @@ class Image
objs_str = objs.join(' ') objs_str = objs.join(' ')
deps = objs.collect {|obj| obj.suffix('d')} deps = objs.collect {|obj| obj.suffix('d')}
deps_str = deps.join(' ') deps_str = deps.join(' ')
"CLEANFILES += #{@name} #{exe} #{objs_str} "CLEANFILES += #{@name} #{exe} #{objs_str}
MOSTLYCLEANFILES += #{deps_str} MOSTLYCLEANFILES += #{deps_str}
@ -79,7 +79,7 @@ endif
flag = if /\.c$/ =~ src then 'CFLAGS' else 'ASFLAGS' end flag = if /\.c$/ =~ src then 'CFLAGS' else 'ASFLAGS' end
extra_flags = if /\.S$/ =~ src then '-DASM_FILE=1' else '' end extra_flags = if /\.S$/ =~ src then '-DASM_FILE=1' else '' end
dir = File.dirname(src) dir = File.dirname(src)
"#{obj}: #{src} $(#{src}_DEPENDENCIES) "#{obj}: #{src} $(#{src}_DEPENDENCIES)
$(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $< $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $<
-include #{dep} -include #{dep}
@ -113,7 +113,7 @@ class PModule
undsym = 'und-' + @name.suffix('lst') undsym = 'und-' + @name.suffix('lst')
mod_name = File.basename(@name, '.mod') mod_name = File.basename(@name, '.mod')
symbolic_name = mod_name.sub(/\.[^\.]*$/, '') symbolic_name = mod_name.sub(/\.[^\.]*$/, '')
"CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym} "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym}
ifneq ($(#{prefix}_EXPORTS),no) ifneq ($(#{prefix}_EXPORTS),no)
CLEANFILES += #{defsym} CLEANFILES += #{defsym}
@ -304,7 +304,7 @@ class Script
end end
src = sources[0] src = sources[0]
if /\.in$/ !~ src if /\.in$/ !~ src
raise "unknown source file `#{src}'" raise "unknown source file `#{src}'"
end end
"CLEANFILES += #{@name} "CLEANFILES += #{@name}
@ -340,7 +340,7 @@ while l = gets
cont = (/\\$/ =~ l) cont = (/\\$/ =~ l)
unless cont unless cont
str.gsub!(/\\\n/, ' ') str.gsub!(/\\\n/, ' ')
if /^([a-zA-Z0-9_]+)\s*\+?=\s*(.*?)\s*$/ =~ str if /^([a-zA-Z0-9_]+)\s*\+?=\s*(.*?)\s*$/ =~ str
var, args = $1, $2 var, args = $1, $2
@ -357,7 +357,7 @@ while l = gets
pmodules += args.split(/\s+/).collect do |pmod| pmodules += args.split(/\s+/).collect do |pmod|
PModule.new(prefix, pmod) PModule.new(prefix, pmod)
end end
when 'UTILITIES' when 'UTILITIES'
utils += args.split(/\s+/).collect do |util| utils += args.split(/\s+/).collect do |util|
Utility.new(prefix, util) Utility.new(prefix, util)
@ -387,10 +387,10 @@ while l = gets
end end
end end
end end
end end
end end
end end

View file

@ -40,7 +40,7 @@ FNR == 1 {
END { END {
if (error == 1) if (error == 1)
exit 1; exit 1;
for (mod in modtab) { for (mod in modtab) {
# Remove duplications. # Remove duplications.
split(modtab[mod], depmods, " "); split(modtab[mod], depmods, " ");

View file

@ -50,7 +50,7 @@ struct grub_acpi_table_header
grub_uint8_t oemtable[8]; grub_uint8_t oemtable[8];
grub_uint32_t oemrev; grub_uint32_t oemrev;
grub_uint8_t creator_id[4]; grub_uint8_t creator_id[4];
grub_uint32_t creator_rev; grub_uint32_t creator_rev;
} __attribute__ ((packed)); } __attribute__ ((packed));
struct grub_acpi_fadt struct grub_acpi_fadt

View file

@ -65,8 +65,8 @@ static inline grub_err_t grub_autoefi_prepare (void)
# define SYSTEM_TABLE_SIZEOF GRUB_EFIEMU_SYSTEM_TABLE_SIZEOF # define SYSTEM_TABLE_SIZEOF GRUB_EFIEMU_SYSTEM_TABLE_SIZEOF
# define SYSTEM_TABLE_VAR GRUB_EFIEMU_SYSTEM_TABLE_VAR # define SYSTEM_TABLE_VAR GRUB_EFIEMU_SYSTEM_TABLE_VAR
# define SYSTEM_TABLE_PTR GRUB_EFIEMU_SYSTEM_TABLE_PTR # define SYSTEM_TABLE_PTR GRUB_EFIEMU_SYSTEM_TABLE_PTR
# define SIZEOF_OF_UINTN GRUB_EFIEMU_SIZEOF_OF_UINTN # define SIZEOF_OF_UINTN GRUB_EFIEMU_SIZEOF_OF_UINTN
# define SYSTEM_TABLE GRUB_EFIEMU_SYSTEM_TABLE # define SYSTEM_TABLE GRUB_EFIEMU_SYSTEM_TABLE
# define grub_efi_allocate_pages(x,y) (x) # define grub_efi_allocate_pages(x,y) (x)
# define grub_efi_free_pages(x,y) GRUB_EFI_SUCCESS # define grub_efi_free_pages(x,y) GRUB_EFI_SUCCESS
# define EFI_PRESENT 1 # define EFI_PRESENT 1

View file

@ -41,7 +41,7 @@ grub_err_t grub_set_datetime (struct grub_datetime *datetime);
int grub_get_weekday (struct grub_datetime *datetime); int grub_get_weekday (struct grub_datetime *datetime);
char *grub_get_weekday_name (struct grub_datetime *datetime); char *grub_get_weekday_name (struct grub_datetime *datetime);
void grub_unixtime2datetime (grub_int32_t nix, void grub_unixtime2datetime (grub_int32_t nix,
struct grub_datetime *datetime); struct grub_datetime *datetime);

View file

@ -56,7 +56,7 @@ struct grub_disk_dev
/* The device id used by the cache manager. */ /* The device id used by the cache manager. */
unsigned long id; unsigned long id;
/* Call HOOK with each device name, until HOOK returns non-zero. */ /* Call HOOK with each device name, until HOOK returns non-zero. */
int (*iterate) (int (*hook) (const char *name)); int (*iterate) (int (*hook) (const char *name));
@ -102,7 +102,7 @@ struct grub_disk
/* The id used by the disk cache manager. */ /* The id used by the disk cache manager. */
unsigned long id; unsigned long id;
/* The partition information. This is machine-specific. */ /* The partition information. This is machine-specific. */
struct grub_partition *partition; struct grub_partition *partition;

View file

@ -662,38 +662,38 @@ typedef struct grub_efi_table_header grub_efi_table_header_t;
struct grub_efi_boot_services struct grub_efi_boot_services
{ {
grub_efi_table_header_t hdr; grub_efi_table_header_t hdr;
grub_efi_tpl_t grub_efi_tpl_t
(*raise_tpl) (grub_efi_tpl_t new_tpl); (*raise_tpl) (grub_efi_tpl_t new_tpl);
void void
(*restore_tpl) (grub_efi_tpl_t old_tpl); (*restore_tpl) (grub_efi_tpl_t old_tpl);
grub_efi_status_t grub_efi_status_t
(*allocate_pages) (grub_efi_allocate_type_t type, (*allocate_pages) (grub_efi_allocate_type_t type,
grub_efi_memory_type_t memory_type, grub_efi_memory_type_t memory_type,
grub_efi_uintn_t pages, grub_efi_uintn_t pages,
grub_efi_physical_address_t *memory); grub_efi_physical_address_t *memory);
grub_efi_status_t grub_efi_status_t
(*free_pages) (grub_efi_physical_address_t memory, (*free_pages) (grub_efi_physical_address_t memory,
grub_efi_uintn_t pages); grub_efi_uintn_t pages);
grub_efi_status_t grub_efi_status_t
(*get_memory_map) (grub_efi_uintn_t *memory_map_size, (*get_memory_map) (grub_efi_uintn_t *memory_map_size,
grub_efi_memory_descriptor_t *memory_map, grub_efi_memory_descriptor_t *memory_map,
grub_efi_uintn_t *map_key, grub_efi_uintn_t *map_key,
grub_efi_uintn_t *descriptor_size, grub_efi_uintn_t *descriptor_size,
grub_efi_uint32_t *descriptor_version); grub_efi_uint32_t *descriptor_version);
grub_efi_status_t grub_efi_status_t
(*allocate_pool) (grub_efi_memory_type_t pool_type, (*allocate_pool) (grub_efi_memory_type_t pool_type,
grub_efi_uintn_t size, grub_efi_uintn_t size,
void **buffer); void **buffer);
grub_efi_status_t grub_efi_status_t
(*free_pool) (void *buffer); (*free_pool) (void *buffer);
grub_efi_status_t grub_efi_status_t
(*create_event) (grub_efi_uint32_t type, (*create_event) (grub_efi_uint32_t type,
grub_efi_tpl_t notify_tpl, grub_efi_tpl_t notify_tpl,
@ -706,7 +706,7 @@ struct grub_efi_boot_services
(*set_timer) (grub_efi_event_t event, (*set_timer) (grub_efi_event_t event,
grub_efi_timer_delay_t type, grub_efi_timer_delay_t type,
grub_efi_uint64_t trigger_time); grub_efi_uint64_t trigger_time);
grub_efi_status_t grub_efi_status_t
(*wait_for_event) (grub_efi_uintn_t num_events, (*wait_for_event) (grub_efi_uintn_t num_events,
grub_efi_event_t *event, grub_efi_event_t *event,
@ -714,10 +714,10 @@ struct grub_efi_boot_services
grub_efi_status_t grub_efi_status_t
(*signal_event) (grub_efi_event_t event); (*signal_event) (grub_efi_event_t event);
grub_efi_status_t grub_efi_status_t
(*close_event) (grub_efi_event_t event); (*close_event) (grub_efi_event_t event);
grub_efi_status_t grub_efi_status_t
(*check_event) (grub_efi_event_t event); (*check_event) (grub_efi_event_t event);
@ -726,13 +726,13 @@ struct grub_efi_boot_services
grub_efi_guid_t *protocol, grub_efi_guid_t *protocol,
grub_efi_interface_type_t interface_type, grub_efi_interface_type_t interface_type,
void *interface); void *interface);
grub_efi_status_t grub_efi_status_t
(*reinstall_protocol_interface) (grub_efi_handle_t handle, (*reinstall_protocol_interface) (grub_efi_handle_t handle,
grub_efi_guid_t *protocol, grub_efi_guid_t *protocol,
void *old_interface, void *old_interface,
void *new_interface); void *new_interface);
grub_efi_status_t grub_efi_status_t
(*uninstall_protocol_interface) (grub_efi_handle_t handle, (*uninstall_protocol_interface) (grub_efi_handle_t handle,
grub_efi_guid_t *protocol, grub_efi_guid_t *protocol,
@ -742,9 +742,9 @@ struct grub_efi_boot_services
(*handle_protocol) (grub_efi_handle_t handle, (*handle_protocol) (grub_efi_handle_t handle,
grub_efi_guid_t *protocol, grub_efi_guid_t *protocol,
void **interface); void **interface);
void *reserved; void *reserved;
grub_efi_status_t grub_efi_status_t
(*register_protocol_notify) (grub_efi_guid_t *protocol, (*register_protocol_notify) (grub_efi_guid_t *protocol,
grub_efi_event_t event, grub_efi_event_t event,
@ -874,7 +874,7 @@ struct grub_efi_runtime_services
{ {
grub_efi_table_header_t hdr; grub_efi_table_header_t hdr;
grub_efi_status_t grub_efi_status_t
(*get_time) (grub_efi_time_t *time, (*get_time) (grub_efi_time_t *time,
grub_efi_time_capabilities_t *capabilities); grub_efi_time_capabilities_t *capabilities);
@ -944,11 +944,11 @@ struct grub_efi_simple_input_interface
grub_efi_status_t grub_efi_status_t
(*reset) (struct grub_efi_simple_input_interface *this, (*reset) (struct grub_efi_simple_input_interface *this,
grub_efi_boolean_t extended_verification); grub_efi_boolean_t extended_verification);
grub_efi_status_t grub_efi_status_t
(*read_key_stroke) (struct grub_efi_simple_input_interface *this, (*read_key_stroke) (struct grub_efi_simple_input_interface *this,
grub_efi_input_key_t *key); grub_efi_input_key_t *key);
grub_efi_event_t wait_for_key; grub_efi_event_t wait_for_key;
}; };
typedef struct grub_efi_simple_input_interface grub_efi_simple_input_interface_t; typedef struct grub_efi_simple_input_interface grub_efi_simple_input_interface_t;
@ -973,7 +973,7 @@ struct grub_efi_simple_text_output_interface
grub_efi_uintn_t *columns, grub_efi_uintn_t *columns,
grub_efi_uintn_t *rows); grub_efi_uintn_t *rows);
grub_efi_status_t grub_efi_status_t
(*set_mode) (struct grub_efi_simple_text_output_interface *this, (*set_mode) (struct grub_efi_simple_text_output_interface *this,
grub_efi_uintn_t mode_number); grub_efi_uintn_t mode_number);
@ -992,7 +992,7 @@ struct grub_efi_simple_text_output_interface
grub_efi_status_t grub_efi_status_t
(*enable_cursor) (struct grub_efi_simple_text_output_interface *this, (*enable_cursor) (struct grub_efi_simple_text_output_interface *this,
grub_efi_boolean_t visible); grub_efi_boolean_t visible);
grub_efi_simple_text_output_mode_t *mode; grub_efi_simple_text_output_mode_t *mode;
}; };
typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output_interface_t; typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output_interface_t;

View file

@ -30,14 +30,14 @@
#define GRUB_MACHINE_MEMORY_NVS 4 #define GRUB_MACHINE_MEMORY_NVS 4
#define GRUB_MACHINE_MEMORY_CODE 5 #define GRUB_MACHINE_MEMORY_CODE 5
#define GRUB_MACHINE_MEMORY_MAX_TYPE 5 #define GRUB_MACHINE_MEMORY_MAX_TYPE 5
/* This one is special: it's used internally but is never reported /* This one is special: it's used internally but is never reported
by firmware. */ by firmware. */
#define GRUB_MACHINE_MEMORY_HOLE 6 #define GRUB_MACHINE_MEMORY_HOLE 6
grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate)
(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t size, grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t size,
int type, int handle); int type, int handle);
grub_err_t grub_machine_mmap_unregister (int handle); grub_err_t grub_machine_mmap_unregister (int handle);

View file

@ -98,7 +98,7 @@ struct grub_pe32_optional_header
grub_uint32_t bss_size; grub_uint32_t bss_size;
grub_uint32_t entry_addr; grub_uint32_t entry_addr;
grub_uint32_t code_base; grub_uint32_t code_base;
#if GRUB_TARGET_SIZEOF_VOID_P == 4 #if GRUB_TARGET_SIZEOF_VOID_P == 4
grub_uint32_t data_base; grub_uint32_t data_base;
grub_uint32_t image_base; grub_uint32_t image_base;
@ -139,7 +139,7 @@ struct grub_pe32_optional_header
grub_uint32_t loader_flags; grub_uint32_t loader_flags;
grub_uint32_t num_data_directories; grub_uint32_t num_data_directories;
/* Data directories. */ /* Data directories. */
struct grub_pe32_data_directory export_table; struct grub_pe32_data_directory export_table;
struct grub_pe32_data_directory import_table; struct grub_pe32_data_directory import_table;
@ -210,7 +210,7 @@ struct grub_pe32_header
{ {
/* This should be filled in with GRUB_PE32_MSDOS_STUB. */ /* This should be filled in with GRUB_PE32_MSDOS_STUB. */
grub_uint8_t msdos_stub[GRUB_PE32_MSDOS_STUB_SIZE]; grub_uint8_t msdos_stub[GRUB_PE32_MSDOS_STUB_SIZE];
/* This is always PE\0\0. */ /* This is always PE\0\0. */
char signature[4]; char signature[4];

View file

@ -155,10 +155,10 @@ grub_err_t grub_efiemu_loadcore_init32 (void *core, grub_size_t core_size,
grub_efiemu_segment_t *segments); grub_efiemu_segment_t *segments);
grub_err_t grub_efiemu_loadcore_init64 (void *core, grub_size_t core_size, grub_err_t grub_efiemu_loadcore_init64 (void *core, grub_size_t core_size,
grub_efiemu_segment_t *segments); grub_efiemu_segment_t *segments);
grub_err_t grub_efiemu_loadcore_load32 (void *core, grub_err_t grub_efiemu_loadcore_load32 (void *core,
grub_size_t core_size, grub_size_t core_size,
grub_efiemu_segment_t segments); grub_efiemu_segment_t segments);
grub_err_t grub_efiemu_loadcore_load64 (void *core, grub_err_t grub_efiemu_loadcore_load64 (void *core,
grub_size_t core_size, grub_size_t core_size,
grub_efiemu_segment_t segments); grub_efiemu_segment_t segments);
grub_err_t grub_efiemu_loadcore_unload32 (void); grub_err_t grub_efiemu_loadcore_unload32 (void);
@ -189,14 +189,14 @@ struct grub_efiemu_configuration_table64
} __attribute__ ((packed)); } __attribute__ ((packed));
typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table64_t; typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table64_t;
grub_err_t grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid); grub_err_t grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid);
grub_err_t grub_err_t
grub_efiemu_register_configuration_table (grub_efi_guid_t guid, grub_efiemu_register_configuration_table (grub_efi_guid_t guid,
void * (*get_table) (void *data), void * (*get_table) (void *data),
void (*unload) (void *data), void (*unload) (void *data),
void *data); void *data);
/* Memory management functions */ /* Memory management functions */
int grub_efiemu_request_memalign (grub_size_t align, grub_size_t size, int grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
grub_efi_memory_type_t type); grub_efi_memory_type_t type);
void *grub_efiemu_mm_obtain_request (int handle); void *grub_efiemu_mm_obtain_request (int handle);
int grub_efiemu_get_memory_map (grub_efi_uintn_t *memory_map_size, int grub_efiemu_get_memory_map (grub_efi_uintn_t *memory_map_size,
@ -218,8 +218,8 @@ int grub_efiemu_get_memory_map (grub_efi_uintn_t *memory_map_size,
grub_efi_uintn_t *descriptor_size, grub_efi_uintn_t *descriptor_size,
grub_efi_uint32_t *descriptor_version); grub_efi_uint32_t *descriptor_version);
grub_err_t grub_err_t
grub_efiemu_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_efiemu_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
grub_uint64_t, grub_uint64_t,
grub_uint32_t)); grub_uint32_t));
int grub_efiemu_sizeof_uintn_t (void); int grub_efiemu_sizeof_uintn_t (void);
int grub_efiemu_exit_boot_services (grub_efi_uintn_t map_key); int grub_efiemu_exit_boot_services (grub_efi_uintn_t map_key);
@ -242,30 +242,30 @@ struct grub_efiemu_prepare_hook
void (*unload) (void *data); void (*unload) (void *data);
void *data; void *data;
}; };
grub_err_t grub_efiemu_prepare32 (struct grub_efiemu_prepare_hook grub_err_t grub_efiemu_prepare32 (struct grub_efiemu_prepare_hook
*prepare_hooks, *prepare_hooks,
struct grub_efiemu_configuration_table struct grub_efiemu_configuration_table
*config_tables); *config_tables);
grub_err_t grub_efiemu_prepare64 (struct grub_efiemu_prepare_hook grub_err_t grub_efiemu_prepare64 (struct grub_efiemu_prepare_hook
*prepare_hooks, *prepare_hooks,
struct grub_efiemu_configuration_table struct grub_efiemu_configuration_table
*config_tables); *config_tables);
grub_err_t grub_efiemu_unload (void); grub_err_t grub_efiemu_unload (void);
grub_err_t grub_efiemu_prepare (void); grub_err_t grub_efiemu_prepare (void);
grub_err_t grub_err_t
grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data), grub_efiemu_register_prepare_hook (grub_err_t (*hook) (void *data),
void (*unload) (void *data), void (*unload) (void *data),
void *data); void *data);
/* symbols and pointers */ /* symbols and pointers */
grub_err_t grub_efiemu_alloc_syms (void); grub_err_t grub_efiemu_alloc_syms (void);
grub_err_t grub_efiemu_request_symbols (int num); grub_err_t grub_efiemu_request_symbols (int num);
grub_err_t grub_efiemu_resolve_symbol (const char *name, grub_err_t grub_efiemu_resolve_symbol (const char *name,
int *handle, grub_off_t *off); int *handle, grub_off_t *off);
grub_err_t grub_efiemu_register_symbol (const char *name, grub_err_t grub_efiemu_register_symbol (const char *name,
int handle, grub_off_t off); int handle, grub_off_t off);
void grub_efiemu_free_syms (void); void grub_efiemu_free_syms (void);
grub_err_t grub_efiemu_write_value (void * addr, grub_uint32_t value, grub_err_t grub_efiemu_write_value (void * addr, grub_uint32_t value,
int plus_handle, int plus_handle,
int minus_handle, int ptv_needed, int size); int minus_handle, int ptv_needed, int size);
grub_err_t grub_efiemu_pnvram (void); grub_err_t grub_efiemu_pnvram (void);

View file

@ -43,18 +43,18 @@ struct grub_fs
/* Call HOOK with each file under DIR. */ /* Call HOOK with each file under DIR. */
grub_err_t (*dir) (grub_device_t device, const char *path, grub_err_t (*dir) (grub_device_t device, const char *path,
int (*hook) (const char *filename, int (*hook) (const char *filename,
const struct grub_dirhook_info *info)); const struct grub_dirhook_info *info));
/* Open a file named NAME and initialize FILE. */ /* Open a file named NAME and initialize FILE. */
grub_err_t (*open) (struct grub_file *file, const char *name); grub_err_t (*open) (struct grub_file *file, const char *name);
/* Read LEN bytes data from FILE into BUF. */ /* Read LEN bytes data from FILE into BUF. */
grub_ssize_t (*read) (struct grub_file *file, char *buf, grub_size_t len); grub_ssize_t (*read) (struct grub_file *file, char *buf, grub_size_t len);
/* Close the file FILE. */ /* Close the file FILE. */
grub_err_t (*close) (struct grub_file *file); grub_err_t (*close) (struct grub_file *file);
/* Return the label of the device DEVICE in LABEL. The label is /* Return the label of the device DEVICE in LABEL. The label is
returned in a grub_malloc'ed buffer and should be freed by the returned in a grub_malloc'ed buffer and should be freed by the
caller. */ caller. */

View file

@ -47,7 +47,7 @@ struct grub_hfs_sblock
/* A pascal style string that holds the volumename. */ /* A pascal style string that holds the volumename. */
grub_uint8_t volname[28]; grub_uint8_t volname[28];
grub_uint8_t unused5[60]; grub_uint8_t unused5[60];
grub_uint16_t embed_sig; grub_uint16_t embed_sig;
struct grub_hfs_extent embed_extent; struct grub_hfs_extent embed_extent;

View file

@ -20,11 +20,11 @@
#define GRUB_ARCH_EFI_EMU_HEADER 1 #define GRUB_ARCH_EFI_EMU_HEADER 1
grub_err_t grub_err_t
grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs, grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs,
struct grub_efiemu_elf_sym *elfsyms, struct grub_efiemu_elf_sym *elfsyms,
void *ehdr); void *ehdr);
grub_err_t grub_err_t
grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs, grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs,
struct grub_efiemu_elf_sym *elfsyms, struct grub_efiemu_elf_sym *elfsyms,
void *ehdr); void *ehdr);

View file

@ -83,7 +83,7 @@ struct grub_e820_mmap
/* For the Linux/i386 boot protocol version 2.03. */ /* For the Linux/i386 boot protocol version 2.03. */
struct linux_kernel_header struct linux_kernel_header
{ {
grub_uint8_t code1[0x0020]; grub_uint8_t code1[0x0020];
grub_uint16_t cl_magic; /* Magic number 0xA33F */ grub_uint16_t cl_magic; /* Magic number 0xA33F */
grub_uint16_t cl_offset; /* The offset of command line */ grub_uint16_t cl_offset; /* The offset of command line */
@ -135,21 +135,21 @@ struct linux_kernel_params
grub_uint8_t video_cursor_y; grub_uint8_t video_cursor_y;
grub_uint16_t ext_mem; /* 2 */ grub_uint16_t ext_mem; /* 2 */
grub_uint16_t video_page; /* 4 */ grub_uint16_t video_page; /* 4 */
grub_uint8_t video_mode; /* 6 */ grub_uint8_t video_mode; /* 6 */
grub_uint8_t video_width; /* 7 */ grub_uint8_t video_width; /* 7 */
grub_uint8_t padding1[0xa - 0x8]; grub_uint8_t padding1[0xa - 0x8];
grub_uint16_t video_ega_bx; /* a */ grub_uint16_t video_ega_bx; /* a */
grub_uint8_t padding2[0xe - 0xc]; grub_uint8_t padding2[0xe - 0xc];
grub_uint8_t video_height; /* e */ grub_uint8_t video_height; /* e */
grub_uint8_t have_vga; /* f */ grub_uint8_t have_vga; /* f */
grub_uint16_t font_size; /* 10 */ grub_uint16_t font_size; /* 10 */
grub_uint16_t lfb_width; /* 12 */ grub_uint16_t lfb_width; /* 12 */
grub_uint16_t lfb_height; /* 14 */ grub_uint16_t lfb_height; /* 14 */
grub_uint16_t lfb_depth; /* 16 */ grub_uint16_t lfb_depth; /* 16 */
@ -183,16 +183,16 @@ struct linux_kernel_params
grub_uint16_t apm_flags; /* 4c */ grub_uint16_t apm_flags; /* 4c */
grub_uint32_t apm_code_len; /* 4e */ grub_uint32_t apm_code_len; /* 4e */
grub_uint16_t apm_data_len; /* 52 */ grub_uint16_t apm_data_len; /* 52 */
grub_uint8_t padding4[0x60 - 0x54]; grub_uint8_t padding4[0x60 - 0x54];
grub_uint32_t ist_signature; /* 60 */ grub_uint32_t ist_signature; /* 60 */
grub_uint32_t ist_command; /* 64 */ grub_uint32_t ist_command; /* 64 */
grub_uint32_t ist_event; /* 68 */ grub_uint32_t ist_event; /* 68 */
grub_uint32_t ist_perf_level; /* 6c */ grub_uint32_t ist_perf_level; /* 6c */
grub_uint8_t padding5[0x80 - 0x70]; grub_uint8_t padding5[0x80 - 0x70];
grub_uint8_t hd0_drive_info[0x10]; /* 80 */ grub_uint8_t hd0_drive_info[0x10]; /* 80 */
grub_uint8_t hd1_drive_info[0x10]; /* 90 */ grub_uint8_t hd1_drive_info[0x10]; /* 90 */
grub_uint16_t rom_config_len; /* a0 */ grub_uint16_t rom_config_len; /* a0 */
@ -232,15 +232,15 @@ struct linux_kernel_params
grub_uint32_t efi_mmap_hi; /* 1dc */ grub_uint32_t efi_mmap_hi; /* 1dc */
} v0206; } v0206;
}; };
grub_uint32_t alt_mem; /* 1e0 */ grub_uint32_t alt_mem; /* 1e0 */
grub_uint8_t padding8[0x1e8 - 0x1e4]; grub_uint8_t padding8[0x1e8 - 0x1e4];
grub_uint32_t mmap_size; /* 1e8 */ grub_uint32_t mmap_size; /* 1e8 */
grub_uint8_t padding9[0x1f1 - 0x1ec]; grub_uint8_t padding9[0x1f1 - 0x1ec];
grub_uint8_t setup_sects; /* The size of the setup in sectors */ grub_uint8_t setup_sects; /* The size of the setup in sectors */
grub_uint16_t root_flags; /* If the root is mounted readonly */ grub_uint16_t root_flags; /* If the root is mounted readonly */
grub_uint16_t syssize; /* obsolete */ grub_uint16_t syssize; /* obsolete */

View file

@ -72,7 +72,7 @@ struct grub_biosdisk_drp
grub_uint8_t device_path[8]; grub_uint8_t device_path[8];
grub_uint8_t reserved2; grub_uint8_t reserved2;
grub_uint8_t checksum; grub_uint8_t checksum;
/* XXX: This is necessary, because the BIOS of Thinkpad X20 /* XXX: This is necessary, because the BIOS of Thinkpad X20
writes a garbage to the tail of drive parameters, writes a garbage to the tail of drive parameters,
regardless of a size specified in a caller. */ regardless of a size specified in a caller. */

View file

@ -90,7 +90,7 @@ struct grub_machine_mmap_entry
#define GRUB_MACHINE_MEMORY_ACPI 3 #define GRUB_MACHINE_MEMORY_ACPI 3
#define GRUB_MACHINE_MEMORY_NVS 4 #define GRUB_MACHINE_MEMORY_NVS 4
#define GRUB_MACHINE_MEMORY_MAX_TYPE 4 #define GRUB_MACHINE_MEMORY_MAX_TYPE 4
/* This one is special: it's used internally but is never reported /* This one is special: it's used internally but is never reported
by firmware. */ by firmware. */
#define GRUB_MACHINE_MEMORY_HOLE 5 #define GRUB_MACHINE_MEMORY_HOLE 5
@ -107,19 +107,19 @@ grub_uint64_t grub_mmap_get_lower (void);
#define GRUB_MMAP_MALLOC_LOW 1 #define GRUB_MMAP_MALLOC_LOW 1
#ifdef GRUB_MACHINE_PCBIOS #ifdef GRUB_MACHINE_PCBIOS
grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t size, grub_err_t grub_machine_mmap_register (grub_uint64_t start, grub_uint64_t size,
int type, int handle); int type, int handle);
grub_err_t grub_machine_mmap_unregister (int handle); grub_err_t grub_machine_mmap_unregister (int handle);
#else #else
static inline grub_err_t static inline grub_err_t
grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)), grub_machine_mmap_register (grub_uint64_t start __attribute__ ((unused)),
grub_uint64_t size __attribute__ ((unused)), grub_uint64_t size __attribute__ ((unused)),
int type __attribute__ ((unused)), int type __attribute__ ((unused)),
int handle __attribute__ ((unused))) int handle __attribute__ ((unused)))
{ {
return GRUB_ERR_NONE; return GRUB_ERR_NONE;
} }
static inline grub_err_t static inline grub_err_t
grub_machine_mmap_unregister (int handle __attribute__ ((unused))) grub_machine_mmap_unregister (int handle __attribute__ ((unused)))
{ {
return GRUB_ERR_NONE; return GRUB_ERR_NONE;

View file

@ -143,9 +143,9 @@ struct grub_vbe_mode_info_block
grub_uint8_t lin_rsvd_field_position; grub_uint8_t lin_rsvd_field_position;
grub_uint32_t max_pixel_clock; grub_uint32_t max_pixel_clock;
/* Reserved field to make structure to be 256 bytes long, VESA BIOS /* Reserved field to make structure to be 256 bytes long, VESA BIOS
Extension 3.0 Specification says to reserve 189 bytes here but Extension 3.0 Specification says to reserve 189 bytes here but
that doesn't make structure to be 256 bytes. So additional one is that doesn't make structure to be 256 bytes. So additional one is
added here. */ added here. */
grub_uint8_t reserved4[189 + 1]; grub_uint8_t reserved4[189 + 1];
} __attribute__ ((packed)); } __attribute__ ((packed));

View file

@ -41,7 +41,7 @@ grub_get_tsc (void)
"pop %%rbx\n" "pop %%rbx\n"
#else #else
"pop %%ebx\n" "pop %%ebx\n"
#endif #endif
:::"%rax", "%rcx", "%rdx"); :::"%rax", "%rcx", "%rdx");
#else #else
__asm__ __volatile__ ("xorl %%eax, %%eax\n\t" __asm__ __volatile__ ("xorl %%eax, %%eax\n\t"

View file

@ -6,22 +6,22 @@ typedef grub_uint32_t grub_xnu_ptr_t;
struct grub_xnu_boot_params struct grub_xnu_boot_params
{ {
grub_uint16_t verminor; grub_uint16_t verminor;
grub_uint16_t vermajor; grub_uint16_t vermajor;
/* Command line passed to xnu. */ /* Command line passed to xnu. */
grub_uint8_t cmdline[1024]; grub_uint8_t cmdline[1024];
/* Later are the same as EFI's get_memory_map (). */ /* Later are the same as EFI's get_memory_map (). */
grub_xnu_ptr_t efi_mmap; grub_xnu_ptr_t efi_mmap;
grub_uint32_t efi_mmap_size; grub_uint32_t efi_mmap_size;
grub_uint32_t efi_mem_desc_size; grub_uint32_t efi_mem_desc_size;
grub_uint32_t efi_mem_desc_version; grub_uint32_t efi_mem_desc_version;
/* Later are video parameters. */ /* Later are video parameters. */
grub_xnu_ptr_t lfb_base; grub_xnu_ptr_t lfb_base;
#define GRUB_XNU_VIDEO_SPLASH 1 #define GRUB_XNU_VIDEO_SPLASH 1
#define GRUB_XNU_VIDEO_TEXT_IN_VIDEO 2 #define GRUB_XNU_VIDEO_TEXT_IN_VIDEO 2
grub_uint32_t lfb_mode; grub_uint32_t lfb_mode;
grub_uint32_t lfb_line_len; grub_uint32_t lfb_line_len;
grub_uint32_t lfb_width; grub_uint32_t lfb_width;
grub_uint32_t lfb_height; grub_uint32_t lfb_height;
@ -30,12 +30,12 @@ struct grub_xnu_boot_params
/* Pointer to device tree and its len. */ /* Pointer to device tree and its len. */
grub_xnu_ptr_t devtree; grub_xnu_ptr_t devtree;
grub_uint32_t devtreelen; grub_uint32_t devtreelen;
/* First used address by kernel or boot structures. */ /* First used address by kernel or boot structures. */
grub_xnu_ptr_t heap_start; grub_xnu_ptr_t heap_start;
/* Last used address by kernel or boot structures minus previous value. */ /* Last used address by kernel or boot structures minus previous value. */
grub_uint32_t heap_size; grub_uint32_t heap_size;
/* First memory page containing runtime code or data. */ /* First memory page containing runtime code or data. */
grub_uint32_t efi_runtime_first_page; grub_uint32_t efi_runtime_first_page;
/* First memory page containing runtime code or data minus previous value. */ /* First memory page containing runtime code or data minus previous value. */

Some files were not shown because too many files have changed in this diff Show more