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