+/* vi: set sw=4 ts=4: */
/*
* e2fsck
*
- * Copyright (C) 1993, 1994 Theodore Ts'o. This file may be
- * redistributed under the terms of the GNU Public License.
- *
- */
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1 /* get strnlen() */
-#endif
-#include <sys/types.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <time.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <setjmp.h>
-#include <errno.h>
-#include <getopt.h>
-#include <limits.h>
-#include <stddef.h>
-#include <assert.h>
-#include <signal.h>
-#include <sys/time.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
-#include <sys/param.h>
-#include <sys/mount.h>
-#include <sys/ioctl.h>
-#include <malloc.h>
-#include <termios.h>
-#include <mntent.h>
-#include <dirent.h>
-
-#include "e2fsbb.h"
-
-#include "ext2fs/ext2_fs.h"
-#include "ext2fs/ext2fs.h"
-#include "blkid/blkid.h"
-#include "ext2fs/ext2_ext_attr.h"
-#include "uuid/uuid.h"
-
-#ifdef __GNUC__
-#define _INLINE_ __inline__
-#define EXT2FS_ATTR(x) __attribute__(x)
-#else
-#define _INLINE_
-#define EXT2FS_ATTR(x)
-#endif
-
-/*
- * Exit codes used by fsck-type programs
- */
-#define FSCK_OK 0 /* No errors */
-#define FSCK_NONDESTRUCT 1 /* File system errors corrected */
-#define FSCK_REBOOT 2 /* System should be rebooted */
-#define FSCK_UNCORRECTED 4 /* File system errors left uncorrected */
-#define FSCK_ERROR 8 /* Operational error */
-#define FSCK_USAGE 16 /* Usage or syntax error */
-#define FSCK_CANCELED 32 /* Aborted with a signal or ^C */
-#define FSCK_LIBRARY 128 /* Shared library error */
-
-/*
- * The last ext2fs revision level that this version of e2fsck is able to
- * support
- */
-#define E2FSCK_CURRENT_REV 1
-
-/*
- * The directory information structure; stores directory information
- * collected in earlier passes, to avoid disk i/o in fetching the
- * directory information.
- */
-struct dir_info {
- ext2_ino_t ino; /* Inode number */
- ext2_ino_t dotdot; /* Parent according to '..' */
- ext2_ino_t parent; /* Parent according to treewalk */
-};
-
-
-/*
- * The indexed directory information structure; stores information for
- * directories which contain a hash tree index.
- */
-struct dx_dir_info {
- ext2_ino_t ino; /* Inode number */
- int numblocks; /* number of blocks */
- int hashversion;
- short depth; /* depth of tree */
- struct dx_dirblock_info *dx_block; /* Array of size numblocks */
-};
-
-#define DX_DIRBLOCK_ROOT 1
-#define DX_DIRBLOCK_LEAF 2
-#define DX_DIRBLOCK_NODE 3
-#define DX_DIRBLOCK_CORRUPT 4
-#define DX_DIRBLOCK_CLEARED 8
-
-struct dx_dirblock_info {
- int type;
- blk_t phys;
- int flags;
- blk_t parent;
- ext2_dirhash_t min_hash;
- ext2_dirhash_t max_hash;
- ext2_dirhash_t node_min_hash;
- ext2_dirhash_t node_max_hash;
-};
-
-#define DX_FLAG_REFERENCED 1
-#define DX_FLAG_DUP_REF 2
-#define DX_FLAG_FIRST 4
-#define DX_FLAG_LAST 8
-
-#ifdef RESOURCE_TRACK
-/*
- * This structure is used for keeping track of how much resources have
- * been used for a particular pass of e2fsck.
- */
-struct resource_track {
- struct timeval time_start;
- struct timeval user_start;
- struct timeval system_start;
- void *brk_start;
-};
-#endif
-
-/*
- * E2fsck options
- */
-#define E2F_OPT_READONLY 0x0001
-#define E2F_OPT_PREEN 0x0002
-#define E2F_OPT_YES 0x0004
-#define E2F_OPT_NO 0x0008
-#define E2F_OPT_TIME 0x0010
-#define E2F_OPT_TIME2 0x0020
-#define E2F_OPT_CHECKBLOCKS 0x0040
-#define E2F_OPT_DEBUG 0x0080
-#define E2F_OPT_FORCE 0x0100
-#define E2F_OPT_WRITECHECK 0x0200
-#define E2F_OPT_COMPRESS_DIRS 0x0400
-
-/*
- * E2fsck flags
- */
-#define E2F_FLAG_ABORT 0x0001 /* Abort signaled */
-#define E2F_FLAG_CANCEL 0x0002 /* Cancel signaled */
-#define E2F_FLAG_SIGNAL_MASK 0x0003
-#define E2F_FLAG_RESTART 0x0004 /* Restart signaled */
-
-#define E2F_FLAG_SETJMP_OK 0x0010 /* Setjmp valid for abort */
-
-#define E2F_FLAG_PROG_BAR 0x0020 /* Progress bar on screen */
-#define E2F_FLAG_PROG_SUPPRESS 0x0040 /* Progress suspended */
-#define E2F_FLAG_JOURNAL_INODE 0x0080 /* Create a new ext3 journal inode */
-#define E2F_FLAG_SB_SPECIFIED 0x0100 /* The superblock was explicitly
- * specified by the user */
-#define E2F_FLAG_RESTARTED 0x0200 /* E2fsck has been restarted */
-#define E2F_FLAG_RESIZE_INODE 0x0400 /* Request to recreate resize inode */
-
-/*
- * Defines for indicating the e2fsck pass number
- */
-#define E2F_PASS_1 1
-#define E2F_PASS_2 2
-#define E2F_PASS_3 3
-#define E2F_PASS_4 4
-#define E2F_PASS_5 5
-#define E2F_PASS_1B 6
-
-/*
- * Define the extended attribute refcount structure
- */
-typedef struct ea_refcount *ext2_refcount_t;
-
-/*
- * This is the global e2fsck structure.
- */
-typedef struct e2fsck_struct *e2fsck_t;
-
-struct e2fsck_struct {
- ext2_filsys fs;
- const char *program_name;
- char *filesystem_name;
- char *device_name;
- char *io_options;
- int flags; /* E2fsck internal flags */
- int options;
- blk_t use_superblock; /* sb requested by user */
- blk_t superblock; /* sb used to open fs */
- int blocksize; /* blocksize */
- blk_t num_blocks; /* Total number of blocks */
- int mount_flags;
- blkid_cache blkid; /* blkid cache */
-
- jmp_buf abort_loc;
-
- unsigned long abort_code;
-
- int (*progress)(e2fsck_t ctx, int pass, unsigned long cur,
- unsigned long max);
-
- ext2fs_inode_bitmap inode_used_map; /* Inodes which are in use */
- ext2fs_inode_bitmap inode_bad_map; /* Inodes which are bad somehow */
- ext2fs_inode_bitmap inode_dir_map; /* Inodes which are directories */
- ext2fs_inode_bitmap inode_bb_map; /* Inodes which are in bad blocks */
- ext2fs_inode_bitmap inode_imagic_map; /* AFS inodes */
- ext2fs_inode_bitmap inode_reg_map; /* Inodes which are regular files*/
-
- ext2fs_block_bitmap block_found_map; /* Blocks which are in use */
- ext2fs_block_bitmap block_dup_map; /* Blks referenced more than once */
- ext2fs_block_bitmap block_ea_map; /* Blocks which are used by EA's */
-
- /*
- * Inode count arrays
- */
- ext2_icount_t inode_count;
- ext2_icount_t inode_link_info;
-
- ext2_refcount_t refcount;
- ext2_refcount_t refcount_extra;
-
- /*
- * Array of flags indicating whether an inode bitmap, block
- * bitmap, or inode table is invalid
- */
- int *invalid_inode_bitmap_flag;
- int *invalid_block_bitmap_flag;
- int *invalid_inode_table_flag;
- int invalid_bitmaps; /* There are invalid bitmaps/itable */
-
- /*
- * Block buffer
- */
- char *block_buf;
-
- /*
- * For pass1_check_directory and pass1_get_blocks
- */
- ext2_ino_t stashed_ino;
- struct ext2_inode *stashed_inode;
-
- /*
- * Location of the lost and found directory
- */
- ext2_ino_t lost_and_found;
- int bad_lost_and_found;
-
- /*
- * Directory information
- */
- int dir_info_count;
- int dir_info_size;
- struct dir_info *dir_info;
-
- /*
- * Indexed directory information
- */
- int dx_dir_info_count;
- int dx_dir_info_size;
- struct dx_dir_info *dx_dir_info;
-
- /*
- * Directories to hash
- */
- ext2_u32_list dirs_to_hash;
-
- /*
- * Tuning parameters
- */
- int process_inode_size;
- int inode_buffer_blocks;
-
- /*
- * ext3 journal support
- */
- io_channel journal_io;
- char *journal_name;
-
-#ifdef RESOURCE_TRACK
- /*
- * For timing purposes
- */
- struct resource_track global_rtrack;
-#endif
-
- /*
- * How we display the progress update (for unix)
- */
- int progress_fd;
- int progress_pos;
- int progress_last_percent;
- unsigned int progress_last_time;
- int interactive; /* Are we connected directly to a tty? */
- char start_meta[2], stop_meta[2];
-
- /* File counts */
- int fs_directory_count;
- int fs_regular_count;
- int fs_blockdev_count;
- int fs_chardev_count;
- int fs_links_count;
- int fs_symlinks_count;
- int fs_fast_symlinks_count;
- int fs_fifo_count;
- int fs_total_count;
- int fs_badblocks_count;
- int fs_sockets_count;
- int fs_ind_count;
- int fs_dind_count;
- int fs_tind_count;
- int fs_fragmented;
- int large_files;
- int fs_ext_attr_inodes;
- int fs_ext_attr_blocks;
-
- int ext_attr_ver;
-
- /*
- * For the use of callers of the e2fsck functions; not used by
- * e2fsck functions themselves.
- */
- void *priv_data;
-};
-
-/* Used by the region allocation code */
-typedef __u32 region_addr_t;
-typedef struct region_struct *region_t;
-
-/*
- * Procedure declarations
- */
-
-static void e2fsck_pass1(e2fsck_t ctx);
-static void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf);
-static void e2fsck_pass2(e2fsck_t ctx);
-static void e2fsck_pass3(e2fsck_t ctx);
-static void e2fsck_pass4(e2fsck_t ctx);
-static void e2fsck_pass5(e2fsck_t ctx);
-
-/* e2fsck.c */
-static errcode_t e2fsck_allocate_context(e2fsck_t *ret);
-static errcode_t e2fsck_reset_context(e2fsck_t ctx);
-static void e2fsck_free_context(e2fsck_t ctx);
-static int e2fsck_run(e2fsck_t ctx);
-
-
-/* badblock.c */
-static void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
- int replace_bad_blocks);
-
-/* dirinfo.c */
-static void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent);
-static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino);
-static void e2fsck_free_dir_info(e2fsck_t ctx);
-static int e2fsck_get_num_dirinfo(e2fsck_t ctx);
-static struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, int *control);
-
-/* dx_dirinfo.c */
-static void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, int num_blocks);
-static struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino);
-static void e2fsck_free_dx_dir_info(e2fsck_t ctx);
-static struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, int *control);
-
-/* ea_refcount.c */
-static errcode_t ea_refcount_create(int size, ext2_refcount_t *ret);
-static void ea_refcount_free(ext2_refcount_t refcount);
-static errcode_t ea_refcount_increment(ext2_refcount_t refcount,
- blk_t blk, int *ret);
-static errcode_t ea_refcount_decrement(ext2_refcount_t refcount,
- blk_t blk, int *ret);
-static errcode_t ea_refcount_store(ext2_refcount_t refcount,
- blk_t blk, int count);
-static void ea_refcount_intr_begin(ext2_refcount_t refcount);
-static blk_t ea_refcount_intr_next(ext2_refcount_t refcount, int *ret);
-
-/* ehandler.c */
-static const char *ehandler_operation(const char *op);
-static void ehandler_init(io_channel channel);
-
-/* journal.c */
-static int e2fsck_check_ext3_journal(e2fsck_t ctx);
-static int e2fsck_run_ext3_journal(e2fsck_t ctx);
-static void e2fsck_move_ext3_journal(e2fsck_t ctx);
-
-/* pass1.c */
-static void e2fsck_use_inode_shortcuts(e2fsck_t ctx, int bool);
-static int e2fsck_pass1_check_device_inode(ext2_filsys fs,
- struct ext2_inode *inode);
-static int e2fsck_pass1_check_symlink(ext2_filsys fs,
- struct ext2_inode *inode, char *buf);
-
-/* pass2.c */
-static int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,
- ext2_ino_t ino, char *buf);
-
-/* pass3.c */
-static int e2fsck_reconnect_file(e2fsck_t ctx, ext2_ino_t inode);
-static errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
- int num, int gauranteed_size);
-static ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix);
-static errcode_t e2fsck_adjust_inode_count(e2fsck_t ctx, ext2_ino_t ino,
- int adj);
-
-
-/* region.c */
-static region_t region_create(region_addr_t min, region_addr_t max);
-static void region_free(region_t region);
-static int region_allocate(region_t region, region_addr_t start, int n);
-
-/* rehash.c */
-static errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino);
-static void e2fsck_rehash_directories(e2fsck_t ctx);
-
-/* super.c */
-static void check_super_block(e2fsck_t ctx);
-static errcode_t e2fsck_get_device_size(e2fsck_t ctx);
-
-#ifdef ENABLE_SWAPFS
-/* swapfs.c */
-static void swap_filesys(e2fsck_t ctx);
-#endif
-
-/* util.c */
-static void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
- const char *description);
-static int ask(e2fsck_t ctx, const char * string, int def);
-static int ask_yn(const char * string, int def);
-static void e2fsck_read_bitmaps(e2fsck_t ctx);
-static void e2fsck_write_bitmaps(e2fsck_t ctx);
-static void preenhalt(e2fsck_t ctx);
-static char *string_copy(e2fsck_t ctx, const char *str, int len);
-#ifdef RESOURCE_TRACK
-static void print_resource_track(const char *desc,
- struct resource_track *track);
-static void init_resource_track(struct resource_track *track);
-#endif
-static void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
- struct ext2_inode * inode, const char * proc);
-static void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
- struct ext2_inode * inode, const char * proc);
-#ifdef MTRACE
-static void mtrace_print(char *mesg);
-#endif
-static blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs,
- const char *name, io_manager manager);
-static int ext2_file_type(unsigned int mode);
-
-/* unix.c */
-static void e2fsck_clear_progbar(e2fsck_t ctx);
-static int e2fsck_simple_progress(e2fsck_t ctx, const char *label,
- float percent, unsigned int dpynum);
-/*
- * problem.h --- e2fsck problem error codes
- */
-
-typedef __u32 problem_t;
-
-struct problem_context {
- errcode_t errcode;
- ext2_ino_t ino, ino2, dir;
- struct ext2_inode *inode;
- struct ext2_dir_entry *dirent;
- blk_t blk, blk2;
- e2_blkcnt_t blkcount;
- int group;
- __u64 num;
- const char *str;
-};
-
-/*
- * We define a set of "latch groups"; these are problems which are
- * handled as a set. The user answers once for a particular latch
- * group.
- */
-#define PR_LATCH_MASK 0x0ff0 /* Latch mask */
-#define PR_LATCH_BLOCK 0x0010 /* Latch for illegal blocks (pass 1) */
-#define PR_LATCH_BBLOCK 0x0020 /* Latch for bad block inode blocks (pass 1) */
-#define PR_LATCH_IBITMAP 0x0030 /* Latch for pass 5 inode bitmap proc. */
-#define PR_LATCH_BBITMAP 0x0040 /* Latch for pass 5 inode bitmap proc. */
-#define PR_LATCH_RELOC 0x0050 /* Latch for superblock relocate hint */
-#define PR_LATCH_DBLOCK 0x0060 /* Latch for pass 1b dup block headers */
-#define PR_LATCH_LOW_DTIME 0x0070 /* Latch for pass1 orphaned list refugees */
-#define PR_LATCH_TOOBIG 0x0080 /* Latch for file to big errors */
-#define PR_LATCH_OPTIMIZE_DIR 0x0090 /* Latch for optimize directories */
-
-#define PR_LATCH(x) ((((x) & PR_LATCH_MASK) >> 4) - 1)
-
-/*
- * Latch group descriptor flags
- */
-#define PRL_YES 0x0001 /* Answer yes */
-#define PRL_NO 0x0002 /* Answer no */
-#define PRL_LATCHED 0x0004 /* The latch group is latched */
-#define PRL_SUPPRESS 0x0008 /* Suppress all latch group questions */
-
-#define PRL_VARIABLE 0x000f /* All the flags that need to be reset */
-
-/*
- * Pre-Pass 1 errors
- */
-
-/* Block bitmap not in group */
-#define PR_0_BB_NOT_GROUP 0x000001
-
-/* Inode bitmap not in group */
-#define PR_0_IB_NOT_GROUP 0x000002
-
-/* Inode table not in group */
-#define PR_0_ITABLE_NOT_GROUP 0x000003
-
-/* Superblock corrupt */
-#define PR_0_SB_CORRUPT 0x000004
-
-/* Filesystem size is wrong */
-#define PR_0_FS_SIZE_WRONG 0x000005
-
-/* Fragments not supported */
-#define PR_0_NO_FRAGMENTS 0x000006
-
-/* Bad blocks_per_group */
-#define PR_0_BLOCKS_PER_GROUP 0x000007
-
-/* Bad first_data_block */
-#define PR_0_FIRST_DATA_BLOCK 0x000008
-
-/* Adding UUID to filesystem */
-#define PR_0_ADD_UUID 0x000009
-
-/* Relocate hint */
-#define PR_0_RELOCATE_HINT 0x00000A
-
-/* Miscellaneous superblock corruption */
-#define PR_0_MISC_CORRUPT_SUPER 0x00000B
-
-/* Error determing physical device size of filesystem */
-#define PR_0_GETSIZE_ERROR 0x00000C
-
-/* Inode count in the superblock incorrect */
-#define PR_0_INODE_COUNT_WRONG 0x00000D
-
-/* The Hurd does not support the filetype feature */
-#define PR_0_HURD_CLEAR_FILETYPE 0x00000E
-
-/* Journal inode is invalid */
-#define PR_0_JOURNAL_BAD_INODE 0x00000F
-
-/* The external journal has multiple filesystems (which we can't handle yet) */
-#define PR_0_JOURNAL_UNSUPP_MULTIFS 0x000010
-
-/* Can't find external journal */
-#define PR_0_CANT_FIND_JOURNAL 0x000011
-
-/* External journal has bad superblock */
-#define PR_0_EXT_JOURNAL_BAD_SUPER 0x000012
-
-/* Superblock has a bad journal UUID */
-#define PR_0_JOURNAL_BAD_UUID 0x000013
-
-/* Journal has an unknown superblock type */
-#define PR_0_JOURNAL_UNSUPP_SUPER 0x000014
-
-/* Journal superblock is corrupt */
-#define PR_0_JOURNAL_BAD_SUPER 0x000015
-
-/* Journal superblock is corrupt */
-#define PR_0_JOURNAL_HAS_JOURNAL 0x000016
-
-/* Superblock has recovery flag set but no journal */
-#define PR_0_JOURNAL_RECOVER_SET 0x000017
-
-/* Journal has data, but recovery flag is clear */
-#define PR_0_JOURNAL_RECOVERY_CLEAR 0x000018
-
-/* Ask if we should clear the journal */
-#define PR_0_JOURNAL_RESET_JOURNAL 0x000019
-
-/* Filesystem revision is 0, but feature flags are set */
-#define PR_0_FS_REV_LEVEL 0x00001A
-
-/* Clearing orphan inode */
-#define PR_0_ORPHAN_CLEAR_INODE 0x000020
-
-/* Illegal block found in orphaned inode */
-#define PR_0_ORPHAN_ILLEGAL_BLOCK_NUM 0x000021
-
-/* Already cleared block found in orphaned inode */
-#define PR_0_ORPHAN_ALREADY_CLEARED_BLOCK 0x000022
-
-/* Illegal orphan inode in superblock */
-#define PR_0_ORPHAN_ILLEGAL_HEAD_INODE 0x000023
-
-/* Illegal inode in orphaned inode list */
-#define PR_0_ORPHAN_ILLEGAL_INODE 0x000024
-
-/* Journal has unsupported read-only feature - abort */
-#define PR_0_JOURNAL_UNSUPP_ROCOMPAT 0x000025
-
-/* Journal has unsupported incompatible feature - abort */
-#define PR_0_JOURNAL_UNSUPP_INCOMPAT 0x000026
-
-/* Journal has unsupported version number */
-#define PR_0_JOURNAL_UNSUPP_VERSION 0x000027
-
-/* Moving journal to hidden file */
-#define PR_0_MOVE_JOURNAL 0x000028
-
-/* Error moving journal */
-#define PR_0_ERR_MOVE_JOURNAL 0x000029
-
-/* Clearing V2 journal superblock */
-#define PR_0_CLEAR_V2_JOURNAL 0x00002A
-
-/* Run journal anyway */
-#define PR_0_JOURNAL_RUN 0x00002B
-
-/* Run journal anyway by default */
-#define PR_0_JOURNAL_RUN_DEFAULT 0x00002C
-
-/* Backup journal inode blocks */
-#define PR_0_BACKUP_JNL 0x00002D
-
-/* Reserved blocks w/o resize_inode */
-#define PR_0_NONZERO_RESERVED_GDT_BLOCKS 0x00002E
-
-/* Resize_inode not enabled, but resize inode is non-zero */
-#define PR_0_CLEAR_RESIZE_INODE 0x00002F
-
-/* Resize inode invalid */
-#define PR_0_RESIZE_INODE_INVALID 0x000030
-
-/*
- * Pass 1 errors
- */
-
-/* Pass 1: Checking inodes, blocks, and sizes */
-#define PR_1_PASS_HEADER 0x010000
-
-/* Root directory is not an inode */
-#define PR_1_ROOT_NO_DIR 0x010001
-
-/* Root directory has dtime set */
-#define PR_1_ROOT_DTIME 0x010002
-
-/* Reserved inode has bad mode */
-#define PR_1_RESERVED_BAD_MODE 0x010003
-
-/* Deleted inode has zero dtime */
-#define PR_1_ZERO_DTIME 0x010004
-
-/* Inode in use, but dtime set */
-#define PR_1_SET_DTIME 0x010005
-
-/* Zero-length directory */
-#define PR_1_ZERO_LENGTH_DIR 0x010006
-
-/* Block bitmap conflicts with some other fs block */
-#define PR_1_BB_CONFLICT 0x010007
-
-/* Inode bitmap conflicts with some other fs block */
-#define PR_1_IB_CONFLICT 0x010008
-
-/* Inode table conflicts with some other fs block */
-#define PR_1_ITABLE_CONFLICT 0x010009
-
-/* Block bitmap is on a bad block */
-#define PR_1_BB_BAD_BLOCK 0x01000A
-
-/* Inode bitmap is on a bad block */
-#define PR_1_IB_BAD_BLOCK 0x01000B
-
-/* Inode has incorrect i_size */
-#define PR_1_BAD_I_SIZE 0x01000C
-
-/* Inode has incorrect i_blocks */
-#define PR_1_BAD_I_BLOCKS 0x01000D
-
-/* Illegal block number in inode */
-#define PR_1_ILLEGAL_BLOCK_NUM 0x01000E
-
-/* Block number overlaps fs metadata */
-#define PR_1_BLOCK_OVERLAPS_METADATA 0x01000F
-
-/* Inode has illegal blocks (latch question) */
-#define PR_1_INODE_BLOCK_LATCH 0x010010
-
-/* Too many bad blocks in inode */
-#define PR_1_TOO_MANY_BAD_BLOCKS 0x010011
-
-/* Illegal block number in bad block inode */
-#define PR_1_BB_ILLEGAL_BLOCK_NUM 0x010012
-
-/* Bad block inode has illegal blocks (latch question) */
-#define PR_1_INODE_BBLOCK_LATCH 0x010013
-
-/* Duplicate or bad blocks in use! */
-#define PR_1_DUP_BLOCKS_PREENSTOP 0x010014
-
-/* Bad block used as bad block indirect block */
-#define PR_1_BBINODE_BAD_METABLOCK 0x010015
-
-/* Inconsistency can't be fixed prompt */
-#define PR_1_BBINODE_BAD_METABLOCK_PROMPT 0x010016
-
-/* Bad primary block */
-#define PR_1_BAD_PRIMARY_BLOCK 0x010017
-
-/* Bad primary block prompt */
-#define PR_1_BAD_PRIMARY_BLOCK_PROMPT 0x010018
-
-/* Bad primary superblock */
-#define PR_1_BAD_PRIMARY_SUPERBLOCK 0x010019
-
-/* Bad primary block group descriptors */
-#define PR_1_BAD_PRIMARY_GROUP_DESCRIPTOR 0x01001A
-
-/* Bad superblock in group */
-#define PR_1_BAD_SUPERBLOCK 0x01001B
-
-/* Bad block group descriptors in group */
-#define PR_1_BAD_GROUP_DESCRIPTORS 0x01001C
-
-/* Block claimed for no reason */
-#define PR_1_PROGERR_CLAIMED_BLOCK 0x01001D
-
-/* Error allocating blocks for relocating metadata */
-#define PR_1_RELOC_BLOCK_ALLOCATE 0x01001E
-
-/* Error allocating block buffer during relocation process */
-#define PR_1_RELOC_MEMORY_ALLOCATE 0x01001F
-
-/* Relocating metadata group information from X to Y */
-#define PR_1_RELOC_FROM_TO 0x010020
-
-/* Relocating metatdata group information to X */
-#define PR_1_RELOC_TO 0x010021
-
-/* Block read error during relocation process */
-#define PR_1_RELOC_READ_ERR 0x010022
-
-/* Block write error during relocation process */
-#define PR_1_RELOC_WRITE_ERR 0x010023
-
-/* Error allocating inode bitmap */
-#define PR_1_ALLOCATE_IBITMAP_ERROR 0x010024
-
-/* Error allocating block bitmap */
-#define PR_1_ALLOCATE_BBITMAP_ERROR 0x010025
-
-/* Error allocating icount structure */
-#define PR_1_ALLOCATE_ICOUNT 0x010026
-
-/* Error allocating dbcount */
-#define PR_1_ALLOCATE_DBCOUNT 0x010027
-
-/* Error while scanning inodes */
-#define PR_1_ISCAN_ERROR 0x010028
-
-/* Error while iterating over blocks */
-#define PR_1_BLOCK_ITERATE 0x010029
-
-/* Error while storing inode count information */
-#define PR_1_ICOUNT_STORE 0x01002A
-
-/* Error while storing directory block information */
-#define PR_1_ADD_DBLOCK 0x01002B
-
-/* Error while reading inode (for clearing) */
-#define PR_1_READ_INODE 0x01002C
-
-/* Suppress messages prompt */
-#define PR_1_SUPPRESS_MESSAGES 0x01002D
-
-/* Imagic flag set on an inode when filesystem doesn't support it */
-#define PR_1_SET_IMAGIC 0x01002F
-
-/* Immutable flag set on a device or socket inode */
-#define PR_1_SET_IMMUTABLE 0x010030
-
-/* Compression flag set on a non-compressed filesystem */
-#define PR_1_COMPR_SET 0x010031
-
-/* Non-zero size on on device, fifo or socket inode */
-#define PR_1_SET_NONZSIZE 0x010032
-
-/* Filesystem revision is 0, but feature flags are set */
-#define PR_1_FS_REV_LEVEL 0x010033
-
-/* Journal inode not in use, needs clearing */
-#define PR_1_JOURNAL_INODE_NOT_CLEAR 0x010034
-
-/* Journal inode has wrong mode */
-#define PR_1_JOURNAL_BAD_MODE 0x010035
-
-/* Inode that was part of orphan linked list */
-#define PR_1_LOW_DTIME 0x010036
-
-/* Latch question which asks how to deal with low dtime inodes */
-#define PR_1_ORPHAN_LIST_REFUGEES 0x010037
-
-/* Error allocating refcount structure */
-#define PR_1_ALLOCATE_REFCOUNT 0x010038
-
-/* Error reading Extended Attribute block */
-#define PR_1_READ_EA_BLOCK 0x010039
-
-/* Invalid Extended Attribute block */
-#define PR_1_BAD_EA_BLOCK 0x01003A
-
-/* Error reading Extended Attribute block while fixing refcount -- abort */
-#define PR_1_EXTATTR_READ_ABORT 0x01003B
-
-/* Extended attribute reference count incorrect */
-#define PR_1_EXTATTR_REFCOUNT 0x01003C
-
-/* Error writing Extended Attribute block while fixing refcount */
-#define PR_1_EXTATTR_WRITE 0x01003D
-
-/* Multiple EA blocks not supported */
-#define PR_1_EA_MULTI_BLOCK 0x01003E
-
-/* Error allocating EA region allocation structure */
-#define PR_1_EA_ALLOC_REGION 0x01003F
-
-/* Error EA allocation collision */
-#define PR_1_EA_ALLOC_COLLISION 0x010040
-
-/* Bad extended attribute name */
-#define PR_1_EA_BAD_NAME 0x010041
-
-/* Bad extended attribute value */
-#define PR_1_EA_BAD_VALUE 0x010042
-
-/* Inode too big (latch question) */
-#define PR_1_INODE_TOOBIG 0x010043
-
-/* Directory too big */
-#define PR_1_TOOBIG_DIR 0x010044
-
-/* Regular file too big */
-#define PR_1_TOOBIG_REG 0x010045
-
-/* Symlink too big */
-#define PR_1_TOOBIG_SYMLINK 0x010046
-
-/* INDEX_FL flag set on a non-HTREE filesystem */
-#define PR_1_HTREE_SET 0x010047
-
-/* INDEX_FL flag set on a non-directory */
-#define PR_1_HTREE_NODIR 0x010048
-
-/* Invalid root node in HTREE directory */
-#define PR_1_HTREE_BADROOT 0x010049
-
-/* Unsupported hash version in HTREE directory */
-#define PR_1_HTREE_HASHV 0x01004A
-
-/* Incompatible flag in HTREE root node */
-#define PR_1_HTREE_INCOMPAT 0x01004B
-
-/* HTREE too deep */
-#define PR_1_HTREE_DEPTH 0x01004C
-
-/* Bad block has indirect block that conflicts with filesystem block */
-#define PR_1_BB_FS_BLOCK 0x01004D
-
-/* Resize inode failed */
-#define PR_1_RESIZE_INODE_CREATE 0x01004E
-
-/* inode->i_size is too long */
-#define PR_1_EXTRA_ISIZE 0x01004F
-
-/* attribute name is too long */
-#define PR_1_ATTR_NAME_LEN 0x010050
-
-/* wrong EA value offset */
-#define PR_1_ATTR_VALUE_OFFSET 0x010051
-
-/* wrong EA blocknumber */
-#define PR_1_ATTR_VALUE_BLOCK 0x010052
-
-/* wrong EA value size */
-#define PR_1_ATTR_VALUE_SIZE 0x010053
-
-/* wrong EA hash value */
-#define PR_1_ATTR_HASH 0x010054
-
-/*
- * Pass 1b errors
- */
-
-/* Pass 1B: Rescan for duplicate/bad blocks */
-#define PR_1B_PASS_HEADER 0x011000
-
-/* Duplicate/bad block(s) header */
-#define PR_1B_DUP_BLOCK_HEADER 0x011001
-
-/* Duplicate/bad block(s) in inode */
-#define PR_1B_DUP_BLOCK 0x011002
-
-/* Duplicate/bad block(s) end */
-#define PR_1B_DUP_BLOCK_END 0x011003
-
-/* Error while scanning inodes */
-#define PR_1B_ISCAN_ERROR 0x011004
-
-/* Error allocating inode bitmap */
-#define PR_1B_ALLOCATE_IBITMAP_ERROR 0x011005
-
-/* Error while iterating over blocks */
-#define PR_1B_BLOCK_ITERATE 0x0110006
-
-/* Error adjusting EA refcount */
-#define PR_1B_ADJ_EA_REFCOUNT 0x0110007
-
-
-/* Pass 1C: Scan directories for inodes with dup blocks. */
-#define PR_1C_PASS_HEADER 0x012000
-
-
-/* Pass 1D: Reconciling duplicate blocks */
-#define PR_1D_PASS_HEADER 0x013000
-
-/* File has duplicate blocks */
-#define PR_1D_DUP_FILE 0x013001
-
-/* List of files sharing duplicate blocks */
-#define PR_1D_DUP_FILE_LIST 0x013002
-
-/* File sharing blocks with filesystem metadata */
-#define PR_1D_SHARE_METADATA 0x013003
-
-/* Report of how many duplicate/bad inodes */
-#define PR_1D_NUM_DUP_INODES 0x013004
-
-/* Duplicated blocks already reassigned or cloned. */
-#define PR_1D_DUP_BLOCKS_DEALT 0x013005
-
-/* Clone duplicate/bad blocks? */
-#define PR_1D_CLONE_QUESTION 0x013006
-
-/* Delete file? */
-#define PR_1D_DELETE_QUESTION 0x013007
-
-/* Couldn't clone file (error) */
-#define PR_1D_CLONE_ERROR 0x013008
-
-/*
- * Pass 2 errors
- */
-
-/* Pass 2: Checking directory structure */
-#define PR_2_PASS_HEADER 0x020000
-
-/* Bad inode number for '.' */
-#define PR_2_BAD_INODE_DOT 0x020001
-
-/* Directory entry has bad inode number */
-#define PR_2_BAD_INO 0x020002
-
-/* Directory entry has deleted or unused inode */
-#define PR_2_UNUSED_INODE 0x020003
-
-/* Directry entry is link to '.' */
-#define PR_2_LINK_DOT 0x020004
-
-/* Directory entry points to inode now located in a bad block */
-#define PR_2_BB_INODE 0x020005
-
-/* Directory entry contains a link to a directory */
-#define PR_2_LINK_DIR 0x020006
-
-/* Directory entry contains a link to the root directry */
-#define PR_2_LINK_ROOT 0x020007
-
-/* Directory entry has illegal characters in its name */
-#define PR_2_BAD_NAME 0x020008
-
-/* Missing '.' in directory inode */
-#define PR_2_MISSING_DOT 0x020009
-
-/* Missing '..' in directory inode */
-#define PR_2_MISSING_DOT_DOT 0x02000A
-
-/* First entry in directory inode doesn't contain '.' */
-#define PR_2_1ST_NOT_DOT 0x02000B
-
-/* Second entry in directory inode doesn't contain '..' */
-#define PR_2_2ND_NOT_DOT_DOT 0x02000C
-
-/* i_faddr should be zero */
-#define PR_2_FADDR_ZERO 0x02000D
-
-/* i_file_acl should be zero */
-#define PR_2_FILE_ACL_ZERO 0x02000E
-
-/* i_dir_acl should be zero */
-#define PR_2_DIR_ACL_ZERO 0x02000F
-
-/* i_frag should be zero */
-#define PR_2_FRAG_ZERO 0x020010
-
-/* i_fsize should be zero */
-#define PR_2_FSIZE_ZERO 0x020011
-
-/* inode has bad mode */
-#define PR_2_BAD_MODE 0x020012
-
-/* directory corrupted */
-#define PR_2_DIR_CORRUPTED 0x020013
-
-/* filename too long */
-#define PR_2_FILENAME_LONG 0x020014
-
-/* Directory inode has a missing block (hole) */
-#define PR_2_DIRECTORY_HOLE 0x020015
-
-/* '.' is not NULL terminated */
-#define PR_2_DOT_NULL_TERM 0x020016
-
-/* '..' is not NULL terminated */
-#define PR_2_DOT_DOT_NULL_TERM 0x020017
-
-/* Illegal character device in inode */
-#define PR_2_BAD_CHAR_DEV 0x020018
-
-/* Illegal block device in inode */
-#define PR_2_BAD_BLOCK_DEV 0x020019
-
-/* Duplicate '.' entry */
-#define PR_2_DUP_DOT 0x02001A
-
-/* Duplicate '..' entry */
-#define PR_2_DUP_DOT_DOT 0x02001B
-
-/* Internal error: couldn't find dir_info */
-#define PR_2_NO_DIRINFO 0x02001C
-
-/* Final rec_len is wrong */
-#define PR_2_FINAL_RECLEN 0x02001D
-
-/* Error allocating icount structure */
-#define PR_2_ALLOCATE_ICOUNT 0x02001E
-
-/* Error iterating over directory blocks */
-#define PR_2_DBLIST_ITERATE 0x02001F
-
-/* Error reading directory block */
-#define PR_2_READ_DIRBLOCK 0x020020
-
-/* Error writing directory block */
-#define PR_2_WRITE_DIRBLOCK 0x020021
-
-/* Error allocating new directory block */
-#define PR_2_ALLOC_DIRBOCK 0x020022
-
-/* Error deallocating inode */
-#define PR_2_DEALLOC_INODE 0x020023
-
-/* Directory entry for '.' is big. Split? */
-#define PR_2_SPLIT_DOT 0x020024
-
-/* Illegal FIFO */
-#define PR_2_BAD_FIFO 0x020025
-
-/* Illegal socket */
-#define PR_2_BAD_SOCKET 0x020026
-
-/* Directory filetype not set */
-#define PR_2_SET_FILETYPE 0x020027
-
-/* Directory filetype incorrect */
-#define PR_2_BAD_FILETYPE 0x020028
-
-/* Directory filetype set when it shouldn't be */
-#define PR_2_CLEAR_FILETYPE 0x020029
-
-/* Directory filename can't be zero-length */
-#define PR_2_NULL_NAME 0x020030
-
-/* Invalid symlink */
-#define PR_2_INVALID_SYMLINK 0x020031
-
-/* i_file_acl (extended attribute) is bad */
-#define PR_2_FILE_ACL_BAD 0x020032
-
-/* Filesystem contains large files, but has no such flag in sb */
-#define PR_2_FEATURE_LARGE_FILES 0x020033
-
-/* Node in HTREE directory not referenced */
-#define PR_2_HTREE_NOTREF 0x020034
-
-/* Node in HTREE directory referenced twice */
-#define PR_2_HTREE_DUPREF 0x020035
-
-/* Node in HTREE directory has bad min hash */
-#define PR_2_HTREE_MIN_HASH 0x020036
-
-/* Node in HTREE directory has bad max hash */
-#define PR_2_HTREE_MAX_HASH 0x020037
-
-/* Clear invalid HTREE directory */
-#define PR_2_HTREE_CLEAR 0x020038
-
-/* Clear the htree flag forcibly */
-/* #define PR_2_HTREE_FCLR 0x020039 */
-
-/* Bad block in htree interior node */
-#define PR_2_HTREE_BADBLK 0x02003A
-
-/* Error adjusting EA refcount */
-#define PR_2_ADJ_EA_REFCOUNT 0x02003B
-
-/* Invalid HTREE root node */
-#define PR_2_HTREE_BAD_ROOT 0x02003C
-
-/* Invalid HTREE limit */
-#define PR_2_HTREE_BAD_LIMIT 0x02003D
-
-/* Invalid HTREE count */
-#define PR_2_HTREE_BAD_COUNT 0x02003E
-
-/* HTREE interior node has out-of-order hashes in table */
-#define PR_2_HTREE_HASH_ORDER 0x02003F
-
-/* Node in HTREE directory has bad depth */
-#define PR_2_HTREE_BAD_DEPTH 0x020040
-
-/* Duplicate directory entry found */
-#define PR_2_DUPLICATE_DIRENT 0x020041
-
-/* Non-unique filename found */
-#define PR_2_NON_UNIQUE_FILE 0x020042
-
-/* Duplicate directory entry found */
-#define PR_2_REPORT_DUP_DIRENT 0x020043
-
-/*
- * Pass 3 errors
+ * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
+ * Copyright (C) 2006 Garrett Kajmowicz
+ *
+ * Dictionary Abstract Data Type
+ * Copyright (C) 1997 Kaz Kylheku <kaz@ashi.footprints.net>
+ * Free Software License:
+ * All rights are reserved by the author, with the following exceptions:
+ * Permission is granted to freely reproduce and distribute this software,
+ * possibly in exchange for a fee, provided that this copyright notice appears
+ * intact. Permission is also granted to adapt this software to produce
+ * derivative works, as long as the modified versions carry this copyright
+ * notice and additional notices stating that the work has been modified.
+ * This source code may be translated into executable form and incorporated
+ * into proprietary software; there is no requirement for such software to
+ * contain a copyright notice related to this source.
+ *
+ * linux/fs/recovery and linux/fs/revoke
+ * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
+ *
+ * Copyright 1999-2000 Red Hat Software --- All Rights Reserved
+ *
+ * Journal recovery routines for the generic filesystem journaling code;
+ * part of the ext2fs journaling system.
+ *
+ * Licensed under GPLv2 or later, see file License in this tarball for details.
*/
-/* Pass 3: Checking directory connectivity */
-#define PR_3_PASS_HEADER 0x030000
-
-/* Root inode not allocated */
-#define PR_3_NO_ROOT_INODE 0x030001
-
-/* No room in lost+found */
-#define PR_3_EXPAND_LF_DIR 0x030002
-
-/* Unconnected directory inode */
-#define PR_3_UNCONNECTED_DIR 0x030003
-
-/* /lost+found not found */
-#define PR_3_NO_LF_DIR 0x030004
-
-/* .. entry is incorrect */
-#define PR_3_BAD_DOT_DOT 0x030005
-
-/* Bad or non-existent /lost+found. Cannot reconnect */
-#define PR_3_NO_LPF 0x030006
-
-/* Could not expand /lost+found */
-#define PR_3_CANT_EXPAND_LPF 0x030007
-
-/* Could not reconnect inode */
-#define PR_3_CANT_RECONNECT 0x030008
-
-/* Error while trying to find /lost+found */
-#define PR_3_ERR_FIND_LPF 0x030009
-
-/* Error in ext2fs_new_block while creating /lost+found */
-#define PR_3_ERR_LPF_NEW_BLOCK 0x03000A
-
-/* Error in ext2fs_new_inode while creating /lost+found */
-#define PR_3_ERR_LPF_NEW_INODE 0x03000B
-
-/* Error in ext2fs_new_dir_block while creating /lost+found */
-#define PR_3_ERR_LPF_NEW_DIR_BLOCK 0x03000C
-
-/* Error while writing directory block for /lost+found */
-#define PR_3_ERR_LPF_WRITE_BLOCK 0x03000D
-
-/* Error while adjusting inode count */
-#define PR_3_ADJUST_INODE 0x03000E
-
-/* Couldn't fix parent directory -- error */
-#define PR_3_FIX_PARENT_ERR 0x03000F
-
-/* Couldn't fix parent directory -- couldn't find it */
-#define PR_3_FIX_PARENT_NOFIND 0x030010
-
-/* Error allocating inode bitmap */
-#define PR_3_ALLOCATE_IBITMAP_ERROR 0x030011
-
-/* Error creating root directory */
-#define PR_3_CREATE_ROOT_ERROR 0x030012
-
-/* Error creating lost and found directory */
-#define PR_3_CREATE_LPF_ERROR 0x030013
-
-/* Root inode is not directory; aborting */
-#define PR_3_ROOT_NOT_DIR_ABORT 0x030014
-
-/* Cannot proceed without a root inode. */
-#define PR_3_NO_ROOT_INODE_ABORT 0x030015
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1 /* get strnlen() */
+#endif
-/* Internal error: couldn't find dir_info */
-#define PR_3_NO_DIRINFO 0x030016
+#include "e2fsck.h" /*Put all of our defines here to clean things up*/
-/* Lost+found is not a directory */
-#define PR_3_LPF_NOTDIR 0x030017
+#define _(x) x
+#define N_(x) x
/*
- * Pass 3a --- rehashing diretories
+ * Procedure declarations
*/
-/* Pass 3a: Reindexing directories */
-#define PR_3A_PASS_HEADER 0x031000
-/* Error iterating over directories */
-#define PR_3A_OPTIMIZE_ITER 0x031001
-
-/* Error rehash directory */
-#define PR_3A_OPTIMIZE_DIR_ERR 0x031002
-
-/* Rehashing dir header */
-#define PR_3A_OPTIMIZE_DIR_HEADER 0x031003
-
-/* Rehashing directory %d */
-#define PR_3A_OPTIMIZE_DIR 0x031004
+static void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf);
-/* Rehashing dir end */
-#define PR_3A_OPTIMIZE_DIR_END 0x031005
+/* pass1.c */
+static void e2fsck_use_inode_shortcuts(e2fsck_t ctx, int bool);
-/*
- * Pass 4 errors
- */
+/* pass2.c */
+static int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,
+ ext2_ino_t ino, char *buf);
-/* Pass 4: Checking reference counts */
-#define PR_4_PASS_HEADER 0x040000
+/* pass3.c */
+static int e2fsck_reconnect_file(e2fsck_t ctx, ext2_ino_t inode);
+static errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
+ int num, int gauranteed_size);
+static ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix);
+static errcode_t e2fsck_adjust_inode_count(e2fsck_t ctx, ext2_ino_t ino,
+ int adj);
-/* Unattached zero-length inode */
-#define PR_4_ZERO_LEN_INODE 0x040001
+/* rehash.c */
+static void e2fsck_rehash_directories(e2fsck_t ctx);
-/* Unattached inode */
-#define PR_4_UNATTACHED_INODE 0x040002
+/* util.c */
+static void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
+ const char *description);
+static int ask(e2fsck_t ctx, const char * string, int def);
+static void e2fsck_read_bitmaps(e2fsck_t ctx);
+static void preenhalt(e2fsck_t ctx);
+static void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
+ struct ext2_inode * inode, const char * proc);
+static void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
+ struct ext2_inode * inode, const char * proc);
+static blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs,
+ const char *name, io_manager manager);
-/* Inode ref count wrong */
-#define PR_4_BAD_REF_COUNT 0x040003
+/* unix.c */
+static void e2fsck_clear_progbar(e2fsck_t ctx);
+static int e2fsck_simple_progress(e2fsck_t ctx, const char *label,
+ float percent, unsigned int dpynum);
-/* Inconsistent inode count information cached */
-#define PR_4_INCONSISTENT_COUNT 0x040004
/*
- * Pass 5 errors
+ * problem.h --- e2fsck problem error codes
*/
-/* Pass 5: Checking group summary information */
-#define PR_5_PASS_HEADER 0x050000
-
-/* Padding at end of inode bitmap is not set. */
-#define PR_5_INODE_BMAP_PADDING 0x050001
-
-/* Padding at end of block bitmap is not set. */
-#define PR_5_BLOCK_BMAP_PADDING 0x050002
-
-/* Block bitmap differences header */
-#define PR_5_BLOCK_BITMAP_HEADER 0x050003
-
-/* Block not used, but marked in bitmap */
-#define PR_5_BLOCK_UNUSED 0x050004
-
-/* Block used, but not marked used in bitmap */
-#define PR_5_BLOCK_USED 0x050005
-
-/* Block bitmap differences end */
-#define PR_5_BLOCK_BITMAP_END 0x050006
-
-/* Inode bitmap differences header */
-#define PR_5_INODE_BITMAP_HEADER 0x050007
-
-/* Inode not used, but marked in bitmap */
-#define PR_5_INODE_UNUSED 0x050008
-
-/* Inode used, but not marked used in bitmap */
-#define PR_5_INODE_USED 0x050009
-
-/* Inode bitmap differences end */
-#define PR_5_INODE_BITMAP_END 0x05000A
-
-/* Free inodes count for group wrong */
-#define PR_5_FREE_INODE_COUNT_GROUP 0x05000B
-
-/* Directories count for group wrong */
-#define PR_5_FREE_DIR_COUNT_GROUP 0x05000C
-
-/* Free inodes count wrong */
-#define PR_5_FREE_INODE_COUNT 0x05000D
-
-/* Free blocks count for group wrong */
-#define PR_5_FREE_BLOCK_COUNT_GROUP 0x05000E
-
-/* Free blocks count wrong */
-#define PR_5_FREE_BLOCK_COUNT 0x05000F
-
-/* Programming error: bitmap endpoints don't match */
-#define PR_5_BMAP_ENDPOINTS 0x050010
-
-/* Internal error: fudging end of bitmap */
-#define PR_5_FUDGE_BITMAP_ERROR 0x050011
-
-/* Error copying in replacement inode bitmap */
-#define PR_5_COPY_IBITMAP_ERROR 0x050012
-
-/* Error copying in replacement block bitmap */
-#define PR_5_COPY_BBITMAP_ERROR 0x050013
-
-/* Block range not used, but marked in bitmap */
-#define PR_5_BLOCK_RANGE_UNUSED 0x050014
-
-/* Block range used, but not marked used in bitmap */
-#define PR_5_BLOCK_RANGE_USED 0x050015
+typedef __u32 problem_t;
-/* Inode range not used, but marked in bitmap */
-#define PR_5_INODE_RANGE_UNUSED 0x050016
+struct problem_context {
+ errcode_t errcode;
+ ext2_ino_t ino, ino2, dir;
+ struct ext2_inode *inode;
+ struct ext2_dir_entry *dirent;
+ blk_t blk, blk2;
+ e2_blkcnt_t blkcount;
+ int group;
+ __u64 num;
+ const char *str;
+};
-/* Inode rangeused, but not marked used in bitmap */
-#define PR_5_INODE_RANGE_USED 0x050017
/*
* Function declarations
static int set_latch_flags(int mask, int setflags, int clearflags);
static void clear_problem_context(struct problem_context *ctx);
-/* message.c */
-static void print_e2fsck_message(e2fsck_t ctx, const char *msg,
- struct problem_context *pctx, int first);
-
/*
* Dictionary Abstract Data Type
* Copyright (C) 1997 Kaz Kylheku <kaz@ashi.footprints.net>
*
- * Free Software License:
- *
- * All rights are reserved by the author, with the following exceptions:
- * Permission is granted to freely reproduce and distribute this software,
- * possibly in exchange for a fee, provided that this copyright notice appears
- * intact. Permission is also granted to adapt this software to produce
- * derivative works, as long as the modified versions carry this copyright
- * notice and additional notices stating that the work has been modified.
- * This source code may be translated into executable form and incorporated
- * into proprietary software; there is no requirement for such software to
- * contain a copyright notice related to this source.
- *
- * $Id: dict.h,v 1.22.2.6 2000/11/13 01:36:44 kaz Exp $
- * $Name: kazlib_1_20 $
+ * dict.h v 1.22.2.6 2000/11/13 01:36:44 kaz
+ * kazlib_1_20
*/
#ifndef DICT_H
} dnode_t;
typedef int (*dict_comp_t)(const void *, const void *);
-typedef dnode_t *(*dnode_alloc_t)(void *);
-typedef void (*dnode_free_t)(dnode_t *, void *);
+typedef void (*dnode_free_t)(dnode_t *);
typedef struct dict_t {
dnode_t dict_nilnode;
dictcount_t dict_nodecount;
dictcount_t dict_maxcount;
dict_comp_t dict_compare;
- dnode_alloc_t dict_allocnode;
dnode_free_t dict_freenode;
- void *dict_context;
int dict_dupes;
} dict_t;
dnode_t dict_nilnode;
} dict_load_t;
-static void dict_set_allocator(dict_t *, dnode_alloc_t, dnode_free_t, void *);
-static void dict_free_nodes(dict_t *);
-static dict_t *dict_init(dict_t *, dictcount_t, dict_comp_t);
-static dnode_t *dict_lookup(dict_t *, const void *);
-static void dict_insert(dict_t *, dnode_t *, const void *);
-static int dict_alloc_insert(dict_t *, const void *, void *);
-static dnode_t *dict_first(dict_t *);
-static dnode_t *dict_next(dict_t *, dnode_t *);
-static dictcount_t dict_count(dict_t *);
-static dnode_t *dnode_init(dnode_t *, void *);
-static void *dnode_get(dnode_t *);
-static const void *dnode_getkey(dnode_t *);
-
#define dict_count(D) ((D)->dict_nodecount)
#define dnode_get(N) ((N)->dict_data)
#define dnode_getkey(N) ((N)->dict_key)
* Pull in the definition of the e2fsck context structure
*/
-
struct buffer_head {
char b_data[8192];
e2fsck_t b_ctx;
int b_err;
};
-struct inode {
- e2fsck_t i_ctx;
- ext2_ino_t i_ino;
- struct ext2_inode i_ext2;
-};
-
-struct kdev_s {
- e2fsck_t k_ctx;
- int k_dev;
-};
#define K_DEV_FS 1
#define K_DEV_JOURNAL 2
-typedef struct kdev_s *kdev_t;
-
#define lock_buffer(bh) do {} while(0)
#define unlock_buffer(bh) do {} while(0)
#define buffer_req(bh) 1
} kmem_cache_t;
#define kmem_cache_alloc(cache,flags) malloc((cache)->object_length)
-#define kmem_cache_free(cache,obj) free(obj)
-#define kmem_cache_create(name,len,a,b,c,d) do_cache_create(len)
-#define kmem_cache_destroy(cache) do_cache_destroy(cache)
-#define kmalloc(len,flags) malloc(len)
-#define kfree(p) free(p)
/*
* We use the standard libext2fs portability tricks for inline
* functions.
*/
-static _INLINE_ kmem_cache_t * do_cache_create(int len)
+static kmem_cache_t * do_cache_create(int len)
{
kmem_cache_t *new_cache;
+
new_cache = malloc(sizeof(*new_cache));
if (new_cache)
new_cache->object_length = len;
return new_cache;
}
-static _INLINE_ void do_cache_destroy(kmem_cache_t *cache)
+static void do_cache_destroy(kmem_cache_t *cache)
{
free(cache);
}
-/*
- * Now pull in the real linux/jfs.h definitions.
- */
-#include "ext2fs/kernel-jbd.h"
-
-/*
- * Kernel compatibility functions are defined in journal.c
- */
-static int journal_bmap(journal_t *journal, blk_t block, unsigned long *phys);
-static struct buffer_head *getblk(kdev_t ctx, blk_t blocknr, int blocksize);
-static void sync_blockdev(kdev_t kdev);
-static void ll_rw_block(int rw, int dummy, struct buffer_head *bh[]);
-static void mark_buffer_dirty(struct buffer_head *bh);
-static void mark_buffer_uptodate(struct buffer_head *bh, int val);
-static void brelse(struct buffer_head *bh);
-static int buffer_uptodate(struct buffer_head *bh);
-static void wait_on_buffer(struct buffer_head *bh);
-
-/*
- * Define newer 2.5 interfaces
- */
-#define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize)
-#define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1)
-
-/*
- * badblocks.c --- replace/append bad blocks to the bad block inode
- *
- * Copyright (C) 1993, 1994 Theodore Ts'o. This file may be
- * redistributed under the terms of the GNU Public License.
- */
-
-static int check_bb_inode_blocks(ext2_filsys fs, blk_t *block_nr, int blockcnt,
- void *priv_data);
-
-
-static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk)
-{
- printf(_("Bad block %u out of range; ignored.\n"), blk);
- return;
-}
-
-void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
- int replace_bad_blocks)
-{
- ext2_filsys fs = ctx->fs;
- errcode_t retval;
- badblocks_list bb_list = 0;
- FILE *f;
- char buf[1024];
-
- e2fsck_read_bitmaps(ctx);
-
- /*
- * Make sure the bad block inode is sane. If there are any
- * illegal blocks, clear them.
- */
- retval = ext2fs_block_iterate(fs, EXT2_BAD_INO, 0, 0,
- check_bb_inode_blocks, 0);
- if (retval) {
- com_err("ext2fs_block_iterate", retval,
- _("while sanity checking the bad blocks inode"));
- goto fatal;
- }
-
- /*
- * If we're appending to the bad blocks inode, read in the
- * current bad blocks.
- */
- if (!replace_bad_blocks) {
- retval = ext2fs_read_bb_inode(fs, &bb_list);
- if (retval) {
- com_err("ext2fs_read_bb_inode", retval,
- _("while reading the bad blocks inode"));
- goto fatal;
- }
- }
-
- /*
- * Now read in the bad blocks from the file; if
- * bad_blocks_file is null, then try to run the badblocks
- * command.
- */
- if (bad_blocks_file) {
- f = fopen(bad_blocks_file, "r");
- if (!f) {
- com_err("read_bad_blocks_file", errno,
- _("while trying to open %s"), bad_blocks_file);
- goto fatal;
- }
- } else {
- sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
- (ctx->options & E2F_OPT_PREEN) ? "" : "-s ",
- (ctx->options & E2F_OPT_WRITECHECK) ? "-n " : "",
- fs->device_name, fs->super->s_blocks_count);
- f = popen(buf, "r");
- if (!f) {
- com_err("read_bad_blocks_file", errno,
- _("while trying popen '%s'"), buf);
- goto fatal;
- }
- }
- retval = ext2fs_read_bb_FILE(fs, f, &bb_list, invalid_block);
- if (bad_blocks_file)
- fclose(f);
- else
- pclose(f);
- if (retval) {
- com_err("ext2fs_read_bb_FILE", retval,
- _("while reading in list of bad blocks from file"));
- goto fatal;
- }
-
- /*
- * Finally, update the bad blocks from the bad_block_map
- */
- retval = ext2fs_update_bb_inode(fs, bb_list);
- if (retval) {
- com_err("ext2fs_update_bb_inode", retval,
- _("while updating bad block inode"));
- goto fatal;
- }
-
- ext2fs_badblocks_list_free(bb_list);
- return;
-
-fatal:
- ctx->flags |= E2F_FLAG_ABORT;
- return;
-
-}
-
-static int check_bb_inode_blocks(ext2_filsys fs,
- blk_t *block_nr,
- int blockcnt EXT2FS_ATTR((unused)),
- void *priv_data EXT2FS_ATTR((unused)))
-{
- if (!*block_nr)
- return 0;
-
- /*
- * If the block number is outrageous, clear it and ignore it.
- */
- if (*block_nr >= fs->super->s_blocks_count ||
- *block_nr < fs->super->s_first_data_block) {
- printf(_("Warning illegal block %u found in bad block inode. Cleared.\n"), *block_nr);
- *block_nr = 0;
- return BLOCK_CHANGED;
- }
-
- return 0;
-}
/*
* Dictionary Abstract Data Type
- * Copyright (C) 1997 Kaz Kylheku <kaz@ashi.footprints.net>
- *
- * Free Software License:
- *
- * All rights are reserved by the author, with the following exceptions:
- * Permission is granted to freely reproduce and distribute this software,
- * possibly in exchange for a fee, provided that this copyright notice appears
- * intact. Permission is also granted to adapt this software to produce
- * derivative works, as long as the modified versions carry this copyright
- * notice and additional notices stating that the work has been modified.
- * This source code may be translated into executable form and incorporated
- * into proprietary software; there is no requirement for such software to
- * contain a copyright notice related to this source.
- *
- * $Id: dict.c,v 1.40.2.7 2000/11/13 01:36:44 kaz Exp $
- * $Name: kazlib_1_20 $
*/
#define data dict_data
#define nilnode dict_nilnode
-#define nodecount dict_nodecount
#define maxcount dict_maxcount
#define compare dict_compare
-#define allocnode dict_allocnode
-#define freenode dict_freenode
-#define context dict_context
#define dupes dict_dupes
-#define dictptr dict_dictptr
-
#define dict_root(D) ((D)->nilnode.left)
#define dict_nil(D) (&(D)->nilnode)
-#define DICT_DEPTH_MAX 64
-static dnode_t *dnode_alloc(void *context);
-static void dnode_free(dnode_t *node, void *context);
+static void dnode_free(dnode_t *node);
/*
* Perform a ``left rotation'' adjustment on the tree. The given node P and
return;
free_nodes(dict, node->left, nil);
free_nodes(dict, node->right, nil);
- dict->freenode(node, dict->context);
+ dict->dict_freenode(node);
}
/*
* Select a different set of node allocator routines.
*/
-void dict_set_allocator(dict_t *dict, dnode_alloc_t al,
- dnode_free_t fr, void *context)
+static void dict_set_allocator(dict_t *dict, dnode_free_t fr)
{
assert (dict_count(dict) == 0);
- assert ((al == NULL && fr == NULL) || (al != NULL && fr != NULL));
-
- dict->allocnode = al ? al : dnode_alloc;
- dict->freenode = fr ? fr : dnode_free;
- dict->context = context;
+ dict->dict_freenode = fr;
}
/*
* installed free routine. The dictionary is emptied.
*/
-void dict_free_nodes(dict_t *dict)
+static void dict_free_nodes(dict_t *dict)
{
dnode_t *nil = dict_nil(dict), *root = dict_root(dict);
free_nodes(dict, root, nil);
- dict->nodecount = 0;
+ dict->dict_nodecount = 0;
dict->nilnode.left = &dict->nilnode;
dict->nilnode.right = &dict->nilnode;
}
* Initialize a user-supplied dictionary object.
*/
-dict_t *dict_init(dict_t *dict, dictcount_t maxcount, dict_comp_t comp)
+static dict_t *dict_init(dict_t *dict, dictcount_t maxcount, dict_comp_t comp)
{
dict->compare = comp;
- dict->allocnode = dnode_alloc;
- dict->freenode = dnode_free;
- dict->context = NULL;
- dict->nodecount = 0;
+ dict->dict_freenode = dnode_free;
+ dict->dict_nodecount = 0;
dict->maxcount = maxcount;
dict->nilnode.left = &dict->nilnode;
dict->nilnode.right = &dict->nilnode;
* located node is returned.
*/
-dnode_t *dict_lookup(dict_t *dict, const void *key)
+static dnode_t *dict_lookup(dict_t *dict, const void *key)
{
dnode_t *root = dict_root(dict);
dnode_t *nil = dict_nil(dict);
* function returns true).
*/
-void dict_insert(dict_t *dict, dnode_t *node, const void *key)
+static void dict_insert(dict_t *dict, dnode_t *node, const void *key)
{
dnode_t *where = dict_root(dict), *nil = dict_nil(dict);
dnode_t *parent = nil, *uncle, *grandpa;
node->left = nil;
node->right = nil;
- dict->nodecount++;
+ dict->dict_nodecount++;
/* red black adjustments */
* the data item.
*/
-int dict_alloc_insert(dict_t *dict, const void *key, void *data)
+static dnode_t *dnode_init(dnode_t *dnode, void *data)
+{
+ dnode->data = data;
+ dnode->parent = NULL;
+ dnode->left = NULL;
+ dnode->right = NULL;
+ return dnode;
+}
+
+static int dict_alloc_insert(dict_t *dict, const void *key, void *data)
{
- dnode_t *node = dict->allocnode(dict->context);
+ dnode_t *node = malloc(sizeof(dnode_t));
if (node) {
dnode_init(node, data);
* (that is, dict_isempty(dict) returns 1) a null pointer is returned.
*/
-dnode_t *dict_first(dict_t *dict)
+static dnode_t *dict_first(dict_t *dict)
{
dnode_t *nil = dict_nil(dict), *root = dict_root(dict), *left;
* the nil node.
*/
-dnode_t *dict_next(dict_t *dict, dnode_t *curr)
+static dnode_t *dict_next(dict_t *dict, dnode_t *curr)
{
dnode_t *nil = dict_nil(dict), *parent, *left;
parent = curr->parent;
}
- return (parent == nil) ? NULL : parent;
-}
-
-#undef dict_count
-#undef dnode_get
-#undef dnode_getkey
-
-dictcount_t dict_count(dict_t *dict)
-{
- return dict->nodecount;
-}
-
-static dnode_t *dnode_alloc(void *context EXT2FS_ATTR((unused)))
-{
- return malloc(sizeof *dnode_alloc(NULL));
-}
-
-static void dnode_free(dnode_t *node, void *context EXT2FS_ATTR((unused)))
-{
- free(node);
-}
-
-dnode_t *dnode_init(dnode_t *dnode, void *data)
-{
- dnode->data = data;
- dnode->parent = NULL;
- dnode->left = NULL;
- dnode->right = NULL;
- return dnode;
-}
-
-void *dnode_get(dnode_t *dnode)
-{
- return dnode->data;
+ return (parent == nil) ? NULL : parent;
}
-const void *dnode_getkey(dnode_t *dnode)
+
+static void dnode_free(dnode_t *node)
{
- return dnode->key;
+ free(node);
}
+
#undef left
#undef right
#undef parent
#undef data
#undef nilnode
-#undef nodecount
#undef maxcount
#undef compare
-#undef allocnode
-#undef freenode
-#undef context
#undef dupes
-#undef dictptr
-
/*
* 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.
*/
/*
* entry. During pass1, the passed-in parent is 0; it will get filled
* in during pass2.
*/
-void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
+static void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
{
struct dir_info *dir;
int i, j;
errcode_t retval;
unsigned long old_size;
-#if 0
- printf("add_dir_info for inode %lu...\n", ino);
-#endif
if (!ctx->dir_info) {
ctx->dir_info_count = 0;
retval = ext2fs_get_num_dirs(ctx->fs, &num_dirs);
* 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;
/*
* Free the dir_info structure when it isn't needed any more.
*/
-void e2fsck_free_dir_info(e2fsck_t ctx)
+static void e2fsck_free_dir_info(e2fsck_t ctx)
{
- if (ctx->dir_info) {
- ext2fs_free_mem(&ctx->dir_info);
- ctx->dir_info = 0;
- }
+ ext2fs_free_mem(&ctx->dir_info);
ctx->dir_info_size = 0;
ctx->dir_info_count = 0;
}
/*
* Return the count of number of directories in the dir_info structure
*/
-int e2fsck_get_num_dirinfo(e2fsck_t ctx)
+static int e2fsck_get_num_dirinfo(e2fsck_t ctx)
{
return ctx->dir_info_count;
}
/*
* A simple interator function
*/
-struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, int *control)
+static struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, int *control)
{
if (*control >= ctx->dir_info_count)
return 0;
return(ctx->dir_info + (*control)++);
}
+
/*
* 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.
*/
#ifdef ENABLE_HTREE
* entry. During pass1, the passed-in parent is 0; it will get filled
* in during pass2.
*/
-void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, int num_blocks)
+static void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, int num_blocks)
{
struct dx_dir_info *dir;
int i, j;
errcode_t retval;
unsigned long old_size;
-#if 0
- printf("add_dx_dir_info for inode %lu...\n", ino);
-#endif
if (!ctx->dx_dir_info) {
ctx->dx_dir_info_count = 0;
ctx->dx_dir_info_size = 100; /* Guess */
* get_dx_dir_info() --- given an inode number, try to find the directory
* information entry for it.
*/
-struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino)
+static struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino)
{
int low, high, mid;
/*
* Free the dx_dir_info structure when it isn't needed any more.
*/
-void e2fsck_free_dx_dir_info(e2fsck_t ctx)
+static void e2fsck_free_dx_dir_info(e2fsck_t ctx)
{
int i;
struct dx_dir_info *dir;
if (ctx->dx_dir_info) {
dir = ctx->dx_dir_info;
for (i=0; i < ctx->dx_dir_info_count; i++) {
- if (dir->dx_block) {
- ext2fs_free_mem(&dir->dx_block);
- dir->dx_block = 0;
- }
+ ext2fs_free_mem(&dir->dx_block);
}
ext2fs_free_mem(&ctx->dx_dir_info);
- ctx->dx_dir_info = 0;
}
ctx->dx_dir_info_size = 0;
ctx->dx_dir_info_count = 0;
/*
* A simple interator function
*/
-struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, int *control)
+static struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, int *control)
{
if (*control >= ctx->dx_dir_info_count)
return 0;
/*
* e2fsck.c - a consistency checker for the new extended file system.
*
- * 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%
*/
/*
* This function allocates an e2fsck context
*/
-errcode_t e2fsck_allocate_context(e2fsck_t *ret)
+static errcode_t e2fsck_allocate_context(e2fsck_t *ret)
{
e2fsck_t context;
errcode_t retval;
return 0;
}
+struct ea_refcount_el {
+ blk_t ea_blk;
+ int ea_count;
+};
+
+struct ea_refcount {
+ blk_t count;
+ blk_t size;
+ blk_t cursor;
+ struct ea_refcount_el *list;
+};
+
+static void ea_refcount_free(ext2_refcount_t refcount)
+{
+ if (!refcount)
+ return;
+
+ ext2fs_free_mem(&refcount->list);
+ ext2fs_free_mem(&refcount);
+}
+
/*
* This function resets an e2fsck context; it is called when e2fsck
* needs to be restarted.
*/
-errcode_t e2fsck_reset_context(e2fsck_t ctx)
+static errcode_t e2fsck_reset_context(e2fsck_t ctx)
{
ctx->flags = 0;
ctx->lost_and_found = 0;
ctx->bad_lost_and_found = 0;
- if (ctx->inode_used_map) {
- ext2fs_free_inode_bitmap(ctx->inode_used_map);
- ctx->inode_used_map = 0;
- }
- if (ctx->inode_dir_map) {
- ext2fs_free_inode_bitmap(ctx->inode_dir_map);
- ctx->inode_dir_map = 0;
- }
- if (ctx->inode_reg_map) {
- ext2fs_free_inode_bitmap(ctx->inode_reg_map);
- ctx->inode_reg_map = 0;
- }
- if (ctx->block_found_map) {
- ext2fs_free_block_bitmap(ctx->block_found_map);
- ctx->block_found_map = 0;
- }
- if (ctx->inode_link_info) {
- ext2fs_free_icount(ctx->inode_link_info);
- ctx->inode_link_info = 0;
- }
+ ext2fs_free_inode_bitmap(ctx->inode_used_map);
+ ctx->inode_used_map = 0;
+ ext2fs_free_inode_bitmap(ctx->inode_dir_map);
+ ctx->inode_dir_map = 0;
+ ext2fs_free_inode_bitmap(ctx->inode_reg_map);
+ ctx->inode_reg_map = 0;
+ ext2fs_free_block_bitmap(ctx->block_found_map);
+ ctx->block_found_map = 0;
+ ext2fs_free_icount(ctx->inode_link_info);
+ ctx->inode_link_info = 0;
if (ctx->journal_io) {
if (ctx->fs && ctx->fs->io != ctx->journal_io)
io_channel_close(ctx->journal_io);
ctx->journal_io = 0;
}
- if (ctx->fs && ctx->fs->dblist) {
+ if (ctx->fs) {
ext2fs_free_dblist(ctx->fs->dblist);
ctx->fs->dblist = 0;
}
#ifdef ENABLE_HTREE
e2fsck_free_dx_dir_info(ctx);
#endif
- if (ctx->refcount) {
- ea_refcount_free(ctx->refcount);
- ctx->refcount = 0;
- }
- if (ctx->refcount_extra) {
- ea_refcount_free(ctx->refcount_extra);
- ctx->refcount_extra = 0;
- }
- if (ctx->block_dup_map) {
- ext2fs_free_block_bitmap(ctx->block_dup_map);
- ctx->block_dup_map = 0;
- }
- if (ctx->block_ea_map) {
- ext2fs_free_block_bitmap(ctx->block_ea_map);
- ctx->block_ea_map = 0;
- }
- if (ctx->inode_bb_map) {
- ext2fs_free_inode_bitmap(ctx->inode_bb_map);
- ctx->inode_bb_map = 0;
- }
- if (ctx->inode_bad_map) {
- ext2fs_free_inode_bitmap(ctx->inode_bad_map);
- ctx->inode_bad_map = 0;
- }
- if (ctx->inode_imagic_map) {
- ext2fs_free_inode_bitmap(ctx->inode_imagic_map);
- ctx->inode_imagic_map = 0;
- }
- if (ctx->dirs_to_hash) {
- ext2fs_u32_list_free(ctx->dirs_to_hash);
- ctx->dirs_to_hash = 0;
- }
+ ea_refcount_free(ctx->refcount);
+ ctx->refcount = 0;
+ ea_refcount_free(ctx->refcount_extra);
+ ctx->refcount_extra = 0;
+ ext2fs_free_block_bitmap(ctx->block_dup_map);
+ ctx->block_dup_map = 0;
+ ext2fs_free_block_bitmap(ctx->block_ea_map);
+ ctx->block_ea_map = 0;
+ ext2fs_free_inode_bitmap(ctx->inode_bad_map);
+ ctx->inode_bad_map = 0;
+ ext2fs_free_inode_bitmap(ctx->inode_imagic_map);
+ ctx->inode_imagic_map = 0;
+ ext2fs_u32_list_free(ctx->dirs_to_hash);
+ ctx->dirs_to_hash = 0;
/*
* Clear the array of invalid meta-data flags
*/
- if (ctx->invalid_inode_bitmap_flag) {
- ext2fs_free_mem(&ctx->invalid_inode_bitmap_flag);
- ctx->invalid_inode_bitmap_flag = 0;
- }
- if (ctx->invalid_block_bitmap_flag) {
- ext2fs_free_mem(&ctx->invalid_block_bitmap_flag);
- ctx->invalid_block_bitmap_flag = 0;
- }
- if (ctx->invalid_inode_table_flag) {
- ext2fs_free_mem(&ctx->invalid_inode_table_flag);
- ctx->invalid_inode_table_flag = 0;
- }
+ ext2fs_free_mem(&ctx->invalid_inode_bitmap_flag);
+ ext2fs_free_mem(&ctx->invalid_block_bitmap_flag);
+ ext2fs_free_mem(&ctx->invalid_inode_table_flag);
/* Clear statistic counters */
ctx->fs_directory_count = 0;
ctx->fs_fast_symlinks_count = 0;
ctx->fs_fifo_count = 0;
ctx->fs_total_count = 0;
- ctx->fs_badblocks_count = 0;
ctx->fs_sockets_count = 0;
ctx->fs_ind_count = 0;
ctx->fs_dind_count = 0;
return 0;
}
-void e2fsck_free_context(e2fsck_t ctx)
+static void e2fsck_free_context(e2fsck_t ctx)
{
if (!ctx)
return;
ext2fs_free_mem(&ctx);
}
-/*
- * This function runs through the e2fsck passes and calls them all,
- * returning restart, abort, or cancel as necessary...
- */
-typedef void (*pass_t)(e2fsck_t ctx);
-
-static pass_t e2fsck_passes[] = {
- e2fsck_pass1, e2fsck_pass2, e2fsck_pass3, e2fsck_pass4,
- e2fsck_pass5, 0 };
-
-#define E2F_FLAG_RUN_RETURN (E2F_FLAG_SIGNAL_MASK|E2F_FLAG_RESTART)
-
-int e2fsck_run(e2fsck_t ctx)
-{
- int i;
- pass_t e2fsck_pass;
-
- if (setjmp(ctx->abort_loc)) {
- ctx->flags &= ~E2F_FLAG_SETJMP_OK;
- return (ctx->flags & E2F_FLAG_RUN_RETURN);
- }
- ctx->flags |= E2F_FLAG_SETJMP_OK;
-
- for (i=0; (e2fsck_pass = e2fsck_passes[i]); i++) {
- if (ctx->flags & E2F_FLAG_RUN_RETURN)
- break;
- e2fsck_pass(ctx);
- if (ctx->progress)
- (void) (ctx->progress)(ctx, 0, 0, 0);
- }
- ctx->flags &= ~E2F_FLAG_SETJMP_OK;
-
- if (ctx->flags & E2F_FLAG_RUN_RETURN)
- return (ctx->flags & E2F_FLAG_RUN_RETURN);
- return 0;
-}
/*
* ea_refcount.c
- *
- * Copyright (C) 2001 Theodore Ts'o. This file may be
- * redistributed under the terms of the GNU Public License.
*/
/*
* removed from the array to save memory space. Once the EA block is
* checked, its bit is set in the block_ea_map bitmap.
*/
-struct ea_refcount_el {
- blk_t ea_blk;
- int ea_count;
-};
-
-struct ea_refcount {
- blk_t count;
- blk_t size;
- blk_t cursor;
- struct ea_refcount_el *list;
-};
-
-void ea_refcount_free(ext2_refcount_t refcount)
-{
- if (!refcount)
- return;
- if (refcount->list)
- ext2fs_free_mem(&refcount->list);
- ext2fs_free_mem(&refcount);
-}
-errcode_t ea_refcount_create(int size, ext2_refcount_t *ret)
+static errcode_t ea_refcount_create(int size, ext2_refcount_t *ret)
{
ext2_refcount_t refcount;
errcode_t retval;
printf("Non-cursor get_refcount_el: %u\n", blk);
#endif
while (low <= high) {
-#if 0
- mid = (low+high)/2;
-#else
if (low == high)
mid = low;
else {
(highval - lowval);
mid = low + ((int) (range * (high-low)));
}
-#endif
+
if (blk == refcount->list[mid].ea_blk) {
refcount->cursor = mid+1;
return &refcount->list[mid];
return 0;
}
-errcode_t ea_refcount_increment(ext2_refcount_t refcount, blk_t blk, int *ret)
+static errcode_t
+ea_refcount_increment(ext2_refcount_t refcount, blk_t blk, int *ret)
{
struct ea_refcount_el *el;
return 0;
}
-errcode_t ea_refcount_decrement(ext2_refcount_t refcount, blk_t blk, int *ret)
+static errcode_t
+ea_refcount_decrement(ext2_refcount_t refcount, blk_t blk, int *ret)
{
struct ea_refcount_el *el;
return 0;
}
-errcode_t ea_refcount_store(ext2_refcount_t refcount, blk_t blk, int count)
+static errcode_t
+ea_refcount_store(ext2_refcount_t refcount, blk_t blk, int count)
{
struct ea_refcount_el *el;
return 0;
}
-void ea_refcount_intr_begin(ext2_refcount_t refcount)
+static inline void ea_refcount_intr_begin(ext2_refcount_t refcount)
{
refcount->cursor = 0;
}
-blk_t ea_refcount_intr_next(ext2_refcount_t refcount,
- int *ret)
+static blk_t ea_refcount_intr_next(ext2_refcount_t refcount, int *ret)
{
struct ea_refcount_el *list;
/*
* ehandler.c --- handle bad block errors which come up during the
* course of an e2fsck session.
- *
- * Copyright (C) 1994 Theodore Ts'o. This file may be redistributed
- * under the terms of the GNU Public License.
*/
static const char *operation;
-static errcode_t e2fsck_handle_read_error(io_channel channel,
- unsigned long block,
- int count,
- void *data,
- size_t size EXT2FS_ATTR((unused)),
- int actual EXT2FS_ATTR((unused)),
- errcode_t error)
+static errcode_t
+e2fsck_handle_read_error(io_channel channel, unsigned long block, int count,
+ void *data, size_t size FSCK_ATTR((unused)),
+ int actual FSCK_ATTR((unused)), errcode_t error)
{
int i;
char *p;
return error;
}
-static errcode_t e2fsck_handle_write_error(io_channel channel,
- unsigned long block,
- int count,
- const void *data,
- size_t size EXT2FS_ATTR((unused)),
- int actual EXT2FS_ATTR((unused)),
- errcode_t error)
+static errcode_t
+e2fsck_handle_write_error(io_channel channel, unsigned long block, int count,
+ const void *data, size_t size FSCK_ATTR((unused)),
+ int actual FSCK_ATTR((unused)), errcode_t error)
{
int i;
const char *p;
return error;
}
-const char *ehandler_operation(const char *op)
+static const char *ehandler_operation(const char *op)
{
const char *ret = operation;
return ret;
}
-void ehandler_init(io_channel channel)
+static void ehandler_init(io_channel channel)
{
channel->read_error = e2fsck_handle_read_error;
channel->write_error = e2fsck_handle_write_error;
}
+
/*
* journal.c --- code for handling the "ext3" journal
*
* any later version.
*/
-#define MNT_FL (MS_MGC_VAL | MS_RDONLY)
-
-
-#ifdef __CONFIG_JBD_DEBUG__E2FS /* Enabled by configure --enable-jfs-debug */
-static int bh_count = 0;
-#endif
-
/*
* Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
* This creates a larger static binary, and a smaller binary using
* to use the recovery.c file virtually unchanged from the kernel, so we
* don't have to do much to keep kernel and user recovery in sync.
*/
-int journal_bmap(journal_t *journal, blk_t block, unsigned long *phys)
+static int journal_bmap(journal_t *journal, blk_t block, unsigned long *phys)
{
#ifdef USE_INODE_IO
*phys = block;
#endif
}
-struct buffer_head *getblk(kdev_t kdev, blk_t blocknr, int blocksize)
+static struct buffer_head *getblk(kdev_t kdev, blk_t blocknr, int blocksize)
{
struct buffer_head *bh;
if (!bh)
return NULL;
- jfs_debug(4, "getblk for block %lu (%d bytes)(total %d)\n",
- (unsigned long) blocknr, blocksize, ++bh_count);
-
bh->b_ctx = kdev->k_ctx;
if (kdev->k_dev == K_DEV_FS)
bh->b_io = kdev->k_ctx->fs->io;
return bh;
}
-void sync_blockdev(kdev_t kdev)
+static void sync_blockdev(kdev_t kdev)
{
io_channel io;
io_channel_flush(io);
}
-void ll_rw_block(int rw, int nr, struct buffer_head *bhp[])
+static void ll_rw_block(int rw, int nr, struct buffer_head *bhp[])
{
int retval;
struct buffer_head *bh;
for (; nr > 0; --nr) {
bh = *bhp++;
if (rw == READ && !bh->b_uptodate) {
- jfs_debug(3, "reading block %lu/%p\n",
- (unsigned long) bh->b_blocknr, (void *) bh);
retval = io_channel_read_blk(bh->b_io,
bh->b_blocknr,
1, bh->b_data);
if (retval) {
- com_err(bh->b_ctx->device_name, retval,
- "while reading block %lu\n",
+ bb_error_msg("while reading block %lu",
(unsigned long) bh->b_blocknr);
bh->b_err = retval;
continue;
}
bh->b_uptodate = 1;
} else if (rw == WRITE && bh->b_dirty) {
- jfs_debug(3, "writing block %lu/%p\n",
- (unsigned long) bh->b_blocknr, (void *) bh);
retval = io_channel_write_blk(bh->b_io,
bh->b_blocknr,
1, bh->b_data);
if (retval) {
- com_err(bh->b_ctx->device_name, retval,
- "while writing block %lu\n",
+ bb_error_msg("while writing block %lu",
(unsigned long) bh->b_blocknr);
bh->b_err = retval;
continue;
}
bh->b_dirty = 0;
bh->b_uptodate = 1;
- } else {
- jfs_debug(3, "no-op %s for block %lu\n",
- rw == READ ? "read" : "write",
- (unsigned long) bh->b_blocknr);
}
}
}
-void mark_buffer_dirty(struct buffer_head *bh)
+static void mark_buffer_dirty(struct buffer_head *bh)
{
bh->b_dirty = 1;
}
-static void mark_buffer_clean(struct buffer_head * bh)
+static inline void mark_buffer_clean(struct buffer_head * bh)
{
bh->b_dirty = 0;
}
-void brelse(struct buffer_head *bh)
+static void brelse(struct buffer_head *bh)
{
if (bh->b_dirty)
ll_rw_block(WRITE, 1, &bh);
- jfs_debug(3, "freeing block %lu/%p (total %d)\n",
- (unsigned long) bh->b_blocknr, (void *) bh, --bh_count);
ext2fs_free_mem(&bh);
}
-int buffer_uptodate(struct buffer_head *bh)
+static int buffer_uptodate(struct buffer_head *bh)
{
return bh->b_uptodate;
}
-void mark_buffer_uptodate(struct buffer_head *bh, int val)
+static inline void mark_buffer_uptodate(struct buffer_head *bh, int val)
{
bh->b_uptodate = val;
}
-void wait_on_buffer(struct buffer_head *bh)
+static void wait_on_buffer(struct buffer_head *bh)
{
if (!bh->b_uptodate)
ll_rw_block(READ, 1, &bh);
return EXT2_ET_LOAD_EXT_JOURNAL;
}
- jfs_debug(1, "Using journal file %s\n", journal_name);
io_ptr = unix_io_manager;
}
-#if 0
- test_io_backing_manager = io_ptr;
- io_ptr = test_io_manager;
-#endif
#ifndef USE_INODE_IO
if (ext_journal)
#endif
memcpy(&jsuper, start ? bh->b_data : bh->b_data + 1024,
sizeof(jsuper));
brelse(bh);
-#ifdef EXT2FS_ENABLE_SWAPFS
+#if BB_BIG_ENDIAN
if (jsuper.s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
ext2fs_swap_super(&jsuper);
#endif
journal->j_superblock = (journal_superblock_t *)bh->b_data;
#ifdef USE_INODE_IO
- if (j_inode)
- ext2fs_free_mem(&j_inode);
+ ext2fs_free_mem(&j_inode);
#endif
*ret_journal = journal;
return 0;
errout:
- if (dev_fs)
- ext2fs_free_mem(&dev_fs);
- if (j_inode)
- ext2fs_free_mem(&j_inode);
- if (journal)
- ext2fs_free_mem(&journal);
+ ext2fs_free_mem(&dev_fs);
+ ext2fs_free_mem(&j_inode);
+ ext2fs_free_mem(&journal);
return retval;
}
ll_rw_block(READ, 1, &jbh);
if (jbh->b_err) {
- com_err(ctx->device_name, jbh->b_err,
- _("reading journal superblock\n"));
+ bb_error_msg(_("reading journal superblock"));
return jbh->b_err;
}
* format to be able to proceed safely, so any other checks that
* fail we should attempt to recover from. */
if (jsb->s_blocksize != htonl(journal->j_blocksize)) {
- com_err(ctx->program_name, EXT2_ET_CORRUPT_SUPERBLOCK,
- _("%s: no valid journal superblock found\n"),
+ bb_error_msg(_("%s: no valid journal superblock found"),
ctx->device_name);
return EXT2_ET_CORRUPT_SUPERBLOCK;
}
if (ntohl(jsb->s_maxlen) < journal->j_maxlen)
journal->j_maxlen = ntohl(jsb->s_maxlen);
else if (ntohl(jsb->s_maxlen) > journal->j_maxlen) {
- com_err(ctx->program_name, EXT2_ET_CORRUPT_SUPERBLOCK,
- _("%s: journal too short\n"),
+ bb_error_msg(_("%s: journal too short"),
ctx->device_name);
return EXT2_ET_CORRUPT_SUPERBLOCK;
}
}
#ifndef USE_INODE_IO
- if (journal->j_inode)
- ext2fs_free_mem(&journal->j_inode);
+ ext2fs_free_mem(&journal->j_inode);
#endif
- if (journal->j_fs_dev)
- ext2fs_free_mem(&journal->j_fs_dev);
+ ext2fs_free_mem(&journal->j_fs_dev);
ext2fs_free_mem(&journal);
}
* This function makes sure that the superblock fields regarding the
* journal are consistent.
*/
-int e2fsck_check_ext3_journal(e2fsck_t ctx)
+static int e2fsck_check_ext3_journal(e2fsck_t ctx)
{
struct ext2_super_block *sb = ctx->fs->super;
journal_t *journal;
return retval;
}
-int e2fsck_run_ext3_journal(e2fsck_t ctx)
+static int e2fsck_run_ext3_journal(e2fsck_t ctx)
{
io_manager io_ptr = ctx->fs->io->manager;
int blocksize = ctx->fs->blocksize;
&ctx->fs);
if (retval) {
- com_err(ctx->program_name, retval,
- _("while trying to re-open %s"),
+ bb_error_msg(_("while trying to re-open %s"),
ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
ctx->fs->priv_data = ctx;
static const char * const journal_names[] = {
".journal", "journal", ".journal.dat", "journal.dat", 0 };
-void e2fsck_move_ext3_journal(e2fsck_t ctx)
+static void e2fsck_move_ext3_journal(e2fsck_t ctx)
{
struct ext2_super_block *sb = ctx->fs->super;
struct problem_context pctx;
/*
* message.c --- print e2fsck messages (with compression)
*
- * Copyright 1996, 1997 by Theodore Ts'o
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
- * %End-Header%
- *
* print_e2fsck_message() prints a message to the user, using
* compression techniques and expansions of abbreviations.
*
* @j journal
* @l lost+found
* @L is a link
+ * @m multiply-claimed
+ * @n invalid
* @o orphaned
* @p problem in
* @r root inode
* abbreviation of the form '@<i>' is expanded by looking up the index
* letter <i> in the table below.
*/
-static const char *abbrevs[] = {
+static const char * const abbrevs[] = {
N_("aextended attribute"),
N_("Aerror allocating"),
N_("bblock"),
N_("hHTREE @d @i"),
N_("llost+found"),
N_("Lis a link"),
+ N_("mmultiply-claimed"),
+ N_("ninvalid"),
N_("oorphaned"),
N_("pproblem in"),
N_("rroot @i"),
* Give more user friendly names to the "special" inodes.
*/
#define num_special_inodes 11
-static const char *special_inode_name[] =
+static const char * const special_inode_name[] =
{
N_("<The NULL inode>"), /* 0 */
N_("<The bad blocks inode>"), /* 1 */
}
}
+static void print_e2fsck_message(e2fsck_t ctx, const char *msg,
+ struct problem_context *pctx, int first);
/*
* This function handles the '@' expansion. We allow recursive
* expansion; an @ expression can contain further '@' and '%'
* expressions.
*/
-static _INLINE_ void expand_at_expression(e2fsck_t ctx, char ch,
+static void expand_at_expression(e2fsck_t ctx, char ch,
struct problem_context *pctx,
int *first)
{
- const char **cpp, *str;
+ const char * const *cpp;
+ const char *str;
/* Search for the abbreviation */
for (cpp = abbrevs; *cpp; cpp++) {
/*
* This function expands '%IX' expressions
*/
-static _INLINE_ void expand_inode_expression(char ch,
+static void expand_inode_expression(char ch,
struct problem_context *ctx)
{
struct ext2_inode *inode;
if (LINUX_S_ISDIR(inode->i_mode))
printf("%u", inode->i_size);
else {
-#ifdef EXT2_NO_64_TYPE
- if (inode->i_size_high)
- printf("0x%x%08x", inode->i_size_high,
- inode->i_size);
- else
- printf("%u", inode->i_size);
-#else
- printf("%llu", (inode->i_size |
- ((__u64) inode->i_size_high << 32)));
-#endif
+ printf("%"PRIu64, (inode->i_size |
+ ((uint64_t) inode->i_size_high << 32)));
}
break;
case 'S':
/*
* This function expands '%dX' expressions
*/
-static _INLINE_ void expand_dirent_expression(char ch,
+static void expand_dirent_expression(char ch,
struct problem_context *ctx)
{
struct ext2_dir_entry *dirent;
}
}
-static _INLINE_ void expand_percent_expression(ext2_filsys fs, char ch,
+static void expand_percent_expression(ext2_filsys fs, char ch,
struct problem_context *ctx)
{
if (!ctx)
printf("%u", ctx->blk);
break;
case 'B':
-#ifdef EXT2_NO_64_TYPE
- printf("%d", ctx->blkcount);
-#else
- printf("%lld", ctx->blkcount);
-#endif
+ printf("%"PRIi64, ctx->blkcount);
break;
case 'c':
printf("%u", ctx->blk2);
printf("%s", error_message(ctx->errcode));
break;
case 'N':
-#ifdef EXT2_NO_64_TYPE
- printf("%u", ctx->num);
-#else
- printf("%llu", ctx->num);
-#endif
+ printf("%"PRIi64, ctx->num);
break;
case 'p':
print_pathname(fs, ctx->ino, 0);
printf("%s", ctx->str ? ctx->str : "NULL");
break;
case 'X':
-#ifdef EXT2_NO_64_TYPE
- printf("0x%x", ctx->num);
-#else
- printf("0x%llx", ctx->num);
-#endif
+ printf("0x%"PRIi64, ctx->num);
break;
default:
no_context:
}
}
-void print_e2fsck_message(e2fsck_t ctx, const char *msg,
+
+static void print_e2fsck_message(e2fsck_t ctx, const char *msg,
struct problem_context *pctx, int first)
{
ext2_filsys fs = ctx->fs;
first = 0;
}
}
+
+
+/*
+ * region.c --- code which manages allocations within a region.
+ */
+
+struct region_el {
+ region_addr_t start;
+ region_addr_t end;
+ struct region_el *next;
+};
+
+struct region_struct {
+ region_addr_t min;
+ region_addr_t max;
+ struct region_el *allocated;
+};
+
+static region_t region_create(region_addr_t min, region_addr_t max)
+{
+ region_t region;
+
+ region = malloc(sizeof(struct region_struct));
+ if (!region)
+ return NULL;
+ memset(region, 0, sizeof(struct region_struct));
+ region->min = min;
+ region->max = max;
+ return region;
+}
+
+static void region_free(region_t region)
+{
+ struct region_el *r, *next;
+
+ for (r = region->allocated; r; r = next) {
+ next = r->next;
+ free(r);
+ }
+ memset(region, 0, sizeof(struct region_struct));
+ free(region);
+}
+
+static int region_allocate(region_t region, region_addr_t start, int n)
+{
+ struct region_el *r, *new_region, *prev, *next;
+ region_addr_t end;
+
+ end = start+n;
+ if ((start < region->min) || (end > region->max))
+ return -1;
+ if (n == 0)
+ return 1;
+
+ /*
+ * Search through the linked list. If we find that it
+ * conflicts witih something that's already allocated, return
+ * 1; if we can find an existing region which we can grow, do
+ * so. Otherwise, stop when we find the appropriate place
+ * insert a new region element into the linked list.
+ */
+ for (r = region->allocated, prev=NULL; r; prev = r, r = r->next) {
+ if (((start >= r->start) && (start < r->end)) ||
+ ((end > r->start) && (end <= r->end)) ||
+ ((start <= r->start) && (end >= r->end)))
+ return 1;
+ if (end == r->start) {
+ r->start = start;
+ return 0;
+ }
+ if (start == r->end) {
+ if ((next = r->next)) {
+ if (end > next->start)
+ return 1;
+ if (end == next->start) {
+ r->end = next->end;
+ r->next = next->next;
+ free(next);
+ return 0;
+ }
+ }
+ r->end = end;
+ return 0;
+ }
+ if (start < r->start)
+ break;
+ }
+ /*
+ * Insert a new region element structure into the linked list
+ */
+ new_region = malloc(sizeof(struct region_el));
+ if (!new_region)
+ return -1;
+ new_region->start = start;
+ new_region->end = start + n;
+ new_region->next = r;
+ if (prev)
+ prev->next = new_region;
+ else
+ region->allocated = new_region;
+ return 0;
+}
+
/*
* pass1.c -- pass #1 of e2fsck: sequential scan of the inode table
*
- * 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%
- *
* Pass 1 of e2fsck iterates over all the inodes in the filesystems,
* and applies the following tests to each inode:
*
* - A bitmap of which inodes are directories. (inode_dir_map)
* - A bitmap of which inodes are regular files. (inode_reg_map)
* - A bitmap of which inodes have bad fields. (inode_bad_map)
- * - A bitmap of which inodes are in bad blocks. (inode_bb_map)
* - A bitmap of which inodes are imagic inodes. (inode_imagic_map)
* - A bitmap of which blocks are in use. (block_found_map)
* - A bitmap of which blocks are in use by two inodes (block_dup_map)
static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
char *block_buf);
static void mark_table_blocks(e2fsck_t ctx);
-static void alloc_bb_map(e2fsck_t ctx);
static void alloc_imagic_map(e2fsck_t ctx);
static void mark_inode_bad(e2fsck_t ctx, ino_t ino);
static void handle_fs_bad_blocks(e2fsck_t ctx);
static void process_inodes(e2fsck_t ctx, char *block_buf);
-static EXT2_QSORT_TYPE process_inode_cmp(const void *a, const void *b);
-static errcode_t scan_callback(ext2_filsys fs, ext2_inode_scan scan,
+static int process_inode_cmp(const void *a, const void *b);
+static errcode_t scan_callback(ext2_filsys fs,
dgrp_t group, void * priv_data);
static void adjust_extattr_refcount(e2fsck_t ctx, ext2_refcount_t refcount,
char *block_buf, int adjust_sign);
* Free all memory allocated by pass1 in preparation for restarting
* things.
*/
-static void unwind_pass1(ext2_filsys fs EXT2FS_ATTR((unused)))
+static void unwind_pass1(void)
{
ext2fs_free_mem(&inodes_to_process);
- inodes_to_process = 0;
}
/*
* since they have the same requirement; the i_block fields should be
* zero.
*/
-int e2fsck_pass1_check_device_inode(ext2_filsys fs, struct ext2_inode *inode)
+static int
+e2fsck_pass1_check_device_inode(ext2_filsys fs, struct ext2_inode *inode)
{
int i;
* Check to make sure a symlink inode is real. Returns 1 if the symlink
* checks out, 0 if not.
*/
-int e2fsck_pass1_check_symlink(ext2_filsys fs, struct ext2_inode *inode,
- char *buf)
+static int
+e2fsck_pass1_check_symlink(ext2_filsys fs, struct ext2_inode *inode, char *buf)
{
unsigned int len;
int i;
* it seems like a corruption. it's very unlikely we could repair
* EA(s) in automatic fashion -bzzz
*/
-#if 0
- problem = PR_1_ATTR_HASH;
-#endif
if (problem == 0 || !fix_problem(ctx, problem, pctx))
return;
return;
}
-#if 0
- printf("inode #%u, i_extra_size %d\n", pctx->ino,
- inode->i_extra_isize);
-#endif
/* i_extra_isize must cover i_extra_isize + i_pad1 at least */
min = sizeof(inode->i_extra_isize) + sizeof(inode->i_pad1);
max = EXT2_INODE_SIZE(sb) - EXT2_GOOD_OLD_INODE_SIZE;
}
}
-void e2fsck_pass1(e2fsck_t ctx)
+static void e2fsck_pass1(e2fsck_t ctx)
{
int i;
__u64 max_sizes;
struct ext2_inode *inode;
ext2_inode_scan scan;
char *block_buf;
-#ifdef RESOURCE_TRACK
- struct resource_track rtrack;
-#endif
unsigned char frag, fsize;
struct problem_context pctx;
struct scan_callback_struct scan_struct;
int busted_fs_time = 0;
int inode_size;
-#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
-#endif
clear_problem_context(&pctx);
if (!(ctx->options & E2F_OPT_PREEN))
ctx->dirs_to_hash = 0;
}
-#ifdef MTRACE
- mtrace_print("Pass 1");
-#endif
+ /* Pass 1 */
#define EXT2_BPP(bits) (1ULL << ((bits) - 2))
if (ctx->progress)
if ((ctx->progress)(ctx, 1, 0, ctx->fs->group_desc_count))
return;
- if (fs->super->s_wtime < fs->super->s_inodes_count)
+ if ((fs->super->s_wtime < fs->super->s_inodes_count) ||
+ (fs->super->s_mtime < fs->super->s_inodes_count))
busted_fs_time = 1;
while (1) {
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
return;
if (pctx.errcode == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) {
- if (!ctx->inode_bb_map)
- alloc_bb_map(ctx);
- ext2fs_mark_inode_bitmap(ctx->inode_bb_map, ino);
- ext2fs_mark_inode_bitmap(ctx->inode_used_map, ino);
continue;
}
if (pctx.errcode) {
handle_fs_bad_blocks(ctx);
/* We don't need the block_ea_map any more */
- if (ctx->block_ea_map) {
- ext2fs_free_block_bitmap(ctx->block_ea_map);
- ctx->block_ea_map = 0;
- }
+ ext2fs_free_block_bitmap(ctx->block_ea_map);
+ ctx->block_ea_map = 0;
if (ctx->flags & E2F_FLAG_RESIZE_INODE) {
ext2fs_block_bitmap save_bmap;
ctx->flags |= E2F_FLAG_ABORT;
return;
}
+ e2fsck_read_inode(ctx, EXT2_RESIZE_INO, inode,
+ "recreate inode");
+ inode->i_mtime = time(0);
+ e2fsck_write_inode(ctx, EXT2_RESIZE_INO, inode,
+ "recreate inode");
fs->block_map = save_bmap;
ctx->flags &= ~E2F_FLAG_RESIZE_INODE;
}
* master superblock.
*/
ctx->use_superblock = 0;
- unwind_pass1(fs);
+ unwind_pass1();
goto endit;
}
ext2fs_free_mem(&block_buf);
ext2fs_free_mem(&inode);
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME2) {
- e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 1"), &rtrack);
- }
-#endif
}
/*
* glock group, call process_inodes.
*/
static errcode_t scan_callback(ext2_filsys fs,
- ext2_inode_scan scan EXT2FS_ATTR((unused)),
dgrp_t group, void * priv_data)
{
struct scan_callback_struct *scan_struct;
char buf[80];
struct problem_context pctx;
-#if 0
- printf("begin process_inodes: ");
-#endif
+ /* begin process_inodes */
if (process_inode_count == 0)
return;
old_operation = ehandler_operation(0);
for (i=0; i < process_inode_count; i++) {
pctx.inode = ctx->stashed_inode = &inodes_to_process[i].inode;
pctx.ino = ctx->stashed_ino = inodes_to_process[i].ino;
-
-#if 0
- printf("%u ", pctx.ino);
-#endif
sprintf(buf, _("reading indirect blocks of inode %u"),
pctx.ino);
ehandler_operation(buf);
ctx->stashed_inode = old_stashed_inode;
ctx->stashed_ino = old_stashed_ino;
process_inode_count = 0;
-#if 0
- printf("end process inodes\n");
-#endif
+ /* end process inodes */
+
ehandler_operation(old_operation);
}
-static EXT2_QSORT_TYPE process_inode_cmp(const void *a, const void *b)
+static int process_inode_cmp(const void *a, const void *b)
{
const struct process_inode_block *ib_a =
(const struct process_inode_block *) a;
}
-/*
- * This procedure will allocate the inode "bb" (badblock) map table
- */
-static void alloc_bb_map(e2fsck_t ctx)
-{
- struct problem_context pctx;
-
- clear_problem_context(&pctx);
- pctx.errcode = ext2fs_allocate_inode_bitmap(ctx->fs,
- _("inode in bad block map"),
- &ctx->inode_bb_map);
- if (pctx.errcode) {
- pctx.num = 4;
- fix_problem(ctx, PR_1_ALLOCATE_IBITMAP_ERROR, &pctx);
- /* Should never get here */
- ctx->flags |= E2F_FLAG_ABORT;
- return;
- }
-}
-
/*
* This procedure will allocate the inode imagic table
*/
* WARNING: Assumes checks have already been done to make sure block
* is valid. This is true in both process_block and process_bad_block.
*/
-static _INLINE_ void mark_block_used(e2fsck_t ctx, blk_t block)
+static void mark_block_used(e2fsck_t ctx, blk_t block)
{
struct problem_context pctx;
}
}
-#if 0
- /* Debugging text */
- printf("Inode %u has EA block %u\n", ino, blk);
-#endif
-
/* Have we seen this EA block before? */
if (ext2fs_fast_test_block_bitmap(ctx->block_ea_map, blk)) {
if (ea_refcount_decrement(ctx->refcount, blk, 0) == 0)
/* Returns 1 if bad htree, 0 if OK */
static int handle_htree(e2fsck_t ctx, struct problem_context *pctx,
- ext2_ino_t ino EXT2FS_ATTR((unused)),
+ ext2_ino_t ino FSCK_ATTR((unused)),
struct ext2_inode *inode,
char *block_buf)
{
}
pb.num_blocks *= (fs->blocksize / 512);
-#if 0
- printf("inode %u, i_size = %lu, last_block = %lld, i_blocks=%lu, num_blocks = %lu\n",
- ino, inode->i_size, pb.last_block, inode->i_blocks,
- pb.num_blocks);
-#endif
+
if (pb.is_dir) {
int nblock = inode->i_size >> EXT2_BLOCK_SIZE_BITS(fs->super);
if (nblock > (pb.last_block + 1))
e2fsck_write_inode(ctx, ino, inode, "check_blocks");
}
-#if 0
-/*
- * Helper function called by process block when an illegal block is
- * found. It returns a description about why the block is illegal
- */
-static char *describe_illegal_block(ext2_filsys fs, blk_t block)
-{
- blk_t super;
- int i;
- static char problem[80];
-
- super = fs->super->s_first_data_block;
- strcpy(problem, "PROGRAMMING ERROR: Unknown reason for illegal block");
- if (block < super) {
- sprintf(problem, "< FIRSTBLOCK (%u)", super);
- return(problem);
- } else if (block >= fs->super->s_blocks_count) {
- sprintf(problem, "> BLOCKS (%u)", fs->super->s_blocks_count);
- return(problem);
- }
- for (i = 0; i < fs->group_desc_count; i++) {
- if (block == super) {
- sprintf(problem, "is the superblock in group %d", i);
- break;
- }
- if (block > super &&
- block <= (super + fs->desc_blocks)) {
- sprintf(problem, "is in the group descriptors "
- "of group %d", i);
- break;
- }
- if (block == fs->group_desc[i].bg_block_bitmap) {
- sprintf(problem, "is the block bitmap of group %d", i);
- break;
- }
- if (block == fs->group_desc[i].bg_inode_bitmap) {
- sprintf(problem, "is the inode bitmap of group %d", i);
- break;
- }
- if (block >= fs->group_desc[i].bg_inode_table &&
- (block < fs->group_desc[i].bg_inode_table
- + fs->inode_blocks_per_group)) {
- sprintf(problem, "is in the inode table of group %d",
- i);
- break;
- }
- super += fs->super->s_blocks_per_group;
- }
- return(problem);
-}
-#endif
/*
* This is a helper function for check_blocks().
static int process_block(ext2_filsys fs,
blk_t *block_nr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct process_block_struct_1 *p;
* Should never happen, since only directories
* get called with BLOCK_FLAG_HOLE
*/
-#if DEBUG_E2FSCK
+#ifdef DEBUG_E2FSCK
printf("process_block() called with blk == 0, "
"blockcnt=%d, inode %lu???\n",
blockcnt, p->ino);
if (blockcnt < 0)
return 0;
if (blockcnt * fs->blocksize < p->inode->i_size) {
-#if 0
- printf("Missing block (#%d) in directory inode %lu!\n",
- blockcnt, p->ino);
-#endif
goto mark_dir;
}
return 0;
}
-#if 0
- printf("Process_block, inode %lu, block %u, #%d\n", p->ino, blk,
- blockcnt);
-#endif
-
/*
* Simplistic fragmentation check. We merely require that the
* file be contiguous. (Which can never be true for really
return ret_code;
}
-static int process_bad_block(ext2_filsys fs,
+static int process_bad_block(ext2_filsys fs FSCK_ATTR((unused)),
blk_t *block_nr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
- void *priv_data)
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
+ void *priv_data EXT2FS_ATTR((unused)))
{
- struct process_block_struct_1 *p;
- blk_t blk = *block_nr;
- blk_t first_block;
- dgrp_t i;
- struct problem_context *pctx;
- e2fsck_t ctx;
-
/*
* Note: This function processes blocks for the bad blocks
* inode, which is never compressed. So we don't use HOLE_BLKADDR().
*/
- if (!blk)
- return 0;
-
- p = (struct process_block_struct_1 *) priv_data;
- ctx = p->ctx;
- pctx = p->pctx;
-
- pctx->ino = EXT2_BAD_INO;
- pctx->blk = blk;
- pctx->blkcount = blockcnt;
-
- if ((blk < fs->super->s_first_data_block) ||
- (blk >= fs->super->s_blocks_count)) {
- if (fix_problem(ctx, PR_1_BB_ILLEGAL_BLOCK_NUM, pctx)) {
- *block_nr = 0;
- return BLOCK_CHANGED;
- } else
- return 0;
- }
-
- if (blockcnt < 0) {
- if (ext2fs_test_block_bitmap(p->fs_meta_blocks, blk)) {
- p->bbcheck = 1;
- if (fix_problem(ctx, PR_1_BB_FS_BLOCK, pctx)) {
- *block_nr = 0;
- return BLOCK_CHANGED;
- }
- } else if (ext2fs_test_block_bitmap(ctx->block_found_map,
- blk)) {
- p->bbcheck = 1;
- if (fix_problem(ctx, PR_1_BBINODE_BAD_METABLOCK,
- pctx)) {
- *block_nr = 0;
- return BLOCK_CHANGED;
- }
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- return BLOCK_ABORT;
- } else
- mark_block_used(ctx, blk);
- return 0;
- }
-#if 0
- printf ("DEBUG: Marking %u as bad.\n", blk);
-#endif
- ctx->fs_badblocks_count++;
- /*
- * If the block is not used, then mark it as used and return.
- * If it is already marked as found, this must mean that
- * there's an overlap between the filesystem table blocks
- * (bitmaps and inode table) and the bad block list.
- */
- if (!ext2fs_test_block_bitmap(ctx->block_found_map, blk)) {
- ext2fs_mark_block_bitmap(ctx->block_found_map, blk);
- return 0;
- }
- /*
- * Try to find the where the filesystem block was used...
- */
- first_block = fs->super->s_first_data_block;
-
- for (i = 0; i < fs->group_desc_count; i++ ) {
- pctx->group = i;
- pctx->blk = blk;
- if (!ext2fs_bg_has_super(fs, i))
- goto skip_super;
- if (blk == first_block) {
- if (i == 0) {
- if (fix_problem(ctx,
- PR_1_BAD_PRIMARY_SUPERBLOCK,
- pctx)) {
- *block_nr = 0;
- return BLOCK_CHANGED;
- }
- return 0;
- }
- fix_problem(ctx, PR_1_BAD_SUPERBLOCK, pctx);
- return 0;
- }
- if ((blk > first_block) &&
- (blk <= first_block + fs->desc_blocks)) {
- if (i == 0) {
- pctx->blk = *block_nr;
- if (fix_problem(ctx,
- PR_1_BAD_PRIMARY_GROUP_DESCRIPTOR, pctx)) {
- *block_nr = 0;
- return BLOCK_CHANGED;
- }
- return 0;
- }
- fix_problem(ctx, PR_1_BAD_GROUP_DESCRIPTORS, pctx);
- return 0;
- }
- skip_super:
- if (blk == fs->group_desc[i].bg_block_bitmap) {
- if (fix_problem(ctx, PR_1_BB_BAD_BLOCK, pctx)) {
- ctx->invalid_block_bitmap_flag[i]++;
- ctx->invalid_bitmaps++;
- }
- return 0;
- }
- if (blk == fs->group_desc[i].bg_inode_bitmap) {
- if (fix_problem(ctx, PR_1_IB_BAD_BLOCK, pctx)) {
- ctx->invalid_inode_bitmap_flag[i]++;
- ctx->invalid_bitmaps++;
- }
- return 0;
- }
- if ((blk >= fs->group_desc[i].bg_inode_table) &&
- (blk < (fs->group_desc[i].bg_inode_table +
- fs->inode_blocks_per_group))) {
- /*
- * If there are bad blocks in the inode table,
- * the inode scan code will try to do
- * something reasonable automatically.
- */
- return 0;
- }
- first_block += fs->super->s_blocks_per_group;
- }
- /*
- * If we've gotten to this point, then the only
- * possibility is that the bad block inode meta data
- * is using a bad block.
- */
- if ((blk == p->inode->i_block[EXT2_IND_BLOCK]) ||
- (blk == p->inode->i_block[EXT2_DIND_BLOCK]) ||
- (blk == p->inode->i_block[EXT2_TIND_BLOCK])) {
- p->bbcheck = 1;
- if (fix_problem(ctx, PR_1_BBINODE_BAD_METABLOCK, pctx)) {
- *block_nr = 0;
- return BLOCK_CHANGED;
- }
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- return BLOCK_ABORT;
- return 0;
- }
-
- pctx->group = -1;
-
- /* Warn user that the block wasn't claimed */
- fix_problem(ctx, PR_1_PROGERR_CLAIMED_BLOCK, pctx);
-
- return 0;
-}
-
-static void new_table_block(e2fsck_t ctx, blk_t first_block, int group,
- const char *name, int num, blk_t *new_block)
-{
- ext2_filsys fs = ctx->fs;
- blk_t old_block = *new_block;
- int i;
- char *buf;
- struct problem_context pctx;
-
- clear_problem_context(&pctx);
-
- pctx.group = group;
- pctx.blk = old_block;
- pctx.str = name;
-
- pctx.errcode = ext2fs_get_free_blocks(fs, first_block,
- first_block + fs->super->s_blocks_per_group,
- num, ctx->block_found_map, new_block);
- if (pctx.errcode) {
- pctx.num = num;
- fix_problem(ctx, PR_1_RELOC_BLOCK_ALLOCATE, &pctx);
- ext2fs_unmark_valid(fs);
- return;
- }
- pctx.errcode = ext2fs_get_mem(fs->blocksize, &buf);
- if (pctx.errcode) {
- fix_problem(ctx, PR_1_RELOC_MEMORY_ALLOCATE, &pctx);
- ext2fs_unmark_valid(fs);
- return;
- }
- ext2fs_mark_super_dirty(fs);
- fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
- pctx.blk2 = *new_block;
- fix_problem(ctx, (old_block ? PR_1_RELOC_FROM_TO :
- PR_1_RELOC_TO), &pctx);
- pctx.blk2 = 0;
- for (i = 0; i < num; i++) {
- pctx.blk = i;
- ext2fs_mark_block_bitmap(ctx->block_found_map, (*new_block)+i);
- if (old_block) {
- pctx.errcode = io_channel_read_blk(fs->io,
- old_block + i, 1, buf);
- if (pctx.errcode)
- fix_problem(ctx, PR_1_RELOC_READ_ERR, &pctx);
- } else
- memset(buf, 0, fs->blocksize);
-
- pctx.blk = (*new_block) + i;
- pctx.errcode = io_channel_write_blk(fs->io, pctx.blk,
- 1, buf);
- if (pctx.errcode)
- fix_problem(ctx, PR_1_RELOC_WRITE_ERR, &pctx);
- }
- ext2fs_free_mem(&buf);
+ printf("Unrecoverable Error: Found %"PRIi64" bad blocks starting at block number: %u\n", blockcnt, *block_nr);
+ return BLOCK_ERROR;
}
/*
*/
static void handle_fs_bad_blocks(e2fsck_t ctx)
{
- ext2_filsys fs = ctx->fs;
- dgrp_t i;
- int first_block = fs->super->s_first_data_block;
-
- for (i = 0; i < fs->group_desc_count; i++) {
- if (ctx->invalid_block_bitmap_flag[i]) {
- new_table_block(ctx, first_block, i, _("block bitmap"),
- 1, &fs->group_desc[i].bg_block_bitmap);
- }
- if (ctx->invalid_inode_bitmap_flag[i]) {
- new_table_block(ctx, first_block, i, _("inode bitmap"),
- 1, &fs->group_desc[i].bg_inode_bitmap);
- }
- if (ctx->invalid_inode_table_flag[i]) {
- new_table_block(ctx, first_block, i, _("inode table"),
- fs->inode_blocks_per_group,
- &fs->group_desc[i].bg_inode_table);
- ctx->flags |= E2F_FLAG_RESTART;
- }
- first_block += fs->super->s_blocks_per_group;
- }
- ctx->invalid_bitmaps = 0;
+ printf("Bad blocks detected on your filesystem\n"
+ "You should get your data off as the device will soon die\n");
}
/*
fs->write_inode = 0;
}
}
+
/*
* pass1b.c --- Pass #1b of e2fsck
*
* (so that the file gets a fresh copy of the duplicated blocks) or
* simply to delete the file.
*
- * 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%
- *
*/
/*
* Free a duplicate inode record
*/
-static void inode_dnode_free(dnode_t *node,
- void *context EXT2FS_ATTR((unused)))
+static void inode_dnode_free(dnode_t *node)
{
struct dup_inode *di;
struct block_el *p, *next;
/*
* Free a duplicate block record
*/
-static void block_dnode_free(dnode_t *node,
- void *context EXT2FS_ATTR((unused)))
+static void block_dnode_free(dnode_t *node)
{
struct dup_block *db;
struct inode_el *p, *next;
dict_init(&ino_dict, DICTCOUNT_T_MAX, dict_int_cmp);
dict_init(&blk_dict, DICTCOUNT_T_MAX, dict_int_cmp);
- dict_set_allocator(&ino_dict, NULL, inode_dnode_free, NULL);
- dict_set_allocator(&blk_dict, NULL, block_dnode_free, NULL);
+ dict_set_allocator(&ino_dict, inode_dnode_free);
+ dict_set_allocator(&blk_dict, block_dnode_free);
pass1b(ctx, block_buf);
pass1c(ctx, block_buf);
e2fsck_use_inode_shortcuts(ctx, 0);
}
-static int process_pass1b_block(ext2_filsys fs EXT2FS_ATTR((unused)),
+static int process_pass1b_block(ext2_filsys fs FSCK_ATTR((unused)),
blk_t *block_nr,
- e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
- blk_t ref_blk EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ e2_blkcnt_t blockcnt FSCK_ATTR((unused)),
+ blk_t ref_blk FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct process_block_struct_1b *p;
static int search_dirent_proc(ext2_ino_t dir, int entry,
struct ext2_dir_entry *dirent,
- int offset EXT2FS_ATTR((unused)),
- int blocksize EXT2FS_ATTR((unused)),
- char *buf EXT2FS_ATTR((unused)),
+ int offset FSCK_ATTR((unused)),
+ int blocksize FSCK_ATTR((unused)),
+ char *buf FSCK_ATTR((unused)),
void *priv_data)
{
struct search_dir_struct *sd;
shared_len = 0;
file_ok = 1;
ino = (ext2_ino_t)VOIDPTR_TO_INT(dnode_getkey(n));
- if (ino == EXT2_BAD_INO)
+ if (ino == EXT2_BAD_INO || ino == EXT2_RESIZE_INO)
continue;
/*
static int delete_file_block(ext2_filsys fs,
blk_t *block_nr,
- e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ e2_blkcnt_t blockcnt FSCK_ATTR((unused)),
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct process_block_struct_1b *pb;
p = (struct dup_block *) dnode_get(n);
decrement_badcount(ctx, *block_nr, p);
} else
- com_err("delete_file_block", 0,
- _("internal error; can't find dup_blk for %d\n"),
+ bb_error_msg(_("internal error; can't find dup_blk for %d"),
*block_nr);
} else {
ext2fs_unmark_block_bitmap(ctx->block_found_map, *block_nr);
static int clone_file_block(ext2_filsys fs,
blk_t *block_nr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct dup_block *p;
return BLOCK_ABORT;
}
}
-#if 0
- printf("Cloning block %u to %u\n", *block_nr,
- new_block);
-#endif
+
retval = io_channel_read_blk(fs->io, *block_nr, 1,
cs->buf);
if (retval) {
ext2fs_mark_block_bitmap(fs->block_map, new_block);
return BLOCK_CHANGED;
} else
- com_err("clone_file_block", 0,
- _("internal error; can't find dup_blk for %d\n"),
+ bb_error_msg(_("internal error; can't find dup_blk for %d"),
*block_nr);
}
return 0;
goto errout;
}
if (cs.errcode) {
- com_err("clone_file", cs.errcode,
- _("returned from clone_file_block"));
+ bb_error_msg(_("returned from clone_file_block"));
retval = cs.errcode;
goto errout;
}
/*
* pass2.c --- check directory structure
*
- * 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%
- *
* Pass 2 of e2fsck iterates through all active directory inodes, and
* applies to following tests to each directory entry in the directory
* blocks in the inodes:
* - The inode_reg_map bitmap
*/
-/* #define DX_DEBUG */
-
/*
* Keeps track of how many times an inode is referenced.
*/
static int check_dir_block(ext2_filsys fs,
struct ext2_db_entry *dir_blocks_info,
void *priv_data);
-static int allocate_dir_block(e2fsck_t ctx,
- struct ext2_db_entry *dir_blocks_info,
- char *buf, struct problem_context *pctx);
+static int allocate_dir_block(e2fsck_t ctx, struct ext2_db_entry *dir_blocks_info,
+ struct problem_context *pctx);
static int update_dir_block(ext2_filsys fs,
blk_t *block_nr,
e2_blkcnt_t blockcnt,
static void clear_htree(e2fsck_t ctx, ext2_ino_t ino);
static int htree_depth(struct dx_dir_info *dx_dir,
struct dx_dirblock_info *dx_db);
-static EXT2_QSORT_TYPE special_dir_block_cmp(const void *a, const void *b);
+static int special_dir_block_cmp(const void *a, const void *b);
struct check_dir_struct {
char *buf;
e2fsck_t ctx;
};
-void e2fsck_pass2(e2fsck_t ctx)
+static void e2fsck_pass2(e2fsck_t ctx)
{
struct ext2_super_block *sb = ctx->fs->super;
struct problem_context pctx;
ext2_filsys fs = ctx->fs;
char *buf;
-#ifdef RESOURCE_TRACK
- struct resource_track rtrack;
-#endif
struct dir_info *dir;
struct check_dir_struct cd;
struct dx_dir_info *dx_dir;
problem_t code;
int bad_dir;
-#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
-#endif
-
clear_problem_context(&cd.pctx);
-#ifdef MTRACE
- mtrace_print("Pass 2");
-#endif
+ /* Pass 2 */
if (!(ctx->options & E2F_OPT_PREEN))
fix_problem(ctx, PR_2_PASS_HEADER, &cd.pctx);
ext2fs_free_mem(&buf);
ext2fs_free_dblist(fs->dblist);
- if (ctx->inode_bad_map) {
- ext2fs_free_inode_bitmap(ctx->inode_bad_map);
- ctx->inode_bad_map = 0;
- }
- if (ctx->inode_reg_map) {
- ext2fs_free_inode_bitmap(ctx->inode_reg_map);
- ctx->inode_reg_map = 0;
- }
+ ext2fs_free_inode_bitmap(ctx->inode_bad_map);
+ ctx->inode_bad_map = 0;
+ ext2fs_free_inode_bitmap(ctx->inode_reg_map);
+ ctx->inode_reg_map = 0;
clear_problem_context(&pctx);
if (ctx->large_files) {
}
}
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME2) {
- e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 2"), &rtrack);
- }
-#endif
}
#define MAX_DEPTH 32000
* This guarantees that the root node of the htree directories are
* processed first, so we know what hash version to use.
*/
-static EXT2_QSORT_TYPE special_dir_block_cmp(const void *a, const void *b)
+static int special_dir_block_cmp(const void *a, const void *b)
{
const struct ext2_db_entry *db_a =
(const struct ext2_db_entry *) a;
*/
static int check_name(e2fsck_t ctx,
struct ext2_dir_entry *dirent,
- ext2_ino_t dir_ino EXT2FS_ATTR((unused)),
struct problem_context *pctx)
{
int i;
/*
* Check the directory filetype (if present)
*/
-static _INLINE_ int check_filetype(e2fsck_t ctx,
+
+/*
+ * Given a mode, return the ext2 file type
+ */
+static int ext2_file_type(unsigned int mode)
+{
+ if (LINUX_S_ISREG(mode))
+ return EXT2_FT_REG_FILE;
+
+ if (LINUX_S_ISDIR(mode))
+ return EXT2_FT_DIR;
+
+ if (LINUX_S_ISCHR(mode))
+ return EXT2_FT_CHRDEV;
+
+ if (LINUX_S_ISBLK(mode))
+ return EXT2_FT_BLKDEV;
+
+ if (LINUX_S_ISLNK(mode))
+ return EXT2_FT_SYMLINK;
+
+ if (LINUX_S_ISFIFO(mode))
+ return EXT2_FT_FIFO;
+
+ if (LINUX_S_ISSOCK(mode))
+ return EXT2_FT_SOCK;
+
+ return 0;
+}
+
+static int check_filetype(e2fsck_t ctx,
struct ext2_dir_entry *dirent,
- ext2_ino_t dir_ino EXT2FS_ATTR((unused)),
struct problem_context *pctx)
{
int filetype = dirent->name_len >> 8;
if (db->blockcnt == 0) {
root = (struct ext2_dx_root_info *) (block_buf + 24);
-
-#ifdef DX_DEBUG
- printf("Root node dump:\n");
- printf("\t Reserved zero: %d\n", root->reserved_zero);
- printf("\t Hash Version: %d\n", root->hash_version);
- printf("\t Info length: %d\n", root->info_length);
- printf("\t Indirect levels: %d\n", root->indirect_levels);
- printf("\t Flags: %d\n", root->unused_flags);
-#endif
-
ent = (struct ext2_dx_entry *) (block_buf + 24 + root->info_length);
} else {
ent = (struct ext2_dx_entry *) (block_buf+8);
}
limit = (struct ext2_dx_countlimit *) ent;
-#ifdef DX_DEBUG
- printf("Number of entries (count): %d\n",
- ext2fs_le16_to_cpu(limit->count));
- printf("Number of entries (limit): %d\n",
- ext2fs_le16_to_cpu(limit->limit));
-#endif
-
count = ext2fs_le16_to_cpu(limit->count);
expect_limit = (fs->blocksize - ((char *) ent - block_buf)) /
sizeof(struct ext2_dx_entry);
for (i=0; i < count; i++) {
prev_hash = hash;
hash = i ? (ext2fs_le32_to_cpu(ent[i].hash) & ~1) : 0;
-#ifdef DX_DEBUG
- printf("Entry #%d: Hash 0x%08x, block %d\n", i,
- hash, ext2fs_le32_to_cpu(ent[i].block));
-#endif
blk = ext2fs_le32_to_cpu(ent[i].block) & 0x0ffffff;
/* Check to make sure the block is valid */
if (blk > (blk_t) dx_dir->numblocks) {
if (i == 0)
dx_db->flags |= DX_FLAG_FIRST;
}
-#ifdef DX_DEBUG
- printf("Blockcnt = %d, min hash 0x%08x, max hash 0x%08x\n",
- db->blockcnt, min_hash, max_hash);
-#endif
dx_db = &dx_dir->dx_block[db->blockcnt];
dx_db->min_hash = min_hash;
dx_db->max_hash = max_hash;
cd->pctx.num = 0;
if (db->blk == 0) {
- if (allocate_dir_block(ctx, db, buf, &cd->pctx))
+ if (allocate_dir_block(ctx, db, &cd->pctx))
return 0;
block_nr = db->blk;
}
ext2fs_u32_list_test(ctx->dirs_to_hash, ino))
dups_found++;
-#if 0
- printf("In process_dir_block block %lu, #%d, inode %lu\n", block_nr,
- db->blockcnt, ino);
-#endif
-
cd->pctx.errcode = ext2fs_read_dir_block(fs, block_nr, buf);
if (cd->pctx.errcode == EXT2_ET_DIR_CORRUPTED)
cd->pctx.errcode = 0; /* We'll handle this ourselves */
* If the inode is unused, offer to clear it.
*/
problem = PR_2_UNUSED_INODE;
- } else if (ctx->inode_bb_map &&
- (ext2fs_test_inode_bitmap(ctx->inode_bb_map,
- dirent->inode))) {
- /*
- * If the inode is in a bad block, offer to
- * clear it.
- */
- problem = PR_2_BB_INODE;
} else if ((dot_state > 1) &&
((dirent->name_len & 0xFF) == 1) &&
(dirent->name[0] == '.')) {
return DIRENT_ABORT;
}
- if (check_name(ctx, dirent, ino, &cd->pctx))
+ if (check_name(ctx, dirent, &cd->pctx))
dir_modified++;
- if (check_filetype(ctx, dirent, ino, &cd->pctx))
+ if (check_filetype(ctx, dirent, &cd->pctx))
dir_modified++;
#ifdef ENABLE_HTREE
offset += dirent->rec_len;
dot_state++;
} while (offset < fs->blocksize);
-#if 0
- printf("\n");
-#endif
#ifdef ENABLE_HTREE
if (dx_db) {
-#ifdef DX_DEBUG
- printf("db_block %d, type %d, min_hash 0x%0x, max_hash 0x%0x\n",
- db->blockcnt, dx_db->type,
- dx_db->min_hash, dx_db->max_hash);
-#endif
cd->pctx.dir = cd->pctx.ino;
if ((dx_db->type == DX_DIRBLOCK_ROOT) ||
(dx_db->type == DX_DIRBLOCK_NODE))
* This function is called to deallocate a block, and is an interator
* functioned called by deallocate inode via ext2fs_iterate_block().
*/
-static int deallocate_inode_block(ext2_filsys fs,
- blk_t *block_nr,
- e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+static int deallocate_inode_block(ext2_filsys fs, blk_t *block_nr,
+ e2_blkcnt_t blockcnt FSCK_ATTR((unused)),
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
e2fsck_t ctx = (e2fsck_t) priv_data;
!(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR) &&
fix_problem(ctx, PR_2_FILE_ACL_ZERO, &pctx)) {
inode.i_file_acl = 0;
-#ifdef EXT2FS_ENABLE_SWAPFS
+#if BB_BIG_ENDIAN
/*
* This is a special kludge to deal with long symlinks
* on big endian systems. i_blocks had already been
* a "hole" in it, or if a directory has a illegal block number
* that was zeroed out and now needs to be replaced.
*/
-static int allocate_dir_block(e2fsck_t ctx,
- struct ext2_db_entry *db,
- char *buf EXT2FS_ATTR((unused)),
+static int allocate_dir_block(e2fsck_t ctx, struct ext2_db_entry *db,
struct problem_context *pctx)
{
ext2_filsys fs = ctx->fs;
/*
* This is a helper function for allocate_dir_block().
*/
-static int update_dir_block(ext2_filsys fs EXT2FS_ATTR((unused)),
+static int update_dir_block(ext2_filsys fs FSCK_ATTR((unused)),
blk_t *block_nr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct ext2_db_entry *db;
}
return 0;
}
+
/*
* pass3.c -- pass #3 of e2fsck: Check for directory connectivity
*
- * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999 Theodore Ts'o.
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
- * %End-Header%
- *
* Pass #3 assures that all directories are connected to the
* filesystem tree, using the following algorithm:
*
* Then, pass3 interates over all directory inodes; for each directory
* it attempts to trace up the filesystem tree, using dirinfo.parent
* until it reaches a directory which has been marked "done". If it
- * can not do so, then the directory must be disconnected, and e2fsck
+ * cannot do so, then the directory must be disconnected, and e2fsck
* will offer to reconnect it to /lost+found. While it is chasing
* parent pointers up the filesystem tree, if pass3 sees a directory
* twice, then it has detected a filesystem loop, and it will again
struct problem_context *pctx);
static void fix_dotdot(e2fsck_t ctx, struct dir_info *dir, ext2_ino_t parent);
-static ext2fs_inode_bitmap inode_loop_detect = 0;
-static ext2fs_inode_bitmap inode_done_map = 0;
+static ext2fs_inode_bitmap inode_loop_detect;
+static ext2fs_inode_bitmap inode_done_map;
-void e2fsck_pass3(e2fsck_t ctx)
+static void e2fsck_pass3(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
int i;
-#ifdef RESOURCE_TRACK
- struct resource_track rtrack;
-#endif
struct problem_context pctx;
struct dir_info *dir;
unsigned long maxdirs, count;
-#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
-#endif
-
clear_problem_context(&pctx);
-#ifdef MTRACE
- mtrace_print("Pass 3");
-#endif
+ /* Pass 3 */
if (!(ctx->options & E2F_OPT_PREEN))
fix_problem(ctx, PR_3_PASS_HEADER, &pctx);
ctx->flags |= E2F_FLAG_ABORT;
goto abort_exit;
}
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME) {
- e2fsck_clear_progbar(ctx);
- print_resource_track(_("Peak memory"), &ctx->global_rtrack);
- }
-#endif
-
check_root(ctx);
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
goto abort_exit;
abort_exit:
e2fsck_free_dir_info(ctx);
- if (inode_loop_detect) {
- ext2fs_free_inode_bitmap(inode_loop_detect);
- inode_loop_detect = 0;
- }
- if (inode_done_map) {
- ext2fs_free_inode_bitmap(inode_done_map);
- inode_done_map = 0;
- }
-
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME2) {
- e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 3"), &rtrack);
- }
-#endif
+ ext2fs_free_inode_bitmap(inode_loop_detect);
+ inode_loop_detect = 0;
+ ext2fs_free_inode_bitmap(inode_done_map);
+ inode_done_map = 0;
}
/*
ext2fs_icount_store(ctx->inode_count, ino, 2);
ext2fs_icount_store(ctx->inode_link_info, ino, 2);
ctx->lost_and_found = ino;
-#if 0
- printf("/lost+found created; inode #%lu\n", ino);
-#endif
return ino;
}
if (retval)
return retval;
-#if 0
- printf("Adjusting link count for inode %lu by %d (from %d)\n", ino, adj,
- inode.i_links_count);
-#endif
-
if (adj == 1) {
ext2fs_icount_increment(ctx->inode_count, ino, 0);
if (inode.i_links_count == (__u16) ~0)
};
static int fix_dotdot_proc(struct ext2_dir_entry *dirent,
- int offset EXT2FS_ATTR((unused)),
- int blocksize EXT2FS_ATTR((unused)),
- char *buf EXT2FS_ATTR((unused)),
+ int offset FSCK_ATTR((unused)),
+ int blocksize FSCK_ATTR((unused)),
+ char *buf FSCK_ATTR((unused)),
void *priv_data)
{
struct fix_dotdot_struct *fp = (struct fix_dotdot_struct *) priv_data;
fp.done = 0;
fp.ctx = ctx;
-#if 0
- printf("Fixing '..' of inode %lu to be %lu...\n", dir->ino, parent);
-#endif
-
retval = ext2fs_dir_iterate(fs, dir->ino, DIRENT_FLAG_INCLUDE_EMPTY,
0, fix_dotdot_proc, &fp);
if (retval || !fp.done) {
static int expand_dir_proc(ext2_filsys fs,
blk_t *blocknr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
/*
* pass4.c -- pass #4 of e2fsck: Check reference counts
*
- * 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%
- *
* Pass 4 frees the following data structures:
- * - A bitmap of which inodes are in bad blocks. (inode_bb_map)
* - A bitmap of which inodes are imagic inodes. (inode_imagic_map)
*/
}
-void e2fsck_pass4(e2fsck_t ctx)
+static void e2fsck_pass4(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
ext2_ino_t i;
struct ext2_inode inode;
-#ifdef RESOURCE_TRACK
- struct resource_track rtrack;
-#endif
struct problem_context pctx;
__u16 link_count, link_counted;
char *buf = 0;
int group, maxgroup;
-#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
-#endif
-
-#ifdef MTRACE
- mtrace_print("Pass 4");
-#endif
+ /* Pass 4 */
clear_problem_context(&pctx);
continue;
if (!(ext2fs_test_inode_bitmap(ctx->inode_used_map, i)) ||
(ctx->inode_imagic_map &&
- ext2fs_test_inode_bitmap(ctx->inode_imagic_map, i)) ||
- (ctx->inode_bb_map &&
- ext2fs_test_inode_bitmap(ctx->inode_bb_map, i)))
+ ext2fs_test_inode_bitmap(ctx->inode_imagic_map, i)))
continue;
ext2fs_icount_fetch(ctx->inode_link_info, i, &link_count);
ext2fs_icount_fetch(ctx->inode_count, i, &link_counted);
}
ext2fs_free_icount(ctx->inode_link_info); ctx->inode_link_info = 0;
ext2fs_free_icount(ctx->inode_count); ctx->inode_count = 0;
- ext2fs_free_inode_bitmap(ctx->inode_bb_map);
- ctx->inode_bb_map = 0;
ext2fs_free_inode_bitmap(ctx->inode_imagic_map);
- ctx->inode_imagic_map = 0;
- if (buf)
- ext2fs_free_mem(&buf);
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME2) {
- e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 4"), &rtrack);
- }
-#endif
+ ctx->inode_imagic_map = 0;
+ ext2fs_free_mem(&buf);
}
/*
* pass5.c --- check block and inode bitmaps against on-disk bitmaps
- *
- * 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%
- *
*/
-static void check_block_bitmaps(e2fsck_t ctx);
-static void check_inode_bitmaps(e2fsck_t ctx);
-static void check_inode_end(e2fsck_t ctx);
-static void check_block_end(e2fsck_t ctx);
-
-void e2fsck_pass5(e2fsck_t ctx)
-{
-#ifdef RESOURCE_TRACK
- struct resource_track rtrack;
-#endif
- struct problem_context pctx;
-
-#ifdef MTRACE
- mtrace_print("Pass 5");
-#endif
-
-#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
-#endif
-
- clear_problem_context(&pctx);
-
- if (!(ctx->options & E2F_OPT_PREEN))
- fix_problem(ctx, PR_5_PASS_HEADER, &pctx);
-
- if (ctx->progress)
- if ((ctx->progress)(ctx, 5, 0, ctx->fs->group_desc_count*2))
- return;
-
- e2fsck_read_bitmaps(ctx);
-
- check_block_bitmaps(ctx);
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- return;
- check_inode_bitmaps(ctx);
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- return;
- check_inode_end(ctx);
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- return;
- check_block_end(ctx);
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- return;
-
- ext2fs_free_inode_bitmap(ctx->inode_used_map);
- ctx->inode_used_map = 0;
- ext2fs_free_inode_bitmap(ctx->inode_dir_map);
- ctx->inode_dir_map = 0;
- ext2fs_free_block_bitmap(ctx->block_found_map);
- ctx->block_found_map = 0;
-
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME2) {
- e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 5"), &rtrack);
- }
-#endif
-}
-
#define NO_BLK ((blk_t) -1)
static void print_bitmap_problem(e2fsck_t ctx, int problem,
}
}
+static void e2fsck_pass5(e2fsck_t ctx)
+{
+ struct problem_context pctx;
+
+ /* Pass 5 */
+
+ clear_problem_context(&pctx);
+
+ if (!(ctx->options & E2F_OPT_PREEN))
+ fix_problem(ctx, PR_5_PASS_HEADER, &pctx);
+
+ if (ctx->progress)
+ if ((ctx->progress)(ctx, 5, 0, ctx->fs->group_desc_count*2))
+ return;
+
+ e2fsck_read_bitmaps(ctx);
+
+ check_block_bitmaps(ctx);
+ if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+ return;
+ check_inode_bitmaps(ctx);
+ if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+ return;
+ check_inode_end(ctx);
+ if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+ return;
+ check_block_end(ctx);
+ if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+ return;
+ ext2fs_free_inode_bitmap(ctx->inode_used_map);
+ ctx->inode_used_map = 0;
+ ext2fs_free_inode_bitmap(ctx->inode_dir_map);
+ ctx->inode_dir_map = 0;
+ ext2fs_free_block_bitmap(ctx->block_found_map);
+ ctx->block_found_map = 0;
+}
/*
* problem.c --- report filesystem problems to the user
- *
- * Copyright 1996, 1997 by Theodore Ts'o
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
- * %End-Header%
*/
#define PR_PREEN_OK 0x000001 /* Don't need to do preenhalt */
* These are the prompts which are used to ask the user if they want
* to fix a problem.
*/
-static const char *prompt[] = {
+static const char * const prompt[] = {
N_("(no prompt)"), /* 0 */
N_("Fix"), /* 1 */
N_("Clear"), /* 2 */
N_("Abort"), /* 11 */
N_("Split"), /* 12 */
N_("Continue"), /* 13 */
- N_("Clone duplicate/bad blocks"), /* 14 */
+ N_("Clone multiply-claimed blocks"), /* 14 */
N_("Delete file"), /* 15 */
N_("Suppress messages"),/* 16 */
N_("Unlink"), /* 17 */
* These messages are printed when we are preen mode and we will be
* automatically fixing the problem.
*/
-static const char *preen_msg[] = {
+static const char * const preen_msg[] = {
N_("(NONE)"), /* 0 */
N_("FIXED"), /* 1 */
N_("CLEARED"), /* 2 */
N_("ABORTED"), /* 11 */
N_("SPLIT"), /* 12 */
N_("CONTINUING"), /* 13 */
- N_("DUPLICATE/BAD BLOCKS CLONED"), /* 14 */
+ N_("MULTIPLY-CLAIMED BLOCKS CLONED"), /* 14 */
N_("FILE DELETED"), /* 15 */
N_("SUPPRESSED"), /* 16 */
N_("UNLINKED"), /* 17 */
/* Relocate hint */
{ PR_0_RELOCATE_HINT,
- N_("Note: if there is several inode or block bitmap blocks\n"
- "which require relocation, or one part of the inode table\n"
- "which must be moved, you may wish to try running e2fsck\n"
- "with the '-b %S' option first. The problem may lie only\n"
- "with the primary block group descriptor, and the backup\n"
- "block group descriptor may be OK.\n\n"),
+ N_("Note: if several inode or block bitmap blocks or part\n"
+ "of the inode table require relocation, you may wish to try\n"
+ "running e2fsck with the '-b %S' option first. The problem\n"
+ "may lie only with the primary block group descriptors, and\n"
+ "the backup block group descriptors may be OK.\n\n"),
PROMPT_NONE, PR_PREEN_OK | PR_NOCOLLATE },
/* Miscellaneous superblock corruption */
/* Inode count in superblock is incorrect */
{ PR_0_INODE_COUNT_WRONG,
- N_("@i count in @S is %i, should be %j.\n"),
+ N_("@i count in @S is %i, @s %j.\n"),
PROMPT_FIX, 0 },
{ PR_0_HURD_CLEAR_FILETYPE,
/* Journal inode is invalid */
{ PR_0_JOURNAL_BAD_INODE,
- N_("@S has a bad ext3 @j (@i %i).\n"),
+ N_("@S has an @n ext3 @j (@i %i).\n"),
PROMPT_CLEAR, PR_PREEN_OK },
/* The external journal has (unsupported) multiple filesystems */
/* Journal has data, but recovery flag is clear */
{ PR_0_JOURNAL_RECOVERY_CLEAR,
- N_("ext3 recovery flag clear, but @j has data.\n"),
+ N_("ext3 recovery flag is clear, but @j has data.\n"),
PROMPT_NONE, 0 },
/* Ask if we should clear the journal */
/* Filesystem revision is 0, but feature flags are set */
{ PR_0_FS_REV_LEVEL,
- "@f has feature flag(s) set, but is a revision 0 @f. ",
+ N_("@f has feature flag(s) set, but is a revision 0 @f. "),
PROMPT_FIX, PR_PREEN_OK | PR_NO_OK },
/* Journal superblock has an unknown read-only feature flag set */
/* Moving journal to hidden file */
{ PR_0_MOVE_JOURNAL,
- N_("Moving @j from /%s to hidden inode.\n\n"),
+ N_("Moving @j from /%s to hidden @i.\n\n"),
PROMPT_NONE, 0 },
/* Error moving journal to hidden file */
/* Clearing V2 journal superblock */
{ PR_0_CLEAR_V2_JOURNAL,
- N_("Found invalid V2 @j @S fields (from V1 journal).\n"
+ N_("Found @n V2 @j @S fields (from V1 @j).\n"
"Clearing fields beyond the V1 @j @S...\n\n"),
PROMPT_NONE, 0 },
/* Resize_inode not enabled, but resize inode is non-zero */
{ PR_0_CLEAR_RESIZE_INODE,
- N_("Resize_@i not enabled, but the resize inode is non-zero. "),
+ N_("Resize_@i not enabled, but the resize @i is non-zero. "),
PROMPT_CLEAR, 0 },
/* Resize inode invalid */
/* Reserved inode has bad mode */
{ PR_1_RESERVED_BAD_MODE,
- N_("Reserved @i %i %Q has bad mode. "),
+ N_("Reserved @i %i (%Q) has @n mode. "),
PROMPT_CLEAR, PR_PREEN_OK },
/* Deleted inode has zero dtime */
/* Bad primary block */
{ PR_1_BAD_PRIMARY_BLOCK,
- N_("\nIf the @b is really bad, the @f can not be fixed.\n"),
+ N_("\nIf the @b is really bad, the @f cannot be fixed.\n"),
PROMPT_NONE, PR_AFTER_CODE, PR_1_BAD_PRIMARY_BLOCK_PROMPT },
/* Bad primary block prompt */
{ PR_1_BAD_PRIMARY_BLOCK_PROMPT,
- N_("You can clear the this @b (and hope for the best) from the\n"
- "bad @b list and hope that @b is really OK, but there are no\n"
- "guarantees.\n\n"),
+ N_("You can remove this @b from the bad @b list and hope\n"
+ "that the @b is really OK. But there are no guarantees.\n\n"),
PROMPT_CLEAR, PR_PREEN_NOMSG },
/* Bad primary superblock */
/* Error allocating inode bitmap */
{ PR_1_ALLOCATE_IBITMAP_ERROR,
- "@A @i @B (%N): %m\n",
+ N_("@A @i @B (%N): %m\n"),
PROMPT_NONE, PR_FATAL },
/* Error allocating block bitmap */
{ PR_1_ALLOCATE_BBITMAP_ERROR,
- "@A @b @B (%N): %m\n",
+ N_("@A @b @B (%N): %m\n"),
PROMPT_NONE, PR_FATAL },
/* Error allocating icount structure */
/* Non-zero size for device, fifo or socket inode */
{ PR_1_SET_NONZSIZE,
- "Special (@v/socket/fifo) @i %i has non-zero size. ",
+ N_("Special (@v/socket/fifo) @i %i has non-zero size. "),
PROMPT_FIX, PR_PREEN_OK },
/* Filesystem revision is 0, but feature flags are set */
{ PR_1_FS_REV_LEVEL,
- "@f has feature flag(s) set, but is a revision 0 @f. ",
+ N_("@f has feature flag(s) set, but is a revision 0 @f. "),
PROMPT_FIX, PR_PREEN_OK | PR_NO_OK },
/* Journal inode is not in use, but contains data */
{ PR_1_JOURNAL_INODE_NOT_CLEAR,
- "@j @i is not in use, but contains data. ",
+ N_("@j @i is not in use, but contains data. "),
PROMPT_CLEAR, PR_PREEN_OK },
/* Journal has bad mode */
/* Deal with inodes that were part of orphan linked list */
{ PR_1_LOW_DTIME,
- N_("@i %i was part of the orphaned @i list. "),
+ N_("@i %i was part of the @o @i list. "),
PROMPT_FIX, PR_LATCH_LOW_DTIME, 0 },
/* Deal with inodes that were part of corrupted orphan linked
/* Error allocating refcount structure */
{ PR_1_ALLOCATE_REFCOUNT,
- "@A refcount structure (%N): %m\n",
+ N_("@A refcount structure (%N): %m\n"),
PROMPT_NONE, PR_FATAL },
/* Error reading extended attribute block */
/* Extended attribute reference count incorrect */
{ PR_1_EXTATTR_REFCOUNT,
- N_("@a @b %b has reference count %B, should be %N. "),
+ N_("@a @b %b has reference count %B, @s %N. "),
PROMPT_FIX, 0 },
/* Error writing Extended Attribute block while fixing refcount */
/* Multiple EA blocks not supported */
{ PR_1_EA_MULTI_BLOCK,
- N_("@a @b %b has h_blocks > 1. "),
+ N_("@a @b %b has h_@bs > 1. "),
PROMPT_CLEAR, 0},
/* Error allocating EA region allocation structure */
{ PR_1_EA_ALLOC_REGION,
- N_("Error allocating @a @b %b. "),
+ N_("@A @a @b %b. "),
PROMPT_ABORT, 0},
/* Error EA allocation collision */
/* Bad extended attribute name */
{ PR_1_EA_BAD_NAME,
- N_("@a @b %b is corrupt (invalid name). "),
+ N_("@a @b %b is corrupt (@n name). "),
PROMPT_CLEAR, 0},
/* Bad extended attribute value */
{ PR_1_EA_BAD_VALUE,
- N_("@a @b %b is corrupt (invalid value). "),
+ N_("@a @b %b is corrupt (@n value). "),
PROMPT_CLEAR, 0},
/* Inode too big (latch question) */
/* Invalid root node in HTREE directory */
{ PR_1_HTREE_BADROOT,
- N_("@h %i has an invalid root node.\n"),
+ N_("@h %i has an @n root node.\n"),
PROMPT_CLEAR_HTREE, PR_PREEN_OK },
/* Unsupported hash version in HTREE directory */
/* invalid inode->i_extra_isize */
{ PR_1_EXTRA_ISIZE,
- N_("@i %i has a extra size (%IS) which is invalid\n"),
+ N_("@i %i has a extra size (%IS) which is @n\n"),
PROMPT_FIX, PR_PREEN_OK },
/* invalid ea entry->e_name_len */
{ PR_1_ATTR_NAME_LEN,
- N_("@a in @i %i has a namelen (%N) which is invalid\n"),
+ N_("@a in @i %i has a namelen (%N) which is @n\n"),
PROMPT_CLEAR, PR_PREEN_OK },
/* invalid ea entry->e_value_size */
{ PR_1_ATTR_VALUE_SIZE,
- N_("@a in @i %i has a value size (%N) which is invalid\n"),
+ N_("@a in @i %i has a value size (%N) which is @n\n"),
PROMPT_CLEAR, PR_PREEN_OK },
/* invalid ea entry->e_value_offs */
{ PR_1_ATTR_VALUE_OFFSET,
- N_("@a in @i %i has a value offset (%N) which is invalid\n"),
+ N_("@a in @i %i has a value offset (%N) which is @n\n"),
PROMPT_CLEAR, PR_PREEN_OK },
/* invalid ea entry->e_value_block */
{ PR_1_ATTR_VALUE_BLOCK,
- N_("@a in @i %i has a value block (%N) which is invalid (must be 0)\n"),
+ N_("@a in @i %i has a value @b (%N) which is @n (must be 0)\n"),
PROMPT_CLEAR, PR_PREEN_OK },
/* invalid ea entry->e_hash */
{ PR_1_ATTR_HASH,
- N_("@a in @i %i has a hash (%N) which is invalid (must be 0)\n"),
+ N_("@a in @i %i has a hash (%N) which is @n (must be 0)\n"),
PROMPT_CLEAR, PR_PREEN_OK },
/* Pass 1b errors */
/* Pass 1B: Rescan for duplicate/bad blocks */
{ PR_1B_PASS_HEADER,
- N_("Duplicate @bs found... invoking duplicate @b passes.\n"
- "Pass 1B: Rescan for duplicate/bad @bs\n"),
+ N_("\nRunning additional passes to resolve @bs claimed by more than one @i...\n"
+ "Pass 1B: Rescanning for @m @bs\n"),
PROMPT_NONE, 0 },
/* Duplicate/bad block(s) header */
{ PR_1B_DUP_BLOCK_HEADER,
- N_("Duplicate/bad @b(s) in @i %i:"),
+ N_("@m @b(s) in @i %i:"),
PROMPT_NONE, 0 },
/* Duplicate/bad block(s) in inode */
/* Error allocating inode bitmap */
{ PR_1B_ALLOCATE_IBITMAP_ERROR,
- N_("@A @i @B (inode_dup_map): %m\n"),
+ N_("@A @i @B (@i_dup_map): %m\n"),
PROMPT_NONE, PR_FATAL },
/* Error while iterating over blocks */
/* Error adjusting EA refcount */
{ PR_1B_ADJ_EA_REFCOUNT,
- N_("Error addjusting refcount for @a @b %b (@i %i): %m\n"),
+ N_("Error adjusting refcount for @a @b %b (@i %i): %m\n"),
PROMPT_NONE, 0 },
- /* Pass 1C: Scan directories for inodes with dup blocks. */
+ /* Pass 1C: Scan directories for inodes with multiply-claimed blocks. */
{ PR_1C_PASS_HEADER,
- N_("Pass 1C: Scan directories for @is with dup @bs.\n"),
+ N_("Pass 1C: Scanning directories for @is with @m @bs.\n"),
PROMPT_NONE, 0 },
- /* Pass 1D: Reconciling duplicate blocks */
+ /* Pass 1D: Reconciling multiply-claimed blocks */
{ PR_1D_PASS_HEADER,
- N_("Pass 1D: Reconciling duplicate @bs\n"),
+ N_("Pass 1D: Reconciling @m @bs\n"),
PROMPT_NONE, 0 },
/* File has duplicate blocks */
{ PR_1D_DUP_FILE,
- N_("File %Q (@i #%i, mod time %IM) \n"
- " has %B duplicate @b(s), shared with %N file(s):\n"),
+ N_("File %Q (@i #%i, mod time %IM)\n"
+ " has %B @m @b(s), shared with %N file(s):\n"),
PROMPT_NONE, 0 },
/* List of files sharing duplicate blocks */
/* Report of how many duplicate/bad inodes */
{ PR_1D_NUM_DUP_INODES,
- N_("(There are %N @is containing duplicate/bad @bs.)\n\n"),
+ N_("(There are %N @is containing @m @bs.)\n\n"),
PROMPT_NONE, 0 },
/* Duplicated blocks already reassigned or cloned. */
{ PR_1D_DUP_BLOCKS_DEALT,
- N_("Duplicated @bs already reassigned or cloned.\n\n"),
+ N_("@m @bs already reassigned or cloned.\n\n"),
PROMPT_NONE, 0 },
/* Clone duplicate/bad blocks? */
/* Bad inode number for '.' */
{ PR_2_BAD_INODE_DOT,
- N_("Bad @i number for '.' in @d @i %i.\n"),
+ N_("@n @i number for '.' in @d @i %i.\n"),
PROMPT_FIX, 0 },
/* Directory entry has bad inode number */
{ PR_2_BAD_INO,
- N_("@E has bad @i #: %Di.\n"),
+ N_("@E has @n @i #: %Di.\n"),
PROMPT_CLEAR, 0 },
/* Directory entry has deleted or unused inode */
/* First entry in directory inode doesn't contain '.' */
{ PR_2_1ST_NOT_DOT,
- N_("First @e '%Dn' (inode=%Di) in @d @i %i (%p) @s '.'\n"),
+ N_("First @e '%Dn' (@i=%Di) in @d @i %i (%p) @s '.'\n"),
PROMPT_FIX, 0 },
/* Second entry in directory inode doesn't contain '..' */
{ PR_2_2ND_NOT_DOT_DOT,
- N_("Second @e '%Dn' (inode=%Di) in @d @i %i @s '..'\n"),
+ N_("Second @e '%Dn' (@i=%Di) in @d @i %i @s '..'\n"),
PROMPT_FIX, 0 },
/* i_faddr should be zero */
/* inode has bad mode */
{ PR_2_BAD_MODE,
- N_("@i %i (%Q) has a bad mode (%Im).\n"),
+ N_("@i %i (%Q) has @n mode (%Im).\n"),
PROMPT_CLEAR, 0 },
/* directory corrupted */
/* Internal error: couldn't find dir_info */
{ PR_2_NO_DIRINFO,
- N_("Internal error: couldn't find dir_info for %i.\n"),
+ N_("Internal error: cannot find dir_info for %i.\n"),
PROMPT_NONE, PR_FATAL },
/* Final rec_len is wrong */
{ PR_2_FINAL_RECLEN,
- N_("@E has rec_len of %Dr, should be %N.\n"),
+ N_("@E has rec_len of %Dr, @s %N.\n"),
PROMPT_FIX, 0 },
/* Error allocating icount structure */
/* Directory filetype incorrect */
{ PR_2_BAD_FILETYPE,
- N_("@E has an incorrect filetype (was %Dt, should be %N).\n"),
+ N_("@E has an incorrect filetype (was %Dt, @s %N).\n"),
PROMPT_FIX, 0 },
/* Directory filetype set on filesystem */
/* Directory filename is null */
{ PR_2_NULL_NAME,
- N_("@E has a zero-length name.\n"),
+ N_("@E has a @z name.\n"),
PROMPT_CLEAR, 0 },
/* Invalid symlink */
{ PR_2_INVALID_SYMLINK,
- N_("Symlink %Q (@i #%i) is invalid.\n"),
+ N_("Symlink %Q (@i #%i) is @n.\n"),
PROMPT_CLEAR, 0 },
/* i_file_acl (extended attribute block) is bad */
{ PR_2_FILE_ACL_BAD,
- N_("@a @b @F invalid (%If).\n"),
+ N_("@a @b @F @n (%If).\n"),
PROMPT_CLEAR, 0 },
/* Filesystem contains large files, but has no such flag in sb */
/* Clear invalid HTREE directory */
{ PR_2_HTREE_CLEAR,
- N_("Invalid @h %d (%q). "), PROMPT_CLEAR, 0 },
+ N_("@n @h %d (%q). "), PROMPT_CLEAR, 0 },
/* Bad block in htree interior node */
{ PR_2_HTREE_BADBLK,
/* Error adjusting EA refcount */
{ PR_2_ADJ_EA_REFCOUNT,
- N_("Error addjusting refcount for @a @b %b (@i %i): %m\n"),
+ N_("Error adjusting refcount for @a @b %b (@i %i): %m\n"),
PROMPT_NONE, PR_FATAL },
/* Invalid HTREE root node */
{ PR_2_HTREE_BAD_ROOT,
- N_("@p @h %d: root node is invalid\n"),
+ N_("@p @h %d: root node is @n\n"),
PROMPT_CLEAR_HTREE, PR_PREEN_OK },
/* Invalid HTREE limit */
{ PR_2_HTREE_BAD_LIMIT,
- N_("@p @h %d: node (%B) has bad limit (%N)\n"),
+ N_("@p @h %d: node (%B) has @n limit (%N)\n"),
PROMPT_CLEAR_HTREE, PR_PREEN_OK },
/* Invalid HTREE count */
{ PR_2_HTREE_BAD_COUNT,
- N_("@p @h %d: node (%B) has bad count (%N)\n"),
+ N_("@p @h %d: node (%B) has @n count (%N)\n"),
PROMPT_CLEAR_HTREE, PR_PREEN_OK },
/* HTREE interior node has out-of-order hashes in table */
N_("@p @h %d: node (%B) has an unordered hash table\n"),
PROMPT_CLEAR_HTREE, PR_PREEN_OK },
- /* Node in HTREE directory has bad depth */
+ /* Node in HTREE directory has invalid depth */
{ PR_2_HTREE_BAD_DEPTH,
- N_("@p @h %d: node (%B) has bad depth\n"),
+ N_("@p @h %d: node (%B) has @n depth\n"),
PROMPT_NONE, 0 },
/* Duplicate directory entry found */
/* Couldn't fix parent directory -- couldn't find it */
{ PR_3_FIX_PARENT_NOFIND,
- N_("Couldn't fix parent of @i %i: Couldn't find parent @d entry\n\n"),
+ N_("Couldn't fix parent of @i %i: Couldn't find parent @d @e\n\n"),
PROMPT_NONE, 0 },
/* Error allocating inode bitmap */
/* Internal error: couldn't find dir_info */
{ PR_3_NO_DIRINFO,
- N_("Internal error: couldn't find dir_info for %i.\n"),
+ N_("Internal error: cannot find dir_info for %i.\n"),
PROMPT_NONE, PR_FATAL },
/* Lost+found not a directory */
/* Unattached zero-length inode */
{ PR_4_ZERO_LEN_INODE,
- "@u @z @i %i. ",
+ N_("@u @z @i %i. "),
PROMPT_CLEAR, PR_PREEN_OK|PR_NO_OK },
/* Unattached inode */
{ PR_4_UNATTACHED_INODE,
- "@u @i %i\n",
+ N_("@u @i %i\n"),
PROMPT_CONNECT, 0 },
/* Inode ref count wrong */
N_("WARNING: PROGRAMMING BUG IN E2FSCK!\n"
"\tOR SOME BONEHEAD (YOU) IS CHECKING A MOUNTED (LIVE) FILESYSTEM.\n"
"@i_link_info[%i] is %N, @i.i_links_count is %Il. "
- "They should be the same!\n"),
+ "They @s the same!\n"),
PROMPT_NONE, 0 },
/* Pass 5 errors */
/* Error copying in replacement inode bitmap */
{ PR_5_COPY_IBITMAP_ERROR,
- "Error copying in replacement @i @B: %m\n",
+ N_("Error copying in replacement @i @B: %m\n"),
PROMPT_NONE, PR_FATAL },
/* Error copying in replacement block bitmap */
{ PR_5_COPY_BBITMAP_ERROR,
- "Error copying in replacement @b @B: %m\n",
+ N_("Error copying in replacement @b @B: %m\n"),
PROMPT_NONE, PR_FATAL },
/* Block range not used, but marked in bitmap */
preenhalt(ctx);
if (ptr->flags & PR_FATAL)
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
if (ptr->prompt == PROMPT_NONE) {
if (ptr->flags & PR_NOCOLLATE)
}
if ((ptr->prompt == PROMPT_ABORT) && answer)
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
if (ptr->flags & PR_AFTER_CODE)
answer = fix_problem(ctx, ptr->second_code, pctx);
return answer;
}
+
/*
* linux/fs/recovery.c
*
* Written by Stephen C. Tweedie <sct@redhat.com>, 1999
- *
- * Copyright 1999-2000 Red Hat Software --- All Rights Reserved
- *
- * This file is part of the Linux kernel and is made available under
- * the terms of the GNU General Public License, version 2, or at your
- * option, any later version, incorporated herein by reference.
- *
- * Journal recovery routines for the generic filesystem journaling code;
- * part of the ext2fs journaling system.
*/
/*
static int scan_revoke_records(journal_t *, struct buffer_head *,
tid_t, struct recovery_info *);
-#ifdef __KERNEL__
-
-/* Release readahead buffers after use */
-void journal_brelse_array(struct buffer_head *b[], int n)
-{
- while (--n >= 0)
- brelse (b[n]);
-}
-
-
-/*
- * When reading from the journal, we are going through the block device
- * layer directly and so there is no readahead being done for us. We
- * need to implement any readahead ourselves if we want it to happen at
- * all. Recovery is basically one long sequential read, so make sure we
- * do the IO in reasonably large chunks.
- *
- * This is not so critical that we need to be enormously clever about
- * the readahead size, though. 128K is a purely arbitrary, good-enough
- * fixed value.
- */
-
-#define MAXBUF 8
-static int do_readahead(journal_t *journal, unsigned int start)
-{
- int err;
- unsigned int max, nbufs, next;
- unsigned long blocknr;
- struct buffer_head *bh;
-
- struct buffer_head * bufs[MAXBUF];
-
- /* Do up to 128K of readahead */
- max = start + (128 * 1024 / journal->j_blocksize);
- if (max > journal->j_maxlen)
- max = journal->j_maxlen;
-
- /* Do the readahead itself. We'll submit MAXBUF buffer_heads at
- * a time to the block device IO layer. */
-
- nbufs = 0;
-
- for (next = start; next < max; next++) {
- err = journal_bmap(journal, next, &blocknr);
-
- if (err) {
- printk (KERN_ERR "JBD: bad block at offset %u\n",
- next);
- goto failed;
- }
-
- bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
- if (!bh) {
- err = -ENOMEM;
- goto failed;
- }
-
- if (!buffer_uptodate(bh) && !buffer_locked(bh)) {
- bufs[nbufs++] = bh;
- if (nbufs == MAXBUF) {
- ll_rw_block(READ, nbufs, bufs);
- journal_brelse_array(bufs, nbufs);
- nbufs = 0;
- }
- } else
- brelse(bh);
- }
-
- if (nbufs)
- ll_rw_block(READ, nbufs, bufs);
- err = 0;
-
-failed:
- if (nbufs)
- journal_brelse_array(bufs, nbufs);
- return err;
-}
-
-#endif /* __KERNEL__ */
-
-
/*
* Read a block from the journal
*/
*bhp = NULL;
- J_ASSERT (offset < journal->j_maxlen);
-
err = journal_bmap(journal, offset, &blocknr);
if (err) {
- printk (KERN_ERR "JBD: bad block at offset %u\n",
- offset);
+ printf("JBD: bad block at offset %u\n", offset);
return err;
}
- bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
+ bh = getblk(journal->j_dev, blocknr, journal->j_blocksize);
if (!bh)
return -ENOMEM;
}
if (!buffer_uptodate(bh)) {
- printk (KERN_ERR "JBD: Failed to read block at offset %u\n",
- offset);
+ printf("JBD: Failed to read block at offset %u\n", offset);
brelse(bh);
return -EIO;
}
/* Make sure we wrap around the log correctly! */
-#define wrap(journal, var) \
-do { \
+#define wrap(journal, var) \
+do { \
if (var >= (journal)->j_last) \
var -= ((journal)->j_last - (journal)->j_first); \
} while (0)
*/
if (!sb->s_start) {
- jbd_debug(1, "No recovery required, last transaction %d\n",
- ntohl(sb->s_sequence));
journal->j_transaction_sequence = ntohl(sb->s_sequence) + 1;
return 0;
}
if (!err)
err = do_one_pass(journal, &info, PASS_REPLAY);
- jbd_debug(0, "JBD: recovery, exit status %d, "
- "recovered transactions %u to %u\n",
- err, info.start_transaction, info.end_transaction);
- jbd_debug(0, "JBD: Replayed %d and revoked %d/%d blocks\n",
- info.nr_replays, info.nr_revoke_hits, info.nr_revokes);
-
/* Restart the log at the next transaction ID, thus invalidating
* any existing commit records in the log. */
journal->j_transaction_sequence = ++info.end_transaction;
if (pass == PASS_SCAN)
info->start_transaction = first_commit_ID;
- jbd_debug(1, "Starting recovery pass %d\n", pass);
-
/*
* Now we walk through the log, transaction by transaction,
* making sure that each transaction has a commit block in the
if (tid_geq(next_commit_ID, info->end_transaction))
break;
- jbd_debug(2, "Scanning for sequence ID %u at %lu/%lu\n",
- next_commit_ID, next_log_block, journal->j_last);
-
/* Skip over each chunk of the transaction looking
* either the next descriptor block or the final commit
* record. */
- jbd_debug(3, "JBD: checking block %ld\n", next_log_block);
err = jread(&bh, journal, next_log_block);
if (err)
goto failed;
blocktype = ntohl(tmp->h_blocktype);
sequence = ntohl(tmp->h_sequence);
- jbd_debug(3, "Found magic %d, sequence %d\n",
- blocktype, sequence);
if (sequence != next_commit_ID) {
brelse(bh);
/* Recover what we can, but
* report failure at the end. */
success = err;
- printk (KERN_ERR
- "JBD: IO error %d recovering "
+ printf("JBD: IO error %d recovering "
"block %ld in log\n",
err, io_block);
} else {
unsigned long blocknr;
- J_ASSERT(obh != NULL);
blocknr = ntohl(tag->t_blocknr);
/* If the block has been
/* Find a buffer for the new
* data being restored */
- nbh = __getblk(journal->j_fs_dev,
+ nbh = getblk(journal->j_fs_dev,
blocknr,
journal->j_blocksize);
if (nbh == NULL) {
- printk(KERN_ERR
- "JBD: Out of memory "
+ printf("JBD: Out of memory "
"during recovery.\n");
err = -ENOMEM;
brelse(bh);
htonl(JFS_MAGIC_NUMBER);
}
- BUFFER_TRACE(nbh, "marking dirty");
- set_buffer_uptodate(nbh);
+ mark_buffer_uptodate(nbh, 1);
mark_buffer_dirty(nbh);
- BUFFER_TRACE(nbh, "marking uptodate");
++info->nr_replays;
/* ll_rw_block(WRITE, 1, &nbh); */
unlock_buffer(nbh);
continue;
default:
- jbd_debug(3, "Unrecognised magic %d, end of scan.\n",
- blocktype);
goto done;
}
}
/* It's really bad news if different passes end up at
* different places (but possible due to IO errors). */
if (info->end_transaction != next_commit_ID) {
- printk (KERN_ERR "JBD: recovery pass %d ended at "
+ printf("JBD: recovery pass %d ended at "
"transaction %u, expected %u\n",
pass, next_commit_ID, info->end_transaction);
if (!success)
}
return 0;
}
-/*
- * region.c --- code which manages allocations within a region.
- *
- * Copyright (C) 2001 Theodore Ts'o.
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
- * %End-Header%
- */
-
-struct region_el {
- region_addr_t start;
- region_addr_t end;
- struct region_el *next;
-};
-
-struct region_struct {
- region_addr_t min;
- region_addr_t max;
- struct region_el *allocated;
-};
-
-region_t region_create(region_addr_t min, region_addr_t max)
-{
- region_t region;
-
- region = malloc(sizeof(struct region_struct));
- if (!region)
- return NULL;
- memset(region, 0, sizeof(struct region_struct));
- region->min = min;
- region->max = max;
- return region;
-}
-
-void region_free(region_t region)
-{
- struct region_el *r, *next;
-
- for (r = region->allocated; r; r = next) {
- next = r->next;
- free(r);
- }
- memset(region, 0, sizeof(struct region_struct));
- free(region);
-}
-int region_allocate(region_t region, region_addr_t start, int n)
-{
- struct region_el *r, *new_region, *prev, *next;
- region_addr_t end;
-
- end = start+n;
- if ((start < region->min) || (end > region->max))
- return -1;
- if (n == 0)
- return 1;
-
- /*
- * Search through the linked list. If we find that it
- * conflicts witih something that's already allocated, return
- * 1; if we can find an existing region which we can grow, do
- * so. Otherwise, stop when we find the appropriate place
- * insert a new region element into the linked list.
- */
- for (r = region->allocated, prev=NULL; r; prev = r, r = r->next) {
- if (((start >= r->start) && (start < r->end)) ||
- ((end > r->start) && (end <= r->end)) ||
- ((start <= r->start) && (end >= r->end)))
- return 1;
- if (end == r->start) {
- r->start = start;
- return 0;
- }
- if (start == r->end) {
- if ((next = r->next)) {
- if (end > next->start)
- return 1;
- if (end == next->start) {
- r->end = next->end;
- r->next = next->next;
- free(next);
- return 0;
- }
- }
- r->end = end;
- return 0;
- }
- if (start < r->start)
- break;
- }
- /*
- * Insert a new region element structure into the linked list
- */
- new_region = malloc(sizeof(struct region_el));
- if (!new_region)
- return -1;
- new_region->start = start;
- new_region->end = start + n;
- new_region->next = r;
- if (prev)
- prev->next = new_region;
- else
- region->allocated = new_region;
- return 0;
-}
/*
* rehash.c --- rebuild hash tree directories
*
- * Copyright (C) 2002 Theodore Ts'o
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
- * %End-Header%
- *
* This algorithm is designed for simplicity of implementation and to
* pack the directory as much as possible. It however requires twice
* as much memory as the size of the directory. The maximum size
static int fill_dir_block(ext2_filsys fs,
blk_t *block_nr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct fill_dir_struct *fd = (struct fill_dir_struct *) priv_data;
}
/* Used for sorting the hash entry */
-static EXT2_QSORT_TYPE name_cmp(const void *a, const void *b)
+static int name_cmp(const void *a, const void *b)
{
const struct hash_entry *he_a = (const struct hash_entry *) a;
const struct hash_entry *he_b = (const struct hash_entry *) b;
}
/* Used for sorting the hash entry */
-static EXT2_QSORT_TYPE hash_cmp(const void *a, const void *b)
+static int hash_cmp(const void *a, const void *b)
{
const struct hash_entry *he_a = (const struct hash_entry *) a;
const struct hash_entry *he_b = (const struct hash_entry *) b;
static void free_out_dir(struct out_dir *outdir)
{
- if (outdir->buf)
- free(outdir->buf);
- if (outdir->hashes)
- free(outdir->hashes);
+ free(outdir->buf);
+ free(outdir->hashes);
outdir->max = 0;
outdir->num =0;
}
static int write_dir_block(ext2_filsys fs,
blk_t *block_nr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ blk_t ref_block FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct write_dir_struct *wd = (struct write_dir_struct *) priv_data;
return 0;
}
-errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino)
+static errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino)
{
ext2_filsys fs = ctx->fs;
errcode_t retval;
goto errout;
}
-#if 0
- printf("%d entries (%d bytes) found in inode %d\n",
- fd.num_array, fd.dir_size, ino);
-#endif
-
/* Sort the list */
resort:
if (fd.compress)
}
retval = write_directory(ctx, fs, &outdir, ino, fd.compress);
- if (retval)
- goto errout;
errout:
- if (dir_buf)
- free(dir_buf);
- if (fd.harray)
- free(fd.harray);
+ free(dir_buf);
+ free(fd.harray);
free_out_dir(&outdir);
return retval;
void e2fsck_rehash_directories(e2fsck_t ctx)
{
struct problem_context pctx;
-#ifdef RESOURCE_TRACK
- struct resource_track rtrack;
-#endif
struct dir_info *dir;
ext2_u32_iterate iter;
ext2_ino_t ino;
errcode_t retval;
int i, cur, max, all_dirs, dir_index, first = 1;
-#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
-#endif
-
all_dirs = ctx->options & E2F_OPT_COMPRESS_DIRS;
if (!ctx->dirs_to_hash && !all_dirs)
fix_problem(ctx, PR_3A_PASS_HEADER, &pctx);
first = 0;
}
-#if 0
- fix_problem(ctx, PR_3A_OPTIMIZE_DIR, &pctx);
-#endif
pctx.errcode = e2fsck_rehash_dir(ctx, ino);
if (pctx.errcode) {
end_problem_latch(ctx, PR_LATCH_OPTIMIZE_DIR);
if (!all_dirs)
ext2fs_u32_list_iterate_end(iter);
- if (ctx->dirs_to_hash)
- ext2fs_u32_list_free(ctx->dirs_to_hash);
+ ext2fs_u32_list_free(ctx->dirs_to_hash);
ctx->dirs_to_hash = 0;
-
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME2) {
- e2fsck_clear_progbar(ctx);
- print_resource_track("Pass 3A", &rtrack);
- }
-#endif
}
+
/*
* linux/fs/revoke.c
*
- * Written by Stephen C. Tweedie <sct@redhat.com>, 2000
- *
- * Copyright 2000 Red Hat corp --- All Rights Reserved
- *
- * This file is part of the Linux kernel and is made available under
- * the terms of the GNU General Public License, version 2, or at your
- * option, any later version, incorporated herein by reference.
- *
* Journal revoke routines for the generic filesystem journaling code;
* part of the ext2fs journaling system.
*
};
-#ifdef __KERNEL__
-static void write_one_revoke_record(journal_t *, transaction_t *,
- struct journal_head **, int *,
- struct jbd_revoke_record_s *);
-static void flush_descriptor(journal_t *, struct journal_head *, int);
-#endif
-
/* Utility functions to maintain the revoke table */
/* Borrowed from buffer.c: this is a tried and tested block hash function */
-static inline int hash(journal_t *journal, unsigned long block)
+static int hash(journal_t *journal, unsigned long block)
{
struct jbd_revoke_table_s *table = journal->j_revoke;
int hash_shift = table->hash_shift;
struct list_head *hash_list;
struct jbd_revoke_record_s *record;
-#ifdef __KERNEL__
-repeat:
-#endif
record = kmem_cache_alloc(revoke_record_cache, GFP_NOFS);
if (!record)
goto oom;
return 0;
oom:
-#ifdef __KERNEL__
- if (!journal_oom_retry)
- return -ENOMEM;
- jbd_debug(1, "ENOMEM in " __FUNCTION__ ", retrying.\n");
- current->policy |= SCHED_YIELD;
- schedule();
- goto repeat;
-#else
return -ENOMEM;
-#endif
}
/* Find a revoke record in the journal's hash table. */
int journal_init_revoke_caches(void)
{
- revoke_record_cache = kmem_cache_create("revoke_record",
- sizeof(struct jbd_revoke_record_s),
- 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
+ revoke_record_cache = do_cache_create(sizeof(struct jbd_revoke_record_s));
if (revoke_record_cache == 0)
return -ENOMEM;
- revoke_table_cache = kmem_cache_create("revoke_table",
- sizeof(struct jbd_revoke_table_s),
- 0, 0, NULL, NULL);
+ revoke_table_cache = do_cache_create(sizeof(struct jbd_revoke_table_s));
if (revoke_table_cache == 0) {
- kmem_cache_destroy(revoke_record_cache);
+ do_cache_destroy(revoke_record_cache);
revoke_record_cache = NULL;
return -ENOMEM;
}
void journal_destroy_revoke_caches(void)
{
- kmem_cache_destroy(revoke_record_cache);
+ do_cache_destroy(revoke_record_cache);
revoke_record_cache = 0;
- kmem_cache_destroy(revoke_table_cache);
+ do_cache_destroy(revoke_table_cache);
revoke_table_cache = 0;
}
{
int shift, tmp;
- J_ASSERT (journal->j_revoke == NULL);
-
journal->j_revoke = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
if (!journal->j_revoke)
return -ENOMEM;
/* Check that the hash_size is a power of two */
- J_ASSERT ((hash_size & (hash_size-1)) == 0);
-
journal->j_revoke->hash_size = hash_size;
shift = 0;
shift++;
journal->j_revoke->hash_shift = shift;
- journal->j_revoke->hash_table =
- kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL);
+ journal->j_revoke->hash_table = malloc(hash_size * sizeof(struct list_head));
if (!journal->j_revoke->hash_table) {
- kmem_cache_free(revoke_table_cache, journal->j_revoke);
+ free(journal->j_revoke);
journal->j_revoke = NULL;
return -ENOMEM;
}
for (i=0; i<table->hash_size; i++) {
hash_list = &table->hash_table[i];
- J_ASSERT (list_empty(hash_list));
}
- kfree(table->hash_table);
- kmem_cache_free(revoke_table_cache, table);
+ free(table->hash_table);
+ free(table);
journal->j_revoke = NULL;
}
-
-#ifdef __KERNEL__
-
-/*
- * journal_revoke: revoke a given buffer_head from the journal. This
- * prevents the block from being replayed during recovery if we take a
- * crash after this current transaction commits. Any subsequent
- * metadata writes of the buffer in this transaction cancel the
- * revoke.
- *
- * Note that this call may block --- it is up to the caller to make
- * sure that there are no further calls to journal_write_metadata
- * before the revoke is complete. In ext3, this implies calling the
- * revoke before clearing the block bitmap when we are deleting
- * metadata.
- *
- * Revoke performs a journal_forget on any buffer_head passed in as a
- * parameter, but does _not_ forget the buffer_head if the bh was only
- * found implicitly.
- *
- * bh_in may not be a journalled buffer - it may have come off
- * the hash tables without an attached journal_head.
- *
- * If bh_in is non-zero, journal_revoke() will decrement its b_count
- * by one.
- */
-
-int journal_revoke(handle_t *handle, unsigned long blocknr,
- struct buffer_head *bh_in)
-{
- struct buffer_head *bh = NULL;
- journal_t *journal;
- kdev_t dev;
- int err;
-
- if (bh_in)
- BUFFER_TRACE(bh_in, "enter");
-
- journal = handle->h_transaction->t_journal;
- if (!journal_set_features(journal, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE)){
- J_ASSERT (!"Cannot set revoke feature!");
- return -EINVAL;
- }
-
- dev = journal->j_fs_dev;
- bh = bh_in;
-
- if (!bh) {
- bh = get_hash_table(dev, blocknr, journal->j_blocksize);
- if (bh)
- BUFFER_TRACE(bh, "found on hash");
- }
-#ifdef JBD_EXPENSIVE_CHECKING
- else {
- struct buffer_head *bh2;
-
- /* If there is a different buffer_head lying around in
- * memory anywhere... */
- bh2 = get_hash_table(dev, blocknr, journal->j_blocksize);
- if (bh2) {
- /* ... and it has RevokeValid status... */
- if ((bh2 != bh) &&
- test_bit(BH_RevokeValid, &bh2->b_state))
- /* ...then it better be revoked too,
- * since it's illegal to create a revoke
- * record against a buffer_head which is
- * not marked revoked --- that would
- * risk missing a subsequent revoke
- * cancel. */
- J_ASSERT_BH(bh2, test_bit(BH_Revoked, &
- bh2->b_state));
- __brelse(bh2);
- }
- }
-#endif
-
- /* We really ought not ever to revoke twice in a row without
- first having the revoke cancelled: it's illegal to free a
- block twice without allocating it in between! */
- if (bh) {
- J_ASSERT_BH(bh, !test_bit(BH_Revoked, &bh->b_state));
- set_bit(BH_Revoked, &bh->b_state);
- set_bit(BH_RevokeValid, &bh->b_state);
- if (bh_in) {
- BUFFER_TRACE(bh_in, "call journal_forget");
- journal_forget(handle, bh_in);
- } else {
- BUFFER_TRACE(bh, "call brelse");
- __brelse(bh);
- }
- }
-
- lock_journal(journal);
- jbd_debug(2, "insert revoke for block %lu, bh_in=%p\n", blocknr, bh_in);
- err = insert_revoke_hash(journal, blocknr,
- handle->h_transaction->t_tid);
- unlock_journal(journal);
- BUFFER_TRACE(bh_in, "exit");
- return err;
-}
-
-/*
- * Cancel an outstanding revoke. For use only internally by the
- * journaling code (called from journal_get_write_access).
- *
- * We trust the BH_Revoked bit on the buffer if the buffer is already
- * being journaled: if there is no revoke pending on the buffer, then we
- * don't do anything here.
- *
- * This would break if it were possible for a buffer to be revoked and
- * discarded, and then reallocated within the same transaction. In such
- * a case we would have lost the revoked bit, but when we arrived here
- * the second time we would still have a pending revoke to cancel. So,
- * do not trust the Revoked bit on buffers unless RevokeValid is also
- * set.
- *
- * The caller must have the journal locked.
- */
-int journal_cancel_revoke(handle_t *handle, struct journal_head *jh)
-{
- struct jbd_revoke_record_s *record;
- journal_t *journal = handle->h_transaction->t_journal;
- int need_cancel;
- int did_revoke = 0; /* akpm: debug */
- struct buffer_head *bh = jh2bh(jh);
-
- jbd_debug(4, "journal_head %p, cancelling revoke\n", jh);
-
- /* Is the existing Revoke bit valid? If so, we trust it, and
- * only perform the full cancel if the revoke bit is set. If
- * not, we can't trust the revoke bit, and we need to do the
- * full search for a revoke record. */
- if (test_and_set_bit(BH_RevokeValid, &bh->b_state))
- need_cancel = (test_and_clear_bit(BH_Revoked, &bh->b_state));
- else {
- need_cancel = 1;
- clear_bit(BH_Revoked, &bh->b_state);
- }
-
- if (need_cancel) {
- record = find_revoke_record(journal, bh->b_blocknr);
- if (record) {
- jbd_debug(4, "cancelled existing revoke on "
- "blocknr %lu\n", bh->b_blocknr);
- list_del(&record->hash);
- kmem_cache_free(revoke_record_cache, record);
- did_revoke = 1;
- }
- }
-
-#ifdef JBD_EXPENSIVE_CHECKING
- /* There better not be one left behind by now! */
- record = find_revoke_record(journal, bh->b_blocknr);
- J_ASSERT_JH(jh, record == NULL);
-#endif
-
- /* Finally, have we just cleared revoke on an unhashed
- * buffer_head? If so, we'd better make sure we clear the
- * revoked status on any hashed alias too, otherwise the revoke
- * state machine will get very upset later on. */
- if (need_cancel && !bh->b_pprev) {
- struct buffer_head *bh2;
- bh2 = get_hash_table(bh->b_dev, bh->b_blocknr, bh->b_size);
- if (bh2) {
- clear_bit(BH_Revoked, &bh2->b_state);
- __brelse(bh2);
- }
- }
-
- return did_revoke;
-}
-
-
-/*
- * Write revoke records to the journal for all entries in the current
- * revoke hash, deleting the entries as we go.
- *
- * Called with the journal lock held.
- */
-
-void journal_write_revoke_records(journal_t *journal,
- transaction_t *transaction)
-{
- struct journal_head *descriptor;
- struct jbd_revoke_record_s *record;
- struct jbd_revoke_table_s *revoke;
- struct list_head *hash_list;
- int i, offset, count;
-
- descriptor = NULL;
- offset = 0;
- count = 0;
- revoke = journal->j_revoke;
-
- for (i = 0; i < revoke->hash_size; i++) {
- hash_list = &revoke->hash_table[i];
-
- while (!list_empty(hash_list)) {
- record = (struct jbd_revoke_record_s *)
- hash_list->next;
- write_one_revoke_record(journal, transaction,
- &descriptor, &offset,
- record);
- count++;
- list_del(&record->hash);
- kmem_cache_free(revoke_record_cache, record);
- }
- }
- if (descriptor)
- flush_descriptor(journal, descriptor, offset);
- jbd_debug(1, "Wrote %d revoke records\n", count);
-}
-
-/*
- * Write out one revoke record. We need to create a new descriptor
- * block if the old one is full or if we have not already created one.
- */
-
-static void write_one_revoke_record(journal_t *journal,
- transaction_t *transaction,
- struct journal_head **descriptorp,
- int *offsetp,
- struct jbd_revoke_record_s *record)
-{
- struct journal_head *descriptor;
- int offset;
- journal_header_t *header;
-
- /* If we are already aborting, this all becomes a noop. We
- still need to go round the loop in
- journal_write_revoke_records in order to free all of the
- revoke records: only the IO to the journal is omitted. */
- if (is_journal_aborted(journal))
- return;
-
- descriptor = *descriptorp;
- offset = *offsetp;
-
- /* Make sure we have a descriptor with space left for the record */
- if (descriptor) {
- if (offset == journal->j_blocksize) {
- flush_descriptor(journal, descriptor, offset);
- descriptor = NULL;
- }
- }
-
- if (!descriptor) {
- descriptor = journal_get_descriptor_buffer(journal);
- if (!descriptor)
- return;
- header = (journal_header_t *) &jh2bh(descriptor)->b_data[0];
- header->h_magic = htonl(JFS_MAGIC_NUMBER);
- header->h_blocktype = htonl(JFS_REVOKE_BLOCK);
- header->h_sequence = htonl(transaction->t_tid);
-
- /* Record it so that we can wait for IO completion later */
- JBUFFER_TRACE(descriptor, "file as BJ_LogCtl");
- journal_file_buffer(descriptor, transaction, BJ_LogCtl);
-
- offset = sizeof(journal_revoke_header_t);
- *descriptorp = descriptor;
- }
-
- * ((unsigned int *)(&jh2bh(descriptor)->b_data[offset])) =
- htonl(record->blocknr);
- offset += 4;
- *offsetp = offset;
-}
-
-/*
- * Flush a revoke descriptor out to the journal. If we are aborting,
- * this is a noop; otherwise we are generating a buffer which needs to
- * be waited for during commit, so it has to go onto the appropriate
- * journal buffer list.
- */
-
-static void flush_descriptor(journal_t *journal,
- struct journal_head *descriptor,
- int offset)
-{
- journal_revoke_header_t *header;
-
- if (is_journal_aborted(journal)) {
- JBUFFER_TRACE(descriptor, "brelse");
- __brelse(jh2bh(descriptor));
- return;
- }
-
- header = (journal_revoke_header_t *) jh2bh(descriptor)->b_data;
- header->r_count = htonl(offset);
- set_bit(BH_JWrite, &jh2bh(descriptor)->b_state);
- {
- struct buffer_head *bh = jh2bh(descriptor);
- BUFFER_TRACE(bh, "write");
- ll_rw_block (WRITE, 1, &bh);
- }
-}
-
-#endif
-
/*
* Revoke support for recovery.
*
* single block.
*/
-int journal_set_revoke(journal_t *journal,
- unsigned long blocknr,
+int journal_set_revoke(journal_t *journal, unsigned long blocknr,
tid_t sequence)
{
struct jbd_revoke_record_s *record;
* ones, but later transactions still need replayed.
*/
-int journal_test_revoke(journal_t *journal,
- unsigned long blocknr,
+int journal_test_revoke(journal_t *journal, unsigned long blocknr,
tid_t sequence)
{
struct jbd_revoke_record_s *record;
while (!list_empty(hash_list)) {
record = (struct jbd_revoke_record_s*) hash_list->next;
list_del(&record->hash);
- kmem_cache_free(revoke_record_cache, record);
+ free(record);
}
}
}
/*
* e2fsck.c - superblock checks
- *
- * 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%
*/
#define MIN_CHECK 1
* e2fsck code..
*/
#ifndef EXT2_SPECIAL_DEVICE_SIZE
-errcode_t e2fsck_get_device_size(e2fsck_t ctx)
+static errcode_t e2fsck_get_device_size(e2fsck_t ctx)
{
return (ext2fs_get_device_size(ctx->filesystem_name,
EXT2_BLOCK_SIZE(ctx->fs->super),
errcode_t errcode;
};
-static int release_inode_block(ext2_filsys fs,
- blk_t *block_nr,
+static int release_inode_block(ext2_filsys fs, blk_t *block_nr,
e2_blkcnt_t blockcnt,
- blk_t ref_blk EXT2FS_ATTR((unused)),
- int ref_offset EXT2FS_ATTR((unused)),
+ blk_t ref_blk FSCK_ATTR((unused)),
+ int ref_offset FSCK_ATTR((unused)),
void *priv_data)
{
struct process_block_struct *pb;
retval = ext2fs_block_iterate2(fs, ino, BLOCK_FLAG_DEPTH_TRAVERSE,
block_buf, release_inode_block, &pb);
if (retval) {
- com_err("release_inode_blocks", retval,
- _("while calling ext2fs_block_iterate for inode %d"),
+ bb_error_msg(_("while calling ext2fs_block_iterate for inode %d"),
ino);
return 1;
}
count = 1;
}
if (retval) {
- com_err("release_inode_blocks", retval,
- _("while calling ext2fs_adjust_ea_refocunt for inode %d"),
+ bb_error_msg(_("while calling ext2fs_adjust_ea_refocunt for inode %d"),
ino);
return 1;
}
}
}
- /* Read the resizde inode */
+ /* Read the resize inode */
pctx.ino = EXT2_RESIZE_INO;
retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode);
if (retval) {
}
cleanup:
- if (dind_buf)
- ext2fs_free_mem(&dind_buf);
+ ext2fs_free_mem(&dind_buf);
}
-void check_super_block(e2fsck_t ctx)
+static void check_super_block(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
blk_t first_block, last_block;
clear_problem_context(&pctx);
-#ifndef EXT2_SKIP_UUID
/*
* If the UUID field isn't assigned, assign it.
*/
fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
}
}
-#endif
- /*
+ /* FIXME - HURD support?
* For the Hurd, check to see if the filetype option is set,
* since it doesn't support it.
*/
e2fsck_move_ext3_journal(ctx);
return;
}
+
/*
* swapfs.c --- byte-swap an ext2 filesystem
- *
- * Copyright 1996, 1997 by Theodore Ts'o
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
- * %End-Header%
- *
*/
#ifdef ENABLE_SWAPFS
retval = ext2fs_block_iterate(ctx->fs, ino, 0, block_buf,
swap_block, &sb);
if (retval) {
- com_err("swap_inode_blocks", retval,
- _("while calling ext2fs_block_iterate"));
+ bb_error_msg(_("while calling ext2fs_block_iterate"));
ctx->flags |= E2F_FLAG_ABORT;
return;
}
if (sb.errcode) {
- com_err("swap_inode_blocks", sb.errcode,
- _("while calling iterator function"));
+ bb_error_msg(_("while calling iterator function"));
ctx->flags |= E2F_FLAG_ABORT;
return;
}
retval = ext2fs_get_mem(fs->blocksize * fs->inode_blocks_per_group,
&buf);
if (retval) {
- com_err("swap_inodes", retval,
- _("while allocating inode buffer"));
+ bb_error_msg(_("while allocating inode buffer"));
ctx->flags |= E2F_FLAG_ABORT;
return;
}
fs->group_desc[group].bg_inode_table,
fs->inode_blocks_per_group, buf);
if (retval) {
- com_err("swap_inodes", retval,
- _("while reading inode table (group %d)"),
+ bb_error_msg(_("while reading inode table (group %d)"),
group);
ctx->flags |= E2F_FLAG_ABORT;
return;
fs->group_desc[group].bg_inode_table,
fs->inode_blocks_per_group, buf);
if (retval) {
- com_err("swap_inodes", retval,
- _("while writing inode table (group %d)"),
+ bb_error_msg(_("while writing inode table (group %d)"),
group);
ctx->flags |= E2F_FLAG_ABORT;
return;
ext2fs_flush_icache(fs);
}
-#if defined(__powerpc__) && defined(EXT2FS_ENABLE_SWAPFS)
+#if defined(__powerpc__) && BB_BIG_ENDIAN
/*
* On the PowerPC, the big-endian variant of the ext2 filesystem
* has its bitmaps stored as 32-bit words with bit 0 as the LSB
#ifdef ENABLE_SWAPFS
-void swap_filesys(e2fsck_t ctx)
+static void swap_filesys(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
-#ifdef RESOURCE_TRACK
- struct resource_track rtrack;
-
- init_resource_track(&rtrack);
-#endif
-
if (!(ctx->options & E2F_OPT_PREEN))
printf(_("Pass 0: Doing byte-swap of filesystem\n"));
-#ifdef MTRACE
- mtrace_print("Byte swap");
-#endif
+ /* Byte swap */
if (fs->super->s_mnt_count) {
fprintf(stderr, _("%s: the filesystem must be freshly "
fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
ext2fs_flush(fs);
fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
-
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME2)
- print_resource_track(_("Byte swap"), &rtrack);
-#endif
}
#endif /* ENABLE_SWAPFS */
#endif
+
/*
* util.c --- miscellaneous utilities
- *
- * 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%
*/
-#ifdef HAVE_CONIO_H
-#undef HAVE_TERMIOS_H
-#include <conio.h>
-#define read_a_char() getch()
-#else
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
-#endif
-#endif
-
-#if 0
-void fatal_error(e2fsck_t ctx, const char *msg)
-{
- if (msg)
- fprintf (stderr, "e2fsck: %s\n", msg);
- if (ctx->fs && ctx->fs->io) {
- if (ctx->fs->io->magic == EXT2_ET_MAGIC_IO_CHANNEL)
- io_channel_flush(ctx->fs->io);
- else
- fprintf(stderr, "e2fsck: io manager magic bad!\n");
- }
- ctx->flags |= E2F_FLAG_ABORT;
- if (ctx->flags & E2F_FLAG_SETJMP_OK)
- longjmp(ctx->abort_loc, 1);
- exit(FSCK_ERROR);
-}
-#endif
void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
const char *description)
void *ret;
char buf[256];
-#ifdef DEBUG_ALLOCATE_MEMORY
- printf("Allocating %d bytes for %s...\n", size, description);
-#endif
ret = malloc(size);
if (!ret) {
sprintf(buf, "Can't allocate %s\n", description);
- fatal_error(ctx, buf);
+ bb_error_msg_and_die(buf);
}
memset(ret, 0, size);
return ret;
}
-char *string_copy(e2fsck_t ctx EXT2FS_ATTR((unused)),
- const char *str, int len)
+static char *string_copy(const char *str, int len)
{
char *ret;
}
#endif
-int ask_yn(const char * string, int def)
+static int ask_yn(const char * string, int def)
{
int c;
const char *defstr;
- const char *short_yes = _("yY");
- const char *short_no = _("nN");
+ static const char short_yes[] = "yY";
+ static const char short_no[] = "nN";
#ifdef HAVE_TERMIOS_H
struct termios termios, tmp;
#endif
if (def == 1)
- defstr = _(_("<y>"));
+ defstr = "<y>";
else if (def == 0)
- defstr = _(_("<n>"));
+ defstr = "<n>";
else
- defstr = _(" (y/n)");
+ defstr = " (y/n)";
printf("%s%s? ", string, defstr);
while (1) {
fflush (stdout);
break;
}
if (def)
- puts(_("yes\n"));
+ puts("yes\n");
else
- puts (_("no\n"));
+ puts ("no\n");
#ifdef HAVE_TERMIOS_H
tcsetattr (0, TCSANOW, &termios);
#endif
int ask (e2fsck_t ctx, const char * string, int def)
{
if (ctx->options & E2F_OPT_NO) {
- printf (_("%s? no\n\n"), string);
+ printf(_("%s? no\n\n"), string);
return 0;
}
if (ctx->options & E2F_OPT_YES) {
- printf (_("%s? yes\n\n"), string);
+ printf(_("%s? yes\n\n"), string);
return 1;
}
if (ctx->options & E2F_OPT_PREEN) {
- printf ("%s? %s\n\n", string, def ? _("yes") : _("no"));
+ printf("%s? %s\n\n", string, def ? _("yes") : _("no"));
return def;
}
return ask_yn(string, def);
errcode_t retval;
if (ctx->invalid_bitmaps) {
- com_err(ctx->program_name, 0,
- _("e2fsck_read_bitmaps: illegal bitmap block(s) for %s"),
+ bb_error_msg(_("e2fsck_read_bitmaps: illegal bitmap block(s) for %s"),
ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
ehandler_operation(_("reading inode and block bitmaps"));
retval = ext2fs_read_bitmaps(fs);
ehandler_operation(0);
if (retval) {
- com_err(ctx->program_name, retval,
- _("while retrying to read bitmaps for %s"),
+ bb_error_msg(_("while retrying to read bitmaps for %s"),
ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
}
-void e2fsck_write_bitmaps(e2fsck_t ctx)
+static void e2fsck_write_bitmaps(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
errcode_t retval;
retval = ext2fs_write_block_bitmap(fs);
ehandler_operation(0);
if (retval) {
- com_err(ctx->program_name, retval,
- _("while retrying to write block bitmaps for %s"),
+ bb_error_msg(_("while retrying to write block bitmaps for %s"),
ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
}
retval = ext2fs_write_inode_bitmap(fs);
ehandler_operation(0);
if (retval) {
- com_err(ctx->program_name, retval,
- _("while retrying to write inode bitmaps for %s"),
+ bb_error_msg(_("while retrying to write inode bitmaps for %s"),
ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
}
}
ext2fs_mark_super_dirty(fs);
ext2fs_close(fs);
}
- exit(FSCK_UNCORRECTED);
-}
-
-#ifdef RESOURCE_TRACK
-void init_resource_track(struct resource_track *track)
-{
-#ifdef HAVE_GETRUSAGE
- struct rusage r;
-#endif
-
- track->brk_start = sbrk(0);
- gettimeofday(&track->time_start, 0);
-#ifdef HAVE_GETRUSAGE
-#ifdef sun
- memset(&r, 0, sizeof(struct rusage));
-#endif
- getrusage(RUSAGE_SELF, &r);
- track->user_start = r.ru_utime;
- track->system_start = r.ru_stime;
-#else
- track->user_start.tv_sec = track->user_start.tv_usec = 0;
- track->system_start.tv_sec = track->system_start.tv_usec = 0;
-#endif
-}
-
-static _INLINE_ float timeval_subtract(struct timeval *tv1,
- struct timeval *tv2)
-{
- return ((tv1->tv_sec - tv2->tv_sec) +
- ((float) (tv1->tv_usec - tv2->tv_usec)) / 1000000);
-}
-
-void print_resource_track(const char *desc, struct resource_track *track)
-{
-#ifdef HAVE_GETRUSAGE
- struct rusage r;
-#endif
-#ifdef HAVE_MALLINFO
- struct mallinfo malloc_info;
-#endif
- struct timeval time_end;
-
- gettimeofday(&time_end, 0);
-
- if (desc)
- printf("%s: ", desc);
-
-#ifdef HAVE_MALLINFO
-#define kbytes(x) (((x) + 1023) / 1024)
-
- malloc_info = mallinfo();
- printf(_("Memory used: %dk/%dk (%dk/%dk), "),
- kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
- kbytes(malloc_info.uordblks), kbytes(malloc_info.fordblks));
-#else
- printf(_("Memory used: %d, "),
- (int) (((char *) sbrk(0)) - ((char *) track->brk_start)));
-#endif
-#ifdef HAVE_GETRUSAGE
- getrusage(RUSAGE_SELF, &r);
-
- printf(_("time: %5.2f/%5.2f/%5.2f\n"),
- timeval_subtract(&time_end, &track->time_start),
- timeval_subtract(&r.ru_utime, &track->user_start),
- timeval_subtract(&r.ru_stime, &track->system_start));
-#else
- printf(_("elapsed time: %6.3f\n"),
- timeval_subtract(&time_end, &track->time_start));
-#endif
+ exit(EXIT_UNCORRECTED);
}
-#endif /* RESOURCE_TRACK */
void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
struct ext2_inode * inode, const char *proc)
retval = ext2fs_read_inode(ctx->fs, ino, inode);
if (retval) {
- com_err("ext2fs_read_inode", retval,
- _("while reading inode %ld in %s"), ino, proc);
- fatal_error(ctx, 0);
+ bb_error_msg(_("while reading inode %ld in %s"), ino, proc);
+ bb_error_msg_and_die(0);
}
}
retval = ext2fs_write_inode_full(ctx->fs, ino, inode, bufsize);
if (retval) {
- com_err("ext2fs_write_inode", retval,
- _("while writing inode %ld in %s"), ino, proc);
- fatal_error(ctx, 0);
+ bb_error_msg(_("while writing inode %ld in %s"), ino, proc);
+ bb_error_msg_and_die(0);
}
}
retval = ext2fs_write_inode(ctx->fs, ino, inode);
if (retval) {
- com_err("ext2fs_write_inode", retval,
- _("while writing inode %ld in %s"), ino, proc);
- fatal_error(ctx, 0);
+ bb_error_msg(_("while writing inode %ld in %s"), ino, proc);
+ bb_error_msg_and_die(0);
}
}
-#ifdef MTRACE
-void mtrace_print(char *mesg)
-{
- FILE *malloc_get_mallstream();
- FILE *f = malloc_get_mallstream();
-
- if (f)
- fprintf(f, "============= %s\n", mesg);
-}
-#endif
-
blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
io_manager manager)
{
if (io_channel_read_blk(io, superblock,
-SUPERBLOCK_SIZE, buf))
continue;
-#ifdef EXT2FS_ENABLE_SWAPFS
+#if BB_BIG_ENDIAN
if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
ext2fs_swap_super(sb);
#endif
cleanup:
if (io)
io_channel_close(io);
- if (buf)
- ext2fs_free_mem(&buf);
+ ext2fs_free_mem(&buf);
return (ret_sb);
}
+
/*
- * Given a mode, return the ext2 file type
+ * This function runs through the e2fsck passes and calls them all,
+ * returning restart, abort, or cancel as necessary...
*/
-int ext2_file_type(unsigned int mode)
-{
- if (LINUX_S_ISREG(mode))
- return EXT2_FT_REG_FILE;
-
- if (LINUX_S_ISDIR(mode))
- return EXT2_FT_DIR;
+typedef void (*pass_t)(e2fsck_t ctx);
- if (LINUX_S_ISCHR(mode))
- return EXT2_FT_CHRDEV;
+static const pass_t e2fsck_passes[] = {
+ e2fsck_pass1, e2fsck_pass2, e2fsck_pass3, e2fsck_pass4,
+ e2fsck_pass5, 0 };
- if (LINUX_S_ISBLK(mode))
- return EXT2_FT_BLKDEV;
+#define E2F_FLAG_RUN_RETURN (E2F_FLAG_SIGNAL_MASK|E2F_FLAG_RESTART)
- if (LINUX_S_ISLNK(mode))
- return EXT2_FT_SYMLINK;
+static int e2fsck_run(e2fsck_t ctx)
+{
+ int i;
+ pass_t e2fsck_pass;
- if (LINUX_S_ISFIFO(mode))
- return EXT2_FT_FIFO;
+ if (setjmp(ctx->abort_loc)) {
+ ctx->flags &= ~E2F_FLAG_SETJMP_OK;
+ return (ctx->flags & E2F_FLAG_RUN_RETURN);
+ }
+ ctx->flags |= E2F_FLAG_SETJMP_OK;
- if (LINUX_S_ISSOCK(mode))
- return EXT2_FT_SOCK;
+ for (i=0; (e2fsck_pass = e2fsck_passes[i]); i++) {
+ if (ctx->flags & E2F_FLAG_RUN_RETURN)
+ break;
+ e2fsck_pass(ctx);
+ if (ctx->progress)
+ (void) (ctx->progress)(ctx, 0, 0, 0);
+ }
+ ctx->flags &= ~E2F_FLAG_SETJMP_OK;
+ if (ctx->flags & E2F_FLAG_RUN_RETURN)
+ return (ctx->flags & E2F_FLAG_RUN_RETURN);
return 0;
}
+
+
/*
* unix.c - The unix-specific code for e2fsck
- *
- * 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%
*/
-
/* Command line options */
static int swapfs;
#ifdef ENABLE_SWAPFS
static int show_version_only;
static int verbose;
-static int replace_bad_blocks;
-static int keep_bad_blocks;
-static char *bad_blocks_file;
-
-#ifdef __CONFIG_JBD_DEBUG__E2FS /* Enabled by configure --enable-jfs-debug */
-int journal_enable_debug = -1;
-#endif
-
-#if 0
-static void usage(e2fsck_t ctx)
-{
- fprintf(stderr,
- _("Usage: %s [-panyrcdfvstDFSV] [-b superblock] [-B blocksize]\n"
- "\t\t[-I inode_buffer_blocks] [-P process_inode_size]\n"
- "\t\t[-l|-L bad_blocks_file] [-C fd] [-j ext-journal]\n"
- "\t\t[-E extended-options] device\n"),
- ctx->program_name);
-
- fprintf(stderr, _("\nEmergency help:\n"
- " -p Automatic repair (no questions)\n"
- " -n Make no changes to the filesystem\n"
- " -y Assume \"yes\" to all questions\n"
- " -c Check for bad blocks and add them to the badblock list\n"
- " -f Force checking even if filesystem is marked clean\n"));
- fprintf(stderr, _(""
- " -v Be verbose\n"
- " -b superblock Use alternative superblock\n"
- " -B blocksize Force blocksize when looking for superblock\n"
- " -j external-journal Set location of the external journal\n"
- " -l bad_blocks_file Add to badblocks list\n"
- " -L bad_blocks_file Set badblocks list\n"
- ));
-
- exit(FSCK_USAGE);
-}
-#endif
+#define P_E2(singular, plural, n) n, ((n) == 1 ? singular : plural)
static void show_stats(e2fsck_t ctx)
{
blocks_used, blocks);
return;
}
- printf (P_("\n%8d inode used (%d%%)\n", "\n%8d inodes used (%d%%)\n",
- inodes_used), inodes_used, 100 * inodes_used / inodes);
- printf (P_("%8d non-contiguous inode (%0d.%d%%)\n",
- "%8d non-contiguous inodes (%0d.%d%%)\n",
- ctx->fs_fragmented),
- ctx->fs_fragmented, frag_percent / 10, frag_percent % 10);
- printf (_(" # of inodes with ind/dind/tind blocks: %d/%d/%d\n"),
+ printf("\n%8d inode%s used (%d%%)\n", P_E2("", "s", inodes_used),
+ 100 * inodes_used / inodes);
+ printf("%8d non-contiguous inode%s (%0d.%d%%)\n",
+ P_E2("", "s", ctx->fs_fragmented),
+ frag_percent / 10, frag_percent % 10);
+ printf(_(" # of inodes with ind/dind/tind blocks: %d/%d/%d\n"),
ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
- printf (P_("%8d block used (%d%%)\n", "%8d blocks used (%d%%)\n",
- blocks_used),
- blocks_used, (int) ((long long) 100 * blocks_used / blocks));
- printf (P_("%8d bad block\n", "%8d bad blocks\n",
- ctx->fs_badblocks_count), ctx->fs_badblocks_count);
- printf (P_("%8d large file\n", "%8d large files\n",
- ctx->large_files), ctx->large_files);
- printf (P_("\n%8d regular file\n", "\n%8d regular files\n",
- ctx->fs_regular_count), ctx->fs_regular_count);
- printf (P_("%8d directory\n", "%8d directories\n",
- ctx->fs_directory_count), ctx->fs_directory_count);
- printf (P_("%8d character device file\n",
- "%8d character device files\n", ctx->fs_chardev_count),
- ctx->fs_chardev_count);
- printf (P_("%8d block device file\n", "%8d block device files\n",
- ctx->fs_blockdev_count), ctx->fs_blockdev_count);
- printf (P_("%8d fifo\n", "%8d fifos\n", ctx->fs_fifo_count),
- ctx->fs_fifo_count);
- printf (P_("%8d link\n", "%8d links\n",
- ctx->fs_links_count - dir_links),
- ctx->fs_links_count - dir_links);
- printf (P_("%8d symbolic link", "%8d symbolic links",
- ctx->fs_symlinks_count), ctx->fs_symlinks_count);
- printf (P_(" (%d fast symbolic link)\n", " (%d fast symbolic links)\n",
- ctx->fs_fast_symlinks_count), ctx->fs_fast_symlinks_count);
- printf (P_("%8d socket\n", "%8d sockets\n", ctx->fs_sockets_count),
- ctx->fs_sockets_count);
- printf ("--------\n");
- printf (P_("%8d file\n", "%8d files\n",
- ctx->fs_total_count - dir_links),
- ctx->fs_total_count - dir_links);
+ printf("%8d block%s used (%d%%)\n", P_E2("", "s", blocks_used),
+ (int) ((long long) 100 * blocks_used / blocks));
+ printf("%8d large file%s\n", P_E2("", "s", ctx->large_files));
+ printf("\n%8d regular file%s\n", P_E2("", "s", ctx->fs_regular_count));
+ printf("%8d director%s\n", P_E2("y", "ies", ctx->fs_directory_count));
+ printf("%8d character device file%s\n", P_E2("", "s", ctx->fs_chardev_count));
+ printf("%8d block device file%s\n", P_E2("", "s", ctx->fs_blockdev_count));
+ printf("%8d fifo%s\n", P_E2("", "s", ctx->fs_fifo_count));
+ printf("%8d link%s\n", P_E2("", "s", ctx->fs_links_count - dir_links));
+ printf("%8d symbolic link%s", P_E2("", "s", ctx->fs_symlinks_count));
+ printf(" (%d fast symbolic link%s)\n", P_E2("", "s", ctx->fs_fast_symlinks_count));
+ printf("%8d socket%s--------\n\n", P_E2("", "s", ctx->fs_sockets_count));
+ printf("%8d file%s\n", P_E2("", "s", ctx->fs_total_count - dir_links));
}
static void check_mount(e2fsck_t ctx)
retval = ext2fs_check_if_mounted(ctx->filesystem_name,
&ctx->mount_flags);
if (retval) {
- com_err("ext2fs_check_if_mount", retval,
- _("while determining whether %s is mounted."),
+ bb_error_msg(_("while determining whether %s is mounted."),
ctx->filesystem_name);
return;
}
printf(_("%s is mounted. "), ctx->filesystem_name);
if (!ctx->interactive)
- fatal_error(ctx, _("Cannot continue, aborting.\n\n"));
+ bb_error_msg_and_die(_("Cannot continue, aborting."));
printf(_("\n\n\007\007\007\007WARNING!!! "
"Running e2fsck on a mounted filesystem may cause\n"
"SEVERE filesystem damage.\007\007\007\n\n"));
cont = ask_yn(_("Do you really want to continue"), -1);
if (!cont) {
- printf (_("check aborted.\n"));
+ printf(_("check aborted.\n"));
exit (0);
}
return;
/*
* This routine checks to see if a filesystem can be skipped; if so,
- * it will exit with E2FSCK_OK. Under some conditions it will print a
+ * it will exit with EXIT_OK. Under some conditions it will print a
* message explaining why a check is being forced.
*/
static void check_if_skip(e2fsck_t ctx)
int batt = is_on_batt();
time_t now = time(0);
- if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file ||
- cflag || swapfs)
+ if ((ctx->options & E2F_OPT_FORCE) || cflag || swapfs)
return;
if ((fs->super->s_state & EXT2_ERROR_FS) ||
ext2fs_close(fs);
ctx->fs = NULL;
e2fsck_free_context(ctx);
- exit(FSCK_OK);
+ exit(EXIT_OK);
}
/*
int max_pass;
int table[32];
};
-static struct percent_tbl e2fsck_tbl = {
+static const struct percent_tbl e2fsck_tbl = {
5, { 0, 70, 90, 92, 95, 100 }
};
+
static char bar[128], spaces[128];
-static float calc_percent(struct percent_tbl *tbl, int pass, int curr,
+static float calc_percent(const struct percent_tbl *tbl, int pass, int curr,
int max)
{
float percent;
+ tbl->table[pass-1]);
}
-extern void e2fsck_clear_progbar(e2fsck_t ctx)
+void e2fsck_clear_progbar(e2fsck_t ctx)
{
if (!(ctx->flags & E2F_FLAG_PROG_BAR))
return;
return 0;
}
-#define PATH_SET "PATH=/sbin"
-
static void reserve_stdio_fds(void)
{
int fd;
while (1) {
- fd = open("/dev/null", O_RDWR);
+ fd = open(bb_dev_null, O_RDWR);
if (fd > 2)
break;
if (fd < 0) {
- fprintf(stderr, _("ERROR: Couldn't open "
+ fprintf(stderr, _("ERROR: Cannot open "
"/dev/null (%s)\n"),
strerror(errno));
break;
close(fd);
}
-static void signal_progress_on(int sig EXT2FS_ATTR((unused)))
+static void signal_progress_on(int sig FSCK_ATTR((unused)))
{
e2fsck_t ctx = e2fsck_global_ctx;
ctx->progress_fd = 0;
}
-static void signal_progress_off(int sig EXT2FS_ATTR((unused)))
+static void signal_progress_off(int sig FSCK_ATTR((unused)))
{
e2fsck_t ctx = e2fsck_global_ctx;
ctx->progress = 0;
}
-static void signal_cancel(int sig EXT2FS_ATTR((unused)))
+static void signal_cancel(int sig FSCK_ATTR((unused)))
{
e2fsck_t ctx = e2fsck_global_ctx;
int ea_ver;
int extended_usage = 0;
- buf = string_copy(ctx, opts, 0);
+ buf = string_copy(opts, 0);
for (token = buf; token && *token; token = next) {
p = strchr(token, ',');
next = 0;
continue;
}
ctx->ext_attr_ver = ea_ver;
- } else
+ } else {
+ fprintf(stderr, _("Unknown extended option: %s\n"),
+ token);
extended_usage++;
+ }
}
if (extended_usage) {
- fprintf(stderr, _("Extended options are separated by commas, "
+ bb_error_msg_and_die(
+ "Extended options are separated by commas, "
"and may take an argument which\n"
"is set off by an equals ('=') sign. "
- "Valid raid options are:\n"
- "\tea_ver=<ea_version (1 or 2)\n\n"));
- exit(1);
+ "Valid extended options are:\n"
+ "\tea_ver=<ea_version (1 or 2)>\n\n");
}
}
{
int flush = 0;
int c, fd;
-#ifdef MTRACE
- extern void *mallwatch;
-#endif
e2fsck_t ctx;
errcode_t retval;
struct sigaction sa;
_("Error validating file descriptor %d: %s\n"),
ctx->progress_fd,
error_message(errno));
- fatal_error(ctx,
- _("Invalid completion information file descriptor"));
+ bb_error_msg_and_die(_("Invalid completion information file descriptor"));
} else
close(fd);
break;
case 'a':
if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) {
conflict_opt:
- fatal_error(ctx,
- _("Only one the options -p/-a, -n or -y may be specified."));
+ bb_error_msg_and_die(_("Only one the options -p/-a, -n or -y may be specified."));
}
ctx->options |= E2F_OPT_PREEN;
break;
ctx->options |= E2F_OPT_YES;
break;
case 't':
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME)
- ctx->options |= E2F_OPT_TIME2;
- else
- ctx->options |= E2F_OPT_TIME;
-#else
+ /* FIXME - This needs to go away in a future path - will change binary */
fprintf(stderr, _("The -t option is not "
"supported on this version of e2fsck.\n"));
-#endif
break;
case 'c':
if (cflag++)
ctx->inode_buffer_blocks = atoi(optarg);
break;
case 'j':
- ctx->journal_name = string_copy(ctx, optarg, 0);
+ ctx->journal_name = string_copy(optarg, 0);
break;
case 'P':
ctx->process_inode_size = atoi(optarg);
break;
- case 'L':
- replace_bad_blocks++;
- case 'l':
- bad_blocks_file = string_copy(ctx, optarg, 0);
- break;
case 'd':
ctx->options |= E2F_OPT_DEBUG;
break;
case 'V':
show_version_only = 1;
break;
-#ifdef MTRACE
- case 'M':
- mallwatch = (void *) strtol(optarg, NULL, 0);
- break;
-#endif
case 'N':
ctx->device_name = optarg;
break;
"of e2fsck\n"));
exit(1);
#endif
- case 'k':
- keep_bad_blocks++;
- break;
default:
- usage();
+ bb_show_usage();
}
if (show_version_only)
return 0;
if (optind != argc - 1)
- usage();
- if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file &&
+ bb_show_usage();
+ if ((ctx->options & E2F_OPT_NO) &&
!cflag && !swapfs && !(ctx->options & E2F_OPT_COMPRESS_DIRS))
ctx->options |= E2F_OPT_READONLY;
ctx->io_options = strchr(argv[optind], '?');
*ctx->io_options++ = 0;
ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0);
if (!ctx->filesystem_name) {
- com_err(ctx->program_name, 0, _("Unable to resolve '%s'"),
- argv[optind]);
- fatal_error(ctx, 0);
+ bb_error_msg(_("Unable to resolve '%s'"), argv[optind]);
+ bb_error_msg_and_die(0);
}
if (extended_opts)
parse_extended_opts(ctx, extended_opts);
if (flush) {
fd = open(ctx->filesystem_name, O_RDONLY, 0);
if (fd < 0) {
- com_err("open", errno,
- _("while opening %s for flushing"),
+ bb_error_msg(_("while opening %s for flushing"),
ctx->filesystem_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
if ((retval = ext2fs_sync_device(fd, 1))) {
- com_err("ext2fs_sync_device", retval,
- _("while trying to flush %s"),
+ bb_error_msg(_("while trying to flush %s"),
ctx->filesystem_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
close(fd);
}
#ifdef ENABLE_SWAPFS
- if (swapfs) {
- if (cflag || bad_blocks_file) {
+ if (swapfs && cflag) {
fprintf(stderr, _("Incompatible options not "
"allowed when byte-swapping.\n"));
- exit(FSCK_USAGE);
- }
+ exit(EXIT_USAGE);
}
#endif
- if (cflag && bad_blocks_file) {
- fprintf(stderr, _("The -c and the -l/-L options may "
- "not be both used at the same time.\n"));
- exit(FSCK_USAGE);
- }
/*
* Set up signal action
*/
sigaction(SIGUSR2, &sa, 0);
/* Update our PATH to include /sbin if we need to run badblocks */
- if (cflag) {
- char *oldpath = getenv("PATH");
- if (oldpath) {
- char *newpath;
-
- newpath = (char *) malloc(sizeof (PATH_SET) + 1 +
- strlen (oldpath));
- if (!newpath)
- fatal_error(ctx, "Couldn't malloc() newpath");
- strcpy (newpath, PATH_SET);
- strcat (newpath, ":");
- strcat (newpath, oldpath);
- putenv (newpath);
- } else
- putenv (PATH_SET);
- }
-#ifdef __CONFIG_JBD_DEBUG__E2FS
- if (getenv("E2FSCK_JBD_DEBUG"))
- journal_enable_debug = atoi(getenv("E2FSCK_JBD_DEBUG"));
-#endif
+ if (cflag)
+ e2fs_set_sbin_path();
return 0;
}
-static const char *my_ver_string = E2FSPROGS_VERSION;
-static const char *my_ver_date = E2FSPROGS_DATE;
+static const char my_ver_string[] = E2FSPROGS_VERSION;
+static const char my_ver_date[] = E2FSPROGS_DATE;
int e2fsck_main (int argc, char *argv[])
{
- errcode_t retval = 0;
- int exit_value = FSCK_OK;
+ errcode_t retval;
+ int exit_value = EXIT_OK;
ext2_filsys fs = 0;
io_manager io_ptr;
struct ext2_super_block *sb;
int flags, run_result;
clear_problem_context(&pctx);
-#ifdef MTRACE
- mtrace();
-#endif
-#ifdef MCHECK
- mcheck(0);
-#endif
-#ifdef ENABLE_NLS
- setlocale(LC_MESSAGES, "");
- setlocale(LC_CTYPE, "");
- bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
- textdomain(NLS_CAT_NAME);
-#endif
+
my_ver = ext2fs_parse_version_string(my_ver_string);
lib_ver = ext2fs_get_library_version(0, &lib_ver_date);
if (my_ver > lib_ver) {
retval = PRS(argc, argv, &ctx);
if (retval) {
- com_err("e2fsck", retval,
- _("while trying to initialize program"));
- exit(FSCK_ERROR);
+ bb_error_msg(_("while trying to initialize program"));
+ exit(EXIT_ERROR);
}
reserve_stdio_fds();
-#ifdef RESOURCE_TRACK
- init_resource_track(&ctx->global_rtrack);
-#endif
-
if (!(ctx->options & E2F_OPT_PREEN) || show_version_only)
fprintf(stderr, "e2fsck %s (%s)\n", my_ver_string,
my_ver_date);
if (show_version_only) {
fprintf(stderr, _("\tUsing %s, %s\n"),
error_message(EXT2_ET_BASE), lib_ver_date);
- exit(FSCK_OK);
+ exit(EXIT_OK);
}
check_mount(ctx);
!(ctx->options & E2F_OPT_NO) &&
!(ctx->options & E2F_OPT_YES)) {
if (!ctx->interactive)
- fatal_error(ctx,
- _("need terminal for interactive repairs"));
+ bb_error_msg_and_die(_("need terminal for interactive repairs"));
}
ctx->superblock = ctx->use_superblock;
restart:
}
}
if (retval) {
- com_err(ctx->program_name, retval, _("while trying to open %s"),
+ bb_error_msg(_("while trying to open %s"),
ctx->filesystem_name);
if (retval == EXT2_ET_REV_TOO_HIGH) {
printf(_("The filesystem revision is apparently "
#endif
else
fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
ctx->fs = fs;
fs->priv_data = ctx;
sb = fs->super;
if (sb->s_rev_level > E2FSCK_CURRENT_REV) {
- com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH,
- _("while trying to open %s"),
+ bb_error_msg(_("while trying to open %s"),
ctx->filesystem_name);
get_newer:
- fatal_error(ctx, _("Get a newer version of e2fsck!"));
+ bb_error_msg_and_die(_("Get a newer version of e2fsck!"));
}
/*
*/
if (ctx->device_name == 0 &&
(sb->s_volume_name[0] != 0)) {
- ctx->device_name = string_copy(ctx, sb->s_volume_name,
+ ctx->device_name = string_copy(sb->s_volume_name,
sizeof(sb->s_volume_name));
}
if (ctx->device_name == 0)
*/
retval = e2fsck_check_ext3_journal(ctx);
if (retval) {
- com_err(ctx->program_name, retval,
- _("while checking ext3 journal for %s"),
+ bb_error_msg(_("while checking ext3 journal for %s"),
ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
/*
* happen, unless the hardware or
* device driver is being bogus.
*/
- com_err(ctx->program_name, 0,
- _("unable to set superblock flags on %s\n"), ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg(_("cannot set superblock flags on %s"), ctx->device_name);
+ bb_error_msg_and_die(0);
}
retval = e2fsck_run_ext3_journal(ctx);
if (retval) {
- com_err(ctx->program_name, retval,
- _("while recovering ext3 journal of %s"),
+ bb_error_msg(_("while recovering ext3 journal of %s"),
ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
ext2fs_close(ctx->fs);
ctx->fs = 0;
*/
if ((sb->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP) ||
(sb->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP)) {
- com_err(ctx->program_name, EXT2_ET_UNSUPP_FEATURE,
- "(%s)", ctx->device_name);
+ bb_error_msg("(%s)", ctx->device_name);
goto get_newer;
}
if (sb->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) {
- com_err(ctx->program_name, EXT2_ET_RO_UNSUPP_FEATURE,
- "(%s)", ctx->device_name);
+ bb_error_msg("(%s)", ctx->device_name);
goto get_newer;
}
#ifdef ENABLE_COMPRESSION
+ /* FIXME - do we support this at all? */
if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION)
- com_err(ctx->program_name, 0,
- _("Warning: compression support is experimental.\n"));
+ bb_error_msg(_("Warning: compression support is experimental."));
#endif
#ifndef ENABLE_HTREE
if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {
- com_err(ctx->program_name, 0,
- _("E2fsck not compiled with HTREE support,\n\t"
- "but filesystem %s has HTREE directories.\n"),
+ bb_error_msg(_("E2fsck not compiled with HTREE support,\n\t"
+ "but filesystem %s has HTREE directories."),
ctx->device_name);
goto get_newer;
}
ext2fs_mark_valid(fs);
check_super_block(ctx);
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
check_if_skip(ctx);
- if (bad_blocks_file)
- read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks);
- else if (cflag)
- read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
#ifdef ENABLE_SWAPFS
+
+#ifdef WORDS_BIGENDIAN
+#define NATIVE_FLAG EXT2_FLAG_SWAP_BYTES
+#else
+#define NATIVE_FLAG 0
+#endif
+
+
if (normalize_swapfs) {
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ==
- ext2fs_native_flag()) {
+ if ((fs->flags & EXT2_FLAG_SWAP_BYTES) == NATIVE_FLAG) {
fprintf(stderr, _("%s: Filesystem byte order "
"already normalized.\n"), ctx->device_name);
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
}
if (swapfs) {
swap_filesys(ctx);
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- fatal_error(ctx, 0);
+ bb_error_msg_and_die(0);
}
#endif
retval = ext2fs_read_bb_inode(fs, &fs->badblocks);
if (retval) {
- com_err(ctx->program_name, retval,
- _("while reading bad blocks inode"));
+ bb_error_msg(_("while reading bad blocks inode"));
preenhalt(ctx);
printf(_("This doesn't bode well,"
" but we'll try to go on...\n"));
printf(_("Restarting e2fsck from the beginning...\n"));
retval = e2fsck_reset_context(ctx);
if (retval) {
- com_err(ctx->program_name, retval,
- _("while resetting context"));
- fatal_error(ctx, 0);
+ bb_error_msg(_("while resetting context"));
+ bb_error_msg_and_die(0);
}
ext2fs_close(fs);
goto restart;
exit_value |= FSCK_CANCELED;
}
if (run_result & E2F_FLAG_ABORT)
- fatal_error(ctx, _("aborted"));
+ bb_error_msg_and_die(_("aborted"));
-#ifdef MTRACE
- mtrace_print("Cleanup");
-#endif
+ /* Cleanup */
if (ext2fs_test_changed(fs)) {
- exit_value |= FSCK_NONDESTRUCT;
+ exit_value |= EXIT_NONDESTRUCT;
if (!(ctx->options & E2F_OPT_PREEN))
printf(_("\n%s: ***** FILE SYSTEM WAS MODIFIED *****\n"),
ctx->device_name);
if (ctx->mount_flags & EXT2_MF_ISROOT) {
printf(_("%s: ***** REBOOT LINUX *****\n"),
ctx->device_name);
- exit_value |= FSCK_REBOOT;
+ exit_value |= EXIT_DESTRUCT;
}
}
if (!ext2fs_test_valid(fs)) {
printf(_("\n%s: ********** WARNING: Filesystem still has "
"errors **********\n\n"), ctx->device_name);
- exit_value |= FSCK_UNCORRECTED;
- exit_value &= ~FSCK_NONDESTRUCT;
+ exit_value |= EXIT_UNCORRECTED;
+ exit_value &= ~EXIT_NONDESTRUCT;
}
if (exit_value & FSCK_CANCELED)
- exit_value &= ~FSCK_NONDESTRUCT;
+ exit_value &= ~EXIT_NONDESTRUCT;
else {
show_stats(ctx);
if (!(ctx->options & E2F_OPT_READONLY)) {
if (ext2fs_test_valid(fs)) {
if (!(sb->s_state & EXT2_VALID_FS))
- exit_value |= FSCK_NONDESTRUCT;
+ exit_value |= EXIT_NONDESTRUCT;
sb->s_state = EXT2_VALID_FS;
} else
sb->s_state &= ~EXT2_VALID_FS;
free(ctx->journal_name);
e2fsck_free_context(ctx);
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME)
- print_resource_track(NULL, &ctx->global_rtrack);
-#endif
-
return exit_value;
}