xref: /illumos-gate/usr/src/uts/common/sys/fs/pc_label.h (revision fc910014e8a32a65612105835a10995f2c13d942)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FS_PC_LABEL_H
28 #define	_SYS_FS_PC_LABEL_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/isa_defs.h>
35 
36 /*
37  * PC master boot block & partition table defines.
38  */
39 
40 #define	PCB_BPSEC	11	/* (short) bytes per sector */
41 #define	PCB_SPC		13	/* (byte) sectors per cluster */
42 #define	PCB_RESSEC	14	/* (short) reserved sectors */
43 #define	PCB_NFAT	16	/* (byte) number of fats */
44 #define	PCB_NROOTENT	17	/* (short) number of root dir entries */
45 #define	PCB_NSEC	19	/* (short) number of sectors on disk */
46 #define	PCB_MEDIA	21	/* (byte) media descriptor */
47 #define	PCB_SPF		22	/* (short) sectors per fat */
48 #define	PCB_SPT		24	/* (short) sectors per track */
49 #define	PCB_NHEAD	26	/* (short) number of heads */
50 #define	PCB_HIDSEC	28	/* (short) number of hidden sectors */
51 
52 #define	PCFS_PART	0x1be	/* partition table offs in blk 0 of unit */
53 #define	PCFS_NUMPART	4	/* Number of partitions in blk 0 of unit */
54 
55 /*
56  *  Offsets into the boot sector where the string 'FAT' is expected.
57  *  First value is where the string is on 12 and 16 bit FATs,
58  *  the second value is where it is on 32 bit FATs.
59  */
60 #define	PCFS_TYPESTRING_OFFSET16	0x36
61 #define	PCFS_TYPESTRING_OFFSET32	0x52
62 
63 #define	PCFS_BPB	0xb	/* offset of the BPB in the boot block	*/
64 #define	PCFS_SIGN	0x1fe   /* offset of the DOS signature		*/
65 #define	DOS_SYSFAT12    1	/* DOS FAT 12 system indicator		*/
66 #define	DOS_SYSFAT16	4	/* DOS FAT 16 system indicator		*/
67 #define	DOS_SYSHUGE	6	/* DOS FAT 16 system indicator > 32MB	*/
68 #define	DOS_FAT32	0xB	/* FAT32 system indicator */
69 #define	DOS_FAT32_LBA	0xC	/* FAT32 system indicator (LBA) */
70 #define	DOS_FAT16P_LBA	0xE	/* FAT16 system indicator (Primary/LBA ) */
71 #define	DOS_FAT16_LBA	0xF	/* FAT16 system indicator (Extended/LBA) */
72 #define	DOS_F12MAXS	20740	/* Max sector for 12 Bit FAT (DOS>=3.2)	*/
73 #define	DOS_F12MAXC	4086	/* Max cluster for 12 Bit FAT (DOS>=3.2) */
74 
75 #define	DOS_ID1		0xe9	/* JMP intrasegment			*/
76 #define	DOS_ID2a	0xeb    /* JMP short				*/
77 #define	DOS_ID2b	0x90
78 #define	DOS_SIGN	0xaa55	/* DOS signature in boot and partition	*/
79 
80 #define	PC_FATBLOCK	1	/* starting block number of fat */
81 /*
82  * Media descriptor byte.
83  * Found in the boot block and in the first byte of the FAT.
84  * Second and third byte in the FAT must be 0xFF.
85  * Note that all technical sources indicate that this means of
86  * identification is extremely unreliable.
87  */
88 #define	MD_FIXED	0xF8	/* fixed disk				*/
89 #define	SS8SPT		0xFE	/* single sided 8 sectors per track	*/
90 #define	DS8SPT		0xFF	/* double sided 8 sectors per track	*/
91 #define	SS9SPT		0xFC	/* single sided 9 sectors per track	*/
92 #define	DS9SPT		0xFD	/* double sided 9 sectors per track	*/
93 #define	DS18SPT		0xF0	/* double sided 18 sectors per track	*/
94 #define	DS9_15SPT	0xF9	/* double sided 9/15 sectors per track	*/
95 
96 #define	PC_SECSIZE	512	/* pc filesystem sector size */
97 
98 /*
99  * conversions to/from little endian format
100  */
101 #if defined(_LITTLE_ENDIAN)
102 /* e.g. i386 machines */
103 #define	ltohs(S)	(*((ushort_t *)(&(S))))
104 #define	ltohi(I)	(*((uint_t *)(&(I))))
105 #define	htols(S)	(*((ushort_t *)(&(S))))
106 #define	htoli(I)	(*((uint_t *)(&(I))))
107 
108 #else
109 /* e.g. SPARC machines */
110 #define	getbyte(A, N)	(((unsigned char *)(&(A)))[N])
111 #define	ltohs(S)	((getbyte(S, 1) << 8) | getbyte(S, 0))
112 #define	ltohi(I)	((getbyte(I, 3) << 24) | (getbyte(I, 2) << 16) | \
113 			    (getbyte(I, 1) << 8) | getbyte(I, 0))
114 #define	htols(S)	((getbyte(S, 1) << 8) | getbyte(S, 0))
115 #define	htoli(I)	((getbyte(I, 3) << 24) | (getbyte(I, 2) << 16) | \
116 			    (getbyte(I, 1) << 8) | getbyte(I, 0))
117 #endif
118 
119 #ifdef	__cplusplus
120 }
121 #endif
122 
123 #endif	/* _SYS_FS_PC_LABEL_H */
124