xref: /netbsd-src/usr.sbin/sysinst/mbr.h (revision 2d8e86c2f207da6fbbd50f11b6f33765ebdfa0e9)
1 /*	$NetBSD: mbr.h,v 1.3 2019/06/19 17:32:31 martin Exp $	*/
2 
3 /*
4  * Copyright 1997, 1988 Piermont Information Systems Inc.
5  * All rights reserved.
6  *
7  * Written by Philip A. Nelson for Piermont Information Systems Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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. The name of Piermont Information Systems Inc. may not be used to endorse
18  *    or promote products derived from this software without specific prior
19  *    written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 #ifndef _MBR_H
36 #define _MBR_H
37 
38 /*
39  * mbr.h -- definitions for reading, writing and editing DOS MBRs.
40  * Use by including from md.h on ports  which use MBRs (i386, powerpc, arc)
41  * naming convention:  dlxxxx => NetBSD disklabel, bxxxx => bios
42  */
43 
44 /* constants and defines */
45 
46 #include <sys/bootblock.h>
47 
48 /*
49  * XXX  I (dsl) haven't the foggiest idea what the MBR extended chain
50  *	looks like if the sector size isn't 512.
51  */
52 #define MBR_SECSIZE     512
53 
54 #define MBR_PUT_LSCYL(c)		((c) & 0xff)
55 #define MBR_PUT_MSCYLANDSEC(c,s)	(((s) & 0x3f) | (((c) >> 2) & 0xc0))
56 
57 typedef struct mbr_info_t mbr_info_t;
58 struct mbr_info_t {
59 	struct mbr_sector	mbr;
60 #ifdef BOOTSEL
61 	struct mbr_bootsel	mbrb;	/* writeable for any mbr code */
62 	uint		oflags;
63 #endif
64 	uint		sector;		/* where we read this from */
65 	mbr_info_t	*extended;	/* next in extended partition list */
66 	const char	*last_mounted[MBR_PART_COUNT];
67 	uint		fs_type[MBR_PART_COUNT], fs_sub_type[MBR_PART_COUNT];
68 #ifdef BOOTSEL
69 	/* only in first item... */
70 	uint		bootsec;	/* start sector of bootmenu default */
71 #endif
72 };
73 
74 #ifdef BOOTSEL
75 struct mbr_bootsel *mbs;
76 
77 	/* sync with src/sbin/fdisk/fdisk.c */
78 #define	DEFAULT_BOOTDIR		"/usr/mdec"
79 #define	DEFAULT_BOOTCODE	"mbr"
80 #define	DEFAULT_BOOTSELCODE	"mbr_bootsel"
81 #define	DEFAULT_BOOTEXTCODE	"mbr_ext"
82 
83 /* Scan values for the various keys we use, as returned by the BIOS */
84 #define	SCAN_ENTER	0x1c
85 #define	SCAN_F1		0x3b
86 #define	SCAN_1		0x2
87 
88 #endif /* BOOTSEL */
89 
90 /* from mbr.c */
91 void	set_fdisk_geom(void);	/* edit incore BIOS geometry */
92 void	disp_cur_geom(void);
93 int	check_geom(void);		/* primitive geometry sanity-check */
94 
95 void	disp_cur_part(struct mbr_partition *, int, int);
96 int 	partsoverlap(struct mbr_partition *, int, int);
97 
98 /* from mbr.c */
99 
100 int	guess_biosgeom_from_parts(struct disk_partitions*, int *, int *, int *);
101 bool	set_bios_geom_with_mbr_guess(struct disk_partitions*);
102 void	set_bios_geom(struct disk_partitions *, int *cyl, int *head, int *sec);
103 int	otherpart(int);
104 int	ourpart(int);
105 void	edit_ptn_bounds(void);
106 #ifdef BOOTSEL
107 void	disp_bootsel(void);
108 void	edit_bootsel_entry(int);
109 void	edit_bootsel_timeout(void);
110 void	edit_bootsel_default_ptn(int);
111 void	edit_bootsel_default_disk(int);
112 void	configure_bootsel(void);
113 #endif
114 
115 /*
116  * MBR specific: check if the chosen partitioning will work
117  * and perform any MD queries/fixup.
118  * With quiet = true, try to avoid user interaction and
119  * never return 1.
120  *
121  * Return value:
122  *  0 -> abort
123  *  1 -> re-edit
124  *  2 -> continue installation
125 */
126 int	md_check_mbr(struct disk_partitions*, mbr_info_t*, bool quiet);
127 
128 /*
129  * Called early during updates (before md_pre_update),
130  * returns true if partitions have been modified.
131  */
132 bool	md_mbr_update_check(struct disk_partitions*, mbr_info_t*);
133 
134 #endif
135