Changeset b7b6753 in mainline for uspace/srv/fs/fat/fat_idx.c
- Timestamp:
- 2008-06-06T20:44:18Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1c03c17
- Parents:
- cde485d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_idx.c
rcde485d rb7b6753 84 84 } 85 85 86 static unused_t *unused_find(dev_handle_t dev_handle, bool lock) 87 { 88 unused_t *u; 89 link_t *l; 90 91 if (lock) 92 futex_down(&unused_futex); 93 for (l = unused_head.next; l != &unused_head; l = l->next) { 94 u = list_get_instance(l, unused_t, link); 95 if (u->dev_handle == dev_handle) 96 return u; 97 } 98 if (lock) 99 futex_up(&unused_futex); 100 return NULL; 101 } 102 86 103 /** Futex protecting the up_hash and ui_hash. */ 87 104 static futex_t used_futex = FUTEX_INITIALIZER; … … 200 217 static bool fat_idx_alloc(dev_handle_t dev_handle, fs_index_t *index) 201 218 { 202 link_t *l;203 219 unused_t *u; 204 220 205 221 assert(index); 206 futex_down(&unused_futex); 207 for (l = unused_head.next; l != &unused_head; l = l->next) { 208 u = list_get_instance(l, unused_t, link); 209 if (u->dev_handle == dev_handle) 210 goto hit; 211 } 212 futex_up(&unused_futex); 213 214 /* dev_handle not found */ 215 return false; 216 217 hit: 222 u = unused_find(dev_handle, true); 223 if (!u) 224 return false; 225 218 226 if (list_empty(&u->freed_head)) { 219 227 if (u->remaining) { … … 271 279 static void fat_idx_free(dev_handle_t dev_handle, fs_index_t index) 272 280 { 273 link_t *l;274 281 unused_t *u; 275 282 276 futex_down(&unused_futex); 277 for (l = unused_head.next; l != &unused_head; l = l->next) { 278 u = list_get_instance(l, unused_t, link); 279 if (u->dev_handle == dev_handle) 280 goto hit; 281 } 282 futex_up(&unused_futex); 283 284 /* should not happen */ 285 assert(0); 286 287 hit: 283 u = unused_find(dev_handle, true); 284 assert(u); 285 288 286 if (u->next == index + 1) { 289 287 /* The index can be returned directly to the counter. */ … … 431 429 int fat_idx_init_by_dev_handle(dev_handle_t dev_handle) 432 430 { 433 unused_t *u = (unused_t *) malloc(sizeof(unused_t)); 431 unused_t *u; 432 int rc = EOK; 433 434 u = (unused_t *) malloc(sizeof(unused_t)); 434 435 if (!u) 435 436 return ENOMEM; 436 437 unused_initialize(u, dev_handle); 437 438 futex_down(&unused_futex); 438 list_append(&u->link, &unused_head); 439 if (!unused_find(dev_handle, false)) 440 list_append(&u->link, &unused_head); 441 else 442 rc = EEXIST; 439 443 futex_up(&unused_futex); 440 return EOK;444 return rc; 441 445 } 442 446 … … 444 448 { 445 449 unused_t *u; 446 link_t *l; 447 448 futex_down(&unused_futex); 449 for (l = unused_head.next; l != &unused_head; l = l->next) { 450 u = list_get_instance(l, unused_t, link); 451 if (u->dev_handle == dev_handle) 452 goto hit; 453 } 454 futex_up(&unused_futex); 455 456 assert(false); /* should not happen */ 457 458 hit: 450 451 u = unused_find(dev_handle, true); 452 assert(u); 459 453 list_remove(&u->link); 460 454 futex_up(&unused_futex);
Note:
See TracChangeset
for help on using the changeset viewer.