1997-04-26 21:21:57 +08:00
|
|
|
/*
|
|
|
|
* dirinfo.c --- maintains the directory information table for e2fsck.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993 Theodore Ts'o. This file may be redistributed
|
|
|
|
* under the terms of the GNU Public License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "e2fsck.h"
|
|
|
|
|
|
|
|
/*
|
1997-04-30 00:15:03 +08:00
|
|
|
* This subroutine is called during pass1 to create a directory info
|
|
|
|
* entry. During pass1, the passed-in parent is 0; it will get filled
|
|
|
|
* in during pass2.
|
1997-04-26 21:21:57 +08:00
|
|
|
*/
|
1997-11-04 03:42:40 +08:00
|
|
|
void e2fsck_add_dir_info(e2fsck_t ctx, ino_t ino, ino_t parent)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
|
|
|
struct dir_info *dir;
|
1997-11-04 03:42:40 +08:00
|
|
|
int i, j;
|
Many files:
dblist.c (ext2fs_get_num_dirs): Make ext2fs_get_num_dirs more paranoid
about validating the directory counts from the block group
information.
all files: Don't include stdlib.h anymore; include it in ext2_fs.h,
since that file requires stdlib.h
ChangeLog, Makefile.in, dirinfo.c:
dirinfo.c (e2fsck_add_dir_info): Use ext2fs_get_num_dirs instead of
e2fsck_get_num_dirs, which has been removed.
Makefile.in (PROGS): Remove @EXTRA_PROGS@, since we don't want to
compile and install flushb.
ChangeLog, configure.in:
Remove @EXTRA_PROGS@, since we aren't using it in 2fsck/Makefile.in anymore
ChangeLog, Makefile.in:
Install debugfs in /sbin, instead of /usr/sbin.
libext2fs.texinfo:
Update version string to be 1.12
Makefile.in:
Fix bug in find script which made the exclusion list, where a '-' was
missing from an -name option.
1997-12-02 02:24:10 +08:00
|
|
|
ino_t num_dirs;
|
1997-11-04 03:42:40 +08:00
|
|
|
errcode_t retval;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
#if 0
|
1997-04-26 21:34:30 +08:00
|
|
|
printf("add_dir_info for inode %lu...\n", ino);
|
1997-04-26 21:21:57 +08:00
|
|
|
#endif
|
1997-11-04 03:42:40 +08:00
|
|
|
if (!ctx->dir_info) {
|
|
|
|
ctx->dir_info_count = 0;
|
Many files:
dblist.c (ext2fs_get_num_dirs): Make ext2fs_get_num_dirs more paranoid
about validating the directory counts from the block group
information.
all files: Don't include stdlib.h anymore; include it in ext2_fs.h,
since that file requires stdlib.h
ChangeLog, Makefile.in, dirinfo.c:
dirinfo.c (e2fsck_add_dir_info): Use ext2fs_get_num_dirs instead of
e2fsck_get_num_dirs, which has been removed.
Makefile.in (PROGS): Remove @EXTRA_PROGS@, since we don't want to
compile and install flushb.
ChangeLog, configure.in:
Remove @EXTRA_PROGS@, since we aren't using it in 2fsck/Makefile.in anymore
ChangeLog, Makefile.in:
Install debugfs in /sbin, instead of /usr/sbin.
libext2fs.texinfo:
Update version string to be 1.12
Makefile.in:
Fix bug in find script which made the exclusion list, where a '-' was
missing from an -name option.
1997-12-02 02:24:10 +08:00
|
|
|
retval = ext2fs_get_num_dirs(ctx->fs, &num_dirs);
|
|
|
|
if (retval)
|
|
|
|
num_dirs = 1024; /* Guess */
|
|
|
|
ctx->dir_info_size = num_dirs + 10;
|
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
|
|
|
ctx->dir_info = (struct dir_info *)
|
|
|
|
e2fsck_allocate_memory(ctx, ctx->dir_info_size
|
|
|
|
* sizeof (struct dir_info),
|
|
|
|
"directory map");
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
1997-11-04 03:42:40 +08:00
|
|
|
if (ctx->dir_info_count >= ctx->dir_info_size) {
|
|
|
|
ctx->dir_info_size += 10;
|
|
|
|
retval = ext2fs_resize_mem(ctx->dir_info_size *
|
|
|
|
sizeof(struct dir_info),
|
|
|
|
(void **) &ctx->dir_info);
|
|
|
|
if (retval) {
|
|
|
|
ctx->dir_info_size -= 10;
|
|
|
|
return;
|
|
|
|
}
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Normally, add_dir_info is called with each inode in
|
|
|
|
* sequential order; but once in a while (like when pass 3
|
|
|
|
* needs to recreate the root directory or lost+found
|
|
|
|
* directory) it is called out of order. In those cases, we
|
|
|
|
* need to move the dir_info entries down to make room, since
|
|
|
|
* the dir_info array needs to be sorted by inode number for
|
|
|
|
* get_dir_info()'s sake.
|
|
|
|
*/
|
1997-11-04 03:42:40 +08:00
|
|
|
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)
|
1997-04-26 21:21:57 +08:00
|
|
|
break;
|
1997-11-04 03:42:40 +08:00
|
|
|
dir = &ctx->dir_info[i];
|
1997-04-26 21:21:57 +08:00
|
|
|
if (dir->ino != ino)
|
1997-11-04 03:42:40 +08:00
|
|
|
for (j = ctx->dir_info_count++; j > i; j--)
|
|
|
|
ctx->dir_info[j] = ctx->dir_info[j-1];
|
1997-04-26 21:21:57 +08:00
|
|
|
} else
|
1997-11-04 03:42:40 +08:00
|
|
|
dir = &ctx->dir_info[ctx->dir_info_count++];
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
dir->ino = ino;
|
|
|
|
dir->dotdot = parent;
|
|
|
|
dir->parent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_dir_info() --- given an inode number, try to find the directory
|
|
|
|
* information entry for it.
|
|
|
|
*/
|
1997-11-04 03:42:40 +08:00
|
|
|
struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ino_t ino)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
|
|
|
int low, high, mid;
|
|
|
|
|
|
|
|
low = 0;
|
1997-11-04 03:42:40 +08:00
|
|
|
high = ctx->dir_info_count-1;
|
|
|
|
if (!ctx->dir_info)
|
1997-04-30 00:15:03 +08:00
|
|
|
return 0;
|
1997-11-04 03:42:40 +08:00
|
|
|
if (ino == ctx->dir_info[low].ino)
|
|
|
|
return &ctx->dir_info[low];
|
|
|
|
if (ino == ctx->dir_info[high].ino)
|
|
|
|
return &ctx->dir_info[high];
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
while (low < high) {
|
|
|
|
mid = (low+high)/2;
|
|
|
|
if (mid == low || mid == high)
|
|
|
|
break;
|
1997-11-04 03:42:40 +08:00
|
|
|
if (ino == ctx->dir_info[mid].ino)
|
|
|
|
return &ctx->dir_info[mid];
|
|
|
|
if (ino < ctx->dir_info[mid].ino)
|
1997-04-26 21:21:57 +08:00
|
|
|
high = mid;
|
|
|
|
else
|
|
|
|
low = mid;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free the dir_info structure when it isn't needed any more.
|
|
|
|
*/
|
1997-11-04 03:42:40 +08:00
|
|
|
void e2fsck_free_dir_info(e2fsck_t ctx)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
1997-11-04 03:42:40 +08:00
|
|
|
if (ctx->dir_info) {
|
|
|
|
ext2fs_free_mem((void **) &ctx->dir_info);
|
|
|
|
ctx->dir_info = 0;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
1997-11-04 03:42:40 +08:00
|
|
|
ctx->dir_info_size = 0;
|
|
|
|
ctx->dir_info_count = 0;
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
1997-04-30 00:15:03 +08:00
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Return the count of number of directories in the dir_info structure
|
|
|
|
*/
|
|
|
|
int e2fsck_get_num_dirinfo(e2fsck_t ctx)
|
|
|
|
{
|
|
|
|
return ctx->dir_info_count;
|
|
|
|
}
|
|
|
|
|
1997-04-30 00:15:03 +08:00
|
|
|
/*
|
|
|
|
* A simple interator function
|
|
|
|
*/
|
1997-11-04 03:42:40 +08:00
|
|
|
struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, int *control)
|
1997-04-30 00:15:03 +08:00
|
|
|
{
|
1997-11-04 03:42:40 +08:00
|
|
|
if (*control >= ctx->dir_info_count)
|
1997-04-30 00:15:03 +08:00
|
|
|
return 0;
|
|
|
|
|
1997-11-04 03:42:40 +08:00
|
|
|
return(ctx->dir_info + (*control)++);
|
1997-04-30 00:15:03 +08:00
|
|
|
}
|