Changeset 9c0c0e1 in mainline


Ignore:
Timestamp:
2011-10-04T12:18:44Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a23297c
Parents:
01ab41b
Message:

part of code needed for successful mount (porting from ext2)

Location:
uspace
Files:
8 edited

Legend:

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

    r01ab41b r9c0c0e1  
    4040 */
    4141typedef struct ext4_block_group {
    42         uint32_t bg_block_bitmap_lo; // Blocks bitmap block
    43         uint32_t bg_inode_bitmap_lo; // Inodes bitmap block
    44         uint32_t bg_inode_table_lo; // Inodes table block
    45         uint16_t bg_free_blocks_count_lo; // Free blocks count
    46         uint16_t bg_free_inodes_count_lo; // Free inodes count
    47         uint16_t bg_used_dirs_count_lo; // Directories count
    48         uint16_t bg_flags; // EXT4_BG_flags (INODE_UNINIT, etc)
    49         uint32_t bg_reserved[2]; // Likely block/inode bitmap checksum
    50         uint16_t bg_itable_unused_lo; // Unused inodes count
    51         uint16_t bg_checksum; // crc16(sb_uuid+group+desc)
    52         uint32_t bg_block_bitmap_hi; // Blocks bitmap block MSB
    53         uint32_t bg_inode_bitmap_hi; // Inodes bitmap block MSB
    54         uint32_t bg_inode_table_hi; // Inodes table block MSB
    55         uint16_t bg_free_blocks_count_hi; // Free blocks count MSB
    56         uint16_t bg_free_inodes_count_hi; // Free inodes count MSB
    57         uint16_t bg_used_dirs_count_hi; // Directories count MSB
    58         uint16_t bg_itable_unused_hi;  // Unused inodes count MSB
    59         uint32_t bg_reserved2[3]; // Padding
     42        uint32_t block_bitmap_lo; // Blocks bitmap block
     43        uint32_t inode_bitmap_lo; // Inodes bitmap block
     44        uint32_t inode_table_lo; // Inodes table block
     45        uint16_t free_blocks_count_lo; // Free blocks count
     46        uint16_t free_inodes_count_lo; // Free inodes count
     47        uint16_t used_dirs_count_lo; // Directories count
     48        uint16_t flags; // EXT4_BG_flags (INODE_UNINIT, etc)
     49        uint32_t reserved[2]; // Likely block/inode bitmap checksum
     50        uint16_t itable_unused_lo; // Unused inodes count
     51        uint16_t checksum; // crc16(sb_uuid+group+desc)
     52        uint32_t block_bitmap_hi; // Blocks bitmap block MSB
     53        uint32_t inode_bitmap_hi; // Inodes bitmap block MSB
     54        uint32_t inode_table_hi; // Inodes table block MSB
     55        uint16_t free_blocks_count_hi; // Free blocks count MSB
     56        uint16_t free_inodes_count_hi; // Free inodes count MSB
     57        uint16_t used_dirs_count_hi; // Directories count MSB
     58        uint16_t itable_unused_hi;  // Unused inodes count MSB
     59        uint32_t reserved2[3]; // Padding
    6060} ext4_group_desc_t;
    6161
  • uspace/lib/ext4/libext4_filesystem.c

    r01ab41b r9c0c0e1  
    5252        fs->device = service_id;
    5353
    54         // TODO block size !!!
     54        // TODO what does constant 2048 mean?
    5555        rc = block_init(EXCHANGE_SERIALIZE, fs->device, 2048);
    5656        if (rc != EOK) {
     
    5858        }
    5959
     60        /* Read superblock from device */
    6061        rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
    6162        if (rc != EOK) {
     
    6465        }
    6566
     67        /* Read block size from superblock and check */
    6668        block_size = ext4_superblock_get_block_size(temp_superblock);
    67 
    6869        if (block_size > EXT4_MAX_BLOCK_SIZE) {
    6970                block_fini(fs->device);
     
    7172        }
    7273
     74        /* Initialize block caching */
    7375        rc = block_cache_init(service_id, block_size, 0, CACHE_MODE_WT);
    7476        if (rc != EOK) {
     
    7779        }
    7880
     81        /* Return loaded superblock */
    7982        fs->superblock = temp_superblock;
    8083
    81 
    82         // TODO
    8384        return EOK;
    8485}
     
    102103 * TODO doxy
    103104 */
    104 int ext4_filesystem_check_flags(ext4_filesystem_t *fs, bool *o_read_only)
     105int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *o_read_only)
    105106{
    106         // TODO
     107        /* Feature flags are present in rev 1 and later */
     108        if (ext4_superblock_get_rev_level(fs->superblock) == 0) {
     109                *o_read_only = false;
     110                return EOK;
     111        }
     112
     113        uint32_t incompatible_features;
     114        incompatible_features = ext4_superblock_get_features_incompatible(fs->superblock);
     115        incompatible_features &= ~EXT4_FEATURE_INCOMPAT_SUPP;
     116        if (incompatible_features > 0) {
     117                *o_read_only = true;
     118                return ENOTSUP;
     119        }
     120
     121        uint32_t compatible_read_only;
     122        compatible_read_only = ext4_superblock_get_features_read_only(fs->superblock);
     123        compatible_read_only &= ~EXT4_FEATURE_RO_COMPAT_SUPP;
     124        if (compatible_read_only > 0) {
     125                *o_read_only = true;
     126        }
     127
    107128        return EOK;
    108129}
  • uspace/lib/ext4/libext4_filesystem.h

    r01ab41b r9c0c0e1  
    4242} ext4_filesystem_t;
    4343
    44 // TODO constant value
    45 #define EXT4_MAX_BLOCK_SIZE             8096
     44#define EXT4_MAX_BLOCK_SIZE 65536 //64 KiB
     45
     46
     47/* Compatible features */
     48// TODO features comments !!!
     49#define EXT4_FEATURE_COMPAT_DIR_PREALLOC        0x0001
     50#define EXT4_FEATURE_COMPAT_IMAGIC_INODES       0x0002
     51#define EXT4_FEATURE_COMPAT_HAS_JOURNAL         0x0004
     52#define EXT4_FEATURE_COMPAT_EXT_ATTR            0x0008
     53#define EXT4_FEATURE_COMPAT_RESIZE_INODE        0x0010
     54#define EXT4_FEATURE_COMPAT_DIR_INDEX           0x0020
     55
     56/* Read-only compatible features */
     57// TODO features comments !!!
     58#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER     0x0001
     59#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE       0x0002
     60#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR        0x0004
     61#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE        0x0008
     62#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM         0x0010
     63#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK        0x0020
     64#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE      0x0040
     65
     66/* Incompatible features */
     67// TODO features comments !!!
     68#define EXT4_FEATURE_INCOMPAT_COMPRESSION       0x0001
     69#define EXT4_FEATURE_INCOMPAT_FILETYPE          0x0002
     70#define EXT4_FEATURE_INCOMPAT_RECOVER           0x0004 /* Needs recovery */
     71#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV       0x0008 /* Journal device */
     72#define EXT4_FEATURE_INCOMPAT_META_BG           0x0010
     73#define EXT4_FEATURE_INCOMPAT_EXTENTS           0x0040 /* extents support */
     74#define EXT4_FEATURE_INCOMPAT_64BIT             0x0080
     75#define EXT4_FEATURE_INCOMPAT_MMP               0x0100
     76#define EXT4_FEATURE_INCOMPAT_FLEX_BG           0x0200
     77#define EXT4_FEATURE_INCOMPAT_EA_INODE          0x0400 /* EA in inode */
     78#define EXT4_FEATURE_INCOMPAT_DIRDATA           0x1000 /* data in dirent */
     79
     80
     81// TODO MODIFY features corresponding with implementation
     82#define EXT4_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR
     83
     84#define EXT4_FEATURE_INCOMPAT_SUPP      (EXT4_FEATURE_INCOMPAT_FILETYPE| \
     85                                         EXT4_FEATURE_INCOMPAT_RECOVER| \
     86                                         EXT4_FEATURE_INCOMPAT_META_BG| \
     87                                         EXT4_FEATURE_INCOMPAT_EXTENTS| \
     88                                         EXT4_FEATURE_INCOMPAT_64BIT| \
     89                                         EXT4_FEATURE_INCOMPAT_FLEX_BG)
     90
     91#define EXT4_FEATURE_RO_COMPAT_SUPP     (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
     92                                         EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
     93                                         EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
     94                                         EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
     95                                         EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
     96                                         EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\
     97                                         EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
     98
    4699
    47100extern int ext4_filesystem_init(ext4_filesystem_t *, service_id_t);
    48101extern int ext4_filesystem_check_sanity(ext4_filesystem_t *fs);
    49 extern int ext4_filesystem_check_flags(ext4_filesystem_t *, bool *);
     102extern int ext4_filesystem_check_features(ext4_filesystem_t *, bool *);
    50103extern void ext4_filesystem_fini(ext4_filesystem_t *fs);
    51104
  • uspace/lib/ext4/libext4_inode.c

    r01ab41b r9c0c0e1  
    3636 */
    3737
     38#include <byteorder.h>
    3839#include "libext4_inode.h"
    3940
     
    4445uint16_t ext4_inode_get_usage_count(ext4_inode_t *inode)
    4546{
    46         // TODO check
    47         return 0;
     47        return uint16_t_le2host(inode->links_count);
    4848}
    4949
  • uspace/lib/ext4/libext4_inode.h

    r01ab41b r9c0c0e1  
    3737#include <sys/types.h>
    3838
    39 // TODO better constant definition !!!
    40 #define EXT4_N_BLOCKS   15
     39#define EXT4_DIRECT_BLOCK_COUNT         12
     40#define EXT4_INDIRECT_BLOCK             EXT4_DIRECT_BLOCK_COUNT
     41#define EXT4_DOUBLE_INDIRECT_BLOCK      (EXT4_INDIRECT_BLOCK + 1)
     42#define EXT4_TRIPPLE_INDIRECT_BLOCK     (EXT4_DOUBLE_INDIRECT_BLOCK + 1)
     43#define EXT4_INODE_BLOCKS                       (EXT4_TRIPPLE_INDIRECT_BLOCK + 1)
    4144
    4245/*
     
    4447 */
    4548typedef struct ext4_inode {
    46         uint16_t i_mode; // File mode
    47         uint16_t i_uid; // Low 16 bits of owner uid
    48         uint32_t i_size_lo; // Size in bytes
    49         uint32_t i_atime; // Access time
    50         uint32_t i_ctime; // Inode change time
    51         uint32_t i_mtime; // Modification time
    52         uint32_t i_dtime; // Deletion time
    53         uint16_t i_gid; // Low 16 bits of group id
    54         uint16_t i_links_count; // Links count
    55         uint32_t i_blocks_lo; // Blocks count
    56         uint32_t i_flags; // File flags
     49        uint16_t mode; // File mode
     50        uint16_t uid; // Low 16 bits of owner uid
     51        uint32_t size_lo; // Size in bytes
    5752
    58         /*
    59         union {
    60                 struct {
    61                         __le32  l_i_version;
    62                 } linux1;
    63                 struct {
    64                         __u32  h_i_translator;
    65                 } hurd1;
    66                 struct {
    67                         __u32  m_i_reserved1;
    68                 } masix1;
    69         } osd1;
    70         */
     53        // TODO Used in HelenOS ???
     54        uint32_t atime; // Access time
     55        uint32_t ctime; // Inode change time
     56        uint32_t mtime; // Modification time
     57        uint32_t dtime; // Deletion time
     58
     59        uint16_t gid; // Low 16 bits of group id
     60        uint16_t links_count; // Links count
     61        uint32_t blocks_lo; // Blocks count
     62        uint32_t flags; // File flags
    7163        uint32_t unused_osd1; // OS dependent - not used in HelenOS
    72 
    73     uint32_t i_block[EXT4_N_BLOCKS]; // Pointers to blocks
    74     uint32_t i_generation; // File version (for NFS)
    75     uint32_t i_file_acl_lo; // File ACL
    76     uint32_t i_size_high;
    77     uint32_t i_obso_faddr; // Obsoleted fragment address
    78 
    79     /*
    80         union {
    81                 struct {
    82                         __le16  l_i_blocks_high;
    83                         __le16  l_i_file_acl_high;
    84                         __le16  l_i_uid_high;
    85                         __le16  l_i_gid_high;
    86                         __u32   l_i_reserved2;
    87                 } linux2;
    88                 struct {
    89                         __le16  h_i_reserved1;
    90                         __u16   h_i_mode_high;
    91                         __u16   h_i_uid_high;
    92                         __u16   h_i_gid_high;
    93                         __u32   h_i_author;
    94                 } hurd2;
    95                 struct {
    96                         __le16  h_i_reserved1;
    97                         __le16  m_i_file_acl_high;
    98                         __u32   m_i_reserved2[2];
    99                 } masix2;
    100         } osd2;
    101         */
    102 
    103         uint32_t unused_osd2[3]; // OS dependent - not used in HelenOS
    104         uint16_t i_extra_isize;
    105         uint16_t i_pad1;
    106         uint32_t  i_ctime_extra; // Extra change time (nsec << 2 | epoch)
    107         uint32_t i_mtime_extra; // Extra Modification time (nsec << 2 | epoch)
    108         uint32_t i_atime_extra; // Extra Access time (nsec << 2 | epoch)
    109         uint32_t i_crtime; // File creation time
    110         uint32_t i_crtime_extra; // Extra file creation time (nsec << 2 | epoch)
    111         uint32_t i_version_hi;   // High 32 bits for 64-bit version
     64    uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
     65    uint32_t generation; // File version (for NFS)
     66    uint32_t file_acl_lo; // File ACL
     67    uint32_t size_hi;
     68    uint32_t obso_faddr; // Obsoleted fragment address
     69    uint32_t unused_osd2[3]; // OS dependent - not used in HelenOS
     70    uint16_t extra_isize;
     71    uint16_t pad1;
     72    uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
     73    uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
     74    uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
     75    uint32_t crtime; // File creation time
     76    uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
     77    uint32_t version_hi;   // High 32 bits for 64-bit version
    11278} __attribute__ ((packed)) ext4_inode_t;
    11379
    11480
    115 // TODO check value
    11681#define EXT4_INODE_ROOT_INDEX   2
    11782
  • uspace/lib/ext4/libext4_superblock.c

    r01ab41b r9c0c0e1  
    4545 * TODO doxy
    4646 */
    47 uint16_t ext2_superblock_get_magic(ext4_superblock_t *sb)
     47uint16_t ext4_superblock_get_magic(ext4_superblock_t *sb)
    4848{
    49         return uint16_t_le2host(sb->s_magic);
     49        return uint16_t_le2host(sb->magic);
    5050}
    5151
     
    5555uint32_t ext4_superblock_get_first_block(ext4_superblock_t *sb)
    5656{
    57         return uint32_t_le2host(sb->s_first_data_block);
     57        return uint32_t_le2host(sb->first_data_block);
    5858}
    5959
     
    6363uint32_t ext4_superblock_get_block_size_log2(ext4_superblock_t *sb)
    6464{
    65         return uint32_t_le2host(sb->s_log_block_size);
     65        return uint32_t_le2host(sb->log_block_size);
    6666}
    6767
     
    7272{
    7373        return 1024 << ext4_superblock_get_block_size_log2(sb);
     74}
     75
     76/**
     77 * TODO doxy
     78 */
     79uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *sb)
     80{
     81        return uint32_t_le2host(sb->rev_level);
     82}
     83
     84/**
     85 * TODO doxy
     86 */
     87uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *sb)
     88{
     89        return uint32_t_le2host(sb->features_compatible);
     90}
     91
     92/**
     93 * TODO doxy
     94 */
     95uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *sb)
     96{
     97        return uint32_t_le2host(sb->features_incompatible);
     98}
     99
     100/**
     101 * TODO doxy
     102 */
     103uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *sb)
     104{
     105        return uint32_t_le2host(sb->features_read_only);
    74106}
    75107
     
    107139int ext4_superblock_check_sanity(ext4_superblock_t *sb)
    108140{
    109         // TODO
     141        if (ext4_superblock_get_magic(sb) != EXT4_SUPERBLOCK_MAGIC) {
     142                return ENOTSUP;
     143        }
     144
     145        // TODO more checks !!!
     146
    110147        return EOK;
    111148}
  • uspace/lib/ext4/libext4_superblock.h

    r01ab41b r9c0c0e1  
    4141 */
    4242typedef struct ext4_superblock {
    43         uint32_t s_inodes_count; // Inodes count
     43        uint32_t inodes_count; // Inodes count
    4444        uint32_t s_blocks_count_lo; // Blocks count
    4545        uint32_t s_r_blocks_count_lo; // Reserved blocks count
    46         uint32_t s_free_blocks_count_lo; // Free blocks count
    47         uint32_t s_free_inodes_count; // Free inodes count
    48         uint32_t s_first_data_block; // First Data Block
    49         uint32_t s_log_block_size; // Block size
     46        uint32_t free_blocks_count_lo; // Free blocks count
     47        uint32_t free_inodes_count; // Free inodes count
     48        uint32_t first_data_block; // First Data Block
     49        uint32_t log_block_size; // Block size
    5050        uint32_t s_obso_log_frag_size; // Obsoleted fragment size
    5151        uint32_t s_blocks_per_group; // Number of blocks per group
     
    5454        uint32_t s_mtime; // Mount time
    5555        uint32_t s_wtime; // Write time
    56         uint16_t s_mnt_count; // Mount count
    57         uint16_t s_max_mnt_count; // Maximal mount count
    58         uint16_t s_magic; // Magic signature
    59         uint16_t s_state; // File system state
    60         uint16_t s_errors; // Behaviour when detecting errors
    61         uint16_t s_minor_rev_level; // Minor revision level
    62         uint32_t s_lastcheck; // Time of last check
    63         uint32_t s_checkinterval; // Maximum time between checks
    64         uint32_t s_creator_os; // Creator OS
    65         uint32_t s_rev_level; // Revision level
     56        uint16_t mount_count; // Mount count
     57        uint16_t max_mount_count; // Maximal mount count
     58        uint16_t magic; // Magic signature
     59        uint16_t state; // File system state
     60        uint16_t errors; // Behaviour when detecting errors
     61        uint16_t minor_rev_level; // Minor revision level
     62        uint32_t last_check; // Time of last check
     63        uint32_t checkinterval; // Maximum time between checks
     64        uint32_t creator_os; // Creator OS
     65        uint32_t rev_level; // Revision level
    6666        uint16_t s_def_resuid; // Default uid for reserved blocks
    6767        uint16_t s_def_resgid; // Default gid for reserved blocks
     
    7171        uint16_t s_inode_size; // Size of inode structure
    7272        uint16_t s_block_group_nr; // Block group number of this superblock
    73         uint32_t s_feature_compat; // Compatible feature set
    74         uint32_t s_feature_incompat; // Incompatible feature set
    75         uint32_t s_feature_ro_compat; // Readonly-compatible feature set
     73        uint32_t features_compatible; // Compatible feature set
     74        uint32_t features_incompatible; // Incompatible feature set
     75        uint32_t features_read_only; // Readonly-compatible feature set
    7676        uint8_t s_uuid[16]; // 128-bit uuid for volume
    7777        char s_volume_name[16]; // Volume name
     
    122122        uint64_t s_snapshot_r_blocks_count; /* reserved blocks for active snapshot's future use */
    123123        uint32_t s_snapshot_list; // inode number of the head of the on-disk snapshot list
    124 
    125         //#define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count)
    126124        uint32_t s_error_count; // number of fs errors
    127125        uint32_t s_first_error_time; // First time an error happened
     
    135133        uint64_t s_last_error_block;     /* block involved of last error */
    136134        uint8_t s_last_error_func[32];  /* function where the error happened */
    137         //#define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts)
    138135        uint8_t s_mount_opts[64];
    139136        uint32_t s_reserved[112]; // Padding to the end of the block
     
    141138} __attribute__((packed)) ext4_superblock_t;
    142139
    143 // TODO constants
    144140#define EXT4_SUPERBLOCK_MAGIC           0xEF53
    145141#define EXT4_SUPERBLOCK_SIZE            1024
    146142#define EXT4_SUPERBLOCK_OFFSET          1024
    147143
     144extern uint16_t ext4_superblock_get_magic(ext4_superblock_t *);
     145extern uint32_t ext4_superblock_get_first_block(ext4_superblock_t *);
    148146extern uint32_t ext4_superblock_get_block_size_log2(ext4_superblock_t *);
    149147extern uint32_t ext4_superblock_get_block_size(ext4_superblock_t *);
     148extern uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *);
     149extern uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *);
     150extern uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *);
     151extern uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *);
    150152
    151153extern int ext4_superblock_read_direct(service_id_t, ext4_superblock_t **);
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    r01ab41b r9c0c0e1  
    4141#include <libfs.h>
    4242#include <malloc.h>
     43#include <stdio.h>
    4344#include <ipc/loc.h>
    4445#include "ext4fs.h"
     
    4647
    4748#define EXT4FS_NODE(node)       ((node) ? (ext4fs_node_t *) (node)->data : NULL)
     49#define EXT4FS_DBG(format, ...) {if (true) printf("ext4fs: %s: " format "\n", __FUNCTION__, ##__VA_ARGS__);}
    4850
    4951typedef struct ext4fs_instance {
     
    6769static int ext4fs_instance_get(service_id_t, ext4fs_instance_t **);
    6870static int ext4fs_node_get_core(fs_node_t **, ext4fs_instance_t *, fs_index_t);
    69 
     71static int ext4fs_node_put_core(ext4fs_node_t *);
    7072
    7173/*
     
    120122 */
    121123
     124/**
     125 * TODO doxy
     126 */
    122127int ext4fs_instance_get(service_id_t service_id, ext4fs_instance_t **inst)
    123128{
     
    145150}
    146151
     152/**
     153 * TODO doxy
     154 */
    147155int ext4fs_root_get(fs_node_t **rfn, service_id_t service_id)
    148156{
     
    150158}
    151159
     160/**
     161 * TODO doxy
     162 */
    152163int ext4fs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
    153164{
     
    156167}
    157168
     169/**
     170 * TODO doxy
     171 */
    158172int ext4fs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index)
    159173{
    160         // TODO
    161         return 0;
    162 }
    163 
     174        ext4fs_instance_t *inst = NULL;
     175        int rc;
     176
     177        rc = ext4fs_instance_get(service_id, &inst);
     178        if (rc != EOK) {
     179                return rc;
     180        }
     181
     182        return ext4fs_node_get_core(rfn, inst, index);
     183}
     184
     185/**
     186 * TODO doxy
     187 */
    164188int ext4fs_node_get_core(fs_node_t **rfn, ext4fs_instance_t *inst,
    165189                fs_index_t index)
     
    172196 * TODO doxy
    173197 */
     198int ext4fs_node_put_core(ext4fs_node_t *enode) {
     199        // TODO
     200        return EOK;
     201}
     202
     203/**
     204 * TODO doxy
     205 */
    174206int ext4fs_node_open(fs_node_t *fn)
    175207{
     
    180212int ext4fs_node_put(fs_node_t *fn)
    181213{
    182         // TODO
     214        EXT4FS_DBG("");
     215        int rc;
     216        ext4fs_node_t *enode = EXT4FS_NODE(fn);
     217
     218        fibril_mutex_lock(&open_nodes_lock);
     219
     220        assert(enode->references > 0);
     221        enode->references--;
     222        if (enode->references == 0) {
     223                rc = ext4fs_node_put_core(enode);
     224                if (rc != EOK) {
     225                        fibril_mutex_unlock(&open_nodes_lock);
     226                        return rc;
     227                }
     228        }
     229
     230        fibril_mutex_unlock(&open_nodes_lock);
     231
    183232        return EOK;
    184233}
     
    278327 */
    279328
     329/**
     330 * TODO doxy
     331 */
    280332static int ext4fs_mounted(service_id_t service_id, const char *opts,
    281333   fs_index_t *index, aoff64_t *size, unsigned *lnkcnt)
    282334{
     335
     336        EXT4FS_DBG("Mounting...");
    283337
    284338        int rc;
     
    300354        }
    301355
    302         /* Initialize the filesystem  */
     356        EXT4FS_DBG("Basic structures allocated");
     357
     358        /* Initialize the filesystem */
    303359        rc = ext4_filesystem_init(fs, service_id);
    304360        if (rc != EOK) {
     
    307363                return rc;
    308364        }
     365
     366        EXT4FS_DBG("initialized");
    309367
    310368        /* Do some sanity checking */
     
    317375        }
    318376
     377        EXT4FS_DBG("Checked and clean");
     378
    319379        /* Check flags */
    320         rc = ext4_filesystem_check_flags(fs, &read_only);
     380        rc = ext4_filesystem_check_features(fs, &read_only);
    321381        if (rc != EOK) {
    322382                ext4_filesystem_fini(fs);
     
    326386        }
    327387
     388        EXT4FS_DBG("Features checked");
     389
    328390        /* Initialize instance */
    329391        link_initialize(&inst->link);
     
    332394        inst->open_nodes_count = 0;
    333395
     396        EXT4FS_DBG("Instance initialized");
     397
    334398        /* Read root node */
    335399        fs_node_t *root_node;
    336         rc = ext4fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX);
     400        rc = ext4fs_root_get(&root_node, inst->service_id);
    337401        if (rc != EOK) {
    338402                ext4_filesystem_fini(fs);
     
    343407        ext4fs_node_t *enode = EXT4FS_NODE(root_node);
    344408
     409        EXT4FS_DBG("Root node found");
     410
    345411        /* Add instance to the list */
    346412        fibril_mutex_lock(&instance_list_mutex);
     
    348414        fibril_mutex_unlock(&instance_list_mutex);
    349415
     416        EXT4FS_DBG("Instance added");
     417
    350418        *index = EXT4_INODE_ROOT_INDEX;
    351419        *size = 0;
    352420        *lnkcnt = ext4_inode_get_usage_count(enode->inode_ref->inode);
    353421
     422        EXT4FS_DBG("Return values set");
     423
    354424        ext4fs_node_put(root_node);
    355425
    356         return EOK;
    357 }
    358 
     426        EXT4FS_DBG("Mounting finished");
     427
     428        return EOK;
     429}
     430
     431/**
     432 * TODO doxy
     433 */
    359434static int ext4fs_unmounted(service_id_t service_id)
    360435{
     
    388463}
    389464
     465/**
     466 * TODO doxy
     467 */
    390468static int
    391469ext4fs_read(service_id_t service_id, fs_index_t index, aoff64_t pos,
     
    396474}
    397475
     476/**
     477 * TODO doxy
     478 */
    398479static int
    399480ext4fs_write(service_id_t service_id, fs_index_t index, aoff64_t pos,
     
    404485}
    405486
     487/**
     488 * TODO doxy
     489 */
    406490static int
    407491ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t size)
     
    411495}
    412496
     497/**
     498 * TODO doxy
     499 */
    413500static int ext4fs_close(service_id_t service_id, fs_index_t index)
    414501{
     
    417504}
    418505
     506/**
     507 * TODO doxy
     508 */
    419509static int ext4fs_destroy(service_id_t service_id, fs_index_t index)
    420510{
     
    423513}
    424514
     515/**
     516 * TODO doxy
     517 */
    425518static int ext4fs_sync(service_id_t service_id, fs_index_t index)
    426519{
Note: See TracChangeset for help on using the changeset viewer.