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