Changeset 3711e7e in mainline for uspace/lib/ext4


Ignore:
Timestamp:
2011-10-05T09:35:12Z (14 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3712434
Parents:
cfa1a8a
Message:

Complete mounting skeleton (ported from ext2fs) - some filesystem checks during mount process still missing

Location:
uspace/lib/ext4
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_block_group.c

    rcfa1a8a r3711e7e  
    3636 */
    3737
    38 #include "libext4_block_group.h"
     38#include <byteorder.h>
     39#include "libext4.h"
    3940
     41uint64_t ext4_block_group_get_inode_table_first_block(ext4_block_group_t *bg)
     42{
     43        return ((uint64_t)uint32_t_le2host(bg->inode_table_first_hi) << 32) |
     44                        uint32_t_le2host(bg->inode_table_first_lo);
     45}
    4046
    4147/**
  • uspace/lib/ext4/libext4_block_group.h

    rcfa1a8a r3711e7e  
    3434#define LIBEXT4_LIBEXT4_BLOCK_GROUP_H_
    3535
     36#include <libblock.h>
    3637#include <sys/types.h>
    37 
     38#include "libext4_block_group.h"
    3839/*
    3940 * Structure of a blocks group descriptor
     
    4243        uint32_t block_bitmap_lo; // Blocks bitmap block
    4344        uint32_t inode_bitmap_lo; // Inodes bitmap block
    44         uint32_t inode_table_lo; // Inodes table block
     45        uint32_t inode_table_first_lo; // Inodes table block
    4546        uint16_t free_blocks_count_lo; // Free blocks count
    4647        uint16_t free_inodes_count_lo; // Free inodes count
     
    5253        uint32_t block_bitmap_hi; // Blocks bitmap block MSB
    5354        uint32_t inode_bitmap_hi; // Inodes bitmap block MSB
    54         uint32_t inode_table_hi; // Inodes table block MSB
     55        uint32_t inode_table_first_hi; // Inodes table block MSB
    5556        uint16_t free_blocks_count_hi; // Free blocks count MSB
    5657        uint16_t free_inodes_count_hi; // Free inodes count MSB
     
    5859        uint16_t itable_unused_hi;  // Unused inodes count MSB
    5960        uint32_t reserved2[3]; // Padding
    60 } ext4_group_desc_t;
     61} ext4_block_group_t;
     62
     63typedef struct ext4_block_group_ref {
     64        block_t *block; // Reference to a block containing this block group descr
     65        ext4_block_group_t *block_group;
     66} ext4_block_group_ref_t;
     67
     68// TODO check value
     69#define EXT4_BLOCK_GROUP_DESCRIPTOR_SIZE 32
     70
     71extern uint64_t ext4_block_group_get_inode_table_first_block(ext4_block_group_t *);
    6172
    6273#endif
  • uspace/lib/ext4/libext4_directory.c

    rcfa1a8a r3711e7e  
    3636 */
    3737
    38 #include "libext4_directory.h"
     38#include "libext4.h"
    3939
    4040
  • uspace/lib/ext4/libext4_filesystem.c

    rcfa1a8a r3711e7e  
    3838#include <errno.h>
    3939#include <malloc.h>
    40 #include "libext4_filesystem.h"
     40#include "libext4.h"
    4141
    4242/**
     
    8383
    8484        return EOK;
     85}
     86
     87/**
     88 * TODO doxy
     89 */
     90void ext4_filesystem_fini(ext4_filesystem_t *fs)
     91{
     92        free(fs->superblock);
     93        block_fini(fs->device);
    8594}
    8695
     
    132141 * TODO doxy
    133142 */
    134 void ext4_filesystem_fini(ext4_filesystem_t *fs)
    135 {
    136         free(fs->superblock);
    137         block_fini(fs->device);
    138 }
    139 
     143int ext4_filesystem_get_block_group_ref(ext4_filesystem_t *fs, uint32_t bgid,
     144    ext4_block_group_ref_t **ref)
     145{
     146        int rc;
     147        aoff64_t block_id;
     148        uint32_t descriptors_per_block;
     149        size_t offset;
     150        ext4_block_group_ref_t *newref;
     151
     152        newref = malloc(sizeof(ext4_block_group_ref_t));
     153        if (newref == NULL) {
     154                return ENOMEM;
     155        }
     156
     157        descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
     158            / EXT4_BLOCK_GROUP_DESCRIPTOR_SIZE;
     159
     160        /* Block group descriptor table starts at the next block after superblock */
     161        block_id = ext4_superblock_get_first_block(fs->superblock) + 1;
     162
     163        /* Find the block containing the descriptor we are looking for */
     164        block_id += bgid / descriptors_per_block;
     165        offset = (bgid % descriptors_per_block) * EXT4_BLOCK_GROUP_DESCRIPTOR_SIZE;
     166
     167        rc = block_get(&newref->block, fs->device, block_id, 0);
     168        if (rc != EOK) {
     169                free(newref);
     170                return rc;
     171        }
     172
     173        newref->block_group = newref->block->data + offset;
     174
     175        *ref = newref;
     176
     177        return EOK;
     178}
     179
     180/**
     181 * TODO doxy
     182 */
     183int ext4_filesystem_get_inode_ref(ext4_filesystem_t *fs, uint32_t index,
     184    ext4_inode_ref_t **ref)
     185{
     186        int rc;
     187        aoff64_t block_id;
     188        uint32_t block_group;
     189        uint32_t offset_in_group;
     190        uint32_t byte_offset_in_group;
     191        size_t offset_in_block;
     192        uint32_t inodes_per_group;
     193        uint32_t inode_table_start;
     194        uint16_t inode_size;
     195        uint32_t block_size;
     196        ext4_block_group_ref_t *bg_ref;
     197        ext4_inode_ref_t *newref;
     198
     199        newref = malloc(sizeof(ext4_inode_ref_t));
     200        if (newref == NULL) {
     201                return ENOMEM;
     202        }
     203
     204        inodes_per_group = ext4_superblock_get_inodes_per_group(fs->superblock);
     205
     206        /* inode numbers are 1-based, but it is simpler to work with 0-based
     207         * when computing indices
     208         */
     209        index -= 1;
     210        block_group = index / inodes_per_group;
     211        offset_in_group = index % inodes_per_group;
     212
     213        rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
     214        if (rc != EOK) {
     215                free(newref);
     216                return rc;
     217        }
     218
     219        inode_table_start = ext4_block_group_get_inode_table_first_block(
     220            bg_ref->block_group);
     221
     222        inode_size = ext4_superblock_get_inode_size(fs->superblock);
     223        block_size = ext4_superblock_get_block_size(fs->superblock);
     224
     225        byte_offset_in_group = offset_in_group * inode_size;
     226
     227        block_id = inode_table_start + (byte_offset_in_group / block_size);
     228        offset_in_block = byte_offset_in_group % block_size;
     229
     230        rc = block_get(&newref->block, fs->device, block_id, 0);
     231        if (rc != EOK) {
     232                free(newref);
     233                return rc;
     234        }
     235
     236        newref->inode = newref->block->data + offset_in_block;
     237        /* we decremented index above, but need to store the original value
     238         * in the reference
     239         */
     240        newref->index = index+1;
     241
     242        *ref = newref;
     243
     244        return EOK;
     245}
    140246
    141247/**
  • uspace/lib/ext4/libext4_filesystem.h

    rcfa1a8a r3711e7e  
    3535
    3636#include <libblock.h>
     37#include "libext4_block_group.h"
     38#include "libext4_inode.h"
    3739#include "libext4_superblock.h"
    3840
     
    4244} ext4_filesystem_t;
    4345
    44 #define EXT4_MAX_BLOCK_SIZE 65536 //64 KiB
    45 
     46#define EXT4_MAX_BLOCK_SIZE     65536 //64 KiB
     47#define EXT4_REV0_INODE_SIZE    128
    4648
    4749/* Compatible features */
     
    99101
    100102extern int ext4_filesystem_init(ext4_filesystem_t *, service_id_t);
     103extern void ext4_filesystem_fini(ext4_filesystem_t *fs);
    101104extern int ext4_filesystem_check_sanity(ext4_filesystem_t *fs);
    102105extern int ext4_filesystem_check_features(ext4_filesystem_t *, bool *);
    103 extern void ext4_filesystem_fini(ext4_filesystem_t *fs);
     106extern int ext4_filesystem_get_block_group_ref(ext4_filesystem_t *, uint32_t,
     107    ext4_block_group_ref_t **);
     108extern int ext4_filesystem_get_inode_ref(ext4_filesystem_t *, uint32_t,
     109                ext4_inode_ref_t **);
     110
    104111
    105112#endif
  • uspace/lib/ext4/libext4_inode.c

    rcfa1a8a r3711e7e  
    3737
    3838#include <byteorder.h>
    39 #include "libext4_inode.h"
     39#include "libext4.h"
    4040
    4141// TODO check return type
  • uspace/lib/ext4/libext4_superblock.c

    rcfa1a8a r3711e7e  
    4040#include <libblock.h>
    4141#include <malloc.h>
    42 #include "libext4_superblock.h"
     42#include "libext4.h"
    4343
    4444/**
     
    8080{
    8181        return uint32_t_le2host(sb->rev_level);
     82}
     83
     84/**
     85 * TODO doxy
     86 */
     87uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *sb)
     88{
     89        if (ext4_superblock_get_rev_level(sb) == 0) {
     90                return EXT4_REV0_INODE_SIZE;
     91        }
     92        return uint16_t_le2host(sb->inode_size);
     93}
     94
     95/**
     96 * TODO doxy
     97 */
     98uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *sb)
     99{
     100        return uint32_t_le2host(sb->inodes_per_group);
    82101}
    83102
  • uspace/lib/ext4/libext4_superblock.h

    rcfa1a8a r3711e7e  
    5151        uint32_t s_blocks_per_group; // Number of blocks per group
    5252        uint32_t s_obso_frags_per_group; // Obsoleted fragments per group
    53         uint32_t s_inodes_per_group; // Number of inodes per group
     53        uint32_t inodes_per_group; // Number of inodes per group
    5454        uint32_t s_mtime; // Mount time
    5555        uint32_t s_wtime; // Write time
     
    6969        // Fields for EXT4_DYNAMIC_REV superblocks only.
    7070        uint32_t s_first_ino; // First non-reserved inode
    71         uint16_t s_inode_size; // Size of inode structure
     71        uint16_t inode_size; // Size of inode structure
    7272        uint16_t s_block_group_nr; // Block group number of this superblock
    7373        uint32_t features_compatible; // Compatible feature set
     
    147147extern uint32_t ext4_superblock_get_block_size(ext4_superblock_t *);
    148148extern uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *);
     149extern uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *);
     150extern uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *);
    149151extern uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *);
    150152extern uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *);
Note: See TracChangeset for help on using the changeset viewer.