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