Changeset e272949 in mainline for uspace/lib/ext2


Ignore:
Timestamp:
2011-02-13T20:27:30Z (14 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
566c401
Parents:
36bca8eb
Message:

Refactor direct reading of superblock

Location:
uspace/lib/ext2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext2/libext2.h

    r36bca8eb re272949  
    7575inline uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *sb);
    7676
    77 int ext2_superblock_read_direct(ext2_superblock_t **superblock,
    78                                                                 devmap_handle_t dev);
     77int ext2_superblock_read_direct(devmap_handle_t, ext2_superblock_t **);
    7978
    8079int ext2_filesystem_init(ext2_filesystem_t *fs, devmap_handle_t dev);
  • uspace/lib/ext2/libext2_filesystem.c

    r36bca8eb re272949  
    3737#include <errno.h>
    3838#include <libblock.h>
    39 #include <mem.h>
    4039#include <malloc.h>
    41 
    42 int ext2_superblock_read_direct(ext2_superblock_t **superblock,
    43                                                                 devmap_handle_t dev) {
    44         int rc;
    45         size_t phys_block_size;
    46         size_t buf_size;
    47         uint8_t *buffer;
    48         size_t first_block;
    49         size_t last_block;
    50         size_t blocks;
    51         size_t offset;
    52         ext2_superblock_t *tmp_superblock;
    53        
    54         rc = block_get_bsize(dev, &phys_block_size);
    55         if (rc != EOK) {
    56                 return rc;
    57         }
    58        
    59         // calculate superblock position and required space
    60         first_block = EXT2_SUPERBLOCK_OFFSET / phys_block_size;
    61         offset = EXT2_SUPERBLOCK_OFFSET % phys_block_size;
    62         last_block = EXT2_SUPERBLOCK_LAST_BYTE / phys_block_size;
    63         blocks = last_block - first_block + 1;
    64         buf_size = blocks * phys_block_size;
    65        
    66         // read the superblock into memory
    67         buffer = malloc(buf_size);
    68         if (buffer == NULL) {
    69                 return ENOMEM;
    70         }
    71        
    72         rc = block_read_direct(dev, first_block, blocks, buffer);
    73         if (rc != EOK) {
    74                 free(buffer);
    75                 return rc;
    76         }
    77        
    78         // copy the superblock from the buffer
    79         // as it may not be at the start of the block
    80         // (i.e. blocks larger than 1K)
    81         tmp_superblock = malloc(EXT2_SUPERBLOCK_SIZE);
    82         if (tmp_superblock == NULL) {
    83                 free(buffer);
    84                 return ENOMEM;
    85         }
    86        
    87         memcpy(tmp_superblock, buffer + offset, EXT2_SUPERBLOCK_SIZE);
    88         free(buffer);
    89         (*superblock) = tmp_superblock;
    90        
    91         return EOK;
    92 }
    9340
    9441/**
     
    10855        }
    10956       
    110         rc = ext2_superblock_read_direct(&temp_superblock, dev);
     57        rc = ext2_superblock_read_direct(dev, &temp_superblock);
    11158        if (rc != EOK) {
    11259                block_fini(dev);
  • uspace/lib/ext2/libext2_superblock.c

    r36bca8eb re272949  
    3535
    3636#include "libext2.h"
     37#include <errno.h>
     38#include <malloc.h>
     39#include <libblock.h>
    3740
    3841/**
     
    104107
    105108
     109/** Read a superblock directly from device (i.e. no libblock cache)
     110 *
     111 * @param devmap_handle Device handle of the block device.
     112 * @param superblock    Pointer where to store pointer to new superblock
     113 *
     114 * @return              EOK on success or negative error code on failure.
     115 */
     116int ext2_superblock_read_direct(devmap_handle_t devmap_handle,
     117    ext2_superblock_t **superblock)
     118{
     119        void *data;
     120        int rc;
     121       
     122        data = malloc(EXT2_SUPERBLOCK_SIZE);
     123        if (data == NULL) {
     124                return ENOMEM;
     125        }
     126       
     127        rc = block_read_bytes_direct(devmap_handle, EXT2_SUPERBLOCK_OFFSET,
     128            EXT2_SUPERBLOCK_SIZE, data);
     129        if (rc != EOK) {
     130                free(data);
     131                return rc;
     132        }
     133       
     134        (*superblock) = data;
     135        return EOK;
     136}
     137
     138
    106139/** @}
    107140 */
Note: See TracChangeset for help on using the changeset viewer.