[9e7615d] | 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 <stdint.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 FATAUTO 0
|
---|
| 46 | #define FAT12 12
|
---|
| 47 | #define FAT16 16
|
---|
| 48 | #define FAT32 32
|
---|
| 49 |
|
---|
| 50 | #define FAT_CLUSTER_DOUBLE_SIZE(a) ((a) / 4)
|
---|
| 51 |
|
---|
| 52 | typedef struct fat_bs {
|
---|
| 53 | uint8_t ji[3]; /**< Jump instruction. */
|
---|
| 54 | uint8_t oem_name[8];
|
---|
| 55 | /* BIOS Parameter Block */
|
---|
| 56 | uint16_t bps; /**< Bytes per sector. */
|
---|
| 57 | uint8_t spc; /**< Sectors per cluster. */
|
---|
| 58 | uint16_t rscnt; /**< Reserved sector count. */
|
---|
| 59 | uint8_t fatcnt; /**< Number of FATs. */
|
---|
| 60 | uint16_t root_ent_max; /**< Maximum number of root directory
|
---|
| 61 | entries. */
|
---|
| 62 | uint16_t totsec16; /**< Total sectors. 16-bit version. */
|
---|
| 63 | uint8_t mdesc; /**< Media descriptor. */
|
---|
| 64 | uint16_t sec_per_fat; /**< Sectors per FAT12/FAT16. */
|
---|
| 65 | uint16_t sec_per_track; /**< Sectors per track. */
|
---|
| 66 | uint16_t headcnt; /**< Number of heads. */
|
---|
| 67 | uint32_t hidden_sec; /**< Hidden sectors. */
|
---|
| 68 | uint32_t totsec32; /**< Total sectors. 32-bit version. */
|
---|
| 69 |
|
---|
| 70 | union {
|
---|
| 71 | struct {
|
---|
| 72 | /* FAT12/FAT16 only: Extended BIOS Parameter Block */
|
---|
| 73 | /** Physical drive number. */
|
---|
| 74 | uint8_t pdn;
|
---|
| 75 | uint8_t reserved;
|
---|
| 76 | /** Extended boot signature. */
|
---|
| 77 | uint8_t ebs;
|
---|
| 78 | /** Serial number. */
|
---|
| 79 | uint32_t id;
|
---|
| 80 | /** Volume label. */
|
---|
| 81 | uint8_t label[11];
|
---|
| 82 | /** FAT type. */
|
---|
| 83 | uint8_t type[8];
|
---|
| 84 | /** Boot code. */
|
---|
| 85 | uint8_t boot_code[448];
|
---|
| 86 | /** Boot sector signature. */
|
---|
| 87 | uint16_t signature;
|
---|
[1433ecda] | 88 | } __attribute__((packed));
|
---|
[9e7615d] | 89 | struct {
|
---|
| 90 | /* FAT32 only */
|
---|
| 91 | /** Sectors per FAT. */
|
---|
| 92 | uint32_t sectors_per_fat;
|
---|
| 93 | /** FAT flags. */
|
---|
| 94 | uint16_t flags;
|
---|
| 95 | /** Version. */
|
---|
| 96 | uint16_t version;
|
---|
| 97 | /** Cluster number of root directory. */
|
---|
| 98 | uint32_t root_cluster;
|
---|
| 99 | /** Sector number of file system information sector. */
|
---|
| 100 | uint16_t fsinfo_sec;
|
---|
| 101 | /** Sector number of boot sector copy. */
|
---|
| 102 | uint16_t bscopy_sec;
|
---|
| 103 | uint8_t reserved1[12];
|
---|
| 104 | /** Physical drive number. */
|
---|
| 105 | uint8_t pdn;
|
---|
| 106 | uint8_t reserved2;
|
---|
| 107 | /** Extended boot signature. */
|
---|
| 108 | uint8_t ebs;
|
---|
| 109 | /** Serial number. */
|
---|
| 110 | uint32_t id;
|
---|
| 111 | /** Volume label. */
|
---|
| 112 | uint8_t label[11];
|
---|
| 113 | /** FAT type. */
|
---|
| 114 | uint8_t type[8];
|
---|
| 115 | /** Boot code. */
|
---|
| 116 | uint8_t boot_code[420];
|
---|
| 117 | /** Signature. */
|
---|
| 118 | uint16_t signature;
|
---|
[1433ecda] | 119 | } __attribute__((packed)) fat32;
|
---|
[9e7615d] | 120 | };
|
---|
[1433ecda] | 121 | } __attribute__((packed)) fat_bs_t;
|
---|
[9e7615d] | 122 |
|
---|
| 123 | #endif
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * @}
|
---|
| 127 | */
|
---|