xref: /illumos-gate/usr/src/cmd/fs.d/pcfs/mkfs/mkfs_pcfs.h (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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 (c) 1996, 1998, 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _MKFS_PCFS_H
28 #define	_MKFS_PCFS_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #define	BPSEC		512	/* Assumed # of bytes per sector */
35 
36 #define	OPCODE1		0xE9
37 #define	OPCODE2		0xEB
38 #define	BOOTSECSIG	0xAA55
39 
40 /*
41  * Offset (in bytes) from address of boot sector to where we put
42  * the backup copy of that sector.  (FAT32 only)
43  */
44 #define	BKUP_BOOTSECT_OFFSET	0xC00
45 
46 #define	uppercase(c)	((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
47 
48 #define	FAT12_TYPE_STRING	"FAT12   "
49 #define	FAT16_TYPE_STRING	"FAT16   "
50 #define	FAT32_TYPE_STRING	"FAT32   "
51 
52 #define	FAT12_ENTSPERSECT	341
53 #define	FAT16_ENTSPERSECT	256
54 #define	FAT32_ENTSPERSECT	128
55 
56 #ifndef	SUNIXOSBOOT
57 #define	SUNIXOSBOOT	190	/* Solaris UNIX boot partition */
58 #endif
59 
60 /*
61  *  A macro implementing a ceiling function for integer divides.
62  */
63 #define	idivceil(dvend, dvsor) \
64 	((dvend)/(dvsor) + (((dvend)%(dvsor) == 0) ? 0 : 1))
65 
66 /*
67  *  Return values for the seek_XXX functions
68  */
69 #define	PART_NOT_FOUND 0
70 #define	PART_FOUND 1
71 
72 /*
73  *	MS-DOS Disk layout:
74  *
75  *	---------------------
76  *	|    Boot sector    |
77  *	|-------------------|
78  *	|   Reserved area   |
79  *	|-------------------|
80  *	|	FAT #1      |
81  *	|-------------------|
82  *	|	FAT #2      |
83  *	|-------------------|
84  *	|   Root directory  |
85  *	|-------------------|
86  *	|                   |
87  *	|     File area     |
88  *	|___________________|
89  */
90 
91 #ifdef i386
92 #pragma	pack(1)
93 #endif
94 struct _orig_bios_param_blk {
95 	uint16_t bytes_sector;
96 	uchar_t	 sectors_per_cluster;
97 	uint16_t resv_sectors;
98 	uchar_t	 num_fats;
99 	uint16_t num_root_entries;
100 	uint16_t sectors_in_volume;
101 	uchar_t	 media;
102 	uint16_t sectors_per_fat;
103 	uint16_t sectors_per_track;
104 	uint16_t heads;
105 	uint32_t hidden_sectors;
106 	uint32_t sectors_in_logical_volume;
107 };
108 #ifdef i386
109 #pragma pack()
110 #endif
111 
112 #ifdef i386
113 #pragma	pack(1)
114 #endif
115 struct _bpb32_extensions {
116 	uint32_t big_sectors_per_fat;
117 	uint16_t ext_flags;
118 	uchar_t	 fs_vers_lo;
119 	uchar_t	 fs_vers_hi;
120 	uint32_t root_dir_clust;
121 	uint16_t fsinfosec;
122 	uint16_t backupboot;
123 	uint16_t reserved[6];
124 };
125 #ifdef i386
126 #pragma pack()
127 #endif
128 
129 #ifdef i386
130 #pragma	pack(1)
131 #endif
132 struct _bpb_extensions {
133 	uchar_t  phys_drive_num;
134 	uchar_t  reserved;
135 	uchar_t  ext_signature;
136 	uint32_t volume_id;
137 	uchar_t  volume_label[11];
138 	uchar_t  type[8];
139 };
140 #ifdef i386
141 #pragma pack()
142 #endif
143 
144 #ifdef i386
145 #pragma	pack(1)
146 #endif
147 struct _sun_bpb_extensions {
148 	uint16_t  bs_offset_high;
149 	uint16_t  bs_offset_low;
150 };
151 #ifdef i386
152 #pragma pack()
153 #endif
154 
155 /*
156  * bpb_t is a conglomeration of all the fields a bpb can have.  Every
157  * bpb will have the orig_bios struct, but only FAT32's will have bpb32,
158  * and only Solaris boot diskettes will have the sunbpb structure.
159  */
160 typedef struct _bios_param_blk {
161 	struct _orig_bios_param_blk bpb;
162 	struct _bpb32_extensions    bpb32;
163 	struct _bpb_extensions	    ebpb;
164 	struct _sun_bpb_extensions  sunbpb;
165 } bpb_t;
166 
167 #ifdef i386
168 #pragma	pack(1)
169 struct _bpb_head {
170 	uchar_t			    bs_jump_code[3];
171 	uchar_t			    bs_oem_name[8];
172 	struct _orig_bios_param_blk bs_bpb;
173 };
174 #pragma pack()
175 
176 #pragma	pack(1)
177 struct _boot_sector {
178 	struct _bpb_head	    bs_front;
179 	struct _bpb_extensions	    bs_ebpb;
180 	struct _sun_bpb_extensions  bs_sebpb;
181 	uchar_t			    bs_bootstrap[444];
182 	uchar_t			    bs_signature[2];
183 };
184 #pragma pack()
185 
186 #pragma	pack(1)
187 struct _boot_sector32 {
188 	struct _bpb_head	    bs_front;
189 	struct _bpb32_extensions    bs_bpb32;
190 	struct _bpb_extensions	    bs_ebpb;
191 	uchar_t			    bs_bootstrap[420];
192 	uchar_t			    bs_signature[2];
193 };
194 #pragma pack()
195 #else
196 #define	ORIG_BPB_START_INDEX	8	/* index into filler field */
197 #define	EXT_BPB_START_INDEX	33	/* index into filler field */
198 #define	BPB_32_START_INDEX	33	/* index into filler field */
199 #define	EXT_BPB_32_START_INDEX	61	/* index into filler field */
200 struct _boot_sector {
201 	uchar_t	 bs_jump_code[3];
202 	uchar_t  bs_filler[59];
203 	uchar_t  bs_sun_bpb[4];
204 	uchar_t	 bs_bootstrap[444];
205 	uchar_t  bs_signature[2];
206 };
207 
208 struct _boot_sector32 {
209 	uchar_t	 bs_jump_code[3];
210 	uchar_t  bs_filler[87];
211 	uchar_t	 bs_bootstrap[420];
212 	uchar_t  bs_signature[2];
213 };
214 #endif
215 
216 typedef union _ubso {
217 	struct _boot_sector	bs;
218 	struct _boot_sector32	bs32;
219 	struct mboot		mb;
220 	uchar_t			buf[BPSEC];
221 } boot_sector_t;
222 
223 #ifdef	__cplusplus
224 }
225 #endif
226 
227 #endif	/* _MKFS_PCFS_H */
228