📄 pass2.c
字号:
fsck_log ("older sd, mode (%M), is replaced with it.\n", st_mode (get_item (&path))); reiserfsck_delete_item (&path, 0/*not temporary*/); reiserfs_search_by_key_4 (fs, &new_ih->ih_key, &path); reiserfsck_insert_item (&path, new_ih, new_item); } } else { /* both stat data are of the same version */ overwrite_stat_data (new_ih, new_item, &path); pathrelse (&path); } return; } /* item not found, insert a new one */ reiserfsck_insert_item (&path, new_ih, new_item);}/* this tries to put each item entry to the tree, if there is no items of the directory, insert item containing 1 entry */static void put_directory_item_into_tree (struct item_head * comingih, char * item){ struct reiserfs_de_head * deh; int i; char * buf; char * name; int namelen; /* if there are anything with this key but a directory - move it somewhere else */ rewrite_file (comingih, 1, 0/* do not change ih */); deh = (struct reiserfs_de_head *)item; for (i = 0; i < get_ih_entry_count (comingih); i ++, deh ++) { name = name_in_entry (deh, i); namelen = name_in_entry_length (comingih, deh, i); if (!is_properly_hashed (fs, name, namelen, get_deh_offset (deh))) reiserfs_panic ("put_directory_item_into_tree: The entry (%d) \"%.*s\" of the directory %k has" " badly hashed entry", i, namelen, name, &comingih->ih_key); asprintf (&buf, "%.*s", namelen, name); /* 1 for fsck is important: if there is no any items of this directory in the tree yet - new item will be inserted marked not reached */ reiserfs_add_entry (fs, &(comingih->ih_key), buf, entry_length (comingih, deh, i), (struct key *)&(deh->deh2_dir_id), 1 << IH_Unreachable); free (buf); }}void insert_item_separately (struct item_head * ih, char * item, int was_in_tree){ if (get_key_dirid (&ih->ih_key) == get_key_objectid (&ih->ih_key)) reiserfs_panic ("insert_item_separately: The item being inserted has the bad key %H", ih); if (is_stat_data_ih (ih)) { put_sd_into_tree (ih, item); } else if (is_direntry_ih (ih)) { put_directory_item_into_tree (ih, item); } else { reiserfsck_file_write (ih, item, was_in_tree); }}static void put_stat_data_items (struct buffer_head * bh) { int i; struct item_head * ih; ih = B_N_PITEM_HEAD (bh, 0); for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) { /* this check instead of saved_items */ if (!is_stat_data_ih (ih) || is_bad_item (bh, ih, B_I_PITEM (bh, ih))) { continue; } insert_item_separately (ih, B_I_PITEM (bh, ih), 0/*was in tree*/); }}static void put_not_stat_data_items (struct buffer_head * bh){ int i; struct item_head * ih; ih = B_N_PITEM_HEAD (bh, 0); for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) { if (is_stat_data_ih (ih) || is_bad_item (bh, ih, B_I_PITEM (bh, ih))) { continue; } insert_item_separately (ih, B_I_PITEM (bh, ih), 0/*was in tree*/); }}static void before_pass_2 (reiserfs_filsys_t * fs){ /* anything specific for pass 2 ? */}static void save_pass_2_result (reiserfs_filsys_t * fs){ FILE * file; int retval; file = open_file("temp_fsck_file.deleteme", "w+"); if (!file) return; /* to be able to restart from semantic we do not need to save anything here, but two magic values */ reiserfs_begin_stage_info_save(file, TREE_IS_BUILT); reiserfs_end_stage_info_save (file); close_file (file); retval = rename ("temp_fsck_file.deleteme", state_dump_file (fs)); if (retval != 0) fsck_progress ("%s: Could not rename the temporary file temp_fsck_file.deleteme to %s", __FUNCTION__, state_dump_file (fs));}/* we have nothing to load from a state file, but we have to fetch on-disk bitmap, copy it to allocable bitmap, and fetch objectid map */void load_pass_2_result (reiserfs_filsys_t * fs){ fsck_new_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb)); reiserfs_bitmap_copy (fsck_new_bitmap (fs), fs->fs_bitmap2); fsck_allocable_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb)); reiserfs_bitmap_copy (fsck_allocable_bitmap (fs), fs->fs_bitmap2); fs->block_allocator = reiserfsck_reiserfs_new_blocknrs; fs->block_deallocator = reiserfsck_reiserfs_free_block; /* we need objectid map on semantic pass to be able to relocate files */ proper_id_map (fs) = id_map_init(); /* Not implemented yet. fetch_objectid_map (proper_id_map (fs), fs); */} /* uninsertable blocks are marked by 0s in uninsertable_leaf_bitmap during the pass 1. They must be not in the tree */static void do_pass_2 (reiserfs_filsys_t * fs) { struct buffer_head * bh; unsigned long j; int i, what_node; unsigned long done = 0, total; total = reiserfs_bitmap_zeros(fsck_uninsertables(fs)) * 2; if (!total) return; fsck_progress ("\nPass 2:\n"); for (i = 0; i < 2; i++) { j = 0; while ((j < fsck_uninsertables(fs)->bm_bit_size) && reiserfs_bitmap_find_zero_bit(fsck_uninsertables(fs), &j) == 0) { bh = bread (fs->fs_dev, j, fs->fs_blocksize); if (bh == 0) { fsck_log ("pass_2: Reading of the block (%lu) failed on the device 0x%x\n", j, fs->fs_dev); goto cont; } if (is_block_used (bh->b_blocknr) && !(block_of_journal (fs, bh->b_blocknr) && fsck_data(fs)->rebuild.use_journal_area)) { fsck_log("%s: The block (%lu) is in the tree already. Should not happen.\n", __FUNCTION__, bh->b_blocknr); goto cont; } /* this must be leaf */ what_node = who_is_this (bh->b_data, bh->b_size); if (what_node != THE_LEAF) { // || B_IS_KEYS_LEVEL(bh)) { fsck_log ("%s: The block (%b), marked as a leaf on the first two passes, " "is not a leaf! Will be skipped.\n", __FUNCTION__, bh); goto cont; }/* fsck_log ("block %lu is being inserted\n", bh->b_blocknr); check_buffers_mem(fsck_log_file (fs)); fflush(fsck_log_file (fs));*/ if (i) { /* insert all not SD items */ put_not_stat_data_items (bh); pass_2_stat (fs)->leaves ++; make_allocable (j); } else /* insert SD items only */ put_stat_data_items (bh); print_how_far (fsck_progress_file (fs), &done, total, 1, fsck_quiet (fs)); cont: brelse (bh); j ++; } } fsck_progress ("\n");}static void after_pass_2 (reiserfs_filsys_t * fs){ time_t t; /* we can now flush new_bitmap on disk as tree is built and contains all data, which were found on dik at start in used bitmaps */ reiserfs_bitmap_copy (fs->fs_bitmap2, fsck_new_bitmap (fs)); /* we should copy new_bitmap to allocable bitmap, becuase evth what is used for now (marked as used in new_bitmap) should not be allocablel; and what is not in tree for now should be allocable. these bitmaps differ because on pass2 we skip those blocks, whose SD's are not in the tree, and therefore indirect items of such bad leaves points to not used and not allocable blocks. */ /* DEBUG only *//* if (reiserfs_bitmap_compare (fsck_allocable_bitmap (fs), fsck_new_bitmap(fs))) { fsck_log ("Allocable bitmap differs from the new bitmap after pass2\n"); reiserfs_bitmap_copy (fsck_allocable_bitmap(fs), fsck_new_bitmap (fs)); }*/ /* update super block: objectid map, fsck state */ set_sb_fs_state (fs->fs_ondisk_sb, TREE_IS_BUILT); mark_buffer_dirty (fs->fs_super_bh); /* write all dirty blocks */ fsck_progress ("Flushing.."); id_map_flush(proper_id_map (fs), fs); fs->fs_dirt = 1; reiserfs_flush_to_ondisk_bitmap (fs->fs_bitmap2, fs); reiserfs_flush (fs); fsck_progress ("finished\n"); /* fixme: should be optional *//* fsck_progress ("Tree is built. Checking it - "); reiserfsck_check_pass1 (); fsck_progress ("finished\n");*/ stage_report (2, fs); /* free what we do not need anymore */ reiserfs_delete_bitmap (fsck_uninsertables (fs)); if (!fsck_run_one_step (fs)) { if (fsck_user_confirmed (fs, "Continue? (Yes):", "Yes\n", 1)) /* reiserfsck continues */ return; } else save_pass_2_result (fs); id_map_free(proper_id_map (fs)); proper_id_map (fs) = 0; reiserfs_delete_bitmap (fsck_new_bitmap (fs)); reiserfs_delete_bitmap (fsck_allocable_bitmap (fs)); time (&t); fsck_progress ("###########\n" "reiserfsck finished pass 2 at %s" "###########\n", ctime (&t)); fs->fs_dirt = 1; reiserfs_close (fs); exit(0);}void pass_2 (reiserfs_filsys_t * fs){ if (fsck_log_file (fs) != stderr) fsck_log ("####### Pass 2 #######\n"); before_pass_2 (fs); /* take blocks which were not inserted into tree yet and put each item separately */ do_pass_2 (fs); after_pass_2 (fs); if (get_sb_root_block (fs->fs_ondisk_sb) == ~(__u32)0 || get_sb_root_block (fs->fs_ondisk_sb) == 0) die ( "\nNo reiserfs metadata found. If you are sure that you had the reiserfs\n" "on this partition, then the start of the partition might be changed\n" "or all data were wiped out. The start of the partition may get changed\n" "by a partitioner if you have used one. Then you probably rebuilt the\n" "superblock as there was no one. Zero the block at 64K offset from the\n" "start of the partition (a new super block you have just built) and try\n" "to move the start of the partition a few cylinders aside and check if\n" "debugreiserfs /dev/xxx detects a reiserfs super block. If it does this\n" "is likely to be the right super block version. \n" "If this makes you nervous, try www.namesys.com/support.html, and for\n" "$25 the author of fsck, or a colleague if he is out, will step you\n" "through it all.\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -