@RESIZER_CMT@RESIZE_DIR= resize
@DEBUGFS_CMT@DEBUGFS_DIR= debugfs
-LIB_SUBDIRS=lib/et lib/ss lib/e2p lib/ext2fs lib/uuid lib/blkid intl
+LIB_SUBDIRS=lib/et lib/ss lib/e2p lib/uuid lib/ext2fs lib/blkid intl
PROG_SUBDIRS=e2fsck $(DEBUGFS_DIR) misc $(RESIZE_DIR) tests/progs po
SUBDIRS=util $(LIB_SUBDIRS) $(PROG_SUBDIRS) tests
LIB_EXT
STATIC_LIB_EXT
PROFILED_LIB_EXT
-SWAPFS_CMT
DEBUGFS_CMT
IMAGER_CMT
RESIZER_CMT
--enable-jbd-debug enable journal debugging
--enable-blkid-debug enable blkid debugging
--enable-testio-debug enable the use of the test I/O manager for debugging
- --disable-swapfs disable support of legacy byte-swapped filesystems
--disable-debugfs disable support of debugfs program
--disable-imager disable support of e2image program
--disable-resizer disable support of e2resize program
fi
-# Check whether --enable-swapfs was given.
-if test "${enable_swapfs+set}" = set; then
- enableval=$enable_swapfs; if test "$enableval" = "no"
-then
- SWAPFS_CMT=#
- echo "Disabling swapfs support"
-else
- SWAPFS_CMT=
- cat >>confdefs.h <<\_ACEOF
-#define ENABLE_SWAPFS 1
-_ACEOF
-
- echo "Enabling swapfs support"
-fi
-
-else
- SWAPFS_CMT=
-echo "Enabling swapfs support by default"
-cat >>confdefs.h <<\_ACEOF
-#define ENABLE_SWAPFS 1
-_ACEOF
-
-
-fi
-
-
# Check whether --enable-debugfs was given.
if test "${enable_debugfs+set}" = set; then
enableval=$enable_debugfs; if test "$enableval" = "no"
LIB_EXT!$LIB_EXT$ac_delim
STATIC_LIB_EXT!$STATIC_LIB_EXT$ac_delim
PROFILED_LIB_EXT!$PROFILED_LIB_EXT$ac_delim
-SWAPFS_CMT!$SWAPFS_CMT$ac_delim
DEBUGFS_CMT!$DEBUGFS_CMT$ac_delim
IMAGER_CMT!$IMAGER_CMT$ac_delim
RESIZER_CMT!$RESIZER_CMT$ac_delim
E2FSCK_TYPE!$E2FSCK_TYPE$ac_delim
+FSCK_PROG!$FSCK_PROG$ac_delim
_ACEOF
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 76; then
ac_delim='%!_!# '
for ac_last_try in false false false false false :; do
cat >conf$$subs.sed <<_ACEOF
-FSCK_PROG!$FSCK_PROG$ac_delim
FSCK_MAN!$FSCK_MAN$ac_delim
E2INITRD_PROG!$E2INITRD_PROG$ac_delim
E2INITRD_MAN!$E2INITRD_MAN$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 81; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 80; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
echo "Disabling testio debugging by default"
)
dnl
-dnl handle --enable-swapfs
-dnl
-AC_ARG_ENABLE([swapfs],
-[ --disable-swapfs disable support of legacy byte-swapped filesystems],
-if test "$enableval" = "no"
-then
- SWAPFS_CMT=#
- echo "Disabling swapfs support"
-else
- SWAPFS_CMT=
- AC_DEFINE(ENABLE_SWAPFS)
- echo "Enabling swapfs support"
-fi
-,
-SWAPFS_CMT=
-echo "Enabling swapfs support by default"
-AC_DEFINE(ENABLE_SWAPFS)
-)
-AC_SUBST(SWAPFS_CMT)
-dnl
dnl handle --enable-debugfs
dnl
AC_ARG_ENABLE([debugfs],
--enable-blkid-devmapper
BF_CONF_FLAGS = --with-ccopts="${CCOPTS} ${BF_CCOPTS}" \
- --disable-nls --disable-swapfs --disable-imager \
+ --disable-nls --disable-imager \
--disable-debugfs --disable-e2initrd-helper
MIPS_NOPIC_CONF_FLAGS = --with-ccopts="${CCOPTS}" \
- --disable-nls \
- --disable-swapfs --disable-imager \
- --disable-resizer # --disable-debugfs
+ --disable-nls --disable-imager --disable-resizer # --disable-debugfs
# we can't use those flags at configure time
MIPS_CFLAGS= -G 0 -fno-pic -mno-abicalls
frag = inode->osd2.hurd2.h_i_frag;
fsize = inode->osd2.hurd2.h_i_fsize;
break;
- case EXT2_OS_MASIX:
- frag = inode->osd2.masix2.m_i_frag;
- fsize = inode->osd2.masix2.m_i_fsize;
- break;
default:
frag = fsize = 0;
}
sprintf(buf, format, *val);
printf("%30s [%s] ", prompt, buf);
- fgets(buf, sizeof(buf), stdin);
+ if (!fgets(buf, sizeof(buf), stdin))
+ return;
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
if (!buf[0])
sprintf(buf, format, *val);
printf("%30s [%s] ", prompt, buf);
- fgets(buf, sizeof(buf), stdin);
+ if (!fgets(buf, sizeof(buf), stdin))
+ return;
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
if (!buf[0])
sprintf(buf, format, *val);
printf("%30s [%s] ", prompt, buf);
- fgets(buf, sizeof(buf), stdin);
+ if (!fgets(buf, sizeof(buf), stdin))
+ return;
if (buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
if (!buf[0])
frag = &inode.osd2.hurd2.h_i_frag;
fsize = &inode.osd2.hurd2.h_i_fsize;
break;
- case EXT2_OS_MASIX:
- frag = &inode.osd2.masix2.m_i_frag;
- fsize = &inode.osd2.masix2.m_i_fsize;
- break;
default:
frag = fsize = 0;
}
struct ext2_inode inode;
int retval;
ext2_ino_t dir;
- char *dest, *cp, *basename;
+ char *dest, *cp, *base_name;
/*
* Get the source inode
ino = string_to_inode(sourcename);
if (!ino)
return;
- basename = strrchr(sourcename, '/');
- if (basename)
- basename++;
+ base_name = strrchr(sourcename, '/');
+ if (base_name)
+ base_name++;
else
- basename = sourcename;
+ base_name = sourcename;
/*
* Figure out the destination. First see if it exists and is
* a directory.
*/
if (! (retval=ext2fs_namei(current_fs, root, cwd, destname, &dir)))
- dest = basename;
+ dest = base_name;
else {
/*
* OK, it doesn't exist. See if it is
{
int retval;
ext2_ino_t dir;
- char *basename;
+ char *base_name;
- basename = strrchr(filename, '/');
- if (basename) {
- *basename++ = '\0';
+ base_name = strrchr(filename, '/');
+ if (base_name) {
+ *base_name++ = '\0';
dir = string_to_inode(filename);
if (!dir)
return;
} else {
dir = cwd;
- basename = filename;
+ base_name = filename;
}
- retval = ext2fs_unlink(current_fs, dir, basename, 0, 0);
+ retval = ext2fs_unlink(current_fs, dir, base_name, 0, 0);
if (retval)
com_err("unlink_file_by_name", retval, 0);
return;
/* set_fields.c */
extern void do_set_super(int argc, char **);
extern void do_set_inode(int argc, char **);
+extern void do_set_block_group_descriptor(int argc, char **);
/* unused.c */
extern void do_dump_unused(int argc, char **argv);
enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL};
-#define ANY_BLOCK ((unsigned int) -1)
+#define ANY_BLOCK ((blk_t) -1)
int dump_all, dump_contents, dump_descriptors;
-unsigned int block_to_dump, group_to_dump, bitmap_to_dump;
-unsigned int inode_block_to_dump, inode_offset_to_dump, bitmap_to_dump;
+blk_t block_to_dump, bitmap_to_dump, inode_block_to_dump;
+unsigned int group_to_dump, inode_offset_to_dump;
ext2_ino_t inode_to_dump;
struct journal_source
jsb = (journal_superblock_t *) buf;
sb = (struct ext2_super_block *) (buf+1024);
-#ifdef ENABLE_SWAPFS
+#ifdef WORDS_BIGENDIAN
if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
ext2fs_swap_super(sb);
#endif
if (dump_all) {
fprintf(out_file, "\tuuid=%s\n", jsb_buffer);
fprintf(out_file, "\tblocksize=%d\n", blocksize);
- fprintf(out_file, "\tjournal data size %ld\n",
- (long) sb->s_blocks_count);
+ fprintf(out_file, "\tjournal data size %lu\n",
+ sb->s_blocks_count);
}
}
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
+#if HAVE_STRINGS_H
+#include <strings.h>
+#endif
#include <fcntl.h>
#include <utime.h>
{
static int do_gmt = -1;
time_t t = (time_t) cl;
- char * tz;
+ const char *tz;
if (do_gmt == -1) {
/* The diet libc doesn't respect the TZ environemnt variable */
@ifinfo
@dircategory Development
-@format
-START-INFO-DIR-ENTRY
+@direntry
* libext2fs: (libext2fs.info). The EXT2FS library.
-END-INFO-DIR-ENTRY
-@end format
+@end direntry
@end ifinfo
@c smallbook
#MCHECK= -DMCHECK
OBJS= dict.o unix.o e2fsck.o super.o pass1.o pass1b.o pass2.o pass3.o pass4.o \
- pass5.o journal.o swapfs.o badblocks.o util.o dirinfo.o dx_dirinfo.o \
+ pass5.o journal.o badblocks.o util.o dirinfo.o dx_dirinfo.o \
ehandler.o problem.o message.o recovery.o region.o revoke.o \
ea_refcount.o rehash.o profile.o prof_err.o $(MTRACE_OBJ)
profiled/pass2.o profiled/pass3.o profiled/pass4.o profiled/pass5.o \
profiled/journal.o profiled/badblocks.o profiled/util.o \
profiled/dirinfo.o profiled/dx_dirinfo.o profiled/ehandler.o \
- profiled/message.o profiled/problem.o profiled/swapfs.o \
+ profiled/message.o profiled/problem.o \
profiled/recovery.o profiled/region.o profiled/revoke.o \
profiled/ea_refcount.o profiled/rehash.o profiled/profile.o \
profiled/prof_err.o
$(srcdir)/ehandler.c \
$(srcdir)/problem.c \
$(srcdir)/message.c \
- $(srcdir)/swapfs.c \
$(srcdir)/ea_refcount.c \
$(srcdir)/rehash.c \
$(srcdir)/region.c \
$(top_builddir)/lib/ext2fs/ext2_err.h $(top_srcdir)/lib/ext2fs/bitops.h \
$(top_srcdir)/lib/blkid/blkid.h $(top_builddir)/lib/blkid/blkid_types.h \
$(srcdir)/profile.h prof_err.h $(srcdir)/problem.h
-swapfs.o: $(srcdir)/swapfs.c $(top_srcdir)/lib/et/com_err.h \
- $(srcdir)/e2fsck.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
- $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \
- $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_srcdir)/lib/ext2fs/ext2_io.h \
- $(top_builddir)/lib/ext2fs/ext2_err.h $(top_srcdir)/lib/ext2fs/bitops.h \
- $(top_srcdir)/lib/blkid/blkid.h $(top_builddir)/lib/blkid/blkid_types.h \
- $(srcdir)/profile.h prof_err.h
ea_refcount.o: $(srcdir)/ea_refcount.c $(srcdir)/e2fsck.h \
$(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h \
$(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \
.SH SYNOPSIS
.B e2fsck
[
-.B \-pacnyrdfkvstDFSV
+.B \-pacnyrdfkvtDFV
]
[
.B \-b
.B \-r
This option does nothing at all; it is provided only for backwards
compatibility.
-.TP
-.B \-s
-This option will byte-swap the filesystem so that it is using the normalized,
-standard byte-order (which is i386 or little endian). If the filesystem is
-already in the standard byte-order,
-.B e2fsck
-will take no action.
-.TP
-.B \-S
-This option will byte-swap the filesystem, regardless of its current
-byte-order.
.TP
.B \-t
Print timing statistics for
struct timeval user_start;
struct timeval system_start;
void *brk_start;
+ unsigned long long bytes_read;
+ unsigned long long bytes_written;
};
#endif
void check_super_block(e2fsck_t ctx);
int check_backup_super_block(e2fsck_t ctx);
-/* swapfs.c */
-void swap_filesys(e2fsck_t ctx);
-
/* util.c */
extern void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
const char *description);
extern char *string_copy(e2fsck_t ctx, const char *str, int len);
#ifdef RESOURCE_TRACK
extern void print_resource_track(const char *desc,
- struct resource_track *track);
-extern void init_resource_track(struct resource_track *track);
+ struct resource_track *track,
+ io_channel channel);
+extern void init_resource_track(struct resource_track *track,
+ io_channel channel);
#endif
extern int inode_has_valid_blocks(struct ext2_inode *inode);
extern void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
memcpy(&jsuper, start ? bh->b_data : bh->b_data + 1024,
sizeof(jsuper));
brelse(bh);
-#ifdef EXT2FS_ENABLE_SWAPFS
+#ifdef WORDS_BIGENDIAN
if (jsuper.s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
ext2fs_swap_super(&jsuper);
#endif
/* simple remove all possible EA(s) */
*((__u32 *)start) = 0UL;
- e2fsck_write_inode_full(ctx, pctx->ino, (struct ext2_inode *) inode,
+ e2fsck_write_inode_full(ctx, pctx->ino, pctx->inode,
EXT2_INODE_SIZE(sb), "pass1");
}
int inode_size;
#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
+ init_resource_track(&rtrack, ctx->fs->io);
#endif
clear_problem_context(&pctx);
frag = inode->osd2.hurd2.h_i_frag;
fsize = inode->osd2.hurd2.h_i_fsize;
break;
- case EXT2_OS_MASIX:
- frag = inode->osd2.masix2.m_i_frag;
- fsize = inode->osd2.masix2.m_i_fsize;
- break;
default:
frag = fsize = 0;
}
#ifdef RESOURCE_TRACK
if (ctx->options & E2F_OPT_TIME2) {
e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 1"), &rtrack);
+ print_resource_track(_("Pass 1"), &rtrack, ctx->fs->io);
}
#endif
}
int bad_dir;
#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
+ init_resource_track(&rtrack, ctx->fs->io);
#endif
clear_problem_context(&cd.pctx);
#ifdef RESOURCE_TRACK
if (ctx->options & E2F_OPT_TIME2) {
e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 2"), &rtrack);
+ print_resource_track(_("Pass 2"), &rtrack, fs->io);
}
#endif
}
frag = &inode.osd2.hurd2.h_i_frag;
fsize = &inode.osd2.hurd2.h_i_fsize;
break;
- case EXT2_OS_MASIX:
- frag = &inode.osd2.masix2.m_i_frag;
- fsize = &inode.osd2.masix2.m_i_fsize;
- break;
default:
frag = fsize = 0;
}
unsigned long maxdirs, count;
#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
+ init_resource_track(&rtrack, ctx->fs->io);
#endif
clear_problem_context(&pctx);
#ifdef RESOURCE_TRACK
if (ctx->options & E2F_OPT_TIME) {
e2fsck_clear_progbar(ctx);
- print_resource_track(_("Peak memory"), &ctx->global_rtrack);
+ print_resource_track(_("Peak memory"), &ctx->global_rtrack,
+ NULL);
}
#endif
#ifdef RESOURCE_TRACK
if (ctx->options & E2F_OPT_TIME2) {
e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 3"), &rtrack);
+ print_resource_track(_("Pass 3"), &rtrack, ctx->fs->io);
}
#endif
}
int group, maxgroup;
#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
+ init_resource_track(&rtrack, ctx->fs->io);
#endif
#ifdef MTRACE
#ifdef RESOURCE_TRACK
if (ctx->options & E2F_OPT_TIME2) {
e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 4"), &rtrack);
+ print_resource_track(_("Pass 4"), &rtrack, ctx->fs->io);
}
#endif
}
#endif
#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
+ init_resource_track(&rtrack, ctx->fs->io);
#endif
clear_problem_context(&pctx);
#ifdef RESOURCE_TRACK
if (ctx->options & E2F_OPT_TIME2) {
e2fsck_clear_progbar(ctx);
- print_resource_track(_("Pass 5"), &rtrack);
+ print_resource_track(_("Pass 5"), &rtrack, ctx->fs->io);
}
#endif
}
blk_t i, super;
int *free_array;
int group = 0;
- unsigned int blocks = 0;
- unsigned int free_blocks = 0;
+ blk_t blocks = 0;
+ blk_t free_blocks = 0;
int group_free = 0;
int actual, bitmap;
struct problem_context pctx;
clear_problem_context(&pctx);
- end = fs->block_map->start +
+ end = ext2fs_get_block_bitmap_start(fs->block_map) +
(EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count) - 1;
pctx.errcode = ext2fs_fudge_block_bitmap_end(fs->block_map, end,
&save_blocks_count);
int cur, max, all_dirs, dir_index, first = 1;
#ifdef RESOURCE_TRACK
- init_resource_track(&rtrack);
+ init_resource_track(&rtrack, ctx->fs->io);
#endif
all_dirs = ctx->options & E2F_OPT_COMPRESS_DIRS;
#ifdef RESOURCE_TRACK
if (ctx->options & E2F_OPT_TIME2) {
e2fsck_clear_progbar(ctx);
- print_resource_track("Pass 3A", &rtrack);
+ print_resource_track("Pass 3A", &rtrack, ctx->fs->io);
}
#endif
}
dgrp_t i;
blk_t should_be;
struct problem_context pctx;
- __u32 free_blocks = 0, free_inodes = 0;
+ blk_t free_blocks = 0;
+ ino_t free_inodes = 0;
inodes_per_block = EXT2_INODES_PER_BLOCK(fs->super);
ipg_max = inodes_per_block * (blocks_per_group - 4);
/*
* Verify the group descriptors....
*/
- first_block = sb->s_first_data_block;
+ first_block = sb->s_first_data_block;
+ last_block = sb->s_blocks_count-1;
for (i = 0, gd=fs->group_desc; i < fs->group_desc_count; i++, gd++) {
pctx.group = i;
- first_block = ext2fs_group_first_block(fs, i);
- last_block = ext2fs_group_last_block(fs, i);
+ if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
+ EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
+ first_block = ext2fs_group_first_block(fs, i);
+ last_block = ext2fs_group_last_block(fs, i);
+ }
if ((gd->bg_block_bitmap < first_block) ||
(gd->bg_block_bitmap > last_block)) {
+++ /dev/null
-/*
- * 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 HAVE_ERRNO_H
-#include <errno.h>
-#endif
-#include <et/com_err.h>
-#include "e2fsck.h"
-
-#ifdef ENABLE_SWAPFS
-
-struct swap_block_struct {
- ext2_ino_t ino;
- int isdir;
- errcode_t errcode;
- char *dir_buf;
- struct ext2_inode *inode;
-};
-
-/*
- * This is a helper function for block_iterate. We mark all of the
- * indirect and direct blocks as changed, so that block_iterate will
- * write them out.
- */
-static int swap_block(ext2_filsys fs, blk_t *block_nr, int blockcnt,
- void *priv_data)
-{
- errcode_t retval;
-
- struct swap_block_struct *sb = (struct swap_block_struct *) priv_data;
-
- if (sb->isdir && (blockcnt >= 0) && *block_nr) {
- retval = ext2fs_read_dir_block(fs, *block_nr, sb->dir_buf);
- if (retval) {
- sb->errcode = retval;
- return BLOCK_ABORT;
- }
- retval = ext2fs_write_dir_block(fs, *block_nr, sb->dir_buf);
- if (retval) {
- sb->errcode = retval;
- return BLOCK_ABORT;
- }
- }
- if (blockcnt >= 0) {
- if (blockcnt < EXT2_NDIR_BLOCKS)
- return 0;
- return BLOCK_CHANGED;
- }
- if (blockcnt == BLOCK_COUNT_IND) {
- if (*block_nr == sb->inode->i_block[EXT2_IND_BLOCK])
- return 0;
- return BLOCK_CHANGED;
- }
- if (blockcnt == BLOCK_COUNT_DIND) {
- if (*block_nr == sb->inode->i_block[EXT2_DIND_BLOCK])
- return 0;
- return BLOCK_CHANGED;
- }
- if (blockcnt == BLOCK_COUNT_TIND) {
- if (*block_nr == sb->inode->i_block[EXT2_TIND_BLOCK])
- return 0;
- return BLOCK_CHANGED;
- }
- return BLOCK_CHANGED;
-}
-
-/*
- * This function is responsible for byte-swapping all of the indirect,
- * block pointers. It is also responsible for byte-swapping directories.
- */
-static void swap_inode_blocks(e2fsck_t ctx, ext2_ino_t ino, char *block_buf,
- struct ext2_inode *inode)
-{
- errcode_t retval;
- struct swap_block_struct sb;
-
- sb.ino = ino;
- sb.inode = inode;
- sb.dir_buf = block_buf + ctx->fs->blocksize*3;
- sb.errcode = 0;
- sb.isdir = 0;
- if (LINUX_S_ISDIR(inode->i_mode))
- sb.isdir = 1;
-
- 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"));
- ctx->flags |= E2F_FLAG_ABORT;
- return;
- }
- if (sb.errcode) {
- com_err("swap_inode_blocks", sb.errcode,
- _("while calling iterator function"));
- ctx->flags |= E2F_FLAG_ABORT;
- return;
- }
-}
-
-static void swap_inodes(e2fsck_t ctx)
-{
- ext2_filsys fs = ctx->fs;
- dgrp_t group;
- unsigned int i;
- ext2_ino_t ino = 1;
- char *buf = NULL, *block_buf = NULL;
- errcode_t retval;
- struct ext2_inode * inode;
-
- e2fsck_use_inode_shortcuts(ctx, 1);
-
- retval = ext2fs_get_mem(fs->blocksize * fs->inode_blocks_per_group,
- &buf);
- if (retval) {
- com_err("swap_inodes", retval,
- _("while allocating inode buffer"));
- ctx->flags |= E2F_FLAG_ABORT;
- goto errout;
- }
- block_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize * 4,
- "block interate buffer");
- for (group = 0; group < fs->group_desc_count; group++) {
- retval = io_channel_read_blk(fs->io,
- 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)"),
- group);
- ctx->flags |= E2F_FLAG_ABORT;
- goto errout;
- }
- inode = (struct ext2_inode *) buf;
- for (i=0; i < fs->super->s_inodes_per_group;
- i++, ino++, inode++) {
- ctx->stashed_ino = ino;
- ctx->stashed_inode = inode;
-
- if (fs->flags & EXT2_FLAG_SWAP_BYTES_READ)
- ext2fs_swap_inode(fs, inode, inode, 0);
-
- /*
- * Skip deleted files.
- */
- if (inode->i_links_count == 0)
- continue;
-
- if (LINUX_S_ISDIR(inode->i_mode) ||
- ((inode->i_block[EXT2_IND_BLOCK] ||
- inode->i_block[EXT2_DIND_BLOCK] ||
- inode->i_block[EXT2_TIND_BLOCK]) &&
- ext2fs_inode_has_valid_blocks(inode)))
- swap_inode_blocks(ctx, ino, block_buf, inode);
-
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- goto errout;
-
- if (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)
- ext2fs_swap_inode(fs, inode, inode, 1);
- }
- retval = io_channel_write_blk(fs->io,
- 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)"),
- group);
- ctx->flags |= E2F_FLAG_ABORT;
- goto errout;
- }
- }
-errout:
- if (buf)
- ext2fs_free_mem(&buf);
- if (block_buf)
- ext2fs_free_mem(&block_buf);
- e2fsck_use_inode_shortcuts(ctx, 0);
- ext2fs_flush_icache(fs);
-}
-
-#if defined(__powerpc__) && defined(EXT2FS_ENABLE_SWAPFS)
-/*
- * 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
- * of each word. Thus a bitmap with only bit 0 set would be, as
- * a string of bytes, 00 00 00 01 00 ...
- * To cope with this, we byte-reverse each word of a bitmap if
- * we have a big-endian filesystem, that is, if we are *not*
- * byte-swapping other word-sized numbers.
- */
-#define EXT2_BIG_ENDIAN_BITMAPS
-#endif
-
-#ifdef EXT2_BIG_ENDIAN_BITMAPS
-static void ext2fs_swap_bitmap(ext2fs_generic_bitmap bmap)
-{
- __u32 *p = (__u32 *) bmap->bitmap;
- int n, nbytes = (bmap->end - bmap->start + 7) / 8;
-
- for (n = nbytes / sizeof(__u32); n > 0; --n, ++p)
- *p = ext2fs_swab32(*p);
-}
-#endif
-
-
-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
-
- if (fs->super->s_mnt_count) {
- fprintf(stderr, _("%s: the filesystem must be freshly "
- "checked using fsck\n"
- "and not mounted before trying to "
- "byte-swap it.\n"), ctx->device_name);
- ctx->flags |= E2F_FLAG_ABORT;
- return;
- }
- if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
- fs->flags &= ~(EXT2_FLAG_SWAP_BYTES|
- EXT2_FLAG_SWAP_BYTES_WRITE);
- fs->flags |= EXT2_FLAG_SWAP_BYTES_READ;
- } else {
- fs->flags &= ~EXT2_FLAG_SWAP_BYTES_READ;
- fs->flags |= EXT2_FLAG_SWAP_BYTES_WRITE;
- }
- swap_inodes(ctx);
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- return;
- if (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)
- fs->flags |= EXT2_FLAG_SWAP_BYTES;
- fs->flags &= ~(EXT2_FLAG_SWAP_BYTES_READ|
- EXT2_FLAG_SWAP_BYTES_WRITE);
-
-#ifdef EXT2_BIG_ENDIAN_BITMAPS
- e2fsck_read_bitmaps(ctx);
- ext2fs_swap_bitmap(fs->inode_map);
- ext2fs_swap_bitmap(fs->block_map);
- fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_IB_DIRTY;
-#endif
- 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
#include "../version.h"
/* Command line options */
-static int swapfs;
-static int normalize_swapfs;
static int cflag; /* check disk */
static int show_version_only;
static int verbose;
static void usage(e2fsck_t ctx)
{
fprintf(stderr,
- _("Usage: %s [-panyrcdfvstDFSV] [-b superblock] [-B blocksize]\n"
+ _("Usage: %s [-panyrcdfvtDFV] [-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 external_journal]\n"
"\t\t[-E extended-options] device\n"),
if (!defer_check_on_battery)
batt = 0;
- if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file ||
- cflag || swapfs)
+ if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file || cflag)
return;
lastcheck = fs->super->s_lastcheck;
case 'N':
ctx->device_name = optarg;
break;
-#ifdef ENABLE_SWAPFS
- case 's':
- normalize_swapfs = 1;
- case 'S':
- swapfs = 1;
- break;
-#else
- case 's':
- case 'S':
- fprintf(stderr, _("Byte-swapping filesystems "
- "not compiled in this version "
- "of e2fsck\n"));
- exit(1);
-#endif
case 'k':
keep_bad_blocks++;
break;
if (optind != argc - 1)
usage(ctx);
if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file &&
- !cflag && !swapfs && !(ctx->options & E2F_OPT_COMPRESS_DIRS))
+ !cflag && !(ctx->options & E2F_OPT_COMPRESS_DIRS))
ctx->options |= E2F_OPT_READONLY;
ctx->io_options = strchr(argv[optind], '?');
if (ctx->io_options)
}
close(fd);
}
-#ifdef ENABLE_SWAPFS
- if (swapfs) {
- if (cflag || bad_blocks_file) {
- fprintf(stderr, _("Incompatible options not "
- "allowed when byte-swapping.\n"));
- exit(FSCK_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"));
reserve_stdio_fds();
#ifdef RESOURCE_TRACK
- init_resource_track(&ctx->global_rtrack);
+ init_resource_track(&ctx->global_rtrack, NULL);
#endif
if (!(ctx->options & E2F_OPT_PREEN) || show_version_only)
read_bad_blocks_file(ctx, 0, !keep_bad_blocks); /* Test disk */
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
fatal_error(ctx, 0);
-#ifdef ENABLE_SWAPFS
- if (normalize_swapfs) {
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ==
- ext2fs_native_flag()) {
- fprintf(stderr, _("%s: Filesystem byte order "
- "already normalized.\n"), ctx->device_name);
- fatal_error(ctx, 0);
- }
- }
- if (swapfs) {
- swap_filesys(ctx);
- if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
- fatal_error(ctx, 0);
- }
-#endif
/*
* Mark the system as valid, 'til proven otherwise
}
e2fsck_write_bitmaps(ctx);
-
+#ifdef RESOURCE_TRACK
+ io_channel_flush(ctx->fs->io);
+ if (ctx->options & E2F_OPT_TIME)
+ print_resource_track(NULL, &ctx->global_rtrack, ctx->fs->io);
+#endif
ext2fs_close(fs);
ctx->fs = NULL;
free(ctx->filesystem_name);
free(ctx->journal_name);
-#ifdef RESOURCE_TRACK
- if (ctx->options & E2F_OPT_TIME)
- print_resource_track(NULL, &ctx->global_rtrack);
-#endif
e2fsck_free_context(ctx);
remove_error_table(&et_ext2_error_table);
remove_error_table(&et_prof_error_table);
}
#ifdef RESOURCE_TRACK
-void init_resource_track(struct resource_track *track)
+void init_resource_track(struct resource_track *track, io_channel channel)
{
#ifdef HAVE_GETRUSAGE
struct rusage r;
#endif
+ io_stats io_start = 0;
track->brk_start = sbrk(0);
gettimeofday(&track->time_start, 0);
track->user_start.tv_sec = track->user_start.tv_usec = 0;
track->system_start.tv_sec = track->system_start.tv_usec = 0;
#endif
+ track->bytes_read = 0;
+ track->bytes_written = 0;
+ if (channel && channel->manager && channel->manager->get_stats)
+ channel->manager->get_stats(channel, &io_start);
+ if (io_start) {
+ track->bytes_read = io_start->bytes_read;
+ track->bytes_written = io_start->bytes_written;
+ }
}
#ifdef __GNUC__
((float) (tv1->tv_usec - tv2->tv_usec)) / 1000000);
}
-void print_resource_track(const char *desc, struct resource_track *track)
+void print_resource_track(const char *desc, struct resource_track *track,
+ io_channel channel)
{
#ifdef HAVE_GETRUSAGE
struct rusage r;
printf(_("elapsed time: %6.3f\n"),
timeval_subtract(&time_end, &track->time_start));
#endif
+#define mbytes(x) (((x) + 1048575) / 1048576)
+ if (channel && channel->manager && channel->manager->get_stats) {
+ io_stats delta = 0;
+ unsigned long long bytes_read = 0;
+ unsigned long long bytes_written = 0;
+
+ if (desc)
+ printf("%s: ", desc);
+
+ channel->manager->get_stats(channel, &delta);
+ if (delta) {
+ bytes_read = delta->bytes_read - track->bytes_read;
+ bytes_written = delta->bytes_written -
+ track->bytes_written;
+ }
+ printf("I/O read: %lluMB, write: %lluMB, rate: %.2fMB/s\n",
+ mbytes(bytes_read), mbytes(bytes_written),
+ (double)mbytes(bytes_read + bytes_written) /
+ timeval_subtract(&time_end, &track->time_start));
+ }
}
#endif /* RESOURCE_TRACK */
if (io_channel_read_blk(io, superblock,
-SUPERBLOCK_SIZE, buf))
continue;
-#ifdef EXT2FS_ENABLE_SWAPFS
+#ifdef WORDS_BIGENDIAN
if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
ext2fs_swap_super(sb);
#endif
struct {
__u32 h_i_translator;
} hurd1;
- struct {
- __u32 m_i_reserved1;
- } masix1;
} osd1; /* OS dependent 1 */
__u32 i_block[EXT2_N_BLOCKS]; /* Pointers to blocks */
__u32 i_version; /* File version (for NFS) */
__u16 h_i_gid_high;
__u32 h_i_author;
} hurd2;
- struct {
- __u8 m_i_frag; /* Fragment number */
- __u8 m_i_fsize; /* Fragment size */
- __u16 m_pad1;
- __u32 m_i_reserved2[2];
- } masix2;
} osd2; /* OS dependent 2 */
};
</ProgramListing>
Version: @E2FSPROGS_VERSION@
Requires: uuid @DEVMAPPER_REQ@
Cflags: -I${includedir}
-Libs: -L${libdir} -lblkid @DEVMAPPER_PC_LIBS@
+Libs: -L${libdir} -lblkid
+Libs.private: @DEVMAPPER_PC_LIBS@
}
#ifdef HAVE_DEVMAPPER
-static void dm_quiet_log(int level, const char *file, int line,
- const char *f, ...)
+static void dm_quiet_log(int level __BLKID_ATTR((unused)),
+ const char *file __BLKID_ATTR((unused)),
+ int line __BLKID_ATTR((unused)),
+ const char *f __BLKID_ATTR((unused)), ...)
{
return;
}
struct dm_task *task;
struct dm_deps *deps;
struct dm_info info;
- int i;
+ unsigned int i;
task = dm_task_create(DM_DEVICE_DEPS);
if (!task)
n = 0;
do {
- names = (void *)names + next;
+ names = (struct dm_names *) ((char *)names + next);
if (dm_device_has_dep(dev, names->name))
ret = 0;
char *device = NULL;
dev_t dev = 0;
- names = (void *)names + next;
+ names = (struct dm_names *) ((char *)names + next);
rc = asprintf(&device, "mapper/%s", names->name);
if (rc < 0)
#ifdef TEST_PROGRAM
int main(int argc, char **argv)
{
- blkid_loff_t bytes;
+ long long bytes;
int fd;
if (argc < 2) {
return 0;
}
-static void set_uuid(blkid_dev dev, uuid_t uuid, char *tag)
+static void set_uuid(blkid_dev dev, uuid_t uuid, const char *tag)
{
char str[37];
#define FAT_ATTR_MASK 0x3f
#define FAT_ENTRY_FREE 0xe5
-static char *no_name = "NO NAME ";
+static const char *no_name = "NO NAME ";
static unsigned char *search_fat_label(struct vfat_dir_entry *dir, int count)
{
struct blkid_magic *id __BLKID_ATTR((unused)),
unsigned char *buf)
{
- unsigned char uuid[40];
+ char uuid[40];
+
/* 168 is the offset to the 40 character uuid:
* http://luks.endorphin.org/LUKS-on-disk-format.pdf */
- strncpy(uuid, buf+168, 40);
+ strncpy(uuid, (char *) buf+168, 40);
blkid_set_tag(probe->dev, "UUID", uuid, sizeof(uuid));
return 0;
}
done
fi
-mkdir -p tests
+mkdir -p tests/tmp
for i in $TESTS
do
echo "non-existent"
continue
fi
- bunzip2 < $SRCDIR/tests/$i.img.bz2 > /tmp/test.img.$$
- ./tst_probe /tmp/test.img.$$ > tests/$i.out
- /bin/rm -f /tmp/test.img.$$ tests/$i.ok tests/$i.failed
+ bunzip2 < $SRCDIR/tests/$i.img.bz2 > tests/tmp/test.img.$$
+ ./tst_probe tests/tmp/test.img.$$ > tests/$i.out
+ /bin/rm -f tests/tmp/test.img.$$ tests/$i.ok tests/$i.failed
cmp -s tests/$i.out $SRCDIR/tests/$i.results
if [ $? = 0 ]; then
echo ok
"extent" },
{ E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_64BIT,
"64bit" },
+ { E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_FLEX_BG,
+ "flex_bg"},
{ 0, 0, 0 },
};
#if HAVE_EXT2_IOCTLS
int fd, r, f, save_errno = 0;
- if (!stat(name, &buf) &&
+ if (!lstat(name, &buf) &&
!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
goto notsupp;
}
#if HAVE_EXT2_IOCTLS
int fd, r, f, save_errno = 0;
- if (!stat(name, &buf) &&
+ if (!lstat(name, &buf) &&
!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
goto notsupp;
}
{
DIR * dir;
struct dirent *de, *dep;
- int max_len = -1, len;
+ int max_len = -1, len, ret = 0;
#if HAVE_PATHCONF && defined(_PC_NAME_MAX)
max_len = pathconf(dir_name, _PC_NAME_MAX);
len = max_len;
#endif
memcpy(de, dep, len);
- (*func) (dir_name, de, private);
+ if ((*func)(dir_name, de, private))
+ ret++;
}
free(de);
closedir(dir);
- return 0;
+ return ret;
}
@ifinfo
@dircategory Development
-@format
-START-INFO-DIR-ENTRY
+@direntry
* Com_err: (com_err). A Common Error Description Library for UNIX.
-END-INFO-DIR-ENTRY
-@end format
+@end direntry
@end ifinfo
@iftex
@MCONFIG@
-@DEBUGFS_CMT@DEBUGFS_LIB_OBJS = bb_compat.o cmp_bitmaps.o fileio.o \
+@DEBUGFS_CMT@DEBUGFS_LIB_OBJS = bb_compat.o fileio.o \
@DEBUGFS_CMT@ inode_io.o namei.o write_bb_file.o
-@RESIZER_CMT@RESIZE_LIB_OBJS = rs_bitmap.o dupfs.o test_io.o
+@RESIZER_CMT@RESIZE_LIB_OBJS = dupfs.o test_io.o
@IMAGER_CMT@E2IMAGE_LIB_OBJS = imager.o
$(srcdir)/bmap.c \
$(srcdir)/check_desc.c \
$(srcdir)/closefs.c \
- $(srcdir)/cmp_bitmaps.c \
$(srcdir)/dblist.c \
$(srcdir)/dblist_dir.c \
$(srcdir)/dirblock.c \
$(srcdir)/read_bb.c \
$(srcdir)/read_bb_file.c \
$(srcdir)/res_gdt.c \
- $(srcdir)/rs_bitmap.c \
$(srcdir)/rw_bitmaps.c \
$(srcdir)/swapfs.c \
$(srcdir)/tdb.c \
$(srcdir)/test_io.c \
- $(srcdir)/unix_io.c \
- $(srcdir)/unlink.c \
- $(srcdir)/valid_blk.c \
- $(srcdir)/version.c \
- $(srcdir)/write_bb_file.c \
$(srcdir)/tst_badblocks.c \
$(srcdir)/tst_bitops.c \
$(srcdir)/tst_byteswap.c \
$(srcdir)/tst_getsize.c \
- $(srcdir)/tst_iscan.c
+ $(srcdir)/tst_iscan.c \
+ $(srcdir)/unix_io.c \
+ $(srcdir)/unlink.c \
+ $(srcdir)/valid_blk.c \
+ $(srcdir)/version.c \
+ $(srcdir)/write_bb_file.c
HFILES= bitops.h ext2fs.h ext2_io.h ext2_fs.h ext2_ext_attr.h ext3_extents.h \
tdb.h
@echo " CONFIG.STATUS $@"
@cd $(top_builddir); CONFIG_FILES=lib/ext2fs/ext2fs.pc ./config.status
-tst_badblocks: tst_badblocks.o freefs.o \
+tst_badblocks: tst_badblocks.o freefs.o bitmaps.o rw_bitmaps.o \
read_bb_file.o write_bb_file.o badblocks.o
@echo " LD $@"
@$(CC) -o tst_badblocks tst_badblocks.o freefs.o \
- read_bb_file.o write_bb_file.o badblocks.o \
- inline.o bitops.o gen_bitmap.o $(LIBCOM_ERR)
+ read_bb_file.o write_bb_file.o badblocks.o rw_bitmaps.o \
+ inline.o bitops.o gen_bitmap.o bitmaps.o $(LIBCOM_ERR)
tst_icount: icount.c initialize.o $(STATIC_LIBEXT2FS)
@echo " LD $@"
@echo " LD $@"
@$(CC) -o mkjournal $(srcdir)/mkjournal.c -DDEBUG $(STATIC_LIBEXT2FS) $(LIBCOM_ERR) $(ALL_CFLAGS)
-check:: tst_bitops tst_badblocks tst_iscan @SWAPFS_CMT@ tst_byteswap \
- tst_types tst_icount tst_super_size
+check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount tst_super_size
LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_bitops
LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_badblocks
LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_iscan
-@SWAPFS_CMT@ LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_byteswap
LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_types
LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_icount
LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_super_size
$(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \
$(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
$(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/bitops.h
-cmp_bitmaps.o: $(srcdir)/cmp_bitmaps.c $(srcdir)/ext2_fs.h \
- $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
- $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
- $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/bitops.h
dblist.o: $(srcdir)/dblist.c $(srcdir)/ext2_fs.h \
$(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fsP.h \
$(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h \
$(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
$(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
$(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/bitops.h
-rs_bitmap.o: $(srcdir)/rs_bitmap.c $(srcdir)/ext2_fs.h \
- $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
- $(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
- $(srcdir)/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/bitops.h
rw_bitmaps.o: $(srcdir)/rw_bitmaps.c $(srcdir)/ext2_fs.h \
$(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
$(srcdir)/ext2_fs.h $(srcdir)/ext3_extents.h $(top_srcdir)/lib/et/com_err.h \
#include "ext2_fs.h"
#include "ext2fs.h"
-static errcode_t make_bitmap(__u32 start, __u32 end, __u32 real_end,
- const char *descr, char *init_map,
- ext2fs_generic_bitmap *ret)
-{
- ext2fs_generic_bitmap bitmap;
- errcode_t retval;
- size_t size;
-
- retval = ext2fs_get_mem(sizeof(struct ext2fs_struct_generic_bitmap),
- &bitmap);
- if (retval)
- return retval;
-
- bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
- bitmap->fs = NULL;
- bitmap->start = start;
- bitmap->end = end;
- bitmap->real_end = real_end;
- bitmap->base_error_code = EXT2_ET_BAD_GENERIC_MARK;
- if (descr) {
- retval = ext2fs_get_mem(strlen(descr)+1, &bitmap->description);
- if (retval) {
- ext2fs_free_mem(&bitmap);
- return retval;
- }
- strcpy(bitmap->description, descr);
- } else
- bitmap->description = 0;
-
- size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1);
- retval = ext2fs_get_mem(size, &bitmap->bitmap);
- if (retval) {
- ext2fs_free_mem(&bitmap->description);
- ext2fs_free_mem(&bitmap);
- return retval;
- }
-
- if (init_map)
- memcpy(bitmap->bitmap, init_map, size);
- else
- memset(bitmap->bitmap, 0, size);
- *ret = bitmap;
- return 0;
-}
-
-errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
- __u32 end,
- __u32 real_end,
- const char *descr,
- ext2fs_generic_bitmap *ret)
-{
- return make_bitmap(start, end, real_end, descr, 0, ret);
+void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
+{
+ ext2fs_free_generic_bitmap(bitmap);
+}
+
+void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
+{
+ ext2fs_free_generic_bitmap(bitmap);
}
errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
ext2fs_generic_bitmap *dest)
{
- errcode_t retval;
- ext2fs_generic_bitmap new_map;
-
- retval = make_bitmap(src->start, src->end, src->real_end,
- src->description, src->bitmap, &new_map);
- if (retval)
- return retval;
- new_map->magic = src->magic;
- new_map->fs = src->fs;
- new_map->base_error_code = src->base_error_code;
- *dest = new_map;
- return 0;
+ return (ext2fs_copy_generic_bitmap(src, dest));
}
void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map)
{
- __u32 i, j;
-
- /* Protect loop from wrap-around if map->real_end is maxed */
- for (i=map->end+1, j = i - map->start;
- i <= map->real_end && i > map->end;
- i++, j++)
- ext2fs_set_bit(j, map->bitmap);
-
- return;
+ ext2fs_set_generic_bitmap_padding(map);
}
errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
const char *descr,
ext2fs_inode_bitmap *ret)
{
- ext2fs_inode_bitmap bitmap;
- errcode_t retval;
__u32 start, end, real_end;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
end = fs->super->s_inodes_count;
real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count);
- retval = ext2fs_allocate_generic_bitmap(start, end, real_end,
- descr, &bitmap);
- if (retval)
- return retval;
-
- bitmap->magic = EXT2_ET_MAGIC_INODE_BITMAP;
- bitmap->fs = fs;
- bitmap->base_error_code = EXT2_ET_BAD_INODE_MARK;
-
- *ret = bitmap;
- return 0;
+ return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs,
+ start, end, real_end,
+ descr, 0, ret));
}
errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
const char *descr,
ext2fs_block_bitmap *ret)
{
- ext2fs_block_bitmap bitmap;
- errcode_t retval;
__u32 start, end, real_end;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
real_end = (EXT2_BLOCKS_PER_GROUP(fs->super)
* fs->group_desc_count)-1 + start;
- retval = ext2fs_allocate_generic_bitmap(start, end, real_end,
- descr, &bitmap);
- if (retval)
- return retval;
-
- bitmap->magic = EXT2_ET_MAGIC_BLOCK_BITMAP;
- bitmap->fs = fs;
- bitmap->base_error_code = EXT2_ET_BAD_BLOCK_MARK;
-
- *ret = bitmap;
- return 0;
+ return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs,
+ start, end, real_end,
+ descr, 0, ret));
}
errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
ext2_ino_t end, ext2_ino_t *oend)
{
- EXT2_CHECK_MAGIC(bitmap, EXT2_ET_MAGIC_INODE_BITMAP);
-
- if (end > bitmap->real_end)
- return EXT2_ET_FUDGE_INODE_BITMAP_END;
- if (oend)
- *oend = bitmap->end;
- bitmap->end = end;
- return 0;
+
+ return (ext2fs_fudge_generic_bitmap_end(bitmap,
+ EXT2_ET_MAGIC_INODE_BITMAP,
+ EXT2_ET_FUDGE_INODE_BITMAP_END,
+ end, oend));
}
errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
blk_t end, blk_t *oend)
{
- EXT2_CHECK_MAGIC(bitmap, EXT2_ET_MAGIC_BLOCK_BITMAP);
-
- if (end > bitmap->real_end)
- return EXT2_ET_FUDGE_BLOCK_BITMAP_END;
- if (oend)
- *oend = bitmap->end;
- bitmap->end = end;
- return 0;
+ return (ext2fs_fudge_generic_bitmap_end(bitmap,
+ EXT2_ET_MAGIC_BLOCK_BITMAP,
+ EXT2_ET_FUDGE_BLOCK_BITMAP_END,
+ end, oend));
}
void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap)
{
- if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP))
- return;
-
- memset(bitmap->bitmap, 0,
- (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1));
+ ext2fs_clear_generic_bitmap(bitmap);
}
void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap)
{
- if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP))
- return;
+ ext2fs_clear_generic_bitmap(bitmap);
+}
- memset(bitmap->bitmap, 0,
- (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1));
+errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
+ ext2fs_inode_bitmap bmap)
+{
+ return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
+ new_end, new_real_end, bmap));
+}
+
+errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
+ ext2fs_block_bitmap bmap)
+{
+ return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
+ new_end, new_real_end, bmap));
+}
+
+errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
+ ext2fs_block_bitmap bm2)
+{
+ return (ext2fs_compare_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP,
+ EXT2_ET_NEQ_BLOCK_BITMAP,
+ bm1, bm2));
+}
+
+errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
+ ext2fs_inode_bitmap bm2)
+{
+ return (ext2fs_compare_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP,
+ EXT2_ET_NEQ_INODE_BITMAP,
+ bm1, bm2));
+}
+
+errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
+ ext2_ino_t start, unsigned int num,
+ void *in)
+{
+ return (ext2fs_set_generic_bitmap_range(bmap,
+ EXT2_ET_MAGIC_INODE_BITMAP,
+ start, num, in));
+}
+
+errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
+ ext2_ino_t start, unsigned int num,
+ void *out)
+{
+ return (ext2fs_get_generic_bitmap_range(bmap,
+ EXT2_ET_MAGIC_INODE_BITMAP,
+ start, num, out));
+}
+
+errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
+ blk_t start, unsigned int num,
+ void *in)
+{
+ return (ext2fs_set_generic_bitmap_range(bmap,
+ EXT2_ET_MAGIC_BLOCK_BITMAP,
+ start, num, in));
+}
+
+errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
+ blk_t start, unsigned int num,
+ void *out)
+{
+ return (ext2fs_get_generic_bitmap_range(bmap,
+ EXT2_ET_MAGIC_BLOCK_BITMAP,
+ start, num, out));
}
com_err(0, errcode, "#%lu", arg);
#endif
}
-
-void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
- int code, unsigned long arg)
-{
-#ifndef OMIT_COM_ERR
- if (bitmap->description)
- com_err(0, bitmap->base_error_code+code,
- "#%lu for %s", arg, bitmap->description);
- else
- com_err(0, bitmap->base_error_code + code, "#%lu", arg);
-#endif
-}
-
blk_t block, int num);
extern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map);
-/* These two routines moved to gen_bitmap.c */
+/* These routines moved to gen_bitmap.c */
extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
__u32 bitno);
extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap,
blk_t bitno);
+extern int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
+ blk_t bitno);
+extern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
+ blk_t block, int num);
+extern __u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap);
+extern __u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap);
+
/*
* The inline routines themselves...
*
}
#endif
-#ifdef EXT2FS_ENABLE_SWAPFS
-_INLINE_ __u32 ext2fs_swab32(__u32 val)
-{
-#ifdef EXT2FS_REQUIRE_486
- __asm__("bswap %0" : "=r" (val) : "0" (val));
-#else
- __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
- "rorl $16,%0\n\t" /* swap words */
- "xchgb %b0,%h0" /* swap higher bytes */
- :"=q" (val)
- : "0" (val));
-#endif
- return val;
-}
-
-_INLINE_ __u16 ext2fs_swab16(__u16 val)
-{
- __asm__("xchgb %b0,%h0" /* swap bytes */ \
- : "=q" (val) \
- : "0" (val)); \
- return val;
-}
-
-_INLINE_ __u64 ext2fs_swab64(__u64 val)
-{
- return (ext2fs_swab32(val >> 32) |
- (((__u64)ext2fs_swab32(val & 0xFFFFFFFFUL)) << 32));
-}
-#endif
-
#undef EXT2FS_ADDR
#endif /* i386 */
#endif /* __mc68000__ */
-#if !defined(_EXT2_HAVE_ASM_SWAB_) && defined(EXT2FS_ENABLE_SWAPFS)
+#if !defined(_EXT2_HAVE_ASM_SWAB_) && defined(WORDS_BIGENDIAN)
_INLINE_ __u16 ext2fs_swab16(__u16 val)
{
}
#endif
-_INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
- blk_t bitno);
-
-_INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
- blk_t bitno)
-{
- if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
- ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno);
- return 0;
- }
- return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap);
-}
-
_INLINE_ int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap,
blk_t block)
{
- return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap)
- bitmap,
+ return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap,
block);
}
_INLINE_ void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap,
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_fast_set_bit(block - bitmap->start, bitmap->bitmap);
+ ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block);
}
_INLINE_ void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap,
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_fast_clear_bit(block - bitmap->start, bitmap->bitmap);
+ ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block);
}
_INLINE_ int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap,
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_generic_bitmap((ext2fs_generic_bitmap) bitmap,
+ block);
}
_INLINE_ void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap,
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_fast_set_bit(inode - bitmap->start, bitmap->bitmap);
+ ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode);
}
_INLINE_ void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap,
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_fast_clear_bit(inode - bitmap->start, bitmap->bitmap);
+ ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode);
}
_INLINE_ int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap,
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_generic_bitmap((ext2fs_generic_bitmap) bitmap,
+ inode);
}
_INLINE_ blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap)
{
- return bitmap->start;
+ return ext2fs_get_generic_bitmap_start((ext2fs_generic_bitmap) bitmap);
}
_INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap)
{
- return bitmap->start;
+ return ext2fs_get_generic_bitmap_start((ext2fs_generic_bitmap) bitmap);
}
_INLINE_ blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap)
{
- return bitmap->end;
+ return ext2fs_get_generic_bitmap_end((ext2fs_generic_bitmap) bitmap);
}
_INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap)
{
- return bitmap->end;
-}
-
-_INLINE_ int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
- blk_t block, int num)
-{
- int i;
-
- if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
- ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
- block, bitmap->description);
- return 0;
- }
- for (i=0; i < num; i++) {
- if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
- return 0;
- }
- return 1;
+ return ext2fs_get_generic_bitmap_end((ext2fs_generic_bitmap) bitmap);
}
_INLINE_ int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
blk_t block, int num)
{
- 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++) {
- if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
- return 0;
- }
- return 1;
-}
-
-_INLINE_ void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
- blk_t block, int num)
-{
- int i;
-
- if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
- ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
- bitmap->description);
- return;
- }
- for (i=0; i < num; i++)
- ext2fs_fast_set_bit(block + i - bitmap->start, bitmap->bitmap);
+ return ext2fs_test_block_bitmap_range(bitmap, block, num);
}
_INLINE_ void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
blk_t block, int num)
{
- 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++)
- ext2fs_fast_set_bit(block + i - bitmap->start, bitmap->bitmap);
-}
-
-_INLINE_ void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
- blk_t block, int num)
-{
- int i;
-
- if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
- ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
- bitmap->description);
- return;
- }
- for (i=0; i < num; i++)
- ext2fs_fast_clear_bit(block + i - bitmap->start,
- bitmap->bitmap);
+ ext2fs_mark_block_bitmap_range(bitmap, block, num);
}
_INLINE_ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
blk_t block, int num)
{
- 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++)
- ext2fs_fast_clear_bit(block + i - bitmap->start,
- bitmap->bitmap);
+ ext2fs_unmark_block_bitmap_range(bitmap, block, num);
}
#undef _INLINE_
#endif
if (flags & BMAP_SET) {
b = *ret_blk;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
- b = ext2fs_swab32(b);
+#ifdef WORDS_BIGENDIAN
+ b = ext2fs_swab32(b);
#endif
((blk_t *) block_buf)[nr] = b;
return io_channel_write_blk(fs->io, ind, 1, block_buf);
b = ((blk_t *) block_buf)[nr];
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
- b = ext2fs_swab32(b);
+#ifdef WORDS_BIGENDIAN
+ b = ext2fs_swab32(b);
#endif
if (!b && (flags & BMAP_ALLOC)) {
if (retval)
return retval;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
- ((blk_t *) block_buf)[nr] = ext2fs_swab32(b);
- else
+#ifdef WORDS_BIGENDIAN
+ ((blk_t *) block_buf)[nr] = ext2fs_swab32(b);
+#else
+ ((blk_t *) block_buf)[nr] = b;
#endif
- ((blk_t *) block_buf)[nr] = b;
retval = io_channel_write_blk(fs->io, ind, 1, block_buf);
if (retval)
if (block < EXT2_NDIR_BLOCKS) {
if (bmap_flags & BMAP_SET) {
b = *phys_blk;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
- b = ext2fs_swab32(b);
+#ifdef WORDS_BIGENDIAN
+ b = ext2fs_swab32(b);
#endif
inode_bmap(inode, block) = b;
inode_dirty++;
{
dgrp_t i;
blk_t first_block = fs->super->s_first_data_block;
- blk_t last_block;
+ blk_t last_block = fs->super->s_blocks_count-1;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
for (i = 0; i < fs->group_desc_count; i++) {
- first_block = ext2fs_group_first_block(fs, i);
- last_block = ext2fs_group_last_block(fs, i);
+ if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
+ EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
+ first_block = ext2fs_group_first_block(fs, i);
+ last_block = ext2fs_group_last_block(fs, i);
+ }
/*
* Check to make sure block bitmap for group is
{
blk_t group_block, super_blk = 0, old_desc_blk = 0, new_desc_blk = 0;
unsigned int meta_bg, meta_bg_size;
- int numblocks, has_super;
- int old_desc_blocks;
+ blk_t numblocks, old_desc_blocks;
+ int has_super;
- group_block = fs->super->s_first_data_block +
- (group * fs->super->s_blocks_per_group);
+ group_block = ext2fs_group_first_block(fs, group);
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
super_blk = group_block;
numblocks--;
}
- meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
meta_bg = group / meta_bg_size;
if (!(fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) ||
if (sgrp > ((1 << 16) - 1))
sgrp = (1 << 16) - 1;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & EXT2_FLAG_SWAP_BYTES)
- super_shadow->s_block_group_nr = ext2fs_swab16(sgrp);
- else
+#ifdef WORDS_BIGENDIAN
+ super_shadow->s_block_group_nr = ext2fs_swab16(sgrp);
+#else
+ fs->super->s_block_group_nr = sgrp;
#endif
- fs->super->s_block_group_nr = sgrp;
return io_channel_write_blk(fs->io, group_block, -SUPERBLOCK_SIZE,
super_shadow);
fs->super->s_wtime = fs->now ? fs->now : time(NULL);
fs->super->s_block_group_nr = 0;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
- retval = EXT2_ET_NO_MEMORY;
- retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &super_shadow);
- if (retval)
- goto errout;
- retval = ext2fs_get_array(fs->blocksize, fs->desc_blocks,
- &group_shadow);
- if (retval)
- goto errout;
- memset(group_shadow, 0, (size_t) fs->blocksize *
- fs->desc_blocks);
-
- /* swap the group descriptors */
- for (j=0, s=fs->group_desc, t=group_shadow;
- j < fs->group_desc_count; j++, t++, s++) {
- *t = *s;
- ext2fs_swap_group_desc(t);
- }
- } else {
- super_shadow = fs->super;
- group_shadow = fs->group_desc;
+#ifdef WORDS_BIGENDIAN
+ retval = EXT2_ET_NO_MEMORY;
+ retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &super_shadow);
+ if (retval)
+ goto errout;
+ retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize,
+ &group_shadow);
+ if (retval)
+ goto errout;
+ memset(group_shadow, 0, (size_t) fs->blocksize *
+ fs->desc_blocks);
+
+ /* swap the group descriptors */
+ for (j=0, s=fs->group_desc, t=group_shadow;
+ j < fs->group_desc_count; j++, t++, s++) {
+ *t = *s;
+ ext2fs_swap_group_desc(t);
}
#else
super_shadow = fs->super;
* we write out the backup superblocks.)
*/
fs->super->s_state &= ~EXT2_VALID_FS;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
- *super_shadow = *fs->super;
- ext2fs_swap_super(super_shadow);
- }
+#ifdef WORDS_BIGENDIAN
+ *super_shadow = *fs->super;
+ ext2fs_swap_super(super_shadow);
#endif
/*
fs->super->s_block_group_nr = 0;
fs->super->s_state = fs_state;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
- *super_shadow = *fs->super;
- ext2fs_swap_super(super_shadow);
- }
+#ifdef WORDS_BIGENDIAN
+ *super_shadow = *fs->super;
+ ext2fs_swap_super(super_shadow);
#endif
retval = io_channel_flush(fs->io);
retval = io_channel_flush(fs->io);
errout:
fs->super->s_state = fs_state;
- if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
- if (super_shadow)
- ext2fs_free_mem(&super_shadow);
- if (group_shadow)
- ext2fs_free_mem(&group_shadow);
- }
+#ifdef WORDS_BIGENDIAN
+ if (super_shadow)
+ ext2fs_free_mem(&super_shadow);
+ if (group_shadow)
+ ext2fs_free_mem(&group_shadow);
+#endif
return retval;
}
+++ /dev/null
-/*
- * cmp_bitmaps.c --- routines to compare inode and block bitmaps.
- *
- * Copyright (C) 1995 Theodore Ts'o.
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
- * %End-Header%
- */
-
-#include <stdio.h>
-#include <string.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <fcntl.h>
-#include <time.h>
-#if HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#include "ext2_fs.h"
-#include "ext2fs.h"
-
-errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
- ext2fs_block_bitmap bm2)
-{
- blk_t i;
-
- EXT2_CHECK_MAGIC(bm1, EXT2_ET_MAGIC_BLOCK_BITMAP);
- EXT2_CHECK_MAGIC(bm2, EXT2_ET_MAGIC_BLOCK_BITMAP);
-
- if ((bm1->start != bm2->start) ||
- (bm1->end != bm2->end) ||
- (memcmp(bm1->bitmap, bm2->bitmap,
- (size_t) (bm1->end - bm1->start)/8)))
- return EXT2_ET_NEQ_BLOCK_BITMAP;
-
- for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
- if (ext2fs_fast_test_block_bitmap(bm1, i) !=
- ext2fs_fast_test_block_bitmap(bm2, i))
- return EXT2_ET_NEQ_BLOCK_BITMAP;
-
- return 0;
-}
-
-errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
- ext2fs_inode_bitmap bm2)
-{
- ext2_ino_t i;
-
- EXT2_CHECK_MAGIC(bm1, EXT2_ET_MAGIC_INODE_BITMAP);
- EXT2_CHECK_MAGIC(bm2, EXT2_ET_MAGIC_INODE_BITMAP);
-
- if ((bm1->start != bm2->start) ||
- (bm1->end != bm2->end) ||
- (memcmp(bm1->bitmap, bm2->bitmap,
- (size_t) (bm1->end - bm1->start)/8)))
- return EXT2_ET_NEQ_INODE_BITMAP;
-
- for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
- if (ext2fs_fast_test_inode_bitmap(bm1, i) !=
- ext2fs_fast_test_inode_bitmap(bm2, i))
- return EXT2_ET_NEQ_INODE_BITMAP;
-
- return 0;
-}
-
errcode_t retval;
char *p, *end;
struct ext2_dir_entry *dirent;
- unsigned int name_len, rec_len, do_swap;
+ unsigned int name_len, rec_len;
retval = io_channel_read_blk(fs->io, block, 1, buf);
if (retval)
return retval;
-#ifdef EXT2FS_ENABLE_SWAPFS
- do_swap = (fs->flags & (EXT2_FLAG_SWAP_BYTES|
- EXT2_FLAG_SWAP_BYTES_READ)) != 0;
-#endif
+
p = (char *) buf;
end = (char *) buf + fs->blocksize;
while (p < end-8) {
dirent = (struct ext2_dir_entry *) p;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (do_swap) {
- dirent->inode = ext2fs_swab32(dirent->inode);
- dirent->rec_len = ext2fs_swab16(dirent->rec_len);
- dirent->name_len = ext2fs_swab16(dirent->name_len);
- }
+#ifdef WORDS_BIGENDIAN
+ dirent->inode = ext2fs_swab32(dirent->inode);
+ dirent->rec_len = ext2fs_swab16(dirent->rec_len);
+ dirent->name_len = ext2fs_swab16(dirent->name_len);
#endif
name_len = dirent->name_len;
#ifdef WORDS_BIGENDIAN
errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
void *inbuf, int flags EXT2FS_ATTR((unused)))
{
-#ifdef EXT2FS_ENABLE_SWAPFS
- int do_swap = 0;
+#ifdef WORDS_BIGENDIAN
errcode_t retval;
char *p, *end;
char *buf = 0;
struct ext2_dir_entry *dirent;
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
- do_swap = 1;
-
-#ifndef WORDS_BIGENDIAN
- if (!do_swap)
- return io_channel_write_blk(fs->io, block, 1, (char *) inbuf);
-#endif
-
retval = ext2fs_get_mem(fs->blocksize, &buf);
if (retval)
return retval;
return (EXT2_ET_DIR_CORRUPTED);
}
p += dirent->rec_len;
- if (do_swap) {
- dirent->inode = ext2fs_swab32(dirent->inode);
- dirent->rec_len = ext2fs_swab16(dirent->rec_len);
- dirent->name_len = ext2fs_swab16(dirent->name_len);
- }
-#ifdef WORDS_BIGENDIAN
+ dirent->inode = ext2fs_swab32(dirent->inode);
+ dirent->rec_len = ext2fs_swab16(dirent->rec_len);
+ dirent->name_len = ext2fs_swab16(dirent->name_len);
+
if (flags & EXT2_DIRBLOCK_V2_STRUCT)
dirent->name_len = ext2fs_swab16(dirent->name_len);
-#endif
}
retval = io_channel_write_blk(fs->io, block, 1, buf);
ext2fs_free_mem(&buf);
/*
* Macro-instructions used to manage group descriptors
*/
+#define EXT2_MIN_DESC_SIZE 32
+#define EXT2_MIN_DESC_SIZE_64BIT 64
+#define EXT2_MAX_DESC_SIZE EXT2_MIN_BLOCK_SIZE
+#define EXT2_DESC_SIZE(s) \
+ ((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? \
+ (s)->s_desc_size : EXT2_MIN_DESC_SIZE)
+
#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
#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) / EXT2_DESC_SIZE(s))
#endif
/*
struct {
__u32 h_i_translator;
} hurd1;
- struct {
- __u32 m_i_reserved1;
- } masix1;
} osd1; /* OS dependent 1 */
__u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
__u32 i_generation; /* File version (for NFS) */
__u16 h_i_gid_high;
__u32 h_i_author;
} hurd2;
- struct {
- __u8 m_i_frag; /* Fragment number */
- __u8 m_i_fsize; /* Fragment size */
- __u16 m_pad1;
- __u32 m_i_reserved2[2];
- } masix2;
} osd2; /* OS dependent 2 */
};
struct {
__u32 h_i_translator;
} hurd1;
- struct {
- __u32 m_i_reserved1;
- } masix1;
} osd1; /* OS dependent 1 */
__u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
__u32 i_generation; /* File version (for NFS) */
__u16 h_i_gid_high;
__u32 h_i_author;
} hurd2;
- struct {
- __u8 m_i_frag; /* Fragment number */
- __u8 m_i_fsize; /* Fragment size */
- __u16 m_pad1;
- __u32 m_i_reserved2[2];
- } masix2;
} osd2; /* OS dependent 2 */
__u16 i_extra_isize;
__u16 i_pad1;
#define inode_uid(inode) ((inode).i_uid | (inode).i_uid_high << 16)
#define inode_gid(inode) ((inode).i_gid | (inode).i_gid_high << 16)
-#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
-#define inode_uid(inode) ((inode).i_uid)
-#define inode_gid(inode) ((inode).i_gid)
-
-#endif /* __masix__ */
#endif /* __GNU__ */
#endif /* defined(__KERNEL__) || defined(__linux__) */
*/
#define EXT2_OS_LINUX 0
#define EXT2_OS_HURD 1
-#define EXT2_OS_MASIX 2
+#define EXT2_OBSO_OS_MASIX 2
#define EXT2_OS_FREEBSD 3
#define EXT2_OS_LITES 4
#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040
#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
#define EXT4_FEATURE_INCOMPAT_MMP 0x0100
+#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
#define EXT2_FEATURE_COMPAT_SUPP 0
typedef struct struct_io_manager *io_manager;
typedef struct struct_io_channel *io_channel;
+typedef struct struct_io_stats *io_stats;
#define CHANNEL_FLAGS_WRITETHROUGH 0x01
void *app_data;
};
+struct struct_io_stats {
+ int num_fields;
+ int reserved;
+ unsigned long long bytes_read;
+ unsigned long long bytes_written;
+};
+
struct struct_io_manager {
errcode_t magic;
const char *name;
int count, const void *data);
errcode_t (*set_option)(io_channel channel, const char *option,
const char *arg);
+ errcode_t (*get_stats)(io_channel channel, io_stats *io_stats);
int reserved[14];
};
#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)
-#define EXT2FS_ENABLE_SWAPFS
-#endif
-
-/*
* Where the master copy of the superblock is located, and how big
* superblocks are supposed to be. We define SUPERBLOCK_SIZE because
* the size of the superblock structure is not necessarily trustworthy
typedef __u32 ext2_ino_t;
typedef __u32 blk_t;
+typedef __u64 blk64_t;
typedef __u32 dgrp_t;
typedef __u32 ext2_off_t;
typedef __s64 e2_blkcnt_t;
typedef struct struct_ext2_filsys *ext2_filsys;
-struct ext2fs_struct_generic_bitmap {
- errcode_t magic;
- ext2_filsys fs;
- __u32 start, end;
- __u32 real_end;
- char * description;
- char * bitmap;
- errcode_t base_error_code;
- __u32 reserved[7];
-};
-
#define EXT2FS_MARK_ERROR 0
#define EXT2FS_UNMARK_ERROR 1
#define EXT2FS_TEST_ERROR 2
/*
* For ext2 compression support
*/
-#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
+#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1)
#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
/*
EXT2_FEATURE_INCOMPAT_COMPRESSION|\
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
EXT2_FEATURE_INCOMPAT_META_BG|\
- EXT3_FEATURE_INCOMPAT_RECOVER)
+ EXT3_FEATURE_INCOMPAT_RECOVER|\
+ EXT4_FEATURE_INCOMPAT_FLEX_BG)
#else
#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
EXT2_FEATURE_INCOMPAT_META_BG|\
- EXT3_FEATURE_INCOMPAT_RECOVER)
+ EXT3_FEATURE_INCOMPAT_RECOVER|\
+ EXT4_FEATURE_INCOMPAT_FLEX_BG)
#endif
#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
ext2_badblocks_list bb_list);
/* bitmaps.c */
+extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
+extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
+extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
+ ext2fs_generic_bitmap *dest);
extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
-extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
- __u32 end,
- __u32 real_end,
- const char *descr,
- ext2fs_generic_bitmap *ret);
extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
const char *descr,
ext2fs_block_bitmap *ret);
extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
+extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
+ ext2fs_inode_bitmap bmap);
+extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
+ ext2fs_block_bitmap bmap);
+extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
+ ext2fs_block_bitmap bm2);
+extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
+ ext2fs_inode_bitmap bm2);
+extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap,
+ ext2_ino_t start, unsigned int num,
+ void *in);
+extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap,
+ ext2_ino_t start, unsigned int num,
+ void *out);
+extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap,
+ blk_t start, unsigned int num,
+ void *in);
+extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap,
+ blk_t start, unsigned int num,
+ void *out);
+
/* block.c */
extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
int *ret_meta_bg);
extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
-/* cmp_bitmaps.c */
-extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
- ext2fs_block_bitmap bm2);
-extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
- ext2fs_inode_bitmap bm2);
-
/* dblist.c */
extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
/* freefs.c */
extern void ext2fs_free(ext2_filsys fs);
-extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
-extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
-extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
extern void ext2fs_free_dblist(ext2_dblist dblist);
extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
extern void ext2fs_u32_list_free(ext2_u32_list bb);
+/* gen_bitmap.c */
+extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
+extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
+ __u32 start, __u32 end,
+ __u32 real_end,
+ const char *descr, char *init_map,
+ ext2fs_generic_bitmap *ret);
+extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
+ __u32 end,
+ __u32 real_end,
+ const char *descr,
+ ext2fs_generic_bitmap *ret);
+extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
+ ext2fs_generic_bitmap *dest);
+extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap);
+extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
+ errcode_t magic,
+ errcode_t neq,
+ ext2_ino_t end,
+ ext2_ino_t *oend);
+extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map);
+extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
+ __u32 new_end,
+ __u32 new_real_end,
+ ext2fs_generic_bitmap bmap);
+extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
+ ext2fs_generic_bitmap bm1,
+ ext2fs_generic_bitmap bm2);
+extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
+ errcode_t magic,
+ __u32 start, __u32 num,
+ void *out);
+extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
+ errcode_t magic,
+ __u32 start, __u32 num,
+ void *in);
+
/* getsize.c */
extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
blk_t *retblocks);
/* res_gdt.c */
extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs);
-/* rs_bitmap.c */
-extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
- __u32 new_real_end,
- ext2fs_generic_bitmap bmap);
-extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
- ext2fs_inode_bitmap bmap);
-extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
- ext2fs_block_bitmap bmap);
-extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
- ext2fs_generic_bitmap *dest);
-
/* swapfs.c */
extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize,
int has_header);
retval = io_channel_read_blk(fs->io, block, 1, buf);
if (retval)
return retval;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->flags & (EXT2_FLAG_SWAP_BYTES|
- EXT2_FLAG_SWAP_BYTES_READ)) != 0)
- ext2fs_swap_ext_attr(buf, buf, fs->blocksize, 1);
+#ifdef WORDS_BIGENDIAN
+ ext2fs_swap_ext_attr(buf, buf, fs->blocksize, 1);
#endif
return 0;
}
char *write_buf;
char *buf = NULL;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) {
- retval = ext2fs_get_mem(fs->blocksize, &buf);
- if (retval)
- return retval;
- write_buf = buf;
- ext2fs_swap_ext_attr(buf, inbuf, fs->blocksize, 1);
- } else
+#ifdef WORDS_BIGENDIAN
+ retval = ext2fs_get_mem(fs->blocksize, &buf);
+ if (retval)
+ return retval;
+ write_buf = buf;
+ ext2fs_swap_ext_attr(buf, inbuf, fs->blocksize, 1);
+#else
+ write_buf = (char *) inbuf;
#endif
- write_buf = (char *) inbuf;
retval = io_channel_write_blk(fs->io, block, 1, write_buf);
if (buf)
ext2fs_free_mem(&buf);
ext2fs_free_mem(&fs);
}
-void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap)
-{
- if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_GENERIC_BITMAP))
- return;
-
- bitmap->magic = 0;
- if (bitmap->description) {
- ext2fs_free_mem(&bitmap->description);
- bitmap->description = 0;
- }
- if (bitmap->bitmap) {
- ext2fs_free_mem(&bitmap->bitmap);
- bitmap->bitmap = 0;
- }
- ext2fs_free_mem(&bitmap);
-}
-
-void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap)
-{
- if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_INODE_BITMAP))
- return;
-
- bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
- ext2fs_free_generic_bitmap(bitmap);
-}
-
-void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap)
-{
- if (!bitmap || (bitmap->magic != EXT2_ET_MAGIC_BLOCK_BITMAP))
- return;
-
- bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
- ext2fs_free_generic_bitmap(bitmap);
-}
-
/*
* Free the inode cache structure
*/
/*
- * gen_bitmap.c --- Generic bitmap routines that used to be inlined.
+ * gen_bitmap.c --- Generic (32-bit) bitmap routines
*
* Copyright (C) 2001 Theodore Ts'o.
*
#include "ext2_fs.h"
#include "ext2fs.h"
+struct ext2fs_struct_generic_bitmap {
+ errcode_t magic;
+ ext2_filsys fs;
+ __u32 start, end;
+ __u32 real_end;
+ char * description;
+ char * bitmap;
+ errcode_t base_error_code;
+ __u32 reserved[7];
+};
+
+/*
+ * Used by previously inlined function, so we have to export this and
+ * not change the function signature
+ */
+void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
+ int code, unsigned long arg)
+{
+#ifndef OMIT_COM_ERR
+ if (bitmap->description)
+ com_err(0, bitmap->base_error_code+code,
+ "#%lu for %s", arg, bitmap->description);
+ else
+ com_err(0, bitmap->base_error_code + code, "#%lu", arg);
+#endif
+}
+
+static errcode_t check_magic(ext2fs_generic_bitmap bitmap)
+{
+ if (!bitmap || !((bitmap->magic == EXT2_ET_MAGIC_GENERIC_BITMAP) ||
+ (bitmap->magic == EXT2_ET_MAGIC_INODE_BITMAP) ||
+ (bitmap->magic == EXT2_ET_MAGIC_BLOCK_BITMAP)))
+ return EXT2_ET_MAGIC_GENERIC_BITMAP;
+ return 0;
+}
+
+errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs,
+ __u32 start, __u32 end, __u32 real_end,
+ const char *descr, char *init_map,
+ ext2fs_generic_bitmap *ret)
+{
+ ext2fs_generic_bitmap bitmap;
+ errcode_t retval;
+ size_t size;
+
+ retval = ext2fs_get_mem(sizeof(struct ext2fs_struct_generic_bitmap),
+ &bitmap);
+ if (retval)
+ return retval;
+
+ bitmap->magic = magic;
+ bitmap->fs = fs;
+ bitmap->start = start;
+ bitmap->end = end;
+ bitmap->real_end = real_end;
+ switch (magic) {
+ case EXT2_ET_MAGIC_INODE_BITMAP:
+ bitmap->base_error_code = EXT2_ET_BAD_INODE_MARK;
+ break;
+ case EXT2_ET_MAGIC_BLOCK_BITMAP:
+ bitmap->base_error_code = EXT2_ET_BAD_BLOCK_MARK;
+ break;
+ default:
+ bitmap->base_error_code = EXT2_ET_BAD_GENERIC_MARK;
+ }
+ if (descr) {
+ retval = ext2fs_get_mem(strlen(descr)+1, &bitmap->description);
+ if (retval) {
+ ext2fs_free_mem(&bitmap);
+ return retval;
+ }
+ strcpy(bitmap->description, descr);
+ } else
+ bitmap->description = 0;
+
+ size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1);
+ retval = ext2fs_get_mem(size, &bitmap->bitmap);
+ if (retval) {
+ ext2fs_free_mem(&bitmap->description);
+ ext2fs_free_mem(&bitmap);
+ return retval;
+ }
+
+ if (init_map)
+ memcpy(bitmap->bitmap, init_map, size);
+ else
+ memset(bitmap->bitmap, 0, size);
+ *ret = bitmap;
+ return 0;
+}
+
+errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
+ __u32 end,
+ __u32 real_end,
+ const char *descr,
+ ext2fs_generic_bitmap *ret)
+{
+ return ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_GENERIC_BITMAP, 0,
+ start, end, real_end, descr, 0, ret);
+}
+
+errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src,
+ ext2fs_generic_bitmap *dest)
+{
+ return (ext2fs_make_generic_bitmap(src->magic, src->fs,
+ src->start, src->end,
+ src->real_end,
+ src->description, src->bitmap,
+ dest));
+}
+
+void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap)
+{
+ if (check_magic(bitmap))
+ return;
+
+ bitmap->magic = 0;
+ if (bitmap->description) {
+ ext2fs_free_mem(&bitmap->description);
+ bitmap->description = 0;
+ }
+ if (bitmap->bitmap) {
+ ext2fs_free_mem(&bitmap->bitmap);
+ bitmap->bitmap = 0;
+ }
+ ext2fs_free_mem(&bitmap);
+}
+
+int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap,
+ blk_t bitno)
+{
+ if ((bitno < bitmap->start) || (bitno > bitmap->end)) {
+ ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno);
+ return 0;
+ }
+ return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap);
+}
+
int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap,
__u32 bitno)
{
}
return ext2fs_clear_bit(bitno - bitmap->start, bitmap->bitmap);
}
+
+__u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap)
+{
+ return bitmap->start;
+}
+
+__u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap)
+{
+ return bitmap->end;
+}
+
+void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap)
+{
+ if (check_magic(bitmap))
+ return;
+
+ memset(bitmap->bitmap, 0,
+ (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1));
+}
+
+errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap,
+ errcode_t magic, errcode_t neq,
+ ext2_ino_t end, ext2_ino_t *oend)
+{
+ EXT2_CHECK_MAGIC(bitmap, magic);
+
+ if (end > bitmap->real_end)
+ return neq;
+ if (oend)
+ *oend = bitmap->end;
+ bitmap->end = end;
+ return 0;
+}
+
+errcode_t ext2fs_resize_generic_bitmap(errcode_t magic,
+ __u32 new_end, __u32 new_real_end,
+ ext2fs_generic_bitmap bmap)
+{
+ errcode_t retval;
+ size_t size, new_size;
+ __u32 bitno;
+
+ if (!bmap || (bmap->magic != magic))
+ return magic;
+
+ /*
+ * If we're expanding the bitmap, make sure all of the new
+ * parts of the bitmap are zero.
+ */
+ if (new_end > bmap->end) {
+ bitno = bmap->real_end;
+ if (bitno > new_end)
+ bitno = new_end;
+ for (; bitno > bmap->end; bitno--)
+ ext2fs_clear_bit(bitno - bmap->start, bmap->bitmap);
+ }
+ if (new_real_end == bmap->real_end) {
+ bmap->end = new_end;
+ return 0;
+ }
+
+ size = ((bmap->real_end - bmap->start) / 8) + 1;
+ new_size = ((new_real_end - bmap->start) / 8) + 1;
+
+ if (size != new_size) {
+ retval = ext2fs_resize_mem(size, new_size, &bmap->bitmap);
+ if (retval)
+ return retval;
+ }
+ if (new_size > size)
+ memset(bmap->bitmap + size, 0, new_size - size);
+
+ bmap->end = new_end;
+ bmap->real_end = new_real_end;
+ return 0;
+}
+
+errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq,
+ ext2fs_generic_bitmap bm1,
+ ext2fs_generic_bitmap bm2)
+{
+ blk_t i;
+
+ if (!bm1 || bm1->magic != magic)
+ return magic;
+ if (!bm2 || bm2->magic != magic)
+ return magic;
+
+ if ((bm1->start != bm2->start) ||
+ (bm1->end != bm2->end) ||
+ (memcmp(bm1->bitmap, bm2->bitmap,
+ (size_t) (bm1->end - bm1->start)/8)))
+ return neq;
+
+ for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
+ if (ext2fs_fast_test_block_bitmap(bm1, i) !=
+ ext2fs_fast_test_block_bitmap(bm2, i))
+ return neq;
+
+ return 0;
+}
+
+void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map)
+{
+ __u32 i, j;
+
+ /* Protect loop from wrap-around if map->real_end is maxed */
+ for (i=map->end+1, j = i - map->start;
+ i <= map->real_end && i > map->end;
+ i++, j++)
+ ext2fs_set_bit(j, map->bitmap);
+}
+
+errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap,
+ errcode_t magic,
+ __u32 start, __u32 num,
+ void *out)
+{
+ if (!bmap || (bmap->magic != magic))
+ return magic;
+
+ if ((start < bmap->start) || (start+num-1 > bmap->real_end))
+ return EXT2_ET_INVALID_ARGUMENT;
+
+ memcpy(out, bmap->bitmap + (start >> 3), (num+7) >> 3);
+ return 0;
+}
+
+errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap,
+ errcode_t magic,
+ __u32 start, __u32 num,
+ void *in)
+{
+ if (!bmap || (bmap->magic != magic))
+ return magic;
+
+ if ((start < bmap->start) || (start+num-1 > bmap->real_end))
+ return EXT2_ET_INVALID_ARGUMENT;
+
+ memcpy(bmap->bitmap + (start >> 3), in, (num+7) >> 3);
+ return 0;
+}
+
+int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap,
+ blk_t block, int num)
+{
+ int i;
+
+ if ((block < bitmap->start) || (block+num-1 > bitmap->real_end)) {
+ ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST,
+ block, bitmap->description);
+ return 0;
+ }
+ for (i=0; i < num; i++) {
+ if (ext2fs_fast_test_block_bitmap(bitmap, block+i))
+ return 0;
+ }
+ return 1;
+}
+
+void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap,
+ blk_t block, int num)
+{
+ int i;
+
+ if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
+ ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
+ bitmap->description);
+ return;
+ }
+ for (i=0; i < num; i++)
+ ext2fs_fast_set_bit(block + i - bitmap->start, bitmap->bitmap);
+}
+
+void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap,
+ blk_t block, int num)
+{
+ int i;
+
+ if ((block < bitmap->start) || (block+num-1 > bitmap->end)) {
+ ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
+ bitmap->description);
+ return;
+ }
+ for (i=0; i < num; i++)
+ ext2fs_fast_clear_bit(block + i - bitmap->start,
+ bitmap->bitmap);
+}
*/
errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags)
{
- char *ptr;
- int c, size;
- char zero_buf[1024];
- ssize_t actual;
- errcode_t retval;
+ ext2fs_generic_bitmap bmap;
+ errcode_t err, retval;
+ ssize_t actual;
+ __u32 itr, cnt, size;
+ int c, total_size;
+ char buf[1024];
if (flags & IMAGER_FLAG_INODEMAP) {
if (!fs->inode_map) {
if (retval)
return retval;
}
- ptr = fs->inode_map->bitmap;
+ bmap = fs->inode_map;
+ err = EXT2_ET_MAGIC_INODE_BITMAP;
+ itr = 1;
+ cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
size = (EXT2_INODES_PER_GROUP(fs->super) / 8);
} else {
if (!fs->block_map) {
if (retval)
return retval;
}
- ptr = fs->block_map->bitmap;
+ bmap = fs->block_map;
+ err = EXT2_ET_MAGIC_BLOCK_BITMAP;
+ itr = fs->super->s_first_data_block;
+ cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count;
size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
}
- size = size * fs->group_desc_count;
-
- actual = write(fd, ptr, size);
- if (actual == -1) {
- retval = errno;
- goto errout;
- }
- if (actual != size) {
- retval = EXT2_ET_SHORT_WRITE;
- goto errout;
+ total_size = size * fs->group_desc_count;
+
+ while (cnt > 0) {
+ size = sizeof(buf);
+ if (size > (cnt >> 3))
+ size = (cnt >> 3);
+
+ retval = ext2fs_get_generic_bitmap_range(bmap,
+ err, itr, size << 3, buf);
+ if (retval)
+ return retval;
+
+ actual = write(fd, buf, size);
+ if (actual == -1)
+ return errno;
+ if (actual != (int) size)
+ return EXT2_ET_SHORT_READ;
+
+ itr += size << 3;
+ cnt -= size << 3;
}
- size = size % fs->blocksize;
- memset(zero_buf, 0, sizeof(zero_buf));
+
+ size = total_size % fs->blocksize;
+ memset(buf, 0, sizeof(buf));
if (size) {
size = fs->blocksize - size;
while (size) {
c = size;
- if (c > (int) sizeof(zero_buf))
- c = sizeof(zero_buf);
- actual = write(fd, zero_buf, c);
- if (actual == -1) {
- retval = errno;
- goto errout;
- }
- if (actual != c) {
- retval = EXT2_ET_SHORT_WRITE;
- goto errout;
- }
+ if (c > (int) sizeof(buf))
+ c = sizeof(buf);
+ actual = write(fd, buf, c);
+ if (actual == -1)
+ return errno;
+ if (actual != c)
+ return EXT2_ET_SHORT_WRITE;
size -= c;
}
}
- retval = 0;
-errout:
- return (retval);
+ return 0;
}
*/
errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags)
{
- char *ptr, *buf = 0;
- int size;
- ssize_t actual;
- errcode_t retval;
+ ext2fs_generic_bitmap bmap;
+ errcode_t err, retval;
+ __u32 itr, cnt;
+ char buf[1024];
+ unsigned int size;
+ ssize_t actual;
if (flags & IMAGER_FLAG_INODEMAP) {
if (!fs->inode_map) {
if (retval)
return retval;
}
- ptr = fs->inode_map->bitmap;
+ bmap = fs->inode_map;
+ err = EXT2_ET_MAGIC_INODE_BITMAP;
+ itr = 1;
+ cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
size = (EXT2_INODES_PER_GROUP(fs->super) / 8);
} else {
if (!fs->block_map) {
if (retval)
return retval;
}
- ptr = fs->block_map->bitmap;
+ bmap = fs->block_map;
+ err = EXT2_ET_MAGIC_BLOCK_BITMAP;
+ itr = fs->super->s_first_data_block;
+ cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count;
size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
}
- size = size * fs->group_desc_count;
- buf = malloc(size);
- if (!buf)
- return ENOMEM;
+ while (cnt > 0) {
+ size = sizeof(buf);
+ if (size > (cnt >> 3))
+ size = (cnt >> 3);
- actual = read(fd, buf, size);
- if (actual == -1) {
- retval = errno;
- goto errout;
- }
- if (actual != size) {
- retval = EXT2_ET_SHORT_WRITE;
- goto errout;
+ actual = read(fd, buf, size);
+ if (actual == -1)
+ return errno;
+ if (actual != (int) size)
+ return EXT2_ET_SHORT_READ;
+
+ retval = ext2fs_set_generic_bitmap_range(bmap,
+ err, itr, size << 3, buf);
+ if (retval)
+ return retval;
+
+ itr += size << 3;
+ cnt -= size << 3;
}
- memcpy(ptr, buf, size);
-
- retval = 0;
-errout:
- if (buf)
- free(buf);
- return (retval);
+ return 0;
}
if (retval)
return retval;
}
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_READ)) {
- block_nr = (blk_t *) buf;
- for (i = 0; i < limit; i++, block_nr++)
- *block_nr = ext2fs_swab32(*block_nr);
- }
+#ifdef WORDS_BIGENDIAN
+ block_nr = (blk_t *) buf;
+ for (i = 0; i < limit; i++, block_nr++)
+ *block_nr = ext2fs_swab32(*block_nr);
#endif
return 0;
}
if (fs->flags & EXT2_FLAG_IMAGE_FILE)
return 0;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & (EXT2_FLAG_SWAP_BYTES | EXT2_FLAG_SWAP_BYTES_WRITE)) {
- block_nr = (blk_t *) buf;
- for (i = 0; i < limit; i++, block_nr++)
- *block_nr = ext2fs_swab32(*block_nr);
- }
+#ifdef WORDS_BIGENDIAN
+ block_nr = (blk_t *) buf;
+ for (i = 0; i < limit; i++, block_nr++)
+ *block_nr = ext2fs_swab32(*block_nr);
#endif
return io_channel_write_blk(fs->io, blk, 1, buf);
}
{
struct ext2_super_block *sb = fs->super;
unsigned long bpg = sb->s_blocks_per_group;
- unsigned int gdpb = fs->blocksize / sizeof(struct ext2_group_desc);
+ unsigned int gdpb = EXT2_DESC_PER_BLOCK(sb);
unsigned long max_blocks = 0xffffffff;
unsigned long rsv_groups;
unsigned int rsv_gdb;
scan->ptr += scan->inode_size - extra_bytes;
scan->bytes_left -= scan->inode_size - extra_bytes;
-#ifdef EXT2FS_ENABLE_SWAPFS
+#ifdef WORDS_BIGENDIAN
memset(inode, 0, bufsize);
- if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
- ext2fs_swap_inode_full(scan->fs,
- (struct ext2_inode_large *) inode,
- (struct ext2_inode_large *) scan->temp_buffer,
- 0, bufsize);
- else
+ ext2fs_swap_inode_full(scan->fs,
+ (struct ext2_inode_large *) inode,
+ (struct ext2_inode_large *) scan->temp_buffer,
+ 0, bufsize);
+#else
+ *inode = *((struct ext2_inode *) scan->temp_buffer);
#endif
- *inode = *((struct ext2_inode *) scan->temp_buffer);
if (scan->scan_flags & EXT2_SF_BAD_EXTRA_BYTES)
retval = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE;
scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES;
} else {
-#ifdef EXT2FS_ENABLE_SWAPFS
+#ifdef WORDS_BIGENDIAN
memset(inode, 0, bufsize);
- if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
- ext2fs_swap_inode_full(scan->fs,
+ ext2fs_swap_inode_full(scan->fs,
(struct ext2_inode_large *) inode,
(struct ext2_inode_large *) scan->ptr,
0, bufsize);
- else
+#else
+ memcpy(inode, scan->ptr, bufsize);
#endif
- memcpy(inode, scan->ptr, bufsize);
scan->ptr += scan->inode_size;
scan->bytes_left -= scan->inode_size;
if (scan->scan_flags & EXT2_SF_BAD_INODE_BLK)
block_nr++;
}
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
- ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) inode,
- (struct ext2_inode_large *) inode,
- 0, bufsize);
+#ifdef WORDS_BIGENDIAN
+ ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) inode,
+ (struct ext2_inode_large *) inode,
+ 0, bufsize);
#endif
/* Update the inode cache */
w_inode = &temp_inode;
memset(w_inode, 0, length);
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
- ext2fs_swap_inode_full(fs, w_inode,
- (struct ext2_inode_large *) inode,
- 1, bufsize);
- else
+#ifdef WORDS_BIGENDIAN
+ ext2fs_swap_inode_full(fs, w_inode,
+ (struct ext2_inode_large *) inode,
+ 1, bufsize);
+#else
+ memcpy(w_inode, inode, bufsize);
#endif
- memcpy(w_inode, inode, bufsize);
-
+
group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super);
offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) *
EXT2_INODE_SIZE(fs->super);
if (!(f = fopen("/proc/swaps", "r")))
return 0;
/* Skip the first line */
- fgets(buf, sizeof(buf), f);
- while (!feof(f)) {
- if (!fgets(buf, sizeof(buf), f))
- break;
+ if (fgets(buf, sizeof(buf), f))
+ while (fgets(buf, sizeof(buf), f)) {
if ((cp = strchr(buf, ' ')) != NULL)
*cp = 0;
if ((cp = strchr(buf, '\t')) != NULL)
(i < fs->super->s_first_meta_bg))
return (group_block + i + 1);
- bg = (fs->blocksize / sizeof (struct ext2_group_desc)) * i;
+ bg = EXT2_DESC_PER_BLOCK(fs->super) * i;
if (ext2fs_bg_has_super(fs, bg))
has_super = 1;
- ret_blk = (fs->super->s_first_data_block + has_super +
- (bg * fs->super->s_blocks_per_group));
+ ret_blk = ext2fs_group_first_block(fs, bg) + has_super;
/*
* If group_block is not the normal value, we're trying to use
* the backup group descriptors and superblock --- so use the
if (fs->orig_super)
memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE);
-#ifdef EXT2FS_ENABLE_SWAPFS
- if ((fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES)) {
- fs->flags |= EXT2_FLAG_SWAP_BYTES;
-
- ext2fs_swap_super(fs->super);
+#ifdef WORDS_BIGENDIAN
+ fs->flags |= EXT2_FLAG_SWAP_BYTES;
+ ext2fs_swap_super(fs->super);
+#else
+ if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
+ retval = EXT2_ET_UNIMPLEMENTED;
+ goto cleanup;
}
#endif
if (!group_block)
group_block = fs->super->s_first_data_block;
dest = (char *) fs->group_desc;
- groups_per_block = fs->blocksize / sizeof(struct ext2_group_desc);
+ groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
for (i=0 ; i < fs->desc_blocks; i++) {
blk = ext2fs_descriptor_block_loc(fs, group_block, i);
retval = io_channel_read_blk(fs->io, blk, 1, dest);
if (retval)
goto cleanup;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
- gdp = (struct ext2_group_desc *) dest;
- for (j=0; j < groups_per_block; j++)
- ext2fs_swap_group_desc(gdp++);
- }
+#ifdef WORDS_BIGENDIAN
+ gdp = (struct ext2_group_desc *) dest;
+ for (j=0; j < groups_per_block; j++)
+ ext2fs_swap_group_desc(gdp++);
#endif
dest += fs->blocksize;
}
+++ /dev/null
-/*
- * rs_bitmap.c --- routine for changing the size of a bitmap
- *
- * Copyright (C) 1996, 1997 Theodore Ts'o.
- *
- * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
- * %End-Header%
- */
-
-#include <stdio.h>
-#include <string.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <fcntl.h>
-#include <time.h>
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
-#include "ext2_fs.h"
-#include "ext2fs.h"
-
-errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, __u32 new_real_end,
- ext2fs_generic_bitmap bmap)
-{
- errcode_t retval;
- size_t size, new_size;
- __u32 bitno;
-
- if (!bmap)
- return EXT2_ET_INVALID_ARGUMENT;
-
- EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_GENERIC_BITMAP);
-
- /*
- * If we're expanding the bitmap, make sure all of the new
- * parts of the bitmap are zero.
- */
- if (new_end > bmap->end) {
- bitno = bmap->real_end;
- if (bitno > new_end)
- bitno = new_end;
- for (; bitno > bmap->end; bitno--)
- ext2fs_clear_bit(bitno - bmap->start, bmap->bitmap);
- }
- if (new_real_end == bmap->real_end) {
- bmap->end = new_end;
- return 0;
- }
-
- size = ((bmap->real_end - bmap->start) / 8) + 1;
- new_size = ((new_real_end - bmap->start) / 8) + 1;
-
- if (size != new_size) {
- retval = ext2fs_resize_mem(size, new_size, &bmap->bitmap);
- if (retval)
- return retval;
- }
- if (new_size > size)
- memset(bmap->bitmap + size, 0, new_size - size);
-
- bmap->end = new_end;
- bmap->real_end = new_real_end;
- return 0;
-}
-
-errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
- ext2fs_inode_bitmap bmap)
-{
- errcode_t retval;
-
- if (!bmap)
- return EXT2_ET_INVALID_ARGUMENT;
-
- EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_INODE_BITMAP);
-
- bmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
- retval = ext2fs_resize_generic_bitmap(new_end, new_real_end,
- bmap);
- bmap->magic = EXT2_ET_MAGIC_INODE_BITMAP;
- return retval;
-}
-
-errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
- ext2fs_block_bitmap bmap)
-{
- errcode_t retval;
-
- if (!bmap)
- return EXT2_ET_INVALID_ARGUMENT;
-
- EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_BLOCK_BITMAP);
-
- bmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
- retval = ext2fs_resize_generic_bitmap(new_end, new_real_end,
- bmap);
- bmap->magic = EXT2_ET_MAGIC_BLOCK_BITMAP;
- return retval;
-}
-
#include "ext2fs.h"
#include "e2image.h"
-#if defined(__powerpc__) && defined(EXT2FS_ENABLE_SWAPFS)
-/*
- * 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
- * of each word. Thus a bitmap with only bit 0 set would be, as
- * a string of bytes, 00 00 00 01 00 ...
- * To cope with this, we byte-reverse each word of a bitmap if
- * we have a big-endian filesystem, that is, if we are *not*
- * byte-swapping other word-sized numbers.
- */
-#define EXT2_BIG_ENDIAN_BITMAPS
-#endif
-
-#ifdef EXT2_BIG_ENDIAN_BITMAPS
-static void ext2fs_swap_bitmap(ext2_filsys fs, char *bitmap, int nbytes)
-{
- __u32 *p = (__u32 *) bitmap;
- int n;
-
- for (n = nbytes / sizeof(__u32); n > 0; --n, ++p)
- *p = ext2fs_swab32(*p);
-}
-#endif
-
static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
{
dgrp_t i;
int block_nbytes, inode_nbytes;
unsigned int nbits;
errcode_t retval;
- char *block_bitmap, *inode_bitmap;
char *block_buf, *inode_buf;
int lazy_flag = 0;
blk_t blk;
+ blk_t blk_itr = fs->super->s_first_data_block;
+ ext2_ino_t ino_itr = 1;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
EXT2_FEATURE_COMPAT_LAZY_BG))
lazy_flag = 1;
inode_nbytes = block_nbytes = 0;
- block_bitmap = inode_bitmap = 0;
if (do_block) {
- block_bitmap = fs->block_map->bitmap;
block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
retval = ext2fs_get_mem(fs->blocksize, &block_buf);
if (retval)
memset(block_buf, 0xff, fs->blocksize);
}
if (do_inode) {
- inode_bitmap = fs->inode_map->bitmap;
inode_nbytes = (size_t)
((EXT2_INODES_PER_GROUP(fs->super)+7) / 8);
retval = ext2fs_get_mem(fs->blocksize, &inode_buf);
}
for (i = 0; i < fs->group_desc_count; i++) {
- if (!block_bitmap || !do_block)
+ if (!do_block)
goto skip_block_bitmap;
if (lazy_flag && fs->group_desc[i].bg_flags &
EXT2_BG_BLOCK_UNINIT)
goto skip_this_block_bitmap;
- memcpy(block_buf, block_bitmap, block_nbytes);
+ retval = ext2fs_get_block_bitmap_range(fs->block_map,
+ blk_itr, block_nbytes << 3, block_buf);
+ if (retval)
+ return retval;
+
if (i == fs->group_desc_count - 1) {
/* Force bitmap padding for the last group */
nbits = ((fs->super->s_blocks_count
}
blk = fs->group_desc[i].bg_block_bitmap;
if (blk) {
-#ifdef EXT2_BIG_ENDIAN_BITMAPS
- if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)))
- ext2fs_swap_bitmap(fs, block_buf,
- block_nbytes);
-#endif
retval = io_channel_write_blk(fs->io, blk, 1,
block_buf);
if (retval)
return EXT2_ET_BLOCK_BITMAP_WRITE;
}
skip_this_block_bitmap:
- block_bitmap += block_nbytes;
+ blk_itr += block_nbytes << 3;
skip_block_bitmap:
- if (!inode_bitmap || !do_inode)
+ if (!do_inode)
continue;
if (lazy_flag && fs->group_desc[i].bg_flags &
EXT2_BG_INODE_UNINIT)
goto skip_this_inode_bitmap;
- memcpy(inode_buf, inode_bitmap, inode_nbytes);
+ retval = ext2fs_get_inode_bitmap_range(fs->inode_map,
+ ino_itr, inode_nbytes << 3, inode_buf);
+ if (retval)
+ return retval;
+
blk = fs->group_desc[i].bg_inode_bitmap;
if (blk) {
-#ifdef EXT2_BIG_ENDIAN_BITMAPS
- if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)))
- ext2fs_swap_bitmap(fs, inode_buf,
- inode_nbytes);
-#endif
retval = io_channel_write_blk(fs->io, blk, 1,
inode_buf);
if (retval)
return EXT2_ET_INODE_BITMAP_WRITE;
}
skip_this_inode_bitmap:
- inode_bitmap += inode_nbytes;
+ ino_itr += inode_nbytes << 3;
}
if (do_block) {
char *block_bitmap = 0, *inode_bitmap = 0;
char *buf;
errcode_t retval;
- int block_nbytes = (int) EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
- int inode_nbytes = (int) EXT2_INODES_PER_GROUP(fs->super) / 8;
+ unsigned int block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
+ unsigned inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;
int lazy_flag = 0;
+ int do_image = fs->flags & EXT2_FLAG_IMAGE_FILE;
+ unsigned int cnt;
blk_t blk;
+ blk_t blk_itr = fs->super->s_first_data_block;
+ blk_t blk_cnt;
+ ext2_ino_t ino_itr = 1;
+ ext2_ino_t ino_cnt;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map);
if (retval)
goto cleanup;
- block_bitmap = fs->block_map->bitmap;
- }
+ retval = ext2fs_get_mem(do_image ? fs->blocksize :
+ block_nbytes, &block_bitmap);
+ if (retval)
+ goto cleanup;
+ } else
+ block_nbytes = 0;
if (do_inode) {
if (fs->inode_map)
ext2fs_free_inode_bitmap(fs->inode_map);
retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map);
if (retval)
goto cleanup;
- inode_bitmap = fs->inode_map->bitmap;
- }
+ retval = ext2fs_get_mem(do_image ? fs->blocksize :
+ inode_nbytes, &inode_bitmap);
+ if (retval)
+ goto cleanup;
+ } else
+ inode_nbytes = 0;
ext2fs_free_mem(&buf);
if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
- if (inode_bitmap) {
- blk = (fs->image_header->offset_inodemap /
- fs->blocksize);
- retval = io_channel_read_blk(fs->image_io, blk,
- -(inode_nbytes * fs->group_desc_count),
- inode_bitmap);
+ blk = (fs->image_header->offset_inodemap / fs->blocksize);
+ ino_cnt = fs->super->s_inodes_count;
+ while (inode_nbytes > 0) {
+ retval = io_channel_read_blk(fs->image_io, blk++,
+ 1, inode_bitmap);
if (retval)
goto cleanup;
+ cnt = fs->blocksize << 3;
+ if (cnt > ino_cnt)
+ cnt = ino_cnt;
+ retval = ext2fs_set_inode_bitmap_range(fs->inode_map,
+ ino_itr, cnt, inode_bitmap);
+ if (retval)
+ goto cleanup;
+ ino_itr += fs->blocksize << 3;
+ ino_cnt -= fs->blocksize << 3;
+ inode_nbytes -= fs->blocksize;
}
- if (block_bitmap) {
- blk = (fs->image_header->offset_blockmap /
- fs->blocksize);
- retval = io_channel_read_blk(fs->image_io, blk,
- -(block_nbytes * fs->group_desc_count),
- block_bitmap);
+ blk = (fs->image_header->offset_blockmap /
+ fs->blocksize);
+ blk_cnt = EXT2_BLOCKS_PER_GROUP(fs->super) *
+ fs->group_desc_count;
+ while (block_nbytes > 0) {
+ retval = io_channel_read_blk(fs->image_io, blk++,
+ 1, block_bitmap);
if (retval)
goto cleanup;
+ cnt = fs->blocksize << 3;
+ if (cnt > blk_cnt)
+ cnt = blk_cnt;
+ retval = ext2fs_set_block_bitmap_range(fs->block_map,
+ blk_itr, cnt, block_bitmap);
+ if (retval)
+ goto cleanup;
+ blk_itr += fs->blocksize << 3;
+ blk_cnt -= fs->blocksize << 3;
+ block_nbytes -= fs->blocksize;
}
- return 0;
+ goto success_cleanup;
}
for (i = 0; i < fs->group_desc_count; i++) {
retval = EXT2_ET_BLOCK_BITMAP_READ;
goto cleanup;
}
-#ifdef EXT2_BIG_ENDIAN_BITMAPS
- if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_READ)))
- ext2fs_swap_bitmap(fs, block_bitmap, block_nbytes);
-#endif
} else
memset(block_bitmap, 0xff, block_nbytes);
- block_bitmap += block_nbytes;
+ cnt = block_nbytes << 3;
+ retval = ext2fs_set_block_bitmap_range(fs->block_map,
+ blk_itr, cnt, block_bitmap);
+ if (retval)
+ goto cleanup;
+ blk_itr += block_nbytes << 3;
}
if (inode_bitmap) {
blk = fs->group_desc[i].bg_inode_bitmap;
retval = EXT2_ET_INODE_BITMAP_READ;
goto cleanup;
}
-#ifdef EXT2_BIG_ENDIAN_BITMAPS
- if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
- (fs->flags & EXT2_FLAG_SWAP_BYTES_READ)))
- ext2fs_swap_bitmap(fs, inode_bitmap, inode_nbytes);
-#endif
} else
memset(inode_bitmap, 0xff, inode_nbytes);
- inode_bitmap += inode_nbytes;
+ cnt = inode_nbytes << 3;
+ retval = ext2fs_set_inode_bitmap_range(fs->inode_map,
+ ino_itr, cnt, inode_bitmap);
+ if (retval)
+ goto cleanup;
+ ino_itr += inode_nbytes << 3;
}
}
+success_cleanup:
+ if (inode_bitmap)
+ ext2fs_free_mem(&inode_bitmap);
+ if (block_bitmap)
+ ext2fs_free_mem(&block_bitmap);
return 0;
cleanup:
ext2fs_free_mem(&fs->inode_map);
fs->inode_map = 0;
}
+ if (inode_bitmap)
+ ext2fs_free_mem(&inode_bitmap);
+ if (block_bitmap)
+ ext2fs_free_mem(&block_bitmap);
if (buf)
ext2fs_free_mem(&buf);
return retval;
#include "ext2fs.h"
#include <ext2fs/ext2_ext_attr.h>
-#ifdef EXT2FS_ENABLE_SWAPFS
+#ifdef WORDS_BIGENDIAN
void ext2fs_swap_super(struct ext2_super_block * sb)
{
int i;
t->osd2.hurd2.h_i_author =
ext2fs_swab32 (f->osd2.hurd2.h_i_author);
break;
- case EXT2_OS_MASIX:
- t->osd1.masix1.m_i_reserved1 =
- ext2fs_swab32(f->osd1.masix1.m_i_reserved1);
- t->osd2.masix2.m_i_frag = f->osd2.masix2.m_i_frag;
- t->osd2.masix2.m_i_fsize = f->osd2.masix2.m_i_fsize;
- t->osd2.masix2.m_pad1 = ext2fs_swab16(f->osd2.masix2.m_pad1);
- t->osd2.masix2.m_i_reserved2[0] =
- ext2fs_swab32(f->osd2.masix2.m_i_reserved2[0]);
- t->osd2.masix2.m_i_reserved2[1] =
- ext2fs_swab32(f->osd2.masix2.m_i_reserved2[1]);
+ default:
break;
}
int count, const void *buf);
static errcode_t test_set_option(io_channel channel, const char *option,
const char *arg);
+static errcode_t test_get_stats(io_channel channel, io_stats *stats);
+
static struct struct_io_manager struct_test_manager = {
EXT2_ET_MAGIC_IO_MANAGER,
test_write_blk,
test_flush,
test_write_byte,
- test_set_option
+ test_set_option,
+ test_get_stats,
};
io_manager test_io_manager = &struct_test_manager;
}
return retval;
}
+
+static errcode_t test_get_stats(io_channel channel, io_stats *stats)
+{
+ struct test_private_data *data;
+ errcode_t retval = 0;
+
+ EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+ data = (struct test_private_data *) channel->private_data;
+ EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
+
+ if (data->real && data->real->manager->get_stats) {
+ retval = (data->real->manager->get_stats)(data->real, stats);
+ }
+ return retval;
+}
int access_time;
ext2_loff_t offset;
struct unix_cache cache[CACHE_SIZE];
+ struct struct_io_stats io_stats;
};
static errcode_t unix_open(const char *name, int flags, io_channel *channel);
int size, const void *data);
static errcode_t unix_set_option(io_channel channel, const char *option,
const char *arg);
-
+static errcode_t unix_get_stats(io_channel channel, io_stats *stats)
+;
static void reuse_cache(io_channel channel, struct unix_private_data *data,
struct unix_cache *cache, unsigned long block);
#else
unix_write_byte,
#endif
- unix_set_option
+ unix_set_option,
+ unix_get_stats,
};
io_manager unix_io_manager = &struct_unix_manager;
+static errcode_t unix_get_stats(io_channel channel, io_stats *stats)
+{
+ errcode_t retval = 0;
+
+ struct unix_private_data *data;
+
+ EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+ data = (struct unix_private_data *) channel->private_data;
+ EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL);
+
+ if (stats)
+ *stats = &data->io_stats;
+
+ return retval;
+}
+
/*
* Here are the raw I/O functions
*/
int actual = 0;
size = (count < 0) ? -count : count * channel->block_size;
+ data->io_stats.bytes_read += size;
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
char sector[BLOCKALIGN];
size = (count < 0) ? -count : count * channel->block_size;
+ data->io_stats.bytes_read += size;
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
#ifdef DEBUG
printf("count=%d, size=%d, block=%lu, blk_size=%d, location=%llx\n",
else
size = count * channel->block_size;
}
+ data->io_stats.bytes_written += size;
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
memset(data, 0, sizeof(struct unix_private_data));
data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL;
+ data->io_stats.num_fields = 2;
if ((retval = alloc_cache(io, data)))
goto cleanup;
Version: @E2FSPROGS_VERSION@
Requires: com_err
Cflags: -I${includedir}
-Libs: -L${libdir} -lss @DLOPEN_LIB@
+Libs: -L${libdir} -lss
+Libs.private: @DLOPEN_LIB@
default_profile.c: $(srcdir)/mke2fs.conf $(srcdir)/profile-to-c.awk
@echo " PROFILE_TO_C mke2fs.conf"
- $(AWK) -f $(srcdir)/profile-to-c.awk < $(srcdir)/mke2fs.conf \
+ @$(AWK) -f $(srcdir)/profile-to-c.awk < $(srcdir)/mke2fs.conf \
> default_profile.c
profile.o:
@echo " CC $<"
static int force = 0; /* force check of mounted device */
static int t_flag = 0; /* number of test patterns */
static int t_max = 0; /* allocated test patterns */
-static unsigned long *t_patts = NULL; /* test patterns */
+static unsigned int *t_patts = NULL; /* test patterns */
static int current_O_DIRECT = 0; /* Current status of O_DIRECT flag */
static int exclusive_ok = 0;
#define T_INC 32
-int sys_page_size = 4096;
+unsigned int sys_page_size = 4096;
static void usage(void)
{
exit(1);
}
-static unsigned long currently_testing = 0;
-static unsigned long num_blocks = 0;
+static blk_t currently_testing = 0;
+static blk_t num_blocks = 0;
static ext2_badblocks_list bb_list = NULL;
static FILE *out;
static blk_t next_bad = 0;
* This routine reports a new bad block. If the bad block has already
* been seen before, then it returns 0; otherwise it returns 1.
*/
-static int bb_output (unsigned long bad)
+static int bb_output (blk_t bad)
{
errcode_t errcode;
if (ext2fs_badblocks_list_test(bb_list, bad))
return 0;
- fprintf(out, "%lu\n", bad);
+ fprintf(out, "%lu\n", (unsigned long) bad);
fflush(out);
errcode = ext2fs_badblocks_list_add (bb_list, bad);
static void print_status(void)
{
- fprintf(stderr, "%15ld/%15ld", currently_testing, num_blocks);
+ fprintf(stderr, "%15lu/%15lu", (unsigned long) currently_testing,
+ (unsigned long) num_blocks);
fputs("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", stderr);
fflush (stderr);
}
}
static void set_o_direct(int dev, unsigned char *buffer, size_t size,
- unsigned long current_block)
+ blk_t current_block)
{
#ifdef O_DIRECT
int new_flag = O_DIRECT;
}
-static void pattern_fill(unsigned char *buffer, unsigned long pattern,
+static void pattern_fill(unsigned char *buffer, unsigned int pattern,
size_t n)
{
unsigned int i, nb;
unsigned char bpattern[sizeof(pattern)], *ptr;
- if (pattern == (unsigned long) ~0) {
+ if (pattern == (unsigned int) ~0) {
for (ptr = buffer; ptr < buffer + n; ptr++) {
(*ptr) = random() % (1 << (8 * sizeof(char)));
}
* Perform a read of a sequence of blocks; return the number of blocks
* successfully sequentially read.
*/
-static long do_read (int dev, unsigned char * buffer, int try, int block_size,
- unsigned long current_block)
+static int do_read (int dev, unsigned char * buffer, int try, int block_size,
+ blk_t current_block)
{
long got;
* Perform a write of a sequence of blocks; return the number of blocks
* successfully sequentially written.
*/
-static long do_write (int dev, unsigned char * buffer, int try, int block_size,
- unsigned long current_block)
+static int do_write(int dev, unsigned char * buffer, int try, int block_size,
+ unsigned long current_block)
{
long got;
com_err(program_name, retval, _("during ext2fs_sync_device"));
}
-static unsigned int test_ro (int dev, unsigned long last_block,
- int block_size, unsigned long from_count,
- unsigned long blocks_at_once)
+static unsigned int test_ro (int dev, blk_t last_block,
+ int block_size, blk_t from_count,
+ unsigned int blocks_at_once)
{
unsigned char * blkbuf;
int try;
- long got;
+ int got;
unsigned int bb_count = 0;
errcode_t errcode;
exit (1);
}
if (v_flag) {
- fprintf (stderr, _("Checking blocks %lu to %lu\n"), from_count,
- last_block - 1);
+ fprintf (stderr, _("Checking blocks %lu to %lu\n"),
+ (unsigned long) from_count,
+ (unsigned long) last_block - 1);
}
if (t_flag) {
fputs(_("Checking for bad blocks in read-only mode\n"), stderr);
if (got == try) {
try = blocks_at_once;
/* recover page-aligned offset for O_DIRECT */
- if ( blocks_at_once >= (unsigned long) (sys_page_size >> 9)
+ if ( (blocks_at_once >= sys_page_size >> 9)
&& (currently_testing % (sys_page_size >> 9)!= 0))
try -= (sys_page_size >> 9)
- (currently_testing
return bb_count;
}
-static unsigned int test_rw (int dev, unsigned long last_block,
- int block_size, unsigned long from_count,
- unsigned long blocks_at_once)
+static unsigned int test_rw (int dev, blk_t last_block,
+ int block_size, blk_t from_count,
+ unsigned int blocks_at_once)
{
unsigned char *buffer, *read_buffer;
- const unsigned long patterns[] = {0xaa, 0x55, 0xff, 0x00};
- const unsigned long *pattern;
+ const unsigned int patterns[] = {0xaa, 0x55, 0xff, 0x00};
+ const unsigned int *pattern;
int i, try, got, nr_pattern, pat_idx;
unsigned int bb_count = 0;
fputs(_("Checking for bad blocks in read-write mode\n"),
stderr);
fprintf(stderr, _("From block %lu to %lu\n"),
- from_count, last_block);
+ (unsigned long) from_count,
+ (unsigned long) last_block);
}
if (t_flag) {
pattern = t_patts;
if (got == try) {
try = blocks_at_once;
/* recover page-aligned offset for O_DIRECT */
- if ( blocks_at_once >= (unsigned long) (sys_page_size >> 9)
+ if ( (blocks_at_once >= sys_page_size >> 9)
&& (currently_testing %
(sys_page_size >> 9)!= 0))
try -= (sys_page_size >> 9)
}
currently_testing += got;
/* recover page-aligned offset for O_DIRECT */
- if ( blocks_at_once >= (unsigned long) (sys_page_size >> 9)
+ if ( (blocks_at_once >= sys_page_size >> 9)
&& (currently_testing % (sys_page_size >> 9)!= 0))
try = blocks_at_once - (sys_page_size >> 9)
- (currently_testing
int num;
};
-static unsigned int test_nd (int dev, unsigned long last_block,
- int block_size, unsigned long from_count,
- unsigned long blocks_at_once)
+static unsigned int test_nd (int dev, blk_t last_block,
+ int block_size, blk_t from_count,
+ unsigned int blocks_at_once)
{
unsigned char *blkbuf, *save_ptr, *test_ptr, *read_ptr;
unsigned char *test_base, *save_base, *read_base;
int try, i;
- const unsigned long patterns[] = { ~0 };
- const unsigned long *pattern;
+ const unsigned int patterns[] = { ~0 };
+ const unsigned int *pattern;
int nr_pattern, pat_idx;
- long got, used2, written, save_currently_testing;
+ int got, used2, written;
+ blk_t save_currently_testing;
struct saved_blk_record *test_record;
/* This is static to prevent being clobbered by the longjmp */
static int num_saved;
flush_bufs();
if (v_flag) {
fputs(_("Checking for bad blocks in non-destructive read-write mode\n"), stderr);
- fprintf (stderr, _("From block %lu to %lu\n"), from_count, last_block);
+ fprintf (stderr, _("From block %lu to %lu\n"),
+ (unsigned long) from_count, (unsigned long) last_block);
}
if (s_flag || v_flag > 1) {
fputs(_("Checking for bad blocks (non-destructive read-write test)\n"), stderr);
if (written != got)
com_err (program_name, errno,
_("during test data write, block %lu"),
- currently_testing + written);
+ (unsigned long) currently_testing +
+ written);
buf_used += got;
save_ptr += got * block_size;
}
+/*
+ * This function will convert a string to an unsigned long, printing
+ * an error message if it fails, and returning success or failure in err.
+ */
+static unsigned int parse_uint(const char *str, const char *descr)
+{
+ char *tmp;
+ unsigned long ret;
+
+ ret = strtoul(str, &tmp, 0);
+ if (*tmp || errno || (ret > UINT_MAX) ||
+ (ret == ULONG_MAX && errno == ERANGE)) {
+ com_err (program_name, 0, _("invalid %s - %s"), descr, str);
+ exit (1);
+ }
+ return ret;
+}
int main (int argc, char ** argv)
{
int c;
- char * tmp;
char * device_name;
char * host_device_name = NULL;
char * input_file = NULL;
char * output_file = NULL;
FILE * in = NULL;
int block_size = 1024;
- unsigned long blocks_at_once = 64;
+ unsigned int blocks_at_once = 64;
blk_t last_block, from_count;
int num_passes = 0;
int passes_clean = 0;
int dev;
errcode_t errcode;
- unsigned long pattern;
- unsigned int (*test_func)(int, unsigned long,
- int, unsigned long,
- unsigned long);
+ unsigned int pattern;
+ unsigned int (*test_func)(int, blk_t,
+ int, blk_t,
+ unsigned int);
int open_flag = 0;
long sysval;
while ((c = getopt (argc, argv, "b:fi:o:svwnc:p:h:t:X")) != EOF) {
switch (c) {
case 'b':
- block_size = strtoul (optarg, &tmp, 0);
- if (*tmp || block_size > 4096) {
+ block_size = parse_uint(optarg, "block size");
+ if (block_size > 4096) {
com_err (program_name, 0,
_("bad block size - %s"), optarg);
exit (1);
w_flag = 2;
break;
case 'c':
- blocks_at_once = strtoul (optarg, &tmp, 0);
- if (*tmp) {
- com_err (program_name, 0,
- "bad simultaneous block count - %s", optarg);
- exit (1);
- }
+ blocks_at_once = parse_uint(optarg, "blocks at once");
break;
case 'p':
- num_passes = strtoul (optarg, &tmp, 0);
- if (*tmp) {
- com_err (program_name, 0,
- "bad number of clean passes - %s", optarg);
- exit (1);
- }
+ num_passes = parse_uint(optarg,
+ "number of clean passes");
break;
case 'h':
host_device_name = optarg;
break;
case 't':
if (t_flag + 1 > t_max) {
- unsigned long *t_patts_new;
+ unsigned int *t_patts_new;
t_patts_new = realloc(t_patts, t_max + T_INC);
if (!t_patts_new) {
if (!strcmp(optarg, "r") || !strcmp(optarg,"random")) {
t_patts[t_flag++] = ~0;
} else {
- pattern = strtoul(optarg, &tmp, 0);
- if (*tmp) {
- com_err(program_name, 0,
- _("invalid test_pattern: %s\n"),
- optarg);
- exit(1);
- }
- if (pattern == (unsigned long) ~0)
+ pattern = parse_uint(optarg, "test pattern");
+ if (pattern == (unsigned int) ~0)
pattern = 0xffff;
t_patts[t_flag++] = pattern;
}
"in read-only mode"));
exit(1);
}
- if (t_patts && (t_patts[0] == (unsigned long) ~0)) {
+ if (t_patts && (t_patts[0] == (unsigned int) ~0)) {
com_err(program_name, 0,
_("Random test_pattern is not allowed "
"in read-only mode"));
}
} else {
errno = 0;
- last_block = strtoul (argv[optind], &tmp, 0);
+ last_block = parse_uint(argv[optind], "last block");
printf("last_block = %d (%s)\n", last_block, argv[optind]);
- if (*tmp || errno ||
- (last_block == ULONG_MAX && errno == ERANGE)) {
- com_err (program_name, 0, _("invalid blocks count - %s"),
- argv[optind]);
- exit (1);
- }
last_block++;
optind++;
}
if (optind <= argc-1) {
errno = 0;
- from_count = strtoul (argv[optind], &tmp, 0);
+ from_count = parse_uint(argv[optind], "start block");
printf("from_count = %d\n", from_count);
- if (*tmp || errno ||
- (from_count == ULONG_MAX && errno == ERANGE)) {
- com_err (program_name, 0, _("invalid starting block - %s"),
- argv[optind]);
- exit (1);
- }
} else from_count = 0;
if (from_count >= last_block) {
- com_err (program_name, 0, _("invalid starting block (%d): must be less than %lu"),
+ com_err (program_name, 0, _("invalid starting block (%lu): must be less than %lu"),
(unsigned long) from_count, (unsigned long) last_block);
exit (1);
}
.SH SYNOPSIS
.B chattr
[
-.B \-RV
+.B \-RVf
]
[
.B \-v
.TP
.B \-R
Recursively change attributes of directories and their contents.
-Symbolic links encountered during recursive directory traversals are
-ignored.
.TP
.B \-V
Be verbose with chattr's output and print the program version.
.TP
+.B \-f
+Suppress most error messages.
+.TP
.BI \-v " version"
Set the file's version/generation number.
.SH ATTRIBUTES
static int recursive;
static int verbose;
+static int silent;
static unsigned long af;
static unsigned long rf;
static void usage(void)
{
- fprintf(stderr,
- _("Usage: %s [-RV] [-+=AacDdijsSu] [-v version] files...\n"),
+ fprintf(stderr,
+ _("Usage: %s [-RVf] [-+=AacDdijsSu] [-v version] files...\n"),
program_name);
exit(1);
}
verbose = 1;
continue;
}
+ if (*p == 'f') {
+ silent = 1;
+ continue;
+ }
if (*p == 'v') {
(*i)++;
if (*i >= argc)
version = strtol (argv[*i], &tmp, 0);
if (*tmp) {
com_err (program_name, 0,
- _("bad version - %s\n"),
+ _("bad version - %s\n"),
argv[*i]);
usage ();
}
static int chattr_dir_proc (const char *, struct dirent *, void *);
-static void change_attributes (const char * name)
+static int change_attributes (const char * name, int cmdline)
{
unsigned long flags;
STRUCT_STAT st;
if (LSTAT (name, &st) == -1) {
- com_err (program_name, errno, _("while trying to stat %s"),
- name);
- return;
+ if (!silent)
+ com_err (program_name, errno,
+ _("while trying to stat %s"), name);
+ return -1;
}
- if (S_ISLNK(st.st_mode) && recursive)
- return;
-
- /* Don't try to open device files, fifos etc. We probably
- ought to display an error if the file was explicitly given
- on the command line (whether or not recursive was
- requested). */
- if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) &&
- !S_ISDIR(st.st_mode))
- return;
if (set) {
if (verbose) {
if (fsetflags (name, sf) == -1)
perror (name);
} else {
- if (fgetflags (name, &flags) == -1)
- com_err (program_name, errno,
- _("while reading flags on %s"), name);
- else {
+ if (fgetflags (name, &flags) == -1) {
+ if (!silent)
+ com_err (program_name, errno,
+ _("while reading flags on %s"), name);
+ return -1;
+ } else {
if (rem)
flags &= ~rf;
if (add)
}
if (!S_ISDIR(st.st_mode))
flags &= ~EXT2_DIRSYNC_FL;
- if (fsetflags (name, flags) == -1)
- com_err (program_name, errno,
- _("while setting flags on %s"), name);
+ if (fsetflags (name, flags) == -1) {
+ if (!silent)
+ com_err(program_name, errno,
+ _("while setting flags on %s"),
+ name);
+ return -1;
+ }
}
}
if (set_version) {
if (verbose)
printf (_("Version of %s set as %lu\n"), name, version);
- if (fsetversion (name, version) == -1)
- com_err (program_name, errno,
- _("while setting version on %s"), name);
+ if (fsetversion (name, version) == -1) {
+ if (!silent)
+ com_err (program_name, errno,
+ _("while setting version on %s"),
+ name);
+ return -1;
+ }
}
if (S_ISDIR(st.st_mode) && recursive)
- iterate_on_dir (name, chattr_dir_proc, NULL);
+ return iterate_on_dir (name, chattr_dir_proc, NULL);
+ return 0;
}
static int chattr_dir_proc (const char * dir_name, struct dirent * de,
void * private EXT2FS_ATTR((unused)))
{
+ int ret = 0;
+
if (strcmp (de->d_name, ".") && strcmp (de->d_name, "..")) {
char *path;
if (!path) {
fprintf(stderr, _("Couldn't allocate path variable "
"in chattr_dir_proc"));
- exit(1);
+ return -1;
}
- sprintf (path, "%s/%s", dir_name, de->d_name);
- change_attributes (path);
+ sprintf(path, "%s/%s", dir_name, de->d_name);
+ ret = change_attributes(path, 0);
free(path);
}
- return 0;
+ return ret;
}
int main (int argc, char ** argv)
{
int i, j;
int end_arg = 0;
+ int err, retval = 0;
#ifdef ENABLE_NLS
setlocale(LC_MESSAGES, "");
if (verbose)
fprintf (stderr, "chattr %s (%s)\n",
E2FSPROGS_VERSION, E2FSPROGS_DATE);
- for (j = i; j < argc; j++)
- change_attributes (argv[j]);
- exit(0);
+ for (j = i; j < argc; j++) {
+ err = change_attributes (argv[j], 1);
+ if (err)
+ retval = 1;
+ }
+ exit(retval);
}
blk_t super_blk, old_desc_blk, new_desc_blk;
char *block_bitmap=NULL, *inode_bitmap=NULL;
int inode_blocks_per_group, old_desc_blocks, reserved_gdt;
+ int block_nbytes, inode_nbytes;
int has_super;
+ blk_t blk_itr = fs->super->s_first_data_block;
+ ext2_ino_t ino_itr = 1;
+
+ block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
+ inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;
if (fs->block_map)
- block_bitmap = fs->block_map->bitmap;
+ block_bitmap = malloc(block_nbytes);
if (fs->inode_map)
- inode_bitmap = fs->inode_map->bitmap;
+ inode_bitmap = malloc(inode_nbytes);
inode_blocks_per_group = ((fs->super->s_inodes_per_group *
EXT2_INODE_SIZE(fs->super)) +
fs->group_desc[i].bg_used_dirs_count);
if (block_bitmap) {
fputs(_(" Free blocks: "), stdout);
+ ext2fs_get_block_bitmap_range(fs->block_map,
+ blk_itr, block_nbytes << 3, block_bitmap);
print_free (i, block_bitmap,
fs->super->s_blocks_per_group,
fs->super->s_first_data_block);
fputc('\n', stdout);
- block_bitmap += fs->super->s_blocks_per_group / 8;
+ blk_itr += fs->super->s_blocks_per_group;
}
if (inode_bitmap) {
fputs(_(" Free inodes: "), stdout);
+ ext2fs_get_inode_bitmap_range(fs->inode_map,
+ ino_itr, inode_nbytes << 3, inode_bitmap);
print_free (i, inode_bitmap,
fs->super->s_inodes_per_group, 1);
fputc('\n', stdout);
- inode_bitmap += fs->super->s_inodes_per_group / 8;
+ ino_itr += fs->super->s_inodes_per_group;
}
}
}
int force = 0;
int flags;
int header_only = 0;
- int big_endian;
int c;
#ifdef ENABLE_NLS
if (print_badblocks) {
list_bad_blocks(fs, 1);
} else {
- big_endian = ((fs->flags & EXT2_FLAG_SWAP_BYTES) != 0);
-#ifdef WORDS_BIGENDIAN
- big_endian = !big_endian;
-#endif
- if (big_endian)
- printf(_("Note: This is a byte-swapped filesystem\n"));
list_super (fs->super);
if (fs->super->s_feature_incompat &
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
hdr.magic_number = EXT2_ET_MAGIC_E2IMAGE;
strcpy(hdr.magic_descriptor, "Ext2 Image 1.0");
gethostname(hdr.fs_hostname, sizeof(hdr.fs_hostname));
- strncat(hdr.fs_device_name, device_name, sizeof(hdr.fs_device_name));
- hdr.fs_device_name[sizeof(hdr.fs_device_name) - 1] = 0;
+ strncat(hdr.fs_device_name, device_name, sizeof(hdr.fs_device_name) - 1);
hdr.fs_blocksize = fs->blocksize;
if (stat(device_name, &st) == 0)
for (p = buf; p < end-8; p += rec_len) {
dirent = (struct ext2_dir_entry_2 *) p;
rec_len = dirent->rec_len;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & EXT2_FLAG_SWAP_BYTES)
- rec_len = ext2fs_swab16(rec_len);
+#ifdef WORDS_BIGENDIAN
+ rec_len = ext2fs_swab16(rec_len);
#endif
#if 0
printf("rec_len = %d, name_len = %d\n", rec_len, dirent->name_len);
"bad rec_len (%d)\n", (unsigned long) blk,
rec_len);
rec_len = end - p;
-#ifdef EXT2FS_ENABLE_SWAPFS
- if (fs->flags & EXT2_FLAG_SWAP_BYTES)
+#ifdef WORDS_BIGENDIAN
dirent->rec_len = ext2fs_swab16(rec_len);
#endif
continue;
if (s->s_reserved_gdt_blocks)
printf(_("Maximum filesystem blocks=%lu\n"),
(s->s_reserved_gdt_blocks + fs->desc_blocks) *
- (fs->blocksize / sizeof(struct ext2_group_desc)) *
- s->s_blocks_per_group);
+ EXT2_DESC_PER_BLOCK(s) * s->s_blocks_per_group);
if (fs->group_desc_count > 1)
printf(_("%u block groups\n"), fs->group_desc_count);
else
sb->s_creator_os = EXT2_OS_LINUX;
else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
sb->s_creator_os = EXT2_OS_HURD;
- else if (strcasecmp(os, "masix") == 0)
- sb->s_creator_os = EXT2_OS_MASIX;
else if (strcasecmp(os, "freebsd") == 0)
sb->s_creator_os = EXT2_OS_FREEBSD;
else if (strcasecmp(os, "lites") == 0)
bpg = param->s_blocks_per_group;
if (!bpg)
bpg = blocksize * 8;
- gdpb = blocksize / sizeof(struct ext2_group_desc);
+ gdpb = EXT2_DESC_PER_BLOCK(param);
group_desc_count =
ext2fs_div_ceil(param->s_blocks_count, bpg);
desc_blocks = (group_desc_count +
EXT2_FEATURE_COMPAT_LAZY_BG, /* Compat */
EXT2_FEATURE_INCOMPAT_FILETYPE| /* Incompat */
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
- EXT2_FEATURE_INCOMPAT_META_BG,
+ EXT2_FEATURE_INCOMPAT_META_BG|
+ EXT4_FEATURE_INCOMPAT_FLEX_BG,
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
};
errcode_t retval = 0;
ext2_filsys fs;
badblocks_list bb_list = 0;
- int journal_blocks;
+ unsigned int journal_blocks;
unsigned int i;
int val;
io_manager io_ptr;
goto no_journal;
}
if (!quiet) {
- printf(_("Creating journal (%d blocks): "),
+ printf(_("Creating journal (%u blocks): "),
journal_blocks);
fflush(stdout);
}
static __u32 ok_features[3] = {
EXT3_FEATURE_COMPAT_HAS_JOURNAL |
EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */
- EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */
+ EXT2_FEATURE_INCOMPAT_FILETYPE| /* Incompat */
+ EXT4_FEATURE_INCOMPAT_FLEX_BG,
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
};
{
int sparse, old_sparse, filetype, old_filetype;
int journal, old_journal, dxdir, old_dxdir;
+ int flex_bg, old_flex_bg;
struct ext2_super_block *sb= fs->super;
__u32 old_compat, old_incompat, old_ro_compat;
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
old_filetype = sb->s_feature_incompat &
EXT2_FEATURE_INCOMPAT_FILETYPE;
+ old_flex_bg = sb->s_feature_incompat &
+ EXT4_FEATURE_INCOMPAT_FLEX_BG;
old_journal = sb->s_feature_compat &
EXT3_FEATURE_COMPAT_HAS_JOURNAL;
old_dxdir = sb->s_feature_compat &
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
filetype = sb->s_feature_incompat &
EXT2_FEATURE_INCOMPAT_FILETYPE;
+ flex_bg = sb->s_feature_incompat &
+ EXT4_FEATURE_INCOMPAT_FLEX_BG;
journal = sb->s_feature_compat &
EXT3_FEATURE_COMPAT_HAS_JOURNAL;
dxdir = sb->s_feature_compat &
if (uuid_is_null((unsigned char *) sb->s_hash_seed))
uuid_generate((unsigned char *) sb->s_hash_seed);
}
+ if (!flex_bg && old_flex_bg) {
+ if (ext2fs_check_desc(fs)) {
+ fputs(_("Clearing the flex_bg flag would "
+ "cause the the filesystem to be\n"
+ "inconsistent.\n"), stderr);
+ exit(1);
+ }
+ }
if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
(sb->s_feature_compat || sb->s_feature_ro_compat ||
fflush(stderr);
fputs(_("Proceed anyway? (y,n) "), stdout);
buf[0] = 0;
- fgets(buf, sizeof(buf), stdin);
- if (strchr(short_yes, buf[0]) == 0)
+ if (!fgets(buf, sizeof(buf), stdin) ||
+ strchr(short_yes, buf[0]) == 0)
exit(1);
}
* in the filesystem. For very small filesystems, it is not reasonable to
* have a journal that fills more than half of the filesystem.
*/
-int figure_journal_size(int size, ext2_filsys fs)
+unsigned int figure_journal_size(int size, ext2_filsys fs)
{
int j_blocks;
j_blocks);
exit(1);
}
- if (j_blocks > fs->super->s_free_blocks_count / 2) {
+ if ((unsigned) j_blocks > fs->super->s_free_blocks_count / 2) {
fputs(_("\nJournal size too big for filesystem.\n"),
stderr);
exit(1);
extern void check_plausibility(const char *device);
extern void parse_journal_opts(const char *opts);
extern void check_mount(const char *device, int force, const char *type);
-extern int figure_journal_size(int size, ext2_filsys fs);
+extern unsigned int figure_journal_size(int size, ext2_filsys fs);
extern void print_check_message(ext2_filsys fs);
ext2fs_mark_block_bitmap(fs->block_map, group_block);
adjblocks++;
}
- meta_bg_size = (fs->blocksize /
- sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
meta_bg = i / meta_bg_size;
if (!(fs->super->s_feature_incompat &
EXT2_FEATURE_INCOMPAT_META_BG) ||
unsigned long meta_bg_size;
unsigned int old_desc_blocks;
- meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
else
* If we're increasing the number of descriptor blocks, life
* gets interesting....
*/
- meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
for (i = 0; i < max_groups; i++) {
has_super = ext2fs_bg_has_super(fs, i);
if (has_super)
+++ /dev/null
-ls
-stat sym
-stat double-indirect-test
-cat fluff
-quit
+++ /dev/null
-Swapfs test
-e2fsck -yf -N test_filesys
-Pass 1: Checking inodes, blocks, and sizes
-Pass 2: Checking directory structure
-Pass 3: Checking directory connectivity
-Pass 4: Checking reference counts
-Pass 5: Checking group summary information
-test_filesys: 25/256 files (0.0% non-contiguous), 418/1024 blocks
-Exit status is 0
-e2fsck -Sy -N test_filesys
-Pass 0: Doing byte-swap of filesystem
-Pass 1: Checking inodes, blocks, and sizes
-Pass 2: Checking directory structure
-Pass 3: Checking directory connectivity
-Pass 4: Checking reference counts
-Pass 5: Checking group summary information
-test_filesys: 25/256 files (0.0% non-contiguous), 418/1024 blocks
-Exit status is 0
-Running debugfs....
-debugfs: ls
- 2 (12) . 2 (12) .. 11 (20) lost+found 12 (16) fluff
- 13 (28) indirect-fluff-test 14 (28) double-indirect-test
- 15 (20) sym 16 (24) long-sym-test 17 (864) dir-test
-debugfs: stat sym
-Inode: 15 Type: symlink Mode: 0777 Flags: 0x0 Generation: 1
-User: 0 Group: 0 Size: 5
-File ACL: 0 Directory ACL: 0
-Links: 1 Blockcount: 0
-Fragment: Address: 0 Number: 0 Size: 0
-ctime: 0x322737e2 -- Fri Aug 30 18:50:10 1996
-atime: 0x322737e2 -- Fri Aug 30 18:50:10 1996
-mtime: 0x322737e2 -- Fri Aug 30 18:50:10 1996
-Fast_link_dest: fluff
-debugfs: stat double-indirect-test
-Inode: 14 Type: regular Mode: 0644 Flags: 0x0 Generation: 1
-User: 0 Group: 0 Size: 348960
-File ACL: 0 Directory ACL: 0
-Links: 1 Blockcount: 688
-Fragment: Address: 0 Number: 0 Size: 0
-ctime: 0x322488cf -- Wed Aug 28 17:58:39 1996
-atime: 0x322488cf -- Wed Aug 28 17:58:39 1996
-mtime: 0x322488cf -- Wed Aug 28 17:58:39 1996
-BLOCKS:
-(0-11):70-81, (IND):82, (12-267):83-338, (DIND):339, (IND):340, (268-340):341-413
-TOTAL: 344
-
-debugfs: cat fluff
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-
-debugfs: quit
-Exit status is 0
-e2fsck -yf -N test_filesys
-Pass 1: Checking inodes, blocks, and sizes
-Pass 2: Checking directory structure
-Pass 3: Checking directory connectivity
-Pass 4: Checking reference counts
-Pass 5: Checking group summary information
-test_filesys: 25/256 files (0.0% non-contiguous), 418/1024 blocks
-Exit status is 0
-e2fsck -sy -N test_filesys
-Pass 0: Doing byte-swap of filesystem
-Pass 1: Checking inodes, blocks, and sizes
-Pass 2: Checking directory structure
-Pass 3: Checking directory connectivity
-Pass 4: Checking reference counts
-Pass 5: Checking group summary information
-test_filesys: 25/256 files (0.0% non-contiguous), 418/1024 blocks
-Exit status is 0
-Running debugfs....
-debugfs: ls
- 2 (12) . 2 (12) .. 11 (20) lost+found 12 (16) fluff
- 13 (28) indirect-fluff-test 14 (28) double-indirect-test
- 15 (20) sym 16 (24) long-sym-test 17 (864) dir-test
-debugfs: stat sym
-Inode: 15 Type: symlink Mode: 0777 Flags: 0x0 Generation: 1
-User: 0 Group: 0 Size: 5
-File ACL: 0 Directory ACL: 0
-Links: 1 Blockcount: 0
-Fragment: Address: 0 Number: 0 Size: 0
-ctime: 0x322737e2 -- Fri Aug 30 18:50:10 1996
-atime: 0x322737e2 -- Fri Aug 30 18:50:10 1996
-mtime: 0x322737e2 -- Fri Aug 30 18:50:10 1996
-Fast_link_dest: fluff
-debugfs: stat double-indirect-test
-Inode: 14 Type: regular Mode: 0644 Flags: 0x0 Generation: 1
-User: 0 Group: 0 Size: 348960
-File ACL: 0 Directory ACL: 0
-Links: 1 Blockcount: 688
-Fragment: Address: 0 Number: 0 Size: 0
-ctime: 0x322488cf -- Wed Aug 28 17:58:39 1996
-atime: 0x322488cf -- Wed Aug 28 17:58:39 1996
-mtime: 0x322488cf -- Wed Aug 28 17:58:39 1996
-BLOCKS:
-(0-11):70-81, (IND):82, (12-267):83-338, (DIND):339, (IND):340, (268-340):341-413
-TOTAL: 344
-
-debugfs: cat fluff
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-yabba dabba doo. cocka doodle doo. yabba dabba doo. cocka doodle doo. yipyip
-
-debugfs: quit
-Exit status is 0
-e2fsck -yf -N test_filesys
-Pass 1: Checking inodes, blocks, and sizes
-Pass 2: Checking directory structure
-Pass 3: Checking directory connectivity
-Pass 4: Checking reference counts
-Pass 5: Checking group summary information
-test_filesys: 25/256 files (0.0% non-contiguous), 418/1024 blocks
-Exit status is 0
+++ /dev/null
-checking the e2fsck swapfs functionality
+++ /dev/null
-if $FSCK -SV > /dev/null 2>&1 ; then
- IMAGE=$test_dir/image.gz
- VERIFY_FSCK_OPT=-yf
- SWAP_FSCK_OPT=-Sy
- NATIVE_FSCK_OPT=-sy
- OUT=$test_name.log
- EXP=$test_dir/expect
-
- gunzip < $IMAGE > $TMPFILE
-
- echo "Swapfs test" > $OUT
-
- echo e2fsck $VERIFY_FSCK_OPT -N test_filesys > $OUT.new
- $FSCK $VERIFY_FSCK_OPT -N test_filesys $TMPFILE >> $OUT.new 2>&1
- status=$?
- echo Exit status is $status >> $OUT.new
- sed -e '2d' $OUT.new >> $OUT
-
- echo e2fsck $SWAP_FSCK_OPT -N test_filesys > $OUT.new
- $FSCK $SWAP_FSCK_OPT -N test_filesys $TMPFILE >> $OUT.new 2>&1
- status=$?
- echo Exit status is $status >> $OUT.new
- sed -e '2d' $OUT.new >> $OUT
-
- echo Running debugfs.... >> $OUT
- $DEBUGFS -f $test_dir/debugfs.cmd $TMPFILE > $OUT.new 2>&1
- status=$?
- echo Exit status is $status >> $OUT.new
- sed -e '1d' $OUT.new >> $OUT
-
- echo e2fsck $VERIFY_FSCK_OPT -N test_filesys > $OUT.new
- $FSCK $VERIFY_FSCK_OPT -N test_filesys $TMPFILE >> $OUT.new 2>&1
- status=$?
- echo Exit status is $status >> $OUT.new
- sed -e '2d' $OUT.new >> $OUT
-
- echo e2fsck $NATIVE_FSCK_OPT -N test_filesys > $OUT.new
- $FSCK $NATIVE_FSCK_OPT -N test_filesys $TMPFILE >> $OUT.new 2>&1
- status=$?
- echo Exit status is $status >> $OUT.new
- sed -e '2d' $OUT.new >> $OUT
-
- echo Running debugfs.... >> $OUT
- $DEBUGFS -f $test_dir/debugfs.cmd $TMPFILE > $OUT.new 2>&1
- status=$?
- echo Exit status is $status >> $OUT.new
- sed -e '1d' $OUT.new >> $OUT
-
- echo e2fsck $VERIFY_FSCK_OPT -N test_filesys > $OUT.new
- $FSCK $VERIFY_FSCK_OPT -N test_filesys $TMPFILE >> $OUT.new 2>&1
- status=$?
- echo Exit status is $status >> $OUT.new
- sed -e '2d' $OUT.new >> $OUT
- rm -f $OUT.new
-
- rm $TMPFILE
-
- #
- # Do the verification
- #
-
- rm -f $test_name.ok $test_name.failed
- cmp -s $OUT $EXP
- status=$?
-
- if [ "$status" = 0 ] ; then
- echo "ok"
- touch $test_name.ok
- else
- echo "failed"
- diff $DIFF_OPTS $EXP $OUT > $test_name.failed
- fi
-
- unset IMAGE VERIFY_FSCK_OPT SWAP_FSCK_OPT NATIVE_FSCK_OPT OUT EXP
-
-else
- rm -f $test_name.ok $test_name.failed
- echo "skipped"
-fi