Changeset d241aae in mainline for uspace/lib/ext2/libext2_filesystem.c


Ignore:
Timestamp:
2011-02-15T19:24:38Z (14 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce13577
Parents:
1d6f507
Message:

Add support for reading ext2 block group descriptors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext2/libext2_filesystem.c

    r1d6f507 rd241aae  
    3434 */
    3535
    36 #include "libext2.h"
     36#include "libext2_filesystem.h"
     37#include "libext2_superblock.h"
     38#include "libext2_block_group.h"
    3739#include <errno.h>
    3840#include <libblock.h>
     
    105107
    106108/**
     109 * Get a reference to block descriptor
     110 *
     111 * @param fs Pointer to filesystem information
     112 * @param bgid Index of block group to find
     113 * @param ref Pointer where to store pointer to block group reference
     114 *
     115 * @return              EOK on success or negative error code on failure
     116 */
     117int ext2_filesystem_get_block_group_ref(ext2_filesystem_t *fs, uint32_t bgid,
     118    ext2_block_group_ref_t **ref)
     119{
     120        int rc;
     121        aoff64_t block_id;
     122        uint32_t descriptors_per_block;
     123        size_t offset;
     124        ext2_block_group_ref_t *newref;
     125       
     126        newref = malloc(sizeof(ext2_block_group_ref_t));
     127        if (newref == NULL) {
     128                return ENOMEM;
     129        }
     130       
     131        descriptors_per_block = ext2_superblock_get_block_size(fs->superblock)
     132            / EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE;
     133       
     134        // Block group descriptor table starts at the next block after superblock
     135        block_id = ext2_superblock_get_first_block(fs->superblock) + 1;
     136       
     137        // Find the block containing the descriptor we are looking for
     138        block_id += bgid / descriptors_per_block;
     139        offset = (bgid % descriptors_per_block) * EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE;
     140       
     141        rc = block_get(&newref->block, fs->device, block_id, 0);
     142        if (rc != EOK) {
     143                free(newref);
     144                return rc;
     145        }
     146       
     147        newref->block_group = newref->block->data + offset;
     148       
     149        *ref = newref;
     150       
     151        return EOK;
     152}
     153
     154/**
     155 * Free a reference to block group
     156 *
     157 * @param ref Pointer to block group reference to free
     158 *
     159 * @return              EOK on success or negative error code on failure
     160 */
     161int ext2_filesystem_put_block_group_ref(ext2_block_group_ref_t *ref)
     162{
     163        int rc;
     164       
     165        rc = block_put(ref->block);
     166        free(ref);
     167       
     168        return rc;
     169}
     170
     171/**
    107172 * Finalize an instance of filesystem
    108173 *
Note: See TracChangeset for help on using the changeset viewer.