1*14e30480Stobias /* $OpenBSD: dosfs.h,v 1.6 2014/06/16 18:33:33 tobias Exp $ */ 2b099d67bSprovos /* $NetBSD: dosfs.h,v 1.5 1997/10/17 11:19:41 ws Exp $ */ 39646ab25Sderaadt 49646ab25Sderaadt /* 5b099d67bSprovos * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 69646ab25Sderaadt * Copyright (c) 1995 Martin Husemann 79646ab25Sderaadt * Some structure declaration borrowed from Paul Popelka 89646ab25Sderaadt * (paulp@uts.amdahl.com), see /sys/msdosfs/ for reference. 99646ab25Sderaadt * 109646ab25Sderaadt * Redistribution and use in source and binary forms, with or without 119646ab25Sderaadt * modification, are permitted provided that the following conditions 129646ab25Sderaadt * are met: 139646ab25Sderaadt * 1. Redistributions of source code must retain the above copyright 149646ab25Sderaadt * notice, this list of conditions and the following disclaimer. 159646ab25Sderaadt * 2. Redistributions in binary form must reproduce the above copyright 169646ab25Sderaadt * notice, this list of conditions and the following disclaimer in the 179646ab25Sderaadt * documentation and/or other materials provided with the distribution. 189646ab25Sderaadt * 199646ab25Sderaadt * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 209646ab25Sderaadt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 219646ab25Sderaadt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 229646ab25Sderaadt * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 239646ab25Sderaadt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 249646ab25Sderaadt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 259646ab25Sderaadt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 269646ab25Sderaadt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 279646ab25Sderaadt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 289646ab25Sderaadt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 299646ab25Sderaadt */ 309646ab25Sderaadt 319646ab25Sderaadt #ifndef DOSFS_H 329646ab25Sderaadt #define DOSFS_H 339646ab25Sderaadt 349646ab25Sderaadt #define DOSBOOTBLOCKSIZE 512 359646ab25Sderaadt 36b099d67bSprovos typedef u_int32_t cl_t; /* type holding a cluster number */ 379646ab25Sderaadt 389646ab25Sderaadt /* 399646ab25Sderaadt * architecture independent description of all the info stored in a 409646ab25Sderaadt * FAT boot block. 419646ab25Sderaadt */ 429646ab25Sderaadt struct bootblock { 439646ab25Sderaadt u_int BytesPerSec; /* bytes per sector */ 449646ab25Sderaadt u_int SecPerClust; /* sectors per cluster */ 459646ab25Sderaadt u_int ResSectors; /* number of reserved sectors */ 469646ab25Sderaadt u_int FATs; /* number of FATs */ 479646ab25Sderaadt u_int RootDirEnts; /* number of root directory entries */ 489646ab25Sderaadt u_int Media; /* media descriptor */ 49b099d67bSprovos u_int FATsmall; /* number of sectors per FAT */ 509646ab25Sderaadt u_int SecPerTrack; /* sectors per track */ 519646ab25Sderaadt u_int Heads; /* number of heads */ 52b099d67bSprovos u_int32_t Sectors; /* total number of sectors */ 539646ab25Sderaadt u_int32_t HiddenSecs; /* # of hidden sectors */ 549646ab25Sderaadt u_int32_t HugeSectors; /* # of sectors if bpbSectors == 0 */ 55b099d67bSprovos u_int FSInfo; /* FSInfo sector */ 56b099d67bSprovos u_int Backup; /* Backup of Bootblocks */ 57b099d67bSprovos cl_t RootCl; /* Start of Root Directory */ 58b099d67bSprovos cl_t FSFree; /* Number of free clusters acc. FSInfo */ 59b099d67bSprovos cl_t FSNext; /* Next free cluster acc. FSInfo */ 609646ab25Sderaadt 619646ab25Sderaadt /* and some more calculated values */ 62b099d67bSprovos u_int flags; /* some flags: */ 63b099d67bSprovos #define FAT32 1 /* this is a FAT32 filesystem */ 64b099d67bSprovos /* 65b099d67bSprovos * Maybe, we should separate out 66b099d67bSprovos * various parts of FAT32? XXX 67b099d67bSprovos */ 68b099d67bSprovos int ValidFat; /* valid fat if FAT32 non-mirrored */ 69b099d67bSprovos cl_t ClustMask; /* mask for entries in FAT */ 709646ab25Sderaadt cl_t NumClusters; /* # of entries in a FAT */ 719646ab25Sderaadt u_int32_t NumSectors; /* how many sectors are there */ 72b099d67bSprovos u_int32_t FATsecs; /* how many sectors are in FAT */ 739646ab25Sderaadt u_int32_t NumFatEntries; /* how many entries really are there */ 749646ab25Sderaadt u_int ClusterOffset; /* at what sector would sector 0 start */ 759646ab25Sderaadt u_int ClusterSize; /* Cluster size in bytes */ 769646ab25Sderaadt 779646ab25Sderaadt /* Now some statistics: */ 789646ab25Sderaadt u_int NumFiles; /* # of plain files */ 799646ab25Sderaadt u_int NumFree; /* # of free clusters */ 80c7481c7eSmillert u_int NumBad; /* # of bad clusters */ 819646ab25Sderaadt }; 829646ab25Sderaadt 839646ab25Sderaadt struct fatEntry { 849646ab25Sderaadt cl_t next; /* pointer to next cluster */ 859646ab25Sderaadt cl_t head; /* pointer to start of chain */ 869646ab25Sderaadt u_int32_t length; /* number of clusters on chain */ 872a4cde9cSderaadt int flags; /* see below */ 889646ab25Sderaadt }; 899646ab25Sderaadt 909646ab25Sderaadt #define CLUST_FREE 0 /* 0 means cluster is free */ 919646ab25Sderaadt #define CLUST_FIRST 2 /* 2 is the minimum valid cluster number */ 92b099d67bSprovos #define CLUST_RSRVD 0xfffffff6 /* start of reserved clusters */ 93b099d67bSprovos #define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ 94b099d67bSprovos #define CLUST_EOFS 0xfffffff8 /* start of EOF indicators */ 95b099d67bSprovos #define CLUST_EOF 0xffffffff /* standard value for last cluster */ 96b099d67bSprovos 97b099d67bSprovos /* 98b099d67bSprovos * Masks for cluster values 99b099d67bSprovos */ 100b099d67bSprovos #define CLUST12_MASK 0xfff 101b099d67bSprovos #define CLUST16_MASK 0xffff 102b099d67bSprovos #define CLUST32_MASK 0xfffffff 1039646ab25Sderaadt 1042a4cde9cSderaadt #define FAT_USED 1 /* This fat chain is used in a file */ 1052a4cde9cSderaadt 1069646ab25Sderaadt #define DOSLONGNAMELEN 256 /* long name maximal length */ 1079646ab25Sderaadt #define LRFIRST 0x40 /* first long name record */ 1089646ab25Sderaadt #define LRNOMASK 0x1f /* mask to extract long record 1099646ab25Sderaadt * sequence number */ 1109646ab25Sderaadt 1119646ab25Sderaadt /* 1129646ab25Sderaadt * Architecture independent description of a directory entry 1139646ab25Sderaadt */ 1149646ab25Sderaadt struct dosDirEntry { 1159646ab25Sderaadt struct dosDirEntry 1169646ab25Sderaadt *parent, /* previous tree level */ 1179646ab25Sderaadt *next, /* next brother */ 1189646ab25Sderaadt *child; /* if this is a directory */ 1199646ab25Sderaadt char name[8+1+3+1]; /* alias name first part */ 1209646ab25Sderaadt char lname[DOSLONGNAMELEN]; /* real name */ 1219646ab25Sderaadt uint flags; /* attributes */ 1229646ab25Sderaadt cl_t head; /* cluster no */ 1239646ab25Sderaadt u_int32_t size; /* filesize in bytes */ 1249646ab25Sderaadt uint fsckflags; /* flags during fsck */ 1259646ab25Sderaadt }; 1269646ab25Sderaadt /* Flags in fsckflags: */ 1279646ab25Sderaadt #define DIREMPTY 1 1289646ab25Sderaadt #define DIREMPWARN 2 1299646ab25Sderaadt 1309646ab25Sderaadt /* 1319646ab25Sderaadt * TODO-list of unread directories 1329646ab25Sderaadt */ 1339646ab25Sderaadt struct dirTodoNode { 1349646ab25Sderaadt struct dosDirEntry *dir; 1359646ab25Sderaadt struct dirTodoNode *next; 1369646ab25Sderaadt }; 1379646ab25Sderaadt 1389646ab25Sderaadt #endif 139