Changeset 5a29b4c in mainline


Ignore:
Timestamp:
2011-04-03T19:33:43Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ee01ff5
Parents:
18346ec
Message:

write_map() must allocate new zones to expand the chain when needed

File:
1 edited

Legend:

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

    r18346ec r5a29b4c  
    4040                                bool write_mode, uint32_t w_block);
    4141
     42static int
     43reset_block_content(struct mfs_instance *inst, uint32_t block);
     44
     45static int
     46alloc_zone_and_clear(struct mfs_instance *inst, uint32_t *block);
     47
     48
    4249/**Given the position in the file expressed in
    4350 *bytes, this function returns the on-disk block
     
    8794        assert(mnode->instance);
    8895
    89         const struct mfs_instance *inst = mnode->instance;
    90         const struct mfs_sb_info *sbi = inst->sbi;
     96        struct mfs_instance *inst = mnode->instance;
     97        struct mfs_sb_info *sbi = inst->sbi;
    9198        assert(sbi);
    9299
     
    116123                /*The wanted block is in the single indirect zone chain*/
    117124                if (ino_i->i_izone[0] == 0) {
    118                         r = -1;
    119                         goto out;
     125                        if (write_mode) {
     126                                uint32_t block;
     127                                r = alloc_zone_and_clear(inst, &block);
     128                                if (r != EOK)
     129                                        goto out;
     130
     131                                ino_i->i_izone[0] = block;
     132                                ino_i->dirty = true;
     133                        } else {
     134                                r = -1;
     135                                goto out;
     136                        }
    120137                }
    121138
     
    150167        /*read the first indirect zone of the chain*/
    151168        if (ino_i->i_izone[1] == 0) {
    152                 r = -1;
    153                 goto out;
     169                if (write_mode) {
     170                        uint32_t block;
     171                        r = alloc_zone_and_clear(inst, &block);
     172                        if (r != EOK)
     173                                goto out;
     174
     175                        ino_i->i_izone[1] = block;
     176                        ino_i->dirty = true;
     177                } else {
     178                        r = -1;
     179                        goto out;
     180                }
    154181        }
    155182
     
    170197                uint16_t *pt16 = bi1->data;
    171198                uint16_t blk = conv16(sbi->native, pt16[di_block]);
     199
     200                if (blk == 0) {
     201                        if (write_mode) {
     202                                uint32_t block;
     203                                r = alloc_zone_and_clear(inst, &block);
     204                                if (r != EOK)
     205                                        goto out;
     206
     207                                blk = block;
     208                                pt16[di_block] = conv16(sbi->native, blk);
     209                                bi1->dirty = true;
     210                        } else {
     211                                r = 1;
     212                                goto out;
     213                        }
     214                }
    172215       
    173216                r = block_get(&bi2, inst->handle, blk, BLOCK_FLAGS_NONE);
     
    186229                uint32_t *pt32 = bi1->data;
    187230                uint32_t blk = conv32(sbi->native, pt32[di_block]);
     231
     232                if (blk == 0) {
     233                        if (write_mode) {
     234                                uint32_t block;
     235                                r = alloc_zone_and_clear(inst, &block);
     236                                if (r != EOK)
     237                                        goto out;
     238
     239                                blk = block;
     240                                pt32[di_block] = conv32(sbi->native, blk);
     241                                bi1->dirty = true;
     242                        } else {
     243                                r = 1;
     244                                goto out;
     245                        }
     246                }
    188247       
    189248                r = block_get(&bi2, inst->handle, blk, BLOCK_FLAGS_NONE);
     
    209268}
    210269
     270
     271static int
     272reset_block_content(struct mfs_instance *inst, uint32_t block)
     273{
     274        block_t *b;
     275        int r;
     276
     277        r = block_get(&b, inst->handle, block, BLOCK_FLAGS_NOREAD);
     278        if (r != EOK)
     279                return r;
     280
     281        memset(b->data, 0, b->size);
     282        b->dirty = true;
     283        block_put(b);
     284
     285        return EOK;
     286}
     287
     288static int
     289alloc_zone_and_clear(struct mfs_instance *inst, uint32_t *block)
     290{
     291        int r;
     292
     293        r = mfs_alloc_bit(inst, block, BMAP_ZONE);
     294        if (r != EOK)
     295                goto out;
     296
     297        r = reset_block_content(inst, *block);
     298out:
     299        return r;
     300}
     301
    211302/**
    212303 * @}
Note: See TracChangeset for help on using the changeset viewer.