[be815bc] | 1 | /*
|
---|
| 2 | * Copyright (c) 2007 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 <ipc/ipc.h>
|
---|
[efd4a72] | 37 | #include <libfs.h>
|
---|
[be815bc] | 38 | #include <atomic.h>
|
---|
| 39 | #include <sys/types.h>
|
---|
| 40 | #include <bool.h>
|
---|
| 41 |
|
---|
| 42 | #define dprintf(...) printf(__VA_ARGS__)
|
---|
| 43 |
|
---|
[5af627fc] | 44 | typedef struct {
|
---|
| 45 | uint8_t ji[3]; /**< Jump instruction. */
|
---|
| 46 | uint8_t oem_name[8];
|
---|
| 47 | /* BIOS Parameter Block */
|
---|
| 48 | uint16_t bps; /**< Bytes per sector. */
|
---|
| 49 | uint8_t spc; /**< Sectors per cluster. */
|
---|
| 50 | uint16_t rsc; /**< Reserved sector count. */
|
---|
| 51 | uint8_t fatcnt; /**< Number of FATs. */
|
---|
| 52 | uint16_t root_ent_max; /**< Maximum number of root directory
|
---|
| 53 | entries. */
|
---|
| 54 | uint16_t totsec; /**< Total sectors. */
|
---|
| 55 | uint8_t mdesc; /**< Media descriptor. */
|
---|
| 56 | uint16_t sec_per_fat; /**< Sectors per FAT12/FAT16. */
|
---|
| 57 | uint16_t sec_per_track; /**< Sectors per track. */
|
---|
| 58 | uint16_t headcnt; /**< Number of heads. */
|
---|
| 59 | uint32_t hidden_sec; /**< Hidden sectors. */
|
---|
| 60 | uint32_t total_sec; /**< Total sectors. */
|
---|
| 61 |
|
---|
| 62 | union {
|
---|
| 63 | struct {
|
---|
| 64 | /* FAT12/FAT16 only: Extended BIOS Parameter Block */
|
---|
| 65 | /** Physical drive number. */
|
---|
| 66 | uint8_t pdn;
|
---|
| 67 | uint8_t reserved;
|
---|
| 68 | /** Extended boot signature. */
|
---|
| 69 | uint8_t ebs;
|
---|
| 70 | /** Serial number. */
|
---|
| 71 | uint32_t id;
|
---|
| 72 | /** Volume label. */
|
---|
| 73 | uint8_t label[11];
|
---|
| 74 | /** FAT type. */
|
---|
| 75 | uint8_t type[8];
|
---|
| 76 | /** Boot code. */
|
---|
| 77 | uint8_t boot_code[448];
|
---|
| 78 | /** Boot sector signature. */
|
---|
| 79 | uint16_t signature;
|
---|
| 80 | } __attribute__ ((packed));
|
---|
| 81 | struct {
|
---|
| 82 | /* FAT32 only */
|
---|
| 83 | /** Sectors per FAT. */
|
---|
| 84 | uint32_t sectors_per_fat;
|
---|
| 85 | /** FAT flags. */
|
---|
| 86 | uint16_t flags;
|
---|
| 87 | /** Version. */
|
---|
| 88 | uint16_t version;
|
---|
| 89 | /** Cluster number of root directory. */
|
---|
| 90 | uint32_t root_cluster;
|
---|
| 91 | /** Sector number of file system information sector. */
|
---|
| 92 | uint16_t fsinfo_sec;
|
---|
| 93 | /** Sector number of boot sector copy. */
|
---|
| 94 | uint16_t bscopy_sec;
|
---|
| 95 | uint8_t reserved1[12];
|
---|
| 96 | /** Physical drive number. */
|
---|
| 97 | uint8_t pdn;
|
---|
| 98 | uint8_t reserved2;
|
---|
| 99 | /** Extended boot signature. */
|
---|
| 100 | uint8_t ebs;
|
---|
| 101 | /** Serial number. */
|
---|
| 102 | uint32_t id;
|
---|
| 103 | /** Volume label. */
|
---|
| 104 | uint8_t label;
|
---|
| 105 | /** FAT type. */
|
---|
| 106 | uint8_t type[8];
|
---|
| 107 | /** Boot code. */
|
---|
| 108 | uint8_t boot_code[420];
|
---|
| 109 | /** Signature. */
|
---|
| 110 | uint16_t signature;
|
---|
| 111 | } __attribute__ ((packed));
|
---|
| 112 | };
|
---|
[263e1ec] | 113 | } __attribute__ ((packed)) fat_bs_t;
|
---|
| 114 |
|
---|
| 115 | typedef struct {
|
---|
| 116 | uint8_t name[8];
|
---|
| 117 | uint8_t ext[3];
|
---|
| 118 | uint8_t attr;
|
---|
| 119 | uint8_t reserved;
|
---|
| 120 | uint8_t ctime_fine;
|
---|
| 121 | uint16_t ctime;
|
---|
| 122 | uint16_t cdate;
|
---|
| 123 | uint16_t adate;
|
---|
| 124 | union {
|
---|
| 125 | uint16_t eaidx; /* FAT12/FAT16 */
|
---|
| 126 | uint16_t firstc_hi; /* FAT32 */
|
---|
| 127 | };
|
---|
| 128 | uint16_t mtime;
|
---|
| 129 | uint16_t mdate;
|
---|
| 130 | union {
|
---|
| 131 | uint16_t firstc; /* FAT12/FAT16 */
|
---|
| 132 | uint16_t firstc_lo; /* FAT32 */
|
---|
| 133 | };
|
---|
| 134 | uint32_t size;
|
---|
| 135 | } __attribute__ ((packed)) fat_dentry_t;
|
---|
[5af627fc] | 136 |
|
---|
[efd4a72] | 137 | extern fs_reg_t fat_reg;
|
---|
[be815bc] | 138 |
|
---|
[6364d3c] | 139 | extern void fat_lookup(ipc_callid_t, ipc_call_t *);
|
---|
| 140 |
|
---|
[be815bc] | 141 | #endif
|
---|
| 142 |
|
---|
| 143 | /**
|
---|
| 144 | * @}
|
---|
| 145 | */
|
---|