xref: /titanic_52/usr/src/boot/lib/libstand/dosfs.h (revision 4a5d661a82b942b6538acd26209d959ce98b593a)
1*4a5d661aSToomas Soome /*
2*4a5d661aSToomas Soome  * Copyright (c) 1996, 1998 Robert Nordier
3*4a5d661aSToomas Soome  * All rights reserved.
4*4a5d661aSToomas Soome  *
5*4a5d661aSToomas Soome  * Redistribution and use in source and binary forms, with or without
6*4a5d661aSToomas Soome  * modification, are permitted provided that the following conditions
7*4a5d661aSToomas Soome  * are met:
8*4a5d661aSToomas Soome  * 1. Redistributions of source code must retain the above copyright
9*4a5d661aSToomas Soome  *    notice, this list of conditions and the following disclaimer.
10*4a5d661aSToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11*4a5d661aSToomas Soome  *    notice, this list of conditions and the following disclaimer in
12*4a5d661aSToomas Soome  *    the documentation and/or other materials provided with the
13*4a5d661aSToomas Soome  *    distribution.
14*4a5d661aSToomas Soome  *
15*4a5d661aSToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
16*4a5d661aSToomas Soome  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*4a5d661aSToomas Soome  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*4a5d661aSToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY
19*4a5d661aSToomas Soome  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*4a5d661aSToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21*4a5d661aSToomas Soome  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*4a5d661aSToomas Soome  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23*4a5d661aSToomas Soome  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24*4a5d661aSToomas Soome  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25*4a5d661aSToomas Soome  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*4a5d661aSToomas Soome  *
27*4a5d661aSToomas Soome  * $FreeBSD$
28*4a5d661aSToomas Soome  */
29*4a5d661aSToomas Soome 
30*4a5d661aSToomas Soome #ifndef DOSIO_H
31*4a5d661aSToomas Soome #define DOSIO_H
32*4a5d661aSToomas Soome 
33*4a5d661aSToomas Soome /*
34*4a5d661aSToomas Soome  * DOS file attributes
35*4a5d661aSToomas Soome  */
36*4a5d661aSToomas Soome 
37*4a5d661aSToomas Soome #define FA_RDONLY  001          /* read-only */
38*4a5d661aSToomas Soome #define FA_HIDDEN  002          /* hidden file */
39*4a5d661aSToomas Soome #define FA_SYSTEM  004          /* system file */
40*4a5d661aSToomas Soome #define FA_LABEL   010          /* volume label */
41*4a5d661aSToomas Soome #define FA_DIR     020          /* directory */
42*4a5d661aSToomas Soome #define FA_ARCH    040          /* archive (file modified) */
43*4a5d661aSToomas Soome #define FA_XDE     017          /* extended directory entry */
44*4a5d661aSToomas Soome #define FA_MASK    077          /* all attributes */
45*4a5d661aSToomas Soome 
46*4a5d661aSToomas Soome /*
47*4a5d661aSToomas Soome  * Macros to convert DOS-format 16-bit and 32-bit quantities
48*4a5d661aSToomas Soome  */
49*4a5d661aSToomas Soome 
50*4a5d661aSToomas Soome #define cv2(p)  ((u_int16_t)(p)[0] |         \
51*4a5d661aSToomas Soome                 ((u_int16_t)(p)[1] << 010))
52*4a5d661aSToomas Soome #define cv4(p)  ((u_int32_t)(p)[0] |          \
53*4a5d661aSToomas Soome                 ((u_int32_t)(p)[1] << 010) |  \
54*4a5d661aSToomas Soome                 ((u_int32_t)(p)[2] << 020) |  \
55*4a5d661aSToomas Soome                 ((u_int32_t)(p)[3] << 030))
56*4a5d661aSToomas Soome 
57*4a5d661aSToomas Soome /*
58*4a5d661aSToomas Soome  * Directory, filesystem, and file structures.
59*4a5d661aSToomas Soome  */
60*4a5d661aSToomas Soome 
61*4a5d661aSToomas Soome typedef struct {
62*4a5d661aSToomas Soome     u_char x_case;              /* case */
63*4a5d661aSToomas Soome     u_char c_hsec;              /* created: secs/100 */
64*4a5d661aSToomas Soome     u_char c_time[2];           /* created: time */
65*4a5d661aSToomas Soome     u_char c_date[2];           /* created: date */
66*4a5d661aSToomas Soome     u_char a_date[2];           /* accessed: date */
67*4a5d661aSToomas Soome     u_char h_clus[2];           /* clus[hi] */
68*4a5d661aSToomas Soome } DOS_DEX;
69*4a5d661aSToomas Soome 
70*4a5d661aSToomas Soome typedef struct {
71*4a5d661aSToomas Soome     u_char name[8];             /* name */
72*4a5d661aSToomas Soome     u_char ext[3];              /* extension */
73*4a5d661aSToomas Soome     u_char attr;                /* attributes */
74*4a5d661aSToomas Soome     DOS_DEX dex;                /* VFAT/FAT32 only */
75*4a5d661aSToomas Soome     u_char time[2];             /* modified: time */
76*4a5d661aSToomas Soome     u_char date[2];             /* modified: date */
77*4a5d661aSToomas Soome     u_char clus[2];             /* starting cluster */
78*4a5d661aSToomas Soome     u_char size[4];             /* size */
79*4a5d661aSToomas Soome } DOS_DE;
80*4a5d661aSToomas Soome 
81*4a5d661aSToomas Soome typedef struct {
82*4a5d661aSToomas Soome     u_char seq;                 /* flags */
83*4a5d661aSToomas Soome     u_char name1[5][2];         /* 1st name area */
84*4a5d661aSToomas Soome     u_char attr;                /* (see fat_de) */
85*4a5d661aSToomas Soome     u_char res;                 /* reserved */
86*4a5d661aSToomas Soome     u_char chk;                 /* checksum */
87*4a5d661aSToomas Soome     u_char name2[6][2];         /* 2nd name area */
88*4a5d661aSToomas Soome     u_char clus[2];             /* (see fat_de) */
89*4a5d661aSToomas Soome     u_char name3[2][2];         /* 3rd name area */
90*4a5d661aSToomas Soome } DOS_XDE;
91*4a5d661aSToomas Soome 
92*4a5d661aSToomas Soome typedef union {
93*4a5d661aSToomas Soome     DOS_DE de;                  /* standard directory entry */
94*4a5d661aSToomas Soome     DOS_XDE xde;                /* extended directory entry */
95*4a5d661aSToomas Soome } DOS_DIR;
96*4a5d661aSToomas Soome 
97*4a5d661aSToomas Soome typedef struct {
98*4a5d661aSToomas Soome     struct open_file *fd;       /* file descriptor */
99*4a5d661aSToomas Soome     u_int links;                /* active links to structure */
100*4a5d661aSToomas Soome     u_int spc;                  /* sectors per cluster */
101*4a5d661aSToomas Soome     u_int bsize;                /* cluster size in bytes */
102*4a5d661aSToomas Soome     u_int bshift;               /* cluster conversion shift */
103*4a5d661aSToomas Soome     u_int dirents;              /* root directory entries */
104*4a5d661aSToomas Soome     u_int spf;                  /* sectors per fat */
105*4a5d661aSToomas Soome     u_int rdcl;                 /* root directory start cluster */
106*4a5d661aSToomas Soome     u_int lsnfat;               /* start of fat */
107*4a5d661aSToomas Soome     u_int lsndir;               /* start of root dir */
108*4a5d661aSToomas Soome     u_int lsndta;               /* start of data area */
109*4a5d661aSToomas Soome     u_int fatsz;                /* FAT entry size */
110*4a5d661aSToomas Soome     u_int xclus;                /* maximum cluster number */
111*4a5d661aSToomas Soome     DOS_DE root;
112*4a5d661aSToomas Soome } DOS_FS;
113*4a5d661aSToomas Soome 
114*4a5d661aSToomas Soome typedef struct {
115*4a5d661aSToomas Soome     DOS_FS *fs;                 /* associated filesystem */
116*4a5d661aSToomas Soome     DOS_DE de;                  /* directory entry */
117*4a5d661aSToomas Soome     u_int offset;               /* current offset */
118*4a5d661aSToomas Soome     u_int c;                    /* last cluster read */
119*4a5d661aSToomas Soome } DOS_FILE;
120*4a5d661aSToomas Soome 
121*4a5d661aSToomas Soome #endif  /* !DOSIO_H */
122