Changeset 4e36219 in mainline for uspace/srv


Ignore:
Timestamp:
2011-06-08T19:18:52Z (14 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b5085a7, c028b22
Parents:
911ee54
Message:

Allow libext2 directory iterator to seek to arbitrary position

File:
1 edited

Legend:

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

    r911ee54 r4e36219  
    241241        }
    242242       
    243         rc = ext2_directory_iterator_init(&it, fs, eparent->inode_ref);
     243        rc = ext2_directory_iterator_init(&it, fs, eparent->inode_ref, 0);
    244244        if (rc != EOK) {
    245245                return rc;
     
    479479        }
    480480       
    481         rc = ext2_directory_iterator_init(&it, fs, enode->inode_ref);
     481        rc = ext2_directory_iterator_init(&it, fs, enode->inode_ref, 0);
    482482        if (rc != EOK) {
    483483                EXT2FS_DBG("error %u", rc);
     
    819819{
    820820        ext2_directory_iterator_t it;
    821         aoff64_t cur;
     821        aoff64_t next;
    822822        uint8_t *buf;
    823823        size_t name_size;
     
    825825        bool found = false;
    826826       
    827         rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref);
     827        rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref, pos);
    828828        if (rc != EOK) {
    829829                async_answer_0(callid, rc);
     
    832832        }
    833833       
    834         /* Find the index we want to read
    835          * Note that we need to iterate and count as
    836          * the underlying structure is a linked list
    837          * Moreover, we want to skip . and .. entries
     834        /* Find next interesting directory entry.
     835         * We want to skip . and .. entries
    838836         * as these are not used in HelenOS
    839837         */
    840         cur = 0;
    841838        while (it.current != NULL) {
    842839                if (it.current->inode == 0) {
     
    852849                }
    853850               
    854                 /* Is this the dir entry we want to read? */
    855                 if (cur == pos) {
    856                         /* The on-disk entry does not contain \0 at the end
    857                          * end of entry name, so we copy it to new buffer
    858                          * and add the \0 at the end
    859                          */
    860                         buf = malloc(name_size+1);
    861                         if (buf == NULL) {
    862                                 ext2_directory_iterator_fini(&it);
    863                                 async_answer_0(callid, ENOMEM);
    864                                 async_answer_0(rid, ENOMEM);
    865                                 return;
    866                         }
    867                         memcpy(buf, &it.current->name, name_size);
    868                         *(buf+name_size) = 0;
    869                         found = true;
    870                         (void) async_data_read_finalize(callid, buf, name_size+1);
    871                         free(buf);
    872                         break;
    873                 }
    874                 cur++;
     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;
     861                }
     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;
    875868               
    876869skip:
     
    884877        }
    885878       
     879        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       
    886888        rc = ext2_directory_iterator_fini(&it);
    887889        if (rc != EOK) {
     
    891893       
    892894        if (found) {
    893                 async_answer_1(rid, EOK, 1);
     895                async_answer_1(rid, EOK, next-pos);
    894896        }
    895897        else {
Note: See TracChangeset for help on using the changeset viewer.