Changeset 2e07f62c in mainline for uspace/lib/libblock/libblock.c


Ignore:
Timestamp:
2010-01-31T18:11:24Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1735f3e, 7d6f7d2b
Parents:
ab4bace (diff), 430de97 (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.
Message:

Merge progress from the file system branch allowing FAT to be unmounted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libblock/libblock.c

    rab4bace r2e07f62c  
    198198        assert(devcon);
    199199       
     200        if (devcon->cache)
     201                (void) block_cache_fini(dev_handle);
     202
    200203        devcon_remove(devcon);
    201204
    202205        if (devcon->bb_buf)
    203206                free(devcon->bb_buf);
    204 
    205         if (devcon->cache) {
    206                 hash_table_destroy(&devcon->cache->block_hash);
    207                 free(devcon->cache);
    208         }
    209207
    210208        munmap(devcon->comm_area, devcon->comm_size);
     
    302300
    303301        devcon->cache = cache;
     302        return EOK;
     303}
     304
     305int block_cache_fini(dev_handle_t dev_handle)
     306{
     307        devcon_t *devcon = devcon_search(dev_handle);
     308        cache_t *cache;
     309        int rc;
     310
     311        if (!devcon)
     312                return ENOENT;
     313        if (!devcon->cache)
     314                return EOK;
     315        cache = devcon->cache;
     316       
     317        /*
     318         * We are expecting to find all blocks for this device handle on the
     319         * free list, i.e. the block reference count should be zero. Do not
     320         * bother with the cache and block locks because we are single-threaded.
     321         */
     322        while (!list_empty(&cache->free_head)) {
     323                block_t *b = list_get_instance(cache->free_head.next,
     324                    block_t, free_link);
     325
     326                list_remove(&b->free_link);
     327                if (b->dirty) {
     328                        memcpy(devcon->comm_area, b->data, b->size);
     329                        rc = write_blocks(devcon, b->boff, 1);
     330                        if (rc != EOK)
     331                                return rc;
     332                }
     333
     334                long key = b->boff;
     335                hash_table_remove(&cache->block_hash, &key, 1);
     336               
     337                free(b->data);
     338                free(b);
     339        }
     340
     341        hash_table_destroy(&cache->block_hash);
     342        devcon->cache = NULL;
     343        free(cache);
     344
    304345        return EOK;
    305346}
Note: See TracChangeset for help on using the changeset viewer.