1 1.1 christos /* $NetBSD: msdosfs.h,v 1.1 2018/01/09 03:31:15 christos Exp $ */ 2 1.1 christos 3 1.1 christos /*- 4 1.1 christos * Copyright (c) 2017 The NetBSD Foundation, Inc. 5 1.1 christos * Copyright (c) 2016 The DragonFly Project 6 1.1 christos * Copyright (c) 2006 Tobias Reifenberger 7 1.1 christos * All rights reserved. 8 1.1 christos * 9 1.1 christos * This code is derived from software contributed to The NetBSD Foundation 10 1.1 christos * by Tomohiro Kusumi <kusumi.tomohiro (at) gmail.com>. 11 1.1 christos * 12 1.1 christos * Redistribution and use in source and binary forms, with or without 13 1.1 christos * modification, are permitted provided that the following conditions 14 1.1 christos * are met: 15 1.1 christos * 1. Redistributions of source code must retain the above copyright 16 1.1 christos * notice, this list of conditions and the following disclaimer. 17 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 18 1.1 christos * notice, this list of conditions and the following disclaimer in the 19 1.1 christos * documentation and/or other materials provided with the distribution. 20 1.1 christos * 21 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 22 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 25 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 1.1 christos * SUCH DAMAGE. 32 1.1 christos * 33 1.1 christos * $FreeBSD$ 34 1.1 christos */ 35 1.1 christos 36 1.1 christos #include <sys/types.h> 37 1.1 christos 38 1.1 christos /* 39 1.1 christos * Conversion macros for little endian encoded unsigned integers 40 1.1 christos * in byte streams to the local unsigned integer format. 41 1.1 christos */ 42 1.1 christos #define UINT16BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1]))) 43 1.1 christos #define UINT32BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1]) + \ 44 1.1 christos (65536*(p)[2]) + (16777216*(p)[3]))) 45 1.1 christos 46 1.1 christos /* 47 1.1 christos * All following structures are according to: 48 1.1 christos * 49 1.1 christos * Microsoft Extensible Firmware Initiative FAT32 File System Specification 50 1.1 christos * FAT: General Overview of On-Disk Format 51 1.1 christos * Version 1.03, December 6, 2000 52 1.1 christos * Microsoft Corporation 53 1.1 christos */ 54 1.1 christos 55 1.1 christos /* 56 1.1 christos * FAT boot sector and boot parameter block for 57 1.1 christos * FAT12 and FAT16 volumes 58 1.1 christos */ 59 1.1 christos typedef struct fat_bsbpb { 60 1.1 christos /* common fields */ 61 1.1 christos uint8_t BS_jmpBoot[3]; 62 1.1 christos uint8_t BS_OEMName[8]; 63 1.1 christos uint8_t BPB_BytsPerSec[2]; 64 1.1 christos uint8_t BPB_SecPerClus; 65 1.1 christos uint8_t BPB_RsvdSecCnt[2]; 66 1.1 christos uint8_t BPB_NumFATs; 67 1.1 christos uint8_t BPB_RootEntCnt[2]; 68 1.1 christos uint8_t BPB_TotSec16[2]; 69 1.1 christos uint8_t BPB_Media; 70 1.1 christos uint8_t BPB_FATSz16[2]; 71 1.1 christos uint8_t BPB_SecPerTrack[2]; 72 1.1 christos uint8_t BPB_NumHeads[2]; 73 1.1 christos uint8_t BPB_HiddSec[4]; 74 1.1 christos uint8_t BPB_TotSec32[4]; 75 1.1 christos /* FAT12/FAT16 only fields */ 76 1.1 christos uint8_t BS_DrvNum; 77 1.1 christos uint8_t BS_Reserved1; 78 1.1 christos uint8_t BS_BootSig; 79 1.1 christos uint8_t BS_VolID[4]; 80 1.1 christos uint8_t BS_VolLab[11]; 81 1.1 christos uint8_t BS_FilSysType[8]; 82 1.1 christos } FAT_BSBPB; /* 62 bytes */ 83 1.1 christos 84 1.1 christos /* 85 1.1 christos * FAT boot sector and boot parameter block for 86 1.1 christos * FAT32 volumes 87 1.1 christos */ 88 1.1 christos typedef struct fat32_bsbpb { 89 1.1 christos /* common fields */ 90 1.1 christos uint8_t BS_jmpBoot[3]; 91 1.1 christos uint8_t BS_OEMName[8]; 92 1.1 christos uint8_t BPB_BytsPerSec[2]; 93 1.1 christos uint8_t BPB_SecPerClus; 94 1.1 christos uint8_t BPB_RsvdSecCnt[2]; 95 1.1 christos uint8_t BPB_NumFATs; 96 1.1 christos uint8_t BPB_RootEntCnt[2]; 97 1.1 christos uint8_t BPB_TotSec16[2]; 98 1.1 christos uint8_t BPB_Media; 99 1.1 christos uint8_t BPB_FATSz16[2]; 100 1.1 christos uint8_t BPB_SecPerTrack[2]; 101 1.1 christos uint8_t BPB_NumHeads[2]; 102 1.1 christos uint8_t BPB_HiddSec[4]; 103 1.1 christos uint8_t BPB_TotSec32[4]; 104 1.1 christos /* FAT32 only fields */ 105 1.1 christos uint8_t BPB_FATSz32[4]; 106 1.1 christos uint8_t BPB_ExtFlags[2]; 107 1.1 christos uint8_t BPB_FSVer[2]; 108 1.1 christos uint8_t BPB_RootClus[4]; 109 1.1 christos uint8_t BPB_FSInfo[2]; 110 1.1 christos uint8_t BPB_BkBootSec[2]; 111 1.1 christos uint8_t BPB_Reserved[12]; 112 1.1 christos uint8_t BS_DrvNum; 113 1.1 christos uint8_t BS_Reserved1; 114 1.1 christos uint8_t BS_BootSig; 115 1.1 christos uint8_t BS_VolID[4]; 116 1.1 christos uint8_t BS_VolLab[11]; 117 1.1 christos uint8_t BS_FilSysType[8]; 118 1.1 christos } FAT32_BSBPB; /* 90 bytes */ 119 1.1 christos 120 1.1 christos /* 121 1.1 christos * FAT directory entry structure 122 1.1 christos */ 123 1.1 christos #define FAT_DES_ATTR_READ_ONLY 0x01 124 1.1 christos #define FAT_DES_ATTR_HIDDEN 0x02 125 1.1 christos #define FAT_DES_ATTR_SYSTEM 0x04 126 1.1 christos #define FAT_DES_ATTR_VOLUME_ID 0x08 127 1.1 christos #define FAT_DES_ATTR_DIRECTORY 0x10 128 1.1 christos #define FAT_DES_ATTR_ARCHIVE 0x20 129 1.1 christos #define FAT_DES_ATTR_LONG_NAME (FAT_DES_ATTR_READ_ONLY | \ 130 1.1 christos FAT_DES_ATTR_HIDDEN | \ 131 1.1 christos FAT_DES_ATTR_SYSTEM | \ 132 1.1 christos FAT_DES_ATTR_VOLUME_ID) 133 1.1 christos 134 1.1 christos typedef struct fat_des { 135 1.1 christos uint8_t DIR_Name[11]; 136 1.1 christos uint8_t DIR_Attr; 137 1.1 christos uint8_t DIR_NTRes; 138 1.1 christos uint8_t DIR_CrtTimeTenth; 139 1.1 christos uint8_t DIR_CrtTime[2]; 140 1.1 christos uint8_t DIR_CrtDate[2]; 141 1.1 christos uint8_t DIR_LstAccDate[2]; 142 1.1 christos uint8_t DIR_FstClusHI[2]; 143 1.1 christos uint8_t DIR_WrtTime[2]; 144 1.1 christos uint8_t DIR_WrtDate[2]; 145 1.1 christos uint8_t DIR_FstClusLO[2]; 146 1.1 christos uint8_t DIR_FileSize[4]; 147 1.1 christos } FAT_DES; 148