Changes in uspace/srv/fs/mfs/mfs_rw.c [e895352:7a46bfe] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_rw.c
re895352 r7a46bfe 31 31 */ 32 32 33 #include <align.h>34 33 #include "mfs.h" 35 34 36 35 static int 37 36 rw_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); 39 38 40 39 static int … … 54 53 *bytes, this function returns the on-disk block 55 54 *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. 62 56 */ 63 57 int … … 68 62 const int block_size = sbi->block_size; 69 63 70 /* Compute relative block number in file*/64 /*Compute relative block number in file*/ 71 65 int rblock = pos / block_size; 72 66 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*/ 75 69 r = EOK; 76 70 *b = 0; … … 85 79 int 86 80 mfs_write_map(struct mfs_node *mnode, const uint32_t pos, uint32_t new_zone, 87 81 uint32_t *old_zone) 88 82 { 89 83 const struct mfs_sb_info *sbi = mnode->instance->sbi; 90 84 91 85 if (pos >= sbi->max_file_size) { 92 /* Can't write beyond the maximum file size*/86 /*Can't write beyond the maximum file size*/ 93 87 return EINVAL; 94 88 } 95 89 96 /* Compute the relative block number in file*/90 /*Compute the relative block number in file*/ 97 91 int rblock = pos / sbi->block_size; 98 92 … … 102 96 static int 103 97 rw_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) 105 99 { 106 100 int r, nr_direct; … … 123 117 } 124 118 125 /* Check if the wanted block is in the direct zones*/119 /*Check if the wanted block is in the direct zones*/ 126 120 if (rblock < nr_direct) { 127 121 *b = ino_i->i_dzone[rblock]; … … 136 130 137 131 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*/ 139 133 if (ino_i->i_izone[0] == 0) { 140 134 if (write_mode && !deleting) { … … 147 141 ino_i->dirty = true; 148 142 } else { 149 /* Sparse block*/143 /*Sparse block*/ 150 144 *b = 0; 151 145 return EOK; … … 168 162 rblock -= ptrs_per_block; 169 163 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*/ 173 167 if (ino_i->i_izone[1] == 0) { 174 168 if (write_mode && !deleting) { … … 181 175 ino_i->dirty = true; 182 176 } else { 183 /* Sparse block*/177 /*Sparse block*/ 184 178 *b = 0; 185 179 return EOK; … … 192 186 193 187 /* 194 * 195 * 188 *Compute the position of the second indirect 189 *zone pointer in the chain. 196 190 */ 197 191 uint32_t ind2_off = rblock / ptrs_per_block; 198 192 199 /* read the second indirect zone of the chain*/193 /*read the second indirect zone of the chain*/ 200 194 if (ind_zone[ind2_off] == 0) { 201 195 if (write_mode && !deleting) { … … 208 202 write_ind_zone(inst, ino_i->i_izone[1], ind_zone); 209 203 } else { 210 /* Sparse block*/204 /*Sparse block*/ 211 205 r = EOK; 212 206 *b = 0; … … 233 227 } 234 228 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*/ 242 230 int 243 231 mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size) … … 251 239 mfs_version_t fs_version = sbi->fs_version; 252 240 253 assert(new_size <= ino_i->i_size);254 255 241 if (fs_version == MFS_VERSION_V1) { 256 242 nr_direct = V1_NR_DIRECT_ZONES; … … 264 250 265 251 if (rblock < nr_direct) { 266 /* Free the single indirect zone*/252 /*free the single indirect zone*/ 267 253 if (ino_i->i_izone[0]) { 268 254 r = mfs_free_zone(inst, ino_i->i_izone[0]); … … 282 268 ++fzone_to_free; 283 269 284 /* Free the entire double indirect zone*/270 /*free the entire double indirect zone*/ 285 271 uint32_t *dbl_zone; 286 272 287 273 if (ino_i->i_izone[1] == 0) { 288 /* Nothing to be done*/274 /*Nothing to be done*/ 289 275 return EOK; 290 276 } … … 350 336 block_t *b; 351 337 const int max_ind_zone_ptrs = (MFS_MAX_BLOCKSIZE / sizeof(uint16_t)) * 352 sizeof(uint32_t);338 sizeof(uint32_t); 353 339 354 340 *ind_zone = malloc(max_ind_zone_ptrs);
Note:
See TracChangeset
for help on using the changeset viewer.