[2fb88ea] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Oleg Romanenko
|
---|
| 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 EXFAT_EXFAT_DENTRY_H_
|
---|
| 34 | #define EXFAT_EXFAT_DENTRY_H_
|
---|
| 35 |
|
---|
| 36 | #include <stdint.h>
|
---|
| 37 | #include <bool.h>
|
---|
| 38 |
|
---|
| 39 | #define EXFAT_FILENAME_LEN 255
|
---|
| 40 | #define EXFAT_NAME_PART_LEN 15
|
---|
| 41 |
|
---|
| 42 | #define EXFAT_TYPE_UNUSED 0x00
|
---|
| 43 | #define EXFAT_TYPE_USED 0x80
|
---|
| 44 | #define EXFAT_TYPE_VOLLABEL 0x83
|
---|
| 45 | #define EXFAT_TYPE_BITMAP 0x81
|
---|
| 46 | #define EXFAT_TYPE_UCTABLE 0x82
|
---|
| 47 | #define EXFAT_TYPE_GUID 0xA0
|
---|
| 48 | #define EXFAT_TYPE_FILE 0x85
|
---|
| 49 | #define EXFAT_TYPE_STREAM 0xC0
|
---|
| 50 | #define EXFAT_TYPE_NAME 0xC1
|
---|
| 51 |
|
---|
[042a725] | 52 | #define EXFAT_ATTR_RDONLY 0x01
|
---|
| 53 | #define EXFAT_ATTR_HIDDEN 0x02
|
---|
| 54 | #define EXFAT_ATTR_SYSTEM 0x04
|
---|
| 55 | #define EXFAT_ATTR_SUBDIR 0x10
|
---|
| 56 | #define EXFAT_ATTR_ARCHIVE 0x20
|
---|
[2fb88ea] | 57 |
|
---|
| 58 |
|
---|
| 59 | /* All dentry structs should have 31 byte size */
|
---|
| 60 | typedef struct {
|
---|
| 61 | uint8_t size;
|
---|
| 62 | uint16_t label[11];
|
---|
| 63 | uint8_t _reserved[8];
|
---|
| 64 | } __attribute__ ((packed)) exfat_vollabel_dentry_t;
|
---|
| 65 |
|
---|
| 66 | typedef struct {
|
---|
| 67 | uint8_t flags;
|
---|
| 68 | uint8_t _reserved[18];
|
---|
[1f78546] | 69 | uint32_t firstc;
|
---|
[2fb88ea] | 70 | uint64_t size;
|
---|
| 71 | } __attribute__ ((packed)) exfat_bitmap_dentry_t;
|
---|
| 72 |
|
---|
| 73 | typedef struct {
|
---|
| 74 | uint8_t _reserved1[3];
|
---|
| 75 | uint32_t checksum;
|
---|
| 76 | uint8_t _reserved2[12];
|
---|
[1f78546] | 77 | uint32_t firstc;
|
---|
[2fb88ea] | 78 | uint64_t size;
|
---|
| 79 | } __attribute__ ((packed)) exfat_uctable_dentry_t;
|
---|
| 80 |
|
---|
| 81 | typedef struct {
|
---|
| 82 | uint8_t count; /* Always zero */
|
---|
| 83 | uint16_t checksum;
|
---|
| 84 | uint16_t flags;
|
---|
| 85 | uint8_t guid[16];
|
---|
| 86 | uint8_t _reserved[10];
|
---|
| 87 | } __attribute__ ((packed)) exfat_guid_dentry_t;
|
---|
| 88 |
|
---|
| 89 | typedef struct {
|
---|
| 90 | uint8_t count;
|
---|
| 91 | uint16_t checksum;
|
---|
| 92 | uint16_t attr;
|
---|
| 93 | uint8_t _reserved1[2];
|
---|
| 94 | uint32_t ctime;
|
---|
| 95 | uint32_t mtime;
|
---|
| 96 | uint32_t atime;
|
---|
| 97 | uint8_t ctime_fine;
|
---|
| 98 | uint8_t mtime_fine;
|
---|
| 99 | uint8_t ctime_tz;
|
---|
| 100 | uint8_t mtime_tz;
|
---|
| 101 | uint8_t atime_tz;
|
---|
| 102 | uint8_t _reserved2[7];
|
---|
| 103 | } __attribute__ ((packed)) exfat_file_dentry_t;
|
---|
| 104 |
|
---|
| 105 | typedef struct {
|
---|
| 106 | uint8_t flags;
|
---|
| 107 | uint8_t _reserved1[1];
|
---|
| 108 | uint8_t name_size;
|
---|
| 109 | uint16_t hash;
|
---|
| 110 | uint8_t _reserved2[2];
|
---|
| 111 | uint64_t valid_data_size;
|
---|
| 112 | uint8_t _reserved3[4];
|
---|
| 113 | uint32_t firstc;
|
---|
| 114 | uint64_t data_size;
|
---|
| 115 | } __attribute__ ((packed)) exfat_stream_dentry_t;
|
---|
| 116 |
|
---|
| 117 | typedef struct {
|
---|
| 118 | uint8_t flags;
|
---|
| 119 | uint16_t name[EXFAT_NAME_PART_LEN];
|
---|
| 120 | } __attribute__ ((packed)) exfat_name_dentry_t;
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | typedef struct {
|
---|
| 124 | uint8_t type;
|
---|
| 125 | union {
|
---|
| 126 | exfat_vollabel_dentry_t vollabel;
|
---|
| 127 | exfat_bitmap_dentry_t bitmap;
|
---|
| 128 | exfat_uctable_dentry_t uctable;
|
---|
| 129 | exfat_guid_dentry_t guid;
|
---|
| 130 | exfat_file_dentry_t file;
|
---|
| 131 | exfat_stream_dentry_t stream;
|
---|
| 132 | exfat_name_dentry_t name;
|
---|
| 133 | };
|
---|
| 134 | } __attribute__ ((packed)) exfat_dentry_t;
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | typedef enum {
|
---|
| 138 | EXFAT_DENTRY_SKIP,
|
---|
| 139 | EXFAT_DENTRY_LAST,
|
---|
| 140 | EXFAT_DENTRY_FREE,
|
---|
| 141 | EXFAT_DENTRY_VOLLABEL,
|
---|
| 142 | EXFAT_DENTRY_BITMAP,
|
---|
| 143 | EXFAT_DENTRY_UCTABLE,
|
---|
| 144 | EXFAT_DENTRY_GUID,
|
---|
| 145 | EXFAT_DENTRY_FILE,
|
---|
| 146 | EXFAT_DENTRY_STREAM,
|
---|
| 147 | EXFAT_DENTRY_NAME
|
---|
| 148 | } exfat_dentry_clsf_t;
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | extern exfat_dentry_clsf_t exfat_classify_dentry(const exfat_dentry_t *d);
|
---|
| 152 |
|
---|
| 153 | extern uint16_t exfat_name_hash(const uint16_t *name);
|
---|
| 154 | extern void exfat_set_checksum(const exfat_dentry_t *d, uint16_t *chksum);
|
---|
| 155 |
|
---|
[1f78546] | 156 | extern void exfat_dentry_get_name(const exfat_name_dentry_t *name, size_t size, uint16_t *dst, size_t *offset);
|
---|
| 157 | extern void exfat_dentry_set_name(const uint16_t *src, size_t *offset, exfat_name_dentry_t *name);
|
---|
[2fb88ea] | 158 |
|
---|
| 159 | extern bool exfat_valid_char(wchar_t ch);
|
---|
| 160 | extern bool exfat_valid_name(const char *name);
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | #endif
|
---|
| 164 |
|
---|
| 165 | /**
|
---|
| 166 | * @}
|
---|
| 167 | */
|
---|