Changes in uspace/srv/fs/fat/fat_idx.c [c7bbf029:19f857a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_idx.c
rc7bbf029 r19f857a 44 44 #include <assert.h> 45 45 #include <fibril_synch.h> 46 #include <malloc.h>47 46 48 47 /** Each instance of this type describes one interval of freed VFS indices. */ … … 59 58 typedef struct { 60 59 link_t link; 61 dev map_handle_t devmap_handle;60 dev_handle_t dev_handle; 62 61 63 62 /** Next unassigned index. */ … … 76 75 static LIST_INITIALIZE(unused_head); 77 76 78 static void unused_initialize(unused_t *u, dev map_handle_t devmap_handle)77 static void unused_initialize(unused_t *u, dev_handle_t dev_handle) 79 78 { 80 79 link_initialize(&u->link); 81 u->dev map_handle = devmap_handle;80 u->dev_handle = dev_handle; 82 81 u->next = 0; 83 82 u->remaining = ((uint64_t)((fs_index_t)-1)) + 1; … … 85 84 } 86 85 87 static unused_t *unused_find(dev map_handle_t devmap_handle, bool lock)86 static unused_t *unused_find(dev_handle_t dev_handle, bool lock) 88 87 { 89 88 unused_t *u; … … 94 93 for (l = unused_head.next; l != &unused_head; l = l->next) { 95 94 u = list_get_instance(l, unused_t, link); 96 if (u->dev map_handle == devmap_handle)95 if (u->dev_handle == dev_handle) 97 96 return u; 98 97 } … … 107 106 /** 108 107 * Global hash table of all used fat_idx_t structures. 109 * The index structures are hashed by the dev map_handle, parent node's first108 * The index structures are hashed by the dev_handle, parent node's first 110 109 * cluster and index within the parent directory. 111 110 */ … … 121 120 static hash_index_t pos_hash(unsigned long key[]) 122 121 { 123 dev map_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];122 dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY]; 124 123 fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY]; 125 124 unsigned pdi = (unsigned)key[UPH_PDI_KEY]; … … 141 140 h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) << 142 141 (UPH_BUCKETS_LOG / 2); 143 h |= (dev map_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<142 h |= (dev_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) << 144 143 (3 * (UPH_BUCKETS_LOG / 4)); 145 144 … … 149 148 static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item) 150 149 { 151 dev map_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];150 dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY]; 152 151 fat_cluster_t pfc; 153 152 unsigned pdi; … … 156 155 switch (keys) { 157 156 case 1: 158 return (dev map_handle == fidx->devmap_handle);157 return (dev_handle == fidx->dev_handle); 159 158 case 3: 160 159 pfc = (fat_cluster_t) key[UPH_PFC_KEY]; 161 160 pdi = (unsigned) key[UPH_PDI_KEY]; 162 return (dev map_handle == fidx->devmap_handle) && (pfc == fidx->pfc) &&161 return (dev_handle == fidx->dev_handle) && (pfc == fidx->pfc) && 163 162 (pdi == fidx->pdi); 164 163 default: … … 182 181 /** 183 182 * Global hash table of all used fat_idx_t structures. 184 * The index structures are hashed by the dev map_handle and index.183 * The index structures are hashed by the dev_handle and index. 185 184 */ 186 185 static hash_table_t ui_hash; … … 194 193 static hash_index_t idx_hash(unsigned long key[]) 195 194 { 196 dev map_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];195 dev_handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY]; 197 196 fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY]; 198 197 199 198 hash_index_t h; 200 199 201 h = dev map_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);200 h = dev_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1); 202 201 h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) << 203 202 (UIH_BUCKETS_LOG / 2); … … 208 207 static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item) 209 208 { 210 dev map_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];209 dev_handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY]; 211 210 fs_index_t index; 212 211 fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link); … … 214 213 switch (keys) { 215 214 case 1: 216 return (dev map_handle == fidx->devmap_handle);215 return (dev_handle == fidx->dev_handle); 217 216 case 2: 218 217 index = (fs_index_t) key[UIH_INDEX_KEY]; 219 return (dev map_handle == fidx->devmap_handle) &&218 return (dev_handle == fidx->dev_handle) && 220 219 (index == fidx->index); 221 220 default: … … 240 239 241 240 /** Allocate a VFS index which is not currently in use. */ 242 static bool fat_index_alloc(dev map_handle_t devmap_handle, fs_index_t *index)241 static bool fat_index_alloc(dev_handle_t dev_handle, fs_index_t *index) 243 242 { 244 243 unused_t *u; 245 244 246 245 assert(index); 247 u = unused_find(dev map_handle, true);246 u = unused_find(dev_handle, true); 248 247 if (!u) 249 248 return false; … … 302 301 303 302 /** Free a VFS index, which is no longer in use. */ 304 static void fat_index_free(dev map_handle_t devmap_handle, fs_index_t index)303 static void fat_index_free(dev_handle_t dev_handle, fs_index_t index) 305 304 { 306 305 unused_t *u; 307 306 308 u = unused_find(dev map_handle, true);307 u = unused_find(dev_handle, true); 309 308 assert(u); 310 309 … … 364 363 } 365 364 366 static int fat_idx_create(fat_idx_t **fidxp, dev map_handle_t devmap_handle)365 static int fat_idx_create(fat_idx_t **fidxp, dev_handle_t dev_handle) 367 366 { 368 367 fat_idx_t *fidx; … … 371 370 if (!fidx) 372 371 return ENOMEM; 373 if (!fat_index_alloc(dev map_handle, &fidx->index)) {372 if (!fat_index_alloc(dev_handle, &fidx->index)) { 374 373 free(fidx); 375 374 return ENOSPC; … … 379 378 link_initialize(&fidx->uih_link); 380 379 fibril_mutex_initialize(&fidx->lock); 381 fidx->dev map_handle = devmap_handle;380 fidx->dev_handle = dev_handle; 382 381 fidx->pfc = FAT_CLST_RES0; /* no parent yet */ 383 382 fidx->pdi = 0; … … 388 387 } 389 388 390 int fat_idx_get_new(fat_idx_t **fidxp, dev map_handle_t devmap_handle)389 int fat_idx_get_new(fat_idx_t **fidxp, dev_handle_t dev_handle) 391 390 { 392 391 fat_idx_t *fidx; … … 394 393 395 394 fibril_mutex_lock(&used_lock); 396 rc = fat_idx_create(&fidx, dev map_handle);395 rc = fat_idx_create(&fidx, dev_handle); 397 396 if (rc != EOK) { 398 397 fibril_mutex_unlock(&used_lock); … … 401 400 402 401 unsigned long ikey[] = { 403 [UIH_DH_KEY] = dev map_handle,402 [UIH_DH_KEY] = dev_handle, 404 403 [UIH_INDEX_KEY] = fidx->index, 405 404 }; … … 414 413 415 414 fat_idx_t * 416 fat_idx_get_by_pos(dev map_handle_t devmap_handle, fat_cluster_t pfc, unsigned pdi)415 fat_idx_get_by_pos(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi) 417 416 { 418 417 fat_idx_t *fidx; 419 418 link_t *l; 420 419 unsigned long pkey[] = { 421 [UPH_DH_KEY] = dev map_handle,420 [UPH_DH_KEY] = dev_handle, 422 421 [UPH_PFC_KEY] = pfc, 423 422 [UPH_PDI_KEY] = pdi, … … 431 430 int rc; 432 431 433 rc = fat_idx_create(&fidx, dev map_handle);432 rc = fat_idx_create(&fidx, dev_handle); 434 433 if (rc != EOK) { 435 434 fibril_mutex_unlock(&used_lock); … … 438 437 439 438 unsigned long ikey[] = { 440 [UIH_DH_KEY] = dev map_handle,439 [UIH_DH_KEY] = dev_handle, 441 440 [UIH_INDEX_KEY] = fidx->index, 442 441 }; … … 457 456 { 458 457 unsigned long pkey[] = { 459 [UPH_DH_KEY] = idx->dev map_handle,458 [UPH_DH_KEY] = idx->dev_handle, 460 459 [UPH_PFC_KEY] = idx->pfc, 461 460 [UPH_PDI_KEY] = idx->pdi, … … 470 469 { 471 470 unsigned long pkey[] = { 472 [UPH_DH_KEY] = idx->dev map_handle,471 [UPH_DH_KEY] = idx->dev_handle, 473 472 [UPH_PFC_KEY] = idx->pfc, 474 473 [UPH_PDI_KEY] = idx->pdi, … … 481 480 482 481 fat_idx_t * 483 fat_idx_get_by_index(dev map_handle_t devmap_handle, fs_index_t index)482 fat_idx_get_by_index(dev_handle_t dev_handle, fs_index_t index) 484 483 { 485 484 fat_idx_t *fidx = NULL; 486 485 link_t *l; 487 486 unsigned long ikey[] = { 488 [UIH_DH_KEY] = dev map_handle,487 [UIH_DH_KEY] = dev_handle, 489 488 [UIH_INDEX_KEY] = index, 490 489 }; … … 508 507 { 509 508 unsigned long ikey[] = { 510 [UIH_DH_KEY] = idx->dev map_handle,509 [UIH_DH_KEY] = idx->dev_handle, 511 510 [UIH_INDEX_KEY] = idx->index, 512 511 }; 513 dev map_handle_t devmap_handle = idx->devmap_handle;512 dev_handle_t dev_handle = idx->dev_handle; 514 513 fs_index_t index = idx->index; 515 514 … … 525 524 fibril_mutex_unlock(&used_lock); 526 525 /* Release the VFS index. */ 527 fat_index_free(dev map_handle, index);526 fat_index_free(dev_handle, index); 528 527 /* The index structure itself is freed in idx_remove_callback(). */ 529 528 } … … 547 546 } 548 547 549 int fat_idx_init_by_dev map_handle(devmap_handle_t devmap_handle)548 int fat_idx_init_by_dev_handle(dev_handle_t dev_handle) 550 549 { 551 550 unused_t *u; … … 555 554 if (!u) 556 555 return ENOMEM; 557 unused_initialize(u, dev map_handle);556 unused_initialize(u, dev_handle); 558 557 fibril_mutex_lock(&unused_lock); 559 if (!unused_find(dev map_handle, false)) {558 if (!unused_find(dev_handle, false)) { 560 559 list_append(&u->link, &unused_head); 561 560 } else { … … 567 566 } 568 567 569 void fat_idx_fini_by_dev map_handle(devmap_handle_t devmap_handle)568 void fat_idx_fini_by_dev_handle(dev_handle_t dev_handle) 570 569 { 571 570 unsigned long ikey[] = { 572 [UIH_DH_KEY] = dev map_handle571 [UIH_DH_KEY] = dev_handle 573 572 }; 574 573 unsigned long pkey[] = { 575 [UPH_DH_KEY] = dev map_handle574 [UPH_DH_KEY] = dev_handle 576 575 }; 577 576 … … 589 588 * Free the unused and freed structures for this instance. 590 589 */ 591 unused_t *u = unused_find(dev map_handle, true);590 unused_t *u = unused_find(dev_handle, true); 592 591 assert(u); 593 592 list_remove(&u->link);
Note:
See TracChangeset
for help on using the changeset viewer.