Changeset ce13577 in mainline


Ignore:
Timestamp:
2011-02-16T08:20:59Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5352d72
Parents:
d241aae
Message:

Basic support for locating an inode

Location:
uspace/lib/ext2
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext2/Makefile

    rd241aae rce13577  
    3737        libext2_filesystem.c \
    3838        libext2_superblock.c \
    39         libext2_block_group.c
     39        libext2_block_group.c \
     40        libext2_inode.c
    4041
    4142include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/ext2/libext2.h

    rd241aae rce13577  
    3939#include "libext2_superblock.h"
    4040#include "libext2_block_group.h"
     41#include "libext2_inode.h"
    4142#include "libext2_filesystem.h"
    4243
  • uspace/lib/ext2/libext2_filesystem.c

    rd241aae rce13577  
    3737#include "libext2_superblock.h"
    3838#include "libext2_block_group.h"
     39#include "libext2_inode.h"
    3940#include <errno.h>
    4041#include <libblock.h>
     
    170171
    171172/**
     173 * Get a reference to inode
     174 *
     175 * @param fs Pointer to filesystem information
     176 * @param index The index number of the inode
     177 * @param ref Pointer where to store pointer to inode reference
     178 *
     179 * @return              EOK on success or negative error code on failure
     180 */
     181int ext2_filesystem_get_inode_ref(ext2_filesystem_t *fs, uint32_t index,
     182    ext2_inode_ref_t **ref)
     183{
     184        int rc;
     185        aoff64_t block_id;
     186        uint32_t block_group;
     187        uint32_t offset_in_group;
     188        uint32_t inodes_per_group;
     189        uint32_t inode_table_start;
     190        uint16_t inode_size;
     191        uint32_t block_size;
     192        ext2_block_group_ref_t *bg_ref;
     193        ext2_inode_ref_t *newref;
     194       
     195        newref = malloc(sizeof(ext2_inode_ref_t));
     196        if (newref == NULL) {
     197                return ENOMEM;
     198        }
     199       
     200        inodes_per_group = ext2_superblock_get_inodes_per_group(fs->superblock);
     201       
     202        // inode numbers are 1-based
     203        index -= 1;
     204        block_group = index / inodes_per_group;
     205        offset_in_group = index % inodes_per_group;
     206       
     207        rc = ext2_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
     208        if (rc != EOK) {
     209                free(newref);
     210                return rc;
     211        }
     212       
     213        inode_table_start = ext2_block_group_get_inode_table_first_block(
     214            bg_ref->block_group);
     215       
     216        inode_size = ext2_superblock_get_inode_size(fs->superblock);
     217        block_size = ext2_superblock_get_block_size(fs->superblock);
     218       
     219        block_id = inode_table_start + ((index * inode_size) / block_size);
     220       
     221        rc = block_get(&newref->block, fs->device, block_id, 0);
     222        if (rc != EOK) {
     223                free(newref);
     224                return rc;
     225        }
     226       
     227        newref->inode = newref->block->data + offset_in_group;
     228       
     229        *ref = newref;
     230       
     231        return EOK;
     232}
     233
     234/**
     235 * Free a reference to inode
     236 *
     237 * @param ref Pointer to inode reference to free
     238 *
     239 * @return              EOK on success or negative error code on failure
     240 */
     241int ext2_filesystem_put_inode_ref(ext2_inode_ref_t *ref)
     242{
     243        int rc;
     244       
     245        rc = block_put(ref->block);
     246        free(ref);
     247       
     248        return rc;
     249}
     250
     251/**
    172252 * Finalize an instance of filesystem
    173253 *
  • uspace/lib/ext2/libext2_filesystem.h

    rd241aae rce13577  
    4040#include "libext2_superblock.h"
    4141#include "libext2_block_group.h"
     42#include "libext2_inode.h"
    4243
    4344typedef struct ext2_filesystem {
     
    5657    ext2_block_group_ref_t **);
    5758extern int ext2_filesystem_put_block_group_ref(ext2_block_group_ref_t *);
     59extern int ext2_filesystem_get_inode_ref(ext2_filesystem_t *, uint32_t,
     60    ext2_inode_ref_t **);
     61extern int ext2_filesystem_put_inode_ref(ext2_inode_ref_t *);
    5862extern void ext2_filesystem_fini(ext2_filesystem_t *);
    5963
Note: See TracChangeset for help on using the changeset viewer.