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

📄 main.c

📁 reiserfsprogs-3.6.19.tar.gz 源码 给有需要的人!
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright 1996-2004 by Hans Reiser, licensing governed by  * reiserfsprogs/README */#include "fsck.h"#include <getopt.h>#include <sys/resource.h>#include <sys/mman.h>#include <signal.h>extern int screen_width;extern int screen_savebuffer_len;extern char *screen_savebuffer;reiserfs_filsys_t * fs;char * badblocks_file;#define print_usage_and_exit() {						\fsck_progress ("Usage: %s [mode] [options] "					\" device\n"									\"\n"										\"Modes:\n"									\"  --check\t\t\tconsistency checking (default)\n"				\"  --fix-fixable\t\t\tfix corruptions which can be fixed without \n"		\"  \t\t\t\t--rebuild-tree\n"							\"  --rebuild-sb\t\t\tsuper block checking and rebuilding if needed\n"		\"  \t\t\t\t(may require --rebuild-tree afterwards)\n"				\"  --rebuild-tree\t\tforce fsck to rebuild filesystem from scratch\n"		\"  \t\t\t\t(takes a long time)\n"						\"  --clean-attributes\t\tclean garbage in reserved fields in StatDatas \n"	\"Options:\n"									\"  -j | --journal device\t\tspecify journal if relocated\n"			\"  -B | --badblocks file\t\tfile with list of all bad blocks on the fs\n"			\"  -l | --logfile file\t\tmake fsck to complain to specifed file\n"		\"  -n | --nolog\t\t\tmake fsck to not complain\n"				\"  -z | --adjust-size\t\tfix file sizes to real size\n"				\"  -q | --quiet\t\t\tno speed info\n"						\"  -y | --yes\t\t\tno confirmations\n"						\"  -V\t\t\t\tprints version and exits\n"					\"  -a and -p\t\t\tsome light-weight auto checks for bootup\n"			\"  -f and -r\t\t\tignored\n"							\"Expert options:\n"								\"  --no-journal-available\tdo not open nor replay journal\n"			\"  -S | --scan-whole-partition\tbuild tree of all blocks of the device\n\n",	\  argv[0]);									\										\  exit(EXIT_OK);								\}/*   -B works with --fix-fixable        fixes indirect pointers pointed to	badblocks, adds badblocks to badblock list in fs.    and with --rebuild        builds the tree without pointers to badblocks (internal,	indirect), adds badblocks to badblock list in fs.  *//*Hidden usage:Modes:"  --rollback-fsck-changes\n\t\t\trollback all changes made by fsck\n"\Options:"  -b | --scan-marked-in-bitmap file\n"\"  \t\t\tbuild tree of blocks marked in the bitmapfile\n"\"  -R | --rollback-data file\n"\"  \t\t\tback up all changes to this file or rollback from this file\n"\"  \t\t\tpreviously backed up changes with --rollback-fsck-changes\n"\"  -d dumpfile\n"\"  \t\t\tto test fsck pass by pass - dump into dumpfile all needed\n"\"  \t\t\tinfo for the next pass and load on the start of the next pass\n"\"  -i | --interactive\tmake fsck to stop after every stage\n"\"  -h | --hash hashname\n"\"  -g | --background\n"\"  -t \t\tdo test\n"\*//* fsck is called with one non-optional argument - file name of device   containing reiserfs. This function parses other options, sets flags   based on parsing and returns non-optional argument */static char * parse_options (struct fsck_data * data, int argc, char * argv []){    int c;    static int mode = FSCK_CHECK;    static int flag;    data->rebuild.scan_area = USED_BLOCKS;    while (1) {	static struct option options[] = {	    /* modes */	    {"check", no_argument, &mode, FSCK_CHECK},	    {"fix-fixable", no_argument, &mode, FSCK_FIX_FIXABLE},	    {"rebuild-sb", no_argument, &mode, FSCK_SB},	    {"rebuild-tree", no_argument, &mode, FSCK_REBUILD},	    {"rollback-fsck-changes", no_argument, &mode, FSCK_ROLLBACK_CHANGES},	    {"clean-attributes", no_argument, &mode, FSCK_CLEAN_ATTRIBUTES},	    /* options */	    {"logfile", required_argument, 0, 'l'},	    {"badblocks", required_argument, 0, 'B'},	    {"interactive", no_argument, 0, 'i'},	    {"adjust-size", no_argument, 0, 'z'},	    {"quiet", no_argument, 0, 'q'},	    {"yes", no_argument, 0, 'y'},	    {"nolog", no_argument, 0, 'n'},	    	    /* if file exists ad reiserfs can be load of it - only               blocks marked used in that bitmap will be read */	    {"scan-marked-in-bitmap", required_argument, 0, 'b'},	    {"create-passes-dump", required_argument, 0, 'd'},		    /* all blocks will be read */	    {"scan-whole-partition", no_argument, 0, 'S'},	    /* useful for -S */	    {"hash", required_argument, 0, 'h'},            /* preparing rollback data*/	    {"rollback-data", required_argument, 0, 'R'},	    	    {"journal", required_argument, 0, 'j'},	    {"no-journal-available", no_argument, &flag, OPT_SKIP_JOURNAL},	    	    {"bad-block-file", required_argument, 0, 'B'},	    /* start reiserfsck in background and exit */	    {"background", no_argument, 0, 'g'},	    {0, 0, 0, 0}	};	int option_index;      	c = getopt_long (argc, argv, "iql:nb:Szd:R:h:j:gafVrpyt:B:",			 options, &option_index);	if (c == -1)	    break;		switch (c) {	case 0:	    /* long-only options */	    if (flag == OPT_SKIP_JOURNAL) {		/* no journal available */		data->options |= OPT_SKIP_JOURNAL;		flag = 0;	    }	    break; 	case 'i': /* --interactive */	    data->options |= OPT_INTERACTIVE;	    break;	case 'q': /* --quiet */	    data->options |= OPT_QUIET;	    break;	case 'y': /* --quiet */	    data->options |= OPT_YES;	    break;	case 'l': /* --logfile */	    data->log_file_name = optarg;	    /*asprintf (&data->log_file_name, "%s", optarg);*/	    data->log = fopen (optarg, "w");	    if (!data->log)		fprintf (stderr, "reiserfsck: Cannot not open \'%s\': %s", 		    optarg, strerror(errno));	    	    break;	case 'n': /* --nolog */	    data->options |= OPT_SILENT;	    break;	case 'b': /* --scan-marked-in-bitmap */	    /* will try to load a bitmap from a file and read only               blocks marked in it. That bitmap could be created by               previous run of reiserfsck with -c */	    data->rebuild.bitmap_file_name = optarg;	    /*asprintf (&data->rebuild.bitmap_file_name, "%s", optarg);*/	    data->rebuild.scan_area = EXTERN_BITMAP;	    break;	case 'S': /* --scan-whole-partition */	    data->rebuild.scan_area = ALL_BLOCKS;	    break;#if 0	case 'J': /* take all blocks which are leaves in journal area and put                     them into tree item by item (DO NOT USE IT UNTIL YOU KNOW                     WHAT ARE YOU DOING) */	    data->rebuild.use_journal_area = 1;	    break;#endif	case 'd': /* --create-passes-dump */	    asprintf (&data->rebuild.passes_dump_file_name, "%s", optarg);	    data->options |= OPT_SAVE_PASSES_DUMP;	    break;		case 'z': /* --adjust-file-size */	    data->options |= OPT_ADJUST_FILE_SIZE;	    break;	case 'h': /* --hash: suppose that this hash was used on a filesystem */	    asprintf (&data->rebuild.defined_hash, "%s", optarg);	    if (name2func (data->rebuild.defined_hash) == 0)		reiserfs_panic ("reiserfsck: Unknown hash is specified: %s",				data->rebuild.defined_hash);	    data->options |= OPT_HASH_DEFINED;	    break;	case 'j': /* specified relocated journal device */	    data->journal_dev_name = optarg;	    break;	case 'R': /* preparing rollback data */	    asprintf (&data->rebuild.rollback_file, "%s", optarg);	    data->options |= OPT_SAVE_ROLLBACK;	    break;		case 'B': /* list of phisically corrupted blocks */	    asprintf (&badblocks_file, "%s", optarg);	    data->options |= BADBLOCKS_FILE;	    break;	case 'g': /* --background */	    data->options |= OPT_BACKGROUND;	    break;	case 'a':	case 'p':		data->options |= OPT_QUIET;		mode = FSCK_AUTO;		break;		case 'f':	case 'r': /* ignored */	    break;	    	case 'V': /* cause fsck to do nothing */	    mode = DO_NOTHING;	    break;		case 't':	    mode = DO_TEST;	    data->rebuild.test = atoi (optarg);	    break;	default:	    print_usage_and_exit();	}    }    if (optind != argc - 1 && mode != DO_NOTHING)	/* only one non-option argument is permitted */	print_usage_and_exit();    if (mode != FSCK_REBUILD &&                (data->rebuild.scan_area == EXTERN_BITMAP ||                data->rebuild.scan_area == ALL_BLOCKS ||                 data->options & OPT_SAVE_PASSES_DUMP))	/* wrong options for this mode */	print_usage_and_exit();/*    if (data->options & OPT_ADJUST_FILE_SIZE) {        if ((mode != FSCK_REBUILD) && (mode != FSCK_FIX_FIXABLE))             print_usage_and_exit();    }*/            if (data->options & OPT_SAVE_ROLLBACK) {        if (mode == FSCK_SB)            print_usage_and_exit();            }    if (mode == FSCK_ROLLBACK_CHANGES) {        if ((data->options & OPT_SAVE_ROLLBACK) == 0)            print_usage_and_exit();            }    if ((data->options & BADBLOCKS_FILE) && mode != FSCK_REBUILD && 	mode != FSCK_FIX_FIXABLE)    {	fprintf(stderr, "Badblocks can be specified with --fix-fixable or "		"--rebuild-tree only.\n");	print_usage_and_exit();    }    if ((mode == FSCK_REBUILD) && (data->options & OPT_YES))	data->options &= ~OPT_YES;        data->mode = mode;    if (!data->log)	data->log = stdout;       return argv[optind];}#define REBUILD_WARNING \"*************************************************************\n\** Do not  run  the  program  with  --rebuild-tree  unless **\n\** something is broken and MAKE A BACKUP  before using it. **\n\** If you have bad sectors on a drive  it is usually a bad **\n\** idea to continue using it. Then you probably should get **\n\** a working hard drive, copy the file system from the bad **\n\** drive  to the good one -- dd_rescue is  a good tool for **\n\** that -- and only then run this program.                 **\n\** If you are using the latest reiserfsprogs and  it fails **\n\** please  email bug reports to reiserfs-list@namesys.com, **\n\** providing  as  much  information  as  possible --  your **\n\** hardware,  kernel,  patches,  settings,  all reiserfsck **\n\** messages  (including version),  the reiserfsck logfile, **\n\** check  the  syslog file  for  any  related information. **\n\** If you would like advice on using this program, support **\n\** is available  for $25 at  www.namesys.com/support.html. **\n\*************************************************************\n\\nWill rebuild the filesystem (%s) tree\n"#define START_WARNING \"*************************************************************\n\** If you are using the latest reiserfsprogs and  it fails **\n\** please  email bug reports to reiserfs-list@namesys.com, **\n\** providing  as  much  information  as  possible --  your **\n\** hardware,  kernel,  patches,  settings,  all reiserfsck **\n\** messages  (including version),  the reiserfsck logfile, **\n\** check  the  syslog file  for  any  related information. **\n\** If you would like advice on using this program, support **\n\** is available  for $25 at  www.namesys.com/support.html. **\n\*************************************************************\n\\n"void warn_what_will_be_done (char * file_name, struct fsck_data * data){    FILE * warn_to;    warn_to = (data->progress ? data->progress : stderr);    if (data->mode == FSCK_REBUILD)	reiserfs_warning (warn_to, REBUILD_WARNING, file_name);    else	reiserfs_warning (warn_to, START_WARNING);        /* warn about fsck mode */    switch (data->mode) {    case FSCK_CHECK:	reiserfs_warning (warn_to, "Will read-only check consistency of the "	    "filesystem on %s\n", file_name);		break;    case FSCK_FIX_FIXABLE:        	reiserfs_warning (warn_to, "Will check consistency of the filesystem "	    "on %s\n", file_name);        reiserfs_warning (warn_to, "and will fix what can be fixed without "	    "--rebuild-tree\n");		break;    case FSCK_SB:	reiserfs_warning (warn_to, "Will check superblock and rebuild it if "	    "needed\n");		break;    case FSCK_REBUILD:	if (data->options & OPT_SAVE_PASSES_DUMP) {	    reiserfs_warning (warn_to, "Will run only 1 step of the rebuilding, "		"write state file '%s' and exit\n", 		data->rebuild.passes_dump_file_name);	} else if (data->options & OPT_INTERACTIVE)	    reiserfs_warning (warn_to, "Will stop after every stage and ask for "                "confirmation before continuing\n");	if (data->rebuild.bitmap_file_name)	    reiserfs_warning (warn_to, "Will try to load a bitmap--of all "		"ReiserFS leaves in the partition--from the file \n'%s'\n",		data->rebuild.bitmap_file_name);	if (data->options & OPT_ADJUST_FILE_SIZE)	    reiserfs_warning (warn_to, "\tWill set file sizes in their metadata "		"to real file sizes actually found by fsck.\n");	if (data->options & OPT_HASH_DEFINED)	    reiserfs_warning (warn_to, "\tSuppose \"%s\" hash is in use\n",		data->rebuild.defined_hash);		break;	    case FSCK_ROLLBACK_CHANGES:	reiserfs_warning (warn_to, "Will rollback all data saved in %s into %s\n",	    data->rebuild.rollback_file, file_name);	        break;    case FSCK_CLEAN_ATTRIBUTES:	reiserfs_warning (warn_to, "Will clean file attributes on %s\n", 	    file_name);        break;    case FSCK_AUTO:	return;    }    if (data->options & OPT_SAVE_ROLLBACK && data->mode != FSCK_ROLLBACK_CHANGES)        reiserfs_warning (warn_to, "Will save all blocks to be changed into "	    "file '%s'\n", data->rebuild.rollback_file);    if (data->options & BADBLOCKS_FILE)        reiserfs_warning (warn_to,            "Bad block list will contain only blocks specified in '%s' "	    "file\n", badblocks_file);    reiserfs_warning (warn_to, "Will put log info to '%s'\n", 	(data->log == stdout) ? "stdout" : 	(data->log_file_name ? data->log_file_name : "fsck.run"));        if (!(data->options & OPT_YES) && !user_confirmed (warn_to, "\nDo you want to "	"run this program?[N/Yes] (note need to type Yes if you do):", "Yes\n"))	exit (EXIT_USER);}static dma_info_t dma_info;static dma_info_t old_dma_info;void check_dma() {    old_dma_info = dma_info;    if (get_dma_info(&dma_info) == -1) {	fsck_log("get_dma_info failed %s\n", strerror (errno));	return;    }        if (dma_info.dma != old_dma_info.dma) {	if (dma_info.dma == 0) {	    printf("\n********************************************************************\n");	    printf("* Warning: It was just detected that dma mode was turned off while *\n");	    printf("* operating -- probably  due  to some  problem with your hardware. *\n");	    printf("* Please check your hardware and have a look into the syslog file. *\n");	    printf("* Note: running with --rebuild-tree on faulty hardware may destroy *\n");	    printf("* your data.                                                       *\n");	    printf("********************************************************************\n");	    if (fsck_log_file (fs) != stdout)		fsck_log("WARNING: dma mode has been turned off.\n");	}    }    if (dma_info.speed != old_dma_info.speed) {	if (dma_info.speed < old_dma_info.speed) {

⌨️ 快捷键说明

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