Changeset e80c2ff in mainline for uspace/srv/fs/minixfs/mfs_ops.c


Ignore:
Timestamp:
2011-07-06T19:56:57Z (14 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b89281b
Parents:
70ac0af
Message:

The read_directory_entry() function has been rewritten to avoid dynamic memory allocation
of the d_info structure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/minixfs/mfs_ops.c

    r70ac0af re80c2ff  
    335335        struct mfs_node *mnode = pfn->data;
    336336        struct mfs_ino_info *ino_i = mnode->ino_i;
    337         struct mfs_dentry_info *d_info;
     337        struct mfs_dentry_info d_info;
    338338        int r;
    339339
     
    344344        const size_t comp_size = str_size(component);
    345345
    346         int i = 2;
    347         while (1) {
    348                 r = read_directory_entry(mnode, &d_info, i++);
     346        unsigned i;
     347        for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
     348                r = read_directory_entry(mnode, &d_info, i);
    349349                on_error(r, return r);
    350350
    351                 if (!d_info) {
    352                         /*Reached the end of the directory entry list*/
    353                         break;
    354                 }
    355 
    356                 if (!d_info->d_inum) {
     351                if (!d_info.d_inum) {
    357352                        /*This entry is not used*/
    358                         free(d_info);
    359353                        continue;
    360354                }
    361355
    362                 if (!bcmp(component, d_info->d_name, min(sbi->max_name_len,
     356                if (!bcmp(component, d_info.d_name, min(sbi->max_name_len,
    363357                                comp_size))) {
    364358                        /*Hit!*/
    365359                        mfs_node_core_get(rfn, mnode->instance,
    366                                           d_info->d_inum);
    367                         free(d_info);
     360                                          d_info.d_inum);
    368361                        goto found;
    369362                }
    370                 free(d_info);
    371363        }
    372364        *rfn = NULL;
     
    566558{
    567559        struct mfs_node *mnode = fsnode->data;
     560        struct mfs_sb_info *sbi = mnode->instance->sbi;
    568561        int r;
    569562
     
    573566                goto out;
    574567
    575         struct mfs_dentry_info *d_info;
     568        struct mfs_dentry_info d_info;
    576569
    577570        /* The first two dentries are always . and .. */
    578         int i = 2;
    579         while (1) {
    580                 r = read_directory_entry(mnode, &d_info, i++);
     571        unsigned i;
     572        for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
     573                r = read_directory_entry(mnode, &d_info, i);
    581574                on_error(r, return r);
    582575
    583                 if (!d_info) {
    584                         /*Reached the end of the dentries list*/
     576                if (d_info.d_inum) {
     577                        /*A valid entry has been found*/
     578                        *has_children = true;
    585579                        break;
    586580                }
    587 
    588                 if (d_info->d_inum) {
    589                         /*A valid entry has been found*/
    590                         *has_children = true;
    591                         free(d_info);
    592                         break;
    593                 }
    594 
    595                 free(d_info);
    596         }
    597 
     581        }
    598582out:
    599583
     
    636620        if (S_ISDIR(ino_i->i_mode)) {
    637621                aoff64_t spos = pos;
    638                 struct mfs_dentry_info *d_info;
    639 
    640                 while (1) {
     622                struct mfs_dentry_info d_info;
     623                struct mfs_sb_info *sbi = mnode->instance->sbi;
     624
     625                unsigned i;
     626                for (i = pos; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
    641627                        rc = read_directory_entry(mnode, &d_info, pos);
    642628                        on_error(rc, goto out_error);
    643629
    644                         if (!d_info) {
    645                                 /*Reached the end of the dentries list*/
    646                                 break;
    647                         }
    648 
    649                         if (d_info->d_inum) {
     630                        if (d_info.d_inum) {
    650631                                /*Dentry found!*/
    651632                                goto found;
    652633                        }
    653 
    654                         free(d_info);
    655634                        pos++;
    656635                }
     
    661640                return;
    662641found:
    663                 async_data_read_finalize(callid, d_info->d_name,
    664                                          str_size(d_info->d_name) + 1);
     642                async_data_read_finalize(callid, d_info.d_name,
     643                                         str_size(d_info.d_name) + 1);
    665644                bytes = ((pos - spos) + 1);
    666645        } else {
Note: See TracChangeset for help on using the changeset viewer.