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


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.