summaryrefslogtreecommitdiff
path: root/e2fsck/dirinfo.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>1997-11-03 19:42:40 +0000
committerTheodore Ts'o <tytso@mit.edu>1997-11-03 19:42:40 +0000
commit08b213017f8371ce4b56ad4d368eb0f92211d04e (patch)
tree4ea99c73df01b238ac33cad38b6b955f330450ee /e2fsck/dirinfo.c
parent79a90bdad033e101c38bb3c3207c8f4be47a2de7 (diff)
downloade2fsprogs-08b213017f8371ce4b56ad4d368eb0f92211d04e.tar.gz
Many files:
Change ext2fs_read_inode, ext2fs_write_inode to take the e2fsck context as their first argument. Change dir_info.c routines to take an e2fsck_context, renamed them to start with e2fsck_ to avoid namespace issues, and changed them to store the directory information inside the e2fsck context. Added e2fsck_run() which calls all of the e2fsck passes in the correct order, and which handles the return of abort codes. Added abort processing, both via setjmp/longjmp and via flags in the e2fsck context. Use a flag in the e2fsck context instead of the restart_e2fsck global variable. Change uses of free and malloc to ext2fs_free_mem and ext2fs_get_mem.
Diffstat (limited to 'e2fsck/dirinfo.c')
-rw-r--r--e2fsck/dirinfo.c90
1 files changed, 47 insertions, 43 deletions
diff --git a/e2fsck/dirinfo.c b/e2fsck/dirinfo.c
index 5218234c..8d37544e 100644
--- a/e2fsck/dirinfo.c
+++ b/e2fsck/dirinfo.c
@@ -8,12 +8,9 @@
#include <et/com_err.h>
#include "e2fsck.h"
-static int dir_info_count = 0;
-static int dir_info_size = 0;
-static struct dir_info *dir_info = 0;
-
-int get_num_dirs(ext2_filsys fs)
+int e2fsck_get_num_dirs(e2fsck_t ctx)
{
+ ext2_filsys fs = ctx->fs;
int i, num_dirs;
num_dirs = 0;
@@ -28,27 +25,33 @@ int get_num_dirs(ext2_filsys fs)
* entry. During pass1, the passed-in parent is 0; it will get filled
* in during pass2.
*/
-void add_dir_info(ext2_filsys fs, ino_t ino, ino_t parent)
+void e2fsck_add_dir_info(e2fsck_t ctx, ino_t ino, ino_t parent)
{
struct dir_info *dir;
- int i, j;
+ int i, j;
+ errcode_t retval;
#if 0
printf("add_dir_info for inode %lu...\n", ino);
#endif
- if (!dir_info) {
- dir_info_count = 0;
- dir_info_size = get_num_dirs(fs) + 10;
+ if (!ctx->dir_info) {
+ ctx->dir_info_count = 0;
+ ctx->dir_info_size = e2fsck_get_num_dirs(ctx) + 10;
- dir_info = allocate_memory(dir_info_size *
- sizeof (struct dir_info),
- "directory map");
+ ctx->dir_info = allocate_memory(ctx->dir_info_size *
+ sizeof (struct dir_info),
+ "directory map");
}
- if (dir_info_count >= dir_info_size) {
- dir_info_size += 10;
- dir_info = realloc(dir_info,
- dir_info_size * sizeof(struct dir_info));
+ 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;
+ }
}
/*
@@ -60,16 +63,17 @@ void add_dir_info(ext2_filsys fs, ino_t ino, ino_t parent)
* the dir_info array needs to be sorted by inode number for
* get_dir_info()'s sake.
*/
- if (dir_info_count && dir_info[dir_info_count-1].ino >= ino) {
- for (i = dir_info_count-1; i > 0; i--)
- if (dir_info[i-1].ino < ino)
+ 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)
break;
- dir = &dir_info[i];
+ dir = &ctx->dir_info[i];
if (dir->ino != ino)
- for (j = dir_info_count++; j > i; j--)
- dir_info[j] = dir_info[j-1];
+ for (j = ctx->dir_info_count++; j > i; j--)
+ ctx->dir_info[j] = ctx->dir_info[j-1];
} else
- dir = &dir_info[dir_info_count++];
+ dir = &ctx->dir_info[ctx->dir_info_count++];
dir->ino = ino;
dir->dotdot = parent;
@@ -80,26 +84,26 @@ void add_dir_info(ext2_filsys fs, ino_t ino, ino_t parent)
* get_dir_info() --- given an inode number, try to find the directory
* information entry for it.
*/
-struct dir_info *get_dir_info(ino_t ino)
+struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ino_t ino)
{
int low, high, mid;
low = 0;
- high = dir_info_count-1;
- if (!dir_info)
+ high = ctx->dir_info_count-1;
+ if (!ctx->dir_info)
return 0;
- if (ino == dir_info[low].ino)
- return &dir_info[low];
- if (ino == dir_info[high].ino)
- return &dir_info[high];
+ if (ino == ctx->dir_info[low].ino)
+ return &ctx->dir_info[low];
+ if (ino == ctx->dir_info[high].ino)
+ return &ctx->dir_info[high];
while (low < high) {
mid = (low+high)/2;
if (mid == low || mid == high)
break;
- if (ino == dir_info[mid].ino)
- return &dir_info[mid];
- if (ino < dir_info[mid].ino)
+ if (ino == ctx->dir_info[mid].ino)
+ return &ctx->dir_info[mid];
+ if (ino < ctx->dir_info[mid].ino)
high = mid;
else
low = mid;
@@ -110,23 +114,23 @@ struct dir_info *get_dir_info(ino_t ino)
/*
* Free the dir_info structure when it isn't needed any more.
*/
-void free_dir_info(ext2_filsys fs)
+void e2fsck_free_dir_info(e2fsck_t ctx)
{
- if (dir_info) {
- free(dir_info);
- dir_info = 0;
+ if (ctx->dir_info) {
+ ext2fs_free_mem((void **) &ctx->dir_info);
+ ctx->dir_info = 0;
}
- dir_info_size = 0;
- dir_info_count = 0;
+ ctx->dir_info_size = 0;
+ ctx->dir_info_count = 0;
}
/*
* A simple interator function
*/
-struct dir_info *dir_info_iter(int *control)
+struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, int *control)
{
- if (*control >= dir_info_count)
+ if (*control >= ctx->dir_info_count)
return 0;
- return(dir_info + (*control)++);
+ return(ctx->dir_info + (*control)++);
}