1*d15e4a5dSmlelstv /* $NetBSD: dosfs.h,v 1.8 2015/01/02 06:21:28 mlelstv Exp $ */ 26ae4c91aSws 36ae4c91aSws /* 4d445160eSws * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 56ae4c91aSws * Copyright (c) 1995 Martin Husemann 66ae4c91aSws * Some structure declaration borrowed from Paul Popelka 7b47f782dSmartin * (paulp@uts.amdahl.com), see sys/fs/msdosfs/ for reference. 86ae4c91aSws * 96ae4c91aSws * Redistribution and use in source and binary forms, with or without 106ae4c91aSws * modification, are permitted provided that the following conditions 116ae4c91aSws * are met: 126ae4c91aSws * 1. Redistributions of source code must retain the above copyright 136ae4c91aSws * notice, this list of conditions and the following disclaimer. 146ae4c91aSws * 2. Redistributions in binary form must reproduce the above copyright 156ae4c91aSws * notice, this list of conditions and the following disclaimer in the 166ae4c91aSws * documentation and/or other materials provided with the distribution. 176ae4c91aSws * 186ae4c91aSws * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 196ae4c91aSws * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 206ae4c91aSws * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 216ae4c91aSws * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 226ae4c91aSws * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 236ae4c91aSws * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246ae4c91aSws * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256ae4c91aSws * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266ae4c91aSws * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 276ae4c91aSws * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286ae4c91aSws */ 296ae4c91aSws 306ae4c91aSws #ifndef DOSFS_H 316ae4c91aSws #define DOSFS_H 326ae4c91aSws 336ae4c91aSws #define DOSBOOTBLOCKSIZE 512 346ae4c91aSws 35d445160eSws typedef u_int32_t cl_t; /* type holding a cluster number */ 366ae4c91aSws 376ae4c91aSws /* 386ae4c91aSws * architecture independent description of all the info stored in a 396ae4c91aSws * FAT boot block. 406ae4c91aSws */ 416ae4c91aSws struct bootblock { 426ae4c91aSws u_int BytesPerSec; /* bytes per sector */ 436ae4c91aSws u_int SecPerClust; /* sectors per cluster */ 446ae4c91aSws u_int ResSectors; /* number of reserved sectors */ 456ae4c91aSws u_int FATs; /* number of FATs */ 466ae4c91aSws u_int RootDirEnts; /* number of root directory entries */ 476ae4c91aSws u_int Media; /* media descriptor */ 48d445160eSws u_int FATsmall; /* number of sectors per FAT */ 496ae4c91aSws u_int SecPerTrack; /* sectors per track */ 506ae4c91aSws u_int Heads; /* number of heads */ 51d445160eSws u_int32_t Sectors; /* total number of sectors */ 526ae4c91aSws u_int32_t HiddenSecs; /* # of hidden sectors */ 536ae4c91aSws u_int32_t HugeSectors; /* # of sectors if bpbSectors == 0 */ 54d445160eSws u_int FSInfo; /* FSInfo sector */ 55d445160eSws u_int Backup; /* Backup of Bootblocks */ 56d445160eSws cl_t RootCl; /* Start of Root Directory */ 57d445160eSws cl_t FSFree; /* Number of free clusters acc. FSInfo */ 58d445160eSws cl_t FSNext; /* Next free cluster acc. FSInfo */ 596ae4c91aSws 606ae4c91aSws /* and some more calculated values */ 61d445160eSws u_int flags; /* some flags: */ 62d445160eSws #define FAT32 1 /* this is a FAT32 filesystem */ 63d445160eSws /* 64d445160eSws * Maybe, we should separate out 65d445160eSws * various parts of FAT32? XXX 66d445160eSws */ 67d445160eSws int ValidFat; /* valid fat if FAT32 non-mirrored */ 68d445160eSws cl_t ClustMask; /* mask for entries in FAT */ 696ae4c91aSws cl_t NumClusters; /* # of entries in a FAT */ 706ae4c91aSws u_int32_t NumSectors; /* how many sectors are there */ 71d445160eSws u_int32_t FATsecs; /* how many sectors are in FAT */ 726ae4c91aSws u_int32_t NumFatEntries; /* how many entries really are there */ 73*d15e4a5dSmlelstv u_int FirstCluster; /* at what sector is Cluster CLUST_FIRST */ 746ae4c91aSws u_int ClusterSize; /* Cluster size in bytes */ 756ae4c91aSws 766ae4c91aSws /* Now some statistics: */ 776ae4c91aSws u_int NumFiles; /* # of plain files */ 786ae4c91aSws u_int NumFree; /* # of free clusters */ 79fdbcbfc2Sws u_int NumBad; /* # of bad clusters */ 806ae4c91aSws }; 816ae4c91aSws 826ae4c91aSws struct fatEntry { 836ae4c91aSws cl_t next; /* pointer to next cluster */ 846ae4c91aSws cl_t head; /* pointer to start of chain */ 856ae4c91aSws u_int32_t length; /* number of clusters on chain */ 8625e3d62eSws int flags; /* see below */ 876ae4c91aSws }; 886ae4c91aSws 896ae4c91aSws #define CLUST_FREE 0 /* 0 means cluster is free */ 906ae4c91aSws #define CLUST_FIRST 2 /* 2 is the minimum valid cluster number */ 91d445160eSws #define CLUST_RSRVD 0xfffffff6 /* start of reserved clusters */ 92d445160eSws #define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 93d445160eSws #define CLUST_EOFS 0xfffffff8 /* start of EOF indicators */ 94d445160eSws #define CLUST_EOF 0xffffffff /* standard value for last cluster */ 95d445160eSws 96d445160eSws /* 97d445160eSws * Masks for cluster values 98d445160eSws */ 99d445160eSws #define CLUST12_MASK 0xfff 100d445160eSws #define CLUST16_MASK 0xffff 101d445160eSws #define CLUST32_MASK 0xfffffff 1026ae4c91aSws 10325e3d62eSws #define FAT_USED 1 /* This fat chain is used in a file */ 10425e3d62eSws 1056ae4c91aSws #define DOSLONGNAMELEN 256 /* long name maximal length */ 1066ae4c91aSws #define LRFIRST 0x40 /* first long name record */ 1076ae4c91aSws #define LRNOMASK 0x1f /* mask to extract long record 1086ae4c91aSws * sequence number */ 1096ae4c91aSws 1106ae4c91aSws /* 1116ae4c91aSws * Architecture independent description of a directory entry 1126ae4c91aSws */ 1136ae4c91aSws struct dosDirEntry { 1146ae4c91aSws struct dosDirEntry 1156ae4c91aSws *parent, /* previous tree level */ 1166ae4c91aSws *next, /* next brother */ 1176ae4c91aSws *child; /* if this is a directory */ 1186ae4c91aSws char name[8+1+3+1]; /* alias name first part */ 1196ae4c91aSws char lname[DOSLONGNAMELEN]; /* real name */ 1206ae4c91aSws uint flags; /* attributes */ 1216ae4c91aSws cl_t head; /* cluster no */ 1226ae4c91aSws u_int32_t size; /* filesize in bytes */ 1236ae4c91aSws uint fsckflags; /* flags during fsck */ 1246ae4c91aSws }; 1256ae4c91aSws /* Flags in fsckflags: */ 1266ae4c91aSws #define DIREMPTY 1 1276ae4c91aSws #define DIREMPWARN 2 1286ae4c91aSws 1296ae4c91aSws /* 1306ae4c91aSws * TODO-list of unread directories 1316ae4c91aSws */ 1326ae4c91aSws struct dirTodoNode { 1336ae4c91aSws struct dosDirEntry *dir; 1346ae4c91aSws struct dirTodoNode *next; 1356ae4c91aSws }; 1366ae4c91aSws 1376ae4c91aSws #endif 138