Changeset 4372b49 in mainline
- 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
- Location:
- uspace/srv/fs/fat
- Files:
-
- 4 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 } -
uspace/srv/fs/fat/fat_dentry.h
r563686b r4372b49 78 78 #define FAT_LFN_NAME_SIZE 255 79 79 #define FAT_LFN_MAX_COUNT 20 80 #define FAT_LFN_PART1_SIZE 1081 #define FAT_LFN_PART2_SIZE 1282 #define FAT_LFN_PART3_SIZE 480 #define FAT_LFN_PART1_SIZE 5 81 #define FAT_LFN_PART2_SIZE 6 82 #define FAT_LFN_PART3_SIZE 2 83 83 #define FAT_LFN_ENTRY_SIZE \ 84 84 (FAT_LFN_PART1_SIZE + FAT_LFN_PART2_SIZE + FAT_LFN_PART3_SIZE) … … 117 117 struct { 118 118 uint8_t order; 119 uint 8_tpart1[FAT_LFN_PART1_SIZE];119 uint16_t part1[FAT_LFN_PART1_SIZE]; 120 120 uint8_t attr; 121 121 uint8_t type; 122 122 uint8_t check_sum; 123 uint 8_tpart2[FAT_LFN_PART2_SIZE];123 uint16_t part2[FAT_LFN_PART2_SIZE]; 124 124 uint16_t firstc_lo; /* MUST be 0 */ 125 uint 8_tpart3[FAT_LFN_PART3_SIZE];126 } lfn __attribute__ ((packed));125 uint16_t part3[FAT_LFN_PART3_SIZE]; 126 } __attribute__ ((packed)) lfn; 127 127 }; 128 128 } __attribute__ ((packed)) fat_dentry_t; … … 136 136 extern uint8_t fat_dentry_chksum(uint8_t *); 137 137 138 extern size_t fat_lfn_str_nlength(const uint 8_t *, size_t);138 extern size_t fat_lfn_str_nlength(const uint16_t *, size_t); 139 139 extern size_t fat_lfn_size(const fat_dentry_t *); 140 extern size_t fat_lfn_copy_part(const uint 8_t *, size_t, uint8_t *, size_t);141 extern size_t fat_lfn_copy_entry(const fat_dentry_t *, uint 8_t *, size_t);142 extern int fat_lfn_convert_name(const uint8_t *, size_t, uint8_t *, size_t);140 extern size_t fat_lfn_copy_part(const uint16_t *, size_t, uint16_t *, size_t *); 141 extern size_t fat_lfn_copy_entry(const fat_dentry_t *, uint16_t *, size_t *); 142 extern int utf16_to_str(char *, size_t, const uint16_t *); 143 143 144 144 -
uspace/srv/fs/fat/fat_directory.c
r563686b r4372b49 41 41 #include <byteorder.h> 42 42 #include <mem.h> 43 #include <str.h> 43 44 44 45 int fat_directory_block_load(fat_directory_t *); … … 58 59 di->last = false; 59 60 60 di-> lfn_utf16[0] = '\0';61 di->wname[0] = '\0'; 61 62 di->lfn_offset = 0; 62 63 di->lfn_size = 0; … … 174 175 (di->checksum == FAT_LFN_CHKSUM(d))) { 175 176 /* Right order! */ 176 di->lfn_offset = fat_lfn_copy_entry(d, di->lfn_utf16, 177 di->lfn_offset); 177 fat_lfn_copy_entry(d, di->wname, &di->lfn_offset); 178 178 } else { 179 179 /* Something wrong with order. Skip this long entries set */ … … 190 190 (FAT_LFN_COUNT(d) - 1)) + fat_lfn_size(d); 191 191 di->lfn_offset = di->lfn_size; 192 di->lfn_offset = fat_lfn_copy_entry(d, di->lfn_utf16, 193 di->lfn_offset); 192 fat_lfn_copy_entry(d, di->wname, &di->lfn_offset); 194 193 di->checksum = FAT_LFN_CHKSUM(d); 195 194 } … … 200 199 if (di->long_entry && 201 200 (di->checksum == fat_dentry_chksum(d->name))) { 202 int rc; 203 rc = fat_lfn_convert_name(di->lfn_utf16, di->lfn_size, 204 (uint8_t*)name, FAT_LFN_NAME_SIZE); 205 if (rc!=EOK) 201 di->wname[di->lfn_size] = '\0'; 202 if (utf16_to_str(name, FAT_LFN_NAME_SIZE, di->wname)!=EOK) 206 203 fat_dentry_name_get(d, name); 207 204 } -
uspace/srv/fs/fat/fat_directory.h
r563686b r4372b49 48 48 bool last; 49 49 /* Long entry data */ 50 uint 8_t lfn_utf16[FAT_LFN_MAX_COUNT * FAT_LFN_ENTRY_SIZE];50 uint16_t wname[FAT_LFN_MAX_COUNT * FAT_LFN_ENTRY_SIZE]; 51 51 size_t lfn_offset; 52 52 size_t lfn_size;
Note:
See TracChangeset
for help on using the changeset viewer.