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


Ignore:
Timestamp:
2011-04-10T10:05:18Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
18c9e6b
Parents:
8f6bb76e
Message:

Improve mfs_read(), now it can read files (not tested with very large files yet)

File:
1 edited

Legend:

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

    r8f6bb76e r230229de  
    593593
    594594        if (!async_data_read_receive(&callid, &len)) {
    595                 mfs_node_put(fn);
    596                 async_answer_0(callid, EINVAL);
    597                 async_answer_0(rid, EINVAL);
    598                 return;
     595                rc = EINVAL;
     596                goto out_error;
    599597        }
    600598
     
    628626                                str_size(d_info->d_name) + 1);
    629627                bytes = ((pos - spos) + 1);
    630         }
    631 
     628        } else {
     629                struct mfs_sb_info *sbi = mnode->instance->sbi;
     630
     631                if (pos >= (size_t) ino_i->i_size) {
     632                        /*Trying to read beyond the end of file*/
     633                        bytes = 0;
     634                        (void) async_data_read_finalize(callid, NULL, 0);
     635                        goto out_success;
     636                }
     637
     638                bytes = min(len, sbi->block_size - pos % sbi->block_size);
     639                bytes = min(bytes, ino_i->i_size - pos);
     640
     641                uint32_t zone;
     642                block_t *b;
     643
     644                rc = read_map(&zone, mnode, pos);
     645                if (rc != EOK)
     646                        goto out_error;
     647
     648                if (zone == 0) {
     649                        /*sparse file*/
     650                        uint8_t *buf = malloc(sbi->block_size);
     651                        if (!buf) {
     652                                rc = ENOMEM;
     653                                goto out_error;
     654                        }
     655                        async_data_read_finalize(callid,
     656                            buf + pos % sbi->block_size, bytes);
     657                        free(buf);
     658                        goto out_success;
     659                }
     660
     661                rc = block_get(&b, handle, zone, BLOCK_FLAGS_NONE);
     662                if (rc != EOK)
     663                        goto out_error;
     664
     665                async_data_read_finalize(callid, b->data +
     666                                pos % sbi->block_size, bytes);
     667
     668                rc = block_put(b);
     669                if (rc != EOK) {
     670                        mfs_node_put(fn);
     671                        async_answer_0(rid, rc);
     672                        return;
     673                }
     674        }
     675out_success:
    632676        rc = mfs_node_put(fn);
    633677        async_answer_1(rid, rc, (sysarg_t)bytes);
     678        return;
     679out_error: ;
     680        int tmp = mfs_node_put(fn);
     681        async_answer_0(callid, tmp != EOK ? tmp : rc);
     682        async_answer_0(rid, tmp != EOK ? tmp : rc);
    634683}
    635684
Note: See TracChangeset for help on using the changeset viewer.