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