Changeset e68c834 in mainline


Ignore:
Timestamp:
2011-10-10T06:48:16Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a68fe5
Parents:
1114173
Message:

More functions ported from ext2

Location:
uspace
Files:
3 edited

Legend:

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

    r1114173 re68c834  
    142142                }
    143143
     144                EXT4FS_DBG("next_block_phys_idx: \%d", next_block_phys_idx);
     145
    144146                rc = block_get(&it->current_block, it->fs->device, next_block_phys_idx,
    145147                    BLOCK_FLAGS_NONE);
     
    151153
    152154        it->current_offset = pos;
     155
    153156        return ext4_directory_iterator_set(it, block_size);
    154157}
  • uspace/lib/ext4/libext4_filesystem.c

    r1114173 re68c834  
    4141#include "libext4.h"
    4242
    43 /**
    44  * TODO doxy
    45  */
    4643int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id)
    4744{
     
    8683}
    8784
    88 /**
    89  * TODO doxy
    90  */
    9185void ext4_filesystem_fini(ext4_filesystem_t *fs)
    9286{
     
    9589}
    9690
    97 /**
    98  * TODO doxy
    99  */
    10091int ext4_filesystem_check_sanity(ext4_filesystem_t *fs)
    10192{
     
    110101}
    111102
    112 /**
    113  * TODO doxy
    114  */
    115103int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *o_read_only)
    116104{
     
    139127}
    140128
    141 /**
    142  * TODO doxy
    143  */
    144129int ext4_filesystem_get_block_group_ref(ext4_filesystem_t *fs, uint32_t bgid,
    145130    ext4_block_group_ref_t **ref)
    146131{
    147         EXT4FS_DBG("");
    148 
    149132        int rc;
    150133        aoff64_t block_id;
     
    164147        block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
    165148
    166         EXT4FS_DBG("block_size = \%d", ext4_superblock_get_block_size(fs->superblock));
    167         EXT4FS_DBG("descriptors_per_block = \%d", descriptors_per_block);
    168         EXT4FS_DBG("bgid = \%d", bgid);
    169         EXT4FS_DBG("first_data_block: \%d", (uint32_t)block_id);
    170 
    171149        /* Find the block containing the descriptor we are looking for */
    172150        block_id += bgid / descriptors_per_block;
    173151        offset = (bgid % descriptors_per_block) * EXT4_BLOCK_GROUP_DESCRIPTOR_SIZE;
    174152
    175         EXT4FS_DBG("updated block_id: \%d", (uint32_t)block_id);
    176 
    177153        rc = block_get(&newref->block, fs->device, block_id, 0);
    178154        if (rc != EOK) {
    179 
    180                 EXT4FS_DBG("block_get error: \%d", rc);
    181 
    182155                free(newref);
    183156                return rc;
    184157        }
    185158
    186         EXT4FS_DBG("block read");
    187 
    188159        newref->block_group = newref->block->data + offset;
    189160
    190161        *ref = newref;
    191162
    192         EXT4FS_DBG("finished");
    193 
    194         return EOK;
    195 }
    196 
    197 /**
    198  * TODO doxy
    199  */
     163        return EOK;
     164}
     165
    200166int ext4_filesystem_get_inode_ref(ext4_filesystem_t *fs, uint32_t index,
    201167    ext4_inode_ref_t **ref)
    202168{
    203         EXT4FS_DBG("");
    204 
    205169        int rc;
    206170        aoff64_t block_id;
     
    221185        }
    222186
    223         EXT4FS_DBG("allocated");
    224 
    225187        inodes_per_group = ext4_superblock_get_inodes_per_group(fs->superblock);
    226 
    227         EXT4FS_DBG("inodes_per_group_loaded");
    228188
    229189        /* inode numbers are 1-based, but it is simpler to work with 0-based
     
    234194        offset_in_group = index % inodes_per_group;
    235195
    236         EXT4FS_DBG("index: \%d", index);
    237         EXT4FS_DBG("inodes_per_group: \%d", inodes_per_group);
    238         EXT4FS_DBG("bg_id: \%d", block_group);
    239 
    240196        rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
    241197        if (rc != EOK) {
     
    243199                return rc;
    244200        }
    245 
    246         EXT4FS_DBG("block_group_ref loaded");
    247201
    248202        inode_table_start = ext4_block_group_get_inode_table_first_block(
    249203            bg_ref->block_group);
    250204
    251         EXT4FS_DBG("inode_table block loaded");
    252 
    253205        inode_size = ext4_superblock_get_inode_size(fs->superblock);
    254206        block_size = ext4_superblock_get_block_size(fs->superblock);
     
    259211        offset_in_block = byte_offset_in_group % block_size;
    260212
    261         EXT4FS_DBG("superblock info loaded");
    262 
    263213        rc = block_get(&newref->block, fs->device, block_id, 0);
    264214        if (rc != EOK) {
     
    266216                return rc;
    267217        }
    268 
    269         EXT4FS_DBG("block got");
    270218
    271219        newref->inode = newref->block->data + offset_in_block;
     
    277225        *ref = newref;
    278226
    279         EXT4FS_DBG("finished");
    280 
    281         return EOK;
    282 }
     227        return EOK;
     228}
     229
    283230
    284231int ext4_filesystem_put_inode_ref(ext4_inode_ref_t *ref)
     
    307254
    308255        /* Handle simple case when we are dealing with direct reference */
    309         if (iblock < EXT4_INODE_DIRECT_BLOCKS) {
     256        if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
    310257                current_block = ext4_inode_get_direct_block(inode, (uint32_t)iblock);
    311258                *fblock = current_block;
     
    317264         */
    318265        block_ids_per_block = ext4_superblock_get_block_size(fs->superblock) / sizeof(uint32_t);
    319         limits[0] = EXT4_INODE_DIRECT_BLOCKS;
     266        limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;
    320267        blocks_per_level[0] = 1;
    321268        for (i = 1; i < 4; i++) {
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    r1114173 re68c834  
    147147int ext4fs_global_init(void)
    148148{
    149         EXT4FS_DBG("");
    150 
    151149        if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS,
    152150            OPEN_NODES_KEYS, &open_nodes_ops)) {
     
    159157int ext4fs_global_fini(void)
    160158{
    161         EXT4FS_DBG("");
    162 
    163159        hash_table_destroy(&open_nodes);
    164160        return EOK;
     
    172168int ext4fs_instance_get(service_id_t service_id, ext4fs_instance_t **inst)
    173169{
    174         EXT4FS_DBG("");
    175 
    176170        ext4fs_instance_t *tmp;
    177171
     
    200194int ext4fs_root_get(fs_node_t **rfn, service_id_t service_id)
    201195{
    202         EXT4FS_DBG("");
    203 
    204196        return ext4fs_node_get(rfn, service_id, EXT4_INODE_ROOT_INDEX);
    205197}
     
    208200int ext4fs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
    209201{
    210         EXT4FS_DBG("");
    211 
    212202        ext4fs_node_t *eparent = EXT4FS_NODE(pfn);
    213203        ext4_filesystem_t *fs;
     
    413403int ext4fs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
    414404{
    415         EXT4FS_DBG("");
     405        EXT4FS_DBG("not supported");
    416406
    417407        // TODO
     
    422412int ext4fs_destroy_node(fs_node_t *fn)
    423413{
    424         EXT4FS_DBG("");
     414        EXT4FS_DBG("not supported");
    425415
    426416        // TODO
     
    431421int ext4fs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
    432422{
    433         EXT4FS_DBG("");
     423        EXT4FS_DBG("not supported");
    434424
    435425        // TODO
     
    440430int ext4fs_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
    441431{
    442         EXT4FS_DBG("");
     432        EXT4FS_DBG("not supported");
    443433
    444434        // TODO
     
    449439int ext4fs_has_children(bool *has_children, fs_node_t *fn)
    450440{
    451         EXT4FS_DBG("");
    452 
    453         // TODO
     441        ext4fs_node_t *enode = EXT4FS_NODE(fn);
     442        ext4_directory_iterator_t it;
     443        ext4_filesystem_t *fs;
     444        int rc;
     445        bool found = false;
     446        size_t name_size;
     447
     448        fs = enode->instance->filesystem;
     449
     450        if (!ext4_inode_is_type(fs->superblock, enode->inode_ref->inode,
     451            EXT4_INODE_MODE_DIRECTORY)) {
     452                *has_children = false;
     453                return EOK;
     454        }
     455
     456        rc = ext4_directory_iterator_init(&it, fs, enode->inode_ref, 0);
     457        if (rc != EOK) {
     458                return rc;
     459        }
     460
     461        /* Find a non-empty directory entry */
     462        while (it.current != NULL) {
     463                if (it.current->inode != 0) {
     464                        name_size = ext4_directory_entry_ll_get_name_length(fs->superblock,
     465                                it.current);
     466                        if (!ext4fs_is_dots(&it.current->name, name_size)) {
     467                                found = true;
     468                                break;
     469                        }
     470                }
     471
     472                rc = ext4_directory_iterator_next(&it);
     473                if (rc != EOK) {
     474                        ext4_directory_iterator_fini(&it);
     475                        return rc;
     476                }
     477        }
     478
     479        rc = ext4_directory_iterator_fini(&it);
     480        if (rc != EOK) {
     481                return rc;
     482        }
     483
     484        *has_children = found;
     485
    454486        return EOK;
    455487}
     
    482514bool ext4fs_is_directory(fs_node_t *fn)
    483515{
    484         EXT4FS_DBG("");
    485 
    486         // TODO
    487         return false;
     516        ext4fs_node_t *enode = EXT4FS_NODE(fn);
     517        bool is_dir = ext4_inode_is_type(enode->instance->filesystem->superblock,
     518            enode->inode_ref->inode, EXT4_INODE_MODE_DIRECTORY);
     519        return is_dir;
    488520}
    489521
     
    500532service_id_t ext4fs_service_get(fs_node_t *fn)
    501533{
    502         EXT4FS_DBG("");
    503 
    504         // TODO
    505         return 0;
     534        ext4fs_node_t *enode = EXT4FS_NODE(fn);
     535        return enode->instance->service_id;
    506536}
    507537
     
    536566   fs_index_t *index, aoff64_t *size, unsigned *lnkcnt)
    537567{
    538         EXT4FS_DBG("");
    539 
    540568        int rc;
    541569        ext4_filesystem_t *fs;
     
    616644static int ext4fs_unmounted(service_id_t service_id)
    617645{
    618         EXT4FS_DBG("");
    619 
    620646        int rc;
    621647        ext4fs_instance_t *inst;
     
    651677    size_t *rbytes)
    652678{
    653         EXT4FS_DBG("");
    654 
    655679        ext4fs_instance_t *inst;
    656680        ext4_inode_ref_t *inode_ref;
     
    712736    ext4fs_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes)
    713737{
    714         EXT4FS_DBG("");
    715738
    716739        ext4_directory_iterator_t it;
     
    720743        int rc;
    721744        bool found = false;
     745
     746        EXT4FS_DBG("inode = \%d", inode_ref->index);
    722747
    723748        rc = ext4_directory_iterator_init(&it, inst->filesystem, inode_ref, pos);
     
    732757         */
    733758        while (it.current != NULL) {
     759
    734760                if (it.current->inode == 0) {
    735761                        goto skip;
     
    738764                name_size = ext4_directory_entry_ll_get_name_length(
    739765                    inst->filesystem->superblock, it.current);
     766
     767
     768                char* name = (char *)(&it.current->name);
     769
     770                EXT4FS_DBG("name: \%s", name);
     771                EXT4FS_DBG("inode-number: \%d", it.current->inode);
    740772
    741773                /* skip . and .. */
     
    878910    size_t *wbytes, aoff64_t *nsize)
    879911{
     912        EXT4FS_DBG("not supported");
     913
    880914        // TODO
    881915        return ENOTSUP;
     
    886920ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t size)
    887921{
     922        EXT4FS_DBG("not supported");
     923
    888924        // TODO
    889925        return ENOTSUP;
     
    900936static int ext4fs_destroy(service_id_t service_id, fs_index_t index)
    901937{
     938        EXT4FS_DBG("not supported");
     939
    902940        //TODO
    903941        return ENOTSUP;
     
    907945static int ext4fs_sync(service_id_t service_id, fs_index_t index)
    908946{
     947        EXT4FS_DBG("not supported");
     948
    909949        // TODO
    910950        return ENOTSUP;
Note: See TracChangeset for help on using the changeset viewer.