summaryrefslogtreecommitdiff
path: root/usr/src/cmd/fs.d/pcfs/mkfs/mkfs_pcfs.h
blob: 1d1b89ad2671562debddd6d0d3e734b36bc5af9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 1996, 1998, 1999 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#ifndef _MKFS_PCFS_H
#define	_MKFS_PCFS_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#ifdef	__cplusplus
extern "C" {
#endif

#define	BPSEC		512	/* Assumed # of bytes per sector */

#define	OPCODE1		0xE9
#define	OPCODE2		0xEB
#define	BOOTSECSIG	0xAA55

/*
 * Offset (in bytes) from address of boot sector to where we put
 * the backup copy of that sector.  (FAT32 only)
 */
#define	BKUP_BOOTSECT_OFFSET	0xC00

#define	uppercase(c)	((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))

#define	FAT12_TYPE_STRING	"FAT12   "
#define	FAT16_TYPE_STRING	"FAT16   "
#define	FAT32_TYPE_STRING	"FAT32   "

#define	FAT12_ENTSPERSECT	341
#define	FAT16_ENTSPERSECT	256
#define	FAT32_ENTSPERSECT	128

#ifndef	SUNIXOSBOOT
#define	SUNIXOSBOOT	190	/* Solaris UNIX boot partition */
#endif

/*
 *  A macro implementing a ceiling function for integer divides.
 */
#define	idivceil(dvend, dvsor) \
	((dvend)/(dvsor) + (((dvend)%(dvsor) == 0) ? 0 : 1))

/*
 *  Return values for the seek_XXX functions
 */
#define	PART_NOT_FOUND 0
#define	PART_FOUND 1

/*
 *	MS-DOS Disk layout:
 *
 *	---------------------
 *	|    Boot sector    |
 *	|-------------------|
 *	|   Reserved area   |
 *	|-------------------|
 *	|	FAT #1      |
 *	|-------------------|
 *	|	FAT #2      |
 *	|-------------------|
 *	|   Root directory  |
 *	|-------------------|
 *	|                   |
 *	|     File area     |
 *	|___________________|
 */

#ifdef i386
#pragma	pack(1)
#endif
struct _orig_bios_param_blk {
	uint16_t bytes_sector;
	uchar_t	 sectors_per_cluster;
	uint16_t resv_sectors;
	uchar_t	 num_fats;
	uint16_t num_root_entries;
	uint16_t sectors_in_volume;
	uchar_t	 media;
	uint16_t sectors_per_fat;
	uint16_t sectors_per_track;
	uint16_t heads;
	uint32_t hidden_sectors;
	uint32_t sectors_in_logical_volume;
};
#ifdef i386
#pragma pack()
#endif

#ifdef i386
#pragma	pack(1)
#endif
struct _bpb32_extensions {
	uint32_t big_sectors_per_fat;
	uint16_t ext_flags;
	uchar_t	 fs_vers_lo;
	uchar_t	 fs_vers_hi;
	uint32_t root_dir_clust;
	uint16_t fsinfosec;
	uint16_t backupboot;
	uint16_t reserved[6];
};
#ifdef i386
#pragma pack()
#endif

#ifdef i386
#pragma	pack(1)
#endif
struct _bpb_extensions {
	uchar_t  phys_drive_num;
	uchar_t  reserved;
	uchar_t  ext_signature;
	uint32_t volume_id;
	uchar_t  volume_label[11];
	uchar_t  type[8];
};
#ifdef i386
#pragma pack()
#endif

#ifdef i386
#pragma	pack(1)
#endif
struct _sun_bpb_extensions {
	uint16_t  bs_offset_high;
	uint16_t  bs_offset_low;
};
#ifdef i386
#pragma pack()
#endif

/*
 * bpb_t is a conglomeration of all the fields a bpb can have.  Every
 * bpb will have the orig_bios struct, but only FAT32's will have bpb32,
 * and only Solaris boot diskettes will have the sunbpb structure.
 */
typedef struct _bios_param_blk {
	struct _orig_bios_param_blk bpb;
	struct _bpb32_extensions    bpb32;
	struct _bpb_extensions	    ebpb;
	struct _sun_bpb_extensions  sunbpb;
} bpb_t;

#ifdef i386
#pragma	pack(1)
struct _bpb_head {
	uchar_t			    bs_jump_code[3];
	uchar_t			    bs_oem_name[8];
	struct _orig_bios_param_blk bs_bpb;
};
#pragma pack()

#pragma	pack(1)
struct _boot_sector {
	struct _bpb_head	    bs_front;
	struct _bpb_extensions	    bs_ebpb;
	struct _sun_bpb_extensions  bs_sebpb;
	uchar_t			    bs_bootstrap[444];
	uchar_t			    bs_signature[2];
};
#pragma pack()

#pragma	pack(1)
struct _boot_sector32 {
	struct _bpb_head	    bs_front;
	struct _bpb32_extensions    bs_bpb32;
	struct _bpb_extensions	    bs_ebpb;
	uchar_t			    bs_bootstrap[420];
	uchar_t			    bs_signature[2];
};
#pragma pack()
#else
#define	ORIG_BPB_START_INDEX	8	/* index into filler field */
#define	EXT_BPB_START_INDEX	33	/* index into filler field */
#define	BPB_32_START_INDEX	33	/* index into filler field */
#define	EXT_BPB_32_START_INDEX	61	/* index into filler field */
struct _boot_sector {
	uchar_t	 bs_jump_code[3];
	uchar_t  bs_filler[59];
	uchar_t  bs_sun_bpb[4];
	uchar_t	 bs_bootstrap[444];
	uchar_t  bs_signature[2];
};

struct _boot_sector32 {
	uchar_t	 bs_jump_code[3];
	uchar_t  bs_filler[87];
	uchar_t	 bs_bootstrap[420];
	uchar_t  bs_signature[2];
};
#endif

typedef union _ubso {
	struct _boot_sector	bs;
	struct _boot_sector32	bs32;
	struct mboot		mb;
	uchar_t			buf[BPSEC];
} boot_sector_t;

#ifdef	__cplusplus
}
#endif

#endif	/* _MKFS_PCFS_H */