Changeset 411e9ca in mainline for uspace/srv/fs/fat/fat_dentry.c
- Timestamp:
- 2011-07-07T19:57:47Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3e018e45
- Parents:
- fc97128
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_dentry.c
rfc97128 r411e9ca 288 288 } 289 289 290 size_t fat_lfn_set_part(const wchar_t *src, size_t *offset, size_t src_size, uint16_t *dst, size_t dst_size)290 size_t fat_lfn_set_part(const uint16_t *src, size_t *offset, size_t src_size, uint16_t *dst, size_t dst_size) 291 291 { 292 292 size_t idx; … … 302 302 } 303 303 304 size_t fat_lfn_set_entry(const wchar_t *src, size_t *offset, size_t size, fat_dentry_t *d)304 size_t fat_lfn_set_entry(const uint16_t *src, size_t *offset, size_t size, fat_dentry_t *d) 305 305 { 306 306 fat_lfn_set_part(src, offset, size, FAT_LFN_PART1(d), FAT_LFN_PART1_SIZE); … … 316 316 } 317 317 318 bool fat_sfn_valid_char(wchar_t c) 319 { 320 char valid[] = {"_.$%\'-@~!(){}^#&"}; 321 size_t idx=0; 322 323 if (!ascii_check(c)) 324 return false; 325 if (isdigit(c) || isupper(c)) 326 return true; 327 while(valid[idx]!=0) 328 if (c == valid[idx++]) 329 return true; 330 331 return false; 332 } 333 334 bool fat_sfn_valid(const wchar_t *wstr) 335 { 336 wchar_t c; 337 size_t idx=0; 338 if (wstr[idx] == 0 || wstr[idx] == '.') 339 return false; 340 while ((c=wstr[idx++]) != 0) { 341 if (!fat_sfn_valid_char(c)) 342 return false; 343 } 344 return true; 345 } 346 347 /* TODO: add more checks to long name */ 348 bool fat_lfn_valid(const wchar_t *wstr) 349 { 350 wchar_t c; 351 size_t idx=0; 352 if (wstr[idx] == 0 || wstr[idx] == '.') 353 return false; 354 while ((c=wstr[idx++]) != 0) { 355 if (ascii_check(c)) { 356 if (c == '?' || c == '*' || c == '\\' || c == '/') 357 return false; 358 } 359 } 360 return true; 361 } 362 363 void wstr_to_ascii(char *dst, const wchar_t *src, size_t count, uint8_t pad) 364 { 318 void str_to_ascii(char *dst, const char *src, size_t count, uint8_t pad) 319 { 320 wchar_t ch; 321 size_t off = 0; 365 322 size_t i = 0; 323 366 324 while (i < count) { 367 if (src && *src) { 368 if (ascii_check(*src)) { 369 *dst = toupper(*src); 370 src++; 371 } 325 if ((ch = str_decode(src, &off, STR_NO_LIMIT)) != 0) { 326 if (ascii_check(ch) & IS_D_CHAR(ch)) 327 *dst = toupper(ch); 372 328 else 373 329 *dst = pad; … … 382 338 } 383 339 384 bool fat_dentry_is_sfn(const wchar_t *wstr) 385 { 386 /* 1. Length <= 11 characters */ 387 if (wstr_length(wstr) > (FAT_NAME_LEN + FAT_EXT_LEN)) 388 return false; 389 /* 390 * 2. All characters in string should be ASCII 391 * 3. All letters must be uppercase 392 * 4. String should not contain invalid characters 393 */ 394 if (!fat_sfn_valid(wstr)) 395 return false; 396 340 bool fat_valid_name(const char *name) 341 { 342 wchar_t ch; 343 size_t offset=0; 344 bool result = true; 345 346 while ((ch = str_decode(name, &offset, STR_NO_LIMIT)) != 0) { 347 if (wstr_chr(FAT_STOP_CHARS, ch) != NULL) { 348 result = false; 349 break; 350 } 351 } 352 return result; 353 } 354 355 bool fat_valid_short_name(const char *name) 356 { 357 unsigned int i; 358 unsigned int dot = 0; 359 bool dot_found = false; 360 361 for (i = 0; name[i]; i++) { 362 if (name[i] == '.') { 363 if (dot_found) { 364 return false; 365 } else { 366 dot_found = true; 367 dot = i; 368 } 369 } else { 370 if (!IS_D_CHAR(name[i])) 371 return false; 372 } 373 } 374 375 if (dot_found) { 376 if (dot > FAT_NAME_LEN) 377 return false; 378 if (i - dot > FAT_EXT_LEN + 1) 379 return false; 380 } else { 381 if (i > FAT_NAME_LEN) 382 return false; 383 } 384 397 385 return true; 398 386 } 399 387 388 size_t utf16_length(const uint16_t *wstr) 389 { 390 size_t len = 0; 391 392 while (*wstr++ != 0) 393 len++; 394 395 return len; 396 } 400 397 401 398 /**
Note:
See TracChangeset
for help on using the changeset viewer.