xref: /titanic_52/usr/src/uts/common/sys/fs/pc_label.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/isa_defs.h>
37 
38 /*
39  * PC master boot block & partition table defines.
40  */
41 
42 #define	PCB_BPSEC	11	/* (short) bytes per sector */
43 #define	PCB_SPC		13	/* (byte) sectors per cluster */
44 #define	PCB_RESSEC	14	/* (short) reserved sectors */
45 #define	PCB_NFAT	16	/* (byte) number of fats */
46 #define	PCB_NROOTENT	17	/* (short) number of root dir entries */
47 #define	PCB_NSEC	19	/* (short) number of sectors on disk */
48 #define	PCB_MEDIA	21	/* (byte) media descriptor */
49 #define	PCB_SPF		22	/* (short) sectors per fat */
50 #define	PCB_SPT		24	/* (short) sectors per track */
51 #define	PCB_NHEAD	26	/* (short) number of heads */
52 #define	PCB_HIDSEC	28	/* (short) number of hidden sectors */
53 
54 #define	PCFS_PART	0x1be	/* partition table offs in blk 0 of unit */
55 #define	PCFS_NUMPART	4	/* Number of partitions in blk 0 of unit */
56 
57 /*
58  *  Offsets into the boot sector where the string 'FAT' is expected.
59  *  First value is where the string is on 12 and 16 bit FATs,
60  *  the second value is where it is on 32 bit FATs.
61  */
62 #define	PCFS_TYPESTRING_OFFSET16	0x36
63 #define	PCFS_TYPESTRING_OFFSET32	0x52
64 
65 #define	PCFS_BPB	0xb	/* offset of the BPB in the boot block	*/
66 #define	PCFS_SIGN	0x1fe   /* offset of the DOS signature		*/
67 #define	DOS_SYSFAT12    1	/* DOS FAT 12 system indicator		*/
68 #define	DOS_SYSFAT16	4	/* DOS FAT 16 system indicator		*/
69 #define	DOS_SYSHUGE	6	/* DOS FAT 16 system indicator > 32MB	*/
70 #define	DOS_FAT32	0xB	/* FAT32 system indicator */
71 #define	DOS_FAT32_LBA	0xC	/* FAT32 system indicator (LBA) */
72 #define	DOS_FAT16P_LBA	0xE	/* FAT16 system indicator (Primary/LBA ) */
73 #define	DOS_FAT16_LBA	0xF	/* FAT16 system indicator (Extended/LBA) */
74 #define	DOS_F12MAXS	20740	/* Max sector for 12 Bit FAT (DOS>=3.2)	*/
75 #define	DOS_F12MAXC	4086	/* Max cluster for 12 Bit FAT (DOS>=3.2) */
76 
77 #define	DOS_ID1		0xe9	/* JMP intrasegment			*/
78 #define	DOS_ID2a	0xeb    /* JMP short				*/
79 #define	DOS_ID2b	0x90
80 #define	DOS_SIGN	0xaa55	/* DOS signature in boot and partition	*/
81 
82 #define	PC_FATBLOCK	1	/* starting block number of fat */
83 /*
84  * Media descriptor byte.
85  * Found in the boot block and in the first byte of the FAT.
86  * Second and third byte in the FAT must be 0xFF.
87  * Note that all technical sources indicate that this means of
88  * identification is extremely unreliable.
89  */
90 #define	MD_FIXED	0xF8	/* fixed disk				*/
91 #define	SS8SPT		0xFE	/* single sided 8 sectors per track	*/
92 #define	DS8SPT		0xFF	/* double sided 8 sectors per track	*/
93 #define	SS9SPT		0xFC	/* single sided 9 sectors per track	*/
94 #define	DS9SPT		0xFD	/* double sided 9 sectors per track	*/
95 #define	DS18SPT		0xF0	/* double sided 18 sectors per track	*/
96 #define	DS9_15SPT	0xF9	/* double sided 9/15 sectors per track	*/
97 
98 #define	PC_SECSIZE	512	/* pc filesystem sector size */
99 
100 /*
101  * conversions to/from little endian format
102  */
103 #if defined(_LITTLE_ENDIAN)
104 /* e.g. i386 machines */
105 #define	ltohs(S)	(*((ushort_t *)(&(S))))
106 #define	ltohi(I)	(*((uint_t *)(&(I))))
107 #define	htols(S)	(*((ushort_t *)(&(S))))
108 #define	htoli(I)	(*((uint_t *)(&(I))))
109 
110 #else
111 /* e.g. SPARC machines */
112 #define	getbyte(A, N)	(((unsigned char *)(&(A)))[N])
113 #define	ltohs(S)	((getbyte(S, 1) << 8) | getbyte(S, 0))
114 #define	ltohi(I)	((getbyte(I, 3) << 24) | (getbyte(I, 2) << 16) | \
115 			    (getbyte(I, 1) << 8) | getbyte(I, 0))
116 #define	htols(S)	((getbyte(S, 1) << 8) | getbyte(S, 0))
117 #define	htoli(I)	((getbyte(I, 3) << 24) | (getbyte(I, 2) << 16) | \
118 			    (getbyte(I, 1) << 8) | getbyte(I, 0))
119 #endif
120 
121 #ifdef	__cplusplus
122 }
123 #endif
124 
125 #endif	/* _SYS_FS_PC_LABEL_H */
126