source: mainline/uspace/srv/fs/fat/fat_dentry.h@ 616e73c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 616e73c was c4bbca8, checked in by Oleg Romanenko <romanenko.oleg@…>, 14 years ago

Add copyrights

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2011 Oleg Romanenko
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
37#include <stdint.h>
38#include <bool.h>
39
40#define FAT_NAME_LEN 8
41#define FAT_EXT_LEN 3
42
43#define FAT_NAME_DOT ". "
44#define FAT_NAME_DOT_DOT ".. "
45#define FAT_EXT_PAD " "
46
47#define FAT_ATTR_RDONLY 0x01
48#define FAT_ATTR_HIDDEN 0x02
49#define FAT_ATTR_SYSTEM 0x04
50#define FAT_ATTR_VOLLABEL 0x08
51#define FAT_ATTR_SUBDIR 0x10
52#define FAT_ATTR_ARCHIVE 0x20
53#define FAT_ATTR_LFN \
54 (FAT_ATTR_RDONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLLABEL)
55
56#define FAT_LCASE_LOWER_NAME 0x08
57#define FAT_LCASE_LOWER_EXT 0x10
58
59#define FAT_PAD ' '
60#define FAT_LFN_PAD 0xffff
61#define FAT_SFN_CHAR '_'
62
63#define FAT_DENTRY_UNUSED 0x00
64#define FAT_DENTRY_E5_ESC 0x05
65#define FAT_DENTRY_DOT 0x2e
66#define FAT_DENTRY_ERASED 0xe5
67#define FAT_LFN_LAST 0x40
68#define FAT_LFN_ERASED 0x80
69
70#define FAT_LFN_ORDER(d) (d->lfn.order)
71#define FAT_IS_LFN(d) \
72 ((FAT_LFN_ORDER(d) & FAT_LFN_LAST) == FAT_LFN_LAST)
73#define FAT_LFN_COUNT(d) \
74 (FAT_LFN_ORDER(d) ^ FAT_LFN_LAST)
75#define FAT_LFN_PART1(d) (d->lfn.part1)
76#define FAT_LFN_PART2(d) (d->lfn.part2)
77#define FAT_LFN_PART3(d) (d->lfn.part3)
78#define FAT_LFN_ATTR(d) (d->lfn.attr)
79#define FAT_LFN_CHKSUM(d) (d->lfn.check_sum)
80
81#define FAT_LFN_NAME_SIZE 260
82#define FAT_LFN_MAX_COUNT 20
83#define FAT_LFN_PART1_SIZE 5
84#define FAT_LFN_PART2_SIZE 6
85#define FAT_LFN_PART3_SIZE 2
86#define FAT_LFN_ENTRY_SIZE \
87 (FAT_LFN_PART1_SIZE + FAT_LFN_PART2_SIZE + FAT_LFN_PART3_SIZE)
88
89typedef enum {
90 FAT_DENTRY_SKIP,
91 FAT_DENTRY_LAST,
92 FAT_DENTRY_FREE,
93 FAT_DENTRY_VALID,
94 FAT_DENTRY_LFN
95} fat_dentry_clsf_t;
96
97typedef struct {
98 union {
99 struct {
100 uint8_t name[8];
101 uint8_t ext[3];
102 uint8_t attr;
103 uint8_t lcase;
104 uint8_t ctime_fine;
105 uint16_t ctime;
106 uint16_t cdate;
107 uint16_t adate;
108 union {
109 uint16_t eaidx; /* FAT12/FAT16 */
110 uint16_t firstc_hi; /* FAT32 */
111 } __attribute__ ((packed));
112 uint16_t mtime;
113 uint16_t mdate;
114 union {
115 uint16_t firstc; /* FAT12/FAT16 */
116 uint16_t firstc_lo; /* FAT32 */
117 } __attribute__ ((packed));
118 uint32_t size;
119 } __attribute__ ((packed));
120 struct {
121 uint8_t order;
122 uint16_t part1[FAT_LFN_PART1_SIZE];
123 uint8_t attr;
124 uint8_t type;
125 uint8_t check_sum;
126 uint16_t part2[FAT_LFN_PART2_SIZE];
127 uint16_t firstc_lo; /* MUST be 0 */
128 uint16_t part3[FAT_LFN_PART3_SIZE];
129 } __attribute__ ((packed)) lfn;
130 };
131} __attribute__ ((packed)) fat_dentry_t;
132
133
134extern int fat_dentry_namecmp(char *, const char *);
135extern void fat_dentry_name_get(const fat_dentry_t *, char *);
136extern void fat_dentry_name_set(fat_dentry_t *, const char *);
137extern fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *);
138extern uint8_t fat_dentry_chksum(uint8_t *);
139
140extern size_t fat_lfn_str_nlength(const uint16_t *, size_t);
141extern size_t fat_lfn_size(const fat_dentry_t *);
142extern size_t fat_lfn_get_part(const uint16_t *, size_t, wchar_t *, size_t *);
143extern size_t fat_lfn_get_entry(const fat_dentry_t *, wchar_t *, size_t *);
144extern size_t fat_lfn_set_part(const wchar_t *, size_t *, size_t, uint16_t *, size_t);
145extern size_t fat_lfn_set_entry(const wchar_t *, size_t *, size_t, fat_dentry_t *);
146
147extern void wstr_to_ascii(char *dst, const wchar_t *src, size_t count, uint8_t pad);
148
149extern bool fat_sfn_valid_char(wchar_t);
150extern bool fat_sfn_valid(const wchar_t *);
151extern bool fat_lfn_valid(const wchar_t *wstr);
152extern bool fat_dentry_is_sfn(const wchar_t *);
153
154
155#endif
156
157/**
158 * @}
159 */
Note: See TracBrowser for help on using the repository browser.