xref: /netbsd-src/external/bsd/pdisk/dist/dpme.h (revision 48a628ae0434c4247b560ad8f2eb1dc06d0dd070)
19428323dSchristos //
29428323dSchristos // dpme.h - Disk Partition Map Entry (dpme)
39428323dSchristos //
49428323dSchristos // Written by Eryk Vershen
59428323dSchristos //
69428323dSchristos // This file describes structures and values related to the standard
79428323dSchristos // Apple SCSI disk partitioning scheme.
89428323dSchristos //
99428323dSchristos // Each entry is (and shall remain) 512 bytes long.
109428323dSchristos //
119428323dSchristos // For more information see:
129428323dSchristos //	"Inside Macintosh: Devices" pages 3-12 to 3-15.
139428323dSchristos //	"Inside Macintosh - Volume V" pages V-576 to V-582
149428323dSchristos //	"Inside Macintosh - Volume IV" page IV-292
159428323dSchristos //
169428323dSchristos // There is a kernel file with much of the same info (under different names):
179428323dSchristos //	/usr/src/mklinux-1.0DR2/osfmk/src/mach_kernel/ppc/POWERMAC/mac_label.h
189428323dSchristos //
199428323dSchristos 
209428323dSchristos /*
219428323dSchristos  * Copyright 1996 by Apple Computer, Inc.
229428323dSchristos  *              All Rights Reserved
239428323dSchristos  *
249428323dSchristos  * Permission to use, copy, modify, and distribute this software and
259428323dSchristos  * its documentation for any purpose and without fee is hereby granted,
269428323dSchristos  * provided that the above copyright notice appears in all copies and
279428323dSchristos  * that both the copyright notice and this permission notice appear in
289428323dSchristos  * supporting documentation.
299428323dSchristos  *
309428323dSchristos  * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
319428323dSchristos  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
329428323dSchristos  * FOR A PARTICULAR PURPOSE.
339428323dSchristos  *
349428323dSchristos  * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
359428323dSchristos  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
369428323dSchristos  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
379428323dSchristos  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
389428323dSchristos  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
399428323dSchristos  */
409428323dSchristos #ifndef __dpme__
419428323dSchristos #define __dpme__
429428323dSchristos 
439428323dSchristos #include "bitfield.h"
449428323dSchristos 
459428323dSchristos //
469428323dSchristos // Defines
479428323dSchristos //
489428323dSchristos #define	BLOCK0_SIGNATURE	0x4552	/* i.e. 'ER' */
499428323dSchristos 
509428323dSchristos #define	DPISTRLEN	32
519428323dSchristos #define	DPME_SIGNATURE	0x504D		/* i.e. 'PM' */
529428323dSchristos 
539428323dSchristos // A/UX only stuff (tradition!)
549428323dSchristos #define	dpme_bzb	dpme_boot_args
559428323dSchristos #define	BZBMAGIC 0xABADBABE	/* BZB magic number */
56*48a628aeSchristos #define	FST	((uint8_t) 0x1)	/* standard UNIX FS */
57*48a628aeSchristos #define	FSTEFS	((uint8_t) 0x2)	/* Autorecovery FS */
58*48a628aeSchristos #define	FSTSFS	((uint8_t) 0x3)	/* Swap FS */
599428323dSchristos 
609428323dSchristos 
619428323dSchristos //
629428323dSchristos // Types
639428323dSchristos //
649428323dSchristos 
659428323dSchristos // Physical block zero of the disk has this format
669428323dSchristos struct Block0 {
67*48a628aeSchristos     uint16_t 	sbSig;		/* unique value for SCSI block 0 */
68*48a628aeSchristos     uint16_t 	sbBlkSize;	/* block size of device */
69*48a628aeSchristos     uint32_t 	sbBlkCount;	/* number of blocks on device */
70*48a628aeSchristos     uint16_t 	sbDevType;	/* device type */
71*48a628aeSchristos     uint16_t 	sbDevId;	/* device id */
72*48a628aeSchristos     uint32_t 	sbData;		/* not used */
73*48a628aeSchristos     uint16_t 	sbDrvrCount;	/* driver descriptor count */
74*48a628aeSchristos     uint16_t 	sbMap[247];	/* descriptor map */
759428323dSchristos };
769428323dSchristos typedef struct Block0 Block0;
779428323dSchristos 
789428323dSchristos // Where &sbMap[0] is actually an array DDMap[sbDrvrCount]
799428323dSchristos // kludge to get around alignment junk
809428323dSchristos struct DDMap {
81*48a628aeSchristos     uint32_t 	ddBlock;	/* 1st driver's starting block (in sbBlkSize blocks!) */
82*48a628aeSchristos     uint16_t 	ddSize;		/* size of 1st driver (512-byte blks) */
83*48a628aeSchristos     uint16_t 	ddType;		/* system type (1 for Mac+) */
849428323dSchristos };
859428323dSchristos typedef struct DDMap DDMap;
869428323dSchristos 
879428323dSchristos 
889428323dSchristos // Each partition map entry (blocks 1 through n) has this format
899428323dSchristos struct dpme {
90*48a628aeSchristos     uint16_t     dpme_signature          ;
91*48a628aeSchristos     uint16_t     dpme_reserved_1         ;
92*48a628aeSchristos     uint32_t     dpme_map_entries        ;
93*48a628aeSchristos     uint32_t     dpme_pblock_start       ;
94*48a628aeSchristos     uint32_t     dpme_pblocks            ;
959428323dSchristos     char    dpme_name[DPISTRLEN]    ;  /* name of partition */
969428323dSchristos     char    dpme_type[DPISTRLEN]    ;  /* type of partition */
97*48a628aeSchristos     uint32_t     dpme_lblock_start       ;
98*48a628aeSchristos     uint32_t     dpme_lblocks            ;
99*48a628aeSchristos     uint32_t     dpme_flags;
1009428323dSchristos #if 0
101*48a628aeSchristos     uint32_t     dpme_reserved_2    : 23 ;  /* Bit 9 through 31.        */
102*48a628aeSchristos     uint32_t     dpme_os_specific_1 :  1 ;  /* Bit 8.                   */
103*48a628aeSchristos     uint32_t     dpme_os_specific_2 :  1 ;  /* Bit 7.                   */
104*48a628aeSchristos     uint32_t     dpme_os_pic_code   :  1 ;  /* Bit 6.                   */
105*48a628aeSchristos     uint32_t     dpme_writable      :  1 ;  /* Bit 5.                   */
106*48a628aeSchristos     uint32_t     dpme_readable      :  1 ;  /* Bit 4.                   */
107*48a628aeSchristos     uint32_t     dpme_bootable      :  1 ;  /* Bit 3.                   */
108*48a628aeSchristos     uint32_t     dpme_in_use        :  1 ;  /* Bit 2.                   */
109*48a628aeSchristos     uint32_t     dpme_allocated     :  1 ;  /* Bit 1.                   */
110*48a628aeSchristos     uint32_t     dpme_valid         :  1 ;  /* Bit 0.                   */
1119428323dSchristos #endif
112*48a628aeSchristos     uint32_t     dpme_boot_block         ;
113*48a628aeSchristos     uint32_t     dpme_boot_bytes         ;
114*48a628aeSchristos     uint32_t     dpme_load_addr          ;
115*48a628aeSchristos     uint32_t     dpme_load_addr_2        ;
116*48a628aeSchristos     uint32_t     dpme_goto_addr          ;
117*48a628aeSchristos     uint32_t     dpme_goto_addr_2        ;
118*48a628aeSchristos     uint32_t     dpme_checksum           ;
1199428323dSchristos     char    dpme_process_id[16]     ;
120*48a628aeSchristos     uint32_t     dpme_boot_args[32]      ;
121*48a628aeSchristos     uint32_t     dpme_reserved_3[62]     ;
1229428323dSchristos };
1239428323dSchristos typedef struct dpme DPME;
1249428323dSchristos 
1259428323dSchristos #define	dpme_diskdriver_set(p, v)	bitfield_set(&p->dpme_flags, 9, 1, v)
1269428323dSchristos #define	dpme_chainable_set(p, v)	bitfield_set(&p->dpme_flags, 8, 1, v)
1279428323dSchristos 
1289428323dSchristos #define	dpme_os_specific_1_set(p, v)	bitfield_set(&p->dpme_flags, 8, 1, v)
1299428323dSchristos #define	dpme_os_specific_2_set(p, v)	bitfield_set(&p->dpme_flags, 7, 1, v)
1309428323dSchristos #define	dpme_os_pic_code_set(p, v)	bitfield_set(&p->dpme_flags, 6, 1, v)
1319428323dSchristos #define	dpme_writable_set(p, v)		bitfield_set(&p->dpme_flags, 5, 1, v)
1329428323dSchristos #define	dpme_readable_set(p, v)		bitfield_set(&p->dpme_flags, 4, 1, v)
1339428323dSchristos #define	dpme_bootable_set(p, v)		bitfield_set(&p->dpme_flags, 3, 1, v)
1349428323dSchristos #define	dpme_in_use_set(p, v)		bitfield_set(&p->dpme_flags, 2, 1, v)
1359428323dSchristos #define	dpme_allocated_set(p, v)	bitfield_set(&p->dpme_flags, 1, 1, v)
1369428323dSchristos #define	dpme_valid_set(p, v)		bitfield_set(&p->dpme_flags, 0, 1, v)
1379428323dSchristos 
1389428323dSchristos #define	dpme_diskdriver_get(p)		bitfield_get(p->dpme_flags, 9, 1)
1399428323dSchristos #define	dpme_chainable_get(p)		bitfield_get(p->dpme_flags, 8, 1)
1409428323dSchristos 
1419428323dSchristos #define	dpme_os_specific_1_get(p)	bitfield_get(p->dpme_flags, 8, 1)
1429428323dSchristos #define	dpme_os_specific_2_get(p)	bitfield_get(p->dpme_flags, 7, 1)
1439428323dSchristos #define	dpme_os_pic_code_get(p)		bitfield_get(p->dpme_flags, 6, 1)
1449428323dSchristos #define	dpme_writable_get(p)		bitfield_get(p->dpme_flags, 5, 1)
1459428323dSchristos #define	dpme_readable_get(p)		bitfield_get(p->dpme_flags, 4, 1)
1469428323dSchristos #define	dpme_bootable_get(p)		bitfield_get(p->dpme_flags, 3, 1)
1479428323dSchristos #define	dpme_in_use_get(p)		bitfield_get(p->dpme_flags, 2, 1)
1489428323dSchristos #define	dpme_allocated_get(p)		bitfield_get(p->dpme_flags, 1, 1)
1499428323dSchristos #define	dpme_valid_get(p)		bitfield_get(p->dpme_flags, 0, 1)
1509428323dSchristos 
1519428323dSchristos 
1529428323dSchristos // A/UX only data structures (sentimental reasons?)
1539428323dSchristos 
1549428323dSchristos // Alternate block map (aka bad block remaping) [Never really used]
1559428323dSchristos struct abm		/* altblk map info stored in bzb */
1569428323dSchristos {
157*48a628aeSchristos     uint32_t  abm_size;	/* size of map in bytes */
158*48a628aeSchristos     uint32_t  abm_ents;	/* number of used entries */
159*48a628aeSchristos     uint32_t  abm_start;	/* start of altblk map */
1609428323dSchristos };
1619428323dSchristos typedef	struct abm ABM;
1629428323dSchristos 
1639428323dSchristos // BZB (Block Zero Block, but I can't remember the etymology)
1649428323dSchristos // Where &dpme_boot_args[0] is actually the address of a struct bzb
1659428323dSchristos // kludge to get around alignment junk
1669428323dSchristos struct	bzb			/* block zero block format */
1679428323dSchristos {
168*48a628aeSchristos     uint32_t  bzb_magic;		/* magic number */
169*48a628aeSchristos     uint8_t   bzb_cluster;		/* Autorecovery cluster grouping */
170*48a628aeSchristos     uint8_t   bzb_type;		/* FS type */
171*48a628aeSchristos     uint16_t  bzb_inode;		/* bad block inode number */
172*48a628aeSchristos     uint32_t  bzb_flags;
1739428323dSchristos #if 0
174*48a628aeSchristos     uint16_t  bzb_root:1,		/* FS is a root FS */
1759428323dSchristos 	 bzb_usr:1,		/* FS is a usr FS */
1769428323dSchristos 	 bzb_crit:1,		/* FS is a critical FS */
1779428323dSchristos 	 bzb_rsrvd:8,		/* reserved for later use */
1789428323dSchristos 	 bzb_slice:5;		/* slice number to associate with plus one */
179*48a628aeSchristos     uint16_t  bzb_filler;		/* pad bitfield to 32 bits */
1809428323dSchristos #endif
181*48a628aeSchristos     uint32_t  bzb_tmade;		/* time of FS creation */
182*48a628aeSchristos     uint32_t  bzb_tmount;		/* time of last mount */
183*48a628aeSchristos     uint32_t  bzb_tumount;		/* time of last umount */
1849428323dSchristos     ABM  bzb_abm;		/* altblk map info */
185*48a628aeSchristos     uint32_t  bzb_fill2[7];		/* for expansion of ABM (ha!ha!) */
186*48a628aeSchristos     uint8_t   bzb_mount_point[64];	/* default mount point name */
1879428323dSchristos };
1889428323dSchristos typedef	struct bzb	BZB;
1899428323dSchristos 
1909428323dSchristos #define	bzb_root_set(p, v)		bitfield_set(&p->bzb_flags, 31, 1, v)
1919428323dSchristos #define	bzb_usr_set(p, v)		bitfield_set(&p->bzb_flags, 30, 1, v)
1929428323dSchristos #define	bzb_crit_set(p, v)		bitfield_set(&p->bzb_flags, 29, 1, v)
1939428323dSchristos #define	bzb_slice_set(p, v)		bitfield_set(&p->bzb_flags, 20, 5, v)
1949428323dSchristos 
1959428323dSchristos #define	bzb_root_get(p)			bitfield_get(p->bzb_flags, 31, 1)
1969428323dSchristos #define	bzb_usr_get(p)			bitfield_get(p->bzb_flags, 30, 1)
1979428323dSchristos #define	bzb_crit_get(p)			bitfield_get(p->bzb_flags, 29, 1)
1989428323dSchristos #define	bzb_slice_get(p)		bitfield_get(p->bzb_flags, 20, 5)
1999428323dSchristos 
2009428323dSchristos 
2019428323dSchristos //
2029428323dSchristos // Global Constants
2039428323dSchristos //
2049428323dSchristos 
2059428323dSchristos 
2069428323dSchristos //
2079428323dSchristos // Global Variables
2089428323dSchristos //
2099428323dSchristos 
2109428323dSchristos 
2119428323dSchristos //
2129428323dSchristos // Forward declarations
2139428323dSchristos //
2149428323dSchristos 
2159428323dSchristos #endif /* __dpme__ */
216