Changeset e80c2ff in mainline


Ignore:
Timestamp:
2011-07-06T19:56:57Z (13 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.

Location:
uspace/srv/fs/minixfs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/minixfs/mfs.h

    r70ac0af re80c2ff  
    208208extern int
    209209read_directory_entry(struct mfs_node *mnode,
    210                      struct mfs_dentry_info **d_info, unsigned index);
     210                     struct mfs_dentry_info *d_info, unsigned index);
    211211
    212212extern int
  • uspace/srv/fs/minixfs/mfs_dentry.c

    r70ac0af re80c2ff  
    3636int
    3737read_directory_entry(struct mfs_node *mnode,
    38                      struct mfs_dentry_info **d_info, unsigned index)
     38                     struct mfs_dentry_info *d_info, unsigned index)
    3939{
    4040        const struct mfs_instance *inst = mnode->instance;
     
    4444        block_t *b;
    4545
    46         *d_info = malloc(sizeof(**d_info));
    47         if (!*d_info)
    48                 return ENOMEM;
    49 
    5046        int r = read_map(&block, mnode, index * sbi->dirsize);
    51         if (r != EOK)
    52                 goto out_err;
     47        on_error(r, goto out_err);
    5348
    5449        if (block == 0) {
     
    5954
    6055        r = block_get(&b, inst->handle, block, BLOCK_FLAGS_NONE);
    61         if (r != EOK)
    62                 goto out_err;
     56        on_error(r, goto out_err);
    6357
    6458        unsigned dentries_per_zone = sbi->block_size / sbi->dirsize;
     
    7064                d3 = b->data + (dentry_off * MFS3_DIRSIZE);
    7165
    72                 (*d_info)->d_inum = conv32(sbi->native, d3->d_inum);
    73                 memcpy((*d_info)->d_name, d3->d_name, MFS3_MAX_NAME_LEN);
     66                d_info->d_inum = conv32(sbi->native, d3->d_inum);
     67                memcpy(d_info->d_name, d3->d_name, MFS3_MAX_NAME_LEN);
    7468        } else {
    7569                const int namelen = longnames ? MFS_L_MAX_NAME_LEN :
     
    8074                d = b->data + dentry_off * (longnames ? MFSL_DIRSIZE :
    8175                                            MFS_DIRSIZE);
    82                 (*d_info)->d_inum = conv16(sbi->native, d->d_inum);
    83                 memcpy((*d_info)->d_name, d->d_name, namelen);
     76                d_info->d_inum = conv16(sbi->native, d->d_inum);
     77                memcpy(d_info->d_name, d->d_name, namelen);
    8478        }
    8579
    8680        block_put(b);
    8781
    88         (*d_info)->index = index;
    89         (*d_info)->node = mnode;
     82        d_info->index = index;
     83        d_info->node = mnode;
     84
     85out_err:
    9086        return EOK;
    91 
    92 out_err:
    93         free(*d_info);
    94         *d_info = NULL;
    95         return r;
    9687}
    9788
     
    10899
    109100        r = read_map(&block, mnode, d_off_bytes);
    110         if (r != EOK)
    111                 goto out;
     101        on_error(r, goto out);
    112102
    113103        r = block_get(&b, mnode->instance->handle, block, BLOCK_FLAGS_NONE);
    114         if (r != EOK)
    115                 goto out;
     104        on_error(r, goto out);
    116105
    117106        const size_t name_len = sbi->max_name_len;
     
    144133{
    145134        struct mfs_sb_info *sbi = mnode->instance->sbi;
    146         struct mfs_dentry_info *d_info;
    147         int i, r;
     135        struct mfs_dentry_info d_info;
     136        int r;
    148137
    149138        const size_t name_len = str_size(d_name);
     
    153142
    154143        /*Search the directory entry to be removed*/
    155         for (i = 0; ; ++i) {
     144        unsigned i;
     145        for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize ; ++i) {
    156146                r = read_directory_entry(mnode, &d_info, i);
    157147                on_error(r, return r);
    158148
    159                 if (!d_info) {
    160                         /*Reached the end of the dentries list*/
    161                         break;
    162                 }
    163 
    164                 if (!bcmp(d_info->d_name, d_name, name_len)) {
    165                         d_info->d_inum = 0;
    166                         r = write_dentry(d_info);
    167                         free(d_info);
     149                if (!bcmp(d_info.d_name, d_name, name_len)) {
     150                        d_info.d_inum = 0;
     151                        r = write_dentry(&d_info);
    168152                        return r;
    169153                }
    170                 free(d_info);
    171154        }
    172155
     
    177160insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum)
    178161{
    179         int i, r;
     162        int r;
    180163        struct mfs_sb_info *sbi = mnode->instance->sbi;
    181         struct mfs_dentry_info *d_info;
     164        struct mfs_dentry_info d_info;
    182165        bool empty_dentry_found = false;
    183166
     
    188171
    189172        /*Search for an empty dentry*/
    190 
    191         for (i = 0; ; ++i) {
     173        unsigned i;
     174        for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
    192175                r = read_directory_entry(mnode, &d_info, i);
    193                 if (r != EOK)
    194                         return r;
    195 
    196                 if (!d_info) {
    197                         /*Reached the end of the dentries list*/
    198                         break;
    199                 }
    200 
    201                 if (d_info->d_inum == 0) {
     176                on_error(r, return r);
     177
     178                if (d_info.d_inum == 0) {
    202179                        /*This entry is not used*/
    203180                        empty_dentry_found = true;
    204181                        break;
    205182                }
    206                 free(d_info);
    207183        }
    208184
     
    213189                r = read_directory_entry(mnode, &d_info, i);
    214190                on_error(r, goto out);
    215 
    216                 assert(d_info != NULL);
    217         }
    218 
    219         d_info->d_inum = d_inum;
    220         memcpy(d_info->d_name, d_name, name_len);
    221         d_info->d_name[name_len] = 0;
    222 
    223         r = write_dentry(d_info);
    224         free(d_info);
     191        }
     192
     193        d_info.d_inum = d_inum;
     194        memcpy(d_info.d_name, d_name, name_len);
     195        d_info.d_name[name_len] = 0;
     196
     197        r = write_dentry(&d_info);
    225198out:
    226199        return r;
  • 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.