xref: /plan9/sys/src/cmd/dossrv/dat.h (revision 9a747e4fd48b9f4522c70c07e8f882a15030f964)
1 typedef struct Dosboot		Dosboot;
2 typedef struct Dosboot32	Dosboot32;
3 typedef struct Dosbpb		Dosbpb;
4 typedef struct Dosdir		Dosdir;
5 typedef struct Dospart		Dospart;
6 typedef struct Dosptr		Dosptr;
7 typedef struct Fatinfo		Fatinfo;
8 typedef struct Xfs		Xfs;
9 typedef struct Xfile		Xfile;
10 
11 struct Dospart{
12 	uchar	active;
13 	uchar	hstart;
14 	uchar	cylstart[2];
15 	uchar	type;
16 	uchar	hend;
17 	uchar	cylend[2];
18 	uchar	start[4];
19 	uchar	length[4];
20 };
21 
22 enum
23 {
24 	/*
25 	 * dos partition types
26 	 */
27 	FAT12		= 0x01,
28 	FAT16		= 0x04,		/* partitions smaller than 32MB */
29 	FATHUGE		= 0x06,		/* fat16 partitions larger than 32MB */
30 	FAT32		= 0x0b,
31 	FAT32X		= 0x0c,
32 	FATHUGEX	= 0x0e,
33 	DMDDO		= 0x54,
34 
35 	FATRESRV	= 2,		/* number of reserved fat entries */
36 };
37 
38 /*
39  * dos boot sector, the start of every dos partition
40  */
41 struct Dosboot{
42 	uchar	magic[3];
43 	uchar	version[8];
44 	uchar	sectsize[2];
45 	uchar	clustsize;
46 	uchar	nresrv[2];
47 	uchar	nfats;
48 	uchar	rootsize[2];
49 	uchar	volsize[2];
50 	uchar	mediadesc;
51 	uchar	fatsize[2];
52 	uchar	trksize[2];
53 	uchar	nheads[2];
54 	uchar	nhidden[4];
55 	uchar	bigvolsize[4];		/* same as Dosboot32 up to here */
56 	uchar	driveno;
57 	uchar	reserved0;
58 	uchar	bootsig;
59 	uchar	volid[4];
60 	uchar	label[11];
61 	uchar	reserved1[8];
62 };
63 
64 /*
65  * dos boot sector for FAT32
66  */
67 enum
68 {
69 	NOFATMIRROR	= 0x0080,	/* masks for extflags */
70 	ACTFATMASK	= 0x000f,
71 };
72 
73 struct Dosboot32{
74 	uchar	magic[3];
75 	uchar	version[8];
76 	uchar	sectsize[2];
77 	uchar	clustsize;
78 	uchar	nresrv[2];
79 	uchar	nfats;
80 	uchar	rootsize[2];
81 	uchar	volsize[2];
82 	uchar	mediadesc;
83 	uchar	fatsize[2];
84 	uchar	trksize[2];
85 	uchar	nheads[2];
86 	uchar	nhidden[4];
87 	uchar	bigvolsize[4];		/* same as Dosboot up to here */
88 	uchar	fatsize32[4];		/* sectors per fat */
89 	uchar	extflags[2];		/* active fat flags */
90 	uchar	version1[2];		/* fat32 version; major & minor bytes */
91 	uchar	rootstart[4];		/* starting cluster of root dir */
92 	uchar	infospec[2];		/* fat allocation info sector */
93 	uchar	backupboot[2];		/* backup boot sector */
94 	uchar	reserved[12];
95 };
96 
97 /*
98  * optional FAT32 info sector
99  */
100 enum
101 {
102 	FATINFOSIG1	= 0x41615252UL,
103 	FATINFOSIG	= 0x61417272UL,
104 };
105 
106 struct Fatinfo
107 {
108 	uchar	sig1[4];
109 	uchar	pad[480];
110 	uchar	sig[4];
111 	uchar	freeclust[4];	/* num frre clusters; -1 is unknown */
112 	uchar	nextfree[4];	/* most recently allocated cluster */
113 	uchar	resrv[4*3];
114 };
115 
116 /*
117  * BIOS paramater block
118  */
119 struct Dosbpb{
120 	MLock;				/* access to fat */
121 	int	sectsize;		/* in bytes */
122 	int	clustsize;		/* in sectors */
123 	int	nresrv;			/* sectors */
124 	int	nfats;			/* usually 2; modified to 1 if fat mirroring disabled */
125 	int	rootsize;		/* number of entries, for fat12 and fat16 */
126 	long	volsize;		/* in sectors */
127 	int	mediadesc;
128 	long	fatsize;		/* in sectors */
129 	int	fatclusters;
130 	int	fatbits;		/* 12, 16, or 32 */
131 	long	fataddr;		/* sector number of first valid fat entry */
132 	long	rootaddr;		/* for fat16 or fat12, sector of root dir */
133 	long	rootstart;		/* for fat32, cluster of root dir */
134 	long	dataaddr;		/* initial sector of data clusters */
135 	long	freeptr;		/* next free cluster candidate */
136 	long	freeclusters;		/* count of free clusters, for fat32 */
137 	int	fatinfo;		/* fat info sector location; 0 => none */
138 };
139 
140 enum
141 {
142 	DOSDIRSIZE	= 32,
143 	DOSEMPTY	= 0xe5,			/* first char in name if entry is unused */
144 	DOSRUNE		= 13,			/* runes per dosdir in a long file name */
145 	DOSNAMELEN	= 261			/* max dos file name length */
146 };
147 
148 struct Dosdir{
149 	uchar	name[8];
150 	uchar	ext[3];
151 	uchar	attr;
152 	uchar	reserved[1];
153 	uchar	ctime[3];		/* creation time */
154 	uchar	cdate[2];		/* creation date */
155 	uchar	adate[2];		/* last access date */
156 	uchar	hstart[2];		/* high bits of start for fat32 */
157 	uchar	time[2];		/* last modified time */
158 	uchar	date[2];		/* last modified date */
159 	uchar	start[2];
160 	uchar	length[4];
161 };
162 
163 enum
164 {
165 	DRONLY		= 0x01,
166 	DHIDDEN		= 0x02,
167 	DSYSTEM		= 0x04,
168 	DVLABEL		= 0x08,
169 	DDIR		= 0x10,
170 	DARCH		= 0x20,
171 };
172 
173 #define	GSHORT(p)	(((p)[0])|(p)[1]<<8)
174 #define	GLONG(p)	(((long)(p)[0])|(p)[1]<<8|(p)[2]<<16|(p)[3]<<24)
175 #define PSHORT(p,v)	((p)[0]=(v),(p)[1]=(v)>>8)
176 #define PLONG(p,v)	((p)[0]=(v),(p)[1]=(v)>>8,(p)[2]=(v)>>16,(p)[3]=(v)>>24)
177 
178 struct Dosptr{
179 	ulong	addr;		/* sector & entry within of file's directory entry */
180 	ulong	offset;
181 	ulong	paddr;		/* of parent's directory entry */
182 	ulong	poffset;
183 	ulong	iclust;		/* ordinal within file */
184 	ulong	clust;
185 	ulong	naddr;		/* next block in directory (for writing multi entry elements) */
186 	ulong	prevaddr;
187 	Iosect *p;
188 	Dosdir *d;
189 };
190 
191 #define	QIDPATH(p)	((p)->addr*(Sectorsize/DOSDIRSIZE) + \
192 			 (p)->offset/DOSDIRSIZE)
193 
194 struct Xfs{
195 	Xfs	*next;
196 	int omode;		/* of file containing external fs */
197 	char	*name;		/* of file containing external f.s. */
198 	Qid	qid;		/* of file containing external f.s. */
199 	long	ref;		/* attach count */
200 	Qid	rootqid;	/* of plan9 constructed root directory */
201 	uchar	isfat32;	/* is a fat 32 file system? */
202 	short	dev;
203 	short	fmt;
204 	long	offset;
205 	void	*ptr;
206 };
207 
208 struct Xfile{
209 	Xfile	*next;		/* in hash bucket */
210 	long	fid;
211 	ulong	flags;
212 	Qid	qid;
213 	Xfs	*xf;
214 	Dosptr	*ptr;
215 };
216 
217 enum{
218 	Asis, Clean, Clunk
219 };
220 
221 enum{
222 	Invalid, Short, ShortLower, Long
223 };
224 
225 enum{	/* Xfile flags */
226 	Oread = 1,
227 	Owrite = 2,
228 	Orclose = 4,
229 	Omodes = 3,
230 };
231 
232 enum{
233 	Enevermind,
234 	Eformat,
235 	Eio,
236 	Enoauth,
237 	Enomem,
238 	Enonexist,
239 	Eperm,
240 	Enofilsys,
241 	Eauth,
242 	Econtig,
243 	Ebadfcall,
244 	Ebadstat,
245 	Eversion,
246 	Etoolong,
247 	Eerrstr,
248 	ESIZE
249 };
250 
251 extern int	chatty;
252 extern int	errno;
253 extern int	readonly;
254 extern char	*deffile;
255 extern int trspaces;