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