xref: /netbsd-src/usr.sbin/sysinst/mbr.h (revision 957b5cd6f458f76fceef8141be7caf06a21678b1)
1 /*	$NetBSD: mbr.h,v 1.6 2020/10/12 16:14:32 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 #define MBR_DEV_LEN	16		/* for wedge names */
58 
59 typedef struct mbr_info_t mbr_info_t;
60 struct mbr_info_t {
61 	struct mbr_sector	mbr;
62 #ifdef BOOTSEL
63 	struct mbr_bootsel	mbrb;	/* writeable for any mbr code */
64 	uint		oflags;
65 #endif
66 	uint		sector;		/* where we read this from */
67 	mbr_info_t	*extended;	/* next in extended partition list */
68 	const char	*last_mounted[MBR_PART_COUNT];
69 	uint		fs_type[MBR_PART_COUNT], fs_sub_type[MBR_PART_COUNT];
70 #ifdef BOOTSEL
71 	/* only in first item... */
72 	uint		bootsec;	/* start sector of bootmenu default */
73 #endif
74 	/* for temporary access */
75 	char		wedge[MBR_PART_COUNT][MBR_DEV_LEN];
76 };
77 
78 #ifdef BOOTSEL
79 extern struct mbr_bootsel *mbs;
80 
81 	/* sync with src/sbin/fdisk/fdisk.c */
82 #define	DEFAULT_BOOTDIR		"/usr/mdec"
83 #define	DEFAULT_BOOTCODE	"mbr"
84 #define	DEFAULT_BOOTSELCODE	"mbr_bootsel"
85 #define	DEFAULT_BOOTEXTCODE	"mbr_ext"
86 
87 /* Scan values for the various keys we use, as returned by the BIOS */
88 #define	SCAN_ENTER	0x1c
89 #define	SCAN_F1		0x3b
90 #define	SCAN_1		0x2
91 
92 #endif /* BOOTSEL */
93 
94 /* from mbr.c */
95 void	set_fdisk_geom(void);	/* edit incore BIOS geometry */
96 void	disp_cur_geom(void);
97 int	check_geom(void);		/* primitive geometry sanity-check */
98 
99 void	disp_cur_part(struct mbr_partition *, int, int);
100 int 	partsoverlap(struct mbr_partition *, int, int);
101 
102 /* from mbr.c */
103 
104 int	guess_biosgeom_from_parts(struct disk_partitions*, int *, int *, int *);
105 /* same return values as edit_outer_parts() */
106 int	set_bios_geom_with_mbr_guess(struct disk_partitions*);
107 void	set_bios_geom(struct disk_partitions *, int *cyl, int *head, int *sec);
108 int	otherpart(int);
109 int	ourpart(int);
110 void	edit_ptn_bounds(void);
111 #ifdef BOOTSEL
112 void	disp_bootsel(void);
113 void	edit_bootsel_entry(int);
114 void	edit_bootsel_timeout(void);
115 void	edit_bootsel_default_ptn(int);
116 void	edit_bootsel_default_disk(int);
117 void	configure_bootsel(void);
118 #endif
119 
120 /*
121  * MBR specific: check if the chosen partitioning will work
122  * and perform any MD queries/fixup.
123  * With quiet = true, try to avoid user interaction and
124  * never return 1.
125  *
126  * Return value:
127  *  0 -> abort
128  *  1 -> re-edit
129  *  2 -> continue installation
130 */
131 int	md_check_mbr(struct disk_partitions*, mbr_info_t*, bool quiet);
132 
133 /*
134  * Called early during updates (before md_pre_update),
135  * returns true if partitions have been modified.
136  */
137 bool	md_mbr_update_check(struct disk_partitions*, mbr_info_t*);
138 
139 #endif
140