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