[6ebaff9] | 1 | /*
|
---|
| 2 | * Copyright (c) 2008 Jakub Jermar
|
---|
[c4bbca8] | 3 | * Copyright (c) 2011 Oleg Romanenko
|
---|
[6ebaff9] | 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 | * @{
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | #ifndef FAT_FAT_DENTRY_H_
|
---|
| 35 | #define FAT_FAT_DENTRY_H_
|
---|
| 36 |
|
---|
[033ef7d3] | 37 | #include <stdint.h>
|
---|
[0fdd6bb] | 38 | #include <bool.h>
|
---|
[033ef7d3] | 39 |
|
---|
[411e9ca] | 40 | #define IS_D_CHAR(ch) (isalnum(ch) || ch == '_')
|
---|
[980311e] | 41 | #define FAT_STOP_CHARS "*?/\\\n\t|'"
|
---|
[411e9ca] | 42 |
|
---|
[033ef7d3] | 43 | #define FAT_NAME_LEN 8
|
---|
| 44 | #define FAT_EXT_LEN 3
|
---|
| 45 |
|
---|
[1baec4b] | 46 | #define FAT_NAME_DOT ". "
|
---|
| 47 | #define FAT_NAME_DOT_DOT ".. "
|
---|
| 48 | #define FAT_EXT_PAD " "
|
---|
| 49 |
|
---|
[2df7fdd4] | 50 | #define FAT_ATTR_RDONLY 0x01
|
---|
| 51 | #define FAT_ATTR_HIDDEN 0x02
|
---|
| 52 | #define FAT_ATTR_SYSTEM 0x04
|
---|
| 53 | #define FAT_ATTR_VOLLABEL 0x08
|
---|
| 54 | #define FAT_ATTR_SUBDIR 0x10
|
---|
| 55 | #define FAT_ATTR_ARCHIVE 0x20
|
---|
[34fdb75] | 56 | #define FAT_ATTR_LFN \
|
---|
[2df7fdd4] | 57 | (FAT_ATTR_RDONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLLABEL)
|
---|
| 58 |
|
---|
[a248234] | 59 | #define FAT_LCASE_LOWER_NAME 0x08
|
---|
| 60 | #define FAT_LCASE_LOWER_EXT 0x10
|
---|
| 61 |
|
---|
[7194a60] | 62 | #define FAT_PAD ' '
|
---|
| 63 | #define FAT_LFN_PAD 0xffff
|
---|
| 64 | #define FAT_SFN_CHAR '_'
|
---|
[a31c1ccf] | 65 |
|
---|
| 66 | #define FAT_DENTRY_UNUSED 0x00
|
---|
| 67 | #define FAT_DENTRY_E5_ESC 0x05
|
---|
| 68 | #define FAT_DENTRY_DOT 0x2e
|
---|
| 69 | #define FAT_DENTRY_ERASED 0xe5
|
---|
[34fdb75] | 70 | #define FAT_LFN_LAST 0x40
|
---|
| 71 | #define FAT_LFN_ERASED 0x80
|
---|
| 72 |
|
---|
[5d95f02] | 73 | #define FAT_LFN_ORDER(d) ((d)->lfn.order)
|
---|
[34fdb75] | 74 | #define FAT_IS_LFN(d) \
|
---|
[5d95f02] | 75 | ((FAT_LFN_ORDER((d)) & FAT_LFN_LAST) == FAT_LFN_LAST)
|
---|
[34fdb75] | 76 | #define FAT_LFN_COUNT(d) \
|
---|
[5d95f02] | 77 | (FAT_LFN_ORDER((d)) ^ FAT_LFN_LAST)
|
---|
| 78 | #define FAT_LFN_PART1(d) ((d)->lfn.part1)
|
---|
| 79 | #define FAT_LFN_PART2(d) ((d)->lfn.part2)
|
---|
| 80 | #define FAT_LFN_PART3(d) ((d)->lfn.part3)
|
---|
| 81 | #define FAT_LFN_ATTR(d) ((d)->lfn.attr)
|
---|
| 82 | #define FAT_LFN_CHKSUM(d) ((d)->lfn.check_sum)
|
---|
[34fdb75] | 83 |
|
---|
[7194a60] | 84 | #define FAT_LFN_NAME_SIZE 260
|
---|
[34fdb75] | 85 | #define FAT_LFN_MAX_COUNT 20
|
---|
[4372b49] | 86 | #define FAT_LFN_PART1_SIZE 5
|
---|
| 87 | #define FAT_LFN_PART2_SIZE 6
|
---|
| 88 | #define FAT_LFN_PART3_SIZE 2
|
---|
[34fdb75] | 89 | #define FAT_LFN_ENTRY_SIZE \
|
---|
| 90 | (FAT_LFN_PART1_SIZE + FAT_LFN_PART2_SIZE + FAT_LFN_PART3_SIZE)
|
---|
[a31c1ccf] | 91 |
|
---|
[033ef7d3] | 92 | typedef enum {
|
---|
| 93 | FAT_DENTRY_SKIP,
|
---|
| 94 | FAT_DENTRY_LAST,
|
---|
[0fdd6bb] | 95 | FAT_DENTRY_FREE,
|
---|
[65ccd23] | 96 | FAT_DENTRY_VALID,
|
---|
| 97 | FAT_DENTRY_LFN
|
---|
[033ef7d3] | 98 | } fat_dentry_clsf_t;
|
---|
| 99 |
|
---|
[5d95f02] | 100 | typedef union {
|
---|
| 101 | struct {
|
---|
| 102 | uint8_t name[8];
|
---|
| 103 | uint8_t ext[3];
|
---|
| 104 | uint8_t attr;
|
---|
| 105 | uint8_t lcase;
|
---|
| 106 | uint8_t ctime_fine;
|
---|
| 107 | uint16_t ctime;
|
---|
| 108 | uint16_t cdate;
|
---|
| 109 | uint16_t adate;
|
---|
| 110 | union {
|
---|
| 111 | uint16_t eaidx; /* FAT12/FAT16 */
|
---|
| 112 | uint16_t firstc_hi; /* FAT32 */
|
---|
[2df7fdd4] | 113 | } __attribute__ ((packed));
|
---|
[5d95f02] | 114 | uint16_t mtime;
|
---|
| 115 | uint16_t mdate;
|
---|
| 116 | union {
|
---|
| 117 | uint16_t firstc; /* FAT12/FAT16 */
|
---|
| 118 | uint16_t firstc_lo; /* FAT32 */
|
---|
| 119 | } __attribute__ ((packed));
|
---|
| 120 | uint32_t size;
|
---|
| 121 | } __attribute__ ((packed));
|
---|
| 122 | struct {
|
---|
| 123 | uint8_t order;
|
---|
| 124 | uint16_t part1[FAT_LFN_PART1_SIZE];
|
---|
| 125 | uint8_t attr;
|
---|
| 126 | uint8_t type;
|
---|
| 127 | uint8_t check_sum;
|
---|
| 128 | uint16_t part2[FAT_LFN_PART2_SIZE];
|
---|
| 129 | uint16_t firstc_lo; /* MUST be 0 */
|
---|
| 130 | uint16_t part3[FAT_LFN_PART3_SIZE];
|
---|
| 131 | } __attribute__ ((packed)) lfn;
|
---|
[033ef7d3] | 132 | } __attribute__ ((packed)) fat_dentry_t;
|
---|
| 133 |
|
---|
[34fdb75] | 134 |
|
---|
[14c331a] | 135 | extern int fat_dentry_namecmp(char *, const char *);
|
---|
[0fdd6bb] | 136 | extern void fat_dentry_name_get(const fat_dentry_t *, char *);
|
---|
| 137 | extern void fat_dentry_name_set(fat_dentry_t *, const char *);
|
---|
| 138 | extern fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *);
|
---|
[ed19497] | 139 | extern uint8_t fat_dentry_chksum(uint8_t *);
|
---|
[033ef7d3] | 140 |
|
---|
[4372b49] | 141 | extern size_t fat_lfn_str_nlength(const uint16_t *, size_t);
|
---|
[34fdb75] | 142 | extern size_t fat_lfn_size(const fat_dentry_t *);
|
---|
[fcc3cd8] | 143 | extern size_t fat_lfn_get_entry(const fat_dentry_t *, uint16_t *, size_t *);
|
---|
[5d95f02] | 144 | extern size_t fat_lfn_set_entry(const uint16_t *, size_t *, size_t,
|
---|
| 145 | fat_dentry_t *);
|
---|
[7194a60] | 146 |
|
---|
[5d95f02] | 147 | extern void str_to_ascii(char *, const char *, size_t, uint8_t);
|
---|
| 148 | extern size_t utf16_length(const uint16_t *);
|
---|
[34fdb75] | 149 |
|
---|
[5d95f02] | 150 | extern bool fat_valid_name(const char *);
|
---|
| 151 | extern bool fat_valid_short_name(const char *);
|
---|
[34fdb75] | 152 |
|
---|
[6ebaff9] | 153 | #endif
|
---|
| 154 |
|
---|
| 155 | /**
|
---|
| 156 | * @}
|
---|
| 157 | */
|
---|