Changeset 298a6ce in mainline
- Timestamp:
- 2011-06-28T05:47:36Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 82374b2
- Parents:
- 620a367
- Location:
- uspace/srv/fs/fat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_directory.c
r620a367 r298a6ce 59 59 di->bnum = 0; 60 60 di->last = false; 61 62 di->wname[0] = '\0';63 di->lfn_offset = 0;64 di->lfn_size = 0;65 di->long_entry = false;66 di->long_entry_count = 0;67 di->checksum=0;68 69 61 return EOK; 70 62 } … … 162 154 { 163 155 fat_dentry_t *d = NULL; 156 wchar_t wname[FAT_LFN_NAME_SIZE]; 157 size_t lfn_offset, lfn_size; 158 bool long_entry = false; 159 int long_entry_count = 0; 160 uint8_t checksum = 0; 164 161 165 162 do { … … 167 164 switch (fat_classify_dentry(d)) { 168 165 case FAT_DENTRY_LAST: 169 di->long_entry_count = 0;170 di->long_entry = false;166 long_entry_count = 0; 167 long_entry = false; 171 168 return ENOENT; 172 169 case FAT_DENTRY_LFN: 173 if ( di->long_entry) {170 if (long_entry) { 174 171 /* We found long entry */ 175 di->long_entry_count--;176 if ((FAT_LFN_ORDER(d) == di->long_entry_count) &&177 ( di->checksum == FAT_LFN_CHKSUM(d))) {172 long_entry_count--; 173 if ((FAT_LFN_ORDER(d) == long_entry_count) && 174 (checksum == FAT_LFN_CHKSUM(d))) { 178 175 /* Right order! */ 179 fat_lfn_get_entry(d, di->wname, &di->lfn_offset);176 fat_lfn_get_entry(d, wname, &lfn_offset); 180 177 } else { 181 178 /* Something wrong with order. Skip this long entries set */ 182 di->long_entry_count = 0;183 di->long_entry = false;179 long_entry_count = 0; 180 long_entry = false; 184 181 } 185 182 } else { … … 187 184 /* We found Last long entry! */ 188 185 if (FAT_LFN_COUNT(d) <= FAT_LFN_MAX_COUNT) { 189 di->long_entry = true;190 di->long_entry_count = FAT_LFN_COUNT(d);191 di->lfn_size = (FAT_LFN_ENTRY_SIZE *186 long_entry = true; 187 long_entry_count = FAT_LFN_COUNT(d); 188 lfn_size = (FAT_LFN_ENTRY_SIZE * 192 189 (FAT_LFN_COUNT(d) - 1)) + fat_lfn_size(d); 193 di->lfn_offset = di->lfn_size;194 fat_lfn_get_entry(d, di->wname, &di->lfn_offset);195 di->checksum = FAT_LFN_CHKSUM(d);190 lfn_offset = lfn_size; 191 fat_lfn_get_entry(d, wname, &lfn_offset); 192 checksum = FAT_LFN_CHKSUM(d); 196 193 } 197 194 } … … 199 196 break; 200 197 case FAT_DENTRY_VALID: 201 if ( di->long_entry &&202 ( di->checksum == fat_dentry_chksum(d->name))) {203 di->wname[di->lfn_size] = '\0';204 if (wstr_to_str(name, FAT_LFN_NAME_SIZE, di->wname)!=EOK)198 if (long_entry && 199 (checksum == fat_dentry_chksum(d->name))) { 200 wname[lfn_size] = '\0'; 201 if (wstr_to_str(name, FAT_LFN_NAME_SIZE, wname)!=EOK) 205 202 fat_dentry_name_get(d, name); 206 203 } … … 209 206 210 207 *de = d; 211 di->long_entry_count = 0;212 di->long_entry = false;213 208 return EOK; 214 209 default: 215 210 case FAT_DENTRY_SKIP: 216 211 case FAT_DENTRY_FREE: 217 di->long_entry_count = 0;218 di->long_entry = false;212 long_entry_count = 0; 213 long_entry = false; 219 214 break; 220 215 } … … 230 225 fat_dentry_t *d; 231 226 bool flag = false; 227 uint8_t checksum; 232 228 233 229 rc = fat_directory_get(di, &d); 234 230 if (rc != EOK) 235 231 return rc; 236 di->checksum = fat_dentry_chksum(d->name);232 checksum = fat_dentry_chksum(d->name); 237 233 238 234 d->name[0] = FAT_DENTRY_ERASED; … … 242 238 if (fat_directory_get(di, &d) == EOK && 243 239 fat_classify_dentry(d) == FAT_DENTRY_LFN && 244 di->checksum == FAT_LFN_CHKSUM(d)) {240 checksum == FAT_LFN_CHKSUM(d)) { 245 241 if (FAT_IS_LFN(d)) 246 242 flag = true; … … 259 255 { 260 256 int rc; 261 rc = str_to_wstr(di->wname, FAT_LFN_NAME_SIZE, name); 257 int long_entry_count; 258 uint8_t checksum; 259 wchar_t wname[FAT_LFN_NAME_SIZE]; 260 size_t lfn_size, lfn_offset; 261 262 rc = str_to_wstr(wname, FAT_LFN_NAME_SIZE, name); 262 263 if (rc != EOK) 263 264 return rc; 264 if (fat_dentry_is_sfn( di->wname)) {265 if (fat_dentry_is_sfn(wname)) { 265 266 /* NAME could be directly stored in dentry without creating LFN */ 266 267 fat_dentry_name_set(de, name); … … 280 281 { 281 282 /* We should create long entries to store name */ 282 di->lfn_size = wstr_length(di->wname);283 di->long_entry_count = di->lfn_size / FAT_LFN_ENTRY_SIZE;284 if ( di->lfn_size % FAT_LFN_ENTRY_SIZE)285 di->long_entry_count++;286 rc = fat_directory_lookup_free(di, di->long_entry_count+1);283 lfn_size = wstr_length(wname); 284 long_entry_count = lfn_size / FAT_LFN_ENTRY_SIZE; 285 if (lfn_size % FAT_LFN_ENTRY_SIZE) 286 long_entry_count++; 287 rc = fat_directory_lookup_free(di, long_entry_count+1); 287 288 if (rc != EOK) 288 289 return rc; … … 290 291 291 292 /* Write Short entry */ 292 rc = fat_directory_create_sfn(di, de );293 if (rc != EOK) 294 return rc; 295 di->checksum = fat_dentry_chksum(de->name);296 297 rc = fat_directory_seek(di, start_pos+ di->long_entry_count);293 rc = fat_directory_create_sfn(di, de, wname); 294 if (rc != EOK) 295 return rc; 296 checksum = fat_dentry_chksum(de->name); 297 298 rc = fat_directory_seek(di, start_pos+long_entry_count); 298 299 if (rc != EOK) 299 300 return rc; … … 303 304 304 305 /* Write Long entry by parts */ 305 di->lfn_offset = 0;306 lfn_offset = 0; 306 307 fat_dentry_t *d; 307 308 size_t idx = 0; … … 313 314 if (rc != EOK) 314 315 return rc; 315 fat_lfn_set_entry( di->wname, &di->lfn_offset, di->lfn_size+1, d);316 FAT_LFN_CHKSUM(d) = di->checksum;316 fat_lfn_set_entry(wname, &lfn_offset, lfn_size+1, d); 317 FAT_LFN_CHKSUM(d) = checksum; 317 318 FAT_LFN_ORDER(d) = ++idx; 318 319 di->b->dirty = true; 319 } while ( di->lfn_offset < di->lfn_size);320 } while (lfn_offset < lfn_size); 320 321 FAT_LFN_ORDER(d) |= FAT_LFN_LAST; 321 322 322 rc = fat_directory_seek(di, start_pos+ di->long_entry_count);323 rc = fat_directory_seek(di, start_pos+long_entry_count); 323 324 if (rc != EOK) 324 325 return rc; … … 327 328 } 328 329 329 int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de )330 int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de, const wchar_t *wname) 330 331 { 331 332 char name[FAT_NAME_LEN+1]; … … 336 337 memset(number, FAT_PAD, FAT_NAME_LEN); 337 338 338 size_t name_len = wstr_size( di->wname);339 wchar_t *pdot = wstr_rchr( di->wname, '.');339 size_t name_len = wstr_size(wname); 340 wchar_t *pdot = wstr_rchr(wname, '.'); 340 341 ext[FAT_EXT_LEN] = '\0'; 341 342 if (pdot) { 342 343 pdot++; 343 344 wstr_to_ascii(ext, pdot, FAT_EXT_LEN, FAT_SFN_CHAR); 344 name_len = (pdot - di->wname - 1);345 name_len = (pdot - wname - 1); 345 346 } 346 347 if (name_len > FAT_NAME_LEN) 347 348 name_len = FAT_NAME_LEN; 348 wstr_to_ascii(name, di->wname, name_len, FAT_SFN_CHAR);349 wstr_to_ascii(name, wname, name_len, FAT_SFN_CHAR); 349 350 350 351 size_t idx; -
uspace/srv/fs/fat/fat_directory.h
r620a367 r298a6ce 49 49 block_t *b; 50 50 bool last; 51 /* Long entry data */52 wchar_t wname[FAT_LFN_NAME_SIZE];53 size_t lfn_offset;54 size_t lfn_size;55 bool long_entry;56 int long_entry_count;57 uint8_t checksum;58 51 } __attribute__ ((packed)) fat_directory_t; 59 52 … … 75 68 extern int fat_directory_lookup_free(fat_directory_t *di, size_t count); 76 69 extern int fat_directory_write_dentry(fat_directory_t *di, fat_dentry_t *de); 77 extern int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de );70 extern int fat_directory_create_sfn(fat_directory_t *di, fat_dentry_t *de, const wchar_t *wname); 78 71 extern int fat_directory_expand(fat_directory_t *di); 79 72 -
uspace/srv/fs/fat/fat_ops.c
r620a367 r298a6ce 587 587 fat_dentry_t de; 588 588 int rc; 589 wchar_t wname[FAT_LFN_NAME_SIZE]; 589 590 590 591 fibril_mutex_lock(&childp->lock); … … 599 600 fibril_mutex_unlock(&childp->lock); 600 601 601 rc = str_to_wstr( di.wname, FAT_LFN_NAME_SIZE, name);602 rc = str_to_wstr(wname, FAT_LFN_NAME_SIZE, name); 602 603 if (rc != EOK) 603 604 return rc; 604 605 605 if (!fat_lfn_valid( di.wname))606 if (!fat_lfn_valid(wname)) 606 607 return ENOTSUP; 607 608
Note:
See TracChangeset
for help on using the changeset viewer.