xref: /illumos-gate/usr/src/common/fs/pcfilep.h (revision c40a6cd785e883b3f052b122c332e21174fc1871)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _PCFILEP_H
28 #define	_PCFILEP_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #define	MAX_DOSMOUNT_RETRIES 3
35 
36 #define	TICKS_PER_SEC	18		/* It's really 18.2! */
37 #define	SECSIZ 512
38 #define	fat_bpc(i) (pi[(i)]->f_bpb.bs_spc * SECSIZ)
39 
40 /*
41  * Access permissions for dosAccess(), dosOpen()
42  * NOTE: These permission need to match those for the DOS compiler.
43  */
44 #define	FILE_EXISTS	1
45 #define	FILE_READ	0x0000
46 #define	FILE_WRITE	0x0001
47 #define	FILE_RDWR	0x0002
48 #define	FILE_APPEND	0x0008
49 #define	FILE_CREATE	0x0100
50 #define	FILE_TRUNC	0x0200
51 
52 #define	TYPE_EMPTY	0x00		/* undefined partition */
53 #define	TYPE_DOS	0x13		/* causes fatInit() to search for */
54 					/* active partition */
55 #define	TYPE_DOS_12	0x01		/* partition with FAT12 filesys */
56 #define	TYPE_DOS_16	0x04		/* partition with FAT16 filesys */
57 #define	TYPE_DOS_EXT	0x05		/* not bootable, ignore */
58 #define	TYPE_HUGH	0x06		/* HUGH partition */
59 #define	TYPE_COMPAQ	0x12		/* Compaq's diag partition */
60 #define	TYPE_SOLARIS	0x82
61 #define	TYPE_SOLARIS_BOOT	0xBE	/* For "boot hill" project */
62 
63 #define	FDISK_START	0x1be		/* location in first sector where */
64 					/* the fdisk starts. */
65 
66 #define	FDISK_PARTS	4		/* Number of partitions in a fdisk */
67 #define	FDISK_ACTIVE	0x80		/* indicates partition is active */
68 #define	FDISK_INACTIVE	0x00		/*  " partition inactive */
69 
70 #pragma pack(1)
71 struct _fdisk_partition_ {
72 	uchar_t	fd_active;
73 	uchar_t	fd_b_head;
74 	uchar_t	fd_b_sec;
75 	uchar_t	fd_b_cyl;
76 	uchar_t	fd_type;
77 	uchar_t	fd_e_head;
78 	uchar_t	fd_e_sec;
79 	uchar_t	fd_e_cyl;
80 	union {
81 		long	fd_start_sec_long;
82 		struct {
83 			ushort_t low;
84 			ushort_t high;
85 		} s;
86 	} u;
87 	long	fd_part_len;
88 };
89 #define	fd_start_sec u.fd_start_sec_long
90 #define	fd_partition fd_type
91 typedef struct _fdisk_partition_ _fdisk_t, *_fdisk_p;
92 #pragma pack()
93 
94 #pragma pack(1)
95 struct _boot_sector_ {
96 	uchar_t	bs_jump_code[3];
97 	uchar_t	bs_oem_name[8];
98 	uchar_t	bs_bytes_sector[2];
99 	uchar_t	bs_spc;			/* ... sectors per cluster */
100 	uchar_t	bs_resv_sectors[2];
101 	uchar_t	bs_num_fats;
102 	uchar_t	bs_num_root_entries[2];
103 	uchar_t	bs_siv[2];			/* ... sectors in volume */
104 	uchar_t	bs_media;
105 	uchar_t	bs_spf[2];			/* ... sectors per fat */
106 	uchar_t	bs_sectors_per_track[2];
107 	uchar_t	bs_heads[2];
108 	/*
109 	 * Byte offset at this point is 28 so we can declare the next
110 	 * variable with the correct type and not worry about alignment.
111 	 */
112 	long	bs_hidden_sectors;
113 	long	bs_lsiv;		/* ... logical sectors in volume */
114 	uchar_t	bs_phys_drive_num;
115 	uchar_t	bs_reserved;
116 	uchar_t	bs_ext_signature;
117 	char	bs_volume_id[4];
118 	char	bs_volume_label[11];
119 	char	bs_type[8];
120 
121 	/* ---- ADDED BY SUNSOFT FOR MDBOOT ---- */
122 	ushort_t	bs_offset_high;
123 	ushort_t	bs_offset_low;
124 };
125 #pragma pack()
126 typedef struct _boot_sector_  _boot_sector_t, *_boot_sector_p;
127 
128 /*
129  * Cluster types
130  */
131 #define	CLUSTER_AVAIL	0x00
132 #define	CLUSTER_RES_12_0	0x0ff0	/* 12bit fat, first reserved */
133 #define	CLUSTER_RES_12_6	0x0ff6	/* 12bit fat, last reserved */
134 #define	CLUSTER_RES_16_0	0xfff0	/* 16bit fat, first reserved */
135 #define	CLUSTER_RES_16_6	0xfff6	/* 16bit fat, last reserved */
136 #define	CLUSTER_BAD_12	0x0ff7	/* 12bit fat, bad entry */
137 #define	CLUSTER_BAD_16	0xfff7	/* 16bit fat, bad entry */
138 #define	CLUSTER_EOF		CLUSTER_EOF_16_0
139 #define	CLUSTER_MAX_12		0x0ff7	/* max clusters for 12bit fat */
140 #define	CLUSTER_EOF_12_0	0x0ff8	/* 12bit fat, EOF first entry */
141 #define	CLUSTER_EOF_12_8	0x0fff	/* 12bit fat, EOF last entry */
142 #define	CLUSTER_EOF_16_0	0xfff8	/* 16bit fat, EOF first entry */
143 #define	CLUSTER_EOF_16_8	0xffff	/* 16bit fat, EOF last entry */
144 
145 /*
146  * Cluster operations for allocation
147  */
148 #define	CLUSTER_NOOP		0x0001	/* ... just allocate cluster */
149 #define	CLUSTER_ZEROFILL	0x0002	/* ... zero fill the alloc'd cluster */
150 
151 #define	CLUSTER_FIRST		0x0002	/* ... first cluster number to search */
152 #define	CLUSTER_ROOTDIR		0x0000	/* ... root dir's cluster number */
153 
154 /*
155  * This structure is filled in by initFAT()
156  */
157 struct _fat_controller_ {
158 	union {
159 		_boot_sector_t	fu_bpb;	 /* boot parameter block */
160 		uchar_t		fu_sector[SECSIZ];
161 	} fu;
162 	long		f_adjust;	/* starting sec for part. */
163 	long		f_rootsec;	/* root dir starting sec. */
164 	long		f_rootlen;	/* length of root in sectors */
165 	long		f_filesec;	/* adjustment for clusters */
166 	long		f_dclust;	/* cur dir cluster */
167 	int		f_nxtfree;	/* next free cluster */
168 	int		f_ncluster;	/* number of cluster in part */
169 	char		f_16bit:1,	/* 1 if 16bit fat entries */
170 			f_flush:1;	/* flush the fat */
171 };
172 typedef struct _fat_controller_ _fat_controller_t, *_fat_controller_p;
173 
174 #define	f_bpb fu.fu_bpb
175 #define	f_sector fu.fu_sector
176 
177 #define	NAMESIZ		8
178 #define	EXTSIZ		3
179 #pragma pack(1)
180 struct _dir_entry_ {
181 	char	d_name[NAMESIZ];
182 	char	d_ext[EXTSIZ];
183 	uchar_t	d_attr;
184 	char	d_res[10];
185 	short	d_time;
186 	short	d_date;
187 	ushort_t d_cluster;
188 	long	d_size;
189 };
190 #pragma pack()
191 typedef struct _dir_entry_ _dir_entry_t, *_dir_entry_p;
192 
193 /*
194  * Number of entries in one sector
195  */
196 #define	DIRENTS (SECSIZ / sizeof (_dir_entry_t))
197 
198 /*
199  * Directory entry attributes
200  */
201 #define	DE_READONLY		0x01
202 #define	DE_HIDDEN		0x02
203 #define	DE_SYSTEM		0x04
204 #define	DE_LABEL		0x08
205 #define	DE_DIRECTORY		0x10
206 #define	DE_ARCHIVE		0x20
207 #define	DE_RESERVED1		0x40
208 #define	DE_RESERVED2		0x80
209 
210 #define	DE_IS_LFN (DE_READONLY | DE_HIDDEN | DE_SYSTEM | DE_LABEL)
211 
212 struct _file_descriptor_ {
213 	struct _file_descriptor_ *f_forw; /* link to next file descriptor */
214 	int	f_desc;			/* descriptor number */
215 	long	f_startclust;		/* starting cluster number */
216 	long	f_off;			/* current offset */
217 	long	f_len;			/* size of file */
218 	long	f_index;		/* index into directory block */
219 	uchar_t	f_attr;			/* attributes */
220 	int	f_volidx;		/* Volume device index */
221 	char	*f_volname;		/* Name of volume */
222 };
223 typedef struct _file_descriptor_ _file_desc_t, *_file_desc_p;
224 
225 #ifdef	__cplusplus
226 }
227 #endif
228 
229 #endif	/* _PCFILEP_H */
230