Changeset 4bfad34 in mainline


Ignore:
Timestamp:
2017-05-11T22:07:09Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
be39fc6
Parents:
71fe4723
Message:

Move parts of ext4 filesystem initialization.

Location:
uspace/lib/ext4
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/include/ext4/filesystem.h

    r71fe4723 r4bfad34  
    3636
    3737#include <block.h>
     38#include "ext4/fstypes.h"
    3839#include "ext4/types.h"
    3940
    40 extern int ext4_filesystem_init(ext4_filesystem_t *, service_id_t,
    41     enum cache_mode);
     41extern int ext4_filesystem_init(ext4_filesystem_t *, ext4fs_instance_t *,
     42    service_id_t, enum cache_mode, aoff64_t *);
    4243extern int ext4_filesystem_fini(ext4_filesystem_t *);
    43 extern int ext4_filesystem_check_features(ext4_filesystem_t *, bool *);
    4444extern uint32_t ext4_filesystem_blockaddr2_index_in_group(ext4_superblock_t *,
    4545    uint32_t);
  • uspace/lib/ext4/include/ext4/ops.h

    r71fe4723 r4bfad34  
    3535
    3636#include <libfs.h>
     37#include "ext4/fstypes.h"
    3738
    3839extern vfs_out_ops_t ext4fs_ops;
     
    4243extern int ext4fs_global_fini(void);
    4344
     45extern int ext4fs_node_get_core(fs_node_t **, ext4fs_instance_t *, fs_index_t);
     46extern int ext4fs_node_put(fs_node_t *);
     47
    4448
    4549#endif
  • uspace/lib/ext4/src/balloc.c

    r71fe4723 r4bfad34  
    3131 */
    3232/**
    33  * @file  libext4_balloc.c
     33 * @file  balloc.c
    3434 * @brief Physical block allocator.
    3535 */
  • uspace/lib/ext4/src/bitmap.c

    r71fe4723 r4bfad34  
    3131 */
    3232/**
    33  * @file  libext4_bitmap.c
     33 * @file  bitmap.c
    3434 * @brief Ext4 bitmap operations.
    3535 */
  • uspace/lib/ext4/src/block_group.c

    r71fe4723 r4bfad34  
    3232 */
    3333/**
    34  * @file  libext4_block_group.c
     34 * @file  block_group.c
    3535 * @brief Ext4 block group structure operations.
    3636 */
  • uspace/lib/ext4/src/directory.c

    r71fe4723 r4bfad34  
    3232 */
    3333/**
    34  * @file  libext4_directory.c
     34 * @file  directory.c
    3535 * @brief Ext4 directory structure operations.
    3636 */
  • uspace/lib/ext4/src/directory_index.c

    r71fe4723 r4bfad34  
    3131 */
    3232/**
    33  * @file  libext4_directory_index.c
     33 * @file  directory_index.c
    3434 * @brief Ext4 directory index operations.
    3535 */
  • uspace/lib/ext4/src/extent.c

    r71fe4723 r4bfad34  
    3131 */
    3232/**
    33  * @file  libext4_extent.c
     33 * @file  extent.c
    3434 * @brief Ext4 extent structures operations.
    3535 */
  • uspace/lib/ext4/src/filesystem.c

    r71fe4723 r4bfad34  
    3232 */
    3333/**
    34  * @file  libext4_filesystem.c
     34 * @file  filesystem.c
    3535 * @brief More complex filesystem operations.
    3636 */
     
    4242#include <crypto.h>
    4343#include <ipc/vfs.h>
     44#include <libfs.h>
    4445#include <stdlib.h>
    4546#include "ext4/balloc.h"
     
    5051#include "ext4/ialloc.h"
    5152#include "ext4/inode.h"
     53#include "ext4/ops.h"
    5254#include "ext4/superblock.h"
     55
     56static int ext4_filesystem_check_features(ext4_filesystem_t *, bool *);
    5357
    5458/** Initialize filesystem and read all needed data.
     
    5660 * @param fs         Filesystem instance to be initialized
    5761 * @param service_id Identifier if device with the filesystem
    58  *
    59  * @return Error code
    60  *
    61  */
    62 int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id,
    63     enum cache_mode cmode)
     62 * @param cmode      Cache mode
     63 * @param read_only  Place to store read only flag
     64 * @param index      Output value - index of root node
     65 * @param size       Output value - size of root node
     66 * @param lnkcnt     Output value - link count of root node
     67 *
     68 * @return Error code
     69 *
     70 */
     71int ext4_filesystem_init(ext4_filesystem_t *fs, ext4fs_instance_t *inst,
     72    service_id_t service_id, enum cache_mode cmode, aoff64_t *size)
    6473{
    6574        int rc;
     
    118127                goto err_2;
    119128
     129        /* Check flags */
     130        bool read_only;
     131        rc = ext4_filesystem_check_features(fs, &read_only);
     132        if (rc != EOK)
     133                goto err_2;
     134
     135        /* Read root node */
     136        fs_node_t *root_node;
     137        rc = ext4fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX);
     138        if (rc != EOK)
     139                goto err_2;
     140
    120141        /* Mark system as mounted */
    121142        ext4_superblock_set_state(fs->superblock, EXT4_SUPERBLOCK_STATE_ERROR_FS);
    122143        rc = ext4_superblock_write_direct(fs->device, fs->superblock);
    123144        if (rc != EOK)
    124                 goto err_2;
     145                goto err_3;
    125146
    126147        uint16_t mnt_count = ext4_superblock_get_mount_count(fs->superblock);
    127148        ext4_superblock_set_mount_count(fs->superblock, mnt_count + 1);
    128149
     150        ext4fs_node_t *enode = EXT4FS_NODE(root_node);
     151       
     152        *size = ext4_inode_get_size(fs->superblock, enode->inode_ref->inode);
     153
     154        ext4fs_node_put(root_node);
    129155        return EOK;
    130 
     156err_3:
     157        ext4fs_node_put(root_node);
    131158err_2:
    132159        block_cache_fini(fs->device);
     
    169196 *
    170197 * @param fs        Filesystem to be checked
    171  * @param read_only Flag if filesystem should be mounted only for reading
    172  *
    173  * @return Error code
    174  *
    175  */
    176 int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *read_only)
     198 * @param read_only Place to write flag saying whether filesystem
     199 *                  should be mounted only for reading
     200 *
     201 * @return Error code
     202 *
     203 */
     204static int ext4_filesystem_check_features(ext4_filesystem_t *fs,
     205    bool *read_only)
    177206{
    178207        /* Feature flags are present only in higher revisions */
  • uspace/lib/ext4/src/hash.c

    r71fe4723 r4bfad34  
    3131 */
    3232/**
    33  * @file  libext4_hash.c
     33 * @file  hash.c
    3434 * @brief Hashing algorithms for ext4 HTree.
    3535 */
  • uspace/lib/ext4/src/ialloc.c

    r71fe4723 r4bfad34  
    3131 */
    3232/**
    33  * @file  libext4_ialloc.c
     33 * @file  ialloc.c
    3434 * @brief I-node (de)allocation operations.
    3535 */
  • uspace/lib/ext4/src/inode.c

    r71fe4723 r4bfad34  
    3232 */
    3333/**
    34  * @file  libext4_inode.c
     34 * @file  inode.c
    3535 * @brief Ext4 i-node structure operations.
    3636 */
  • uspace/lib/ext4/src/ops.c

    r71fe4723 r4bfad34  
    3232 */
    3333/**
    34  * @file  ext4fs_ops.c
     34 * @file  ops.c
    3535 * @brief Operations for ext4 filesystem.
    3636 */
     
    4646#include <ipc/loc.h>
    4747#include "ext4/ops.h"
    48 //#include "../../vfs/vfs.h"
    49 
    50 #define EXT4FS_NODE(node) \
    51         ((node) ? (ext4fs_node_t *) (node)->data : NULL)
    52 
    53 /**
    54  * Type for holding an instance of mounted partition.
    55  */
    56 typedef struct ext4fs_instance {
    57         link_t link;
    58         service_id_t service_id;
    59         ext4_filesystem_t *filesystem;
    60         unsigned int open_nodes_count;
    61 } ext4fs_instance_t;
    62 
    63 /**
    64  * Type for wrapping common fs_node and add some useful pointers.
    65  */
    66 typedef struct ext4fs_node {
    67         ext4fs_instance_t *instance;
    68         ext4_inode_ref_t *inode_ref;
    69         fs_node_t *fs_node;
    70         ht_link_t link;
    71         unsigned int references;
    72 } ext4fs_node_t;
     48#include "ext4/fstypes.h"
    7349
    7450/* Forward declarations of auxiliary functions */
     
    8056static bool ext4fs_is_dots(const uint8_t *, size_t);
    8157static int ext4fs_instance_get(service_id_t, ext4fs_instance_t **);
    82 static int ext4fs_node_get_core(fs_node_t **, ext4fs_instance_t *, fs_index_t);
    83 static int ext4fs_node_put_core(ext4fs_node_t *);
    8458
    8559/* Forward declarations of ext4 libfs operations. */
     
    8963static int ext4fs_node_get(fs_node_t **, service_id_t, fs_index_t);
    9064static int ext4fs_node_open(fs_node_t *);
    91 static int ext4fs_node_put(fs_node_t *);
     65      int ext4fs_node_put(fs_node_t *);
    9266static int ext4fs_create_node(fs_node_t **, service_id_t, int);
    9367static int ext4fs_destroy_node(fs_node_t *);
     
    373347 *
    374348 */
    375 int ext4fs_node_put_core(ext4fs_node_t *enode)
     349static int ext4fs_node_put_core(ext4fs_node_t *enode)
    376350{
    377351        hash_table_remove_item(&open_nodes, &enode->link);
     
    966940                cmode = CACHE_MODE_WB;
    967941       
    968         /* Initialize the filesystem */
    969         int rc = ext4_filesystem_init(fs, service_id, cmode);
    970         if (rc != EOK) {
    971                 free(fs);
    972                 free(inst);
    973                 return rc;
    974         }
    975        
    976         /* Check flags */
    977         bool read_only;
    978         rc = ext4_filesystem_check_features(fs, &read_only);
    979         if (rc != EOK) {
    980                 ext4_filesystem_fini(fs);
    981                 free(fs);
    982                 free(inst);
    983                 return rc;
    984         }
    985        
    986942        /* Initialize instance */
    987943        link_initialize(&inst->link);
     
    990946        inst->open_nodes_count = 0;
    991947       
    992         /* Read root node */
    993         fs_node_t *root_node;
    994         rc = ext4fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX);
    995         if (rc != EOK) {
    996                 ext4_filesystem_fini(fs);
     948        /* Initialize the filesystem */
     949        aoff64_t rnsize;
     950        int rc = ext4_filesystem_init(fs, inst, service_id, cmode, &rnsize);
     951        if (rc != EOK) {
    997952                free(fs);
    998953                free(inst);
     
    1005960        fibril_mutex_unlock(&instance_list_mutex);
    1006961       
    1007         ext4fs_node_t *enode = EXT4FS_NODE(root_node);
    1008        
    1009962        *index = EXT4_INODE_ROOT_INDEX;
    1010         *size = ext4_inode_get_size(fs->superblock, enode->inode_ref->inode);
     963        *size = rnsize;
    1011964        *lnkcnt = 1;
    1012965       
    1013         return ext4fs_node_put(root_node);
     966        return EOK;
    1014967}
    1015968
  • uspace/lib/ext4/src/superblock.c

    r71fe4723 r4bfad34  
    3333
    3434/**
    35  * @file  libext4_superblock.c
     35 * @file  superblock.c
    3636 * @brief Ext4 superblock operations.
    3737 */
Note: See TracChangeset for help on using the changeset viewer.