Changeset b83e16ff in mainline


Ignore:
Timestamp:
2011-03-09T10:13:08Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
df38657
Parents:
4dc6a32
Message:

Split ext2fs_read_directory from ext2fs_read

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/ext2fs/ext2fs_ops.c

    r4dc6a32 rb83e16ff  
    7272
    7373static int ext2fs_instance_get(devmap_handle_t, ext2fs_instance_t **);
     74static void ext2fs_read_directory(ipc_callid_t, ipc_callid_t, aoff64_t,
     75        size_t, ext2fs_instance_t *, ext2_inode_ref_t *);
    7476
    7577/*
     
    566568        ext2_inode_ref_t *inode_ref;
    567569        int rc;
    568         ext2_directory_iterator_t it;
    569         aoff64_t cur;
    570         uint8_t *buf;
    571         size_t name_size;
    572 
     570       
    573571        /*
    574572         * Receive the read request.
     
    603601        else if (ext2_inode_is_type(inst->filesystem->superblock, inode_ref->inode,
    604602                    EXT2_INODE_MODE_DIRECTORY)) {
    605                 rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref);
     603                ext2fs_read_directory(rid, callid, pos, size, inst, inode_ref);
     604        }
     605       
     606        // Other inode types not supported
     607        async_answer_0(callid, ENOTSUP);
     608        async_answer_0(rid, ENOTSUP);
     609}
     610
     611void ext2fs_read_directory(ipc_callid_t rid, ipc_callid_t callid, aoff64_t pos,
     612        size_t size, ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref)
     613{
     614        ext2_directory_iterator_t it;
     615        aoff64_t cur;
     616        uint8_t *buf;
     617        size_t name_size;
     618        int rc;
     619       
     620        rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref);
     621        if (rc != EOK) {
     622                async_answer_0(callid, rc);
     623                async_answer_0(rid, rc);
     624                return;
     625        }
     626       
     627        cur = 0;
     628        while (it.current != NULL) {
     629                if (it.current->inode != 0) {
     630                        if (cur == pos) {
     631                                // This is the dir entry we want to read
     632                                name_size = ext2_directory_entry_ll_get_name_length(
     633                                        inst->filesystem->superblock, it.current);
     634                                // The on-disk entry does not contain \0 at the end
     635                                // end of entry name, so we copy it to new buffer
     636                                // and the \0 at the end
     637                                buf = malloc(name_size+1);
     638                                if (buf == NULL) {
     639                                        ext2_directory_iterator_fini(&it);
     640                                        async_answer_0(callid, ENOMEM);
     641                                        async_answer_0(rid, ENOMEM);
     642                                        return;
     643                                }
     644                                memcpy(buf, &it.current->name, name_size);
     645                                *(buf+name_size) = 0;
     646                                (void) async_data_read_finalize(callid, buf, name_size+1);
     647                                break;
     648                        }
     649                        cur++;
     650                }
     651               
     652                rc = ext2_directory_iterator_next(&it);
    606653                if (rc != EOK) {
     654                        ext2_directory_iterator_fini(&it);
    607655                        async_answer_0(callid, rc);
    608656                        async_answer_0(rid, rc);
    609657                        return;
    610658                }
    611                
    612                 cur = 0;
    613                 while (it.current != NULL) {
    614                         if (it.current->inode != 0) {
    615                                 if (cur == pos) {
    616                                         // This is the dir entry we want to read
    617                                         name_size = ext2_directory_entry_ll_get_name_length(
    618                                             inst->filesystem->superblock, it.current);
    619                                         // The on-disk entry does not contain \0 at the end
    620                                         // end of entry name, so we copy it to new buffer
    621                                         // and the \0 at the end
    622                                         buf = malloc(name_size+1);
    623                                         if (buf == NULL) {
    624                                                 ext2_directory_iterator_fini(&it);
    625                                                 async_answer_0(callid, ENOMEM);
    626                                                 async_answer_0(rid, ENOMEM);
    627                                                 return;
    628                                         }
    629                                         memcpy(buf, &it.current->name, name_size);
    630                                         *(buf+name_size) = 0;
    631                                         (void) async_data_read_finalize(callid, buf, name_size+1);
    632                                         break;
    633                                 }
    634                                 cur++;
    635                         }
    636                        
    637                         rc = ext2_directory_iterator_next(&it);
    638                         if (rc != EOK) {
    639                                 ext2_directory_iterator_fini(&it);
    640                                 async_answer_0(callid, rc);
    641                                 async_answer_0(rid, rc);
    642                                 return;
    643                         }
    644                 }
    645                
    646                 rc = ext2_directory_iterator_fini(&it);
    647                 if (rc != EOK) {
    648                         async_answer_0(rid, ENOMEM);
    649                         return;
    650                 }
    651                
    652                 async_answer_1(rid, EOK, 1);           
    653         }
    654        
    655         // Other inode types not supported
    656         async_answer_0(callid, ENOTSUP);
    657         async_answer_0(rid, ENOTSUP);
     659        }
     660       
     661        rc = ext2_directory_iterator_fini(&it);
     662        if (rc != EOK) {
     663                async_answer_0(rid, ENOMEM);
     664                return;
     665        }
     666       
     667        async_answer_1(rid, EOK, 1);
    658668}
    659669
Note: See TracChangeset for help on using the changeset viewer.