Lines Matching +full:block +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0
7 * Based on portions of file.c by Makoto Kato <m_kato@ga2.so-net.ne.jp>
39 * befs_read_datastream - get buffer_head containing data, starting from pos.
43 * @off: offset of data in buffer_head->b_data
45 * Returns pointer to buffer_head containing data starting with offset @off,
46 * if you don't need to know offset just set @off = NULL.
54 befs_blocknr_t block; /* block coresponding to pos */ in befs_read_datastream() local
56 befs_debug(sb, "---> %s %llu", __func__, pos); in befs_read_datastream()
57 block = pos >> BEFS_SB(sb)->block_shift; in befs_read_datastream()
59 *off = pos - (block << BEFS_SB(sb)->block_shift); in befs_read_datastream()
61 if (befs_fblock2brun(sb, ds, block, &run) != BEFS_OK) { in befs_read_datastream()
62 befs_error(sb, "BeFS: Error finding disk addr of block %lu", in befs_read_datastream()
63 (unsigned long)block); in befs_read_datastream()
64 befs_debug(sb, "<--- %s ERROR", __func__); in befs_read_datastream()
69 befs_error(sb, "BeFS: Error reading block %lu from datastream", in befs_read_datastream()
70 (unsigned long)block); in befs_read_datastream()
74 befs_debug(sb, "<--- %s read data, starting at %llu", __func__, pos); in befs_read_datastream()
80 * befs_fblock2brun - give back block run for fblock
86 * Takes a file position and gives back a brun who's starting block
87 * is block number fblock of the file.
99 befs_off_t pos = fblock << BEFS_SB(sb)->block_shift; in befs_fblock2brun()
101 if (pos < data->max_direct_range) { in befs_fblock2brun()
104 } else if (pos < data->max_indirect_range) { in befs_fblock2brun()
107 } else if (pos < data->max_double_indirect_range) { in befs_fblock2brun()
112 "befs_fblock2brun() was asked to find block %lu, " in befs_fblock2brun()
121 * befs_read_lsmylink - read long symlink from datastream.
137 befs_debug(sb, "---> %s length: %llu", __func__, len); in befs_read_lsymlink()
142 befs_error(sb, "BeFS: Error reading datastream block " in befs_read_lsymlink()
144 befs_debug(sb, "<--- %s ERROR", __func__); in befs_read_lsymlink()
148 plen = ((bytes_read + BEFS_SB(sb)->block_size) < len) ? in befs_read_lsymlink()
149 BEFS_SB(sb)->block_size : len - bytes_read; in befs_read_lsymlink()
150 memcpy(buff + bytes_read, bh->b_data, plen); in befs_read_lsymlink()
155 befs_debug(sb, "<--- %s read %u bytes", __func__, (unsigned int) in befs_read_lsymlink()
161 * befs_count_blocks - blocks used by a file
179 befs_debug(sb, "---> %s", __func__); in befs_count_blocks()
181 datablocks = ds->size >> befs_sb->block_shift; in befs_count_blocks()
182 if (ds->size & (befs_sb->block_size - 1)) in befs_count_blocks()
185 metablocks = 1; /* Start with 1 block for inode */ in befs_count_blocks()
187 /* Size of indirect block */ in befs_count_blocks()
188 if (ds->size > ds->max_direct_range) in befs_count_blocks()
189 metablocks += ds->indirect.len; in befs_count_blocks()
192 * Double indir block, plus all the indirect blocks it maps. in befs_count_blocks()
193 * In the double-indirect range, all block runs of data are in befs_count_blocks()
195 * how many data block runs are in the double-indirect region, in befs_count_blocks()
200 if (ds->size > ds->max_indirect_range && ds->max_indirect_range != 0) { in befs_count_blocks()
206 ds->max_double_indirect_range - ds->max_indirect_range; in befs_count_blocks()
208 dbl_bytes / (befs_sb->block_size * BEFS_DBLINDIR_BRUN_LEN); in befs_count_blocks()
211 metablocks += ds->double_indirect.len; in befs_count_blocks()
216 befs_debug(sb, "<--- %s %u blocks", __func__, (unsigned int)blocks); in befs_count_blocks()
222 * befs_find_brun_direct - find a direct block run in the datastream
228 * Finds the block run that starts at file block number blockno
237 * contains the blockno-th filesystem block. This is necessary
238 * because the block runs map variable amounts of data. Simply
240 * incrementing this by the length of each block run as we come
245 * When/if blockno is found, if blockno is inside of a block
246 * run as stored on disk, we offset the start and length members
247 * of the block run, so that blockno is the start and len is
255 const befs_block_run *array = data->direct; in befs_find_brun_direct()
258 befs_debug(sb, "---> %s, find %lu", __func__, (unsigned long)blockno); in befs_find_brun_direct()
263 int offset = blockno - sum; in befs_find_brun_direct() local
265 run->allocation_group = array[i].allocation_group; in befs_find_brun_direct()
266 run->start = array[i].start + offset; in befs_find_brun_direct()
267 run->len = array[i].len - offset; in befs_find_brun_direct()
269 befs_debug(sb, "---> %s, " in befs_find_brun_direct()
276 befs_error(sb, "%s failed to find file block %lu", __func__, in befs_find_brun_direct()
278 befs_debug(sb, "---> %s ERROR", __func__); in befs_find_brun_direct()
283 * befs_find_brun_indirect - find a block run in the datastream
289 * Finds the block run that starts at file block number blockno
297 * For each block in the indirect run of the datastream, read
317 befs_block_run indirect = data->indirect; in befs_find_brun_indirect()
321 befs_debug(sb, "---> %s, find %lu", __func__, (unsigned long)blockno); in befs_find_brun_indirect()
323 indir_start_blk = data->max_direct_range >> BEFS_SB(sb)->block_shift; in befs_find_brun_indirect()
324 search_blk = blockno - indir_start_blk; in befs_find_brun_indirect()
330 befs_error(sb, "---> %s failed to read " in befs_find_brun_indirect()
331 "disk block %lu from the indirect brun", in befs_find_brun_indirect()
333 befs_debug(sb, "<--- %s ERROR", __func__); in befs_find_brun_indirect()
337 array = (befs_disk_block_run *) indirblock->b_data; in befs_find_brun_indirect()
343 int offset = search_blk - sum; in befs_find_brun_indirect() local
344 run->allocation_group = in befs_find_brun_indirect()
346 run->start = in befs_find_brun_indirect()
347 fs16_to_cpu(sb, array[j].start) + offset; in befs_find_brun_indirect()
348 run->len = in befs_find_brun_indirect()
349 fs16_to_cpu(sb, array[j].len) - offset; in befs_find_brun_indirect()
353 "<--- %s found file block " in befs_find_brun_indirect()
367 "file block %lu", __func__, (unsigned long)blockno); in befs_find_brun_indirect()
369 befs_debug(sb, "<--- %s ERROR", __func__); in befs_find_brun_indirect()
374 * befs_find_brun_dblindirect - find a block run in the datastream
380 * Finds the block run that starts at file block number blockno
382 * blockno is in the double-indirect region of the datastream.
388 * The block runs in the double-indirect region are different.
390 * block run maps a constant amount of file data. This means
391 * that we can directly calculate how many block runs into the
392 * double-indirect region we need to go to get to the one that
393 * maps a particular filesystem block.
396 * inode addresses in the double-indirect block will point us
397 * to the indirect block that contains the mapping for the data,
399 * indirect block maps the data block we are after.
403 * though the double-indirect run may be several blocks long,
406 * the indirect block and perform a similar process to find
407 * the actual block run that maps the data block we are interested
410 * Then we offset the run as in befs_find_brun_array() and we are
421 int offset; in befs_find_brun_dblindirect() local
434 data->max_indirect_range >> BEFS_SB(sb)->block_shift; in befs_find_brun_dblindirect()
436 off_t dbl_indir_off = blockno - indir_start_blk; in befs_find_brun_dblindirect()
439 * the indirect block pointed to by the double indirect block in befs_find_brun_dblindirect()
444 * the double indirect block in befs_find_brun_dblindirect()
449 befs_debug(sb, "---> %s find %lu", __func__, (unsigned long)blockno); in befs_find_brun_dblindirect()
451 /* First, discover which of the double_indir->indir blocks in befs_find_brun_dblindirect()
454 * the indirect block contains pos. in befs_find_brun_dblindirect()
461 /* Read double indirect block */ in befs_find_brun_dblindirect()
463 if (dbl_which_block > data->double_indirect.len) { in befs_find_brun_dblindirect()
464 befs_error(sb, "The double-indirect index calculated by " in befs_find_brun_dblindirect()
466 "of the double-indirect block", __func__, in befs_find_brun_dblindirect()
472 sb_bread(sb, iaddr2blockno(sb, &data->double_indirect) + in befs_find_brun_dblindirect()
476 "double-indirect block at blockno %lu", __func__, in befs_find_brun_dblindirect()
478 iaddr2blockno(sb, &data->double_indirect) + in befs_find_brun_dblindirect()
484 dblindir_indx - (dbl_which_block * befs_iaddrs_per_block(sb)); in befs_find_brun_dblindirect()
485 iaddr_array = (befs_disk_inode_addr *) dbl_indir_block->b_data; in befs_find_brun_dblindirect()
489 /* Read indirect block */ in befs_find_brun_dblindirect()
494 "of the indirect block", __func__, indir_indx); in befs_find_brun_dblindirect()
501 befs_error(sb, "%s couldn't read the indirect block " in befs_find_brun_dblindirect()
507 block_indx = indir_indx - (which_block * befs_iaddrs_per_block(sb)); in befs_find_brun_dblindirect()
508 iaddr_array = (befs_disk_inode_addr *) indir_block->b_data; in befs_find_brun_dblindirect()
515 offset = blockno - blockno_at_run_start; in befs_find_brun_dblindirect()
517 run->start += offset; in befs_find_brun_dblindirect()
518 run->len -= offset; in befs_find_brun_dblindirect()
520 befs_debug(sb, "Found file block %lu in double_indirect[%d][%d]," in befs_find_brun_dblindirect()