Changeset df38657 in mainline


Ignore:
Timestamp:
2011-03-09T11:57:45Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
529edc66
Parents:
b83e16ff
Message:

Reorganize ext2fs_read_directory and skip . and .. entries

File:
1 edited

Legend:

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

    rb83e16ff rdf38657  
    603603                ext2fs_read_directory(rid, callid, pos, size, inst, inode_ref);
    604604        }
    605        
    606         // Other inode types not supported
    607         async_answer_0(callid, ENOTSUP);
    608         async_answer_0(rid, ENOTSUP);
     605        else {
     606                // Other inode types not supported
     607                async_answer_0(callid, ENOTSUP);
     608                async_answer_0(rid, ENOTSUP);
     609        }
     610       
     611        ext2_filesystem_put_inode_ref(inode_ref);
     612       
    609613}
    610614
     
    617621        size_t name_size;
    618622        int rc;
     623        bool found = false;
    619624       
    620625        rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref);
     
    625630        }
    626631       
     632        // Find the index we want to read
     633        // Note that we need to iterate and count as
     634        // the underlying structure is a linked list
     635        // Moreover, we want to skip . and .. entries
     636        // as these are not used in HelenOS
    627637        cur = 0;
    628638        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;
     639                if (it.current->inode == 0) {
     640                        goto skip;
     641                }
     642               
     643                name_size = ext2_directory_entry_ll_get_name_length(
     644                        inst->filesystem->superblock, it.current);
     645               
     646                // skip . and ..
     647                if ((name_size == 1 || name_size == 2) && it.current->name == '.') {
     648                        if (name_size == 1) {
     649                                goto skip;
    648650                        }
    649                         cur++;
     651                        else if (name_size == 2 && *(&it.current->name+1) == '.') {
     652                                goto skip;
     653                        }
    650654                }
    651655               
     656                // Is this the dir entry we want to read?
     657                if (cur == pos) {
     658                        // The on-disk entry does not contain \0 at the end
     659                        // end of entry name, so we copy it to new buffer
     660                        // and add the \0 at the end
     661                        buf = malloc(name_size+1);
     662                        if (buf == NULL) {
     663                                ext2_directory_iterator_fini(&it);
     664                                async_answer_0(callid, ENOMEM);
     665                                async_answer_0(rid, ENOMEM);
     666                                return;
     667                        }
     668                        memcpy(buf, &it.current->name, name_size);
     669                        *(buf+name_size) = 0;
     670                        found = true;
     671                        (void) async_data_read_finalize(callid, buf, name_size+1);
     672                        free(buf);
     673                        break;
     674                }
     675                cur++;
     676               
     677skip:
    652678                rc = ext2_directory_iterator_next(&it);
    653679                if (rc != EOK) {
     
    661687        rc = ext2_directory_iterator_fini(&it);
    662688        if (rc != EOK) {
    663                 async_answer_0(rid, ENOMEM);
    664                 return;
    665         }
    666        
    667         async_answer_1(rid, EOK, 1);
     689                async_answer_0(rid, rc);
     690                return;
     691        }
     692       
     693        if (found) {
     694                async_answer_1(rid, EOK, 1);
     695        }
     696        else {
     697                async_answer_0(callid, ENOENT);
     698                async_answer_0(rid, ENOENT);
     699        }
    668700}
    669701
Note: See TracChangeset for help on using the changeset viewer.