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

📄 xchkdsk.c

📁 在Linux内核从2.4升级到2.6时需要升级的软件包
💻 C
📖 第 1 页 / 共 5 页
字号:
/* *   Copyright (C) International Business Machines Corp., 2000-2004 * *   This program is free software;  you can redistribute it and/or modify *   it under the terms of the GNU General Public License as published by *   the Free Software Foundation; either version 2 of the License, or *   (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY;  without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See *   the GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program;  if not, write to the Free Software *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <config.h>#include <ctype.h>#include <getopt.h>#include <pwd.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>#include <sys/stat.h>/* defines and includes common among the jfs_fsck modules */#include "xfsckint.h"#include "xchkdsk.h"#include "fsck_message.h"	/* message text, all messages, in english */#include "jfs_byteorder.h"#include "jfs_unicode.h"#include "jfs_version.h"	/* version number and date for utils */#include "logform.h"#include "logredo.h"#include "message.h"#include "super.h"#include "utilsubs.h"int64_t ondev_jlog_byte_offset;/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * * superblock buffer and pointer * *    values are assigned by the xchkdsk routine */struct superblock aggr_superblock;struct superblock *sb_ptr;/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * * fsck aggregate info structure and pointer * *    values are assigned by the xchkdsk routine */struct fsck_agg_record agg_record;struct fsck_agg_record *agg_recptr;/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * * fsck block map info structure and pointer * *    values are assigned by the xchkdsk routine */struct fsck_bmap_record bmap_record;struct fsck_bmap_record *bmap_recptr;/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * * For message processing * *    values are assigned by the xchkdsk routine */char *Vol_Label;char *program_name;struct tm *fsck_DateTime = NULL;char time_stamp[20];/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * * For directory entry processing * */int32_t key_len[2];UniChar key[2][JFS_NAME_MAX];UniChar ukey[2][JFS_NAME_MAX];int32_t Uni_Name_len;UniChar Uni_Name[JFS_NAME_MAX];int32_t Str_Name_len;char Str_Name[JFS_NAME_MAX];/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * * Device information. * *     values are assigned when (if) the device is opened. */FILE *Dev_IOPort;uint32_t Dev_blksize;int32_t Dev_SectorSize;char log_device[512] = { 0 };/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * * Unicode path strings information. * *     values are assigned when the fsck aggregate record is initialized. *     accessed via addresses in the fack aggregate record. */UniChar uni_LSFN_NAME[11] =    { 'L', 'O', 'S', 'T', '+', 'F', 'O', 'U', 'N', 'D' };UniChar uni_lsfn_name[11] =    { 'l', 'o', 's', 't', '+', 'f', 'o', 'u', 'n', 'd' };/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * * fsckwsp error handling fields * *     values are assigned when the fsck workspace storage is *     allocated. */int wsp_dynstg_action;int wsp_dynstg_object;/* VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV * * The following are internal to this file * */int check_parents_and_first_refs(void);int create_lost_and_found(void);int final_processing(void);int initial_processing(int, char **);void parse_parms(int, char **);int phase0_processing(void);int phase1_processing(void);int phase2_processing(void);int phase3_processing(void);int phase4_processing(void);int phase5_processing(void);int phase6_processing(void);int phase7_processing(void);int phase8_processing(void);int phase9_processing(void);int repair_fs_inodes(void);int report_problems_setup_repairs(void);int resolve_lost_and_found(void);int validate_fs_inodes(void);int verify_parms(void);void ask_continue(void);void fsck_usage(void);/* VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV *//* exit value */int exit_value = FSCK_OK;/***************************************************************************** * NAME: main (jfs_fsck) * * FUNCTION: Entry point for jfs check/repair of aggregate * * INTERFACE: *            jfs_fsck <device name> * *                         [ -a ] *                         autocheck mode *                         replay the transaction log and quit fsck unless *                         aggregate state is dirty or log replay failed * *                         [ -f ] *                         force check *                         replay the tranaction log and force checking * *                         [ -j journal_device ] *                         specify the external journal device * *                         [ -n ] *                         read only check *                         report but do not repair problems * *                         [ --omit_journal_replay ] *                         omit replay of the transaction log * *                         [ -p ] *                         preen *                         same functionality as -a * *                         [ --replay_journal_only ] *                         only replay the transaction log * *                         [ -v ] *                         verbose messaging * *                         [ -V ] *                         version information *                         print version information and exit * * RETURNS: *      success:                   FSCK_OK (0) *      log successfully replayed: FSCK_CORRECTED (1) *      errors corrected:          FSCK_CORRECTED (1) *      errors uncorrected:        FSCK_ERRORS_UNCORRECTED (4) *      operational error:         FSCK_OP_ERROR (8) *      usage error:               FSCK_USAGE_ERROR (16) */int main(int argc, char **argv){	int rc = FSCK_OK;	time_t Current_Time;	/*	 * some basic initializations	 */	sb_ptr = &aggr_superblock;	agg_recptr = &agg_record;	bmap_recptr = &bmap_record;#ifdef _JFS_DEBUG	printf("sb_ptr = %p   agg_recptr = %p   bmap_recptr = %p\n", sb_ptr,	       agg_recptr, bmap_recptr);#endif	if (argc && **argv)		program_name = *argv;	else		program_name = "jfs_fsck";	printf("%s version %s, %s\n", program_name, VERSION, JFSUTILS_DATE);	wsp_dynstg_action = dynstg_unknown;	wsp_dynstg_object = dynstg_unknown;	/* init workspace aggregate record	 * (the parms will be recorded in it)	 */	rc = init_agg_record();	/*	 * Allocate the multi-purpose buffer now so that it can be	 * used during superblock verification.	 *	 * This must be done at least before calling logredo to ensure	 * that the malloc() will succeed.	 * (In autocheck mode, logredo is likely to eat up all the	 * low memory.  We don't want to use the alloc_wrksp routine	 * because we want a page boundary without having to burn	 * 4096 extra bytes.	 */	if ((rc = alloc_vlarge_buffer()) != FSCK_OK) {		/* alloc_vlarge_buffer not OK */		exit_value = FSCK_OP_ERROR;		goto main_exit;	}	if ((rc = initial_processing(argc, argv)) != FSCK_OK) {		/*		 * Something very wrong has happened.  We're not		 * even sure we're checking a JFS file system!		 * Appropriate messages should already be logged.		 */		/* initial_processing sets exit value if unsuccessful */		goto main_exit;	}	if (!agg_recptr->stdout_redirected) {		/* begin the "running" indicator */		fsck_hbeat_start();	}#ifdef CLEARBADBLOCK	/*	 * If they specified Clear Bad Blocks List only (aka /B),	 * release everything that's allocated, close everything	 * that's open, and then initiate the requested processing.	 */	if ((agg_recptr->parm_options[UFS_CHKDSK_CLRBDBLKLST])	    && (!agg_recptr->fsck_is_done)) {		/* bad block list processing only */		/*		 * this path is taken only when -f not specified, so		 * fsck processing is readonly, but the clrbblks		 * processing requires fsck to do some things it only		 * permits when processing readwrite.  So we reset the		 * switches temporarily and take care what routines we call.		 */		agg_recptr->processing_readwrite = 1;		agg_recptr->processing_readonly = 0;		/*		 * JFS Clear Bad Blocks List processing		 *		 * If things go well, this will issue messages and		 * write to the service log.		 */		rc = establish_wsp_block_map_ctl();		/*		 * terminate fsck service logging		 */		fscklog_end();		/*		 * restore the original values.		 */		agg_recptr->processing_readwrite = 0;		agg_recptr->processing_readonly = 1;		/*		 * release any workspace that has been allocated		 */		workspace_release();		/*		 * Close (Unlock) the device		 */		if (agg_recptr->device_is_open) {			close_volume();		}		/*		 * Then exit		 */		if (!agg_recptr->stdout_redirected) {			/* end the "running" indicator */			fsck_hbeat_stop();		}		return (rc);	}#endif	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase0_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	/*	 * If -n flag was specified, disable write processing now	 */	if (agg_recptr->parm_options[UFS_CHKDSK_LEVEL0]) {		agg_recptr->processing_readonly = 1;		agg_recptr->processing_readwrite = 0;	}	rc = phase1_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase2_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase3_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase4_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase5_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase6_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase7_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase8_processing();	if (agg_recptr->fsck_is_done)		goto phases_complete;	rc = phase9_processing();      phases_complete:	if (!agg_recptr->superblk_ok) {		/* superblock is bad */		exit_value = FSCK_ERRORS_UNCORRECTED;		goto close_vol;	}	/* we at least have a superblock */	if ((rc == FSCK_OK) && (!(agg_recptr->fsck_is_done))) {		/* not fleeing an error and not making a speedy exit */		/* finish up and display some information */		rc = final_processing();		/* flush the I/O buffers to complete any pending writes */		if (rc == FSCK_OK) {			rc = blkmap_flush();		} else {			blkmap_flush();		}		if (rc == FSCK_OK) {			rc = blktbl_dmaps_flush();		} else {			blktbl_dmaps_flush();		}		if (rc == FSCK_OK) {			rc = blktbl_Ln_pages_flush();		} else {			blktbl_Ln_pages_flush();		}		if (rc == FSCK_OK) {			rc = iags_flush();		} else {			iags_flush();		}		if (rc == FSCK_OK) {			rc = inodes_flush();		} else {			inodes_flush();		}		if (rc == FSCK_OK) {			rc = mapctl_flush();		} else {			mapctl_flush();		}		if (rc == FSCK_OK) {			rc = flush_index_pages();		} else {			flush_index_pages();		}	}	/*	 * last chance to write to the wsp block map control page...	 */	Current_Time = time(NULL);	fsck_DateTime = localtime(&Current_Time);	sprintf(time_stamp, "%d/%d/%d %d:%02d:%02d",		fsck_DateTime->tm_mon + 1,		fsck_DateTime->tm_mday, (fsck_DateTime->tm_year + 1900),		fsck_DateTime->tm_hour, fsck_DateTime->tm_min,		fsck_DateTime->tm_sec);	if (agg_recptr->processing_readwrite) {		/* on-device fsck workspace block map */		if (agg_recptr->blkmp_ctlptr != NULL) {			memcpy(&agg_recptr->blkmp_ctlptr->hdr.end_time[0],			       &time_stamp[0], 20);			agg_recptr->blkmp_ctlptr->hdr.return_code = rc;			blkmap_put_ctl_page(agg_recptr->blkmp_ctlptr);		}	}	if (rc == FSCK_OK) {		/* either all ok or nothing fatal */		if (agg_recptr->processing_readonly) {			/* remind the caller not to take			 * any messages issued too seriously			 */			fsck_send_msg(fsck_READONLY);			if (agg_recptr->corrections_needed ||			    agg_recptr->corrections_approved) {				fsck_send_msg(fsck_ERRORSDETECTED);				exit_value = FSCK_ERRORS_UNCORRECTED;

⌨️ 快捷键说明

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