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