1//
2// dpme.h - Disk Partition Map Entry (dpme)
3//
4// Written by Eryk Vershen
5//
6// This file describes structures and values related to the standard
7// Apple SCSI disk partitioning scheme.
8//
9// Each entry is (and shall remain) 512 bytes long.
10//
11// For more information see:
12//	"Inside Macintosh: Devices" pages 3-12 to 3-15.
13//	"Inside Macintosh - Volume V" pages V-576 to V-582
14//	"Inside Macintosh - Volume IV" page IV-292
15//
16// There is a kernel file with much of the same info (under different names):
17//	/usr/src/mklinux-1.0DR2/osfmk/src/mach_kernel/ppc/POWERMAC/mac_label.h
18//
19
20/*
21 * Copyright 1996 by Apple Computer, Inc.
22 *              All Rights Reserved
23 *
24 * Permission to use, copy, modify, and distribute this software and
25 * its documentation for any purpose and without fee is hereby granted,
26 * provided that the above copyright notice appears in all copies and
27 * that both the copyright notice and this permission notice appear in
28 * supporting documentation.
29 *
30 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
31 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32 * FOR A PARTICULAR PURPOSE.
33 *
34 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
35 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
36 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
37 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
38 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
39 */
40#ifndef __dpme__
41#define __dpme__
42
43#include "bitfield.h"
44
45//
46// Defines
47//
48#define	BLOCK0_SIGNATURE	0x4552	/* i.e. 'ER' */
49
50#define	DPISTRLEN	32
51#define	DPME_SIGNATURE	0x504D		/* i.e. 'PM' */
52
53// A/UX only stuff (tradition!)
54#define	dpme_bzb	dpme_boot_args
55#define	BZBMAGIC 0xABADBABE	/* BZB magic number */
56#define	FST	((uint8_t) 0x1)	/* standard UNIX FS */
57#define	FSTEFS	((uint8_t) 0x2)	/* Autorecovery FS */
58#define	FSTSFS	((uint8_t) 0x3)	/* Swap FS */
59
60
61//
62// Types
63//
64
65// Physical block zero of the disk has this format
66struct Block0 {
67    uint16_t 	sbSig;		/* unique value for SCSI block 0 */
68    uint16_t 	sbBlkSize;	/* block size of device */
69    uint32_t 	sbBlkCount;	/* number of blocks on device */
70    uint16_t 	sbDevType;	/* device type */
71    uint16_t 	sbDevId;	/* device id */
72    uint32_t 	sbData;		/* not used */
73    uint16_t 	sbDrvrCount;	/* driver descriptor count */
74    uint16_t 	sbMap[247];	/* descriptor map */
75};
76typedef struct Block0 Block0;
77
78// Where &sbMap[0] is actually an array DDMap[sbDrvrCount]
79// kludge to get around alignment junk
80struct DDMap {
81    uint32_t 	ddBlock;	/* 1st driver's starting block (in sbBlkSize blocks!) */
82    uint16_t 	ddSize;		/* size of 1st driver (512-byte blks) */
83    uint16_t 	ddType;		/* system type (1 for Mac+) */
84};
85typedef struct DDMap DDMap;
86
87
88// Each partition map entry (blocks 1 through n) has this format
89struct dpme {
90    uint16_t     dpme_signature          ;
91    uint16_t     dpme_reserved_1         ;
92    uint32_t     dpme_map_entries        ;
93    uint32_t     dpme_pblock_start       ;
94    uint32_t     dpme_pblocks            ;
95    char    dpme_name[DPISTRLEN]    ;  /* name of partition */
96    char    dpme_type[DPISTRLEN]    ;  /* type of partition */
97    uint32_t     dpme_lblock_start       ;
98    uint32_t     dpme_lblocks            ;
99    uint32_t     dpme_flags;
100#if 0
101    uint32_t     dpme_reserved_2    : 23 ;  /* Bit 9 through 31.        */
102    uint32_t     dpme_os_specific_1 :  1 ;  /* Bit 8.                   */
103    uint32_t     dpme_os_specific_2 :  1 ;  /* Bit 7.                   */
104    uint32_t     dpme_os_pic_code   :  1 ;  /* Bit 6.                   */
105    uint32_t     dpme_writable      :  1 ;  /* Bit 5.                   */
106    uint32_t     dpme_readable      :  1 ;  /* Bit 4.                   */
107    uint32_t     dpme_bootable      :  1 ;  /* Bit 3.                   */
108    uint32_t     dpme_in_use        :  1 ;  /* Bit 2.                   */
109    uint32_t     dpme_allocated     :  1 ;  /* Bit 1.                   */
110    uint32_t     dpme_valid         :  1 ;  /* Bit 0.                   */
111#endif
112    uint32_t     dpme_boot_block         ;
113    uint32_t     dpme_boot_bytes         ;
114    uint32_t     dpme_load_addr          ;
115    uint32_t     dpme_load_addr_2        ;
116    uint32_t     dpme_goto_addr          ;
117    uint32_t     dpme_goto_addr_2        ;
118    uint32_t     dpme_checksum           ;
119    char    dpme_process_id[16]     ;
120    uint32_t     dpme_boot_args[32]      ;
121    uint32_t     dpme_reserved_3[62]     ;
122};
123typedef struct dpme DPME;
124
125#define	dpme_diskdriver_set(p, v)	bitfield_set(&p->dpme_flags, 9, 1, v)
126#define	dpme_chainable_set(p, v)	bitfield_set(&p->dpme_flags, 8, 1, v)
127
128#define	dpme_os_specific_1_set(p, v)	bitfield_set(&p->dpme_flags, 8, 1, v)
129#define	dpme_os_specific_2_set(p, v)	bitfield_set(&p->dpme_flags, 7, 1, v)
130#define	dpme_os_pic_code_set(p, v)	bitfield_set(&p->dpme_flags, 6, 1, v)
131#define	dpme_writable_set(p, v)		bitfield_set(&p->dpme_flags, 5, 1, v)
132#define	dpme_readable_set(p, v)		bitfield_set(&p->dpme_flags, 4, 1, v)
133#define	dpme_bootable_set(p, v)		bitfield_set(&p->dpme_flags, 3, 1, v)
134#define	dpme_in_use_set(p, v)		bitfield_set(&p->dpme_flags, 2, 1, v)
135#define	dpme_allocated_set(p, v)	bitfield_set(&p->dpme_flags, 1, 1, v)
136#define	dpme_valid_set(p, v)		bitfield_set(&p->dpme_flags, 0, 1, v)
137
138#define	dpme_diskdriver_get(p)		bitfield_get(p->dpme_flags, 9, 1)
139#define	dpme_chainable_get(p)		bitfield_get(p->dpme_flags, 8, 1)
140
141#define	dpme_os_specific_1_get(p)	bitfield_get(p->dpme_flags, 8, 1)
142#define	dpme_os_specific_2_get(p)	bitfield_get(p->dpme_flags, 7, 1)
143#define	dpme_os_pic_code_get(p)		bitfield_get(p->dpme_flags, 6, 1)
144#define	dpme_writable_get(p)		bitfield_get(p->dpme_flags, 5, 1)
145#define	dpme_readable_get(p)		bitfield_get(p->dpme_flags, 4, 1)
146#define	dpme_bootable_get(p)		bitfield_get(p->dpme_flags, 3, 1)
147#define	dpme_in_use_get(p)		bitfield_get(p->dpme_flags, 2, 1)
148#define	dpme_allocated_get(p)		bitfield_get(p->dpme_flags, 1, 1)
149#define	dpme_valid_get(p)		bitfield_get(p->dpme_flags, 0, 1)
150
151
152// A/UX only data structures (sentimental reasons?)
153
154// Alternate block map (aka bad block remaping) [Never really used]
155struct abm		/* altblk map info stored in bzb */
156{
157    uint32_t  abm_size;	/* size of map in bytes */
158    uint32_t  abm_ents;	/* number of used entries */
159    uint32_t  abm_start;	/* start of altblk map */
160};
161typedef	struct abm ABM;
162
163// BZB (Block Zero Block, but I can't remember the etymology)
164// Where &dpme_boot_args[0] is actually the address of a struct bzb
165// kludge to get around alignment junk
166struct	bzb			/* block zero block format */
167{
168    uint32_t  bzb_magic;		/* magic number */
169    uint8_t   bzb_cluster;		/* Autorecovery cluster grouping */
170    uint8_t   bzb_type;		/* FS type */
171    uint16_t  bzb_inode;		/* bad block inode number */
172    uint32_t  bzb_flags;
173#if 0
174    uint16_t  bzb_root:1,		/* FS is a root FS */
175	 bzb_usr:1,		/* FS is a usr FS */
176	 bzb_crit:1,		/* FS is a critical FS */
177	 bzb_rsrvd:8,		/* reserved for later use */
178	 bzb_slice:5;		/* slice number to associate with plus one */
179    uint16_t  bzb_filler;		/* pad bitfield to 32 bits */
180#endif
181    uint32_t  bzb_tmade;		/* time of FS creation */
182    uint32_t  bzb_tmount;		/* time of last mount */
183    uint32_t  bzb_tumount;		/* time of last umount */
184    ABM  bzb_abm;		/* altblk map info */
185    uint32_t  bzb_fill2[7];		/* for expansion of ABM (ha!ha!) */
186    uint8_t   bzb_mount_point[64];	/* default mount point name */
187};
188typedef	struct bzb	BZB;
189
190#define	bzb_root_set(p, v)		bitfield_set(&p->bzb_flags, 31, 1, v)
191#define	bzb_usr_set(p, v)		bitfield_set(&p->bzb_flags, 30, 1, v)
192#define	bzb_crit_set(p, v)		bitfield_set(&p->bzb_flags, 29, 1, v)
193#define	bzb_slice_set(p, v)		bitfield_set(&p->bzb_flags, 20, 5, v)
194
195#define	bzb_root_get(p)			bitfield_get(p->bzb_flags, 31, 1)
196#define	bzb_usr_get(p)			bitfield_get(p->bzb_flags, 30, 1)
197#define	bzb_crit_get(p)			bitfield_get(p->bzb_flags, 29, 1)
198#define	bzb_slice_get(p)		bitfield_get(p->bzb_flags, 20, 5)
199
200
201//
202// Global Constants
203//
204
205
206//
207// Global Variables
208//
209
210
211//
212// Forward declarations
213//
214
215#endif /* __dpme__ */
216