source: mainline/uspace/srv/fs/exfat/exfat_dentry.c@ 062d900

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 062d900 was e738d56, checked in by Maurizio Lombardi <m.lombardi85@…>, 14 years ago

exfat: rename extern symbols not prefixed by "exfat_"

  • Property mode set to 100644
File size: 3.5 KB
Line 
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/**
34 * @file exfat_dentry.c
35 * @brief Functions that work with exFAT directory entries.
36 */
37
38#include "exfat_dentry.h"
39#include <ctype.h>
40#include <str.h>
41#include <errno.h>
42#include <byteorder.h>
43#include <assert.h>
44
45exfat_dentry_clsf_t exfat_classify_dentry(const exfat_dentry_t *d)
46{
47 switch (d->type) {
48 case EXFAT_TYPE_VOLLABEL:
49 return EXFAT_DENTRY_VOLLABEL;
50 case EXFAT_TYPE_BITMAP:
51 return EXFAT_DENTRY_BITMAP;
52 case EXFAT_TYPE_UCTABLE:
53 return EXFAT_DENTRY_UCTABLE;
54 case EXFAT_TYPE_GUID:
55 return EXFAT_DENTRY_GUID;
56 case EXFAT_TYPE_FILE:
57 return EXFAT_DENTRY_FILE;
58 case EXFAT_TYPE_STREAM:
59 return EXFAT_DENTRY_STREAM;
60 case EXFAT_TYPE_NAME:
61 return EXFAT_DENTRY_NAME;
62 case EXFAT_TYPE_UNUSED:
63 return EXFAT_DENTRY_LAST;
64 default:
65 if (d->type & EXFAT_TYPE_USED)
66 return EXFAT_DENTRY_SKIP;
67 else
68 return EXFAT_DENTRY_FREE;
69 }
70}
71
72uint16_t exfat_name_hash(const uint16_t *name, const uint16_t *uctable, size_t chars)
73{
74 uint16_t hash = 0;
75 uint16_t ch;
76 while (*name) {
77 if (*name < chars)
78 ch = uint16_t_le2host(uctable[*name]);
79 else
80 ch = *name;
81 name++;
82
83 hash = ((hash << 15) | (hash >> 1)) + (ch & 0xff);
84 hash = ((hash << 15) | (hash >> 1)) + (ch >> 8);
85 }
86
87 return hash;
88}
89
90void exfat_dentry_get_name(const exfat_name_dentry_t *name, size_t size, uint16_t *dst, size_t *offset)
91{
92 size_t i = 0;
93 while (i < EXFAT_NAME_PART_LEN && *offset < size) {
94 dst[*offset] = uint16_t_le2host(name->name[i]);
95 i++;
96 (*offset)++;
97 }
98 dst[*offset] = '\0';
99}
100
101bool exfat_valid_char(wchar_t ch)
102{
103 switch (ch) {
104 case 0x01 ... 0x1F:
105 case '/':
106 case '\\':
107 case '?':
108 case '|':
109 case '>':
110 case '<':
111 case '"':
112 case '*':
113 case ':':
114 return false;
115 default:
116 return true;
117 }
118}
119
120bool exfat_valid_name(const char *name)
121{
122 size_t off = 0;
123 wchar_t ch;
124
125 while ((ch = str_decode(name, &off, STR_NO_LIMIT)) != 0) {
126 if (!exfat_valid_char(ch))
127 return false;
128 }
129 return true;
130}
131
132size_t exfat_utf16_length(const uint16_t *wstr)
133{
134 size_t len = 0;
135
136 while (*wstr++ != 0)
137 len++;
138
139 return len;
140}
141
142/**
143 * @}
144 */
Note: See TracBrowser for help on using the repository browser.