138451Smsmith/* 238451Smsmith * Copyright (c) 1996, 1998 Robert Nordier 338451Smsmith * All rights reserved. 438451Smsmith * 538451Smsmith * Redistribution and use in source and binary forms, with or without 638451Smsmith * modification, are permitted provided that the following conditions 738451Smsmith * are met: 838451Smsmith * 1. Redistributions of source code must retain the above copyright 938451Smsmith * notice, this list of conditions and the following disclaimer. 1038451Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1138451Smsmith * notice, this list of conditions and the following disclaimer in 1238451Smsmith * the documentation and/or other materials provided with the 1338451Smsmith * distribution. 1438451Smsmith * 1538451Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS 1638451Smsmith * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1738451Smsmith * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1838451Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY 1938451Smsmith * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2038451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 2138451Smsmith * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2238451Smsmith * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2338451Smsmith * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2438451Smsmith * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 2538451Smsmith * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2638451Smsmith */ 2738451Smsmith 2838451Smsmith#ifndef DOSIO_H 2938451Smsmith#define DOSIO_H 3038451Smsmith 3138451Smsmith/* 3238451Smsmith * DOS file attributes 3338451Smsmith */ 3438451Smsmith 3538451Smsmith#define FA_RDONLY 001 /* read-only */ 3638451Smsmith#define FA_HIDDEN 002 /* hidden file */ 3738451Smsmith#define FA_SYSTEM 004 /* system file */ 3838451Smsmith#define FA_LABEL 010 /* volume label */ 3938451Smsmith#define FA_DIR 020 /* directory */ 4038451Smsmith#define FA_ARCH 040 /* archive (file modified) */ 4138451Smsmith#define FA_XDE 017 /* extended directory entry */ 4238451Smsmith#define FA_MASK 077 /* all attributes */ 4338451Smsmith 4438451Smsmith/* 4538451Smsmith * Macros to convert DOS-format 16-bit and 32-bit quantities 4638451Smsmith */ 4738451Smsmith 4838451Smsmith#define cv2(p) ((u_int16_t)(p)[0] | \ 4938451Smsmith ((u_int16_t)(p)[1] << 010)) 5038451Smsmith#define cv4(p) ((u_int32_t)(p)[0] | \ 5138451Smsmith ((u_int32_t)(p)[1] << 010) | \ 5238451Smsmith ((u_int32_t)(p)[2] << 020) | \ 5338451Smsmith ((u_int32_t)(p)[3] << 030)) 5438451Smsmith 5538451Smsmith/* 5638451Smsmith * Directory, filesystem, and file structures. 5738451Smsmith */ 5838451Smsmith 5938451Smsmithtypedef struct { 6038451Smsmith u_char x_case; /* case */ 6138451Smsmith u_char c_hsec; /* created: secs/100 */ 6238451Smsmith u_char c_time[2]; /* created: time */ 6338451Smsmith u_char c_date[2]; /* created: date */ 6438451Smsmith u_char a_date[2]; /* accessed: date */ 6538451Smsmith u_char h_clus[2]; /* clus[hi] */ 6638451Smsmith} DOS_DEX; 6738451Smsmith 6838451Smsmithtypedef struct { 6938451Smsmith u_char name[8]; /* name */ 7038451Smsmith u_char ext[3]; /* extension */ 7138451Smsmith u_char attr; /* attributes */ 7238451Smsmith DOS_DEX dex; /* VFAT/FAT32 only */ 7338451Smsmith u_char time[2]; /* modified: time */ 7438451Smsmith u_char date[2]; /* modified: date */ 7538451Smsmith u_char clus[2]; /* starting cluster */ 7638451Smsmith u_char size[4]; /* size */ 7738451Smsmith} DOS_DE; 7838451Smsmith 7938451Smsmithtypedef struct { 8038451Smsmith u_char seq; /* flags */ 8138451Smsmith u_char name1[5][2]; /* 1st name area */ 8238451Smsmith u_char attr; /* (see fat_de) */ 8338451Smsmith u_char res; /* reserved */ 8438451Smsmith u_char chk; /* checksum */ 8538451Smsmith u_char name2[6][2]; /* 2nd name area */ 8638451Smsmith u_char clus[2]; /* (see fat_de) */ 8738451Smsmith u_char name3[2][2]; /* 3rd name area */ 8838451Smsmith} DOS_XDE; 8938451Smsmith 9038451Smsmithtypedef union { 9138451Smsmith DOS_DE de; /* standard directory entry */ 9238451Smsmith DOS_XDE xde; /* extended directory entry */ 9338451Smsmith} DOS_DIR; 9438451Smsmith 9538451Smsmithtypedef struct { 9638451Smsmith struct open_file *fd; /* file descriptor */ 9738451Smsmith u_char *buf; /* buffer */ 9838451Smsmith u_int bufsec; /* buffered sector */ 9938451Smsmith u_int links; /* active links to structure */ 10038451Smsmith u_int spc; /* sectors per cluster */ 10138451Smsmith u_int bsize; /* cluster size in bytes */ 10238451Smsmith u_int bshift; /* cluster conversion shift */ 10338451Smsmith u_int dirents; /* root directory entries */ 10438451Smsmith u_int spf; /* sectors per fat */ 10538451Smsmith u_int rdcl; /* root directory start cluster */ 10638451Smsmith u_int lsnfat; /* start of fat */ 10738451Smsmith u_int lsndir; /* start of root dir */ 10838451Smsmith u_int lsndta; /* start of data area */ 10938451Smsmith u_int fatsz; /* FAT entry size */ 11038451Smsmith u_int xclus; /* maximum cluster number */ 11138451Smsmith} DOS_FS; 11238451Smsmith 11338451Smsmithtypedef struct { 11438451Smsmith DOS_FS *fs; /* associated filesystem */ 11538451Smsmith DOS_DE de; /* directory entry */ 11638451Smsmith u_int offset; /* current offset */ 11738451Smsmith u_int c; /* last cluster read */ 11838451Smsmith} DOS_FILE; 11938451Smsmith 12038451Smsmith#endif /* !DOSIO_H */ 121