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