Changeset 36bca8eb in mainline


Ignore:
Timestamp:
2011-02-13T18:55:00Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e272949
Parents:
d5e2763
Message:

Add some more superblock members and function to read a superblock

Location:
uspace
Files:
2 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/ext2info/ext2info.c

    rd5e2763 r36bca8eb  
    6060        char *dev_path;
    6161        devmap_handle_t handle;
    62         size_t block_size;
    63         aoff64_t dev_nblocks;
    64         uint8_t *data;
    6562        ext2_superblock_t *superblock;
    6663       
     
    9592        }
    9693
    97         rc = block_get_bsize(handle, &block_size);
    98         if (rc != EOK) {
    99                 printf(NAME ": Error determining device block size.\n");
    100                 return 2;
    101         }
    102 
    103         rc = block_get_nblocks(handle, &dev_nblocks);
    104         if (rc != EOK) {
    105                 printf(NAME ": Warning, failed to obtain block device size.\n");
    106         }
    107 
    108         data = malloc(block_size);
    109         if (data == NULL) {
    110                 printf(NAME ": Error allocating data buffer of %" PRIuOFF64 " bytes", (aoff64_t) block_size);
    111                 block_fini(handle);
     94        rc = ext2_superblock_read_direct(&superblock, handle);
     95        if (rc != EOK)  {
     96                printf(NAME ": Error reading superblock.\n");
    11297                return 3;
    11398        }
    114        
    115         // TODO: don't assume device block size of 512 bytes
    116         rc = block_read_direct(handle, 2, 1, data);
    117         if (rc != EOK) {
    118                 printf(NAME ": Error reading block");
    119                 free(data);
    120                 return 3;
    121         }
    122        
    123         superblock = (ext2_superblock_t *) data;
    12499       
    125100        printf("Superblock:\n");
     
    133108       
    134109       
    135         free(data);
     110        free(superblock);
    136111
    137112        block_fini(handle);
  • uspace/lib/ext2/Makefile

    rd5e2763 r36bca8eb  
    3131USPACE_PREFIX = ../..
    3232LIBRARY = libext2
     33EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
    3334
    3435SOURCES = \
    35         libext2.c
     36        libext2_filesystem.c \
     37        libext2_superblock.c
    3638
    3739include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/ext2/libext2.h

    rd5e2763 r36bca8eb  
    3838
    3939#include <byteorder.h>
     40#include <libblock.h>
    4041
    4142typedef struct ext2_superblock {
    42         uint8_t unused[56];
    43         uint16_t magic;
    44 } ext2_superblock_t;
     43        uint8_t         unused[20];
     44        uint32_t        first_block; // Block containing the superblock (either 0 or 1)
     45        uint32_t        block_size_log2; // log_2(block_size)
     46        int32_t         fragment_size_log2; // log_2(fragment size)
     47        uint32_t        blocks_per_group; // Number of blocks in one block group
     48        uint32_t        fragments_per_group; // Number of fragments per block group
     49        uint32_t        inodes_per_group; // Number of inodes per block group
     50        uint8_t         unused2[12];
     51        uint16_t        magic; // Magic value
     52} __attribute__ ((packed)) ext2_superblock_t;
     53// TODO: add __attribute__((aligned(...)) for better performance?
     54//       (it is necessary to ensure the superblock is correctly aligned then
     55//        though)
    4556
    46 #define EXT2_SUPERBLOCK_MAGIC 0xEF53
     57typedef struct ext2_filesystem {
     58        devmap_handle_t         device;
     59        ext2_superblock_t *     superblock;
     60} ext2_filesystem_t;
    4761
    48 inline uint16_t ext2_superblock_get_magic(ext2_superblock_t *superblock);
     62#define EXT2_SUPERBLOCK_MAGIC           0xEF53
     63#define EXT2_SUPERBLOCK_SIZE            1024
     64#define EXT2_SUPERBLOCK_OFFSET          1024
     65#define EXT2_SUPERBLOCK_LAST_BYTE       (EXT2_SUPERBLOCK_OFFSET + \
     66                                                                         EXT2_SUPERBLOCK_SIZE -1)
     67
     68inline uint16_t ext2_superblock_get_magic(ext2_superblock_t *sb);
     69inline uint32_t ext2_superblock_get_first_block(ext2_superblock_t *sb);
     70inline uint32_t ext2_superblock_get_block_size_log2(ext2_superblock_t *sb);
     71inline uint32_t ext2_superblock_get_block_size(ext2_superblock_t *sb);
     72inline int32_t  ext2_superblock_get_fragment_size_log2(ext2_superblock_t *sb);
     73inline uint32_t ext2_superblock_get_fragment_size(ext2_superblock_t *sb);
     74inline uint32_t ext2_superblock_get_blocks_per_group(ext2_superblock_t *sb);
     75inline uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *sb);
     76
     77int ext2_superblock_read_direct(ext2_superblock_t **superblock,
     78                                                                devmap_handle_t dev);
     79
     80int ext2_filesystem_init(ext2_filesystem_t *fs, devmap_handle_t dev);
     81void ext2_filesystem_fini(ext2_filesystem_t *fs);
    4982
    5083#endif
Note: See TracChangeset for help on using the changeset viewer.