[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 |
|
---|
[b1834a01] | 29 | /** @addtogroup exfat
|
---|
[2fb88ea] | 30 | * @{
|
---|
[1b20da0] | 31 | */
|
---|
[2fb88ea] | 32 |
|
---|
| 33 | #ifndef EXFAT_EXFAT_DENTRY_H_
|
---|
| 34 | #define EXFAT_EXFAT_DENTRY_H_
|
---|
| 35 |
|
---|
[78188e5] | 36 | #include <stddef.h>
|
---|
[2fb88ea] | 37 | #include <stdint.h>
|
---|
[3e6a98c5] | 38 | #include <stdbool.h>
|
---|
[28a5ebd] | 39 | #include <uchar.h>
|
---|
[2fb88ea] | 40 |
|
---|
| 41 | #define EXFAT_FILENAME_LEN 255
|
---|
| 42 | #define EXFAT_NAME_PART_LEN 15
|
---|
[f3504c1] | 43 | #define EXFAT_VOLLABEL_LEN 11
|
---|
[2fb88ea] | 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 |
|
---|
[042a725] | 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
|
---|
[2fb88ea] | 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];
|
---|
[1433ecda] | 66 | } __attribute__((packed)) exfat_vollabel_dentry_t;
|
---|
[2fb88ea] | 67 |
|
---|
| 68 | typedef struct {
|
---|
| 69 | uint8_t flags;
|
---|
| 70 | uint8_t _reserved[18];
|
---|
[1f78546] | 71 | uint32_t firstc;
|
---|
[2fb88ea] | 72 | uint64_t size;
|
---|
[1433ecda] | 73 | } __attribute__((packed)) exfat_bitmap_dentry_t;
|
---|
[2fb88ea] | 74 |
|
---|
| 75 | typedef struct {
|
---|
| 76 | uint8_t _reserved1[3];
|
---|
| 77 | uint32_t checksum;
|
---|
| 78 | uint8_t _reserved2[12];
|
---|
[1f78546] | 79 | uint32_t firstc;
|
---|
[2fb88ea] | 80 | uint64_t size;
|
---|
[1433ecda] | 81 | } __attribute__((packed)) exfat_uctable_dentry_t;
|
---|
[2fb88ea] | 82 |
|
---|
| 83 | typedef struct {
|
---|
[1b20da0] | 84 | uint8_t count; /* Always zero */
|
---|
[2fb88ea] | 85 | uint16_t checksum;
|
---|
| 86 | uint16_t flags;
|
---|
| 87 | uint8_t guid[16];
|
---|
| 88 | uint8_t _reserved[10];
|
---|
[1433ecda] | 89 | } __attribute__((packed)) exfat_guid_dentry_t;
|
---|
[2fb88ea] | 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];
|
---|
[1433ecda] | 105 | } __attribute__((packed)) exfat_file_dentry_t;
|
---|
[2fb88ea] | 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;
|
---|
[1433ecda] | 117 | } __attribute__((packed)) exfat_stream_dentry_t;
|
---|
[2fb88ea] | 118 |
|
---|
| 119 | typedef struct {
|
---|
| 120 | uint8_t flags;
|
---|
| 121 | uint16_t name[EXFAT_NAME_PART_LEN];
|
---|
[1433ecda] | 122 | } __attribute__((packed)) exfat_name_dentry_t;
|
---|
[2fb88ea] | 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 | };
|
---|
[1433ecda] | 135 | } __attribute__((packed)) exfat_dentry_t;
|
---|
[2fb88ea] | 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 |
|
---|
[ff0c270] | 150 | extern exfat_dentry_clsf_t exfat_classify_dentry(const exfat_dentry_t *);
|
---|
[2fb88ea] | 151 |
|
---|
[ff0c270] | 152 | extern uint16_t exfat_name_hash(const uint16_t *, const uint16_t *, size_t);
|
---|
[b4af128] | 153 |
|
---|
[ff0c270] | 154 | extern void exfat_dentry_get_name(const exfat_name_dentry_t *, size_t,
|
---|
| 155 | uint16_t *, size_t *);
|
---|
[f3504c1] | 156 | extern void exfat_dentry_get_vollabel(const exfat_vollabel_dentry_t *, size_t,
|
---|
| 157 | uint16_t *);
|
---|
[2fb88ea] | 158 |
|
---|
[28a5ebd] | 159 | extern bool exfat_valid_char(char32_t);
|
---|
[ff0c270] | 160 | extern bool exfat_valid_name(const char *);
|
---|
[2fb88ea] | 161 |
|
---|
[f3504c1] | 162 | extern size_t exfat_utf16_length(const uint16_t *);
|
---|
| 163 |
|
---|
[2fb88ea] | 164 | #endif
|
---|
| 165 |
|
---|
| 166 | /**
|
---|
| 167 | * @}
|
---|
| 168 | */
|
---|