Ignore:
File:
1 edited

Legend:

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

    r4e36219 rb72efe8  
    187187{
    188188        EXT2FS_DBG("(%" PRIun ", -)", devmap_handle);
    189         link_t *link;
    190189        ext2fs_instance_t *tmp;
    191190       
     
    198197        }
    199198
    200         for (link = instance_list.next; link != &instance_list; link = link->next) {
     199        list_foreach(instance_list, link) {
    201200                tmp = list_get_instance(link, ext2fs_instance_t, link);
    202201               
     
    241240        }
    242241       
    243         rc = ext2_directory_iterator_init(&it, fs, eparent->inode_ref, 0);
     242        rc = ext2_directory_iterator_init(&it, fs, eparent->inode_ref);
    244243        if (rc != EOK) {
    245244                return rc;
     
    479478        }
    480479       
    481         rc = ext2_directory_iterator_init(&it, fs, enode->inode_ref, 0);
     480        rc = ext2_directory_iterator_init(&it, fs, enode->inode_ref);
    482481        if (rc != EOK) {
    483482                EXT2FS_DBG("error %u", rc);
     
    819818{
    820819        ext2_directory_iterator_t it;
    821         aoff64_t next;
     820        aoff64_t cur;
    822821        uint8_t *buf;
    823822        size_t name_size;
     
    825824        bool found = false;
    826825       
    827         rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref, pos);
     826        rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref);
    828827        if (rc != EOK) {
    829828                async_answer_0(callid, rc);
     
    832831        }
    833832       
    834         /* Find next interesting directory entry.
    835          * We want to skip . and .. entries
     833        /* Find the index we want to read
     834         * Note that we need to iterate and count as
     835         * the underlying structure is a linked list
     836         * Moreover, we want to skip . and .. entries
    836837         * as these are not used in HelenOS
    837838         */
     839        cur = 0;
    838840        while (it.current != NULL) {
    839841                if (it.current->inode == 0) {
     
    849851                }
    850852               
    851                 /* The on-disk entry does not contain \0 at the end
    852                         * end of entry name, so we copy it to new buffer
    853                         * and add the \0 at the end
    854                         */
    855                 buf = malloc(name_size+1);
    856                 if (buf == NULL) {
    857                         ext2_directory_iterator_fini(&it);
    858                         async_answer_0(callid, ENOMEM);
    859                         async_answer_0(rid, ENOMEM);
    860                         return;
     853                /* Is this the dir entry we want to read? */
     854                if (cur == pos) {
     855                        /* The on-disk entry does not contain \0 at the end
     856                         * end of entry name, so we copy it to new buffer
     857                         * and add the \0 at the end
     858                         */
     859                        buf = malloc(name_size+1);
     860                        if (buf == NULL) {
     861                                ext2_directory_iterator_fini(&it);
     862                                async_answer_0(callid, ENOMEM);
     863                                async_answer_0(rid, ENOMEM);
     864                                return;
     865                        }
     866                        memcpy(buf, &it.current->name, name_size);
     867                        *(buf+name_size) = 0;
     868                        found = true;
     869                        (void) async_data_read_finalize(callid, buf, name_size+1);
     870                        free(buf);
     871                        break;
    861872                }
    862                 memcpy(buf, &it.current->name, name_size);
    863                 *(buf+name_size) = 0;
    864                 found = true;
    865                 (void) async_data_read_finalize(callid, buf, name_size+1);
    866                 free(buf);
    867                 break;
     873                cur++;
    868874               
    869875skip:
     
    877883        }
    878884       
     885        rc = ext2_directory_iterator_fini(&it);
     886        if (rc != EOK) {
     887                async_answer_0(rid, rc);
     888                return;
     889        }
     890       
    879891        if (found) {
    880                 rc = ext2_directory_iterator_next(&it);
    881                 if (rc != EOK) {
    882                         async_answer_0(rid, rc);
    883                         return;
    884                 }
    885                 next = it.current_offset;
    886         }
    887        
    888         rc = ext2_directory_iterator_fini(&it);
    889         if (rc != EOK) {
    890                 async_answer_0(rid, rc);
    891                 return;
    892         }
    893        
    894         if (found) {
    895                 async_answer_1(rid, EOK, next-pos);
     892                async_answer_1(rid, EOK, 1);
    896893        }
    897894        else {
Note: See TracChangeset for help on using the changeset viewer.