Big dead code elimination pass from Garrett.

This commit is contained in:
Rob Landley 2006-05-03 21:58:45 +00:00
parent db2ab89b7c
commit 7c94bed234
24 changed files with 138 additions and 449 deletions

View File

@ -14,44 +14,27 @@
#define E2FSPROGS_VERSION "1.38" #define E2FSPROGS_VERSION "1.38"
#define E2FSPROGS_DATE "30-Jun-2005" #define E2FSPROGS_DATE "30-Jun-2005"
/* make sure com_err.h isnt included before us */
#ifdef __COM_ERR_H__
#error You should not have included com_err.h !
#endif
#define __COM_ERR_H__
/* com_err crap */
#define com_err(w, c, fmt, args...) bb_error_msg(fmt, ## args)
typedef long errcode_t; typedef long errcode_t;
#define ERRCODE_RANGE 8 #define ERRCODE_RANGE 8
#define error_message(code) strerror((int) (code & ((1<<ERRCODE_RANGE)-1))) #define error_message(code) strerror((int) (code & ((1<<ERRCODE_RANGE)-1)))
/* misc crap */
#define fatal_error(err, msg) bb_error_msg_and_die(msg)
#define usage() bb_show_usage()
/* header defines */ /* header defines */
#define ENABLE_HTREE 1 #define ENABLE_HTREE 1
#define HAVE_ERRNO_H 1 #define HAVE_ERRNO_H 1
#define HAVE_EXT2_IOCTLS 1 #define HAVE_EXT2_IOCTLS 1
#define HAVE_INTTYPES_H 1
#define HAVE_LINUX_FD_H 1 #define HAVE_LINUX_FD_H 1
#define HAVE_MALLOC_H 1
#define HAVE_MNTENT_H 1 #define HAVE_MNTENT_H 1
#define HAVE_NETINET_IN_H 1 #define HAVE_NETINET_IN_H 1
#define HAVE_NET_IF_H 1 #define HAVE_NET_IF_H 1
#define HAVE_SYS_IOCTL_H 1 #define HAVE_SYS_IOCTL_H 1
#define HAVE_SYS_MOUNT_H 1 #define HAVE_SYS_MOUNT_H 1
#define HAVE_SYS_QUEUE_H 1 #define HAVE_SYS_QUEUE_H 1
#define HAVE_SYS_RESOURCE_H 1
#define HAVE_SYS_SOCKET_H 1
#define HAVE_SYS_STAT_H 1 #define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TYPES_H 1 #define HAVE_SYS_TYPES_H 1
#define HAVE_UNISTD_H 1 #define HAVE_UNISTD_H 1
/* Endianness */ /* Endianness */
#if __BYTE_ORDER == __BIG_ENDIAN #if BB_BIG_ENDIAN
#define ENABLE_SWAPFS 1 #define ENABLE_SWAPFS 1
#define WORDS_BIGENDIAN 1 #define WORDS_BIGENDIAN 1
#endif #endif

View File

