Rev 3675 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3675 | Rev 4377 | ||
|---|---|---|---|
| Line 60... | Line 60... | ||
| 60 | * @return Zero on match, non-zero otherwise. |
60 | * @return Zero on match, non-zero otherwise. |
| 61 | */ |
61 | */ |
| 62 | int fat_dentry_namecmp(char *name, const char *component) |
62 | int fat_dentry_namecmp(char *name, const char *component) |
| 63 | { |
63 | { |
| 64 | int rc; |
64 | int rc; |
| - | 65 | size_t size; |
|
| - | 66 | ||
| 65 | if (!(rc = stricmp(name, component))) |
67 | if (!(rc = stricmp(name, component))) |
| 66 | return rc; |
68 | return rc; |
| 67 | if (!strchr(name, '.')) { |
69 | if (!str_chr(name, '.')) { |
| 68 | /* |
70 | /* |
| 69 | * There is no '.' in the name, so we know that there is enough |
71 | * There is no '.' in the name, so we know that there is enough |
| 70 | * space for appending an extra '.' to name. |
72 | * space for appending an extra '.' to name. |
| 71 | */ |
73 | */ |
| - | 74 | size = str_size(name); |
|
| 72 | name[strlen(name)] = '.'; |
75 | name[size] = '.'; |
| 73 | name[strlen(name) + 1] = '\0'; |
76 | name[size + 1] = '\0'; |
| 74 | rc = stricmp(name, component); |
77 | rc = stricmp(name, component); |
| 75 | } |
78 | } |
| 76 | return rc; |
79 | return rc; |
| 77 | } |
80 | } |
| 78 | 81 | ||
| Line 109... | Line 112... | ||
| 109 | return true; |
112 | return true; |
| 110 | } |
113 | } |
| 111 | 114 | ||
| 112 | void fat_dentry_name_get(const fat_dentry_t *d, char *buf) |
115 | void fat_dentry_name_get(const fat_dentry_t *d, char *buf) |
| 113 | { |
116 | { |
| 114 | int i; |
117 | unsigned int i; |
| 115 | 118 | ||
| 116 | for (i = 0; i < FAT_NAME_LEN; i++) { |
119 | for (i = 0; i < FAT_NAME_LEN; i++) { |
| 117 | if (d->name[i] == FAT_PAD) |
120 | if (d->name[i] == FAT_PAD) |
| 118 | break; |
121 | break; |
| - | 122 | ||
| 119 | if (d->name[i] == FAT_DENTRY_E5_ESC) |
123 | if (d->name[i] == FAT_DENTRY_E5_ESC) |
| 120 | *buf++ = 0xe5; |
124 | *buf++ = 0xe5; |
| - | 125 | else { |
|
| - | 126 | if (d->lcase & FAT_LCASE_LOWER_NAME) |
|
| - | 127 | *buf++ = tolower(d->name[i]); |
|
| 121 | else |
128 | else |
| 122 | *buf++ = d->name[i]; |
129 | *buf++ = d->name[i]; |
| - | 130 | } |
|
| 123 | } |
131 | } |
| - | 132 | ||
| 124 | if (d->ext[0] != FAT_PAD) |
133 | if (d->ext[0] != FAT_PAD) |
| 125 | *buf++ = '.'; |
134 | *buf++ = '.'; |
| - | 135 | ||
| 126 | for (i = 0; i < FAT_EXT_LEN; i++) { |
136 | for (i = 0; i < FAT_EXT_LEN; i++) { |
| 127 | if (d->ext[i] == FAT_PAD) { |
137 | if (d->ext[i] == FAT_PAD) { |
| 128 | *buf = '\0'; |
138 | *buf = '\0'; |
| 129 | return; |
139 | return; |
| 130 | } |
140 | } |
| - | 141 | ||
| 131 | if (d->ext[i] == FAT_DENTRY_E5_ESC) |
142 | if (d->ext[i] == FAT_DENTRY_E5_ESC) |
| 132 | *buf++ = 0xe5; |
143 | *buf++ = 0xe5; |
| - | 144 | else { |
|
| - | 145 | if (d->lcase & FAT_LCASE_LOWER_EXT) |
|
| - | 146 | *buf++ = tolower(d->ext[i]); |
|
| 133 | else |
147 | else |
| 134 | *buf++ = d->ext[i]; |
148 | *buf++ = d->ext[i]; |
| - | 149 | } |
|
| 135 | } |
150 | } |
| - | 151 | ||
| 136 | *buf = '\0'; |
152 | *buf = '\0'; |
| 137 | } |
153 | } |
| 138 | 154 | ||
| 139 | void fat_dentry_name_set(fat_dentry_t *d, const char *name) |
155 | void fat_dentry_name_set(fat_dentry_t *d, const char *name) |
| 140 | { |
156 | { |
| 141 | int i; |
157 | unsigned int i; |
| 142 | const char fake_ext[] = " "; |
158 | const char fake_ext[] = " "; |
| 143 | - | ||
| - | 159 | bool lower_name = true; |
|
| - | 160 | bool lower_ext = true; |
|
| 144 | 161 | ||
| 145 | for (i = 0; i < FAT_NAME_LEN; i++) { |
162 | for (i = 0; i < FAT_NAME_LEN; i++) { |
| 146 | switch ((uint8_t) *name) { |
163 | switch ((uint8_t) *name) { |
| 147 | case 0xe5: |
164 | case 0xe5: |
| 148 | d->name[i] = FAT_DENTRY_E5_ESC; |
165 | d->name[i] = FAT_DENTRY_E5_ESC; |
| 149 | name++; |
166 | name++; |
| Line 151... | Line 168... | ||
| 151 | case '\0': |
168 | case '\0': |
| 152 | case '.': |
169 | case '.': |
| 153 | d->name[i] = FAT_PAD; |
170 | d->name[i] = FAT_PAD; |
| 154 | break; |
171 | break; |
| 155 | default: |
172 | default: |
| - | 173 | if (isalpha(*name)) { |
|
| - | 174 | if (!islower(*name)) |
|
| - | 175 | lower_name = false; |
|
| - | 176 | } |
|
| - | 177 | ||
| 156 | d->name[i] = toupper(*name++); |
178 | d->name[i] = toupper(*name++); |
| 157 | break; |
179 | break; |
| 158 | } |
180 | } |
| 159 | } |
181 | } |
| - | 182 | ||
| 160 | if (*name++ != '.') |
183 | if (*name++ != '.') |
| 161 | name = fake_ext; |
184 | name = fake_ext; |
| - | 185 | ||
| 162 | for (i = 0; i < FAT_EXT_LEN; i++) { |
186 | for (i = 0; i < FAT_EXT_LEN; i++) { |
| 163 | switch ((uint8_t) *name) { |
187 | switch ((uint8_t) *name) { |
| 164 | case 0xe5: |
188 | case 0xe5: |
| 165 | d->ext[i] = FAT_DENTRY_E5_ESC; |
189 | d->ext[i] = FAT_DENTRY_E5_ESC; |
| 166 | name++; |
190 | name++; |
| 167 | break; |
191 | break; |
| 168 | case '\0': |
192 | case '\0': |
| 169 | d->ext[i] = FAT_PAD; |
193 | d->ext[i] = FAT_PAD; |
| 170 | break; |
194 | break; |
| 171 | default: |
195 | default: |
| - | 196 | if (isalpha(*name)) { |
|
| - | 197 | if (!islower(*name)) |
|
| - | 198 | lower_ext = false; |
|
| - | 199 | } |
|
| - | 200 | ||
| 172 | d->ext[i] = toupper(*name++); |
201 | d->ext[i] = toupper(*name++); |
| 173 | break; |
202 | break; |
| 174 | } |
203 | } |
| 175 | } |
204 | } |
| - | 205 | ||
| - | 206 | if (lower_name) |
|
| - | 207 | d->lcase |= FAT_LCASE_LOWER_NAME; |
|
| - | 208 | else |
|
| - | 209 | d->lcase &= ~FAT_LCASE_LOWER_NAME; |
|
| - | 210 | ||
| - | 211 | if (lower_ext) |
|
| - | 212 | d->lcase |= FAT_LCASE_LOWER_EXT; |
|
| - | 213 | else |
|
| - | 214 | d->lcase &= ~FAT_LCASE_LOWER_EXT; |
|
| 176 | } |
215 | } |
| 177 | 216 | ||
| 178 | fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *d) |
217 | fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *d) |
| 179 | { |
218 | { |
| 180 | if (d->attr & FAT_ATTR_VOLLABEL) { |
219 | if (d->attr & FAT_ATTR_VOLLABEL) { |