2007-04-26 22:51:00 +04:00
|
|
|
/* $NetBSD: fdisk.c,v 1.104 2007/04/26 18:51:00 christos Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
/*
|
1993-04-09 23:23:56 +04:00
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1992 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
1994-09-23 08:30:13 +04:00
|
|
|
*
|
1993-04-09 23:23:56 +04:00
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
1994-09-23 08:30:13 +04:00
|
|
|
*
|
1993-04-09 23:23:56 +04:00
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
1994-09-23 08:30:13 +04:00
|
|
|
*
|
1993-04-09 23:23:56 +04:00
|
|
|
* Carnegie Mellon requests users of this software to return to
|
1994-09-23 08:30:13 +04:00
|
|
|
*
|
1993-04-09 23:23:56 +04:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
1994-09-23 08:30:13 +04:00
|
|
|
*
|
1993-04-09 23:23:56 +04:00
|
|
|
* any improvements or extensions that they make and grant Carnegie Mellon
|
|
|
|
* the rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/*
|
|
|
|
* 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University
|
|
|
|
* Copyright (c) 1989 Robert. V. Baron
|
|
|
|
* Created.
|
|
|
|
*/
|
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
1997-09-06 01:26:57 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
1993-08-02 21:48:44 +04:00
|
|
|
#ifndef lint
|
2007-04-26 22:51:00 +04:00
|
|
|
__RCSID("$NetBSD: fdisk.c,v 1.104 2007/04/26 18:51:00 christos Exp $");
|
1993-08-02 21:48:44 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2004-11-12 19:57:46 +03:00
|
|
|
#define MBRPTYPENAMES
|
1993-04-09 23:23:56 +04:00
|
|
|
#include <sys/types.h>
|
2005-06-12 23:14:10 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include <nbinclude/sys/disklabel.h>
|
|
|
|
#include <nbinclude/sys/bootblock.h>
|
|
|
|
#else
|
1993-04-09 23:23:56 +04:00
|
|
|
#include <sys/disklabel.h>
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
#include <sys/bootblock.h>
|
1993-04-09 23:23:56 +04:00
|
|
|
#include <sys/ioctl.h>
|
2001-11-07 17:50:32 +03:00
|
|
|
#include <sys/sysctl.h>
|
2005-06-12 23:14:10 +04:00
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
#include <ctype.h>
|
1994-09-23 08:30:13 +04:00
|
|
|
#include <err.h>
|
1997-09-14 17:52:26 +04:00
|
|
|
#include <errno.h>
|
1994-09-23 08:30:13 +04:00
|
|
|
#include <fcntl.h>
|
1997-09-14 17:52:26 +04:00
|
|
|
#include <paths.h>
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
1994-09-23 08:30:13 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1994-12-05 23:15:31 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2007-03-10 17:18:28 +03:00
|
|
|
#include <vis.h>
|
2005-06-12 23:14:10 +04:00
|
|
|
|
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "../../include/disktab.h"
|
|
|
|
#else
|
|
|
|
#include <disktab.h>
|
1997-09-25 09:08:28 +04:00
|
|
|
#include <util.h>
|
2005-06-12 23:14:10 +04:00
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-10-11 08:50:49 +04:00
|
|
|
#define DEFAULT_BOOTDIR "/usr/mdec"
|
|
|
|
|
2006-01-29 15:55:16 +03:00
|
|
|
#define LE_MBR_MAGIC htole16(MBR_MAGIC)
|
|
|
|
#define LE_MBR_BS_MAGIC htole16(MBR_BS_MAGIC)
|
|
|
|
|
2002-11-30 16:47:19 +03:00
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2005-06-12 23:14:10 +04:00
|
|
|
#if !HAVE_NBTOOL_CONFIG_H
|
1999-04-17 05:38:00 +04:00
|
|
|
#include <machine/cpu.h>
|
2005-06-12 23:14:10 +04:00
|
|
|
#endif /* !HAVE_NBTOOL_CONFIG_H */
|
2003-04-30 23:47:10 +04:00
|
|
|
#define BOOTSEL
|
2006-02-14 07:48:15 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BOOTSEL
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
|
|
|
|
#define DEFAULT_BOOTCODE "mbr"
|
|
|
|
#define DEFAULT_BOOTSELCODE "mbr_bootsel"
|
|
|
|
#define DEFAULT_BOOTEXTCODE "mbr_ext"
|
|
|
|
|
|
|
|
/* Scan values for the various keys we use, as returned by the BIOS */
|
|
|
|
#define SCAN_ENTER 0x1c
|
|
|
|
#define SCAN_F1 0x3b
|
|
|
|
#define SCAN_1 0x2
|
|
|
|
|
1999-04-17 05:38:00 +04:00
|
|
|
#endif
|
|
|
|
|
1993-04-09 23:23:56 +04:00
|
|
|
#define LBUF 100
|
|
|
|
static char lbuf[LBUF];
|
|
|
|
|
2003-08-29 20:31:30 +04:00
|
|
|
#ifndef PRIdaddr
|
|
|
|
#define PRIdaddr PRId64
|
|
|
|
#endif
|
|
|
|
|
2005-10-07 05:04:08 +04:00
|
|
|
#ifndef PRId64
|
2005-10-08 03:57:10 +04:00
|
|
|
#if HAVE_LONG_LONG
|
|
|
|
#define PRId64 "lld"
|
|
|
|
#endif
|
2005-10-07 05:04:08 +04:00
|
|
|
#endif
|
|
|
|
|
2000-01-31 18:54:48 +03:00
|
|
|
#ifndef _PATH_DEFDISK
|
2003-04-30 23:47:10 +04:00
|
|
|
#define _PATH_DEFDISK "/dev/rwd0d"
|
2000-01-31 18:54:48 +03:00
|
|
|
#endif
|
|
|
|
|
2000-12-19 19:01:28 +03:00
|
|
|
const char *disk = _PATH_DEFDISK;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
|
|
|
struct disklabel disklabel; /* disk parameters */
|
|
|
|
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned int cylinders, sectors, heads;
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t disksectors;
|
|
|
|
#define cylindersectors (heads * sectors)
|
1993-04-09 23:23:56 +04:00
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_sector mboot;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
struct {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_sector *ptn; /* array of pbrs */
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t base; /* first sector of ext. ptn */
|
|
|
|
daddr_t limit; /* last sector of ext. ptn */
|
|
|
|
int num_ptn; /* number of contained partitions */
|
|
|
|
int ptn_id; /* entry in mbr */
|
|
|
|
int is_corrupt; /* 1 if extended chain illegal */
|
|
|
|
} ext;
|
|
|
|
|
2005-06-27 05:00:04 +04:00
|
|
|
const char *boot_dir = DEFAULT_BOOTDIR;
|
2003-04-30 23:47:10 +04:00
|
|
|
char *boot_path = 0; /* name of file we actually opened */
|
|
|
|
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
|
|
|
|
#define DEFAULT_ACTIVE (~(daddr_t)0)
|
|
|
|
|
2004-03-19 21:19:17 +03:00
|
|
|
#define OPTIONS "0123BFSafiluvs:b:c:E:r:w:t:T:"
|
1999-04-17 05:38:00 +04:00
|
|
|
#else
|
2003-04-30 23:47:10 +04:00
|
|
|
#define change_part(e, p, id, st, sz, bm) change__part(e, p, id, st, sz)
|
2004-03-19 21:19:17 +03:00
|
|
|
#define OPTIONS "0123FSafiluvs:b:c:E:r:w:"
|
1998-10-15 19:23:23 +04:00
|
|
|
#endif
|
|
|
|
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned int dos_cylinders;
|
|
|
|
unsigned int dos_heads;
|
|
|
|
unsigned int dos_sectors;
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t dos_disksectors;
|
|
|
|
#define dos_cylindersectors (dos_heads * dos_sectors)
|
|
|
|
#define dos_totalsectors (dos_heads * dos_sectors * dos_cylinders)
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
#define DOSSECT(s,c) (((s) & 0x3f) | (((c) >> 2) & 0xc0))
|
|
|
|
#define DOSCYL(c) ((c) & 0xff)
|
2003-04-30 23:47:10 +04:00
|
|
|
#define SEC_IN_1M (1024 * 1024 / 512)
|
2005-06-12 23:06:43 +04:00
|
|
|
#define SEC_TO_MB(sec) ((unsigned int)(((sec) + SEC_IN_1M / 2) / SEC_IN_1M))
|
2003-04-30 23:47:10 +04:00
|
|
|
#define SEC_TO_CYL(sec) (((sec) + dos_cylindersectors/2) / dos_cylindersectors)
|
1998-09-28 19:44:18 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
#define MAXCYL 1024 /* Usual limit is 1023 */
|
|
|
|
#define MAXHEAD 256 /* Usual limit is 255 */
|
|
|
|
#define MAXSECTOR 63
|
1994-09-23 08:30:13 +04:00
|
|
|
int partition = -1;
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
int fd = -1, wfd = -1, *rfd = &fd;
|
2005-06-12 23:14:10 +04:00
|
|
|
char *disk_file = NULL;
|
2004-03-19 21:19:17 +03:00
|
|
|
char *disk_type = NULL;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int a_flag; /* set active partition */
|
1998-09-28 19:44:18 +04:00
|
|
|
int i_flag; /* init bootcode */
|
1994-09-23 08:30:13 +04:00
|
|
|
int u_flag; /* update partition data */
|
2003-04-30 23:47:10 +04:00
|
|
|
int v_flag; /* more verbose */
|
1997-08-12 03:31:41 +04:00
|
|
|
int sh_flag; /* Output data as shell defines */
|
|
|
|
int f_flag; /* force --not interactive */
|
|
|
|
int s_flag; /* set id,offset,size */
|
1997-09-06 01:26:57 +04:00
|
|
|
int b_flag; /* Set cyl, heads, secs (as c/h/s) */
|
1999-04-17 05:38:00 +04:00
|
|
|
int B_flag; /* Edit/install bootselect code */
|
2003-04-30 23:47:10 +04:00
|
|
|
int E_flag; /* extended partition number */
|
1997-09-06 01:26:57 +04:00
|
|
|
int b_cyl, b_head, b_sec; /* b_flag values. */
|
2004-03-19 21:19:17 +03:00
|
|
|
int F_flag = 0;
|
1994-09-23 08:30:13 +04:00
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_sector bootcode[8192 / sizeof (struct mbr_sector)];
|
1998-10-15 19:23:23 +04:00
|
|
|
int bootsize; /* actual size of bootcode */
|
2003-04-30 23:47:10 +04:00
|
|
|
int boot_installed; /* 1 if we've copied code into the mbr */
|
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H
|
2003-04-30 23:47:10 +04:00
|
|
|
struct disklist *dl;
|
|
|
|
#endif
|
1998-10-15 19:23:23 +04:00
|
|
|
|
2000-12-19 18:44:27 +03:00
|
|
|
|
2004-11-12 19:57:46 +03:00
|
|
|
#define KNOWN_SYSIDS (sizeof(mbr_ptypes)/sizeof(mbr_ptypes[0]))
|
2002-03-27 02:56:05 +03:00
|
|
|
|
2000-12-19 18:44:27 +03:00
|
|
|
void usage(void);
|
|
|
|
void print_s0(int);
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
void print_part(struct mbr_sector *, int, daddr_t);
|
|
|
|
void print_mbr_partition(struct mbr_sector *, int, daddr_t, daddr_t, int);
|
2007-03-10 17:18:28 +03:00
|
|
|
void print_pbr(daddr_t, int, uint8_t);
|
|
|
|
int is_all_zero(const char *, size_t);
|
|
|
|
void printvis(int, const char *, const char *, size_t);
|
2003-04-30 23:47:10 +04:00
|
|
|
int read_boot(const char *, void *, size_t, int);
|
|
|
|
void init_sector0(int);
|
2000-12-19 18:44:27 +03:00
|
|
|
void intuit_translated_geometry(void);
|
|
|
|
void get_geometry(void);
|
2003-04-30 23:47:10 +04:00
|
|
|
void get_extended_ptn(void);
|
2006-02-14 07:48:15 +03:00
|
|
|
#if (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H
|
2000-12-19 19:01:28 +03:00
|
|
|
void get_diskname(const char *, char *, size_t);
|
2006-02-14 07:48:15 +03:00
|
|
|
#endif /* (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H */
|
2003-04-30 23:47:10 +04:00
|
|
|
int change_part(int, int, int, daddr_t, daddr_t, char *);
|
2000-12-19 18:44:27 +03:00
|
|
|
void print_params(void);
|
|
|
|
void change_active(int);
|
|
|
|
void get_params_to_use(void);
|
|
|
|
void dos(int, unsigned char *, unsigned char *, unsigned char *);
|
|
|
|
int open_disk(int);
|
2003-04-30 23:47:10 +04:00
|
|
|
int read_disk(daddr_t, void *);
|
|
|
|
int write_disk(daddr_t, void *);
|
2000-12-19 18:44:27 +03:00
|
|
|
int get_params(void);
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
int read_s0(daddr_t, struct mbr_sector *);
|
2003-04-30 23:47:10 +04:00
|
|
|
int write_mbr(void);
|
|
|
|
int yesno(const char *, ...);
|
|
|
|
int decimal(const char *, int, int, int, int);
|
|
|
|
#define DEC_SEC 1 /* asking for a sector number */
|
|
|
|
#define DEC_RND 2 /* round to end of first track */
|
|
|
|
#define DEC_RND_0 4 /* round 0 to size of a track */
|
|
|
|
#define DEC_RND_DOWN 8 /* subtract 1 track */
|
|
|
|
#define DEC_RND_DOWN_2 16 /* subtract 2 tracks */
|
|
|
|
void string(const char *, int, char *);
|
|
|
|
int ptn_id(const char *, int *);
|
2000-12-19 18:44:27 +03:00
|
|
|
int type_match(const void *, const void *);
|
|
|
|
const char *get_type(int);
|
2005-06-12 23:06:43 +04:00
|
|
|
int get_mapping(int, unsigned int *, unsigned int *, unsigned int *, unsigned long *);
|
2003-04-30 23:47:10 +04:00
|
|
|
#ifdef BOOTSEL
|
|
|
|
daddr_t configure_bootsel(daddr_t);
|
|
|
|
void install_bootsel(int);
|
|
|
|
daddr_t get_default_boot(void);
|
|
|
|
void set_default_boot(daddr_t);
|
1999-04-17 05:38:00 +04:00
|
|
|
#endif
|
1997-09-06 01:26:57 +04:00
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if !HAVE_NBTOOL_CONFIG_H
|
|
|
|
static void
|
|
|
|
initvar_disk(const char **diskp)
|
|
|
|
{
|
|
|
|
int mib[2];
|
|
|
|
size_t len;
|
|
|
|
char *root_device;
|
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_ROOT_DEVICE;
|
|
|
|
if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1 ||
|
|
|
|
(root_device = malloc(len)) == NULL ||
|
|
|
|
sysctl(mib, 2, root_device, &len, NULL, 0) == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*diskp = root_device;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
1997-09-06 01:26:57 +04:00
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
2000-12-19 18:44:27 +03:00
|
|
|
main(int argc, char *argv[])
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
2003-04-30 23:47:10 +04:00
|
|
|
struct stat sb;
|
2005-06-12 23:14:10 +04:00
|
|
|
int ch;
|
2002-04-03 07:17:36 +04:00
|
|
|
size_t len;
|
2003-04-30 23:47:10 +04:00
|
|
|
char *cp;
|
|
|
|
int n;
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
daddr_t default_ptn; /* start sector of default ptn */
|
|
|
|
char *cbootmenu = 0;
|
|
|
|
#endif
|
1994-09-23 08:30:13 +04:00
|
|
|
|
1997-08-12 03:31:41 +04:00
|
|
|
int csysid, cstart, csize; /* For the b_flag. */
|
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if !HAVE_NBTOOL_CONFIG_H
|
|
|
|
initvar_disk(&disk);
|
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
2001-11-07 17:50:32 +03:00
|
|
|
|
1997-09-06 01:26:57 +04:00
|
|
|
a_flag = i_flag = u_flag = sh_flag = f_flag = s_flag = b_flag = 0;
|
2003-04-30 23:47:10 +04:00
|
|
|
v_flag = 0;
|
|
|
|
E_flag = 0;
|
1997-08-12 03:31:41 +04:00
|
|
|
csysid = cstart = csize = 0;
|
1999-04-17 05:38:00 +04:00
|
|
|
while ((ch = getopt(argc, argv, OPTIONS)) != -1)
|
1994-09-23 08:30:13 +04:00
|
|
|
switch (ch) {
|
|
|
|
case '0':
|
|
|
|
partition = 0;
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
partition = 1;
|
1993-04-09 23:23:56 +04:00
|
|
|
break;
|
1994-09-23 08:30:13 +04:00
|
|
|
case '2':
|
|
|
|
partition = 2;
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
partition = 3;
|
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'E': /* Extended partition number */
|
|
|
|
E_flag = 1;
|
|
|
|
partition = strtoul(optarg, &cp, 0);
|
|
|
|
if (*cp || partition < 0)
|
|
|
|
errx(1, "Bad partition number -E %s.", optarg);
|
|
|
|
break;
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
case 'B': /* Bootselect parameters */
|
1999-04-17 05:38:00 +04:00
|
|
|
B_flag = 1;
|
|
|
|
break;
|
|
|
|
#endif
|
2004-03-19 21:19:17 +03:00
|
|
|
case 'F': /* device argument is really a file */
|
|
|
|
F_flag = 1;
|
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'S': /* Output as shell variables */
|
1997-08-12 03:31:41 +04:00
|
|
|
sh_flag = 1;
|
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'a': /* Set active partition */
|
1994-09-23 08:30:13 +04:00
|
|
|
a_flag = 1;
|
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'f': /* Non interactive */
|
1997-08-12 03:31:41 +04:00
|
|
|
f_flag = 1;
|
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'i': /* Always update bootcode */
|
1994-09-23 08:30:13 +04:00
|
|
|
i_flag = 1;
|
1997-08-12 03:31:41 +04:00
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'l': /* List known partition types */
|
2002-03-27 02:56:05 +03:00
|
|
|
for (len = 0; len < KNOWN_SYSIDS; len++)
|
2004-11-12 19:57:46 +03:00
|
|
|
printf("%03d %s\n", mbr_ptypes[len].id,
|
|
|
|
mbr_ptypes[len].name);
|
2002-03-27 02:56:05 +03:00
|
|
|
return 0;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'u': /* Update partition details */
|
1994-09-23 08:30:13 +04:00
|
|
|
u_flag = 1;
|
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'v': /* Be verbose */
|
|
|
|
v_flag++;
|
|
|
|
break;
|
|
|
|
case 's': /* Partition details */
|
1997-07-29 12:31:31 +04:00
|
|
|
s_flag = 1;
|
2003-04-30 23:47:10 +04:00
|
|
|
if (sscanf(optarg, "%d/%d/%d%n", &csysid, &cstart,
|
|
|
|
&csize, &n) == 3) {
|
|
|
|
if (optarg[n] == 0)
|
|
|
|
break;
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
if (optarg[n] == '/') {
|
|
|
|
cbootmenu = optarg + n + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
errx(1, "Bad argument to the -s flag.");
|
1997-09-06 01:26:57 +04:00
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'b': /* BIOS geometry */
|
1997-09-06 01:26:57 +04:00
|
|
|
b_flag = 1;
|
2003-04-30 23:47:10 +04:00
|
|
|
if (sscanf(optarg, "%d/%d/%d%n", &b_cyl, &b_head,
|
|
|
|
&b_sec, &n) != 3 || optarg[n] != 0)
|
2002-08-08 17:19:18 +04:00
|
|
|
errx(1, "Bad argument to the -b flag.");
|
1998-09-28 19:44:18 +04:00
|
|
|
if (b_cyl > MAXCYL)
|
|
|
|
b_cyl = MAXCYL;
|
1997-07-29 12:31:31 +04:00
|
|
|
break;
|
2003-04-30 23:47:10 +04:00
|
|
|
case 'c': /* file/directory containing boot code */
|
|
|
|
if (strchr(optarg, '/') != NULL &&
|
|
|
|
stat(optarg, &sb) == 0 &&
|
|
|
|
(sb.st_mode & S_IFMT) == S_IFDIR) {
|
|
|
|
boot_dir = optarg;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bootsize = read_boot(optarg, bootcode,
|
|
|
|
sizeof bootcode, 1);
|
|
|
|
i_flag = 1;
|
|
|
|
break;
|
|
|
|
case 'r': /* read data from disk_file (not raw disk) */
|
|
|
|
rfd = &wfd;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 'w': /* write data to disk_file */
|
|
|
|
disk_file = optarg;
|
1998-10-15 19:23:23 +04:00
|
|
|
break;
|
2004-03-19 21:19:17 +03:00
|
|
|
case 't':
|
|
|
|
if (setdisktab(optarg) == -1)
|
|
|
|
errx(EXIT_FAILURE, "bad disktab");
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
disk_type = optarg;
|
|
|
|
break;
|
1994-09-23 08:30:13 +04:00
|
|
|
default:
|
|
|
|
usage();
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
1994-09-23 08:30:13 +04:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
if (disk_file == NULL && argc > 0)
|
|
|
|
disk_file = argv[0];
|
|
|
|
else if (disk_file == NULL)
|
|
|
|
usage();
|
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
|
|
|
|
2004-03-19 21:19:17 +03:00
|
|
|
if (disk_type != NULL && getdiskbyname(disk_type) == NULL)
|
|
|
|
errx(EXIT_FAILURE, "bad disktype");
|
|
|
|
|
1997-08-12 03:31:41 +04:00
|
|
|
if (sh_flag && (a_flag || i_flag || u_flag || f_flag || s_flag))
|
|
|
|
usage();
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (B_flag && f_flag) {
|
|
|
|
warnx("Bootselector may only be configured interactively");
|
1999-04-17 05:38:00 +04:00
|
|
|
usage();
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (f_flag && u_flag && !s_flag) {
|
|
|
|
warnx("Partition data not specified");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s_flag && partition == -1) {
|
2002-03-27 02:56:05 +03:00
|
|
|
warnx("-s flag requires a partition selected.");
|
1997-07-29 12:31:31 +04:00
|
|
|
usage();
|
1997-08-12 03:31:41 +04:00
|
|
|
}
|
|
|
|
|
1993-04-09 23:23:56 +04:00
|
|
|
if (argc > 0)
|
|
|
|
disk = argv[0];
|
1994-09-23 08:30:13 +04:00
|
|
|
|
1999-04-17 05:38:00 +04:00
|
|
|
if (open_disk(B_flag || a_flag || i_flag || u_flag) < 0)
|
1993-04-09 23:23:56 +04:00
|
|
|
exit(1);
|
|
|
|
|
2000-12-19 19:01:28 +03:00
|
|
|
if (read_s0(0, &mboot))
|
2003-04-30 23:47:10 +04:00
|
|
|
/* must have been a blank disk */
|
|
|
|
init_sector0(1);
|
1995-10-05 02:11:19 +03:00
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H
|
1999-04-17 05:38:00 +04:00
|
|
|
get_geometry();
|
|
|
|
#else
|
1995-10-05 02:11:19 +03:00
|
|
|
intuit_translated_geometry();
|
1999-04-17 05:38:00 +04:00
|
|
|
#endif
|
2003-04-30 23:47:10 +04:00
|
|
|
get_extended_ptn();
|
1997-08-12 03:31:41 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
#ifdef BOOTSEL
|
|
|
|
default_ptn = get_default_boot();
|
|
|
|
#endif
|
1997-08-12 03:31:41 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (E_flag && !u_flag && partition >= ext.num_ptn)
|
|
|
|
errx(1, "Extended partition %d is not defined.", partition);
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (u_flag && (!f_flag || b_flag))
|
|
|
|
get_params_to_use();
|
1997-08-12 03:31:41 +04:00
|
|
|
|
|
|
|
/* Do the update stuff! */
|
|
|
|
if (u_flag) {
|
2003-04-30 23:47:10 +04:00
|
|
|
if (s_flag)
|
|
|
|
change_part(E_flag, partition, csysid, cstart, csize,
|
|
|
|
cbootmenu);
|
|
|
|
else {
|
|
|
|
int part = partition, chg_ext = E_flag, prompt = 1;
|
|
|
|
do {
|
|
|
|
if (prompt) {
|
|
|
|
printf("\n");
|
|
|
|
print_s0(partition);
|
|
|
|
}
|
|
|
|
if (partition == -1)
|
|
|
|
part = ptn_id(
|
|
|
|
"Which partition do you want to change?",
|
|
|
|
&chg_ext);
|
|
|
|
if (part < 0)
|
|
|
|
break;
|
|
|
|
prompt = change_part(chg_ext, part, 0, 0, 0, 0);
|
|
|
|
} while (partition == -1);
|
|
|
|
}
|
1994-09-23 08:30:13 +04:00
|
|
|
} else
|
2003-04-30 23:47:10 +04:00
|
|
|
if (!i_flag && !B_flag) {
|
|
|
|
print_params();
|
1997-08-12 03:31:41 +04:00
|
|
|
print_s0(partition);
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (a_flag && !E_flag)
|
1993-04-09 23:23:56 +04:00
|
|
|
change_active(partition);
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
#ifdef BOOTSEL
|
|
|
|
if (B_flag || u_flag || i_flag)
|
|
|
|
/* Ensure the mbr code supports this configuration */
|
|
|
|
install_bootsel(0);
|
|
|
|
if (B_flag)
|
|
|
|
default_ptn = configure_bootsel(default_ptn);
|
|
|
|
set_default_boot(default_ptn);
|
|
|
|
#else
|
|
|
|
if (i_flag)
|
|
|
|
init_sector0(0);
|
1999-04-17 05:38:00 +04:00
|
|
|
#endif
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (u_flag || a_flag || i_flag || B_flag) {
|
1997-08-12 03:31:41 +04:00
|
|
|
if (!f_flag) {
|
1999-04-17 05:38:00 +04:00
|
|
|
printf("\nWe haven't written the MBR back to disk "
|
1997-08-12 03:31:41 +04:00
|
|
|
"yet. This is your last chance.\n");
|
2003-04-30 23:47:10 +04:00
|
|
|
if (u_flag)
|
|
|
|
print_s0(-1);
|
1997-08-12 03:31:41 +04:00
|
|
|
if (yesno("Should we write new partition table?"))
|
2003-04-30 23:47:10 +04:00
|
|
|
write_mbr();
|
1997-08-12 03:31:41 +04:00
|
|
|
} else
|
2003-04-30 23:47:10 +04:00
|
|
|
write_mbr();
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
1994-09-23 08:30:13 +04:00
|
|
|
}
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
void
|
2000-12-19 18:44:27 +03:00
|
|
|
usage(void)
|
1994-09-23 08:30:13 +04:00
|
|
|
{
|
2003-04-30 23:47:10 +04:00
|
|
|
int indent = 7 + (int)strlen(getprogname()) + 1;
|
|
|
|
|
2004-01-06 02:23:32 +03:00
|
|
|
(void)fprintf(stderr, "usage: %s [-afiluvBS] "
|
2003-04-30 23:47:10 +04:00
|
|
|
"[-b cylinders/heads/sectors] \\\n"
|
|
|
|
"%*s[-0123 | -E num "
|
|
|
|
"[-s id/start/size[/bootmenu]]] \\\n"
|
2004-03-19 21:19:17 +03:00
|
|
|
"%*s[-t disktab] [-T disktype] \\\n"
|
2005-06-12 23:14:10 +04:00
|
|
|
"%*s[-c bootcode] "
|
|
|
|
#if !HAVE_NBTOOL_CONFIG_H
|
|
|
|
"[-r|-w file] [device]\n"
|
|
|
|
#else
|
|
|
|
"[-r|-w] file\n"
|
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
2003-04-30 23:47:10 +04:00
|
|
|
"\t-a change active partition\n"
|
|
|
|
"\t-f force - not interactive\n"
|
|
|
|
"\t-i initialise MBR code\n"
|
|
|
|
"\t-l list partition types\n"
|
|
|
|
"\t-u update partition data\n"
|
|
|
|
"\t-v verbose output, -v -v more verbose still\n"
|
|
|
|
"\t-B update bootselect options\n"
|
2004-03-19 21:19:17 +03:00
|
|
|
"\t-F treat device as a regular file\n"
|
2003-04-30 23:47:10 +04:00
|
|
|
"\t-S output as shell defines\n",
|
2004-03-19 21:19:17 +03:00
|
|
|
getprogname(), indent, "", indent, "", indent, "");
|
1994-09-23 08:30:13 +04:00
|
|
|
exit(1);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
static daddr_t
|
|
|
|
ext_offset(int part)
|
|
|
|
{
|
|
|
|
daddr_t offset = ext.base;
|
|
|
|
|
|
|
|
if (part != 0)
|
|
|
|
offset += le32toh(ext.ptn[part - 1].mbr_parts[1].mbrp_start);
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
void
|
2000-12-19 18:44:27 +03:00
|
|
|
print_s0(int which)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1994-09-23 08:30:13 +04:00
|
|
|
int part;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
if (which == -1) {
|
2003-04-30 23:47:10 +04:00
|
|
|
if (!sh_flag)
|
|
|
|
printf("Partition table:\n");
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (part = 0; part < MBR_PART_COUNT; part++) {
|
1997-08-12 03:31:41 +04:00
|
|
|
if (!sh_flag)
|
|
|
|
printf("%d: ", part);
|
2003-04-30 23:47:10 +04:00
|
|
|
print_part(&mboot, part, 0);
|
1997-08-12 03:31:41 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
if (!sh_flag) {
|
|
|
|
if (ext.is_corrupt)
|
2004-11-18 15:00:18 +03:00
|
|
|
printf("Extended partition table is corrupt\n");
|
2003-04-30 23:47:10 +04:00
|
|
|
else
|
|
|
|
if (ext.num_ptn != 0)
|
|
|
|
printf("Extended partition table:\n");
|
|
|
|
}
|
|
|
|
for (part = 0; part < ext.num_ptn; part++) {
|
|
|
|
if (!sh_flag)
|
|
|
|
printf("E%d: ", part);
|
|
|
|
print_part(&ext.ptn[part], 0, ext_offset(part));
|
|
|
|
if (!sh_flag && v_flag >= 2) {
|
|
|
|
printf("link: ");
|
|
|
|
print_mbr_partition(&ext.ptn[part], 1,
|
|
|
|
ext_offset(part), ext.base, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef BOOTSEL
|
2006-01-29 15:55:16 +03:00
|
|
|
if (!sh_flag && mboot.mbr_bootsel_magic == LE_MBR_BS_MAGIC) {
|
2003-04-30 23:47:10 +04:00
|
|
|
int tmo;
|
2004-03-22 10:11:00 +03:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("Bootselector ");
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mboot.mbr_bootsel.mbrbs_flags & MBR_BS_ACTIVE) {
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("enabled");
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
tmo = le16toh(mboot.mbr_bootsel.mbrbs_timeo);
|
2003-04-30 23:47:10 +04:00
|
|
|
if (tmo == 0xffff)
|
|
|
|
printf(", infinite timeout");
|
|
|
|
else
|
|
|
|
printf(", timeout %d seconds",
|
|
|
|
(10 * tmo + 9) / 182);
|
|
|
|
} else
|
|
|
|
printf("disabled");
|
|
|
|
printf(".\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
1997-03-29 23:46:17 +03:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (E_flag) {
|
|
|
|
if (!sh_flag)
|
|
|
|
printf("Extended partition E%d:\n", which);
|
|
|
|
if (which > ext.num_ptn)
|
|
|
|
printf("Undefined\n");
|
|
|
|
else
|
|
|
|
print_part(&ext.ptn[which], 0, ext_offset(which));
|
|
|
|
} else {
|
|
|
|
if (!sh_flag)
|
|
|
|
printf("Partition %d:\n", which);
|
|
|
|
print_part(&mboot, which, 0);
|
|
|
|
}
|
1997-03-29 23:46:17 +03:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
void
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
print_part(struct mbr_sector *boot, int part, daddr_t offset)
|
1997-03-29 23:46:17 +03:00
|
|
|
{
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_partition *partp;
|
2005-06-27 05:00:04 +04:00
|
|
|
const char *e;
|
1997-03-29 23:46:17 +03:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (!sh_flag) {
|
|
|
|
print_mbr_partition(boot, part, offset, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
1997-03-29 23:46:17 +03:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
partp = &boot->mbr_parts[part];
|
|
|
|
if (boot != &mboot) {
|
|
|
|
part = boot - ext.ptn;
|
|
|
|
e = "E";
|
|
|
|
} else
|
|
|
|
e = "";
|
1997-03-29 23:46:17 +03:00
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (partp->mbrp_type == 0) {
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("PART%s%dSIZE=0\n", e, part);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
printf("PART%s%dID=%d\n", e, part, partp->mbrp_type);
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("PART%s%dSIZE=%u\n", e, part, le32toh(partp->mbrp_size));
|
2003-08-29 20:31:30 +04:00
|
|
|
printf("PART%s%dSTART=%"PRIdaddr"\n", e, part,
|
|
|
|
offset + le32toh(partp->mbrp_start));
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("PART%s%dFLAG=0x%x\n", e, part, partp->mbrp_flag);
|
|
|
|
printf("PART%s%dBCYL=%d\n", e, part,
|
|
|
|
MBR_PCYL(partp->mbrp_scyl, partp->mbrp_ssect));
|
|
|
|
printf("PART%s%dBHEAD=%d\n", e, part, partp->mbrp_shd);
|
|
|
|
printf("PART%s%dBSEC=%d\n", e, part, MBR_PSECT(partp->mbrp_ssect));
|
|
|
|
printf("PART%s%dECYL=%d\n", e, part,
|
|
|
|
MBR_PCYL(partp->mbrp_ecyl, partp->mbrp_esect));
|
|
|
|
printf("PART%s%dEHEAD=%d\n", e, part, partp->mbrp_ehd);
|
|
|
|
printf("PART%s%dESEC=%d\n", e, part, MBR_PSECT(partp->mbrp_esect));
|
1997-03-29 23:46:17 +03:00
|
|
|
}
|
|
|
|
|
2000-12-19 18:44:27 +03:00
|
|
|
static void
|
2006-11-25 19:10:32 +03:00
|
|
|
pr_cyls(daddr_t sector, int is_end)
|
1997-03-29 23:46:17 +03:00
|
|
|
{
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned long cyl, head, sect;
|
2003-04-30 23:47:10 +04:00
|
|
|
cyl = sector / dos_cylindersectors;
|
|
|
|
sect = sector - cyl * dos_cylindersectors;
|
|
|
|
head = sect / dos_sectors;
|
|
|
|
sect -= head * dos_sectors;
|
|
|
|
|
|
|
|
printf("%lu", cyl);
|
2006-11-25 19:10:32 +03:00
|
|
|
|
|
|
|
if (is_end) {
|
|
|
|
if (head == dos_heads - 1 && sect == dos_sectors - 1)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (head == 0 && sect == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("/%lu/%lu", head, sect + 1);
|
1997-03-29 23:46:17 +03:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
void
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
print_mbr_partition(struct mbr_sector *boot, int part,
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t offset, daddr_t exoffset, int indent)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t start;
|
|
|
|
daddr_t size;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_partition *partp = &boot->mbr_parts[part];
|
|
|
|
struct mbr_sector eboot;
|
2003-04-30 23:47:10 +04:00
|
|
|
int p;
|
|
|
|
static int dumped = 0;
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (partp->mbrp_type == 0 && v_flag < 2) {
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("<UNUSED>\n");
|
|
|
|
return;
|
|
|
|
}
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
start = le32toh(partp->mbrp_start);
|
|
|
|
size = le32toh(partp->mbrp_size);
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (MBR_IS_EXTENDED(partp->mbrp_type))
|
2003-04-30 23:47:10 +04:00
|
|
|
start += exoffset;
|
|
|
|
else
|
|
|
|
start += offset;
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
printf("%s (sysid %d)\n", get_type(partp->mbrp_type), partp->mbrp_type);
|
2003-04-30 23:47:10 +04:00
|
|
|
#ifdef BOOTSEL
|
2006-01-29 15:55:16 +03:00
|
|
|
if (boot->mbr_bootsel_magic == LE_MBR_BS_MAGIC &&
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
boot->mbr_bootsel.mbrbs_nametab[part][0])
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("%*s bootmenu: %s\n", indent, "",
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
boot->mbr_bootsel.mbrbs_nametab[part]);
|
2003-04-30 23:47:10 +04:00
|
|
|
#endif
|
1997-07-29 12:31:31 +04:00
|
|
|
|
2003-08-29 20:31:30 +04:00
|
|
|
printf("%*s start %"PRIdaddr", size %"PRIdaddr,
|
|
|
|
indent, "", start, size);
|
2003-04-30 23:47:10 +04:00
|
|
|
if (size != 0) {
|
|
|
|
printf(" (%u MB, Cyls ", SEC_TO_MB(size));
|
|
|
|
if (v_flag == 0 && le32toh(partp->mbrp_start) == dos_sectors)
|
2006-11-25 19:10:32 +03:00
|
|
|
pr_cyls(start - dos_sectors, 0);
|
2003-04-30 23:47:10 +04:00
|
|
|
else
|
2006-11-25 19:10:32 +03:00
|
|
|
pr_cyls(start, 0);
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("-");
|
2006-11-25 19:10:32 +03:00
|
|
|
pr_cyls(start + size - 1, 1);
|
2003-04-30 23:47:10 +04:00
|
|
|
printf(")");
|
|
|
|
}
|
1997-07-29 12:31:31 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
switch (partp->mbrp_flag) {
|
|
|
|
case 0:
|
|
|
|
break;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
case MBR_PFLAG_ACTIVE:
|
2003-04-30 23:47:10 +04:00
|
|
|
printf(", Active");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf(", flag 0x%x", partp->mbrp_flag);
|
|
|
|
break;
|
1997-07-29 12:31:31 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("\n");
|
2000-12-19 19:01:28 +03:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (v_flag) {
|
|
|
|
printf("%*s beg: cylinder %4d, head %3d, sector %2d\n",
|
|
|
|
indent, "",
|
|
|
|
MBR_PCYL(partp->mbrp_scyl, partp->mbrp_ssect),
|
|
|
|
partp->mbrp_shd, MBR_PSECT(partp->mbrp_ssect));
|
|
|
|
printf("%*s end: cylinder %4d, head %3d, sector %2d\n",
|
|
|
|
indent, "",
|
|
|
|
MBR_PCYL(partp->mbrp_ecyl, partp->mbrp_esect),
|
|
|
|
partp->mbrp_ehd, MBR_PSECT(partp->mbrp_esect));
|
|
|
|
}
|
1997-07-29 12:31:31 +04:00
|
|
|
|
2007-03-10 17:18:28 +03:00
|
|
|
if (! MBR_IS_EXTENDED(partp->mbrp_type))
|
|
|
|
print_pbr(start, indent + 8, partp->mbrp_type);
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (!MBR_IS_EXTENDED(partp->mbrp_type) ||
|
2003-04-30 23:47:10 +04:00
|
|
|
(v_flag <= 2 && !ext.is_corrupt))
|
1993-04-09 23:23:56 +04:00
|
|
|
return;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Recursive dump extended table,
|
|
|
|
* This is read from the disk - so is wrong during editing.
|
|
|
|
* Just ensure we only show it once.
|
|
|
|
*/
|
|
|
|
if (dumped)
|
|
|
|
return;
|
|
|
|
|
|
|
|
printf("%*s Extended partition table:\n", indent, "");
|
|
|
|
indent += 4;
|
|
|
|
if (read_s0(start, &eboot) == -1)
|
|
|
|
return;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (p = 0; p < MBR_PART_COUNT; p++) {
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("%*s%d: ", indent, "", p);
|
|
|
|
print_mbr_partition(&eboot, p, start,
|
|
|
|
exoffset ? exoffset : start, indent);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
if (exoffset == 0)
|
|
|
|
dumped = 1;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
2007-03-10 17:18:28 +03:00
|
|
|
/* Print a line with a label and a vis-encoded string */
|
|
|
|
void
|
|
|
|
printvis(int indent, const char *label, const char *buf, size_t size)
|
|
|
|
{
|
|
|
|
char *visbuf;
|
|
|
|
|
|
|
|
if ((visbuf = malloc(size * 4 + 1)) == NULL)
|
|
|
|
err(1, "Malloc failed");
|
|
|
|
strsvisx(visbuf, buf, size, VIS_TAB|VIS_NL|VIS_OCTAL, "\"");
|
|
|
|
printf("%*s%s: \"%s\"\n",
|
|
|
|
indent, "",
|
|
|
|
label, visbuf);
|
|
|
|
free(visbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether a buffer contains all bytes zero */
|
|
|
|
int
|
|
|
|
is_all_zero(const char *p, size_t size)
|
|
|
|
{
|
|
|
|
|
|
|
|
while (size-- > 0) {
|
|
|
|
if (*p++ != 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report on the contents of a PBR sector.
|
|
|
|
*
|
|
|
|
* We first perform several sanity checks. If vflag >= 2, we report all
|
|
|
|
* failing tests, but for smaller values of v_flag we stop after the
|
|
|
|
* first failing test. Tests are ordered in an attempt to get the most
|
|
|
|
* useful error message from the first failing test.
|
|
|
|
*
|
|
|
|
* If v_flag >= 2, we also report some decoded values from the PBR.
|
|
|
|
* These results may be meaningless, if the PBR doesn't follow common
|
|
|
|
* conventions.
|
|
|
|
*
|
|
|
|
* Trying to decode anything more than the magic number in the last
|
|
|
|
* two bytes is a layering violation, but it can be very useful in
|
|
|
|
* diagnosing boot failures.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_pbr(daddr_t sector, int indent, uint8_t part_type)
|
|
|
|
{
|
|
|
|
struct mbr_sector pboot;
|
|
|
|
unsigned char *p, *endp;
|
|
|
|
unsigned char val;
|
|
|
|
int ok;
|
|
|
|
int errcount = 0;
|
|
|
|
|
|
|
|
#define PBR_ERROR(...) \
|
|
|
|
do { \
|
|
|
|
++errcount; \
|
|
|
|
printf("%*s%s: ", indent, "", \
|
|
|
|
(v_flag < 2 ? "PBR is not bootable" : "Not bootable")); \
|
|
|
|
printf(__VA_ARGS__); \
|
|
|
|
if (v_flag < 2) \
|
|
|
|
return; \
|
|
|
|
} while (/*CONSTCOND*/ 0)
|
|
|
|
|
|
|
|
if (v_flag >= 2) {
|
|
|
|
printf("%*sInformation from PBR:\n",
|
|
|
|
indent, "");
|
|
|
|
indent += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read_disk(sector, &pboot) == -1) {
|
|
|
|
PBR_ERROR("Sector %"PRIdaddr" is unreadable (%s)\n",
|
|
|
|
sector, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* all bytes identical? */
|
|
|
|
p = (char *)&pboot;
|
|
|
|
endp = p + sizeof(pboot);
|
|
|
|
val = *p;
|
|
|
|
ok = 0;
|
|
|
|
for (; p < endp; p++) {
|
|
|
|
if (*p != val) {
|
|
|
|
ok = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! ok)
|
|
|
|
PBR_ERROR("All bytes are identical (0x%02x)\n", val);
|
|
|
|
|
|
|
|
if (pboot.mbr_magic != LE_MBR_MAGIC)
|
|
|
|
PBR_ERROR("Bad magic number (0x%04x)>\n",
|
|
|
|
le16toh(pboot.mbr_magic));
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Some i386 OS might fail this test. All non-i386 will fail. */
|
|
|
|
if (pboot.mbr_jmpboot[0] != 0xE9
|
|
|
|
&& pboot.mbr_jmpboot[0] != 0xEB) {
|
|
|
|
PBR_ERROR("Does not begin with i386 JMP instruction"
|
|
|
|
" (0x%02x 0x%02x0 0x%02x)\n",
|
|
|
|
pboot.mbr_jmpboot[0], pboot.mbr_jmpboot[1],
|
|
|
|
pboot.mbr_jmpboot[2]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (v_flag > 0 && errcount == 0)
|
|
|
|
printf("%*sPBR appears to be bootable\n",
|
|
|
|
indent, "");
|
|
|
|
if (v_flag < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (! is_all_zero(pboot.mbr_oemname, sizeof(pboot.mbr_oemname))) {
|
|
|
|
printvis(indent, "OEM name", (char *)pboot.mbr_oemname,
|
|
|
|
sizeof(pboot.mbr_oemname));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pboot.mbr_dsn != 0)
|
|
|
|
printf("%*sDrive serial number: %"PRId32" (0x%08x)\n",
|
|
|
|
indent, "",
|
|
|
|
le32toh(pboot.mbr_dsn),
|
|
|
|
le32toh(pboot.mbr_dsn));
|
|
|
|
|
|
|
|
if (pboot.mbr_bpb.bpb16.bsBootSig == 0x29)
|
|
|
|
printf("%*sBPB FAT16 boot signature found\n",
|
|
|
|
indent, "");
|
|
|
|
if (pboot.mbr_bpb.bpb32.bsBootSig == 0x29)
|
|
|
|
printf("%*sBPB FAT32 boot signature found\n",
|
|
|
|
indent, "");
|
|
|
|
|
|
|
|
#undef PBR_ERROR
|
|
|
|
}
|
|
|
|
|
1999-04-17 05:38:00 +04:00
|
|
|
int
|
2003-04-30 23:47:10 +04:00
|
|
|
read_boot(const char *name, void *buf, size_t len, int err_exit)
|
1998-10-15 19:23:23 +04:00
|
|
|
{
|
1999-04-17 05:38:00 +04:00
|
|
|
int bfd, ret;
|
1998-10-15 19:23:23 +04:00
|
|
|
struct stat st;
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (boot_path != NULL)
|
|
|
|
free(boot_path);
|
2003-05-18 03:14:42 +04:00
|
|
|
if (strchr(name, '/') == 0)
|
|
|
|
asprintf(&boot_path, "%s/%s", boot_dir, name);
|
|
|
|
else
|
|
|
|
boot_path = strdup(name);
|
2003-04-30 23:47:10 +04:00
|
|
|
if (boot_path == NULL)
|
|
|
|
err(1, "Malloc failed");
|
|
|
|
|
|
|
|
if ((bfd = open(boot_path, O_RDONLY)) < 0 || fstat(bfd, &st) == -1) {
|
|
|
|
warn("%s", boot_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (st.st_size > (off_t)len) {
|
|
|
|
warnx("%s: bootcode too large", boot_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-04-17 05:38:00 +04:00
|
|
|
ret = st.st_size;
|
2003-04-30 23:47:10 +04:00
|
|
|
if (ret < 0x200) {
|
|
|
|
warnx("%s: bootcode too small", boot_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (read(bfd, buf, len) != ret) {
|
|
|
|
warn("%s", boot_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
1998-10-15 19:23:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do some sanity checking here
|
|
|
|
*/
|
2006-01-29 15:55:16 +03:00
|
|
|
if (((struct mbr_sector *)buf)->mbr_magic != LE_MBR_MAGIC) {
|
2003-04-30 23:47:10 +04:00
|
|
|
warnx("%s: invalid magic", boot_path);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(bfd);
|
|
|
|
ret = (ret + 0x1ff) & ~0x1ff;
|
1999-04-17 05:38:00 +04:00
|
|
|
return ret;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
fail:
|
2006-03-18 11:36:50 +03:00
|
|
|
if (bfd >= 0)
|
|
|
|
close(bfd);
|
2003-04-30 23:47:10 +04:00
|
|
|
if (err_exit)
|
|
|
|
exit(1);
|
|
|
|
return 0;
|
1998-10-15 19:23:23 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
void
|
2004-03-22 10:11:00 +03:00
|
|
|
init_sector0(int zappart)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1997-08-12 03:31:41 +04:00
|
|
|
int i;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
int copy_size = MBR_PART_OFFSET;
|
1997-08-12 03:31:41 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
#ifdef DEFAULT_BOOTCODE
|
|
|
|
if (bootsize == 0)
|
|
|
|
bootsize = read_boot(DEFAULT_BOOTCODE, bootcode,
|
|
|
|
sizeof bootcode, 1);
|
|
|
|
#endif
|
|
|
|
#ifdef BOOTSEL
|
2006-01-29 15:55:16 +03:00
|
|
|
if (mboot.mbr_bootsel_magic == LE_MBR_BS_MAGIC
|
|
|
|
&& bootcode[0].mbr_bootsel_magic == LE_MBR_BS_MAGIC)
|
2004-03-22 10:11:00 +03:00
|
|
|
copy_size = MBR_BS_OFFSET;
|
1998-10-15 19:23:23 +04:00
|
|
|
#endif
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (bootsize != 0) {
|
|
|
|
boot_installed = 1;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
memcpy(&mboot, bootcode, copy_size);
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
2006-01-29 15:55:16 +03:00
|
|
|
mboot.mbr_magic = LE_MBR_MAGIC;
|
1997-08-12 03:31:41 +04:00
|
|
|
|
2004-03-22 10:11:00 +03:00
|
|
|
if (!zappart)
|
2003-04-30 23:47:10 +04:00
|
|
|
return;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (i = 0; i < MBR_PART_COUNT; i++)
|
2003-04-30 23:47:10 +04:00
|
|
|
memset(&mboot.mbr_parts[i], 0, sizeof(mboot.mbr_parts[i]));
|
|
|
|
}
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
void
|
|
|
|
get_extended_ptn(void)
|
|
|
|
{
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_partition *mp;
|
|
|
|
struct mbr_sector *boot;
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t offset;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_sector *nptn;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
/* find first (there should only be one) extended partition */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (mp = mboot.mbr_parts; !MBR_IS_EXTENDED(mp->mbrp_type); mp++)
|
|
|
|
if (mp >= &mboot.mbr_parts[MBR_PART_COUNT])
|
2003-04-30 23:47:10 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The extended partition should be structured as a linked list
|
|
|
|
* (even though it appears, at first glance, to be a tree).
|
|
|
|
*/
|
|
|
|
ext.base = le32toh(mp->mbrp_start);
|
|
|
|
ext.limit = ext.base + le32toh(mp->mbrp_size);
|
|
|
|
ext.ptn_id = mp - mboot.mbr_parts;
|
|
|
|
for (offset = 0;; offset = le32toh(boot->mbr_parts[1].mbrp_start)) {
|
2003-09-19 12:35:15 +04:00
|
|
|
nptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn);
|
|
|
|
if (nptn == NULL)
|
2003-04-30 23:47:10 +04:00
|
|
|
err(1, "Malloc failed");
|
2003-09-19 12:35:15 +04:00
|
|
|
ext.ptn = nptn;
|
2003-04-30 23:47:10 +04:00
|
|
|
boot = ext.ptn + ext.num_ptn;
|
|
|
|
if (read_s0(offset + ext.base, boot) == -1)
|
|
|
|
break;
|
|
|
|
/* expect p0 to be valid and p1 to be another extended ptn */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (MBR_IS_EXTENDED(boot->mbr_parts[0].mbrp_type))
|
2003-04-30 23:47:10 +04:00
|
|
|
break;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (boot->mbr_parts[1].mbrp_type != 0 &&
|
|
|
|
!MBR_IS_EXTENDED(boot->mbr_parts[1].mbrp_type))
|
2003-04-30 23:47:10 +04:00
|
|
|
break;
|
|
|
|
/* p2 and p3 should be unallocated */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (boot->mbr_parts[2].mbrp_type != 0 ||
|
|
|
|
boot->mbr_parts[3].mbrp_type != 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
break;
|
|
|
|
/* data ptn inside extended one */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (boot->mbr_parts[0].mbrp_type != 0 &&
|
2003-04-30 23:47:10 +04:00
|
|
|
offset + le32toh(boot->mbr_parts[0].mbrp_start)
|
|
|
|
+ le32toh(boot->mbr_parts[0].mbrp_size) > ext.limit)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ext.num_ptn++;
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (boot->mbr_parts[1].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
/* end of extended partition chain */
|
|
|
|
return;
|
|
|
|
/* must be in sector order */
|
|
|
|
if (offset >= le32toh(boot->mbr_parts[1].mbrp_start))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
warnx("Extended partition table is corrupt\n");
|
|
|
|
ext.is_corrupt = 1;
|
|
|
|
ext.num_ptn = 0;
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
|
2006-02-14 07:48:15 +03:00
|
|
|
#if (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H
|
1999-04-17 05:38:00 +04:00
|
|
|
void
|
2000-12-19 19:01:28 +03:00
|
|
|
get_diskname(const char *fullname, char *diskname, size_t size)
|
1999-04-17 05:38:00 +04:00
|
|
|
{
|
2000-12-19 19:01:28 +03:00
|
|
|
const char *p, *p2;
|
1999-04-17 05:38:00 +04:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
p = strrchr(fullname, '/');
|
|
|
|
if (p == NULL)
|
|
|
|
p = fullname;
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if (*p == 0) {
|
2003-04-30 23:47:10 +04:00
|
|
|
strlcpy(diskname, fullname, size);
|
1999-04-17 05:38:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p == 'r')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
for (p2 = p; *p2 != 0; p2++)
|
2004-10-28 23:48:41 +04:00
|
|
|
if (isdigit((unsigned char)*p2))
|
1999-04-17 05:38:00 +04:00
|
|
|
break;
|
|
|
|
if (*p2 == 0) {
|
|
|
|
/* XXX invalid diskname? */
|
2003-04-30 23:47:10 +04:00
|
|
|
strlcpy(diskname, fullname, size);
|
1999-04-17 05:38:00 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-10-28 23:48:41 +04:00
|
|
|
while (isdigit((unsigned char)*p2))
|
1999-04-17 05:38:00 +04:00
|
|
|
p2++;
|
|
|
|
|
|
|
|
len = p2 - p;
|
|
|
|
if (len > size) {
|
|
|
|
/* XXX */
|
2003-04-30 23:47:10 +04:00
|
|
|
strlcpy(diskname, fullname, size);
|
1999-04-17 05:38:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
memcpy(diskname, p, len);
|
1999-04-17 05:38:00 +04:00
|
|
|
diskname[len] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-12-19 18:44:27 +03:00
|
|
|
get_geometry(void)
|
1999-04-17 05:38:00 +04:00
|
|
|
{
|
|
|
|
int mib[2], i;
|
|
|
|
size_t len;
|
|
|
|
struct biosdisk_info *bip;
|
|
|
|
struct nativedisk_info *nip;
|
|
|
|
char diskname[8];
|
|
|
|
|
|
|
|
mib[0] = CTL_MACHDEP;
|
|
|
|
mib[1] = CPU_DISKINFO;
|
|
|
|
if (sysctl(mib, 2, NULL, &len, NULL, 0) < 0) {
|
2004-07-31 03:42:29 +04:00
|
|
|
goto out;
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
dl = (struct disklist *) malloc(len);
|
2006-03-17 18:53:46 +03:00
|
|
|
if (dl == NULL)
|
|
|
|
err(1, "Malloc failed");
|
2004-07-31 03:42:29 +04:00
|
|
|
if (sysctl(mib, 2, dl, &len, NULL, 0) < 0) {
|
|
|
|
free(dl);
|
|
|
|
dl = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
1999-04-17 05:38:00 +04:00
|
|
|
|
|
|
|
get_diskname(disk, diskname, sizeof diskname);
|
|
|
|
|
|
|
|
for (i = 0; i < dl->dl_nnativedisks; i++) {
|
|
|
|
nip = &dl->dl_nativedisks[i];
|
|
|
|
if (strcmp(diskname, nip->ni_devname))
|
|
|
|
continue;
|
|
|
|
/*
|
2003-04-30 23:47:10 +04:00
|
|
|
* XXX listing possible matches is better. This is ok for
|
|
|
|
* now because the user has a chance to change it later.
|
|
|
|
* Also, if all the disks have the same parameters then we can
|
|
|
|
* just use them, we don't need to know which disk is which.
|
1999-04-17 05:38:00 +04:00
|
|
|
*/
|
|
|
|
if (nip->ni_nmatches != 0) {
|
|
|
|
bip = &dl->dl_biosdisks[nip->ni_biosmatches[0]];
|
|
|
|
dos_cylinders = bip->bi_cyl;
|
|
|
|
dos_heads = bip->bi_head;
|
|
|
|
dos_sectors = bip->bi_sec;
|
2003-04-30 23:47:10 +04:00
|
|
|
if (bip->bi_lbasecs)
|
|
|
|
dos_disksectors = bip->bi_lbasecs;
|
1999-04-17 05:38:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-07-31 03:42:29 +04:00
|
|
|
out:
|
1999-04-17 05:38:00 +04:00
|
|
|
/* Allright, allright, make a stupid guess.. */
|
|
|
|
intuit_translated_geometry();
|
|
|
|
}
|
2006-02-14 07:48:15 +03:00
|
|
|
#endif /* (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H */
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
#ifdef BOOTSEL
|
|
|
|
daddr_t
|
|
|
|
get_default_boot(void)
|
1999-04-17 05:38:00 +04:00
|
|
|
{
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned int id;
|
2003-04-30 23:47:10 +04:00
|
|
|
int p;
|
|
|
|
|
2006-01-29 15:55:16 +03:00
|
|
|
if (mboot.mbr_bootsel_magic != LE_MBR_BS_MAGIC)
|
2003-04-30 23:47:10 +04:00
|
|
|
/* default to first active partition */
|
|
|
|
return DEFAULT_ACTIVE;
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mboot.mbr_bootsel.mbrbs_defkey == SCAN_ENTER)
|
2003-04-30 23:47:10 +04:00
|
|
|
return DEFAULT_ACTIVE;
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
id = mboot.mbr_bootsel.mbrbs_defkey;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
/* 1+ => allocated partition id, F1+ => disk 0+ */
|
|
|
|
if (id >= SCAN_F1)
|
|
|
|
return id - SCAN_F1;
|
|
|
|
id -= SCAN_1;
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (p = 0; p < MBR_PART_COUNT; p++) {
|
|
|
|
if (mboot.mbr_parts[p].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mboot.mbr_bootsel.mbrbs_nametab[p][0] == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
if (id-- == 0)
|
|
|
|
return le32toh(mboot.mbr_parts[p].mbrp_start);
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
for (p = 0; p < ext.num_ptn; p++) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_bootsel.mbrbs_nametab[0][0] == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
if (id-- == 0)
|
|
|
|
return ext_offset(p)
|
|
|
|
+ le32toh(ext.ptn[p].mbr_parts[0].mbrp_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
return DEFAULT_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_default_boot(daddr_t default_ptn)
|
|
|
|
{
|
|
|
|
int p;
|
|
|
|
int key = SCAN_1;
|
|
|
|
|
2006-01-29 15:55:16 +03:00
|
|
|
if (mboot.mbr_bootsel_magic != LE_MBR_BS_MAGIC)
|
2003-04-30 23:47:10 +04:00
|
|
|
/* sanity */
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (default_ptn == DEFAULT_ACTIVE) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
mboot.mbr_bootsel.mbrbs_defkey = SCAN_ENTER;
|
1999-04-17 05:38:00 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (p = 0; p < MBR_PART_COUNT; p++) {
|
|
|
|
if (mboot.mbr_parts[p].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mboot.mbr_bootsel.mbrbs_nametab[p][0] == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
if (le32toh(mboot.mbr_parts[p].mbrp_start) == default_ptn) {
|
2004-03-22 10:11:00 +03:00
|
|
|
mboot.mbr_bootsel.mbrbs_defkey = key;
|
1999-04-17 05:38:00 +04:00
|
|
|
return;
|
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
key++;
|
|
|
|
}
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mboot.mbr_bootsel.mbrbs_flags & MBR_BS_EXTLBA) {
|
2003-04-30 23:47:10 +04:00
|
|
|
for (p = 0; p < ext.num_ptn; p++) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_bootsel.mbrbs_nametab[0][0] == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
if (le32toh(ext.ptn[p].mbr_parts[0].mbrp_start) +
|
|
|
|
ext_offset(p) == default_ptn) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
mboot.mbr_bootsel.mbrbs_defkey = key;
|
1999-04-17 05:38:00 +04:00
|
|
|
return;
|
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
key++;
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (default_ptn < 8) {
|
2004-03-22 10:11:00 +03:00
|
|
|
key = SCAN_F1;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
mboot.mbr_bootsel.mbrbs_defkey = key + default_ptn;
|
2003-04-30 23:47:10 +04:00
|
|
|
return;
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/* Default to first active partition */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
mboot.mbr_bootsel.mbrbs_defkey = SCAN_ENTER;
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
void
|
|
|
|
install_bootsel(int needed)
|
|
|
|
{
|
|
|
|
struct mbr_bootsel *mbs = &mboot.mbr_bootsel;
|
|
|
|
int p;
|
|
|
|
int ext13 = 0;
|
2005-06-27 05:00:04 +04:00
|
|
|
const char *code;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
2004-03-22 10:11:00 +03:00
|
|
|
needed |= MBR_BS_NEWMBR; /* need new bootsel code */
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/* Work out which boot code we need for this configuration */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (p = 0; p < MBR_PART_COUNT; p++) {
|
|
|
|
if (mboot.mbr_parts[p].mbrp_type == 0)
|
1999-04-17 05:38:00 +04:00
|
|
|
continue;
|
2006-01-29 15:55:16 +03:00
|
|
|
if (mboot.mbr_bootsel_magic != LE_MBR_BS_MAGIC)
|
2003-04-30 23:47:10 +04:00
|
|
|
break;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mbs->mbrbs_nametab[p][0] == 0)
|
1999-04-17 05:38:00 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
needed |= MBR_BS_ACTIVE;
|
2003-04-30 23:47:10 +04:00
|
|
|
if (le32toh(mboot.mbr_parts[p].mbrp_start) >= dos_totalsectors)
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
ext13 = MBR_BS_EXTINT13;
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
for (p = 0; p < ext.num_ptn; p++) {
|
2006-01-29 15:55:16 +03:00
|
|
|
if (ext.ptn[p].mbr_bootsel_magic != LE_MBR_BS_MAGIC)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_bootsel.mbrbs_nametab[p][0] == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
needed |= MBR_BS_EXTLBA | MBR_BS_ACTIVE;
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (B_flag)
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
needed |= MBR_BS_ACTIVE;
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/* Is the installed code good enough ? */
|
2004-03-22 10:11:00 +03:00
|
|
|
if (!i_flag && (needed == 0 ||
|
2006-01-29 15:55:16 +03:00
|
|
|
(mboot.mbr_bootsel_magic == LE_MBR_BS_MAGIC
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
&& (mbs->mbrbs_flags & needed) == needed))) {
|
2003-04-30 23:47:10 +04:00
|
|
|
/* yes - just set flags */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
mbs->mbrbs_flags |= ext13;
|
2003-04-30 23:47:10 +04:00
|
|
|
return;
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/* ok - we need to replace the bootcode */
|
|
|
|
|
|
|
|
if (f_flag && !(i_flag || B_flag)) {
|
|
|
|
warnx("Installed bootfile doesn't support required options.");
|
|
|
|
return;
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
|
2004-05-09 00:52:59 +04:00
|
|
|
if (!f_flag && bootsize == 0 && !i_flag)
|
2003-04-30 23:47:10 +04:00
|
|
|
/* Output an explanation for the 'update bootcode' prompt. */
|
2004-03-22 10:11:00 +03:00
|
|
|
printf("\n%s\n",
|
|
|
|
"Installed bootfile doesn't support required options.");
|
1999-06-04 22:59:15 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/* Were we told a specific file ? (which we have already read) */
|
|
|
|
/* If so check that it supports what we need. */
|
|
|
|
if (bootsize != 0 && needed != 0
|
2006-01-29 15:55:16 +03:00
|
|
|
&& (bootcode[0].mbr_bootsel_magic != LE_MBR_BS_MAGIC
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
|| ((bootcode[0].mbr_bootsel.mbrbs_flags & needed) != needed))) {
|
2003-04-30 23:47:10 +04:00
|
|
|
/* No it doesn't... */
|
|
|
|
if (f_flag)
|
|
|
|
warnx("Bootfile %s doesn't support "
|
|
|
|
"required bootsel options", boot_path );
|
|
|
|
/* But install it anyway */
|
|
|
|
else
|
|
|
|
if (yesno("Bootfile %s doesn't support the required "
|
|
|
|
"options,\ninstall default bootfile instead?",
|
|
|
|
boot_path))
|
|
|
|
bootsize = 0;
|
|
|
|
}
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (bootsize == 0) {
|
|
|
|
/* Get name of bootfile that supports the required facilities */
|
|
|
|
code = DEFAULT_BOOTCODE;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (needed & MBR_BS_ACTIVE)
|
2003-04-30 23:47:10 +04:00
|
|
|
code = DEFAULT_BOOTSELCODE;
|
|
|
|
#ifdef DEFAULT_BOOTEXTCODE
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (needed & MBR_BS_EXTLBA)
|
2003-04-30 23:47:10 +04:00
|
|
|
code = DEFAULT_BOOTEXTCODE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bootsize = read_boot(code, bootcode, sizeof bootcode, 0);
|
|
|
|
if (bootsize == 0)
|
|
|
|
/* The old bootcode is better than no bootcode at all */
|
|
|
|
return;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if ((bootcode[0].mbr_bootsel.mbrbs_flags & needed) != needed)
|
2003-04-30 23:47:10 +04:00
|
|
|
warnx("Default bootfile %s doesn't support required "
|
|
|
|
"options. Got flags 0x%x, wanted 0x%x\n",
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
boot_path, bootcode[0].mbr_bootsel.mbrbs_flags,
|
2003-04-30 23:47:10 +04:00
|
|
|
needed);
|
1999-04-17 05:38:00 +04:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (!f_flag && !yesno("Update the bootcode from %s?", boot_path))
|
|
|
|
return;
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
init_sector0(0);
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2006-01-29 15:55:16 +03:00
|
|
|
if (mboot.mbr_bootsel_magic == LE_MBR_BS_MAGIC)
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
mbs->mbrbs_flags = bootcode[0].mbr_bootsel.mbrbs_flags | ext13;
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
1999-04-17 05:38:00 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t
|
|
|
|
configure_bootsel(daddr_t default_ptn)
|
|
|
|
{
|
|
|
|
struct mbr_bootsel *mbs = &mboot.mbr_bootsel;
|
|
|
|
int i, item, opt;
|
|
|
|
int tmo;
|
|
|
|
daddr_t *off;
|
|
|
|
int num_bios_disks;
|
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H
|
2003-04-30 23:47:10 +04:00
|
|
|
if (dl != NULL) {
|
|
|
|
num_bios_disks = dl->dl_nbiosdisks;
|
|
|
|
if (num_bios_disks > 8)
|
|
|
|
num_bios_disks = 8;
|
|
|
|
} else
|
2005-06-12 23:14:10 +04:00
|
|
|
#endif
|
2003-04-30 23:47:10 +04:00
|
|
|
num_bios_disks = 8;
|
|
|
|
|
|
|
|
printf("\nBoot selector configuration:\n");
|
|
|
|
|
|
|
|
/* The timeout value is in ticks, ~18.2 Hz. Avoid using floats.
|
|
|
|
* Ticks are nearly 64k/3600 - so our long timers are sligtly out!
|
|
|
|
* Newer bootcode always waits for 1 tick, so treats 0xffff
|
|
|
|
* as wait forever.
|
|
|
|
*/
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
tmo = le16toh(mbs->mbrbs_timeo);
|
2003-04-30 23:47:10 +04:00
|
|
|
tmo = tmo == 0xffff ? -1 : (10 * tmo + 9) / 182;
|
|
|
|
tmo = decimal("Timeout value (0 to 3600 seconds, -1 => never)",
|
|
|
|
tmo, 0, -1, 3600);
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
mbs->mbrbs_timeo = htole16(tmo == -1 ? 0xffff : (tmo * 182) / 10);
|
1999-04-17 05:38:00 +04:00
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
off = calloc(1 + MBR_PART_COUNT + ext.num_ptn + num_bios_disks, sizeof *off);
|
2003-04-30 23:47:10 +04:00
|
|
|
if (off == NULL)
|
|
|
|
err(1, "Malloc failed");
|
|
|
|
|
|
|
|
printf("Select the default boot option. Options are:\n\n");
|
|
|
|
item = 0;
|
|
|
|
opt = 0;
|
|
|
|
off[opt] = DEFAULT_ACTIVE;
|
|
|
|
printf("%d: The first active partition\n", opt);
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (i = 0; i < MBR_PART_COUNT; i++) {
|
|
|
|
if (mboot.mbr_parts[i].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mbs->mbrbs_nametab[i][0] == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
printf("%d: %s\n", ++opt, &mbs->mbrbs_nametab[i][0]);
|
2003-04-30 23:47:10 +04:00
|
|
|
off[opt] = le32toh(mboot.mbr_parts[i].mbrp_start);
|
|
|
|
if (off[opt] == default_ptn)
|
|
|
|
item = opt;
|
|
|
|
}
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mbs->mbrbs_flags & MBR_BS_EXTLBA) {
|
2003-04-30 23:47:10 +04:00
|
|
|
for (i = 0; i < ext.num_ptn; i++) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[i].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[i].mbr_bootsel.mbrbs_nametab[0][0] == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
printf("%d: %s\n",
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
++opt, ext.ptn[i].mbr_bootsel.mbrbs_nametab[0]);
|
2003-04-30 23:47:10 +04:00
|
|
|
off[opt] = ext_offset(i) +
|
|
|
|
le32toh(ext.ptn[i].mbr_parts[0].mbrp_start);
|
|
|
|
if (off[opt] == default_ptn)
|
|
|
|
item = opt;
|
1999-04-29 03:27:01 +04:00
|
|
|
}
|
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
for (i = 0; i < num_bios_disks; i++) {
|
|
|
|
printf("%d: Harddisk %d\n", ++opt, i);
|
|
|
|
off[opt] = i;
|
|
|
|
if (i == default_ptn)
|
|
|
|
item = opt;
|
|
|
|
}
|
1999-04-29 03:27:01 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
item = decimal("Default boot option", item, 0, 0, opt);
|
|
|
|
|
|
|
|
default_ptn = off[item];
|
|
|
|
free(off);
|
|
|
|
return default_ptn;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2004-03-24 05:49:37 +03:00
|
|
|
#endif /* BOOTSEL */
|
1999-04-17 05:38:00 +04:00
|
|
|
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1995-10-05 02:11:19 +03:00
|
|
|
/* Prerequisite: the disklabel parameters and master boot record must
|
|
|
|
* have been read (i.e. dos_* and mboot are meaningful).
|
|
|
|
* Specification: modifies dos_cylinders, dos_heads, dos_sectors, and
|
|
|
|
* dos_cylindersectors to be consistent with what the
|
|
|
|
* partition table is using, if we can find a geometry
|
|
|
|
* which is consistent with all partition table entries.
|
|
|
|
* We may get the number of cylinders slightly wrong (in
|
|
|
|
* the conservative direction). The idea is to be able
|
|
|
|
* to create a NetBSD partition on a disk we don't know
|
|
|
|
* the translated geometry of.
|
2003-04-30 23:47:10 +04:00
|
|
|
* This routine is only used for non-x86 systems or when we fail to
|
|
|
|
* get the BIOS geometry from the kernel.
|
|
|
|
*/
|
1995-10-05 02:11:19 +03:00
|
|
|
void
|
2000-12-19 18:44:27 +03:00
|
|
|
intuit_translated_geometry(void)
|
1995-10-05 02:11:19 +03:00
|
|
|
{
|
2000-12-19 19:01:28 +03:00
|
|
|
int xcylinders = -1, xheads = -1, xsectors = -1, i, j;
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned int c1, h1, s1, c2, h2, s2;
|
|
|
|
unsigned long a1, a2;
|
2003-04-30 23:47:10 +04:00
|
|
|
uint64_t num, denom;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The physical parameters may be invalid as bios geometry.
|
|
|
|
* If we cannot determine the actual bios geometry, we are
|
|
|
|
* better off picking a likely 'faked' geometry than leaving
|
|
|
|
* the invalid physical one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (dos_cylinders > MAXCYL || dos_heads > MAXHEAD ||
|
|
|
|
dos_sectors > MAXSECTOR) {
|
|
|
|
h1 = MAXHEAD - 1;
|
|
|
|
c1 = MAXCYL - 1;
|
2005-06-12 23:14:10 +04:00
|
|
|
#if (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H
|
2003-04-30 23:47:10 +04:00
|
|
|
if (dl != NULL) {
|
|
|
|
/* BIOS may use 256 heads or 1024 cylinders */
|
|
|
|
for (i = 0; i < dl->dl_nbiosdisks; i++) {
|
|
|
|
if (h1 < dl->dl_biosdisks[i].bi_head)
|
|
|
|
h1 = dl->dl_biosdisks[i].bi_head;
|
|
|
|
if (c1 < dl->dl_biosdisks[i].bi_cyl)
|
|
|
|
c1 = dl->dl_biosdisks[i].bi_cyl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
dos_sectors = MAXSECTOR;
|
|
|
|
dos_heads = h1;
|
|
|
|
dos_cylinders = disklabel.d_secperunit / (MAXSECTOR * h1);
|
|
|
|
if (dos_cylinders > c1)
|
|
|
|
dos_cylinders = c1;
|
|
|
|
}
|
1995-10-05 02:11:19 +03:00
|
|
|
|
|
|
|
/* Try to deduce the number of heads from two different mappings. */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (i = 0; i < MBR_PART_COUNT * 2 - 1; i++) {
|
1995-10-05 02:11:19 +03:00
|
|
|
if (get_mapping(i, &c1, &h1, &s1, &a1) < 0)
|
|
|
|
continue;
|
2004-09-12 11:46:24 +04:00
|
|
|
a1 -= s1;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (j = i + 1; j < MBR_PART_COUNT * 2; j++) {
|
1995-10-05 02:11:19 +03:00
|
|
|
if (get_mapping(j, &c2, &h2, &s2, &a2) < 0)
|
|
|
|
continue;
|
2003-04-30 23:47:10 +04:00
|
|
|
a2 -= s2;
|
|
|
|
num = (uint64_t)h1 * a2 - (uint64_t)h2 * a1;
|
|
|
|
denom = (uint64_t)c2 * a1 - (uint64_t)c1 * a2;
|
1995-10-05 02:11:19 +03:00
|
|
|
if (denom != 0 && num % denom == 0) {
|
2000-12-19 19:01:28 +03:00
|
|
|
xheads = num / denom;
|
2003-04-30 23:47:10 +04:00
|
|
|
xsectors = a1 / (c1 * xheads + h1);
|
1995-10-05 02:11:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-12-19 19:01:28 +03:00
|
|
|
if (xheads != -1)
|
1995-10-05 02:11:19 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-02 21:40:34 +04:00
|
|
|
if (xheads == -1) {
|
|
|
|
warnx("Cannot determine the number of heads");
|
|
|
|
return;
|
|
|
|
}
|
1995-10-05 02:11:19 +03:00
|
|
|
|
|
|
|
/* Estimate the number of cylinders. */
|
2000-12-19 19:01:28 +03:00
|
|
|
xcylinders = disklabel.d_secperunit / xheads / xsectors;
|
2003-07-14 13:32:12 +04:00
|
|
|
if (disklabel.d_secperunit > xcylinders * xheads * xsectors)
|
|
|
|
xcylinders++;
|
1995-10-05 02:11:19 +03:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/*
|
|
|
|
* Now verify consistency with each of the partition table entries.
|
1995-10-05 02:11:19 +03:00
|
|
|
* Be willing to shove cylinders up a little bit to make things work,
|
2003-04-30 23:47:10 +04:00
|
|
|
* but translation mismatches are fatal.
|
|
|
|
*/
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (i = 0; i < MBR_PART_COUNT * 2; i++) {
|
1995-10-05 02:11:19 +03:00
|
|
|
if (get_mapping(i, &c1, &h1, &s1, &a1) < 0)
|
|
|
|
continue;
|
2003-07-14 13:32:12 +04:00
|
|
|
if (c1 >= MAXCYL - 2)
|
|
|
|
continue;
|
2000-12-19 19:01:28 +03:00
|
|
|
if (xsectors * (c1 * xheads + h1) + s1 != a1)
|
1995-10-05 02:11:19 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
/* Everything checks out.
|
|
|
|
* Reset the geometry to use for further calculations.
|
2003-07-14 13:32:12 +04:00
|
|
|
* But cylinders cannot be > 1024.
|
2003-04-30 23:47:10 +04:00
|
|
|
*/
|
2003-07-14 13:32:12 +04:00
|
|
|
if (xcylinders > MAXCYL)
|
|
|
|
dos_cylinders = MAXCYL;
|
|
|
|
else
|
2003-04-30 23:47:10 +04:00
|
|
|
dos_cylinders = xcylinders;
|
2000-12-19 19:01:28 +03:00
|
|
|
dos_heads = xheads;
|
|
|
|
dos_sectors = xsectors;
|
1995-10-05 02:11:19 +03:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/*
|
|
|
|
* For the purposes of intuit_translated_geometry(), treat the partition
|
1995-10-05 02:11:19 +03:00
|
|
|
* table as a list of eight mapping between (cylinder, head, sector)
|
|
|
|
* triplets and absolute sectors. Get the relevant geometry triplet and
|
|
|
|
* absolute sectors for a given entry, or return -1 if it isn't present.
|
2003-04-30 23:47:10 +04:00
|
|
|
* Note: for simplicity, the returned sector is 0-based.
|
|
|
|
*/
|
1995-10-05 02:11:19 +03:00
|
|
|
int
|
2005-06-12 23:06:43 +04:00
|
|
|
get_mapping(int i, unsigned int *cylinder, unsigned int *head, unsigned int *sector,
|
2000-12-19 18:44:27 +03:00
|
|
|
unsigned long *absolute)
|
1995-10-05 02:11:19 +03:00
|
|
|
{
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_partition *part = &mboot.mbr_parts[i / 2];
|
1995-10-05 02:11:19 +03:00
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (part->mbrp_type == 0)
|
1995-10-05 02:11:19 +03:00
|
|
|
return -1;
|
|
|
|
if (i % 2 == 0) {
|
1999-01-28 00:41:31 +03:00
|
|
|
*cylinder = MBR_PCYL(part->mbrp_scyl, part->mbrp_ssect);
|
|
|
|
*head = part->mbrp_shd;
|
|
|
|
*sector = MBR_PSECT(part->mbrp_ssect) - 1;
|
2003-04-30 23:47:10 +04:00
|
|
|
*absolute = le32toh(part->mbrp_start);
|
1995-10-05 02:11:19 +03:00
|
|
|
} else {
|
1999-01-28 00:41:31 +03:00
|
|
|
*cylinder = MBR_PCYL(part->mbrp_ecyl, part->mbrp_esect);
|
|
|
|
*head = part->mbrp_ehd;
|
|
|
|
*sector = MBR_PSECT(part->mbrp_esect) - 1;
|
2003-04-30 23:47:10 +04:00
|
|
|
*absolute = le32toh(part->mbrp_start)
|
|
|
|
+ le32toh(part->mbrp_size) - 1;
|
1995-10-05 02:11:19 +03:00
|
|
|
}
|
2006-05-21 20:00:17 +04:00
|
|
|
/* Sanity check the data against all zeroes */
|
|
|
|
if ((*cylinder == 0) && (*sector == 0) && (*head == 0))
|
|
|
|
return -1;
|
2003-04-30 23:47:10 +04:00
|
|
|
/* Sanity check the data against max values */
|
|
|
|
if ((((*cylinder * MAXHEAD) + *head) * MAXSECTOR + *sector) < *absolute)
|
|
|
|
/* cannot be a CHS mapping */
|
|
|
|
return -1;
|
1995-10-05 02:11:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
static void
|
|
|
|
delete_ptn(int part)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
2003-04-30 23:47:10 +04:00
|
|
|
if (part == ext.ptn_id) {
|
|
|
|
/* forget all about the extended partition */
|
|
|
|
free(ext.ptn);
|
|
|
|
memset(&ext, 0, sizeof ext);
|
|
|
|
}
|
1993-04-09 23:23:56 +04:00
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
mboot.mbr_parts[part].mbrp_type = 0;
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
static void
|
|
|
|
delete_ext_ptn(int part)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (part == 0) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
ext.ptn[0].mbr_parts[0].mbrp_type = 0;
|
2003-04-30 23:47:10 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ext.ptn[part - 1].mbr_parts[1] = ext.ptn[part].mbr_parts[1];
|
|
|
|
memmove(&ext.ptn[part], &ext.ptn[part + 1],
|
|
|
|
(ext.num_ptn - part - 1) * sizeof ext.ptn[0]);
|
|
|
|
ext.num_ptn--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_ext_ptn(daddr_t start, daddr_t size)
|
|
|
|
{
|
|
|
|
int part;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_partition *partp;
|
|
|
|
struct mbr_sector *nptn;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
2003-09-19 12:35:15 +04:00
|
|
|
nptn = realloc(ext.ptn, (ext.num_ptn + 1) * sizeof *ext.ptn);
|
|
|
|
if (!nptn)
|
|
|
|
err(1, "realloc");
|
|
|
|
ext.ptn = nptn;
|
2003-04-30 23:47:10 +04:00
|
|
|
for (part = 0; part < ext.num_ptn; part++)
|
|
|
|
if (ext_offset(part) > start)
|
|
|
|
break;
|
|
|
|
/* insert before 'part' - make space... */
|
|
|
|
memmove(&ext.ptn[part + 1], &ext.ptn[part],
|
|
|
|
(ext.num_ptn - part) * sizeof ext.ptn[0]);
|
|
|
|
memset(&ext.ptn[part], 0, sizeof ext.ptn[0]);
|
2006-01-29 15:55:16 +03:00
|
|
|
ext.ptn[part].mbr_magic = LE_MBR_MAGIC;
|
2003-04-30 23:47:10 +04:00
|
|
|
/* we will be 'part' */
|
|
|
|
if (part == 0) {
|
|
|
|
/* link us to 'next' */
|
|
|
|
partp = &ext.ptn[0].mbr_parts[1];
|
|
|
|
/* offset will be fixed by caller */
|
|
|
|
partp->mbrp_size = htole32(
|
|
|
|
le32toh(ext.ptn[1].mbr_parts[0].mbrp_start) +
|
|
|
|
le32toh(ext.ptn[1].mbr_parts[0].mbrp_size));
|
|
|
|
} else {
|
|
|
|
/* link us to prev's next */
|
|
|
|
partp = &ext.ptn[part - 1].mbr_parts[1];
|
|
|
|
ext.ptn[part].mbr_parts[1] = *partp;
|
|
|
|
/* and prev onto us */
|
|
|
|
partp->mbrp_start = htole32(start - dos_sectors - ext.base);
|
|
|
|
partp->mbrp_size = htole32(size + dos_sectors);
|
|
|
|
}
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
partp->mbrp_type = 5; /* as used by win98 */
|
2003-04-30 23:47:10 +04:00
|
|
|
partp->mbrp_flag = 0;
|
|
|
|
/* wallop in some CHS values - win98 doesn't saturate them */
|
|
|
|
dos(le32toh(partp->mbrp_start),
|
|
|
|
&partp->mbrp_scyl, &partp->mbrp_shd, &partp->mbrp_ssect);
|
|
|
|
dos(le32toh(partp->mbrp_start) + le32toh(partp->mbrp_size) - 1,
|
|
|
|
&partp->mbrp_ecyl, &partp->mbrp_ehd, &partp->mbrp_esect);
|
|
|
|
ext.num_ptn++;
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
check_overlap(int part, int sysid, daddr_t start, daddr_t size, int fix)
|
|
|
|
{
|
|
|
|
int p;
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned int p_s, p_e;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
if (sysid != 0) {
|
|
|
|
if (start < dos_sectors)
|
|
|
|
return "Track zero is reserved for the BIOS";
|
2004-05-11 00:32:07 +04:00
|
|
|
if (start + size > disksectors)
|
2003-04-30 23:47:10 +04:00
|
|
|
return "Partition exceeds size of disk";
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (p = 0; p < MBR_PART_COUNT; p++) {
|
|
|
|
if (p == part || mboot.mbr_parts[p].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
p_s = le32toh(mboot.mbr_parts[p].mbrp_start);
|
|
|
|
p_e = p_s + le32toh(mboot.mbr_parts[p].mbrp_size);
|
|
|
|
if (start + size <= p_s || start >= p_e)
|
|
|
|
continue;
|
|
|
|
if (f_flag) {
|
|
|
|
if (fix)
|
|
|
|
delete_ptn(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return "Overlaps another partition";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Are we trying to create an extended partition */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (!MBR_IS_EXTENDED(mboot.mbr_parts[part].mbrp_type)) {
|
2003-04-30 23:47:10 +04:00
|
|
|
/* this wasn't the extended partition */
|
|
|
|
if (!MBR_IS_EXTENDED(sysid))
|
|
|
|
return 0;
|
|
|
|
/* making an extended partition */
|
|
|
|
if (ext.base != 0) {
|
|
|
|
if (!f_flag)
|
|
|
|
return "There cannot be 2 extended partitions";
|
|
|
|
if (fix)
|
|
|
|
delete_ptn(ext.ptn_id);
|
|
|
|
}
|
|
|
|
if (fix) {
|
|
|
|
/* allocate a new extended partition */
|
|
|
|
ext.ptn = calloc(1, sizeof ext.ptn[0]);
|
|
|
|
if (ext.ptn == NULL)
|
|
|
|
err(1, "Malloc failed");
|
2006-01-29 15:55:16 +03:00
|
|
|
ext.ptn[0].mbr_magic = LE_MBR_MAGIC;
|
2003-04-30 23:47:10 +04:00
|
|
|
ext.ptn_id = part;
|
|
|
|
ext.base = start;
|
|
|
|
ext.limit = start + size;
|
|
|
|
ext.num_ptn = 1;
|
1998-10-02 21:23:22 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check we haven't cut space allocated to an extended ptn */
|
|
|
|
|
|
|
|
if (!MBR_IS_EXTENDED(sysid)) {
|
|
|
|
/* no longer an extended partition */
|
|
|
|
if (fix) {
|
|
|
|
/* Kill all memory of the extended partitions */
|
|
|
|
delete_ptn(part);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ext.num_ptn == 0 ||
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
(ext.num_ptn == 1 && ext.ptn[0].mbr_parts[0].mbrp_type == 0))
|
2003-04-30 23:47:10 +04:00
|
|
|
/* nothing in extended partition */
|
|
|
|
return 0;
|
1997-08-12 03:31:41 +04:00
|
|
|
if (f_flag)
|
2003-04-30 23:47:10 +04:00
|
|
|
return 0;
|
|
|
|
if (yesno("Do you really want to delete all the extended partitions?"))
|
|
|
|
return 0;
|
|
|
|
return "Extended partition busy";
|
1997-08-12 03:31:41 +04:00
|
|
|
}
|
1994-09-23 08:30:13 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (le32toh(mboot.mbr_parts[part].mbrp_start) != ext.base)
|
|
|
|
/* maybe impossible, but an extra sanity check */
|
|
|
|
return 0;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
for (p = ext.num_ptn; --p >= 0;) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
p_s = ext_offset(p);
|
|
|
|
p_e = p_s + le32toh(ext.ptn[p].mbr_parts[0].mbrp_start)
|
|
|
|
+ le32toh(ext.ptn[p].mbr_parts[0].mbrp_size);
|
|
|
|
if (p_s >= start && p_e <= start + size)
|
|
|
|
continue;
|
|
|
|
if (!f_flag)
|
|
|
|
return "Extended partition outside main partition";
|
|
|
|
if (fix)
|
|
|
|
delete_ext_ptn(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fix && start != ext.base) {
|
|
|
|
/* The internal offsets need to be fixed up */
|
|
|
|
for (p = 0; p < ext.num_ptn - 1; p++)
|
|
|
|
ext.ptn[p].mbr_parts[1].mbrp_start = htole32(
|
|
|
|
le32toh(ext.ptn[p].mbr_parts[1].mbrp_start)
|
|
|
|
+ ext.base - start);
|
|
|
|
/* and maybe an empty partition at the start */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[0].mbr_parts[0].mbrp_type == 0) {
|
2003-04-30 23:47:10 +04:00
|
|
|
if (le32toh(ext.ptn[0].mbr_parts[1].mbrp_start) == 0) {
|
|
|
|
/* don't need the empty slot */
|
|
|
|
memmove(&ext.ptn[0], &ext.ptn[1],
|
|
|
|
(ext.num_ptn - 1) * sizeof ext.ptn[0]);
|
|
|
|
ext.num_ptn--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* must create an empty slot */
|
|
|
|
add_ext_ptn(start, dos_sectors);
|
|
|
|
ext.ptn[0].mbr_parts[1].mbrp_start = htole32(ext.base
|
|
|
|
- start);
|
1994-09-23 09:30:09 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
|
|
|
if (fix) {
|
|
|
|
ext.base = start;
|
|
|
|
ext.limit = start + size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
static const char *
|
|
|
|
check_ext_overlap(int part, int sysid, daddr_t start, daddr_t size, int fix)
|
|
|
|
{
|
|
|
|
int p;
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned int p_s, p_e;
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
if (sysid == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (MBR_IS_EXTENDED(sysid))
|
|
|
|
return "Nested extended partitions are not allowed";
|
|
|
|
|
|
|
|
/* allow one track at start for extended partition header */
|
|
|
|
start -= dos_sectors;
|
|
|
|
size += dos_sectors;
|
|
|
|
if (start < ext.base || start + size > ext.limit)
|
|
|
|
return "Outside bounds of extended partition";
|
|
|
|
|
|
|
|
if (f_flag && !fix)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (p = ext.num_ptn; --p >= 0;) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (p == part || ext.ptn[p].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
p_s = ext_offset(p);
|
|
|
|
p_e = p_s + le32toh(ext.ptn[p].mbr_parts[0].mbrp_start)
|
|
|
|
+ le32toh(ext.ptn[p].mbr_parts[0].mbrp_size);
|
|
|
|
if (p == 0)
|
|
|
|
p_s += le32toh(ext.ptn[p].mbr_parts[0].mbrp_start)
|
|
|
|
- dos_sectors;
|
|
|
|
if (start < p_e && start + size > p_s) {
|
|
|
|
if (!f_flag)
|
|
|
|
return "Overlaps another extended partition";
|
|
|
|
if (fix) {
|
|
|
|
if (part == -1)
|
|
|
|
delete_ext_ptn(p);
|
|
|
|
else
|
|
|
|
/* must not change numbering yet */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
ext.ptn[p].mbr_parts[0].mbrp_type = 0;
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
1994-09-23 09:30:09 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
int
|
|
|
|
change_part(int extended, int part, int sysid, daddr_t start, daddr_t size,
|
|
|
|
char *bootmenu)
|
|
|
|
{
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_partition *partp;
|
|
|
|
struct mbr_sector *boot;
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t offset;
|
2005-06-27 05:00:04 +04:00
|
|
|
const char *e;
|
2003-04-30 23:47:10 +04:00
|
|
|
int upart = part;
|
|
|
|
int p;
|
|
|
|
int fl;
|
|
|
|
daddr_t n_s, n_e;
|
|
|
|
const char *errtext;
|
|
|
|
#ifdef BOOTSEL
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
char tmp_bootmenu[MBR_PART_COUNT * (MBR_BS_PARTNAMESIZE + 1)];
|
|
|
|
int bootmenu_len = (extended ? MBR_PART_COUNT : 1) * (MBR_BS_PARTNAMESIZE + 1);
|
1998-09-28 19:44:18 +04:00
|
|
|
#endif
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
if (extended) {
|
|
|
|
if (part != -1 && part < ext.num_ptn) {
|
|
|
|
boot = &ext.ptn[part];
|
|
|
|
partp = &boot->mbr_parts[0];
|
|
|
|
offset = ext_offset(part);
|
1993-04-09 23:23:56 +04:00
|
|
|
} else {
|
2003-04-30 23:47:10 +04:00
|
|
|
part = -1;
|
|
|
|
boot = 0;
|
|
|
|
partp = 0;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
upart = 0;
|
|
|
|
e = "E";
|
|
|
|
} else {
|
|
|
|
boot = &mboot;
|
|
|
|
partp = &boot->mbr_parts[part];
|
|
|
|
offset = 0;
|
|
|
|
e = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!f_flag && part != -1) {
|
|
|
|
printf("The data for partition %s%d is:\n", e, part);
|
|
|
|
print_part(boot, upart, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
if (bootmenu != NULL)
|
|
|
|
strlcpy(tmp_bootmenu, bootmenu, bootmenu_len);
|
|
|
|
else
|
2006-01-29 15:55:16 +03:00
|
|
|
if (boot != NULL && boot->mbr_bootsel_magic == LE_MBR_BS_MAGIC)
|
2003-04-30 23:47:10 +04:00
|
|
|
strlcpy(tmp_bootmenu,
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
boot->mbr_bootsel.mbrbs_nametab[upart],
|
2003-04-30 23:47:10 +04:00
|
|
|
bootmenu_len);
|
|
|
|
else
|
|
|
|
tmp_bootmenu[0] = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!s_flag && partp != NULL) {
|
|
|
|
/* values not specified, default to current ones */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
sysid = partp->mbrp_type;
|
2003-04-30 23:47:10 +04:00
|
|
|
start = offset + le32toh(partp->mbrp_start);
|
|
|
|
size = le32toh(partp->mbrp_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* creating a new partition, default to free space */
|
|
|
|
if (!s_flag && sysid == 0 && extended) {
|
|
|
|
/* non-extended partition */
|
|
|
|
start = ext.base;
|
|
|
|
for (p = 0; p < ext.num_ptn; p++) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
n_s = ext_offset(p);
|
|
|
|
if (n_s > start + dos_sectors)
|
|
|
|
break;
|
|
|
|
start = ext_offset(p)
|
|
|
|
+ le32toh(ext.ptn[p].mbr_parts[0].mbrp_start)
|
|
|
|
+ le32toh(ext.ptn[p].mbr_parts[0].mbrp_size);
|
|
|
|
}
|
|
|
|
if (ext.limit - start <= dos_sectors) {
|
|
|
|
printf("No space in extended partition\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
start += dos_sectors;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s_flag && sysid == 0 && !extended) {
|
|
|
|
/* same for non-extended partition */
|
|
|
|
/* first see if old start is free */
|
|
|
|
if (start < dos_sectors)
|
|
|
|
start = 0;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (p = 0; start != 0 && p < MBR_PART_COUNT; p++) {
|
|
|
|
if (mboot.mbr_parts[p].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
n_s = le32toh(mboot.mbr_parts[p].mbrp_start);
|
|
|
|
if (start >= n_s &&
|
|
|
|
start < n_s + le32toh(mboot.mbr_parts[p].mbrp_size))
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
if (start == 0) {
|
|
|
|
/* Look for first gap */
|
|
|
|
start = dos_sectors;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (p = 0; p < MBR_PART_COUNT; p++) {
|
|
|
|
if (mboot.mbr_parts[p].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
n_s = le32toh(mboot.mbr_parts[p].mbrp_start);
|
|
|
|
n_e = n_s + le32toh(mboot.mbr_parts[p].mbrp_size);
|
|
|
|
if (start >= n_s && start < n_e) {
|
|
|
|
start = n_e;
|
|
|
|
p = -1;
|
|
|
|
}
|
|
|
|
}
|
2004-05-11 00:32:07 +04:00
|
|
|
if (start >= disksectors) {
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("No free space\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-28 19:44:18 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (!f_flag) {
|
|
|
|
/* request new values from user */
|
|
|
|
if (sysid == 0)
|
|
|
|
sysid = 169;
|
|
|
|
sysid = decimal("sysid", sysid, 0, 0, 255);
|
|
|
|
if (sysid == 0 && !v_flag) {
|
|
|
|
start = 0;
|
|
|
|
size = 0;
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
tmp_bootmenu[0] = 0;
|
1998-09-28 19:44:18 +04:00
|
|
|
#endif
|
2003-04-30 23:47:10 +04:00
|
|
|
} else {
|
|
|
|
daddr_t old = start;
|
2004-05-11 00:32:07 +04:00
|
|
|
daddr_t lim = extended ? ext.limit : disksectors;
|
2003-04-30 23:47:10 +04:00
|
|
|
start = decimal("start", start,
|
|
|
|
DEC_SEC | DEC_RND_0 | (extended ? DEC_RND : 0),
|
|
|
|
extended ? ext.base : 0, lim);
|
|
|
|
/* Adjust 'size' so that end doesn't move when 'start'
|
|
|
|
* is only changed slightly.
|
|
|
|
*/
|
|
|
|
if (size > start - old)
|
|
|
|
size -= start - old;
|
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
/* Find end of available space from this start point */
|
|
|
|
if (extended) {
|
|
|
|
for (p = 0; p < ext.num_ptn; p++) {
|
|
|
|
if (p == part)
|
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
n_s = ext_offset(p);
|
|
|
|
if (n_s > start && n_s < lim)
|
|
|
|
lim = n_s;
|
|
|
|
if (start >= n_s && start < n_s
|
|
|
|
+ le32toh(ext.ptn[p].mbr_parts[0].mbrp_start)
|
|
|
|
+ le32toh(ext.ptn[p].mbr_parts[0].mbrp_size)) {
|
|
|
|
lim = start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (p = 0; p < MBR_PART_COUNT; p++) {
|
2003-04-30 23:47:10 +04:00
|
|
|
if (p == part)
|
|
|
|
continue;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (mboot.mbr_parts[p].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
continue;
|
|
|
|
n_s = le32toh(mboot.mbr_parts[p].mbrp_start);
|
|
|
|
if (n_s > start && n_s < lim)
|
|
|
|
lim = n_s;
|
|
|
|
if (start >= n_s && start < n_s
|
|
|
|
+ le32toh(mboot.mbr_parts[p].mbrp_size)) {
|
|
|
|
lim = start;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lim -= start;
|
|
|
|
if (lim == 0) {
|
|
|
|
printf("Start sector already allocated\n");
|
|
|
|
return 0;
|
1998-10-02 21:23:22 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
if (size == 0 || size > lim)
|
|
|
|
size = lim;
|
|
|
|
fl = DEC_SEC;
|
|
|
|
if (start % dos_cylindersectors == dos_sectors)
|
|
|
|
fl |= DEC_RND_DOWN;
|
|
|
|
if (start == 2 * dos_sectors)
|
|
|
|
fl |= DEC_RND_DOWN | DEC_RND_DOWN_2;
|
|
|
|
size = decimal("size", size, fl, 0, lim);
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
#ifndef DEFAULT_BOOTEXTCODE
|
|
|
|
if (!extended)
|
|
|
|
#endif
|
|
|
|
string("bootmenu", bootmenu_len, tmp_bootmenu);
|
|
|
|
#endif
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before we write these away, we must verify that nothing
|
|
|
|
* untoward has been requested.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (extended)
|
|
|
|
errtext = check_ext_overlap(part, sysid, start, size, 0);
|
|
|
|
else
|
|
|
|
errtext = check_overlap(part, sysid, start, size, 0);
|
|
|
|
if (errtext != NULL) {
|
|
|
|
if (f_flag)
|
|
|
|
errx(2, "%s\n", errtext);
|
|
|
|
printf("%s\n", errtext);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before proceeding, delete any overlapped partitions.
|
|
|
|
* This can only happen if '-f' was supplied on the command line.
|
|
|
|
* Just hope the caller knows what they are doing.
|
|
|
|
* This also fixes the base of each extended partition if the
|
|
|
|
* partition itself has moved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (extended)
|
|
|
|
errtext = check_ext_overlap(part, sysid, start, size, 1);
|
|
|
|
else
|
|
|
|
errtext = check_overlap(part, sysid, start, size, 1);
|
|
|
|
|
|
|
|
if (errtext)
|
|
|
|
errx(1, "%s\n", errtext);
|
|
|
|
|
|
|
|
if (sysid == 0) {
|
|
|
|
/* delete this partition - save info though */
|
|
|
|
if (partp == NULL)
|
|
|
|
/* must have been trying to create an extended ptn */
|
|
|
|
return 0;
|
|
|
|
if (start == 0 && size == 0)
|
|
|
|
memset(partp, 0, sizeof *partp);
|
|
|
|
#ifdef BOOTSEL
|
2006-01-29 15:55:16 +03:00
|
|
|
if (boot->mbr_bootsel_magic == LE_MBR_BS_MAGIC)
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
memset(boot->mbr_bootsel.mbrbs_nametab[upart], 0,
|
|
|
|
sizeof boot->mbr_bootsel.mbrbs_nametab[0]);
|
2003-04-30 23:47:10 +04:00
|
|
|
#endif
|
|
|
|
if (extended)
|
|
|
|
delete_ext_ptn(part);
|
|
|
|
else
|
|
|
|
delete_ptn(part);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (extended) {
|
|
|
|
if (part != -1)
|
|
|
|
delete_ext_ptn(part);
|
|
|
|
if (start == ext.base + dos_sectors)
|
|
|
|
/* First one must have been free */
|
|
|
|
part = 0;
|
|
|
|
else
|
|
|
|
part = add_ext_ptn(start, size);
|
|
|
|
|
|
|
|
/* These must be re-calculated because of the realloc */
|
|
|
|
boot = &ext.ptn[part];
|
|
|
|
partp = &boot->mbr_parts[0];
|
|
|
|
offset = ext_offset(part);
|
|
|
|
}
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
partp->mbrp_type = sysid;
|
2003-04-30 23:47:10 +04:00
|
|
|
partp->mbrp_start = htole32( start - offset);
|
|
|
|
partp->mbrp_size = htole32( size);
|
|
|
|
dos(start, &partp->mbrp_scyl, &partp->mbrp_shd, &partp->mbrp_ssect);
|
|
|
|
dos(start + size - 1,
|
|
|
|
&partp->mbrp_ecyl, &partp->mbrp_ehd, &partp->mbrp_esect);
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
if (extended) {
|
2006-01-29 15:55:16 +03:00
|
|
|
boot->mbr_bootsel_magic = LE_MBR_BS_MAGIC;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
strncpy(boot->mbr_bootsel.mbrbs_nametab[upart], tmp_bootmenu,
|
2003-04-30 23:47:10 +04:00
|
|
|
bootmenu_len);
|
|
|
|
} else {
|
|
|
|
/* We need to bootselect code installed in order to have
|
|
|
|
* somewhere to safely write the menu tag.
|
|
|
|
*/
|
2006-01-29 15:55:16 +03:00
|
|
|
if (boot->mbr_bootsel_magic != LE_MBR_BS_MAGIC) {
|
2007-04-26 22:51:00 +04:00
|
|
|
if (f_flag ||
|
|
|
|
yesno("The bootselect code is not installed, "
|
|
|
|
"do you want to install it now?"))
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
install_bootsel(MBR_BS_ACTIVE);
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
2006-01-29 15:55:16 +03:00
|
|
|
if (boot->mbr_bootsel_magic == LE_MBR_BS_MAGIC) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
strncpy(boot->mbr_bootsel.mbrbs_nametab[upart],
|
2003-04-30 23:47:10 +04:00
|
|
|
tmp_bootmenu, bootmenu_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (v_flag && !f_flag && yesno("Explicitly specify beg/end address?")) {
|
|
|
|
/* this really isn't a good idea.... */
|
|
|
|
int tsector, tcylinder, thead;
|
|
|
|
|
|
|
|
tcylinder = MBR_PCYL(partp->mbrp_scyl, partp->mbrp_ssect);
|
|
|
|
thead = partp->mbrp_shd;
|
|
|
|
tsector = MBR_PSECT(partp->mbrp_ssect);
|
|
|
|
tcylinder = decimal("beginning cylinder",
|
|
|
|
tcylinder, 0, 0, dos_cylinders - 1);
|
|
|
|
thead = decimal("beginning head",
|
|
|
|
thead, 0, 0, dos_heads - 1);
|
|
|
|
tsector = decimal("beginning sector",
|
|
|
|
tsector, 0, 1, dos_sectors);
|
|
|
|
partp->mbrp_scyl = DOSCYL(tcylinder);
|
|
|
|
partp->mbrp_shd = thead;
|
|
|
|
partp->mbrp_ssect = DOSSECT(tsector, tcylinder);
|
|
|
|
|
|
|
|
tcylinder = MBR_PCYL(partp->mbrp_ecyl, partp->mbrp_esect);
|
|
|
|
thead = partp->mbrp_ehd;
|
|
|
|
tsector = MBR_PSECT(partp->mbrp_esect);
|
|
|
|
tcylinder = decimal("ending cylinder",
|
|
|
|
tcylinder, 0, 0, dos_cylinders - 1);
|
|
|
|
thead = decimal("ending head",
|
|
|
|
thead, 0, 0, dos_heads - 1);
|
|
|
|
tsector = decimal("ending sector",
|
|
|
|
tsector, 0, 1, dos_sectors);
|
|
|
|
partp->mbrp_ecyl = DOSCYL(tcylinder);
|
|
|
|
partp->mbrp_ehd = thead;
|
|
|
|
partp->mbrp_esect = DOSSECT(tsector, tcylinder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we had to mark an extended partition as deleted because
|
|
|
|
* another request would have overlapped it, now is the time
|
|
|
|
* to do the actual delete.
|
|
|
|
*/
|
|
|
|
if (extended && f_flag) {
|
|
|
|
for (p = ext.num_ptn; --p >= 0;)
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (ext.ptn[p].mbr_parts[0].mbrp_type == 0)
|
2003-04-30 23:47:10 +04:00
|
|
|
delete_ext_ptn(p);
|
|
|
|
}
|
|
|
|
return 1;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
void
|
2000-12-19 18:44:27 +03:00
|
|
|
print_params(void)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1994-09-23 08:30:13 +04:00
|
|
|
|
1997-08-12 03:31:41 +04:00
|
|
|
if (sh_flag) {
|
2003-11-22 00:47:42 +03:00
|
|
|
printf("DISK=%s\n", disk);
|
2003-08-29 20:31:30 +04:00
|
|
|
printf("DLCYL=%d\nDLHEAD=%d\nDLSEC=%d\nDLSIZE=%"PRIdaddr"\n",
|
|
|
|
cylinders, heads, sectors, disksectors);
|
|
|
|
printf("BCYL=%d\nBHEAD=%d\nBSEC=%d\nBDLSIZE=%"PRIdaddr"\n",
|
|
|
|
dos_cylinders, dos_heads, dos_sectors, dos_disksectors);
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("NUMEXTPTN=%d\n", ext.num_ptn);
|
1997-07-29 12:31:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-08-12 03:31:41 +04:00
|
|
|
/* Not sh_flag */
|
2001-11-07 17:50:32 +03:00
|
|
|
printf("Disk: %s\n", disk);
|
1999-04-17 05:38:00 +04:00
|
|
|
printf("NetBSD disklabel disk geometry:\n");
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("cylinders: %d, heads: %d, sectors/track: %d "
|
2003-08-29 20:31:30 +04:00
|
|
|
"(%d sectors/cylinder)\ntotal sectors: %"PRIdaddr"\n\n",
|
|
|
|
cylinders, heads, sectors, cylindersectors, disksectors);
|
1999-04-17 05:38:00 +04:00
|
|
|
printf("BIOS disk geometry:\n");
|
2003-04-30 23:47:10 +04:00
|
|
|
printf("cylinders: %d, heads: %d, sectors/track: %d "
|
2003-08-29 20:31:30 +04:00
|
|
|
"(%d sectors/cylinder)\ntotal sectors: %"PRIdaddr"\n\n",
|
2003-04-30 23:47:10 +04:00
|
|
|
dos_cylinders, dos_heads, dos_sectors, dos_cylindersectors,
|
2003-08-29 20:31:30 +04:00
|
|
|
dos_disksectors);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
void
|
2000-12-19 18:44:27 +03:00
|
|
|
change_active(int which)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
struct mbr_partition *partp;
|
1994-09-23 08:30:13 +04:00
|
|
|
int part;
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
int active = MBR_PART_COUNT;
|
1994-09-23 08:30:13 +04:00
|
|
|
|
2003-04-30 14:29:51 +04:00
|
|
|
partp = &mboot.mbr_parts[0];
|
1993-04-09 23:23:56 +04:00
|
|
|
|
|
|
|
if (a_flag && which != -1)
|
|
|
|
active = which;
|
1994-09-23 08:30:13 +04:00
|
|
|
else {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (part = 0; part < MBR_PART_COUNT; part++)
|
|
|
|
if (partp[part].mbrp_flag & MBR_PFLAG_ACTIVE)
|
1994-09-23 08:30:13 +04:00
|
|
|
active = part;
|
|
|
|
}
|
1997-08-12 03:31:41 +04:00
|
|
|
if (!f_flag) {
|
|
|
|
if (yesno("Do you want to change the active partition?")) {
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
printf ("Choosing %d will make no partition active.\n",
|
|
|
|
MBR_PART_COUNT);
|
1997-08-12 03:31:41 +04:00
|
|
|
do {
|
2003-04-30 23:47:10 +04:00
|
|
|
active = decimal("active partition",
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
active, 0, 0, MBR_PART_COUNT);
|
1997-08-12 03:31:41 +04:00
|
|
|
} while (!yesno("Are you happy with this choice?"));
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
} else
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (active != MBR_PART_COUNT)
|
1997-08-12 03:31:41 +04:00
|
|
|
printf ("Making partition %d active.\n", active);
|
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
for (part = 0; part < MBR_PART_COUNT; part++)
|
|
|
|
partp[part].mbrp_flag &= ~MBR_PFLAG_ACTIVE;
|
|
|
|
if (active < MBR_PART_COUNT)
|
|
|
|
partp[active].mbrp_flag |= MBR_PFLAG_ACTIVE;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
void
|
2000-12-19 18:44:27 +03:00
|
|
|
get_params_to_use(void)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
2003-05-01 13:23:30 +04:00
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
2003-04-30 23:47:10 +04:00
|
|
|
struct biosdisk_info *bip;
|
|
|
|
int i;
|
2003-05-01 13:23:30 +04:00
|
|
|
#endif
|
2000-12-19 18:44:27 +03:00
|
|
|
|
1997-09-06 01:26:57 +04:00
|
|
|
if (b_flag) {
|
|
|
|
dos_cylinders = b_cyl;
|
|
|
|
dos_heads = b_head;
|
|
|
|
dos_sectors = b_sec;
|
|
|
|
return;
|
|
|
|
}
|
1994-09-23 08:30:13 +04:00
|
|
|
|
1993-04-09 23:23:56 +04:00
|
|
|
print_params();
|
2003-04-30 23:47:10 +04:00
|
|
|
if (!yesno("Do you want to change our idea of what BIOS thinks?"))
|
|
|
|
return;
|
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H
|
2003-04-30 23:47:10 +04:00
|
|
|
if (dl != NULL) {
|
|
|
|
for (i = 0; i < dl->dl_nbiosdisks; i++) {
|
|
|
|
if (i == 0)
|
|
|
|
printf("\nGeometries of known disks:\n");
|
|
|
|
bip = &dl->dl_biosdisks[i];
|
|
|
|
printf("Disk %d: cylinders %u, heads %u, sectors %u"
|
2003-08-29 20:31:30 +04:00
|
|
|
" (%"PRIdaddr" sectors, %dMB)\n",
|
2003-04-30 23:47:10 +04:00
|
|
|
i, bip->bi_cyl, bip->bi_head, bip->bi_sec,
|
2003-08-29 20:31:30 +04:00
|
|
|
bip->bi_lbasecs, SEC_TO_MB(bip->bi_lbasecs));
|
2003-04-30 23:47:10 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
printf("\n");
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
#endif
|
|
|
|
do {
|
|
|
|
dos_cylinders = decimal("BIOS's idea of #cylinders",
|
|
|
|
dos_cylinders, 0, 0, MAXCYL);
|
|
|
|
dos_heads = decimal("BIOS's idea of #heads",
|
|
|
|
dos_heads, 0, 0, MAXHEAD);
|
|
|
|
dos_sectors = decimal("BIOS's idea of #sectors",
|
|
|
|
dos_sectors, 0, 1, MAXSECTOR);
|
|
|
|
print_params();
|
|
|
|
} while (!yesno("Are you happy with this choice?"));
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
|
1993-04-09 23:23:56 +04:00
|
|
|
/***********************************************\
|
|
|
|
* Change real numbers into strange dos numbers *
|
|
|
|
\***********************************************/
|
1994-09-23 08:30:13 +04:00
|
|
|
void
|
2000-12-19 18:44:27 +03:00
|
|
|
dos(int sector, unsigned char *cylinderp, unsigned char *headp,
|
|
|
|
unsigned char *sectorp)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1994-09-23 09:30:09 +04:00
|
|
|
int cylinder, head;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-09-23 09:30:09 +04:00
|
|
|
cylinder = sector / dos_cylindersectors;
|
|
|
|
sector -= cylinder * dos_cylindersectors;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-09-23 09:30:09 +04:00
|
|
|
head = sector / dos_sectors;
|
|
|
|
sector -= head * dos_sectors;
|
2003-08-10 14:20:08 +04:00
|
|
|
if (cylinder > 1023)
|
|
|
|
cylinder = 1023;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-09-23 09:30:09 +04:00
|
|
|
*cylinderp = DOSCYL(cylinder);
|
|
|
|
*headp = head;
|
|
|
|
*sectorp = DOSSECT(sector + 1, cylinder);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
2000-12-19 19:01:28 +03:00
|
|
|
open_disk(int update)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1997-09-14 17:52:26 +04:00
|
|
|
static char namebuf[MAXPATHLEN + 1];
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2005-06-12 23:14:10 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
strlcpy(namebuf, disk_file, sizeof(namebuf));
|
|
|
|
if ((fd = open(disk_file, update ? O_RDWR : O_RDONLY, 0)) == -1) {
|
|
|
|
warn("%s", disk_file);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
2003-04-30 23:47:10 +04:00
|
|
|
fd = opendisk(disk, update && disk_file == NULL ? O_RDWR : O_RDONLY,
|
|
|
|
namebuf, sizeof(namebuf), 0);
|
1997-09-14 17:52:26 +04:00
|
|
|
if (fd < 0) {
|
2001-11-01 10:04:18 +03:00
|
|
|
if (errno == ENODEV)
|
|
|
|
warnx("%s is not a character device", namebuf);
|
|
|
|
else
|
|
|
|
warn("%s", namebuf);
|
1994-09-23 08:30:13 +04:00
|
|
|
return (-1);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2005-06-12 23:14:10 +04:00
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
1997-09-14 17:52:26 +04:00
|
|
|
disk = namebuf;
|
1994-09-23 08:30:13 +04:00
|
|
|
if (get_params() == -1) {
|
|
|
|
close(fd);
|
2003-04-30 23:47:10 +04:00
|
|
|
fd = -1;
|
1994-09-23 08:30:13 +04:00
|
|
|
return (-1);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
if (disk_file != NULL) {
|
|
|
|
/* for testing: read/write data from a disk file */
|
|
|
|
wfd = open(disk_file, update ? O_RDWR|O_CREAT : O_RDONLY, 0777);
|
|
|
|
if (wfd == -1) {
|
|
|
|
warn("%s", disk_file);
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
wfd = fd;
|
1994-09-23 08:30:13 +04:00
|
|
|
return (0);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
2003-04-30 23:47:10 +04:00
|
|
|
read_disk(daddr_t sector, void *buf)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1994-09-23 08:30:13 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (*rfd == -1)
|
2000-12-19 19:01:28 +03:00
|
|
|
errx(1, "read_disk(); fd == -1");
|
2003-04-30 23:47:10 +04:00
|
|
|
if (lseek(*rfd, sector * (off_t)512, 0) == -1)
|
1994-09-23 08:30:13 +04:00
|
|
|
return (-1);
|
2003-04-30 23:47:10 +04:00
|
|
|
return (read(*rfd, buf, 512));
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
2003-04-30 23:47:10 +04:00
|
|
|
write_disk(daddr_t sector, void *buf)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1994-09-23 08:30:13 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
if (wfd == -1)
|
|
|
|
errx(1, "write_disk(); wfd == -1");
|
|
|
|
if (lseek(wfd, sector * (off_t)512, 0) == -1)
|
1994-09-23 08:30:13 +04:00
|
|
|
return (-1);
|
2003-04-30 23:47:10 +04:00
|
|
|
return (write(wfd, buf, 512));
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
2004-03-19 21:19:17 +03:00
|
|
|
static void
|
|
|
|
guess_geometry(daddr_t _sectors)
|
|
|
|
{
|
|
|
|
dos_sectors = MAXSECTOR;
|
|
|
|
dos_heads = MAXHEAD - 1; /* some BIOS might use 256 */
|
|
|
|
dos_cylinders = _sectors / (MAXSECTOR * (MAXHEAD - 1));
|
|
|
|
if (dos_cylinders < 1)
|
|
|
|
dos_cylinders = 1;
|
|
|
|
else if (dos_cylinders > MAXCYL - 1)
|
|
|
|
dos_cylinders = MAXCYL - 1;
|
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
2000-12-19 18:44:27 +03:00
|
|
|
get_params(void)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
2004-03-19 21:19:17 +03:00
|
|
|
if (disk_type != NULL) {
|
|
|
|
struct disklabel *tmplabel;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2004-03-19 21:19:17 +03:00
|
|
|
if ((tmplabel = getdiskbyname(disk_type)) == NULL) {
|
|
|
|
warn("bad disktype");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
disklabel = *tmplabel;
|
|
|
|
} else if (F_flag) {
|
|
|
|
struct stat st;
|
|
|
|
if (fstat(fd, &st) == -1) {
|
|
|
|
warn("fstat");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (st.st_size % 512 != 0) {
|
|
|
|
warnx("%s size (%lld) is not divisible "
|
|
|
|
"by sector size (%d)", disk, (long long)st.st_size,
|
|
|
|
512);
|
|
|
|
}
|
|
|
|
disklabel.d_secperunit = st.st_size / 512;
|
|
|
|
guess_geometry(disklabel.d_secperunit);
|
|
|
|
disklabel.d_ncylinders = dos_cylinders;
|
|
|
|
disklabel.d_ntracks = dos_heads;
|
|
|
|
disklabel.d_nsectors = dos_sectors;
|
2005-06-12 23:14:10 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
} else {
|
|
|
|
warnx("no disklabel specified");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
2004-03-19 21:19:17 +03:00
|
|
|
} else if (ioctl(fd, DIOCGDEFLABEL, &disklabel) == -1) {
|
2000-07-06 21:22:43 +04:00
|
|
|
warn("DIOCGDEFLABEL");
|
|
|
|
if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
|
|
|
|
warn("DIOCGDINFO");
|
|
|
|
return (-1);
|
|
|
|
}
|
1994-09-23 08:30:13 +04:00
|
|
|
}
|
2005-06-12 23:14:10 +04:00
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
2004-03-19 21:19:17 +03:00
|
|
|
disksectors = disklabel.d_secperunit;
|
2003-04-30 23:47:10 +04:00
|
|
|
cylinders = disklabel.d_ncylinders;
|
|
|
|
heads = disklabel.d_ntracks;
|
|
|
|
sectors = disklabel.d_nsectors;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
/* pick up some defaults for the BIOS sizes */
|
|
|
|
if (sectors <= MAXSECTOR) {
|
|
|
|
dos_cylinders = cylinders;
|
|
|
|
dos_heads = heads;
|
|
|
|
dos_sectors = sectors;
|
|
|
|
} else {
|
|
|
|
/* guess - has to better than the above */
|
2004-03-19 21:19:17 +03:00
|
|
|
guess_geometry(disksectors);
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
|
|
|
dos_disksectors = disksectors;
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
return (0);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
2004-09-12 11:46:24 +04:00
|
|
|
#ifdef BOOTSEL
|
|
|
|
/*
|
|
|
|
* Rather unfortunately the bootsel 'magic' number is at the end of the
|
|
|
|
* the structure, and there is no checksum. So when other operating
|
|
|
|
* systems install mbr code by only writing the length of their code they
|
|
|
|
* can overwrite part of the structure but keeping the magic number intact.
|
|
|
|
* This code attempts to empirically detect this problem.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
validate_bootsel(struct mbr_bootsel *mbs)
|
|
|
|
{
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned int key = mbs->mbrbs_defkey;
|
|
|
|
unsigned int tmo;
|
2004-09-12 11:46:24 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (v_flag)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check default key is sane
|
|
|
|
* - this is the most likely field to be stuffed
|
|
|
|
* 12 disks and 12 bootable partitions seems enough!
|
|
|
|
* (the keymap decode starts falling apart at that point)
|
|
|
|
*/
|
|
|
|
if (key != 0 && !(key == SCAN_ENTER
|
|
|
|
|| (key >= SCAN_1 && key < SCAN_1 + 12)
|
|
|
|
|| (key >= SCAN_F1 && key < SCAN_F1 + 12)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Checking the flags will lead to breakage... */
|
|
|
|
|
|
|
|
/* Timeout value is expecyed to be a multiple of a second */
|
|
|
|
tmo = htole16(mbs->mbrbs_timeo);
|
|
|
|
if (tmo != 0 && tmo != 0xffff && tmo != (10 * tmo + 9) / 182 * 182 / 10)
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
/* Check the menu strings are printable */
|
|
|
|
/* Unfortunately they aren't zero filled... */
|
|
|
|
for (i = 0; i < sizeof(mbs->mbrbs_nametab); i++) {
|
|
|
|
int c = (uint8_t)mbs->mbrbs_nametab[0][i];
|
|
|
|
if (c == 0 || isprint(c))
|
|
|
|
continue;
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
read_s0(daddr_t offset, struct mbr_sector *boot)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
2004-03-22 10:11:00 +03:00
|
|
|
const char *tabletype = offset ? "extended" : "primary";
|
2004-09-12 11:46:24 +04:00
|
|
|
#ifdef BOOTSEL
|
|
|
|
static int reported;
|
|
|
|
#endif
|
1994-09-23 08:30:13 +04:00
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (read_disk(offset, boot) == -1) {
|
2004-03-22 10:11:00 +03:00
|
|
|
warn("Can't read %s partition table", tabletype);
|
2003-04-30 23:47:10 +04:00
|
|
|
return -1;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2006-01-29 15:55:16 +03:00
|
|
|
if (boot->mbr_magic != LE_MBR_MAGIC) {
|
2004-05-19 11:36:14 +04:00
|
|
|
warnx("%s partition table invalid, "
|
|
|
|
"no magic in sector %"PRIdaddr, tabletype, offset);
|
2003-04-30 23:47:10 +04:00
|
|
|
return -1;
|
2004-09-12 11:46:24 +04:00
|
|
|
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2004-03-24 05:49:37 +03:00
|
|
|
#ifdef BOOTSEL
|
2006-01-29 15:55:16 +03:00
|
|
|
if (boot->mbr_bootsel_magic == LE_MBR_BS_MAGIC) {
|
2004-09-12 11:46:24 +04:00
|
|
|
/* mbr_bootsel in new location */
|
|
|
|
if (validate_bootsel(&boot->mbr_bootsel)) {
|
|
|
|
warnx("removing corrupt bootsel information");
|
|
|
|
boot->mbr_bootsel_magic = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-01-29 15:55:16 +03:00
|
|
|
if (boot->mbr_bootsel_magic != LE_MBR_MAGIC)
|
2004-09-12 11:46:24 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* mbr_bootsel in old location */
|
|
|
|
if (!reported)
|
2004-03-22 10:11:00 +03:00
|
|
|
warnx("%s partition table: using old-style bootsel information",
|
|
|
|
tabletype);
|
2004-09-12 11:46:24 +04:00
|
|
|
reported = 1;
|
|
|
|
if (validate_bootsel((void *)((uint8_t *)boot + MBR_BS_OFFSET + 4))) {
|
|
|
|
warnx("%s bootsel information corrupt - ignoring", tabletype);
|
|
|
|
return 0;
|
2004-03-22 10:11:00 +03:00
|
|
|
}
|
2005-06-12 23:06:43 +04:00
|
|
|
memmove((uint8_t *)boot + MBR_BS_OFFSET,
|
|
|
|
(uint8_t *)boot + MBR_BS_OFFSET + 4,
|
2004-09-12 11:46:24 +04:00
|
|
|
sizeof(struct mbr_bootsel));
|
|
|
|
if ( ! (boot->mbr_bootsel.mbrbs_flags & MBR_BS_NEWMBR)) {
|
|
|
|
/* old style default key */
|
|
|
|
int id;
|
|
|
|
/* F1..F4 => ptn 0..3, F5+ => disk 0+ */
|
|
|
|
id = boot->mbr_bootsel.mbrbs_defkey;
|
|
|
|
id -= SCAN_F1;
|
|
|
|
if (id >= MBR_PART_COUNT)
|
|
|
|
id -= MBR_PART_COUNT; /* Use number of disk */
|
|
|
|
else if (mboot.mbr_parts[id].mbrp_type != 0)
|
|
|
|
id = le32toh(boot->mbr_parts[id].mbrp_start);
|
|
|
|
else
|
|
|
|
id = DEFAULT_ACTIVE;
|
|
|
|
boot->mbr_bootsel.mbrbs_defkey = id;
|
|
|
|
}
|
2006-01-29 15:55:16 +03:00
|
|
|
boot->mbr_bootsel_magic = LE_MBR_BS_MAGIC;
|
2004-09-12 11:46:24 +04:00
|
|
|
/* highlight that new bootsel code is necessary */
|
|
|
|
boot->mbr_bootsel.mbrbs_flags &= ~MBR_BS_NEWMBR;
|
2004-03-24 05:49:37 +03:00
|
|
|
#endif /* BOOTSEL */
|
2004-09-12 11:46:24 +04:00
|
|
|
return 0;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
2003-04-30 23:47:10 +04:00
|
|
|
write_mbr(void)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1998-10-15 19:23:23 +04:00
|
|
|
int flag, i;
|
2003-04-30 23:47:10 +04:00
|
|
|
daddr_t offset;
|
|
|
|
int rval = -1;
|
1994-09-23 08:30:13 +04:00
|
|
|
|
1993-04-09 23:23:56 +04:00
|
|
|
/*
|
|
|
|
* write enable label sector before write (if necessary),
|
|
|
|
* disable after writing.
|
|
|
|
* needed if the disklabel protected area also protects
|
|
|
|
* sector 0. (e.g. empty disk)
|
|
|
|
*/
|
|
|
|
flag = 1;
|
2005-06-12 23:14:10 +04:00
|
|
|
#if !HAVE_NBTOOL_CONFIG_H
|
2004-03-19 21:19:17 +03:00
|
|
|
if (wfd == fd && F_flag == 0 && ioctl(wfd, DIOCWLABEL, &flag) < 0)
|
1994-09-23 08:30:13 +04:00
|
|
|
warn("DIOCWLABEL");
|
2005-06-12 23:14:10 +04:00
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (write_disk(0, &mboot) == -1) {
|
2003-04-30 23:47:10 +04:00
|
|
|
warn("Can't write fdisk partition table");
|
|
|
|
goto protect_label;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
if (boot_installed)
|
|
|
|
for (i = bootsize; (i -= 0x200) > 0;)
|
|
|
|
if (write_disk(i / 0x200, &bootcode[i / 0x200]) == -1) {
|
|
|
|
warn("Can't write bootcode");
|
|
|
|
goto protect_label;
|
|
|
|
}
|
|
|
|
for (offset = 0, i = 0; i < ext.num_ptn; i++) {
|
|
|
|
if (write_disk(ext.base + offset, ext.ptn + i) == -1) {
|
|
|
|
warn("Can't write %dth extended partition", i);
|
|
|
|
goto protect_label;
|
1998-10-15 19:23:23 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
offset = le32toh(ext.ptn[i].mbr_parts[1].mbrp_start);
|
|
|
|
}
|
|
|
|
rval = 0;
|
|
|
|
protect_label:
|
2005-06-12 23:14:10 +04:00
|
|
|
#if !HAVE_NBTOOL_CONFIG_H
|
1994-09-23 08:30:13 +04:00
|
|
|
flag = 0;
|
2004-03-19 21:19:17 +03:00
|
|
|
if (wfd == fd && F_flag == 0 && ioctl(wfd, DIOCWLABEL, &flag) < 0)
|
1994-09-23 08:30:13 +04:00
|
|
|
warn("DIOCWLABEL");
|
2005-06-12 23:14:10 +04:00
|
|
|
#endif /* HAVE_NBTOOL_CONFIG_H */
|
2003-04-30 23:47:10 +04:00
|
|
|
return rval;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
2003-04-30 23:47:10 +04:00
|
|
|
yesno(const char *str, ...)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1994-09-23 08:30:13 +04:00
|
|
|
int ch, first;
|
2003-04-30 23:47:10 +04:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, str);
|
1994-09-23 08:30:13 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
vprintf(str, ap);
|
|
|
|
printf(" [n] ");
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
first = ch = getchar();
|
|
|
|
while (ch != '\n' && ch != EOF)
|
|
|
|
ch = getchar();
|
2002-06-05 16:19:23 +04:00
|
|
|
if (ch == EOF)
|
|
|
|
errx(1, "EOF");
|
1994-09-23 08:30:13 +04:00
|
|
|
return (first == 'y' || first == 'Y');
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
int
|
|
|
|
decimal(const char *prompt, int dflt, int flags, int minval, int maxval)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
1994-12-05 23:15:31 +03:00
|
|
|
int acc = 0;
|
1994-09-23 08:30:13 +04:00
|
|
|
char *cp;
|
2005-04-08 00:23:13 +04:00
|
|
|
char ch;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
for (;;) {
|
|
|
|
if (flags & DEC_SEC) {
|
|
|
|
printf("%s: [%d..%dcyl default: %d, %dcyl, %uMB] ",
|
|
|
|
prompt, SEC_TO_CYL(minval), SEC_TO_CYL(maxval),
|
|
|
|
dflt, SEC_TO_CYL(dflt), SEC_TO_MB(dflt));
|
|
|
|
} else
|
|
|
|
printf("%s: [%d..%d default: %d] ",
|
|
|
|
prompt, minval, maxval, dflt);
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2002-06-05 16:19:23 +04:00
|
|
|
if (!fgets(lbuf, LBUF, stdin))
|
|
|
|
errx(1, "EOF");
|
1994-10-20 03:06:17 +03:00
|
|
|
lbuf[strlen(lbuf)-1] = '\0';
|
|
|
|
cp = lbuf;
|
|
|
|
|
|
|
|
cp += strspn(cp, " \t");
|
|
|
|
if (*cp == '\0')
|
2003-04-30 23:47:10 +04:00
|
|
|
return dflt;
|
|
|
|
|
|
|
|
if (cp[0] == '$' && cp[1] == 0)
|
|
|
|
return maxval;
|
|
|
|
|
2004-10-28 23:48:41 +04:00
|
|
|
if (isdigit((unsigned char)*cp) || *cp == '-') {
|
2003-04-30 23:47:10 +04:00
|
|
|
acc = strtol(lbuf, &cp, 10);
|
|
|
|
if (flags & DEC_SEC) {
|
2005-04-08 00:23:13 +04:00
|
|
|
ch = *cp;
|
|
|
|
if (ch == 'g' || ch == 'G') {
|
|
|
|
acc *= 1024;
|
|
|
|
ch = 'm';
|
|
|
|
}
|
|
|
|
if (ch == 'm' || ch == 'M') {
|
2003-04-30 23:47:10 +04:00
|
|
|
acc *= SEC_IN_1M;
|
|
|
|
/* round to whole number of cylinders */
|
|
|
|
acc += dos_cylindersectors / 2;
|
|
|
|
acc /= dos_cylindersectors;
|
2005-04-08 00:23:13 +04:00
|
|
|
ch = 'c';
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
2005-04-08 00:23:13 +04:00
|
|
|
if (ch == 'c' || ch == 'C') {
|
|
|
|
cp++;
|
2003-04-30 23:47:10 +04:00
|
|
|
acc *= dos_cylindersectors;
|
|
|
|
/* adjustments for cylinder boundary */
|
|
|
|
if (acc == 0 && flags & DEC_RND_0)
|
|
|
|
acc += dos_sectors;
|
|
|
|
if (flags & DEC_RND)
|
|
|
|
acc += dos_sectors;
|
|
|
|
if (flags & DEC_RND_DOWN)
|
|
|
|
acc -= dos_sectors;
|
|
|
|
if (flags & DEC_RND_DOWN_2)
|
|
|
|
acc -= dos_sectors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1993-04-09 23:23:56 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
cp += strspn(cp, " \t");
|
|
|
|
if (*cp != '\0') {
|
|
|
|
printf("%s is not a valid %s number.\n", lbuf,
|
|
|
|
flags & DEC_SEC ? "sector" : "decimal");
|
1994-09-23 09:30:09 +04:00
|
|
|
continue;
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (acc >= minval && acc <= maxval)
|
|
|
|
return acc;
|
|
|
|
printf("%d is not between %d and %d.\n", acc, minval, maxval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ptn_id(const char *prompt, int *extended)
|
|
|
|
{
|
2005-06-12 23:06:43 +04:00
|
|
|
unsigned int acc = 0;
|
2003-04-30 23:47:10 +04:00
|
|
|
char *cp;
|
|
|
|
|
|
|
|
for (;; printf("%s is not a valid partition number.\n", lbuf)) {
|
|
|
|
printf("%s: [none] ", prompt);
|
|
|
|
|
|
|
|
if (!fgets(lbuf, LBUF, stdin))
|
|
|
|
errx(1, "EOF");
|
|
|
|
lbuf[strlen(lbuf)-1] = '\0';
|
|
|
|
cp = lbuf;
|
|
|
|
|
|
|
|
cp += strspn(cp, " \t");
|
|
|
|
*extended = 0;
|
|
|
|
if (*cp == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (*cp == 'E' || *cp == 'e') {
|
|
|
|
cp++;
|
|
|
|
*extended = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
acc = strtoul(cp, &cp, 10);
|
1994-10-20 03:06:17 +03:00
|
|
|
|
1994-09-23 09:30:09 +04:00
|
|
|
cp += strspn(cp, " \t");
|
|
|
|
if (*cp != '\0')
|
|
|
|
continue;
|
1993-04-09 23:23:56 +04:00
|
|
|
|
Overhaul MBR handling (part 1):
<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.
As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.
<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).
amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.
* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).
* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.
* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.
* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.
* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.
installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)
mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.
Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
2003-10-08 08:25:43 +04:00
|
|
|
if (*extended || acc < MBR_PART_COUNT)
|
2003-04-30 23:47:10 +04:00
|
|
|
return acc;
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BOOTSEL
|
|
|
|
void
|
|
|
|
string(const char *prompt, int length, char *buf)
|
|
|
|
{
|
|
|
|
int len;
|
1994-09-23 09:30:09 +04:00
|
|
|
|
2003-04-30 23:47:10 +04:00
|
|
|
for (;;) {
|
|
|
|
printf("%s: [%.*s] ", prompt, length, buf);
|
|
|
|
|
|
|
|
if (!fgets(lbuf, LBUF, stdin))
|
|
|
|
errx(1, "EOF");
|
|
|
|
len = strlen(lbuf);
|
|
|
|
if (len <= 1)
|
|
|
|
/* unchanged if just <enter> */
|
|
|
|
return;
|
|
|
|
/* now strip trailing spaces, <space><enter> deletes string */
|
|
|
|
do
|
|
|
|
lbuf[--len] = 0;
|
|
|
|
while (len != 0 && lbuf[len - 1] == ' ');
|
|
|
|
if (len < length)
|
|
|
|
break;
|
2004-03-22 10:11:00 +03:00
|
|
|
printf("'%s' is longer than %d characters.\n",
|
|
|
|
lbuf, length - 1);
|
2003-04-30 23:47:10 +04:00
|
|
|
}
|
|
|
|
strncpy(buf, lbuf, length);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|
2003-04-30 23:47:10 +04:00
|
|
|
#endif
|
1993-04-09 23:23:56 +04:00
|
|
|
|
1994-09-23 08:30:13 +04:00
|
|
|
int
|
2000-12-19 18:44:27 +03:00
|
|
|
type_match(const void *key, const void *item)
|
1993-04-09 23:23:56 +04:00
|
|
|
{
|
2004-11-12 19:57:46 +03:00
|
|
|
const int *idp = key;
|
|
|
|
const struct mbr_ptype *ptr = item;
|
1994-09-23 08:30:13 +04:00
|
|
|
|
2004-11-12 19:57:46 +03:00
|
|
|
if (*idp < ptr->id)
|
1994-09-23 08:30:13 +04:00
|
|
|
return (-1);
|
2004-11-12 19:57:46 +03:00
|
|
|
if (*idp > ptr->id)
|
1994-09-23 08:30:13 +04:00
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-12-19 18:44:27 +03:00
|
|
|
const char *
|
|
|
|
get_type(int type)
|
1994-09-23 08:30:13 +04:00
|
|
|
{
|
2004-11-12 19:57:46 +03:00
|
|
|
struct mbr_ptype *ptr;
|
1994-09-23 08:30:13 +04:00
|
|
|
|
2004-11-12 19:57:46 +03:00
|
|
|
ptr = bsearch(&type, mbr_ptypes, KNOWN_SYSIDS,
|
2004-11-16 00:59:23 +03:00
|
|
|
sizeof(mbr_ptypes[0]), type_match);
|
1994-09-23 08:30:13 +04:00
|
|
|
if (ptr == 0)
|
|
|
|
return ("unknown");
|
1997-09-06 01:26:57 +04:00
|
|
|
return (ptr->name);
|
1993-04-09 23:23:56 +04:00
|
|
|
}
|