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