[9c2c7d2] | 1 | /*
|
---|
| 2 | * Copyright (c) 2008 Jakub Jermar
|
---|
| 3 | * Copyright (c) 2011 Oleg Romanenko
|
---|
| 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup fs
|
---|
| 31 | * @{
|
---|
[1b20da0] | 32 | */
|
---|
[9c2c7d2] | 33 |
|
---|
| 34 | #ifndef FAT_FAT_DENTRY_H_
|
---|
| 35 | #define FAT_FAT_DENTRY_H_
|
---|
| 36 |
|
---|
| 37 | #include <stdint.h>
|
---|
| 38 | #include <stdbool.h>
|
---|
| 39 | #include <stddef.h>
|
---|
| 40 | #include <unaligned.h>
|
---|
| 41 |
|
---|
| 42 | #define IS_D_CHAR(ch) (isalnum(ch) || ch == '_')
|
---|
| 43 | #define FAT_STOP_CHARS "*?/\\\n\t|'"
|
---|
| 44 |
|
---|
| 45 | #define FAT_NAME_LEN 8
|
---|
| 46 | #define FAT_EXT_LEN 3
|
---|
| 47 | #define FAT_VOLLABEL_LEN 11
|
---|
| 48 |
|
---|
| 49 | #define FAT_NAME_DOT ". "
|
---|
| 50 | #define FAT_NAME_DOT_DOT ".. "
|
---|
| 51 | #define FAT_EXT_PAD " "
|
---|
| 52 |
|
---|
| 53 | #define FAT_ATTR_RDONLY 0x01
|
---|
| 54 | #define FAT_ATTR_HIDDEN 0x02
|
---|
| 55 | #define FAT_ATTR_SYSTEM 0x04
|
---|
| 56 | #define FAT_ATTR_VOLLABEL 0x08
|
---|
| 57 | #define FAT_ATTR_SUBDIR 0x10
|
---|
| 58 | #define FAT_ATTR_ARCHIVE 0x20
|
---|
| 59 | #define FAT_ATTR_LFN \
|
---|
| 60 | (FAT_ATTR_RDONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLLABEL)
|
---|
[a35b458] | 61 |
|
---|
[9c2c7d2] | 62 | #define FAT_LCASE_LOWER_NAME 0x08
|
---|
| 63 | #define FAT_LCASE_LOWER_EXT 0x10
|
---|
| 64 |
|
---|
| 65 | #define FAT_PAD ' '
|
---|
| 66 | #define FAT_LFN_PAD 0xffff
|
---|
| 67 | #define FAT_SFN_CHAR '_'
|
---|
| 68 |
|
---|
| 69 | #define FAT_DENTRY_UNUSED 0x00
|
---|
| 70 | #define FAT_DENTRY_E5_ESC 0x05
|
---|
| 71 | #define FAT_DENTRY_DOT 0x2e
|
---|
| 72 | #define FAT_DENTRY_ERASED 0xe5
|
---|
| 73 | #define FAT_LFN_LAST 0x40
|
---|
| 74 | #define FAT_LFN_ERASED 0x80
|
---|
| 75 |
|
---|
| 76 | #define FAT_LFN_ORDER(d) ((d)->lfn.order)
|
---|
| 77 | #define FAT_IS_LFN(d) \
|
---|
| 78 | ((FAT_LFN_ORDER((d)) & FAT_LFN_LAST) == FAT_LFN_LAST)
|
---|
| 79 | #define FAT_LFN_COUNT(d) \
|
---|
| 80 | (FAT_LFN_ORDER((d)) ^ FAT_LFN_LAST)
|
---|
| 81 | #define FAT_LFN_PART1(d) ((d)->lfn.part1)
|
---|
| 82 | #define FAT_LFN_PART2(d) ((d)->lfn.part2)
|
---|
| 83 | #define FAT_LFN_PART3(d) ((d)->lfn.part3)
|
---|
| 84 | #define FAT_LFN_ATTR(d) ((d)->lfn.attr)
|
---|
| 85 | #define FAT_LFN_CHKSUM(d) ((d)->lfn.check_sum)
|
---|
| 86 |
|
---|
| 87 | #define FAT_LFN_NAME_LEN 260 /* characters */
|
---|
| 88 | #define FAT_LFN_NAME_SIZE STR_BOUNDS(FAT_LFN_NAME_LEN) /* bytes */
|
---|
| 89 | #define FAT_LFN_MAX_COUNT 20
|
---|
| 90 | #define FAT_LFN_PART1_SIZE 5
|
---|
| 91 | #define FAT_LFN_PART2_SIZE 6
|
---|
| 92 | #define FAT_LFN_PART3_SIZE 2
|
---|
| 93 | #define FAT_LFN_ENTRY_SIZE \
|
---|
| 94 | (FAT_LFN_PART1_SIZE + FAT_LFN_PART2_SIZE + FAT_LFN_PART3_SIZE)
|
---|
| 95 |
|
---|
| 96 | typedef enum {
|
---|
| 97 | FAT_DENTRY_SKIP,
|
---|
| 98 | FAT_DENTRY_LAST,
|
---|
| 99 | FAT_DENTRY_FREE,
|
---|
| 100 | FAT_DENTRY_VALID,
|
---|
| 101 | FAT_DENTRY_LFN,
|
---|
| 102 | FAT_DENTRY_VOLLABEL
|
---|
| 103 | } fat_dentry_clsf_t;
|
---|
| 104 |
|
---|
| 105 | typedef union {
|
---|
| 106 | struct {
|
---|
| 107 | uint8_t name[8];
|
---|
| 108 | uint8_t ext[3];
|
---|
| 109 | uint8_t attr;
|
---|
| 110 | uint8_t lcase;
|
---|
| 111 | uint8_t ctime_fine;
|
---|
| 112 | uint16_t ctime;
|
---|
| 113 | uint16_t cdate;
|
---|
| 114 | uint16_t adate;
|
---|
| 115 | union {
|
---|
| 116 | uint16_t eaidx; /* FAT12/FAT16 */
|
---|
| 117 | uint16_t firstc_hi; /* FAT32 */
|
---|
| 118 | } __attribute__ ((packed));
|
---|
| 119 | uint16_t mtime;
|
---|
| 120 | uint16_t mdate;
|
---|
| 121 | union {
|
---|
| 122 | uint16_t firstc; /* FAT12/FAT16 */
|
---|
| 123 | uint16_t firstc_lo; /* FAT32 */
|
---|
| 124 | } __attribute__ ((packed));
|
---|
| 125 | uint32_t size;
|
---|
| 126 | } __attribute__ ((packed));
|
---|
| 127 | struct {
|
---|
| 128 | uint8_t order;
|
---|
| 129 | uint16_t part1[FAT_LFN_PART1_SIZE];
|
---|
| 130 | uint8_t attr;
|
---|
| 131 | uint8_t type;
|
---|
| 132 | uint8_t check_sum;
|
---|
| 133 | uint16_t part2[FAT_LFN_PART2_SIZE];
|
---|
| 134 | uint16_t firstc_lo; /* MUST be 0 */
|
---|
| 135 | uint16_t part3[FAT_LFN_PART3_SIZE];
|
---|
| 136 | } __attribute__ ((packed)) lfn;
|
---|
| 137 | } __attribute__ ((packed)) fat_dentry_t;
|
---|
| 138 |
|
---|
| 139 | #endif
|
---|
| 140 |
|
---|
| 141 | /**
|
---|
| 142 | * @}
|
---|
| 143 | */
|
---|