Changeset 925a21e in mainline for uspace/srv/fs/fat/fat_idx.c
- Timestamp:
- 2011-09-24T14:20:29Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5bf76c1
- Parents:
- 867e2555 (diff), 1ab4aca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_idx.c
r867e2555 r925a21e 59 59 typedef struct { 60 60 link_t link; 61 devmap_handle_t devmap_handle;61 service_id_t service_id; 62 62 63 63 /** Next unassigned index. */ … … 76 76 static LIST_INITIALIZE(unused_list); 77 77 78 static void unused_initialize(unused_t *u, devmap_handle_t devmap_handle)78 static void unused_initialize(unused_t *u, service_id_t service_id) 79 79 { 80 80 link_initialize(&u->link); 81 u-> devmap_handle = devmap_handle;81 u->service_id = service_id; 82 82 u->next = 0; 83 83 u->remaining = ((uint64_t)((fs_index_t)-1)) + 1; … … 85 85 } 86 86 87 static unused_t *unused_find( devmap_handle_t devmap_handle, bool lock)87 static unused_t *unused_find(service_id_t service_id, bool lock) 88 88 { 89 89 unused_t *u; … … 94 94 list_foreach(unused_list, l) { 95 95 u = list_get_instance(l, unused_t, link); 96 if (u-> devmap_handle == devmap_handle)96 if (u->service_id == service_id) 97 97 return u; 98 98 } … … 108 108 /** 109 109 * Global hash table of all used fat_idx_t structures. 110 * The index structures are hashed by the devmap_handle, parent node's first110 * The index structures are hashed by the service_id, parent node's first 111 111 * cluster and index within the parent directory. 112 112 */ … … 116 116 #define UPH_BUCKETS (1 << UPH_BUCKETS_LOG) 117 117 118 #define UPH_ DH_KEY 0118 #define UPH_SID_KEY 0 119 119 #define UPH_PFC_KEY 1 120 120 #define UPH_PDI_KEY 2 … … 122 122 static hash_index_t pos_hash(unsigned long key[]) 123 123 { 124 devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];124 service_id_t service_id = (service_id_t)key[UPH_SID_KEY]; 125 125 fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY]; 126 126 unsigned pdi = (unsigned)key[UPH_PDI_KEY]; … … 142 142 h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) << 143 143 (UPH_BUCKETS_LOG / 2); 144 h |= ( devmap_handle& ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<144 h |= (service_id & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) << 145 145 (3 * (UPH_BUCKETS_LOG / 4)); 146 146 … … 150 150 static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item) 151 151 { 152 devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];152 service_id_t service_id = (service_id_t)key[UPH_SID_KEY]; 153 153 fat_cluster_t pfc; 154 154 unsigned pdi; … … 157 157 switch (keys) { 158 158 case 1: 159 return ( devmap_handle == fidx->devmap_handle);159 return (service_id == fidx->service_id); 160 160 case 3: 161 161 pfc = (fat_cluster_t) key[UPH_PFC_KEY]; 162 162 pdi = (unsigned) key[UPH_PDI_KEY]; 163 return ( devmap_handle == fidx->devmap_handle) && (pfc == fidx->pfc) &&163 return (service_id == fidx->service_id) && (pfc == fidx->pfc) && 164 164 (pdi == fidx->pdi); 165 165 default: … … 183 183 /** 184 184 * Global hash table of all used fat_idx_t structures. 185 * The index structures are hashed by the devmap_handleand index.185 * The index structures are hashed by the service_id and index. 186 186 */ 187 187 static hash_table_t ui_hash; … … 190 190 #define UIH_BUCKETS (1 << UIH_BUCKETS_LOG) 191 191 192 #define UIH_ DH_KEY 0192 #define UIH_SID_KEY 0 193 193 #define UIH_INDEX_KEY 1 194 194 195 195 static hash_index_t idx_hash(unsigned long key[]) 196 196 { 197 devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];197 service_id_t service_id = (service_id_t)key[UIH_SID_KEY]; 198 198 fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY]; 199 199 200 200 hash_index_t h; 201 201 202 h = devmap_handle& ((1 << (UIH_BUCKETS_LOG / 2)) - 1);202 h = service_id & ((1 << (UIH_BUCKETS_LOG / 2)) - 1); 203 203 h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) << 204 204 (UIH_BUCKETS_LOG / 2); … … 209 209 static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item) 210 210 { 211 devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];211 service_id_t service_id = (service_id_t)key[UIH_SID_KEY]; 212 212 fs_index_t index; 213 213 fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link); … … 215 215 switch (keys) { 216 216 case 1: 217 return ( devmap_handle == fidx->devmap_handle);217 return (service_id == fidx->service_id); 218 218 case 2: 219 219 index = (fs_index_t) key[UIH_INDEX_KEY]; 220 return ( devmap_handle == fidx->devmap_handle) &&220 return (service_id == fidx->service_id) && 221 221 (index == fidx->index); 222 222 default: … … 241 241 242 242 /** Allocate a VFS index which is not currently in use. */ 243 static bool fat_index_alloc( devmap_handle_t devmap_handle, fs_index_t *index)243 static bool fat_index_alloc(service_id_t service_id, fs_index_t *index) 244 244 { 245 245 unused_t *u; 246 246 247 247 assert(index); 248 u = unused_find( devmap_handle, true);248 u = unused_find(service_id, true); 249 249 if (!u) 250 250 return false; … … 303 303 304 304 /** Free a VFS index, which is no longer in use. */ 305 static void fat_index_free( devmap_handle_t devmap_handle, fs_index_t index)305 static void fat_index_free(service_id_t service_id, fs_index_t index) 306 306 { 307 307 unused_t *u; 308 308 309 u = unused_find( devmap_handle, true);309 u = unused_find(service_id, true); 310 310 assert(u); 311 311 … … 365 365 } 366 366 367 static int fat_idx_create(fat_idx_t **fidxp, devmap_handle_t devmap_handle)367 static int fat_idx_create(fat_idx_t **fidxp, service_id_t service_id) 368 368 { 369 369 fat_idx_t *fidx; … … 372 372 if (!fidx) 373 373 return ENOMEM; 374 if (!fat_index_alloc( devmap_handle, &fidx->index)) {374 if (!fat_index_alloc(service_id, &fidx->index)) { 375 375 free(fidx); 376 376 return ENOSPC; … … 380 380 link_initialize(&fidx->uih_link); 381 381 fibril_mutex_initialize(&fidx->lock); 382 fidx-> devmap_handle = devmap_handle;382 fidx->service_id = service_id; 383 383 fidx->pfc = FAT_CLST_RES0; /* no parent yet */ 384 384 fidx->pdi = 0; … … 389 389 } 390 390 391 int fat_idx_get_new(fat_idx_t **fidxp, devmap_handle_t devmap_handle)391 int fat_idx_get_new(fat_idx_t **fidxp, service_id_t service_id) 392 392 { 393 393 fat_idx_t *fidx; … … 395 395 396 396 fibril_mutex_lock(&used_lock); 397 rc = fat_idx_create(&fidx, devmap_handle);397 rc = fat_idx_create(&fidx, service_id); 398 398 if (rc != EOK) { 399 399 fibril_mutex_unlock(&used_lock); … … 402 402 403 403 unsigned long ikey[] = { 404 [UIH_ DH_KEY] = devmap_handle,404 [UIH_SID_KEY] = service_id, 405 405 [UIH_INDEX_KEY] = fidx->index, 406 406 }; … … 415 415 416 416 fat_idx_t * 417 fat_idx_get_by_pos( devmap_handle_t devmap_handle, fat_cluster_t pfc, unsigned pdi)417 fat_idx_get_by_pos(service_id_t service_id, fat_cluster_t pfc, unsigned pdi) 418 418 { 419 419 fat_idx_t *fidx; 420 420 link_t *l; 421 421 unsigned long pkey[] = { 422 [UPH_ DH_KEY] = devmap_handle,422 [UPH_SID_KEY] = service_id, 423 423 [UPH_PFC_KEY] = pfc, 424 424 [UPH_PDI_KEY] = pdi, … … 432 432 int rc; 433 433 434 rc = fat_idx_create(&fidx, devmap_handle);434 rc = fat_idx_create(&fidx, service_id); 435 435 if (rc != EOK) { 436 436 fibril_mutex_unlock(&used_lock); … … 439 439 440 440 unsigned long ikey[] = { 441 [UIH_ DH_KEY] = devmap_handle,441 [UIH_SID_KEY] = service_id, 442 442 [UIH_INDEX_KEY] = fidx->index, 443 443 }; … … 458 458 { 459 459 unsigned long pkey[] = { 460 [UPH_ DH_KEY] = idx->devmap_handle,460 [UPH_SID_KEY] = idx->service_id, 461 461 [UPH_PFC_KEY] = idx->pfc, 462 462 [UPH_PDI_KEY] = idx->pdi, … … 471 471 { 472 472 unsigned long pkey[] = { 473 [UPH_ DH_KEY] = idx->devmap_handle,473 [UPH_SID_KEY] = idx->service_id, 474 474 [UPH_PFC_KEY] = idx->pfc, 475 475 [UPH_PDI_KEY] = idx->pdi, … … 482 482 483 483 fat_idx_t * 484 fat_idx_get_by_index( devmap_handle_t devmap_handle, fs_index_t index)484 fat_idx_get_by_index(service_id_t service_id, fs_index_t index) 485 485 { 486 486 fat_idx_t *fidx = NULL; 487 487 link_t *l; 488 488 unsigned long ikey[] = { 489 [UIH_ DH_KEY] = devmap_handle,489 [UIH_SID_KEY] = service_id, 490 490 [UIH_INDEX_KEY] = index, 491 491 }; … … 509 509 { 510 510 unsigned long ikey[] = { 511 [UIH_ DH_KEY] = idx->devmap_handle,511 [UIH_SID_KEY] = idx->service_id, 512 512 [UIH_INDEX_KEY] = idx->index, 513 513 }; 514 devmap_handle_t devmap_handle = idx->devmap_handle;514 service_id_t service_id = idx->service_id; 515 515 fs_index_t index = idx->index; 516 516 … … 526 526 fibril_mutex_unlock(&used_lock); 527 527 /* Release the VFS index. */ 528 fat_index_free( devmap_handle, index);528 fat_index_free(service_id, index); 529 529 /* The index structure itself is freed in idx_remove_callback(). */ 530 530 } … … 548 548 } 549 549 550 int fat_idx_init_by_ devmap_handle(devmap_handle_t devmap_handle)550 int fat_idx_init_by_service_id(service_id_t service_id) 551 551 { 552 552 unused_t *u; … … 556 556 if (!u) 557 557 return ENOMEM; 558 unused_initialize(u, devmap_handle);558 unused_initialize(u, service_id); 559 559 fibril_mutex_lock(&unused_lock); 560 if (!unused_find( devmap_handle, false)) {560 if (!unused_find(service_id, false)) { 561 561 list_append(&u->link, &unused_list); 562 562 } else { … … 568 568 } 569 569 570 void fat_idx_fini_by_ devmap_handle(devmap_handle_t devmap_handle)570 void fat_idx_fini_by_service_id(service_id_t service_id) 571 571 { 572 572 unsigned long ikey[] = { 573 [UIH_ DH_KEY] = devmap_handle573 [UIH_SID_KEY] = service_id 574 574 }; 575 575 unsigned long pkey[] = { 576 [UPH_ DH_KEY] = devmap_handle576 [UPH_SID_KEY] = service_id 577 577 }; 578 578 … … 590 590 * Free the unused and freed structures for this instance. 591 591 */ 592 unused_t *u = unused_find( devmap_handle, true);592 unused_t *u = unused_find(service_id, true); 593 593 assert(u); 594 594 list_remove(&u->link);
Note:
See TracChangeset
for help on using the changeset viewer.