1275680Strasz/*-
2275680Strasz * Copyright (c) 2006 Tobias Reifenberger
3275680Strasz * All rights reserved.
4275680Strasz *
5275680Strasz * Redistribution and use in source and binary forms, with or without
6275680Strasz * modification, are permitted provided that the following conditions
7275680Strasz * are met:
8275680Strasz * 1. Redistributions of source code must retain the above copyright
9275680Strasz *    notice, this list of conditions and the following disclaimer.
10275680Strasz * 2. Redistributions in binary form must reproduce the above copyright
11275680Strasz *    notice, this list of conditions and the following disclaimer in the
12275680Strasz *    documentation and/or other materials provided with the distribution.
13275680Strasz *
14275680Strasz * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15275680Strasz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16275680Strasz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17275680Strasz * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18275680Strasz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19275680Strasz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20275680Strasz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21275680Strasz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22275680Strasz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23275680Strasz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24275680Strasz * SUCH DAMAGE.
25275680Strasz *
26275680Strasz * $FreeBSD: releng/10.3/usr.sbin/fstyp/msdosfs.h 275680 2014-12-10 14:14:16Z trasz $
27275680Strasz */
28275680Strasz
29275680Strasz#include <sys/types.h>
30275680Strasz
31275680Strasz/*
32275680Strasz * Conversion macros for little endian encoded unsigned integers
33275680Strasz * in byte streams to the local unsigned integer format.
34275680Strasz */
35275680Strasz#define UINT16BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1])))
36275680Strasz#define UINT32BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1]) +		\
37275680Strasz	    (65536*(p)[2]) + (16777216*(p)[3])))
38275680Strasz
39275680Strasz/*
40275680Strasz * All following structures are according to:
41275680Strasz *
42275680Strasz * Microsoft Extensible Firmware Initiative FAT32 File System Specification
43275680Strasz * FAT: General Overview of On-Disk Format
44275680Strasz * Version 1.03, December 6, 2000
45275680Strasz * Microsoft Corporation
46275680Strasz */
47275680Strasz
48275680Strasz/*
49275680Strasz * FAT boot sector and boot parameter block for
50275680Strasz * FAT12 and FAT16 volumes
51275680Strasz */
52275680Strasztypedef struct fat_bsbpb {
53275680Strasz	/* common fields */
54275680Strasz	uint8_t BS_jmpBoot[3];
55275680Strasz	uint8_t BS_OEMName[8];
56275680Strasz	uint8_t BPB_BytsPerSec[2];
57275680Strasz	uint8_t BPB_SecPerClus;
58275680Strasz	uint8_t BPB_RsvdSecCnt[2];
59275680Strasz	uint8_t BPB_NumFATs;
60275680Strasz	uint8_t BPB_RootEntCnt[2];
61275680Strasz	uint8_t BPB_TotSec16[2];
62275680Strasz	uint8_t BPB_Media;
63275680Strasz	uint8_t BPB_FATSz16[2];
64275680Strasz	uint8_t BPB_SecPerTrack[2];
65275680Strasz	uint8_t BPB_NumHeads[2];
66275680Strasz	uint8_t BPB_HiddSec[4];
67275680Strasz	uint8_t BPB_TotSec32[4];
68275680Strasz	/* FAT12/FAT16 only fields */
69275680Strasz	uint8_t BS_DrvNum;
70275680Strasz	uint8_t BS_Reserved1;
71275680Strasz	uint8_t BS_BootSig;
72275680Strasz	uint8_t BS_VolID[4];
73275680Strasz	uint8_t BS_VolLab[11];
74275680Strasz	uint8_t BS_FilSysType[8];
75275680Strasz} FAT_BSBPB; /* 62 bytes */
76275680Strasz
77275680Strasz/*
78275680Strasz * FAT boot sector and boot parameter block for
79275680Strasz * FAT32 volumes
80275680Strasz */
81275680Strasztypedef struct fat32_bsbpb {
82275680Strasz	/* common fields */
83275680Strasz	uint8_t BS_jmpBoot[3];
84275680Strasz	uint8_t BS_OEMName[8];
85275680Strasz	uint8_t BPB_BytsPerSec[2];
86275680Strasz	uint8_t BPB_SecPerClus;
87275680Strasz	uint8_t BPB_RsvdSecCnt[2];
88275680Strasz	uint8_t BPB_NumFATs;
89275680Strasz	uint8_t BPB_RootEntCnt[2];
90275680Strasz	uint8_t BPB_TotSec16[2];
91275680Strasz	uint8_t BPB_Media;
92275680Strasz	uint8_t BPB_FATSz16[2];
93275680Strasz	uint8_t BPB_SecPerTrack[2];
94275680Strasz	uint8_t BPB_NumHeads[2];
95275680Strasz	uint8_t BPB_HiddSec[4];
96275680Strasz	uint8_t BPB_TotSec32[4];
97275680Strasz	/* FAT32 only fields */
98275680Strasz	uint8_t BPB_FATSz32[4];
99275680Strasz	uint8_t BPB_ExtFlags[2];
100275680Strasz	uint8_t BPB_FSVer[2];
101275680Strasz	uint8_t BPB_RootClus[4];
102275680Strasz	uint8_t BPB_FSInfo[2];
103275680Strasz	uint8_t BPB_BkBootSec[2];
104275680Strasz	uint8_t BPB_Reserved[12];
105275680Strasz	uint8_t BS_DrvNum;
106275680Strasz	uint8_t BS_Reserved1;
107275680Strasz	uint8_t BS_BootSig;
108275680Strasz	uint8_t BS_VolID[4];
109275680Strasz	uint8_t BS_VolLab[11];
110275680Strasz	uint8_t BS_FilSysType[8];
111275680Strasz} FAT32_BSBPB; /* 90 bytes */
112275680Strasz
113275680Strasz/*
114275680Strasz * FAT directory entry structure
115275680Strasz */
116275680Strasz#define	FAT_DES_ATTR_READ_ONLY	0x01
117275680Strasz#define	FAT_DES_ATTR_HIDDEN	0x02
118275680Strasz#define	FAT_DES_ATTR_SYSTEM	0x04
119275680Strasz#define	FAT_DES_ATTR_VOLUME_ID	0x08
120275680Strasz#define	FAT_DES_ATTR_DIRECTORY	0x10
121275680Strasz#define	FAT_DES_ATTR_ARCHIVE	0x20
122275680Strasz#define	FAT_DES_ATTR_LONG_NAME	(FAT_DES_ATTR_READ_ONLY |		\
123275680Strasz				 FAT_DES_ATTR_HIDDEN |			\
124275680Strasz				 FAT_DES_ATTR_SYSTEM |			\
125275680Strasz				 FAT_DES_ATTR_VOLUME_ID)
126275680Strasz
127275680Strasztypedef struct fat_des {
128275680Strasz	uint8_t DIR_Name[11];
129275680Strasz	uint8_t DIR_Attr;
130275680Strasz	uint8_t DIR_NTRes;
131275680Strasz	uint8_t DIR_CrtTimeTenth;
132275680Strasz	uint8_t DIR_CrtTime[2];
133275680Strasz	uint8_t DIR_CrtDate[2];
134275680Strasz	uint8_t DIR_LstAccDate[2];
135275680Strasz	uint8_t DIR_FstClusHI[2];
136275680Strasz	uint8_t DIR_WrtTime[2];
137275680Strasz	uint8_t DIR_WrtDate[2];
138275680Strasz	uint8_t DIR_FstClusLO[2];
139275680Strasz	uint8_t DIR_FileSize[4];
140275680Strasz} FAT_DES;
141