Changeset 4372b49 in mainline for uspace/srv/fs/fat/fat_dentry.c
- Timestamp:
- 2011-06-21T12:02:24Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9553d7d
- Parents:
- 563686b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_dentry.c
r563686b r4372b49 41 41 #include <errno.h> 42 42 #include <byteorder.h> 43 #include <assert.h> 43 44 44 45 static bool is_d_char(const char ch) … … 276 277 * 277 278 */ 278 size_t fat_lfn_str_nlength(const uint 8_t *str, size_t size)279 size_t fat_lfn_str_nlength(const uint16_t *str, size_t size) 279 280 { 280 281 size_t offset = 0; 281 282 282 283 while (offset < size) { 283 if ((str[offset] == 0x00 && str[offset+1] == 0x00) || 284 (str[offset] == 0xff && str[offset+1] == 0xff)) 285 break; 286 287 offset += 2; 284 if (str[offset] == 0 || str[offset] == 0xffff) 285 break; 286 offset++; 288 287 } 289 288 return offset; … … 308 307 } 309 308 310 size_t fat_lfn_copy_part(const uint8_t *src, size_t src_size, uint8_t *dst, size_t offset) 311 { 312 int i; 313 for (i=src_size-1; i>0 && offset>1; i-=2) { 314 if ((src[i] == 0x00 && src[i-1] == 0x00) || 315 (src[i] == 0xff && src[i-1] == 0xff)) 309 size_t fat_lfn_copy_part(const uint16_t *src, size_t src_size, uint16_t *dst, size_t *offset) 310 { 311 while (src_size!=0 && (*offset)!=0) { 312 src_size--; 313 if (src[src_size] == 0 || src[src_size] == 0xffff) 316 314 continue; 317 dst[offset-1] = src[i]; 318 dst[offset-2] = src[i-1]; 319 offset-=2; 320 } 321 return offset; 322 } 323 324 size_t fat_lfn_copy_entry(const fat_dentry_t *d, uint8_t *dst, size_t offset) 325 { 326 offset = fat_lfn_copy_part(FAT_LFN_PART3(d), 327 FAT_LFN_PART3_SIZE, dst, offset); 328 offset = fat_lfn_copy_part(FAT_LFN_PART2(d), 329 FAT_LFN_PART2_SIZE, dst, offset); 330 offset = fat_lfn_copy_part(FAT_LFN_PART1(d), 331 FAT_LFN_PART1_SIZE, dst, offset); 332 333 return offset; 334 } 335 336 int fat_lfn_convert_name(const uint8_t *src, size_t src_size, uint8_t *dst, size_t dst_size) 337 { 338 size_t i, offset = 0; 339 uint16_t c; 315 316 (*offset)--; 317 dst[(*offset)] = uint16_t_le2host(src[src_size]); 318 } 319 return (*offset); 320 } 321 322 size_t fat_lfn_copy_entry(const fat_dentry_t *d, uint16_t *dst, size_t *offset) 323 { 324 fat_lfn_copy_part(FAT_LFN_PART3(d), FAT_LFN_PART3_SIZE, dst, offset); 325 fat_lfn_copy_part(FAT_LFN_PART2(d), FAT_LFN_PART2_SIZE, dst, offset); 326 fat_lfn_copy_part(FAT_LFN_PART1(d), FAT_LFN_PART1_SIZE, dst, offset); 327 328 return *offset; 329 } 330 331 /** Convert utf16 string to string. 332 * 333 * Convert wide string @a src to string. The output is written to the buffer 334 * specified by @a dest and @a size. @a size must be non-zero and the string 335 * written will always be well-formed. 336 * 337 * @param dest Destination buffer. 338 * @param size Size of the destination buffer. 339 * @param src Source wide string. 340 */ 341 int utf16_to_str(char *dest, size_t size, const uint16_t *src) 342 { 340 343 int rc; 341 for (i=0; i<src_size; i+=2) { 342 if (src[i+1] == 0x00) { 343 if (offset+1 < dst_size) 344 dst[offset++] = src[i]; 345 else 346 return EOVERFLOW; 347 } else { 348 c = uint16_t_le2host((src[i] << 8) | src[i+1]); 349 rc = chr_encode(c, (char*)dst, &offset, dst_size); 350 if (rc!=EOK) { 351 return rc; 352 } 353 } 354 } 355 dst[offset] = 0; 344 uint16_t ch; 345 size_t src_idx, dest_off; 346 347 /* There must be space for a null terminator in the buffer. */ 348 assert(size > 0); 349 350 src_idx = 0; 351 dest_off = 0; 352 353 while ((ch = src[src_idx++]) != 0) { 354 rc = chr_encode(ch, dest, &dest_off, size - 1); 355 if (rc != EOK) 356 return rc; 357 } 358 359 dest[dest_off] = '\0'; 356 360 return EOK; 357 361 }
Note:
See TracChangeset
for help on using the changeset viewer.