1 | /*
|
---|
2 | * Copyright (c) 2008 Jakub Jermar
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup fs
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | #ifndef FAT_FAT_H_
|
---|
34 | #define FAT_FAT_H_
|
---|
35 |
|
---|
36 | #include <sys/types.h>
|
---|
37 |
|
---|
38 | #define BS_BLOCK 0
|
---|
39 | #define BS_SIZE 512
|
---|
40 | #define DIRENT_SIZE 32
|
---|
41 |
|
---|
42 | #define FAT12_CLST_MAX 4085
|
---|
43 | #define FAT16_CLST_MAX 65525
|
---|
44 |
|
---|
45 | #define FAT12 12
|
---|
46 | #define FAT16 16
|
---|
47 | #define FAT32 32
|
---|
48 |
|
---|
49 | #define FAT_CLUSTER_DOUBLE_SIZE(a) ((a) / 4)
|
---|
50 |
|
---|
51 | typedef struct fat_bs {
|
---|
52 | uint8_t ji[3]; /**< Jump instruction. */
|
---|
53 | uint8_t oem_name[8];
|
---|
54 | /* BIOS Parameter Block */
|
---|
55 | uint16_t bps; /**< Bytes per sector. */
|
---|
56 | uint8_t spc; /**< Sectors per cluster. */
|
---|
57 | uint16_t rscnt; /**< Reserved sector count. */
|
---|
58 | uint8_t fatcnt; /**< Number of FATs. */
|
---|
59 | uint16_t root_ent_max; /**< Maximum number of root directory
|
---|
60 | entries. */
|
---|
61 | uint16_t totsec16; /**< Total sectors. 16-bit version. */
|
---|
62 | uint8_t mdesc; /**< Media descriptor. */
|
---|
63 | uint16_t sec_per_fat; /**< Sectors per FAT12/FAT16. */
|
---|
64 | uint16_t sec_per_track; /**< Sectors per track. */
|
---|
65 | uint16_t headcnt; /**< Number of heads. */
|
---|
66 | uint32_t hidden_sec; /**< Hidden sectors. */
|
---|
67 | uint32_t totsec32; /**< Total sectors. 32-bit version. */
|
---|
68 |
|
---|
69 | union {
|
---|
70 | struct {
|
---|
71 | /* FAT12/FAT16 only: Extended BIOS Parameter Block */
|
---|
72 | /** Physical drive number. */
|
---|
73 | uint8_t pdn;
|
---|
74 | uint8_t reserved;
|
---|
75 | /** Extended boot signature. */
|
---|
76 | uint8_t ebs;
|
---|
77 | /** Serial number. */
|
---|
78 | uint32_t id;
|
---|
79 | /** Volume label. */
|
---|
80 | uint8_t label[11];
|
---|
81 | /** FAT type. */
|
---|
82 | uint8_t type[8];
|
---|
83 | /** Boot code. */
|
---|
84 | uint8_t boot_code[448];
|
---|
85 | /** Boot sector signature. */
|
---|
86 | uint16_t signature;
|
---|
87 | } __attribute__ ((packed));
|
---|
88 | struct {
|
---|
89 | /* FAT32 only */
|
---|
90 | /** Sectors per FAT. */
|
---|
91 | uint32_t sectors_per_fat;
|
---|
92 | /** FAT flags. */
|
---|
93 | uint16_t flags;
|
---|
94 | /** Version. */
|
---|
95 | uint16_t version;
|
---|
96 | /** Cluster number of root directory. */
|
---|
97 | uint32_t root_cluster;
|
---|
98 | /** Sector number of file system information sector. */
|
---|
99 | uint16_t fsinfo_sec;
|
---|
100 | /** Sector number of boot sector copy. */
|
---|
101 | uint16_t bscopy_sec;
|
---|
102 | uint8_t reserved1[12];
|
---|
103 | /** Physical drive number. */
|
---|
104 | uint8_t pdn;
|
---|
105 | uint8_t reserved2;
|
---|
106 | /** Extended boot signature. */
|
---|
107 | uint8_t ebs;
|
---|
108 | /** Serial number. */
|
---|
109 | uint32_t id;
|
---|
110 | /** Volume label. */
|
---|
111 | uint8_t label[11];
|
---|
112 | /** FAT type. */
|
---|
113 | uint8_t type[8];
|
---|
114 | /** Boot code. */
|
---|
115 | uint8_t boot_code[420];
|
---|
116 | /** Signature. */
|
---|
117 | uint16_t signature;
|
---|
118 | } fat32 __attribute__ ((packed));
|
---|
119 | };
|
---|
120 | } __attribute__ ((packed)) fat_bs_t;
|
---|
121 |
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * @}
|
---|
126 | */
|
---|