1997-04-26 21:21:57 +08:00
|
|
|
/*
|
|
|
|
* pass1b.c --- Pass #1b of e2fsck
|
|
|
|
*
|
|
|
|
* This file contains pass1B, pass1C, and pass1D of e2fsck. They are
|
|
|
|
* only invoked if pass 1 discovered blocks which are in use by more
|
|
|
|
* than one inode.
|
2008-08-28 11:07:54 +08:00
|
|
|
*
|
1997-04-26 21:21:57 +08:00
|
|
|
* Pass1B scans the data blocks of all the inodes again, generating a
|
|
|
|
* complete list of duplicate blocks and which inodes have claimed
|
|
|
|
* them.
|
|
|
|
*
|
|
|
|
* Pass1C does a tree-traversal of the filesystem, to determine the
|
|
|
|
* parent directories of these inodes. This step is necessary so that
|
|
|
|
* e2fsck can print out the pathnames of affected inodes.
|
|
|
|
*
|
|
|
|
* Pass1D is a reconciliation pass. For each inode with duplicate
|
|
|
|
* blocks, the user is prompted if s/he would like to clone the file
|
|
|
|
* (so that the file gets a fresh copy of the duplicated blocks) or
|
|
|
|
* simply to delete the file.
|
2008-08-28 11:07:54 +08:00
|
|
|
*
|
1997-04-30 00:15:03 +08:00
|
|
|
* Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
2008-08-28 11:07:54 +08:00
|
|
|
*
|
1997-04-26 21:21:57 +08:00
|
|
|
*/
|
|
|
|
|
2011-09-19 05:34:37 +08:00
|
|
|
#include "config.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <time.h>
|
1997-04-26 21:58:21 +08:00
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2003-08-02 02:26:23 +08:00
|
|
|
#ifdef HAVE_INTTYPES_H
|
|
|
|
#include <inttypes.h>
|
|
|
|
#endif
|
|
|
|
|
2005-01-09 13:57:45 +08:00
|
|
|
#ifndef HAVE_INTPTR_T
|
2006-05-29 23:06:16 +08:00
|
|
|
typedef long intptr_t;
|
2005-01-09 13:57:45 +08:00
|
|
|
#endif
|
|
|
|
|
2003-08-02 02:26:23 +08:00
|
|
|
/* Needed for architectures where sizeof(int) != sizeof(void *) */
|
|
|
|
#define INT_TO_VOIDPTR(val) ((void *)(intptr_t)(val))
|
|
|
|
#define VOIDPTR_TO_INT(ptr) ((int)(intptr_t)(ptr))
|
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <et/com_err.h>
|
|
|
|
#include "e2fsck.h"
|
|
|
|
|
1997-04-30 00:15:03 +08:00
|
|
|
#include "problem.h"
|
2015-07-13 10:43:31 +08:00
|
|
|
#include "support/dict.h"
|
1997-04-30 00:15:03 +08:00
|
|
|
|
2001-07-02 23:54:09 +08:00
|
|
|
/* Define an extension to the ext2 library's block count information */
|
|
|
|
#define BLOCK_COUNT_EXTATTR (-5)
|
|
|
|
|
2011-07-10 10:56:22 +08:00
|
|
|
struct cluster_el {
|
|
|
|
blk64_t cluster;
|
|
|
|
struct cluster_el *next;
|
2002-08-02 00:37:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct inode_el {
|
|
|
|
ext2_ino_t inode;
|
|
|
|
struct inode_el *next;
|
|
|
|
};
|
|
|
|
|
2011-07-10 10:56:22 +08:00
|
|
|
struct dup_cluster {
|
1997-04-26 21:21:57 +08:00
|
|
|
int num_bad;
|
2002-08-02 00:37:00 +08:00
|
|
|
struct inode_el *inode_list;
|
1997-04-26 21:21:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure stores information about a particular inode which
|
|
|
|
* is sharing blocks with other inodes. This information is collected
|
|
|
|
* to display to the user, so that the user knows what files he or she
|
|
|
|
* is dealing with, when trying to decide how to resolve the conflict
|
|
|
|
* of multiply-claimed blocks.
|
|
|
|
*/
|
|
|
|
struct dup_inode {
|
2002-08-02 00:37:00 +08:00
|
|
|
ext2_ino_t dir;
|
1997-04-30 00:15:03 +08:00
|
|
|
int num_dupblocks;
|
2016-05-22 10:10:39 +08:00
|
|
|
struct ext2_inode_large inode;
|
2011-07-10 10:56:22 +08:00
|
|
|
struct cluster_el *cluster_list;
|
1997-04-26 21:21:57 +08:00
|
|
|
};
|
|
|
|
|
2009-09-08 10:29:45 +08:00
|
|
|
static int process_pass1b_block(ext2_filsys fs, blk64_t *blocknr,
|
|
|
|
e2_blkcnt_t blockcnt, blk64_t ref_blk,
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
int ref_offset, void *priv_data);
|
2002-08-02 00:37:00 +08:00
|
|
|
static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
|
|
|
|
struct dup_inode *dp, char *block_buf);
|
2013-12-03 10:37:10 +08:00
|
|
|
static errcode_t clone_file(e2fsck_t ctx, ext2_ino_t ino,
|
|
|
|
struct dup_inode *dp, char* block_buf);
|
2011-07-10 10:56:22 +08:00
|
|
|
static int check_if_fs_block(e2fsck_t ctx, blk64_t test_block);
|
|
|
|
static int check_if_fs_cluster(e2fsck_t ctx, blk64_t cluster);
|
2000-02-09 07:19:32 +08:00
|
|
|
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
static void pass1b(e2fsck_t ctx, char *block_buf);
|
|
|
|
static void pass1c(e2fsck_t ctx, char *block_buf);
|
|
|
|
static void pass1d(e2fsck_t ctx, char *block_buf);
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
static int dup_inode_count = 0;
|
2007-04-20 20:14:27 +08:00
|
|
|
static int dup_inode_founddir = 0;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2011-07-10 10:56:22 +08:00
|
|
|
static dict_t clstr_dict, ino_dict;
|
2002-08-02 00:37:00 +08:00
|
|
|
|
1997-04-26 21:34:30 +08:00
|
|
|
static ext2fs_inode_bitmap inode_dup_map;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2002-08-02 00:37:00 +08:00
|
|
|
static int dict_int_cmp(const void *a, const void *b)
|
|
|
|
{
|
2003-08-02 02:26:23 +08:00
|
|
|
intptr_t ia, ib;
|
2002-08-02 00:37:00 +08:00
|
|
|
|
2003-08-02 02:26:23 +08:00
|
|
|
ia = (intptr_t)a;
|
|
|
|
ib = (intptr_t)b;
|
2002-08-02 00:37:00 +08:00
|
|
|
|
|
|
|
return (ia-ib);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a duplicate block record
|
|
|
|
*/
|
2011-07-10 10:56:22 +08:00
|
|
|
static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk64_t cluster,
|
2016-05-22 10:10:39 +08:00
|
|
|
struct ext2_inode_large *inode)
|
2002-08-02 00:37:00 +08:00
|
|
|
{
|
|
|
|
dnode_t *n;
|
2011-07-10 10:56:22 +08:00
|
|
|
struct dup_cluster *db;
|
2002-08-02 00:37:00 +08:00
|
|
|
struct dup_inode *di;
|
2011-07-10 10:56:22 +08:00
|
|
|
struct cluster_el *cluster_el;
|
2002-08-02 00:37:00 +08:00
|
|
|
struct inode_el *ino_el;
|
|
|
|
|
2011-07-10 10:56:22 +08:00
|
|
|
n = dict_lookup(&clstr_dict, INT_TO_VOIDPTR(cluster));
|
2002-08-02 00:37:00 +08:00
|
|
|
if (n)
|
2011-07-10 10:56:22 +08:00
|
|
|
db = (struct dup_cluster *) dnode_get(n);
|
2002-08-02 00:37:00 +08:00
|
|
|
else {
|
2011-07-10 10:56:22 +08:00
|
|
|
db = (struct dup_cluster *) e2fsck_allocate_memory(ctx,
|
|
|
|
sizeof(struct dup_cluster), "duplicate cluster header");
|
2002-08-02 00:37:00 +08:00
|
|
|
db->num_bad = 0;
|
|
|
|
db->inode_list = 0;
|
2011-07-10 10:56:22 +08:00
|
|
|
dict_alloc_insert(&clstr_dict, INT_TO_VOIDPTR(cluster), db);
|
2002-08-02 00:37:00 +08:00
|
|
|
}
|
|
|
|
ino_el = (struct inode_el *) e2fsck_allocate_memory(ctx,
|
|
|
|
sizeof(struct inode_el), "inode element");
|
|
|
|
ino_el->inode = ino;
|
|
|
|
ino_el->next = db->inode_list;
|
|
|
|
db->inode_list = ino_el;
|
|
|
|
db->num_bad++;
|
|
|
|
|
2003-08-02 02:26:23 +08:00
|
|
|
n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino));
|
2002-08-02 00:37:00 +08:00
|
|
|
if (n)
|
|
|
|
di = (struct dup_inode *) dnode_get(n);
|
|
|
|
else {
|
|
|
|
di = (struct dup_inode *) e2fsck_allocate_memory(ctx,
|
|
|
|
sizeof(struct dup_inode), "duplicate inode header");
|
2007-04-20 20:14:27 +08:00
|
|
|
if (ino == EXT2_ROOT_INO) {
|
|
|
|
di->dir = EXT2_ROOT_INO;
|
|
|
|
dup_inode_founddir++;
|
|
|
|
} else
|
|
|
|
di->dir = 0;
|
|
|
|
|
2002-08-02 00:37:00 +08:00
|
|
|
di->num_dupblocks = 0;
|
2011-07-10 10:56:22 +08:00
|
|
|
di->cluster_list = 0;
|
2002-08-02 00:37:00 +08:00
|
|
|
di->inode = *inode;
|
2003-08-02 02:26:23 +08:00
|
|
|
dict_alloc_insert(&ino_dict, INT_TO_VOIDPTR(ino), di);
|
2002-08-02 00:37:00 +08:00
|
|
|
}
|
2011-07-10 10:56:22 +08:00
|
|
|
cluster_el = (struct cluster_el *) e2fsck_allocate_memory(ctx,
|
|
|
|
sizeof(struct cluster_el), "cluster element");
|
|
|
|
cluster_el->cluster = cluster;
|
|
|
|
cluster_el->next = di->cluster_list;
|
|
|
|
di->cluster_list = cluster_el;
|
2002-08-02 00:37:00 +08:00
|
|
|
di->num_dupblocks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free a duplicate inode record
|
|
|
|
*/
|
2008-08-28 11:07:54 +08:00
|
|
|
static void inode_dnode_free(dnode_t *node,
|
2003-12-07 14:28:50 +08:00
|
|
|
void *context EXT2FS_ATTR((unused)))
|
2002-08-02 00:37:00 +08:00
|
|
|
{
|
|
|
|
struct dup_inode *di;
|
2011-07-10 10:56:22 +08:00
|
|
|
struct cluster_el *p, *next;
|
2002-08-02 00:37:00 +08:00
|
|
|
|
|
|
|
di = (struct dup_inode *) dnode_get(node);
|
2011-07-10 10:56:22 +08:00
|
|
|
for (p = di->cluster_list; p; p = next) {
|
2002-08-02 00:37:00 +08:00
|
|
|
next = p->next;
|
|
|
|
free(p);
|
|
|
|
}
|
2009-06-15 15:50:07 +08:00
|
|
|
free(di);
|
2002-08-02 00:37:00 +08:00
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-07-10 10:56:22 +08:00
|
|
|
* Free a duplicate cluster record
|
2002-08-02 00:37:00 +08:00
|
|
|
*/
|
2011-07-10 10:56:22 +08:00
|
|
|
static void cluster_dnode_free(dnode_t *node,
|
|
|
|
void *context EXT2FS_ATTR((unused)))
|
2002-08-02 00:37:00 +08:00
|
|
|
{
|
2011-07-10 10:56:22 +08:00
|
|
|
struct dup_cluster *dc;
|
2002-08-02 00:37:00 +08:00
|
|
|
struct inode_el *p, *next;
|
|
|
|
|
2011-07-10 10:56:22 +08:00
|
|
|
dc = (struct dup_cluster *) dnode_get(node);
|
|
|
|
for (p = dc->inode_list; p; p = next) {
|
2002-08-02 00:37:00 +08:00
|
|
|
next = p->next;
|
|
|
|
free(p);
|
|
|
|
}
|
2011-07-10 10:56:22 +08:00
|
|
|
free(dc);
|
2002-08-02 00:37:00 +08:00
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
/*
|
|
|
|
* Main procedure for handling duplicate blocks
|
|
|
|
*/
|
1997-11-04 03:42:40 +08:00
|
|
|
void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ext2_filsys fs = ctx->fs;
|
|
|
|
struct problem_context pctx;
|
2009-05-05 11:12:30 +08:00
|
|
|
#ifdef RESOURCE_TRACK
|
|
|
|
struct resource_track rtrack;
|
|
|
|
#endif
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
|
|
|
|
clear_problem_context(&pctx);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2011-12-17 03:55:50 +08:00
|
|
|
pctx.errcode = e2fsck_allocate_inode_bitmap(fs,
|
|
|
|
_("multiply claimed inode map"),
|
|
|
|
EXT2FS_BMAP64_RBTREE, "inode_dup_map",
|
|
|
|
&inode_dup_map);
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
if (pctx.errcode) {
|
|
|
|
fix_problem(ctx, PR_1B_ALLOCATE_IBITMAP_ERROR, &pctx);
|
Many files:
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c: Add calls to the progress
indicator function.
pass1.c (scan_callback): Add call to the progress feedback function
(if it exists).
super.c (check_super_block): Skip the device size check if the
get_device_size returns EXT2_EXT_UNIMPLEMENTED.
iscan.c (main): Don't use fatal_error() anymore.
pass1b.c, swapfs.c, badblocks.c: Set E2F_FLAG_ABORT instead of calling
fatal_error(0).
problem.c, pass3.c (PR_3_ROOT_NOT_DIR_ABORT,
PR_3_NO_ROOT_INODE_ABORT): New problem codes.
problem.c, pass2.c (PR_2_SPLIT_DOT): New problem code.
problem.c, pass1.c (PR_1_SUPPRESS_MESSAGES): New problem code.
problemP.h: New file which separates out the private fix_problem data
structures.
util.c, dirinfo.c, pass1.c, pass1b.c, pass2.c, pass5.c, super.c,
swapfs.c util.c: allocate_memory() now takes a e2fsck context as its
first argument, and rename it to be e2fsck_allocate_memory().
problemP.h:
New file which contains the private problem abstraction definitions.
Makefile.pq:
Remove include of MAKEFILE.STD, which doesn't exist at this point.
1997-11-14 13:23:04 +08:00
|
|
|
ctx->flags |= E2F_FLAG_ABORT;
|
|
|
|
return;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
2002-08-02 00:37:00 +08:00
|
|
|
|
|
|
|
dict_init(&ino_dict, DICTCOUNT_T_MAX, dict_int_cmp);
|
2011-07-10 10:56:22 +08:00
|
|
|
dict_init(&clstr_dict, DICTCOUNT_T_MAX, dict_int_cmp);
|
2002-08-02 00:37:00 +08:00
|
|
|
dict_set_allocator(&ino_dict, NULL, inode_dnode_free, NULL);
|
2011-07-10 10:56:22 +08:00
|
|
|
dict_set_allocator(&clstr_dict, NULL, cluster_dnode_free, NULL);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2009-05-05 11:12:30 +08:00
|
|
|
init_resource_track(&rtrack, ctx->fs->io);
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
pass1b(ctx, block_buf);
|
2009-05-28 21:55:10 +08:00
|
|
|
print_resource_track(ctx, "Pass 1b", &rtrack, ctx->fs->io);
|
2009-05-05 11:12:30 +08:00
|
|
|
|
|
|
|
init_resource_track(&rtrack, ctx->fs->io);
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
pass1c(ctx, block_buf);
|
2009-05-28 21:55:10 +08:00
|
|
|
print_resource_track(ctx, "Pass 1c", &rtrack, ctx->fs->io);
|
2009-05-05 11:12:30 +08:00
|
|
|
|
|
|
|
init_resource_track(&rtrack, ctx->fs->io);
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
pass1d(ctx, block_buf);
|
2009-05-28 21:55:10 +08:00
|
|
|
print_resource_track(ctx, "Pass 1d", &rtrack, ctx->fs->io);
|
2009-05-05 11:12:30 +08:00
|
|
|
|
2018-03-06 04:52:13 +08:00
|
|
|
if (ext2fs_has_feature_shared_blocks(ctx->fs->super) &&
|
|
|
|
(ctx->options & E2F_OPT_UNSHARE_BLOCKS)) {
|
|
|
|
/*
|
|
|
|
* If we successfully managed to unshare all blocks, unset the
|
|
|
|
* shared block feature.
|
|
|
|
*/
|
|
|
|
blk64_t next;
|
|
|
|
int result = ext2fs_find_first_set_block_bitmap2(
|
|
|
|
ctx->block_dup_map,
|
|
|
|
ctx->fs->super->s_first_data_block,
|
|
|
|
ext2fs_blocks_count(ctx->fs->super) - 1,
|
|
|
|
&next);
|
2018-04-28 07:10:29 +08:00
|
|
|
if (result == ENOENT && !(ctx->options & E2F_OPT_NO)) {
|
2018-03-06 04:52:13 +08:00
|
|
|
ext2fs_clear_feature_shared_blocks(ctx->fs->super);
|
|
|
|
ext2fs_mark_super_dirty(ctx->fs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
/*
|
|
|
|
* Time to free all of the accumulated data structures that we
|
|
|
|
* don't need anymore.
|
|
|
|
*/
|
2002-08-02 00:37:00 +08:00
|
|
|
dict_free_nodes(&ino_dict);
|
2011-07-10 10:56:22 +08:00
|
|
|
dict_free_nodes(&clstr_dict);
|
2009-06-15 15:50:07 +08:00
|
|
|
ext2fs_free_inode_bitmap(inode_dup_map);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the inodes looking for inodes that contain duplicate blocks.
|
|
|
|
*/
|
|
|
|
struct process_block_struct {
|
2002-08-02 00:37:00 +08:00
|
|
|
e2fsck_t ctx;
|
Many files:
dirinfo.c, e2fsck.h, emptydir.c, iscan.c, jfs_user.h, journal.c,
message.c, pass1.c, pass1b.c, pass2.c, pass3.c, pass4.c, pass5.c,
problem.h, scantest.c, super.c, swapfs.c: Change ino_t to ext2_ino_t.
2001-01-11 23:12:14 +08:00
|
|
|
ext2_ino_t ino;
|
|
|
|
int dup_blocks;
|
2014-07-26 08:34:04 +08:00
|
|
|
blk64_t cur_cluster, phys_cluster;
|
2014-03-16 00:12:35 +08:00
|
|
|
blk64_t last_blk;
|
2016-05-22 10:10:39 +08:00
|
|
|
struct ext2_inode_large *inode;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
struct problem_context *pctx;
|
1997-04-26 21:21:57 +08:00
|
|
|
};
|
|
|
|
|
1997-11-04 03:42:40 +08:00
|
|
|
static void pass1b(e2fsck_t ctx, char *block_buf)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ext2_filsys fs = ctx->fs;
|
2011-12-17 04:36:40 +08:00
|
|
|
ext2_ino_t ino = 0;
|
2016-05-22 10:10:39 +08:00
|
|
|
struct ext2_inode_large inode;
|
1997-04-26 21:21:57 +08:00
|
|
|
ext2_inode_scan scan;
|
|
|
|
struct process_block_struct pb;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
struct problem_context pctx;
|
2014-03-16 00:12:35 +08:00
|
|
|
problem_t op;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
clear_problem_context(&pctx);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2004-02-23 04:41:11 +08:00
|
|
|
if (!(ctx->options & E2F_OPT_PREEN))
|
|
|
|
fix_problem(ctx, PR_1B_PASS_HEADER, &pctx);
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
pctx.errcode = ext2fs_open_inode_scan(fs, ctx->inode_buffer_blocks,
|
|
|
|
&scan);
|
|
|
|
if (pctx.errcode) {
|
|
|
|
fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
|
Many files:
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c: Add calls to the progress
indicator function.
pass1.c (scan_callback): Add call to the progress feedback function
(if it exists).
super.c (check_super_block): Skip the device size check if the
get_device_size returns EXT2_EXT_UNIMPLEMENTED.
iscan.c (main): Don't use fatal_error() anymore.
pass1b.c, swapfs.c, badblocks.c: Set E2F_FLAG_ABORT instead of calling
fatal_error(0).
problem.c, pass3.c (PR_3_ROOT_NOT_DIR_ABORT,
PR_3_NO_ROOT_INODE_ABORT): New problem codes.
problem.c, pass2.c (PR_2_SPLIT_DOT): New problem code.
problem.c, pass1.c (PR_1_SUPPRESS_MESSAGES): New problem code.
problemP.h: New file which separates out the private fix_problem data
structures.
util.c, dirinfo.c, pass1.c, pass1b.c, pass2.c, pass5.c, super.c,
swapfs.c util.c: allocate_memory() now takes a e2fsck context as its
first argument, and rename it to be e2fsck_allocate_memory().
problemP.h:
New file which contains the private problem abstraction definitions.
Makefile.pq:
Remove include of MAKEFILE.STD, which doesn't exist at this point.
1997-11-14 13:23:04 +08:00
|
|
|
ctx->flags |= E2F_FLAG_ABORT;
|
|
|
|
return;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
2016-05-22 10:10:39 +08:00
|
|
|
ctx->stashed_inode = EXT2_INODE(&inode);
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
pb.ctx = ctx;
|
|
|
|
pb.pctx = &pctx;
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
pctx.str = "pass1b";
|
2002-10-03 13:09:35 +08:00
|
|
|
while (1) {
|
2011-09-25 01:48:55 +08:00
|
|
|
if (ino % (fs->super->s_inodes_per_group * 4) == 1) {
|
|
|
|
if (e2fsck_mmp_update(fs))
|
|
|
|
fatal_error(ctx, 0);
|
|
|
|
}
|
2016-05-22 10:10:39 +08:00
|
|
|
pctx.errcode = ext2fs_get_next_inode_full(scan, &ino,
|
|
|
|
EXT2_INODE(&inode), sizeof(inode));
|
2002-10-03 13:09:35 +08:00
|
|
|
if (pctx.errcode == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE)
|
|
|
|
continue;
|
|
|
|
if (pctx.errcode) {
|
2014-07-23 01:52:33 +08:00
|
|
|
pctx.ino = ino;
|
2002-10-03 13:09:35 +08:00
|
|
|
fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
|
|
|
|
ctx->flags |= E2F_FLAG_ABORT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!ino)
|
|
|
|
break;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
pctx.ino = ctx->stashed_ino = ino;
|
1997-04-26 21:21:57 +08:00
|
|
|
if ((ino != EXT2_BAD_INO) &&
|
2009-08-23 10:29:02 +08:00
|
|
|
!ext2fs_test_inode_bitmap2(ctx->inode_used_map, ino))
|
2002-10-03 13:09:35 +08:00
|
|
|
continue;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
pb.ino = ino;
|
|
|
|
pb.dup_blocks = 0;
|
2002-08-02 00:37:00 +08:00
|
|
|
pb.inode = &inode;
|
2011-11-29 00:00:48 +08:00
|
|
|
pb.cur_cluster = ~0;
|
2014-07-26 08:34:04 +08:00
|
|
|
pb.phys_cluster = ~0;
|
2014-03-16 00:12:35 +08:00
|
|
|
pb.last_blk = 0;
|
|
|
|
pb.pctx->blk = pb.pctx->blk2 = 0;
|
2002-08-17 22:19:44 +08:00
|
|
|
|
2016-05-22 10:10:39 +08:00
|
|
|
if (ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(&inode)) ||
|
2002-08-17 22:19:44 +08:00
|
|
|
(ino == EXT2_BAD_INO))
|
2009-09-08 10:29:45 +08:00
|
|
|
pctx.errcode = ext2fs_block_iterate3(fs, ino,
|
2007-08-21 09:31:11 +08:00
|
|
|
BLOCK_FLAG_READ_ONLY, block_buf,
|
|
|
|
process_pass1b_block, &pb);
|
2011-06-01 07:59:56 +08:00
|
|
|
/* If the feature is not set, attrs will be cleared later anyway */
|
2015-10-24 12:43:19 +08:00
|
|
|
if (ext2fs_has_feature_xattr(fs->super) &&
|
2016-05-22 10:10:39 +08:00
|
|
|
ext2fs_file_acl_block(fs, EXT2_INODE(&inode))) {
|
|
|
|
blk64_t blk = ext2fs_file_acl_block(fs, EXT2_INODE(&inode));
|
2009-09-08 10:29:45 +08:00
|
|
|
process_pass1b_block(fs, &blk,
|
2001-07-02 23:54:09 +08:00
|
|
|
BLOCK_COUNT_EXTATTR, 0, 0, &pb);
|
2016-05-22 10:10:39 +08:00
|
|
|
ext2fs_file_acl_block_set(fs, EXT2_INODE(&inode), blk);
|
2011-06-01 07:59:56 +08:00
|
|
|
}
|
1997-04-26 21:21:57 +08:00
|
|
|
if (pb.dup_blocks) {
|
2014-03-16 00:12:35 +08:00
|
|
|
if (ino != EXT2_BAD_INO) {
|
|
|
|
op = pctx.blk == pctx.blk2 ?
|
|
|
|
PR_1B_DUP_BLOCK : PR_1B_DUP_RANGE;
|
|
|
|
fix_problem(ctx, op, pb.pctx);
|
|
|
|
}
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
end_problem_latch(ctx, PR_LATCH_DBLOCK);
|
2002-08-02 00:37:00 +08:00
|
|
|
if (ino >= EXT2_FIRST_INODE(fs->super) ||
|
|
|
|
ino == EXT2_ROOT_INO)
|
1997-04-26 21:21:57 +08:00
|
|
|
dup_inode_count++;
|
|
|
|
}
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
if (pctx.errcode)
|
|
|
|
fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
ext2fs_close_inode_scan(scan);
|
2001-06-02 03:29:36 +08:00
|
|
|
e2fsck_use_inode_shortcuts(ctx, 0);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
2003-12-07 14:28:50 +08:00
|
|
|
static int process_pass1b_block(ext2_filsys fs EXT2FS_ATTR((unused)),
|
2009-09-08 10:29:45 +08:00
|
|
|
blk64_t *block_nr,
|
2011-11-29 00:00:48 +08:00
|
|
|
e2_blkcnt_t blockcnt,
|
2009-09-08 10:29:45 +08:00
|
|
|
blk64_t ref_blk EXT2FS_ATTR((unused)),
|
2003-12-07 14:28:50 +08:00
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
2001-01-06 13:55:58 +08:00
|
|
|
void *priv_data)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
|
|
|
struct process_block_struct *p;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
e2fsck_t ctx;
|
2014-07-26 08:34:04 +08:00
|
|
|
blk64_t lc, pc;
|
2014-03-16 00:12:35 +08:00
|
|
|
problem_t op;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2015-04-12 20:22:07 +08:00
|
|
|
if (*block_nr == 0)
|
1997-04-26 21:21:57 +08:00
|
|
|
return 0;
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
p = (struct process_block_struct *) priv_data;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ctx = p->ctx;
|
2011-11-29 00:00:48 +08:00
|
|
|
lc = EXT2FS_B2C(fs, blockcnt);
|
2014-07-26 08:34:04 +08:00
|
|
|
pc = EXT2FS_B2C(fs, *block_nr);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2009-08-23 10:29:02 +08:00
|
|
|
if (!ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr))
|
2011-11-29 00:00:48 +08:00
|
|
|
goto finish;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2002-08-02 00:37:00 +08:00
|
|
|
/* OK, this is a duplicate block */
|
|
|
|
if (p->ino != EXT2_BAD_INO) {
|
2014-03-16 00:12:35 +08:00
|
|
|
if (p->last_blk + 1 != *block_nr) {
|
|
|
|
if (p->last_blk) {
|
|
|
|
op = p->pctx->blk == p->pctx->blk2 ?
|
|
|
|
PR_1B_DUP_BLOCK :
|
|
|
|
PR_1B_DUP_RANGE;
|
|
|
|
fix_problem(ctx, op, p->pctx);
|
|
|
|
}
|
|
|
|
p->pctx->blk = *block_nr;
|
|
|
|
}
|
|
|
|
p->pctx->blk2 = *block_nr;
|
|
|
|
p->last_blk = *block_nr;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
2002-08-02 00:37:00 +08:00
|
|
|
p->dup_blocks++;
|
2009-08-23 10:29:02 +08:00
|
|
|
ext2fs_mark_inode_bitmap2(inode_dup_map, p->ino);
|
2002-08-02 00:37:00 +08:00
|
|
|
|
2014-07-26 08:34:04 +08:00
|
|
|
/*
|
|
|
|
* Qualifications for submitting a block for duplicate processing:
|
|
|
|
* It's an extent/indirect block (and has a negative logical offset);
|
|
|
|
* we've crossed a logical cluster boundary; or the physical cluster
|
|
|
|
* suddenly changed, which indicates that blocks in a logical cluster
|
|
|
|
* are mapped to multiple physical clusters.
|
|
|
|
*/
|
|
|
|
if (blockcnt < 0 || lc != p->cur_cluster || pc != p->phys_cluster)
|
2011-11-29 00:00:48 +08:00
|
|
|
add_dupe(ctx, p->ino, EXT2FS_B2C(fs, *block_nr), p->inode);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2011-11-29 00:00:48 +08:00
|
|
|
finish:
|
|
|
|
p->cur_cluster = lc;
|
2014-07-26 08:34:04 +08:00
|
|
|
p->phys_cluster = pc;
|
1997-04-26 21:21:57 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass 1c: Scan directories for inodes with duplicate blocks. This
|
|
|
|
* is used so that we can print pathnames when prompting the user for
|
|
|
|
* what to do.
|
|
|
|
*/
|
1997-04-30 00:15:03 +08:00
|
|
|
struct search_dir_struct {
|
1997-04-26 21:21:57 +08:00
|
|
|
int count;
|
Many files:
dirinfo.c, e2fsck.h, emptydir.c, iscan.c, jfs_user.h, journal.c,
message.c, pass1.c, pass1b.c, pass2.c, pass3.c, pass4.c, pass5.c,
problem.h, scantest.c, super.c, swapfs.c: Change ino_t to ext2_ino_t.
2001-01-11 23:12:14 +08:00
|
|
|
ext2_ino_t first_inode;
|
|
|
|
ext2_ino_t max_inode;
|
1997-04-26 21:21:57 +08:00
|
|
|
};
|
|
|
|
|
Many files:
dirinfo.c, e2fsck.h, emptydir.c, iscan.c, jfs_user.h, journal.c,
message.c, pass1.c, pass1b.c, pass2.c, pass3.c, pass4.c, pass5.c,
problem.h, scantest.c, super.c, swapfs.c: Change ino_t to ext2_ino_t.
2001-01-11 23:12:14 +08:00
|
|
|
static int search_dirent_proc(ext2_ino_t dir, int entry,
|
1997-04-30 00:15:03 +08:00
|
|
|
struct ext2_dir_entry *dirent,
|
2008-08-28 11:07:54 +08:00
|
|
|
int offset EXT2FS_ATTR((unused)),
|
2003-12-07 14:28:50 +08:00
|
|
|
int blocksize EXT2FS_ATTR((unused)),
|
2008-08-28 11:07:54 +08:00
|
|
|
char *buf EXT2FS_ATTR((unused)),
|
2003-12-07 14:28:50 +08:00
|
|
|
void *priv_data)
|
1997-04-30 00:15:03 +08:00
|
|
|
{
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
struct search_dir_struct *sd;
|
1997-04-30 00:15:03 +08:00
|
|
|
struct dup_inode *p;
|
2002-08-02 00:37:00 +08:00
|
|
|
dnode_t *n;
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
|
|
|
|
sd = (struct search_dir_struct *) priv_data;
|
|
|
|
|
1997-04-30 01:48:10 +08:00
|
|
|
if (dirent->inode > sd->max_inode)
|
|
|
|
/* Should abort this inode, but not everything */
|
2008-08-28 11:07:54 +08:00
|
|
|
return 0;
|
1997-04-30 01:48:10 +08:00
|
|
|
|
2002-08-02 00:37:00 +08:00
|
|
|
if ((dirent->inode < sd->first_inode) || (entry < DIRENT_OTHER_FILE) ||
|
2009-08-23 10:29:02 +08:00
|
|
|
!ext2fs_test_inode_bitmap2(inode_dup_map, dirent->inode))
|
1997-04-30 00:15:03 +08:00
|
|
|
return 0;
|
|
|
|
|
2003-08-02 02:26:23 +08:00
|
|
|
n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(dirent->inode));
|
2002-08-02 00:37:00 +08:00
|
|
|
if (!n)
|
1997-04-30 00:15:03 +08:00
|
|
|
return 0;
|
2002-08-02 00:37:00 +08:00
|
|
|
p = (struct dup_inode *) dnode_get(n);
|
2007-04-11 10:55:09 +08:00
|
|
|
if (!p->dir) {
|
|
|
|
p->dir = dir;
|
|
|
|
sd->count--;
|
|
|
|
}
|
1997-04-30 00:15:03 +08:00
|
|
|
|
|
|
|
return(sd->count ? 0 : DIRENT_ABORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-04 03:42:40 +08:00
|
|
|
static void pass1c(e2fsck_t ctx, char *block_buf)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ext2_filsys fs = ctx->fs;
|
1997-04-30 00:15:03 +08:00
|
|
|
struct search_dir_struct sd;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
struct problem_context pctx;
|
|
|
|
|
|
|
|
clear_problem_context(&pctx);
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2004-02-23 04:41:11 +08:00
|
|
|
if (!(ctx->options & E2F_OPT_PREEN))
|
|
|
|
fix_problem(ctx, PR_1C_PASS_HEADER, &pctx);
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Search through all directories to translate inodes to names
|
|
|
|
* (by searching for the containing directory for that inode.)
|
|
|
|
*/
|
2007-04-20 20:14:27 +08:00
|
|
|
sd.count = dup_inode_count - dup_inode_founddir;
|
1997-04-30 00:15:03 +08:00
|
|
|
sd.first_inode = EXT2_FIRST_INODE(fs->super);
|
1997-04-30 01:48:10 +08:00
|
|
|
sd.max_inode = fs->super->s_inodes_count;
|
1997-04-30 00:15:03 +08:00
|
|
|
ext2fs_dblist_dir_iterate(fs->dblist, 0, block_buf,
|
|
|
|
search_dirent_proc, &sd);
|
2008-08-28 11:07:54 +08:00
|
|
|
}
|
1997-04-26 21:21:57 +08:00
|
|
|
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
static void pass1d(e2fsck_t ctx, char *block_buf)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ext2_filsys fs = ctx->fs;
|
2002-08-02 00:37:00 +08:00
|
|
|
struct dup_inode *p, *t;
|
2011-07-10 10:56:22 +08:00
|
|
|
struct dup_cluster *q;
|
2002-08-02 00:37:00 +08:00
|
|
|
ext2_ino_t *shared, ino;
|
1997-04-26 21:21:57 +08:00
|
|
|
int shared_len;
|
|
|
|
int i;
|
|
|
|
int file_ok;
|
1997-04-30 01:48:10 +08:00
|
|
|
int meta_data = 0;
|
1997-04-30 00:15:03 +08:00
|
|
|
struct problem_context pctx;
|
2002-08-02 00:37:00 +08:00
|
|
|
dnode_t *n, *m;
|
2011-07-10 10:56:22 +08:00
|
|
|
struct cluster_el *s;
|
2002-08-02 00:37:00 +08:00
|
|
|
struct inode_el *r;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
clear_problem_context(&pctx);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2004-02-23 04:41:11 +08:00
|
|
|
if (!(ctx->options & E2F_OPT_PREEN))
|
|
|
|
fix_problem(ctx, PR_1D_PASS_HEADER, &pctx);
|
Many files:
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c: Add calls to the progress
indicator function.
pass1.c (scan_callback): Add call to the progress feedback function
(if it exists).
super.c (check_super_block): Skip the device size check if the
get_device_size returns EXT2_EXT_UNIMPLEMENTED.
iscan.c (main): Don't use fatal_error() anymore.
pass1b.c, swapfs.c, badblocks.c: Set E2F_FLAG_ABORT instead of calling
fatal_error(0).
problem.c, pass3.c (PR_3_ROOT_NOT_DIR_ABORT,
PR_3_NO_ROOT_INODE_ABORT): New problem codes.
problem.c, pass2.c (PR_2_SPLIT_DOT): New problem code.
problem.c, pass1.c (PR_1_SUPPRESS_MESSAGES): New problem code.
problemP.h: New file which separates out the private fix_problem data
structures.
util.c, dirinfo.c, pass1.c, pass1b.c, pass2.c, pass5.c, super.c,
swapfs.c util.c: allocate_memory() now takes a e2fsck context as its
first argument, and rename it to be e2fsck_allocate_memory().
problemP.h:
New file which contains the private problem abstraction definitions.
Makefile.pq:
Remove include of MAKEFILE.STD, which doesn't exist at this point.
1997-11-14 13:23:04 +08:00
|
|
|
e2fsck_read_bitmaps(ctx);
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2002-08-02 00:37:00 +08:00
|
|
|
pctx.num = dup_inode_count; /* dict_count(&ino_dict); */
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
fix_problem(ctx, PR_1D_NUM_DUP_INODES, &pctx);
|
Many files:
dirinfo.c, e2fsck.h, emptydir.c, iscan.c, jfs_user.h, journal.c,
message.c, pass1.c, pass1b.c, pass2.c, pass3.c, pass4.c, pass5.c,
problem.h, scantest.c, super.c, swapfs.c: Change ino_t to ext2_ino_t.
2001-01-11 23:12:14 +08:00
|
|
|
shared = (ext2_ino_t *) e2fsck_allocate_memory(ctx,
|
2002-08-02 00:37:00 +08:00
|
|
|
sizeof(ext2_ino_t) * dict_count(&ino_dict),
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
"Shared inode list");
|
2002-08-02 00:37:00 +08:00
|
|
|
for (n = dict_first(&ino_dict); n; n = dict_next(&ino_dict, n)) {
|
|
|
|
p = (struct dup_inode *) dnode_get(n);
|
1997-04-26 21:21:57 +08:00
|
|
|
shared_len = 0;
|
|
|
|
file_ok = 1;
|
2003-08-02 02:26:23 +08:00
|
|
|
ino = (ext2_ino_t)VOIDPTR_TO_INT(dnode_getkey(n));
|
2005-04-15 05:10:14 +08:00
|
|
|
if (ino == EXT2_BAD_INO || ino == EXT2_RESIZE_INO)
|
1997-04-26 21:21:57 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
2002-08-02 00:37:00 +08:00
|
|
|
* Find all of the inodes which share blocks with this
|
|
|
|
* one. First we find all of the duplicate blocks
|
|
|
|
* belonging to this inode, and then search each block
|
|
|
|
* get the list of inodes, and merge them together.
|
1997-04-26 21:21:57 +08:00
|
|
|
*/
|
2011-07-10 10:56:22 +08:00
|
|
|
for (s = p->cluster_list; s; s = s->next) {
|
|
|
|
m = dict_lookup(&clstr_dict,
|
|
|
|
INT_TO_VOIDPTR(s->cluster));
|
2002-08-02 00:37:00 +08:00
|
|
|
if (!m)
|
|
|
|
continue; /* Should never happen... */
|
2011-07-10 10:56:22 +08:00
|
|
|
q = (struct dup_cluster *) dnode_get(m);
|
1997-04-26 21:21:57 +08:00
|
|
|
if (q->num_bad > 1)
|
|
|
|
file_ok = 0;
|
2011-07-10 10:56:22 +08:00
|
|
|
if (check_if_fs_cluster(ctx, s->cluster)) {
|
1997-04-30 01:48:10 +08:00
|
|
|
file_ok = 0;
|
|
|
|
meta_data = 1;
|
|
|
|
}
|
2008-08-28 11:07:54 +08:00
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
/*
|
|
|
|
* Add all inodes used by this block to the
|
|
|
|
* shared[] --- which is a unique list, so
|
|
|
|
* if an inode is already in shared[], don't
|
|
|
|
* add it again.
|
|
|
|
*/
|
2002-08-02 00:37:00 +08:00
|
|
|
for (r = q->inode_list; r; r = r->next) {
|
|
|
|
if (r->inode == ino)
|
1997-04-26 21:21:57 +08:00
|
|
|
continue;
|
|
|
|
for (i = 0; i < shared_len; i++)
|
2002-08-02 00:37:00 +08:00
|
|
|
if (shared[i] == r->inode)
|
1997-04-26 21:21:57 +08:00
|
|
|
break;
|
|
|
|
if (i == shared_len) {
|
2002-08-02 00:37:00 +08:00
|
|
|
shared[shared_len++] = r->inode;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1997-04-30 00:15:03 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Report the inode that we are working on
|
|
|
|
*/
|
2016-05-22 10:10:39 +08:00
|
|
|
pctx.inode = EXT2_INODE(&p->inode);
|
2002-08-02 00:37:00 +08:00
|
|
|
pctx.ino = ino;
|
1997-04-30 00:15:03 +08:00
|
|
|
pctx.dir = p->dir;
|
|
|
|
pctx.blkcount = p->num_dupblocks;
|
1997-04-30 01:48:10 +08:00
|
|
|
pctx.num = meta_data ? shared_len+1 : shared_len;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
fix_problem(ctx, PR_1D_DUP_FILE, &pctx);
|
1997-04-30 00:15:03 +08:00
|
|
|
pctx.blkcount = 0;
|
|
|
|
pctx.num = 0;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
1997-04-30 01:48:10 +08:00
|
|
|
if (meta_data)
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
fix_problem(ctx, PR_1D_SHARE_METADATA, &pctx);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
for (i = 0; i < shared_len; i++) {
|
2003-08-02 02:26:23 +08:00
|
|
|
m = dict_lookup(&ino_dict, INT_TO_VOIDPTR(shared[i]));
|
2002-08-02 00:37:00 +08:00
|
|
|
if (!m)
|
|
|
|
continue; /* should never happen */
|
|
|
|
t = (struct dup_inode *) dnode_get(m);
|
1997-04-30 00:15:03 +08:00
|
|
|
/*
|
|
|
|
* Report the inode that we are sharing with
|
|
|
|
*/
|
2016-05-22 10:10:39 +08:00
|
|
|
pctx.inode = EXT2_INODE(&t->inode);
|
2002-08-02 00:37:00 +08:00
|
|
|
pctx.ino = shared[i];
|
|
|
|
pctx.dir = t->dir;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
fix_problem(ctx, PR_1D_DUP_FILE_LIST, &pctx);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
2014-07-26 08:34:04 +08:00
|
|
|
/*
|
|
|
|
* Even if the file shares blocks with itself, we still need to
|
|
|
|
* clone the blocks.
|
|
|
|
*/
|
|
|
|
if (file_ok && (meta_data ? shared_len+1 : shared_len) != 0) {
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
fix_problem(ctx, PR_1D_DUP_BLOCKS_DEALT, &pctx);
|
1997-04-26 21:21:57 +08:00
|
|
|
continue;
|
|
|
|
}
|
2018-03-06 04:52:13 +08:00
|
|
|
if ((ctx->options & E2F_OPT_UNSHARE_BLOCKS) ||
|
|
|
|
fix_problem(ctx, PR_1D_CLONE_QUESTION, &pctx)) {
|
2002-08-02 00:37:00 +08:00
|
|
|
pctx.errcode = clone_file(ctx, ino, p, block_buf);
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
if (pctx.errcode)
|
|
|
|
fix_problem(ctx, PR_1D_CLONE_ERROR, &pctx);
|
|
|
|
else
|
1997-04-26 21:21:57 +08:00
|
|
|
continue;
|
|
|
|
}
|
2018-03-06 04:52:13 +08:00
|
|
|
/*
|
|
|
|
* Note: When unsharing blocks, we don't prompt to delete
|
|
|
|
* files. If the clone operation fails than the unshare
|
|
|
|
* operation should fail too.
|
|
|
|
*/
|
|
|
|
if (!(ctx->options & E2F_OPT_UNSHARE_BLOCKS) &&
|
|
|
|
fix_problem(ctx, PR_1D_DELETE_QUESTION, &pctx))
|
2002-08-02 00:37:00 +08:00
|
|
|
delete_file(ctx, ino, p, block_buf);
|
1997-04-26 21:21:57 +08:00
|
|
|
else
|
|
|
|
ext2fs_unmark_valid(fs);
|
|
|
|
}
|
2003-08-01 21:41:07 +08:00
|
|
|
ext2fs_free_mem(&shared);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
2001-07-08 01:20:34 +08:00
|
|
|
/*
|
|
|
|
* Drop the refcount on the dup_block structure, and clear the entry
|
|
|
|
* in the block_dup_map if appropriate.
|
|
|
|
*/
|
2011-07-10 10:56:22 +08:00
|
|
|
static void decrement_badcount(e2fsck_t ctx, blk64_t block,
|
|
|
|
struct dup_cluster *p)
|
2001-07-08 01:20:34 +08:00
|
|
|
{
|
|
|
|
p->num_bad--;
|
|
|
|
if (p->num_bad <= 0 ||
|
2011-07-10 10:56:22 +08:00
|
|
|
(p->num_bad == 1 && !check_if_fs_block(ctx, block))) {
|
|
|
|
if (check_if_fs_cluster(ctx, EXT2FS_B2C(ctx->fs, block)))
|
|
|
|
return;
|
2009-08-23 10:29:02 +08:00
|
|
|
ext2fs_unmark_block_bitmap2(ctx->block_dup_map, block);
|
2011-07-10 10:56:22 +08:00
|
|
|
}
|
2001-07-08 01:20:34 +08:00
|
|
|
}
|
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
static int delete_file_block(ext2_filsys fs,
|
2009-09-08 10:29:45 +08:00
|
|
|
blk64_t *block_nr,
|
2011-11-29 00:00:48 +08:00
|
|
|
e2_blkcnt_t blockcnt,
|
2009-09-08 10:29:45 +08:00
|
|
|
blk64_t ref_block EXT2FS_ATTR((unused)),
|
2003-12-07 14:28:50 +08:00
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
void *priv_data)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
struct process_block_struct *pb;
|
2011-07-10 10:56:22 +08:00
|
|
|
struct dup_cluster *p;
|
2002-08-02 00:37:00 +08:00
|
|
|
dnode_t *n;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
e2fsck_t ctx;
|
2011-11-29 00:00:48 +08:00
|
|
|
blk64_t c, lc;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
pb = (struct process_block_struct *) priv_data;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ctx = pb->ctx;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2015-04-12 20:22:07 +08:00
|
|
|
if (*block_nr == 0)
|
1997-04-26 21:21:57 +08:00
|
|
|
return 0;
|
|
|
|
|
2011-07-10 10:56:22 +08:00
|
|
|
c = EXT2FS_B2C(fs, *block_nr);
|
2011-11-29 00:00:48 +08:00
|
|
|
lc = EXT2FS_B2C(fs, blockcnt);
|
2009-08-23 10:29:02 +08:00
|
|
|
if (ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) {
|
2011-07-10 10:56:22 +08:00
|
|
|
n = dict_lookup(&clstr_dict, INT_TO_VOIDPTR(c));
|
2002-08-02 00:37:00 +08:00
|
|
|
if (n) {
|
2017-05-25 09:34:20 +08:00
|
|
|
if (lc != pb->cur_cluster) {
|
|
|
|
p = (struct dup_cluster *) dnode_get(n);
|
2011-11-29 00:00:48 +08:00
|
|
|
decrement_badcount(ctx, *block_nr, p);
|
2017-05-25 09:34:20 +08:00
|
|
|
pb->dup_blocks++;
|
|
|
|
}
|
1997-04-26 21:21:57 +08:00
|
|
|
} else
|
|
|
|
com_err("delete_file_block", 0,
|
2009-09-08 10:29:45 +08:00
|
|
|
_("internal error: can't find dup_blk for %llu\n"),
|
1997-04-26 21:21:57 +08:00
|
|
|
*block_nr);
|
|
|
|
} else {
|
2014-07-27 04:28:58 +08:00
|
|
|
if ((*block_nr % EXT2FS_CLUSTER_RATIO(ctx->fs)) == 0)
|
|
|
|
ext2fs_block_alloc_stats2(fs, *block_nr, -1);
|
2011-07-21 02:40:06 +08:00
|
|
|
pb->dup_blocks++;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
2011-11-29 00:00:48 +08:00
|
|
|
pb->cur_cluster = lc;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2002-08-02 00:37:00 +08:00
|
|
|
static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
|
|
|
|
struct dup_inode *dp, char* block_buf)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ext2_filsys fs = ctx->fs;
|
1997-04-26 21:21:57 +08:00
|
|
|
struct process_block_struct pb;
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
struct problem_context pctx;
|
2002-08-17 22:19:44 +08:00
|
|
|
unsigned int count;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
clear_problem_context(&pctx);
|
2002-08-02 00:37:00 +08:00
|
|
|
pctx.ino = pb.ino = ino;
|
2011-07-21 02:40:06 +08:00
|
|
|
pb.dup_blocks = 0;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
pb.ctx = ctx;
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
pctx.str = "delete_file";
|
2011-11-29 00:00:48 +08:00
|
|
|
pb.cur_cluster = ~0;
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
|
2016-05-22 10:10:39 +08:00
|
|
|
if (ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(&dp->inode)))
|
2013-05-20 09:13:33 +08:00
|
|
|
pctx.errcode = ext2fs_block_iterate3(fs, ino,
|
|
|
|
BLOCK_FLAG_READ_ONLY,
|
|
|
|
block_buf,
|
|
|
|
delete_file_block, &pb);
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
if (pctx.errcode)
|
|
|
|
fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
if (ctx->inode_bad_map)
|
2009-08-23 10:29:02 +08:00
|
|
|
ext2fs_unmark_inode_bitmap2(ctx->inode_bad_map, ino);
|
2013-05-20 09:13:33 +08:00
|
|
|
ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(dp->inode.i_mode));
|
|
|
|
quota_data_sub(ctx->qctx, &dp->inode, ino,
|
|
|
|
pb.dup_blocks * fs->blocksize);
|
|
|
|
quota_data_inodes(ctx->qctx, &dp->inode, ino, -1);
|
2002-08-17 22:19:44 +08:00
|
|
|
|
|
|
|
/* Inode may have changed by block_iterate, so reread it */
|
2016-05-22 10:10:39 +08:00
|
|
|
e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&dp->inode),
|
|
|
|
sizeof(dp->inode), "delete_file");
|
|
|
|
e2fsck_clear_inode(ctx, ino, EXT2_INODE(&dp->inode), 0, "delete_file");
|
|
|
|
if (ext2fs_file_acl_block(fs, EXT2_INODE(&dp->inode)) &&
|
2015-10-24 12:43:19 +08:00
|
|
|
ext2fs_has_feature_xattr(fs->super)) {
|
2016-05-22 10:10:39 +08:00
|
|
|
blk64_t file_acl_block = ext2fs_file_acl_block(fs,
|
|
|
|
EXT2_INODE(&dp->inode));
|
|
|
|
|
2002-08-17 22:19:44 +08:00
|
|
|
count = 1;
|
2016-05-22 10:10:39 +08:00
|
|
|
pctx.errcode = ext2fs_adjust_ea_refcount3(fs, file_acl_block,
|
2012-08-03 08:47:44 +08:00
|
|
|
block_buf, -1, &count, ino);
|
2002-08-17 22:19:44 +08:00
|
|
|
if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) {
|
|
|
|
pctx.errcode = 0;
|
|
|
|
count = 1;
|
|
|
|
}
|
|
|
|
if (pctx.errcode) {
|
2016-05-22 10:10:39 +08:00
|
|
|
pctx.blk = file_acl_block;
|
2002-08-17 22:19:44 +08:00
|
|
|
fix_problem(ctx, PR_1B_ADJ_EA_REFCOUNT, &pctx);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the count is zero, then arrange to have the
|
|
|
|
* block deleted. If the block is in the block_dup_map,
|
|
|
|
* also call delete_file_block since it will take care
|
|
|
|
* of keeping the accounting straight.
|
|
|
|
*/
|
|
|
|
if ((count == 0) ||
|
2009-08-23 10:29:02 +08:00
|
|
|
ext2fs_test_block_bitmap2(ctx->block_dup_map,
|
2016-05-22 10:10:39 +08:00
|
|
|
file_acl_block)) {
|
|
|
|
delete_file_block(fs, &file_acl_block,
|
2002-08-17 22:19:44 +08:00
|
|
|
BLOCK_COUNT_EXTATTR, 0, 0, &pb);
|
2016-05-22 10:10:39 +08:00
|
|
|
ext2fs_file_acl_block_set(fs, EXT2_INODE(&dp->inode),
|
|
|
|
file_acl_block);
|
|
|
|
quota_data_sub(ctx->qctx, &dp->inode, ino,
|
|
|
|
fs->blocksize);
|
2009-09-08 10:29:45 +08:00
|
|
|
}
|
2002-08-17 22:19:44 +08:00
|
|
|
}
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct clone_struct {
|
|
|
|
errcode_t errcode;
|
2011-07-10 10:56:22 +08:00
|
|
|
blk64_t dup_cluster;
|
|
|
|
blk64_t alloc_block;
|
2014-07-26 08:34:04 +08:00
|
|
|
ext2_ino_t dir, ino;
|
1997-04-26 21:21:57 +08:00
|
|
|
char *buf;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
e2fsck_t ctx;
|
2016-05-22 10:10:39 +08:00
|
|
|
struct ext2_inode_large *inode;
|
2015-01-28 21:53:54 +08:00
|
|
|
|
|
|
|
struct dup_cluster *save_dup_cluster;
|
|
|
|
blk64_t save_blocknr;
|
1997-04-26 21:21:57 +08:00
|
|
|
};
|
|
|
|
|
2015-01-28 21:53:54 +08:00
|
|
|
/*
|
|
|
|
* Decrement the bad count *after* we've shown that (a) we can allocate a
|
|
|
|
* replacement block and (b) remap the file blocks. Unfortunately, there's no
|
|
|
|
* way to find out if the remap succeeded until either the next
|
|
|
|
* clone_file_block() call (an error when remapping the block after returning
|
|
|
|
* BLOCK_CHANGED will halt the iteration) or after block_iterate() returns.
|
|
|
|
* Otherwise, it's possible that we decrease the badcount once in preparation
|
|
|
|
* to remap, then the remap fails (either we can't find a replacement block or
|
|
|
|
* we have to split the extent tree and can't find a new extent block), so we
|
|
|
|
* delete the file, which decreases the badcount again.
|
|
|
|
*/
|
|
|
|
static void deferred_dec_badcount(struct clone_struct *cs)
|
|
|
|
{
|
|
|
|
if (!cs->save_dup_cluster)
|
|
|
|
return;
|
|
|
|
decrement_badcount(cs->ctx, cs->save_blocknr, cs->save_dup_cluster);
|
|
|
|
cs->save_dup_cluster = NULL;
|
|
|
|
}
|
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
static int clone_file_block(ext2_filsys fs,
|
2009-09-08 10:29:45 +08:00
|
|
|
blk64_t *block_nr,
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
e2_blkcnt_t blockcnt,
|
2009-09-08 10:29:45 +08:00
|
|
|
blk64_t ref_block EXT2FS_ATTR((unused)),
|
2003-12-07 14:28:50 +08:00
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
void *priv_data)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
2015-01-28 21:53:54 +08:00
|
|
|
struct dup_cluster *p = NULL;
|
2009-08-23 10:29:02 +08:00
|
|
|
blk64_t new_block;
|
1997-04-26 21:21:57 +08:00
|
|
|
errcode_t retval;
|
Many files:
e2fsck.h: If EXT2_FLAT_INCLUDES is defined, then assume all of
the ext2-specific header files are in a flat directory.
dirinfo.c, ehandler.c, pass1.c, pass1b.c, pass2.c, pass5.c,
super.c, swapfs.c, unix.c: Explicitly cast all assignments
from void * to be compatible with C++.
unix.c (sync_disk): Remove sync_disk and calls to that function,
since ext2fs_close() now takes care of this.
pass1.c, pass1b.c, pass2.c, pass3.c, swapfs, badblocks.c,
ehandler.c, unix.c: Change use of private to be priv_data, to
avoid C++ reserved name clash.
1998-01-19 22:50:49 +08:00
|
|
|
struct clone_struct *cs = (struct clone_struct *) priv_data;
|
2002-08-02 00:37:00 +08:00
|
|
|
dnode_t *n;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
e2fsck_t ctx;
|
2011-07-10 10:56:22 +08:00
|
|
|
blk64_t c;
|
|
|
|
int is_meta = 0;
|
2018-04-28 07:10:29 +08:00
|
|
|
int should_write = 1;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ctx = cs->ctx;
|
2015-01-28 21:53:54 +08:00
|
|
|
deferred_dec_badcount(cs);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2015-04-12 20:22:07 +08:00
|
|
|
if (*block_nr == 0)
|
1997-04-26 21:21:57 +08:00
|
|
|
return 0;
|
|
|
|
|
2018-04-28 07:10:29 +08:00
|
|
|
if (ext2fs_has_feature_shared_blocks(ctx->fs->super) &&
|
|
|
|
(ctx->options & E2F_OPT_UNSHARE_BLOCKS) &&
|
|
|
|
(ctx->options & E2F_OPT_NO))
|
|
|
|
should_write = 0;
|
|
|
|
|
2011-07-10 10:56:22 +08:00
|
|
|
c = EXT2FS_B2C(fs, blockcnt);
|
|
|
|
if (check_if_fs_cluster(ctx, EXT2FS_B2C(fs, *block_nr)))
|
|
|
|
is_meta = 1;
|
|
|
|
|
2011-11-29 00:00:48 +08:00
|
|
|
if (c == cs->dup_cluster && cs->alloc_block) {
|
|
|
|
new_block = cs->alloc_block;
|
|
|
|
goto got_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) {
|
2011-07-10 10:56:22 +08:00
|
|
|
n = dict_lookup(&clstr_dict,
|
|
|
|
INT_TO_VOIDPTR(EXT2FS_B2C(fs, *block_nr)));
|
|
|
|
if (!n) {
|
|
|
|
com_err("clone_file_block", 0,
|
|
|
|
_("internal error: can't find dup_blk for %llu\n"),
|
|
|
|
*block_nr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (struct dup_cluster *) dnode_get(n);
|
|
|
|
|
|
|
|
cs->dup_cluster = c;
|
2014-07-26 08:34:04 +08:00
|
|
|
/*
|
|
|
|
* Let's try an implied cluster allocation. If we get the same
|
|
|
|
* cluster back, then we need to find a new block; otherwise,
|
|
|
|
* we're merely fixing the problem of one logical cluster being
|
|
|
|
* mapped to multiple physical clusters.
|
|
|
|
*/
|
|
|
|
new_block = 0;
|
2016-05-22 10:10:39 +08:00
|
|
|
retval = ext2fs_map_cluster_block(fs, cs->ino,
|
|
|
|
EXT2_INODE(cs->inode),
|
2014-07-26 08:34:04 +08:00
|
|
|
blockcnt, &new_block);
|
|
|
|
if (retval == 0 && new_block != 0 &&
|
|
|
|
EXT2FS_B2C(ctx->fs, new_block) !=
|
|
|
|
EXT2FS_B2C(ctx->fs, *block_nr))
|
|
|
|
goto cluster_alloc_ok;
|
2011-07-10 10:56:22 +08:00
|
|
|
retval = ext2fs_new_block2(fs, 0, ctx->block_found_map,
|
|
|
|
&new_block);
|
|
|
|
if (retval) {
|
|
|
|
cs->errcode = retval;
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
2018-03-06 04:52:13 +08:00
|
|
|
if (ext2fs_has_feature_shared_blocks(fs->super)) {
|
|
|
|
/*
|
|
|
|
* Update the block stats so we don't get a prompt to fix block
|
|
|
|
* counts in the final pass.
|
|
|
|
*/
|
|
|
|
ext2fs_block_alloc_stats2(fs, new_block, +1);
|
|
|
|
}
|
2014-07-26 08:34:04 +08:00
|
|
|
cluster_alloc_ok:
|
2011-07-10 10:56:22 +08:00
|
|
|
cs->alloc_block = new_block;
|
|
|
|
|
|
|
|
got_block:
|
|
|
|
new_block &= ~EXT2FS_CLUSTER_MASK(fs);
|
|
|
|
new_block += EXT2FS_CLUSTER_MASK(fs) & blockcnt;
|
|
|
|
if (cs->dir && (blockcnt >= 0)) {
|
|
|
|
retval = ext2fs_set_dir_block2(fs->dblist,
|
|
|
|
cs->dir, new_block, blockcnt);
|
1997-04-26 21:21:57 +08:00
|
|
|
if (retval) {
|
|
|
|
cs->errcode = retval;
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
2011-07-10 10:56:22 +08:00
|
|
|
}
|
2001-07-08 11:01:31 +08:00
|
|
|
#if 0
|
2011-07-10 10:56:22 +08:00
|
|
|
printf("Cloning block #%lld from %llu to %llu\n",
|
|
|
|
blockcnt, *block_nr, new_block);
|
2001-07-08 11:01:31 +08:00
|
|
|
#endif
|
2011-07-10 10:56:22 +08:00
|
|
|
retval = io_channel_read_blk64(fs->io, *block_nr, 1, cs->buf);
|
|
|
|
if (retval) {
|
|
|
|
cs->errcode = retval;
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
2018-04-28 07:10:29 +08:00
|
|
|
if (should_write) {
|
|
|
|
retval = io_channel_write_blk64(fs->io, new_block, 1, cs->buf);
|
|
|
|
if (retval) {
|
|
|
|
cs->errcode = retval;
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
2011-07-10 10:56:22 +08:00
|
|
|
}
|
2015-01-28 21:53:54 +08:00
|
|
|
cs->save_dup_cluster = (is_meta ? NULL : p);
|
|
|
|
cs->save_blocknr = *block_nr;
|
2011-07-10 10:56:22 +08:00
|
|
|
*block_nr = new_block;
|
|
|
|
ext2fs_mark_block_bitmap2(ctx->block_found_map, new_block);
|
|
|
|
ext2fs_mark_block_bitmap2(fs->block_map, new_block);
|
2018-04-28 07:10:29 +08:00
|
|
|
|
|
|
|
if (!should_write) {
|
|
|
|
/* Don't try to change extent information; we want e2fsck to
|
|
|
|
* return success.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-10 10:56:22 +08:00
|
|
|
return BLOCK_CHANGED;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2013-12-03 10:37:10 +08:00
|
|
|
static errcode_t clone_file(e2fsck_t ctx, ext2_ino_t ino,
|
|
|
|
struct dup_inode *dp, char* block_buf)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
ext2_filsys fs = ctx->fs;
|
1997-04-26 21:21:57 +08:00
|
|
|
errcode_t retval;
|
|
|
|
struct clone_struct cs;
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
struct problem_context pctx;
|
2009-09-08 10:29:45 +08:00
|
|
|
blk64_t blk, new_blk;
|
2002-08-02 00:37:00 +08:00
|
|
|
dnode_t *n;
|
|
|
|
struct inode_el *ino_el;
|
2011-07-10 10:56:22 +08:00
|
|
|
struct dup_cluster *dc;
|
2002-08-02 00:37:00 +08:00
|
|
|
struct dup_inode *di;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
clear_problem_context(&pctx);
|
1997-04-26 21:21:57 +08:00
|
|
|
cs.errcode = 0;
|
1997-04-30 01:48:10 +08:00
|
|
|
cs.dir = 0;
|
2011-11-29 00:00:48 +08:00
|
|
|
cs.dup_cluster = ~0;
|
2011-07-10 10:56:22 +08:00
|
|
|
cs.alloc_block = 0;
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-04 01:48:10 +08:00
|
|
|
cs.ctx = ctx;
|
2014-07-26 08:34:04 +08:00
|
|
|
cs.ino = ino;
|
|
|
|
cs.inode = &dp->inode;
|
2015-01-28 21:53:54 +08:00
|
|
|
cs.save_dup_cluster = NULL;
|
|
|
|
cs.save_blocknr = 0;
|
2003-08-01 21:41:07 +08:00
|
|
|
retval = ext2fs_get_mem(fs->blocksize, &cs.buf);
|
1997-11-04 03:42:40 +08:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
1997-04-30 01:48:10 +08:00
|
|
|
|
2009-08-23 10:29:02 +08:00
|
|
|
if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, ino))
|
2002-08-02 00:37:00 +08:00
|
|
|
cs.dir = ino;
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
|
2002-08-02 00:37:00 +08:00
|
|
|
pctx.ino = ino;
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
pctx.str = "clone_file";
|
2016-05-22 10:10:39 +08:00
|
|
|
if (ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(&dp->inode)))
|
2009-09-08 10:29:45 +08:00
|
|
|
pctx.errcode = ext2fs_block_iterate3(fs, ino, 0, block_buf,
|
2002-08-17 22:19:44 +08:00
|
|
|
clone_file_block, &cs);
|
2015-01-28 21:53:54 +08:00
|
|
|
deferred_dec_badcount(&cs);
|
1997-04-26 21:21:57 +08:00
|
|
|
ext2fs_mark_bb_dirty(fs);
|
ChangeLog, message.c, pass1b.c, pass2.c, pass3.c, problem.c, problem.h:
pass1b.c: Change routines to use PR_1B_BLOCK_ITERATE when reporting
problems rather than using com_err directly.
problem.c, problem.h (PR_1B_BLOCK_ITERATE): Add new problem code.
message.c (expand_percent_expression): Add safety check. If ctx->str
is NULL, print "NULL" instead of dereferencing the null pointer.
pass1b.c, pass2.c, pass3.c: Change calls to ext2fs_block_iterate to
ext2fs_block_iterate2, to support 64-bit filesizes and to speed things
up slightly by avoiding the use of the ext2fs_block_iterate's
compatibility shim layer.
version.h:
Update for WIP release.
2000-11-17 13:40:49 +08:00
|
|
|
if (pctx.errcode) {
|
|
|
|
fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
|
2001-07-08 01:20:34 +08:00
|
|
|
retval = pctx.errcode;
|
|
|
|
goto errout;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
if (cs.errcode) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err("clone_file", cs.errcode, "%s",
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 11:11:03 +08:00
|
|
|
_("returned from clone_file_block"));
|
2001-07-08 01:20:34 +08:00
|
|
|
retval = cs.errcode;
|
|
|
|
goto errout;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
2002-08-17 22:19:44 +08:00
|
|
|
/* The inode may have changed on disk, so we have to re-read it */
|
2016-05-22 10:10:39 +08:00
|
|
|
e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&dp->inode),
|
|
|
|
sizeof(dp->inode), "clone file EA");
|
|
|
|
blk = ext2fs_file_acl_block(fs, EXT2_INODE(&dp->inode));
|
2009-09-08 10:29:45 +08:00
|
|
|
new_blk = blk;
|
|
|
|
if (blk && (clone_file_block(fs, &new_blk,
|
2001-07-08 01:20:34 +08:00
|
|
|
BLOCK_COUNT_EXTATTR, 0, 0, &cs) ==
|
|
|
|
BLOCK_CHANGED)) {
|
2016-05-22 10:10:39 +08:00
|
|
|
ext2fs_file_acl_block_set(fs, EXT2_INODE(&dp->inode), new_blk);
|
|
|
|
e2fsck_write_inode_full(ctx, ino, EXT2_INODE(&dp->inode),
|
|
|
|
sizeof(dp->inode), "clone file EA");
|
2001-07-02 23:54:09 +08:00
|
|
|
/*
|
|
|
|
* If we cloned the EA block, find all other inodes
|
2017-10-08 19:30:08 +08:00
|
|
|
* which referred to that EA block, and modify
|
2001-07-02 23:54:09 +08:00
|
|
|
* them to point to the new EA block.
|
|
|
|
*/
|
2011-07-10 10:56:22 +08:00
|
|
|
n = dict_lookup(&clstr_dict,
|
|
|
|
INT_TO_VOIDPTR(EXT2FS_B2C(fs, blk)));
|
2007-03-19 20:52:10 +08:00
|
|
|
if (!n) {
|
2008-08-28 11:07:54 +08:00
|
|
|
com_err("clone_file", 0,
|
2007-03-19 20:52:10 +08:00
|
|
|
_("internal error: couldn't lookup EA "
|
2009-09-08 10:29:45 +08:00
|
|
|
"block record for %llu"), blk);
|
2007-03-19 20:52:10 +08:00
|
|
|
retval = 0; /* OK to stumble on... */
|
|
|
|
goto errout;
|
|
|
|
}
|
2011-07-10 10:56:22 +08:00
|
|
|
dc = (struct dup_cluster *) dnode_get(n);
|
|
|
|
for (ino_el = dc->inode_list; ino_el; ino_el = ino_el->next) {
|
2002-08-02 00:37:00 +08:00
|
|
|
if (ino_el->inode == ino)
|
2001-07-02 23:54:09 +08:00
|
|
|
continue;
|
2003-08-02 02:26:23 +08:00
|
|
|
n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino_el->inode));
|
2007-03-19 20:52:10 +08:00
|
|
|
if (!n) {
|
2008-08-28 11:07:54 +08:00
|
|
|
com_err("clone_file", 0,
|
2007-03-19 20:52:10 +08:00
|
|
|
_("internal error: couldn't lookup EA "
|
2008-08-28 11:07:54 +08:00
|
|
|
"inode record for %u"),
|
2007-03-19 20:52:10 +08:00
|
|
|
ino_el->inode);
|
|
|
|
retval = 0; /* OK to stumble on... */
|
|
|
|
goto errout;
|
|
|
|
}
|
2002-08-02 00:37:00 +08:00
|
|
|
di = (struct dup_inode *) dnode_get(n);
|
2016-05-22 10:10:39 +08:00
|
|
|
if (ext2fs_file_acl_block(fs,
|
|
|
|
EXT2_INODE(&di->inode)) == blk) {
|
|
|
|
ext2fs_file_acl_block_set(fs,
|
|
|
|
EXT2_INODE(&di->inode),
|
|
|
|
ext2fs_file_acl_block(fs, EXT2_INODE(&dp->inode)));
|
|
|
|
e2fsck_write_inode_full(ctx, ino_el->inode,
|
|
|
|
EXT2_INODE(&di->inode),
|
|
|
|
sizeof(di->inode), "clone file EA");
|
2011-07-10 10:56:22 +08:00
|
|
|
decrement_badcount(ctx, blk, dc);
|
2001-07-08 01:20:34 +08:00
|
|
|
}
|
2001-07-02 23:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
2001-07-08 01:20:34 +08:00
|
|
|
retval = 0;
|
|
|
|
errout:
|
2003-08-01 21:41:07 +08:00
|
|
|
ext2fs_free_mem(&cs.buf);
|
2001-07-08 01:20:34 +08:00
|
|
|
return retval;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
2000-02-09 07:19:32 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine returns 1 if a block overlaps with one of the superblocks,
|
|
|
|
* group descriptors, inode bitmaps, or block bitmaps.
|
|
|
|
*/
|
2010-06-14 05:00:00 +08:00
|
|
|
static int check_if_fs_block(e2fsck_t ctx, blk64_t test_block)
|
2000-02-09 07:19:32 +08:00
|
|
|
{
|
|
|
|
ext2_filsys fs = ctx->fs;
|
2010-06-14 05:00:00 +08:00
|
|
|
blk64_t first_block;
|
2003-12-07 14:28:50 +08:00
|
|
|
dgrp_t i;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2006-09-13 02:55:22 +08:00
|
|
|
first_block = fs->super->s_first_data_block;
|
2000-02-09 07:19:32 +08:00
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
|
|
|
|
2006-09-13 02:55:22 +08:00
|
|
|
/* Check superblocks/block group descriptors */
|
2000-02-09 07:19:32 +08:00
|
|
|
if (ext2fs_bg_has_super(fs, i)) {
|
2006-09-13 02:55:22 +08:00
|
|
|
if (test_block >= first_block &&
|
|
|
|
(test_block <= first_block + fs->desc_blocks))
|
2000-02-09 07:19:32 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2000-02-09 07:19:32 +08:00
|
|
|
/* Check the inode table */
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
if ((ext2fs_inode_table_loc(fs, i)) &&
|
|
|
|
(test_block >= ext2fs_inode_table_loc(fs, i)) &&
|
|
|
|
(test_block < (ext2fs_inode_table_loc(fs, i) +
|
2000-02-09 07:19:32 +08:00
|
|
|
fs->inode_blocks_per_group)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Check the bitmap blocks */
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
if ((test_block == ext2fs_block_bitmap_loc(fs, i)) ||
|
|
|
|
(test_block == ext2fs_inode_bitmap_loc(fs, i)))
|
2000-02-09 07:19:32 +08:00
|
|
|
return 1;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2006-09-13 02:55:22 +08:00
|
|
|
first_block += fs->super->s_blocks_per_group;
|
2000-02-09 07:19:32 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-10 10:56:22 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine returns 1 if a cluster overlaps with one of the superblocks,
|
|
|
|
* group descriptors, inode bitmaps, or block bitmaps.
|
|
|
|
*/
|
|
|
|
static int check_if_fs_cluster(e2fsck_t ctx, blk64_t cluster)
|
|
|
|
{
|
|
|
|
ext2_filsys fs = ctx->fs;
|
|
|
|
blk64_t first_block;
|
|
|
|
dgrp_t i;
|
|
|
|
|
|
|
|
first_block = fs->super->s_first_data_block;
|
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
|
|
|
|
|
|
|
/* Check superblocks/block group descriptors */
|
|
|
|
if (ext2fs_bg_has_super(fs, i)) {
|
|
|
|
if (cluster >= EXT2FS_B2C(fs, first_block) &&
|
|
|
|
(cluster <= EXT2FS_B2C(fs, first_block +
|
|
|
|
fs->desc_blocks)))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the inode table */
|
|
|
|
if ((ext2fs_inode_table_loc(fs, i)) &&
|
|
|
|
(cluster >= EXT2FS_B2C(fs,
|
|
|
|
ext2fs_inode_table_loc(fs, i))) &&
|
|
|
|
(cluster <= EXT2FS_B2C(fs,
|
|
|
|
ext2fs_inode_table_loc(fs, i) +
|
|
|
|
fs->inode_blocks_per_group - 1)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Check the bitmap blocks */
|
|
|
|
if ((cluster == EXT2FS_B2C(fs,
|
|
|
|
ext2fs_block_bitmap_loc(fs, i))) ||
|
|
|
|
(cluster == EXT2FS_B2C(fs,
|
|
|
|
ext2fs_inode_bitmap_loc(fs, i))))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
first_block += fs->super->s_blocks_per_group;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|