Ignore:
File:
1 edited

Legend:

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

    re895352 r7a46bfe  
    3131 */
    3232
    33 #include <align.h>
    3433#include "mfs.h"
    3534
    3635static int
    3736rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
    38     bool write_mode, uint32_t w_block);
     37              bool write_mode, uint32_t w_block);
    3938
    4039static int
     
    5453 *bytes, this function returns the on-disk block
    5554 *relative to that position.
    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.
     55 *Returns zero if the block does not exist.
    6256 */
    6357int
     
    6862        const int block_size = sbi->block_size;
    6963
    70         /* Compute relative block number in file */
     64        /*Compute relative block number in file*/
    7165        int rblock = pos / block_size;
    7266
    73         if (ROUND_UP(mnode->ino_i->i_size, sbi->block_size) < pos) {
    74                 /* Trying to read beyond the end of file */
     67        if (mnode->ino_i->i_size < pos) {
     68                /*Trying to read beyond the end of file*/
    7569                r = EOK;
    7670                *b = 0;
     
    8579int
    8680mfs_write_map(struct mfs_node *mnode, const uint32_t pos, uint32_t new_zone,
    87     uint32_t *old_zone)
     81          uint32_t *old_zone)
    8882{
    8983        const struct mfs_sb_info *sbi = mnode->instance->sbi;
    9084
    9185        if (pos >= sbi->max_file_size) {
    92                 /* Can't write beyond the maximum file size */
     86                /*Can't write beyond the maximum file size*/
    9387                return EINVAL;
    9488        }
    9589
    96         /* Compute the relative block number in file */
     90        /*Compute the relative block number in file*/
    9791        int rblock = pos / sbi->block_size;
    9892
     
    10296static int
    10397rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
    104     bool write_mode, uint32_t w_block)
     98              bool write_mode, uint32_t w_block)
    10599{
    106100        int r, nr_direct;
     
    123117        }
    124118
    125         /* Check if the wanted block is in the direct zones */
     119        /*Check if the wanted block is in the direct zones*/
    126120        if (rblock < nr_direct) {
    127121                *b = ino_i->i_dzone[rblock];
     
    136130
    137131        if (rblock < ptrs_per_block) {
    138                 /* The wanted block is in the single indirect zone chain */
     132                /*The wanted block is in the single indirect zone chain*/
    139133                if (ino_i->i_izone[0] == 0) {
    140134                        if (write_mode && !deleting) {
     
    147141                                ino_i->dirty = true;
    148142                        } else {
    149                                 /* Sparse block */
     143                                /*Sparse block*/
    150144                                *b = 0;
    151145                                return EOK;
     
    168162        rblock -= ptrs_per_block;
    169163
    170         /* The wanted block is in the double indirect zone chain */
    171 
    172         /* Read the first indirect zone of the chain */
     164        /*The wanted block is in the double indirect zone chain*/
     165
     166        /*read the first indirect zone of the chain*/
    173167        if (ino_i->i_izone[1] == 0) {
    174168                if (write_mode && !deleting) {
     
    181175                        ino_i->dirty = true;
    182176                } else {
    183                         /* Sparse block */
     177                        /*Sparse block*/
    184178                        *b = 0;
    185179                        return EOK;
     
    192186
    193187        /*
    194          * Compute the position of the second indirect
    195          * zone pointer in the chain.
     188         *Compute the position of the second indirect
     189         *zone pointer in the chain.
    196190         */
    197191        uint32_t ind2_off = rblock / ptrs_per_block;
    198192
    199         /* read the second indirect zone of the chain */
     193        /*read the second indirect zone of the chain*/
    200194        if (ind_zone[ind2_off] == 0) {
    201195                if (write_mode && !deleting) {
     
    208202                        write_ind_zone(inst, ino_i->i_izone[1], ind_zone);
    209203                } else {
    210                         /* Sparse block */
     204                        /*Sparse block*/
    211205                        r = EOK;
    212206                        *b = 0;
     
    233227}
    234228
    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  */
     229/*Free unused indirect zones*/
    242230int
    243231mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size)
     
    251239        mfs_version_t fs_version = sbi->fs_version;
    252240       
    253         assert(new_size <= ino_i->i_size);
    254 
    255241        if (fs_version == MFS_VERSION_V1) {
    256242                nr_direct = V1_NR_DIRECT_ZONES;
     
    264250
    265251        if (rblock < nr_direct) {
    266                 /* Free the single indirect zone */
     252                /*free the single indirect zone*/
    267253                if (ino_i->i_izone[0]) {
    268254                        r = mfs_free_zone(inst, ino_i->i_izone[0]);
     
    282268                ++fzone_to_free;
    283269
    284         /* Free the entire double indirect zone */
     270        /*free the entire double indirect zone*/
    285271        uint32_t *dbl_zone;
    286272
    287273        if (ino_i->i_izone[1] == 0) {
    288                 /* Nothing to be done */
     274                /*Nothing to be done*/
    289275                return EOK;
    290276        }
     
    350336        block_t *b;
    351337        const int max_ind_zone_ptrs = (MFS_MAX_BLOCKSIZE / sizeof(uint16_t)) *
    352             sizeof(uint32_t);
     338                                      sizeof(uint32_t);
    353339
    354340        *ind_zone = malloc(max_ind_zone_ptrs);
Note: See TracChangeset for help on using the changeset viewer.