Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/mfs/mfs_rw.c

    r7a46bfe re895352  
    3131 */
    3232
     33#include <align.h>
    3334#include "mfs.h"
    3435
    3536static int
    3637rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
    37               bool write_mode, uint32_t w_block);
     38    bool write_mode, uint32_t w_block);
    3839
    3940static int
     
    5354 *bytes, this function returns the on-disk block
    5455 *relative to that position.
    55  *Returns zero if the block does not exist.
     56 *
     57 * @param b     Pointer to a 32bit number where the block number will be stored
     58 * @param mnode Pointer to a generic MINIX inode in memory.
     59 * @param pos   Position in file.
     60 *
     61 * @return      EOK on success or a negative error code.
    5662 */
    5763int
     
    6268        const int block_size = sbi->block_size;
    6369
    64         /*Compute relative block number in file*/
     70        /* Compute relative block number in file */
    6571        int rblock = pos / block_size;
    6672
    67         if (mnode->ino_i->i_size < pos) {
    68                 /*Trying to read beyond the end of file*/
     73        if (ROUND_UP(mnode->ino_i->i_size, sbi->block_size) < pos) {
     74                /* Trying to read beyond the end of file */
    6975                r = EOK;
    7076                *b = 0;
     
    7985int
    8086mfs_write_map(struct mfs_node *mnode, const uint32_t pos, uint32_t new_zone,
    81           uint32_t *old_zone)
     87    uint32_t *old_zone)
    8288{
    8389        const struct mfs_sb_info *sbi = mnode->instance->sbi;
    8490
    8591        if (pos >= sbi->max_file_size) {
    86                 /*Can't write beyond the maximum file size*/
     92                /* Can't write beyond the maximum file size */
    8793                return EINVAL;
    8894        }
    8995
    90         /*Compute the relative block number in file*/
     96        /* Compute the relative block number in file */
    9197        int rblock = pos / sbi->block_size;
    9298
     
    96102static int
    97103rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
    98               bool write_mode, uint32_t w_block)
     104    bool write_mode, uint32_t w_block)
    99105{
    100106        int r, nr_direct;
     
    117123        }
    118124
    119         /*Check if the wanted block is in the direct zones*/
     125        /* Check if the wanted block is in the direct zones */
    120126        if (rblock < nr_direct) {
    121127                *b = ino_i->i_dzone[rblock];
     
    130136
    131137        if (rblock < ptrs_per_block) {
    132                 /*The wanted block is in the single indirect zone chain*/
     138                /* The wanted block is in the single indirect zone chain */
    133139                if (ino_i->i_izone[0] == 0) {
    134140                        if (write_mode && !deleting) {
     
    141147                                ino_i->dirty = true;
    142148                        } else {
    143                                 /*Sparse block*/
     149                                /* Sparse block */
    144150                                *b = 0;
    145151                                return EOK;
     
    162168        rblock -= ptrs_per_block;
    163169
    164         /*The wanted block is in the double indirect zone chain*/
    165 
    166         /*read the first indirect zone of the chain*/
     170        /* The wanted block is in the double indirect zone chain */
     171
     172        /* Read the first indirect zone of the chain */
    167173        if (ino_i->i_izone[1] == 0) {
    168174                if (write_mode && !deleting) {
     
    175181                        ino_i->dirty = true;
    176182                } else {
    177                         /*Sparse block*/
     183                        /* Sparse block */
    178184                        *b = 0;
    179185                        return EOK;
     
    186192
    187193        /*
    188          *Compute the position of the second indirect
    189          *zone pointer in the chain.
     194         * Compute the position of the second indirect
     195         * zone pointer in the chain.
    190196         */
    191197        uint32_t ind2_off = rblock / ptrs_per_block;
    192198
    193         /*read the second indirect zone of the chain*/
     199        /* read the second indirect zone of the chain */
    194200        if (ind_zone[ind2_off] == 0) {
    195201                if (write_mode && !deleting) {
     
    202208                        write_ind_zone(inst, ino_i->i_izone[1], ind_zone);
    203209                } else {
    204                         /*Sparse block*/
     210                        /* Sparse block */
    205211                        r = EOK;
    206212                        *b = 0;
     
    227233}
    228234
    229 /*Free unused indirect zones*/
     235/**Free unused indirect zones from a MINIX inode according to its new size.
     236 *
     237 * @param mnode         Pointer to a generic MINIX inode in memory.
     238 * @param new_size      The new size of the inode.
     239 *
     240 * @return              EOK on success or a negative error code.
     241 */
    230242int
    231243mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size)
     
    239251        mfs_version_t fs_version = sbi->fs_version;
    240252       
     253        assert(new_size <= ino_i->i_size);
     254
    241255        if (fs_version == MFS_VERSION_V1) {
    242256                nr_direct = V1_NR_DIRECT_ZONES;
     
    250264
    251265        if (rblock < nr_direct) {
    252                 /*free the single indirect zone*/
     266                /* Free the single indirect zone */
    253267                if (ino_i->i_izone[0]) {
    254268                        r = mfs_free_zone(inst, ino_i->i_izone[0]);
     
    268282                ++fzone_to_free;
    269283
    270         /*free the entire double indirect zone*/
     284        /* Free the entire double indirect zone */
    271285        uint32_t *dbl_zone;
    272286
    273287        if (ino_i->i_izone[1] == 0) {
    274                 /*Nothing to be done*/
     288                /* Nothing to be done */
    275289                return EOK;
    276290        }
     
    336350        block_t *b;
    337351        const int max_ind_zone_ptrs = (MFS_MAX_BLOCKSIZE / sizeof(uint16_t)) *
    338                                       sizeof(uint32_t);
     352            sizeof(uint32_t);
    339353
    340354        *ind_zone = malloc(max_ind_zone_ptrs);
Note: See TracChangeset for help on using the changeset viewer.