Changeset 5a29b4c in mainline
- Timestamp:
- 2011-04-03T19:33:43Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ee01ff5
- Parents:
- 18346ec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/minixfs/mfs_read.c
r18346ec r5a29b4c 40 40 bool write_mode, uint32_t w_block); 41 41 42 static int 43 reset_block_content(struct mfs_instance *inst, uint32_t block); 44 45 static int 46 alloc_zone_and_clear(struct mfs_instance *inst, uint32_t *block); 47 48 42 49 /**Given the position in the file expressed in 43 50 *bytes, this function returns the on-disk block … … 87 94 assert(mnode->instance); 88 95 89 conststruct mfs_instance *inst = mnode->instance;90 conststruct mfs_sb_info *sbi = inst->sbi;96 struct mfs_instance *inst = mnode->instance; 97 struct mfs_sb_info *sbi = inst->sbi; 91 98 assert(sbi); 92 99 … … 116 123 /*The wanted block is in the single indirect zone chain*/ 117 124 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 } 120 137 } 121 138 … … 150 167 /*read the first indirect zone of the chain*/ 151 168 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 } 154 181 } 155 182 … … 170 197 uint16_t *pt16 = bi1->data; 171 198 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 } 172 215 173 216 r = block_get(&bi2, inst->handle, blk, BLOCK_FLAGS_NONE); … … 186 229 uint32_t *pt32 = bi1->data; 187 230 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 } 188 247 189 248 r = block_get(&bi2, inst->handle, blk, BLOCK_FLAGS_NONE); … … 209 268 } 210 269 270 271 static int 272 reset_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 288 static int 289 alloc_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); 298 out: 299 return r; 300 } 301 211 302 /** 212 303 * @}
Note:
See TracChangeset
for help on using the changeset viewer.