1/*	$NetBSD: mbr.h,v 1.26 2011/06/30 20:09:15 wiz 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
57typedef struct mbr_info_t mbr_info_t;
58struct 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	mbr_info_t	*prev_ext;	/* and back ptr */
67	const char	*last_mounted[MBR_PART_COUNT];
68	/* only in first item... */
69	int		opt;		/* entry being edited */
70	uint		install;	/* start sector of install partition */
71#ifdef BOOTSEL
72	uint		bootsec;	/* start sector of bootmenu default */
73#endif
74};
75
76/* incore fdisk (mbr, bios) geometry */
77int bcyl, bhead, bsec;
78
79mbr_info_t mbr;
80
81#ifdef BOOTSEL
82struct mbr_bootsel *mbs;
83
84	/* sync with src/sbin/fdisk/fdisk.c */
85#define	DEFAULT_BOOTDIR		"/usr/mdec"
86#define	DEFAULT_BOOTCODE	"mbr"
87#define	DEFAULT_BOOTSELCODE	"mbr_bootsel"
88#define	DEFAULT_BOOTEXTCODE	"mbr_ext"
89
90/* Scan values for the various keys we use, as returned by the BIOS */
91#define	SCAN_ENTER	0x1c
92#define	SCAN_F1		0x3b
93#define	SCAN_1		0x2
94
95#endif /* BOOTSEL */
96
97/* from mbr.c */
98void	set_fdisk_geom(void);	/* edit incore BIOS geometry */
99void	disp_cur_geom(void);
100int	check_geom(void);		/* primitive geometry sanity-check */
101
102void	disp_cur_part(struct mbr_partition *, int, int);
103int	edit_mbr(mbr_info_t *);
104int	mbr_use_wholedisk(mbr_info_t *);
105int 	partsoverlap(struct mbr_partition *, int, int);
106
107/* from mbr.c */
108
109int     read_mbr(const char *, mbr_info_t *);
110int     write_mbr(const char *, mbr_info_t *, int);
111int     valid_mbr(struct mbr_sector *);
112int	guess_biosgeom_from_mbr(mbr_info_t *, int *, int *, daddr_t *);
113int	set_bios_geom_with_mbr_guess(void);
114void	set_bios_geom(int, int, int);
115int	otherpart(int);
116int	ourpart(int);
117const char	*get_partname(int);
118void	edit_ptn_bounds(void);
119#ifdef BOOTSEL
120void	disp_bootsel(void);
121void	edit_bootsel_entry(int);
122void	edit_bootsel_timeout(void);
123void	edit_bootsel_default_ptn(int);
124void	edit_bootsel_default_disk(int);
125void	configure_bootsel(void);
126#endif
127
128/* Machine dependent mbr functions */
129int	md_mbr_use_wholedisk(mbr_info_t *mbri);
130int	md_check_mbr(mbr_info_t *mbri);
131
132#endif
133