mirror of https://github.com/vitalif/e2fsprogs
Rework e2fsck's dirinfo abstraction to be more friendly for databases
Change the iterator abstraction and replace e2fsck_get_dir_info() with e2fsck_dir_info_{set,get}_{parent,dotdot} so that we can support an on-disk dirinfo implementation. This allows e2fsck to check very large filesystems on systems with smaller amounts of memory and/or address space. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>bitmap-optimize
parent
86bc90f4f1
commit
28db82a84a
|
@ -1,5 +1,12 @@
|
|||
2007-04-04 Theodore Tso <tytso@mit.edu>
|
||||
|
||||
* dirinfo.c, pass2.c, pass3.c, rehash.c, e2fsck.h: Change the
|
||||
iterator abstraction and replace e2fsck_get_dir_info()
|
||||
with e2fsck_dir_info_{set,get}_{parent,dotdot} so that we
|
||||
can support an on-disk dirinfo implementation. This
|
||||
allows e2fsck to check very large filesystems on systems
|
||||
with smaller amounts of memory and/or address space.
|
||||
|
||||
* pass1.c (check_ext_attr): Make sure the region variable is
|
||||
initialized to zero to avoid checking and then freeing an
|
||||
uninitialized pointer if there is a corrupted EA block.
|
||||
|
|
263
e2fsck/dirinfo.c
263
e2fsck/dirinfo.c
|
@ -5,7 +5,45 @@
|
|||
* under the terms of the GNU Public License.
|
||||
*/
|
||||
|
||||
#undef DIRINFO_DEBUG
|
||||
|
||||
#include "e2fsck.h"
|
||||
struct dir_info_db {
|
||||
int count;
|
||||
int size;
|
||||
struct dir_info *array;
|
||||
struct dir_info *last_lookup;
|
||||
};
|
||||
|
||||
struct dir_info_iter {
|
||||
int i;
|
||||
};
|
||||
|
||||
static void e2fsck_put_dir_info(e2fsck_t ctx, struct dir_info *dir);
|
||||
|
||||
void setup_db(e2fsck_t ctx)
|
||||
{
|
||||
struct dir_info_db *db;
|
||||
ext2_ino_t num_dirs;
|
||||
errcode_t retval;
|
||||
|
||||
db = (struct dir_info_db *)
|
||||
e2fsck_allocate_memory(ctx, sizeof(struct dir_info_db),
|
||||
"directory map db");
|
||||
db->count = db->size = 0;
|
||||
db->array = 0;
|
||||
|
||||
retval = ext2fs_get_num_dirs(ctx->fs, &num_dirs);
|
||||
if (retval)
|
||||
num_dirs = 1024; /* Guess */
|
||||
db->size = num_dirs + 10;
|
||||
db->array = (struct dir_info *)
|
||||
e2fsck_allocate_memory(ctx, db->size
|
||||
* sizeof (struct dir_info),
|
||||
"directory map");
|
||||
|
||||
ctx->dir_info = db;
|
||||
}
|
||||
|
||||
/*
|
||||
* This subroutine is called during pass1 to create a directory info
|
||||
|
@ -14,39 +52,37 @@
|
|||
*/
|
||||
void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
|
||||
{
|
||||
struct dir_info *dir;
|
||||
int i, j;
|
||||
ext2_ino_t num_dirs;
|
||||
errcode_t retval;
|
||||
unsigned long old_size;
|
||||
struct dir_info_db *db;
|
||||
struct dir_info *dir, ent;
|
||||
int i, j;
|
||||
errcode_t retval;
|
||||
unsigned long old_size;
|
||||
|
||||
#if 0
|
||||
printf("add_dir_info for inode %lu...\n", ino);
|
||||
#ifdef DIRINFO_DEBUG
|
||||
printf("add_dir_info for inode (%lu, %lu)...\n", ino, parent);
|
||||
#endif
|
||||
if (!ctx->dir_info) {
|
||||
ctx->dir_info_count = 0;
|
||||
retval = ext2fs_get_num_dirs(ctx->fs, &num_dirs);
|
||||
if (retval)
|
||||
num_dirs = 1024; /* Guess */
|
||||
ctx->dir_info_size = num_dirs + 10;
|
||||
ctx->dir_info = (struct dir_info *)
|
||||
e2fsck_allocate_memory(ctx, ctx->dir_info_size
|
||||
* sizeof (struct dir_info),
|
||||
"directory map");
|
||||
}
|
||||
if (!ctx->dir_info)
|
||||
setup_db(ctx);
|
||||
db = ctx->dir_info;
|
||||
|
||||
if (ctx->dir_info_count >= ctx->dir_info_size) {
|
||||
old_size = ctx->dir_info_size * sizeof(struct dir_info);
|
||||
ctx->dir_info_size += 10;
|
||||
retval = ext2fs_resize_mem(old_size, ctx->dir_info_size *
|
||||
if (ctx->dir_info->count >= ctx->dir_info->size) {
|
||||
old_size = ctx->dir_info->size * sizeof(struct dir_info);
|
||||
ctx->dir_info->size += 10;
|
||||
retval = ext2fs_resize_mem(old_size, ctx->dir_info->size *
|
||||
sizeof(struct dir_info),
|
||||
&ctx->dir_info);
|
||||
if (retval) {
|
||||
ctx->dir_info_size -= 10;
|
||||
ctx->dir_info->size -= 10;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ent.ino = ino;
|
||||
ent.parent = parent;
|
||||
ent.dotdot = parent;
|
||||
|
||||
e2fsck_put_dir_info(ctx, &ent);
|
||||
|
||||
/*
|
||||
* Normally, add_dir_info is called with each inode in
|
||||
* sequential order; but once in a while (like when pass 3
|
||||
|
@ -56,17 +92,17 @@ void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
|
|||
* the dir_info array needs to be sorted by inode number for
|
||||
* get_dir_info()'s sake.
|
||||
*/
|
||||
if (ctx->dir_info_count &&
|
||||
ctx->dir_info[ctx->dir_info_count-1].ino >= ino) {
|
||||
for (i = ctx->dir_info_count-1; i > 0; i--)
|
||||
if (ctx->dir_info[i-1].ino < ino)
|
||||
if (ctx->dir_info->count &&
|
||||
ctx->dir_info->array[ctx->dir_info->count-1].ino >= ino) {
|
||||
for (i = ctx->dir_info->count-1; i > 0; i--)
|
||||
if (ctx->dir_info->array[i-1].ino < ino)
|
||||
break;
|
||||
dir = &ctx->dir_info[i];
|
||||
dir = &ctx->dir_info->array[i];
|
||||
if (dir->ino != ino)
|
||||
for (j = ctx->dir_info_count++; j > i; j--)
|
||||
ctx->dir_info[j] = ctx->dir_info[j-1];
|
||||
for (j = ctx->dir_info->count++; j > i; j--)
|
||||
ctx->dir_info->array[j] = ctx->dir_info->array[j-1];
|
||||
} else
|
||||
dir = &ctx->dir_info[ctx->dir_info_count++];
|
||||
dir = &ctx->dir_info->array[ctx->dir_info->count++];
|
||||
|
||||
dir->ino = ino;
|
||||
dir->dotdot = parent;
|
||||
|
@ -77,26 +113,53 @@ void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
|
|||
* get_dir_info() --- given an inode number, try to find the directory
|
||||
* information entry for it.
|
||||
*/
|
||||
struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
|
||||
static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
|
||||
{
|
||||
int low, high, mid;
|
||||
struct dir_info_db *db = ctx->dir_info;
|
||||
int low, high, mid, ret;
|
||||
|
||||
if (!db)
|
||||
return 0;
|
||||
|
||||
#ifdef DIRINFO_DEBUG
|
||||
printf("e2fsck_get_dir_info %d...", ino);
|
||||
#endif
|
||||
|
||||
if (db->last_lookup && db->last_lookup->ino == ino)
|
||||
return db->last_lookup;
|
||||
|
||||
low = 0;
|
||||
high = ctx->dir_info_count-1;
|
||||
if (!ctx->dir_info)
|
||||
return 0;
|
||||
if (ino == ctx->dir_info[low].ino)
|
||||
return &ctx->dir_info[low];
|
||||
if (ino == ctx->dir_info[high].ino)
|
||||
return &ctx->dir_info[high];
|
||||
high = ctx->dir_info->count-1;
|
||||
if (ino == ctx->dir_info->array[low].ino) {
|
||||
#ifdef DIRINFO_DEBUG
|
||||
printf("(%d,%d,%d)\n", ino,
|
||||
ctx->dir_info->array[low].dotdot,
|
||||
ctx->dir_info->array[low].parent);
|
||||
#endif
|
||||
return &ctx->dir_info->array[low];
|
||||
}
|
||||
if (ino == ctx->dir_info->array[high].ino) {
|
||||
#ifdef DIRINFO_DEBUG
|
||||
printf("(%d,%d,%d)\n", ino,
|
||||
ctx->dir_info->array[high].dotdot,
|
||||
ctx->dir_info->array[high].parent);
|
||||
#endif
|
||||
return &ctx->dir_info->array[high];
|
||||
}
|
||||
|
||||
while (low < high) {
|
||||
mid = (low+high)/2;
|
||||
if (mid == low || mid == high)
|
||||
break;
|
||||
if (ino == ctx->dir_info[mid].ino)
|
||||
return &ctx->dir_info[mid];
|
||||
if (ino < ctx->dir_info[mid].ino)
|
||||
if (ino == ctx->dir_info->array[mid].ino) {
|
||||
#ifdef DIRINFO_DEBUG
|
||||
printf("(%d,%d,%d)\n", ino,
|
||||
ctx->dir_info->array[mid].dotdot,
|
||||
ctx->dir_info->array[mid].parent);
|
||||
#endif
|
||||
return &ctx->dir_info->array[mid];
|
||||
}
|
||||
if (ino < ctx->dir_info->array[mid].ino)
|
||||
high = mid;
|
||||
else
|
||||
low = mid;
|
||||
|
@ -104,17 +167,26 @@ struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void e2fsck_put_dir_info(e2fsck_t ctx, struct dir_info *dir)
|
||||
{
|
||||
#ifdef DIRINFO_DEBUG
|
||||
printf("e2fsck_put_dir_info (%d, %d, %d)...", dir->ino, dir->dotdot,
|
||||
dir->parent);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the dir_info structure when it isn't needed any more.
|
||||
*/
|
||||
void e2fsck_free_dir_info(e2fsck_t ctx)
|
||||
{
|
||||
if (ctx->dir_info) {
|
||||
ctx->dir_info->size = 0;
|
||||
ctx->dir_info->count = 0;
|
||||
ext2fs_free_mem(&ctx->dir_info);
|
||||
ctx->dir_info = 0;
|
||||
}
|
||||
ctx->dir_info_size = 0;
|
||||
ctx->dir_info_count = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -122,16 +194,107 @@ void e2fsck_free_dir_info(e2fsck_t ctx)
|
|||
*/
|
||||
int e2fsck_get_num_dirinfo(e2fsck_t ctx)
|
||||
{
|
||||
return ctx->dir_info_count;
|
||||
return ctx->dir_info ? ctx->dir_info->count : 0;
|
||||
}
|
||||
|
||||
extern struct dir_info_iter *e2fsck_dir_info_iter_begin(e2fsck_t ctx)
|
||||
{
|
||||
struct dir_info_iter *iter;
|
||||
struct dir_info_db *db = ctx->dir_info;
|
||||
int ret;
|
||||
|
||||
iter = e2fsck_allocate_memory(ctx, sizeof(struct dir_info_iter),
|
||||
"dir_info iterator");
|
||||
memset(iter, 0, sizeof(iter));
|
||||
return iter;
|
||||
}
|
||||
|
||||
extern void e2fsck_dir_info_iter_end(e2fsck_t ctx,
|
||||
struct dir_info_iter *iter)
|
||||
{
|
||||
ext2fs_free_mem(&iter);
|
||||
}
|
||||
|
||||
/*
|
||||
* A simple interator function
|
||||
*/
|
||||
struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, int *control)
|
||||
struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, struct dir_info_iter *iter)
|
||||
{
|
||||
if (*control >= ctx->dir_info_count)
|
||||
if (!ctx->dir_info || !iter ||
|
||||
(iter->i >= ctx->dir_info->count))
|
||||
return 0;
|
||||
|
||||
return(ctx->dir_info + (*control)++);
|
||||
|
||||
#ifdef DIRINFO_DEBUG
|
||||
printf("iter(%d, %d, %d)...", ctx->dir_info->array[iter->i].ino,
|
||||
ctx->dir_info->array[iter->i].dotdot,
|
||||
ctx->dir_info->array[iter->i].parent);
|
||||
#endif
|
||||
return(ctx->dir_info->array + iter->i++);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function only sets the parent pointer, and requires that
|
||||
* dirinfo structure has already been created.
|
||||
*/
|
||||
int e2fsck_dir_info_set_parent(e2fsck_t ctx, ext2_ino_t ino,
|
||||
ext2_ino_t parent)
|
||||
{
|
||||
struct dir_info *p;
|
||||
|
||||
p = e2fsck_get_dir_info(ctx, ino);
|
||||
if (!p)
|
||||
return 1;
|
||||
p->parent = parent;
|
||||
e2fsck_put_dir_info(ctx, p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function only sets the dot dot pointer, and requires that
|
||||
* dirinfo structure has already been created.
|
||||
*/
|
||||
int e2fsck_dir_info_set_dotdot(e2fsck_t ctx, ext2_ino_t ino,
|
||||
ext2_ino_t dotdot)
|
||||
{
|
||||
struct dir_info *p;
|
||||
|
||||
p = e2fsck_get_dir_info(ctx, ino);
|
||||
if (!p)
|
||||
return 1;
|
||||
p->dotdot = dotdot;
|
||||
e2fsck_put_dir_info(ctx, p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function only sets the parent pointer, and requires that
|
||||
* dirinfo structure has already been created.
|
||||
*/
|
||||
int e2fsck_dir_info_get_parent(e2fsck_t ctx, ext2_ino_t ino,
|
||||
ext2_ino_t *parent)
|
||||
{
|
||||
struct dir_info *p;
|
||||
|
||||
p = e2fsck_get_dir_info(ctx, ino);
|
||||
if (!p)
|
||||
return 1;
|
||||
*parent = p->parent;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function only sets the dot dot pointer, and requires that
|
||||
* dirinfo structure has already been created.
|
||||
*/
|
||||
int e2fsck_dir_info_get_dotdot(e2fsck_t ctx, ext2_ino_t ino,
|
||||
ext2_ino_t *dotdot)
|
||||
{
|
||||
struct dir_info *p;
|
||||
|
||||
p = e2fsck_get_dir_info(ctx, ino);
|
||||
if (!p)
|
||||
return 1;
|
||||
*dotdot = p->dotdot;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -263,9 +263,7 @@ struct e2fsck_struct {
|
|||
/*
|
||||
* Directory information
|
||||
*/
|
||||
int dir_info_count;
|
||||
int dir_info_size;
|
||||
struct dir_info *dir_info;
|
||||
struct dir_info_db *dir_info;
|
||||
|
||||
/*
|
||||
* Indexed directory information
|
||||
|
@ -374,10 +372,20 @@ extern void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
|
|||
|
||||
/* dirinfo.c */
|
||||
extern void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent);
|
||||
extern struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino);
|
||||
extern void e2fsck_free_dir_info(e2fsck_t ctx);
|
||||
extern int e2fsck_get_num_dirinfo(e2fsck_t ctx);
|
||||
extern struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, int *control);
|
||||
extern struct dir_info_iter *e2fsck_dir_info_iter_begin(e2fsck_t ctx);
|
||||
extern struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx,
|
||||
struct dir_info_iter *);
|
||||
extern void e2fsck_dir_info_iter_end(e2fsck_t ctx, struct dir_info_iter *);
|
||||
extern int e2fsck_dir_info_set_parent(e2fsck_t ctx, ext2_ino_t ino,
|
||||
ext2_ino_t parent);
|
||||
extern int e2fsck_dir_info_set_dotdot(e2fsck_t ctx, ext2_ino_t ino,
|
||||
ext2_ino_t dotdot);
|
||||
extern int e2fsck_dir_info_get_parent(e2fsck_t ctx, ext2_ino_t ino,
|
||||
ext2_ino_t *parent);
|
||||
extern int e2fsck_dir_info_get_dotdot(e2fsck_t ctx, ext2_ino_t ino,
|
||||
ext2_ino_t *dotdot);
|
||||
|
||||
/* dx_dirinfo.c */
|
||||
extern void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, int num_blocks);
|
||||
|
|
|
@ -93,7 +93,6 @@ void e2fsck_pass2(e2fsck_t ctx)
|
|||
#ifdef RESOURCE_TRACK
|
||||
struct resource_track rtrack;
|
||||
#endif
|
||||
struct dir_info *dir;
|
||||
struct check_dir_struct cd;
|
||||
struct dx_dir_info *dx_dir;
|
||||
struct dx_dirblock_info *dx_db, *dx_parent;
|
||||
|
@ -131,9 +130,7 @@ void e2fsck_pass2(e2fsck_t ctx)
|
|||
* present. (If the root directory is not present, we will
|
||||
* create it in pass 3.)
|
||||
*/
|
||||
dir = e2fsck_get_dir_info(ctx, EXT2_ROOT_INO);
|
||||
if (dir)
|
||||
dir->parent = EXT2_ROOT_INO;
|
||||
(void) e2fsck_dir_info_set_parent(ctx, EXT2_ROOT_INO, EXT2_ROOT_INO);
|
||||
|
||||
cd.buf = buf;
|
||||
cd.ctx = ctx;
|
||||
|
@ -412,9 +409,9 @@ static int check_dot(e2fsck_t ctx,
|
|||
*/
|
||||
static int check_dotdot(e2fsck_t ctx,
|
||||
struct ext2_dir_entry *dirent,
|
||||
struct dir_info *dir, struct problem_context *pctx)
|
||||
ext2_ino_t ino, struct problem_context *pctx)
|
||||
{
|
||||
int problem = 0;
|
||||
int problem = 0;
|
||||
|
||||
if (!dirent->inode)
|
||||
problem = PR_2_MISSING_DOT_DOT;
|
||||
|
@ -443,7 +440,10 @@ static int check_dotdot(e2fsck_t ctx,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
dir->dotdot = dirent->inode;
|
||||
if (e2fsck_dir_info_set_dotdot(ctx, ino, dirent->inode)) {
|
||||
fix_problem(ctx, PR_2_NO_DIRINFO, pctx);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -698,7 +698,7 @@ static int check_dir_block(ext2_filsys fs,
|
|||
struct ext2_db_entry *db,
|
||||
void *priv_data)
|
||||
{
|
||||
struct dir_info *subdir, *dir;
|
||||
struct dir_info *subdir;
|
||||
struct dx_dir_info *dx_dir;
|
||||
#ifdef ENABLE_HTREE
|
||||
struct dx_dirblock_info *dx_db = 0;
|
||||
|
@ -710,6 +710,7 @@ static int check_dir_block(ext2_filsys fs,
|
|||
int dot_state;
|
||||
blk_t block_nr = db->blk;
|
||||
ext2_ino_t ino = db->ino;
|
||||
ext2_ino_t subdir_parent;
|
||||
__u16 links;
|
||||
struct check_dir_struct *cd;
|
||||
char *buf;
|
||||
|
@ -720,6 +721,7 @@ static int check_dir_block(ext2_filsys fs,
|
|||
static dict_t de_dict;
|
||||
struct problem_context pctx;
|
||||
int dups_found = 0;
|
||||
int ret;
|
||||
|
||||
cd = (struct check_dir_struct *) priv_data;
|
||||
buf = cd->buf;
|
||||
|
@ -846,12 +848,10 @@ static int check_dir_block(ext2_filsys fs,
|
|||
if (check_dot(ctx, dirent, ino, &cd->pctx))
|
||||
dir_modified++;
|
||||
} else if (dot_state == 1) {
|
||||
dir = e2fsck_get_dir_info(ctx, ino);
|
||||
if (!dir) {
|
||||
fix_problem(ctx, PR_2_NO_DIRINFO, &cd->pctx);
|
||||
ret = check_dotdot(ctx, dirent, ino, &cd->pctx);
|
||||
if (ret < 0)
|
||||
goto abort_free_dict;
|
||||
}
|
||||
if (check_dotdot(ctx, dirent, dir, &cd->pctx))
|
||||
if (ret)
|
||||
dir_modified++;
|
||||
} else if (dirent->inode == ino) {
|
||||
problem = PR_2_LINK_DOT;
|
||||
|
@ -981,14 +981,14 @@ static int check_dir_block(ext2_filsys fs,
|
|||
if ((dot_state > 1) &&
|
||||
(ext2fs_test_inode_bitmap(ctx->inode_dir_map,
|
||||
dirent->inode))) {
|
||||
subdir = e2fsck_get_dir_info(ctx, dirent->inode);
|
||||
if (!subdir) {
|
||||
if (e2fsck_dir_info_get_parent(ctx, dirent->inode,
|
||||
&subdir_parent)) {
|
||||
cd->pctx.ino = dirent->inode;
|
||||
fix_problem(ctx, PR_2_NO_DIRINFO, &cd->pctx);
|
||||
goto abort_free_dict;
|
||||
}
|
||||
if (subdir->parent) {
|
||||
cd->pctx.ino2 = subdir->parent;
|
||||
if (subdir_parent) {
|
||||
cd->pctx.ino2 = subdir_parent;
|
||||
if (fix_problem(ctx, PR_2_LINK_DIR,
|
||||
&cd->pctx)) {
|
||||
dirent->inode = 0;
|
||||
|
@ -996,8 +996,10 @@ static int check_dir_block(ext2_filsys fs,
|
|||
goto next;
|
||||
}
|
||||
cd->pctx.ino2 = 0;
|
||||
} else
|
||||
subdir->parent = ino;
|
||||
} else {
|
||||
(void) e2fsck_dir_info_set_parent(ctx,
|
||||
dirent->inode, ino);
|
||||
}
|
||||
}
|
||||
|
||||
if (dups_found) {
|
||||
|
|
|
@ -42,9 +42,9 @@
|
|||
#include "problem.h"
|
||||
|
||||
static void check_root(e2fsck_t ctx);
|
||||
static int check_directory(e2fsck_t ctx, struct dir_info *dir,
|
||||
static int check_directory(e2fsck_t ctx, ext2_ino_t ino,
|
||||
struct problem_context *pctx);
|
||||
static void fix_dotdot(e2fsck_t ctx, struct dir_info *dir, ext2_ino_t parent);
|
||||
static void fix_dotdot(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent);
|
||||
|
||||
static ext2fs_inode_bitmap inode_loop_detect = 0;
|
||||
static ext2fs_inode_bitmap inode_done_map = 0;
|
||||
|
@ -52,7 +52,7 @@ static ext2fs_inode_bitmap inode_done_map = 0;
|
|||
void e2fsck_pass3(e2fsck_t ctx)
|
||||
{
|
||||
ext2_filsys fs = ctx->fs;
|
||||
int i;
|
||||
struct dir_info_iter *iter;
|
||||
#ifdef RESOURCE_TRACK
|
||||
struct resource_track rtrack;
|
||||
#endif
|
||||
|
@ -104,15 +104,17 @@ void e2fsck_pass3(e2fsck_t ctx)
|
|||
if ((ctx->progress)(ctx, 3, 0, maxdirs))
|
||||
goto abort_exit;
|
||||
|
||||
for (i=0; (dir = e2fsck_dir_info_iter(ctx, &i)) != 0;) {
|
||||
iter = e2fsck_dir_info_iter_begin(ctx);
|
||||
while ((dir = e2fsck_dir_info_iter(ctx, iter)) != 0) {
|
||||
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
|
||||
goto abort_exit;
|
||||
if (ctx->progress && (ctx->progress)(ctx, 3, count++, maxdirs))
|
||||
goto abort_exit;
|
||||
if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, dir->ino))
|
||||
if (check_directory(ctx, dir, &pctx))
|
||||
if (check_directory(ctx, dir->ino, &pctx))
|
||||
goto abort_exit;
|
||||
}
|
||||
e2fsck_dir_info_iter_end(ctx, iter);
|
||||
|
||||
/*
|
||||
* Force the creation of /lost+found if not present
|
||||
|
@ -267,16 +269,13 @@ static void check_root(e2fsck_t ctx)
|
|||
* increment a counter; if the counter exceeds some extreme threshold,
|
||||
* then we try again with the loop detection bitmap enabled.
|
||||
*/
|
||||
static int check_directory(e2fsck_t ctx, struct dir_info *dir,
|
||||
static int check_directory(e2fsck_t ctx, ext2_ino_t dir,
|
||||
struct problem_context *pctx)
|
||||
{
|
||||
ext2_filsys fs = ctx->fs;
|
||||
struct dir_info *p = dir;
|
||||
ext2_ino_t ino = dir, parent;
|
||||
int loop_pass = 0, parent_count = 0;
|
||||
|
||||
if (!p)
|
||||
return 0;
|
||||
|
||||
while (1) {
|
||||
/*
|
||||
* Mark this inode as being "done"; by the time we
|
||||
|
@ -288,44 +287,38 @@ static int check_directory(e2fsck_t ctx, struct dir_info *dir,
|
|||
* If it was marked done already, then we've reached a
|
||||
* parent we've already checked.
|
||||
*/
|
||||
if (ext2fs_mark_inode_bitmap(inode_done_map, p->ino))
|
||||
if (ext2fs_mark_inode_bitmap(inode_done_map, ino))
|
||||
break;
|
||||
|
||||
if (e2fsck_dir_info_get_parent(ctx, ino, &parent)) {
|
||||
fix_problem(ctx, PR_3_NO_DIRINFO, pctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If this directory doesn't have a parent, or we've
|
||||
* seen the parent once already, then offer to
|
||||
* reparent it to lost+found
|
||||
*/
|
||||
if (!p->parent ||
|
||||
if (!parent ||
|
||||
(loop_pass &&
|
||||
(ext2fs_test_inode_bitmap(inode_loop_detect,
|
||||
p->parent)))) {
|
||||
pctx->ino = p->ino;
|
||||
parent)))) {
|
||||
pctx->ino = ino;
|
||||
if (fix_problem(ctx, PR_3_UNCONNECTED_DIR, pctx)) {
|
||||
if (e2fsck_reconnect_file(ctx, pctx->ino))
|
||||
ext2fs_unmark_valid(fs);
|
||||
else {
|
||||
p = e2fsck_get_dir_info(ctx, pctx->ino);
|
||||
if (!p) {
|
||||
fix_problem(ctx,
|
||||
PR_3_NO_DIRINFO, pctx);
|
||||
return 0;
|
||||
}
|
||||
p->parent = ctx->lost_and_found;
|
||||
fix_dotdot(ctx, p, ctx->lost_and_found);
|
||||
fix_dotdot(ctx, pctx->ino,
|
||||
ctx->lost_and_found);
|
||||
parent = ctx->lost_and_found;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
p = e2fsck_get_dir_info(ctx, p->parent);
|
||||
if (!p) {
|
||||
pctx->ino = p->parent;
|
||||
fix_problem(ctx, PR_3_NO_DIRINFO, pctx);
|
||||
return 0;
|
||||
}
|
||||
ino = parent;
|
||||
if (loop_pass) {
|
||||
ext2fs_mark_inode_bitmap(inode_loop_detect,
|
||||
p->ino);
|
||||
ext2fs_mark_inode_bitmap(inode_loop_detect, ino);
|
||||
} else if (parent_count++ > 2048) {
|
||||
/*
|
||||
* If we've run into a path depth that's
|
||||
|
@ -346,7 +339,7 @@ static int check_directory(e2fsck_t ctx, struct dir_info *dir,
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
p = dir;
|
||||
ino = dir;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,12 +347,15 @@ static int check_directory(e2fsck_t ctx, struct dir_info *dir,
|
|||
* Make sure that .. and the parent directory are the same;
|
||||
* offer to fix it if not.
|
||||
*/
|
||||
if (dir->parent != dir->dotdot) {
|
||||
pctx->ino = dir->ino;
|
||||
pctx->ino2 = dir->dotdot;
|
||||
pctx->dir = dir->parent;
|
||||
pctx->ino = dir;
|
||||
if (e2fsck_dir_info_get_dotdot(ctx, dir, &pctx->ino2) ||
|
||||
e2fsck_dir_info_get_parent(ctx, dir, &pctx->dir)) {
|
||||
fix_problem(ctx, PR_3_NO_DIRINFO, pctx);
|
||||
return 0;
|
||||
}
|
||||
if (pctx->ino2 != pctx->dir) {
|
||||
if (fix_problem(ctx, PR_3_BAD_DOT_DOT, pctx))
|
||||
fix_dotdot(ctx, dir, dir->parent);
|
||||
fix_dotdot(ctx, dir, pctx->dir);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -378,7 +374,6 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
|
|||
char * block;
|
||||
static const char name[] = "lost+found";
|
||||
struct problem_context pctx;
|
||||
struct dir_info *dirinfo;
|
||||
|
||||
if (ctx->lost_and_found)
|
||||
return ctx->lost_and_found;
|
||||
|
@ -409,9 +404,7 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
|
|||
fix_problem(ctx, PR_3_CREATE_LPF_ERROR, &pctx);
|
||||
return 0;
|
||||
}
|
||||
dirinfo = e2fsck_get_dir_info(ctx, ino);
|
||||
if (dirinfo)
|
||||
dirinfo->parent = 0;
|
||||
(void) e2fsck_dir_info_set_parent(ctx, ino, 0);
|
||||
e2fsck_adjust_inode_count(ctx, ino, -1);
|
||||
} else if (retval != EXT2_ET_FILE_NOT_FOUND) {
|
||||
pctx.errcode = retval;
|
||||
|
@ -656,7 +649,7 @@ static int fix_dotdot_proc(struct ext2_dir_entry *dirent,
|
|||
return DIRENT_ABORT | DIRENT_CHANGED;
|
||||
}
|
||||
|
||||
static void fix_dotdot(e2fsck_t ctx, struct dir_info *dir, ext2_ino_t parent)
|
||||
static void fix_dotdot(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
|
||||
{
|
||||
ext2_filsys fs = ctx->fs;
|
||||
errcode_t retval;
|
||||
|
@ -669,21 +662,23 @@ static void fix_dotdot(e2fsck_t ctx, struct dir_info *dir, ext2_ino_t parent)
|
|||
fp.ctx = ctx;
|
||||
|
||||
#if 0
|
||||
printf("Fixing '..' of inode %lu to be %lu...\n", dir->ino, parent);
|
||||
printf("Fixing '..' of inode %lu to be %lu...\n", ino, parent);
|
||||
#endif
|
||||
|
||||
retval = ext2fs_dir_iterate(fs, dir->ino, DIRENT_FLAG_INCLUDE_EMPTY,
|
||||
clear_problem_context(&pctx);
|
||||
pctx.ino = ino;
|
||||
retval = ext2fs_dir_iterate(fs, ino, DIRENT_FLAG_INCLUDE_EMPTY,
|
||||
0, fix_dotdot_proc, &fp);
|
||||
if (retval || !fp.done) {
|
||||
clear_problem_context(&pctx);
|
||||
pctx.ino = dir->ino;
|
||||
pctx.errcode = retval;
|
||||
fix_problem(ctx, retval ? PR_3_FIX_PARENT_ERR :
|
||||
PR_3_FIX_PARENT_NOFIND, &pctx);
|
||||
ext2fs_unmark_valid(fs);
|
||||
}
|
||||
dir->dotdot = parent;
|
||||
|
||||
(void) e2fsck_dir_info_set_dotdot(ctx, ino, parent);
|
||||
if (e2fsck_dir_info_set_parent(ctx, ino, ctx->lost_and_found))
|
||||
fix_problem(ctx, PR_3_NO_DIRINFO, &pctx);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -772,9 +772,10 @@ void e2fsck_rehash_directories(e2fsck_t ctx)
|
|||
#endif
|
||||
struct dir_info *dir;
|
||||
ext2_u32_iterate iter;
|
||||
struct dir_info_iter * dirinfo_iter = 0;
|
||||
ext2_ino_t ino;
|
||||
errcode_t retval;
|
||||
int i, cur, max, all_dirs, dir_index, first = 1;
|
||||
int cur, max, all_dirs, dir_index, first = 1;
|
||||
|
||||
#ifdef RESOURCE_TRACK
|
||||
init_resource_track(&rtrack);
|
||||
|
@ -792,7 +793,7 @@ void e2fsck_rehash_directories(e2fsck_t ctx)
|
|||
dir_index = ctx->fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX;
|
||||
cur = 0;
|
||||
if (all_dirs) {
|
||||
i = 0;
|
||||
dirinfo_iter = e2fsck_dir_info_iter_begin(ctx);
|
||||
max = e2fsck_get_num_dirinfo(ctx);
|
||||
} else {
|
||||
retval = ext2fs_u32_list_iterate_begin(ctx->dirs_to_hash,
|
||||
|
@ -806,7 +807,8 @@ void e2fsck_rehash_directories(e2fsck_t ctx)
|
|||
}
|
||||
while (1) {
|
||||
if (all_dirs) {
|
||||
if ((dir = e2fsck_dir_info_iter(ctx, &i)) == 0)
|
||||
if ((dir = e2fsck_dir_info_iter(ctx,
|
||||
dirinfo_iter)) == 0)
|
||||
break;
|
||||
ino = dir->ino;
|
||||
} else {
|
||||
|
@ -833,7 +835,9 @@ void e2fsck_rehash_directories(e2fsck_t ctx)
|
|||
100.0 * (float) (++cur) / (float) max, ino);
|
||||
}
|
||||
end_problem_latch(ctx, PR_LATCH_OPTIMIZE_DIR);
|
||||
if (!all_dirs)
|
||||
if (all_dirs)
|
||||
e2fsck_dir_info_iter_end(ctx, dirinfo_iter);
|
||||
else
|
||||
ext2fs_u32_list_iterate_end(iter);
|
||||
|
||||
if (ctx->dirs_to_hash)
|
||||
|
|
Loading…
Reference in New Issue