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