* grub-core/fs/fat.c: Include grub/fat.h.
(grub_fat_bpb): Moved to ... * include/grub/fat.h (grub_fat_bpb): ... here. New file. * grub-core/loader/i386/pc/chainloader.c: Include grub/fat.h and grub/ntfs.h. * include/grub/i386/pc/chainloader.h (grub_chainloader_flags_t): Moved from here... * grub-core/loader/i386/pc/chainloader.c (grub_chainloader_flags_t): ... here. * grub-core/loader/i386/pc/chainloader.c (grub_chainloader_patch_bpb): New function. (grub_chainloader_cmd): Patch BPB if --bpb is given. (GRUB_MOD_INIT): Show --bpb. * grub-core/loader/i386/pc/ntldr.c (grub_cmd_ntldr): Patch BPB. * grub-core/normal/main.c (features): New variable. (GRUB_MOD_INIT): Set feature_* variables. * include/grub/i386/pc/chainloader.h (grub_chainloader_patch_bpb): New proto. * include/grub/ntfs.h (grub_ntfs_bpb): New field bios_drive.
This commit is contained in:
commit
1e4b43901a
8 changed files with 199 additions and 59 deletions
22
ChangeLog
22
ChangeLog
|
@ -1,3 +1,25 @@
|
||||||
|
2011-05-18 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* grub-core/fs/fat.c: Include grub/fat.h.
|
||||||
|
(grub_fat_bpb): Moved to ...
|
||||||
|
* include/grub/fat.h (grub_fat_bpb): ... here. New file.
|
||||||
|
* grub-core/loader/i386/pc/chainloader.c: Include grub/fat.h and
|
||||||
|
grub/ntfs.h.
|
||||||
|
* include/grub/i386/pc/chainloader.h (grub_chainloader_flags_t):
|
||||||
|
Moved from here...
|
||||||
|
* grub-core/loader/i386/pc/chainloader.c (grub_chainloader_flags_t): ...
|
||||||
|
here.
|
||||||
|
* grub-core/loader/i386/pc/chainloader.c (grub_chainloader_patch_bpb):
|
||||||
|
New function.
|
||||||
|
(grub_chainloader_cmd): Patch BPB if --bpb is given.
|
||||||
|
(GRUB_MOD_INIT): Show --bpb.
|
||||||
|
* grub-core/loader/i386/pc/ntldr.c (grub_cmd_ntldr): Patch BPB.
|
||||||
|
* grub-core/normal/main.c (features): New variable.
|
||||||
|
(GRUB_MOD_INIT): Set feature_* variables.
|
||||||
|
* include/grub/i386/pc/chainloader.h (grub_chainloader_patch_bpb): New
|
||||||
|
proto.
|
||||||
|
* include/grub/ntfs.h (grub_ntfs_bpb): New field bios_drive.
|
||||||
|
|
||||||
2011-05-18 Vladimir Serbinenko <phcoder@gmail.com>
|
2011-05-18 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* grub-core/Makefile.core.def (ieee1275_fb): Use enable=powerpc_ieee1275
|
* grub-core/Makefile.core.def (ieee1275_fb): Use enable=powerpc_ieee1275
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <grub/err.h>
|
#include <grub/err.h>
|
||||||
#include <grub/dl.h>
|
#include <grub/dl.h>
|
||||||
#include <grub/charset.h>
|
#include <grub/charset.h>
|
||||||
|
#include <grub/fat.h>
|
||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
@ -51,52 +52,6 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
| GRUB_FAT_ATTR_ARCHIVE \
|
| GRUB_FAT_ATTR_ARCHIVE \
|
||||||
| GRUB_FAT_ATTR_VOLUME_ID)
|
| GRUB_FAT_ATTR_VOLUME_ID)
|
||||||
|
|
||||||
struct grub_fat_bpb
|
|
||||||
{
|
|
||||||
grub_uint8_t jmp_boot[3];
|
|
||||||
grub_uint8_t oem_name[8];
|
|
||||||
grub_uint16_t bytes_per_sector;
|
|
||||||
grub_uint8_t sectors_per_cluster;
|
|
||||||
grub_uint16_t num_reserved_sectors;
|
|
||||||
grub_uint8_t num_fats;
|
|
||||||
grub_uint16_t num_root_entries;
|
|
||||||
grub_uint16_t num_total_sectors_16;
|
|
||||||
grub_uint8_t media;
|
|
||||||
grub_uint16_t sectors_per_fat_16;
|
|
||||||
grub_uint16_t sectors_per_track;
|
|
||||||
grub_uint16_t num_heads;
|
|
||||||
grub_uint32_t num_hidden_sectors;
|
|
||||||
grub_uint32_t num_total_sectors_32;
|
|
||||||
union
|
|
||||||
{
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
grub_uint8_t num_ph_drive;
|
|
||||||
grub_uint8_t reserved;
|
|
||||||
grub_uint8_t boot_sig;
|
|
||||||
grub_uint32_t num_serial;
|
|
||||||
grub_uint8_t label[11];
|
|
||||||
grub_uint8_t fstype[8];
|
|
||||||
} __attribute__ ((packed)) fat12_or_fat16;
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
grub_uint32_t sectors_per_fat_32;
|
|
||||||
grub_uint16_t extended_flags;
|
|
||||||
grub_uint16_t fs_version;
|
|
||||||
grub_uint32_t root_cluster;
|
|
||||||
grub_uint16_t fs_info;
|
|
||||||
grub_uint16_t backup_boot_sector;
|
|
||||||
grub_uint8_t reserved[12];
|
|
||||||
grub_uint8_t num_ph_drive;
|
|
||||||
grub_uint8_t reserved1;
|
|
||||||
grub_uint8_t boot_sig;
|
|
||||||
grub_uint32_t num_serial;
|
|
||||||
grub_uint8_t label[11];
|
|
||||||
grub_uint8_t fstype[8];
|
|
||||||
} __attribute__ ((packed)) fat32;
|
|
||||||
} __attribute__ ((packed)) version_specific;
|
|
||||||
} __attribute__ ((packed));
|
|
||||||
|
|
||||||
struct grub_fat_dir_entry
|
struct grub_fat_dir_entry
|
||||||
{
|
{
|
||||||
grub_uint8_t name[11];
|
grub_uint8_t name[11];
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
#include <grub/i18n.h>
|
#include <grub/i18n.h>
|
||||||
#include <grub/video.h>
|
#include <grub/video.h>
|
||||||
#include <grub/mm.h>
|
#include <grub/mm.h>
|
||||||
|
#include <grub/fat.h>
|
||||||
|
#include <grub/ntfs.h>
|
||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
@ -44,6 +46,12 @@ static grub_dl_t my_mod;
|
||||||
static int boot_drive;
|
static int boot_drive;
|
||||||
static void *boot_part_addr;
|
static void *boot_part_addr;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
GRUB_CHAINLOADER_FORCE = 0x1,
|
||||||
|
GRUB_CHAINLOADER_BPB = 0x2,
|
||||||
|
} grub_chainloader_flags_t;
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
grub_chainloader_boot (void)
|
grub_chainloader_boot (void)
|
||||||
{
|
{
|
||||||
|
@ -61,6 +69,63 @@ grub_chainloader_unload (void)
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl)
|
||||||
|
{
|
||||||
|
grub_uint32_t part_start = 0;
|
||||||
|
if (dev && dev->disk)
|
||||||
|
part_start = grub_partition_get_start (dev->disk->partition);
|
||||||
|
if (grub_memcmp ((char *) &((struct grub_ntfs_bpb *) bs)->oem_name,
|
||||||
|
"NTFS", 4) == 0)
|
||||||
|
{
|
||||||
|
struct grub_ntfs_bpb *bpb = (struct grub_ntfs_bpb *) bs;
|
||||||
|
bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
|
||||||
|
bpb->bios_drive = dl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
struct grub_fat_bpb *bpb = (struct grub_fat_bpb *) bs;
|
||||||
|
if (grub_strncmp((const char *) bpb->version_specific.fat12_or_fat16.fstype, "FAT12", 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))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (grub_le_to_cpu16 (bpb->bytes_per_sector) < 512
|
||||||
|
|| (grub_le_to_cpu16 (bpb->bytes_per_sector)
|
||||||
|
& (grub_le_to_cpu16 (bpb->bytes_per_sector) - 1)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (bpb->sectors_per_cluster == 0
|
||||||
|
|| (bpb->sectors_per_cluster & (bpb->sectors_per_cluster - 1)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (bpb->num_reserved_sectors == 0)
|
||||||
|
break;
|
||||||
|
if (bpb->num_total_sectors_16 == 0 || bpb->num_total_sectors_32 == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (bpb->num_fats == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (bpb->sectors_per_fat_16)
|
||||||
|
{
|
||||||
|
bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
|
||||||
|
bpb->version_specific.fat12_or_fat16.num_ph_drive = dl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (bpb->version_specific.fat32.sectors_per_fat_32)
|
||||||
|
{
|
||||||
|
bpb->num_hidden_sectors = grub_cpu_to_le32 (part_start);
|
||||||
|
bpb->version_specific.fat32.num_ph_drive = dl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (0);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
|
grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
|
||||||
{
|
{
|
||||||
|
@ -121,6 +186,9 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & GRUB_CHAINLOADER_BPB)
|
||||||
|
grub_chainloader_patch_bpb ((void *) 0x7C00, dev, drive);
|
||||||
|
|
||||||
if (dev)
|
if (dev)
|
||||||
grub_device_close (dev);
|
grub_device_close (dev);
|
||||||
|
|
||||||
|
@ -147,11 +215,23 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
|
||||||
{
|
{
|
||||||
grub_chainloader_flags_t flags = 0;
|
grub_chainloader_flags_t flags = 0;
|
||||||
|
|
||||||
if (argc > 0 && grub_strcmp (argv[0], "--force") == 0)
|
while (argc > 0)
|
||||||
|
{
|
||||||
|
if (grub_strcmp (argv[0], "--force") == 0)
|
||||||
{
|
{
|
||||||
flags |= GRUB_CHAINLOADER_FORCE;
|
flags |= GRUB_CHAINLOADER_FORCE;
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (grub_strcmp (argv[0], "--bpb") == 0)
|
||||||
|
{
|
||||||
|
flags |= GRUB_CHAINLOADER_BPB;
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
|
@ -167,7 +247,8 @@ static grub_command_t cmd;
|
||||||
GRUB_MOD_INIT(chainloader)
|
GRUB_MOD_INIT(chainloader)
|
||||||
{
|
{
|
||||||
cmd = grub_register_command ("chainloader", grub_cmd_chainloader,
|
cmd = grub_register_command ("chainloader", grub_cmd_chainloader,
|
||||||
0, N_("Load another boot loader."));
|
"[--force|--bpb] FILE",
|
||||||
|
N_("Load another boot loader."));
|
||||||
my_mod = mod;
|
my_mod = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <grub/video.h>
|
#include <grub/video.h>
|
||||||
#include <grub/mm.h>
|
#include <grub/mm.h>
|
||||||
#include <grub/cpu/relocator.h>
|
#include <grub/cpu/relocator.h>
|
||||||
|
#include <grub/machine/chainloader.h>
|
||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
@ -112,6 +113,7 @@ grub_cmd_ntldr (grub_command_t cmd __attribute__ ((unused)),
|
||||||
grub_device_close (dev);
|
grub_device_close (dev);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
grub_chainloader_patch_bpb (bs, dev, edx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev)
|
if (dev)
|
||||||
|
|
|
@ -473,9 +473,14 @@ grub_mini_cmd_clear (struct grub_command *cmd __attribute__ ((unused)),
|
||||||
static grub_command_t cmd_clear;
|
static grub_command_t cmd_clear;
|
||||||
|
|
||||||
static void (*grub_xputs_saved) (const char *str);
|
static void (*grub_xputs_saved) (const char *str);
|
||||||
|
static const char *features[] = {
|
||||||
|
"feature_chainloader_bpb", "feature_ntldr"
|
||||||
|
};
|
||||||
|
|
||||||
GRUB_MOD_INIT(normal)
|
GRUB_MOD_INIT(normal)
|
||||||
{
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
/* Previously many modules depended on gzio. Be nice to user and load it. */
|
/* Previously many modules depended on gzio. Be nice to user and load it. */
|
||||||
grub_dl_load ("gzio");
|
grub_dl_load ("gzio");
|
||||||
|
|
||||||
|
@ -517,6 +522,12 @@ GRUB_MOD_INIT(normal)
|
||||||
/* Set default color names. */
|
/* Set default color names. */
|
||||||
grub_env_set ("color_normal", "white/black");
|
grub_env_set ("color_normal", "white/black");
|
||||||
grub_env_set ("color_highlight", "black/white");
|
grub_env_set ("color_highlight", "black/white");
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE (features); i++)
|
||||||
|
{
|
||||||
|
grub_env_set (features[i], "y");
|
||||||
|
grub_env_export (features[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GRUB_MOD_FINI(normal)
|
GRUB_MOD_FINI(normal)
|
||||||
|
|
70
include/grub/fat.h
Normal file
70
include/grub/fat.h
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* GRUB is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GRUB is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GRUB_FAT_H
|
||||||
|
#define GRUB_FAT_H 1
|
||||||
|
|
||||||
|
#include <grub/types.h>
|
||||||
|
|
||||||
|
struct grub_fat_bpb
|
||||||
|
{
|
||||||
|
grub_uint8_t jmp_boot[3];
|
||||||
|
grub_uint8_t oem_name[8];
|
||||||
|
grub_uint16_t bytes_per_sector;
|
||||||
|
grub_uint8_t sectors_per_cluster;
|
||||||
|
grub_uint16_t num_reserved_sectors;
|
||||||
|
grub_uint8_t num_fats;
|
||||||
|
grub_uint16_t num_root_entries;
|
||||||
|
grub_uint16_t num_total_sectors_16;
|
||||||
|
grub_uint8_t media;
|
||||||
|
grub_uint16_t sectors_per_fat_16;
|
||||||
|
grub_uint16_t sectors_per_track;
|
||||||
|
grub_uint16_t num_heads;
|
||||||
|
grub_uint32_t num_hidden_sectors;
|
||||||
|
grub_uint32_t num_total_sectors_32;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
grub_uint8_t num_ph_drive;
|
||||||
|
grub_uint8_t reserved;
|
||||||
|
grub_uint8_t boot_sig;
|
||||||
|
grub_uint32_t num_serial;
|
||||||
|
grub_uint8_t label[11];
|
||||||
|
grub_uint8_t fstype[8];
|
||||||
|
} __attribute__ ((packed)) fat12_or_fat16;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
grub_uint32_t sectors_per_fat_32;
|
||||||
|
grub_uint16_t extended_flags;
|
||||||
|
grub_uint16_t fs_version;
|
||||||
|
grub_uint32_t root_cluster;
|
||||||
|
grub_uint16_t fs_info;
|
||||||
|
grub_uint16_t backup_boot_sector;
|
||||||
|
grub_uint8_t reserved[12];
|
||||||
|
grub_uint8_t num_ph_drive;
|
||||||
|
grub_uint8_t reserved1;
|
||||||
|
grub_uint8_t boot_sig;
|
||||||
|
grub_uint32_t num_serial;
|
||||||
|
grub_uint8_t label[11];
|
||||||
|
grub_uint8_t fstype[8];
|
||||||
|
} __attribute__ ((packed)) fat32;
|
||||||
|
} __attribute__ ((packed)) version_specific;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
#endif
|
|
@ -21,10 +21,7 @@
|
||||||
|
|
||||||
#include <grub/dl.h>
|
#include <grub/dl.h>
|
||||||
|
|
||||||
/* Common function for normal and rescue mode commands. */
|
void
|
||||||
typedef enum
|
grub_chainloader_patch_bpb (void *bs, grub_device_t dev, grub_uint8_t dl);
|
||||||
{
|
|
||||||
GRUB_CHAINLOADER_FORCE = 0x1
|
|
||||||
} grub_chainloader_flags_t;
|
|
||||||
|
|
||||||
#endif /* GRUB_CHAINLOADER_MACHINE_HEADER */
|
#endif /* GRUB_CHAINLOADER_MACHINE_HEADER */
|
||||||
|
|
|
@ -106,14 +106,16 @@ struct grub_ntfs_bpb
|
||||||
grub_uint16_t sectors_per_track;
|
grub_uint16_t sectors_per_track;
|
||||||
grub_uint16_t num_heads;
|
grub_uint16_t num_heads;
|
||||||
grub_uint32_t num_hidden_sectors;
|
grub_uint32_t num_hidden_sectors;
|
||||||
grub_uint32_t reserved_3[2];
|
grub_uint32_t reserved_3;
|
||||||
|
grub_uint8_t bios_drive;
|
||||||
|
grub_uint8_t reserved_4[3];
|
||||||
grub_uint64_t num_total_sectors;
|
grub_uint64_t num_total_sectors;
|
||||||
grub_uint64_t mft_lcn;
|
grub_uint64_t mft_lcn;
|
||||||
grub_uint64_t mft_mirr_lcn;
|
grub_uint64_t mft_mirr_lcn;
|
||||||
grub_int8_t clusters_per_mft;
|
grub_int8_t clusters_per_mft;
|
||||||
grub_int8_t reserved_4[3];
|
|
||||||
grub_int8_t clusters_per_index;
|
|
||||||
grub_int8_t reserved_5[3];
|
grub_int8_t reserved_5[3];
|
||||||
|
grub_int8_t clusters_per_index;
|
||||||
|
grub_int8_t reserved_6[3];
|
||||||
grub_uint64_t num_serial;
|
grub_uint64_t num_serial;
|
||||||
grub_uint32_t checksum;
|
grub_uint32_t checksum;
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
Loading…
Reference in a new issue