/*1* Copyright (c) 1996, 1998 Robert Nordier2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in11* the documentation and/or other materials provided with the12* distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS15* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE20* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS21* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER22* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR23* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN24* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#ifndef DOSIO_H28#define DOSIO_H2930/*31* DOS file attributes32*/3334#define FA_RDONLY 001 /* read-only */35#define FA_HIDDEN 002 /* hidden file */36#define FA_SYSTEM 004 /* system file */37#define FA_LABEL 010 /* volume label */38#define FA_DIR 020 /* directory */39#define FA_ARCH 040 /* archive (file modified) */40#define FA_XDE 017 /* extended directory entry */41#define FA_MASK 077 /* all attributes */4243/*44* Macros to convert DOS-format 16-bit and 32-bit quantities45*/4647#define cv2(p) ((uint16_t)(p)[0] | \48((uint16_t)(p)[1] << 010))49#define cv4(p) ((uint32_t)(p)[0] | \50((uint32_t)(p)[1] << 010) | \51((uint32_t)(p)[2] << 020) | \52((uint32_t)(p)[3] << 030))5354/*55* Directory, filesystem, and file structures.56*/5758typedef struct {59u_char x_case; /* case */60u_char c_hsec; /* created: secs/100 */61u_char c_time[2]; /* created: time */62u_char c_date[2]; /* created: date */63u_char a_date[2]; /* accessed: date */64u_char h_clus[2]; /* clus[hi] */65} DOS_DEX;6667typedef struct {68u_char name[8]; /* name */69u_char ext[3]; /* extension */70u_char attr; /* attributes */71DOS_DEX dex; /* VFAT/FAT32 only */72u_char time[2]; /* modified: time */73u_char date[2]; /* modified: date */74u_char clus[2]; /* starting cluster */75u_char size[4]; /* size */76} DOS_DE;7778typedef struct {79u_char seq; /* flags */80u_char name1[5][2]; /* 1st name area */81u_char attr; /* (see fat_de) */82u_char res; /* reserved */83u_char chk; /* checksum */84u_char name2[6][2]; /* 2nd name area */85u_char clus[2]; /* (see fat_de) */86u_char name3[2][2]; /* 3rd name area */87} DOS_XDE;8889typedef union {90DOS_DE de; /* standard directory entry */91DOS_XDE xde; /* extended directory entry */92} DOS_DIR;9394typedef struct {95struct open_file *fd; /* file descriptor */96u_char *secbuf; /* sector cache */97u_char *fatbuf; /* FAT cache buffer */98u_int fatbuf_blknum; /* number of 128K block in FAT cache buffer */99u_int links; /* active links to structure */100u_int sshift; /* sector shift */101u_int spc; /* sectors per cluster */102u_int bsize; /* cluster size in bytes */103u_int bshift; /* cluster conversion shift */104u_int dshift; /* directory entries shift */105u_int dirents; /* root directory entries */106u_int spf; /* sectors per fat */107u_int rdcl; /* root directory start cluster */108u_int lsnfat; /* start of fat */109u_int lsndir; /* start of root dir */110u_int lsndta; /* start of data area */111u_int fatsz; /* FAT entry size */112u_int xclus; /* maximum cluster number */113DOS_DE root;114} DOS_FS;115116typedef struct {117DOS_FS *fs; /* associated filesystem */118DOS_DE de; /* directory entry */119u_int offset; /* current offset */120u_int c; /* last cluster read */121} DOS_FILE;122123#endif /* !DOSIO_H */124125126