1 /* $NetBSD: mbr.h,v 1.23 2009/05/14 16:23:38 sborrill Exp $ */
4 * Copyright 1997, 1988 Piermont Information Systems Inc.
7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Piermont Information Systems Inc.
21 * 4. The name of Piermont Information Systems Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE.
43 * mbr.h -- definitions for reading, writing and editing DOS MBRs.
44 * Use by including from md.h on ports which use MBRs (i386, powerpc, arc)
45 * naming convention: dlxxxx => NetBSD disklabel, bxxxx => bios
48 /* constants and defines */
50 #include <sys/bootblock.h>
53 * XXX I (dsl) haven't the foggiest idea what the MBR extended chain
54 * looks like if the sector size isn't 512.
56 #define MBR_SECSIZE 512
58 #define MBR_PUT_LSCYL(c) ((c) & 0xff)
59 #define MBR_PUT_MSCYLANDSEC(c,s) (((s) & 0x3f) | (((c) >> 2) & 0xc0))
61 typedef struct mbr_info_t mbr_info_t
;
63 struct mbr_sector mbr
;
65 struct mbr_bootsel mbrb
; /* writeable for any mbr code */
68 uint sector
; /* where we read this from */
69 mbr_info_t
*extended
; /* next in extended partition list */
70 mbr_info_t
*prev_ext
; /* and back ptr */
71 const char *last_mounted
[MBR_PART_COUNT
];
72 /* only in first item... */
73 int opt
; /* entry being edited */
74 uint install
; /* start sector of install partition */
76 uint bootsec
; /* start sector of bootmenu default */
80 /* incore fdisk (mbr, bios) geometry */
81 int bcyl
, bhead
, bsec
;
86 struct mbr_bootsel
*mbs
;
88 /* sync with src/sbin/fdisk/fdisk.c */
89 #define DEFAULT_BOOTDIR "/usr/mdec"
90 #define DEFAULT_BOOTCODE "mbr"
91 #define DEFAULT_BOOTSELCODE "mbr_bootsel"
92 #define DEFAULT_BOOTEXTCODE "mbr_ext"
94 /* Scan values for the various keys we use, as returned by the BIOS */
95 #define SCAN_ENTER 0x1c
102 void set_fdisk_geom(void); /* edit incore BIOS geometry */
103 void disp_cur_geom(void);
104 int check_geom(void); /* primitive geometry sanity-check */
106 void disp_cur_part(struct mbr_partition
*, int, int);
107 int edit_mbr(mbr_info_t
*);
108 int mbr_use_wholedisk(mbr_info_t
*);
109 int partsoverlap(struct mbr_partition
*, int, int);
113 int read_mbr(const char *, mbr_info_t
*);
114 int write_mbr(const char *, mbr_info_t
*, int);
115 int valid_mbr(struct mbr_sector
*);
116 int guess_biosgeom_from_mbr(mbr_info_t
*, int *, int *, daddr_t
*);
117 int set_bios_geom_with_mbr_guess(void);
118 void set_bios_geom(int, int, int);
121 const char *get_partname(int);
122 void edit_ptn_bounds(void);
124 void disp_bootsel(void);
125 void edit_bootsel_entry(int);
126 void edit_bootsel_timeout(void);
127 void edit_bootsel_default_ptn(int);
128 void edit_bootsel_default_disk(int);
129 void configure_bootsel(void);
132 /* Machine dependant mbr functions */
133 int md_mbr_use_wholedisk(mbr_info_t
*mbri
);
134 int md_check_mbr(mbr_info_t
*mbri
);