@ -2,6 +2,7 @@
* e2fsck * e2fsck
* *
* Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o. * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
* Copyright (C) 2006 Garrett Kajmowicz
* This file may be * This file may be
* redistributed under the terms of the GNU Public License. * redistributed under the terms of the GNU Public License.
* *
@ -38,14 +39,6 @@
#include "e2fsck.h" /*Put all of our defines here to clean things up*/ #include "e2fsck.h" /*Put all of our defines here to clean things up*/
#ifdef __GNUC__
#define _INLINE_ __inline__
#define EXT2FS_ATTR(x) __attribute__(x)
#else
#define _INLINE_
#define EXT2FS_ATTR(x)
#endif
/* /*
* Procedure declarations * Procedure declarations
*/ */
@ -219,7 +212,7 @@ typedef struct {
* functions. * 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; kmem_cache_t *new_cache;
@ -229,7 +222,7 @@ static _INLINE_ kmem_cache_t * do_cache_create(int len)
return new_cache; return new_cache;
} }
static _INLINE_ void do_cache_destroy(kmem_cache_t *cache) static void do_cache_destroy(kmem_cache_t *cache)
{ {
free(cache); free(cache);
} }
@ -266,8 +259,7 @@ static void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
retval = ext2fs_block_iterate(fs, EXT2_BAD_INO, 0, 0, retval = ext2fs_block_iterate(fs, EXT2_BAD_INO, 0, 0,
check_bb_inode_blocks, 0); check_bb_inode_blocks, 0);
if (retval) { if (retval) {
com_err("ext2fs_block_iterate", retval, bb_error_msg(_("while sanity checking the bad blocks inode"));
_("while sanity checking the bad blocks inode"));
goto fatal; goto fatal;
} }
@ -278,8 +270,7 @@ static void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
if (!replace_bad_blocks) { if (!replace_bad_blocks) {
retval = ext2fs_read_bb_inode(fs, &bb_list); retval = ext2fs_read_bb_inode(fs, &bb_list);
if (retval) { if (retval) {
com_err("ext2fs_read_bb_inode", retval, bb_error_msg(_("while reading the bad blocks inode"));
_("while reading the bad blocks inode"));
goto fatal; goto fatal;
} }
} }
@ -292,8 +283,7 @@ static void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
if (bad_blocks_file) { if (bad_blocks_file) {
f = fopen(bad_blocks_file, "r"); f = fopen(bad_blocks_file, "r");
if (!f) { if (!f) {
com_err("read_bad_blocks_file", errno, bb_error_msg(_("while trying to open %s"), bad_blocks_file);
_("while trying to open %s"), bad_blocks_file);
goto fatal; goto fatal;
} }
} else { } else {
@ -303,8 +293,7 @@ static void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
fs->device_name, fs->super->s_blocks_count); fs->device_name, fs->super->s_blocks_count);
f = popen(buf, "r"); f = popen(buf, "r");
if (!f) { if (!f) {
com_err("read_bad_blocks_file", errno, bb_error_msg(_("while trying popen '%s'"), buf);
_("while trying popen '%s'"), buf);
goto fatal; goto fatal;
} }
} }
@ -314,8 +303,7 @@ static void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
else else
pclose(f); pclose(f);
if (retval) { if (retval) {
com_err("ext2fs_read_bb_FILE", retval, bb_error_msg(_("while reading in list of bad blocks from file"));
_("while reading in list of bad blocks from file"));
goto fatal; goto fatal;
} }
@ -324,8 +312,7 @@ static void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
*/ */
retval = ext2fs_update_bb_inode(fs, bb_list); retval = ext2fs_update_bb_inode(fs, bb_list);
if (retval) { if (retval) {
com_err("ext2fs_update_bb_inode", retval, bb_error_msg(_("while updating bad block inode"));
_("while updating bad block inode"));
goto fatal; goto fatal;
} }
@ -390,7 +377,6 @@ static int check_bb_inode_blocks(ext2_filsys fs,
#define dict_root(D) ((D)->nilnode.left) #define dict_root(D) ((D)->nilnode.left)
#define dict_nil(D) (&(D)->nilnode) #define dict_nil(D) (&(D)->nilnode)
#define DICT_DEPTH_MAX 64
static void dnode_free(dnode_t *node); static void dnode_free(dnode_t *node);
@ -1528,8 +1514,6 @@ static void ehandler_init(io_channel channel)
* any later version. * any later version.
*/ */
#define MNT_FL (MS_MGC_VAL | MS_RDONLY)
/* /*
* Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths. * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
* This creates a larger static binary, and a smaller binary using * This creates a larger static binary, and a smaller binary using
@ -1608,8 +1592,7 @@ static void ll_rw_block(int rw, int nr, struct buffer_head *bhp[])
bh->b_blocknr, bh->b_blocknr,
1, bh->b_data); 1, bh->b_data);
if (retval) { if (retval) {
com_err(bh->b_ctx->device_name, retval, bb_error_msg("while reading block %lu\n",
"while reading block %lu\n",
(unsigned long) bh->b_blocknr); (unsigned long) bh->b_blocknr);
bh->b_err = retval; bh->b_err = retval;
continue; continue;
@ -1620,8 +1603,7 @@ static void ll_rw_block(int rw, int nr, struct buffer_head *bhp[])
bh->b_blocknr, bh->b_blocknr,
1, bh->b_data); 1, bh->b_data);
if (retval) { if (retval) {
com_err(bh->b_ctx->device_name, retval, bb_error_msg("while writing block %lu\n",
"while writing block %lu\n",
(unsigned long) bh->b_blocknr); (unsigned long) bh->b_blocknr);
bh->b_err = retval; bh->b_err = retval;
continue; continue;
@ -1831,7 +1813,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
memcpy(&jsuper, start ? bh->b_data : bh->b_data + 1024, memcpy(&jsuper, start ? bh->b_data : bh->b_data + 1024,
sizeof(jsuper)); sizeof(jsuper));
brelse(bh); brelse(bh);
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (jsuper.s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) if (jsuper.s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
ext2fs_swap_super(&jsuper); ext2fs_swap_super(&jsuper);
#endif #endif
@ -1937,8 +1919,7 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
ll_rw_block(READ, 1, &jbh); ll_rw_block(READ, 1, &jbh);
if (jbh->b_err) { if (jbh->b_err) {
com_err(ctx->device_name, jbh->b_err, bb_error_msg(_("reading journal superblock\n"));
_("reading journal superblock\n"));
return jbh->b_err; return jbh->b_err;
} }
@ -1994,8 +1975,7 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
* format to be able to proceed safely, so any other checks that * format to be able to proceed safely, so any other checks that
* fail we should attempt to recover from. */ * fail we should attempt to recover from. */
if (jsb->s_blocksize != htonl(journal->j_blocksize)) { if (jsb->s_blocksize != htonl(journal->j_blocksize)) {
com_err(ctx->program_name, EXT2_ET_CORRUPT_SUPERBLOCK, bb_error_msg(_("%s: no valid journal superblock found\n"),
_("%s: no valid journal superblock found\n"),
ctx->device_name); ctx->device_name);
return EXT2_ET_CORRUPT_SUPERBLOCK; return EXT2_ET_CORRUPT_SUPERBLOCK;
} }
@ -2003,8 +1983,7 @@ static errcode_t e2fsck_journal_load(journal_t *journal)
if (ntohl(jsb->s_maxlen) < journal->j_maxlen) if (ntohl(jsb->s_maxlen) < journal->j_maxlen)
journal->j_maxlen = ntohl(jsb->s_maxlen); journal->j_maxlen = ntohl(jsb->s_maxlen);
else if (ntohl(jsb->s_maxlen) > journal->j_maxlen) { else if (ntohl(jsb->s_maxlen) > journal->j_maxlen) {
com_err(ctx->program_name, EXT2_ET_CORRUPT_SUPERBLOCK, bb_error_msg(_("%s: journal too short\n"),
_("%s: journal too short\n"),
ctx->device_name); ctx->device_name);
return EXT2_ET_CORRUPT_SUPERBLOCK; return EXT2_ET_CORRUPT_SUPERBLOCK;
} }
@ -2297,10 +2276,9 @@ static int e2fsck_run_ext3_journal(e2fsck_t ctx)
&ctx->fs); &ctx->fs);
if (retval) { if (retval) {
com_err(ctx->program_name, retval, bb_error_msg(_("while trying to re-open %s"),
_("while trying to re-open %s"),
ctx->device_name); ctx->device_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
ctx->fs->priv_data = ctx; ctx->fs->priv_data = ctx;
@ -2737,7 +2715,7 @@ static void expand_inode_expression(char ch,
/* /*
* This function expands '%dX' expressions * 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 problem_context *ctx)
{ {
struct ext2_dir_entry *dirent; struct ext2_dir_entry *dirent;
@ -2776,7 +2754,7 @@ static _INLINE_ void expand_dirent_expression(char ch,
} }
} }
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) struct problem_context *ctx)
{ {
if (!ctx) if (!ctx)
@ -3036,7 +3014,7 @@ static void alloc_imagic_map(e2fsck_t ctx);
static void mark_inode_bad(e2fsck_t ctx, ino_t ino); static void mark_inode_bad(e2fsck_t ctx, ino_t ino);
static void handle_fs_bad_blocks(e2fsck_t ctx); static void handle_fs_bad_blocks(e2fsck_t ctx);
static void process_inodes(e2fsck_t ctx, char *block_buf); static void process_inodes(e2fsck_t ctx, char *block_buf);
static EXT2_QSORT_TYPE process_inode_cmp(const void *a, const void *b); static int process_inode_cmp(const void *a, const void *b);
static errcode_t scan_callback(ext2_filsys fs, ext2_inode_scan scan, static errcode_t scan_callback(ext2_filsys fs, ext2_inode_scan scan,
dgrp_t group, void * priv_data); dgrp_t group, void * priv_data);
static void adjust_extattr_refcount(e2fsck_t ctx, ext2_refcount_t refcount, static void adjust_extattr_refcount(e2fsck_t ctx, ext2_refcount_t refcount,
@ -3929,7 +3907,7 @@ static void process_inodes(e2fsck_t ctx, char *block_buf)
ehandler_operation(old_operation); 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 *ib_a =
(const struct process_inode_block *) a; (const struct process_inode_block *) a;
@ -4015,7 +3993,7 @@ static void alloc_imagic_map(e2fsck_t ctx)
* WARNING: Assumes checks have already been done to make sure block * WARNING: Assumes checks have already been done to make sure block
* is valid. This is true in both process_block and process_bad_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; struct problem_context pctx;
@ -5522,8 +5500,7 @@ static int delete_file_block(ext2_filsys fs,
p = (struct dup_block *) dnode_get(n); p = (struct dup_block *) dnode_get(n);
decrement_badcount(ctx, *block_nr, p); decrement_badcount(ctx, *block_nr, p);
} else } else
com_err("delete_file_block", 0, bb_error_msg(_("internal error; can't find dup_blk for %d\n"),
_("internal error; can't find dup_blk for %d\n"),
*block_nr); *block_nr);
} else { } else {
ext2fs_unmark_block_bitmap(ctx->block_found_map, *block_nr); ext2fs_unmark_block_bitmap(ctx->block_found_map, *block_nr);
@ -5656,8 +5633,7 @@ static int clone_file_block(ext2_filsys fs,
ext2fs_mark_block_bitmap(fs->block_map, new_block); ext2fs_mark_block_bitmap(fs->block_map, new_block);
return BLOCK_CHANGED; return BLOCK_CHANGED;
} else } else
com_err("clone_file_block", 0, bb_error_msg(_("internal error; can't find dup_blk for %d\n"),
_("internal error; can't find dup_blk for %d\n"),
*block_nr); *block_nr);
} }
return 0; return 0;
@ -5699,8 +5675,7 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
goto errout; goto errout;
} }
if (cs.errcode) { if (cs.errcode) {
com_err("clone_file", cs.errcode, bb_error_msg(_("returned from clone_file_block"));
_("returned from clone_file_block"));
retval = cs.errcode; retval = cs.errcode;
goto errout; goto errout;
} }
@ -5827,7 +5802,7 @@ static int update_dir_block(ext2_filsys fs,
static void clear_htree(e2fsck_t ctx, ext2_ino_t ino); static void clear_htree(e2fsck_t ctx, ext2_ino_t ino);
static int htree_depth(struct dx_dir_info *dx_dir, static int htree_depth(struct dx_dir_info *dx_dir,
struct dx_dirblock_info *dx_db); 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 { struct check_dir_struct {
char *buf; char *buf;
@ -6057,7 +6032,7 @@ static int dict_de_cmp(const void *a, const void *b)
* This guarantees that the root node of the htree directories are * This guarantees that the root node of the htree directories are
* processed first, so we know what hash version to use. * 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 *db_a =
(const struct ext2_db_entry *) a; (const struct ext2_db_entry *) a;
@ -6239,7 +6214,7 @@ static int ext2_file_type(unsigned int mode)
return 0; return 0;
} }
static _INLINE_ int check_filetype(e2fsck_t ctx, static int check_filetype(e2fsck_t ctx,
struct ext2_dir_entry *dirent, struct ext2_dir_entry *dirent,
struct problem_context *pctx) struct problem_context *pctx)
{ {
@ -6909,7 +6884,7 @@ static int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,
!(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR) && !(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR) &&
fix_problem(ctx, PR_2_FILE_ACL_ZERO, &pctx)) { fix_problem(ctx, PR_2_FILE_ACL_ZERO, &pctx)) {
inode.i_file_acl = 0; inode.i_file_acl = 0;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
/* /*
* This is a special kludge to deal with long symlinks * This is a special kludge to deal with long symlinks
* on big endian systems. i_blocks had already been * on big endian systems. i_blocks had already been
@ -10166,7 +10141,7 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
preenhalt(ctx); preenhalt(ctx);
if (ptr->flags & PR_FATAL) if (ptr->flags & PR_FATAL)
fatal_error(ctx, 0); bb_error_msg_and_die(0);
if (ptr->prompt == PROMPT_NONE) { if (ptr->prompt == PROMPT_NONE) {
if (ptr->flags & PR_NOCOLLATE) if (ptr->flags & PR_NOCOLLATE)
@ -10198,7 +10173,7 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
} }
if ((ptr->prompt == PROMPT_ABORT) && answer) if ((ptr->prompt == PROMPT_ABORT) && answer)
fatal_error(ctx, 0); bb_error_msg_and_die(0);
if (ptr->flags & PR_AFTER_CODE) if (ptr->flags & PR_AFTER_CODE)
answer = fix_problem(ctx, ptr->second_code, pctx); answer = fix_problem(ctx, ptr->second_code, pctx);
@ -10773,7 +10748,7 @@ static int fill_dir_block(ext2_filsys fs,
} }
/* Used for sorting the hash entry */ /* 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_a = (const struct hash_entry *) a;
const struct hash_entry *he_b = (const struct hash_entry *) b; const struct hash_entry *he_b = (const struct hash_entry *) b;
@ -10797,7 +10772,7 @@ static EXT2_QSORT_TYPE name_cmp(const void *a, const void *b)
} }
/* Used for sorting the hash entry */ /* 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_a = (const struct hash_entry *) a;
const struct hash_entry *he_b = (const struct hash_entry *) b; const struct hash_entry *he_b = (const struct hash_entry *) b;
@ -11891,8 +11866,7 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
retval = ext2fs_block_iterate2(fs, ino, BLOCK_FLAG_DEPTH_TRAVERSE, retval = ext2fs_block_iterate2(fs, ino, BLOCK_FLAG_DEPTH_TRAVERSE,
block_buf, release_inode_block, &pb); block_buf, release_inode_block, &pb);
if (retval) { if (retval) {
com_err("release_inode_blocks", retval, bb_error_msg(_("while calling ext2fs_block_iterate for inode %d"),
_("while calling ext2fs_block_iterate for inode %d"),
ino); ino);
return 1; return 1;
} }
@ -11914,8 +11888,7 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
count = 1; count = 1;
} }
if (retval) { if (retval) {
com_err("release_inode_blocks", retval, bb_error_msg(_("while calling ext2fs_adjust_ea_refocunt for inode %d"),
_("while calling ext2fs_adjust_ea_refocunt for inode %d"),
ino); ino);
return 1; return 1;
} }
@ -12486,14 +12459,12 @@ static void swap_inode_blocks(e2fsck_t ctx, ext2_ino_t ino, char *block_buf,
retval = ext2fs_block_iterate(ctx->fs, ino, 0, block_buf, retval = ext2fs_block_iterate(ctx->fs, ino, 0, block_buf,
swap_block, &sb); swap_block, &sb);
if (retval) { if (retval) {
com_err("swap_inode_blocks", retval, bb_error_msg(_("while calling ext2fs_block_iterate"));
_("while calling ext2fs_block_iterate"));
ctx->flags |= E2F_FLAG_ABORT; ctx->flags |= E2F_FLAG_ABORT;
return; return;
} }
if (sb.errcode) { if (sb.errcode) {
com_err("swap_inode_blocks", sb.errcode, bb_error_msg(_("while calling iterator function"));
_("while calling iterator function"));
ctx->flags |= E2F_FLAG_ABORT; ctx->flags |= E2F_FLAG_ABORT;
return; return;
} }
@ -12514,8 +12485,7 @@ static void swap_inodes(e2fsck_t ctx)
retval = ext2fs_get_mem(fs->blocksize * fs->inode_blocks_per_group, retval = ext2fs_get_mem(fs->blocksize * fs->inode_blocks_per_group,
&buf); &buf);
if (retval) { if (retval) {
com_err("swap_inodes", retval, bb_error_msg(_("while allocating inode buffer"));
_("while allocating inode buffer"));
ctx->flags |= E2F_FLAG_ABORT; ctx->flags |= E2F_FLAG_ABORT;
return; return;
} }
@ -12526,8 +12496,7 @@ static void swap_inodes(e2fsck_t ctx)
fs->group_desc[group].bg_inode_table, fs->group_desc[group].bg_inode_table,
fs->inode_blocks_per_group, buf); fs->inode_blocks_per_group, buf);
if (retval) { if (retval) {
com_err("swap_inodes", retval, bb_error_msg(_("while reading inode table (group %d)"),
_("while reading inode table (group %d)"),
group); group);
ctx->flags |= E2F_FLAG_ABORT; ctx->flags |= E2F_FLAG_ABORT;
return; return;
@ -12564,8 +12533,7 @@ static void swap_inodes(e2fsck_t ctx)
fs->group_desc[group].bg_inode_table, fs->group_desc[group].bg_inode_table,
fs->inode_blocks_per_group, buf); fs->inode_blocks_per_group, buf);
if (retval) { if (retval) {
com_err("swap_inodes", retval, bb_error_msg(_("while writing inode table (group %d)"),
_("while writing inode table (group %d)"),
group); group);
ctx->flags |= E2F_FLAG_ABORT; ctx->flags |= E2F_FLAG_ABORT;
return; return;
@ -12577,7 +12545,7 @@ static void swap_inodes(e2fsck_t ctx)
ext2fs_flush_icache(fs); 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 * 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 * has its bitmaps stored as 32-bit words with bit 0 as the LSB
@ -12663,7 +12631,7 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
ret = malloc(size); ret = malloc(size);
if (!ret) { if (!ret) {
sprintf(buf, "Can't allocate %s\n", description); sprintf(buf, "Can't allocate %s\n", description);
fatal_error(ctx, buf); bb_error_msg_and_die(buf);
} }
memset(ret, 0, size); memset(ret, 0, size);
return ret; return ret;
@ -12792,20 +12760,18 @@ void e2fsck_read_bitmaps(e2fsck_t ctx)
errcode_t retval; errcode_t retval;
if (ctx->invalid_bitmaps) { if (ctx->invalid_bitmaps) {
com_err(ctx->program_name, 0, bb_error_msg(_("e2fsck_read_bitmaps: illegal bitmap block(s) for %s"),
_("e2fsck_read_bitmaps: illegal bitmap block(s) for %s"),
ctx->device_name); ctx->device_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
ehandler_operation(_("reading inode and block bitmaps")); ehandler_operation(_("reading inode and block bitmaps"));
retval = ext2fs_read_bitmaps(fs); retval = ext2fs_read_bitmaps(fs);
ehandler_operation(0); ehandler_operation(0);
if (retval) { if (retval) {
com_err(ctx->program_name, retval, bb_error_msg(_("while retrying to read bitmaps for %s"),
_("while retrying to read bitmaps for %s"),
ctx->device_name); ctx->device_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
} }
@ -12819,10 +12785,9 @@ static void e2fsck_write_bitmaps(e2fsck_t ctx)
retval = ext2fs_write_block_bitmap(fs); retval = ext2fs_write_block_bitmap(fs);
ehandler_operation(0); ehandler_operation(0);
if (retval) { if (retval) {
com_err(ctx->program_name, retval, bb_error_msg(_("while retrying to write block bitmaps for %s"),
_("while retrying to write block bitmaps for %s"),
ctx->device_name); ctx->device_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
} }
@ -12831,10 +12796,9 @@ static void e2fsck_write_bitmaps(e2fsck_t ctx)
retval = ext2fs_write_inode_bitmap(fs); retval = ext2fs_write_inode_bitmap(fs);
ehandler_operation(0); ehandler_operation(0);
if (retval) { if (retval) {
com_err(ctx->program_name, retval, bb_error_msg(_("while retrying to write inode bitmaps for %s"),
_("while retrying to write inode bitmaps for %s"),
ctx->device_name); ctx->device_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
} }
} }
@ -12863,9 +12827,8 @@ void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
retval = ext2fs_read_inode(ctx->fs, ino, inode); retval = ext2fs_read_inode(ctx->fs, ino, inode);
if (retval) { if (retval) {
com_err("ext2fs_read_inode", retval, bb_error_msg(_("while reading inode %ld in %s"), ino, proc);
_("while reading inode %ld in %s"), ino, proc); bb_error_msg_and_die(0);
fatal_error(ctx, 0);
} }
} }
@ -12877,9 +12840,8 @@ extern void e2fsck_write_inode_full(e2fsck_t ctx, unsigned long ino,
retval = ext2fs_write_inode_full(ctx->fs, ino, inode, bufsize); retval = ext2fs_write_inode_full(ctx->fs, ino, inode, bufsize);
if (retval) { if (retval) {
com_err("ext2fs_write_inode", retval, bb_error_msg(_("while writing inode %ld in %s"), ino, proc);
_("while writing inode %ld in %s"), ino, proc); bb_error_msg_and_die(0);
fatal_error(ctx, 0);
} }
} }
@ -12890,9 +12852,8 @@ extern void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
retval = ext2fs_write_inode(ctx->fs, ino, inode); retval = ext2fs_write_inode(ctx->fs, ino, inode);
if (retval) { if (retval) {
com_err("ext2fs_write_inode", retval, bb_error_msg(_("while writing inode %ld in %s"), ino, proc);
_("while writing inode %ld in %s"), ino, proc); bb_error_msg_and_die(0);
fatal_error(ctx, 0);
} }
} }
@ -12946,7 +12907,7 @@ blk_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
if (io_channel_read_blk(io, superblock, if (io_channel_read_blk(io, superblock,
-SUPERBLOCK_SIZE, buf)) -SUPERBLOCK_SIZE, buf))
continue; continue;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
ext2fs_swap_super(sb); ext2fs_swap_super(sb);
#endif #endif
@ -13085,8 +13046,7 @@ static void check_mount(e2fsck_t ctx)
retval = ext2fs_check_if_mounted(ctx->filesystem_name, retval = ext2fs_check_if_mounted(ctx->filesystem_name,
&ctx->mount_flags); &ctx->mount_flags);
if (retval) { if (retval) {
com_err("ext2fs_check_if_mount", retval, bb_error_msg(_("while determining whether %s is mounted."),
_("while determining whether %s is mounted."),
ctx->filesystem_name); ctx->filesystem_name);
return; return;
} }
@ -13107,7 +13067,7 @@ static void check_mount(e2fsck_t ctx)
printf(_("%s is mounted. "), ctx->filesystem_name); printf(_("%s is mounted. "), ctx->filesystem_name);
if (!ctx->interactive) if (!ctx->interactive)
fatal_error(ctx, _("Cannot continue, aborting.\n\n")); bb_error_msg_and_die(_("Cannot continue, aborting.\n\n"));
printf(_("\n\n\007\007\007\007WARNING!!! " printf(_("\n\n\007\007\007\007WARNING!!! "
"Running e2fsck on a mounted filesystem may cause\n" "Running e2fsck on a mounted filesystem may cause\n"
"SEVERE filesystem damage.\007\007\007\n\n")); "SEVERE filesystem damage.\007\007\007\n\n"));
@ -13502,8 +13462,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
_("Error validating file descriptor %d: %s\n"), _("Error validating file descriptor %d: %s\n"),
ctx->progress_fd, ctx->progress_fd,
error_message(errno)); error_message(errno));
fatal_error(ctx, bb_error_msg_and_die(_("Invalid completion information file descriptor"));
_("Invalid completion information file descriptor"));
} else } else
close(fd); close(fd);
break; break;
@ -13517,8 +13476,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
case 'a': case 'a':
if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) { if (ctx->options & (E2F_OPT_YES|E2F_OPT_NO)) {
conflict_opt: conflict_opt:
fatal_error(ctx, bb_error_msg_and_die(_("Only one the options -p/-a, -n or -y may be specified."));
_("Only one the options -p/-a, -n or -y may be specified."));
} }
ctx->options |= E2F_OPT_PREEN; ctx->options |= E2F_OPT_PREEN;
break; break;
@ -13602,12 +13560,12 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
keep_bad_blocks++; keep_bad_blocks++;
break; break;
default: default:
usage(); bb_show_usage();
} }
if (show_version_only) if (show_version_only)
return 0; return 0;
if (optind != argc - 1) if (optind != argc - 1)
usage(); bb_show_usage();
if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file && if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file &&
!cflag && !swapfs && !(ctx->options & E2F_OPT_COMPRESS_DIRS)) !cflag && !swapfs && !(ctx->options & E2F_OPT_COMPRESS_DIRS))
ctx->options |= E2F_OPT_READONLY; ctx->options |= E2F_OPT_READONLY;
@ -13616,9 +13574,8 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
*ctx->io_options++ = 0; *ctx->io_options++ = 0;
ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0); ctx->filesystem_name = blkid_get_devname(ctx->blkid, argv[optind], 0);
if (!ctx->filesystem_name) { if (!ctx->filesystem_name) {
com_err(ctx->program_name, 0, _("Unable to resolve '%s'"), bb_error_msg(_("Unable to resolve '%s'"), argv[optind]);
argv[optind]); bb_error_msg_and_die(0);
fatal_error(ctx, 0);
} }
if (extended_opts) if (extended_opts)
parse_extended_opts(ctx, extended_opts); parse_extended_opts(ctx, extended_opts);
@ -13626,16 +13583,14 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
if (flush) { if (flush) {
fd = open(ctx->filesystem_name, O_RDONLY, 0); fd = open(ctx->filesystem_name, O_RDONLY, 0);
if (fd < 0) { if (fd < 0) {
com_err("open", errno, bb_error_msg(_("while opening %s for flushing"),
_("while opening %s for flushing"),
ctx->filesystem_name); ctx->filesystem_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
if ((retval = ext2fs_sync_device(fd, 1))) { if ((retval = ext2fs_sync_device(fd, 1))) {
com_err("ext2fs_sync_device", retval, bb_error_msg(_("while trying to flush %s"),
_("while trying to flush %s"),
ctx->filesystem_name); ctx->filesystem_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
close(fd); close(fd);
} }
@ -13703,8 +13658,7 @@ int e2fsck_main (int argc, char *argv[])
retval = PRS(argc, argv, &ctx); retval = PRS(argc, argv, &ctx);
if (retval) { if (retval) {
com_err("e2fsck", retval, bb_error_msg(_("while trying to initialize program"));
_("while trying to initialize program"));
exit(EXIT_ERROR); exit(EXIT_ERROR);
} }
reserve_stdio_fds(); reserve_stdio_fds();
@ -13725,8 +13679,7 @@ int e2fsck_main (int argc, char *argv[])
!(ctx->options & E2F_OPT_NO) && !(ctx->options & E2F_OPT_NO) &&
!(ctx->options & E2F_OPT_YES)) { !(ctx->options & E2F_OPT_YES)) {
if (!ctx->interactive) if (!ctx->interactive)
fatal_error(ctx, bb_error_msg_and_die(_("need terminal for interactive repairs"));
_("need terminal for interactive repairs"));
} }
ctx->superblock = ctx->use_superblock; ctx->superblock = ctx->use_superblock;
restart: restart:
@ -13773,7 +13726,7 @@ restart:
} }
} }
if (retval) { if (retval) {
com_err(ctx->program_name, retval, _("while trying to open %s"), bb_error_msg(_("while trying to open %s"),
ctx->filesystem_name); ctx->filesystem_name);
if (retval == EXT2_ET_REV_TOO_HIGH) { if (retval == EXT2_ET_REV_TOO_HIGH) {
printf(_("The filesystem revision is apparently " printf(_("The filesystem revision is apparently "
@ -13798,17 +13751,16 @@ restart:
#endif #endif
else else
fix_problem(ctx, PR_0_SB_CORRUPT, &pctx); fix_problem(ctx, PR_0_SB_CORRUPT, &pctx);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
ctx->fs = fs; ctx->fs = fs;
fs->priv_data = ctx; fs->priv_data = ctx;
sb = fs->super; sb = fs->super;
if (sb->s_rev_level > E2FSCK_CURRENT_REV) { if (sb->s_rev_level > E2FSCK_CURRENT_REV) {
com_err(ctx->program_name, EXT2_ET_REV_TOO_HIGH, bb_error_msg(_("while trying to open %s"),
_("while trying to open %s"),
ctx->filesystem_name); ctx->filesystem_name);
get_newer: get_newer:
fatal_error(ctx, _("Get a newer version of e2fsck!")); bb_error_msg_and_die(_("Get a newer version of e2fsck!"));
} }
/* /*
@ -13828,10 +13780,9 @@ restart:
*/ */
retval = e2fsck_check_ext3_journal(ctx); retval = e2fsck_check_ext3_journal(ctx);
if (retval) { if (retval) {
com_err(ctx->program_name, retval, bb_error_msg(_("while checking ext3 journal for %s"),
_("while checking ext3 journal for %s"),
ctx->device_name); ctx->device_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
/* /*
@ -13852,16 +13803,14 @@ restart:
* happen, unless the hardware or * happen, unless the hardware or
* device driver is being bogus. * device driver is being bogus.
*/ */
com_err(ctx->program_name, 0, bb_error_msg(_("unable to set superblock flags on %s\n"), ctx->device_name);
_("unable to set superblock flags on %s\n"), ctx->device_name); bb_error_msg_and_die(0);
fatal_error(ctx, 0);
} }
retval = e2fsck_run_ext3_journal(ctx); retval = e2fsck_run_ext3_journal(ctx);
if (retval) { if (retval) {
com_err(ctx->program_name, retval, bb_error_msg(_("while recovering ext3 journal of %s"),
_("while recovering ext3 journal of %s"),
ctx->device_name); ctx->device_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
ext2fs_close(ctx->fs); ext2fs_close(ctx->fs);
ctx->fs = 0; ctx->fs = 0;
@ -13876,25 +13825,21 @@ restart:
*/ */
if ((sb->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP) || if ((sb->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP) ||
(sb->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP)) { (sb->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP)) {
com_err(ctx->program_name, EXT2_ET_UNSUPP_FEATURE, bb_error_msg("(%s)", ctx->device_name);
"(%s)", ctx->device_name);
goto get_newer; goto get_newer;
} }
if (sb->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) { if (sb->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) {
com_err(ctx->program_name, EXT2_ET_RO_UNSUPP_FEATURE, bb_error_msg("(%s)", ctx->device_name);
"(%s)", ctx->device_name);
goto get_newer; goto get_newer;
} }
#ifdef ENABLE_COMPRESSION #ifdef ENABLE_COMPRESSION
/* FIXME - do we support this at all? */ /* FIXME - do we support this at all? */
if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION) if (sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_COMPRESSION)
com_err(ctx->program_name, 0, bb_error_msg(_("Warning: compression support is experimental.\n"));
_("Warning: compression support is experimental.\n"));
#endif #endif
#ifndef ENABLE_HTREE #ifndef ENABLE_HTREE
if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) { if (sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) {
com_err(ctx->program_name, 0, bb_error_msg(_("E2fsck not compiled with HTREE support,\n\t"
_("E2fsck not compiled with HTREE support,\n\t"
"but filesystem %s has HTREE directories.\n"), "but filesystem %s has HTREE directories.\n"),
ctx->device_name); ctx->device_name);
goto get_newer; goto get_newer;
@ -13926,14 +13871,14 @@ restart:
ext2fs_mark_valid(fs); ext2fs_mark_valid(fs);
check_super_block(ctx); check_super_block(ctx);
if (ctx->flags & E2F_FLAG_SIGNAL_MASK) if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
fatal_error(ctx, 0); bb_error_msg_and_die(0);
check_if_skip(ctx); check_if_skip(ctx);
if (bad_blocks_file) if (bad_blocks_file)
read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks); read_bad_blocks_file(ctx, bad_blocks_file, replace_bad_blocks);
else if (cflag) else if (cflag)
read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */ read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */
if (ctx->flags & E2F_FLAG_SIGNAL_MASK) if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
fatal_error(ctx, 0); bb_error_msg_and_die(0);
#ifdef ENABLE_SWAPFS #ifdef ENABLE_SWAPFS
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
@ -13947,13 +13892,13 @@ restart:
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) == NATIVE_FLAG) { if ((fs->flags & EXT2_FLAG_SWAP_BYTES) == NATIVE_FLAG) {
fprintf(stderr, _("%s: Filesystem byte order " fprintf(stderr, _("%s: Filesystem byte order "
"already normalized.\n"), ctx->device_name); "already normalized.\n"), ctx->device_name);
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
} }
if (swapfs) { if (swapfs) {
swap_filesys(ctx); swap_filesys(ctx);
if (ctx->flags & E2F_FLAG_SIGNAL_MASK) if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
fatal_error(ctx, 0); bb_error_msg_and_die(0);
} }
#endif #endif
@ -13964,8 +13909,7 @@ restart:
retval = ext2fs_read_bb_inode(fs, &fs->badblocks); retval = ext2fs_read_bb_inode(fs, &fs->badblocks);
if (retval) { if (retval) {
com_err(ctx->program_name, retval, bb_error_msg(_("while reading bad blocks inode"));
_("while reading bad blocks inode"));
preenhalt(ctx); preenhalt(ctx);
printf(_("This doesn't bode well," printf(_("This doesn't bode well,"
" but we'll try to go on...\n")); " but we'll try to go on...\n"));
@ -13977,9 +13921,8 @@ restart:
printf(_("Restarting e2fsck from the beginning...\n")); printf(_("Restarting e2fsck from the beginning...\n"));
retval = e2fsck_reset_context(ctx); retval = e2fsck_reset_context(ctx);
if (retval) { if (retval) {
com_err(ctx->program_name, retval, bb_error_msg(_("while resetting context"));
_("while resetting context")); bb_error_msg_and_die(0);
fatal_error(ctx, 0);
} }
ext2fs_close(fs); ext2fs_close(fs);
goto restart; goto restart;
@ -13990,7 +13933,7 @@ restart:
exit_value |= FSCK_CANCELED; exit_value |= FSCK_CANCELED;
} }
if (run_result & E2F_FLAG_ABORT) if (run_result & E2F_FLAG_ABORT)
fatal_error(ctx, _("aborted")); bb_error_msg_and_die(_("aborted"));
/* Cleanup */ /* Cleanup */
if (ext2fs_test_changed(fs)) { if (ext2fs_test_changed(fs)) {

View File

@ -27,7 +27,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <linux/types.h> #include <linux/types.h>
/* /*
* Now pull in the real linux/jfs.h definitions. * Now pull in the real linux/jfs.h definitions.
*/ */
@ -82,8 +81,6 @@ These defines are used in the type field of dx_dirblock_info
#define DX_DIRBLOCK_ROOT 1 #define DX_DIRBLOCK_ROOT 1
#define DX_DIRBLOCK_LEAF 2 #define DX_DIRBLOCK_LEAF 2
#define DX_DIRBLOCK_NODE 3 #define DX_DIRBLOCK_NODE 3
#define DX_DIRBLOCK_CORRUPT 4
#define DX_DIRBLOCK_CLEARED 8
/* /*
@ -102,7 +99,6 @@ The following defines are used in the 'flags' field of a dx_dirblock_info
#define E2F_OPT_YES 0x0004 #define E2F_OPT_YES 0x0004
#define E2F_OPT_NO 0x0008 #define E2F_OPT_NO 0x0008
#define E2F_OPT_TIME 0x0010 #define E2F_OPT_TIME 0x0010
#define E2F_OPT_TIME2 0x0020
#define E2F_OPT_CHECKBLOCKS 0x0040 #define E2F_OPT_CHECKBLOCKS 0x0040
#define E2F_OPT_DEBUG 0x0080 #define E2F_OPT_DEBUG 0x0080
#define E2F_OPT_FORCE 0x0100 #define E2F_OPT_FORCE 0x0100
@ -127,21 +123,10 @@ The following defines are used in the 'flags' field of a dx_dirblock_info
#define E2F_FLAG_RESTARTED 0x0200 /* E2fsck has been restarted */ #define E2F_FLAG_RESTARTED 0x0200 /* E2fsck has been restarted */
#define E2F_FLAG_RESIZE_INODE 0x0400 /* Request to recreate resize inode */ #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
/*Don't know where these come from*/ /*Don't know where these come from*/
#define READ 0 #define READ 0
#define WRITE 1 #define WRITE 1
#define KERN_ERR ""
#define KERN_DEBUG ""
#define cpu_to_be32(n) htonl(n) #define cpu_to_be32(n) htonl(n)
#define be32_to_cpu(n) ntohl(n) #define be32_to_cpu(n) ntohl(n)

View File

@ -71,9 +71,9 @@ void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
{ {
#ifndef OMIT_COM_ERR #ifndef OMIT_COM_ERR
if (description) if (description)
com_err(0, errcode, "#%lu for %s", arg, description); bb_error_msg("#%lu for %s", arg, description);
else else
com_err(0, errcode, "#%lu", arg); bb_error_msg("#%lu", arg);
#endif #endif
} }
@ -82,10 +82,9 @@ void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
{ {
#ifndef OMIT_COM_ERR #ifndef OMIT_COM_ERR
if (bitmap->description) if (bitmap->description)
com_err(0, bitmap->base_error_code+code, bb_error_msg("#%lu for %s", arg, bitmap->description);
"#%lu for %s", arg, bitmap->description);
else else
com_err(0, bitmap->base_error_code + code, "#%lu", arg); bb_error_msg("#%lu", arg);
#endif #endif
} }

View File

@ -18,12 +18,6 @@
#include "ext2_fs.h" #include "ext2_fs.h"
#include "ext2fs.h" #include "ext2fs.h"
#if defined(__GNUC__) && !defined(NO_INLINE_FUNCS)
#define _BMAP_INLINE_ __inline__
#else
#define _BMAP_INLINE_
#endif
extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
struct ext2_inode *inode, struct ext2_inode *inode,
char *block_buf, int bmap_flags, char *block_buf, int bmap_flags,
@ -31,7 +25,7 @@ extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
#define inode_bmap(inode, nr) ((inode)->i_block[(nr)]) #define inode_bmap(inode, nr) ((inode)->i_block[(nr)])
static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags, static errcode_t block_ind_bmap(ext2_filsys fs, int flags,
blk_t ind, char *block_buf, blk_t ind, char *block_buf,
int *blocks_alloc, int *blocks_alloc,
blk_t nr, blk_t *ret_blk) blk_t nr, blk_t *ret_blk)
@ -51,7 +45,7 @@ static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags,
if (flags & BMAP_SET) { if (flags & BMAP_SET) {
b = *ret_blk; b = *ret_blk;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
b = ext2fs_swab32(b); b = ext2fs_swab32(b);
@ -62,7 +56,7 @@ static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags,
b = ((blk_t *) block_buf)[nr]; b = ((blk_t *) block_buf)[nr];
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) (fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
b = ext2fs_swab32(b); b = ext2fs_swab32(b);
@ -75,7 +69,7 @@ static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags,
if (retval) if (retval)
return retval; return retval;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
((blk_t *) block_buf)[nr] = ext2fs_swab32(b); ((blk_t *) block_buf)[nr] = ext2fs_swab32(b);
@ -94,7 +88,7 @@ static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags,
return 0; return 0;
} }
static _BMAP_INLINE_ errcode_t block_dind_bmap(ext2_filsys fs, int flags, static errcode_t block_dind_bmap(ext2_filsys fs, int flags,
blk_t dind, char *block_buf, blk_t dind, char *block_buf,
int *blocks_alloc, int *blocks_alloc,
blk_t nr, blk_t *ret_blk) blk_t nr, blk_t *ret_blk)
@ -114,7 +108,7 @@ static _BMAP_INLINE_ errcode_t block_dind_bmap(ext2_filsys fs, int flags,
return retval; return retval;
} }
static _BMAP_INLINE_ errcode_t block_tind_bmap(ext2_filsys fs, int flags, static errcode_t block_tind_bmap(ext2_filsys fs, int flags,
blk_t tind, char *block_buf, blk_t tind, char *block_buf,
int *blocks_alloc, int *blocks_alloc,
blk_t nr, blk_t *ret_blk) blk_t nr, blk_t *ret_blk)
@ -167,7 +161,7 @@ errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode,
if (block < EXT2_NDIR_BLOCKS) { if (block < EXT2_NDIR_BLOCKS) {
if (bmap_flags & BMAP_SET) { if (bmap_flags & BMAP_SET) {
b = *phys_blk; b = *phys_blk;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) (fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
b = ext2fs_swab32(b); b = ext2fs_swab32(b);

View File

@ -14,9 +14,7 @@
#if HAVE_SYS_TYPES_H #if HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#if HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif
#include "ext2_fs.h" #include "ext2_fs.h"
#include "ext2fsP.h" #include "ext2fsP.h"

View File

@ -191,7 +191,7 @@ static errcode_t write_backup_super(ext2_filsys fs, dgrp_t group,
if (sgrp > ((1 << 16) - 1)) if (sgrp > ((1 << 16) - 1))
sgrp = (1 << 16) - 1; sgrp = (1 << 16) - 1;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (fs->flags & EXT2_FLAG_SWAP_BYTES) if (fs->flags & EXT2_FLAG_SWAP_BYTES)
super_shadow->s_block_group_nr = ext2fs_swab16(sgrp); super_shadow->s_block_group_nr = ext2fs_swab16(sgrp);
else else
@ -213,7 +213,7 @@ errcode_t ext2fs_flush(ext2_filsys fs)
struct ext2_group_desc *group_shadow = 0; struct ext2_group_desc *group_shadow = 0;
char *group_ptr; char *group_ptr;
int old_desc_blocks; int old_desc_blocks;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
dgrp_t j; dgrp_t j;
struct ext2_group_desc *s, *t; struct ext2_group_desc *s, *t;
#endif #endif
@ -224,7 +224,7 @@ errcode_t ext2fs_flush(ext2_filsys fs)
fs->super->s_wtime = time(NULL); fs->super->s_wtime = time(NULL);
fs->super->s_block_group_nr = 0; fs->super->s_block_group_nr = 0;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (fs->flags & EXT2_FLAG_SWAP_BYTES) { if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
retval = EXT2_ET_NO_MEMORY; retval = EXT2_ET_NO_MEMORY;
retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &super_shadow); retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &super_shadow);
@ -267,7 +267,7 @@ errcode_t ext2fs_flush(ext2_filsys fs)
* we write out the backup superblocks.) * we write out the backup superblocks.)
*/ */
fs->super->s_state &= ~EXT2_VALID_FS; fs->super->s_state &= ~EXT2_VALID_FS;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (fs->flags & EXT2_FLAG_SWAP_BYTES) { if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
*super_shadow = *fs->super; *super_shadow = *fs->super;
ext2fs_swap_super(super_shadow); ext2fs_swap_super(super_shadow);
@ -316,7 +316,7 @@ errcode_t ext2fs_flush(ext2_filsys fs)
} }
fs->super->s_block_group_nr = 0; fs->super->s_block_group_nr = 0;
fs->super->s_state = fs_state; fs->super->s_state = fs_state;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (fs->flags & EXT2_FLAG_SWAP_BYTES) { if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
*super_shadow = *fs->super; *super_shadow = *fs->super;
ext2fs_swap_super(super_shadow); ext2fs_swap_super(super_shadow);

View File

@ -20,7 +20,7 @@
#include "ext2_fs.h" #include "ext2_fs.h"
#include "ext2fsP.h" #include "ext2fsP.h"
static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b); static int dir_block_cmp(const void *a, const void *b);
/* /*
* Returns the number of directories in the filesystem as reported by * Returns the number of directories in the filesystem as reported by
@ -203,7 +203,7 @@ errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk,
} }
void ext2fs_dblist_sort(ext2_dblist dblist, void ext2fs_dblist_sort(ext2_dblist dblist,
EXT2_QSORT_TYPE (*sortfunc)(const void *, int (*sortfunc)(const void *,
const void *)) const void *))
{ {
if (!sortfunc) if (!sortfunc)
@ -237,7 +237,7 @@ errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
return 0; return 0;
} }
static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b) static int dir_block_cmp(const void *a, const void *b)
{ {
const struct ext2_db_entry *db_a = const struct ext2_db_entry *db_a =
(const struct ext2_db_entry *) a; (const struct ext2_db_entry *) a;

View File

@ -26,14 +26,14 @@ errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
char *p, *end; char *p, *end;
struct ext2_dir_entry *dirent; struct ext2_dir_entry *dirent;
unsigned int name_len, rec_len; unsigned int name_len, rec_len;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
unsigned int do_swap; unsigned int do_swap;
#endif #endif
retval = io_channel_read_blk(fs->io, block, 1, buf); retval = io_channel_read_blk(fs->io, block, 1, buf);
if (retval) if (retval)
return retval; return retval;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
do_swap = (fs->flags & (EXT2_FLAG_SWAP_BYTES| do_swap = (fs->flags & (EXT2_FLAG_SWAP_BYTES|
EXT2_FLAG_SWAP_BYTES_READ)) != 0; EXT2_FLAG_SWAP_BYTES_READ)) != 0;
#endif #endif
@ -41,7 +41,7 @@ errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
end = (char *) buf + fs->blocksize; end = (char *) buf + fs->blocksize;
while (p < end-8) { while (p < end-8) {
dirent = (struct ext2_dir_entry *) p; dirent = (struct ext2_dir_entry *) p;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (do_swap) { if (do_swap) {
dirent->inode = ext2fs_swab32(dirent->inode); dirent->inode = ext2fs_swab32(dirent->inode);
dirent->rec_len = ext2fs_swab16(dirent->rec_len); dirent->rec_len = ext2fs_swab16(dirent->rec_len);
@ -75,7 +75,7 @@ errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block, errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
void *inbuf, int flags EXT2FS_ATTR((unused))) void *inbuf, int flags EXT2FS_ATTR((unused)))
{ {
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
int do_swap = 0; int do_swap = 0;
errcode_t retval; errcode_t retval;
char *p, *end; char *p, *end;

View File

@ -28,9 +28,6 @@ struct ext2_ext_attr_entry {
__u32 e_value_block; /* disk block attribute is stored on (n/i) */ __u32 e_value_block; /* disk block attribute is stored on (n/i) */
__u32 e_value_size; /* size of attribute value */ __u32 e_value_size; /* size of attribute value */
__u32 e_hash; /* hash value of name and value */ __u32 e_hash; /* hash value of name and value */
#if 0
char e_name[0]; /* attribute name */
#endif
}; };
#define EXT2_EXT_ATTR_PAD_BITS 2 #define EXT2_EXT_ATTR_PAD_BITS 2
@ -53,17 +50,3 @@ struct ext2_ext_attr_entry {
#define EXT2_XATTR_SIZE(size) \ #define EXT2_XATTR_SIZE(size) \
(((size) + EXT2_EXT_ATTR_ROUND) & ~EXT2_EXT_ATTR_ROUND) (((size) + EXT2_EXT_ATTR_ROUND) & ~EXT2_EXT_ATTR_ROUND)
#ifdef __KERNEL__
# ifdef CONFIG_EXT2_FS_EXT_ATTR
extern int ext2_get_ext_attr(struct inode *, const char *, char *, size_t, int);
extern int ext2_set_ext_attr(struct inode *, const char *, char *, size_t, int);
extern void ext2_ext_attr_free_inode(struct inode *inode);
extern void ext2_ext_attr_put_super(struct super_block *sb);
extern int ext2_ext_attr_init(void);
extern void ext2_ext_attr_done(void);
# else
# define ext2_get_ext_attr NULL
# define ext2_set_ext_attr NULL
# endif
#endif /* __KERNEL__ */

View File

@ -18,27 +18,6 @@
#include "ext2_types.h" /* Changed from linux/types.h */ #include "ext2_types.h" /* Changed from linux/types.h */
/*
* The second extended filesystem constants/structures
*/
/*
* Define EXT2FS_DEBUG to produce debug messages
*/
#undef EXT2FS_DEBUG
/*
* Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
*/
#define EXT2_PREALLOCATE
#define EXT2_DEFAULT_PREALLOC_BLOCKS 8
/*
* The second extended file system version
*/
#define EXT2FS_DATE "95/08/09"
#define EXT2FS_VERSION "0.5b"
/* /*
* Special inode numbers * Special inode numbers
*/ */
@ -59,14 +38,10 @@
*/ */
#define EXT2_SUPER_MAGIC 0xEF53 #define EXT2_SUPER_MAGIC 0xEF53
#ifdef __KERNEL__
#define EXT2_SB(sb) (&((sb)->u.ext2_sb))
#else
/* Assume that user mode programs are passing in an ext2fs superblock, not /* Assume that user mode programs are passing in an ext2fs superblock, not
* a kernel struct super_block. This will allow us to call the feature-test * a kernel struct super_block. This will allow us to call the feature-test
* macros from user land. */ * macros from user land. */
#define EXT2_SB(sb) (sb) #define EXT2_SB(sb) (sb)
#endif
/* /*
* Maximal count of links to a file * Maximal count of links to a file
@ -80,20 +55,12 @@
#define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */ #define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */
#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE) #define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE)
#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE) #define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE)
#ifdef __KERNEL__
#define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
#define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->addr_per_block_bits)
#define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size)
#define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino)
#else
#define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size) #define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) #define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \ #define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size) EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size)
#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \ #define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino) EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino)
#endif
#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(__u32)) #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(__u32))
/* /*
@ -102,13 +69,8 @@
#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE #define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE
#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE #define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE
#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE #define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE
#ifdef __KERNEL__
# define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->s_frag_size)
# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->s_frags_per_block)
#else
# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size) # define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s)) # define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
#endif
/* /*
* ACL structures * ACL structures
@ -193,12 +155,7 @@ struct ext2_dx_countlimit {
/* limits imposed by 16-bit value gd_free_{blocks,inode}_count */ /* limits imposed by 16-bit value gd_free_{blocks,inode}_count */
#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8) #define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8)
#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s)) #define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s))
#ifdef __KERNEL__
#define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block)
#define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
#else
#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc)) #define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
#endif
/* /*
* Constants relative to the data blocks * Constants relative to the data blocks
@ -365,38 +322,6 @@ struct ext2_inode_large {
#define i_size_high i_dir_acl #define i_size_high i_dir_acl
#if defined(__KERNEL__) || defined(__linux__)
#define i_reserved1 osd1.linux1.l_i_reserved1
#define i_frag osd2.linux2.l_i_frag
#define i_fsize osd2.linux2.l_i_fsize
#define i_uid_low i_uid
#define i_gid_low i_gid
#define i_uid_high osd2.linux2.l_i_uid_high
#define i_gid_high osd2.linux2.l_i_gid_high
#define i_reserved2 osd2.linux2.l_i_reserved2
#else
#if defined(__GNU__)
#define i_translator osd1.hurd1.h_i_translator
#define i_frag osd2.hurd2.h_i_frag;
#define i_fsize osd2.hurd2.h_i_fsize;
#define i_uid_high osd2.hurd2.h_i_uid_high
#define i_gid_high osd2.hurd2.h_i_gid_high
#define i_author osd2.hurd2.h_i_author
#else
#if defined(__masix__)
#define i_reserved1 osd1.masix1.m_i_reserved1
#define i_frag osd2.masix2.m_i_frag
#define i_fsize osd2.masix2.m_i_fsize
#define i_reserved2 osd2.masix2.m_i_reserved2
#endif /* __masix__ */
#endif /* __GNU__ */
#endif /* defined(__KERNEL__) || defined(__linux__) */
/* /*
* File system states * File system states
*/ */

View File

@ -12,32 +12,13 @@
#ifndef _EXT2FS_EXT2FS_H #ifndef _EXT2FS_EXT2FS_H
#define _EXT2FS_EXT2FS_H #define _EXT2FS_EXT2FS_H
#ifdef __GNUC__
#define EXT2FS_ATTR(x) __attribute__(x)
#else
#define EXT2FS_ATTR(x) #define EXT2FS_ATTR(x)
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/*
* Non-GNU C compilers won't necessarily understand inline
*/
#if (!defined(__GNUC__) && !defined(__WATCOMC__))
#define NO_INLINE_FUNCS
#endif
/*
* Build in support for byte-swapping filesystems if we the feature
* has been configured or if we're being built on a CPU architecture
* with a non-native byte order.
*/
#if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN) || __BYTE_ORDER== __BIG_ENDIAN
#define EXT2FS_ENABLE_SWAPFS
#endif
/* /*
* Where the master copy of the superblock is located, and how big * Where the master copy of the superblock is located, and how big
* superblocks are supposed to be. We define SUPERBLOCK_SIZE because * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
@ -74,15 +55,6 @@ typedef __u32 ext2_dirhash_t;
#include "ext2_io.h" #include "ext2_io.h"
#include "ext2_err.h" #include "ext2_err.h"
/*
* Portability help for Microsoft Visual C++
*/
#ifdef _MSC_VER
#define EXT2_QSORT_TYPE int __cdecl
#else
#define EXT2_QSORT_TYPE int
#endif
typedef struct struct_ext2_filsys *ext2_filsys; typedef struct struct_ext2_filsys *ext2_filsys;
struct ext2fs_struct_generic_bitmap { struct ext2fs_struct_generic_bitmap {
@ -104,12 +76,7 @@ typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap; typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap; typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
#ifdef EXT2_DYNAMIC_REV
#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s) #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
#else
#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO
#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode)
#endif
/* /*
* badblocks list definitions * badblocks list definitions
@ -609,7 +576,7 @@ extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
blk_t blk, int blockcnt); blk_t blk, int blockcnt);
extern void ext2fs_dblist_sort(ext2_dblist dblist, extern void ext2fs_dblist_sort(ext2_dblist dblist,
EXT2_QSORT_TYPE (*sortfunc)(const void *, int (*sortfunc)(const void *,
const void *)); const void *));
extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info, int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,

View File

@ -238,78 +238,36 @@ int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap, void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
blk_t block) blk_t block)
{ {
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((block < bitmap->start) || (block > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
bitmap->description);
return;
}
#endif
ext2fs_set_bit(block - bitmap->start, bitmap->bitmap); ext2fs_set_bit(block - bitmap->start, bitmap->bitmap);
} }
void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap, void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
blk_t block) blk_t block)
{ {
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((block < bitmap->start) || (block > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK,
block, bitmap->description);
return;
}
#endif
ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap); ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap);
} }
int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap, int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
blk_t block) blk_t block)
{ {
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((block < bitmap->start) || (block > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
block, bitmap->description);
return 0;
}
#endif
return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap); return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap);
} }
void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
ext2_ino_t inode) ext2_ino_t inode)
{ {
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((inode < bitmap->start) || (inode > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_MARK,
inode, bitmap->description);
return;
}
#endif
ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap); ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap);
} }
void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
ext2_ino_t inode) ext2_ino_t inode)
{ {
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((inode < bitmap->start) || (inode > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_UNMARK,
inode, bitmap->description);
return;
}
#endif
ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap); ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap);
} }
int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap, int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
ext2_ino_t inode) ext2_ino_t inode)
{ {
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((inode < bitmap->start) || (inode > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_TEST,
inode, bitmap->description);
return 0;
}
#endif
return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap); return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap);
} }
@ -355,13 +313,6 @@ int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
{ {
int i; int i;
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
block, bitmap->description);
return 0;
}
#endif
for (i=0; i < num; i++) { for (i=0; i < num; i++) {
if (ext2fs_fast_test_block_bitmap(bitmap, block+i)) if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
return 0; return 0;
@ -388,13 +339,6 @@ void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
{ {
int i; int i;
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
bitmap->description);
return;
}
#endif
for (i=0; i < num; i++) for (i=0; i < num; i++)
ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap); ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap);
} }
@ -417,14 +361,6 @@ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
blk_t block, int num) blk_t block, int num)
{ {
int i; int i;
#ifdef EXT2FS_DEBUG_FAST_OPS
if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
bitmap->description);
return;
}
#endif
for (i=0; i < num; i++) for (i=0; i < num; i++)
ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap); ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap);
} }

View File

@ -12,15 +12,12 @@
*/ */
#include <stdio.h> #include <stdio.h>
#if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "ext2_fs.h" #include "ext2_fs.h"
#include "ext2_ext_attr.h" #include "ext2_ext_attr.h"
#include "ext2fs.h" #include "ext2fs.h"
errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf) errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf)
@ -30,7 +27,7 @@ errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf)
retval = io_channel_read_blk(fs->io, block, 1, buf); retval = io_channel_read_blk(fs->io, block, 1, buf);
if (retval) if (retval)
return retval; return retval;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->flags & (EXT2_FLAG_SWAP_BYTES| if ((fs->flags & (EXT2_FLAG_SWAP_BYTES|
EXT2_FLAG_SWAP_BYTES_READ)) != 0) EXT2_FLAG_SWAP_BYTES_READ)) != 0)
ext2fs_swap_ext_attr(buf, buf, fs->blocksize, 1); ext2fs_swap_ext_attr(buf, buf, fs->blocksize, 1);
@ -44,7 +41,7 @@ errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf)
char *write_buf; char *write_buf;
char *buf = NULL; char *buf = NULL;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) { (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) {
retval = ext2fs_get_mem(fs->blocksize, &buf); retval = ext2fs_get_mem(fs->blocksize, &buf);

View File

@ -22,7 +22,7 @@
errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf) errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf)
{ {
errcode_t retval; errcode_t retval;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
blk_t *block_nr; blk_t *block_nr;
int i; int i;
int limit = fs->blocksize >> 2; int limit = fs->blocksize >> 2;
@ -36,7 +36,7 @@ errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf)
if (retval) if (retval)
return retval; return retval;
} }
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_READ)) { if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_READ)) {
block_nr = (blk_t *) buf; block_nr = (blk_t *) buf;
for (i = 0; i < limit; i++, block_nr++) for (i = 0; i < limit; i++, block_nr++)
@ -48,7 +48,7 @@ errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf)
errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf) errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf)
{ {
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
blk_t *block_nr; blk_t *block_nr;
int i; int i;
int limit = fs->blocksize >> 2; int limit = fs->blocksize >> 2;
@ -57,7 +57,7 @@ errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf)
if (fs->flags & EXT2_FLAG_IMAGE_FILE) if (fs->flags & EXT2_FLAG_IMAGE_FILE)
return 0; return 0;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_WRITE)) { if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_WRITE)) {
block_nr = (blk_t *) buf; block_nr = (blk_t *) buf;
for (i = 0; i < limit; i++, block_nr++) for (i = 0; i < limit; i++, block_nr++)

View File

@ -446,7 +446,7 @@ errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, ext2_ino_t *ino,
scan->ptr += scan->inode_size - extra_bytes; scan->ptr += scan->inode_size - extra_bytes;
scan->bytes_left -= scan->inode_size - extra_bytes; scan->bytes_left -= scan->inode_size - extra_bytes;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) (scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
ext2fs_swap_inode_full(scan->fs, ext2fs_swap_inode_full(scan->fs,
@ -460,7 +460,7 @@ errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, ext2_ino_t *ino,
retval = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE; retval = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE;
scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES; scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES;
} else { } else {
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) (scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
ext2fs_swap_inode_full(scan->fs, ext2fs_swap_inode_full(scan->fs,
@ -574,7 +574,7 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
block_nr++; block_nr++;
} }
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) (fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) inode, ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) inode,
@ -646,7 +646,7 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
w_inode = &temp_inode; w_inode = &temp_inode;
memset(w_inode, 0, length); memset(w_inode, 0, length);
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
ext2fs_swap_inode_full(fs, w_inode, ext2fs_swap_inode_full(fs, w_inode,

View File

@ -89,7 +89,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
int groups_per_block, blocks_per_group; int groups_per_block, blocks_per_group;
blk_t group_block, blk; blk_t group_block, blk;
char *dest, *cp; char *dest, *cp;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
int j; int j;
struct ext2_group_desc *gdp; struct ext2_group_desc *gdp;
#endif #endif
@ -175,7 +175,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
if (fs->orig_super) if (fs->orig_super)
memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE); memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE);
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if ((fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) || if ((fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES)) { (fs->flags & EXT2_FLAG_SWAP_BYTES)) {
fs->flags |= EXT2_FLAG_SWAP_BYTES; fs->flags |= EXT2_FLAG_SWAP_BYTES;
@ -277,7 +277,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
retval = io_channel_read_blk(fs->io, blk, 1, dest); retval = io_channel_read_blk(fs->io, blk, 1, dest);
if (retval) if (retval)
goto cleanup; goto cleanup;
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
if (fs->flags & EXT2_FLAG_SWAP_BYTES) { if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
gdp = (struct ext2_group_desc *) dest; gdp = (struct ext2_group_desc *) dest;
for (j=0; j < groups_per_block; j++) for (j=0; j < groups_per_block; j++)

View File

@ -27,7 +27,7 @@
#include "ext2fs.h" #include "ext2fs.h"
#include "e2image.h" #include "e2image.h"
#if defined(__powerpc__) && defined(EXT2FS_ENABLE_SWAPFS) #if defined(__powerpc__) && BB_BIG_ENDIAN
/* /*
* On the PowerPC, the big-endian variant of the ext2 filesystem * 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 * has its bitmaps stored as 32-bit words with bit 0 as the LSB

View File

@ -10,9 +10,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -20,7 +18,7 @@
#include "ext2fs.h" #include "ext2fs.h"
#include "ext2_ext_attr.h" #include "ext2_ext_attr.h"
#ifdef EXT2FS_ENABLE_SWAPFS #if BB_BIG_ENDIAN
void ext2fs_swap_super(struct ext2_super_block * sb) void ext2fs_swap_super(struct ext2_super_block * sb)
{ {
int i; int i;

View File

@ -34,9 +34,7 @@
#if HAVE_SYS_TYPES_H #if HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h> #include <sys/resource.h>
#endif
#include "ext2_fs.h" #include "ext2_fs.h"
#include "ext2fs.h" #include "ext2fs.h"

View File

@ -1175,14 +1175,6 @@ static int check_all(void)
return status; return status;
} }
#if 0
static void usage(void)
{
fputs("Usage: fsck [-ANPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n", stderr);
exit(EXIT_USAGE);
}
#endif
static void signal_cancel(int sig FSCK_ATTR((unused))) static void signal_cancel(int sig FSCK_ATTR((unused)))
{ {
cancel_requested++; cancel_requested++;
@ -1300,13 +1292,13 @@ static void PRS(int argc, char *argv[])
case 't': case 't':
tmp = 0; tmp = 0;
if (fstype) if (fstype)
usage(); bb_show_usage();
if (arg[j+1]) if (arg[j+1])
tmp = arg+j+1; tmp = arg+j+1;
else if ((i+1) < argc) else if ((i+1) < argc)
tmp = argv[++i]; tmp = argv[++i];
else else
usage(); bb_show_usage();
fstype = string_copy(tmp); fstype = string_copy(tmp);
compile_fs_type(fstype, &fs_type_compiled); compile_fs_type(fstype, &fs_type_compiled);
goto next_arg; goto next_arg;
@ -1314,7 +1306,7 @@ static void PRS(int argc, char *argv[])
opts_for_fsck++; opts_for_fsck++;
break; break;
case '?': case '?':
usage(); bb_show_usage();
break; break;
default: default:
options[++opt] = arg[j]; options[++opt] = arg[j];

View File

@ -11,6 +11,5 @@
#define EXIT_ERROR 8 #define EXIT_ERROR 8
#define EXIT_USAGE 16 #define EXIT_USAGE 16
#define FSCK_CANCELED 32 /* Aborted with a signal or ^C */ #define FSCK_CANCELED 32 /* Aborted with a signal or ^C */
#define EXIT_LIBRARY 128
extern char *e2fs_set_sbin_path(void); extern char *e2fs_set_sbin_path(void);

View File

@ -33,12 +33,6 @@
#include "e2fsbb.h" #include "e2fsbb.h"
#include "e2p/e2p.h" #include "e2p/e2p.h"
#ifdef __GNUC__
# define EXT2FS_ATTR(x) __attribute__(x)
#else
# define EXT2FS_ATTR(x)
#endif
#define OPT_RECUR 1 #define OPT_RECUR 1
#define OPT_ALL 2 #define OPT_ALL 2
#define OPT_DIRS_OPT 4 #define OPT_DIRS_OPT 4
@ -98,7 +92,7 @@ static void lsattr_args(const char *name)
} }
static int lsattr_dir_proc(const char *dir_name, struct dirent *de, static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
void *private EXT2FS_ATTR((unused))) void *private)
{ {
STRUCT_STAT st; STRUCT_STAT st;
char *path; char *path;

View File

@ -44,9 +44,7 @@
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h> #include <sys/socket.h>
#endif
#ifdef HAVE_SYS_SOCKIO_H #ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h> #include <sys/sockio.h>
#endif #endif