Changeset 34fdb75 in mainline
- Timestamp:
- 2011-06-10T16:55:14Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 65ccd23
- Parents:
- ed19497
- Location:
- uspace/srv/fs/fat
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_dentry.c
red19497 r34fdb75 39 39 #include <ctype.h> 40 40 #include <str.h> 41 #include <errno.h> 41 42 42 43 static bool is_d_char(const char ch) … … 218 219 fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *d) 219 220 { 221 /* if (d->attr == FAT_ATTR_LFN) { */ 222 /* long name entry */ 223 /* if (d->attr & FAT_LFN_ERASED) 224 return FAT_DENTRY_FREE; 225 else 226 return FAT_DENTRY_LFN; 227 }*/ 220 228 if (d->attr & FAT_ATTR_VOLLABEL) { 221 229 /* volume label entry */ … … 259 267 } 260 268 269 /** Get number of bytes in a string with size limit. 270 * 271 * @param str NULL-terminated (or not) string. 272 * @param size Maximum number of bytes to consider. 273 * 274 * @return Number of bytes in string (without 0 and ff). 275 * 276 */ 277 size_t fat_lfn_str_nlength(const uint8_t *str, size_t size) 278 { 279 size_t offset = 0; 280 281 while (offset < size) { 282 if ((str[offset] == 0x00 && str[offset+1] == 0x00) || 283 (str[offset] == 0xff && str[offset+1] == 0xff)) 284 break; 285 286 offset += 2; 287 } 288 return offset; 289 } 290 291 /** Get number of bytes in a FAT long entry occuped by characters. 292 * 293 * @param d FAT long entry. 294 * 295 * @return Number of bytes. 296 * 297 */ 298 size_t fat_lfn_size(const fat_dentry_t *d) 299 { 300 size_t size = 0; 301 302 size += fat_lfn_str_nlength(FAT_LFN_PART1(d), FAT_LFN_PART1_SIZE); 303 size += fat_lfn_str_nlength(FAT_LFN_PART2(d), FAT_LFN_PART2_SIZE); 304 size += fat_lfn_str_nlength(FAT_LFN_PART3(d), FAT_LFN_PART3_SIZE); 305 306 return size; 307 } 308 309 void fat_lfn_copy_part(const uint8_t *src, size_t src_size, uint8_t *dst, size_t *offset) 310 { 311 int i; 312 for (i=src_size-1; i>0 && (*offset)>1; i-=2) { 313 if ((src[i] == 0x00 && src[i-1] == 0x00) || 314 (src[i] == 0xff && src[i-1] == 0xff)) 315 continue; 316 dst[(*offset)-1] = src[i]; 317 dst[(*offset)-2] = src[i-1]; 318 (*offset)-=2; 319 } 320 } 321 322 void fat_lfn_copy_entry(const fat_dentry_t *d, uint8_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 329 int fat_lfn_convert_name(const uint8_t *src, size_t src_size, uint8_t *dst, size_t dst_size) 330 { 331 size_t i, offset = 0; 332 uint16_t c; 333 int rc; 334 for (i=0; i<src_size; i+=2) { 335 if (src[i+1] == 0x00) { 336 if (offset+1 < dst_size) 337 dst[offset++] = src[i]; 338 else 339 return EOVERFLOW; 340 } else { 341 c = (src[i] << 8) | src[i+1]; 342 rc = chr_encode(c, (char*)dst, &offset, dst_size); 343 if (rc!=EOK) { 344 return rc; 345 } 346 } 347 } 348 dst[offset] = 0; 349 return EOK; 350 } 351 261 352 262 353 /** -
uspace/srv/fs/fat/fat_dentry.h
red19497 r34fdb75 50 50 #define FAT_ATTR_SUBDIR 0x10 51 51 #define FAT_ATTR_ARCHIVE 0x20 52 #define FAT_ATTR_L NAME\52 #define FAT_ATTR_LFN \ 53 53 (FAT_ATTR_RDONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLLABEL) 54 54 … … 62 62 #define FAT_DENTRY_DOT 0x2e 63 63 #define FAT_DENTRY_ERASED 0xe5 64 #define FAT_LAST_LONG_ENTRY 0x40 64 #define FAT_LFN_LAST 0x40 65 #define FAT_LFN_ERASED 0x80 66 67 #define FAT_LFN_ORDER(d) (d->lfn.order) 68 #define FAT_IS_LFN(d) \ 69 ((FAT_LFN_ORDER(d) & FAT_LFN_LAST) == FAT_LFN_LAST) 70 #define FAT_LFN_COUNT(d) \ 71 (FAT_LFN_ORDER(d) ^ FAT_LFN_LAST) 72 #define FAT_LFN_PART1(d) (d->lfn.part1) 73 #define FAT_LFN_PART2(d) (d->lfn.part2) 74 #define FAT_LFN_PART3(d) (d->lfn.part3) 75 #define FAT_LFN_ATTR(d) (d->lfn.attr) 76 #define FAT_LFN_CHKSUM(d) (d->lfn.check_sum) 77 78 #define FAT_LFN_NAME_SIZE 255 79 #define FAT_LFN_MAX_COUNT 20 80 #define FAT_LFN_PART1_SIZE 10 81 #define FAT_LFN_PART2_SIZE 12 82 #define FAT_LFN_PART3_SIZE 4 83 #define FAT_LFN_ENTRY_SIZE \ 84 (FAT_LFN_PART1_SIZE + FAT_LFN_PART2_SIZE + FAT_LFN_PART3_SIZE) 65 85 66 86 typedef enum { … … 69 89 FAT_DENTRY_FREE, 70 90 FAT_DENTRY_VALID 91 /* FAT_DENTRY_LFN */ 71 92 } fat_dentry_clsf_t; 72 93 … … 96 117 struct { 97 118 uint8_t order; 98 uint8_t name1[10];119 uint8_t part1[FAT_LFN_PART1_SIZE]; 99 120 uint8_t attr; 100 121 uint8_t type; 101 122 uint8_t check_sum; 102 uint8_t name2[12];123 uint8_t part2[FAT_LFN_PART2_SIZE]; 103 124 uint16_t firstc_lo; /* MUST be 0 */ 104 uint8_t name3[4];105 } l ong_entry__attribute__ ((packed));125 uint8_t part3[FAT_LFN_PART3_SIZE]; 126 } lfn __attribute__ ((packed)); 106 127 }; 107 128 } __attribute__ ((packed)) fat_dentry_t; 129 108 130 109 131 extern int fat_dentry_namecmp(char *, const char *); … … 114 136 extern uint8_t fat_dentry_chksum(uint8_t *); 115 137 138 extern size_t fat_lfn_str_nlength(const uint8_t *, size_t); 139 extern size_t fat_lfn_size(const fat_dentry_t *); 140 extern void fat_lfn_copy_part(const uint8_t *, size_t, uint8_t *, size_t *); 141 extern void fat_lfn_copy_entry(const fat_dentry_t *, uint8_t *, size_t *); 142 extern int fat_lfn_convert_name(const uint8_t *, size_t, uint8_t *, size_t); 143 144 116 145 #endif 117 146
Note:
See TracChangeset
for help on using the changeset viewer.