Changeset 488f7ed in mainline


Ignore:
Timestamp:
2011-04-16T11:47:52Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6fc5262
Parents:
afd9c3b
Message:

read_directory_entry() should return an error code, not a poniter to the directory structure

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

Legend:

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

    rafd9c3b r488f7ed  
    181181
    182182/*mfs_dentry.c*/
    183 extern struct mfs_dentry_info *
    184 read_directory_entry(struct mfs_node *mnode, unsigned index);
     183extern int
     184read_directory_entry(struct mfs_node *mnode,
     185                        struct mfs_dentry_info **d_info, unsigned index);
    185186
    186187extern int
  • uspace/srv/fs/minixfs/mfs_dentry.c

    rafd9c3b r488f7ed  
    3636#include "mfs_utils.h"
    3737
    38 struct mfs_dentry_info *
    39 read_directory_entry(struct mfs_node *mnode, unsigned index)
     38int
     39read_directory_entry(struct mfs_node *mnode,
     40                        struct mfs_dentry_info **d_info, unsigned index)
    4041{
    4142        const struct mfs_instance *inst = mnode->instance;
     
    4748        mfsdebug("read_directory(%u)\n", index);
    4849
    49         struct mfs_dentry_info *d_info = malloc(sizeof(*d_info));
    50         if (!d_info)
    51                 return NULL;
     50        *d_info = malloc(sizeof(**d_info));
     51        if (!*d_info)
     52                return ENOMEM;
    5253
    5354        int r = read_map(&block, mnode, index * sbi->dirsize);
    54         if (r != EOK || block == 0)
     55        if (r != EOK)
    5556                goto out_err;
     57
     58        if (block == 0) {
     59                r = EIO;
     60                goto out_err;
     61        }
    5662
    5763        r = block_get(&b, inst->handle, block, BLOCK_FLAGS_NONE);
     
    6773                d3 = b->data + (dentry_off * MFS3_DIRSIZE);
    6874
    69                 d_info->d_inum = conv32(sbi->native, d3->d_inum);
    70                 memcpy(d_info->d_name, d3->d_name, MFS3_MAX_NAME_LEN);
     75                (*d_info)->d_inum = conv32(sbi->native, d3->d_inum);
     76                memcpy((*d_info)->d_name, d3->d_name, MFS3_MAX_NAME_LEN);
    7177        } else {
    7278                const int namelen = longnames ? MFS_L_MAX_NAME_LEN :
     
    7783                d = b->data + dentry_off * (longnames ? MFSL_DIRSIZE :
    7884                                                        MFS_DIRSIZE);
    79                 d_info->d_inum = conv16(sbi->native, d->d_inum);
    80                 memcpy(d_info->d_name, d->d_name, namelen);
     85                (*d_info)->d_inum = conv16(sbi->native, d->d_inum);
     86                memcpy((*d_info)->d_name, d->d_name, namelen);
    8187        }
    8288
    8389        block_put(b);
    8490
    85         d_info->index = index;
    86         d_info->node = mnode;
    87         return d_info;
     91        (*d_info)->index = index;
     92        (*d_info)->node = mnode;
     93        return EOK;
    8894
    8995out_err:
    90         free(d_info);
    91         return NULL;
     96        free(*d_info);
     97        *d_info = NULL;
     98        return r;
    9299}
    93100
     
    151158
    152159        for (i = 2; ; ++i) {
    153                 d_info = read_directory_entry(mnode, i);
     160                r = read_directory_entry(mnode, &d_info, i);
     161                if (r != EOK)
     162                        return r;
    154163
    155164                if (!d_info) {
     
    171180                        return r;
    172181
    173                 d_info = read_directory_entry(mnode, i);
    174                 if (!d_info)
    175                         return EIO;
     182                r = read_directory_entry(mnode, &d_info, i);
     183                if (r != EOK)
     184                        return r;
    176185        }
    177186
  • uspace/srv/fs/minixfs/mfs_ops.c

    rafd9c3b r488f7ed  
    336336        struct mfs_ino_info *ino_i = mnode->ino_i;
    337337        struct mfs_dentry_info *d_info;
     338        int r;
    338339
    339340        mfsdebug("mfs_match()\n");
     
    347348        int i = 2;
    348349        while (1) {
    349                 d_info = read_directory_entry(mnode, i++);
     350                r = read_directory_entry(mnode, &d_info, i++);
     351                if (r != EOK)
     352                        return r;
     353
    350354                if (!d_info) {
    351355                        /*Reached the end of the directory entry list*/
     
    535539{
    536540        struct mfs_node *mnode = fsnode->data;
     541        int r;
    537542
    538543        *has_children = false;
     
    546551        int i = 2;
    547552        while (1) {
    548                 d_info = read_directory_entry(mnode, i++);
     553                r = read_directory_entry(mnode, &d_info, i++);
     554                if (r != EOK)
     555                        return r;
    549556
    550557                if (!d_info) {
     
    612619
    613620                while (1) {
    614                         d_info = read_directory_entry(mnode, pos);
     621                        rc = read_directory_entry(mnode, &d_info, pos);
     622                        if (rc != EOK)
     623                                goto out_error;
     624
    615625                        if (!d_info) {
    616626                                /*Reached the end of the dentries list*/
Note: See TracChangeset for help on using the changeset viewer.