Changeset 45f04f8 in mainline for uspace/srv/fs/fat/fat_idx.c
- Timestamp:
- 2010-11-18T18:23:43Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3f0a7971, a7811f17, cb569e6
- Parents:
- 51a268f (diff), c63e70c (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
r51a268f r45f04f8 58 58 typedef struct { 59 59 link_t link; 60 dev _handle_t dev_handle;60 devmap_handle_t devmap_handle; 61 61 62 62 /** Next unassigned index. */ … … 75 75 static LIST_INITIALIZE(unused_head); 76 76 77 static void unused_initialize(unused_t *u, dev _handle_t dev_handle)77 static void unused_initialize(unused_t *u, devmap_handle_t devmap_handle) 78 78 { 79 79 link_initialize(&u->link); 80 u->dev _handle = dev_handle;80 u->devmap_handle = devmap_handle; 81 81 u->next = 0; 82 82 u->remaining = ((uint64_t)((fs_index_t)-1)) + 1; … … 84 84 } 85 85 86 static unused_t *unused_find(dev _handle_t dev_handle, bool lock)86 static unused_t *unused_find(devmap_handle_t devmap_handle, bool lock) 87 87 { 88 88 unused_t *u; … … 93 93 for (l = unused_head.next; l != &unused_head; l = l->next) { 94 94 u = list_get_instance(l, unused_t, link); 95 if (u->dev _handle == dev_handle)95 if (u->devmap_handle == devmap_handle) 96 96 return u; 97 97 } … … 106 106 /** 107 107 * Global hash table of all used fat_idx_t structures. 108 * The index structures are hashed by the dev _handle, parent node's first108 * The index structures are hashed by the devmap_handle, parent node's first 109 109 * cluster and index within the parent directory. 110 110 */ … … 120 120 static hash_index_t pos_hash(unsigned long key[]) 121 121 { 122 dev _handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];122 devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY]; 123 123 fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY]; 124 124 unsigned pdi = (unsigned)key[UPH_PDI_KEY]; … … 140 140 h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) << 141 141 (UPH_BUCKETS_LOG / 2); 142 h |= (dev _handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<142 h |= (devmap_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) << 143 143 (3 * (UPH_BUCKETS_LOG / 4)); 144 144 … … 148 148 static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item) 149 149 { 150 dev _handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];150 devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY]; 151 151 fat_cluster_t pfc; 152 152 unsigned pdi; … … 155 155 switch (keys) { 156 156 case 1: 157 return (dev _handle == fidx->dev_handle);157 return (devmap_handle == fidx->devmap_handle); 158 158 case 3: 159 159 pfc = (fat_cluster_t) key[UPH_PFC_KEY]; 160 160 pdi = (unsigned) key[UPH_PDI_KEY]; 161 return (dev _handle == fidx->dev_handle) && (pfc == fidx->pfc) &&161 return (devmap_handle == fidx->devmap_handle) && (pfc == fidx->pfc) && 162 162 (pdi == fidx->pdi); 163 163 default: … … 181 181 /** 182 182 * Global hash table of all used fat_idx_t structures. 183 * The index structures are hashed by the dev _handle and index.183 * The index structures are hashed by the devmap_handle and index. 184 184 */ 185 185 static hash_table_t ui_hash; … … 193 193 static hash_index_t idx_hash(unsigned long key[]) 194 194 { 195 dev _handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY];195 devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY]; 196 196 fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY]; 197 197 198 198 hash_index_t h; 199 199 200 h = dev _handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);200 h = devmap_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1); 201 201 h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) << 202 202 (UIH_BUCKETS_LOG / 2); … … 207 207 static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item) 208 208 { 209 dev _handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY];209 devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY]; 210 210 fs_index_t index; 211 211 fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link); … … 213 213 switch (keys) { 214 214 case 1: 215 return (dev _handle == fidx->dev_handle);215 return (devmap_handle == fidx->devmap_handle); 216 216 case 2: 217 217 index = (fs_index_t) key[UIH_INDEX_KEY]; 218 return (dev _handle == fidx->dev_handle) &&218 return (devmap_handle == fidx->devmap_handle) && 219 219 (index == fidx->index); 220 220 default: … … 239 239 240 240 /** Allocate a VFS index which is not currently in use. */ 241 static bool fat_index_alloc(dev _handle_t dev_handle, fs_index_t *index)241 static bool fat_index_alloc(devmap_handle_t devmap_handle, fs_index_t *index) 242 242 { 243 243 unused_t *u; 244 244 245 245 assert(index); 246 u = unused_find(dev _handle, true);246 u = unused_find(devmap_handle, true); 247 247 if (!u) 248 248 return false; … … 301 301 302 302 /** Free a VFS index, which is no longer in use. */ 303 static void fat_index_free(dev _handle_t dev_handle, fs_index_t index)303 static void fat_index_free(devmap_handle_t devmap_handle, fs_index_t index) 304 304 { 305 305 unused_t *u; 306 306 307 u = unused_find(dev _handle, true);307 u = unused_find(devmap_handle, true); 308 308 assert(u); 309 309 … … 363 363 } 364 364 365 static int fat_idx_create(fat_idx_t **fidxp, dev _handle_t dev_handle)365 static int fat_idx_create(fat_idx_t **fidxp, devmap_handle_t devmap_handle) 366 366 { 367 367 fat_idx_t *fidx; … … 370 370 if (!fidx) 371 371 return ENOMEM; 372 if (!fat_index_alloc(dev _handle, &fidx->index)) {372 if (!fat_index_alloc(devmap_handle, &fidx->index)) { 373 373 free(fidx); 374 374 return ENOSPC; … … 378 378 link_initialize(&fidx->uih_link); 379 379 fibril_mutex_initialize(&fidx->lock); 380 fidx->dev _handle = dev_handle;380 fidx->devmap_handle = devmap_handle; 381 381 fidx->pfc = FAT_CLST_RES0; /* no parent yet */ 382 382 fidx->pdi = 0; … … 387 387 } 388 388 389 int fat_idx_get_new(fat_idx_t **fidxp, dev _handle_t dev_handle)389 int fat_idx_get_new(fat_idx_t **fidxp, devmap_handle_t devmap_handle) 390 390 { 391 391 fat_idx_t *fidx; … … 393 393 394 394 fibril_mutex_lock(&used_lock); 395 rc = fat_idx_create(&fidx, dev _handle);395 rc = fat_idx_create(&fidx, devmap_handle); 396 396 if (rc != EOK) { 397 397 fibril_mutex_unlock(&used_lock); … … 400 400 401 401 unsigned long ikey[] = { 402 [UIH_DH_KEY] = dev _handle,402 [UIH_DH_KEY] = devmap_handle, 403 403 [UIH_INDEX_KEY] = fidx->index, 404 404 }; … … 413 413 414 414 fat_idx_t * 415 fat_idx_get_by_pos(dev _handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)415 fat_idx_get_by_pos(devmap_handle_t devmap_handle, fat_cluster_t pfc, unsigned pdi) 416 416 { 417 417 fat_idx_t *fidx; 418 418 link_t *l; 419 419 unsigned long pkey[] = { 420 [UPH_DH_KEY] = dev _handle,420 [UPH_DH_KEY] = devmap_handle, 421 421 [UPH_PFC_KEY] = pfc, 422 422 [UPH_PDI_KEY] = pdi, … … 430 430 int rc; 431 431 432 rc = fat_idx_create(&fidx, dev _handle);432 rc = fat_idx_create(&fidx, devmap_handle); 433 433 if (rc != EOK) { 434 434 fibril_mutex_unlock(&used_lock); … … 437 437 438 438 unsigned long ikey[] = { 439 [UIH_DH_KEY] = dev _handle,439 [UIH_DH_KEY] = devmap_handle, 440 440 [UIH_INDEX_KEY] = fidx->index, 441 441 }; … … 456 456 { 457 457 unsigned long pkey[] = { 458 [UPH_DH_KEY] = idx->dev _handle,458 [UPH_DH_KEY] = idx->devmap_handle, 459 459 [UPH_PFC_KEY] = idx->pfc, 460 460 [UPH_PDI_KEY] = idx->pdi, … … 469 469 { 470 470 unsigned long pkey[] = { 471 [UPH_DH_KEY] = idx->dev _handle,471 [UPH_DH_KEY] = idx->devmap_handle, 472 472 [UPH_PFC_KEY] = idx->pfc, 473 473 [UPH_PDI_KEY] = idx->pdi, … … 480 480 481 481 fat_idx_t * 482 fat_idx_get_by_index(dev _handle_t dev_handle, fs_index_t index)482 fat_idx_get_by_index(devmap_handle_t devmap_handle, fs_index_t index) 483 483 { 484 484 fat_idx_t *fidx = NULL; 485 485 link_t *l; 486 486 unsigned long ikey[] = { 487 [UIH_DH_KEY] = dev _handle,487 [UIH_DH_KEY] = devmap_handle, 488 488 [UIH_INDEX_KEY] = index, 489 489 }; … … 507 507 { 508 508 unsigned long ikey[] = { 509 [UIH_DH_KEY] = idx->dev _handle,509 [UIH_DH_KEY] = idx->devmap_handle, 510 510 [UIH_INDEX_KEY] = idx->index, 511 511 }; 512 dev _handle_t dev_handle = idx->dev_handle;512 devmap_handle_t devmap_handle = idx->devmap_handle; 513 513 fs_index_t index = idx->index; 514 514 … … 524 524 fibril_mutex_unlock(&used_lock); 525 525 /* Release the VFS index. */ 526 fat_index_free(dev _handle, index);526 fat_index_free(devmap_handle, index); 527 527 /* The index structure itself is freed in idx_remove_callback(). */ 528 528 } … … 546 546 } 547 547 548 int fat_idx_init_by_dev _handle(dev_handle_t dev_handle)548 int fat_idx_init_by_devmap_handle(devmap_handle_t devmap_handle) 549 549 { 550 550 unused_t *u; … … 554 554 if (!u) 555 555 return ENOMEM; 556 unused_initialize(u, dev _handle);556 unused_initialize(u, devmap_handle); 557 557 fibril_mutex_lock(&unused_lock); 558 if (!unused_find(dev _handle, false)) {558 if (!unused_find(devmap_handle, false)) { 559 559 list_append(&u->link, &unused_head); 560 560 } else { … … 566 566 } 567 567 568 void fat_idx_fini_by_dev _handle(dev_handle_t dev_handle)568 void fat_idx_fini_by_devmap_handle(devmap_handle_t devmap_handle) 569 569 { 570 570 unsigned long ikey[] = { 571 [UIH_DH_KEY] = dev _handle571 [UIH_DH_KEY] = devmap_handle 572 572 }; 573 573 unsigned long pkey[] = { 574 [UPH_DH_KEY] = dev _handle574 [UPH_DH_KEY] = devmap_handle 575 575 }; 576 576 … … 588 588 * Free the unused and freed structures for this instance. 589 589 */ 590 unused_t *u = unused_find(dev _handle, true);590 unused_t *u = unused_find(devmap_handle, true); 591 591 assert(u); 592 592 list_remove(&u->link);
Note:
See TracChangeset
for help on using the changeset viewer.