⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 reiserfsprogs-3.6.19.tar.gz 源码 给有需要的人!
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (get_reiserfs_format (fs->fs_ondisk_sb) != REISERFS_FORMAT_3_6) {        fsck_progress ("Filesystems of 3_5 format do not support extended "	    "attributes.\n");	        exit(EXIT_USER);    }    fsck_progress ("###########\n"	           "reiserfsck --clean-attributes started at %s"                   "###########\n", ctime (&t));    init_rollback_file (state_rollback_file(fs), &fs->fs_blocksize, 	fsck_data(fs)->log);    prepare_fs_for_check(fs);    do_clean_attributes (fs);    clean_after_dma_check(fs->fs_dev, &dma_info);    reiserfs_close (fs);    close_rollback_file ();    fsck_progress ("###########\n"		   "reiserfsck finished at %s"		   "###########\n", ctime (&t));    exit (EXIT_FIXED);}/* Do not allow buffers to be flushed after finishing to avoid another bitmap  * reading on mounting. */static void fsck_sleep() {    int res;        res = fork();        if (res == -1) {	reiserfs_panic ("reiserfsck: Fork failed: %s", strerror(errno));    } else if (res == 0) {	/* Make the child process to sleep for 5 secs. */	sleep(5);    }}static int auto_check (reiserfs_filsys_t *fs) {    __u16 state;    int retval = 0;        print_super_block (stdout, fs, fs->fs_file_name, fs->fs_super_bh, 1);        state = get_sb_fs_state (fs->fs_ondisk_sb);    if ((state & FS_FATAL) == FS_FATAL) {	fprintf(stderr, "Filesystem seems to have fatal corruptions. Running "	    "with --rebuild-tree is required.\n");	goto error;    }    if ((state & FS_ERROR) == FS_ERROR) {	fprintf(stderr, "Some corruptions on the filesystem were detected. Switching to "	    "the --fix-fixable mode.\n");	/* run fixable pass. */	return 0;    }        if (state != FS_CONSISTENT)	fprintf(stderr, "Some strange state was specified in the super block. "	    "Do usual check.\n");    prepare_fs_for_check(fs);    /* Check bitmaps. */    retval = reiserfs_open_ondisk_bitmap (fs);        if (retval > 0) {	fsck_log("Zero bit found in on-disk bitmap after the last valid bit. "	    "Switching to --fix-fixable mode.\n");	/* run fixable pass. */	return 0;    } else if (retval < 0) {        fsck_progress ("reiserfsck: Could not open bitmap\n");	goto error;    }        if (get_sb_block_count (fs->fs_ondisk_sb) - 	get_sb_free_blocks(fs->fs_ondisk_sb) != 	fs->fs_bitmap2->bm_set_bits)    {	fsck_log("Wrong amount of used blocks. Switching to the --fix-fixable mode.\n");	/* run fixable pass. */	return 0;    }    check_fs_tree (fs);        if (fsck_data (fs)->check.fatal_corruptions) {			fprintf(stderr, "%lu fatal corruption(s) found in the root block. Running "	    "with the --rebuild-tree is required.\n", 	    fsck_data (fs)->check.fatal_corruptions);	goto fatal_error;    } else if (fsck_data (fs)->check.fixable_corruptions) {        /* seems that this cannot happen. */	fprintf(stderr, "%lu fixable corruption(s) found. Switching to "	    "the --fix-fixable mode.\n", fsck_data (fs)->check.fixable_corruptions);	fsck_data (fs)->check.fixable_corruptions = 0;	/* run fixable pass. */	return 0;    }        clean_after_dma_check(fs->fs_dev, &dma_info);        fsck_sleep();        reiserfs_close (fs);    /* do not do anything else. */        exit (EXIT_OK);fatal_error:    set_sb_fs_state(fs->fs_ondisk_sb, FS_FATAL);    mark_buffer_dirty (fs->fs_super_bh);    bwrite(fs->fs_super_bh);	error:    clean_after_dma_check(fs->fs_dev, &dma_info);    reiserfs_close(fs);    exit(EXIT_FATAL);}/* check umounted or read-only mounted filesystems only */static void check_fs (reiserfs_filsys_t * fs){    int retval = EXIT_OK;    time_t t;    time (&t);    if (fsck_mode (fs) != FSCK_FIX_FIXABLE) {        fsck_progress ("###########\n"	               "reiserfsck --check started at %s"                       "###########\n", ctime (&t));    } else {        fsck_progress ("###########\n"	               "reiserfsck --fix-fixable started at %s"                       "###########\n", ctime (&t));    }    init_rollback_file (state_rollback_file(fs), &fs->fs_blocksize, 	fsck_data(fs)->log);        prepare_fs_for_check (fs);    if (!fs->fs_bitmap2)	/* It could be done on auto_check already. */	retval = reiserfs_open_ondisk_bitmap (fs);    if (retval > 0) {	if (fsck_mode(fs) != FSCK_FIX_FIXABLE) {	    fsck_log("Zero bit found in on-disk bitmap after the last valid "		"bit.\n");	    	    one_more_corruption(fs, FIXABLE);	} else {	    fsck_log("Zero bit found in on-disk bitmap after the last valid "		"bit. Fixed.\n");	}    } else if (retval < 0) {        fsck_progress ("reiserfsck: Could not open bitmap\n");	reiserfs_close (fs);	exit(EXIT_OPER);    }    check_fs_tree (fs);    semantic_check ();        if (fsck_data (fs)->check.fatal_corruptions) {	fsck_progress ("%lu found corruptions can be fixed only when running with "	    "--rebuild-tree\n", fsck_data (fs)->check.fatal_corruptions);	        set_sb_fs_state (fs->fs_ondisk_sb, FS_FATAL);        mark_buffer_dirty (fs->fs_super_bh);	retval = EXIT_FATAL;    } else if (fsck_data (fs)->check.fixable_corruptions) {        /* fixable corruptions found */	if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {            /* fixable corruptions found and fix-fixable has not fixed them, 	     * do rebuild-tree */	                fsck_progress ("Fatal error: %lu fixable corruptions found after "		"--fix-fixable.\n", fsck_data (fs)->check.fixable_corruptions);	    retval = EXIT_OPER;        } else {	    fsck_progress ("%lu found corruptions can be fixed when running with "		"--fix-fixable\n", fsck_data (fs)->check.fixable_corruptions);	    	    retval = EXIT_FIXABLE;        }        set_sb_fs_state (fs->fs_ondisk_sb, FS_ERROR);        mark_buffer_dirty (fs->fs_super_bh);    } else {	fsck_progress ("No corruptions found\n");	stage_report (5, fs);	if (fsck_mode(fs) != FSCK_CHECK) {		if (misc_device_mounted(fs->fs_file_name) == MF_RO) {			reiserfs_warning(stderr, "\nThe partition is mounted ro. It is better "					 "to umount and mount it again.\n\n");			retval = EXIT_REBOOT;		} else 			retval = EXIT_FIXED;	} else		retval = EXIT_OK;	mark_filesystem_consistent (fs);    }       if (fsck_mode (fs) == FSCK_FIX_FIXABLE && !fsck_data (fs)->check.fatal_corruptions)        id_map_flush(proper_id_map (fs), fs);            id_map_free(proper_id_map (fs));    clean_after_dma_check(fs->fs_dev, &dma_info);    reiserfs_close (fs);    close_rollback_file ();        //clear_relocated_list();            time (&t);    fsck_progress ("###########\n"		   "reiserfsck finished at %s"		   "###########\n", ctime (&t));    exit(retval);}static int open_devices_for_rollback (char * file_name,     struct fsck_data * data) {    int fd;    fd = open (file_name, O_RDWR | O_LARGEFILE);    if (fd == -1) {        reiserfs_warning (stderr, "reiserfsck: Cannot not open the fs "	    "partition %s\n", file_name);        return -1;    }    fs = getmem (sizeof (*fs));    fs->fs_dev = fd;    fs->fs_vp = data;    asprintf (&fs->fs_file_name, "%s", file_name);    if (data->journal_dev_name && 	strcmp (data->journal_dev_name, file_name))     {	fs->fs_journal_dev = open (data->journal_dev_name, 	    O_RDWR | O_LARGEFILE);	if (fs->fs_journal_dev == -1) {	    reiserfs_warning (stderr, "Cannot open journal partition\n");     	    return -1;	}    }    if (open_rollback_file (state_rollback_file(fs), fsck_data(fs)->log))        return -1;    return 0;    	}static void fsck_rollback (reiserfs_filsys_t * fs) {    time_t t;    time (&t);    fsck_progress ("###########\n"	           "reiserfsck --rollback-fsck-changes started at %s"                   "###########\n", ctime (&t));    do_fsck_rollback (fs->fs_dev, fs->fs_journal_dev, fsck_progress_file (fs));    close_rollback_file ();    close (fs->fs_journal_dev);    free (fs->fs_file_name);    fs->fs_file_name = 0;    close (fs->fs_dev);    freemem (fs);    time (&t);    fsck_progress ("###########\n"		   "reiserfsck finished at %s"		   "###########\n", ctime (&t));    exit(EXIT_FIXED);}int main (int argc, char * argv []){    char * file_name;    struct fsck_data * data;    struct rlimit rlim = {RLIM_INFINITY, RLIM_INFINITY};    char *width;    int retval;    int error;        width = getenv("COLUMNS");    if ( width )	screen_width = atoi(width);        if (screen_width == 0)	screen_width = 80; // We default to 80 characters wide screen    screen_width--;    screen_savebuffer_len=screen_width;    screen_savebuffer=getmem(screen_width+1);    memset(screen_savebuffer,0,screen_savebuffer_len+1);        lost_found_dir_key.k2_dir_id = cpu_to_le32(lost_found_dir_key.k2_dir_id);    lost_found_dir_key.k2_objectid = cpu_to_le32(lost_found_dir_key.k2_objectid);    /* this is only needed (and works) when running under 2.4 on regular files */    if (setrlimit (RLIMIT_FSIZE, &rlim) == -1) {	reiserfs_warning (stderr, "Cannot change the system limit for file size "	    "with setrlimit: %s\n", strerror(errno));    }    data = getmem (sizeof (struct fsck_data));    file_name = parse_options (data, argc, argv);    if (data->mode != FSCK_AUTO)	print_banner ("reiserfsck");    if (data->mode == DO_NOTHING) {	freemem (data);	exit(EXIT_OK);    }    if (data->options & OPT_BACKGROUND) {	/* running in background reiserfsck appends progress information into           'fsck.run'. Logs get there if log file was not specified*/	data->options |= OPT_QUIET;	data->progress = fopen ("fsck.run", "a+");	if (!data->progress) {	    reiserfs_exit(EXIT_OPER, "reiserfsck: Cannot not open \"fsck.run\"");	}	if (data->log == stdout)	    /* no log file specifed - redirect log into 'fsck.run' */	    data->log = data->progress;	retval = fork ();	if (retval == -1) {	    reiserfs_panic ("reiserfsck: Fork failed: %s", strerror(errno));	} else if (retval != 0) {	    exit(EXIT_OPER);	}	reiserfs_warning (stderr, "\nReiserfsck is running in background as "	    "[%d],\nmake sure that it gets all the confirmations from stdin "	    "that it requests.\n\n", getpid ());    }    /* This asks for confirmation also. */    if (data->mode != FSCK_AUTO)	warn_what_will_be_done(file_name, data);    if (data->mode == FSCK_ROLLBACK_CHANGES) {    	if (open_devices_for_rollback (file_name, data) == -1)    	    exit(EXIT_OPER);    } else {	fs = reiserfs_open (file_name, O_RDONLY, &error, data, 	    data->mode != FSCK_SB);			if (error) {		reiserfs_exit(EXIT_OPER, "Failed to open the device "			      "'%s': %s\n\n", file_name, strerror(error));	} 		if (data->mode != FSCK_SB) {	    if (no_reiserfs_found (fs)) {		reiserfs_exit(EXIT_OPER, "Failed to open the filesystem.\n\n"			      "If the partition table has not been changed, "			      "and the partition is\nvalid  and  it really  "			      "contains  a reiserfs  partition,  then the\n"			      "superblock  is corrupted and you need to run "			      "this utility with\n--rebuild-sb.\n");	    }	    if (fsck_skip_journal (fs) && 		!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb)) 	    {		reiserfs_warning (stderr, "Filesystem with default journal found, "			"--no-journal-available is ignored\n");		fsck_data(fs)->options &= ~OPT_SKIP_JOURNAL;	    }		    if (!fsck_skip_journal (fs)) {		retval = reiserfs_open_journal(fs, data->journal_dev_name, O_RDONLY);				if (retval) {	            fsck_progress ("Failed to open the journal device (%s).\n", 			data->journal_dev_name);		    		    if (retval == 1) {			    fsck_progress ("Run --rebuild-sb to rebuild journal parameters.\n");		    }		    		    reiserfs_close (fs);		    exit(EXIT_OPER);	        }	    }		    if (data->options & BADBLOCKS_FILE) {		if (create_badblock_bitmap (fs, badblocks_file) != 0) 		    exit(EXIT_OPER);	    }	    	    register_timer();    	}    }    switch (data->mode) {    case FSCK_SB:	rebuild_sb (fs, file_name, data);	break;        case FSCK_AUTO:	/* perform some light-weight checks. If error, do fixable job. */	if (auto_check (fs))	    break;	data->mode = FSCK_FIX_FIXABLE;    case FSCK_CHECK:    case FSCK_FIX_FIXABLE:	check_fs (fs);	break;    case FSCK_REBUILD:    case DO_TEST:	rebuild_tree (fs);	break;    case FSCK_ROLLBACK_CHANGES:	fsck_rollback (fs); 	break;    case FSCK_CLEAN_ATTRIBUTES:	clean_attributes (fs);    }        exit(EXIT_OPER);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -