xref: /netbsd-src/sys/arch/atari/stand/ahdilabel/privahdi.h (revision 811d5a8b03bd98285c849c9bf915ab5506b2c4d6)
1 /*	$NetBSD: privahdi.h,v 1.4 2020/09/29 02:49:55 msaitoh Exp $	*/
2 
3 /*
4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Julian Coleman, Waldi Ravens and Leo Weppelman.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/param.h>
33 #include <sys/disklabel.h>
34 #include <machine/ahdilabel.h>
35 
36 /* Flags for ahdi_readlabel() */
37 #define	FORCE_AHDI	0x01	/* Read AHDI label when NetBSD label exists */
38 #define	AHDI_IGN_EXISTS	0x02	/* Ignore partition exists flag (ICD tools) */
39 #define	AHDI_IGN_EXT	0x04	/* Ignore last extended partition (HDDriver) */
40 #define	AHDI_IGN_CKSUM	0x08	/* Ignore checksum mismatch on root sector */
41 #define	AHDI_IGN_SPU	0x10	/* Ignore total sectors mismatch */
42 
43 /* Flags for ahdi_writelabel() */
44 #define AHDI_KEEP_BOOT	0x01	/* Keep boot sector */
45 #define AHDI_KEEP_BSL	0x02	/* Keep bad sector list */
46 #define AHDI_KEEP_NBDA	0x04	/* Keep NetBSD label */
47 
48 struct ptable_part {
49 	u_int8_t	flag;	/* partition flag */
50 	u_int8_t	id[3];	/* id: GEM, BGM, NBD, ... */
51 	u_int32_t	root;	/* root sector */
52 	u_int32_t	start;	/* start sector */
53 	u_int32_t	size;	/* size in sectors */
54 	int		letter;	/* partition letter */
55 };
56 
57 struct ahdi_ptable {
58 	u_int32_t		nsectors;	/* number of sectors/track */
59 	u_int32_t		ntracks;	/* number of tracks/cylinder */
60 	u_int32_t		ncylinders;	/* number of cylinders */
61 	u_int32_t		secpercyl;	/* number of sectors/cylinder */
62 	u_int32_t		secperunit;	/* number of total sectors */
63 	int			nparts;		/* number of partitions */
64 	struct ptable_part	parts[MAXPARTITIONS];
65 };
66 
67 int	 ahdi_buildlabel(struct ahdi_ptable *);
68 int	 ahdi_checklabel(struct ahdi_ptable *);
69 int	 ahdi_readlabel(struct ahdi_ptable *, char *, int);
70 int	 ahdi_writedisktab(struct ahdi_ptable *, char *, char *, char *);
71 int	 ahdi_writelabel(struct ahdi_ptable *, char *, int);
72 
73 extern int	ahdi_errp1, ahdi_errp2;
74 
75 /* Internal functions */
76 u_int16_t		 ahdi_cksum(void *);
77 void			 assign_letters(struct ahdi_ptable *);
78 int			 check_magic(int, u_int, int);
79 int			 dkcksum(struct disklabel *);
80 void			*disk_read(int, u_int, u_int);
81 int			 disk_write(int, u_int, u_int, void *);
82 int			 invalidate_netbsd_label(int, u_int32_t);
83 int			 openraw(const char *, int);
84 struct disklabel	*read_dl(int);
85 int			 read_rsec(int, struct ahdi_ptable *, u_int,
86 			     u_int, int);
87 int			 write_bsl(int);
88