Lines Matching +full:cache +full:- +full:block

1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
5 * GRUB -- GRand Unified Bootloader
8 * (C) Copyright 2003 - 2004
51 return -1; in substring()
66 printf ("%-10s %4hd %6d %6d %9d %24.24s", in sd_print_item()
73 printf ("%-10s %4d %6d %6d %9d %24.24s", in sd_print_item()
80 journal_read (int block, int len, char *buffer) in journal_read() argument
82 return reiserfs_devread ((INFO->journal_block + block) << INFO->blocksize_shift, in journal_read()
86 /* Read a block from ReiserFS file system, taking the journal into
87 * account. If the block nr is in the journal, the block from the
93 int transactions = INFO->journal_transactions; in block_read()
94 int desc_block = INFO->journal_first_desc; in block_read()
95 int journal_mask = INFO->journal_block_count - 1; in block_read()
98 while (transactions-- > 0) in block_read()
110 journal_table += j_len - i; in block_read()
138 if (__le32_to_cpu(commit.j_realblock[i++ - JOURNAL_TRANS_HALF]) == blockNr) in block_read()
145 translatedNr = INFO->journal_block + ((desc_block + i) & journal_mask); in block_read()
147 printf ("block_read: block %d is mapped to journal block %d.\n", in block_read()
148 blockNr, translatedNr - INFO->journal_block); in block_read()
150 /* We must continue the search, as this block may be overwritten in block_read()
156 return reiserfs_devread (translatedNr << INFO->blocksize_shift, start, len, buffer); in block_read()
159 /* Init the journal data structure. We try to cache as much as
160 * possible in the JOURNAL_START-JOURNAL_END space, but if it is full
163 * The first number of valid transactions and the descriptor block of the
170 unsigned int block_count = INFO->journal_block_count; in journal_init()
184 INFO->journal_first_desc = desc_block; in journal_init()
201 commit_block = (desc_block + __le32_to_cpu(desc.j_len) + 1) & (block_count - 1); in journal_init()
226 /* Cache the length and the realblock numbers in the table. in journal_init()
227 * The block number of descriptor can easily be computed. in journal_init()
238 printf ("block %d is in journal %d.\n", in journal_init()
245 *journal_table++ = commit.j_realblock[i-JOURNAL_TRANS_HALF]; in journal_init()
247 printf ("block %d is in journal %d.\n", in journal_init()
248 __le32_to_cpu(commit.j_realblock[i-JOURNAL_TRANS_HALF]), in journal_init()
254 desc_block = (commit_block + 1) & (block_count - 1); in journal_init()
261 INFO->journal_transactions in journal_init()
262 = next_trans_id - __le32_to_cpu(header.j_last_flush_trans_id) - 1; in journal_init()
272 char *cache; in reiserfs_mount() local
284 /* Try old super block position */ in reiserfs_mount()
294 /* pre journaling super block ? */ in reiserfs_mount()
309 INFO->version = sb_version(&super); in reiserfs_mount()
310 INFO->blocksize = sb_blocksize(&super); in reiserfs_mount()
311 INFO->fullblocksize_shift = log2 (sb_blocksize(&super)); in reiserfs_mount()
312 INFO->blocksize_shift = INFO->fullblocksize_shift - SECTOR_BITS; in reiserfs_mount()
313 INFO->cached_slots = in reiserfs_mount()
314 (FSYSREISER_CACHE_SIZE >> INFO->fullblocksize_shift) - 1; in reiserfs_mount()
318 INFO->version, INFO->blocksize); in reiserfs_mount()
321 /* Clear node cache. */ in reiserfs_mount()
322 memset (INFO->blocks, 0, sizeof (INFO->blocks)); in reiserfs_mount()
326 || (SECTOR_SIZE << INFO->blocksize_shift) != sb_blocksize(&super)) in reiserfs_mount()
332 INFO->journal_transactions = 0; in reiserfs_mount()
335 INFO->journal_block = sb_journal_block(&super); in reiserfs_mount()
336 INFO->journal_block_count = sb_journal_size(&super); in reiserfs_mount()
337 if (is_power_of_two (INFO->journal_block_count)) in reiserfs_mount()
340 /* Read in super block again, maybe it is in the journal */ in reiserfs_mount()
341 block_read (superblock >> INFO->blocksize_shift, in reiserfs_mount()
345 if (! block_read (sb_root_block(&super), 0, INFO->blocksize, (char*) ROOT)) in reiserfs_mount()
348 cache = ROOT; in reiserfs_mount()
349 INFO->tree_depth = __le16_to_cpu(BLOCKHEAD (cache)->blk_level); in reiserfs_mount()
352 printf ("root read_in: block=%d, depth=%d\n", in reiserfs_mount()
353 sb_root_block(&super), INFO->tree_depth); in reiserfs_mount()
356 if (INFO->tree_depth >= MAX_HEIGHT) in reiserfs_mount()
358 if (INFO->tree_depth == DISK_LEAF_NODE_LEVEL) in reiserfs_mount()
362 memcpy (LEAF, ROOT, INFO->blocksize); in reiserfs_mount()
372 * My tree node cache is organized as following
375 * 2-n other nodes on current path from bottom to top.
376 * if there is not enough space in the cache, the top most are
388 /* Read in the node at the current path and depth into the node cache.
389 * You must set INFO->blocks[depth] before.
394 char* cache = CACHE(depth); in read_tree_node() local
395 int num_cached = INFO->cached_slots; in read_tree_node()
398 /* This is the cached part of the path. Check if same block is in read_tree_node()
401 if (blockNr == INFO->blocks[depth]) in read_tree_node()
402 return cache; in read_tree_node()
405 cache = CACHE(num_cached); in read_tree_node()
408 printf (" next read_in: block=%d (depth=%d)\n", in read_tree_node()
411 if (! block_read (blockNr, 0, INFO->blocksize, cache)) in read_tree_node()
414 if (__le16_to_cpu(BLOCKHEAD (cache)->blk_level) != depth) in read_tree_node()
420 INFO->blocks[depth] = blockNr; in read_tree_node()
421 return cache; in read_tree_node()
425 * tree order. INFO->current_ih and
426 * INFO->current_info are adapted accordingly. */
431 struct item_head *ih = INFO->current_ih + 1; in next_key()
432 char *cache; in next_key() local
436 __le32_to_cpu(INFO->current_ih->ih_key.k_dir_id), in next_key()
437 __le32_to_cpu(INFO->current_ih->ih_key.k_objectid), in next_key()
438 __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_offset), in next_key()
439 __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_uniqueness), in next_key()
440 __le16_to_cpu(INFO->current_ih->ih_version)); in next_key()
443 if (ih == &ITEMHEAD[__le16_to_cpu(BLOCKHEAD (LEAF)->blk_nr_item)]) in next_key()
447 * Read in the next block in next_key()
451 if (depth == INFO->tree_depth) in next_key()
455 ih = (struct item_head *) &BLOCKHEAD (LEAF)->blk_right_delim_key; in next_key()
460 printf (" depth=%d, i=%d\n", depth, INFO->next_key_nr[depth]); in next_key()
463 while (INFO->next_key_nr[depth] == 0); in next_key()
465 if (depth == INFO->tree_depth) in next_key()
466 cache = ROOT; in next_key()
467 else if (depth <= INFO->cached_slots) in next_key()
468 cache = CACHE (depth); in next_key()
471 cache = read_tree_node (INFO->blocks[depth], depth); in next_key()
472 if (! cache) in next_key()
478 int nr_item = __le16_to_cpu(BLOCKHEAD (cache)->blk_nr_item); in next_key()
479 int key_nr = INFO->next_key_nr[depth]++; in next_key()
484 /* This is the last item in this block, set the next_key_nr to 0 */ in next_key()
485 INFO->next_key_nr[depth] = 0; in next_key()
487 cache = read_tree_node (dc_block_number(&(DC (cache)[key_nr])), --depth); in next_key()
488 if (! cache) in next_key()
496 INFO->current_ih = ih; in next_key()
497 INFO->current_item = &LEAF[__le16_to_cpu(ih->ih_item_location)]; in next_key()
500 __le32_to_cpu(INFO->current_ih->ih_key.k_dir_id), in next_key()
501 __le32_to_cpu(INFO->current_ih->ih_key.k_objectid), in next_key()
502 __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_offset), in next_key()
503 __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_uniqueness), in next_key()
504 __le16_to_cpu(INFO->current_ih->ih_version)); in next_key()
510 * INFO block is valid
515 * searched key. INFO->next_key contains the next key after
517 * side effects: messes around with the cache.
522 char *cache; in search_stat() local
531 depth = INFO->tree_depth; in search_stat()
532 cache = ROOT; in search_stat()
537 nr_item = __le16_to_cpu(BLOCKHEAD (cache)->blk_nr_item); in search_stat()
539 key = KEY (cache); in search_stat()
543 if (__le32_to_cpu(key->k_dir_id) > dir_id in search_stat()
544 || (__le32_to_cpu(key->k_dir_id) == dir_id in search_stat()
545 && (__le32_to_cpu(key->k_objectid) > objectid in search_stat()
546 || (__le32_to_cpu(key->k_objectid) == objectid in search_stat()
547 && (__le32_to_cpu(key->u.v1.k_offset) in search_stat()
548 | __le32_to_cpu(key->u.v1.k_uniqueness)) > 0)))) in search_stat()
556 INFO->next_key_nr[depth] = (i == nr_item) ? 0 : i+1; in search_stat()
557 cache = read_tree_node (dc_block_number(&(DC (cache)[i])), --depth); in search_stat()
558 if (! cache) in search_stat()
562 /* cache == LEAF */ in search_stat()
563 nr_item = __le16_to_cpu(BLOCKHEAD (LEAF)->blk_nr_item); in search_stat()
567 if (__le32_to_cpu(ih->ih_key.k_dir_id) == dir_id in search_stat()
568 && __le32_to_cpu(ih->ih_key.k_objectid) == objectid in search_stat()
569 && __le32_to_cpu(ih->ih_key.u.v1.k_offset) == 0 in search_stat()
570 && __le32_to_cpu(ih->ih_key.u.v1.k_uniqueness) == 0) in search_stat()
575 INFO->current_ih = ih; in search_stat()
576 INFO->current_item = &LEAF[__le16_to_cpu(ih->ih_item_location)]; in search_stat()
595 filepos, len, (__u64) IH_KEY_OFFSET (INFO->current_ih) - 1); in reiserfs_read()
598 if (__le32_to_cpu(INFO->current_ih->ih_key.k_objectid) != INFO->fileinfo.k_objectid in reiserfs_read()
599 || IH_KEY_OFFSET (INFO->current_ih) > filepos + 1) in reiserfs_read()
601 search_stat (INFO->fileinfo.k_dir_id, INFO->fileinfo.k_objectid); in reiserfs_read()
607 if (__le32_to_cpu(INFO->current_ih->ih_key.k_objectid) != INFO->fileinfo.k_objectid) { in reiserfs_read()
611 offset = filepos - IH_KEY_OFFSET (INFO->current_ih) + 1; in reiserfs_read()
612 blocksize = __le16_to_cpu(INFO->current_ih->ih_item_len); in reiserfs_read()
619 if (IH_KEY_ISTYPE(INFO->current_ih, TYPE_DIRECT) in reiserfs_read()
626 to_read = blocksize - offset; in reiserfs_read()
630 memcpy (buf, INFO->current_item + offset, to_read); in reiserfs_read()
633 else if (IH_KEY_ISTYPE(INFO->current_ih, TYPE_INDIRECT)) in reiserfs_read()
635 blocksize = (blocksize >> 2) << INFO->fullblocksize_shift; in reiserfs_read()
643 __u32 blocknr = __le32_to_cpu(((__u32 *) INFO->current_item) in reiserfs_read()
644 [offset >> INFO->fullblocksize_shift]); in reiserfs_read()
645 int blk_offset = offset & (INFO->blocksize-1); in reiserfs_read()
646 to_read = INFO->blocksize - blk_offset; in reiserfs_read()
653 reiserfs_devread (blocknr << INFO->blocksize_shift, in reiserfs_read()
656 len -= to_read; in reiserfs_read()
668 return errnum ? 0 : buf - prev_buf; in reiserfs_read()
673 * INFO block is valid
675 * postconditions: on a nonzero return, INFO->fileinfo contains the info
707 stat_data_v1(INFO->current_ih) ? sd_v1_mode((struct stat_data_v1 *) INFO->current_item) : in reiserfs_dir()
708 sd_v2_mode((struct stat_data *) (INFO->current_item)), in reiserfs_dir()
709 stat_data_v1(INFO->current_ih) ? sd_v1_size((struct stat_data_v1 *) INFO->current_item) : in reiserfs_dir()
710 sd_v2_size((struct stat_data *) INFO->current_item) in reiserfs_dir()
714 mode = stat_data_v1(INFO->current_ih) ? in reiserfs_dir()
715 sd_v1_mode((struct stat_data_v1 *) INFO->current_item) : in reiserfs_dir()
716 sd_v2_mode((struct stat_data *) INFO->current_item); in reiserfs_dir()
729 filemax = stat_data_v1(INFO->current_ih) ? in reiserfs_dir()
730 sd_v1_size((struct stat_data_v1 *) INFO->current_item) : in reiserfs_dir()
731 sd_v2_size((struct stat_data *) INFO->current_item); in reiserfs_dir()
738 if (filemax + len > sizeof (linkbuf) - 1) in reiserfs_dir()
748 INFO->fileinfo.k_dir_id = dir_id; in reiserfs_dir()
749 INFO->fileinfo.k_objectid = objectid; in reiserfs_dir()
793 filemax = stat_data_v1(INFO->current_ih) ? in reiserfs_dir()
794 sd_v1_size((struct stat_data_v1 *) INFO->current_item) : in reiserfs_dir()
795 sd_v2_size((struct stat_data *) INFO->current_item); in reiserfs_dir()
800 if (__le16_to_cpu(INFO->current_ih->ih_version) == ITEM_VERSION_2 in reiserfs_dir()
801 && sd_size_hi((struct stat_data *) INFO->current_item) > 0) in reiserfs_dir()
804 INFO->fileinfo.k_dir_id = dir_id; in reiserfs_dir()
805 INFO->fileinfo.k_objectid = objectid; in reiserfs_dir()
834 __le32_to_cpu(INFO->current_ih->ih_key.k_dir_id), in reiserfs_dir()
835 __le32_to_cpu(INFO->current_ih->ih_key.k_objectid), in reiserfs_dir()
836 __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_offset), in reiserfs_dir()
837 __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_uniqueness), in reiserfs_dir()
838 __le16_to_cpu(INFO->current_ih->ih_version)); in reiserfs_dir()
841 if (__le32_to_cpu(INFO->current_ih->ih_key.k_objectid) != objectid) in reiserfs_dir()
844 name_end = INFO->current_item + __le16_to_cpu(INFO->current_ih->ih_item_len); in reiserfs_dir()
845 de_head = (struct reiserfs_de_head *) INFO->current_item; in reiserfs_dir()
846 num_entries = __le16_to_cpu(INFO->current_ih->u.ih_entry_count); in reiserfs_dir()
849 char *filename = INFO->current_item + deh_location(de_head); in reiserfs_dir()
856 * NOTE: that this may overwrite the first block in in reiserfs_dir()
857 * the tree cache. That doesn't hurt as long as we in reiserfs_dir()
872 print_possibilities = -print_possibilities; in reiserfs_dir()
881 sd_print_item(INFO->current_ih, INFO->current_item); in reiserfs_dir()
897 num_entries--; in reiserfs_dir()
922 * U-Boot interface functions
928 * RETURN: 0 - OK, else grub_error_t errnum
958 * RETURN: >0 - OK, size of opened file
959 * <0 - ERROR -grub_error_t errnum
968 return -errnum; in reiserfs_open()