1/* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 25 * Copyright (c) 1995 Martin Husemann 26 * Some structure declaration borrowed from Paul Popelka 27 * (paulp@uts.amdahl.com), see /sys/msdosfs/ for reference. 28 * 29 * Redistribution and use in source and binary forms, with or without 30 * modification, are permitted provided that the following conditions 31 * are met: 32 * 1. Redistributions of source code must retain the above copyright 33 * notice, this list of conditions and the following disclaimer. 34 * 2. Redistributions in binary form must reproduce the above copyright 35 * notice, this list of conditions and the following disclaimer in the 36 * documentation and/or other materials provided with the distribution. 37 * 3. All advertising materials mentioning features or use of this software 38 * must display the following acknowledgement: 39 * This product includes software developed by Martin Husemann 40 * and Wolfgang Solfrank. 41 * 4. Neither the name of the University nor the names of its contributors 42 * may be used to endorse or promote products derived from this software 43 * without specific prior written permission. 44 * 45 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 48 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 49 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 51 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 */ 56 57#ifndef DOSFS_H 58#define DOSFS_H 59 60#define DOSBOOTBLOCKSIZE 512 61#define MAX_SECTOR_SIZE 4096 62 63typedef u_int32_t cl_t; /* type holding a cluster number */ 64 65/* 66 * architecture independent description of all the info stored in a 67 * FAT boot block. 68 */ 69struct bootblock { 70 u_int BytesPerSec; /* bytes per sector */ 71 u_int SecPerClust; /* sectors per cluster */ 72 u_int ResSectors; /* number of reserved sectors */ 73 u_int FATs; /* number of FATs */ 74 u_int RootDirEnts; /* number of root directory entries */ 75 u_int Media; /* media descriptor */ 76 u_int FATsmall; /* number of sectors per FAT */ 77 u_int SecPerTrack; /* sectors per track */ 78 u_int Heads; /* number of heads */ 79 u_int32_t Sectors; /* total number of sectors */ 80 u_int32_t HiddenSecs; /* # of hidden sectors */ 81 u_int32_t HugeSectors; /* # of sectors if bpbSectors == 0 */ 82 u_int FSInfo; /* FSInfo sector */ 83 u_int Backup; /* Backup of Bootblocks */ 84 cl_t RootCl; /* Start of Root Directory */ 85 cl_t FSFree; /* Number of free clusters acc. FSInfo */ 86 cl_t FSNext; /* Next free cluster acc. FSInfo */ 87 88 /* and some more calculated values */ 89 u_int flags; /* some flags: */ 90#define FAT32 1 /* this is a FAT32 filesystem */ 91 /* 92 * Maybe, we should separate out 93 * various parts of FAT32? XXX 94 */ 95 int ValidFat; /* valid fat if FAT32 non-mirrored */ 96 cl_t ClustMask; /* mask for entries in FAT */ 97 cl_t NumClusters; /* # of entries in a FAT */ 98 u_int32_t NumSectors; /* how many sectors are there */ 99 u_int32_t FATsecs; /* how many sectors are in FAT */ 100 u_int32_t NumFatEntries; /* how many entries really are there */ 101 u_int ClusterOffset; /* at what sector would sector 0 start */ 102 u_int ClusterSize; /* Cluster size in bytes */ 103 104 /* Now some statistics: */ 105 u_int NumFiles; /* # of plain files */ 106 u_int NumFree; /* # of free clusters */ 107 u_int NumBad; /* # of bad clusters */ 108}; 109 110/* 111 * Note: FAT32 only uses 28 bits for cluster numbers; the upper 4 bits are 112 * reserved. For ease of coding, reserved/bad/EOF values are sign extended 113 * to a full 32 bits regardless of FAT type. 114 * 115 * The CLUST_ERROR value is a value that can't be represented in the FAT. 116 * It is a synthetic value that indicates an error occured. 117 */ 118#define CLUST_FREE 0 /* 0 means cluster is free */ 119#define CLUST_FIRST 2 /* 2 is the minimum valid cluster number */ 120#define CLUST_ERROR 0xEEEEEEEE /* fat_get got an error */ 121#define CLUST_RSRVD 0xfffffff6 /* start of reserved clusters */ 122#define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 123#define CLUST_EOFS 0xfffffff8 /* start of EOF indicators */ 124#define CLUST_EOF 0xffffffff /* standard value for last cluster */ 125 126/* 127 * Masks for cluster values 128 */ 129#define CLUST12_MASK 0x0fff 130#define CLUST16_MASK 0xffff 131#define CLUST32_MASK 0x0fffffff 132 133#define DOSLONGNAMELEN 256 /* long name maximal length */ 134#define LRFIRST 0x40 /* first long name record */ 135#define LRNOMASK 0x1f /* mask to extract long record 136 * sequence number */ 137 138/* 139 * Architecture independent description of a directory entry 140 */ 141struct dosDirEntry { 142 struct dosDirEntry 143 *parent, /* previous tree level */ 144 *next, /* next brother */ 145 *child; /* if this is a directory */ 146 char name[8+1+3+1]; /* alias name first part */ 147 char lname[DOSLONGNAMELEN]; /* real name */ 148 uint flags; /* attributes */ 149 cl_t head; /* cluster no */ 150 cl_t end; /* cluster # to stop iterating at */ 151 u_int32_t size; /* filesize in bytes */ 152 u_int64_t physicalSize; /* Number of bytes in object's cluster chain */ 153 uint fsckflags; /* flags during fsck */ 154}; 155/* Flags in fsckflags: */ 156#define DIREMPTY 1 157#define DIREMPWARN 2 158 159/* 160 * TODO-list of unread directories 161 */ 162struct dirTodoNode { 163 struct dosDirEntry *dir; 164 struct dirTodoNode *next; 165}; 166 167#endif 168