xref: /plan9/sys/src/9/pcboot/dosfs.h (revision 25210b069a6ed8c047fa67220cf1dff32812f121)
1 typedef struct Dosboot	Dosboot;
2 typedef struct Dos	Dos;
3 typedef struct Dosdir	Dosdir;
4 typedef struct Dosfile	Dosfile;
5 typedef struct Dospart	Dospart;
6 typedef struct File File;
7 typedef struct Bootfs Bootfs;
8 
9 int fsread(File *file, void *a, long n);
10 int fsboot(Bootfs *fs, char *path, Boot *b);
11 int fswalk(Bootfs *fs, char *path, File *f);
12 
13 struct Dospart
14 {
15 	uchar flag;		/* active flag */
16 	uchar shead;		/* starting head */
17 	uchar scs[2];		/* starting cylinder/sector */
18 	uchar type;		/* partition type */
19 	uchar ehead;		/* ending head */
20 	uchar ecs[2];		/* ending cylinder/sector */
21 	uchar start[4];		/* starting sector */
22 	uchar len[4];		/* length in sectors */
23 };
24 
25 #define FAT12	0x01
26 #define FAT16	0x04
27 #define EXTEND	0x05
28 #define FATHUGE	0x06
29 #define FAT32	0x0b
30 #define FAT32X	0x0c
31 #define EXTHUGE	0x0f
32 #define DMDDO	0x54
33 #define PLAN9	0x39
34 #define LEXTEND 0x85
35 
36 struct Dosfile{
37 	Dos	*dos;		/* owning dos file system */
38 	char	name[8];
39 	char	ext[3];
40 	uchar	attr;
41 	long	length;
42 	long	pstart;		/* physical start cluster address */
43 	long	pcurrent;	/* physical current cluster address */
44 	long	lcurrent;	/* logical current cluster address */
45 	long	offset;
46 };
47 
48 struct Dos{
49 	long	start;		/* start of file system */
50 	int	sectsize;	/* in bytes */
51 	int	clustsize;	/* in sectors */
52 	int	clustbytes;	/* in bytes */
53 	int	nresrv;		/* sectors */
54 	int	nfats;		/* usually 2 */
55 	int	rootsize;	/* number of entries */
56 	int	volsize;	/* in sectors */
57 	int	mediadesc;
58 	int	fatsize;	/* in sectors */
59 	int	fatclusters;
60 	int	fatbits;	/* 12 or 16 */
61 	long	fataddr;	/* sector number */
62 	long	rootaddr;
63 	long	rootclust;
64 	long	dataaddr;
65 	long	freeptr;
66 };
67 
68 typedef struct Dosboot Dosboot;
69 typedef struct Dosdir Dosdir;
70 
71 struct Dosboot{
72 	uchar	magic[3];
73 	uchar	version[8];
74 	uchar	sectsize[2];
75 	uchar	clustsize;
76 	uchar	nresrv[2];
77 	uchar	nfats;
78 	uchar	rootsize[2];
79 	uchar	volsize[2];
80 	uchar	mediadesc;
81 	uchar	fatsize[2];
82 	uchar	trksize[2];
83 	uchar	nheads[2];
84 	uchar	nhidden[4];
85 	uchar	bigvolsize[4];
86 /* fat 32 */
87 	uchar	bigfatsize[4];
88 	uchar	extflags[2];
89 	uchar	fsversion[2];
90 	uchar	rootdirstartclust[4];
91 	uchar	fsinfosect[2];
92 	uchar	backupbootsect[2];
93 /* ???
94 	uchar	driveno;
95 	uchar	reserved0;
96 	uchar	bootsig;
97 	uchar	volid[4];
98 	uchar	label[11];
99 	uchar	reserved1[8];
100 */
101 };
102 
103 struct Dosdir{
104 	uchar	name[8];
105 	uchar	ext[3];
106 	uchar	attr;
107 	uchar	lowercase;
108 	uchar	hundredth;
109 	uchar	ctime[2];
110 	uchar	cdate[2];
111 	uchar	adate[2];
112 	uchar	highstart[2];
113 	uchar	mtime[2];
114 	uchar	mdate[2];
115 	uchar	start[2];
116 	uchar	length[4];
117 };
118 
119 #define	DOSRONLY	0x01
120 #define	DOSHIDDEN	0x02
121 #define	DOSSYSTEM	0x04
122 #define	DOSVLABEL	0x08
123 #define	DOSDIR	0x10
124 #define	DOSARCH	0x20
125 
126 // #pragma incomplete Bootfs
127 
128 struct File{
129 	union{
130 		Dosfile	dos;
131 		int walked;
132 	};
133 	Bootfs	*fs;
134 	char	*path;
135 };
136 
137 struct Bootfs{
138 	union {
139 		Dos dos;
140 	};
141 	Chan	*devch;
142 	char	*disk;
143 
144 	/* for *bios.c */
145 	int	dev;				/* device id */
146 	long	(*diskread)(Bootfs*, void*, long);	/* disk read routine */
147 	vlong	(*diskseek)(Bootfs*, vlong);	/* disk seek routine */
148 
149 	long	(*read)(File*, void*, long);
150 	int	(*walk)(File*, char*);
151 	File	root;
152 };
153 
154 extern int	dosinit(Bootfs*, char *);
155 
156 #define BADPTR(x) ((ulong)(x) < 0x80000000)
157