1 /* $OpenBSD: dosfs.h,v 1.6 2014/06/16 18:33:33 tobias Exp $ */ 2 /* $NetBSD: dosfs.h,v 1.5 1997/10/17 11:19:41 ws Exp $ */ 3 4 /* 5 * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 6 * Copyright (c) 1995 Martin Husemann 7 * Some structure declaration borrowed from Paul Popelka 8 * (paulp@uts.amdahl.com), see /sys/msdosfs/ for reference. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef DOSFS_H 32 #define DOSFS_H 33 34 #define DOSBOOTBLOCKSIZE 512 35 36 typedef u_int32_t cl_t; /* type holding a cluster number */ 37 38 /* 39 * architecture independent description of all the info stored in a 40 * FAT boot block. 41 */ 42 struct bootblock { 43 u_int BytesPerSec; /* bytes per sector */ 44 u_int SecPerClust; /* sectors per cluster */ 45 u_int ResSectors; /* number of reserved sectors */ 46 u_int FATs; /* number of FATs */ 47 u_int RootDirEnts; /* number of root directory entries */ 48 u_int Media; /* media descriptor */ 49 u_int FATsmall; /* number of sectors per FAT */ 50 u_int SecPerTrack; /* sectors per track */ 51 u_int Heads; /* number of heads */ 52 u_int32_t Sectors; /* total number of sectors */ 53 u_int32_t HiddenSecs; /* # of hidden sectors */ 54 u_int32_t HugeSectors; /* # of sectors if bpbSectors == 0 */ 55 u_int FSInfo; /* FSInfo sector */ 56 u_int Backup; /* Backup of Bootblocks */ 57 cl_t RootCl; /* Start of Root Directory */ 58 cl_t FSFree; /* Number of free clusters acc. FSInfo */ 59 cl_t FSNext; /* Next free cluster acc. FSInfo */ 60 61 /* and some more calculated values */ 62 u_int flags; /* some flags: */ 63 #define FAT32 1 /* this is a FAT32 filesystem */ 64 /* 65 * Maybe, we should separate out 66 * various parts of FAT32? XXX 67 */ 68 int ValidFat; /* valid fat if FAT32 non-mirrored */ 69 cl_t ClustMask; /* mask for entries in FAT */ 70 cl_t NumClusters; /* # of entries in a FAT */ 71 u_int32_t NumSectors; /* how many sectors are there */ 72 u_int32_t FATsecs; /* how many sectors are in FAT */ 73 u_int32_t NumFatEntries; /* how many entries really are there */ 74 u_int ClusterOffset; /* at what sector would sector 0 start */ 75 u_int ClusterSize; /* Cluster size in bytes */ 76 77 /* Now some statistics: */ 78 u_int NumFiles; /* # of plain files */ 79 u_int NumFree; /* # of free clusters */ 80 u_int NumBad; /* # of bad clusters */ 81 }; 82 83 struct fatEntry { 84 cl_t next; /* pointer to next cluster */ 85 cl_t head; /* pointer to start of chain */ 86 u_int32_t length; /* number of clusters on chain */ 87 int flags; /* see below */ 88 }; 89 90 #define CLUST_FREE 0 /* 0 means cluster is free */ 91 #define CLUST_FIRST 2 /* 2 is the minimum valid cluster number */ 92 #define CLUST_RSRVD 0xfffffff6 /* start of reserved clusters */ 93 #define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 94 #define CLUST_EOFS 0xfffffff8 /* start of EOF indicators */ 95 #define CLUST_EOF 0xffffffff /* standard value for last cluster */ 96 97 /* 98 * Masks for cluster values 99 */ 100 #define CLUST12_MASK 0xfff 101 #define CLUST16_MASK 0xffff 102 #define CLUST32_MASK 0xfffffff 103 104 #define FAT_USED 1 /* This fat chain is used in a file */ 105 106 #define DOSLONGNAMELEN 256 /* long name maximal length */ 107 #define LRFIRST 0x40 /* first long name record */ 108 #define LRNOMASK 0x1f /* mask to extract long record 109 * sequence number */ 110 111 /* 112 * Architecture independent description of a directory entry 113 */ 114 struct dosDirEntry { 115 struct dosDirEntry 116 *parent, /* previous tree level */ 117 *next, /* next brother */ 118 *child; /* if this is a directory */ 119 char name[8+1+3+1]; /* alias name first part */ 120 char lname[DOSLONGNAMELEN]; /* real name */ 121 uint flags; /* attributes */ 122 cl_t head; /* cluster no */ 123 u_int32_t size; /* filesize in bytes */ 124 uint fsckflags; /* flags during fsck */ 125 }; 126 /* Flags in fsckflags: */ 127 #define DIREMPTY 1 128 #define DIREMPWARN 2 129 130 /* 131 * TODO-list of unread directories 132 */ 133 struct dirTodoNode { 134 struct dosDirEntry *dir; 135 struct dirTodoNode *next; 136 }; 137 138 #endif 139