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
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.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 #define MAX_DOSMOUNT_RETRIES 3
38 #define TICKS_PER_SEC 18 /* It's really 18.2! */
40 #define fat_bpc(i) (pi[(i)]->f_bpb.bs_spc * SECSIZ)
43 * Access permissions for dosAccess(), dosOpen()
44 * NOTE: These permission need to match those for the DOS compiler.
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
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 */
65 #define FDISK_START 0x1be /* location in first sector where */
66 /* the fdisk starts. */
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 */
73 struct _fdisk_partition_
{
83 long fd_start_sec_long
;
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
;
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];
104 uchar_t bs_num_root_entries
[2];
105 uchar_t bs_siv
[2]; /* ... sectors in volume */
107 uchar_t bs_spf
[2]; /* ... sectors per fat */
108 uchar_t bs_sectors_per_track
[2];
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.
114 long bs_hidden_sectors
;
115 long bs_lsiv
; /* ... logical sectors in volume */
116 uchar_t bs_phys_drive_num
;
118 uchar_t bs_ext_signature
;
119 char bs_volume_id
[4];
120 char bs_volume_label
[11];
123 /* ---- ADDED BY SUNSOFT FOR MDBOOT ---- */
124 ushort_t bs_offset_high
;
125 ushort_t bs_offset_low
;
128 typedef struct _boot_sector_ _boot_sector_t
, *_boot_sector_p
;
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 */
148 * Cluster operations for allocation
150 #define CLUSTER_NOOP 0x0001 /* ... just allocate cluster */
151 #define CLUSTER_ZEROFILL 0x0002 /* ... zero fill the alloc'd cluster */
153 #define CLUSTER_FIRST 0x0002 /* ... first cluster number to search */
154 #define CLUSTER_ROOTDIR 0x0000 /* ... root dir's cluster number */
157 * This structure is filled in by initFAT()
159 struct _fat_controller_
{
161 _boot_sector_t fu_bpb
; /* boot parameter block */
162 uchar_t fu_sector
[SECSIZ
];
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 */
174 typedef struct _fat_controller_ _fat_controller_t
, *_fat_controller_p
;
176 #define f_bpb fu.fu_bpb
177 #define f_sector fu.fu_sector
183 char d_name
[NAMESIZ
];
193 typedef struct _dir_entry_ _dir_entry_t
, *_dir_entry_p
;
196 * Number of entries in one sector
198 #define DIRENTS (SECSIZ / sizeof (_dir_entry_t))
201 * Directory entry attributes
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
212 #define DE_IS_LFN (DE_READONLY | DE_HIDDEN | DE_SYSTEM | DE_LABEL)
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 */
225 typedef struct _file_descriptor_ _file_desc_t
, *_file_desc_p
;
231 #endif /* _PCFILEP_H */