14a5d661aSToomas Soome /* 24a5d661aSToomas Soome * Copyright (c) 1996, 1998 Robert Nordier 34a5d661aSToomas Soome * All rights reserved. 44a5d661aSToomas Soome * 54a5d661aSToomas Soome * Redistribution and use in source and binary forms, with or without 64a5d661aSToomas Soome * modification, are permitted provided that the following conditions 74a5d661aSToomas Soome * are met: 84a5d661aSToomas Soome * 1. Redistributions of source code must retain the above copyright 94a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer. 104a5d661aSToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 114a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer in 124a5d661aSToomas Soome * the documentation and/or other materials provided with the 134a5d661aSToomas Soome * distribution. 144a5d661aSToomas Soome * 154a5d661aSToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS 164a5d661aSToomas Soome * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 174a5d661aSToomas Soome * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 184a5d661aSToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY 194a5d661aSToomas Soome * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 204a5d661aSToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 214a5d661aSToomas Soome * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 224a5d661aSToomas Soome * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 234a5d661aSToomas Soome * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 244a5d661aSToomas Soome * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 254a5d661aSToomas Soome * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 264a5d661aSToomas Soome * 274a5d661aSToomas Soome */ 284a5d661aSToomas Soome 294a5d661aSToomas Soome #ifndef DOSIO_H 304a5d661aSToomas Soome #define DOSIO_H 314a5d661aSToomas Soome 324a5d661aSToomas Soome /* 334a5d661aSToomas Soome * DOS file attributes 344a5d661aSToomas Soome */ 354a5d661aSToomas Soome 364a5d661aSToomas Soome #define FA_RDONLY 001 /* read-only */ 374a5d661aSToomas Soome #define FA_HIDDEN 002 /* hidden file */ 384a5d661aSToomas Soome #define FA_SYSTEM 004 /* system file */ 394a5d661aSToomas Soome #define FA_LABEL 010 /* volume label */ 404a5d661aSToomas Soome #define FA_DIR 020 /* directory */ 414a5d661aSToomas Soome #define FA_ARCH 040 /* archive (file modified) */ 424a5d661aSToomas Soome #define FA_XDE 017 /* extended directory entry */ 434a5d661aSToomas Soome #define FA_MASK 077 /* all attributes */ 444a5d661aSToomas Soome 454a5d661aSToomas Soome /* 464a5d661aSToomas Soome * Macros to convert DOS-format 16-bit and 32-bit quantities 474a5d661aSToomas Soome */ 484a5d661aSToomas Soome 494a5d661aSToomas Soome #define cv2(p) ((u_int16_t)(p)[0] | \ 504a5d661aSToomas Soome ((u_int16_t)(p)[1] << 010)) 514a5d661aSToomas Soome #define cv4(p) ((u_int32_t)(p)[0] | \ 524a5d661aSToomas Soome ((u_int32_t)(p)[1] << 010) | \ 534a5d661aSToomas Soome ((u_int32_t)(p)[2] << 020) | \ 544a5d661aSToomas Soome ((u_int32_t)(p)[3] << 030)) 554a5d661aSToomas Soome 564a5d661aSToomas Soome /* 574a5d661aSToomas Soome * Directory, filesystem, and file structures. 584a5d661aSToomas Soome */ 594a5d661aSToomas Soome 604a5d661aSToomas Soome typedef struct { 614a5d661aSToomas Soome u_char x_case; /* case */ 624a5d661aSToomas Soome u_char c_hsec; /* created: secs/100 */ 634a5d661aSToomas Soome u_char c_time[2]; /* created: time */ 644a5d661aSToomas Soome u_char c_date[2]; /* created: date */ 654a5d661aSToomas Soome u_char a_date[2]; /* accessed: date */ 664a5d661aSToomas Soome u_char h_clus[2]; /* clus[hi] */ 674a5d661aSToomas Soome } DOS_DEX; 684a5d661aSToomas Soome 694a5d661aSToomas Soome typedef struct { 704a5d661aSToomas Soome u_char name[8]; /* name */ 714a5d661aSToomas Soome u_char ext[3]; /* extension */ 724a5d661aSToomas Soome u_char attr; /* attributes */ 734a5d661aSToomas Soome DOS_DEX dex; /* VFAT/FAT32 only */ 744a5d661aSToomas Soome u_char time[2]; /* modified: time */ 754a5d661aSToomas Soome u_char date[2]; /* modified: date */ 764a5d661aSToomas Soome u_char clus[2]; /* starting cluster */ 774a5d661aSToomas Soome u_char size[4]; /* size */ 784a5d661aSToomas Soome } DOS_DE; 794a5d661aSToomas Soome 804a5d661aSToomas Soome typedef struct { 814a5d661aSToomas Soome u_char seq; /* flags */ 824a5d661aSToomas Soome u_char name1[5][2]; /* 1st name area */ 834a5d661aSToomas Soome u_char attr; /* (see fat_de) */ 844a5d661aSToomas Soome u_char res; /* reserved */ 854a5d661aSToomas Soome u_char chk; /* checksum */ 864a5d661aSToomas Soome u_char name2[6][2]; /* 2nd name area */ 874a5d661aSToomas Soome u_char clus[2]; /* (see fat_de) */ 884a5d661aSToomas Soome u_char name3[2][2]; /* 3rd name area */ 894a5d661aSToomas Soome } DOS_XDE; 904a5d661aSToomas Soome 914a5d661aSToomas Soome typedef union { 924a5d661aSToomas Soome DOS_DE de; /* standard directory entry */ 934a5d661aSToomas Soome DOS_XDE xde; /* extended directory entry */ 944a5d661aSToomas Soome } DOS_DIR; 954a5d661aSToomas Soome 964a5d661aSToomas Soome typedef struct { 974a5d661aSToomas Soome struct open_file *fd; /* file descriptor */ 98*8c8024e2SToomas Soome u_char *fatbuf; /* FAT cache buffer */ 99*8c8024e2SToomas Soome u_int fatbuf_blknum; /* number of 128K block in FAT cache buffer */ 1004a5d661aSToomas Soome u_int links; /* active links to structure */ 1014a5d661aSToomas Soome u_int spc; /* sectors per cluster */ 1024a5d661aSToomas Soome u_int bsize; /* cluster size in bytes */ 1034a5d661aSToomas Soome u_int bshift; /* cluster conversion shift */ 1044a5d661aSToomas Soome u_int dirents; /* root directory entries */ 1054a5d661aSToomas Soome u_int spf; /* sectors per fat */ 1064a5d661aSToomas Soome u_int rdcl; /* root directory start cluster */ 1074a5d661aSToomas Soome u_int lsnfat; /* start of fat */ 1084a5d661aSToomas Soome u_int lsndir; /* start of root dir */ 1094a5d661aSToomas Soome u_int lsndta; /* start of data area */ 1104a5d661aSToomas Soome u_int fatsz; /* FAT entry size */ 1114a5d661aSToomas Soome u_int xclus; /* maximum cluster number */ 1124a5d661aSToomas Soome DOS_DE root; 1134a5d661aSToomas Soome } DOS_FS; 1144a5d661aSToomas Soome 1154a5d661aSToomas Soome typedef struct { 1164a5d661aSToomas Soome DOS_FS *fs; /* associated filesystem */ 1174a5d661aSToomas Soome DOS_DE de; /* directory entry */ 1184a5d661aSToomas Soome u_int offset; /* current offset */ 1194a5d661aSToomas Soome u_int c; /* last cluster read */ 1204a5d661aSToomas Soome } DOS_FILE; 1214a5d661aSToomas Soome 1224a5d661aSToomas Soome #endif /* !DOSIO_H */ 123