]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/dossrv/dat.h
Backed out changeset 2737b9af622b
[plan9front.git] / sys / src / cmd / dossrv / dat.h
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         vlong   volsize;                /* in sectors */
127         int     mediadesc;
128         vlong   fatsize;                /* in sectors */
129         long    fatclusters;
130         int     fatbits;                /* 12, 16, or 32 */
131         vlong   fataddr;                /* sector number of first valid fat entry */
132         vlong   rootaddr;               /* for fat16 or fat12, sector of root dir */
133         vlong   dataaddr;               /* initial sector of data clusters */
134         long    rootstart;              /* for fat32, cluster of root dir */
135         long    freeptr;                /* next free cluster candidate */
136         long    freeclusters;           /* count of free clusters, for fat32 */
137         vlong   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         MAXFILELEN      = 0xFFFFFFFFUL,
147 };
148
149 struct Dosdir{
150         uchar   name[8];
151         uchar   ext[3];
152         uchar   attr;
153         uchar   reserved[1];
154         uchar   ctimetenth;
155         uchar   ctime[2];               /* creation time */
156         uchar   cdate[2];               /* creation date */
157         uchar   adate[2];               /* last access date */
158         uchar   hstart[2];              /* high bits of start for fat32 */
159         uchar   time[2];                /* last modified time */
160         uchar   date[2];                /* last modified date */
161         uchar   start[2];
162         uchar   length[4];
163 };
164
165 enum
166 {
167         DRONLY          = 0x01,
168         DHIDDEN         = 0x02,
169         DSYSTEM         = 0x04,
170         DVLABEL         = 0x08,
171         DDIR            = 0x10,
172         DARCH           = 0x20,
173 };
174
175 #define GSHORT(p)       (((ushort)(p)[0])|(ushort)(p)[1]<<8)
176 #define GLONG(p)        (((ulong)(p)[0])|(ulong)(p)[1]<<8|(ulong)(p)[2]<<16|(ulong)(p)[3]<<24)
177 #define PSHORT(p,v)     ((p)[0]=(v),(p)[1]=(v)>>8)
178 #define PLONG(p,v)      ((p)[0]=(v),(p)[1]=(v)>>8,(p)[2]=(v)>>16,(p)[3]=(v)>>24)
179
180 struct Dosptr{
181         vlong   addr;           /* sector & entry within of file's directory entry */
182         vlong   paddr;          /* of parent's directory entry */
183         ulong   offset;
184         ulong   poffset;
185         ulong   iclust;         /* ordinal within file */
186         ulong   clust;
187         vlong   naddr;          /* next block in directory (for writing multi entry elements) */
188         vlong   prevaddr;
189         Iosect *p;
190         Dosdir *d;
191 };
192
193 #define QIDPATH(p)      ((p)->addr*(Sectorsize/DOSDIRSIZE) + \
194                          (p)->offset/DOSDIRSIZE)
195
196 struct Xfs{
197         Xfs     *next;
198         int omode;              /* of file containing external fs */
199         char    *name;          /* of file containing external f.s. */
200         Qid     qid;            /* of file containing external f.s. */
201         long    ref;            /* attach count */
202         Qid     rootqid;        /* of plan9 constructed root directory */
203         uchar   isfat32;        /* is a fat 32 file system? */
204         short   dev;
205         short   fmt;
206         vlong   offset;
207         void    *ptr;
208 };
209
210 struct Xfile{
211         Xfile   *next;          /* in hash bucket */
212         long    fid;
213         ulong   flags;
214         Qid     qid;
215         Xfs     *xf;
216         Dosptr  *ptr;
217 };
218
219 enum{
220         Asis, Clean, Clunk
221 };
222
223 enum{
224         Invalid, Short, ShortLower, Long
225 };
226
227 enum{   /* Xfile flags */
228         Oread = 1,
229         Owrite = 2,
230         Orclose = 4,
231         Omodes = 3,
232 };
233
234 enum{
235         Enevermind,
236         Eformat,
237         Eio,
238         Enoauth,
239         Enomem,
240         Enonexist,
241         Eperm,
242         Enofilsys,
243         Eauth,
244         Econtig,
245         Ebadfcall,
246         Ebadstat,
247         Eversion,
248         Etoolong,
249         Eerrstr,
250         ESIZE
251 };
252
253 extern int      chatty;
254 extern int      errno;
255 extern int      readonly;
256 extern char     *deffile;
257 extern int trspaces;