Imported reiserfsprogs-3.6.2
This commit is contained in:
1 parent
e7102bdb66
commit
b69459eb80
86 files changed
+22926
-13213
No files matched your search
@@ -1,3 +1,157 @@
|
||||
2002-06-27
|
||||
* reiserfsprogs
|
||||
called 3.6.2
|
||||
2002-05-23
|
||||
* reiserfsck
|
||||
speedup for pass2: do not check whether a file should be relocated
|
||||
if the file body was previously deleted from the tree and is
|
||||
inserted again.
|
||||
2002-05-10
|
||||
* reiserfsck
|
||||
fix-fixable is able to fix wrong nlinks.
|
||||
check makes some check about nlinks also.
|
||||
2002-04-30
|
||||
* reiserfsck
|
||||
delete direntries of old format in new format directories
|
||||
2002-03-29
|
||||
* reiserfsprogs
|
||||
bad blocks support added.
|
||||
2002-03-15
|
||||
* reiserfsprogs
|
||||
different blocksize support added.
|
||||
2002-02-18
|
||||
* debugreiserfs
|
||||
new option -J, prints a journal header.
|
||||
2002-02-10
|
||||
* reiserfsprogs
|
||||
a few speedups were added.
|
||||
2002-02-05
|
||||
* reiserfsprogs
|
||||
optimization of the work with disk buffers.
|
||||
2002-01-28
|
||||
* mkreiserfs
|
||||
zeroing the first block on the device if not SPARC
|
||||
2002-01-26
|
||||
* reiserfsck
|
||||
a few speedups were added.
|
||||
2002-01-20
|
||||
* debugreiserfs
|
||||
investigation of unused space added (-D -U options, hidden)
|
||||
2002-01-16
|
||||
* reiserfsprogs
|
||||
support for UUID and LABEL was added
|
||||
2002-01-15
|
||||
* reiserfstune
|
||||
creates a standard journal from a non-standard
|
||||
2001-12-25
|
||||
* reiserfsck
|
||||
Handles safe links.
|
||||
2001-12-03
|
||||
* reiserfsck
|
||||
Filenames output during tree scan is now nicely scrolled
|
||||
left and right, when entire line does not fit the screen.
|
||||
2001-11-20
|
||||
* reiserfsck
|
||||
Can rebuild superblock properly.
|
||||
2001-11-03
|
||||
* reiserfsck
|
||||
Can now backup all data which get changed during fscking
|
||||
and can rollback all changes.
|
||||
2001-10-30
|
||||
* reiserfsprogs
|
||||
mkreiserfs/reiserfsck/reiserfstune/debugreiserfs work with
|
||||
relocated journal
|
||||
2001-09-30
|
||||
* debugreiserfs
|
||||
super block editor (-C -B 16)
|
||||
2001-08-23
|
||||
* reiserfsck
|
||||
--fix-fixable becomes a mode, can fix everything what does
|
||||
not need to rebuild a tree.
|
||||
--fix-non-critical option moved to --ajust-file-size option,
|
||||
work in --fix-fixable and --rebuild-tree modes.
|
||||
2001-07-19
|
||||
* mkreiserfs
|
||||
can now create non-standard journal: journal size,
|
||||
offset, device may now vary
|
||||
* reiserfstune
|
||||
initial release. Allows to change journal parameters for
|
||||
existing filesystems
|
||||
* reisrefsck
|
||||
it now sets "consistency checked" flag after
|
||||
--rebuild-tree and --check which did not find anything
|
||||
broken
|
||||
* man pages
|
||||
updated
|
||||
|
||||
2001-06-25
|
||||
* mkreiserfs
|
||||
long options (--journal-device, --journal-size)
|
||||
* library
|
||||
reiserfs_create, reiserfs_create_journal
|
||||
|
||||
2001-06-20
|
||||
* global changes
|
||||
Jeff's patch (safe endianness) is merged (with changes)
|
||||
mlock is used to estimate amount of memory available
|
||||
|
||||
2001-06-14
|
||||
* reiserfsck
|
||||
update journal header when transaction is replayed
|
||||
|
||||
2001-06-13
|
||||
* reiserfsck
|
||||
lost+found's mode is set to drwx------ after lost+found pass
|
||||
|
||||
2001-06-08
|
||||
* library
|
||||
functions to deal with journal
|
||||
|
||||
2001-06-05
|
||||
* global change
|
||||
Unified access via get_/set_ macroses is added for fields
|
||||
of struct key, struct item_head, struct
|
||||
reiserfs_journal_desc/commit, struct block_head, struct disk_child
|
||||
|
||||
2001-05-22
|
||||
* global change
|
||||
Access to super block's fields are unified vid get_sb_xxx
|
||||
and set_sb_xxx macroses
|
||||
|
||||
2001-05-05
|
||||
* called 3.x.0k-pre4
|
||||
* reiserfsck
|
||||
entries in lost+found are removed on pass 0
|
||||
|
||||
2001-05-03
|
||||
* mkreiserfs
|
||||
first 64k get zeroed now. This kills JFS if it was there
|
||||
* reiserfsprogs.spec (Anthon van der Neut)
|
||||
prereleases can be built by rpm now
|
||||
link from /sbin/mkreiserfs to /sbin/mkfs.reiserfs
|
||||
guess about reiserfs kernel support is added
|
||||
|
||||
2001-04-16
|
||||
* reiserfsck
|
||||
in --check mode it exits with 0 if there were no
|
||||
corruptions found, 1 if there were only corruptions
|
||||
fixable by --fix-fixable or 2 if --rebuild-tree is
|
||||
required
|
||||
man page updated, simple example of using reiserfsck is
|
||||
added
|
||||
|
||||
2001-04-15
|
||||
* mkreiserfs
|
||||
bug in confirmation dialogs fixed
|
||||
|
||||
2001-04-13-Friday
|
||||
* reiserfsck
|
||||
--hash option makes reiserfsck to skip blocks having
|
||||
directory entries created with other hash. It is useful
|
||||
together with --scan-whole-partition
|
||||
--background option allows to fork fsck end exit (useful
|
||||
for running remotely)
|
||||
|
||||
2001-03-31
|
||||
* reiserfsck
|
||||
empty lost directories do not get linked into /lost+found
|
||||
|
||||
+6
-2
@@ -1,4 +1,8 @@
|
||||
SUBDIRS = include lib reiserfscore mkreiserfs fsck debugreiserfs resize_reiserfs
|
||||
SUBDIRS = include lib reiserfscore fsck debugreiserfs resize_reiserfs mkreiserfs tune
|
||||
|
||||
EXTRA_DIST = version.h reiserfsprogs.spec
|
||||
noinst_DATA = reiserfsprogs.spec
|
||||
|
||||
EXTRA_DIST = version.h
|
||||
|
||||
dist-hook:
|
||||
cp -f reiserfsprogs.spec $(distdir)
|
||||
+57
-19
@@ -1,6 +1,6 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -62,16 +62,22 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
SUBDIRS = include lib reiserfscore mkreiserfs fsck debugreiserfs resize_reiserfs
|
||||
SUBDIRS = include lib reiserfscore fsck debugreiserfs resize_reiserfs mkreiserfs tune
|
||||
|
||||
EXTRA_DIST = version.h reiserfsprogs.spec
|
||||
noinst_DATA = reiserfsprogs.spec
|
||||
|
||||
EXTRA_DIST = version.h
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ./include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
DATA = $(noinst_DATA)
|
||||
|
||||
DIST_COMMON = README AUTHORS COPYING ChangeLog INSTALL Makefile.am \
|
||||
Makefile.in NEWS aclocal.m4 configure configure.in install-sh missing \
|
||||
mkinstalldirs
|
||||
Makefile.in NEWS acconfig.h aclocal.m4 configure configure.in \
|
||||
include/config.h.in include/stamp-h.in install-sh missing mkinstalldirs
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
@@ -95,6 +101,34 @@ config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
|
||||
cd $(srcdir) && $(AUTOCONF)
|
||||
|
||||
include/config.h: include/stamp-h
|
||||
@if test ! -f $@; then \
|
||||
rm -f include/stamp-h; \
|
||||
$(MAKE) include/stamp-h; \
|
||||
else :; fi
|
||||
include/stamp-h: $(srcdir)/include/config.h.in $(top_builddir)/config.status
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES= CONFIG_HEADERS=include/config.h \
|
||||
$(SHELL) ./config.status
|
||||
@echo timestamp > include/stamp-h 2> /dev/null
|
||||
$(srcdir)/include/config.h.in: $(srcdir)/include/stamp-h.in
|
||||
@if test ! -f $@; then \
|
||||
rm -f $(srcdir)/include/stamp-h.in; \
|
||||
$(MAKE) $(srcdir)/include/stamp-h.in; \
|
||||
else :; fi
|
||||
$(srcdir)/include/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4) acconfig.h
|
||||
cd $(top_srcdir) && $(AUTOHEADER)
|
||||
@echo timestamp > $(srcdir)/include/stamp-h.in 2> /dev/null
|
||||
|
||||
mostlyclean-hdr:
|
||||
|
||||
clean-hdr:
|
||||
|
||||
distclean-hdr:
|
||||
-rm -f include/config.h
|
||||
|
||||
maintainer-clean-hdr:
|
||||
|
||||
# This directory's subdirectories are mostly independent; you can cd
|
||||
# into them and run `make' without going through this Makefile.
|
||||
# To change the values of `make' variables: instead of editing Makefiles,
|
||||
@@ -131,7 +165,7 @@ maintainer-clean-recursive:
|
||||
dot_seen=no; \
|
||||
rev=''; list='$(SUBDIRS)'; for subdir in $$list; do \
|
||||
rev="$$subdir $$rev"; \
|
||||
test "$$subdir" = "." && dot_seen=yes; \
|
||||
test "$$subdir" != "." || dot_seen=yes; \
|
||||
done; \
|
||||
test "$$dot_seen" = "no" && rev=". $$rev"; \
|
||||
target=`echo $@ | sed s/-recursive//`; \
|
||||
@@ -225,7 +259,7 @@ distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
@@ -242,6 +276,7 @@ distdir: $(DISTFILES)
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
$(MAKE) $(AM_MAKEFLAGS) top_distdir="$(top_distdir)" distdir="$(distdir)" dist-hook
|
||||
info-am:
|
||||
info: info-recursive
|
||||
dvi-am:
|
||||
@@ -261,7 +296,7 @@ install-am: all-am
|
||||
install: install-recursive
|
||||
uninstall-am:
|
||||
uninstall: uninstall-recursive
|
||||
all-am: Makefile
|
||||
all-am: Makefile $(DATA)
|
||||
all-redirect: all-recursive
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
@@ -278,32 +313,32 @@ distclean-generic:
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
mostlyclean-am: mostlyclean-tags mostlyclean-generic
|
||||
mostlyclean-am: mostlyclean-hdr mostlyclean-tags mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-recursive
|
||||
|
||||
clean-am: clean-tags clean-generic mostlyclean-am
|
||||
clean-am: clean-hdr clean-tags clean-generic mostlyclean-am
|
||||
|
||||
clean: clean-recursive
|
||||
|
||||
distclean-am: distclean-tags distclean-generic clean-am
|
||||
distclean-am: distclean-hdr distclean-tags distclean-generic clean-am
|
||||
|
||||
distclean: distclean-recursive
|
||||
-rm -f config.status
|
||||
|
||||
maintainer-clean-am: maintainer-clean-tags maintainer-clean-generic \
|
||||
distclean-am
|
||||
maintainer-clean-am: maintainer-clean-hdr maintainer-clean-tags \
|
||||
maintainer-clean-generic distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-recursive
|
||||
-rm -f config.status
|
||||
|
||||
.PHONY: install-data-recursive uninstall-data-recursive \
|
||||
install-exec-recursive uninstall-exec-recursive installdirs-recursive \
|
||||
uninstalldirs-recursive all-recursive check-recursive \
|
||||
installcheck-recursive info-recursive dvi-recursive \
|
||||
mostlyclean-recursive distclean-recursive clean-recursive \
|
||||
.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \
|
||||
install-data-recursive uninstall-data-recursive install-exec-recursive \
|
||||
uninstall-exec-recursive installdirs-recursive uninstalldirs-recursive \
|
||||
all-recursive check-recursive installcheck-recursive info-recursive \
|
||||
dvi-recursive mostlyclean-recursive distclean-recursive clean-recursive \
|
||||
maintainer-clean-recursive tags tags-recursive mostlyclean-tags \
|
||||
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
|
||||
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
|
||||
@@ -313,6 +348,9 @@ installdirs mostlyclean-generic distclean-generic clean-generic \
|
||||
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
dist-hook:
|
||||
cp -f reiserfsprogs.spec $(distdir)
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
Vendored
+28
-5
@@ -1,6 +1,6 @@
|
||||
dnl aclocal.m4 generated automatically by aclocal 1.4
|
||||
dnl aclocal.m4 generated automatically by aclocal 1.4-p5
|
||||
|
||||
dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
@@ -19,7 +19,7 @@ dnl PARTICULAR PURPOSE.
|
||||
dnl Usage:
|
||||
dnl AM_INIT_AUTOMAKE(package,version, [no-define])
|
||||
|
||||
AC_DEFUN(AM_INIT_AUTOMAKE,
|
||||
AC_DEFUN([AM_INIT_AUTOMAKE],
|
||||
[AC_REQUIRE([AC_PROG_INSTALL])
|
||||
PACKAGE=[$1]
|
||||
AC_SUBST(PACKAGE)
|
||||
@@ -47,7 +47,7 @@ AC_REQUIRE([AC_PROG_MAKE_SET])])
|
||||
# Check to make sure that the build environment is sane.
|
||||
#
|
||||
|
||||
AC_DEFUN(AM_SANITY_CHECK,
|
||||
AC_DEFUN([AM_SANITY_CHECK],
|
||||
[AC_MSG_CHECKING([whether build environment is sane])
|
||||
# Just in case
|
||||
sleep 1
|
||||
@@ -88,7 +88,7 @@ AC_MSG_RESULT(yes)])
|
||||
|
||||
dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
|
||||
dnl The program must properly implement --version.
|
||||
AC_DEFUN(AM_MISSING_PROG,
|
||||
AC_DEFUN([AM_MISSING_PROG],
|
||||
[AC_MSG_CHECKING(for working $2)
|
||||
# Run test in a subshell; some versions of sh will print an error if
|
||||
# an executable is not found, even if stderr is redirected.
|
||||
@@ -102,3 +102,26 @@ else
|
||||
fi
|
||||
AC_SUBST($1)])
|
||||
|
||||
# Like AC_CONFIG_HEADER, but automatically create stamp file.
|
||||
|
||||
AC_DEFUN([AM_CONFIG_HEADER],
|
||||
[AC_PREREQ([2.12])
|
||||
AC_CONFIG_HEADER([$1])
|
||||
dnl When config.status generates a header, we must update the stamp-h file.
|
||||
dnl This file resides in the same directory as the config header
|
||||
dnl that is generated. We must strip everything past the first ":",
|
||||
dnl and everything past the last "/".
|
||||
AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl
|
||||
ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>,
|
||||
<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
|
||||
<<am_indx=1
|
||||
for am_file in <<$1>>; do
|
||||
case " <<$>>CONFIG_HEADERS " in
|
||||
*" <<$>>am_file "*<<)>>
|
||||
echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx
|
||||
;;
|
||||
esac
|
||||
am_indx=`expr "<<$>>am_indx" + 1`
|
||||
done<<>>dnl>>)
|
||||
changequote([,]))])
|
||||
|
||||
+17
-12
@@ -1,16 +1,19 @@
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(version.h)
|
||||
|
||||
AM_INIT_AUTOMAKE(reiserfsprogs, 3.x.0j)
|
||||
AM_INIT_AUTOMAKE(reiserfsprogs, 3.6.2)
|
||||
|
||||
dnl We install in /sbin, the utils are to be available on boot
|
||||
AC_PREFIX_DEFAULT(/)
|
||||
dnl AC_PREFIX(/)
|
||||
|
||||
AM_CONFIG_HEADER(include/config.h)
|
||||
|
||||
AC_SUBST(sbindir)
|
||||
|
||||
PRESET_CFLAGS=$CFLAGS
|
||||
AC_PROG_CC
|
||||
if test -z $PRESET_CFLAGS; then
|
||||
dnl CFLAGS="${RPM_OPT_FLAGS} $CFLAGS -Wall"
|
||||
CFLAGS="${RPM_OPT_FLAGS} -g -O2 -Wall"
|
||||
if test "x" = "x$PRESET_CFLAGS"; then
|
||||
CFLAGS="${RPM_OPT_FLAGS} $CFLAGS -Wall"
|
||||
fi
|
||||
|
||||
dnl Checks for programs.
|
||||
@@ -38,11 +41,13 @@ AC_FUNC_STRFTIME
|
||||
AC_FUNC_VPRINTF
|
||||
AC_CHECK_FUNCS(strerror strstr strtol)
|
||||
|
||||
AC_OUTPUT(include/Makefile mkreiserfs/Makefile resize_reiserfs/Makefile fsck/Makefile lib/Makefile Makefile reiserfscore/Makefile debugreiserfs/Makefile)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
dnl Never enable this. It is for debugging only
|
||||
AC_ARG_ENABLE(io-failure-emulation,
|
||||
[ --enable-io-failure-emulation Never use that. It is for debugging only],
|
||||
[ if test "$enableval" = "yes" ; then
|
||||
echo -e "\nCarefull! IO failure emulation is ON\n"
|
||||
AC_DEFINE(IO_FAILURE_EMULATION, 1, [gets set when configure --enable-io-failure-emulation])
|
||||
fi
|
||||
])
|
||||
|
||||
AC_OUTPUT(include/Makefile mkreiserfs/Makefile resize_reiserfs/Makefile fsck/Makefile lib/Makefile Makefile reiserfscore/Makefile debugreiserfs/Makefile tune/Makefile)
|
||||
@@ -1,10 +1,8 @@
|
||||
sbin_PROGRAMS = debugreiserfs unpack
|
||||
|
||||
debugreiserfs_SOURCES = debugreiserfs.c pack.c
|
||||
unpack_SOURCES = unpack.c debugreiserfs.h
|
||||
debugreiserfs_SOURCES = debugreiserfs.c pack.c stat.c corruption.c scan.c recover.c journal.c
|
||||
unpack_SOURCES = unpack.c pack.c debugreiserfs.h
|
||||
man_MANS = debugreiserfs.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
|
||||
INCLUDES = -I../include
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
+37
-17
@@ -1,6 +1,6 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -62,33 +62,36 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
sbin_PROGRAMS = debugreiserfs unpack
|
||||
|
||||
debugreiserfs_SOURCES = debugreiserfs.c pack.c
|
||||
unpack_SOURCES = unpack.c debugreiserfs.h
|
||||
debugreiserfs_SOURCES = debugreiserfs.c pack.c stat.c corruption.c scan.c recover.c journal.c
|
||||
unpack_SOURCES = unpack.c pack.c debugreiserfs.h
|
||||
man_MANS = debugreiserfs.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
|
||||
INCLUDES = -I../include
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
PROGRAMS = $(sbin_PROGRAMS)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
debugreiserfs_OBJECTS = debugreiserfs.o pack.o
|
||||
debugreiserfs_OBJECTS = debugreiserfs.o pack.o stat.o corruption.o \
|
||||
scan.o recover.o journal.o
|
||||
debugreiserfs_LDADD = $(LDADD)
|
||||
debugreiserfs_DEPENDENCIES = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
debugreiserfs_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
|
||||
$(top_srcdir)/reiserfscore/libcore.a
|
||||
debugreiserfs_LDFLAGS =
|
||||
unpack_OBJECTS = unpack.o
|
||||
unpack_OBJECTS = unpack.o pack.o
|
||||
unpack_LDADD = $(LDADD)
|
||||
unpack_DEPENDENCIES = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
unpack_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
|
||||
$(top_srcdir)/reiserfscore/libcore.a
|
||||
unpack_LDFLAGS =
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@@ -247,20 +250,37 @@ distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
fi; \
|
||||
done
|
||||
corruption.o: corruption.c debugreiserfs.h ../include/io.h \
|
||||
../include/misc.h ../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
debugreiserfs.o: debugreiserfs.c debugreiserfs.h ../include/io.h \
|
||||
../include/misc.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../version.h
|
||||
../include/misc.h ../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
journal.o: journal.c debugreiserfs.h ../include/io.h ../include/misc.h \
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
pack.o: pack.c debugreiserfs.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h ../version.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
recover.o: recover.c debugreiserfs.h ../include/io.h ../include/misc.h \
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
scan.o: scan.c debugreiserfs.h ../include/io.h ../include/misc.h \
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
stat.o: stat.c debugreiserfs.h ../include/io.h ../include/misc.h \
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
unpack.o: unpack.c debugreiserfs.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h ../version.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
|
||||
@@ -0,0 +1,487 @@
|
||||
/*
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#include "debugreiserfs.h"
|
||||
|
||||
|
||||
static int str2int (char * str, int * res)
|
||||
{
|
||||
int val;
|
||||
char * tmp;
|
||||
|
||||
val = (int) strtol (str, &tmp, 0);
|
||||
if (tmp == str)
|
||||
/* could not convert string into a number */
|
||||
return 0;
|
||||
*res = val;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void edit_journal_params (struct journal_params * jp)
|
||||
{
|
||||
char * str;
|
||||
size_t n;
|
||||
int num;
|
||||
|
||||
printf ("Journal parameters:\n");
|
||||
printf ("\tDevice: current: %x: new:", get_jp_journal_dev (jp));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_jp_journal_dev (jp, num);
|
||||
|
||||
printf ("\tFirst block: current: %d: new:",
|
||||
get_jp_journal_1st_block (jp));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_jp_journal_1st_block (jp, num);
|
||||
|
||||
printf ("\tSize: current: %d: new:", get_jp_journal_size (jp));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_jp_journal_size (jp, num);
|
||||
|
||||
printf ("\tMagic number: current: %d: new:", get_jp_journal_magic (jp));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_jp_journal_magic (jp, num);
|
||||
|
||||
printf ("\tMax transaction size: current: %d: new:",
|
||||
get_jp_journal_max_trans_len (jp));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_jp_journal_max_trans_len (jp, num);
|
||||
|
||||
printf ("\tMax batch size: current: %d: new:",
|
||||
get_jp_journal_max_batch (jp));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_jp_journal_max_batch (jp, num);
|
||||
|
||||
printf ("\tMax commit age: current: %d: new:",
|
||||
get_jp_journal_max_commit_age (jp));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_jp_journal_max_commit_age (jp, num);
|
||||
}
|
||||
|
||||
|
||||
/* this allows to edit all super block fields */
|
||||
static void edit_super_block (reiserfs_filsys_t * fs)
|
||||
{
|
||||
char * str;
|
||||
size_t n;
|
||||
int num;
|
||||
|
||||
|
||||
str = 0;
|
||||
n = 0;
|
||||
|
||||
/* bs_block_count */
|
||||
printf ("\tBlock count: current: %u: new:",
|
||||
get_sb_block_count (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_block_count (fs->fs_ondisk_sb, num);
|
||||
|
||||
|
||||
/* sb_free_blocks */
|
||||
printf ("\tFree block count: current: %u: new:",
|
||||
get_sb_free_blocks (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_free_blocks (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* sb_root_block */
|
||||
printf ("\tRoot block: current: %u: new:",
|
||||
get_sb_root_block (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_root_block (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* sb_journal */
|
||||
edit_journal_params (sb_jp (fs->fs_ondisk_sb));
|
||||
|
||||
/* sb_blocksize */
|
||||
printf ("\tBlocksize: current: %u: new:",
|
||||
get_sb_block_size (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_block_size (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* sb_oid_maxsize */
|
||||
printf ("\tMax objectid size: current: %u: new:",
|
||||
get_sb_oid_maxsize (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_oid_maxsize (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* sb_oid_cursize */
|
||||
printf ("\tCur objectid size: current: %u: new:",
|
||||
get_sb_oid_cursize (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_oid_cursize (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* sb_state */
|
||||
printf ("\tUmount state: current: %u: new:",
|
||||
get_sb_umount_state (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_umount_state (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* char s_magic [10]; */
|
||||
printf ("\tMagic: current: \"%s\": new:", fs->fs_ondisk_sb->s_v1.s_magic);
|
||||
getline (&str, &n, stdin);
|
||||
if (strcmp (str, "\n"))
|
||||
strncpy (fs->fs_ondisk_sb->s_v1.s_magic, str, n > 10 ? 10 : n);
|
||||
|
||||
/* __u16 sb_fsck_state; */
|
||||
printf ("\tFielsystem state: current: %u: new:", get_sb_fs_state (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_fs_state (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* __u32 sb_hash_function_code; */
|
||||
printf ("\tHash code: current: %u: new (tea %d, r5 %d, rupasov %d):",
|
||||
get_sb_hash_code (fs->fs_ondisk_sb), TEA_HASH, R5_HASH, YURA_HASH);
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_hash_code (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* __u16 sb_tree_height; */
|
||||
printf ("\tTree height: current: %u: new:",
|
||||
get_sb_tree_height (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_tree_height (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* __u16 sb_bmap_nr; */
|
||||
printf ("\tNumber of bitmaps: current: %u: new:",
|
||||
get_sb_bmap_nr (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_bmap_nr (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* __u16 sb_version; */
|
||||
printf ("\tFilesystem format: current: %u: new:",
|
||||
le16_to_cpu (fs->fs_ondisk_sb->s_v1.sb_version));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_version (fs->fs_ondisk_sb, num);
|
||||
|
||||
/* __u16 sb_reserved_for_journal; */
|
||||
printf ("\tSpace reserved for journal: current: %u: new:",
|
||||
get_sb_reserved_for_journal (fs->fs_ondisk_sb));
|
||||
getline (&str, &n, stdin);
|
||||
if (str2int (str, &num))
|
||||
set_sb_reserved_for_journal (fs->fs_ondisk_sb, num);
|
||||
|
||||
|
||||
print_block (stdout, fs, fs->fs_super_bh);
|
||||
if (user_confirmed (stderr, "Is this ok ? [N/Yes]: ", "Yes\n")) {
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
bwrite (fs->fs_super_bh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void corrupt_clobber_hash (char * name, struct item_head * ih,
|
||||
struct reiserfs_de_head * deh)
|
||||
{
|
||||
printf ("\tCorrupting deh_offset of entry \"%s\" of [%u %u]\n", name,
|
||||
get_key_dirid (&ih->ih_key), get_key_objectid (&ih->ih_key));
|
||||
set_deh_offset (deh, 700);
|
||||
}
|
||||
|
||||
|
||||
/* this reads list of desired corruptions from stdin and perform the
|
||||
corruptions. Format of that list:
|
||||
A hash_code
|
||||
C name objectid - 'C'ut entry 'name' from directory item with 'objectid'
|
||||
H name objectid - clobber 'H'hash of entry 'name' of directory 'objectid'
|
||||
I item_num pos_in_item make pos_in_item-th slot of indirect item to point out of device
|
||||
O item_num - destroy item 'O'rder - make 'item_num'-th to have key bigger than 'item_num' + 1-th item
|
||||
D item_num - 'D'elete item_num-th item
|
||||
S item_num value - change file size (item_num-th item must be stat data)
|
||||
F item_num value - change sd_first_direct_byte of stat data
|
||||
J item_num objectid
|
||||
E name objectid new - change entry's deh_objectid to new
|
||||
P - print the block
|
||||
*/
|
||||
void do_corrupt_one_block (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
int i, j;
|
||||
struct item_head * ih;
|
||||
int item_num;
|
||||
char * line = 0;
|
||||
size_t n = 0;
|
||||
char code, name [100];
|
||||
__u32 objectid, new_objectid;
|
||||
int value;
|
||||
int hash_code;
|
||||
int pos_in_item;
|
||||
unsigned long block;
|
||||
int type, format;
|
||||
|
||||
|
||||
block = certain_block (fs);
|
||||
if (block == fs->fs_super_bh->b_blocknr) {
|
||||
edit_super_block (fs);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fs->fs_bitmap2) {
|
||||
struct buffer_head * bm_bh;
|
||||
unsigned long bm_block;
|
||||
|
||||
if (spread_bitmaps (fs))
|
||||
bm_block = ( block / (fs->fs_blocksize * 8) ) ?
|
||||
(block / (fs->fs_blocksize * 8)) * (fs->fs_blocksize * 8) :
|
||||
fs->fs_super_bh->b_blocknr + 1;
|
||||
else
|
||||
bm_block = fs->fs_super_bh->b_blocknr + 1 + (block / (fs->fs_blocksize * 8));
|
||||
|
||||
bm_bh = bread (fs->fs_dev, bm_block, fs->fs_blocksize);
|
||||
if (bm_bh) {
|
||||
if ( test_bit((block % (fs->fs_blocksize * 8)), bm_bh->b_data) )
|
||||
fprintf (stderr, "%lu is used in ondisk bitmap\n", block);
|
||||
else
|
||||
fprintf (stderr, "%lu is free in ondisk bitmap\n", block);
|
||||
|
||||
brelse (bm_bh);
|
||||
}
|
||||
} else {
|
||||
if (reiserfs_bitmap_test_bit (fs->fs_bitmap2, block))
|
||||
fprintf (stderr, "%lu is used in ondisk bitmap\n", block);
|
||||
else
|
||||
fprintf (stderr, "%lu is free in ondisk bitmap\n", block);
|
||||
}
|
||||
|
||||
bh = bread (fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
printf ("corrupt_one_block: bread fialed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (who_is_this (bh->b_data, fs->fs_blocksize) != THE_LEAF) {
|
||||
printf ("Can not corrupt not a leaf node\n");
|
||||
brelse (bh);
|
||||
return;
|
||||
}
|
||||
|
||||
printf ("Corrupting block %lu..\n", bh->b_blocknr);
|
||||
|
||||
while (getline (&line, &n, stdin) != -1) {
|
||||
switch (line[0]) {
|
||||
case '#':
|
||||
case '\n':
|
||||
continue;
|
||||
case '?':
|
||||
printf ("A hash_code - reset hAsh code in super block\n"
|
||||
"T item_num type (0, 1, 2, 3) format (0, 1)\n"
|
||||
"C name objectid - Cut entry 'name' from directory item with 'objectid'\n"
|
||||
"H name objectid - clobber Hash of entry 'name' of directory 'objectid'\n"
|
||||
"I item_num pos_in_item make pos_in_tem-th slot of Indirect item to point out of device\n"
|
||||
"O item_num - destroy item Order - make 'item_num'-th to have key bigger than 'item_num' + 1-th item\n"
|
||||
"D item_num - Delete item_num-th item\n"
|
||||
"S item_num value - change file Size (item_num-th item must be stat data)\n"
|
||||
"F item_num value - change sd_First_direct_byte of stat data\n"
|
||||
"J item_num objectid - set 'obJectid' of 'item_num'-th item\n"
|
||||
"E name objectid objectid - set deh_objectid of an entry to objectid\n");
|
||||
|
||||
continue;
|
||||
|
||||
case 'P':
|
||||
print_block (stderr, fs, bh, 3, -1, -1);
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
/* corrupt hash record in super block */
|
||||
if (sscanf (line, "%c %d\n", &code, &hash_code) != 2) {
|
||||
printf ("Wrong format \'%c\'\n", line [0]);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'C': /* cut entry */
|
||||
case 'H': /* make hash wrong */
|
||||
if (sscanf (line, "%c %s %u\n", &code, name, &objectid) != 3) {
|
||||
printf ("Wrong format \'%c\'\n", line [0]);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'T': /* set type of item */
|
||||
if (sscanf (line, "%c %d %d %d\n", &code, &item_num, &type, &format) != 4) {
|
||||
printf ("Wrong format \'%c\'\n", line [0]);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'J': /* set objectid : used to simulate objectid sharing problem */
|
||||
if (sscanf (line, "%c %d %d\n", &code, &item_num, &objectid) != 3) {
|
||||
printf ("Wrong format \'%c\'\n", line [0]);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'E': /* set objectid : used to simulate objectid sharing problem */
|
||||
if (sscanf (line, "%c %s %u %d\n", &code, name, &objectid, &new_objectid) != 4) {
|
||||
printf ("Wrong format \'%c\'\n", line [0]);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'I': /* break unformatted node pointer */
|
||||
if (sscanf (line, "%c %d %d\n", &code, &item_num, &pos_in_item) != 3) {
|
||||
printf ("Wrong format \'%c\'\n", line [0]);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'D': /* delete item */
|
||||
case 'O': /* make item out of order */
|
||||
if (sscanf (line, "%c %d\n", &code, &item_num) != 2) {
|
||||
printf ("Wrong format \'%c\'\n", line [0]);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'S': /* corrupt st_size */
|
||||
case 'F': /* st_first_direct_byte */
|
||||
if (sscanf (line, "%c %d %d\n", &code, &item_num, &value) != 3) {
|
||||
printf ("Wrong format \'%c\'\n", line [0]);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (code == 'A') {
|
||||
reiserfs_warning (stderr, "Changing %s to %s\n", code2name (get_sb_hash_code (fs->fs_ondisk_sb)),
|
||||
code2name (hash_code));
|
||||
set_sb_hash_code (fs->fs_ondisk_sb, hash_code);
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
continue;
|
||||
}
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < get_blkh_nr_items (B_BLK_HEAD (bh)); i ++, ih ++) {
|
||||
struct reiserfs_de_head * deh;
|
||||
|
||||
if (code == 'T' && i == item_num) {
|
||||
set_ih_key_format (ih, format);
|
||||
set_type (format, &ih->ih_key, type);
|
||||
mark_buffer_dirty (bh);
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (code == 'I' && i == item_num) {
|
||||
if (!is_indirect_ih (ih) || pos_in_item >= I_UNFM_NUM (ih)) {
|
||||
reiserfs_warning (stderr, "Not an indirect item or there is "
|
||||
"not so many unfm ptrs in it\n");
|
||||
continue;
|
||||
}
|
||||
* ((__u32 *)B_I_PITEM (bh, ih) + pos_in_item) = get_sb_block_count (fs->fs_ondisk_sb) + 100;
|
||||
mark_buffer_dirty (bh);
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (code == 'J' && i == item_num) {
|
||||
set_key_objectid (&ih->ih_key, objectid);
|
||||
mark_buffer_dirty (bh);
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (code == 'S' && i == item_num) {
|
||||
/* fixme: old stat data only */
|
||||
struct stat_data_v1 * sd;
|
||||
|
||||
sd = (struct stat_data_v1 *)B_I_PITEM (bh, ih);
|
||||
reiserfs_warning (stderr, "Changing sd_size of %k from %d to %d\n",
|
||||
&ih->ih_key, sd_v1_size(sd), value);
|
||||
set_sd_v1_size( sd, value );
|
||||
mark_buffer_dirty (bh);
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (code == 'F' && i == item_num) {
|
||||
/* fixme: old stat data only */
|
||||
struct stat_data_v1 * sd;
|
||||
|
||||
sd = (struct stat_data_v1 *)B_I_PITEM (bh, ih);
|
||||
reiserfs_warning (stderr, "Changing sd_first_direct_byte of %k from %d to %d\n",
|
||||
&ih->ih_key, sd_v1_first_direct_byte(sd), value);
|
||||
set_sd_v1_first_direct_byte( sd, value );
|
||||
mark_buffer_dirty (bh);
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (code == 'D' && i == item_num) {
|
||||
delete_item (fs, bh, item_num);
|
||||
mark_buffer_dirty (bh);
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (code == 'O' && i == item_num) {
|
||||
/* destroy item order */
|
||||
struct key * key;
|
||||
if (i == get_blkh_nr_items (B_BLK_HEAD (bh)) - 1) {
|
||||
printf ("can not destroy order\n");
|
||||
continue;
|
||||
}
|
||||
key = &(ih + 1)->ih_key;
|
||||
set_key_dirid (&ih->ih_key, get_key_dirid (key) + 1);
|
||||
mark_buffer_dirty (bh);
|
||||
}
|
||||
|
||||
if (get_key_objectid (&ih->ih_key) != objectid || !is_direntry_ih (ih))
|
||||
continue;
|
||||
|
||||
deh = B_I_DEH (bh, ih);
|
||||
|
||||
for (j = 0; j < get_ih_entry_count (ih); j ++, deh ++) {
|
||||
/* look for proper entry */
|
||||
if (name_in_entry_length (ih, deh, j) != strlen (name) ||
|
||||
strncmp (name, name_in_entry (deh, j), strlen (name)))
|
||||
continue;
|
||||
|
||||
/* ok, required entry found, make a corruption */
|
||||
switch (code) {
|
||||
case 'C': /* cut entry */
|
||||
cut_entry (fs, bh, i, j, 1);
|
||||
mark_buffer_dirty (bh);
|
||||
|
||||
if (!B_IS_IN_TREE (bh)) {
|
||||
printf ("NOTE: block is deleted from the tree\n");
|
||||
exit (0);
|
||||
}
|
||||
goto cont;
|
||||
break;
|
||||
|
||||
case 'H': /* clobber hash */
|
||||
corrupt_clobber_hash (name, ih, deh);
|
||||
goto cont;
|
||||
break;
|
||||
|
||||
case 'E': /* change entry's deh_objectid */
|
||||
set_deh_objectid (deh, new_objectid);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("Unknown command found\n");
|
||||
}
|
||||
mark_buffer_dirty (bh);
|
||||
}
|
||||
}
|
||||
cont:
|
||||
}
|
||||
free (line);
|
||||
printf ("Done\n");
|
||||
brelse (bh);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
.\" -*- nroff -*-
|
||||
.\" Copyright 1996-2001 Hans Reiser.
|
||||
.\" Copyright 1996-2002 Hans Reiser.
|
||||
.\"
|
||||
.TH DEBUGREISERFS 8 "March 2001" "Reiserfsprogs 3.x.0j"
|
||||
.TH DEBUGREISERFS 8 "January 2002" "Reiserfsprogs 3.6.2"
|
||||
.SH NAME
|
||||
debugreiserfs
|
||||
.SH SYNOPSIS
|
||||
.B debugreiserfs
|
||||
[
|
||||
.B -jdcmos
|
||||
.B -dJmoqpS
|
||||
] [
|
||||
.B -b \fIblocknumber
|
||||
.B -j \fIdevice
|
||||
] [
|
||||
.B -p \fIfilename.bmp
|
||||
] [
|
||||
.B -P \fIfilename.bmp
|
||||
.B -B \fIblocknumber
|
||||
]
|
||||
|
||||
.\" ] [
|
||||
.\" .B -s
|
||||
.\" ] [
|
||||
.I device
|
||||
.SH DESCRIPTION
|
||||
It helps sometimes to solve problems with reiserfs filesystems. Being
|
||||
@@ -26,43 +28,54 @@ is the special file corresponding to the device (e.g /dev/hdXX for
|
||||
IDE disk partition or /dev/sdXX for SCSI disk partition).
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB-j
|
||||
print contents of journal
|
||||
\fB-j\fR \fIdevice\fR
|
||||
print contents of journal. Also with the option -p it allows to pack
|
||||
journal into archive with other metadata
|
||||
.TP
|
||||
\fB-d
|
||||
\fB-J\fR
|
||||
print journal header.
|
||||
.TP
|
||||
.B -d
|
||||
print formatted nodes of the filesystem
|
||||
.TP
|
||||
\fB-c
|
||||
print contents of direct items
|
||||
.TP
|
||||
\fB-m
|
||||
.B -m
|
||||
print contents of bitmap (not very useful)
|
||||
.TP
|
||||
\fB-o
|
||||
.B -o
|
||||
print objectid map (not very useful)
|
||||
.TP
|
||||
\fB-s
|
||||
scans the partition and prints a line when any kind of reiserfs formatted nodes found
|
||||
.TP
|
||||
\fB-b \fIblocknumber
|
||||
\fB-1\fR \fIblocknumber\fR
|
||||
print specified block of the filesystem
|
||||
.TP
|
||||
\fB-p \fIfilename
|
||||
\fB-P \fIfilename
|
||||
|
||||
Makes \fBdebugreiserfs\fR to find filesystem metadata
|
||||
These exist to help reiserfsck debugging. If reiserfsck fails -
|
||||
you may extract filesystem metadata with \fBdebugreiserfs\fR -p filename /dev/xxx |gzip
|
||||
-c > xxx.gz. We download that data and make the filesystem similar
|
||||
to your with gunzip -c xxx.gz | unpack /dev/xxx (unpack is included
|
||||
into reiserfsprogs package). This usually allows to reproduce and
|
||||
debug the problem quickly. When data file is not too large.
|
||||
-P will cause \fBdebugreiserfs\fR to find and pack metadata from all the device whereas with -p it will only go through blocks marked used in filesystem bitmaps
|
||||
|
||||
.\" \fB-s
|
||||
.\" scans the partition and prints a line when any kind of reiserfs
|
||||
.\" formatted nodes found. Can be used to find specific key in the filesystem.
|
||||
.\" .TP
|
||||
.B -p
|
||||
Makes \fBdebugreiserfs\fR to find filesystem metadata This option
|
||||
exists to help reiserfsck debugging. If reiserfsck fails - you may
|
||||
extract filesystem metadata with \fBdebugreiserfs\fR -p
|
||||
/dev/xxx |gzip -c > xxx.gz. We download that data and make the
|
||||
filesystem similar to your with gunzip -c xxx.gz | unpack /dev/xxx
|
||||
(unpack is included into reiserfsprogs package). This usually allows
|
||||
to reproduce and debug the problem quickly. When data file is not too
|
||||
large.
|
||||
.TP
|
||||
.B -S
|
||||
When -S is not specified -p
|
||||
.\" and -s
|
||||
deals with blocks marked used in the
|
||||
filesystem bitmap. With this option set they will work with whole
|
||||
device.
|
||||
.TP
|
||||
.B -q
|
||||
Suppress showing speed of progress when
|
||||
.\" -s or
|
||||
-p is in use
|
||||
.SH AUTHOR
|
||||
This version of \fBdebugreiserfs\fR has been written by Hans Reiser <reiser@idiom.com>.
|
||||
.SH BUGS
|
||||
There are probably few of them. Please, report bugs to Hans Reiser <reiser@idiom.com>.
|
||||
There are probably few of them. Please, report bugs to ReiserFS mail-list <reiserfs-list@namesys.com>.
|
||||
.SH SEE ALSO
|
||||
.BR reiserfsck (8),
|
||||
.BR mkreiserfs (8)
|
||||
+401
-868
File diff suppressed because it is too large.
Load diff
+170
-47
@@ -1,8 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
@@ -18,25 +19,40 @@
|
||||
#include "io.h"
|
||||
#include "misc.h"
|
||||
#include "reiserfs_lib.h"
|
||||
#include "../include/config.h"
|
||||
#include "../version.h"
|
||||
|
||||
extern reiserfs_filsys_t * fs;
|
||||
|
||||
|
||||
/*
|
||||
* modes
|
||||
*/
|
||||
#define DO_DUMP 1 /* not a real dump, just printing to stdout contents of
|
||||
tree nodes */
|
||||
#define DO_CORRUPT 2 /* used to make filesystem corruption and then test fsck */
|
||||
#define DO_SCAN 3
|
||||
#define DO_SCAN_FOR_NAME 4
|
||||
#define DO_RECOVER 5
|
||||
#define DO_TEST 6
|
||||
#define DO_PACK 7 /* -p extract meta data of reiserfs filesystem */
|
||||
#define DO_PACK_ALL 8 /* -p */
|
||||
#define DO_DUMP 1 /* not a real dump, just printing to stdout contents of
|
||||
tree nodes */
|
||||
#define DO_CORRUPT 2 /* used to make filesystem corruption and then test fsck */
|
||||
#define DO_SCAN 3
|
||||
#define DO_RECOVER 4
|
||||
#define DO_TEST 6
|
||||
#define DO_PACK 7 /* -p extract meta data of reiserfs filesystem */
|
||||
#define DO_STAT 8
|
||||
#define DO_SCAN_FOR_NAME 9 /* -n */
|
||||
#define DO_LOOK_FOR_NAME 10 /* -N */
|
||||
#define DO_SCAN_JOURNAL 11 /* -J */
|
||||
#define DO_EXTRACT_BADBLOCKS 12
|
||||
|
||||
extern int opt_quiet;
|
||||
extern int mode;
|
||||
/*first bits are in reiserfs_fs.b*/
|
||||
#define PRINT_JOURNAL 0x10
|
||||
#define PRINT_JOURNAL_HEADER 0x20
|
||||
#define PRINT_BITMAP 0x40
|
||||
#define PRINT_OBJECTID_MAP 0x80
|
||||
#define BE_QUIET 0x100
|
||||
|
||||
/* these moved to reiserfs_fs.h */
|
||||
//#define PRINT_TREE_DETAILS
|
||||
//#define PRINT_DETAILS
|
||||
//#define PRINT_ITEM_DETAILS
|
||||
//#define PRINT_DIRECT_ITEMS
|
||||
|
||||
|
||||
// the leaf is stored in compact form:
|
||||
@@ -48,7 +64,7 @@ extern int mode;
|
||||
// end magic number
|
||||
|
||||
/* we store hash code in high byte of 16 bits */
|
||||
#define LEAF_START_MAGIC 0xa5
|
||||
#define LEAF_START_MAGIC 0xa6
|
||||
#define LEAF_END_MAGIC 0x5a
|
||||
|
||||
|
||||
@@ -60,76 +76,183 @@ extern int mode;
|
||||
#define END_MAGIC 0x8d
|
||||
#define INTERNAL_START_MAGIC
|
||||
#define INTERNAL_START_MAGIC
|
||||
|
||||
#define SEPARATED_JOURNAL_START_MAGIC 0xf8
|
||||
#define SEPARATED_JOURNAL_END_MAGIC 0x8f
|
||||
|
||||
#define ITEM_START_MAGIC 0x476576
|
||||
#define ITEM_END_MAGIC 0x2906504
|
||||
|
||||
/* flags in packed item mask */
|
||||
#define NEW_FORMAT 1 // 0 here means - old format, 1 - new format
|
||||
#define DIR_ID 2
|
||||
#define OBJECT_ID 4
|
||||
#define OFFSET_BITS_32 8
|
||||
#define OFFSET_BITS_64 16
|
||||
#define ENTRY_COUNT 32 // shows whether ih_free_space/ih_entry_count is stored
|
||||
#define MAP_MAGIC 0xe9
|
||||
#define MAP_END_MAGIC 0x9e
|
||||
|
||||
#define INDIRECT_ITEM 64
|
||||
#define DIRENTRY_ITEM 128
|
||||
#define DIRECT_ITEM 256
|
||||
#define STAT_DATA_ITEM 512
|
||||
|
||||
#define ITEM_BODY 1024
|
||||
#define WHOLE_INDIRECT 128
|
||||
#define WITH_SD_FIRST_DIRECT_BYTE 8192 /* for old stat data first_direct_byte
|
||||
is stored */
|
||||
#define NLINK_BITS_32 8192 /* nlinks stored in 32 bits */
|
||||
#define SIZE_BITS_64 16384 /* size has to be stored in 64 bit */
|
||||
/* 12 bits of mask are used to define */
|
||||
#define NEW_FORMAT 0x01 /* 1. 0 here means - old format, 1 - new format */
|
||||
#define DIR_ID 0x02 /* 2. dir_id is stored */
|
||||
#define OBJECT_ID 0x04 /* 3. objectid is stored */
|
||||
#define OFFSET_BITS_32 0x08 /* 4. offset is stored as 32 bit */
|
||||
#define OFFSET_BITS_64 0x10 /* 5. offset is stored as 64 bit */
|
||||
#define IH_ENTRY_COUNT 0x20 /* 6. ih_free_space/ih_entry_count is stored */
|
||||
#define IH_FREE_SPACE 0x20
|
||||
#define IH_FORMAT 0x40 /* 7. ih_format is stored */
|
||||
#define WITH_SD_FIRST_DIRECT_BYTE 0x80 /* 8. for old stat data first_direct_byte is stored */
|
||||
#define NLINK_BITS_32 0x0100 /* 9. nlinks stored in 32 bits */
|
||||
#define SIZE_BITS_64 0x0200 /* 10. size has to be stored in 64 bit */
|
||||
#define WHOLE_INDIRECT 0x0400 /* 11. indirect item is stored with compression */
|
||||
#define SAFE_LINK 0x0800 /* 11. indirect item is stored with compression */
|
||||
|
||||
|
||||
#define TYPE_MASK 0x3 /* two lowest bits are used to store item type */
|
||||
//#define MASK_MASK 0xffffc /* what is packed: dirid, objectid, etc */
|
||||
#define ITEM_LEN_MASK 0xfff00000 /* contents of ih_item_len of item_head */
|
||||
|
||||
struct packed_item {
|
||||
/*__u16 length;*/ // length of the area we store item in
|
||||
__u16 mask; // what is stored: dirid, objectid, 32 bit offset or 64 bit offset, type
|
||||
__u16 item_len;
|
||||
__u32 type_2_mask_18_len_12;
|
||||
};
|
||||
|
||||
#define HAS_DIR_ID 1
|
||||
#define HAS_GEN_COUNTER 2
|
||||
#define HAS_STATE 4
|
||||
#define YURA 8
|
||||
#define TEA 16
|
||||
#define R5 32
|
||||
|
||||
/* defined as inlines in both pack.c and unpack.c */
|
||||
inline void set_pi_type( struct packed_item *pi, __u32 val );
|
||||
inline __u32 get_pi_type( const struct packed_item *pi );
|
||||
inline void set_pi_mask( struct packed_item *pi, __u32 val );
|
||||
inline __u32 get_pi_mask( const struct packed_item *pi );
|
||||
inline void set_pi_item_len( struct packed_item *pi, __u32 val );
|
||||
inline __u32 get_pi_item_len( const struct packed_item *pi );
|
||||
|
||||
|
||||
#define HAS_DIR_ID 0x01
|
||||
#define HAS_GEN_COUNTER 0x02
|
||||
#define HAS_STATE 0x04
|
||||
#define YURA 0x08
|
||||
#define TEA 0x10
|
||||
#define R5 0x20
|
||||
|
||||
struct packed_dir_entry {
|
||||
__u8 mask;
|
||||
__u16 entrylen;
|
||||
};
|
||||
|
||||
/* packed_dir_entry.mask is *always* endian safe, since it's 8 bit */
|
||||
#define get_pe_entrylen(pe) (le16_to_cpu((pe)->entrylen))
|
||||
#define set_pe_entrylen(pe,v) ((pe)->entrylen = cpu_to_le16(v))
|
||||
|
||||
|
||||
#define fread8(pv) fread (pv, sizeof (__u8), 1, stdin)
|
||||
|
||||
#define fread_le16(pv)\
|
||||
{\
|
||||
__u16 tmp; \
|
||||
fread16(&tmp); \
|
||||
*pv = le16_to_cpu(tmp); \
|
||||
}
|
||||
|
||||
#define fread_le32(pv)\
|
||||
{\
|
||||
__u32 tmp; \
|
||||
fread32(&tmp); \
|
||||
*pv = le32_to_cpu(tmp); \
|
||||
}
|
||||
|
||||
#define fread_le64(pv)\
|
||||
{\
|
||||
__u64 tmp; \
|
||||
fread64(&tmp); \
|
||||
*pv = le64_to_cpu(tmp); \
|
||||
}
|
||||
|
||||
|
||||
#define fread8(pv) fread (pv, sizeof (__u8), 1, stdin)
|
||||
#define fread16(pv) fread (pv, sizeof (__u16), 1, stdin)
|
||||
#define fread32(pv) fread (pv, sizeof (__u32), 1, stdin)
|
||||
#define fread64(pv) fread (pv, sizeof (__u64), 1, stdin)
|
||||
|
||||
|
||||
#define fwrite_le16(pv)\
|
||||
{\
|
||||
__u16 tmp = cpu_to_le16(*(pv));\
|
||||
fwrite16(&tmp);\
|
||||
}
|
||||
|
||||
#define fwrite_le32(pv)\
|
||||
{\
|
||||
__u32 tmp = cpu_to_le32(*(pv));\
|
||||
fwrite32(&tmp);\
|
||||
}
|
||||
|
||||
#define fwrite_le64(pv)\
|
||||
{\
|
||||
__u64 tmp = cpu_to_le64(*(pv));\
|
||||
fwrite64(&tmp);\
|
||||
}
|
||||
|
||||
#define fwrite8(pv) {\
|
||||
if (fwrite (pv, sizeof (__u8), 1, stdout) != 1)\
|
||||
reiserfs_panic ("fwrite8 failed: %m");\
|
||||
sent_bytes ++;\
|
||||
}
|
||||
#define fwrite16(pv) {\
|
||||
if (fwrite (pv, sizeof (__u16), 1, stdout) != 1)\
|
||||
reiserfs_panic ("fwrite16 failed: %m");\
|
||||
sent_bytes += 2;\
|
||||
}
|
||||
#define fwrite32(pv) {\
|
||||
if (fwrite (pv, sizeof (__u32), 1, stdout) != 1)\
|
||||
reiserfs_panic ("fwrite32 failed: %m");\
|
||||
sent_bytes += 4;\
|
||||
}
|
||||
#define fwrite64(pv) {\
|
||||
if (fwrite (pv, sizeof (__u64), 1, stdout) != 1)\
|
||||
reiserfs_panic ("fwrite64 failed: %m");\
|
||||
sent_bytes += 8;\
|
||||
}
|
||||
/*
|
||||
#define fwrite16(pv) fwrite (pv, sizeof (__u16), 1, stdout)
|
||||
#define fwrite32(pv) fwrite (pv, sizeof (__u32), 1, stdout)
|
||||
#define fwrite64(pv) fwrite (pv, sizeof (__u64), 1, stdout)
|
||||
*/
|
||||
|
||||
|
||||
#define BLOCKS_PER_READ 8
|
||||
extern char * where_to_save;
|
||||
struct debugreiserfs_data {
|
||||
int mode; /* DO_DUMP | DO_PACK | DO_CORRUPT... */
|
||||
#define USED_BLOCKS 1
|
||||
#define EXTERN_BITMAP 2
|
||||
#define ALL_BLOCKS 3
|
||||
#define UNUSED_BLOCKS 4
|
||||
|
||||
int scan_area; /* for -p, -s and -n */
|
||||
char * input_bitmap; /* when ->scan_area is set to EXTERN_BITMAP */
|
||||
reiserfs_bitmap_t * bitmap; /* bitmap is read from ->input_bitmap */
|
||||
unsigned long block; /* set by -B. this is a must for -C, option for -p and -d */
|
||||
char * pattern; /* for -n */
|
||||
char * device_name;
|
||||
char * journal_device_name; /* for -j */
|
||||
char * map_file; /* for -n, -N and -r */
|
||||
|
||||
unsigned long options; /* -q only yet*/
|
||||
int JJ;
|
||||
};
|
||||
|
||||
#define data(fs) ((struct debugreiserfs_data *)((fs)->fs_vp))
|
||||
|
||||
#define debug_mode(fs) (data(fs)->mode)
|
||||
#define certain_block(fs) (data(fs)->block)
|
||||
#define input_bitmap(fs) (data(fs)->bitmap)
|
||||
#define input_bitmap_file_name(fs) (data(fs)->input_bitmap)
|
||||
#define scan_area(fs) (data(fs)->scan_area)
|
||||
#define name_pattern(fs) (data(fs)->pattern)
|
||||
#define device_name(fs) (data(fs)->device_name)
|
||||
#define journal_device_name(fs) (data(fs)->journal_device_name)
|
||||
#define map_file(fs) (data(fs)->map_file)
|
||||
|
||||
|
||||
#define be_quiet(fs) (data(fs)->options & BE_QUIET)
|
||||
|
||||
/* stat.c */
|
||||
void do_stat (reiserfs_filsys_t * fs);
|
||||
|
||||
/* corruption.c */
|
||||
void do_corrupt_one_block (reiserfs_filsys_t * fs);
|
||||
|
||||
/* recover.c */
|
||||
void do_recover (reiserfs_filsys_t * fs);
|
||||
|
||||
/* scan.c */
|
||||
void do_scan (reiserfs_filsys_t * fs);
|
||||
|
||||
/* journal.c */
|
||||
void scan_journal (reiserfs_filsys_t * fs);
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright 2002 Hans Reiser
|
||||
*/
|
||||
|
||||
#include "debugreiserfs.h"
|
||||
|
||||
|
||||
extern unsigned long * badblocks;
|
||||
extern int badblocks_nr;
|
||||
|
||||
#if 0
|
||||
static void look_in_transaction (reiserfs_filsys_t * fs,
|
||||
reiserfs_trans_t * trans)
|
||||
{
|
||||
struct buffer_head * d_bh, * c_bh, * logged, * in_place;
|
||||
struct reiserfs_journal_desc * desc;
|
||||
struct reiserfs_journal_commit * commit;
|
||||
int i, j;
|
||||
int who;
|
||||
|
||||
|
||||
d_bh = bread (fs->fs_dev, trans->desc_blocknr, fs->fs_blocksize);
|
||||
if (!d_bh) {
|
||||
reiserfs_warning (stdout, "reading descriptor block %lu failed\n",
|
||||
trans->desc_blocknr);
|
||||
return;
|
||||
}
|
||||
|
||||
c_bh = bread (fs->fs_dev, trans->commit_blocknr, fs->fs_blocksize);
|
||||
if (!c_bh) {
|
||||
reiserfs_warning (stdout, "reading commit block %lu failed\n",
|
||||
trans->commit_blocknr);
|
||||
brelse (d_bh);
|
||||
return;
|
||||
}
|
||||
|
||||
// desc = (struct reiserfs_journal_desc *)(d_bh->b_data);
|
||||
// commit = (struct reiserfs_journal_commit *)(c_bh->b_data);
|
||||
|
||||
reiserfs_warning (stdout, "Transaction %lu\n", trans->trans_id);
|
||||
|
||||
for (i = 0; i < badblocks_nr; i ++) {
|
||||
for (j = 0; j < get_jd_len (d_bh); j ++) {
|
||||
if ((j < JOURNAL_TRANS_HALF && badblocks [i] == le32_to_cpu (desc->j2_realblock[j])) ||
|
||||
(j >= JOURNAL_TRANS_HALF && badblocks [i] == le32_to_cpu (commit->j3_realblock[j - JOURNAL_TRANS_HALF]))) {
|
||||
reiserfs_warning (stdout,
|
||||
"\tblock %lu is logged in it (block of journal area %lu - ",
|
||||
badblocks [i], d_bh->b_blocknr + j + 1);
|
||||
|
||||
logged = 0;
|
||||
in_place = 0;
|
||||
|
||||
logged = bread (fs->fs_dev, d_bh->b_blocknr + j + 1, fs->fs_blocksize);
|
||||
in_place = bread (fs->fs_dev, badblocks [i], fs->fs_blocksize);
|
||||
if (!logged || !in_place) {
|
||||
reiserfs_warning (stdout, "Could not read blocks\n");
|
||||
brelse (logged);
|
||||
brelse (in_place);
|
||||
continue;
|
||||
}
|
||||
|
||||
who = who_is_this (logged->b_data, logged->b_size);
|
||||
if (who != THE_LEAF && who != HAS_IH_ARRAY) {
|
||||
brelse (logged);
|
||||
brelse (in_place);
|
||||
continue;
|
||||
}
|
||||
|
||||
reiserfs_warning (stdout, "%s\n", which_block (who));
|
||||
if (data (fs)->JJ > 1) {
|
||||
/* overwrite in-place block with a logged version */
|
||||
if (who_is_this (in_place->b_data, in_place->b_size) == THE_LEAF)
|
||||
reiserfs_warning (stderr, "Block %d is leaf already, skip it\n",
|
||||
in_place->b_blocknr);
|
||||
else {
|
||||
memcpy (in_place->b_data, logged->b_data, fs->fs_blocksize);
|
||||
mark_buffer_dirty (in_place);
|
||||
bwrite (in_place);
|
||||
if (input_bitmap (fs))
|
||||
reiserfs_bitmap_set_bit (input_bitmap (fs), in_place->b_blocknr);
|
||||
}
|
||||
}
|
||||
|
||||
brelse (logged);
|
||||
brelse (in_place);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
brelse (d_bh);
|
||||
brelse (c_bh);
|
||||
}
|
||||
|
||||
/* go through all transactions in the journal to check whether block is there */
|
||||
static void find_in_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
for_each_transaction (fs, look_in_transaction);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define BLOCK_IN_Q 12762
|
||||
|
||||
static void check_block_9555 (reiserfs_filsys_t * fs, reiserfs_trans_t * trans,
|
||||
int index,
|
||||
unsigned long in_journal, unsigned long in_place)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
|
||||
|
||||
if (in_place == 17) {
|
||||
/* read block of journal which contains block 17 abd check whether bit
|
||||
BLOCK_IN_Q is set */
|
||||
bh = bread (fs->fs_journal_dev, in_journal, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "could not read block %lu (of journal area)\n",
|
||||
in_journal);
|
||||
return;
|
||||
}
|
||||
|
||||
if (test_bit (BLOCK_IN_Q, bh->b_data))
|
||||
reiserfs_warning (stdout, "trans %lu, pos %d - block 17: block %d is marked used in it\n",
|
||||
trans->trans_id, index, BLOCK_IN_Q);
|
||||
else
|
||||
reiserfs_warning (stdout, "trans %lu, pos %d - block 17: block %d is marked free in it\n",
|
||||
trans->trans_id, index, BLOCK_IN_Q);
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
if (in_place == BLOCK_IN_Q) {
|
||||
reiserfs_warning (stdout, "trans %lu, block %d is logged at pos %d\n",
|
||||
trans->trans_id, BLOCK_IN_Q, index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* remove when the problem is found */
|
||||
static void check_transaction (reiserfs_filsys_t * fs, reiserfs_trans_t * trans)
|
||||
{
|
||||
for_each_block (fs, trans, check_block_9555);
|
||||
}
|
||||
|
||||
|
||||
void scan_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
for_each_transaction (fs, check_transaction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
/* read block numbers from stdin, look for them in the journal, and (if -JJ is
|
||||
given) write then "in-place" amd mark overwritten blocks used in the bitmap
|
||||
specified with -b */
|
||||
void scan_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
char * str = 0;
|
||||
size_t n = 0;
|
||||
|
||||
|
||||
/* store all blocks which come from stdin */
|
||||
while (1) {
|
||||
if (getline (&str, &n, stdin) == -1)
|
||||
break;
|
||||
if (!strcmp (str, "\n"))
|
||||
break;
|
||||
str [strlen (str) - 1] = 0;
|
||||
|
||||
badblocks = realloc (badblocks, (badblocks_nr + 1) * 4);
|
||||
if (!badblocks)
|
||||
reiserfs_panic ("realloc failed");
|
||||
badblocks [badblocks_nr ++] = atol (str);
|
||||
|
||||
free (str);
|
||||
str = 0;
|
||||
n = 0;
|
||||
}
|
||||
|
||||
if (data (fs)->JJ > 1)
|
||||
reiserfs_reopen (fs, O_RDWR);
|
||||
reiserfs_warning (stdout, "%d blocks given\n", badblocks_nr); fflush (stdout);
|
||||
find_in_journal (fs);
|
||||
|
||||
if (data (fs)->JJ > 1 && input_bitmap (fs)) {
|
||||
FILE * fp;
|
||||
|
||||
fp = fopen (input_bitmap_file_name (fs), "w+");
|
||||
if (!fp) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_save: could not save bitmap in %s: %m",
|
||||
input_bitmap_file_name (fs));
|
||||
return;
|
||||
}
|
||||
reiserfs_bitmap_save (fp, input_bitmap (fs));
|
||||
fclose (fp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+341
-276
@@ -1,66 +1,123 @@
|
||||
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#include "debugreiserfs.h"
|
||||
|
||||
|
||||
|
||||
/* counters for each kind of blocks */
|
||||
int packed,
|
||||
packed_leaves,
|
||||
full_blocks,
|
||||
having_ih_array, /* blocks with broken block head */
|
||||
bad_leaves, /* failed to compress */
|
||||
internals,
|
||||
descs,
|
||||
others;
|
||||
|
||||
|
||||
reiserfs_bitmap_t what_to_pack;
|
||||
reiserfs_bitmap_t what_packed;
|
||||
|
||||
int packed_leaves, bad_leaves, full_blocks, internals, descs, full_of_journal;
|
||||
|
||||
reiserfs_bitmap_t * what_to_pack;
|
||||
|
||||
/* these are to calculate compression */
|
||||
unsigned long sent; /* how many bytes sent to stdout */
|
||||
unsigned long sent_bytes; /* how many bytes sent to stdout */
|
||||
unsigned long had_to_be_sent; /* how many bytes were to be sent */
|
||||
|
||||
|
||||
|
||||
static void pack_key (struct packed_item * pi, struct item_head * ih)
|
||||
inline void set_pi_type( struct packed_item *pi, __u32 val )
|
||||
{
|
||||
if (pi->mask & DIR_ID) {
|
||||
fwrite32 (&ih->ih_key.k_dir_id);
|
||||
sent += sizeof (__u32);
|
||||
set_bit_field_XX (32, pi, val, 0, 2);
|
||||
}
|
||||
|
||||
|
||||
inline __u32 get_pi_type( const struct packed_item *pi )
|
||||
{
|
||||
get_bit_field_XX (32, pi, 0, 2);
|
||||
}
|
||||
|
||||
|
||||
inline void set_pi_mask( struct packed_item *pi, __u32 val )
|
||||
{
|
||||
set_bit_field_XX (32, pi, val, 2, 18);
|
||||
}
|
||||
|
||||
|
||||
__u32 get_pi_mask( const struct packed_item *pi )
|
||||
{
|
||||
get_bit_field_XX (32, pi, 2, 18);
|
||||
}
|
||||
|
||||
|
||||
inline void set_pi_item_len( struct packed_item *pi, __u32 val )
|
||||
{
|
||||
set_bit_field_XX (32, pi, val, 20, 12);
|
||||
}
|
||||
|
||||
|
||||
inline __u32 get_pi_item_len( const struct packed_item *pi )
|
||||
{
|
||||
get_bit_field_XX (32, pi, 20, 12);
|
||||
}
|
||||
|
||||
|
||||
static void pack_ih (struct packed_item * pi, struct item_head * ih)
|
||||
{
|
||||
__u32 v32;
|
||||
__u16 v16;
|
||||
|
||||
/* send packed item head first */
|
||||
fwrite (pi, sizeof (*pi), 1, stdout);
|
||||
sent_bytes += sizeof (*pi);
|
||||
|
||||
/* sen key components which are to be sent */
|
||||
if (get_pi_mask(pi) & DIR_ID) {
|
||||
v32 = get_key_dirid (&ih->ih_key);
|
||||
fwrite_le32 (&v32);
|
||||
}
|
||||
|
||||
if (pi->mask & OBJECT_ID) {
|
||||
fwrite32 (&ih->ih_key.k_objectid);
|
||||
sent += sizeof (__u32);
|
||||
if (get_pi_mask(pi) & OBJECT_ID) {
|
||||
v32 = get_key_objectid (&ih->ih_key);
|
||||
fwrite_le32 (&v32);
|
||||
}
|
||||
|
||||
if (pi->mask & OFFSET_BITS_64) {
|
||||
if (get_pi_mask(pi) & OFFSET_BITS_64) {
|
||||
__u64 offset;
|
||||
|
||||
offset = get_offset (&ih->ih_key);
|
||||
fwrite64 (&offset);
|
||||
sent += sizeof (__u64);
|
||||
fwrite_le64 (&offset);
|
||||
}
|
||||
|
||||
if (pi->mask & OFFSET_BITS_32) {
|
||||
if (get_pi_mask(pi) & OFFSET_BITS_32) {
|
||||
__u32 offset;
|
||||
|
||||
offset = get_offset (&ih->ih_key);
|
||||
fwrite32 (&offset);
|
||||
sent += sizeof (__u32);
|
||||
fwrite_le32 (&offset);
|
||||
}
|
||||
|
||||
if (get_pi_mask(pi) & IH_FREE_SPACE) {
|
||||
v16 = get_ih_entry_count (ih);
|
||||
fwrite_le16 (&v16);
|
||||
}
|
||||
|
||||
if (get_pi_mask(pi) & IH_FORMAT) {
|
||||
/* fixme */
|
||||
fwrite16 (&ih->ih_format);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void pack_direct (struct packed_item * pi, struct buffer_head * bh,
|
||||
struct item_head * ih)
|
||||
struct item_head * ih)
|
||||
{
|
||||
pi->mask |= DIRECT_ITEM;
|
||||
if (get_ih_free_space (ih) != 0xffff)
|
||||
/* ih_free_space has unexpected value */
|
||||
set_pi_mask (pi, get_pi_mask (pi) | IH_FREE_SPACE);
|
||||
|
||||
/* send packed item header to stdout */
|
||||
fwrite (pi, sizeof (*pi), 1, stdout);
|
||||
sent += sizeof (*pi);
|
||||
if (get_pi_mask(pi) & SAFE_LINK)
|
||||
set_key_dirid(&ih->ih_key, le32_to_cpu(*(__u32 *)B_I_PITEM (bh, ih)) );
|
||||
|
||||
/* send key components which are to be sent */
|
||||
pack_key (pi, ih);
|
||||
pack_ih (pi, ih);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +127,8 @@ static int should_pack_indirect (__u32 * ind_item, int unfm_num)
|
||||
int i, len;
|
||||
|
||||
for (i = 1, len = 1; i < unfm_num; i ++) {
|
||||
if ((!ind_item [i] && !ind_item [i - 1]) || /* hole continues */
|
||||
ind_item [i] == ind_item [i - 1] + 1) { /* subsequent blocks */
|
||||
if ((ind_item [i] == 0 && ind_item [i - 1] == 0) || /* hole continues */
|
||||
le32_to_cpu (ind_item [i]) == le32_to_cpu (ind_item [i - 1]) + 1) { /* subsequent blocks */
|
||||
len ++;
|
||||
if (len > 2)
|
||||
return 1;
|
||||
@@ -94,50 +151,42 @@ static void pack_indirect (struct packed_item * pi, struct buffer_head * bh,
|
||||
__u32 * ind_item;
|
||||
__u16 len;
|
||||
|
||||
pi->mask |= INDIRECT_ITEM;
|
||||
if (ih_entry_count (ih))
|
||||
pi->mask |= ENTRY_COUNT;
|
||||
|
||||
if (get_ih_entry_count (ih))
|
||||
set_pi_mask (pi, get_pi_mask (pi) | IH_FREE_SPACE);
|
||||
|
||||
ind_item = (__u32 *)B_I_PITEM (bh, ih);
|
||||
if (!should_pack_indirect (ind_item, I_UNFM_NUM (ih)))
|
||||
pi->mask |= WHOLE_INDIRECT;
|
||||
set_pi_mask (pi, get_pi_mask (pi) | WHOLE_INDIRECT);
|
||||
|
||||
/* send packed item header to stdout */
|
||||
fwrite (pi, sizeof (*pi), 1, stdout);
|
||||
sent += sizeof (*pi);
|
||||
|
||||
/* send key components which are to be sent */
|
||||
pack_key (pi, ih);
|
||||
if (get_pi_mask(pi) & SAFE_LINK)
|
||||
set_key_dirid(&ih->ih_key, le32_to_cpu(*ind_item) );
|
||||
|
||||
if (pi->mask & ENTRY_COUNT) {
|
||||
__u16 ih_free_space;
|
||||
pack_ih (pi, ih);
|
||||
|
||||
ih_free_space = ih_entry_count (ih);
|
||||
fwrite16 (&ih_free_space);
|
||||
sent += sizeof (__u16);
|
||||
}
|
||||
if (get_pi_mask(pi) & SAFE_LINK)
|
||||
return;
|
||||
|
||||
if (pi->mask & WHOLE_INDIRECT) {
|
||||
fwrite (ind_item, ih_item_len (ih), 1, stdout);
|
||||
sent += ih_item_len (ih);
|
||||
if (get_pi_mask(pi) & WHOLE_INDIRECT) {
|
||||
fwrite (ind_item, get_ih_item_len (ih), 1, stdout);
|
||||
sent_bytes += get_ih_item_len (ih);
|
||||
return;
|
||||
}
|
||||
|
||||
fwrite32 (&ind_item [0]);
|
||||
sent += sizeof (__u32);
|
||||
|
||||
for (i = 1, len = 1; i < I_UNFM_NUM (ih); i ++) {
|
||||
if ((!ind_item [i] && !ind_item [i - 1]) || /* hole continues */
|
||||
if ((ind_item [i] == 0 && ind_item [i - 1] == 0) || /* hole continues */
|
||||
ind_item [i] == ind_item[ i - 1] + 1) { /* subsequent blocks */
|
||||
len ++;
|
||||
} else {
|
||||
fwrite16 (&len);
|
||||
fwrite_le16 (&len);
|
||||
fwrite32 (&ind_item[i]);
|
||||
sent += (sizeof (__u32) + sizeof (__u16));
|
||||
len = 1;
|
||||
}
|
||||
}
|
||||
fwrite16 (&len);
|
||||
sent += sizeof (__u16);
|
||||
fwrite_le16 (&len);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -154,7 +203,7 @@ static void pack_indirect (struct packed_item * pi, struct buffer_head * bh,
|
||||
maybe gencounter (16)
|
||||
maybe deh_state (16)
|
||||
*/
|
||||
static void pack_direntry (reiserfs_filsys_t fs, struct packed_item * pi,
|
||||
static void pack_direntry (reiserfs_filsys_t * fs, struct packed_item * pi,
|
||||
struct buffer_head * bh,
|
||||
struct item_head * ih)
|
||||
{
|
||||
@@ -164,56 +213,45 @@ static void pack_direntry (reiserfs_filsys_t fs, struct packed_item * pi,
|
||||
__u16 entry_count, gen_counter;
|
||||
|
||||
|
||||
pi->mask |= (DIRENTRY_ITEM | ENTRY_COUNT);
|
||||
set_pi_mask (pi, get_pi_mask (pi) | IH_ENTRY_COUNT);
|
||||
|
||||
/* send packed item header to stdout */
|
||||
fwrite (pi, sizeof (*pi), 1, stdout);
|
||||
sent += sizeof (*pi);
|
||||
|
||||
/* send key components which are to be sent */
|
||||
pack_key (pi, ih);
|
||||
/* send item_head components which are to be sent */
|
||||
pack_ih (pi, ih);
|
||||
|
||||
/* entry count is sent unconditionally */
|
||||
entry_count = ih_entry_count (ih);
|
||||
fwrite16 (&entry_count);
|
||||
entry_count = get_ih_entry_count (ih);
|
||||
|
||||
deh = B_I_DEH (bh, ih);
|
||||
for (i = 0; i < entry_count; i ++, deh ++) {
|
||||
pe.entrylen = entry_length (ih, deh, i);
|
||||
pe.mask = 0;
|
||||
if (deh_dir_id (deh) != le32_to_cpu (ih->ih_key.k_objectid))
|
||||
if (get_deh_dirid (deh) != get_key_objectid (&ih->ih_key))
|
||||
/* entry points to name of another directory, store deh_dir_id */
|
||||
pe.mask |= HAS_DIR_ID;
|
||||
|
||||
gen_counter = GET_GENERATION_NUMBER (deh_offset (deh));
|
||||
gen_counter = GET_GENERATION_NUMBER (get_deh_offset (deh));
|
||||
if (gen_counter != 0)
|
||||
/* store generation counter if it is != 0 */
|
||||
pe.mask |= HAS_GEN_COUNTER;
|
||||
|
||||
if (le16_to_cpu (deh->deh_state) != 4)
|
||||
if (get_deh_state (deh) != 4)
|
||||
/* something unusual in deh_state. Store it */
|
||||
pe.mask |= HAS_STATE;
|
||||
|
||||
fwrite8 (&pe.mask);
|
||||
fwrite16 (&pe.entrylen);
|
||||
fwrite_le16 (&pe.entrylen);
|
||||
fwrite (name_in_entry (deh, i), pe.entrylen, 1, stdout);
|
||||
fwrite32 (&(deh->deh_objectid));
|
||||
sent += (sizeof (__u8) + sizeof (__u16) + pe.entrylen + sizeof (__u32));
|
||||
sent_bytes += pe.entrylen;
|
||||
fwrite32 (&(deh->deh2_objectid));
|
||||
|
||||
if (pe.mask & HAS_DIR_ID) {
|
||||
fwrite32 (&deh->deh_dir_id);
|
||||
sent += sizeof (__u32);
|
||||
}
|
||||
if (pe.mask & HAS_DIR_ID)
|
||||
fwrite32 (&deh->deh2_dir_id);
|
||||
|
||||
if (pe.mask & HAS_GEN_COUNTER) {
|
||||
fwrite16 (&gen_counter);
|
||||
sent += sizeof (__u16);
|
||||
}
|
||||
if (pe.mask & HAS_GEN_COUNTER)
|
||||
fwrite_le16 (&gen_counter);
|
||||
|
||||
if (pe.mask & HAS_STATE) {
|
||||
fwrite16 (&deh->deh_state);
|
||||
sent += sizeof (__u16);
|
||||
}
|
||||
if (pe.mask & HAS_STATE)
|
||||
fwrite16 (&deh->deh2_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +259,9 @@ static void pack_direntry (reiserfs_filsys_t fs, struct packed_item * pi,
|
||||
static void pack_stat_data (struct packed_item * pi, struct buffer_head * bh,
|
||||
struct item_head * ih)
|
||||
{
|
||||
pi->mask |= STAT_DATA_ITEM;
|
||||
if (get_ih_free_space (ih) != 0xffff)
|
||||
/* ih_free_space has unexpected value */
|
||||
set_pi_mask (pi, get_pi_mask (pi) | IH_FREE_SPACE);
|
||||
|
||||
if (stat_data_v1 (ih)) {
|
||||
/* for old stat data: we take
|
||||
@@ -234,25 +274,19 @@ static void pack_stat_data (struct packed_item * pi, struct buffer_head * bh,
|
||||
struct stat_data_v1 * sd_v1;
|
||||
|
||||
sd_v1 = (struct stat_data_v1 *)B_I_PITEM (bh, ih);
|
||||
if (sd_v1->sd_first_direct_byte != 0xffffffff)
|
||||
pi->mask |= WITH_SD_FIRST_DIRECT_BYTE;
|
||||
if (sd_v1->sd_first_direct_byte != 0xffffffff) /* ok if -1 */
|
||||
set_pi_mask (pi, get_pi_mask (pi) | WITH_SD_FIRST_DIRECT_BYTE);
|
||||
|
||||
/* we are done with packed_item send packed it to stdout */
|
||||
fwrite (pi, sizeof (*pi), 1, stdout);
|
||||
sent += sizeof (*pi);
|
||||
|
||||
/* send key components which are to be sent */
|
||||
pack_key (pi, ih);
|
||||
pack_ih (pi, ih);
|
||||
|
||||
fwrite16 (&sd_v1->sd_mode);
|
||||
fwrite16 (&sd_v1->sd_nlink);
|
||||
fwrite32 (&sd_v1->sd_size);
|
||||
fwrite32 (&sd_v1->u.sd_blocks);
|
||||
sent += (sizeof (__u16) * 2 + sizeof (__u32) * 2);
|
||||
if (pi->mask & WITH_SD_FIRST_DIRECT_BYTE) {
|
||||
|
||||
if (get_pi_mask(pi) & WITH_SD_FIRST_DIRECT_BYTE)
|
||||
fwrite32 (&sd_v1->sd_first_direct_byte);
|
||||
sent += sizeof (__u32);
|
||||
}
|
||||
} else {
|
||||
/* for new stat data
|
||||
mode - 16 bits
|
||||
@@ -261,85 +295,75 @@ static void pack_stat_data (struct packed_item * pi, struct buffer_head * bh,
|
||||
blocks - 32 bits
|
||||
*/
|
||||
struct stat_data * sd;
|
||||
/* these will maintain disk-order values */
|
||||
__u16 nlink16;
|
||||
__u32 nlink32, size32;
|
||||
__u64 size64;
|
||||
|
||||
sd = (struct stat_data *)B_I_PITEM (bh, ih);
|
||||
if (sd->sd_nlink > 0xffff) {
|
||||
pi->mask |= NLINK_BITS_32;
|
||||
if (sd_v2_nlink (sd) > 0xffff) {
|
||||
set_pi_mask (pi, get_pi_mask (pi) | NLINK_BITS_32);
|
||||
nlink32 = sd->sd_nlink;
|
||||
} else {
|
||||
nlink16 = sd->sd_nlink;
|
||||
/* This is required to deal w/ big endian systems */
|
||||
nlink16 = cpu_to_le16 ((__u16)sd_v2_nlink (sd));
|
||||
}
|
||||
if (sd->sd_size > 0xffffffff) {
|
||||
pi->mask |= SIZE_BITS_64;
|
||||
if (sd_v2_size (sd) > 0xffffffff) {
|
||||
set_pi_mask (pi, get_pi_mask (pi) | SIZE_BITS_64);
|
||||
size64 = sd->sd_size;
|
||||
} else {
|
||||
size32 = sd->sd_size;
|
||||
/* This is required to deal w/ big endian systems */
|
||||
size32 = cpu_to_le32 ((__u32)sd_v2_size (sd));
|
||||
}
|
||||
|
||||
/* we are done with packed_item send packed it to stdout */
|
||||
fwrite (pi, sizeof (*pi), 1, stdout);
|
||||
sent += sizeof (*pi);
|
||||
|
||||
/* send key components which are to be sent */
|
||||
pack_key (pi, ih);
|
||||
pack_ih (pi, ih);
|
||||
|
||||
fwrite16 (&sd->sd_mode);
|
||||
sent += sizeof (__u16);
|
||||
if (pi->mask & NLINK_BITS_32) {
|
||||
|
||||
if (get_pi_mask (pi) & NLINK_BITS_32) {
|
||||
fwrite32 (&nlink32);
|
||||
sent += sizeof (__u32);
|
||||
} else {
|
||||
fwrite16 (&nlink16);
|
||||
sent += sizeof (__u16);
|
||||
}
|
||||
|
||||
if (pi->mask & SIZE_BITS_64) {
|
||||
if (get_pi_mask (pi) & SIZE_BITS_64) {
|
||||
fwrite64 (&size64);
|
||||
sent += sizeof (__u64);
|
||||
} else {
|
||||
fwrite32 (&size32);
|
||||
sent += sizeof (__u32);
|
||||
}
|
||||
|
||||
fwrite32 (&sd->sd_blocks);
|
||||
sent += sizeof (__u32);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void pack_full_block (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
static void pack_full_block (reiserfs_filsys_t * fs, struct buffer_head * bh)
|
||||
{
|
||||
__u16 magic;
|
||||
__u32 block;
|
||||
|
||||
|
||||
magic = FULL_BLOCK_START_MAGIC;
|
||||
fwrite16 (&magic);
|
||||
fwrite_le16 (&magic);
|
||||
|
||||
block = bh->b_blocknr;
|
||||
fwrite32 (&block);
|
||||
fwrite_le32 (&block);
|
||||
|
||||
fwrite (bh->b_data, 4096, 1, stdout);
|
||||
sent += 4096;
|
||||
had_to_be_sent += 4096;
|
||||
fwrite (bh->b_data, fs->fs_blocksize, 1, stdout);
|
||||
|
||||
sent_bytes += fs->fs_blocksize;
|
||||
had_to_be_sent += fs->fs_blocksize;
|
||||
|
||||
full_blocks ++;
|
||||
|
||||
if (who_is_this (bh->b_data, bh->b_size) == THE_JDESC)
|
||||
descs ++;
|
||||
if (who_is_this (bh->b_data, bh->b_size) == THE_INTERNAL)
|
||||
internals ++;
|
||||
if (block_of_journal (fs, bh->b_blocknr))
|
||||
full_of_journal ++;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
/* unformatted node pointer is considered bad when it points either to blocks
|
||||
of journal, bitmap blocks, super block or is transparently out of range of
|
||||
disk block numbers */
|
||||
static int check_unfm_ptr (reiserfs_filsys_t fs, __u32 block)
|
||||
static int check_unfm_ptr (reiserfs_filsys_t * fs, __u32 block)
|
||||
{
|
||||
if (block >= SB_BLOCK_COUNT (fs))
|
||||
return 1;
|
||||
@@ -349,17 +373,17 @@ static int check_unfm_ptr (reiserfs_filsys_t fs, __u32 block)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* we only pack leaves which do not have any corruptions */
|
||||
static int can_pack_leaf (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
static int can_pack_leaf (reiserfs_filsys_t * fs, struct buffer_head * bh)
|
||||
{
|
||||
int i;
|
||||
struct item_head * ih;
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < node_item_number (bh); i ++, ih ++) {
|
||||
if (is_it_bad_item (fs, ih, B_I_PITEM (bh, ih), check_unfm_ptr, 1/*bad dir*/))
|
||||
for (i = 0; i < get_blkh_nr_items (B_BLK_HEAD (bh)); i ++, ih ++) {
|
||||
if (is_it_bad_item (fs, ih, B_I_PITEM (bh, ih), 0/*check_unfm_ptr*/, 1/*bad dir*/))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@@ -369,7 +393,7 @@ static int can_pack_leaf (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
/* pack leaf only if all its items are correct: keys are correct,
|
||||
direntries are hashed properly and hash function is defined,
|
||||
indirect items are correct, stat data ?, */
|
||||
static void pack_leaf (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
static void pack_leaf (reiserfs_filsys_t * fs, struct buffer_head * bh)
|
||||
{
|
||||
int i;
|
||||
struct item_head * ih;
|
||||
@@ -377,60 +401,81 @@ static void pack_leaf (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
__u16 v16;
|
||||
|
||||
if (!can_pack_leaf (fs, bh)) {
|
||||
/* if something looks suspicious in this leaf - pack whole block */
|
||||
pack_full_block (fs, bh);
|
||||
fprintf (stderr, "leaf %lu is bad\n", bh->b_blocknr);
|
||||
/* something looks suspicious in this leaf - pack whole block */
|
||||
bad_leaves ++;
|
||||
pack_full_block (fs, bh);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* start magic in low 8 bits, hash code in high 8 bits */
|
||||
v16 = (LEAF_START_MAGIC | (func2code (fs->s_hash_function) << 8));
|
||||
fwrite16 (&v16);
|
||||
v16 = (LEAF_START_MAGIC | (func2code (fs->fs_hash_function) << 8));
|
||||
fwrite_le16 (&v16);
|
||||
|
||||
/* block number */
|
||||
fwrite32 (&bh->b_blocknr);
|
||||
fwrite_le32 (&bh->b_blocknr);
|
||||
|
||||
/* item number */
|
||||
v16 = node_item_number (bh);
|
||||
fwrite16 (&v16);
|
||||
v16 = get_blkh_nr_items (B_BLK_HEAD (bh));
|
||||
fwrite_le16 (&v16);
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
|
||||
for (i = 0; i < node_item_number (bh); i ++, ih ++) {
|
||||
for (i = 0; i < v16; i ++, ih ++) {
|
||||
#if 0
|
||||
v32 = ITEM_START_MAGIC;
|
||||
fwrite32 (&v32);
|
||||
#endif
|
||||
|
||||
pi.mask = 0;
|
||||
pi.item_len = ih_item_len (ih);
|
||||
set_pi_mask (&pi, 0);
|
||||
set_pi_item_len (&pi, get_ih_item_len (ih));
|
||||
set_pi_type (&pi, get_type (&ih->ih_key));
|
||||
|
||||
// format
|
||||
if (ih_key_format (ih) == KEY_FORMAT_2)
|
||||
pi.mask |= NEW_FORMAT;
|
||||
if (get_ih_key_format (ih) == KEY_FORMAT_2)
|
||||
set_pi_mask( &pi, get_pi_mask(&pi) | NEW_FORMAT );
|
||||
|
||||
// k_dir_id
|
||||
if (!i || (i && ih->ih_key.k_dir_id != (ih - 1)->ih_key.k_dir_id)) {
|
||||
if (!i || (i && get_key_dirid (&ih->ih_key) != get_key_dirid (&(ih - 1)->ih_key))) {
|
||||
/* if item is first in the leaf or if previous item has different
|
||||
k_dir_id - store it */
|
||||
pi.mask |= DIR_ID;
|
||||
set_pi_mask (&pi, get_pi_mask (&pi) | DIR_ID);
|
||||
}
|
||||
// k_object_id
|
||||
if (!i || (i && ih->ih_key.k_objectid != (ih - 1)->ih_key.k_objectid)) {
|
||||
if (!i || (i && get_key_objectid (&ih->ih_key) != get_key_objectid (&(ih - 1)->ih_key))) {
|
||||
/* if item is first in the leaf or if previous item has different
|
||||
k_objectid - store it */
|
||||
pi.mask |= OBJECT_ID;
|
||||
set_pi_mask (&pi, get_pi_mask (&pi) | OBJECT_ID);
|
||||
}
|
||||
|
||||
/* store offset if it is != 0 in 32 or 64 bits */
|
||||
if (get_offset (&ih->ih_key)) {
|
||||
if (get_offset (&ih->ih_key) > 0xffffffffULL)
|
||||
pi.mask |= OFFSET_BITS_64;
|
||||
else
|
||||
pi.mask |= OFFSET_BITS_32;
|
||||
int send_offset = 1;
|
||||
|
||||
if ((get_pi_mask (&pi) & DIR_ID) == 0 && (get_pi_mask (&pi) & OBJECT_ID) == 0) {
|
||||
/* previous item is of the same object, so try to avoid
|
||||
sending k_offset */
|
||||
if ((is_stat_data_ih (ih - 1) && get_offset (&ih->ih_key) == 1) ||
|
||||
(is_indirect_ih (ih - 1) && is_direct_ih (ih) &&
|
||||
get_offset (&(ih - 1)->ih_key) + get_bytes_number (ih - 1, fs->fs_blocksize) == get_offset (&ih->ih_key)))
|
||||
/* unpack can calculate offset itself */
|
||||
send_offset = 0;
|
||||
}
|
||||
if (send_offset) {
|
||||
if (get_offset (&ih->ih_key) > 0xffffffffULL)
|
||||
set_pi_mask (&pi, get_pi_mask (&pi) | OFFSET_BITS_64);
|
||||
else
|
||||
set_pi_mask (&pi, get_pi_mask (&pi) | OFFSET_BITS_32);
|
||||
}
|
||||
}
|
||||
|
||||
/* ih key format is correct, check fsck_need field */
|
||||
if (get_ih_flags (ih))
|
||||
set_pi_mask (&pi, get_pi_mask (&pi) | IH_FORMAT);
|
||||
|
||||
if ((get_key_dirid (&ih->ih_key) == (__u32)-1) && (get_ih_item_len (ih) == 4))
|
||||
set_pi_mask (&pi, get_pi_mask (&pi) | SAFE_LINK);
|
||||
|
||||
if (is_direct_ih (ih)) {
|
||||
pack_direct (&pi, bh, ih);
|
||||
} else if (is_indirect_ih (ih))
|
||||
@@ -448,24 +493,26 @@ static void pack_leaf (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
}
|
||||
|
||||
v16 = LEAF_END_MAGIC;
|
||||
fwrite16 (&v16);
|
||||
fwrite_le16 (&v16);
|
||||
|
||||
|
||||
had_to_be_sent += fs->fs_blocksize;
|
||||
packed_leaves ++;
|
||||
had_to_be_sent += 4096;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static int can_pack_internal (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
static int can_pack_internal (reiserfs_filsys_t * fs, struct buffer_head * bh)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* pack internal node as a full block */
|
||||
static void pack_internal (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
static void pack_internal (reiserfs_filsys_t * fs, struct buffer_head * bh)
|
||||
{
|
||||
internals ++;
|
||||
if (!can_pack_internal (fs, bh)) {
|
||||
pack_full_block (fs, bh);
|
||||
return;
|
||||
@@ -475,83 +522,132 @@ static void pack_internal (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
}
|
||||
|
||||
|
||||
static int how_many_to_pack (reiserfs_filsys_t fs, unsigned long first, int count)
|
||||
{
|
||||
int i;
|
||||
int used;
|
||||
|
||||
used = 0;
|
||||
for (i = 0; i < count; i ++) {
|
||||
if ((SB_BLOCK_COUNT (fs) > (first + i)) &&
|
||||
reiserfs_bitmap_test_bit (what_to_pack, first + i))
|
||||
used ++;
|
||||
}
|
||||
return used;
|
||||
}
|
||||
|
||||
|
||||
/* packed blocks are marked free in the bitmap*/
|
||||
static void send_block (reiserfs_filsys_t fs, struct buffer_head * bh)
|
||||
static void send_block (reiserfs_filsys_t * fs, struct buffer_head * bh, int send_unknown)
|
||||
{
|
||||
int type;
|
||||
|
||||
|
||||
if ((type = who_is_this (bh->b_data, bh->b_size)) != THE_LEAF) {
|
||||
if (type == THE_INTERNAL) {
|
||||
pack_internal (fs, bh);
|
||||
} else if (!not_data_block (fs, bh->b_blocknr)) {
|
||||
/* unformatted */
|
||||
return;
|
||||
} else
|
||||
/* bitmaps, super block, blocks of journal - not leaves */
|
||||
pack_full_block (fs, bh);
|
||||
} else
|
||||
packed ++;
|
||||
type = who_is_this (bh->b_data, bh->b_size);
|
||||
switch (type) {
|
||||
case THE_LEAF:
|
||||
pack_leaf (fs, bh);
|
||||
break;
|
||||
|
||||
reiserfs_bitmap_set_bit (what_packed, bh->b_blocknr);
|
||||
case HAS_IH_ARRAY:
|
||||
having_ih_array ++;
|
||||
fprintf (stderr, "BROKEN BLOCK HEAD %lu\n", bh->b_blocknr);
|
||||
pack_full_block (fs, bh);
|
||||
break;
|
||||
|
||||
case THE_INTERNAL:
|
||||
pack_internal (fs, bh);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (send_unknown)
|
||||
pack_full_block (fs, bh);
|
||||
else
|
||||
packed --;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* do not send one block twice */
|
||||
reiserfs_bitmap_clear_bit (what_to_pack, bh->b_blocknr);
|
||||
}
|
||||
|
||||
|
||||
/* super block, journal, bitmaps */
|
||||
static void pack_frozen_data (reiserfs_filsys_t fs)
|
||||
static void pack_frozen_data (reiserfs_filsys_t * fs)
|
||||
{
|
||||
int i;
|
||||
struct buffer_head * bh;
|
||||
unsigned long block;
|
||||
__u16 magic16;
|
||||
int sent_journal_start_magic = 0;
|
||||
|
||||
if (is_reiserfs_jr_magic_string(fs->fs_ondisk_sb) &&
|
||||
get_jp_journal_dev(sb_jp(fs->fs_ondisk_sb)) &&
|
||||
!journal_device_name(fs)) {
|
||||
if (!user_confirmed (stderr,
|
||||
"\n File system has non-standard journal "
|
||||
"that hasn't been specified.\n"
|
||||
"Continue packing without journal? [N/Yes] (note need to type Yes):", "Yes\n"))
|
||||
exit (0);
|
||||
}
|
||||
|
||||
/* super block */
|
||||
reiserfs_warning (stderr, "super block..");fflush (stderr);
|
||||
send_block (fs, fs->s_sbh);
|
||||
reiserfs_warning (stderr, "ok\nbitmaps..(%d).. ", SB_BMAP_NR (fs));
|
||||
send_block (fs, fs->fs_super_bh, 1/*send block even if its format is not determined */);
|
||||
reiserfs_warning (stderr, "ok\nbitmaps..(%d).. ",
|
||||
get_sb_bmap_nr (fs->fs_ondisk_sb));
|
||||
fflush (stderr);
|
||||
|
||||
/* bitmaps */
|
||||
for (i = 0; i < SB_BMAP_NR (fs); i ++) {
|
||||
send_block (fs, SB_AP_BITMAP (fs)[i]);
|
||||
}
|
||||
|
||||
reiserfs_warning (stderr, "ok\njournal (from %lu to %lu)..",
|
||||
rs_journal_start (fs->s_rs),
|
||||
rs_journal_start (fs->s_rs) + rs_journal_size (fs->s_rs));
|
||||
fflush (stderr);
|
||||
/* journal */
|
||||
for (i = rs_journal_start (fs->s_rs);
|
||||
i <= rs_journal_start (fs->s_rs) + rs_journal_size (fs->s_rs);
|
||||
i ++) {
|
||||
bh = bread (fs->s_dev, i, fs->s_blocksize);
|
||||
send_block (fs, bh);
|
||||
block = fs->fs_super_bh->b_blocknr + 1;
|
||||
for (i = 0; i < get_sb_bmap_nr (fs->fs_ondisk_sb); i ++) {
|
||||
bh = bread (fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
fprintf (stderr, "pack_frozen_data: bread failed: %lu\n", block);
|
||||
continue;
|
||||
}
|
||||
send_block (fs, bh, 1);
|
||||
if (spread_bitmaps (fs))
|
||||
block = (block / (fs->fs_blocksize * 8) + 1) * (fs->fs_blocksize * 8);
|
||||
else
|
||||
block ++;
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
/* journal */
|
||||
|
||||
if (get_jp_journal_dev (sb_jp (fs->fs_ondisk_sb))) {
|
||||
/* non-standard journal is on a separate device */
|
||||
|
||||
if (journal_device_name (fs) && !reiserfs_journal_opened (fs))
|
||||
die ("Specified journal is not available. Specify it correctly or "
|
||||
"don't specify at all");
|
||||
else if (!journal_device_name(fs))
|
||||
/* non-standard journal was not specified (that confirmed by user) -
|
||||
skipped packing journal */
|
||||
return;
|
||||
else {
|
||||
magic16 = SEPARATED_JOURNAL_START_MAGIC;
|
||||
fwrite_le16 (&magic16);
|
||||
sent_journal_start_magic = 1;
|
||||
}
|
||||
}
|
||||
block = get_jp_journal_1st_block (sb_jp (fs->fs_ondisk_sb));
|
||||
reiserfs_warning (stderr, "ok\njournal (from %lu to %lu)..",
|
||||
block, block + get_jp_journal_size (sb_jp (fs->fs_ondisk_sb)));
|
||||
fflush (stderr);
|
||||
for (i = 0; i <= get_jp_journal_size (sb_jp (fs->fs_ondisk_sb)); i ++) {
|
||||
bh = bread (fs->fs_journal_dev, block + i, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "could not read %lu, skipped\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
send_block (fs, bh, 1);
|
||||
brelse (bh);
|
||||
}
|
||||
if (sent_journal_start_magic) {
|
||||
magic16 = SEPARATED_JOURNAL_END_MAGIC;
|
||||
fwrite_le16 (&magic16);
|
||||
}
|
||||
reiserfs_warning (stderr, "ok\n");fflush (stderr);
|
||||
reiserfs_warning (stderr,
|
||||
"Super block, bitmaps, journal - %d blocks - done, %d blocks left\n",
|
||||
packed, reiserfs_bitmap_ones (what_to_pack));
|
||||
}
|
||||
|
||||
|
||||
/* pack all "not data blocks" and correct leaf */
|
||||
void pack_partition (reiserfs_filsys_t fs)
|
||||
void pack_partition (reiserfs_filsys_t * fs)
|
||||
{
|
||||
int i, j;
|
||||
struct buffer_head tmp, * bh;
|
||||
int nr_to_read = BLOCKS_PER_READ;
|
||||
int i;
|
||||
struct buffer_head * bh;
|
||||
__u32 magic32;
|
||||
__u16 blocksize;
|
||||
__u16 magic16;
|
||||
@@ -559,94 +655,61 @@ void pack_partition (reiserfs_filsys_t fs)
|
||||
|
||||
|
||||
magic32 = REISERFS_SUPER_MAGIC;
|
||||
fwrite32 (&magic32);
|
||||
fwrite_le32 (&magic32);
|
||||
|
||||
blocksize = fs->s_blocksize;
|
||||
fwrite16 (&blocksize);
|
||||
blocksize = fs->fs_blocksize;
|
||||
fwrite_le16 (&blocksize);
|
||||
|
||||
tmp.b_size = blocksize;
|
||||
|
||||
/* will save information about what packed here */
|
||||
what_packed = reiserfs_create_bitmap (SB_BLOCK_COUNT (fs));
|
||||
|
||||
/* will get information about what is to be packed */
|
||||
what_to_pack = reiserfs_create_bitmap (SB_BLOCK_COUNT (fs));
|
||||
if (!what_to_pack)
|
||||
die ("pack_partition: could not create bitmap");
|
||||
if (mode == DO_PACK) {
|
||||
/* read blocks marked used and pack them */
|
||||
reiserfs_fetch_disk_bitmap (what_to_pack, fs);
|
||||
reiserfs_warning (stderr, "Packing blocks marked used on the device %d\n",
|
||||
reiserfs_bitmap_ones (what_to_pack));
|
||||
} else {
|
||||
reiserfs_bitmap_fill (what_to_pack);
|
||||
reiserfs_warning (stderr, "Packing all blocks of the device %d\n",
|
||||
reiserfs_bitmap_ones (what_to_pack));
|
||||
}
|
||||
/* will get information about what is to be packed. Bits corresponding to
|
||||
packed blocks will be cleared */
|
||||
what_to_pack = input_bitmap(fs);
|
||||
|
||||
|
||||
/* super block, journal, bitmaps */
|
||||
pack_frozen_data (fs);
|
||||
|
||||
reiserfs_warning (stderr,
|
||||
"Super block, bitmaps, journal - %d blocks - done, %d blocks left\n",
|
||||
reiserfs_bitmap_ones (what_packed), reiserfs_bitmap_ones (what_to_pack));
|
||||
|
||||
/* what's left */
|
||||
total = reiserfs_bitmap_ones (what_to_pack);
|
||||
|
||||
for (i = 0; i < SB_BLOCK_COUNT (fs); i += nr_to_read) {
|
||||
int to_pack;
|
||||
|
||||
to_pack = how_many_to_pack (fs, i, nr_to_read);
|
||||
if (to_pack) {
|
||||
print_how_far (&done, total, to_pack, opt_quiet);
|
||||
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
|
||||
if (!reiserfs_bitmap_test_bit (what_to_pack, i))
|
||||
continue;
|
||||
|
||||
bh = bread (fs->s_dev, i / nr_to_read, blocksize * nr_to_read);
|
||||
if (bh) {
|
||||
for (j = 0; j < nr_to_read; j ++) {
|
||||
if (reiserfs_bitmap_test_bit (what_to_pack, i + j)) {
|
||||
tmp.b_data = bh->b_data + j * tmp.b_size;
|
||||
tmp.b_blocknr = i + j;
|
||||
send_block (fs, &tmp);
|
||||
}
|
||||
}
|
||||
brelse (bh);
|
||||
} else {
|
||||
/* bread failed */
|
||||
if (nr_to_read != 1) {
|
||||
/* we tryied to read bunch of blocks. Try to read them by one */
|
||||
nr_to_read = 1;
|
||||
i --;
|
||||
continue;
|
||||
} else {
|
||||
/* we were reading one block at time, and failed, so mark
|
||||
block bad */
|
||||
reiserfs_warning (stderr, "could not read block %lu\n", i);
|
||||
}
|
||||
}
|
||||
print_how_far (stderr, &done, total, 1, be_quiet (fs));
|
||||
|
||||
bh = bread (fs->fs_dev, i, blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "could not read block %lu\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
send_block (fs, bh, 0/*do not send block of not determined format */);
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
magic16 = END_MAGIC;
|
||||
fwrite16 (&magic16);
|
||||
fwrite_le16 (&magic16);
|
||||
|
||||
fprintf (stderr, "Packed\n\tleaves %d\n"
|
||||
fprintf (stderr, "\nPacked %d blocks:\n"
|
||||
"\tcompessed %d\n"
|
||||
"\tfull blocks %d\n"
|
||||
"\t\tof journal %d\n"
|
||||
"\t\tleaves with broken block head %d\n"
|
||||
"\t\tcorrupted leaves %d\n"
|
||||
"\t\tinternals %d\n"
|
||||
"\t\tdescriptors %d\n",
|
||||
packed_leaves, full_blocks, full_of_journal, bad_leaves, internals, descs);
|
||||
fprintf (stderr, "data packed with ratio %.2f\n", (double)sent / had_to_be_sent);
|
||||
packed,
|
||||
packed_leaves, full_blocks, having_ih_array,
|
||||
bad_leaves, internals, descs);
|
||||
|
||||
if (where_to_save)
|
||||
reiserfs_bitmap_save (where_to_save, what_packed);
|
||||
fprintf (stderr, "data packed with ratio %.2f\n", (double)sent_bytes / had_to_be_sent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void pack_one_block (reiserfs_filsys_t fs, unsigned long block)
|
||||
void pack_one_block (reiserfs_filsys_t * fs, unsigned long block)
|
||||
{
|
||||
__u32 magic32;
|
||||
__u16 magic16;
|
||||
@@ -654,12 +717,12 @@ void pack_one_block (reiserfs_filsys_t fs, unsigned long block)
|
||||
|
||||
// reiserfs magic
|
||||
magic32 = REISERFS_SUPER_MAGIC;
|
||||
fwrite32 (&magic32);
|
||||
fwrite_le32 (&magic32);
|
||||
|
||||
// blocksize
|
||||
fwrite16 (&fs->s_blocksize);
|
||||
fwrite_le16 (&fs->fs_blocksize);
|
||||
|
||||
bh = bread (fs->s_dev, block, fs->s_blocksize);
|
||||
bh = bread (fs->fs_dev, block, fs->fs_blocksize);
|
||||
|
||||
if (who_is_this (bh->b_data, bh->b_size) == THE_LEAF)
|
||||
pack_leaf (fs, bh);
|
||||
@@ -670,10 +733,9 @@ void pack_one_block (reiserfs_filsys_t fs, unsigned long block)
|
||||
|
||||
// end magic
|
||||
magic16 = END_MAGIC;
|
||||
fwrite16 (&magic16);
|
||||
fwrite_le16 (&magic16);
|
||||
|
||||
fprintf (stderr, "Packed\n\tleaves %d\n\tfull block %d\n\tcorrupted leaves %d\n",
|
||||
packed_leaves, full_blocks, bad_leaves);
|
||||
fprintf (stderr, "Done\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -682,7 +744,7 @@ void pack_one_block (reiserfs_filsys_t fs, unsigned long block)
|
||||
// this test program has two modes: 'pack file blocknr'
|
||||
// and 'unpack file'
|
||||
// in the first mode blocknr-th 4k block of the 'file' will be packed out to stdout
|
||||
// the the second mode standart input will be converted to the reiserfs leaf on 'file'
|
||||
// the the second mode standard input will be converted to the reiserfs leaf on 'file'
|
||||
//
|
||||
static int do_unpack (char * file)
|
||||
{
|
||||
@@ -714,7 +776,7 @@ static int do_unpack (char * file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_pack (char * file, int block)
|
||||
static int do_pack (char * file, unsigned long block)
|
||||
{
|
||||
int fd;
|
||||
struct buffer_head * bh;
|
||||
@@ -762,4 +824,7 @@ int main (int argc, char ** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* 0 */
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#include "debugreiserfs.h"
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
/* this reads stdin and recover file of given key: */
|
||||
/* the input has to be in the follwong format:
|
||||
K dirid objectid
|
||||
N name
|
||||
B blocknumber
|
||||
..
|
||||
then recover_file will read every block, look there specified file and put it into
|
||||
*/
|
||||
void do_recover (reiserfs_filsys_t fs)
|
||||
{
|
||||
char name [100];
|
||||
char * line = 0;
|
||||
int n = 0;
|
||||
int fd;
|
||||
struct key key = {0, 0, };
|
||||
struct buffer_head * bh;
|
||||
struct item_head * ih;
|
||||
unsigned long block;
|
||||
char code;
|
||||
loff_t recovered = 0;
|
||||
int i, j;
|
||||
reiserfs_bitmap_t bitmap;
|
||||
int used, not_used;
|
||||
|
||||
bitmap = reiserfs_create_bitmap (SB_BLOCK_COUNT (fs));
|
||||
reiserfs_fetch_disk_bitmap (bitmap, fs);
|
||||
/* we check how many blocks recoverd items point to are free or used */
|
||||
used = 0;
|
||||
not_used = 0;
|
||||
|
||||
fd = 0;
|
||||
while (getline (&line, &n, stdin) != -1) {
|
||||
if (line [0] == '#' || line [0] == '\n')
|
||||
continue;
|
||||
switch (line [0]) {
|
||||
case 'K':
|
||||
/* get a key of file which is to be recovered */
|
||||
if (sscanf (line, "%c %u %u\n", &code, &key.k_dir_id, &key.k_objectid) != 3) {
|
||||
die ("recover_file: wrong input K format");
|
||||
}
|
||||
printf ("Recovering file (%u, %u)\n", key.k_dir_id, key.k_objectid);
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
/* get a file name */
|
||||
recovered = 0;
|
||||
if (sscanf (line, "%c %s\n", &code, name) != 2) {
|
||||
die ("recover_file: wrong input N format");
|
||||
}
|
||||
fd = open (name, O_RDWR | O_CREAT | O_EXCL, 0644);
|
||||
if (fd == -1)
|
||||
die ("recover_file: could not create file %s: %s",
|
||||
name,strerror (errno));
|
||||
printf ("Recovering file %s..\n", name);
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
if (!fd)
|
||||
die ("recover_file: file name is not specified");
|
||||
if (sscanf (line, "%c %lu\n", &code, &block) != 2) {
|
||||
die ("recover_file: wrong input B format");
|
||||
}
|
||||
bh = bread (fs->s_dev, block, fs->s_blocksize);
|
||||
if (!bh) {
|
||||
printf ("reading block %lu failed\n", block);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf ("working with block %lu..\n", block);
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < node_item_number (bh); i ++, ih ++) {
|
||||
__u32 * indirect;
|
||||
struct buffer_head * tmp_bh;
|
||||
|
||||
if (!is_indirect_ih (ih) || key.k_dir_id != ih->ih_key.k_dir_id ||
|
||||
key.k_objectid != ih->ih_key.k_objectid)
|
||||
continue;
|
||||
|
||||
indirect = (__u32 *)B_I_PITEM (bh, ih);
|
||||
for (j = 0; j < I_UNFM_NUM (ih); j ++) {
|
||||
block = le32_to_cpu (indirect [j]);
|
||||
if (!block)
|
||||
continue;
|
||||
tmp_bh = bread (fs->s_dev, block, fs->s_blocksize);
|
||||
if (!tmp_bh) {
|
||||
printf ("reading block %Lu failed\n", (loff_t)block * fs->s_blocksize);
|
||||
continue;
|
||||
}
|
||||
if (lseek64 (fd, get_offset (&ih->ih_key) + j * fs->s_blocksize - 1,
|
||||
SEEK_SET) == (loff_t)-1) {
|
||||
printf ("llseek failed to pos %Ld\n", (loff_t)block * fs->s_blocksize);
|
||||
brelse (tmp_bh);
|
||||
continue;
|
||||
}
|
||||
if (reiserfs_bitmap_test_bit (bitmap, block))
|
||||
used ++;
|
||||
else
|
||||
not_used ++;
|
||||
/*printf ("block of file %Ld gets block %lu\n",
|
||||
(get_offset (&ih->ih_key) - 1) / fs->s_blocksize + j, block);*/
|
||||
if (write (fd, tmp_bh->b_data, tmp_bh->b_size) != tmp_bh->b_size) {
|
||||
printf ("write failed to pos %Ld\n", (loff_t)block * fs->s_blocksize);
|
||||
brelse (tmp_bh);
|
||||
continue;
|
||||
}
|
||||
recovered += fs->s_blocksize;
|
||||
brelse (tmp_bh);
|
||||
}
|
||||
}
|
||||
brelse (bh);
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf ("recover_file: %Ld bytes recovered of file %s, key %u %u, %d blocks are free and %d are used\n",
|
||||
recovered, name, key.k_dir_id, key.k_objectid, not_used, used);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* read a file containing map of one or more files and either recover
|
||||
them or just print info */
|
||||
static void read_map (FILE * fp)
|
||||
{
|
||||
int i;
|
||||
__u32 v32;
|
||||
char * buf;
|
||||
__u32 ids [4];
|
||||
int do_recover = 0;
|
||||
|
||||
|
||||
buf = 0;
|
||||
while (1) {
|
||||
if (fread (&v32, sizeof (v32), 1, fp) != 1)
|
||||
break;
|
||||
if (v32 != MAP_MAGIC)
|
||||
reiserfs_panic ("read_map: no magic found");
|
||||
|
||||
/* device name length and name itself */
|
||||
fread (&v32, sizeof (v32), 1, fp);
|
||||
buf = realloc (buf, v32);
|
||||
if (!buf)
|
||||
reiserfs_panic ("realloc failed");
|
||||
fread (buf, v32, 1, fp);
|
||||
reiserfs_warning (stdout, "\"%s\": ", buf);
|
||||
|
||||
/* file name length and name itself*/
|
||||
fread (&v32, sizeof (v32), 1, fp);
|
||||
buf = realloc (buf, v32);
|
||||
if (!buf)
|
||||
reiserfs_panic ("realloc failed");
|
||||
fread (buf, v32, 1, fp);
|
||||
|
||||
/* read directory key and poined object key */
|
||||
fread (ids, sizeof (ids), 1, fp);
|
||||
reiserfs_warning (stdout, "[%K]:\"%s\"-->[%K]\n",
|
||||
&ids[0], buf, &ids[2]);
|
||||
|
||||
/*
|
||||
do_recover = user_confirmed (stdout, "recover? (Y):", "Y\n");
|
||||
if (do_recover)
|
||||
reiserfs_warning (stderr, "recovering not ready\n");
|
||||
*/
|
||||
|
||||
/* how many data blocks are there */
|
||||
fread (&v32, sizeof (v32), 1, fp);
|
||||
if (v32) {
|
||||
buf = realloc (buf, v32 * 4);
|
||||
if (!buf)
|
||||
reiserfs_panic ("realloc failed (%u)", v32);
|
||||
|
||||
/* read list of data block numbers */
|
||||
fread (buf, 4, v32, fp);
|
||||
|
||||
if (!do_recover) {
|
||||
for (i = 0; i < v32; i ++)
|
||||
reiserfs_warning (stdout, "%d ", ((__u32 *)buf)[i]);
|
||||
reiserfs_warning (stdout, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* main tail length */
|
||||
fread (&v32, sizeof (v32), 1, fp);
|
||||
if (v32) {
|
||||
/* there is tail */
|
||||
buf = realloc (buf, v32);
|
||||
if (!buf)
|
||||
reiserfs_panic ("realloc failed");
|
||||
fread (buf, v32, 1, fp);
|
||||
if (!do_recover)
|
||||
reiserfs_warning (stdout, "%d bytes long tail\n", v32);
|
||||
} else {
|
||||
if (!do_recover)
|
||||
reiserfs_warning (stdout, "No tail\n");
|
||||
}
|
||||
|
||||
if (fread (&v32, sizeof (v32), 1, fp) != 1)
|
||||
break;
|
||||
if (v32 != MAP_END_MAGIC)
|
||||
reiserfs_panic ("read_map: no magic found");
|
||||
}
|
||||
|
||||
free (buf);
|
||||
}
|
||||
|
||||
|
||||
void do_recover (reiserfs_filsys_t * fs)
|
||||
{
|
||||
FILE * fp;
|
||||
|
||||
if (map_file (fs)) {
|
||||
fp = fopen (map_file (fs), "r");
|
||||
if (fp == 0) {
|
||||
reiserfs_warning (stderr, "do_recover: fopen failed: %m");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
reiserfs_warning (stderr, "Reading file map from stdin..\n");
|
||||
fflush (stderr);
|
||||
fp = stdin;
|
||||
}
|
||||
|
||||
read_map (fp);
|
||||
|
||||
if (fp != stdin)
|
||||
fclose (fp);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,941 @@
|
||||
/*
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#include "debugreiserfs.h"
|
||||
#include <regex.h>
|
||||
#include <obstack.h>
|
||||
#include <search.h>
|
||||
|
||||
#define obstack_chunk_alloc malloc
|
||||
#define obstack_chunk_free free
|
||||
|
||||
|
||||
/* -n pattern scans the area (on-disk bitmap, or all the device or extern
|
||||
bitmap) and looks for every name matching the pattern. All those names get
|
||||
stored in 'name_store' and are indexed by name (name_index) and by a key
|
||||
they point to (key_index) */
|
||||
|
||||
struct obstack name_store;
|
||||
struct obstack item_store;
|
||||
|
||||
int saved_names;
|
||||
int saved_items;
|
||||
int skipped_names;
|
||||
void * key_index;
|
||||
void * name_index;
|
||||
|
||||
regex_t pattern;
|
||||
|
||||
|
||||
struct saved_item {
|
||||
struct item_head si_ih;
|
||||
unsigned long si_block;
|
||||
int si_item_num;
|
||||
struct saved_item * si_next; /* list of items having the same key */
|
||||
};
|
||||
|
||||
|
||||
struct saved_name {
|
||||
unsigned int dirid; /* pointed object */
|
||||
unsigned int objectid;
|
||||
struct saved_name * first_name; /* pointer to name which points to the
|
||||
same object and contains list of file
|
||||
items */
|
||||
|
||||
unsigned int parent_dirid; /* parent directory */
|
||||
unsigned int parent_objectid;
|
||||
unsigned long block; /* where we saw the name for the first time */
|
||||
unsigned short count; /* how many times the name appeared */
|
||||
|
||||
void * items;
|
||||
struct saved_name * name_next; /* list of identical names */
|
||||
|
||||
unsigned short name_len;
|
||||
char name[1];
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* attach item to every name in the list */
|
||||
static void store_item (struct saved_name * name, struct buffer_head * bh,
|
||||
struct item_head * ih)
|
||||
{
|
||||
struct saved_item * new;
|
||||
void * vp;
|
||||
struct saved_item * item_in;
|
||||
|
||||
new = obstack_alloc (&item_store, sizeof (struct saved_item));
|
||||
new->si_ih = *ih;
|
||||
new->si_block = bh->b_blocknr;
|
||||
new->si_item_num = ih - B_N_PITEM_HEAD (bh, 0);
|
||||
new->si_next = 0;
|
||||
|
||||
vp = tfind (new, &name->items, comp_keys);
|
||||
if (vp) {
|
||||
item_in = *(void **)vp;
|
||||
/* add item to the end of list of items having this key */
|
||||
while (1) {
|
||||
if (!item_in->si_next) {
|
||||
item_in->si_next = new;
|
||||
break;
|
||||
}
|
||||
item_in = item_in->si_next;
|
||||
}
|
||||
} else
|
||||
tsearch (new, &name->items, comp_keys);
|
||||
|
||||
saved_items ++;
|
||||
}
|
||||
|
||||
|
||||
static int comp_names (const void * p1, const void * p2)
|
||||
{
|
||||
struct saved_name * name1, * name2;
|
||||
|
||||
name1 = (struct saved_name *)p1;
|
||||
name2 = (struct saved_name *)p2;
|
||||
|
||||
return strcmp (name1->name, name2->name);
|
||||
}
|
||||
|
||||
|
||||
static int comp_pointed (const void * p1, const void * p2)
|
||||
{
|
||||
struct saved_name * name1, * name2;
|
||||
|
||||
name1 = (struct saved_name *)p1;
|
||||
name2 = (struct saved_name *)p2;
|
||||
|
||||
return comp_short_keys (&name1->dirid, &name2->dirid);
|
||||
}
|
||||
|
||||
|
||||
/* we consider name found only if it points to the same object and from the
|
||||
same directory */
|
||||
static int name_found (struct saved_name * name, struct saved_name ** name_in)
|
||||
{
|
||||
void * vp;
|
||||
struct saved_name * cur;
|
||||
|
||||
vp = tfind (name, &name_index, comp_names);
|
||||
if (!vp) {
|
||||
*name_in = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*name_in = *(void **)vp;
|
||||
|
||||
/* check every name in the list */
|
||||
cur = *name_in;
|
||||
while (cur) {
|
||||
if (!not_of_one_file (&name->dirid, &cur->dirid) &&
|
||||
!not_of_one_file (&name->parent_dirid, &cur->parent_dirid)) {
|
||||
cur->count ++;
|
||||
return 1;
|
||||
}
|
||||
cur = cur->name_next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* add key name is pointing to to the index of keys. If there was already name
|
||||
pointing to this key - add pointer to that name */
|
||||
static void add_key (struct saved_name * name)
|
||||
{
|
||||
void * vp;
|
||||
|
||||
vp = tfind (name, &key_index, comp_pointed);
|
||||
if (vp) {
|
||||
/* */
|
||||
name->first_name = *(void **)vp;
|
||||
} else {
|
||||
tsearch (name, &key_index, comp_pointed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void add_name (struct saved_name * name, struct saved_name * name_in)
|
||||
{
|
||||
if (name_in) {
|
||||
/* add name to the end of list of identical names */
|
||||
while (1) {
|
||||
if (!name_in->name_next) {
|
||||
name_in->name_next = name;
|
||||
break;
|
||||
}
|
||||
name_in = name_in->name_next;
|
||||
}
|
||||
} else {
|
||||
/* add name into name index */
|
||||
tsearch (name, &name_index, comp_names);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* take each name matching to a given pattern, */
|
||||
static void scan_for_name (struct buffer_head * bh)
|
||||
{
|
||||
int i, j;
|
||||
struct item_head * ih;
|
||||
struct reiserfs_de_head * deh;
|
||||
int namelen;
|
||||
char * name;
|
||||
struct saved_name * new, *name_in;
|
||||
char ch;
|
||||
int retval;
|
||||
int min_entry_size = 1;
|
||||
int ih_entry_count = 0;
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) {
|
||||
if (!is_direntry_ih (ih))
|
||||
continue;
|
||||
if (is_it_bad_item (fs, ih, B_I_PITEM (bh, ih), 0, 1))
|
||||
continue;
|
||||
|
||||
deh = B_I_DEH (bh, ih);
|
||||
|
||||
if ( (get_ih_entry_count (ih) > (get_ih_item_len(ih) / (DEH_SIZE + min_entry_size))) ||
|
||||
(get_ih_entry_count (ih) == 0))
|
||||
ih_entry_count = get_ih_item_len(ih) / (DEH_SIZE + min_entry_size);
|
||||
else
|
||||
ih_entry_count = get_ih_entry_count (ih);
|
||||
|
||||
for (j = 0; j < ih_entry_count; j ++, deh ++) {
|
||||
name = name_in_entry (deh, j);
|
||||
namelen = name_in_entry_length (ih, deh, j);
|
||||
ch = name[namelen];
|
||||
name[namelen] = 0;
|
||||
retval = regexec (&pattern, name, 0, NULL, 0);
|
||||
name[namelen] = ch;
|
||||
if (retval != 0)
|
||||
continue;
|
||||
|
||||
/* name matching given pattern found */
|
||||
|
||||
new = obstack_alloc (&name_store, sizeof (struct saved_name) + namelen);
|
||||
|
||||
/* pointed object */
|
||||
new->dirid = get_deh_dirid (deh);
|
||||
new->objectid = get_deh_objectid (deh);
|
||||
|
||||
/* pointer to first name which points the same key */
|
||||
new->first_name = 0;
|
||||
|
||||
/* where this name is from */
|
||||
new->parent_dirid = get_key_dirid (&ih->ih_key);
|
||||
new->parent_objectid = get_key_objectid (&ih->ih_key);
|
||||
new->block = bh->b_blocknr;
|
||||
|
||||
new->count = 1;
|
||||
new->items = 0;
|
||||
|
||||
/* name */
|
||||
new->name_len = namelen;
|
||||
memcpy (new->name, name, namelen);
|
||||
new->name [namelen] = 0;
|
||||
new->name_next = 0;
|
||||
|
||||
/*
|
||||
reiserfs_warning (stdout, "\n(%K):%s-->(%K) - ", &new->parent_dirid,
|
||||
new->name, &new->dirid);
|
||||
*/
|
||||
if (name_found (new, &name_in)) {
|
||||
/* there was already exactly this name */
|
||||
obstack_free (&name_store, new);
|
||||
continue;
|
||||
}
|
||||
|
||||
saved_names ++;
|
||||
add_name (new, name_in);
|
||||
add_key (new);
|
||||
} /* for each entry */
|
||||
} /* for each item */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* take every item, look for its key in the key index, if it is found - store
|
||||
item in the sorted list of items of a file */
|
||||
static void scan_items (struct buffer_head * bh)
|
||||
{
|
||||
int i;
|
||||
struct item_head * ih;
|
||||
struct saved_name * name_in_store;
|
||||
void * res;
|
||||
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) {
|
||||
res = tfind (&ih->ih_key, &key_index, comp_pointed);
|
||||
if (!res)
|
||||
/* there were no names pointing to this key */
|
||||
continue;
|
||||
|
||||
/* name pointing to this key found */
|
||||
name_in_store = *(struct saved_name **)res;
|
||||
|
||||
store_item (name_in_store, bh, ih);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* FIXME: does not work for long files */
|
||||
struct version {
|
||||
int flag; /* direct or indirect */
|
||||
int len;
|
||||
__u32 from;
|
||||
int count;
|
||||
void * data;
|
||||
};
|
||||
|
||||
|
||||
struct tail {
|
||||
__u32 offset;
|
||||
int len;
|
||||
char * data;
|
||||
};
|
||||
|
||||
|
||||
struct file_map {
|
||||
int head_len; /* number of unfm pointers */
|
||||
void * head;
|
||||
|
||||
int tail_nr; /* number of tails found */
|
||||
struct tail * tails;
|
||||
|
||||
int version_nr;
|
||||
void * versions; /* list of range versions */
|
||||
};
|
||||
|
||||
|
||||
struct file_map map;
|
||||
|
||||
|
||||
static int have_to_append (struct item_head * ih)
|
||||
{
|
||||
loff_t off = get_offset (&ih->ih_key);
|
||||
|
||||
if (is_indirect_ih (ih)) {
|
||||
if (map.head_len * fs->fs_blocksize + 1 <= off)
|
||||
return 1;
|
||||
return 0;
|
||||
} else if (is_direct_ih (ih)) {
|
||||
int i;
|
||||
__u32 tail_start;
|
||||
|
||||
tail_start = (off & ~(fs->fs_blocksize - 1)) + 1;
|
||||
|
||||
/* find correct tail first */
|
||||
for (i = 0; i < map.tail_nr; i ++) {
|
||||
if (map.tails[i].offset == tail_start) {
|
||||
if (map.tails[i].offset + map.tails[i].len <= off)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* there was no this tail yet */
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void do_append (struct item_head * ih, void * data)
|
||||
{
|
||||
int i;
|
||||
int padd;
|
||||
loff_t off = get_offset (&ih->ih_key);
|
||||
|
||||
if (is_indirect_ih (ih)) {
|
||||
|
||||
padd = (off - 1) / fs->fs_blocksize - map.head_len;
|
||||
map.head = realloc (map.head, (map.head_len + padd + I_UNFM_NUM (ih)) * 4);
|
||||
if (!map.head)
|
||||
reiserfs_panic ("realloc failed");
|
||||
memset ((char *)map.head + map.head_len * 4, 0, padd * 4);
|
||||
memcpy ((char *)map.head + (map.head_len + padd) * 4, data,
|
||||
get_ih_item_len (ih));
|
||||
map.head_len += (padd + I_UNFM_NUM (ih));
|
||||
|
||||
} else if (is_direct_ih (ih)) {
|
||||
int tail_start;
|
||||
int skip;
|
||||
|
||||
/* find correct tail first */
|
||||
tail_start = (off & ~(fs->fs_blocksize - 1)) + 1;
|
||||
skip = (off - 1) & (fs->fs_blocksize - 1);
|
||||
for (i = 0; i < map.tail_nr; i ++) {
|
||||
if (map.tails[i].offset == tail_start) {
|
||||
map.tails[i].data = realloc (map.tails[i].data,
|
||||
off - tail_start + get_ih_item_len (ih));
|
||||
if (!map.tails[i].data)
|
||||
reiserfs_panic ("realloc failed");
|
||||
padd = skip - map.tails[i].len;
|
||||
memset (map.tails[i].data + map.tails[i].len, 0, padd);
|
||||
memcpy (map.tails[i].data + map.tails[i].len + padd, data, get_ih_item_len (ih));
|
||||
map.tails[i].len += (padd + get_ih_item_len (ih));
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* allocate memory for new tail */
|
||||
map.tails = realloc (map.tails, (map.tail_nr + 1) * sizeof (struct tail));
|
||||
if (!map.tails)
|
||||
reiserfs_panic ("realloc failed");
|
||||
|
||||
map.tails[map.tail_nr].offset = off;
|
||||
map.tails[map.tail_nr].len = skip + get_ih_item_len (ih);
|
||||
map.tails[map.tail_nr].data = malloc (map.tails[map.tail_nr].len);
|
||||
memset (map.tails[map.tail_nr].data, 0, skip);
|
||||
memcpy (map.tails[map.tail_nr].data + skip, data, get_ih_item_len (ih));
|
||||
map.tail_nr ++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* map contains */
|
||||
static void do_overwrite (struct item_head * ih, void * data)
|
||||
{
|
||||
int skip; /* now may bytes/pointers to skip */
|
||||
int to_compare;
|
||||
int to_append;
|
||||
loff_t off = get_offset (&ih->ih_key);
|
||||
char * p;
|
||||
struct item_head tmp_ih;
|
||||
|
||||
if (is_indirect_ih (ih)) {
|
||||
|
||||
skip = (off - 1) / fs->fs_blocksize;
|
||||
to_compare = (map.head_len - skip > I_UNFM_NUM (ih)) ? I_UNFM_NUM (ih) :
|
||||
(map.head_len - skip);
|
||||
to_append = I_UNFM_NUM (ih) - to_compare;
|
||||
|
||||
p = (char *)map.head + skip * 4;
|
||||
|
||||
if (memcmp (p, data, to_compare * 4))
|
||||
reiserfs_warning (stderr, "overwrite (indirect): %H contains different data\n", ih);
|
||||
|
||||
if (to_append) {
|
||||
tmp_ih = *ih;
|
||||
set_ih_item_len (&tmp_ih, get_ih_item_len (ih) - to_compare * 4);
|
||||
set_offset (key_format (&ih->ih_key), &tmp_ih.ih_key, off + to_compare * fs->fs_blocksize);
|
||||
do_append (&tmp_ih, (char *)data + to_compare * 4);
|
||||
}
|
||||
|
||||
} else if (is_direct_ih (ih)) {
|
||||
int tail_start;
|
||||
int i;
|
||||
|
||||
/* find correct tail first */
|
||||
tail_start = (off & ~(fs->fs_blocksize - 1)) + 1;
|
||||
for (i = 0; i < map.tail_nr; i ++) {
|
||||
if (map.tails[i].offset == tail_start) {
|
||||
/* ih is a part of this tail */
|
||||
skip = (off - 1) & (fs->fs_blocksize - 1);
|
||||
to_compare = (map.tails[i].len - skip > get_ih_item_len (ih) ? get_ih_item_len (ih) :
|
||||
map.tails[i].len - skip);
|
||||
to_append = get_ih_item_len (ih) - to_compare;
|
||||
|
||||
p = (char *)map.tails[i].data + skip;
|
||||
|
||||
if (memcmp (p, data, to_compare))
|
||||
reiserfs_warning (stderr, "overwrite (direct): %H contains different data\n", ih);
|
||||
|
||||
if (to_append) {
|
||||
tmp_ih = *ih;
|
||||
set_ih_item_len (&tmp_ih, get_ih_item_len (ih) - to_compare);
|
||||
set_offset (key_format (&ih->ih_key), &tmp_ih.ih_key, off + to_compare);
|
||||
do_append (&tmp_ih, (char *)data + to_compare);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
reiserfs_panic ("no appropriate tail found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void map_one_item (struct saved_item * item)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
struct item_head * ih;
|
||||
void * data;
|
||||
|
||||
/* read the block containing the item */
|
||||
bh = bread (fs->fs_dev, item->si_block, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "bread failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, item->si_item_num);
|
||||
data = B_I_PITEM (bh, ih);
|
||||
if (memcmp (&item->si_ih, ih, sizeof (*ih)))
|
||||
reiserfs_panic ("wrong item");
|
||||
|
||||
if (have_to_append (ih)) {
|
||||
do_append (ih, data);
|
||||
} else
|
||||
do_overwrite (ih, data);
|
||||
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
|
||||
static void map_item_list (const void *nodep, VISIT value, int level)
|
||||
{
|
||||
struct saved_item * item, * longest;
|
||||
int bytes, max_bytes;
|
||||
|
||||
if (value != leaf && value != postorder)
|
||||
return;
|
||||
|
||||
item = *(struct saved_item **)nodep;
|
||||
|
||||
/* 1. find the longest item */
|
||||
max_bytes = get_bytes_number (&item->si_ih, fs->fs_blocksize);
|
||||
longest = item;
|
||||
while (item->si_next) {
|
||||
item = item->si_next;
|
||||
bytes = get_bytes_number (&item->si_ih, fs->fs_blocksize);
|
||||
if (bytes > max_bytes) {
|
||||
longest = item;
|
||||
max_bytes = bytes;
|
||||
}
|
||||
}
|
||||
|
||||
map_one_item (longest);
|
||||
|
||||
/* map other items */
|
||||
item = *(struct saved_item **)nodep;
|
||||
while (item) {
|
||||
if (item != longest)
|
||||
map_one_item (item);
|
||||
item = item->si_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* flush map which is in variable map */
|
||||
static void flush_map (reiserfs_filsys_t * fs,
|
||||
struct key * dir,
|
||||
char * name,
|
||||
struct key * key)
|
||||
{
|
||||
int i;
|
||||
FILE * fp;
|
||||
__u32 v32;
|
||||
|
||||
|
||||
if (!map_file (fs))
|
||||
asprintf (&map_file (fs), "%s", ".map");
|
||||
|
||||
/*reiserfs_warning (stderr, "Saving maps into %s\n", map_file (fs));*/
|
||||
fp = fopen (map_file (fs), "a");
|
||||
if (fp == 0) {
|
||||
reiserfs_warning (stderr, "flush_map: fopen failed: %m");
|
||||
return;
|
||||
}
|
||||
|
||||
v32 = MAP_MAGIC;
|
||||
fwrite (&v32, sizeof (v32), 1, fp);
|
||||
|
||||
/* device name */
|
||||
v32 = strlen (device_name (fs)) + 1;
|
||||
fwrite (&v32, sizeof (v32), 1, fp);
|
||||
fwrite (device_name (fs), v32, 1, fp);
|
||||
|
||||
/* name length and the name itself */
|
||||
v32 = strlen (name) + 1;
|
||||
fwrite (&v32, sizeof (v32), 1, fp);
|
||||
fwrite (name, v32, 1, fp);
|
||||
|
||||
/* short key of a directory */
|
||||
fwrite (dir, SHORT_KEY_SIZE, 1, fp);
|
||||
|
||||
/* short key of file */
|
||||
fwrite (key, SHORT_KEY_SIZE, 1, fp);
|
||||
|
||||
/* list of data block pointers */
|
||||
fwrite (&map.head_len, sizeof (map.head_len), 1, fp);
|
||||
fwrite (map.head, map.head_len * 4, 1, fp);
|
||||
|
||||
|
||||
/* find correct tail first */
|
||||
for (i = 0; i < map.tail_nr; i ++) {
|
||||
if (map.tails [i].offset == map.head_len * fs->fs_blocksize) {
|
||||
/* tail length and the tail itself */
|
||||
fwrite (&map.tails [i].len, sizeof (map.tails [i].len), 1, fp);
|
||||
fwrite (map.tails [i].data, map.tails [i].len, 1, fp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == map.tail_nr) {
|
||||
/* no tail */
|
||||
v32 = 0;
|
||||
fwrite (&v32, sizeof (v32), 1, fp);
|
||||
}
|
||||
|
||||
v32 = MAP_END_MAGIC;
|
||||
fwrite (&v32, sizeof (v32), 1, fp);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
|
||||
/* write map of file to a map file */
|
||||
static void make_file_map (const void *nodep, VISIT value, int level)
|
||||
{
|
||||
struct saved_name * name;
|
||||
static int nr = 0;
|
||||
|
||||
name = *(struct saved_name **)nodep;
|
||||
|
||||
if (value == leaf || value == postorder) {
|
||||
while (name) {
|
||||
reiserfs_warning (stdout, "%d - (%d): [%K]:\"%s\":\n", ++nr, name->count,
|
||||
&name->parent_dirid, name->name);
|
||||
|
||||
if (name->items) {
|
||||
/* initialize the map */
|
||||
memset (&map, 0, sizeof (struct file_map));
|
||||
|
||||
/* make a map of file */
|
||||
twalk (name->items, map_item_list);
|
||||
|
||||
/* write map to a file */
|
||||
flush_map (fs, (struct key *)&name->parent_dirid, name->name,
|
||||
(struct key *)&name->dirid);
|
||||
|
||||
} else if (name->first_name)
|
||||
reiserfs_warning (stdout, "[%K]:\"%s\" has item list\n",
|
||||
&name->first_name->parent_dirid,
|
||||
name->first_name->name);
|
||||
else {
|
||||
reiserfs_warning (stdout, "No items of the file [%K] found\n",
|
||||
&name->dirid);
|
||||
}
|
||||
|
||||
name = name->name_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* file.list will contain list of names such that it can be used as
|
||||
input for -N */
|
||||
static void print_name (const void *nodep, VISIT value, int level)
|
||||
{
|
||||
struct saved_name * name;
|
||||
static FILE * fp = 0;
|
||||
|
||||
if (fp == 0) {
|
||||
fp = fopen ("file.list", "w+");
|
||||
if (!fp)
|
||||
reiserfs_panic ("could open file.list: %m");
|
||||
}
|
||||
name = *(struct saved_name **)nodep;
|
||||
if (value == leaf || value == postorder) {
|
||||
while (name) {
|
||||
if (name->items)
|
||||
/* we have found items of this file */
|
||||
reiserfs_warning (fp, "%u %u %s\n",
|
||||
name->parent_dirid, name->parent_objectid,
|
||||
name->name);
|
||||
name = name->name_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* store map if it is a regular file */
|
||||
static void locate_file (reiserfs_filsys_t * fs, struct key * key)
|
||||
{
|
||||
INITIALIZE_PATH (path);
|
||||
struct key * next_key;
|
||||
int retval;
|
||||
|
||||
do {
|
||||
retval = reiserfs_search_by_key_4 (fs, key, &path);
|
||||
if (retval != ITEM_FOUND)
|
||||
break;
|
||||
|
||||
if (!is_stat_data_key (key) && !is_direntry_key (key)) {
|
||||
struct saved_item si;
|
||||
|
||||
si.si_block = get_bh (&path)->b_blocknr;
|
||||
si.si_item_num = get_item_pos (&path);
|
||||
si.si_ih = *get_ih (&path);
|
||||
map_one_item (&si);
|
||||
}
|
||||
|
||||
/*reiserfs_warning (stdout, "\t");
|
||||
reiserfs_print_item (stdout, get_bh (&path), get_ih (&path));*/
|
||||
|
||||
next_key = reiserfs_next_key (&path);
|
||||
if (!next_key || not_of_one_file (next_key, key))
|
||||
break;
|
||||
|
||||
*key = *next_key;
|
||||
pathrelse (&path);
|
||||
} while (1);
|
||||
|
||||
pathrelse (&path);
|
||||
}
|
||||
|
||||
|
||||
/* read stdin and look for specified name in the specified directory */
|
||||
static void look_for_name (reiserfs_filsys_t * fs)
|
||||
{
|
||||
INITIALIZE_PATH (path);
|
||||
char * name, * objectid, * dirid;
|
||||
size_t n;
|
||||
struct key key = {0, };
|
||||
|
||||
reiserfs_warning (stderr,
|
||||
"Enter dirid objectid \"name\" or press ^D to quit\n");
|
||||
while (1) {
|
||||
reiserfs_warning (stderr, ">");
|
||||
n = 0; dirid = 0;
|
||||
if (getdelim (&dirid, &n, ' ', stdin) == -1)
|
||||
break;
|
||||
if (!strcmp (dirid, "\n"))
|
||||
break;
|
||||
set_key_dirid (&key, atol (dirid));
|
||||
|
||||
n = 0; objectid = 0;
|
||||
if (getdelim (&objectid, &n, ' ', stdin) == -1)
|
||||
break;
|
||||
set_key_objectid (&key, atol (objectid));
|
||||
|
||||
n = 0; name = 0;
|
||||
if (getdelim (&name, &n, '\n', stdin) == -1)
|
||||
break;
|
||||
|
||||
name [strlen (name) - 1] = 0;
|
||||
reiserfs_warning (stdout, "looking for file \"%s\" in (%K) - ",
|
||||
name, &key);
|
||||
|
||||
if (reiserfs_locate_entry (fs, &key, name, &path)) {
|
||||
struct key fkey = {0, };
|
||||
struct reiserfs_de_head * deh;
|
||||
|
||||
reiserfs_warning (stdout, "name is found in block %lu (item %d, entry %d)\n",
|
||||
get_bh (&path)->b_blocknr, get_item_pos (&path),
|
||||
path.pos_in_item);
|
||||
deh = B_I_DEH (get_bh (&path), get_ih (&path)) + path.pos_in_item;
|
||||
set_key_dirid (&fkey, get_deh_dirid (deh));
|
||||
set_key_objectid (&fkey, get_deh_objectid (deh));
|
||||
|
||||
pathrelse (&path);
|
||||
|
||||
/* look for file and print its layout */
|
||||
memset (&map, 0, sizeof (struct file_map));
|
||||
|
||||
locate_file (fs, &fkey);
|
||||
|
||||
flush_map (fs, &key, name, &fkey);
|
||||
|
||||
} else {
|
||||
reiserfs_warning (stdout, "name not found\n");
|
||||
}
|
||||
|
||||
free (dirid);
|
||||
free (objectid);
|
||||
free (name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FILE * log;
|
||||
|
||||
static void scan_for_key (struct buffer_head * bh, struct key * key)
|
||||
{
|
||||
int i, j;
|
||||
struct item_head * ih;
|
||||
struct reiserfs_de_head * deh;
|
||||
int min_entry_size = 1;
|
||||
int ih_entry_count = 0;
|
||||
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) {
|
||||
if ((get_key_dirid (&ih->ih_key) == get_key_dirid (key) ||
|
||||
(int)get_key_dirid (key) == -1) &&
|
||||
(get_key_objectid (&ih->ih_key) == get_key_objectid (key) ||
|
||||
(int)get_key_objectid (key) == -1)) {
|
||||
reiserfs_warning (log, "%d-th item of block %lu is item of file %K: %H\n",
|
||||
i, bh->b_blocknr, key, ih);
|
||||
}
|
||||
if (!is_direntry_ih (ih))
|
||||
continue;
|
||||
deh = B_I_DEH (bh, ih);
|
||||
|
||||
if ( (get_ih_entry_count (ih) > (get_ih_item_len(ih) / (DEH_SIZE + min_entry_size))) ||
|
||||
(get_ih_entry_count (ih) == 0))
|
||||
ih_entry_count = get_ih_item_len(ih) / (DEH_SIZE + min_entry_size);
|
||||
else
|
||||
ih_entry_count = get_ih_entry_count (ih);
|
||||
|
||||
|
||||
for (j = 0; j < ih_entry_count; j ++, deh ++) {
|
||||
if ((get_deh_dirid (deh) == get_key_dirid (key) || (int)get_key_dirid (key) == -1) &&
|
||||
(get_deh_objectid (deh) == get_key_objectid (key) || (int)get_key_objectid (key) == -1)) {
|
||||
reiserfs_warning (log, "dir item %d (%H) of block %lu has "
|
||||
"entry (%d-th) %.*s pointing to %K\n",
|
||||
i, ih, bh->b_blocknr, j,
|
||||
name_in_entry_length (ih, deh, j), name_in_entry (deh, j), key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void do_scan (reiserfs_filsys_t * fs)
|
||||
{
|
||||
unsigned long i;
|
||||
struct buffer_head * bh;
|
||||
int type;
|
||||
char * answer = 0;
|
||||
size_t n = 0;
|
||||
struct key key = {0, 0, };
|
||||
unsigned long done, total;
|
||||
|
||||
|
||||
if (debug_mode (fs) == DO_SCAN_JOURNAL) {
|
||||
scan_journal (fs);
|
||||
return;
|
||||
}
|
||||
|
||||
if (debug_mode (fs) == DO_LOOK_FOR_NAME) {
|
||||
/* look for a file in using tree algorithms */
|
||||
look_for_name (fs);
|
||||
return;
|
||||
}
|
||||
|
||||
/* scan area of disk and store all names matching the pattern */
|
||||
|
||||
/* initialize storage and two indexes */
|
||||
obstack_init (&name_store);
|
||||
obstack_init (&item_store);
|
||||
key_index = 0;
|
||||
name_index = 0;
|
||||
|
||||
total = reiserfs_bitmap_ones (input_bitmap (fs));
|
||||
|
||||
log = fopen ("scan.log", "w+");
|
||||
printf ("Log file 'scan.log' is opened\n");
|
||||
|
||||
if (debug_mode (fs) == DO_SCAN_FOR_NAME) {
|
||||
if (regcomp (&pattern, name_pattern (fs), 0)) {
|
||||
printf ("regcomp failed");
|
||||
return;
|
||||
}
|
||||
|
||||
printf ("Looking for names matching %s\n", name_pattern (fs));
|
||||
set_key_dirid (&key, 1);
|
||||
} else {
|
||||
printf ("What key do you want to find: dirid?");
|
||||
getline (&answer, &n, stdin);
|
||||
set_key_dirid (&key, atoi (answer));
|
||||
|
||||
printf ("objectid?");
|
||||
getline (&answer, &n, stdin);
|
||||
set_key_objectid (&key, atoi (answer));
|
||||
reiserfs_warning (stderr, "looking for (%K)\n", &key);
|
||||
}
|
||||
|
||||
done = 0;
|
||||
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
|
||||
if (!reiserfs_bitmap_test_bit (input_bitmap (fs), i))
|
||||
continue;
|
||||
bh = bread (fs->fs_dev, i, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
printf ("could not read block %lu\n", i);
|
||||
continue;
|
||||
}
|
||||
type = who_is_this (bh->b_data, bh->b_size);
|
||||
switch (type) {
|
||||
case THE_JDESC:
|
||||
if (!get_key_dirid (&key))
|
||||
printf ("block %lu is journal descriptor\n", i);
|
||||
reiserfs_bitmap_clear_bit (input_bitmap (fs), i);
|
||||
break;
|
||||
case THE_SUPER:
|
||||
if (!get_key_dirid (&key))
|
||||
printf ("block %lu is reiserfs super block\n", i);
|
||||
reiserfs_bitmap_clear_bit (input_bitmap (fs), i);
|
||||
break;
|
||||
case THE_INTERNAL:
|
||||
if (!get_key_dirid (&key))
|
||||
printf ("block %lu is reiserfs internal node\n", i);
|
||||
reiserfs_bitmap_clear_bit (input_bitmap (fs), i);
|
||||
break;
|
||||
case THE_LEAF:
|
||||
if (debug_mode (fs) == DO_SCAN_FOR_NAME) {
|
||||
scan_for_name (bh);
|
||||
} else if (get_key_dirid (&key)) {
|
||||
scan_for_key (bh, &key);
|
||||
} else {
|
||||
printf ("block %lu is reiserfs leaf node\n", i);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
reiserfs_bitmap_clear_bit (input_bitmap (fs), i);
|
||||
break;
|
||||
}
|
||||
brelse (bh);
|
||||
print_how_far (stderr, &done, total, 1, be_quiet (fs));
|
||||
}
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
if (debug_mode (fs) == DO_SCAN_FOR_NAME)
|
||||
fprintf (stderr, "There were found %d names matching the pattern \"%s\", %d names skipped\n",
|
||||
saved_names, name_pattern (fs), skipped_names);
|
||||
fflush (stderr);
|
||||
|
||||
|
||||
if (debug_mode (fs) != DO_SCAN_FOR_NAME)
|
||||
return;
|
||||
|
||||
/* step 2: */
|
||||
done = 0;
|
||||
total = reiserfs_bitmap_ones (input_bitmap (fs));
|
||||
printf ("%ld bits set in bitmap\n", total);
|
||||
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
|
||||
if (!reiserfs_bitmap_test_bit (input_bitmap (fs), i))
|
||||
continue;
|
||||
bh = bread (fs->fs_dev, i, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
printf ("could not read block %lu\n", i);
|
||||
continue;
|
||||
}
|
||||
if (who_is_this (bh->b_data, bh->b_size) != THE_LEAF) {
|
||||
brelse (bh);
|
||||
continue;
|
||||
}
|
||||
|
||||
scan_items (bh);
|
||||
|
||||
brelse (bh);
|
||||
print_how_far (stderr, &done, total, 1, be_quiet (fs));
|
||||
}
|
||||
fprintf (stderr, "\nThere were %d items saved\n", saved_items);
|
||||
|
||||
/* ok, print what we found */
|
||||
/*twalk (name_index, print_file);*/
|
||||
|
||||
/* create map for every file in */
|
||||
twalk (name_index, make_file_map);
|
||||
|
||||
/* print names of files we have map of in a file 'file.list' */
|
||||
twalk (name_index, print_name);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* Copyright 2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#include "debugreiserfs.h"
|
||||
#include <search.h>
|
||||
#include <obstack.h>
|
||||
|
||||
#define obstack_chunk_alloc malloc
|
||||
#define obstack_chunk_free free
|
||||
|
||||
|
||||
/* try to find blocks which contain only items which are */
|
||||
|
||||
|
||||
/* read blocks marked in debug_bitmap and collect statistic of it:
|
||||
number of stat data */
|
||||
struct {
|
||||
unsigned long all;
|
||||
unsigned long items [5];
|
||||
unsigned long unique_keys; /* keys of stat datas */
|
||||
unsigned long unique_entry_keys; /* keys which appear in directory entries */
|
||||
unsigned long names; /* dir entries but "." and ".." */
|
||||
unsigned long dir_blocks; /* block containing only one directory item */
|
||||
unsigned long unique_items;
|
||||
unsigned long leaves;
|
||||
unsigned long blocks_to_skip;
|
||||
} fs_stat;
|
||||
|
||||
|
||||
/* store unique item heads */
|
||||
struct obstack items;
|
||||
|
||||
/* tree sorting item heades by comp_items_1 */
|
||||
void * items_tree;
|
||||
|
||||
|
||||
static int comp_items_1 (const void * p1, const void * p2)
|
||||
{
|
||||
int retval;
|
||||
struct item_head * ih1, * ih2;
|
||||
|
||||
/*
|
||||
if (*(int *)p1 != *(int *)p2)
|
||||
retval = 1;
|
||||
else
|
||||
retval = 0;
|
||||
*/
|
||||
retval = comp_keys (p1, p2);
|
||||
/*retval = comp_short_keys (p1, p2);*/
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
|
||||
ih1 = (struct item_head *)p1;
|
||||
ih2 = (struct item_head *)p2;
|
||||
|
||||
if (get_ih_item_len (ih1) < get_ih_item_len (ih2))
|
||||
return -1;
|
||||
if (get_ih_item_len (ih1) > get_ih_item_len (ih2))
|
||||
return 1;
|
||||
if (get_ih_entry_count (ih1) < get_ih_entry_count (ih2))
|
||||
return -1;
|
||||
if (get_ih_entry_count (ih1) > get_ih_entry_count (ih2))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
static void print_node (const void *nodep, VISIT value, int level)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (value == leaf) {
|
||||
for (i = 0; i < level; i ++)
|
||||
reiserfs_warning (stdout, "\t");
|
||||
reiserfs_warning (stdout, "%H\n", *(struct item_head **)nodep);
|
||||
return;
|
||||
}
|
||||
if (value == postorder) {
|
||||
for (i = 0; i < level; i ++)
|
||||
reiserfs_warning (stdout, "\t");
|
||||
reiserfs_warning (stdout, "%H\n", *(struct item_head **)nodep);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static int is_unique_item (struct obstack * ostack, void ** tree, void * ih)
|
||||
{
|
||||
void * res;
|
||||
void * key1;
|
||||
|
||||
key1 = obstack_copy (ostack, ih, IH_SIZE);
|
||||
res = tsearch (key1, tree, comp_items_1);
|
||||
if (!res)
|
||||
reiserfs_panic ("Too many keys found");
|
||||
|
||||
/* twalk (*tree, print_node);*/
|
||||
/* reiserfs_warning (stderr, "\n\n");*/
|
||||
if (*(void **)res != key1) {
|
||||
/* key is in tree already, remove it from obstack */
|
||||
/*reiserfs_warning (stdout, "%H is skipped\n", ih);fflush (stdout);*/
|
||||
obstack_free (ostack, key1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*reiserfs_warning (stdout, "%k is added\n", ih);fflush (stdout);*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void stat1_the_leaf (reiserfs_filsys_t * fs, struct buffer_head * bh)
|
||||
{
|
||||
int i;
|
||||
struct item_head * ih;
|
||||
int is_there_unique_item;
|
||||
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
is_there_unique_item = 0;
|
||||
for (i = 0; i < get_blkh_nr_items (B_BLK_HEAD (bh)); i ++, ih ++) {
|
||||
/* count all items */
|
||||
fs_stat.all ++;
|
||||
|
||||
if (is_unique_item (&items, &items_tree, ih)) {
|
||||
/* this is item we have not seen yet */
|
||||
fs_stat.unique_items ++;
|
||||
is_there_unique_item ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_there_unique_item) {
|
||||
/* the node contains only items we have seen already. so we will skip
|
||||
it */
|
||||
fs_stat.blocks_to_skip ++;
|
||||
reiserfs_bitmap_clear_bit (input_bitmap (fs), bh->b_blocknr);
|
||||
} else {
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
/* node contains at least one unique item. We will put it in, count items of each type */
|
||||
for (i = 0; i < get_blkh_nr_items (B_BLK_HEAD (bh)); i ++, ih ++) {
|
||||
fs_stat.items [get_type (&ih->ih_key)] ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
static void stat2_the_leaf (struct buffer_head * bh)
|
||||
{
|
||||
int i;
|
||||
struct item_head * ih;
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < node_item_number (bh); i ++, ih ++) {
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void do_stat (reiserfs_filsys_t * fs)
|
||||
{
|
||||
unsigned long i;
|
||||
unsigned long done, total;
|
||||
struct buffer_head * bh;
|
||||
int type;
|
||||
FILE * fp;
|
||||
|
||||
|
||||
obstack_init (&items);
|
||||
items_tree = 0;
|
||||
|
||||
/*
|
||||
bh = bread (fs->s_dev, 8211, fs->s_blocksize);
|
||||
stat1_the_leaf (fs, bh);
|
||||
|
||||
return;
|
||||
*/
|
||||
|
||||
|
||||
|
||||
total = reiserfs_bitmap_ones (input_bitmap (fs));
|
||||
|
||||
/* pass 0 of stating */
|
||||
total = reiserfs_bitmap_ones (input_bitmap (fs));
|
||||
done = 0;
|
||||
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
|
||||
if (!reiserfs_bitmap_test_bit (input_bitmap (fs), i))
|
||||
continue;
|
||||
|
||||
print_how_far (stderr, &done, total, 1, be_quiet (fs));
|
||||
|
||||
bh = bread (fs->fs_dev, i, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
printf ("could not read block %lu\n", i);
|
||||
continue;
|
||||
}
|
||||
type = who_is_this (bh->b_data, bh->b_size);
|
||||
if (type != THE_LEAF) {
|
||||
reiserfs_bitmap_clear_bit (input_bitmap (fs), i);
|
||||
brelse (bh);
|
||||
continue;
|
||||
}
|
||||
fs_stat.leaves ++;
|
||||
stat1_the_leaf (fs, bh);
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
reiserfs_warning (stderr, "\nThere were %lu leaves\n"
|
||||
"\ttotal number of items %lu there\n"
|
||||
"\tblocks containing at least one unique item %lu\n"
|
||||
"\tblocks which can be skipped %lu\n"
|
||||
"\t\tstat data %lu\n"
|
||||
"\t\tindirect %lu\n"
|
||||
"\t\tdirect %lu\n"
|
||||
"\t\tdirectory items %lu\n"
|
||||
"\tunique items %lu\n",
|
||||
/*
|
||||
"\tnames there (but \".\" and \"..\") %lu\n"
|
||||
"\tpointing to unique keys %lu\n"
|
||||
"other items %lu\n"
|
||||
"blocks containing only 1 dir item %lu\n",
|
||||
*/
|
||||
fs_stat.leaves,
|
||||
fs_stat.all,
|
||||
fs_stat.leaves - fs_stat.blocks_to_skip,
|
||||
fs_stat.blocks_to_skip,
|
||||
fs_stat.items [TYPE_STAT_DATA],
|
||||
fs_stat.items [TYPE_INDIRECT],
|
||||
fs_stat.items [TYPE_DIRECT],
|
||||
fs_stat.items [TYPE_DIRENTRY],
|
||||
fs_stat.unique_items);
|
||||
/*
|
||||
fs_stat.names,
|
||||
fs_stat.unique_keys,
|
||||
fs_stat.items [4],
|
||||
fs_stat.dir_blocks);
|
||||
*/
|
||||
if (!input_bitmap_file_name(fs))
|
||||
return;
|
||||
|
||||
fp = fopen (input_bitmap_file_name(fs), "w");
|
||||
if (!fp)
|
||||
reiserfs_panic ("stat: could not open %s to save bitmap: %m\n",
|
||||
input_bitmap_file_name(fs));
|
||||
reiserfs_warning (stderr, "Updated bitmap contains %d blocks marked\n",
|
||||
reiserfs_bitmap_ones (input_bitmap (fs)));
|
||||
reiserfs_bitmap_save (fp, input_bitmap (fs));
|
||||
fclose (fp);
|
||||
return;
|
||||
|
||||
|
||||
/* pass 2 of stating */
|
||||
reiserfs_warning (stderr, "Looking for blocks containing only keys not pointed by any of entries\n");
|
||||
total = reiserfs_bitmap_ones (input_bitmap (fs));
|
||||
done = 0;
|
||||
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
|
||||
if (!reiserfs_bitmap_test_bit (input_bitmap (fs), i))
|
||||
continue;
|
||||
|
||||
print_how_far (stderr, &done, total, 1, be_quiet (fs));
|
||||
|
||||
bh = bread (fs->fs_dev, i, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
printf ("could not read block %lu\n", i);
|
||||
continue;
|
||||
}
|
||||
/*stat2_the_leaf (bh);*/
|
||||
}
|
||||
|
||||
}
|
||||
+185
-102
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#include "debugreiserfs.h"
|
||||
@@ -8,41 +8,52 @@
|
||||
|
||||
#define print_usage_and_exit() die ("Usage: %s [-v] [-b filename] device\n\
|
||||
-v prints blocks number of every block unpacked\n\
|
||||
-b filename makes unpack to save bitmap of blocks unpacked\n", argv[0]);
|
||||
|
||||
-b filename makes unpack to save bitmap of blocks unpacked\n\
|
||||
-j filename makes unpack to store journal in specified file\n", argv[0]);
|
||||
|
||||
|
||||
/* when super block gets unpacked for the first time - create a bitmap
|
||||
and mark in it what have been unpacked. Save that bitmap at the end */
|
||||
reiserfs_bitmap_t what_unpacked = 0;
|
||||
reiserfs_bitmap_t * what_unpacked = 0;
|
||||
|
||||
|
||||
int unpacked, data_blocks_unpacked;
|
||||
int leaves, full;
|
||||
|
||||
int verbose = 0;
|
||||
|
||||
int Default_journal = 1;
|
||||
|
||||
|
||||
static void unpack_offset (struct packed_item * pi, struct item_head * ih)
|
||||
static void unpack_offset (struct packed_item * pi, struct item_head * ih, int blocksize)
|
||||
{
|
||||
if (pi->mask & OFFSET_BITS_64) {
|
||||
|
||||
if (get_pi_mask(pi) & OFFSET_BITS_64) {
|
||||
__u64 v64;
|
||||
|
||||
if (ih_key_format (ih) != KEY_FORMAT_2)
|
||||
if (get_ih_key_format (ih) != KEY_FORMAT_2)
|
||||
die ("unpack_offset: key format is not set or wrong");
|
||||
fread64 (&v64);
|
||||
fread_le64 (&v64);
|
||||
set_offset (KEY_FORMAT_2, &ih->ih_key, v64);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pi->mask & OFFSET_BITS_32) {
|
||||
if (get_pi_mask(pi) & OFFSET_BITS_32) {
|
||||
__u32 v32;
|
||||
|
||||
fread32 (&v32);
|
||||
set_offset (ih_key_format (ih), &ih->ih_key, v32);
|
||||
fread_le32 (&v32);
|
||||
set_offset (get_ih_key_format (ih), &ih->ih_key, v32);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((get_pi_mask(pi) & DIR_ID) == 0 && (get_pi_mask(pi) & OBJECT_ID) == 0) {
|
||||
/* offset was not sent, as it can be calculated looking at the
|
||||
previous item */
|
||||
if (is_stat_data_ih (ih - 1))
|
||||
set_offset (get_ih_key_format (ih), &ih->ih_key, 1);
|
||||
if (is_indirect_ih (ih - 1))
|
||||
set_offset (get_ih_key_format (ih), &ih->ih_key,
|
||||
get_offset (&(ih - 1)->ih_key) + get_bytes_number (ih - 1, blocksize));
|
||||
}
|
||||
|
||||
// offset is 0
|
||||
return;
|
||||
}
|
||||
@@ -50,21 +61,14 @@ static void unpack_offset (struct packed_item * pi, struct item_head * ih)
|
||||
|
||||
static void unpack_type (struct packed_item * pi, struct item_head * ih)
|
||||
{
|
||||
if (pi->mask & DIRECT_ITEM)
|
||||
set_type (ih_key_format (ih), &ih->ih_key, TYPE_DIRECT);
|
||||
else if (pi->mask & STAT_DATA_ITEM)
|
||||
set_type (ih_key_format (ih), &ih->ih_key, TYPE_STAT_DATA);
|
||||
else if (pi->mask & INDIRECT_ITEM)
|
||||
set_type (ih_key_format (ih), &ih->ih_key, TYPE_INDIRECT);
|
||||
else if (pi->mask & DIRENTRY_ITEM)
|
||||
set_type (ih_key_format (ih), &ih->ih_key, TYPE_DIRENTRY);
|
||||
else
|
||||
reiserfs_panic (0, "%h, mask 0%o\n", ih, pi->mask);
|
||||
set_type (get_ih_key_format (ih), &ih->ih_key, get_pi_type(pi));
|
||||
if (type_unknown (&ih->ih_key))
|
||||
reiserfs_panic ("unpack_type: unknown type %d unpacked for %H\n",
|
||||
get_pi_type(pi), ih);
|
||||
}
|
||||
|
||||
|
||||
/* direntry item comes in the following format:
|
||||
entry count - 16 bits
|
||||
for each entry
|
||||
mask - 8 bits
|
||||
entry length - 16 bits
|
||||
@@ -87,17 +91,21 @@ static void unpack_direntry (struct packed_item * pi, struct buffer_head * bh,
|
||||
if (!hash_func)
|
||||
die ("unpack_direntry: hash function is not set");
|
||||
|
||||
fread16 (&entry_count);
|
||||
set_entry_count (ih, entry_count);
|
||||
if (!(get_pi_mask(pi) & IH_FREE_SPACE))
|
||||
die ("ih_entry_count must be packed for directory items");
|
||||
|
||||
item = bh->b_data + ih_location (ih);
|
||||
entry_count = get_ih_entry_count (ih);
|
||||
/* if (!entry_count)
|
||||
reiserfs_panic ("unpack_direntry: entry count should be set already");*/
|
||||
|
||||
item = bh->b_data + get_ih_location (ih);
|
||||
deh = (struct reiserfs_de_head *)item;
|
||||
location = pi->item_len;
|
||||
location = get_pi_item_len(pi);
|
||||
for (i = 0; i < entry_count; i ++, deh ++) {
|
||||
fread8 (&mask);
|
||||
fread16 (&entry_len);
|
||||
fread_le16 (&entry_len);
|
||||
location -= entry_len;
|
||||
deh->deh_location = location;
|
||||
set_deh_location (deh, location);
|
||||
fread (item + location, entry_len, 1, stdin);
|
||||
|
||||
/* find name length */
|
||||
@@ -106,29 +114,30 @@ static void unpack_direntry (struct packed_item * pi, struct buffer_head * bh,
|
||||
else
|
||||
namelen = strlen (item + location);
|
||||
|
||||
fread32 (&deh->deh_objectid);
|
||||
fread32 (&deh->deh2_objectid);
|
||||
if (mask & HAS_DIR_ID)
|
||||
fread32 (&deh->deh_dir_id);
|
||||
fread32 (&deh->deh2_dir_id);
|
||||
else
|
||||
deh->deh_dir_id = ih->ih_key.k_objectid;
|
||||
set_deh_dirid (deh, get_key_objectid (&ih->ih_key));
|
||||
|
||||
if (*(item + location) == '.' && namelen == 1)
|
||||
/* old or new "." */
|
||||
deh->deh_offset = DOT_OFFSET;
|
||||
set_deh_offset (deh, DOT_OFFSET);
|
||||
else if (*(item + location) == '.' && *(item + location + 1) == '.' && namelen == 2)
|
||||
/* old or new ".." */
|
||||
deh->deh_offset = DOT_DOT_OFFSET;
|
||||
set_deh_offset (deh, DOT_DOT_OFFSET);
|
||||
else
|
||||
deh->deh_offset = GET_HASH_VALUE (hash_func (item + location,
|
||||
namelen));
|
||||
set_deh_offset (deh, GET_HASH_VALUE (hash_func (item + location,
|
||||
namelen)));
|
||||
if (mask & HAS_GEN_COUNTER) {
|
||||
fread16 (&gen_counter);
|
||||
deh->deh_offset |= gen_counter;
|
||||
fread_le16 (&gen_counter);
|
||||
set_deh_offset (deh, get_deh_offset (deh) | gen_counter);
|
||||
}
|
||||
|
||||
if (mask & HAS_STATE)
|
||||
fread16 (&deh->deh_state);
|
||||
fread16 (&deh->deh2_state);
|
||||
else
|
||||
deh->deh_state = (1 << DEH_Visible);
|
||||
set_deh_state (deh, (1 << DEH_Visible2));
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -139,9 +148,12 @@ static void unpack_direntry (struct packed_item * pi, struct buffer_head * bh,
|
||||
static void unpack_stat_data (struct packed_item * pi, struct buffer_head * bh,
|
||||
struct item_head * ih)
|
||||
{
|
||||
set_entry_count (ih, 0xffff);
|
||||
if (!(get_pi_mask(pi) & IH_FREE_SPACE)) {
|
||||
/* ih_free_space was not packed - set default */
|
||||
set_ih_entry_count (ih, 0xffff);
|
||||
}
|
||||
|
||||
if (ih_key_format (ih) == KEY_FORMAT_1) {
|
||||
if (get_ih_key_format (ih) == KEY_FORMAT_1) {
|
||||
/* stat data comes in the following format:
|
||||
if this is old stat data:
|
||||
mode - 16 bits
|
||||
@@ -160,7 +172,7 @@ static void unpack_stat_data (struct packed_item * pi, struct buffer_head * bh,
|
||||
fread32 (&sd->sd_size);
|
||||
fread32 (&sd->u.sd_blocks);
|
||||
|
||||
if (pi->mask & WITH_SD_FIRST_DIRECT_BYTE) {
|
||||
if (get_pi_mask(pi) & WITH_SD_FIRST_DIRECT_BYTE) {
|
||||
fread32 (&sd->sd_first_direct_byte);
|
||||
} else {
|
||||
sd->sd_first_direct_byte = 0xffffffff;
|
||||
@@ -179,22 +191,23 @@ static void unpack_stat_data (struct packed_item * pi, struct buffer_head * bh,
|
||||
|
||||
fread16 (&sd->sd_mode);
|
||||
|
||||
if (pi->mask & NLINK_BITS_32) {
|
||||
if (get_pi_mask(pi) & NLINK_BITS_32) {
|
||||
fread32 (&sd->sd_nlink);
|
||||
} else {
|
||||
__u16 nlink16;
|
||||
|
||||
fread16 (&nlink16);
|
||||
sd->sd_nlink = nlink16;
|
||||
set_sd_v2_nlink (sd, le16_to_cpu(nlink16));
|
||||
}
|
||||
|
||||
if (pi->mask & SIZE_BITS_64) {
|
||||
if (get_pi_mask(pi) & SIZE_BITS_64) {
|
||||
fread64 (&sd->sd_size);
|
||||
} else {
|
||||
__u32 size32;
|
||||
|
||||
fread32 (&size32);
|
||||
sd->sd_size = size32;
|
||||
/* We need the endian conversions since sd->sd_size is 64 bit */
|
||||
fread_le32 (&size32);
|
||||
set_sd_v2_size (sd, size32 );
|
||||
}
|
||||
|
||||
fread32 (&sd->sd_blocks);
|
||||
@@ -213,25 +226,33 @@ static void unpack_indirect (struct packed_item * pi, struct buffer_head * bh,
|
||||
int i;
|
||||
__u16 v16;
|
||||
|
||||
v16 = 0;
|
||||
if (pi->mask & ENTRY_COUNT)
|
||||
fread16 (&v16);
|
||||
|
||||
set_entry_count (ih, v16);
|
||||
if (!(get_pi_mask(pi) & IH_FREE_SPACE)) {
|
||||
/* ih_free_space was not packed - set default */
|
||||
set_ih_entry_count (ih, 0);
|
||||
}
|
||||
|
||||
ind_item = (__u32 *)B_I_PITEM (bh, ih);
|
||||
if (pi->mask & WHOLE_INDIRECT) {
|
||||
fread (ind_item, pi->item_len, 1, stdin);
|
||||
|
||||
if (get_pi_mask(pi) & SAFE_LINK) {
|
||||
*ind_item = cpu_to_le32(get_key_dirid(&ih->ih_key));
|
||||
set_key_dirid(&ih->ih_key, (__u32)-1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (get_pi_mask(pi) & WHOLE_INDIRECT) {
|
||||
fread (ind_item, get_pi_item_len(pi), 1, stdin);
|
||||
return;
|
||||
}
|
||||
|
||||
end = ind_item + I_UNFM_NUM (ih);
|
||||
while (ind_item < end) {
|
||||
__u32 base;
|
||||
fread32 (ind_item);
|
||||
fread16 (&v16);
|
||||
fread_le16 (&v16);
|
||||
base = le32_to_cpu(ind_item[0]);
|
||||
for (i = 1; i < v16; i ++) {
|
||||
if (ind_item[0])
|
||||
ind_item [i] = ind_item[0] + i;
|
||||
if (ind_item[0] != 0)
|
||||
ind_item [i] = cpu_to_le32(base + i);
|
||||
else
|
||||
ind_item [i] = 0;
|
||||
}
|
||||
@@ -245,13 +266,23 @@ static void unpack_indirect (struct packed_item * pi, struct buffer_head * bh,
|
||||
static void unpack_direct (struct packed_item * pi, struct buffer_head * bh,
|
||||
struct item_head * ih)
|
||||
{
|
||||
set_entry_count (ih, 0xffff);
|
||||
memset (bh->b_data + ih_location (ih), 'a', pi->item_len);
|
||||
__u32 * d_item = (__u32 *)B_I_PITEM (bh, ih);
|
||||
|
||||
if (!(get_pi_mask(pi) & IH_FREE_SPACE))
|
||||
/* ih_free_space was not packed - set default */
|
||||
set_ih_entry_count (ih, 0xffff);
|
||||
|
||||
if (get_pi_mask(pi) & SAFE_LINK) {
|
||||
*d_item = cpu_to_le32(get_key_dirid(&ih->ih_key));
|
||||
set_key_dirid(&ih->ih_key, (__u32)-1);
|
||||
} else {
|
||||
memset (d_item, 'a', get_pi_item_len(pi));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static void unpack_leaf (int dev, hashf_t hash_func)
|
||||
static void unpack_leaf (int dev, hashf_t hash_func, __u16 blocksize)
|
||||
{
|
||||
static int unpacked_leaves = 0;
|
||||
struct buffer_head * bh;
|
||||
@@ -262,28 +293,26 @@ static void unpack_leaf (int dev, hashf_t hash_func)
|
||||
__u32 v32;
|
||||
|
||||
/* block number */
|
||||
fread32 (&v32);
|
||||
fread_le32 (&v32);
|
||||
|
||||
|
||||
/* item number */
|
||||
fread16 (&v16);
|
||||
fread_le16 (&v16);
|
||||
|
||||
if (verbose)
|
||||
fprintf (stderr, "leaf %d\n", v32);
|
||||
reiserfs_warning (stderr, "leaf %d: %d items\n", v32, v16);
|
||||
|
||||
|
||||
|
||||
bh = getblk (dev, v32, 4096);
|
||||
bh = getblk (dev, v32, blocksize);
|
||||
if (!bh)
|
||||
die ("unpack_leaf: getblk failed");
|
||||
|
||||
set_node_item_number (bh, v16);
|
||||
set_node_level (bh, DISK_LEAF_NODE_LEVEL);
|
||||
set_node_free_space (bh, bh->b_size - BLKH_SIZE);
|
||||
set_blkh_nr_items (B_BLK_HEAD (bh), v16);
|
||||
set_blkh_level (B_BLK_HEAD (bh), DISK_LEAF_NODE_LEVEL);
|
||||
set_blkh_free_space (B_BLK_HEAD (bh), MAX_FREE_SPACE (bh->b_size));
|
||||
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < v16; i ++, ih ++) {
|
||||
for (i = 0; i < get_blkh_nr_items (B_BLK_HEAD (bh)); i ++, ih ++) {
|
||||
#if 0
|
||||
fread32 (&v32);
|
||||
if (v32 != ITEM_START_MAGIC)
|
||||
@@ -294,37 +323,46 @@ static void unpack_leaf (int dev, hashf_t hash_func)
|
||||
fread (&pi, sizeof (struct packed_item), 1, stdin);
|
||||
|
||||
/* dir_id - if it is there */
|
||||
if (pi.mask & DIR_ID) {
|
||||
if (get_pi_mask(&pi) & DIR_ID) {
|
||||
fread32 (&v32);
|
||||
ih->ih_key.k_dir_id = v32;
|
||||
set_key_dirid (&ih->ih_key, le32_to_cpu(v32));
|
||||
} else {
|
||||
if (!i)
|
||||
die ("unpack_leaf: dir_id is not set");
|
||||
ih->ih_key.k_dir_id = (ih - 1)->ih_key.k_dir_id;
|
||||
set_key_dirid (&ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));
|
||||
}
|
||||
|
||||
/* object_id - if it is there */
|
||||
if (pi.mask & OBJECT_ID) {
|
||||
if (get_pi_mask(&pi) & OBJECT_ID) {
|
||||
fread32 (&v32);
|
||||
ih->ih_key.k_objectid = v32;
|
||||
set_key_objectid (&ih->ih_key, le32_to_cpu(v32));
|
||||
} else {
|
||||
if (!i)
|
||||
die ("unpack_leaf: object_id is not set");
|
||||
ih->ih_key.k_objectid = (ih - 1)->ih_key.k_objectid;
|
||||
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
|
||||
}
|
||||
|
||||
// we need to set item format before offset unpacking
|
||||
set_key_format (ih, (pi.mask & NEW_FORMAT) ? KEY_FORMAT_2 : KEY_FORMAT_1);
|
||||
set_ih_key_format (ih, (get_pi_mask(&pi) & NEW_FORMAT) ? KEY_FORMAT_2 : KEY_FORMAT_1);
|
||||
|
||||
// offset
|
||||
unpack_offset (&pi, ih);
|
||||
unpack_offset (&pi, ih, bh->b_size);
|
||||
|
||||
/* type */
|
||||
unpack_type (&pi, ih);
|
||||
|
||||
/* ih_free_space and ih_format */
|
||||
if (get_pi_mask(&pi) & IH_FREE_SPACE) {
|
||||
fread16 (&v16);
|
||||
set_ih_entry_count (ih, le16_to_cpu(v16));
|
||||
}
|
||||
|
||||
if (get_pi_mask(&pi) & IH_FORMAT)
|
||||
fread16 (&ih->ih_format);
|
||||
|
||||
/* item length and item location */
|
||||
set_ih_item_len (ih, pi.item_len);
|
||||
set_ih_location (ih, (i ? ih_location (ih - 1) : bh->b_size) - pi.item_len);
|
||||
set_ih_item_len (ih, get_pi_item_len(&pi));
|
||||
set_ih_location (ih, (i ? get_ih_location (ih - 1) : bh->b_size) - get_pi_item_len(&pi));
|
||||
|
||||
// item itself
|
||||
if (is_direct_ih (ih)) {
|
||||
@@ -336,16 +374,20 @@ static void unpack_leaf (int dev, hashf_t hash_func)
|
||||
} else if (is_stat_data_ih (ih)) {
|
||||
unpack_stat_data (&pi, bh, ih);
|
||||
}
|
||||
set_node_free_space (bh, node_free_space (bh) - (IH_SIZE + ih_item_len (ih)));
|
||||
set_blkh_free_space (B_BLK_HEAD (bh), get_blkh_free_space (B_BLK_HEAD (bh)) -
|
||||
(IH_SIZE + get_ih_item_len (ih)));
|
||||
|
||||
#if 0
|
||||
fread32 (&v32);
|
||||
if (v32 != ITEM_END_MAGIC)
|
||||
die ("unpack_leaf: no end item magic found: block %lu, item %i",
|
||||
bh->b_blocknr, i);
|
||||
if (verbose)
|
||||
reiserfs_warning (stderr, "%d: %H\n", i, ih);
|
||||
#endif
|
||||
}
|
||||
|
||||
fread16 (&v16);
|
||||
fread_le16 (&v16);
|
||||
if (v16 != LEAF_END_MAGIC)
|
||||
die ("unpack_leaf: wrong end signature found - %x, block %lu",
|
||||
v16, bh->b_blocknr);
|
||||
@@ -361,7 +403,7 @@ static void unpack_leaf (int dev, hashf_t hash_func)
|
||||
|
||||
if (what_unpacked)
|
||||
reiserfs_bitmap_set_bit (what_unpacked, bh->b_blocknr);
|
||||
unpacked ++;
|
||||
/*unpacked ++;*/
|
||||
|
||||
if (!(++ unpacked_leaves % 10))
|
||||
fprintf (stderr, "#");
|
||||
@@ -374,7 +416,7 @@ static void unpack_full_block (int dev, int blocksize)
|
||||
__u32 block;
|
||||
struct buffer_head * bh;
|
||||
|
||||
fread32 (&block);
|
||||
fread_le32 (&block);
|
||||
|
||||
if (verbose)
|
||||
fprintf (stderr, "full #%d\n", block);
|
||||
@@ -387,10 +429,18 @@ static void unpack_full_block (int dev, int blocksize)
|
||||
|
||||
if (who_is_this (bh->b_data, bh->b_size) == THE_SUPER && !what_unpacked) {
|
||||
unsigned long blocks;
|
||||
struct buffer_head * tmp;
|
||||
|
||||
blocks = rs_block_count ((struct reiserfs_super_block *)(bh->b_data));
|
||||
blocks = get_sb_block_count ((struct reiserfs_super_block *)(bh->b_data));
|
||||
fprintf (stderr, "There were %lu blocks on the device\n", blocks);
|
||||
what_unpacked = reiserfs_create_bitmap (blocks);
|
||||
|
||||
/* make file as long as filesystem is */
|
||||
tmp = getblk (dev, blocks - 1, blocksize);
|
||||
mark_buffer_dirty (tmp);
|
||||
mark_buffer_uptodate (tmp, 0);
|
||||
bwrite (tmp);
|
||||
brelse (tmp);
|
||||
}
|
||||
|
||||
mark_buffer_uptodate (bh, 1);
|
||||
@@ -404,7 +454,7 @@ static void unpack_full_block (int dev, int blocksize)
|
||||
|
||||
if (what_unpacked)
|
||||
reiserfs_bitmap_set_bit (what_unpacked, block);
|
||||
unpacked ++;
|
||||
/*unpacked ++;*/
|
||||
|
||||
if (!(++ full_blocks_unpacked % 50))
|
||||
fprintf (stderr, ".");
|
||||
@@ -419,8 +469,8 @@ static void unpack_unformatted_bitmap (int dev, int blocksize)
|
||||
int i;
|
||||
char * buf;
|
||||
|
||||
fread16 (&bmap_num);
|
||||
fread32 (&block_count);
|
||||
fread_le16 (&bmap_num);
|
||||
fread_le32 (&block_count);
|
||||
|
||||
buf = malloc (blocksize);
|
||||
if (!buf)
|
||||
@@ -436,17 +486,19 @@ static void unpack_unformatted_bitmap (int dev, int blocksize)
|
||||
|
||||
|
||||
// read packed reiserfs partition metadata from stdin
|
||||
void unpack_partition (int dev)
|
||||
void unpack_partition (int fd, int jfd)
|
||||
{
|
||||
__u32 magic32;
|
||||
__u16 magic16;
|
||||
__u16 blocksize;
|
||||
int dev = fd;
|
||||
|
||||
fread32 (&magic32);
|
||||
fread_le32 (&magic32);
|
||||
if (magic32 != REISERFS_SUPER_MAGIC)
|
||||
die ("unpack_partition: reiserfs magic number not found");
|
||||
die ("unpack_partition: reiserfs magic number (0x%x) not found - %x\n",
|
||||
REISERFS_SUPER_MAGIC, magic32);
|
||||
|
||||
fread16 (&blocksize);
|
||||
fread_le16 (&blocksize);
|
||||
|
||||
if (verbose)
|
||||
fprintf (stderr, "Blocksize %d\n", blocksize);
|
||||
@@ -480,15 +532,27 @@ void unpack_partition (int dev)
|
||||
}
|
||||
|
||||
fread (c + 1, 1, 1, stdin);
|
||||
magic16 = *(__u16 *)c;
|
||||
magic16 = le16_to_cpu(*(__u16 *)c);
|
||||
/*fread16 (&magic16);*/
|
||||
|
||||
switch (magic16 & 0xff) {
|
||||
case LEAF_START_MAGIC:
|
||||
unpack_leaf (dev, code2func (magic16 >> 8));
|
||||
leaves ++;
|
||||
unpack_leaf (dev, code2func (magic16 >> 8), blocksize);
|
||||
break;
|
||||
|
||||
case SEPARATED_JOURNAL_START_MAGIC:
|
||||
if (Default_journal)
|
||||
die ("file name for separated journal has to be specified");
|
||||
dev = jfd;
|
||||
break;
|
||||
|
||||
case SEPARATED_JOURNAL_END_MAGIC:
|
||||
dev = fd;
|
||||
break;
|
||||
|
||||
case FULL_BLOCK_START_MAGIC:
|
||||
full ++;
|
||||
unpack_full_block (dev, blocksize);
|
||||
break;
|
||||
|
||||
@@ -505,7 +569,7 @@ void unpack_partition (int dev)
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (stderr, "Unpacked %d (%d) blocks\n", unpacked, what_unpacked ? reiserfs_bitmap_ones (what_unpacked) : 0);
|
||||
fprintf (stderr, "Unpacked %d leaves, %d full blocks\n", leaves, full);
|
||||
|
||||
|
||||
/* fclose (block_list);*/
|
||||
@@ -514,8 +578,9 @@ void unpack_partition (int dev)
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
int fd;
|
||||
int fd, fdj = -2;
|
||||
int c;
|
||||
char * j_filename;
|
||||
char * filename = ".bitmap";
|
||||
struct rlimit lim = {0xffffffff, 0xffffffff};
|
||||
|
||||
@@ -526,13 +591,18 @@ int main (int argc, char ** argv)
|
||||
fprintf (stderr, "sertlimit failed: %m\n");
|
||||
}
|
||||
|
||||
while ((c = getopt (argc, argv, "vb:")) != EOF) {
|
||||
while ((c = getopt (argc, argv, "vb:j:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 'b':
|
||||
asprintf (&filename, "%s", optarg);
|
||||
break;
|
||||
case 'j':
|
||||
Default_journal = 0;
|
||||
asprintf (&j_filename, "%s", optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (optind != argc - 1)
|
||||
@@ -548,11 +618,24 @@ int main (int argc, char ** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
unpack_partition (fd);
|
||||
if (!Default_journal) {
|
||||
fdj = open (j_filename, O_RDWR | O_LARGEFILE);
|
||||
if (fdj == -1) {
|
||||
perror ("open failed");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (what_unpacked && filename)
|
||||
reiserfs_bitmap_save (filename, what_unpacked);
|
||||
unpack_partition (fd, fdj);
|
||||
|
||||
if (what_unpacked && filename) {
|
||||
FILE * file = open_file(filename, "w+");
|
||||
reiserfs_bitmap_save (file, what_unpacked);
|
||||
close_file(file);
|
||||
}
|
||||
|
||||
close (fd);
|
||||
if (!Default_journal)
|
||||
close (fdj);
|
||||
return 0;
|
||||
}
|
||||
+5
-5
@@ -1,11 +1,11 @@
|
||||
sbin_PROGRAMS = reiserfsck
|
||||
|
||||
reiserfsck_SOURCES = main.c pass0.c pass1.c pass2.c semantic.c pass4.c lost+found.c \
|
||||
ubitmap.c uobjectid.c ustree.c ufile.c check.c check_tree.c journal.c info.c segments.c\
|
||||
fsck.h
|
||||
reiserfsck_SOURCES = main.c pass0.c pass1.c pass2.c semantic_check.c \
|
||||
semantic_rebuild.c pass4.c lost+found.c ubitmap.c uobjectid.c ustree.c \
|
||||
ufile.c check.c check_tree.c info.c super.c fsck.h
|
||||
|
||||
man_MANS = reiserfsck.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
|
||||
INCLUDES = -I../include -I.
|
||||
+49
-31
@@ -1,6 +1,6 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -62,31 +62,33 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
sbin_PROGRAMS = reiserfsck
|
||||
|
||||
reiserfsck_SOURCES = main.c pass0.c pass1.c pass2.c semantic.c pass4.c lost+found.c ubitmap.c uobjectid.c ustree.c ufile.c check.c check_tree.c journal.c info.c segments.c fsck.h
|
||||
reiserfsck_SOURCES = main.c pass0.c pass1.c pass2.c semantic_check.c semantic_rebuild.c pass4.c lost+found.c ubitmap.c uobjectid.c ustree.c ufile.c check.c check_tree.c info.c super.c fsck.h
|
||||
|
||||
|
||||
man_MANS = reiserfsck.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
|
||||
INCLUDES = -I../include -I.
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
PROGRAMS = $(sbin_PROGRAMS)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
reiserfsck_OBJECTS = main.o pass0.o pass1.o pass2.o semantic.o pass4.o \
|
||||
lost+found.o ubitmap.o uobjectid.o ustree.o ufile.o check.o \
|
||||
check_tree.o journal.o info.o segments.o
|
||||
reiserfsck_OBJECTS = main.o pass0.o pass1.o pass2.o semantic_check.o \
|
||||
semantic_rebuild.o pass4.o lost+found.o ubitmap.o uobjectid.o ustree.o \
|
||||
ufile.o check.o check_tree.o info.o super.o
|
||||
reiserfsck_LDADD = $(LDADD)
|
||||
reiserfsck_DEPENDENCIES = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
reiserfsck_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
|
||||
$(top_srcdir)/reiserfscore/libcore.a
|
||||
reiserfsck_LDFLAGS =
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@@ -241,7 +243,7 @@ distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
@@ -249,37 +251,53 @@ distdir: $(DISTFILES)
|
||||
fi; \
|
||||
done
|
||||
check.o: check.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
check_tree.o: check_tree.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
info.o: info.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
journal.o: journal.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
lost+found.o: lost+found.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
main.o: main.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h ../version.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
pass0.o: pass0.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
pass1.o: pass1.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
pass2.o: pass2.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
pass4.o: pass4.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
segments.o: segments.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
semantic.o: semantic.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
semantic_check.o: semantic_check.c fsck.h ../include/io.h \
|
||||
../include/misc.h ../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
semantic_rebuild.o: semantic_rebuild.c fsck.h ../include/io.h \
|
||||
../include/misc.h ../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
super.o: super.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
ubitmap.o: ubitmap.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
ufile.o: ufile.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
uobjectid.o: uobjectid.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
ustree.o: ustree.c fsck.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
|
||||
+20
-26
@@ -18,8 +18,8 @@ static void check_directory_item (struct item_head * ih, struct buffer_head * bh
|
||||
int i;
|
||||
struct reiserfs_de_head * deh;
|
||||
|
||||
for (i = 0, deh = B_I_DEH (bh, ih); i < ih_entry_count (ih) - 1; i ++)
|
||||
if (deh_offset(&deh[i]) > deh_offset(&deh[i + 1]))
|
||||
for (i = 0, deh = B_I_DEH (bh, ih); i < get_ih_entry_count (ih) - 1; i ++)
|
||||
if (get_deh_offset(&deh[i]) > get_deh_offset(&deh[i + 1]))
|
||||
die ("check_directory_item: entries are not sorted properly");
|
||||
}
|
||||
|
||||
@@ -74,8 +74,9 @@ static void is_there_unaccessed_items (struct buffer_head * bh)
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) {
|
||||
if (is_objectid_used (fs, ih->ih_key.k_objectid) == 0)
|
||||
die ("is_there_unaccessed_items: %lu is not marked as used", ih->ih_key.k_objectid);
|
||||
if (is_objectid_used (fs, get_key_objectid (&ih->ih_key)) == 0)
|
||||
die ("is_there_unaccessed_items: %lu is not marked as used",
|
||||
( long unsigned ) get_key_objectid (&ih->ih_key));
|
||||
|
||||
if (!is_item_reachable (ih)) {
|
||||
die ("is_there_unaccessed_items: block %lu - unaccessed item found",
|
||||
@@ -136,7 +137,7 @@ static int is_leaf_bad_xx (struct buffer_head * bh)
|
||||
}
|
||||
|
||||
|
||||
static void reiserfsck_check_tree (int dev, int block, int size, check_function_t comp_func)
|
||||
static void reiserfsck_check_tree (int dev, unsigned long block, int size, check_function_t comp_func)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
int what_node;
|
||||
@@ -158,7 +159,7 @@ static void reiserfsck_check_tree (int dev, int block, int size, check_function_
|
||||
die ("Not marked as used");
|
||||
|
||||
if (is_leaf_node (bh) && is_leaf_bad_xx (bh))
|
||||
die ("Bad leaf");
|
||||
die ("Bad leaf %lu", bh->b_blocknr);
|
||||
|
||||
if (is_internal_node(bh) && is_internal_bad (bh))
|
||||
die ("bad internal");
|
||||
@@ -169,7 +170,7 @@ static void reiserfsck_check_tree (int dev, int block, int size, check_function_
|
||||
|
||||
dc = B_N_CHILD (bh, 0);
|
||||
for (i = 0; i <= B_NR_ITEMS (bh); i ++, dc ++) {
|
||||
reiserfsck_check_tree (dev, dc->dc_block_number, size, comp_func);
|
||||
reiserfsck_check_tree (dev, get_dc_child_blocknr (dc), size, comp_func);
|
||||
g_dkey = B_N_PDELIM_KEY (bh, i);
|
||||
}
|
||||
} else if (is_leaf_node (bh)) {
|
||||
@@ -187,7 +188,7 @@ static void reiserfsck_check_tree (int dev, int block, int size, check_function_
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
static void reiserfsck_check_cached_tree (int dev, int block, int size)
|
||||
static void reiserfsck_check_cached_tree (int dev, unsigned long block, int size)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
int what_node;
|
||||
@@ -202,7 +203,7 @@ static void reiserfsck_check_cached_tree (int dev, int block, int size)
|
||||
bh->b_count ++;
|
||||
|
||||
if (!B_IS_IN_TREE (bh)) {
|
||||
die ("reiserfsck_check_cached_tree: buffer (%b %z) not in tree", bh, bh);
|
||||
reiserfs_panic ("reiserfsck_check_cached_tree: buffer (%b %z) not in tree", bh, bh);
|
||||
}
|
||||
|
||||
what_node = who_is_this (bh->b_data, bh->b_size);
|
||||
@@ -217,7 +218,7 @@ static void reiserfsck_check_cached_tree (int dev, int block, int size)
|
||||
|
||||
dc = B_N_CHILD (bh, 0);
|
||||
for (i = 0; i <= B_NR_ITEMS (bh); i ++, dc ++) {
|
||||
reiserfsck_check_cached_tree (dev, dc->dc_block_number, size);
|
||||
reiserfsck_check_cached_tree (dev, get_dc_child_blocknr (dc), size);
|
||||
g_dkey = B_N_PDELIM_KEY (bh, i);
|
||||
}
|
||||
} else if (is_leaf_node (bh)) {
|
||||
@@ -235,7 +236,8 @@ void reiserfsck_tree_check (check_function_t how_to_compare_neighbors)
|
||||
{
|
||||
g_left = 0;
|
||||
g_dkey = 0;
|
||||
reiserfsck_check_tree (fs->s_dev, SB_ROOT_BLOCK(fs), fs->s_blocksize, how_to_compare_neighbors);
|
||||
reiserfsck_check_tree (fs->fs_dev, get_sb_root_block (fs->fs_ondisk_sb),
|
||||
fs->fs_blocksize, how_to_compare_neighbors);
|
||||
brelse (g_right);
|
||||
}
|
||||
|
||||
@@ -248,7 +250,8 @@ void reiserfsck_check_pass1 ()
|
||||
|
||||
void check_cached_tree ()
|
||||
{
|
||||
reiserfsck_check_cached_tree (fs->s_dev, SB_ROOT_BLOCK (fs), fs->s_blocksize);
|
||||
reiserfsck_check_cached_tree (fs->fs_dev, get_sb_root_block (fs->fs_ondisk_sb),
|
||||
fs->fs_blocksize);
|
||||
}
|
||||
|
||||
void reiserfsck_check_after_all ()
|
||||
@@ -277,9 +280,9 @@ static int is_bad_sd (struct item_head * ih, char * item)
|
||||
#include <sys/mount.h>
|
||||
|
||||
|
||||
int blocks_on_device (int dev, int blocksize)
|
||||
unsigned long blocks_on_device (int dev, int blocksize)
|
||||
{
|
||||
int size;
|
||||
unsigned long size;
|
||||
|
||||
if (ioctl (dev, BLKGETSIZE, &size) >= 0) {
|
||||
return size / (blocksize / 512);
|
||||
@@ -309,21 +312,12 @@ int is_internal_bad (struct buffer_head * bh)
|
||||
return 0;
|
||||
for (i = 0; i < B_NR_ITEMS (bh); i ++) {
|
||||
key = B_N_PDELIM_KEY (bh, i);
|
||||
if (//key->k_dir_id >= key->k_objectid ||
|
||||
key->u.k_offset_v1.k_uniqueness != V1_DIRENTRY_UNIQUENESS && key->u.k_offset_v1.k_uniqueness != V1_DIRECT_UNIQUENESS &&
|
||||
key->u.k_offset_v1.k_uniqueness != V1_INDIRECT_UNIQUENESS && key->u.k_offset_v1.k_uniqueness != V1_SD_UNIQUENESS &&
|
||||
key->u.k_offset_v2.k_type != TYPE_DIRENTRY && key->u.k_offset_v2.k_type != TYPE_DIRECT &&
|
||||
key->u.k_offset_v2.k_type != TYPE_INDIRECT && key->u.k_offset_v2.k_type != TYPE_STAT_DATA //&&
|
||||
// key->u.k_offset_v1.k_uniqueness != V1_ANY_UNIQUENESS && key->u.k_offset_v2.k_type != TYPE_ANY
|
||||
)
|
||||
if (!KEY_IS_STAT_DATA_KEY (key) && !KEY_IS_DIRECTORY_KEY (key) &&
|
||||
!KEY_IS_DIRECT_KEY (key) && !KEY_IS_INDIRECT_KEY (key))
|
||||
/* key of unknown item */
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+686
-294
File diff suppressed because it is too large.
Load diff
+266
-171
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-2001 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
@@ -23,54 +23,54 @@
|
||||
#include "reiserfs_lib.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/* main.c */
|
||||
extern reiserfs_filsys_t fs;
|
||||
extern reiserfs_bitmap_t uninsertable_leaf_bitmap;
|
||||
extern reiserfs_filsys_t * fs;
|
||||
int main (int argc, char * argv []);
|
||||
|
||||
|
||||
/*
|
||||
* modes
|
||||
*/
|
||||
#define DO_NOTHING 0 /* -a specified */
|
||||
#define FSCK_CHECK 1
|
||||
#define FSCK_SB 2
|
||||
#define FSCK_REBUILD 3
|
||||
#define DO_NOTHING 0 /* -a specified */
|
||||
#define FSCK_CHECK 1
|
||||
#define FSCK_FIX_FIXABLE 2
|
||||
#define FSCK_SB 3
|
||||
#define FSCK_REBUILD 4
|
||||
#define FSCK_ROLLBACK_CHANGES 5
|
||||
#define FSCK_FAST_REBUILD 6
|
||||
#define FSCK_CLEAN_ATTRIBUTES 7
|
||||
#define AUTO 8 /* -p specified */
|
||||
|
||||
/* temporary */
|
||||
#define FSCK_ZERO_FILES 4
|
||||
#define DO_TEST 5
|
||||
|
||||
/*
|
||||
#define FSCK_FAST_REBUILD 4
|
||||
*/
|
||||
|
||||
#define DO_TEST 9
|
||||
|
||||
/*
|
||||
* options
|
||||
*/
|
||||
#define OPT_INTERACTIVE 1
|
||||
#define OPT_FIX_FIXABLE 2 /* not default yet */
|
||||
#define OPT_FIX_NON_CRITICAL 4 /* not default yet */
|
||||
#define OPT_QUIET 8
|
||||
#define OPT_SAVE_EXTERN_BITMAP 16
|
||||
#define OPT_SILENT 32
|
||||
#define OPT_INTERACTIVE 0x1
|
||||
//#define OPT_FIX_FIXABLE 0x2 /* not default yet */
|
||||
#define OPT_ADJUST_FILE_SIZE 0x4 /* not default yet */
|
||||
#define OPT_QUIET 0x8 /* no "speed" info */
|
||||
/*#define OPT_SAVE_EXTERN_BITMAP 0x10*/
|
||||
#define OPT_SILENT 0x20 /* no complains about found corruptions */
|
||||
#define OPT_BACKGROUND 0x40
|
||||
#define OPT_SKIP_JOURNAL 0x80
|
||||
#define OPT_HASH_DEFINED 0x100
|
||||
#define OPT_SAVE_PASSES_DUMP 0x200
|
||||
#define BADBLOCKS_FILE 0x400
|
||||
#define OPT_SAVE_ROLLBACK 0x800
|
||||
|
||||
extern int g_blocks_to_read;
|
||||
|
||||
/* pass 0 and 1 read the device NR_TO_READ block in time */
|
||||
#define NR_TO_READ 8
|
||||
|
||||
/* pass0.c */
|
||||
int pass_0 (reiserfs_filsys_t);
|
||||
int are_there_used_leaves (unsigned long from, int count);
|
||||
void pass_0 (reiserfs_filsys_t *);
|
||||
void load_pass_0_result (FILE *, reiserfs_filsys_t *);
|
||||
|
||||
int is_used_leaf (unsigned long block);
|
||||
int how_many_leaves_were_there (void);
|
||||
int is_bad_unformatted (unsigned long block);
|
||||
int is_good_unformatted (unsigned long block);
|
||||
void mark_good_unformatted (unsigned long block);
|
||||
int is_bad_unformatted (unsigned long block);
|
||||
|
||||
int are_there_allocable_blocks (int amout_needed);
|
||||
unsigned long alloc_block (void);
|
||||
void make_allocable (unsigned long block);
|
||||
@@ -80,32 +80,40 @@ void register_saved_item (void);
|
||||
unsigned long how_many_items_were_saved (void);
|
||||
int still_bad_unfm_ptr_1 (unsigned long block);
|
||||
int still_bad_unfm_ptr_2 (unsigned long block);
|
||||
void make_alloc_bitmap (struct super_block * s);
|
||||
void make_alloc_bitmap (reiserfs_filsys_t *);
|
||||
|
||||
void delete_aux_bitmaps ();
|
||||
void set_aux_bitmaps(reiserfs_bitmap_t * leaves, reiserfs_bitmap_t * good, reiserfs_bitmap_t * bad);
|
||||
|
||||
#define __is_marked(name,block) reiserfs_bitmap_test_bit (name##_bitmap, block)
|
||||
#define __mark(name,block) reiserfs_bitmap_set_bit (name##_bitmap, block)
|
||||
#define __unmark(name,block) reiserfs_bitmap_clear_bit (name##_bitmap, block)
|
||||
|
||||
/* unformatted in tree */
|
||||
extern reiserfs_bitmap_t bad_unfm_in_tree_once_bitmap;
|
||||
extern reiserfs_bitmap_t * bad_unfm_in_tree_once_bitmap;
|
||||
#define is_bad_unfm_in_tree_once(block) __is_marked (bad_unfm_in_tree_once, block)
|
||||
#define mark_bad_unfm_in_tree_once(block) __mark (bad_unfm_in_tree_once, block)
|
||||
|
||||
|
||||
|
||||
/* pass1.c */
|
||||
void pass_1_pass_2_build_the_tree (void);
|
||||
struct buffer_head * make_buffer (int dev, int blocknr, int size, char * data);
|
||||
void pass_1 (reiserfs_filsys_t *);
|
||||
void load_pass_1_result (FILE *, reiserfs_filsys_t *);
|
||||
struct buffer_head * make_buffer (int dev, unsigned long blocknr, int size, char * data);
|
||||
void build_the_tree (void);
|
||||
extern int g_unaccessed_items;
|
||||
int is_item_reachable (struct item_head * ih);
|
||||
void mark_item_reachable (struct item_head * ih, struct buffer_head * bh);
|
||||
void mark_item_unreachable (struct item_head * ih);
|
||||
void rebuild_sb (reiserfs_filsys_t fs);
|
||||
|
||||
struct si * remove_saved_item (struct si * si);
|
||||
int tree_is_empty (void);
|
||||
void make_single_leaf_tree (struct buffer_head * bh);
|
||||
|
||||
|
||||
/* pass2.c */
|
||||
void pass_2 (reiserfs_filsys_t *);
|
||||
void load_pass_2_result (reiserfs_filsys_t *);
|
||||
void insert_item_separately (struct item_head * ih, char * item,
|
||||
int was_in_tree);
|
||||
struct si * save_and_delete_file_item (struct si * si, struct path * path);
|
||||
@@ -115,8 +123,10 @@ void pass_2_take_bad_blocks_put_into_tree (void);
|
||||
/*int is_remapped (struct item_head * ih);*/
|
||||
void link_relocated_files (void);
|
||||
void relocate_file (struct item_head * ih, int change_ih);
|
||||
int should_relocate (struct item_head * ih);
|
||||
void relocate_dir (struct item_head * ih, int change_ih);
|
||||
__u32 objectid_for_relocation (struct key * key);
|
||||
int should_be_relocated (struct key * key);
|
||||
|
||||
/* file.c */
|
||||
struct si {
|
||||
@@ -130,62 +140,48 @@ struct si {
|
||||
};
|
||||
void put_saved_items_into_tree (struct si *);
|
||||
int reiserfsck_file_write (struct item_head * ih, char * item, int);
|
||||
int are_file_items_correct (struct key * key, int key_version, __u64 * size, __u32 * blocks, int mark_passed_items,
|
||||
int symlink, __u64 symlink_size);
|
||||
int are_file_items_correct (struct item_head * sd_ih, void * sd, __u64 * size, __u32 * blocks, int mark_passed_items, int * symlink);
|
||||
|
||||
|
||||
|
||||
/* semantic.c */
|
||||
extern struct key root_dir_key;
|
||||
extern struct key parent_root_dir_key;
|
||||
extern struct key lost_found_dir_key;
|
||||
void pass_3_semantic (void);
|
||||
|
||||
/* return values for check_regular_file and check_semantic_tree */
|
||||
#define OK 0
|
||||
#define STAT_DATA_NOT_FOUND -1
|
||||
#define DIRECTORY_HAS_NO_ITEMS -2
|
||||
#define RELOCATED -3
|
||||
#define LOOP_FOUND -4
|
||||
|
||||
void load_semantic_result (FILE *, reiserfs_filsys_t *);
|
||||
|
||||
void pass_3_semantic (reiserfs_filsys_t *);
|
||||
void semantic_check (void);
|
||||
int check_semantic_tree (struct key * key, struct key * parent, int is_dot_dot, int lost_found, struct item_head * new_ih);
|
||||
void zero_nlink (struct item_head * ih, void * sd);
|
||||
int not_a_directory (void * sd);
|
||||
int not_a_regfile (void * sd);
|
||||
int fix_obviously_wrong_sd_mode (struct path * path);
|
||||
int is_dot_dot (char * name, int namelen);
|
||||
int is_dot (char * name, int namelen);
|
||||
void create_dir_sd (reiserfs_filsys_t fs,
|
||||
struct path * path, struct key * key);
|
||||
/*void create_dir_sd (reiserfs_filsys_t * fs,
|
||||
struct path * path, struct key * key);*/
|
||||
int rebuild_check_regular_file (struct path * path, void * sd,
|
||||
struct item_head * new_ih);
|
||||
int rebuild_semantic_pass (struct key * key, struct key * parent, int is_dot_dot,
|
||||
struct item_head * new_ih);
|
||||
|
||||
/* access to stat data fields */
|
||||
void get_set_sd_field (int field, struct item_head * ih, void * sd,
|
||||
void * value, int set);
|
||||
#define GET_SD_MODE 0
|
||||
#define GET_SD_SIZE 1
|
||||
#define GET_SD_NLINK 2
|
||||
#define GET_SD_BLOCKS 3
|
||||
#define GET_SD_FIRST_DIRECT_BYTE 4
|
||||
|
||||
#define get_sd_mode(ih,sd,pmode) get_set_sd_field (GET_SD_MODE, ih, sd, pmode, 0/*get*/)
|
||||
#define set_sd_mode(ih,sd,pmode) get_set_sd_field (GET_SD_MODE, ih, sd, pmode, 1/*set*/)
|
||||
|
||||
#define get_sd_size(ih,sd,psize) get_set_sd_field (GET_SD_SIZE, ih, sd, psize, 0/*get*/)
|
||||
#define set_sd_size(ih,sd,psize) get_set_sd_field (GET_SD_SIZE, ih, sd, psize, 1/*set*/)
|
||||
|
||||
#define get_sd_blocks(ih,sd,pblocks) get_set_sd_field (GET_SD_BLOCKS, ih, sd, pblocks, 0/*get*/)
|
||||
#define set_sd_blocks(ih,sd,pblocks) get_set_sd_field (GET_SD_BLOCKS, ih, sd, pblocks, 1/*set*/)
|
||||
|
||||
#define get_sd_nlink(ih,sd,pnlink) get_set_sd_field (GET_SD_NLINK, ih, sd, pnlink, 0/*get*/)
|
||||
#define set_sd_nlink(ih,sd,pnlink) get_set_sd_field (GET_SD_NLINK, ih, sd, pnlink, 1/*set*/)
|
||||
|
||||
#define get_sd_first_direct_byte(ih,sd,pfdb) get_set_sd_field (GET_SD_FIRST_DIRECT_BYTE, ih, sd, pfdb, 0/*get*/)
|
||||
#define set_sd_first_direct_byte(ih,sd,pfdb) get_set_sd_field (GET_SD_FIRST_DIRECT_BYTE, ih, sd, pfdb, 1/*set*/)
|
||||
|
||||
|
||||
|
||||
/* lost+found.c */
|
||||
void pass_3a_look_for_lost (reiserfs_filsys_t s);
|
||||
void pass_3a_look_for_lost (reiserfs_filsys_t *);
|
||||
|
||||
void load_lost_found_result (reiserfs_filsys_t *);
|
||||
|
||||
/* pass4.c */
|
||||
void get_next_key (struct path * path, int i, struct key * key);
|
||||
int pass_4_check_unaccessed_items (void);
|
||||
|
||||
//void get_next_key (struct path * path, int i, struct key * key);
|
||||
void pass_4_check_unaccessed_items (void);
|
||||
|
||||
/* check.c */
|
||||
int is_leaf_bad (struct buffer_head * bh);
|
||||
@@ -202,69 +198,66 @@ int is_bad_directory (struct item_head * ih, char * item, int dev, int blocksize
|
||||
//extern int bad_block_number (struct super_block * s, blocknr_t block);
|
||||
|
||||
/* check_tree.c */
|
||||
void check_fs_tree (struct super_block * s);
|
||||
int check_sb (struct super_block * s);
|
||||
int bad_pair (struct super_block * s, struct buffer_head * bh, int i);
|
||||
int bad_leaf_2 (struct super_block * s, struct buffer_head * bh);
|
||||
void check_fs_tree (reiserfs_filsys_t *);
|
||||
void do_clean_attributes (reiserfs_filsys_t * fs);
|
||||
//int check_sb (reiserfs_filsys_t *);
|
||||
int bad_pair (reiserfs_filsys_t *, struct buffer_head * bh, int i);
|
||||
int bad_leaf_2 (reiserfs_filsys_t *, struct buffer_head * bh);
|
||||
|
||||
|
||||
|
||||
/* ustree.c */
|
||||
void init_tb_struct (struct tree_balance * tb, struct super_block * s, struct path * path, int size);
|
||||
void reiserfsck_paste_into_item (struct path * path, const char * body, int size);
|
||||
void reiserfsck_insert_item (struct path * path, struct item_head * ih, const char * body);
|
||||
void reiserfsck_delete_item (struct path * path, int temporary);
|
||||
void reiserfsck_cut_from_item (struct path * path, int cut_size);
|
||||
typedef int (comp_function_t)(void * key1, void * key2);
|
||||
typedef int (comp3_function_t)(void * key1, void * key2, int version);
|
||||
/*typedef int (comp3_function_t)(void * key1, void * key2, int version);*/
|
||||
/*typedef int (comp_function_t)(struct key * key1, struct key * key2);*/
|
||||
int ubin_search_id(__u32 * id, __u32 * base, __u32 number, __u32 * pos);
|
||||
int usearch_by_key (struct super_block * s, struct key * key, struct path * path);
|
||||
int usearch_by_key_3 (struct super_block * s, struct key * key, struct path * path, int * repeat, int stop_level,
|
||||
/*int ubin_search_id(__u32 * id, __u32 * base, __u32 number, __u32 * pos);*/
|
||||
/*int usearch_by_key (struct super_block * s, struct key * key, struct path * path);*/
|
||||
/*int usearch_by_key_3 (struct super_block * s, struct key * key, struct path * path, int * repeat, int stop_level,
|
||||
comp3_function_t comp_func, int version);
|
||||
int usearch_by_entry_key (struct super_block * s, struct key * key, struct path * path);
|
||||
int usearch_by_position (struct super_block * s, struct key * key, int version, struct path * path);
|
||||
struct key * uget_lkey (struct path * path);
|
||||
struct key * uget_rkey (struct path * path);
|
||||
int usearch_by_entry_key (struct super_block * s, struct key * key, struct path * path);*/
|
||||
|
||||
typedef int do_after_read_t (struct super_block * s, struct buffer_head **, int h);
|
||||
typedef int do_on_full_path_t (struct super_block * s, struct buffer_head **, int);
|
||||
void pass_through_tree (struct super_block *, do_after_read_t, do_on_full_path_t);
|
||||
typedef int do_after_read_t (reiserfs_filsys_t *, struct buffer_head **, int h);
|
||||
typedef int do_on_full_path_t (reiserfs_filsys_t *, struct buffer_head **, int);
|
||||
void pass_through_tree (reiserfs_filsys_t *, do_after_read_t, do_on_full_path_t);
|
||||
|
||||
//int comp_keys_3 (void * key1, void * key2);
|
||||
//int comp_dir_entries (void * key1, void * key2);
|
||||
inline int ubin_search (void * key, void * base, int num, int width, __u32 *ppos, comp_function_t comp_func);
|
||||
|
||||
|
||||
/* bitmap.c */
|
||||
int reiserfsck_reiserfs_new_blocknrs (reiserfs_filsys_t fs,
|
||||
int reiserfsck_reiserfs_new_blocknrs (reiserfs_filsys_t * fs,
|
||||
unsigned long * pblocknrs,
|
||||
unsigned long start_from,
|
||||
int amount_needed);
|
||||
int reiserfsck_reiserfs_free_block (reiserfs_filsys_t fs, unsigned long block);
|
||||
int reiserfsck_reiserfs_free_block (reiserfs_filsys_t * fs, unsigned long block);
|
||||
struct buffer_head * reiserfsck_get_new_buffer (unsigned long start);
|
||||
int is_block_used (unsigned long block);
|
||||
int is_to_be_read (reiserfs_filsys_t fs, unsigned long block);
|
||||
void mark_block_used (unsigned long block);
|
||||
void mark_block_used (unsigned long block, int check_hardware);
|
||||
void mark_block_uninsertable (unsigned long block);
|
||||
int is_block_uninsertable (unsigned long block);
|
||||
|
||||
|
||||
/* objectid.c */
|
||||
int is_objectid_used (struct super_block * s, __u32 objectid);
|
||||
void mark_objectid_as_used (struct super_block * s, __u32 objectid);
|
||||
void mark_objectid_as_free (struct super_block * s, __u32 objectid);
|
||||
__u32 get_unused_objectid (struct super_block * s);
|
||||
int comp_ids(const void *p1, const void *p2);
|
||||
int is_objectid_used (reiserfs_filsys_t *, __u32 objectid);
|
||||
__u32 get_unused_objectid (reiserfs_filsys_t *);
|
||||
|
||||
struct id_map * init_id_map (void);
|
||||
void free_id_map (struct id_map **);
|
||||
int is_objectid_really_used (struct id_map *, __u32 id, int * ppos);
|
||||
void free_id_map (struct id_map *);
|
||||
int is_objectid_really_used (struct id_map *, __u32 id, __u32 * ppos);
|
||||
int mark_objectid_really_used (struct id_map *, __u32 id);
|
||||
void flush_objectid_map (struct id_map * map, reiserfs_filsys_t fs);
|
||||
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t fs);
|
||||
int __mark_objectid_really_used (struct id_map *, __u32 id, __u32 pos);
|
||||
void flush_objectid_map (struct id_map * map, reiserfs_filsys_t * fs);
|
||||
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t * fs);
|
||||
|
||||
void reiserfs_objectid_map_save (FILE * fp, struct id_map * id_map);
|
||||
struct id_map * reiserfs_objectid_map_load (FILE * fp);
|
||||
|
||||
/* segments.c */
|
||||
/*
|
||||
struct overwritten_unfm_segment {
|
||||
int ous_begin;
|
||||
int ous_end;
|
||||
@@ -275,14 +268,18 @@ struct overwritten_unfm_segment * find_overwritten_unfm (unsigned long unfm, int
|
||||
int get_unoverwritten_segment (struct overwritten_unfm_segment * list_head, struct overwritten_unfm_segment * unoverwritten_segment);
|
||||
void save_unfm_overwriting (unsigned long unfm, struct item_head * direct_ih);
|
||||
void free_overwritten_unfms (void);
|
||||
*/
|
||||
|
||||
void mark_formatted_pointed_by_indirect (__u32);
|
||||
int is_formatted_pointed_by_indirect (__u32);
|
||||
|
||||
|
||||
/* size of 1 piece of in-memory map */
|
||||
#define MAP_SIZE 4096
|
||||
|
||||
struct id_map {
|
||||
__u32 * m_begin; /* pointer to map area */
|
||||
unsigned long m_used_slots_count;
|
||||
__u32 m_used_slots_count;
|
||||
int m_page_count; /* objectid map expands by one page at
|
||||
time. This is size of objectid map size in
|
||||
pages */
|
||||
@@ -291,125 +288,214 @@ struct id_map {
|
||||
};
|
||||
|
||||
|
||||
struct fsck_data {
|
||||
unsigned long all_blocks; /* super block's block count */
|
||||
|
||||
/* pass 0 */
|
||||
unsigned long analyzed; /* blocks marked used (not data not included) */
|
||||
unsigned long free; /* free blocks */
|
||||
unsigned long not_data; /* super block, bitmap, journal */
|
||||
unsigned long leaves; /* blocks looking like reiserfs leaves */
|
||||
unsigned long pointed_leaves;
|
||||
unsigned long pointed; /* by indirect items */
|
||||
unsigned long pointed_once;
|
||||
unsigned long pointed_more_than_once;
|
||||
unsigned long allocable;
|
||||
unsigned long wrong_pointers; /* out of range or pointers to free
|
||||
area */
|
||||
struct pass0_stat {
|
||||
unsigned long dealt_with; /* number of blocks read during pass 0 */
|
||||
unsigned long leaves; /* blocks looking like reiserfs leaves found */
|
||||
unsigned long leaves_corrected;
|
||||
unsigned long all_contents_removed;
|
||||
unsigned long too_old_leaves; /* these are leaves which contains
|
||||
direntries with different hash from the
|
||||
one specified with -h */
|
||||
unsigned long wrong_pointers; /* pointers in indirect items pointing to
|
||||
wrong area */
|
||||
unsigned long pointed; /* pointers blocks of device pointed by all
|
||||
indirect items */
|
||||
};
|
||||
|
||||
/* pass 1, 2 */
|
||||
unsigned long read_leaves;
|
||||
|
||||
struct pass1_stat {
|
||||
unsigned long leaves; /* leaves found in pass0 to build tree off */
|
||||
unsigned long inserted_leaves; /* number of leaves inserted by pointers */
|
||||
unsigned long pointed_leaves; /* pointers in indirect items which pointed
|
||||
to leaves (zeroed) */
|
||||
unsigned long uninsertable_leaves;
|
||||
unsigned long inserted_leaves;
|
||||
unsigned long shared_objectids;
|
||||
unsigned long saved_on_pass1;
|
||||
unsigned long relocated;
|
||||
unsigned long rewritten;
|
||||
unsigned long non_unique_pointers; /* pointers to already pointed unformatted nodes */
|
||||
unsigned long correct_pointers;
|
||||
unsigned long saved_items; /* items saved on pass1: should be 0 */
|
||||
unsigned long allocable_blocks; /* allocable blocks before pass 1 starts */
|
||||
};
|
||||
|
||||
/* stat of semantic pass */
|
||||
|
||||
struct pass2_stat {
|
||||
unsigned long leaves; /* leaves inserted item by item */
|
||||
unsigned long safe_non_unique_pointers; /* these are just the same pointers */
|
||||
unsigned long relocated;
|
||||
unsigned long shared_objectids;
|
||||
unsigned long rewritten;
|
||||
};
|
||||
|
||||
|
||||
struct semantic_stat {
|
||||
unsigned long oid_sharing_files_relocated;
|
||||
unsigned long regular_files;
|
||||
unsigned long broken_files; /* files having stat data and broken body */
|
||||
unsigned long directories;
|
||||
unsigned long symlinks;
|
||||
unsigned long broken_files;
|
||||
unsigned long others;
|
||||
unsigned long fixed_sizes;
|
||||
unsigned long deleted_entries; /* entries pointing to nowhere */
|
||||
unsigned long oid_sharing; /* files relocated due to objectid sharing */
|
||||
unsigned long oid_sharing_files_relocated; /* relocated files */
|
||||
unsigned long oid_sharing_dirs_relocated; /* relocated dirs */
|
||||
unsigned long lost_found;
|
||||
unsigned long empty_lost_dirs;
|
||||
unsigned long lost_found_dirs;
|
||||
unsigned long oid_sharing;
|
||||
unsigned long oid_sharing_dirs_relocated;
|
||||
unsigned long deleted_entries;
|
||||
};
|
||||
|
||||
|
||||
struct lost_found_stat {
|
||||
unsigned long dir_recovered;
|
||||
unsigned long empty_lost_dirs;
|
||||
unsigned long lost_found;
|
||||
unsigned long lost_found_files;
|
||||
unsigned long lost_found_dirs;
|
||||
unsigned long oid_sharing;
|
||||
unsigned long oid_sharing_dirs_relocated;
|
||||
unsigned long oid_sharing_files_relocated;
|
||||
};
|
||||
|
||||
/* pass 4 */
|
||||
unsigned long deleted_items; /* items which were not touched by
|
||||
semantic pass */
|
||||
|
||||
/* objectid maps */
|
||||
struct id_map * proper_id_map;
|
||||
struct id_map * semantic_id_map; /* this objectid map is used to
|
||||
cure objectid sharing problem */
|
||||
struct pass_4_stat {
|
||||
unsigned long deleted_items;
|
||||
};
|
||||
|
||||
|
||||
struct rebuild_info {
|
||||
union {
|
||||
struct pass0_stat pass0;
|
||||
struct pass1_stat pass1;
|
||||
struct pass2_stat pass2;
|
||||
struct semantic_stat semantic;
|
||||
struct lost_found_stat lost_found;
|
||||
struct pass_4_stat pass4;
|
||||
} pass_u;
|
||||
|
||||
/* bitmaps */
|
||||
reiserfs_bitmap_t on_disk_bitmap;
|
||||
reiserfs_bitmap_t new_bitmap;
|
||||
reiserfs_bitmap_t allocable_bitmap;
|
||||
reiserfs_bitmap_t * source_bitmap;
|
||||
reiserfs_bitmap_t * new_bitmap;
|
||||
reiserfs_bitmap_t * allocable_bitmap;
|
||||
reiserfs_bitmap_t * uninsertables;
|
||||
|
||||
char * bitmap_file_name;
|
||||
char * new_bitmap_file_name;
|
||||
/*char * new_bitmap_file_name;*/
|
||||
char * passes_dump_file_name; /* after pass 0, 1 or 2 reiserfsck can store
|
||||
data with which it will be able to start
|
||||
from the point it stopped last time at */
|
||||
|
||||
unsigned short mode;
|
||||
unsigned long options;
|
||||
|
||||
/* log file name and handle */
|
||||
char * log_file_name;
|
||||
FILE * log;
|
||||
/* rollback file */
|
||||
char * rollback_file;
|
||||
|
||||
/* hash hits stat */
|
||||
int hash_amount;
|
||||
unsigned long * hash_hits;
|
||||
char * defined_hash;
|
||||
|
||||
#define USED_BLOCKS 1
|
||||
#define EXTERN_BITMAP 2
|
||||
#define ALL_BLOCKS 3
|
||||
int scan_area;
|
||||
int use_journal_area;
|
||||
int test;
|
||||
};
|
||||
|
||||
|
||||
#define stats(s) ((struct fsck_data *)((s)->s_vp))
|
||||
struct check_info {
|
||||
unsigned long bad_nodes;
|
||||
unsigned long fatal_corruptions;
|
||||
unsigned long fixable_corruptions;
|
||||
// unsigned long badblocks_corruptions;
|
||||
unsigned long leaves;
|
||||
unsigned long internals;
|
||||
unsigned long dirs;
|
||||
unsigned long files;
|
||||
unsigned long safe;
|
||||
unsigned long unfm_pointers;
|
||||
unsigned long zero_unfm_pointers;
|
||||
};
|
||||
|
||||
#define proper_id_map(s) stats(s)->proper_id_map
|
||||
#define semantic_id_map(s) stats(s)->semantic_id_map
|
||||
|
||||
#define fsck_disk_bitmap(s) stats(s)->on_disk_bitmap
|
||||
#define fsck_new_bitmap(s) stats(s)->new_bitmap
|
||||
#define fsck_allocable_bitmap(s) stats(s)->allocable_bitmap
|
||||
struct fsck_data {
|
||||
unsigned short mode; /* check, rebuild, etc*/
|
||||
unsigned long options;
|
||||
|
||||
#define fsck_interactive(fs) (stats(fs)->options & OPT_INTERACTIVE)
|
||||
#define fsck_fix_fixable(fs) (stats(fs)->options & OPT_FIX_FIXABLE)
|
||||
struct rebuild_info rebuild;
|
||||
struct check_info check;
|
||||
|
||||
char * journal_dev_name;
|
||||
/* log file name and handle */
|
||||
char * log_file_name;
|
||||
FILE * log;
|
||||
|
||||
/* this is a file where reiserfsck will explain what it is doing. This is
|
||||
usually stderr. But when -g is specified - reiserfsck runs in the
|
||||
background and append progress information into 'fsck.run' */
|
||||
FILE * progress;
|
||||
|
||||
/* objectid maps */
|
||||
struct id_map * proper_id_map;
|
||||
struct id_map * semantic_id_map; /* this objectid map is used to
|
||||
cure objectid sharing problem */
|
||||
};
|
||||
|
||||
|
||||
#define fsck_data(fs) ((struct fsck_data *)((fs)->fs_vp))
|
||||
#define pass_0_stat(fs) (&(fsck_data(fs)->rebuild.pass_u.pass0))
|
||||
#define pass_1_stat(fs) (&(fsck_data(fs)->rebuild.pass_u.pass1))
|
||||
#define pass_2_stat(fs) (&(fsck_data(fs)->rebuild.pass_u.pass2))
|
||||
#define sem_pass_stat(fs) (&(fsck_data(fs)->rebuild.pass_u.semantic))
|
||||
#define lost_found_pass_stat(fs) (&(fsck_data(fs)->rebuild.pass_u.lost_found))
|
||||
#define pass_4_stat(fs) (&(fsck_data(fs)->rebuild.pass_u.pass4))
|
||||
|
||||
#define fsck_check_stat(fs) (&(fsck_data(fs)->check))
|
||||
|
||||
|
||||
#define proper_id_map(s) fsck_data(s)->proper_id_map
|
||||
#define semantic_id_map(s) fsck_data(s)->semantic_id_map
|
||||
|
||||
#define fsck_source_bitmap(fs) fsck_data(fs)->rebuild.source_bitmap
|
||||
#define fsck_new_bitmap(fs) fsck_data(fs)->rebuild.new_bitmap
|
||||
#define fsck_allocable_bitmap(fs) fsck_data(fs)->rebuild.allocable_bitmap
|
||||
#define fsck_uninsertables(fs) fsck_data(fs)->rebuild.uninsertables
|
||||
|
||||
|
||||
#define fsck_interactive(fs) (fsck_data(fs)->options & OPT_INTERACTIVE)
|
||||
//#define fsck_fix_fixable(fs) (fsck_data(fs)->options & OPT_FIX_FIXABLE)
|
||||
|
||||
#define fsck_run_one_step(fs) (fsck_data(fs)->options & OPT_SAVE_PASSES_DUMP)
|
||||
|
||||
#define fsck_save_rollback(fs) (fsck_data(fs)->options & OPT_SAVE_ROLLBACK)
|
||||
|
||||
/* change unknown modes (corrupted) to mode of regular files, fix file
|
||||
sizes which are bigger than a real file size, relocate files with
|
||||
shared objectids (this slows fsck down (when there are too many
|
||||
files sharing the same objectid), it will also remove other names
|
||||
pointing to this file */
|
||||
#define fsck_fix_non_critical(fs) (stats(fs)->options & OPT_FIX_NON_CRITICAL)
|
||||
#define fsck_quiet(fs) (stats(fs)->options & OPT_QUIET)
|
||||
#define fsck_silent(fs) (stats(fs)->options & OPT_SILENT)
|
||||
|
||||
#define fsck_save_leaf_bitmap(fs) (stats(fs)->options & OPT_SAVE_EXTERN_BITMAP)
|
||||
|
||||
#define fsck_mode(fs) (stats(fs)->mode)
|
||||
#define fsck_log_file(fs) (stats(fs)->log)
|
||||
#define fsck_adjust_file_size(fs) (fsck_data(fs)->options & OPT_ADJUST_FILE_SIZE)
|
||||
#define fsck_quiet(fs) (fsck_data(fs)->options & OPT_QUIET)
|
||||
#define fsck_silent(fs) (fsck_data(fs)->options & OPT_SILENT)
|
||||
#define fsck_save_leaf_bitmap(fs) (fsck_data(fs)->options & OPT_SAVE_EXTERN_BITMAP)
|
||||
#define fsck_in_background(fs) (fsck_data(fs)->options & OPT_BACKGROUND)
|
||||
#define fsck_hash_defined(fs) (fsck_data(fs)->options & OPT_HASH_DEFINED)
|
||||
#define fsck_skip_journal(fs) (fsck_data(fs)->options & OPT_SKIP_JOURNAL)
|
||||
|
||||
|
||||
/* ?? */
|
||||
extern inline int change_version (int version)
|
||||
{
|
||||
return (version == 1)?0:1;
|
||||
}
|
||||
#define fsck_mode(fs) (fsck_data(fs)->mode)
|
||||
#define fsck_log_file(fs) (fsck_data(fs)->log)
|
||||
#define fsck_progress_file(fs) ((fs && fsck_data(fs)->progress) ? fsck_data(fs)->progress : stderr)
|
||||
|
||||
/* name of file where we store information for continuing */
|
||||
#define state_dump_file(fs) fsck_data(fs)->rebuild.passes_dump_file_name
|
||||
|
||||
int fsck_user_confirmed (reiserfs_filsys_t fs, char * q, char * a, int default_answer);
|
||||
void stage_report (int, reiserfs_filsys_t fs);
|
||||
/* name of file where we store rollback data */
|
||||
#define state_rollback_file(fs) fsck_data(fs)->rebuild.rollback_file
|
||||
|
||||
int fsck_user_confirmed (reiserfs_filsys_t * fs, char * q, char * a, int default_answer);
|
||||
void stage_report (int, reiserfs_filsys_t *);
|
||||
|
||||
/* journal.c */
|
||||
int reiserfs_replay_journal (struct super_block * s);
|
||||
int replay_journal (reiserfs_filsys_t *);
|
||||
|
||||
/*pass1: rebuild super block*/
|
||||
void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * data);
|
||||
|
||||
|
||||
#define fsck_log(fmt, list...) \
|
||||
@@ -420,6 +506,15 @@ if (!fsck_silent (fs))\
|
||||
|
||||
#define fsck_progress(fmt, list...) \
|
||||
{\
|
||||
reiserfs_warning (stderr, fmt, ## list);\
|
||||
fflush (stderr);\
|
||||
reiserfs_warning (fsck_progress_file(fs), fmt, ## list);\
|
||||
fflush (fsck_progress_file(fs));\
|
||||
}
|
||||
|
||||
#define one_more_corruption(fs,kind) fsck_check_stat (fs)->kind##_corruptions++
|
||||
#define one_less_corruption(fs,kind) fsck_check_stat (fs)->kind##_corruptions--
|
||||
|
||||
#define fsck_exit(fmt, list...) \
|
||||
{\
|
||||
reiserfs_warning (fsck_progress_file(fs), fmt, ## list);\
|
||||
exit (4);\
|
||||
}
|
||||
+93
-52
@@ -1,99 +1,119 @@
|
||||
|
||||
/*
|
||||
* Copyright 1996-1999 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
|
||||
#include "fsck.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
int fsck_user_confirmed (reiserfs_filsys_t fs, char * q, char * a, int default_answer)
|
||||
int fsck_user_confirmed (reiserfs_filsys_t * fs, char * q, char * a, int default_answer)
|
||||
{
|
||||
if (!fsck_interactive (fs))
|
||||
return default_answer;
|
||||
|
||||
return user_confirmed (q, a);
|
||||
return user_confirmed (fsck_progress_file (fs), q, a);
|
||||
}
|
||||
|
||||
|
||||
void stage_report (int pass, reiserfs_filsys_t fs)
|
||||
void stage_report (int pass, reiserfs_filsys_t * fs)
|
||||
{
|
||||
FILE * fp;
|
||||
struct fsck_data * stat;
|
||||
|
||||
stat = stats (fs);
|
||||
fp = stderr;
|
||||
|
||||
switch (pass) {
|
||||
case 0:
|
||||
fsck_progress ("\tRead blocks (but not data blocks) %lu\n", stat->analyzed);
|
||||
stat->analyzed = 0;
|
||||
{
|
||||
struct pass0_stat * stat;
|
||||
|
||||
/* what has been done on pass 0 */
|
||||
stat = pass_0_stat (fs);
|
||||
fsck_progress ("\tRead blocks (but not data blocks) %lu\n", stat->dealt_with);
|
||||
fsck_progress ("\t\tLeaves among those %lu\n", stat->leaves);
|
||||
if (stat->leaves_corrected)
|
||||
fsck_progress ("\t\t\t- corrected leaves %lu\n", stat->leaves_corrected);
|
||||
if (stat->all_contents_removed)
|
||||
fsck_progress ("\t\t\t- eaves all contents of which could not be saved and deleted %lu\n", stat->all_contents_removed);
|
||||
if (stat->pointed_leaves)
|
||||
fsck_progress ("\t\t\t- leaves pointed by indirect items %lu\n", stat->pointed_leaves);
|
||||
if (stat->pointed)
|
||||
fsck_progress ("\t\tBlocks pointed by indirect items %lu\n", stat->pointed);
|
||||
if (stat->pointed_once)
|
||||
fsck_progress ("\t\t\t- once %lu\n", stat->pointed_once);
|
||||
if (stat->pointed_more_than_once)
|
||||
fsck_progress ("\t\t\t- more than once %lu\n", stat->pointed_more_than_once);
|
||||
fsck_progress ("\t\t\t- leaves all contents of which could not be saved and deleted %lu\n",
|
||||
stat->all_contents_removed);
|
||||
if (stat->too_old_leaves)
|
||||
fsck_progress ("\t\t\t- too old leaves %lu (skipped)\n", stat->too_old_leaves);
|
||||
if (stat->wrong_pointers)
|
||||
fsck_progress ("\t\t\t- pointers to wrong area of filesystem (zeroed) %lu\n", stat->wrong_pointers);
|
||||
/* pass1 will calculate how many pointers were zeeros there */
|
||||
stat->wrong_pointers = 0;
|
||||
fsck_progress ("\t\tpointers in indirect items to wrong area %lu (zeroed)\n",
|
||||
stat->wrong_pointers);
|
||||
fsck_progress ("\t\tObjectids found %lu\n", proper_id_map (fs)->objectids_marked);
|
||||
|
||||
/*fsck_progress ("\tblocks marked free %lu\n", stat->free);*/
|
||||
fsck_progress ("\tallocable %lu blocks\n", stat->allocable);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
fsck_progress ("\t%lu leaves read\n", stat->analyzed);
|
||||
{
|
||||
struct pass1_stat * stat;
|
||||
|
||||
/* what has been done on pass 1 */
|
||||
stat = pass_1_stat (fs);
|
||||
fsck_progress ("\t%lu leaves read\n", stat->leaves);
|
||||
fsck_progress ("\t\t%lu inserted\n", stat->inserted_leaves);
|
||||
if (stat->pointed_leaves)
|
||||
fsck_progress ("\t\t\t- pointers in indirect items pointing to metadata %lu (zeroed)\n",
|
||||
stat->pointed_leaves);
|
||||
if (stat->saved_items)
|
||||
fsck_progress ("\tSaved %lu items\n", stat->saved_items);
|
||||
if (stat->uninsertable_leaves)
|
||||
fsck_progress ("\t\t%lu not inserted\n", stat->uninsertable_leaves);
|
||||
if (stat->saved_on_pass1)
|
||||
fsck_progress ("\tSaved %lu items\n", stat->saved_on_pass1);
|
||||
if (stat->wrong_pointers)
|
||||
fsck_progress ("\tPointers to leaves or non-unique (zeroed) %lu\n",
|
||||
stat->wrong_pointers);
|
||||
break;
|
||||
if (stat->non_unique_pointers)
|
||||
fsck_progress ("\tnon-unique pointers in indirect items (zeroed) %lu\n",
|
||||
stat->non_unique_pointers);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
struct pass2_stat * stat;
|
||||
|
||||
/* what has been done on pass 2 */
|
||||
stat = pass_2_stat (fs);
|
||||
if (stat->leaves)
|
||||
fsck_progress ("\tLeaves inserted item by item %lu\n", stat->leaves);
|
||||
if (stat->safe_non_unique_pointers)
|
||||
fsck_progress ("\t%lu \n",
|
||||
stat->safe_non_unique_pointers);
|
||||
if (stat->shared_objectids)
|
||||
fsck_progress ("\t%lu shared objectids\n", stat->shared_objectids);
|
||||
if (stat->relocated)
|
||||
fsck_progress ("\tFiles relocated because of key conflicts w/ a directory %lu\n",
|
||||
stat->relocated);
|
||||
if (stat->rewritten)
|
||||
fsck_progress ("\tFiles rewritten %lu\n",
|
||||
stat->rewritten);
|
||||
return;
|
||||
fsck_progress ("\tFiles rewritten %lu\n", stat->rewritten);
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: /* semantic pass */
|
||||
case 3: /* semantic */
|
||||
{
|
||||
struct semantic_stat * stat;
|
||||
|
||||
/* what has been done on the semantic pass */
|
||||
stat = sem_pass_stat (fs);
|
||||
fsck_progress ("\tFiles found: %ld\n", stat->regular_files);
|
||||
fsck_progress ("\tDirectories found: %ld\n", stat->directories);
|
||||
if (stat->symlinks)
|
||||
fsck_progress ("\tSymlinks found: %ld\n", stat->symlinks);
|
||||
if (stat->others)
|
||||
fsck_progress ("\tOthers: %ld\n", stat->others);
|
||||
if (stat->broken_files)
|
||||
fsck_progress ("\tBroken (of files/symlinks/others): %ld\n", stat->broken_files);
|
||||
if (stat->fixed_sizes)
|
||||
fsck_progress ("\tFiles with fixed size: %ld\n", stat->fixed_sizes);
|
||||
if (stat->deleted_entries)
|
||||
fsck_progress ("\tNames pointing to nowhere (removed): %ld\n", stat->deleted_entries);
|
||||
if (stat->oid_sharing)
|
||||
fsck_progress ("\tObjects having used objectids: %lu\n", stat->oid_sharing);
|
||||
if (stat->oid_sharing_files_relocated)
|
||||
fsck_progress ("\t\tfiles fixed %lu\n", stat->oid_sharing_files_relocated);
|
||||
if (stat->oid_sharing_dirs_relocated)
|
||||
fsck_progress ("\t\tdirs fixed %lu\n", stat->oid_sharing_dirs_relocated);
|
||||
stat->oid_sharing = 0;
|
||||
stat->oid_sharing_files_relocated = 0;
|
||||
stat->oid_sharing_dirs_relocated = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x3a: /* looking for lost files */
|
||||
case 0x3a: /* lost+found pass */
|
||||
{
|
||||
struct lost_found_stat * stat;
|
||||
|
||||
/* what has been done on the semantic pass */
|
||||
stat = lost_found_pass_stat (fs);
|
||||
if (stat->lost_found)
|
||||
fsck_progress ("\tObjects without names %lu\n",
|
||||
stat->lost_found);
|
||||
@@ -116,19 +136,40 @@ void stage_report (int pass, reiserfs_filsys_t fs)
|
||||
fsck_progress ("\t\tfiles fixed %lu\n", stat->oid_sharing_files_relocated);
|
||||
if (stat->oid_sharing_dirs_relocated)
|
||||
fsck_progress ("\t\tdirs fixed %lu\n", stat->oid_sharing_dirs_relocated);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 4: /* removing of unreachable */
|
||||
{
|
||||
struct pass_4_stat * stat;
|
||||
|
||||
/* what has been done on the semantic pass */
|
||||
stat = pass_4_stat (fs);
|
||||
if (stat->deleted_items)
|
||||
fsck_progress ("\tDeleted unreachable items %lu\n",
|
||||
stat->deleted_items);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
fsck_progress ("There are on the filesystem:\n"
|
||||
"\tLeaves %lu\n\tInternal nodes %lu\n"
|
||||
"\tDirectories %lu\n\tOther files %lu\n"
|
||||
"\tData block pointers %lu (%lu of them are zero)\n"
|
||||
"\tSafe links %lu\n",
|
||||
fsck_check_stat (fs)->leaves,
|
||||
fsck_check_stat (fs)->internals,
|
||||
fsck_check_stat (fs)->dirs,
|
||||
fsck_check_stat (fs)->files,
|
||||
fsck_check_stat (fs)->unfm_pointers,
|
||||
fsck_check_stat (fs)->zero_unfm_pointers,
|
||||
fsck_check_stat (fs)->safe);
|
||||
|
||||
|
||||
} /* switch */
|
||||
|
||||
memset (&fsck_data (fs)->rebuild.pass_u, 0, sizeof (fsck_data (fs)->rebuild.pass_u));
|
||||
|
||||
if (!fsck_user_confirmed (fs, "Continue? (Yes):", "Yes\n", 1)) {
|
||||
reiserfs_close (fs);
|
||||
exit (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-219
@@ -1,219 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000 Hans Reiser
|
||||
*/
|
||||
|
||||
#include "fsck.h"
|
||||
#include <limits.h>
|
||||
/*#include <stdlib.h>*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define bh_desc(bh) ((struct reiserfs_journal_desc *)((bh)->b_data))
|
||||
#define bh_commit(bh) ((struct reiserfs_journal_commit *)((bh)->b_data))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int next_expected_desc (struct super_block * s, struct buffer_head * d_bh)
|
||||
{
|
||||
int offset;
|
||||
struct reiserfs_journal_desc * desc;
|
||||
|
||||
desc = (struct reiserfs_journal_desc *)d_bh->b_data;
|
||||
offset = d_bh->b_blocknr - SB_JOURNAL_BLOCK (s);
|
||||
return SB_JOURNAL_BLOCK (s) + ((offset + desc->j_len + 1 + 1) % JOURNAL_BLOCK_COUNT);
|
||||
}
|
||||
|
||||
|
||||
static int is_valid_transaction (struct super_block * s, struct buffer_head * d_bh)
|
||||
{
|
||||
struct buffer_head * c_bh;
|
||||
int offset;
|
||||
struct reiserfs_journal_desc *desc = (struct reiserfs_journal_desc *)d_bh->b_data;
|
||||
struct reiserfs_journal_commit *commit ;
|
||||
__u32 block, start_block;
|
||||
|
||||
|
||||
offset = d_bh->b_blocknr - SB_JOURNAL_BLOCK (s);
|
||||
|
||||
/* ok, we have a journal description block, lets see if the transaction was valid */
|
||||
block = next_expected_desc (s, d_bh) - 1;
|
||||
start_block = d_bh->b_blocknr;
|
||||
while(!(c_bh = bread (s->s_dev, block, s->s_blocksize))){
|
||||
if (++block == SB_JOURNAL_BLOCK (s) + JOURNAL_BLOCK_COUNT)
|
||||
block = SB_JOURNAL_BLOCK (s);
|
||||
if (block == start_block)
|
||||
return 0;
|
||||
}
|
||||
|
||||
commit = (struct reiserfs_journal_commit *)c_bh->b_data ;
|
||||
if (does_desc_match_commit (desc, commit)) {
|
||||
// if (journal_compare_desc_commit (s, desc, commit)) {
|
||||
/* printf ("desc and commit block do not match\n");*/
|
||||
brelse (c_bh) ;
|
||||
return 0;
|
||||
}
|
||||
brelse (c_bh);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int reiserfs_replay_journal (struct super_block * s)
|
||||
{
|
||||
struct buffer_head * d_bh, * c_bh, * jh_bh;
|
||||
struct reiserfs_journal_header * j_head;
|
||||
struct reiserfs_journal_desc * j_desc;
|
||||
struct reiserfs_journal_commit * j_commit;
|
||||
unsigned long latest_mount_id;
|
||||
unsigned long j_cur;
|
||||
unsigned long j_start;
|
||||
unsigned long j_size;
|
||||
unsigned long mount_id, trans_id;
|
||||
unsigned long t_first, t_last, t_count, t_flushed;
|
||||
unsigned long t_offset;
|
||||
int i;
|
||||
|
||||
fsck_progress ("Analyzing journal..");
|
||||
|
||||
j_start = SB_JOURNAL_BLOCK (s);
|
||||
j_cur = 0;
|
||||
j_size = rs_journal_size (s->s_rs);
|
||||
t_first = 0;
|
||||
t_last = 0;
|
||||
latest_mount_id = 0;
|
||||
|
||||
/* look for the transactions with the most recent mount_id */
|
||||
for (j_cur = 0; j_cur < j_size; ) {
|
||||
d_bh = bread (s->s_dev, j_start + j_cur, s->s_blocksize);
|
||||
if (d_bh && who_is_this (d_bh->b_data, d_bh->b_size) == THE_JDESC && is_valid_transaction (s, d_bh)) {
|
||||
j_desc = (struct reiserfs_journal_desc *)d_bh->b_data;
|
||||
|
||||
mount_id = le32_to_cpu (j_desc->j_mount_id);
|
||||
trans_id = le32_to_cpu (j_desc->j_trans_id);
|
||||
|
||||
if (mount_id > latest_mount_id) {
|
||||
/* more recent mount_id found */
|
||||
latest_mount_id = mount_id;
|
||||
t_first = t_last = trans_id;
|
||||
t_offset = j_cur;
|
||||
t_count = 1;
|
||||
} else if (mount_id == latest_mount_id) {
|
||||
t_count ++;
|
||||
if (trans_id > t_last)
|
||||
t_last = trans_id;
|
||||
if (trans_id < t_first) {
|
||||
t_first = trans_id;
|
||||
t_offset = j_cur;
|
||||
}
|
||||
}
|
||||
j_cur += le32_to_cpu (j_desc->j_len) + 1;
|
||||
}
|
||||
j_cur ++;
|
||||
brelse (d_bh);
|
||||
}
|
||||
|
||||
/* replay only if journal header looks resonable */
|
||||
jh_bh = bread (s->s_dev, j_start + j_size, s->s_blocksize);
|
||||
j_head = (struct reiserfs_journal_header *)(jh_bh->b_data);
|
||||
|
||||
if (latest_mount_id != le32_to_cpu (j_head->j_mount_id)) {
|
||||
fsck_progress ("nothing to replay (no transactions match to latest mount id)\n");
|
||||
brelse (jh_bh);
|
||||
return 0;
|
||||
}
|
||||
/* last transaction flushed - which should not be replayed */
|
||||
t_flushed = le32_to_cpu (j_head->j_last_flush_trans_id);
|
||||
if (t_flushed >= t_last) {
|
||||
fsck_progress ("nothing to replay (no transactions older than last flushed one found)\n");
|
||||
brelse (jh_bh);
|
||||
return 0;
|
||||
}
|
||||
if (t_first > t_flushed + 1) {
|
||||
if (t_flushed)
|
||||
fsck_progress ("last flushed trans %lu, the oldest but newer is %lu\n",
|
||||
t_flushed, t_first);
|
||||
} else {
|
||||
/* start replaying with first not flushed transaction */
|
||||
t_first = t_flushed + 1;
|
||||
t_offset = le32_to_cpu (j_head->j_first_unflushed_offset);
|
||||
}
|
||||
|
||||
fsck_progress ("last flushed trans %lu, mount_id %lu, "
|
||||
"will replay from %lu up to %lu:Yes?",
|
||||
t_flushed, latest_mount_id, t_first, t_last);
|
||||
if (!fsck_user_confirmed (fs, "", "Yes\n", 1))
|
||||
die ("");
|
||||
|
||||
/* replay transactions we have found */
|
||||
for (j_cur = t_offset; t_first <= t_last; t_first ++) {
|
||||
unsigned long offset;
|
||||
|
||||
d_bh = bread (s->s_dev, j_start + j_cur, s->s_blocksize);
|
||||
j_desc = (struct reiserfs_journal_desc *)d_bh->b_data;
|
||||
if (who_is_this (d_bh->b_data, d_bh->b_size) != THE_JDESC ||
|
||||
le32_to_cpu (j_desc->j_mount_id) != latest_mount_id ||
|
||||
le32_to_cpu (j_desc->j_trans_id) != t_first)
|
||||
die ("reiserfs_replay_journal: desc block not found");
|
||||
|
||||
offset = j_cur + 1;
|
||||
j_cur += le32_to_cpu (j_desc->j_len) + 1;
|
||||
j_cur %= j_size;
|
||||
c_bh = bread (s->s_dev, j_start + j_cur, s->s_blocksize);
|
||||
j_commit = (struct reiserfs_journal_commit *)c_bh->b_data;
|
||||
if (does_desc_match_commit (j_desc, j_commit))
|
||||
die ("reiserfs_replay_journal: commit block not found");
|
||||
|
||||
fsck_log ("Mount_id %lu, transaction %lu, desc block %lu, commit block %lu: (",
|
||||
latest_mount_id, t_first, d_bh->b_blocknr, c_bh->b_blocknr);
|
||||
|
||||
/* replay one transaction */
|
||||
for (i = 0; i < le32_to_cpu (j_desc->j_len); i ++) {
|
||||
struct buffer_head * in_place, * log;
|
||||
unsigned long block;
|
||||
|
||||
log = bread (s->s_dev, j_start + ((offset + i) % j_size), s->s_blocksize);
|
||||
|
||||
if (i < JOURNAL_TRANS_HALF) {
|
||||
block = le32_to_cpu (j_desc->j_realblock[i]);
|
||||
} else {
|
||||
block = le32_to_cpu (j_commit->j_realblock[i - JOURNAL_TRANS_HALF]);
|
||||
}
|
||||
|
||||
if (not_journalable (s, block)) {
|
||||
fsck_log ("transaction %lu, block %d could not be replayed (%lu)\n",
|
||||
t_first, i, block);
|
||||
} else {
|
||||
fsck_log (" %lu", block);
|
||||
|
||||
in_place = getblk (s->s_dev, block, s->s_blocksize) ;
|
||||
memcpy (in_place->b_data, log->b_data, s->s_blocksize);
|
||||
mark_buffer_dirty (in_place);
|
||||
mark_buffer_uptodate (in_place, 1);
|
||||
bwrite (in_place);
|
||||
brelse (in_place);
|
||||
}
|
||||
brelse (log);
|
||||
|
||||
}
|
||||
fsck_log (")\n");
|
||||
|
||||
brelse (d_bh);
|
||||
brelse (c_bh);
|
||||
j_cur ++;
|
||||
j_cur %= j_size;
|
||||
|
||||
/* update journal header */
|
||||
j_head->j_last_flush_trans_id = cpu_to_le32 (t_first);
|
||||
mark_buffer_dirty (jh_bh);
|
||||
bwrite (jh_bh);
|
||||
}
|
||||
|
||||
brelse (jh_bh);
|
||||
fsck_progress ("Journal replaied\n");
|
||||
return 0;
|
||||
}
|
||||
+148
-42
@@ -1,12 +1,17 @@
|
||||
/*
|
||||
* Copyright 2000-2001 Hans Reiser
|
||||
* Copyright 2000-2002 Hans Reiser
|
||||
*/
|
||||
|
||||
#include "fsck.h"
|
||||
|
||||
|
||||
void erase_name (int len);
|
||||
void print_name (char * name, int len);
|
||||
|
||||
void modify_item (struct item_head * ih, void * item);
|
||||
|
||||
/* fixme: search_by_key is not needed after any add_entry */
|
||||
static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
static __u64 _look_for_lost (reiserfs_filsys_t * fs, int link_lost_dirs)
|
||||
{
|
||||
struct key key, prev_key, * rdkey;
|
||||
INITIALIZE_PATH (path);
|
||||
@@ -36,12 +41,12 @@ static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
/* total size of added entries */
|
||||
size = 0;
|
||||
while (1) {
|
||||
retval = usearch_by_key (fs, &key, &path);
|
||||
retval = reiserfs_search_by_key_4 (fs, &key, &path);
|
||||
/* fixme: we assume path ends up with a leaf */
|
||||
bh = get_bh (&path);
|
||||
item_pos = get_item_pos (&path);
|
||||
if (retval != ITEM_FOUND) {
|
||||
if (item_pos == node_item_number (bh)) {
|
||||
if (item_pos == get_blkh_nr_items (B_BLK_HEAD (bh))) {
|
||||
rdkey = uget_rkey (&path);
|
||||
if (!rdkey) {
|
||||
pathrelse (&path);
|
||||
@@ -56,9 +61,9 @@ static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
|
||||
/* print ~ how many leaves were scanned and how fast it was */
|
||||
if (!fsck_quiet (fs))
|
||||
print_how_fast (0, leaves++, 50);
|
||||
print_how_fast (leaves++, 0, 50, 0);
|
||||
|
||||
for (ih = get_ih (&path); item_pos < node_item_number (bh); item_pos ++, ih ++) {
|
||||
for (ih = get_ih (&path); item_pos < get_blkh_nr_items (B_BLK_HEAD (bh)); item_pos ++, ih ++, PATH_LAST_POSITION(&path)++) {
|
||||
if (is_item_reachable (ih))
|
||||
continue;
|
||||
|
||||
@@ -74,14 +79,15 @@ static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
|
||||
sd = ih->ih_key;
|
||||
set_type_and_offset (KEY_FORMAT_1, &sd, SD_OFFSET, TYPE_STAT_DATA);
|
||||
if (usearch_by_key (fs, &sd, &tmp) == ITEM_FOUND) {
|
||||
if (reiserfs_search_by_key_4 (fs, &sd, &tmp) == ITEM_FOUND) {
|
||||
/* should not happen - because if there were a stat data -
|
||||
we would have done with the whole directory */
|
||||
pathrelse (&tmp);
|
||||
continue;
|
||||
}
|
||||
stats(fs)->dir_recovered ++;
|
||||
create_dir_sd (fs, &tmp, &sd);
|
||||
lost_found_pass_stat (fs)->dir_recovered ++;
|
||||
create_dir_sd (fs, &tmp, &sd, modify_item);
|
||||
mark_objectid_really_used (proper_id_map (fs), get_key_objectid (&sd));
|
||||
key = sd;
|
||||
pathrelse (&path);
|
||||
goto cont;
|
||||
@@ -89,7 +95,10 @@ static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
|
||||
|
||||
/* stat data marked "not having name" found */
|
||||
is_it_dir = ((not_a_directory (B_I_PITEM (bh,ih))) ? 0 : 1);
|
||||
if (is_stat_data_ih (get_ih(&path)))
|
||||
fix_obviously_wrong_sd_mode (&path);
|
||||
|
||||
is_it_dir = ((not_a_directory (B_I_PITEM (bh,ih))) ? 0 : 1);
|
||||
|
||||
if (is_it_dir) {
|
||||
struct key tmp_key;
|
||||
@@ -99,17 +108,17 @@ static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
/* there is no need to link empty lost directories into /lost+found */
|
||||
tmp_key = ih->ih_key;
|
||||
set_type_and_offset (KEY_FORMAT_1, &tmp_key, 0xffffffff, TYPE_DIRENTRY);
|
||||
usearch_by_key (fs, &tmp_key, &tmp_path);
|
||||
reiserfs_search_by_key_4 (fs, &tmp_key, &tmp_path);
|
||||
tmp_ih = get_ih (&tmp_path);
|
||||
tmp_ih --;
|
||||
if (not_of_one_file (&tmp_key, tmp_ih))
|
||||
reiserfs_panic ("not directory found");
|
||||
if (!is_direntry_ih (tmp_ih) ||
|
||||
(deh_offset (B_I_DEH (get_bh (&tmp_path), ih) +
|
||||
ih_entry_count (tmp_ih) - 1) == DOT_DOT_OFFSET)) {
|
||||
(get_deh_offset (B_I_DEH (get_bh (&tmp_path), tmp_ih) +
|
||||
get_ih_entry_count (tmp_ih) - 1) == DOT_DOT_OFFSET)) {
|
||||
/* last directory item is either stat data or empty
|
||||
directory item - do not link this dir into lost+found */
|
||||
stats(fs)->empty_lost_dirs ++;
|
||||
lost_found_pass_stat (fs)->empty_lost_dirs ++;
|
||||
pathrelse (&tmp_path);
|
||||
continue;
|
||||
}
|
||||
@@ -122,72 +131,75 @@ static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
continue;
|
||||
}
|
||||
|
||||
stats(fs)->lost_found ++;
|
||||
lost_found_pass_stat (fs)->lost_found ++;
|
||||
|
||||
{
|
||||
struct key obj_key = {0, 0, {{0, 0},}};
|
||||
char * lost_name;
|
||||
struct item_head tmp_ih;
|
||||
int pos_in_map;
|
||||
__u32 pos_in_map;
|
||||
|
||||
/* key to continue */
|
||||
key = ih->ih_key;
|
||||
key.k_objectid ++;
|
||||
set_key_objectid (&key, get_key_objectid (&key) + 1);
|
||||
|
||||
tmp_ih = *ih;
|
||||
if (is_objectid_really_used (semantic_id_map (fs), ih->ih_key.k_objectid,
|
||||
if (is_objectid_really_used (semantic_id_map (fs),
|
||||
get_key_objectid (&ih->ih_key),
|
||||
&pos_in_map)) {
|
||||
/* objectid is used, relocate an object */
|
||||
stats(fs)->oid_sharing ++;
|
||||
if (fsck_fix_non_critical (fs)) {
|
||||
lost_found_pass_stat (fs)->oid_sharing ++;
|
||||
if (1/*fsck_adjust_file_size (fs)*/) {
|
||||
if (is_it_dir) {
|
||||
relocate_dir (&tmp_ih, 1);
|
||||
stats(fs)->oid_sharing_dirs_relocated ++;
|
||||
lost_found_pass_stat (fs)->oid_sharing_dirs_relocated ++;
|
||||
} else {
|
||||
relocate_file (&tmp_ih, 1);
|
||||
stats(fs)->oid_sharing_files_relocated ++;
|
||||
lost_found_pass_stat (fs)->oid_sharing_files_relocated ++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!is_it_dir)
|
||||
mark_objectid_really_used (semantic_id_map (fs), ih->ih_key.k_objectid);
|
||||
mark_objectid_really_used (semantic_id_map (fs), get_key_objectid (&ih->ih_key));
|
||||
}
|
||||
|
||||
asprintf (&lost_name, "%u_%u", le32_to_cpu (tmp_ih.ih_key.k_dir_id),
|
||||
le32_to_cpu (tmp_ih.ih_key.k_objectid));
|
||||
asprintf (&lost_name, "%u_%u", get_key_dirid (&tmp_ih.ih_key),
|
||||
get_key_objectid (&tmp_ih.ih_key));
|
||||
|
||||
/* entry in lost+found directory will point to this key */
|
||||
obj_key.k_dir_id = tmp_ih.ih_key.k_dir_id;
|
||||
obj_key.k_objectid = tmp_ih.ih_key.k_objectid;
|
||||
|
||||
set_key_dirid (&obj_key, get_key_dirid (&tmp_ih.ih_key));
|
||||
set_key_objectid (&obj_key, get_key_objectid (&tmp_ih.ih_key));
|
||||
|
||||
pathrelse (&path);
|
||||
|
||||
/* 0 does not mean anyting - item w/ "." and ".." already
|
||||
exists and reached, so only name will be added */
|
||||
size += reiserfs_add_entry (fs, &lost_found_dir_key, lost_name, &obj_key, 0/*fsck_need*/);
|
||||
size += reiserfs_add_entry (fs, &lost_found_dir_key, lost_name,
|
||||
name_length (lost_name, lost_found_dir_format), &obj_key, 0/*fsck_need*/);
|
||||
|
||||
if (is_it_dir) {
|
||||
/* fixme: we hope that if we will try to pull all the
|
||||
directory right now - then there will be less
|
||||
lost_found things */
|
||||
fsck_progress ("\tChecking lost dir \"%s\":", lost_name);
|
||||
print_name (lost_name, strlen (lost_name));
|
||||
/*fsck_progress ("\tChecking lost dir \"%s\":", lost_name);*/
|
||||
rebuild_semantic_pass (&obj_key, &lost_found_dir_key, /*dot_dot*/0, /*reloc_ih*/0);
|
||||
fsck_progress ("ok\n");
|
||||
stats(fs)->lost_found_dirs ++;
|
||||
erase_name (strlen (lost_name));
|
||||
/*fsck_progress ("ok\n");*/
|
||||
|
||||
lost_found_pass_stat (fs)->lost_found_dirs ++;
|
||||
} else {
|
||||
if (usearch_by_key (fs, &obj_key, &path) != ITEM_FOUND)
|
||||
if (reiserfs_search_by_key_4 (fs, &obj_key, &path) != ITEM_FOUND)
|
||||
reiserfs_panic ("look_for_lost: lost file stat data %K not found",
|
||||
&obj_key);
|
||||
|
||||
/* check_regular_file does not mark stat data reachable */
|
||||
mark_item_reachable (get_ih (&path), get_bh (&path));
|
||||
mark_buffer_dirty (get_bh (&path));
|
||||
|
||||
rebuild_check_regular_file (&path, get_item (&path), 0/*reloc_ih*/);
|
||||
pathrelse (&path);
|
||||
|
||||
stats(fs)->lost_found_files ++;
|
||||
lost_found_pass_stat (fs)->lost_found_files ++;
|
||||
lost_files --;
|
||||
}
|
||||
|
||||
@@ -197,7 +209,14 @@ static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
} /* for */
|
||||
|
||||
prev_key = key;
|
||||
get_next_key (&path, item_pos - 1, &key);
|
||||
|
||||
PATH_LAST_POSITION(&path) = item_pos - 1;
|
||||
rdkey = reiserfs_next_key (&path);
|
||||
if (rdkey)
|
||||
key = *rdkey;
|
||||
else
|
||||
break;
|
||||
|
||||
if (comp_keys (&prev_key, &key) != -1)
|
||||
reiserfs_panic ("pass_3a: key must grow 2: prev=%k next=%k",
|
||||
&prev_key, &key);
|
||||
@@ -227,16 +246,90 @@ static __u64 _look_for_lost (reiserfs_filsys_t fs, int link_lost_dirs)
|
||||
|
||||
}
|
||||
|
||||
static void save_lost_found_result (reiserfs_filsys_t * fs)
|
||||
{
|
||||
FILE * file;
|
||||
int retval;
|
||||
|
||||
void pass_3a_look_for_lost (reiserfs_filsys_t fs)
|
||||
/* save bitmaps with which we will be able start reiserfs from
|
||||
pass 1 */
|
||||
file = open_file ("temp_fsck_file.deleteme", "w+");
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
reiserfs_begin_stage_info_save (file, LOST_FOUND_DONE);
|
||||
reiserfs_end_stage_info_save (file);
|
||||
close_file (file);
|
||||
|
||||
retval = unlink (state_dump_file (fs));
|
||||
retval = rename ("temp_fsck_file.deleteme", state_dump_file (fs));
|
||||
if (retval != 0)
|
||||
fsck_progress ("pass 0: could not rename temp file temp_fsck_file.deleteme to %s",
|
||||
state_dump_file (fs));
|
||||
}
|
||||
|
||||
/* we have nothing to load from a state file, but we have to fetch
|
||||
on-disk bitmap, copy it to allocable bitmap, and fetch objectid
|
||||
map */
|
||||
void load_lost_found_result (reiserfs_filsys_t * fs)
|
||||
{
|
||||
fsck_new_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_copy (fsck_new_bitmap (fs), fs->fs_bitmap2);
|
||||
|
||||
fsck_allocable_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_copy (fsck_allocable_bitmap (fs), fs->fs_bitmap2);
|
||||
|
||||
fs->block_allocator = reiserfsck_reiserfs_new_blocknrs;
|
||||
fs->block_deallocator = reiserfsck_reiserfs_free_block;
|
||||
|
||||
/* we need objectid map on semantic pass to be able to relocate files */
|
||||
proper_id_map (fs) = init_id_map ();
|
||||
fetch_objectid_map (proper_id_map (fs), fs);
|
||||
}
|
||||
|
||||
void after_lost_found (reiserfs_filsys_t * fs)
|
||||
{
|
||||
/* update super block: objectid map, fsck state */
|
||||
set_sb_fs_state (fs->fs_ondisk_sb, LOST_FOUND_DONE);
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
|
||||
/* write all dirty blocks */
|
||||
fsck_progress ("Flushing..");
|
||||
flush_objectid_map (proper_id_map (fs), fs);
|
||||
fs->fs_dirt = 1;
|
||||
reiserfs_flush_to_ondisk_bitmap (fsck_new_bitmap(fs), fs);
|
||||
reiserfs_flush (fs);
|
||||
fsck_progress ("done\n");
|
||||
|
||||
stage_report (0x3a, fs);
|
||||
|
||||
if (!fsck_run_one_step (fs)) {
|
||||
if (fsck_user_confirmed (fs, "Continue? (Yes):", "Yes\n", 1))
|
||||
/* reiserfsck continues */
|
||||
return;
|
||||
}
|
||||
|
||||
save_lost_found_result (fs);
|
||||
|
||||
free_id_map (proper_id_map (fs));
|
||||
proper_id_map (fs) = 0;
|
||||
|
||||
fs->fs_dirt = 1;
|
||||
reiserfs_close (fs);
|
||||
exit (4);
|
||||
}
|
||||
|
||||
void pass_3a_look_for_lost (reiserfs_filsys_t * fs)
|
||||
{
|
||||
INITIALIZE_PATH (path);
|
||||
struct item_head * ih;
|
||||
void * sd;
|
||||
__u64 size, sd_size;
|
||||
__u32 blocks;
|
||||
|
||||
fsck_progress ("Pass 3a (looking for lost files):\n");
|
||||
__u16 mode;
|
||||
__u32 objectid;
|
||||
int gen_counter;
|
||||
fsck_progress ("Pass 3a (looking for lost dir/files):\n");
|
||||
|
||||
/* when warnings go not to stderr - separate then in the log */
|
||||
if (fsck_log_file (fs) != stderr)
|
||||
@@ -250,20 +343,33 @@ void pass_3a_look_for_lost (reiserfs_filsys_t fs)
|
||||
size += _look_for_lost (fs, 0);
|
||||
|
||||
/* update /lost+found sd_size and sd_blocks (nlink is correct already) */
|
||||
if (usearch_by_key (fs, &lost_found_dir_key, &path) != ITEM_FOUND)
|
||||
|
||||
objectid = reiserfs_find_entry (fs, &root_dir_key, "lost+found",
|
||||
&gen_counter, &lost_found_dir_key);
|
||||
|
||||
if (!objectid) {
|
||||
reiserfs_panic ("look_for_lost: 'lost+found' direntry not found");
|
||||
}
|
||||
|
||||
if (reiserfs_search_by_key_4 (fs, &lost_found_dir_key, &path) != ITEM_FOUND)
|
||||
reiserfs_panic ("look_for_lost: /lost+found stat data %K not found",
|
||||
&lost_found_dir_key);
|
||||
ih = get_ih (&path);
|
||||
sd = get_item (&path);
|
||||
get_sd_size (ih, sd, &sd_size);
|
||||
size += sd_size;
|
||||
blocks = dir_size2st_blocks (fs->s_blocksize, size);
|
||||
blocks = dir_size2st_blocks (size);
|
||||
|
||||
set_sd_size (ih, sd, &size);
|
||||
set_sd_blocks (ih, sd, &blocks);
|
||||
|
||||
/* make lost+found to be drwx------ */
|
||||
mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
|
||||
set_sd_mode (ih, sd, &mode);
|
||||
|
||||
mark_buffer_dirty (get_bh (&path));
|
||||
pathrelse (&path);
|
||||
|
||||
stage_report (0x3a, fs);
|
||||
after_lost_found (fs);
|
||||
}
|
||||
|
||||
+859
-487
File diff suppressed because it is too large.
Load diff
+969
-569
File diff suppressed because it is too large.
Load diff
+348
-346
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
* Copyright 1996-1999 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
#include "fsck.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
reiserfs_bitmap_t * bad_unfm_in_tree_once_bitmap;
|
||||
|
||||
reiserfs_bitmap_t bad_unfm_in_tree_once_bitmap;
|
||||
|
||||
//int step = 0; // 0 - find stat_data or any item ; 1 - find item ; 2 - already found
|
||||
|
||||
|
||||
/* allocates buffer head and copy buffer content */
|
||||
struct buffer_head * make_buffer (int dev, int blocknr, int size, char * data)
|
||||
struct buffer_head * make_buffer (int dev, unsigned long blocknr, int size, char * data)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
|
||||
@@ -27,11 +27,11 @@ struct buffer_head * make_buffer (int dev, int blocknr, int size, char * data)
|
||||
|
||||
int find_not_of_one_file(struct key * to_find, struct key * key)
|
||||
{
|
||||
if ((to_find->k_objectid != -1) &&
|
||||
(to_find->k_objectid != key->k_objectid))
|
||||
if ((get_key_objectid (to_find) != -1) &&
|
||||
(get_key_objectid (to_find) != get_key_objectid (key)))
|
||||
return 1;
|
||||
if ((to_find->k_dir_id != -1) &&
|
||||
(to_find->k_dir_id != key->k_dir_id))
|
||||
if ((get_key_dirid (to_find) != -1) &&
|
||||
(get_key_dirid (to_find) != get_key_dirid (key)))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -45,27 +45,27 @@ int is_item_reachable (struct item_head * ih)
|
||||
|
||||
void mark_item_unreachable (struct item_head * ih)
|
||||
{
|
||||
clean_ih_flags (ih);
|
||||
mark_ih_unreachable (ih);
|
||||
|
||||
if (is_indirect_ih (ih))
|
||||
set_free_space (ih, 0);
|
||||
set_ih_free_space (ih, 0);
|
||||
}
|
||||
|
||||
|
||||
void mark_item_reachable (struct item_head * ih, struct buffer_head * bh)
|
||||
{
|
||||
mark_ih_ok (ih);
|
||||
mark_ih_reachable (ih);
|
||||
mark_buffer_dirty (bh);
|
||||
}
|
||||
|
||||
|
||||
static void stat_data_in_tree (struct buffer_head *bh,
|
||||
struct item_head * ih)
|
||||
{
|
||||
#if 0
|
||||
__u32 objectid;
|
||||
|
||||
objectid = le32_to_cpu (ih->ih_key.k_objectid);
|
||||
objectid = get_key_objectid (&ih->ih_key);
|
||||
|
||||
if (mark_objectid_really_used (proper_id_map (fs), objectid)) {
|
||||
stat_shared_objectid_found (fs);
|
||||
@@ -84,7 +84,7 @@ static void indirect_in_tree (struct buffer_head * bh,
|
||||
{
|
||||
int i;
|
||||
__u32 * unp;
|
||||
unsigned long unfm_ptr;
|
||||
__u32 unfm_ptr;
|
||||
|
||||
unp = (__u32 *)B_I_PITEM (bh, ih);
|
||||
|
||||
@@ -92,13 +92,12 @@ static void indirect_in_tree (struct buffer_head * bh,
|
||||
unfm_ptr = le32_to_cpu (unp[i]);
|
||||
if (unfm_ptr == 0)
|
||||
continue;
|
||||
|
||||
if (still_bad_unfm_ptr_1 (unfm_ptr))
|
||||
reiserfs_panic ("mark_unformatted_used: (%lu: %k) "
|
||||
"still has bad pointer %lu",
|
||||
bh->b_blocknr, &ih->ih_key, unfm_ptr);
|
||||
|
||||
mark_block_used (unfm_ptr);
|
||||
mark_block_used (unfm_ptr, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,11 +106,11 @@ static void leaf_is_in_tree_now (struct buffer_head * bh)
|
||||
{
|
||||
item_action_t actions[] = {stat_data_in_tree, indirect_in_tree, 0, 0};
|
||||
|
||||
mark_block_used ((bh)->b_blocknr);
|
||||
mark_block_used ((bh)->b_blocknr, 1);
|
||||
|
||||
for_every_item (bh, mark_item_unreachable, actions);
|
||||
|
||||
stats(fs)->inserted_leaves ++;
|
||||
pass_1_stat (fs)->inserted_leaves ++;
|
||||
|
||||
mark_buffer_dirty (bh);
|
||||
}
|
||||
@@ -194,13 +193,13 @@ int balance_condition_2_fails (struct buffer_head * new, struct path * path)
|
||||
call search_by_key, which will read right neighbor as well */
|
||||
INITIALIZE_PATH(path_to_right_neighbor);
|
||||
|
||||
if (usearch_by_key (fs, right_dkey, &path_to_right_neighbor) != ITEM_FOUND)
|
||||
if (reiserfs_search_by_key_4 (fs, right_dkey, &path_to_right_neighbor) != ITEM_FOUND)
|
||||
die ("get_right_neighbor_free_space: invalid right delimiting key");
|
||||
used_space = B_CHILD_SIZE (PATH_PLAST_BUFFER (&path_to_right_neighbor));
|
||||
pathrelse (&path_to_right_neighbor);
|
||||
}
|
||||
else
|
||||
used_space = B_N_CHILD (bh, pos + 1)->dc_size;
|
||||
used_space = get_dc_child_size (B_N_CHILD (bh, pos + 1));
|
||||
|
||||
if (B_FREE_SPACE (new) >= used_space -
|
||||
(are_items_mergeable (B_N_PITEM_HEAD (new, B_NR_ITEMS (new) - 1), (struct item_head *)right_dkey, new->b_size) ? IH_SIZE : 0))
|
||||
@@ -218,32 +217,28 @@ static void get_max_buffer_key (struct buffer_head * bh, struct key * key)
|
||||
copy_key (key, &(ih->ih_key));
|
||||
|
||||
if (is_direntry_key (key)) {
|
||||
/* copy 3-rd and 4-th key components of the last entry */
|
||||
//set_le_key_k_offset (ih_version(ih), key, B_I_DEH (bh, ih)[I_ENTRY_COUNT (ih) - 1].deh_offset);
|
||||
//set_le_key_k_type (ih_version(ih), key, TYPE_DIRENTRY);
|
||||
/* copy deh_offset 3-rd and 4-th key components of the last entry */
|
||||
set_offset (KEY_FORMAT_1, key,
|
||||
le32_to_cpu (B_I_DEH (bh, ih)[ih_entry_count (ih) - 1].deh_offset));
|
||||
get_deh_offset (B_I_DEH (bh, ih) + get_ih_entry_count (ih) - 1));
|
||||
|
||||
} else if (!is_stat_data_key (key))
|
||||
/* get key of the last byte, which is contained in the item */
|
||||
set_offset (key_format (key), key, get_offset (key) + get_bytes_number (ih, bh->b_size) - 1);
|
||||
//set_le_key_k_offset(ih_version(ih), key,
|
||||
// le_key_k_offset(ih_version(ih), key) + get_bytes_number (bh, ih, 0, CHECK_FREE_BYTES) - 1 );
|
||||
}
|
||||
|
||||
|
||||
static int tree_is_empty (void)
|
||||
int tree_is_empty (void)
|
||||
{
|
||||
return (SB_ROOT_BLOCK (fs) == ~0) ? 1 : 0;
|
||||
return (get_sb_root_block (fs->fs_ondisk_sb) == ~0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
static void make_single_leaf_tree (struct buffer_head * bh)
|
||||
void make_single_leaf_tree (struct buffer_head * bh)
|
||||
{
|
||||
/* tree is empty, make tree root */
|
||||
set_root_block (fs->s_rs, bh->b_blocknr);
|
||||
set_tree_height (fs->s_rs, 2);
|
||||
mark_buffer_dirty (fs->s_sbh);
|
||||
set_sb_root_block (fs->fs_ondisk_sb, bh->b_blocknr);
|
||||
set_sb_tree_height (fs->fs_ondisk_sb, 2);
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
leaf_is_in_tree_now (bh);
|
||||
}
|
||||
|
||||
@@ -263,11 +258,10 @@ static void try_to_insert_pointer_to_leaf (struct buffer_head * new_bh)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
first_bh_key = B_N_PKEY (new_bh, 0);
|
||||
|
||||
/* try to find place in the tree for the first key of the coming node */
|
||||
ret_value = usearch_by_key (fs, first_bh_key, &path);
|
||||
ret_value = reiserfs_search_by_key_4 (fs, first_bh_key, &path);
|
||||
if (ret_value == ITEM_FOUND)
|
||||
goto cannot_insert;
|
||||
|
||||
@@ -300,13 +294,13 @@ static void try_to_insert_pointer_to_leaf (struct buffer_head * new_bh)
|
||||
if (balance_condition_2_fails (new_bh, &path))
|
||||
goto cannot_insert;
|
||||
|
||||
|
||||
insert:
|
||||
insert_pointer (new_bh, &path);
|
||||
goto out;
|
||||
|
||||
cannot_insert:
|
||||
/* statistic */
|
||||
stats (fs)->uninsertable_leaves ++;
|
||||
|
||||
mark_block_uninsertable (new_bh->b_blocknr);
|
||||
|
||||
@@ -324,7 +318,7 @@ static void try_to_insert_pointer_to_leaf (struct buffer_head * new_bh)
|
||||
3. what we should do with directory entries hashed by another hash?
|
||||
they are deleted for now
|
||||
*/
|
||||
static void pass1_correct_leaf (reiserfs_filsys_t s,
|
||||
static void pass1_correct_leaf (reiserfs_filsys_t * fs,
|
||||
struct buffer_head * bh)
|
||||
{
|
||||
int i, j;
|
||||
@@ -343,9 +337,9 @@ static void pass1_correct_leaf (reiserfs_filsys_t s,
|
||||
int hash_code;
|
||||
|
||||
deh = B_I_DEH (bh, ih);
|
||||
for (j = 0; j < ih_entry_count (ih); j ++) {
|
||||
for (j = 0; j < get_ih_entry_count (ih); j ++) {
|
||||
name = name_in_entry (deh + j, j);
|
||||
name_len = name_length (ih, deh + j, j);
|
||||
name_len = name_in_entry_length (ih, deh + j, j);
|
||||
|
||||
if ((j == 0 && is_dot (name, name_len)) ||
|
||||
(j == 1 && is_dot_dot (name, name_len))) {
|
||||
@@ -353,14 +347,14 @@ static void pass1_correct_leaf (reiserfs_filsys_t s,
|
||||
}
|
||||
|
||||
hash_code = find_hash_in_use (name, name_len,
|
||||
GET_HASH_VALUE (deh_offset (deh + j)),
|
||||
rs_hash (fs->s_rs));
|
||||
if (hash_code != rs_hash (fs->s_rs)) {
|
||||
GET_HASH_VALUE (get_deh_offset (deh + j)),
|
||||
get_sb_hash_code (fs->fs_ondisk_sb));
|
||||
if (hash_code != get_sb_hash_code (fs->fs_ondisk_sb)) {
|
||||
fsck_log ("pass1: block %lu, %H, entry \"%.*s\" "
|
||||
"hashed with %s whereas proper hash is %s\n",
|
||||
bh->b_blocknr, ih, name_len, name,
|
||||
code2name (hash_code), code2name (rs_hash (fs->s_rs)));
|
||||
if (ih_entry_count (ih) == 1) {
|
||||
code2name (hash_code), code2name (get_sb_hash_code (fs->fs_ondisk_sb)));
|
||||
if (get_ih_entry_count (ih) == 1) {
|
||||
delete_item (fs, bh, i);
|
||||
i --;
|
||||
ih --;
|
||||
@@ -389,7 +383,7 @@ static void pass1_correct_leaf (reiserfs_filsys_t s,
|
||||
continue;
|
||||
|
||||
/* this corruption of indirect item had to be fixed in pass0 */
|
||||
if (not_data_block (s, unfm_ptr) || unfm_ptr >= SB_BLOCK_COUNT (s))
|
||||
if (not_data_block (fs, unfm_ptr) || unfm_ptr >= get_sb_block_count (fs->fs_ondisk_sb))
|
||||
/*!was_block_used (unfm_ptr))*/
|
||||
reiserfs_panic ("pass1_correct_leaf: (%lu: %k), %d-th slot is not fixed",
|
||||
bh->b_blocknr, &ih->ih_key, j);
|
||||
@@ -398,7 +392,7 @@ static void pass1_correct_leaf (reiserfs_filsys_t s,
|
||||
if (is_used_leaf (unfm_ptr)) {
|
||||
dirty ++;
|
||||
*ind_item = 0;
|
||||
stats(fs)->wrong_pointers ++;
|
||||
pass_1_stat (fs)->pointed_leaves ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -410,13 +404,14 @@ static void pass1_correct_leaf (reiserfs_filsys_t s,
|
||||
special bitmap */
|
||||
mark_bad_unfm_in_tree_once (unfm_ptr);
|
||||
else {
|
||||
/* Yes, we have seen this pointer already, zero other pointers to it */
|
||||
/* Yes, we have seen this pointer already, zero other pointers to it. */
|
||||
dirty ++;
|
||||
*ind_item = 0;
|
||||
stats(fs)->wrong_pointers ++;
|
||||
pass_1_stat (fs)->non_unique_pointers ++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else
|
||||
pass_1_stat (fs)->correct_pointers ++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,16 +432,16 @@ void save_item (struct si ** head, struct buffer_head * bh, struct item_head * i
|
||||
}
|
||||
|
||||
if (is_indirect_ih (ih)) {
|
||||
fsck_progress ("save_item: %H (should not happen)\n", ih);
|
||||
fsck_progress ("save_item (block %lu: %H (should not happen)\n", ih);
|
||||
}
|
||||
|
||||
stats(fs)->saved_on_pass1 ++;
|
||||
pass_1_stat (fs)->saved_items ++;
|
||||
|
||||
si = getmem (sizeof (*si));
|
||||
si->si_dnm_data = getmem (ih_item_len(ih));
|
||||
si->si_dnm_data = getmem (get_ih_item_len(ih));
|
||||
/*si->si_blocknr = blocknr;*/
|
||||
memcpy (&(si->si_ih), ih, IH_SIZE);
|
||||
memcpy (si->si_dnm_data, item, ih_item_len(ih));
|
||||
memcpy (si->si_dnm_data, item, get_ih_item_len(ih));
|
||||
|
||||
// changed by XB
|
||||
si->last_known = NULL;
|
||||
@@ -483,6 +478,17 @@ void save_item (struct si ** head, struct buffer_head * bh, struct item_head * i
|
||||
}
|
||||
|
||||
|
||||
struct si * remove_saved_item (struct si * si)
|
||||
{
|
||||
struct si * tmp = si->si_next;
|
||||
|
||||
freemem (si->si_dnm_data);
|
||||
freemem (si);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
static void save_items (struct si ** head, struct buffer_head * bh)
|
||||
{
|
||||
int i;
|
||||
@@ -494,17 +500,6 @@ static void save_items (struct si ** head, struct buffer_head * bh)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct si * remove_saved_item (struct si * si)
|
||||
{
|
||||
struct si * tmp = si->si_next;
|
||||
|
||||
freemem (si->si_dnm_data);
|
||||
freemem (si);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
/* insert_item_separately */
|
||||
static void put_saved_items_into_tree_1 (struct si * si)
|
||||
{
|
||||
@@ -514,38 +509,222 @@ static void put_saved_items_into_tree_1 (struct si * si)
|
||||
si = remove_saved_item (si);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* reads the device by set of 8 blocks, takes leaves and tries to
|
||||
insert them into tree */
|
||||
void pass_1_pass_2_build_the_tree (void)
|
||||
/* fsck starts creating of this bitmap on pass 1. It will then become
|
||||
on-disk bitmap */
|
||||
static void init_new_bitmap (reiserfs_filsys_t * fs)
|
||||
{
|
||||
int i;
|
||||
unsigned long block;
|
||||
unsigned long reserved;
|
||||
|
||||
|
||||
fsck_new_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
|
||||
/* mark_block_used skips 0, set the bit explicitly */
|
||||
reiserfs_bitmap_set_bit (fsck_new_bitmap (fs), 0);
|
||||
|
||||
/* mark other skipped blocks and super block used */
|
||||
for (i = 1; i <= fs->fs_super_bh->b_blocknr; i ++)
|
||||
mark_block_used (i, 1);
|
||||
|
||||
/* mark bitmap blocks as used */
|
||||
block = fs->fs_super_bh->b_blocknr + 1;
|
||||
for (i = 0; i < get_sb_bmap_nr (fs->fs_ondisk_sb); i ++) {
|
||||
mark_block_used (block, 1);
|
||||
if (spread_bitmaps (fs))
|
||||
block = (block / (fs->fs_blocksize * 8) + 1) * (fs->fs_blocksize * 8);
|
||||
else
|
||||
block ++;
|
||||
}
|
||||
|
||||
reserved = get_size_of_journal_or_reserved_area (fs->fs_ondisk_sb);
|
||||
/* where does journal area (or reserved journal area) start from */
|
||||
|
||||
if (!is_new_sb_location (fs->fs_super_bh->b_blocknr, fs->fs_blocksize) &&
|
||||
!is_old_sb_location (fs->fs_super_bh->b_blocknr, fs->fs_blocksize))
|
||||
die ("init_new_bitmap: wrong super block");
|
||||
|
||||
block = get_journal_start_must (fs);
|
||||
|
||||
for (i = block; i < reserved + block; i ++)
|
||||
mark_block_used (i, 1);
|
||||
|
||||
|
||||
if (fs->fs_badblocks_bm)
|
||||
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
|
||||
if (reiserfs_bitmap_test_bit (fs->fs_badblocks_bm, i)) {
|
||||
if (reiserfs_bitmap_test_bit (fsck_new_bitmap (fs), i))
|
||||
reiserfs_panic ("%s: bad block pointer to not data area, cannot happen\n",
|
||||
__FUNCTION__);
|
||||
reiserfs_bitmap_set_bit (fsck_new_bitmap (fs), i);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* mark journal area as used if journal is standard or it is non standard
|
||||
and initialy has been created on a main device */
|
||||
reserved = 0;
|
||||
if (!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb))
|
||||
reserved = get_jp_journal_size (sb_jp (fs->fs_ondisk_sb));
|
||||
if (get_sb_reserved_for_journal (fs->fs_ondisk_sb))
|
||||
reserved = get_sb_reserved_for_journal (fs->fs_ondisk_sb);
|
||||
if (reserved) {
|
||||
for (i = 0; i <= reserved; i ++)
|
||||
mark_block_used (i + get_jp_journal_1st_block (sb_jp
|
||||
(fs->fs_ondisk_sb)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* this makes a map of blocks which can be allocated when fsck will
|
||||
continue */
|
||||
static void find_allocable_blocks (reiserfs_filsys_t * fs)
|
||||
{
|
||||
int i;
|
||||
|
||||
fsck_progress ("Looking for allocable blocks .. ");
|
||||
|
||||
fsck_allocable_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_fill (fsck_allocable_bitmap (fs));
|
||||
|
||||
|
||||
/* find how many leaves are not pointed by any indirect items */
|
||||
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
|
||||
if (not_data_block (fs, i))
|
||||
/* journal (or reserved for it area), bitmaps, super block and
|
||||
blocks before it */
|
||||
continue;
|
||||
|
||||
if (is_good_unformatted (i) && is_bad_unformatted (i))
|
||||
die ("find_allocable_blocks: bad and good unformatted");
|
||||
|
||||
if (is_good_unformatted (i) || is_bad_unformatted (i)) {
|
||||
/* blocks which were pointed once or more thn onec from indirect
|
||||
items - they will not be allocated */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* make allocable not leaves, not bad blocks */
|
||||
if (!is_used_leaf (i) &&
|
||||
(!fs->fs_badblocks_bm || !reiserfs_bitmap_test_bit (fs->fs_badblocks_bm, i))) {
|
||||
/* this is not leaf and it is not pointed by found indirect items,
|
||||
so it does not contains anything valuable */
|
||||
make_allocable (i);
|
||||
pass_1_stat (fs)->allocable_blocks ++;
|
||||
}
|
||||
}
|
||||
fsck_progress ("ok\n");
|
||||
|
||||
fs->block_allocator = reiserfsck_reiserfs_new_blocknrs;
|
||||
fs->block_deallocator = reiserfsck_reiserfs_free_block;
|
||||
}
|
||||
|
||||
|
||||
static void before_pass_1 (reiserfs_filsys_t * fs)
|
||||
{
|
||||
/* this will become an on-disk bitmap */
|
||||
init_new_bitmap (fs);
|
||||
|
||||
/* bitmap of leaves which could not be inserted on pass 1. FIXME:
|
||||
no need to have 1 bit per block */
|
||||
fsck_uninsertables (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_fill (fsck_uninsertables (fs));
|
||||
|
||||
/* find blocks which can be allocated */
|
||||
find_allocable_blocks (fs);
|
||||
|
||||
/* bitmap of bad unformatted nodes which are in the tree already */
|
||||
bad_unfm_in_tree_once_bitmap = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
|
||||
/* pass 1 does not deal with objectid */
|
||||
}
|
||||
|
||||
|
||||
static void save_pass_1_result (reiserfs_filsys_t * fs)
|
||||
{
|
||||
FILE * file;
|
||||
int retval;
|
||||
|
||||
file = open_file("temp_fsck_file.deleteme", "w+");
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
/* to be able to get a new bitmap on pass2 we should flush it on disk
|
||||
new_bitmap should not be flushed on disk if run w/out -d option, as
|
||||
if fsck fails on pass1 we get wrong bitmap on the next fsck start */
|
||||
reiserfs_flush_to_ondisk_bitmap (fsck_new_bitmap (fs), fs);
|
||||
|
||||
/* to be able to restart with pass 2 we need bitmap of
|
||||
uninsertable blocks and bitmap of alocable blocks */
|
||||
reiserfs_begin_stage_info_save(file, PASS_1_DONE);
|
||||
reiserfs_bitmap_save (file, fsck_uninsertables (fs));
|
||||
reiserfs_bitmap_save (file, fsck_allocable_bitmap(fs));
|
||||
reiserfs_end_stage_info_save (file);
|
||||
close_file (file);
|
||||
retval = unlink (state_dump_file (fs));
|
||||
retval = rename ("temp_fsck_file.deleteme", state_dump_file (fs));
|
||||
if (retval != 0)
|
||||
fsck_progress ("pass 1: could not rename temp file temp_fsck_file.deleteme to %s",
|
||||
state_dump_file (fs));
|
||||
}
|
||||
|
||||
|
||||
void load_pass_1_result (FILE * fp, reiserfs_filsys_t * fs)
|
||||
{
|
||||
fsck_new_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_copy (fsck_new_bitmap (fs), fs->fs_bitmap2);
|
||||
|
||||
fsck_uninsertables (fs) = reiserfs_bitmap_load (fp);
|
||||
fsck_allocable_bitmap (fs) = reiserfs_bitmap_load (fp);
|
||||
|
||||
fs->block_allocator = reiserfsck_reiserfs_new_blocknrs;
|
||||
fs->block_deallocator = reiserfsck_reiserfs_free_block;
|
||||
|
||||
if (!fsck_new_bitmap (fs) || !fsck_allocable_bitmap (fs) ||
|
||||
!fsck_allocable_bitmap (fs))
|
||||
fsck_exit ("State dump file seems corrupted. Run without -d");
|
||||
|
||||
|
||||
/* we need objectid map on pass 2 to be able to relocate files */
|
||||
proper_id_map (fs) = init_id_map ();
|
||||
fetch_objectid_map (proper_id_map (fs), fs);
|
||||
|
||||
fsck_progress ("Pass 1 result loaded. %d blocks used, %d allocable, "
|
||||
"still to be inserted %d\n",
|
||||
reiserfs_bitmap_ones (fsck_new_bitmap (fs)),
|
||||
reiserfs_bitmap_zeros (fsck_allocable_bitmap (fs)),
|
||||
reiserfs_bitmap_zeros (fsck_uninsertables (fs)));
|
||||
}
|
||||
|
||||
|
||||
extern reiserfs_bitmap_t * leaves_bitmap;
|
||||
|
||||
/* reads blocks marked in leaves_bitmap and tries to insert them into
|
||||
tree */
|
||||
static void do_pass_1 (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
int i;
|
||||
int what_node;
|
||||
unsigned long done = 0, total;
|
||||
struct si * saved_items = 0;
|
||||
|
||||
if (fsck_log_file (fs) != stderr)
|
||||
fsck_log ("####### Pass 1 #######\n");
|
||||
|
||||
bad_unfm_in_tree_once_bitmap = reiserfs_create_bitmap (SB_BLOCK_COUNT (fs));
|
||||
|
||||
|
||||
/* on pass0 we have found that amount of leaves */
|
||||
total = how_many_leaves_were_there ();
|
||||
|
||||
fsck_progress ("\nPass1:\n");
|
||||
total = reiserfs_bitmap_ones (leaves_bitmap);
|
||||
|
||||
/* read all leaves found on the pass 0 */
|
||||
for (i = 0; i < SB_BLOCK_COUNT (fs); i ++) {
|
||||
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
|
||||
if (!is_used_leaf (i))
|
||||
continue;
|
||||
|
||||
print_how_far (&done, total, 1, fsck_quiet (fs));
|
||||
print_how_far (fsck_progress_file (fs), &done, total, 1, fsck_quiet (fs));
|
||||
|
||||
/* at least one of nr_to_read blocks is to be checked */
|
||||
bh = bread (fs->s_dev, i, fs->s_blocksize);
|
||||
bh = bread (fs->fs_dev, i, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
/* we were reading one block at time, and failed, so mark
|
||||
block bad */
|
||||
@@ -553,7 +732,7 @@ void pass_1_pass_2_build_the_tree (void)
|
||||
continue;
|
||||
}
|
||||
|
||||
what_node = who_is_this (bh->b_data, fs->s_blocksize);
|
||||
what_node = who_is_this (bh->b_data, bh->b_size);
|
||||
if ( what_node != THE_LEAF ) {
|
||||
fsck_progress ("build_the_tree: nothing but leaves are expected. "
|
||||
"Block %lu - %s\n", i,
|
||||
@@ -562,18 +741,19 @@ void pass_1_pass_2_build_the_tree (void)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_block_used (i))
|
||||
if (is_block_used (i) && !(block_of_journal (fs, i) &&
|
||||
fsck_data(fs)->rebuild.use_journal_area))
|
||||
/* block is in new tree already */
|
||||
die ("build_the_tree: leaf (%lu) is in tree already\n", i);
|
||||
die ("build_the_tree: leaf (%u) is in tree already\n", i);
|
||||
|
||||
/* fprintf (block_list, "leaf %d\n", i + j);*/
|
||||
stats(fs)->analyzed ++;
|
||||
pass_1_stat (fs)->leaves ++;
|
||||
|
||||
/* the leaf may still contain indirect items with wrong
|
||||
slots. Fix that */
|
||||
pass1_correct_leaf (fs, bh);
|
||||
|
||||
if (node_item_number (bh) == 0) {
|
||||
if (get_blkh_nr_items (B_BLK_HEAD (bh)) == 0) {
|
||||
/* all items were deleted on pass 0 or pass 1 */
|
||||
mark_buffer_clean (bh);
|
||||
brelse (bh);
|
||||
@@ -586,8 +766,34 @@ void pass_1_pass_2_build_the_tree (void)
|
||||
|
||||
/* Save good items only to put them into tree at the
|
||||
end of this pass */
|
||||
save_items (&saved_items, bh);
|
||||
//save_items (&saved_items, bh);
|
||||
mark_block_uninsertable (bh->b_blocknr);
|
||||
brelse (bh);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (block_of_journal (fs, i) && fsck_data(fs)->rebuild.use_journal_area) {
|
||||
/* FIXME: temporary thing */
|
||||
if (tree_is_empty ()) {
|
||||
/* we insert inot tree only first leaf of journal */
|
||||
unsigned long block;
|
||||
struct buffer_head * new_bh;
|
||||
|
||||
block = alloc_block ();
|
||||
if (!block)
|
||||
die ("could not allocate block");
|
||||
new_bh = getblk (bh->b_dev, block, bh->b_size);
|
||||
memcpy (new_bh->b_data, bh->b_data, bh->b_size);
|
||||
mark_buffer_uptodate (new_bh, 1);
|
||||
mark_buffer_dirty (new_bh);
|
||||
make_single_leaf_tree (new_bh);
|
||||
brelse (new_bh);
|
||||
brelse (bh);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* other blocks of journal will be inserted in pass 2 */
|
||||
mark_block_uninsertable (bh->b_blocknr);
|
||||
brelse (bh);
|
||||
continue;
|
||||
}
|
||||
@@ -596,131 +802,76 @@ void pass_1_pass_2_build_the_tree (void)
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
/* read all leaves found on the pass 0 */
|
||||
for (i = 0; i < SB_BLOCK_COUNT (fs); i += nr_to_read) {
|
||||
to_scan = how_many_to_scan (fs, i, nr_to_read);
|
||||
if (to_scan) {
|
||||
print_how_far (&done, total, to_scan, fsck_quiet (fs));
|
||||
|
||||
/* at least one of nr_to_read blocks is to be checked */
|
||||
bbh = bread (fs->s_dev, i / nr_to_read, fs->s_blocksize * nr_to_read);
|
||||
if (bbh) {
|
||||
for (j = 0; j < nr_to_read; j ++) {
|
||||
if (!is_used_leaf (i + j))
|
||||
continue;
|
||||
|
||||
data = bbh->b_data + j * fs->s_blocksize;
|
||||
|
||||
what_node = who_is_this (data, fs->s_blocksize);
|
||||
if ( what_node != THE_LEAF ) {
|
||||
fsck_progress ("build_the_tree: nothing but leaves are expected. "
|
||||
"Block %lu - %s\n", i + j,
|
||||
(what_node == THE_INTERNAL) ? "internal" : "??");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_block_used (i + j))
|
||||
/* block is in new tree already */
|
||||
die ("build_the_tree: leaf (%lu) is in tree already\n",
|
||||
i + j);
|
||||
|
||||
/* fprintf (block_list, "leaf %d\n", i + j);*/
|
||||
|
||||
bh = make_buffer (fs->s_dev, i + j, fs->s_blocksize, data);
|
||||
stats(fs)->analyzed ++;
|
||||
|
||||
/* the leaf may still contain indirect items with wrong
|
||||
slots. Fix that */
|
||||
pass1_correct_leaf (fs, bh);
|
||||
|
||||
if (node_item_number (bh) == 0) {
|
||||
/* all items were deleted on pass 0 or pass 1 */
|
||||
mark_buffer_clean (bh);
|
||||
brelse (bh);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_leaf_bad (bh)) {
|
||||
/* FIXME: will die */
|
||||
fsck_log ("pass1: (is_leaf_bad) bad leaf (%lu)\n", bh->b_blocknr);
|
||||
|
||||
/* Save good items only to put them into tree at the
|
||||
end of this pass */
|
||||
save_items (&saved_items, bh);
|
||||
|
||||
brelse (bh);
|
||||
continue;
|
||||
}
|
||||
|
||||
try_to_insert_pointer_to_leaf (bh);
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
bforget (bbh);
|
||||
} else {
|
||||
done -= to_scan;
|
||||
|
||||
/* bread failed */
|
||||
if (nr_to_read != 1) {
|
||||
/* we tryied to read bunch of blocks. Try to read them by one */
|
||||
nr_to_read = 1;
|
||||
i --;
|
||||
continue;
|
||||
} else {
|
||||
/* we were reading one block at time, and failed, so mark
|
||||
block bad */
|
||||
fsck_progress ("pass0: block %lu is bad, marked used\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nr_to_read == 1 && ((i + 1) % NR_TO_READ) == 0) {
|
||||
/* we have read NR_TO_READ blocks one at time, switch back to
|
||||
reading NR_TO_READ blocks at time */
|
||||
i -= (NR_TO_READ - 1);
|
||||
nr_to_read = NR_TO_READ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
fsck_progress ("\n");
|
||||
|
||||
/* Pass 1a (this should die) */
|
||||
}
|
||||
|
||||
/* put saved items into tree. These items were in leaves, those could not
|
||||
be inserted into tree because some indirect items point to those
|
||||
leaves. Rather than lookup for corresponding unfm pointers in the tree,
|
||||
we save items of those leaves and put them into tree separately */
|
||||
if (how_many_items_were_saved ()) {
|
||||
fsck_progress ("There were %lu saved items\nPass 1a - ",
|
||||
how_many_items_were_saved ());
|
||||
fflush (stdout);
|
||||
put_saved_items_into_tree_1 (saved_items);
|
||||
}
|
||||
|
||||
static void after_pass_1 (reiserfs_filsys_t * fs)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
/* update fsck_state */
|
||||
|
||||
/* we should not flush bitmaps on disk after pass1, because
|
||||
new_bitmap contains only those blocks which are good leaves or
|
||||
just allocated internal blocks. */
|
||||
|
||||
set_sb_fs_state (fs->fs_ondisk_sb, PASS_1_DONE);
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
|
||||
/* write all dirty blocks */
|
||||
fsck_progress ("Flushing..");
|
||||
fs->fs_dirt = 1;
|
||||
reiserfs_flush (fs);
|
||||
fsck_progress ("done\n");
|
||||
|
||||
stage_report (1, fs);
|
||||
/* end of pass 1 */
|
||||
|
||||
|
||||
if (SB_ROOT_BLOCK(fs) == -1)
|
||||
die ("\n\nNo reiserfs metadata found");
|
||||
|
||||
/* pass 2 */
|
||||
pass_2_take_bad_blocks_put_into_tree ();
|
||||
|
||||
flush_buffers ();
|
||||
|
||||
stage_report (2, fs);
|
||||
|
||||
fsck_progress ("Tree is built. Checking it - "); fflush (stdout);
|
||||
reiserfsck_check_pass1 ();
|
||||
fsck_progress ("done\n"); fflush (stdout);
|
||||
|
||||
/* we do not need this anymore */
|
||||
delete_aux_bitmaps ();
|
||||
reiserfs_delete_bitmap (bad_unfm_in_tree_once_bitmap);
|
||||
|
||||
if (!fsck_run_one_step (fs)) {
|
||||
if (fsck_user_confirmed (fs, "Continue? (Yes):", "Yes\n", 1))
|
||||
/* reiserfsck continues */
|
||||
return;
|
||||
} else
|
||||
save_pass_1_result (fs);
|
||||
|
||||
if (proper_id_map (fs)) {
|
||||
/* when we run pass 1 only - we do not have proper_id_map */
|
||||
free_id_map (proper_id_map (fs));
|
||||
proper_id_map (fs) = 0;
|
||||
}
|
||||
|
||||
time (&t);
|
||||
fsck_progress ("###########\n"
|
||||
"reiserfsck finished pass 1 at %s"
|
||||
"###########\n", ctime (&t));
|
||||
fs->fs_dirt = 1;
|
||||
reiserfs_close (fs);
|
||||
exit (4);
|
||||
}
|
||||
|
||||
|
||||
void pass_1 (reiserfs_filsys_t * fs)
|
||||
{
|
||||
fsck_progress ("\nPass 1 (will try to insert %lu leaves):\n",
|
||||
reiserfs_bitmap_ones (fsck_source_bitmap (fs)));
|
||||
if (fsck_log_file (fs) != stderr)
|
||||
fsck_log ("####### Pass 1 #######\n");
|
||||
|
||||
|
||||
before_pass_1 (fs);
|
||||
|
||||
/* try to insert leaves found during pass 0 */
|
||||
do_pass_1 (fs);
|
||||
|
||||
after_pass_1 (fs);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
/* pass the S+ tree of filesystem */
|
||||
@@ -730,152 +881,3 @@ void recover_internal_tree (struct super_block * s)
|
||||
build_the_tree();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void rebuild_sb (reiserfs_filsys_t fs)
|
||||
{
|
||||
int version;
|
||||
struct buffer_head * bh;
|
||||
struct reiserfs_super_block * rs;
|
||||
__u32 blocks;
|
||||
|
||||
|
||||
if (no_reiserfs_found (fs)) {
|
||||
char * answer = 0;
|
||||
size_t n = 0;
|
||||
printf("\nwhat is version of ReiserFS you use[1-4]\n"
|
||||
"\t(1) 3.6.x\n"
|
||||
"\t(2) >=3.5.9\n"
|
||||
"\t(3) < 3.5.9 converted to new format\n"
|
||||
"\t(4) < 3.5.9\n"
|
||||
"\t(X) exit\n");
|
||||
getline (&answer, &n, stdin);
|
||||
version = atoi (answer);
|
||||
if (version < 1 || version > 4)
|
||||
die ("rebuild_sb: wrong version");
|
||||
|
||||
fs->s_blocksize = 4096;
|
||||
|
||||
switch(version){
|
||||
case 1:
|
||||
case 2:
|
||||
bh = getblk (fs->s_dev, (REISERFS_DISK_OFFSET_IN_BYTES / fs->s_blocksize),
|
||||
fs->s_blocksize);
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
bh = getblk (fs->s_dev, (2), fs->s_blocksize);
|
||||
break;
|
||||
default:
|
||||
exit(0);
|
||||
}
|
||||
if (!bh)
|
||||
die ("rebuild_sb: can't bread");
|
||||
rs = (struct reiserfs_super_block *)bh->b_data;
|
||||
fs->s_rs = rs;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* reiserfs super block is found */
|
||||
version = check_sb(fs);
|
||||
if (!user_confirmed ("\nDo you want to remake your super block\n"
|
||||
"(say no if you use resizer)[Yes/no]: ", "Yes\n"))
|
||||
return;
|
||||
rs = fs->s_rs;
|
||||
bh = fs->s_sbh;
|
||||
}
|
||||
|
||||
// set block number on the device and number of bitmap blocks needed to
|
||||
// address all blocks
|
||||
blocks = (count_blocks ("", fs->s_blocksize, fs->s_dev) / 8) * 8;
|
||||
set_block_count (rs, blocks);
|
||||
//rs->s_block_count = cpu_to_le32(blocks);
|
||||
|
||||
set_bmap_nr (rs, (blocks + (fs->s_blocksize * 8 - 1)) / (fs->s_blocksize * 8));
|
||||
set_journal_size(rs, JOURNAL_BLOCK_COUNT);
|
||||
|
||||
//rs->s_bmap_nr = cpu_to_le16( blocks / (g_sb.s_blocksize * 8) +
|
||||
// ((blocks % (g_sb.s_blocksize * 8)) ? 1 : 0) );
|
||||
|
||||
switch (version){
|
||||
case 1:
|
||||
// super block v2 at 64k offset
|
||||
set_blocksize (rs, fs->s_blocksize);
|
||||
strncpy (rs->s_v1.s_magic, REISER2FS_SUPER_MAGIC_STRING,
|
||||
strlen(REISER2FS_SUPER_MAGIC_STRING));
|
||||
set_journal_start (rs, get_journal_start_must (fs->s_blocksize));
|
||||
set_version (rs, REISERFS_VERSION_2);
|
||||
set_objectid_map_max_size (rs, (fs->s_blocksize - SB_SIZE) / sizeof(__u32) / 2 * 2);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// super block v1 at 64k offset
|
||||
set_blocksize (rs, fs->s_blocksize);
|
||||
strncpy (rs->s_v1.s_magic, REISERFS_SUPER_MAGIC_STRING,
|
||||
strlen(REISERFS_SUPER_MAGIC_STRING));
|
||||
set_journal_start (rs, get_journal_start_must (fs->s_blocksize));
|
||||
set_version (rs, REISERFS_VERSION_1);
|
||||
set_objectid_map_max_size (rs, (fs->s_blocksize - SB_SIZE_V1) / sizeof(__u32) / 2 * 2);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// super block v2 at 8k offset
|
||||
set_blocksize (rs, fs->s_blocksize);
|
||||
strncpy (rs->s_v1.s_magic, REISER2FS_SUPER_MAGIC_STRING,
|
||||
strlen(REISER2FS_SUPER_MAGIC_STRING));
|
||||
set_journal_start (rs, get_journal_old_start_must (rs));
|
||||
set_version (rs, REISERFS_VERSION_2);
|
||||
set_objectid_map_max_size (rs, (fs->s_blocksize - SB_SIZE) / sizeof(__u32) / 2 * 2);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
// super block v1 at 8k offset
|
||||
set_blocksize (rs, fs->s_blocksize);
|
||||
strncpy (rs->s_v1.s_magic, REISERFS_SUPER_MAGIC_STRING,
|
||||
strlen(REISERFS_SUPER_MAGIC_STRING));
|
||||
set_journal_start (rs, get_journal_old_start_must (rs));
|
||||
set_version (rs, REISERFS_VERSION_1);
|
||||
set_objectid_map_max_size (rs, (fs->s_blocksize - SB_SIZE_V1) / sizeof(__u32) / 2 * 2);
|
||||
break;
|
||||
}
|
||||
|
||||
print_block (stderr, fs, bh);
|
||||
if (user_confirmed ("Is this ok ? [N/Yes]: ", "Yes\n")) {
|
||||
mark_buffer_uptodate (bh, 1);
|
||||
mark_buffer_dirty (bh);
|
||||
bwrite (bh);
|
||||
fsck_progress ("\nDo not forget to run reiserfsck --rebuild-tree\n\n");
|
||||
} else
|
||||
fsck_progress ("Super block was not written\n");
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
/*
|
||||
check_sb and rebuild-sb don't touch these fields:
|
||||
__u32 s_journal_dev;
|
||||
__u32 s_journal_trans_max ;
|
||||
__u32 s_journal_block_count ;
|
||||
__u32 s_journal_max_batch ;
|
||||
__u32 s_journal_max_commit_age ;
|
||||
__u32 s_journal_max_trans_age ;
|
||||
|
||||
others are checked and set in either rebuild_sb or rebuild-tree
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+267
-74
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-2001 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
|
||||
#include "fsck.h"
|
||||
@@ -44,21 +44,21 @@ __u32 objectid_for_relocation (struct key * key)
|
||||
cur = relocated_list;
|
||||
|
||||
while (cur) {
|
||||
if (cur->old_dir_id == key->k_dir_id &&
|
||||
cur->old_objectid == key->k_objectid)
|
||||
if (cur->old_dir_id == get_key_dirid (key) &&
|
||||
cur->old_objectid == get_key_objectid (key))
|
||||
/* object is relocated already */
|
||||
return cur->new_objectid;
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
cur = getmem (sizeof (struct relocated));
|
||||
cur->old_dir_id = key->k_dir_id;
|
||||
cur->old_objectid = key->k_objectid;
|
||||
cur->old_dir_id = get_key_dirid (key);
|
||||
cur->old_objectid = get_key_objectid (key);
|
||||
cur->new_objectid = get_unused_objectid (fs);
|
||||
cur->next = relocated_list;
|
||||
relocated_list = cur;
|
||||
fsck_log ("relocation: (%K) is relocated to (%lu, %lu)\n",
|
||||
key, key->k_dir_id, cur->new_objectid);
|
||||
key, get_key_dirid (key), cur->new_objectid);
|
||||
return cur->new_objectid;
|
||||
}
|
||||
|
||||
@@ -71,10 +71,10 @@ static void save_item_2 (struct si ** head, struct item_head * ih,
|
||||
struct si * si, * cur;
|
||||
|
||||
si = getmem (sizeof (*si));
|
||||
si->si_dnm_data = getmem (ih_item_len(ih));
|
||||
si->si_dnm_data = getmem (get_ih_item_len(ih));
|
||||
/*si->si_blocknr = blocknr;*/
|
||||
memcpy (&(si->si_ih), ih, IH_SIZE);
|
||||
memcpy (si->si_dnm_data, item, ih_item_len(ih));
|
||||
memcpy (si->si_dnm_data, item, get_ih_item_len(ih));
|
||||
|
||||
if (*head == 0)
|
||||
*head = si;
|
||||
@@ -102,7 +102,7 @@ struct si * save_and_delete_file_item (struct si * si, struct path * path)
|
||||
|
||||
|
||||
/* check whether there are any directory items with this key */
|
||||
static int should_relocate (struct item_head * ih)
|
||||
int should_relocate (struct item_head * ih)
|
||||
{
|
||||
struct key key;
|
||||
struct key * rkey;
|
||||
@@ -115,7 +115,8 @@ static int should_relocate (struct item_head * ih)
|
||||
set_type_and_offset (KEY_FORMAT_1, &key, SD_OFFSET, TYPE_STAT_DATA);
|
||||
|
||||
while (1) {
|
||||
usearch_by_key (fs, &key, &path);
|
||||
reiserfs_search_by_key_4 (fs, &key, &path);
|
||||
|
||||
if (get_item_pos (&path) == B_NR_ITEMS (get_bh (&path))) {
|
||||
rkey = uget_rkey (&path);
|
||||
if (rkey && !not_of_one_file (&key, rkey)) {
|
||||
@@ -129,6 +130,9 @@ static int should_relocate (struct item_head * ih)
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_stat_data_ih (get_ih(&path)))
|
||||
fix_obviously_wrong_sd_mode (&path);
|
||||
|
||||
path_ih = get_ih (&path);
|
||||
if (not_of_one_file (&key, &(path_ih->ih_key))) {
|
||||
/* there are no more item with this key */
|
||||
@@ -171,7 +175,8 @@ void relocate_file (struct item_head * ih, int change_ih)
|
||||
|
||||
si = 0;
|
||||
while (1) {
|
||||
usearch_by_key (fs, &key, &path);
|
||||
reiserfs_search_by_key_4 (fs, &key, &path);
|
||||
|
||||
if (get_item_pos (&path) == B_NR_ITEMS (get_bh (&path))) {
|
||||
rkey = uget_rkey (&path);
|
||||
if (rkey && !not_of_one_file (&key, rkey)) {
|
||||
@@ -185,6 +190,9 @@ void relocate_file (struct item_head * ih, int change_ih)
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_stat_data_ih (get_ih(&path)))
|
||||
fix_obviously_wrong_sd_mode (&path);
|
||||
|
||||
path_ih = get_ih (&path);
|
||||
if (not_of_one_file (&key, &(path_ih->ih_key))) {
|
||||
/* there are no more item with this key */
|
||||
@@ -214,7 +222,7 @@ void relocate_file (struct item_head * ih, int change_ih)
|
||||
was relocated already */
|
||||
new_objectid = objectid_for_relocation (&ih->ih_key);
|
||||
if (change_ih)
|
||||
ih->ih_key.k_objectid = new_objectid;
|
||||
set_key_objectid (&ih->ih_key, new_objectid);
|
||||
|
||||
moved_items = 0;
|
||||
|
||||
@@ -222,7 +230,7 @@ void relocate_file (struct item_head * ih, int change_ih)
|
||||
while (si) {
|
||||
/*fsck_log ("relocate_file: move %H to ", &si->si_ih);*/
|
||||
old = si->si_ih.ih_key;
|
||||
si->si_ih.ih_key.k_objectid = new_objectid;
|
||||
set_key_objectid (&(si->si_ih.ih_key), new_objectid);
|
||||
new = si->si_ih.ih_key;
|
||||
/*fsck_log ("%H\n", &si->si_ih);*/
|
||||
insert_item_separately (&(si->si_ih), si->si_dnm_data, 1/*was in tree*/);
|
||||
@@ -242,9 +250,32 @@ void relocate_file (struct item_head * ih, int change_ih)
|
||||
#define st_mtime_v1(sd) le32_to_cpu(((struct stat_data_v1 *)(sd))->sd_mtime)
|
||||
#define st_mtime_v2(sd) le32_to_cpu(((struct stat_data *)(sd))->sd_mtime)
|
||||
|
||||
|
||||
/* either both sd-s are new of both are old */
|
||||
static void overwrite_stat_data (struct item_head * new_ih,
|
||||
void * new_item, struct path * path)
|
||||
{
|
||||
__u16 new_mode, old_mode;
|
||||
|
||||
get_sd_mode (new_ih, new_item, &new_mode);
|
||||
get_sd_mode (get_ih (path), get_item (path), &old_mode);
|
||||
|
||||
|
||||
if (S_ISREG (new_mode) && !S_ISREG (old_mode)) {
|
||||
/* in tree we have not regular file - overwrite its stat data
|
||||
with stat data of regular file */
|
||||
memcpy (get_item (path), new_item, get_ih_item_len (get_ih (path)));
|
||||
mark_buffer_dirty (get_bh (path));
|
||||
return;
|
||||
}
|
||||
|
||||
if (S_ISREG (old_mode) && !S_ISREG (new_mode)) {
|
||||
/* new stat data is not a stat data of regular file, keep
|
||||
regular file stat data in tree */
|
||||
return;
|
||||
}
|
||||
|
||||
/* if coming stat data has newer mtime - use that */
|
||||
if (stat_data_v1 (new_ih)) {
|
||||
if (st_mtime_v1 (new_item) > st_mtime_v1 (get_item (path))) {
|
||||
memcpy (get_item (path), new_item, SD_V1_SIZE);
|
||||
@@ -286,9 +317,9 @@ static void put_sd_into_tree (struct item_head * new_ih, char * new_item)
|
||||
items of a directory, and that if we are inserting stat data is
|
||||
of not a directory - it either has new key already or there are
|
||||
no items with this key which are items of a directory */
|
||||
if (usearch_by_key (fs, &(new_ih->ih_key), &path) == ITEM_FOUND) {
|
||||
if (reiserfs_search_by_key_4 (fs, &(new_ih->ih_key), &path) == ITEM_FOUND) {
|
||||
/* this stat data is found */
|
||||
if (ih_key_format (get_ih(&path)) != ih_key_format (new_ih)) {
|
||||
if (get_ih_key_format (get_ih(&path)) != get_ih_key_format (new_ih)) {
|
||||
/* in tree stat data and a new one are of different
|
||||
formats */
|
||||
fsck_log ("put_sd_into_tree: inserting stat data %K (%M)..",
|
||||
@@ -298,13 +329,14 @@ static void put_sd_into_tree (struct item_head * new_ih, char * new_item)
|
||||
is of V2 */
|
||||
fsck_log ("found newer in the tree (%M), skip inserting\n",
|
||||
st_mode (get_item (&path)));
|
||||
pathrelse (&path);
|
||||
} else {
|
||||
/* the stat data in the tree is sd_v1 */
|
||||
fsck_log ("older sd (%M) is replaced with it\n",
|
||||
st_mode (get_item (&path)));
|
||||
reiserfsck_delete_item (&path, 0/*not temporary*/);
|
||||
|
||||
usearch_by_key (fs, &new_ih->ih_key, &path);
|
||||
reiserfs_search_by_key_4 (fs, &new_ih->ih_key, &path);
|
||||
reiserfsck_insert_item (&path, new_ih, new_item);
|
||||
}
|
||||
} else {
|
||||
@@ -330,28 +362,27 @@ static void put_directory_item_into_tree (struct item_head * comingih, char * it
|
||||
char * name;
|
||||
int namelen;
|
||||
|
||||
/* if there are anything ith this key but a directory - move it
|
||||
/* if there are anything with this key but a directory - move it
|
||||
somewhere else */
|
||||
relocate_file (comingih, 0/* do not change ih */);
|
||||
|
||||
deh = (struct reiserfs_de_head *)item;
|
||||
|
||||
for (i = 0; i < ih_entry_count (comingih); i ++, deh ++) {
|
||||
for (i = 0; i < get_ih_entry_count (comingih); i ++, deh ++) {
|
||||
name = name_in_entry (deh, i);
|
||||
namelen = name_length (comingih, deh, i);
|
||||
namelen = name_in_entry_length (comingih, deh, i);
|
||||
|
||||
if (!is_properly_hashed (fs, name, namelen, deh_offset (deh)))
|
||||
reiserfs_panic ("put_directory_item_into_tree: should be hashed properly ()");
|
||||
if (!is_properly_hashed (fs, name, namelen, get_deh_offset (deh)))
|
||||
reiserfs_panic ("put_directory_item_into_tree: should be hashed properly (%k)", &comingih->ih_key);
|
||||
|
||||
asprintf (&buf, "%.*s", namelen, name);
|
||||
/* 1 for fsck is important: if there is no any items of this
|
||||
directory in the tree yet - new item will be inserted
|
||||
marked not reached */
|
||||
reiserfs_add_entry (fs, &(comingih->ih_key), buf, (struct key *)&(deh->deh_dir_id), 1/*fsck_need*/);
|
||||
reiserfs_add_entry (fs, &(comingih->ih_key), buf, entry_length (comingih, deh, i),
|
||||
(struct key *)&(deh->deh2_dir_id), 1 << IH_Unreachable);
|
||||
free (buf);
|
||||
}
|
||||
|
||||
/* make a directory */
|
||||
}
|
||||
|
||||
|
||||
@@ -362,14 +393,16 @@ static void link_one (struct relocated * file)
|
||||
struct key obj_key;
|
||||
|
||||
asprintf (&name, "%lu,%lu", file->old_dir_id, file->new_objectid);
|
||||
obj_key.k_dir_id = file->old_dir_id;
|
||||
obj_key.k_objectid = file->new_objectid;
|
||||
set_key_dirid (&obj_key, file->old_dir_id);
|
||||
set_key_objectid (&obj_key, file->new_objectid);
|
||||
|
||||
|
||||
/* 0 for fsck_need does not mean too much - it would make effect
|
||||
if there were no this directory yet. But /lost_found is there
|
||||
already */
|
||||
reiserfs_add_entry (fs, &lost_found_dir_key, name, &obj_key, 0/*fsck_need*/);
|
||||
stats(fs)->relocated ++;
|
||||
reiserfs_add_entry (fs, &lost_found_dir_key, name, name_length (name, lost_found_dir_format),
|
||||
&obj_key, 0/*fsck_need*/);
|
||||
pass_2_stat (fs)->relocated ++;
|
||||
free (name);
|
||||
}
|
||||
|
||||
@@ -393,7 +426,7 @@ void link_relocated_files (void)
|
||||
void insert_item_separately (struct item_head * ih,
|
||||
char * item, int was_in_tree)
|
||||
{
|
||||
if (ih->ih_key.k_dir_id == ih->ih_key.k_objectid)
|
||||
if (get_key_dirid (&ih->ih_key) == get_key_objectid (&ih->ih_key))
|
||||
reiserfs_panic ("insert_item_separately: can not insert bad item %H", ih);
|
||||
|
||||
if (is_stat_data_ih (ih)) {
|
||||
@@ -401,7 +434,7 @@ void insert_item_separately (struct item_head * ih,
|
||||
} else if (is_direntry_ih (ih)) {
|
||||
put_directory_item_into_tree (ih, item);
|
||||
} else {
|
||||
if (should_relocate (ih))
|
||||
if (!was_in_tree && should_relocate (ih))
|
||||
relocate_file (ih, 1/*change new_ih*/);
|
||||
|
||||
reiserfsck_file_write (ih, item, was_in_tree);
|
||||
@@ -409,15 +442,32 @@ void insert_item_separately (struct item_head * ih,
|
||||
}
|
||||
|
||||
|
||||
static void put_items (struct buffer_head * bh)
|
||||
static void put_stat_data_items (struct buffer_head * bh)
|
||||
{
|
||||
int i;
|
||||
struct item_head * ih;
|
||||
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) {
|
||||
|
||||
/* this check instead of saved_items */
|
||||
if (!is_stat_data_ih (ih) || is_bad_item (bh, ih, B_I_PITEM (bh, ih))) {
|
||||
continue;
|
||||
}
|
||||
insert_item_separately (ih, B_I_PITEM (bh, ih), 0/*was in tree*/);
|
||||
}
|
||||
}
|
||||
|
||||
static void put_not_stat_data_items (struct buffer_head * bh)
|
||||
{
|
||||
int i;
|
||||
struct item_head * ih;
|
||||
|
||||
ih = B_N_PITEM_HEAD (bh, 0);
|
||||
for (i = 0; i < B_NR_ITEMS (bh); i ++, ih ++) {
|
||||
if (i && bad_pair (fs, bh, i)) {
|
||||
/* skip item if it is in wrong order */
|
||||
|
||||
if (is_stat_data_ih (ih) || is_bad_item (bh, ih, B_I_PITEM (bh, ih))) {
|
||||
continue;
|
||||
}
|
||||
insert_item_separately (ih, B_I_PITEM (bh, ih), 0/*was in tree*/);
|
||||
@@ -425,61 +475,204 @@ static void put_items (struct buffer_head * bh)
|
||||
}
|
||||
|
||||
|
||||
/* uninsertable blocks are marked by 0s in uninsertable_leaf_bitmap
|
||||
during the pass 1. They must be not in the tree */
|
||||
void pass_2_take_bad_blocks_put_into_tree (void)
|
||||
static void before_pass_2 (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
unsigned long j;
|
||||
unsigned long bb_counter = 0;
|
||||
int what_node;
|
||||
/* anything specific for pass 2 ? */
|
||||
}
|
||||
|
||||
|
||||
if (!stats(fs)->uninsertable_leaves)
|
||||
static void save_pass_2_result (reiserfs_filsys_t * fs)
|
||||
{
|
||||
FILE * file;
|
||||
int retval;
|
||||
|
||||
file = open_file("temp_fsck_file.deleteme", "w+");
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
if (fsck_log_file (fs) != stderr)
|
||||
fsck_log ("####### Pass 2 #######\n");
|
||||
/* to be able to restart from semantic we do not need to save
|
||||
anything here, but two magic values */
|
||||
reiserfs_begin_stage_info_save(file, TREE_IS_BUILT);
|
||||
reiserfs_end_stage_info_save (file);
|
||||
close_file (file);
|
||||
retval = unlink (state_dump_file (fs));
|
||||
retval = rename ("temp_fsck_file.deleteme", state_dump_file (fs));
|
||||
if (retval != 0)
|
||||
fsck_progress ("pass 2: could not rename temp file temp_fsck_file.deleteme to %s",
|
||||
state_dump_file (fs));
|
||||
}
|
||||
|
||||
|
||||
/* we have nothing to load from a state file, but we have to fetch
|
||||
on-disk bitmap, copy it to allocable bitmap, and fetch objectid
|
||||
map */
|
||||
void load_pass_2_result (reiserfs_filsys_t * fs)
|
||||
{
|
||||
fsck_new_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_copy (fsck_new_bitmap (fs), fs->fs_bitmap2);
|
||||
|
||||
fsck_allocable_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_copy (fsck_allocable_bitmap (fs), fs->fs_bitmap2);
|
||||
|
||||
fs->block_allocator = reiserfsck_reiserfs_new_blocknrs;
|
||||
fs->block_deallocator = reiserfsck_reiserfs_free_block;
|
||||
|
||||
/* we need objectid map on semantic pass to be able to relocate files */
|
||||
proper_id_map (fs) = init_id_map ();
|
||||
fetch_objectid_map (proper_id_map (fs), fs);
|
||||
}
|
||||
|
||||
|
||||
/* uninsertable blocks are marked by 0s in uninsertable_leaf_bitmap
|
||||
during the pass 1. They must be not in the tree */
|
||||
static void do_pass_2 (reiserfs_filsys_t * fs) {
|
||||
|
||||
struct buffer_head * bh;
|
||||
unsigned long j;
|
||||
int i, what_node;
|
||||
unsigned long done = 0, total;
|
||||
|
||||
|
||||
total = reiserfs_bitmap_zeros (fsck_uninsertables (fs)) * 2;
|
||||
if (!total)
|
||||
return;
|
||||
|
||||
fsck_progress ("\nPass2:\n");
|
||||
|
||||
j = 0;
|
||||
while (reiserfs_bitmap_find_zero_bit (uninsertable_leaf_bitmap, &j) == 0) {
|
||||
bh = bread (fs->s_dev, j, fs->s_blocksize);
|
||||
if (bh == 0) {
|
||||
fsck_log ("pass_2_take_bad_blocks_put_into_tree: "
|
||||
for (i = 0; i < 2; i++) {
|
||||
j = 0;
|
||||
while (reiserfs_bitmap_find_zero_bit (fsck_uninsertables (fs), &j) == 0) {
|
||||
bh = bread (fs->fs_dev, j, fs->fs_blocksize);
|
||||
if (bh == 0) {
|
||||
fsck_log ("pass_2_take_bad_blocks_put_into_tree: "
|
||||
"unable to read %lu block on device 0x%x\n",
|
||||
j, fs->s_dev);
|
||||
goto next;
|
||||
}
|
||||
j, fs->fs_dev);
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (is_block_used (bh->b_blocknr)) {
|
||||
fsck_log ("pass_2_take_bad_blocks_put_into_tree: "
|
||||
"block %d can not be in tree\n", bh->b_blocknr);
|
||||
goto next;
|
||||
}
|
||||
/* this must be leaf */
|
||||
what_node = who_is_this (bh->b_data, fs->s_blocksize);
|
||||
if (what_node != THE_LEAF) { // || B_IS_KEYS_LEVEL(bh)) {
|
||||
fsck_log ("take_bad_blocks_put_into_tree: buffer (%b %z) must contain leaf\n", bh, bh);
|
||||
goto next;
|
||||
}
|
||||
if (is_block_used (bh->b_blocknr) && !(block_of_journal (fs, bh->b_blocknr) &&
|
||||
fsck_data(fs)->rebuild.use_journal_area)) {
|
||||
fsck_log ("pass_2_take_bad_blocks_put_into_tree: "
|
||||
"block %d can not be in tree\n", bh->b_blocknr);
|
||||
goto next;
|
||||
}
|
||||
/* this must be leaf */
|
||||
what_node = who_is_this (bh->b_data, bh->b_size);
|
||||
if (what_node != THE_LEAF) { // || B_IS_KEYS_LEVEL(bh)) {
|
||||
fsck_log ("take_bad_blocks_put_into_tree: buffer (%b %z) must contain leaf\n", bh, bh);
|
||||
goto next;
|
||||
}
|
||||
|
||||
/*fsck_log ("block %lu is being inserted\n", bh->b_blocknr);*/
|
||||
put_items (bh);
|
||||
|
||||
print_how_far (&bb_counter, stats(fs)->uninsertable_leaves, 1, fsck_quiet (fs));
|
||||
// fsck_log ("block %lu is being inserted\n", bh->b_blocknr);
|
||||
// fflush(fsck_log_file (fs));
|
||||
|
||||
next:
|
||||
brelse (bh);
|
||||
j ++;
|
||||
if (i) {
|
||||
/* insert all not SD items */
|
||||
put_not_stat_data_items (bh);
|
||||
pass_2_stat (fs)->leaves ++;
|
||||
make_allocable (j);
|
||||
} else
|
||||
/* insert SD items only */
|
||||
put_stat_data_items (bh);
|
||||
|
||||
print_how_far (fsck_progress_file (fs), &done, total, 1, fsck_quiet (fs));
|
||||
next:
|
||||
brelse (bh);
|
||||
j ++;
|
||||
}
|
||||
}
|
||||
|
||||
fsck_progress ("\n");
|
||||
|
||||
|
||||
if (bb_counter != stats(fs)->uninsertable_leaves)
|
||||
die ("take_bad_blocks_put_into_tree: found bad block %d, must be %d",
|
||||
bb_counter, stats(fs)->uninsertable_leaves);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void after_pass_2 (reiserfs_filsys_t * fs)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
/* we can now flush new_bitmap on disk as tree is built and
|
||||
contains all data, which were found on dik at start in
|
||||
used bitmaps */
|
||||
reiserfs_bitmap_copy (fs->fs_bitmap2, fsck_new_bitmap (fs));
|
||||
|
||||
/* we should copy new_bitmap to allocable bitmap, becuase evth what is used
|
||||
for now (marked as used in new_bitmap) should not be allocablel;
|
||||
and what is not in tree for now should be allocable.
|
||||
these bitmaps differ because on pass2 we skip those blocks, whose SD's
|
||||
are not in the tree, and therefore indirect items of such bad leaves points
|
||||
to not used and not allocable blocks.
|
||||
*/
|
||||
|
||||
|
||||
/* DEBUG only */
|
||||
if (reiserfs_bitmap_compare (fsck_allocable_bitmap (fs), fsck_new_bitmap(fs))) {
|
||||
reiserfs_warning (fsck_log_file (fs), "allocable bitmap differs from new bitmap after pass2\n");
|
||||
reiserfs_bitmap_copy (fsck_allocable_bitmap(fs), fsck_new_bitmap (fs));
|
||||
}
|
||||
|
||||
/* update super block: objectid map, fsck state */
|
||||
set_sb_fs_state (fs->fs_ondisk_sb, TREE_IS_BUILT);
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
|
||||
/* write all dirty blocks */
|
||||
fsck_progress ("Flushing..");
|
||||
flush_objectid_map (proper_id_map (fs), fs);
|
||||
fs->fs_dirt = 1;
|
||||
reiserfs_flush_to_ondisk_bitmap (fs->fs_bitmap2, fs);
|
||||
reiserfs_flush (fs);
|
||||
fsck_progress ("done\n");
|
||||
|
||||
/* fixme: should be optional */
|
||||
/* fsck_progress ("Tree is built. Checking it - ");
|
||||
reiserfsck_check_pass1 ();
|
||||
fsck_progress ("done\n");*/
|
||||
|
||||
stage_report (2, fs);
|
||||
|
||||
/* free what we do not need anymore */
|
||||
reiserfs_delete_bitmap (fsck_uninsertables (fs));
|
||||
|
||||
if (!fsck_run_one_step (fs)) {
|
||||
if (fsck_user_confirmed (fs, "Continue? (Yes):", "Yes\n", 1))
|
||||
/* reiserfsck continues */
|
||||
return;
|
||||
} else
|
||||
save_pass_2_result (fs);
|
||||
|
||||
|
||||
free_id_map (proper_id_map (fs));
|
||||
proper_id_map (fs) = 0;
|
||||
|
||||
reiserfs_delete_bitmap (fsck_new_bitmap (fs));
|
||||
reiserfs_delete_bitmap (fsck_allocable_bitmap (fs));
|
||||
|
||||
time (&t);
|
||||
fsck_progress ("###########\n"
|
||||
"reiserfsck finished pass 2 at %s"
|
||||
"###########\n", ctime (&t));
|
||||
fs->fs_dirt = 1;
|
||||
reiserfs_close (fs);
|
||||
exit (4);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pass_2 (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (fsck_log_file (fs) != stderr)
|
||||
fsck_log ("####### Pass 2 #######\n");
|
||||
|
||||
before_pass_2 (fs);
|
||||
|
||||
/* take blocks which were not inserted into tree yet and put each
|
||||
item separately */
|
||||
do_pass_2 (fs);
|
||||
|
||||
after_pass_2 (fs);
|
||||
|
||||
if (get_sb_root_block (fs->fs_ondisk_sb) == -1)
|
||||
die ("\n\nNo reiserfs metadata found");
|
||||
}
|
||||
|
||||
|
||||
+42
-16
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright 1996, 1997, 1998 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
#include "fsck.h"
|
||||
|
||||
|
||||
/*
|
||||
void get_next_key (struct path * path, int i, struct key * key)
|
||||
{
|
||||
struct buffer_head * bh = PATH_PLAST_BUFFER (path);
|
||||
@@ -11,23 +11,23 @@ void get_next_key (struct path * path, int i, struct key * key)
|
||||
|
||||
|
||||
if (i < B_NR_ITEMS (bh) - 1) {
|
||||
/* next item is in this block */
|
||||
// next item is in this block
|
||||
copy_key (key, B_N_PKEY (bh, i + 1));
|
||||
return;
|
||||
}
|
||||
|
||||
rkey = uget_rkey (path);
|
||||
if (rkey) {
|
||||
/* got next item key from right delimiting key */
|
||||
// got next item key from right delimiting key
|
||||
copy_key (key, rkey);
|
||||
} else {
|
||||
/* there is no next item */
|
||||
// there is no next item
|
||||
memset (key, 0xff, KEY_SIZE);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
int pass_4_check_unaccessed_items (void)
|
||||
void pass_4_check_unaccessed_items (void)
|
||||
{
|
||||
struct key key;
|
||||
struct path path;
|
||||
@@ -35,6 +35,7 @@ int pass_4_check_unaccessed_items (void)
|
||||
struct buffer_head * bh;
|
||||
struct item_head * ih;
|
||||
unsigned long items;
|
||||
struct key * rdkey;
|
||||
|
||||
path.path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
|
||||
key = root_dir_key;
|
||||
@@ -42,29 +43,38 @@ int pass_4_check_unaccessed_items (void)
|
||||
fsck_progress ("Pass 4 - ");
|
||||
items = 0;
|
||||
|
||||
while (usearch_by_key (fs, &key, &path) == ITEM_FOUND) {
|
||||
while (reiserfs_search_by_key_4 (fs, &key, &path) == ITEM_FOUND) {
|
||||
bh = PATH_PLAST_BUFFER (&path);
|
||||
|
||||
/* print ~ how many leaves were scanned and how fast it was */
|
||||
if (!fsck_quiet (fs))
|
||||
print_how_fast (0, items++, 50);
|
||||
print_how_fast (items++, 0, 50, 0);
|
||||
|
||||
for (i = get_item_pos (&path), ih = get_ih (&path); i < B_NR_ITEMS (bh); i ++, ih ++) {
|
||||
|
||||
|
||||
if (!is_item_reachable (ih)) {
|
||||
|
||||
get_next_key (&path, i, &key);
|
||||
|
||||
stats(fs)->deleted_items ++;
|
||||
|
||||
PATH_LAST_POSITION (&path) = i;
|
||||
rdkey = get_next_key_2 (&path);
|
||||
if (rdkey)
|
||||
key = *rdkey;
|
||||
else
|
||||
memset (&key, 0xff, KEY_SIZE);
|
||||
|
||||
pass_4_stat (fs)->deleted_items ++;
|
||||
|
||||
reiserfsck_delete_item (&path, 0);
|
||||
|
||||
goto cont;
|
||||
}
|
||||
}
|
||||
get_next_key (&path, i - 1, &key);
|
||||
PATH_LAST_POSITION(&path) = i - 1;
|
||||
rdkey = reiserfs_next_key (&path);
|
||||
if (rdkey)
|
||||
key = *rdkey;
|
||||
else
|
||||
memset (&key, 0xff, KEY_SIZE);
|
||||
|
||||
pathrelse (&path);
|
||||
|
||||
cont:
|
||||
@@ -75,5 +85,21 @@ int pass_4_check_unaccessed_items (void)
|
||||
fsck_progress ("done\n");
|
||||
stage_report (4, fs);
|
||||
|
||||
return 0;
|
||||
/* after pass 4 */
|
||||
|
||||
/* put bitmap on place */
|
||||
reiserfs_bitmap_copy (fs->fs_bitmap2, fsck_new_bitmap (fs));
|
||||
|
||||
/* update super block */
|
||||
set_sb_free_blocks (fs->fs_ondisk_sb, reiserfs_bitmap_zeros (fsck_new_bitmap (fs)));
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
|
||||
/* write all dirty blocks */
|
||||
fsck_progress ("Flushing..");
|
||||
fs->fs_dirt = 1;
|
||||
flush_objectid_map (proper_id_map (fs), fs);
|
||||
reiserfs_flush_to_ondisk_bitmap (fs->fs_bitmap2, fs);
|
||||
reiserfs_flush (fs);
|
||||
fsck_progress ("done\n");
|
||||
return;
|
||||
}
|
||||
+127
-62
@@ -1,91 +1,156 @@
|
||||
.\" -*- nroff -*-
|
||||
.\" Copyright 1996-2001 Hans Reiser.
|
||||
.\" Copyright 1996-2002 Hans Reiser.
|
||||
.\"
|
||||
.TH REISERFSCK 8 "March 2001" "Reiserfsprogs-3.x.0j"
|
||||
.TH REISERFSCK 8 "January 2002" "Reiserfsprogs-3.6.2"
|
||||
.SH NAME
|
||||
reiserfsck \- check a Linux Reiserfs file system
|
||||
.SH SYNOPSIS
|
||||
.B reiserfsck
|
||||
[
|
||||
.B -arvixoV
|
||||
] [
|
||||
.B -l logfilename
|
||||
] [
|
||||
.B --rebuild-tree
|
||||
] [
|
||||
.B --check
|
||||
] [
|
||||
.B --rebuild-sb
|
||||
] [
|
||||
.B --interactive
|
||||
] [
|
||||
\fB --logfile \fI logfilename
|
||||
] [
|
||||
.B --fix-fixable
|
||||
]
|
||||
[ \fB-afprVy\fR ]
|
||||
[ \fB--check\fR | \fB--fix-fixable\fR | \fB--rebuild-sb\fR
|
||||
| \fB--rebuild-tree\fR | \fB--clean-attributes\fR ]
|
||||
.\" [ \fB-i\fR | \fB--interactive\fR ]
|
||||
[ \fB-j\fR | \fB--journal-device\fR \fIdevice\fR ]
|
||||
[ \fB--no-journal-available\fR ]
|
||||
[ \fB-z\fR | \fB--adjust-file-size\fR ]
|
||||
[ \fB-S\fR | \fB--scan-whole-partition\fR ]
|
||||
[ \fB-l\fR | \fB--logfile \fIfilename\fR ]
|
||||
[ \fB-n\fR | \fB--nolog\fR ]
|
||||
[ \fB-q\fR | \fB--quiet\fR ]
|
||||
.\" [ \fB-b\fR | \fB--scan-marked-in-bitmap \fIbitmap-filename\fR ]
|
||||
.\" [ \fB-h\fR | \fB--hash \fIhash-name\fR ]
|
||||
.\" [ \fB-g\fR | \fB--background\fR ]
|
||||
.I device
|
||||
.SH DESCRIPTION
|
||||
It looks for reiserfs filesystem on a device, replays transactions
|
||||
which are to be replayed and either check or repair the filesystem
|
||||
\fBReiserfsck\fR searches for a Reiserfs filesystem on a device, replays
|
||||
any necessary transactions, and either checks or repairs the file system.
|
||||
.TP
|
||||
.I device
|
||||
is the special file corresponding to the device (e.g /dev/hdXX for
|
||||
IDE disk partition or /dev/sdXX for SCSI disk partition).
|
||||
is the special file corresponding to the device or partition (e.g /dev/hdXX
|
||||
for IDE disk partition or /dev/sdXX for SCSI disk partition).
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B --check
|
||||
This checks filesystem consistency. This is a default action. It may
|
||||
be used on a filesystem mounted read-only
|
||||
This default action checks file system consistency and reports but
|
||||
does not repair any corruption that it finds. This option may be
|
||||
used on a read-only file system mount. The \fB--check\fR option exits
|
||||
with status 0 to indicate that no corruption was found. Otherwise,
|
||||
\fBreiserfsck\fR returns 1 to indicate corruption that can be fixed with
|
||||
\fB--fix-fixable\fR and 2 to indicate corruption that requires
|
||||
\fB--rebuild-tree\fR.
|
||||
.TP
|
||||
.B --rebuild-tree
|
||||
This rebuilds filesystem tree using leaf nodes found on the
|
||||
device. Normally, you do not need this, but if you have to rebuild
|
||||
tree - please backup whole partition first or at least the most
|
||||
important data if you can mount the partition.
|
||||
.B --fix-fixable
|
||||
This option recovers certain kinds of corruption that do not require
|
||||
rebuilding the entire file system tree (\fB--rebuild-tree\fR). Normally
|
||||
you only need this option if the \fB--check\fR option reports
|
||||
"corruption that can be fixed with \fB--fix-fixable\fR". This includes:
|
||||
zeroing invalid data-block pointers, correcting st_size and st_blocks
|
||||
for directories, and deleting invalid directory entries.
|
||||
.TP
|
||||
.B --rebuild-sb
|
||||
This option recovers the superblock on a Reiserfs partition. Normally you
|
||||
only need this option if mount reports "read_super_block: can't find
|
||||
a reiserfs file system" and you are sure that a Reiserfs file system is
|
||||
there.
|
||||
.TP
|
||||
.B --interactive, -i
|
||||
This makes \fBreiserfsck\fR to stop after each pass completed.
|
||||
.B --rebuild-tree
|
||||
This option rebuilds the entire file system tree using leaf nodes found
|
||||
on the device. Normally you only need this option if the \fB--check\fR
|
||||
option reports "corruption that can be fixed only during \fB--rebuild-tree\fR".
|
||||
You are strongly encouraged to make a backup copy of the whole partition
|
||||
before attempting the \fB--rebuild-tree\fR option.
|
||||
.TP
|
||||
.B --quiet, -q
|
||||
have \fBreiserfsck\fR to not reflect its progress
|
||||
.B --clean-attributes
|
||||
This option cleans reserved fields of Stat-Data items.
|
||||
.TP
|
||||
.B \fB--journal-device \fIdevice \fR, \fB-j \fIdevice \fR
|
||||
This option supplies the device name of the current file system journal.
|
||||
This option is required when the journal resides on a separate device
|
||||
from the main data device (although it can be avoided with the expert
|
||||
option \fB--no-journal-available\fR).
|
||||
.TP
|
||||
.\" .B --interactive, -i
|
||||
.\" This makes \fBreiserfsck\fR to stop after each pass completed.
|
||||
.\" .TP
|
||||
.B --adjust-file-size, -z
|
||||
This option causes \fBreiserfsck\fR to correct file sizes that
|
||||
are larger than the offset of the last discovered byte. This
|
||||
implies that holes at the end of a file will be removed. File
|
||||
sizes that are smaller than the offset of the last discovered
|
||||
byte are corrected by --fix-fixable.
|
||||
.TP
|
||||
\fB--logfile \fIfilename\fR, \fB-l \fI filename\fR
|
||||
This option causes \fBreiserfsck\fR to report any corruption it finds
|
||||
to the specified log file rather than stderr.
|
||||
.TP
|
||||
.B --nolog, -n
|
||||
have \fBreiserfsck\fR to not log anything
|
||||
This option prevents \fBreiserfsck\fR from reporting any kinds of corruption.
|
||||
.TP
|
||||
\fB--logfile \fIfilename\fR, \fB-l \fI filename
|
||||
have \fBreiserfsck\fR to put info about found corruptions in logfile
|
||||
rather than on stderr
|
||||
.B --quiet, -q
|
||||
This option prevents \fBreiserfsck\fR from reporting its rate of progress.
|
||||
.TP
|
||||
.B --fix-fixable, -x
|
||||
have \fBreiserfsck\fR to recover corruptions which can be fixed w/o
|
||||
--rebuild-tree when it is runnig in check mode. Corruptions which can
|
||||
be fixed so far: bad pointers to data blocks, wrong directory's
|
||||
st_size and st_blocks, directories entries pointing to nowhere can be
|
||||
deleted
|
||||
.TP
|
||||
.B --fix-non-critical, -o
|
||||
have \fBreiserfsck\fR to fix: file sizes when they are bigger than
|
||||
real file size, set file mode to regular file when mode looks wrong
|
||||
and to try to recover "objectid sharing" problem
|
||||
.TP
|
||||
.B -a
|
||||
When it is set - \fBreiserfsck\fR assumes that it is called by fsck -A
|
||||
and just returns even if filesystem seems not umounted cleanly
|
||||
.TP
|
||||
.B -r
|
||||
ignored
|
||||
\fB-a\fR, \fB-p\fR
|
||||
These options are usually passed by fsck -A during the automatic
|
||||
checking of /etc/fstab partitions. For compatibility, these options
|
||||
simply cause reiserfsck to print information about the specified file
|
||||
system. No checks are performed.
|
||||
When it is set - \fBreiserfsck\fR assumes that it is called by \fBfsck\fR -A,
|
||||
provides some information about the specified filesystem and exits.
|
||||
.TP
|
||||
.B -V
|
||||
Prints version and exits
|
||||
This option prints the reiserfsprogs version and exit.
|
||||
.TP
|
||||
\fB-r\fR, \fB-p\fR, \fB-y\fR
|
||||
These options are ignored.
|
||||
.TP
|
||||
.B -V\fR, \fB-f\fR
|
||||
prints version and exits
|
||||
.SH EXPERT OPTIONS
|
||||
DO NOT USE THESE OPTIONS UNLESS YOU KNOW WHAT YOU ARE DOING.
|
||||
WE ARE NOT RESPONSIBLE IF YOU LOSE DATA AS A RESULT OF THESE
|
||||
OPTIONS.
|
||||
.TP
|
||||
.B \fB\--no-journal-available\fR
|
||||
This option allows \fBreiserfsck\fR to proceed when the journal device is
|
||||
not available. This option has no effect when the journal is located on
|
||||
the main data device. NOTE: after this operation you must use \fBreiserfstune\fR
|
||||
to specify a new journal device.
|
||||
.TP
|
||||
.B --scan-whole-partition, -S
|
||||
This option causes \fB--rebuild-tree\fR to scan the whole partition, not only
|
||||
used space on the partition.
|
||||
.SH EXAMPLE OF USING
|
||||
1. You think something may be wrong with a reiserfs partition on /dev/hda1
|
||||
or you would just like to perform a periodic disk check.
|
||||
|
||||
2. Run \fBreiserfsck --check --logfile check.log /dev/hda1\fR. If \fBreiserfsck
|
||||
--check\fR exits with status 0 it means no errors were discovered.
|
||||
|
||||
3. If \fBreiserfsck --check\fR exits with status 1 (and reports about fixable
|
||||
corruptions) it means that you should run \fBreiserfsck --fix-fixable --logfile
|
||||
fixable.log /dev/hda1\fR.
|
||||
|
||||
4. If \fBreiserfsck --check\fR exits with status 2 (and reports about fatal
|
||||
corruptions) it means that you need to run \fBreiserfsck --rebuild-tree\fR.
|
||||
If \fBreiserfsck --check\fR fails in some way you should also run \fBreiserfsck
|
||||
--rebuild-tree\fR, but we also encourage you to submit this as a bug report.
|
||||
|
||||
5. Before running \fBreiserfsck --rebuild-tree\fR, please make a backup of
|
||||
the whole partition before proceeding. Then run \fBreiserfsck --rebuild-tree
|
||||
--logfile rebuild.log /dev/hda1\fR.
|
||||
|
||||
6. If the \fB--rebuild-tree\fR step fails or does not recover what you expected,
|
||||
please submit this as a bug report. Try to provide as much information as
|
||||
possible and we will try to help solve the problem.
|
||||
.SH AUTHOR
|
||||
This version of \fBreiserfsck\fR has been written by Hans Reiser
|
||||
<reiser@idiom.com>.
|
||||
This version of \fBreiserfsck\fR has been written by Vitaly Fertman <vitaly@namesys.com>
|
||||
and Vladimir Saveliev <vs@namesys.com>.
|
||||
.SH BUGS
|
||||
There are probably few of them. Please, report bugs to Hans Reiser <reiser@idiom.com>.
|
||||
There are likely to be some bugs. Please report bugs to the ReiserFS mail-list
|
||||
<reiserfs-list@namesys.com>.
|
||||
.SH TODO
|
||||
Faster recovering, signal handling, i/o error handling, etc.
|
||||
Faster recovering, signal handling, i/o error handling, return reasonable exit codes, etc.
|
||||
.SH SEE ALSO
|
||||
.BR mkreiserfs (8),
|
||||
.BR debugreiserfs (8)
|
||||
.BR debugreiserfs (8),
|
||||
.BR reiserfstune (8)
|
||||
-202
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* Copyright 1998 Hans Reiser
|
||||
*/
|
||||
/*#include <stdio.h>
|
||||
#include <string.h>*/
|
||||
/*#include <asm/bitops.h>
|
||||
#include "../include/reiserfs_fs.h"
|
||||
#include "../include/reiserfs_fs_sb.h"
|
||||
#include "../include/reiserfslib.h"*/
|
||||
#include "fsck.h"
|
||||
|
||||
|
||||
/* there is a situation, when we overwrite contents of unformatted
|
||||
node with direct item. One unformatted node can be overwritten
|
||||
several times by direct items */
|
||||
/*
|
||||
struct overwritten_unfm_segment {
|
||||
int ous_begin;
|
||||
int ous_end;
|
||||
struct overwritten_unfm_segment * ous_next;
|
||||
};
|
||||
*/
|
||||
struct overwritten_unfm {
|
||||
unsigned long ou_unfm_ptr; /* block number of unfm node */
|
||||
unsigned long ou_dir_id;
|
||||
unsigned long ou_objectid; /* key corresponding to an unfm node */
|
||||
unsigned long ou_offset;
|
||||
|
||||
struct overwritten_unfm_segment * ou_segments; /* list of segmens, than have been overwritten in ths unfm node */
|
||||
};
|
||||
|
||||
struct overwritten_unfm ** g_overwritten_unfms;
|
||||
int g_overwritten_unfms_amount; /* number of unformatted nodes, which contain direct items */
|
||||
|
||||
|
||||
/* adds segment to the single linked list of segments sorted by begin
|
||||
field. Retuns pointer to first element of list */
|
||||
static struct overwritten_unfm_segment * add_segment (struct overwritten_unfm_segment * first, int begin, int end)
|
||||
{
|
||||
struct overwritten_unfm_segment * new, * next, * prev;
|
||||
|
||||
new = getmem (sizeof (struct overwritten_unfm_segment));
|
||||
new->ous_begin = begin;
|
||||
new->ous_end = end;
|
||||
new->ous_next = 0;
|
||||
|
||||
next = first;
|
||||
prev = 0;
|
||||
while (next) {
|
||||
if (next->ous_begin > begin)
|
||||
break;
|
||||
prev = next;
|
||||
next = next->ous_next;
|
||||
}
|
||||
|
||||
if (prev == 0) {
|
||||
/* insert into head of list */
|
||||
first = new;
|
||||
} else {
|
||||
prev->ous_next = new;
|
||||
}
|
||||
new->ous_next = next;
|
||||
return first;
|
||||
}
|
||||
|
||||
|
||||
/* input parameter
|
||||
`list_head` - first element of overlapping segments sorted by left edge
|
||||
`unoverwritten_segment` - returned by previous call of get_unoverwritten_segment or (-2,-2) if called first time
|
||||
*/
|
||||
/* returns
|
||||
1 and segment unoverwritten by elements of list `list_head`
|
||||
0 if there isno such segment
|
||||
*/
|
||||
int get_unoverwritten_segment (struct overwritten_unfm_segment * list_head, struct overwritten_unfm_segment * unoverwritten_segment)
|
||||
{
|
||||
int end;
|
||||
|
||||
/* look for segment, which has begin field greater than end of previous interval */
|
||||
while (list_head->ous_begin <= unoverwritten_segment->ous_end) {
|
||||
list_head = list_head->ous_next;
|
||||
}
|
||||
/* look for the end of the continuous region covered by otrezkami */
|
||||
end = list_head->ous_end;
|
||||
while (list_head->ous_next) {
|
||||
if (list_head->ous_next->ous_begin > end + 1)
|
||||
/* intreval found */
|
||||
break;
|
||||
if (list_head->ous_next->ous_end > end)
|
||||
end = list_head->ous_next->ous_end;
|
||||
list_head = list_head->ous_next;
|
||||
}
|
||||
/* ok, between segment and segment->next we have an interval (segment->next != 0) */
|
||||
if (list_head->ous_next != 0) {
|
||||
unoverwritten_segment->ous_begin = end + 1;
|
||||
unoverwritten_segment->ous_end = list_head->ous_next->ous_begin - 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void print_segments (struct overwritten_unfm_segment * list_head)
|
||||
{
|
||||
struct overwritten_unfm_segment * cur;
|
||||
|
||||
cur = list_head;
|
||||
while (cur) {
|
||||
printf ("%s%d %d%s", cur == list_head ? "(" : "", cur->ous_begin, cur->ous_end, cur->ous_next ? ", " : ")\n");
|
||||
cur = cur->ous_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* this prepare list of segments to extracting of unoverwritten segments */
|
||||
struct overwritten_unfm_segment * find_overwritten_unfm (unsigned long unfm, int length, struct overwritten_unfm_segment * segment_to_init)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_overwritten_unfms_amount && g_overwritten_unfms[i] != 0; i ++)
|
||||
if (g_overwritten_unfms[i]->ou_unfm_ptr == unfm) {
|
||||
if (g_overwritten_unfms[i]->ou_segments == 0)
|
||||
die ("find_overwritten_unfm: no segment found");
|
||||
g_overwritten_unfms[i]->ou_segments = add_segment (g_overwritten_unfms[i]->ou_segments, -1, -1);
|
||||
add_segment (g_overwritten_unfms[i]->ou_segments, length, length);
|
||||
segment_to_init->ous_begin = -2;
|
||||
segment_to_init->ous_end = -2;
|
||||
return g_overwritten_unfms[i]->ou_segments;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct overwritten_unfm * look_for_overwritten_unfm (__u32 unfm)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_overwritten_unfms_amount && g_overwritten_unfms[i] != 0; i ++)
|
||||
if (g_overwritten_unfms[i]->ou_unfm_ptr == unfm)
|
||||
return g_overwritten_unfms[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define GROW_BY 10
|
||||
struct overwritten_unfm * add_overwritten_unfm (unsigned long unfm, struct item_head * direct_ih)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_overwritten_unfms_amount && g_overwritten_unfms[i] != 0; i ++) {
|
||||
if (g_overwritten_unfms[i]->ou_unfm_ptr == unfm)
|
||||
return g_overwritten_unfms[i];
|
||||
}
|
||||
|
||||
if (i == g_overwritten_unfms_amount) {
|
||||
g_overwritten_unfms = expandmem (g_overwritten_unfms, sizeof (struct overwritten_unfm *) * i,
|
||||
sizeof (struct overwritten_unfm *) * GROW_BY);
|
||||
g_overwritten_unfms_amount += GROW_BY;
|
||||
}
|
||||
g_overwritten_unfms[i] = getmem (sizeof (struct overwritten_unfm));
|
||||
g_overwritten_unfms[i]->ou_unfm_ptr = unfm;
|
||||
g_overwritten_unfms[i]->ou_dir_id = direct_ih->ih_key.k_dir_id;
|
||||
g_overwritten_unfms[i]->ou_objectid = direct_ih->ih_key.k_objectid;
|
||||
g_overwritten_unfms[i]->ou_offset = get_offset(&direct_ih->ih_key) - (get_offset(&direct_ih->ih_key) - 1) % fs->s_blocksize;
|
||||
return g_overwritten_unfms[i];
|
||||
}
|
||||
|
||||
|
||||
void save_unfm_overwriting (unsigned long unfm, struct item_head * direct_ih)
|
||||
{
|
||||
struct overwritten_unfm * ov_unfm;
|
||||
|
||||
/* add new overwritten unfm or return existing one */
|
||||
ov_unfm = add_overwritten_unfm (unfm, direct_ih);
|
||||
ov_unfm->ou_segments = add_segment (ov_unfm->ou_segments, (get_offset(&direct_ih->ih_key) - 1) % fs->s_blocksize,
|
||||
(get_offset(&direct_ih->ih_key) - 1) % fs->s_blocksize + ih_item_len (direct_ih) - 1);
|
||||
}
|
||||
|
||||
|
||||
void free_overwritten_unfms (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_overwritten_unfms_amount && g_overwritten_unfms[i]; i ++) {
|
||||
/* free all segments */
|
||||
while (g_overwritten_unfms[i]->ou_segments) {
|
||||
struct overwritten_unfm_segment * tmp;
|
||||
|
||||
tmp = g_overwritten_unfms[i]->ou_segments->ous_next;
|
||||
freemem (g_overwritten_unfms[i]->ou_segments);
|
||||
g_overwritten_unfms[i]->ou_segments = tmp;
|
||||
}
|
||||
/* free struct overwritten_unfm */
|
||||
freemem (g_overwritten_unfms[i]);
|
||||
}
|
||||
|
||||
/* free array of pointers to overwritten unfms */
|
||||
if (g_overwritten_unfms)
|
||||
freemem (g_overwritten_unfms);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
-1346
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,731 @@
|
||||
/*
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
#include "fsck.h"
|
||||
|
||||
int wrong_mode (struct key * key, __u16 * mode, __u64 real_size, int symlink);
|
||||
int wrong_st_blocks (struct key * key, __u32 * blocks, __u32 sd_blocks, __u16 mode, int new_format);
|
||||
int wrong_st_size (struct key * key, loff_t max_file_size, int blocksize,
|
||||
__u64 * size, __u64 sd_size, int is_dir);
|
||||
int wrong_first_direct_byte (struct key * key, int blocksize,
|
||||
__u32 * first_direct_byte,
|
||||
__u32 sd_first_direct_byte, __u32 size);
|
||||
void get_object_key (struct reiserfs_de_head * deh, struct key * key,
|
||||
struct key * entry_key, struct item_head * ih);
|
||||
void print_name (char * name, int len);
|
||||
void erase_name (int len);
|
||||
|
||||
|
||||
struct path_key
|
||||
{
|
||||
struct short_key
|
||||
{
|
||||
__u32 k_dir_id;
|
||||
__u32 k_objectid;
|
||||
} key;
|
||||
struct path_key * next, * prev;
|
||||
};
|
||||
|
||||
struct path_key * head_key = NULL;
|
||||
struct path_key * tail_key = NULL;
|
||||
|
||||
static int check_path_key(struct key * key)
|
||||
{
|
||||
struct path_key * cur = head_key;
|
||||
|
||||
while(cur != NULL)
|
||||
{
|
||||
if (!comp_short_keys(&cur->key, key)) {
|
||||
fsck_log("\nsemantic check: directory %k has 2 names ", key);
|
||||
return LOOP_FOUND;
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_path_key(struct key * key, int check)
|
||||
{
|
||||
if (check && check_path_key(key))
|
||||
return LOOP_FOUND;
|
||||
|
||||
if (tail_key == NULL)
|
||||
{
|
||||
tail_key = getmem(sizeof(struct path_key));
|
||||
head_key = tail_key;
|
||||
tail_key->prev = NULL;
|
||||
}else{
|
||||
tail_key->next = getmem(sizeof(struct path_key));
|
||||
tail_key->next->prev = tail_key;
|
||||
tail_key = tail_key->next;
|
||||
}
|
||||
copy_short_key (&tail_key->key, key);
|
||||
tail_key->next = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void del_path_key()
|
||||
{
|
||||
if (tail_key == NULL)
|
||||
die("wrong path_key structure");
|
||||
|
||||
if (tail_key->prev == NULL)
|
||||
{
|
||||
freemem(tail_key);
|
||||
tail_key = head_key = NULL;
|
||||
}else{
|
||||
tail_key = tail_key->prev;
|
||||
freemem(tail_key->next);
|
||||
tail_key->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* path is path to stat data. If file will be relocated - new_ih will contain
|
||||
a key file was relocated with */
|
||||
static int check_check_regular_file (struct path * path, void * sd,
|
||||
struct item_head * new_ih)
|
||||
{
|
||||
int is_new_file;
|
||||
// struct key key, sd_key;
|
||||
__u16 mode;
|
||||
__u32 nlink;
|
||||
__u64 real_size, saved_size;
|
||||
__u32 blocks, saved_blocks; /* proper values and value in stat data */
|
||||
__u32 first_direct_byte, saved_first_direct_byte;
|
||||
|
||||
struct buffer_head * bh;
|
||||
struct item_head * ih, sd_ih;
|
||||
int fix_sd;
|
||||
int symlnk = 0;
|
||||
int retval = OK;
|
||||
|
||||
|
||||
ih = get_ih (path);
|
||||
bh = get_bh (path);
|
||||
|
||||
if (new_ih) {
|
||||
/* this objectid is used already */
|
||||
*new_ih = *ih;
|
||||
pathrelse (path);
|
||||
relocate_file (new_ih, 1);
|
||||
one_less_corruption (fs, fixable);
|
||||
sem_pass_stat (fs)->oid_sharing_files_relocated ++;
|
||||
retval = RELOCATED;
|
||||
if (reiserfs_search_by_key_4 (fs, &(new_ih->ih_key), path) == ITEM_NOT_FOUND)
|
||||
reiserfs_panic ("check_check_regular_file: could not find stat data of relocated file");
|
||||
/* stat data is marked unreachable again due to relocation, fix that */
|
||||
ih = get_ih (path);
|
||||
bh = get_bh (path);
|
||||
sd = get_item (path);
|
||||
}
|
||||
|
||||
|
||||
if (get_ih_item_len (ih) == SD_SIZE)
|
||||
is_new_file = 1;
|
||||
else
|
||||
is_new_file = 0;
|
||||
|
||||
|
||||
get_sd_nlink (ih, sd, &nlink);
|
||||
get_sd_mode (ih, sd, &mode);
|
||||
get_sd_size (ih, sd, &saved_size);
|
||||
get_sd_blocks (ih, sd, &saved_blocks);
|
||||
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
/* check and set nlink first */
|
||||
nlink ++;
|
||||
set_sd_nlink (ih, sd, &nlink);
|
||||
mark_buffer_dirty (bh);
|
||||
|
||||
if (nlink > 1)
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (!is_new_file)
|
||||
get_sd_first_direct_byte (ih, sd, &saved_first_direct_byte);
|
||||
|
||||
if (S_ISLNK (mode))
|
||||
symlnk = 1;
|
||||
|
||||
sd_ih = *ih;
|
||||
// sd_key = sd_ih.ih_key;
|
||||
pathrelse (path);
|
||||
|
||||
if (are_file_items_correct (&sd_ih, sd, &real_size, &blocks, 0/*do not mark items reachable*/, &symlnk) != 1) {
|
||||
one_more_corruption (fs, fatal);
|
||||
fsck_log ("check_regular_file: broken file found %K\n", &sd_ih.ih_key);
|
||||
} else {
|
||||
fix_sd = 0;
|
||||
|
||||
fix_sd += wrong_mode (&sd_ih.ih_key, &mode, real_size, symlnk);
|
||||
if (!is_new_file)
|
||||
fix_sd += wrong_first_direct_byte (&sd_ih.ih_key, fs->fs_blocksize,
|
||||
&first_direct_byte, saved_first_direct_byte, real_size);
|
||||
fix_sd += wrong_st_size (&sd_ih.ih_key, is_new_file ? MAX_FILE_SIZE_V2 : MAX_FILE_SIZE_V1,
|
||||
fs->fs_blocksize, &real_size, saved_size, 0/*not dir*/);
|
||||
|
||||
fix_sd += wrong_st_blocks (&sd_ih.ih_key, &blocks, saved_blocks, mode, is_new_file);
|
||||
|
||||
if (fix_sd) {
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
/* find stat data and correct it */
|
||||
set_type_and_offset (KEY_FORMAT_1, &sd_ih.ih_key, SD_OFFSET, TYPE_STAT_DATA);
|
||||
if (reiserfs_search_by_key_4 (fs, &sd_ih.ih_key, path) != ITEM_FOUND) {
|
||||
fsck_log ("check_regular_file: stat data not found");
|
||||
one_more_corruption (fs, fatal);
|
||||
return STAT_DATA_NOT_FOUND;
|
||||
}
|
||||
|
||||
bh = get_bh (path);
|
||||
ih = get_ih (path);
|
||||
sd = get_item (path);
|
||||
set_sd_size (ih, sd, &real_size);
|
||||
set_sd_blocks (ih, sd, &blocks);
|
||||
set_sd_mode (ih, sd, &mode);
|
||||
if (!is_new_file)
|
||||
set_sd_first_direct_byte (ih, sd, &first_direct_byte);
|
||||
mark_buffer_dirty (bh);
|
||||
} else {
|
||||
fsck_check_stat (fs)->fixable_corruptions += fix_sd;
|
||||
}
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* returns buffer, containing found directory item.*/
|
||||
static char * get_next_directory_item (struct key * key, /* on return this will
|
||||
contain key of next item
|
||||
in the tree */
|
||||
struct key * parent,
|
||||
struct item_head * ih,/*not in tree*/
|
||||
__u32 * pos_in_item, int dir_format)
|
||||
{
|
||||
INITIALIZE_PATH (path);
|
||||
char * dir_item;
|
||||
struct key * rdkey;
|
||||
struct buffer_head * bh;
|
||||
struct reiserfs_de_head * deh;
|
||||
int i;
|
||||
int retval;
|
||||
|
||||
|
||||
start_again:
|
||||
|
||||
retval = reiserfs_search_by_entry_key (fs, key, &path);
|
||||
|
||||
if (retval != POSITION_FOUND && get_offset (key) != DOT_OFFSET)
|
||||
reiserfs_panic ("get_next_directory_item: %k is not found", key);
|
||||
|
||||
/* leaf containing directory item */
|
||||
bh = PATH_PLAST_BUFFER (&path);
|
||||
*pos_in_item = path.pos_in_item;
|
||||
*ih = *get_ih (&path);
|
||||
deh = B_I_DEH (bh, ih);
|
||||
|
||||
/* position was not found for '.' or there is no '..' */
|
||||
if (retval != POSITION_FOUND || ((get_offset (key) == DOT_OFFSET) &&
|
||||
(get_ih_entry_count (ih) < 2 || name_in_entry_length (ih, deh + 1, 1) != 2 ||
|
||||
strncmp (name_in_entry (deh + 1, 1), "..", 2)))) {
|
||||
|
||||
fsck_log ("get_next_directory_item: %k %s is not found", key,
|
||||
(retval == POSITION_NOT_FOUND) ? "entry" : "directory");
|
||||
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
/* add "." and ".." exist */
|
||||
pathrelse (&path);
|
||||
reiserfs_add_entry (fs, key, ".", name_length (".", dir_format), key, 0);
|
||||
reiserfs_add_entry (fs, key, "..", name_length ("..", dir_format), parent, 0);
|
||||
fsck_log (" - fixed\n");
|
||||
goto start_again;
|
||||
} else {
|
||||
one_more_corruption (fs, fixable);
|
||||
fsck_log ("\n");
|
||||
if (retval == DIRECTORY_NOT_FOUND)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* make sure, that ".." exists as well */
|
||||
/*
|
||||
if (get_offset (key) == DOT_OFFSET) {
|
||||
if (get_ih_entry_count (ih) < 2 ||
|
||||
name_in_entry_length (ih, deh + 1, 1) != 2 ||
|
||||
strncmp (name_in_entry (deh + 1, 1), "..", 2))
|
||||
{
|
||||
fsck_log ("get_next_directory_item: \"..\" not found in %H\n", ih);
|
||||
pathrelse (&path);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
/* mark hidden entries as visible, set "." and ".." correctly */
|
||||
deh += *pos_in_item;
|
||||
for (i = *pos_in_item; i < get_ih_entry_count (ih); i ++, deh ++) {
|
||||
int namelen;
|
||||
char * name;
|
||||
|
||||
name = name_in_entry (deh, i);
|
||||
namelen = name_in_entry_length (ih, deh, i);
|
||||
/* if (de_hidden (deh)) // handled in check_tree
|
||||
reiserfs_panic ("get_next_directory_item: item %k: hidden entry %d \'%.*s\'\n",
|
||||
key, i, namelen, name);
|
||||
*/
|
||||
|
||||
if (get_deh_offset (deh) == DOT_OFFSET) {
|
||||
if (not_of_one_file (&(deh->deh2_dir_id), key)) {
|
||||
/* "." must point to the directory it is in */
|
||||
|
||||
//deh->deh_objectid != REISERFS_ROOT_PARENT_OBJECTID)/*????*/ {
|
||||
fsck_log ("get_next_directory_item: %k: \".\" pointes to [%K], "
|
||||
"should point to [%K]", key, (struct key *)(&(deh->deh2_dir_id)));
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
set_deh_dirid (deh, get_key_dirid (key));
|
||||
set_deh_objectid (deh, get_key_objectid (key));
|
||||
mark_buffer_dirty (bh);
|
||||
fsck_log (" - fixed\n");
|
||||
} else
|
||||
fsck_log ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (get_deh_offset (deh) == DOT_DOT_OFFSET) {
|
||||
/* set ".." so that it points to the correct parent directory */
|
||||
if (comp_short_keys (&(deh->deh2_dir_id), parent)) {
|
||||
fsck_log ("get_next_directory_item: %k: \"..\" pointes to [%K], "
|
||||
"should point to [%K]", key, (struct key *)(&(deh->deh2_dir_id)), parent);
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
set_deh_dirid (deh, get_key_dirid (parent));
|
||||
set_deh_objectid (deh, get_key_objectid (parent));
|
||||
mark_buffer_dirty (bh);
|
||||
fsck_log (" - fixed\n");
|
||||
} else
|
||||
fsck_log ("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* copy directory item to the temporary buffer */
|
||||
dir_item = getmem (get_ih_item_len (ih));
|
||||
memcpy (dir_item, B_I_PITEM (bh, ih), get_ih_item_len (ih));
|
||||
|
||||
|
||||
/* next item key */
|
||||
if (PATH_LAST_POSITION (&path) == (B_NR_ITEMS (bh) - 1) &&
|
||||
(rdkey = uget_rkey (&path)))
|
||||
copy_key (key, rdkey);
|
||||
else {
|
||||
set_key_dirid (key, 0);
|
||||
set_key_objectid (key, 0);
|
||||
}
|
||||
|
||||
if (fsck_mode (fs) != FSCK_CHECK && fsck_mode (fs) != FSCK_FIX_FIXABLE)
|
||||
mark_item_reachable (get_ih (&path), bh);
|
||||
pathrelse (&path);
|
||||
|
||||
return dir_item;
|
||||
}
|
||||
|
||||
/* semantic pass of --check */
|
||||
static int check_semantic_pass (struct key * key, struct key * parent, int dot_dot, struct item_head * new_ih)
|
||||
{
|
||||
struct path path;
|
||||
void * sd;
|
||||
__u32 nlink;
|
||||
int is_new_dir;
|
||||
struct buffer_head * bh;
|
||||
struct item_head * ih;
|
||||
int retval;
|
||||
char * dir_item;
|
||||
__u32 pos_in_item;
|
||||
struct item_head tmp_ih;
|
||||
struct key next_item_key, entry_key, object_key;
|
||||
__u64 dir_size = 0;
|
||||
__u32 blocks;
|
||||
__u64 saved_size;
|
||||
__u32 saved_blocks;
|
||||
int fix_sd;
|
||||
int relocate;
|
||||
int dir_format = 0;
|
||||
__u16 mode;
|
||||
|
||||
retval = OK;
|
||||
|
||||
start_again: /* when directory was relocated */
|
||||
|
||||
if (!KEY_IS_STAT_DATA_KEY (key)) {
|
||||
fsck_log ("check_semantic_pass: key must be key of a stat data");
|
||||
one_more_corruption (fs, fatal);
|
||||
return STAT_DATA_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* look for stat data of an object */
|
||||
if (reiserfs_search_by_key_4 (fs, key, &path) == ITEM_NOT_FOUND) {
|
||||
pathrelse (&path);
|
||||
return STAT_DATA_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* stat data has been found */
|
||||
ih = get_ih (&path);
|
||||
sd = get_item(&path);
|
||||
|
||||
get_sd_nlink (ih, sd, &nlink);
|
||||
relocate = should_be_relocated(&ih->ih_key);
|
||||
|
||||
if (fix_obviously_wrong_sd_mode (&path)) {
|
||||
one_more_corruption (fs, fixable);
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (not_a_directory (sd)) {
|
||||
fsck_check_stat (fs)->files ++;
|
||||
retval = check_check_regular_file (&path, sd, relocate ? new_ih : 0);
|
||||
pathrelse (&path);
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (relocate) {
|
||||
if (!new_ih)
|
||||
reiserfs_panic ("check_semantic_pass: can not relocate %K",
|
||||
&ih->ih_key);
|
||||
*new_ih = *ih;
|
||||
pathrelse (&path);
|
||||
sem_pass_stat (fs)->oid_sharing_dirs_relocated ++;
|
||||
relocate_dir (new_ih, 1);
|
||||
one_less_corruption (fs, fixable);
|
||||
*key = new_ih->ih_key;
|
||||
retval = RELOCATED;
|
||||
goto start_again;
|
||||
}
|
||||
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
/* it looks like stat data of a directory found */
|
||||
if (nlink) {
|
||||
/* we saw this directory already */
|
||||
if (!dot_dot) {
|
||||
/* this name is not ".." - and hard links are not allowed on
|
||||
directories */
|
||||
pathrelse (&path);
|
||||
return STAT_DATA_NOT_FOUND;
|
||||
} else {
|
||||
/* ".." found */
|
||||
nlink ++;
|
||||
set_sd_nlink (ih, sd, &nlink);
|
||||
mark_buffer_dirty (get_bh (&path));
|
||||
pathrelse (&path);
|
||||
return OK;
|
||||
}
|
||||
} /*do not run it for dot_dot on check at all*/
|
||||
|
||||
nlink = 2;
|
||||
if (get_key_objectid (key) == REISERFS_ROOT_OBJECTID)
|
||||
nlink ++;
|
||||
set_sd_nlink (ih, sd, &nlink);
|
||||
mark_buffer_dirty (get_bh (&path));
|
||||
}
|
||||
|
||||
/* directory stat data found */
|
||||
if (get_ih_item_len (ih) == SD_SIZE)
|
||||
is_new_dir = 1;
|
||||
else
|
||||
is_new_dir = 0;
|
||||
|
||||
/* save stat data's size and st_blocks */
|
||||
get_sd_size (ih, sd, &saved_size);
|
||||
get_sd_blocks (ih, sd, &saved_blocks);
|
||||
get_sd_mode (ih, sd, &mode);
|
||||
|
||||
dir_format = (get_ih_item_len (get_ih (&path)) == SD_SIZE) ? KEY_FORMAT_2 : KEY_FORMAT_1;
|
||||
|
||||
/* release path pointing to stat data */
|
||||
pathrelse (&path);
|
||||
|
||||
fsck_check_stat (fs)->dirs ++;
|
||||
|
||||
set_key_dirid (&next_item_key, get_key_dirid (key));
|
||||
set_key_objectid (&next_item_key, get_key_objectid (key));
|
||||
set_key_offset_v1 (&next_item_key, DOT_OFFSET);
|
||||
set_key_uniqueness (&next_item_key, DIRENTRY_UNIQUENESS);
|
||||
|
||||
dir_size = 0;
|
||||
while ((dir_item = get_next_directory_item (&next_item_key, parent, &tmp_ih, &pos_in_item, dir_format)) != 0) {
|
||||
/* dir_item is copy of the item in separately allocated memory,
|
||||
item_key is a key of next item in the tree */
|
||||
int i;
|
||||
char * name = 0;
|
||||
int namelen, entry_len;
|
||||
struct reiserfs_de_head * deh = (struct reiserfs_de_head *)dir_item + pos_in_item;
|
||||
|
||||
|
||||
for (i = pos_in_item; i < get_ih_entry_count (&tmp_ih); i ++, deh ++) {
|
||||
struct item_head relocated_ih;
|
||||
|
||||
if (name) {
|
||||
free (name);
|
||||
name = 0;
|
||||
}
|
||||
|
||||
namelen = name_in_entry_length (&tmp_ih, deh, i);
|
||||
asprintf (&name, "%.*s", namelen, name_in_entry (deh, i));
|
||||
entry_len = entry_length (&tmp_ih, deh, i);
|
||||
|
||||
get_object_key (deh, &object_key, &entry_key, &tmp_ih);
|
||||
|
||||
if ((dir_format == KEY_FORMAT_2) && (entry_len % 8 != 0)) {
|
||||
/* not alighed directory of new format - delete it */
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
fsck_log ("name \"%.*s\" in directory %K of wrong format, %K - deleted\n",
|
||||
namelen, name, &tmp_ih.ih_key, (struct key *)&(deh->deh2_dir_id));
|
||||
reiserfs_remove_entry (fs, &entry_key);
|
||||
entry_len = name_length (name, dir_format);
|
||||
reiserfs_add_entry (fs, key, name, entry_len, (struct key *)&(deh->deh2_dir_id), 0);
|
||||
} else {
|
||||
fsck_log ("name \"%.*s\" in directory %K of wrong format, %K\n",
|
||||
namelen, name, &tmp_ih.ih_key, (struct key *)&(deh->deh2_dir_id));
|
||||
one_more_corruption (fs, fixable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print_name (name, namelen);
|
||||
|
||||
if (!is_properly_hashed (fs, name, namelen, get_deh_offset (deh))) {
|
||||
one_more_corruption (fs, fatal);
|
||||
fsck_log ("check_semantic_pass: hash mismatch detected (%.*s)\n", namelen, name);
|
||||
}
|
||||
|
||||
if (is_dot (name, namelen) || (is_dot_dot (name, namelen) &&
|
||||
(fsck_mode (fs) != FSCK_FIX_FIXABLE || get_key_objectid (&object_key) == REISERFS_ROOT_PARENT_OBJECTID))) {
|
||||
/* do not go through "." and ".." */
|
||||
retval = OK;
|
||||
} else {
|
||||
if ((retval = add_path_key (&object_key, (fsck_mode (fs) != FSCK_FIX_FIXABLE)? 1 : 0)) == 0) {
|
||||
retval = check_semantic_pass (&object_key, key, is_dot_dot(name, namelen), &relocated_ih);
|
||||
del_path_key ();
|
||||
}
|
||||
}
|
||||
|
||||
erase_name (namelen);
|
||||
|
||||
/* check what check_semantic_tree returned */
|
||||
switch (retval) {
|
||||
case OK:
|
||||
dir_size += DEH_SIZE + entry_len;
|
||||
break;
|
||||
|
||||
case STAT_DATA_NOT_FOUND:
|
||||
fsck_log ("check_semantic_pass: name \"%.*s\" in directory %K points to nowhere",
|
||||
namelen, name, &tmp_ih.ih_key);
|
||||
case LOOP_FOUND:
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
reiserfs_remove_entry (fs, &entry_key);
|
||||
fsck_log (" - removed");
|
||||
} else {
|
||||
one_more_corruption (fs, fixable);
|
||||
}
|
||||
fsck_log ("\n");
|
||||
break;
|
||||
|
||||
case DIRECTORY_HAS_NO_ITEMS:
|
||||
fsck_log ("check_semantic_pass: name \"%.*s\" in directory %K points dir without body\n",
|
||||
namelen, name, &tmp_ih.ih_key);
|
||||
|
||||
/* fixme: stat data should be deleted as well */
|
||||
/*
|
||||
if (fsck_fix_fixable (fs)) {
|
||||
reiserfs_remove_entry (fs, &entry_key);
|
||||
fsck_data(fs)->deleted_entries ++;
|
||||
fsck_log (" - removed");
|
||||
}
|
||||
fsck_log ("\n");*/
|
||||
break;
|
||||
|
||||
case RELOCATED:
|
||||
/* file was relocated, update key in corresponding directory entry */
|
||||
if (reiserfs_search_by_entry_key (fs, &entry_key, &path) != POSITION_FOUND) {
|
||||
fsck_progress ("could not find name of relocated file\n");
|
||||
} else {
|
||||
/* update key dir entry points to */
|
||||
struct reiserfs_de_head * tmp_deh;
|
||||
|
||||
tmp_deh = B_I_DEH (get_bh (&path), get_ih (&path)) + path.pos_in_item;
|
||||
fsck_log ("name \"%.*s\" of dir %K pointing to %K updated to point to ",
|
||||
namelen, name, &tmp_ih.ih_key, &tmp_deh->deh2_dir_id);
|
||||
set_deh_dirid (tmp_deh, get_key_dirid (&relocated_ih.ih_key));
|
||||
set_deh_objectid (tmp_deh, get_key_objectid (&relocated_ih.ih_key));
|
||||
|
||||
fsck_log ("%K\n", &tmp_deh->deh2_dir_id);
|
||||
mark_buffer_dirty (get_bh (&path));
|
||||
}
|
||||
dir_size += DEH_SIZE + entry_len;
|
||||
pathrelse (&path);
|
||||
break;
|
||||
}
|
||||
} /* for */
|
||||
|
||||
freemem (dir_item);
|
||||
free (name);
|
||||
name = 0;
|
||||
|
||||
if (not_of_one_file (&next_item_key, key))
|
||||
/* next key is not of this directory */
|
||||
break;
|
||||
|
||||
} /* while (dir_item) */
|
||||
|
||||
|
||||
if (dir_size == 0)
|
||||
/* FIXME: is it possible? */
|
||||
return DIRECTORY_HAS_NO_ITEMS;
|
||||
|
||||
/* calc correct value of sd_blocks field of stat data */
|
||||
blocks = dir_size2st_blocks (dir_size);
|
||||
|
||||
fix_sd = 0;
|
||||
fix_sd += wrong_st_blocks (key, &blocks, saved_blocks, mode, is_new_dir);
|
||||
fix_sd += wrong_st_size (key, is_new_dir ? MAX_FILE_SIZE_V2 : MAX_FILE_SIZE_V1,
|
||||
fs->fs_blocksize, &dir_size, saved_size, 1/*dir*/);
|
||||
|
||||
if (fix_sd) {
|
||||
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
|
||||
/* we have to fix either sd_size or sd_blocks, so look for stat data again */
|
||||
if (reiserfs_search_by_key_4 (fs, key, &path) != ITEM_FOUND) {
|
||||
fsck_log ("check_semantic_tree: stat data not found");
|
||||
one_more_corruption(fs, fatal);
|
||||
return STAT_DATA_NOT_FOUND;
|
||||
}
|
||||
|
||||
bh = get_bh (&path);
|
||||
ih = get_ih (&path);
|
||||
sd = get_item (&path);
|
||||
|
||||
set_sd_size (ih, sd, &dir_size);
|
||||
set_sd_blocks (ih, sd, &blocks);
|
||||
mark_buffer_dirty (bh);
|
||||
pathrelse (&path);
|
||||
} else {
|
||||
fsck_check_stat (fs)->fixable_corruptions += fix_sd;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int check_safe_links ()
|
||||
{
|
||||
struct path safe_link_path, path;
|
||||
struct key safe_link_key = {-1, 0, {{0, 0}}};
|
||||
struct key key = {0, 0, {{0, 0}}};
|
||||
struct key * rkey;
|
||||
struct item_head * tmp_ih;
|
||||
|
||||
while (1) {
|
||||
if (get_key_dirid (&safe_link_key) == 0)
|
||||
break;
|
||||
|
||||
reiserfs_search_by_key_4 (fs, &safe_link_key, &safe_link_path);
|
||||
|
||||
if (get_blkh_nr_items ( B_BLK_HEAD (get_bh(&safe_link_path))) <= PATH_LAST_POSITION (&safe_link_path)) {
|
||||
pathrelse (&safe_link_path);
|
||||
break;
|
||||
}
|
||||
|
||||
tmp_ih = get_ih(&safe_link_path);
|
||||
|
||||
if (get_key_dirid(&tmp_ih->ih_key) != (__u32)-1 ||
|
||||
get_key_objectid(&tmp_ih->ih_key) == (__u32)-1) {
|
||||
pathrelse (&safe_link_path);
|
||||
break;
|
||||
}
|
||||
|
||||
if (get_ih_item_len (tmp_ih) != 4)
|
||||
reiserfs_panic ("safe link cannot be of size %d", get_ih_item_len (tmp_ih));
|
||||
|
||||
set_key_dirid(&key, le32_to_cpu(*(__u32 *)get_item(&safe_link_path)));
|
||||
set_key_objectid(&key, get_key_objectid(&tmp_ih->ih_key));
|
||||
if ( (rkey = get_next_key_2 (&safe_link_path)) == NULL )
|
||||
set_key_dirid (&safe_link_key, 0);
|
||||
else
|
||||
safe_link_key = *rkey;
|
||||
|
||||
if (reiserfs_search_by_key_4 (fs, &key, &path) == ITEM_NOT_FOUND) {
|
||||
/*sware on check, delete on fix-fixable*/
|
||||
if (fsck_mode(fs) == FSCK_CHECK) {
|
||||
fsck_log ("invalid safe link, cannot find a pointed object (%K)\n", &key);
|
||||
one_more_corruption (fs, fixable);
|
||||
} else if (fsck_mode(fs) == FSCK_FIX_FIXABLE) {
|
||||
fsck_log ("invalid safe link, cannot find a pointed object (%K) - delete\n", &key);
|
||||
*(__u32 *)get_item(&safe_link_path) = (__u32)0;
|
||||
pathrelse (&path);
|
||||
reiserfsck_delete_item (&safe_link_path, 0);
|
||||
continue;
|
||||
}
|
||||
} else if (get_offset(&tmp_ih->ih_key) == 0x1) {
|
||||
if (!not_a_directory (get_item(&path))) {
|
||||
/*truncate on directory should not happen*/
|
||||
/*sware on check, delete on fix-fixable*/
|
||||
if (fsck_mode(fs) == FSCK_CHECK) {
|
||||
fsck_log ("invalid truncate safe link, cannot happen for directory (%K)\n", &key);
|
||||
one_more_corruption (fs, fixable);
|
||||
} else if (fsck_mode(fs) == FSCK_FIX_FIXABLE) {
|
||||
fsck_log ("invalid truncate safe link, cannot happen for directory (%K) - delete\n", &key);
|
||||
*(__u32 *)get_item(&safe_link_path) = (__u32)0;
|
||||
pathrelse (&path);
|
||||
reiserfsck_delete_item (&safe_link_path, 0);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
pathrelse (&path);
|
||||
pathrelse (&safe_link_path);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* called when --check is given */
|
||||
void semantic_check (void)
|
||||
{
|
||||
if (fsck_data (fs)->check.bad_nodes) {
|
||||
fsck_progress ("Bad nodes were found, Semantic pass skipped\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (fsck_data (fs)->check.fatal_corruptions) {
|
||||
fsck_progress ("Fatal corruptions were found, Semantic pass skipped\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
fsck_progress ("Checking Semantic tree...\n");
|
||||
|
||||
if (fsck_mode(fs) == FSCK_FIX_FIXABLE) {
|
||||
/*create new_bitmap, and initialize new_bitmap & allocable bitmap*/
|
||||
fsck_new_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_copy (fsck_new_bitmap (fs), fs->fs_bitmap2);
|
||||
fsck_allocable_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
reiserfs_bitmap_copy (fsck_allocable_bitmap (fs), fs->fs_bitmap2);
|
||||
fs->block_allocator = reiserfsck_reiserfs_new_blocknrs;
|
||||
fs->block_deallocator = reiserfsck_reiserfs_free_block;
|
||||
}
|
||||
|
||||
if (check_semantic_pass (&root_dir_key, &parent_root_dir_key, 0, 0) != OK) {
|
||||
fsck_log ("check_semantic_tree: no root directory found");
|
||||
one_more_corruption (fs, fatal);
|
||||
}
|
||||
|
||||
check_safe_links ();
|
||||
|
||||
if (fsck_mode(fs) == FSCK_FIX_FIXABLE) {
|
||||
reiserfs_delete_bitmap (fs->fs_bitmap2);
|
||||
fs->fs_bitmap2 = fsck_new_bitmap (fs);
|
||||
reiserfs_delete_bitmap (fsck_allocable_bitmap (fs));
|
||||
fsck_allocable_bitmap (fs) = NULL;
|
||||
set_sb_free_blocks (fs->fs_ondisk_sb, reiserfs_bitmap_zeros (fs->fs_bitmap2));
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
add_badblock_list(fs, 0);
|
||||
}
|
||||
|
||||
fsck_progress ("ok\n");
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
+552
@@ -0,0 +1,552 @@
|
||||
#include "fsck.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define fsck_conditional_log(sb_found, fmt, list...) { \
|
||||
if (sb_found) \
|
||||
fsck_log(fmt, ## list); \
|
||||
}
|
||||
|
||||
int what_fs_version ()
|
||||
{
|
||||
size_t n = 0;
|
||||
char * answer = 0;
|
||||
int version;
|
||||
printf("\nwhat is version of ReiserFS you use[1-4]\n"
|
||||
"\t(1) 3.6.x\n"
|
||||
"\t(2) >=3.5.9 (introduced in the middle of 1999) (if you use linux 2.2, choose this one)\n"
|
||||
"\t(3) < 3.5.9 converted to new format (don't choose if unsure)\n"
|
||||
"\t(4) < 3.5.9 (this is very old format, don't choose if unsure)\n"
|
||||
"\t(X) exit\n");
|
||||
getline (&answer, &n, stdin);
|
||||
version = atoi (answer);
|
||||
if (version < 1 || version > 4)
|
||||
die ("rebuild_sb: wrong version");
|
||||
return version;
|
||||
}
|
||||
|
||||
void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * data)
|
||||
{
|
||||
int version = 0;
|
||||
struct reiserfs_super_block * ondisk_sb = 0;
|
||||
struct reiserfs_super_block * sb = 0;
|
||||
|
||||
int magic_was_found = 0;
|
||||
unsigned long block_count = 0;
|
||||
__u16 p_oid_maxsize;
|
||||
__u16 p_bmap_nr;
|
||||
__u32 p_jp_journal_1st_block = 0;
|
||||
__u32 p_jp_dev_size = 0;
|
||||
int standard_journal = -1;
|
||||
char * journal_dev_name = 0;
|
||||
char * tmp;
|
||||
int sb_size;
|
||||
|
||||
char * answer = 0;
|
||||
size_t n = 0;
|
||||
struct stat stat_buf;
|
||||
int retval;
|
||||
|
||||
if (!no_reiserfs_found (fs)) {
|
||||
sb = getmem (sizeof (*sb));
|
||||
if (!is_opened_rw (fs)) {
|
||||
close (fs->fs_dev);
|
||||
fs->fs_dev = open (fs->fs_file_name, O_RDWR | O_LARGEFILE);
|
||||
}
|
||||
|
||||
if (!is_blocksize_correct (fs->fs_blocksize)) {
|
||||
printf("\nCannot find a proper blocksize, enter block size [4096]: \n");
|
||||
getline (&answer, &n, stdin);
|
||||
if (strcmp(answer, "\n")) {
|
||||
retval = (int) strtol (answer, &tmp, 0);
|
||||
if ((*tmp && strcmp(tmp, "\n")) || retval < 0)
|
||||
reiserfs_exit (1, "rebuild_sb: wrong block size specified\n");
|
||||
if (!is_blocksize_correct (retval))
|
||||
reiserfs_exit (1, "rebuild_sb: wrong block size specified, only divisible by 1024 are supported currently\n");
|
||||
} else
|
||||
retval = 4096;
|
||||
|
||||
fs->fs_blocksize = retval;
|
||||
}
|
||||
|
||||
block_count = count_blocks (filename, fs->fs_blocksize);
|
||||
|
||||
/* save ondisk_sb somewhere and work in temp area */
|
||||
ondisk_sb = fs->fs_ondisk_sb;
|
||||
memcpy (sb, fs->fs_ondisk_sb, sizeof (*sb));
|
||||
fs->fs_ondisk_sb = sb;
|
||||
|
||||
if (is_reiserfs_3_6_magic_string (sb)) {
|
||||
/* 3_6 magic */
|
||||
if (fsck_data (fs)->journal_dev_name)
|
||||
/* journal dev must not be specified with standard journal */
|
||||
reiserfs_exit (1, "Reiserfs with standard journal found, but there was specified a journal dev");
|
||||
|
||||
if (get_jp_journal_1st_block(sb_jp(sb)) == get_journal_new_start_must (fs))
|
||||
version = 1;
|
||||
else if (get_jp_journal_1st_block(sb_jp(sb)) == get_journal_old_start_must (fs))
|
||||
version = 3;
|
||||
magic_was_found = 2;
|
||||
} else if (is_reiserfs_3_5_magic_string (sb)) {
|
||||
if (fsck_data (fs)->journal_dev_name)
|
||||
/* journal dev must not be specified with standard journal */
|
||||
reiserfs_exit (1, "Reiserfs with standard journal found, but there was specified a journal dev");
|
||||
|
||||
/* 3_5 magic */
|
||||
if (get_jp_journal_1st_block(sb_jp(sb)) == get_journal_new_start_must (fs))
|
||||
version = 2;
|
||||
else if (get_jp_journal_1st_block(sb_jp(sb)) == get_journal_old_start_must (fs))
|
||||
version = 4;
|
||||
magic_was_found = 1;
|
||||
} else if (is_reiserfs_jr_magic_string (sb)) {
|
||||
if (!fsck_data (fs)->journal_dev_name)
|
||||
/* journal dev must be specified with non standard journal */
|
||||
reiserfs_exit (1, "Reiserfs with non standard journal found, but there was not specified any journal dev");
|
||||
|
||||
if (get_sb_version (sb) == REISERFS_FORMAT_3_6) {
|
||||
/*non-standard magic + sb_format == 3_6*/
|
||||
if (get_jp_journal_1st_block(sb_jp(sb)) == get_journal_new_start_must (fs))
|
||||
version = 1;
|
||||
else if (get_jp_journal_1st_block(sb_jp(sb)) == get_journal_old_start_must (fs))
|
||||
version = 3;
|
||||
magic_was_found = 3;
|
||||
} else if (get_sb_version (sb) == REISERFS_FORMAT_3_5) {
|
||||
/* non-standard magic + sb_format == 3_5 */
|
||||
if (get_jp_journal_1st_block(sb_jp(sb)) == get_journal_new_start_must (fs))
|
||||
version = 2;
|
||||
else if (get_jp_journal_1st_block(sb_jp(sb)) == get_journal_old_start_must (fs))
|
||||
version = 4;
|
||||
magic_was_found = 3;
|
||||
} else {
|
||||
/* non-standard magic + bad sb_format */
|
||||
version = 0;
|
||||
magic_was_found = 3;
|
||||
}
|
||||
} else
|
||||
reiserfs_exit (1, "we opened device but there is no magic and there is no correct superbblock format found");
|
||||
|
||||
if (magic_was_found == 1 || magic_was_found == 2)
|
||||
standard_journal = 1;
|
||||
else
|
||||
standard_journal = 0;
|
||||
|
||||
if (version == 0)
|
||||
version = what_fs_version ();
|
||||
|
||||
if (get_sb_block_count (sb) != block_count) {
|
||||
do {
|
||||
printf("\nDid you use resiser(y/n)[n]: ");
|
||||
getline (&answer, &n, stdin);
|
||||
} while (strcmp ("y\n", answer) && strcmp ("n\n", answer) && strcmp ("\n", answer));
|
||||
if (!strcmp ("y\n", answer)) {
|
||||
printf("\nEnter partition size [%lu]: ", block_count);
|
||||
getline (&answer, &n, stdin);
|
||||
if (strcmp ("\n", answer))
|
||||
block_count = atoi (answer);
|
||||
set_sb_block_count (sb, block_count);
|
||||
} else {
|
||||
fsck_conditional_log (magic_was_found, "rebuild-sb: wrong block count occured (%lu), fixed (%lu)\n",
|
||||
get_sb_block_count(sb), block_count);
|
||||
set_sb_block_count (sb, block_count);
|
||||
}
|
||||
}
|
||||
|
||||
if (get_sb_block_size (sb) != fs->fs_blocksize) {
|
||||
fsck_log("rebuild-sb: wrong block size occured (%lu), fixed (%lu)\n", get_sb_block_size (sb), fs->fs_blocksize);
|
||||
set_sb_block_size (sb, fs->fs_blocksize);
|
||||
}
|
||||
}
|
||||
|
||||
/* if no reiserfs_found or bad data found in that SB, what was checked in previous clause */
|
||||
if (no_reiserfs_found (fs)) {
|
||||
int fd;
|
||||
|
||||
fd = open (filename, O_RDWR | O_LARGEFILE);
|
||||
|
||||
if (fd == -1)
|
||||
reiserfs_exit (1, "rebuils_sb: cannot open device %s", filename);
|
||||
|
||||
version = what_fs_version ();
|
||||
|
||||
if (version == 3 || version == 4) {
|
||||
retval = 4096;
|
||||
} else {
|
||||
printf("\nEnter block size [4096]: \n");
|
||||
getline (&answer, &n, stdin);
|
||||
if (strcmp(answer, "\n")) {
|
||||
retval = (int) strtol (answer, &tmp, 0);
|
||||
if ((*tmp && strcmp(tmp, "\n")) || retval < 0)
|
||||
reiserfs_exit (1, "rebuild_sb: wrong block size specified\n");
|
||||
if (!is_blocksize_correct (retval))
|
||||
reiserfs_exit (1, "rebuild_sb: wrong block size specified, only divisible by 1024 are supported currently\n");
|
||||
} else
|
||||
retval = 4096;
|
||||
}
|
||||
|
||||
block_count = count_blocks (filename, retval);
|
||||
|
||||
switch(version){
|
||||
case 1:
|
||||
fs = reiserfs_create (filename, REISERFS_FORMAT_3_6, block_count, retval, 1, 1);
|
||||
break;
|
||||
case 2:
|
||||
fs = reiserfs_create (filename, REISERFS_FORMAT_3_5, block_count, retval, 1, 1);
|
||||
break;
|
||||
case 3:
|
||||
fs = reiserfs_create (filename, REISERFS_FORMAT_3_6, block_count, retval, 1, 0);
|
||||
break;
|
||||
case 4:
|
||||
fs = reiserfs_create (filename, REISERFS_FORMAT_3_5, block_count, retval, 1, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
fs->fs_vp = data;
|
||||
|
||||
if (!fsck_skip_journal (fs)) {
|
||||
if (!fsck_data (fs)->journal_dev_name) {
|
||||
do {
|
||||
printf("\nNo journal device was specified. (If journal is not available, re-run with --no-journal-available).\n"\
|
||||
"Is journal standard? (y/n)[y]: ");
|
||||
getline (&answer, &n, stdin);
|
||||
} while (strcmp ("y\n", answer) && strcmp ("n\n", answer) && strcmp ("\n", answer));
|
||||
if (!strcmp ("n\n", answer)) {
|
||||
printf("\nSpecify journal device with -j option. Use \n");
|
||||
exit(1);
|
||||
}
|
||||
standard_journal = 1;
|
||||
} else {
|
||||
standard_journal = 0;
|
||||
memcpy (fs->fs_ondisk_sb->s_v1.s_magic, REISERFS_JR_SUPER_MAGIC_STRING,
|
||||
strlen (REISERFS_JR_SUPER_MAGIC_STRING));
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
printf("\nDid you use resiser(y/n)[n]: ");
|
||||
getline (&answer, &n, stdin);
|
||||
} while (strcmp ("y\n", answer) && strcmp ("n\n", answer) && strcmp ("\n", answer));
|
||||
if (!strcmp ("y\n", answer)) {
|
||||
printf("\nEnter partition size [%lu]: ", block_count);
|
||||
getline (&answer, &n, stdin);
|
||||
if (strcmp ("\n", answer))
|
||||
block_count = atoi (answer);
|
||||
set_sb_block_count (sb, block_count);
|
||||
}
|
||||
|
||||
set_sb_fs_state (sb, REISERFS_CORRUPTED);
|
||||
}
|
||||
|
||||
|
||||
if (version == 1 || version == 3) {
|
||||
if (get_reiserfs_format (sb) != REISERFS_FORMAT_3_6) {
|
||||
fsck_log("rebuild-sb: wrong reiserfs version occured (%lu), fixed (%lu)\n", get_reiserfs_format (sb), REISERFS_FORMAT_3_6);
|
||||
set_sb_version (sb, REISERFS_FORMAT_3_6);
|
||||
}
|
||||
} else if (version == 2 || version == 4) {
|
||||
if (get_reiserfs_format (sb) != REISERFS_FORMAT_3_5) {
|
||||
fsck_log("rebuild-sb: wrong reiserfs version occured (%lu), fixed (%lu)\n", get_reiserfs_format (sb), REISERFS_FORMAT_3_5);
|
||||
set_sb_version (sb, REISERFS_FORMAT_3_5);
|
||||
}
|
||||
}
|
||||
|
||||
p_oid_maxsize = (fs->fs_blocksize - reiserfs_super_block_size (sb)) / sizeof(__u32) / 2 * 2;
|
||||
if (get_sb_oid_maxsize (sb) != p_oid_maxsize) {
|
||||
fsck_log("rebuild-sb: wrong objectid map max size occured (%lu), fixed (%lu)\n", get_sb_oid_maxsize (sb), p_oid_maxsize);
|
||||
set_sb_oid_maxsize (sb, p_oid_maxsize);
|
||||
}
|
||||
|
||||
p_bmap_nr = (block_count + (fs->fs_blocksize * 8 - 1)) / (fs->fs_blocksize * 8);
|
||||
if (get_sb_bmap_nr (sb) != p_bmap_nr) {
|
||||
fsck_log("rebuild-sb: wrong bitmap number occured (%lu), fixed (%lu)\n", get_sb_bmap_nr (sb), p_bmap_nr);
|
||||
set_sb_bmap_nr (sb, (block_count + (fs->fs_blocksize * 8 - 1)) / (fs->fs_blocksize * 8));
|
||||
}
|
||||
|
||||
if (get_sb_root_block (sb) > block_count) {
|
||||
fsck_log("rebuild-sb: wrong root block occured (%lu), zeroed\n", get_sb_root_block (sb));
|
||||
set_sb_root_block (sb, 0);
|
||||
}
|
||||
|
||||
if (get_sb_free_blocks (sb) > block_count) {
|
||||
fsck_log ("rebuild-sb: wrong free block count occured (%lu), zeroed\n", get_sb_free_blocks (sb));
|
||||
set_sb_free_blocks (sb, 0);
|
||||
}
|
||||
|
||||
if (get_sb_umount_state (sb) != REISERFS_CLEANLY_UMOUNTED && get_sb_umount_state (sb) != REISERFS_NOT_CLEANLY_UMOUNTED) {
|
||||
fsck_conditional_log (magic_was_found, "rebuild-sb: wrong umount state, fixed to (REISERFS_NOT_CLEANLY_UMOUNTED)\n",
|
||||
get_sb_umount_state (sb));
|
||||
set_sb_umount_state (sb, REISERFS_NOT_CLEANLY_UMOUNTED);
|
||||
}
|
||||
|
||||
if (get_sb_oid_cursize (sb) == 1 || get_sb_oid_cursize (sb) > get_sb_oid_maxsize (sb)) {
|
||||
fsck_log("rebuild-sb: wrong objectid map occured (%lu), zeroed\n", get_sb_oid_cursize (sb));
|
||||
set_sb_oid_cursize (sb, 0);
|
||||
}
|
||||
|
||||
if ( get_sb_tree_height (sb) &&
|
||||
((get_sb_tree_height (sb) < DISK_LEAF_NODE_LEVEL + 1) ||
|
||||
(get_sb_tree_height (sb) > MAX_HEIGHT)) ) {
|
||||
fsck_log("rebuild-sb: wrong tree height occured, zeroed\n", get_sb_tree_height (sb));
|
||||
set_sb_tree_height (sb, 0);
|
||||
}
|
||||
|
||||
if (get_sb_hash_code (sb) && code2name (get_sb_hash_code (sb)) == 0) {
|
||||
fsck_log("rebuild-sb: wrong hash occured (%lu), zeroed\n", get_sb_hash_code (sb));
|
||||
set_sb_hash_code (sb, 0);
|
||||
}
|
||||
|
||||
if (version == 1 || version == 3) {
|
||||
if (!uuid_is_correct(sb->s_uuid)) {
|
||||
if (generate_random_uuid (sb->s_uuid)) {
|
||||
fsck_log ("rebuild-sb: no uuid found, failed to genetate UUID\n");
|
||||
} else {
|
||||
fsck_log ("rebuild-sb: no uuid found, a new uuid generated (%U)\n", sb->s_uuid);
|
||||
}
|
||||
}
|
||||
if (sb->s_flags != 0 && sb->s_flags != 1) {
|
||||
fsck_log ("rebuild-sb: super block flags found, zeroed\n",
|
||||
sb->s_flags);
|
||||
sb->s_flags = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if we have a standard journal
|
||||
reserved = 0
|
||||
dev - same
|
||||
size = journal_default_size(fs->fs_super_bh->b_blocknr, fs)
|
||||
offset = journal_default_size(fs)
|
||||
if we have a non standard journal
|
||||
if we found magic string
|
||||
try to find a jhead and comare dev, size, offset there
|
||||
if params are not equal move to "if we did not find a magic string" clause
|
||||
if we did not find a magic string
|
||||
ask user about his journal
|
||||
try to find a jhead and comare dev, size, offset there
|
||||
if params are not equal exit with error
|
||||
*/
|
||||
|
||||
|
||||
p_jp_journal_1st_block = get_journal_start_must (fs);
|
||||
|
||||
if (!fsck_skip_journal (fs) && standard_journal == 1) {
|
||||
if (get_jp_journal_dev (sb_jp(sb)) != 0) {
|
||||
fsck_conditional_log (magic_was_found, "rebuild-sb: wrong journal device occured (%lu), fixed (0)\n",
|
||||
get_jp_journal_dev (sb_jp(sb)));
|
||||
set_jp_journal_dev (sb_jp(sb), 0);
|
||||
}
|
||||
if (get_sb_reserved_for_journal (sb) != 0) {
|
||||
fsck_log ("rebuild-sb: wrong size reserved for standard journal occured (%lu), fixed (0)\n",
|
||||
get_sb_reserved_for_journal (sb));
|
||||
set_sb_reserved_for_journal (sb, 0);
|
||||
}
|
||||
if (get_jp_journal_1st_block (sb_jp(sb)) != p_jp_journal_1st_block) {
|
||||
fsck_conditional_log (magic_was_found, "rebuild-sb: wrong journal first block occured (%lu), fixed (%lu)\n",
|
||||
get_jp_journal_1st_block (sb_jp(sb)), p_jp_journal_1st_block);
|
||||
set_jp_journal_1st_block (sb_jp(sb) , p_jp_journal_1st_block);
|
||||
}
|
||||
if (get_jp_journal_size (sb_jp(sb)) != journal_default_size(fs->fs_super_bh->b_blocknr, fs->fs_blocksize)) {
|
||||
fsck_conditional_log (magic_was_found, "rebuild-sb: wrong journal size occured (%lu), fixed (%lu)\n",
|
||||
get_jp_journal_size (sb_jp(sb)) + 1,
|
||||
journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize) + 1);
|
||||
set_jp_journal_size (sb_jp(sb), journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize));
|
||||
}
|
||||
if (get_jp_journal_max_trans_len (sb_jp(sb)) !=
|
||||
advise_journal_max_trans_len( get_jp_journal_max_trans_len (sb_jp(sb)),
|
||||
get_jp_journal_size (sb_jp(sb)),
|
||||
fs->fs_blocksize))
|
||||
{
|
||||
fsck_conditional_log (magic_was_found, "rebuild-sb: wrong journal max transaction length occured (%lu), fixed (%d)\n",
|
||||
get_jp_journal_max_trans_len (sb_jp(sb)),
|
||||
advise_journal_max_trans_len ( get_jp_journal_max_trans_len (sb_jp(sb)),
|
||||
get_jp_journal_size (sb_jp(sb)),
|
||||
fs->fs_blocksize));
|
||||
set_jp_journal_max_trans_len (sb_jp(sb),
|
||||
advise_journal_max_trans_len( get_jp_journal_max_trans_len (sb_jp(sb)),
|
||||
get_jp_journal_size (sb_jp(sb)),
|
||||
fs->fs_blocksize));
|
||||
}
|
||||
/* if (get_jp_journal_magic (sb_jp(sb)) != 0) {
|
||||
fsck_log ("rebuild-sb: wrong journal magic occured (%lu), fixed (0)\n", get_jp_journal_magic (sb_jp(sb)));
|
||||
set_jp_journal_magic (sb_jp(sb), 0);
|
||||
}*/
|
||||
if (get_jp_journal_max_batch (sb_jp(sb)) != advise_journal_max_batch(get_jp_journal_max_trans_len (sb_jp(sb)))) {
|
||||
fsck_conditional_log (magic_was_found, "rebuild-sb: wrong journal max batch size occured (%lu), fixed (%d)\n",
|
||||
get_jp_journal_max_batch (sb_jp(sb)), advise_journal_max_batch(get_jp_journal_max_trans_len (sb_jp(sb))));
|
||||
set_jp_journal_max_batch (sb_jp(sb), advise_journal_max_batch(get_jp_journal_max_trans_len (sb_jp(sb))));
|
||||
}
|
||||
if (get_jp_journal_max_commit_age (sb_jp(sb)) != advise_journal_max_commit_age()) {
|
||||
fsck_conditional_log (magic_was_found, "rebuild-sb: wrong journal max commit age occured (%lu), fixed (%d)\n",
|
||||
get_jp_journal_max_commit_age (sb_jp(sb)), advise_journal_max_commit_age());
|
||||
set_jp_journal_max_commit_age (sb_jp(sb), advise_journal_max_commit_age());
|
||||
}
|
||||
if (get_jp_journal_max_trans_age (sb_jp(sb)) != advise_journal_max_trans_age()) {
|
||||
fsck_log ("rebuild-sb: wrong journal max commit age occured (%lu), fixed (0)\n",
|
||||
get_jp_journal_max_trans_age (sb_jp(sb)), advise_journal_max_trans_age());
|
||||
set_jp_journal_max_trans_age (sb_jp(sb), advise_journal_max_trans_age());
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else if (!fsck_skip_journal(fs) && standard_journal == 0) {
|
||||
/* non standard journal */
|
||||
struct reiserfs_journal_header * jh;
|
||||
|
||||
journal_dev_name = fsck_data (fs)->journal_dev_name;
|
||||
retval = stat(journal_dev_name, &stat_buf);
|
||||
if (retval == -1)
|
||||
reiserfs_exit (1, "rebuild_sb: wrong journal device specified\n");
|
||||
if (strcmp (fs->fs_file_name, journal_dev_name))
|
||||
set_jp_journal_dev (sb_jp(sb), stat_buf.st_rdev);
|
||||
else
|
||||
set_jp_journal_dev (sb_jp(sb), 0);
|
||||
|
||||
/*
|
||||
if (journal_dev_name == 0) {
|
||||
// ask user about the dev
|
||||
printf("\nEnter dev with journal[%s]: \n", fs->fs_file_name);
|
||||
getline (&answer, &n, stdin);
|
||||
if (strcmp(answer, "\n")) {
|
||||
journal_dev_name = malloc (strlen(answer));
|
||||
strncpy(journal_dev_name, answer, strlen(answer) - 1);
|
||||
retval = stat(journal_dev_name, &stat_buf);
|
||||
if (retval == -1)
|
||||
die ("rebuild_sb: wrong device specified\n");
|
||||
if (strcmp (fs->fs_file_name, journal_dev_name))
|
||||
set_jp_journal_dev (sb_jp(sb), stat_buf.st_rdev);
|
||||
else
|
||||
set_jp_journal_dev (sb_jp(sb), 0);
|
||||
} else {
|
||||
set_jp_journal_dev (sb_jp(sb), 0);
|
||||
journal_dev_name = fs->fs_file_name;
|
||||
}
|
||||
}
|
||||
*/
|
||||
retval = -1;
|
||||
if (magic_was_found == 0 || (retval = reiserfs_open_journal (fs, journal_dev_name, O_RDONLY)) == 0) {
|
||||
__u64 default_value;
|
||||
/* journal header was not found or journal cannot be opened -> adjust journal size and offset */
|
||||
|
||||
/* default offset if magic was not found is 0 for relocated journal and get_journal_start_must
|
||||
for any journal on the same device;
|
||||
default offset if magic was found is found value */
|
||||
if (retval == 0)
|
||||
fsck_log ("Journal cannot be opened, assuming specified journal device is correct\n");
|
||||
|
||||
if (magic_was_found == 0)
|
||||
default_value = (!strcmp(fs->fs_file_name, journal_dev_name)) ? p_jp_journal_1st_block : 0;
|
||||
else
|
||||
default_value = get_jp_journal_1st_block (sb_jp(sb));
|
||||
|
||||
printf("\nEnter journal offset on %s in blocks [%Lu]: \n",
|
||||
journal_dev_name, (unsigned long long)default_value);
|
||||
|
||||
getline (&answer, &n, stdin);
|
||||
if (strcmp(answer, "\n")) {
|
||||
retval = (int) strtol (answer, &tmp, 0);
|
||||
if ((*tmp && strcmp(tmp, "\n")) || retval < 0)
|
||||
reiserfs_exit (1, "rebuild_sb: wrong offset specified\n");
|
||||
set_jp_journal_1st_block (sb_jp(sb), retval);
|
||||
} else
|
||||
set_jp_journal_1st_block (sb_jp(sb), default_value);
|
||||
|
||||
p_jp_dev_size = count_blocks (journal_dev_name, fs->fs_blocksize);
|
||||
/* some checks for journal offset */
|
||||
if (strcmp(fs->fs_file_name, journal_dev_name) != 0) {
|
||||
if (p_jp_dev_size < get_jp_journal_1st_block (sb_jp(sb)) + 1)
|
||||
reiserfs_exit (1, "rebuild_sb: offset is much then device size\n");
|
||||
}
|
||||
|
||||
/* default size if magic was not found is device size - journal_1st_block;
|
||||
default size if magic was found is found value + 1 block for journal header */
|
||||
if (magic_was_found == 0)
|
||||
default_value = (!strcmp(fs->fs_file_name, journal_dev_name)) ?
|
||||
journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize) + 1 :
|
||||
p_jp_dev_size - get_jp_journal_1st_block (sb_jp(sb));
|
||||
else
|
||||
default_value = get_jp_journal_size (sb_jp(sb)) + 1;
|
||||
|
||||
|
||||
printf("\nEnter journal size (including 1 block for journal header) on %s in blocks [%Lu]: \n",
|
||||
journal_dev_name, (unsigned long long)default_value);
|
||||
|
||||
getline (&answer, &n, stdin);
|
||||
if (strcmp(answer, "\n")) {
|
||||
retval = (int) strtol (answer, &tmp, 0);
|
||||
if ((*tmp && strcmp(tmp, "\n")) || retval < 0)
|
||||
reiserfs_exit (1, "rebuild_sb: wrong offset specified\n");
|
||||
set_jp_journal_size (sb_jp(sb), retval - 1);
|
||||
} else {
|
||||
set_jp_journal_size (sb_jp(sb), default_value - 1);
|
||||
}
|
||||
|
||||
/* some checks for journal size */
|
||||
if (get_jp_journal_size (sb_jp(sb)) +
|
||||
get_jp_journal_1st_block (sb_jp(sb)) + 1 > p_jp_dev_size)
|
||||
reiserfs_exit (1, "rebuild_sb: journal offset + journal size is much then device size\n");
|
||||
|
||||
if (reiserfs_open_journal (fs, journal_dev_name, O_RDONLY) == 0)
|
||||
reiserfs_exit (1, "rebuild-sb: journal header is not found, wrong dev/offset/size configuration\n");
|
||||
}
|
||||
|
||||
jh = (struct reiserfs_journal_header *)fs->fs_jh_bh->b_data;
|
||||
memcpy (sb_jp(sb), &jh->jh_journal, sizeof (struct journal_params));
|
||||
} else {
|
||||
fsck_log ("Journal was specified as not available, zeroing all journal fields in super block..");
|
||||
set_jp_journal_dev (sb_jp(sb), 0);
|
||||
set_sb_reserved_for_journal (sb, 0);
|
||||
set_jp_journal_1st_block (sb_jp(sb) , 0);
|
||||
set_jp_journal_size (sb_jp(sb), 0);
|
||||
set_jp_journal_max_trans_len (sb_jp(sb), 0);
|
||||
set_jp_journal_max_batch (sb_jp(sb), 0);
|
||||
set_jp_journal_max_commit_age (sb_jp(sb), 0);
|
||||
set_jp_journal_max_commit_age (sb_jp(sb), 0);
|
||||
}
|
||||
|
||||
/* whether journal header contains params with the same dev, offset, size will be
|
||||
checked in open_journal */
|
||||
|
||||
if (version == 1 || version == 3)
|
||||
sb_size = SB_SIZE;
|
||||
else
|
||||
sb_size = SB_SIZE_V1;
|
||||
|
||||
if (!magic_was_found || memcmp(ondisk_sb, sb, sb_size -
|
||||
((sb_size == SB_SIZE) ? sizeof(fs->fs_ondisk_sb->s_unused) : 0)) )
|
||||
{
|
||||
/* smth was changed in SB or a new one has been built */
|
||||
set_sb_fs_state (sb, get_sb_fs_state (sb) || REISERFS_CORRUPTED);
|
||||
|
||||
if (ondisk_sb) {
|
||||
/* if super_block was found, we keep sb in ondisk_sb */
|
||||
fs->fs_ondisk_sb = ondisk_sb;
|
||||
memcpy (ondisk_sb, sb, sb_size);
|
||||
freemem(sb);
|
||||
}
|
||||
|
||||
print_block (stderr, fs, fs->fs_super_bh);
|
||||
|
||||
if (user_confirmed (stderr, "Is this ok ? (y/n)[n]: ", "y\n")) {
|
||||
mark_buffer_uptodate (fs->fs_super_bh, 1);
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
bwrite (fs->fs_super_bh);
|
||||
fsck_progress ("\nDo not forget to run reiserfsck --rebuild-tree\n\n");
|
||||
} else {
|
||||
mark_buffer_clean (fs->fs_super_bh);
|
||||
fsck_progress ("Super block was not written\n");
|
||||
}
|
||||
} else {
|
||||
print_block (stderr, fs, fs->fs_super_bh);
|
||||
|
||||
mark_buffer_clean (fs->fs_super_bh);
|
||||
fsck_progress ("\nSuper block seems to be correct\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* if (version == 0) {
|
||||
brelse (fs->fs_super_bh);
|
||||
freemem (fs);
|
||||
close (fs->fs_dev);
|
||||
fs = NULL;
|
||||
}
|
||||
*/
|
||||
+22
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-1999 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
|
||||
#include "fsck.h"
|
||||
@@ -40,11 +40,6 @@
|
||||
*/
|
||||
|
||||
|
||||
int is_to_be_read (reiserfs_filsys_t fs, unsigned long block)
|
||||
{
|
||||
return reiserfs_bitmap_test_bit (fsck_disk_bitmap (fs), block);
|
||||
}
|
||||
|
||||
|
||||
/* is blocks used (marked by 1 in new bitmap) in the tree which is being built
|
||||
(as leaf, internal, bitmap, or unformatted node) */
|
||||
@@ -54,12 +49,21 @@ int is_block_used (unsigned long block)
|
||||
}
|
||||
|
||||
|
||||
void mark_block_used (unsigned long block)
|
||||
void check_hardware_msg (void) {
|
||||
fprintf(stderr, "\nThe problem has occured looks like a hardware problem.\n"\
|
||||
"Send us the bug report only if the second run dies at the same place \n"\
|
||||
"with the same block number.\n");
|
||||
}
|
||||
|
||||
void mark_block_used (unsigned long block, int check_hardware)
|
||||
{
|
||||
if (!block)
|
||||
return;
|
||||
if (is_block_used (block))
|
||||
if (is_block_used (block)) {
|
||||
if (check_hardware)
|
||||
check_hardware_msg();
|
||||
die ("mark_block_used: (%lu) used already", block);
|
||||
}
|
||||
|
||||
reiserfs_bitmap_set_bit (fsck_new_bitmap (fs), block);
|
||||
}
|
||||
@@ -68,7 +72,7 @@ void mark_block_used (unsigned long block)
|
||||
void mark_block_free (unsigned long block)
|
||||
{
|
||||
if (!is_block_used (block))
|
||||
die ("mark_block_used: (%lu) is free", block);
|
||||
die ("mark_block_free: (%lu) is free already", block);
|
||||
|
||||
reiserfs_bitmap_clear_bit (fsck_new_bitmap (fs), block);
|
||||
}
|
||||
@@ -76,7 +80,7 @@ void mark_block_free (unsigned long block)
|
||||
|
||||
int is_block_uninsertable (unsigned long block)
|
||||
{
|
||||
return !reiserfs_bitmap_test_bit (uninsertable_leaf_bitmap, block);
|
||||
return !reiserfs_bitmap_test_bit (fsck_uninsertables (fs), block);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,11 +90,14 @@ void mark_block_uninsertable (unsigned long block)
|
||||
if (is_block_uninsertable (block))
|
||||
die ("mark_block_uninsertable: (%lu) is uninsertable already", block);
|
||||
|
||||
reiserfs_bitmap_clear_bit (uninsertable_leaf_bitmap, block);
|
||||
reiserfs_bitmap_clear_bit (fsck_uninsertables (fs), block);
|
||||
/* we do not need thsi actually */
|
||||
pass_1_stat (fs)->uninsertable_leaves ++;
|
||||
}
|
||||
|
||||
|
||||
int reiserfsck_reiserfs_new_blocknrs (reiserfs_filsys_t fs,
|
||||
/* FIXME: should be able to work around no disk space */
|
||||
int reiserfsck_reiserfs_new_blocknrs (reiserfs_filsys_t * fs,
|
||||
unsigned long * free_blocknrs,
|
||||
unsigned long start, int amount_needed)
|
||||
{
|
||||
@@ -102,7 +109,7 @@ int reiserfsck_reiserfs_new_blocknrs (reiserfs_filsys_t fs,
|
||||
free_blocknrs[i] = alloc_block ();
|
||||
if (!free_blocknrs[i])
|
||||
die ("reiserfs_new_blocknrs: 0 is allocated");
|
||||
mark_block_used (free_blocknrs[i]);
|
||||
mark_block_used (free_blocknrs[i], 0);
|
||||
}
|
||||
return CARRY_ON;
|
||||
}
|
||||
@@ -119,13 +126,13 @@ struct buffer_head * reiserfsck_get_new_buffer (unsigned long start)
|
||||
struct buffer_head * bh = NULL;
|
||||
|
||||
reiserfs_new_blocknrs (fs, &blocknr, start, 1);
|
||||
bh = getblk (fs->s_dev, blocknr, fs->s_blocksize);
|
||||
bh = getblk (fs->fs_dev, blocknr, fs->fs_blocksize);
|
||||
return bh;
|
||||
}
|
||||
|
||||
|
||||
/* free block in new bitmap */
|
||||
int reiserfsck_reiserfs_free_block (reiserfs_filsys_t fs, unsigned long block)
|
||||
int reiserfsck_reiserfs_free_block (reiserfs_filsys_t * fs, unsigned long block)
|
||||
{
|
||||
mark_block_free (block);
|
||||
|
||||
|
||||
+487
-337
File diff suppressed because it is too large.
Load diff
+160
-91
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-2001 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
#include "fsck.h"
|
||||
|
||||
@@ -10,25 +10,28 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* is it marked used in super block's objectid map */
|
||||
int is_objectid_used (reiserfs_filsys_t s, __u32 objectid)
|
||||
#if 0
|
||||
/* is it marked used in super block's objectid map. fixme: binary search could
|
||||
be used here */
|
||||
int is_objectid_used (reiserfs_filsys_t * fs, __u32 objectid)
|
||||
{
|
||||
__u32 * objectid_map;
|
||||
int i = 0;
|
||||
|
||||
objectid_map = (__u32 *)((char *)(s->s_rs) + (sb_size(s)));
|
||||
|
||||
while (i < SB_OBJECTID_MAP_SIZE (s)) {
|
||||
if (objectid == objectid_map[i]) {
|
||||
objectid_map = (__u32 *)((char *)(fs->fs_ondisk_sb) + (sb_size(fs)));
|
||||
|
||||
while (i < get_sb_oid_cursize (fs->fs_ondisk_sb)) {
|
||||
if (objectid == le32_to_cpu (objectid_map[i])) {
|
||||
return 1; /* objectid is used */
|
||||
}
|
||||
|
||||
if (objectid > objectid_map[i] && objectid < objectid_map[i+1]) {
|
||||
if (objectid > le32_to_cpu(objectid_map[i]) &&
|
||||
objectid < le32_to_cpu(objectid_map[i+1])) {
|
||||
return 1; /* objectid is used */
|
||||
}
|
||||
|
||||
if (objectid < objectid_map[i])
|
||||
if (objectid < le32_to_cpu(objectid_map[i]))
|
||||
break;
|
||||
|
||||
i += 2;
|
||||
@@ -37,25 +40,22 @@ int is_objectid_used (reiserfs_filsys_t s, __u32 objectid)
|
||||
/* objectid is free */
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* true objectid map */
|
||||
|
||||
|
||||
/* size of 1 piece of map */
|
||||
#define MAP_SIZE 4096 /* must be n * 2 * sizeof(__u32) */
|
||||
#define MAX_MAP_SIZE 1 /* % of available memory? */
|
||||
|
||||
|
||||
|
||||
/* increase area by MAP_SIZE bytes */
|
||||
static void grow_id_map (struct id_map * map)
|
||||
{
|
||||
/*
|
||||
if (map->m_page_count && ((map->m_page_count % 5) == 0)) {
|
||||
fsck_log ("grow_id_map: objectid map expanded: used %lu, %d blocks\n",
|
||||
map->m_used_slots_count, map->m_page_count);
|
||||
}
|
||||
*/
|
||||
map->m_begin = expandmem (map->m_begin, map->m_page_count * MAP_SIZE, MAP_SIZE);
|
||||
map->m_page_count ++;
|
||||
}
|
||||
@@ -64,9 +64,11 @@ static void grow_id_map (struct id_map * map)
|
||||
static void try_to_shrink_id_map (struct id_map * map)
|
||||
{
|
||||
if (map->m_used_slots_count * sizeof(__u32) <= (map->m_page_count - 1) * MAP_SIZE) {
|
||||
/*
|
||||
if (map->m_page_count && ((map->m_page_count % 5) == 0))
|
||||
fsck_log ("shrink_id_map: objectid map shrinked: used %lu, %d blocks\n",
|
||||
map->m_used_slots_count, map->m_page_count);
|
||||
*/
|
||||
map->m_begin = expandmem (map->m_begin, map->m_page_count * MAP_SIZE,
|
||||
-MAP_SIZE);
|
||||
map->m_page_count--;
|
||||
@@ -81,42 +83,26 @@ static void try_to_shrink_id_map (struct id_map * map)
|
||||
static void check_id_search_result(struct id_map * map, int res, __u32 pos,
|
||||
__u32 id)
|
||||
{
|
||||
if (res != ITEM_FOUND && res != ITEM_NOT_FOUND)
|
||||
if (res != POSITION_FOUND && res != POSITION_NOT_FOUND)
|
||||
die("check_id_search_result: get wrong result from ubin_search (%d)", res);
|
||||
|
||||
if (res == 1 && *(map->m_begin + pos) != id)
|
||||
die("check_id_search_result: wrong id found %u %u", id, *(map->m_begin + pos));
|
||||
if (res == 1 && le32_to_cpu (map->m_begin[pos]) != id)
|
||||
die("check_id_search_result: wrong id found %u %u", id, le32_to_cpu(map->m_begin[pos]));
|
||||
|
||||
if (res == 1)
|
||||
{
|
||||
if (pos > map->m_used_slots_count)
|
||||
die("check_id_search_result: get bad position (%u), used %u",
|
||||
pos, map->m_used_slots_count);
|
||||
if (pos >= 0 && pos <= map->m_used_slots_count && *(map->m_begin + pos - 1) >= id)
|
||||
if (pos >= 0 && pos <= map->m_used_slots_count && le32_to_cpu(map->m_begin[pos - 1]) >= id)
|
||||
die("check_id_search_result: previous id (%u) not less than (%u)",
|
||||
*(map->m_begin + pos - 1), id);
|
||||
if (pos >= 0 && pos < map->m_used_slots_count && *(map->m_begin + pos) < id)
|
||||
le32_to_cpu(map->m_begin[pos - 1]), id);
|
||||
if (pos >= 0 && pos < map->m_used_slots_count && le32_to_cpu(map->m_begin[pos]) < id)
|
||||
die("check_id_search_result: found id (%u) not much than (%u)",
|
||||
*(map->m_begin + pos), id);
|
||||
le32_to_cpu(map->m_begin[pos]), id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int comp_ids (void * p1, void * p2)
|
||||
{
|
||||
__u32 * id1, * id2;
|
||||
|
||||
id1 = p1;
|
||||
id2 = p2;
|
||||
|
||||
if ( *id1 < *id2 )
|
||||
return -1;
|
||||
if ( *id1 > *id2 )
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* */
|
||||
struct id_map * init_id_map (void)
|
||||
{
|
||||
@@ -132,18 +118,18 @@ struct id_map * init_id_map (void)
|
||||
|
||||
|
||||
/* free whole map */
|
||||
void free_id_map (struct id_map ** map)
|
||||
void free_id_map (struct id_map * map)
|
||||
{
|
||||
freemem ((*map)->m_begin);
|
||||
freemem (*map);
|
||||
*map = 0;
|
||||
freemem (map->m_begin);
|
||||
freemem (map);
|
||||
}
|
||||
|
||||
|
||||
/* return 1 if id is marked used, 0 otherwise */
|
||||
int is_objectid_really_used (struct id_map * map, __u32 id, int * ppos)
|
||||
int is_objectid_really_used (struct id_map * map, __u32 id, __u32 * ppos)
|
||||
{
|
||||
int res;
|
||||
__u32 le_id = cpu_to_le32 (id);
|
||||
|
||||
*ppos = 0;
|
||||
|
||||
@@ -151,13 +137,14 @@ int is_objectid_really_used (struct id_map * map, __u32 id, int * ppos)
|
||||
return 0;
|
||||
|
||||
/* smth exists in the map, find proper place to insert or this id */
|
||||
res = ubin_search (&id, map->m_begin, map->m_used_slots_count, sizeof (__u32), ppos, comp_ids);
|
||||
res = reiserfs_bin_search (&le_id, map->m_begin, map->m_used_slots_count,
|
||||
sizeof (__u32), ppos, comp_ids);
|
||||
#if 1
|
||||
check_id_search_result (map, res, *ppos, id);
|
||||
#endif
|
||||
/* *ppos is position in objectid map of the element which is equal id
|
||||
or position of an element which is smallest and greater than id */
|
||||
if (res == ITEM_NOT_FOUND)
|
||||
if (res == POSITION_NOT_FOUND)
|
||||
/* id is not found in the map. if returned position is odd -
|
||||
id is marked used */
|
||||
return (*ppos % 2);
|
||||
@@ -166,26 +153,30 @@ int is_objectid_really_used (struct id_map * map, __u32 id, int * ppos)
|
||||
return !(*ppos % 2);
|
||||
}
|
||||
|
||||
|
||||
static void check_objectid_map (struct id_map * map)
|
||||
static void check_objectid_map (struct id_map * map, int pos)
|
||||
{
|
||||
/* check only previous id, current and 2 next ones,
|
||||
if not specified to check evth */
|
||||
int count = 3;
|
||||
int i;
|
||||
int first = pos;
|
||||
|
||||
for (i = 1; i < map->m_used_slots_count; i ++)
|
||||
if (map->m_begin [i - 1] >= map->m_begin [i])
|
||||
if (first == 0) {
|
||||
first = 1;
|
||||
} else if (first == -1) {
|
||||
count = map->m_used_slots_count - 1;
|
||||
first = 1;
|
||||
}
|
||||
|
||||
if (first + count > map->m_used_slots_count)
|
||||
count = map->m_used_slots_count - first;
|
||||
|
||||
for (i = first; i < first + count; i ++)
|
||||
if (le32_to_cpu(map->m_begin [i - 1]) >= le32_to_cpu(map->m_begin [i]))
|
||||
die ("check_objectid_map: map corrupted");
|
||||
}
|
||||
|
||||
|
||||
/* returns 1 objectid is marked used already, 0 otherwise */
|
||||
int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
{
|
||||
int pos;
|
||||
|
||||
|
||||
/* check whether id is used and get place if used or place to insert if not */
|
||||
if (is_objectid_really_used (map, id, &pos) == 1)
|
||||
return 1;
|
||||
int __mark_objectid_really_used(struct id_map *map, __u32 id, __u32 pos) {
|
||||
|
||||
map->objectids_marked ++;
|
||||
if (pos % 2 == 0){
|
||||
@@ -200,7 +191,7 @@ int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
/* we can mark id as used w/o expanding of id map */
|
||||
map->m_begin[pos] = cpu_to_le32 (id);
|
||||
|
||||
check_objectid_map (map);
|
||||
check_objectid_map (map, pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -215,7 +206,7 @@ int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
map->m_begin[pos] = cpu_to_le32 (id);
|
||||
map->m_begin[pos+1] = cpu_to_le32 (id + 1);
|
||||
|
||||
check_objectid_map (map);
|
||||
check_objectid_map (map, pos);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -226,19 +217,31 @@ int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
/* if end id of current interval == start id of next interval we
|
||||
eliminated a sequence of unused objectids */
|
||||
if (pos + 1 < map->m_used_slots_count &&
|
||||
map->m_begin[pos + 1] == map->m_begin[pos]) {
|
||||
map->m_begin[pos + 1] == map->m_begin[pos]) { /* safe, both are le */
|
||||
memmove (map->m_begin + pos, map->m_begin + pos + 2, (map->m_used_slots_count - pos - 2) * sizeof (__u32));
|
||||
map->m_used_slots_count -= 2;
|
||||
try_to_shrink_id_map (map);
|
||||
}
|
||||
|
||||
check_objectid_map (map);
|
||||
check_objectid_map (map, pos);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* returns 1 objectid is marked used already, 0 otherwise */
|
||||
int mark_objectid_really_used (struct id_map * map, __u32 id)
|
||||
{
|
||||
__u32 pos;
|
||||
|
||||
static __u32 get_free_id (reiserfs_filsys_t fs)
|
||||
/* check whether id is used and get place if used or place to insert if not */
|
||||
if (is_objectid_really_used (map, id, &pos) == 1)
|
||||
return 1;
|
||||
|
||||
return __mark_objectid_really_used(map, id, pos) ;
|
||||
}
|
||||
|
||||
|
||||
static __u32 get_free_id (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct id_map * map;
|
||||
|
||||
@@ -256,13 +259,14 @@ static __u32 get_free_id (reiserfs_filsys_t fs)
|
||||
}
|
||||
|
||||
|
||||
__u32 get_unused_objectid (reiserfs_filsys_t fs)
|
||||
__u32 get_unused_objectid (reiserfs_filsys_t * fs)
|
||||
{
|
||||
__u32 objectid;
|
||||
|
||||
objectid = get_free_id (fs);
|
||||
if (mark_objectid_really_used (proper_id_map (fs), objectid))
|
||||
die ("get_unused_objectid: could not mark %lu used", objectid);
|
||||
die ("get_unused_objectid: could not mark %lu used",
|
||||
( long unsigned ) objectid);
|
||||
|
||||
return objectid;
|
||||
}
|
||||
@@ -274,7 +278,7 @@ __u32 get_unused_objectid (reiserfs_filsys_t fs)
|
||||
#if 0
|
||||
/* returns 0 if on-disk objectid map matches to the correct one, 1
|
||||
otherwise */
|
||||
int compare_id_maps (reiserfs_filsys_t fs)
|
||||
int compare_id_maps (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct id_map * map;
|
||||
int disk_size;
|
||||
@@ -293,7 +297,7 @@ int compare_id_maps (reiserfs_filsys_t fs)
|
||||
|
||||
|
||||
/* copy objectid map into buffer containing super block */
|
||||
void correct_objectid_map (reiserfs_filsys_t fs)
|
||||
void correct_objectid_map (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct id_map * map;
|
||||
int size, disk_max;
|
||||
@@ -320,17 +324,15 @@ void correct_objectid_map (reiserfs_filsys_t fs)
|
||||
#endif
|
||||
|
||||
|
||||
#if 0
|
||||
/* print the map of objectids */
|
||||
void print_objectid_list ()
|
||||
void print_objectid_list (__u32 *map, int count)
|
||||
{
|
||||
int i;
|
||||
printf ("\n control id map: all %d, used:%d", id_map.m_page_count * MAP_SIZE, id_map.m_used_slots_count);
|
||||
|
||||
for (i = 0; i < id_map.m_used_slots_count; i += 2)
|
||||
printf ("\n[%u-%u]", id_map.m_begin[i], id_map.m_begin[i + 1] - 1);
|
||||
for (i = 0; i < count ; i += 2)
|
||||
printf ("\n[%u-%u]", le32_to_cpu(map[i]),le32_to_cpu(map[i+1]));
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* print on-disk map of objectids */
|
||||
void print_disk_objectid_list (void)
|
||||
{
|
||||
@@ -339,53 +341,120 @@ void print_disk_objectid_list (void)
|
||||
printf ("\n on-disk id map. used:%lu", SB_OBJECTID_MAP_SIZE(&g_sb));
|
||||
|
||||
for (i = 0; i < SB_OBJECTID_MAP_SIZE(&g_sb); i += 2)
|
||||
printf ("\n[%u-%u]", objectid_map[i], objectid_map[i + 1] - 1);
|
||||
printf ("\n[%u-%u]", objectid_map[i], objectid_map[i + 1] - 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void flush_objectid_map (struct id_map * map, reiserfs_filsys_t fs)
|
||||
void flush_objectid_map (struct id_map * map, reiserfs_filsys_t * fs)
|
||||
{
|
||||
int size, max;
|
||||
int sb_size;
|
||||
__u32 * sb_objectid_map;
|
||||
|
||||
sb_size = (is_reiser2fs_magic_string (fs->s_rs) ? SB_SIZE : SB_SIZE_V1);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->s_rs) + sb_size);
|
||||
sb_size = reiserfs_super_block_size (fs->fs_ondisk_sb);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->fs_ondisk_sb) + sb_size);
|
||||
|
||||
check_objectid_map (map);
|
||||
|
||||
max = ((fs->s_blocksize - sb_size) >> 3 << 1);
|
||||
set_objectid_map_max_size (fs->s_rs, max);
|
||||
max = ((fs->fs_blocksize - sb_size) >> 3 << 1);
|
||||
set_sb_oid_maxsize (fs->fs_ondisk_sb, max);
|
||||
if (map->m_used_slots_count > max)
|
||||
size = max;
|
||||
else
|
||||
size = map->m_used_slots_count;
|
||||
|
||||
check_objectid_map (map, -1);
|
||||
|
||||
memcpy (sb_objectid_map, map->m_begin, size * sizeof (__u32));
|
||||
memset (sb_objectid_map + size, 0, (max - size) * sizeof (__u32));
|
||||
|
||||
set_objectid_map_size (fs->s_rs, size);
|
||||
set_sb_oid_cursize (fs->fs_ondisk_sb, size);
|
||||
if (size == max)
|
||||
/*((__u32 *)((char *)(fs->s_rs) + sb_size))*/
|
||||
sb_objectid_map [max - 1] = map->m_begin [map->m_used_slots_count - 1];
|
||||
sb_objectid_map [max - 1] = map->m_begin [map->m_used_slots_count - 1];
|
||||
|
||||
check_objectid_map (map);
|
||||
// check_objectid_map (map);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t fs)
|
||||
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t * fs)
|
||||
{
|
||||
int sb_size;
|
||||
__u32 * sb_objectid_map;
|
||||
|
||||
sb_size = (is_reiser2fs_magic_string (fs->s_rs) ? SB_SIZE : SB_SIZE_V1);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->s_rs) + sb_size);
|
||||
sb_size = reiserfs_super_block_size (fs->fs_ondisk_sb);
|
||||
sb_objectid_map = (__u32 *)((char *)(fs->fs_ondisk_sb) + sb_size);
|
||||
|
||||
if (map->m_page_count != 1)
|
||||
die ("fetch_objectid_map: can not fetch long map");
|
||||
grow_id_map (map);
|
||||
memcpy (map->m_begin, sb_objectid_map, rs_objectid_map_size (fs->s_rs) * sizeof (__u32));
|
||||
map->m_used_slots_count = rs_objectid_map_size (fs->s_rs);
|
||||
memcpy (map->m_begin, sb_objectid_map, get_sb_oid_cursize (fs->fs_ondisk_sb) * sizeof (__u32));
|
||||
map->m_used_slots_count = get_sb_oid_cursize (fs->fs_ondisk_sb);
|
||||
}
|
||||
|
||||
#define OBJMAP_START_MAGIC 375331
|
||||
#define OBJMAP_END_MAGIC 7700472
|
||||
|
||||
void reiserfs_objectid_map_save (FILE * fp, struct id_map * id_map)
|
||||
{
|
||||
__u32 v;
|
||||
int i;
|
||||
|
||||
v = OBJMAP_START_MAGIC;
|
||||
fwrite (&v, 4, 1, fp);
|
||||
|
||||
v = id_map->m_used_slots_count;
|
||||
fwrite (&v, 4, 1, fp);
|
||||
|
||||
for (i = 0; i < id_map->m_page_count - 1; i++) {
|
||||
fwrite ((char *)id_map->m_begin + MAP_SIZE * i, 4, 1, fp);
|
||||
}
|
||||
|
||||
for (i = 0; i < id_map->m_used_slots_count * sizeof(__u32) - (id_map->m_page_count - 1) * MAP_SIZE; i++) {
|
||||
fwrite ((char *)id_map->m_begin + MAP_SIZE * (id_map->m_page_count - 1) + i, 4, 1, fp);
|
||||
}
|
||||
|
||||
v = OBJMAP_END_MAGIC;
|
||||
fwrite (&v, 4, 1, fp);
|
||||
}
|
||||
|
||||
struct id_map * reiserfs_objectid_map_load (FILE * fp)
|
||||
{
|
||||
__u32 v;
|
||||
int i;
|
||||
struct id_map * id_map;
|
||||
|
||||
fread (&v, 4, 1, fp);
|
||||
if (v != OBJMAP_START_MAGIC) {
|
||||
reiserfs_warning (stderr, "reiserfs_objectid_map_load: no objectid map begin magic found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* read bit size of objectid map */
|
||||
fread (&v, 4, 1, fp);
|
||||
|
||||
id_map = init_id_map ();
|
||||
|
||||
id_map->m_used_slots_count = v;
|
||||
id_map->m_page_count = v / MAP_SIZE + 1;
|
||||
|
||||
id_map->m_begin = expandmem (id_map->m_begin, 0, id_map->m_page_count * MAP_SIZE);
|
||||
|
||||
for (i = 0; i < id_map->m_page_count - 1; i++) {
|
||||
fread ((char *)id_map->m_begin + MAP_SIZE * i, 4, 1, fp);
|
||||
}
|
||||
|
||||
for (i = 0; i < id_map->m_used_slots_count * sizeof(__u32) - (id_map->m_page_count - 1) * MAP_SIZE; i++) {
|
||||
fread ((char *)id_map->m_begin + MAP_SIZE * (id_map->m_page_count - 1) + i, 4, 1, fp);
|
||||
}
|
||||
|
||||
fread (&v, 4, 1, fp);
|
||||
|
||||
if (v != OBJMAP_END_MAGIC) {
|
||||
reiserfs_warning (stderr, "reiserfs_objectid_map_load: no objectid map end magic found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fflush (stderr);
|
||||
return id_map;
|
||||
}
|
||||
|
||||
+73
-487
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-2001 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
#include "fsck.h"
|
||||
|
||||
@@ -20,18 +20,6 @@ int comp_dir_entries (void * key1, void * key2)
|
||||
}
|
||||
|
||||
|
||||
void init_tb_struct (struct tree_balance * tb, struct super_block * s, struct path * path, int size)
|
||||
{
|
||||
memset (tb, '\0', sizeof(struct tree_balance));
|
||||
tb->tb_sb = s;
|
||||
tb->tb_path = path;
|
||||
|
||||
PATH_OFFSET_PBUFFER(path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
|
||||
PATH_OFFSET_POSITION(path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
|
||||
tb->insert_size[0] = size;
|
||||
}
|
||||
|
||||
|
||||
struct tree_balance * cur_tb = 0;
|
||||
|
||||
void reiserfsck_paste_into_item (struct path * path, const char * body, int size)
|
||||
@@ -52,7 +40,7 @@ void reiserfsck_insert_item (struct path * path, struct item_head * ih, const ch
|
||||
{
|
||||
struct tree_balance tb;
|
||||
|
||||
init_tb_struct (&tb, fs, path, IH_SIZE + ih_item_len(ih));
|
||||
init_tb_struct (&tb, fs, path, IH_SIZE + get_ih_item_len(ih));
|
||||
if (fix_nodes (/*tb.transaction_handle,*/ M_INSERT, &tb, ih/*, body*/) != CARRY_ON)
|
||||
die ("reiserfsck_insert_item: fix_nodes failed");
|
||||
do_balance (/*tb.transaction_handle,*/ &tb, ih, body, M_INSERT, 0/*zero num*/);
|
||||
@@ -65,17 +53,17 @@ static void free_unformatted_nodes (struct item_head * ih, struct buffer_head *
|
||||
int i;
|
||||
|
||||
for (i = 0; i < I_UNFM_NUM (ih); i ++, punfm ++)
|
||||
if (*punfm) {
|
||||
if (*punfm != 0) {
|
||||
struct buffer_head * to_be_forgotten;
|
||||
|
||||
to_be_forgotten = find_buffer (fs->s_dev, *punfm, fs->s_blocksize);
|
||||
to_be_forgotten = find_buffer (fs->fs_dev, le32_to_cpu (*punfm), fs->fs_blocksize);
|
||||
if (to_be_forgotten) {
|
||||
//atomic_inc(&to_be_forgotten->b_count);
|
||||
to_be_forgotten->b_count ++;
|
||||
bforget (to_be_forgotten);
|
||||
}
|
||||
|
||||
reiserfs_free_block (fs, *punfm);
|
||||
reiserfs_free_block (fs, le32_to_cpu (*punfm));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +76,7 @@ void reiserfsck_delete_item (struct path * path, int temporary)
|
||||
if (is_indirect_ih (ih) && !temporary)
|
||||
free_unformatted_nodes (ih, PATH_PLAST_BUFFER (path));
|
||||
|
||||
init_tb_struct (&tb, fs, path, -(IH_SIZE + ih_item_len(ih)));
|
||||
init_tb_struct (&tb, fs, path, -(IH_SIZE + get_ih_item_len(ih)));
|
||||
|
||||
if (fix_nodes (/*tb.transaction_handle,*/ M_DELETE, &tb, 0/*ih*/) != CARRY_ON)
|
||||
die ("reiserfsck_delete_item: fix_nodes failed");
|
||||
@@ -107,10 +95,10 @@ void reiserfsck_cut_from_item (struct path * path, int cut_size)
|
||||
|
||||
if (is_indirect_ih (ih = PATH_PITEM_HEAD (path))) {
|
||||
__u32 unfm_ptr = B_I_POS_UNFM_POINTER (PATH_PLAST_BUFFER (path), ih, I_UNFM_NUM (ih) - 1);
|
||||
if (unfm_ptr) {
|
||||
if (unfm_ptr != 0) {
|
||||
struct buffer_head * to_be_forgotten;
|
||||
|
||||
to_be_forgotten = find_buffer (fs->s_dev, le32_to_cpu (unfm_ptr), fs->s_blocksize);
|
||||
to_be_forgotten = find_buffer (fs->fs_dev, le32_to_cpu (unfm_ptr), fs->fs_blocksize);
|
||||
if (to_be_forgotten) {
|
||||
//atomic_inc(&to_be_forgotten->b_count);
|
||||
to_be_forgotten->b_count ++;
|
||||
@@ -130,45 +118,8 @@ void reiserfsck_cut_from_item (struct path * path, int cut_size)
|
||||
}
|
||||
|
||||
|
||||
/* uget_lkey is utils clone of stree.c/get_lkey */
|
||||
struct key * uget_lkey (struct path * path)
|
||||
{
|
||||
int pos, offset = path->path_length;
|
||||
struct buffer_head * bh;
|
||||
|
||||
if (offset < FIRST_PATH_ELEMENT_OFFSET)
|
||||
die ("uget_lkey: illegal offset in the path (%d)", offset);
|
||||
|
||||
|
||||
/* While not higher in path than first element. */
|
||||
while (offset-- > FIRST_PATH_ELEMENT_OFFSET) {
|
||||
if (! buffer_uptodate (PATH_OFFSET_PBUFFER (path, offset)) )
|
||||
die ("uget_lkey: parent is not uptodate");
|
||||
|
||||
/* Parent at the path is not in the tree now. */
|
||||
if (! B_IS_IN_TREE (bh = PATH_OFFSET_PBUFFER (path, offset)))
|
||||
die ("uget_lkey: buffer on the path is not in tree");
|
||||
|
||||
/* Check whether position in the parent is correct. */
|
||||
if ((pos = PATH_OFFSET_POSITION (path, offset)) > B_NR_ITEMS (bh))
|
||||
die ("uget_lkey: invalid position (%d) in the path", pos);
|
||||
|
||||
/* Check whether parent at the path really points to the child. */
|
||||
if (B_N_CHILD_NUM (bh, pos) != PATH_OFFSET_PBUFFER (path, offset + 1)->b_blocknr)
|
||||
die ("uget_lkey: invalid block number (%d). Must be %d",
|
||||
B_N_CHILD_NUM (bh, pos), PATH_OFFSET_PBUFFER (path, offset + 1)->b_blocknr);
|
||||
|
||||
/* Return delimiting key if position in the parent is not equal to zero. */
|
||||
if (pos)
|
||||
return B_N_PDELIM_KEY(bh, pos - 1);
|
||||
}
|
||||
|
||||
/* there is no left delimiting key */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* uget_rkey is utils clone of stree.c/get_rkey */
|
||||
/*
|
||||
struct key * uget_rkey (struct path * path)
|
||||
{
|
||||
int pos, offset = path->path_length;
|
||||
@@ -181,316 +132,33 @@ struct key * uget_rkey (struct path * path)
|
||||
if (! buffer_uptodate (PATH_OFFSET_PBUFFER (path, offset)))
|
||||
die ("uget_rkey: parent is not uptodate");
|
||||
|
||||
/* Parent at the path is not in the tree now. */
|
||||
// Parent at the path is not in the tree now.
|
||||
if (! B_IS_IN_TREE (bh = PATH_OFFSET_PBUFFER (path, offset)))
|
||||
die ("uget_rkey: buffer on the path is not in tree");
|
||||
|
||||
/* Check whether position in the parrent is correct. */
|
||||
// Check whether position in the parrent is correct.
|
||||
if ((pos = PATH_OFFSET_POSITION (path, offset)) > B_NR_ITEMS (bh))
|
||||
die ("uget_rkey: invalid position (%d) in the path", pos);
|
||||
|
||||
/* Check whether parent at the path really points to the child. */
|
||||
if (B_N_CHILD_NUM (bh, pos) != PATH_OFFSET_PBUFFER (path, offset + 1)->b_blocknr)
|
||||
die ("uget_rkey: invalid block number (%d). Must be %d",
|
||||
B_N_CHILD_NUM (bh, pos), PATH_OFFSET_PBUFFER (path, offset + 1)->b_blocknr);
|
||||
// Check whether parent at the path really points to the child.
|
||||
if (get_dc_child_blocknr (B_N_CHILD (bh, pos)) != PATH_OFFSET_PBUFFER (path, offset + 1)->b_blocknr)
|
||||
die ("uget_rkey: invalid block number (%d). Must be %ld",
|
||||
get_dc_child_blocknr (B_N_CHILD (bh, pos)), PATH_OFFSET_PBUFFER (path, offset + 1)->b_blocknr);
|
||||
|
||||
/* Return delimiting key if position in the parent is not the last one. */
|
||||
// Return delimiting key if position in the parent is not the last one.
|
||||
if (pos != B_NR_ITEMS (bh))
|
||||
return B_N_PDELIM_KEY(bh, pos);
|
||||
}
|
||||
|
||||
/* there is no right delimiting key */
|
||||
// there is no right delimiting key
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int ubin_search (void * key, void * base, int num, int width, __u32 *ppos, comp_function_t comp_func)
|
||||
{
|
||||
__u32 rbound, lbound, j;
|
||||
|
||||
lbound = 0;
|
||||
|
||||
if (num == 0){
|
||||
*ppos = 0;
|
||||
return ITEM_NOT_FOUND;
|
||||
}
|
||||
|
||||
rbound = num - 1;
|
||||
|
||||
for (j = (rbound + lbound) / 2; lbound <= rbound; j = (rbound + lbound) / 2) {
|
||||
switch (comp_func ((void *)((char *)base + j * width), key ) ) {
|
||||
case -1:/* second is greater */
|
||||
lbound = j + 1;
|
||||
continue;
|
||||
|
||||
case 1: /* first is greater */
|
||||
if (j == 0){
|
||||
*ppos = lbound;
|
||||
return ITEM_NOT_FOUND;
|
||||
}
|
||||
rbound = j - 1;
|
||||
continue;
|
||||
|
||||
case 0:
|
||||
*ppos = j;
|
||||
return ITEM_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
*ppos = lbound;
|
||||
return ITEM_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
/* this searches in tree through items */
|
||||
int usearch_by_key (struct super_block * s, struct key * key, struct path * path)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
unsigned long block = SB_ROOT_BLOCK (s);
|
||||
struct path_element * curr;
|
||||
int retval;
|
||||
|
||||
path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
|
||||
while (1) {
|
||||
curr = PATH_OFFSET_PELEMENT (path, ++ path->path_length);
|
||||
bh = curr->pe_buffer = bread (s->s_dev, block, s->s_blocksize);
|
||||
if (bh == 0)
|
||||
reiserfs_panic ("usearch_by_key: unable to read %lu block on device 0x%x\n",block, s->s_dev);
|
||||
retval = ubin_search (key, B_N_PKEY (bh, 0), B_NR_ITEMS (bh),
|
||||
is_leaf_node (bh) ? IH_SIZE : KEY_SIZE, &(curr->pe_position), comp_keys);
|
||||
if (retval == ITEM_FOUND) {
|
||||
/* key found, return if this is leaf level */
|
||||
if (is_leaf_node (bh)) {
|
||||
path->pos_in_item = 0;
|
||||
return ITEM_FOUND;
|
||||
}
|
||||
curr->pe_position ++;
|
||||
} else {
|
||||
/* key not found in the node */
|
||||
if (is_leaf_node (bh))
|
||||
return ITEM_NOT_FOUND;
|
||||
}
|
||||
block = B_N_CHILD_NUM (bh, curr->pe_position);
|
||||
}
|
||||
die ("search_by_key: you can not get here");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* key is key of directory entry. This searches in tree through items and in
|
||||
the found directory item as well */
|
||||
int usearch_by_entry_key (struct super_block * s, struct key * key, struct path * path)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
struct item_head * ih;
|
||||
struct key tmpkey;
|
||||
|
||||
if (usearch_by_key (s, key, path) == ITEM_FOUND) {
|
||||
/* entry found */
|
||||
path->pos_in_item = 0;
|
||||
return POSITION_FOUND;
|
||||
}
|
||||
|
||||
bh = PATH_PLAST_BUFFER (path);
|
||||
|
||||
if (PATH_LAST_POSITION (path) == 0) {
|
||||
/* previous item does not exist, that means we are in leftmost leaf of
|
||||
the tree */
|
||||
if (uget_lkey (path) != 0)
|
||||
die ("search_by_entry_key: invalid position after search_by_key");
|
||||
|
||||
if (not_of_one_file (B_N_PKEY (bh, 0), key)) {
|
||||
path->pos_in_item = 0;
|
||||
return DIRECTORY_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (!is_direntry_ih (get_ih (path))) {
|
||||
fsck_progress ("search_by_entry_key: directory expected to have this key %K\n", key);
|
||||
return REGULAR_FILE_FOUND;
|
||||
}
|
||||
|
||||
/* position for name insertion is found */
|
||||
path->pos_in_item = 0;
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* take previous item */
|
||||
PATH_LAST_POSITION (path) --;
|
||||
ih = PATH_PITEM_HEAD (path);
|
||||
if (not_of_one_file (&(ih->ih_key), key) || !is_direntry_ih(ih)) {
|
||||
/* previous item belongs to another object or is stat data, check next
|
||||
item */
|
||||
|
||||
PATH_LAST_POSITION (path) ++;
|
||||
if (PATH_LAST_POSITION (path) < B_NR_ITEMS (bh))
|
||||
{
|
||||
/* found item is not last item of the node */
|
||||
struct item_head * next_ih = B_N_PITEM_HEAD (bh, PATH_LAST_POSITION (path));
|
||||
|
||||
if (not_of_one_file (&(next_ih->ih_key), key))
|
||||
{
|
||||
path->pos_in_item = 0;
|
||||
return DIRECTORY_NOT_FOUND;
|
||||
}
|
||||
if (!is_direntry_ih(next_ih))
|
||||
{
|
||||
/* there is an item in the tree, but it is not a directory item */
|
||||
reiserfs_warning (stderr, "search_by_entry_key: directory expected to have this key %k\n",
|
||||
key);
|
||||
return REGULAR_FILE_FOUND;
|
||||
}
|
||||
} else {
|
||||
/* found item is last item of the node */
|
||||
struct key * next_key = uget_rkey (path);
|
||||
|
||||
if (next_key == 0 || not_of_one_file (next_key, key))
|
||||
{
|
||||
/* there is not any part of such directory in the tree */
|
||||
path->pos_in_item = 0;
|
||||
return DIRECTORY_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (!is_direntry_key (next_key))
|
||||
{
|
||||
/* there is an item in the tree, but it is not a directory item */
|
||||
fsck_progress ("search_by_entry_key: directory expected to have this key %k\n",
|
||||
key);
|
||||
return REGULAR_FILE_FOUND;
|
||||
}
|
||||
|
||||
// we got right delimiting key - search for it - the entry will be
|
||||
// pasted in position 0
|
||||
copy_key (&tmpkey, next_key);
|
||||
pathrelse (path);
|
||||
if (usearch_by_key (s, &tmpkey, path) != ITEM_FOUND || PATH_LAST_POSITION (path) != 0)
|
||||
die ("search_by_entry_key: item not found by corresponding delimiting key");
|
||||
}
|
||||
|
||||
/* next item is the part of this directory */
|
||||
path->pos_in_item = 0;
|
||||
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* previous item is part of desired directory */
|
||||
if (ubin_search (&(key->u.k_offset_v1.k_offset), B_I_DEH (bh, ih), ih_entry_count (ih),
|
||||
DEH_SIZE, &(path->pos_in_item), comp_dir_entries) == ITEM_FOUND)
|
||||
return POSITION_FOUND;
|
||||
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
/* key is key of byte in the regular file. This searches in tree
|
||||
through items and in the found item as well */
|
||||
int usearch_by_position (struct super_block * s, struct key * key, int version, struct path * path)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
struct item_head * ih;
|
||||
|
||||
if (usearch_by_key (s, key, path) == ITEM_FOUND)
|
||||
{
|
||||
ih = PATH_PITEM_HEAD (path);
|
||||
|
||||
if (!is_direct_ih(ih) && !is_indirect_ih(ih))
|
||||
return DIRECTORY_FOUND;
|
||||
path->pos_in_item = 0;
|
||||
return POSITION_FOUND;
|
||||
}
|
||||
|
||||
bh = PATH_PLAST_BUFFER (path);
|
||||
ih = PATH_PITEM_HEAD (path);
|
||||
|
||||
|
||||
if ( (PATH_LAST_POSITION(path) < B_NR_ITEMS (bh)) &&
|
||||
!not_of_one_file (&ih->ih_key, key) &&
|
||||
(get_offset(&ih->ih_key) == get_offset(key)) )
|
||||
{
|
||||
|
||||
if (!is_direct_ih(ih) && !is_indirect_ih(ih))
|
||||
return DIRECTORY_FOUND;
|
||||
path->pos_in_item = 0;
|
||||
|
||||
|
||||
return POSITION_FOUND;
|
||||
}
|
||||
|
||||
if (PATH_LAST_POSITION (path) == 0) {
|
||||
/* previous item does not exist, that means we are in leftmost leaf of the tree */
|
||||
if (!not_of_one_file (B_N_PKEY (bh, 0), key)) {
|
||||
if (!is_direct_ih(ih) && !is_indirect_ih (ih))
|
||||
return DIRECTORY_FOUND;
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
/* take previous item */
|
||||
PATH_LAST_POSITION (path) --;
|
||||
ih = PATH_PITEM_HEAD (path);
|
||||
|
||||
if (not_of_one_file (&ih->ih_key, key) || is_stat_data_ih(ih)) {
|
||||
struct key * next_key;
|
||||
|
||||
/* previous item belongs to another object or is a stat data, check next item */
|
||||
PATH_LAST_POSITION (path) ++;
|
||||
if (PATH_LAST_POSITION (path) < B_NR_ITEMS (PATH_PLAST_BUFFER (path)))
|
||||
/* next key is in the same node */
|
||||
next_key = B_N_PKEY (PATH_PLAST_BUFFER (path), PATH_LAST_POSITION (path));
|
||||
else
|
||||
next_key = uget_rkey (path);
|
||||
if (next_key == 0 || not_of_one_file (next_key, key)) {
|
||||
/* there is no any part of such file in the tree */
|
||||
path->pos_in_item = 0;
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (is_direntry_key (next_key)) {
|
||||
fsck_log ("\nusearch_by_position: looking for %k found a directory with the same key\n", next_key);
|
||||
return DIRECTORY_FOUND;
|
||||
}
|
||||
/* next item is the part of this file */
|
||||
path->pos_in_item = 0;
|
||||
if ( get_offset(next_key) == get_offset(key) ) {
|
||||
pathrelse(path);
|
||||
if (usearch_by_key (s, next_key, path) != ITEM_FOUND) {
|
||||
reiserfs_panic ("usearch_by_position: keys must be equals %k %k",
|
||||
next_key, &PATH_PITEM_HEAD (path)->ih_key);
|
||||
}
|
||||
return POSITION_FOUND;
|
||||
}
|
||||
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (is_direntry_ih(ih)) {
|
||||
return DIRECTORY_FOUND;
|
||||
}
|
||||
if (is_stat_data_ih(ih)) {
|
||||
PATH_LAST_POSITION (path) ++;
|
||||
return FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* previous item is part of desired file */
|
||||
|
||||
|
||||
//if (is_key_in_item (bh,ih,key,bh->b_size)) {
|
||||
if (I_K_KEY_IN_ITEM (ih, key, bh->b_size)) {
|
||||
path->pos_in_item = get_offset (key) - get_offset (&ih->ih_key);
|
||||
if (is_indirect_ih (ih) )
|
||||
path->pos_in_item /= bh->b_size;
|
||||
return POSITION_FOUND;
|
||||
}
|
||||
|
||||
path->pos_in_item = is_indirect_ih (ih) ? I_UNFM_NUM (ih) : ih_item_len (ih);
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
static unsigned long first_child (struct buffer_head * bh)
|
||||
{
|
||||
return child_block_number (bh, 0);
|
||||
return get_dc_child_blocknr (B_N_CHILD (bh, 0));
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -500,6 +168,7 @@ static unsigned long last_child (struct buffer_head * bh)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static unsigned long get_child (int pos, struct buffer_head * parent)
|
||||
{
|
||||
if (pos == -1)
|
||||
@@ -507,22 +176,15 @@ static unsigned long get_child (int pos, struct buffer_head * parent)
|
||||
|
||||
if (pos > B_NR_ITEMS (parent))
|
||||
die ("get_child: no child found, should not happen: %d of %d", pos, B_NR_ITEMS (parent));
|
||||
return child_block_number (parent, pos);
|
||||
return get_dc_child_blocknr (B_N_CHILD (parent, pos));
|
||||
|
||||
/*
|
||||
for (i = 0; i < B_NR_ITEMS (parent); i ++)
|
||||
{
|
||||
if (child_block_number (parent, i) == block)
|
||||
return child_block_number (parent, i + 1);
|
||||
}
|
||||
die ("next_child: no child found: should not happen");
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
static void print (int cur, int total)
|
||||
{
|
||||
if (fsck_quiet (fs))
|
||||
return;
|
||||
printf ("/%3d (of %3d)", cur, total);fflush (stdout);
|
||||
}
|
||||
|
||||
@@ -530,160 +192,84 @@ static void print (int cur, int total)
|
||||
/* erase /XXX(of XXX) */
|
||||
static void erase (void)
|
||||
{
|
||||
if (fsck_quiet (fs))
|
||||
return;
|
||||
printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b");
|
||||
printf (" ");
|
||||
printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b");
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void pass_through_tree2 (struct super_block * s, do_after_read_t action1,
|
||||
void pass_through_tree (reiserfs_filsys_t * fs, do_after_read_t action1,
|
||||
do_on_full_path_t action2)
|
||||
{
|
||||
struct buffer_head * path[MAX_HEIGHT] = {0,};
|
||||
int total[MAX_HEIGHT] = {0,};
|
||||
int cur[MAX_HEIGHT] = {0,};
|
||||
int h = 0;
|
||||
unsigned long block = SB_ROOT_BLOCK (s);
|
||||
int del_p;
|
||||
unsigned long block = get_sb_root_block (fs->fs_ondisk_sb);
|
||||
int problem;
|
||||
|
||||
if (block >= SB_BLOCK_COUNT (s) || not_data_block (s, block))
|
||||
return;
|
||||
|
||||
if (block >= get_sb_block_count (fs->fs_ondisk_sb) || not_data_block (fs, block)) {
|
||||
die ("\nBad root block %lu. (--rebuild-tree did not complete)\n", block);
|
||||
}
|
||||
|
||||
while ( 1 ) {
|
||||
problem = 0;
|
||||
|
||||
if (path[h])
|
||||
die ("pass_through_tree: empty slot expected");
|
||||
if (h)
|
||||
print (cur[h - 1], total[h - 1]);
|
||||
|
||||
path[h] = bread (s->s_dev, block, s->s_blocksize);
|
||||
get_child (-1, path[h]);
|
||||
if (fs->fs_badblocks_bm && reiserfs_bitmap_test_bit (fs->fs_badblocks_bm, block)) {
|
||||
fsck_log ("%s: block %lu specified in badblock list found in tree, whole subtree skipped\n",
|
||||
__FUNCTION__, block);
|
||||
fsck_data (fs)->check.bad_nodes++;
|
||||
one_more_corruption (fs, fatal);
|
||||
|
||||
if (path[h] == 0)
|
||||
reiserfs_warning ("pass_through_tree: unable to read %lu block on device 0x%x\n",
|
||||
block, s->s_dev);
|
||||
|
||||
del_p = 0;
|
||||
if (path[h] && action1) {
|
||||
if (action1 (s, path, h)) {
|
||||
;
|
||||
#if 0
|
||||
// something wrong with a buffer we just have read
|
||||
if (opt_fsck_mode == FSCK_FAST_REBUILD){
|
||||
//need to change the way we are going on
|
||||
del_p = 1;
|
||||
if (h == 0)
|
||||
break;
|
||||
} else {
|
||||
;
|
||||
//reiserfs_panic (s, "Run reiserfsck with --rebuild-tree\n");
|
||||
}
|
||||
#endif
|
||||
if (h == 0) {
|
||||
brelse (path[h]);
|
||||
path[h] = 0;
|
||||
break;
|
||||
}
|
||||
problem = 1;
|
||||
} else {
|
||||
path[h] = bread (fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (path[h] == 0)
|
||||
/* FIXME: handle case when read failed */
|
||||
die ("pass_through_tree: unable to read %lu block on device 0x%x\n",
|
||||
block, fs->fs_dev);
|
||||
|
||||
if (action1)
|
||||
if ((problem = action1 (fs, path, h))) {
|
||||
fsck_log ("whole subtree skipped\n");
|
||||
fsck_data (fs)->check.bad_nodes++;
|
||||
|
||||
if (h == 0) {
|
||||
brelse (path[h]);
|
||||
path[h] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!path[h] || is_leaf_node (path[h]))
|
||||
{
|
||||
if (path[h] && action2) {
|
||||
if (action2 (s, path, h)) {
|
||||
;
|
||||
#if 0
|
||||
if (opt_fsck_mode == FSCK_FAST_REBUILD) {
|
||||
//need to change the way we are going on
|
||||
del_p = 1;
|
||||
if (h == 0)
|
||||
break;
|
||||
} else {
|
||||
;
|
||||
//reiserfs_panic (s, "Run reiserfsck with --rebuild-tree\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (path[h])
|
||||
brelse (path[h]);
|
||||
if (h)
|
||||
erase ();
|
||||
|
||||
while (h && (!path[h-1] || cur[h-1] == total[h-1] ))
|
||||
{
|
||||
path[h] = 0;
|
||||
h --;
|
||||
if (path[h])
|
||||
brelse (path[h]);
|
||||
if (h)
|
||||
erase ();
|
||||
}
|
||||
|
||||
if (h == 0) {
|
||||
path[h] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (path[h])
|
||||
cur[h - 1] ++;
|
||||
if (del_p){
|
||||
total[h-1]--;
|
||||
del_p = 0;
|
||||
}
|
||||
block = get_child (cur[h - 1] - 1, path[h-1]);
|
||||
path[h] = 0;
|
||||
continue;
|
||||
}
|
||||
total[h] = B_NR_ITEMS (path[h]) + 1;
|
||||
cur[h] = 1;
|
||||
block = first_child (path[h]);
|
||||
h ++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void pass_through_tree (struct super_block * s, do_after_read_t action1,
|
||||
do_on_full_path_t action2)
|
||||
{
|
||||
struct buffer_head * path[MAX_HEIGHT] = {0,};
|
||||
int total[MAX_HEIGHT] = {0,};
|
||||
int cur[MAX_HEIGHT] = {0,};
|
||||
int h = 0;
|
||||
unsigned long block = SB_ROOT_BLOCK (s);
|
||||
|
||||
|
||||
if (block >= SB_BLOCK_COUNT (s) || not_data_block (s, block)) {
|
||||
fsck_progress ("\nBad root block %lu. (--rebuild-tree did not complete)\n", block);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
while ( 1 ) {
|
||||
if (path[h])
|
||||
die ("pass_through_tree: empty slot expected");
|
||||
if (h)
|
||||
print (cur[h - 1], total[h - 1]);
|
||||
|
||||
path[h] = bread (s->s_dev, block, s->s_blocksize);
|
||||
if (path[h] == 0)
|
||||
/* FIXME: handle case when read failed */
|
||||
die ("pass_through_tree: unable to read %lu block on device 0x%x\n",
|
||||
block, s->s_dev);
|
||||
|
||||
if (action1)
|
||||
action1 (s, path, h);
|
||||
|
||||
if (is_leaf_node (path[h])) {
|
||||
if (action2)
|
||||
action2 (s, path, h);
|
||||
if (problem || is_leaf_node (path[h])) {
|
||||
if (!problem && action2)
|
||||
action2 (fs, path, h);
|
||||
|
||||
brelse (path[h]);
|
||||
if (h)
|
||||
erase ();
|
||||
|
||||
while (h && (cur[h-1] == total[h-1])) {
|
||||
path[h] = 0;
|
||||
h --;
|
||||
brelse (path[h]);
|
||||
if (h)
|
||||
erase ();
|
||||
while (h && (cur[h-1] == total[h-1] || problem)) {
|
||||
problem = 0;
|
||||
path[h] = 0;
|
||||
h --;
|
||||
brelse (path[h]);
|
||||
if (h)
|
||||
erase ();
|
||||
}
|
||||
|
||||
if (h == 0) {
|
||||
@@ -692,7 +278,7 @@ void pass_through_tree (struct super_block * s, do_after_read_t action1,
|
||||
}
|
||||
|
||||
block = get_child (cur[h - 1], path[h-1]);
|
||||
cur[h - 1] ++;
|
||||
cur[h - 1] ++;
|
||||
path[h] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
noinst_HEADERS = io.h misc.h reiserfs_fs.h reiserfs_lib.h
|
||||
noinst_HEADERS = io.h misc.h reiserfs_fs.h reiserfs_lib.h swab.h
|
||||
+51
-17
@@ -1,6 +1,6 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -62,13 +62,15 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
noinst_HEADERS = io.h misc.h reiserfs_fs.h reiserfs_lib.h
|
||||
noinst_HEADERS = io.h misc.h reiserfs_fs.h reiserfs_lib.h swab.h
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
HEADERS = $(noinst_HEADERS)
|
||||
|
||||
DIST_COMMON = Makefile.am Makefile.in
|
||||
DIST_COMMON = ./stamp-h.in Makefile.am Makefile.in config.h.in
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
@@ -85,6 +87,34 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
|
||||
config.h: stamp-h
|
||||
@if test ! -f $@; then \
|
||||
rm -f stamp-h; \
|
||||
$(MAKE) stamp-h; \
|
||||
else :; fi
|
||||
stamp-h: $(srcdir)/config.h.in $(top_builddir)/config.status
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES= CONFIG_HEADERS=include/config.h \
|
||||
$(SHELL) ./config.status
|
||||
@echo timestamp > stamp-h 2> /dev/null
|
||||
$(srcdir)/config.h.in: $(srcdir)/stamp-h.in
|
||||
@if test ! -f $@; then \
|
||||
rm -f $(srcdir)/stamp-h.in; \
|
||||
$(MAKE) $(srcdir)/stamp-h.in; \
|
||||
else :; fi
|
||||
$(srcdir)/stamp-h.in: $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOHEADER)
|
||||
@echo timestamp > $(srcdir)/stamp-h.in 2> /dev/null
|
||||
|
||||
mostlyclean-hdr:
|
||||
|
||||
clean-hdr:
|
||||
|
||||
distclean-hdr:
|
||||
-rm -f config.h
|
||||
|
||||
maintainer-clean-hdr:
|
||||
|
||||
tags: TAGS
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
@@ -95,15 +125,15 @@ ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
here=`pwd` && cd $(srcdir) \
|
||||
&& mkid -f$$here/ID $$unique $(LISP)
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
|
||||
TAGS: $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|
||||
test -z "$(ETAGS_ARGS)config.h.in$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags config.h.in $$unique $(LISP) -o $$here/TAGS)
|
||||
|
||||
mostlyclean-tags:
|
||||
|
||||
@@ -122,7 +152,7 @@ distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
@@ -137,6 +167,9 @@ check-am: all-am
|
||||
check: check-am
|
||||
installcheck-am:
|
||||
installcheck: installcheck-am
|
||||
all-recursive-am: config.h
|
||||
$(MAKE) $(AM_MAKEFLAGS) all-recursive
|
||||
|
||||
install-exec-am:
|
||||
install-exec: install-exec-am
|
||||
|
||||
@@ -148,7 +181,7 @@ install-am: all-am
|
||||
install: install-am
|
||||
uninstall-am:
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(HEADERS)
|
||||
all-am: Makefile $(HEADERS) config.h
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
@@ -164,28 +197,29 @@ distclean-generic:
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
mostlyclean-am: mostlyclean-tags mostlyclean-generic
|
||||
mostlyclean-am: mostlyclean-hdr mostlyclean-tags mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
clean-am: clean-tags clean-generic mostlyclean-am
|
||||
clean-am: clean-hdr clean-tags clean-generic mostlyclean-am
|
||||
|
||||
clean: clean-am
|
||||
|
||||
distclean-am: distclean-tags distclean-generic clean-am
|
||||
distclean-am: distclean-hdr distclean-tags distclean-generic clean-am
|
||||
|
||||
distclean: distclean-am
|
||||
|
||||
maintainer-clean-am: maintainer-clean-tags maintainer-clean-generic \
|
||||
distclean-am
|
||||
maintainer-clean-am: maintainer-clean-hdr maintainer-clean-tags \
|
||||
maintainer-clean-generic distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: tags mostlyclean-tags distclean-tags clean-tags \
|
||||
maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \
|
||||
installcheck-am installcheck install-exec-am install-exec \
|
||||
.PHONY: mostlyclean-hdr distclean-hdr clean-hdr maintainer-clean-hdr \
|
||||
tags mostlyclean-tags distclean-tags clean-tags maintainer-clean-tags \
|
||||
distdir info-am info dvi-am dvi check check-am installcheck-am \
|
||||
installcheck all-recursive-am install-exec-am install-exec \
|
||||
install-data-am install-data install-am install uninstall-am uninstall \
|
||||
all-redirect all-am all installdirs mostlyclean-generic \
|
||||
distclean-generic clean-generic maintainer-clean-generic clean \
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/* include/config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
/*
|
||||
* Copyright 1996, 1997 Hans Reiser, see reiserfs/README for licensing and copyright details
|
||||
*/
|
||||
|
||||
/* Define if you don't have `vprintf' but do have `_doprnt.' */
|
||||
#undef HAVE_DOPRNT
|
||||
|
||||
/* Define if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define if you have the <malloc.h> header file. */
|
||||
#undef HAVE_MALLOC_H
|
||||
|
||||
/* Define if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define if you have the `strerror' function. */
|
||||
#undef HAVE_STRERROR
|
||||
|
||||
/* Define if you have the `strftime' function. */
|
||||
#undef HAVE_STRFTIME
|
||||
|
||||
/* Define if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define if you have the `strstr' function. */
|
||||
#undef HAVE_STRSTR
|
||||
|
||||
/* Define if you have the `strtol' function. */
|
||||
#undef HAVE_STRTOL
|
||||
|
||||
/* Define if `st_rdev' is member of `struct stat'. */
|
||||
#undef HAVE_STRUCT_STAT_ST_RDEV
|
||||
|
||||
/* Define if your `struct stat' has `st_rdev'. Deprecated, use
|
||||
`HAVE_STRUCT_STAT_ST_RDEV' instead. */
|
||||
#undef HAVE_ST_RDEV
|
||||
|
||||
/* Define if you have the <sys/ioctl.h> header file. */
|
||||
#undef HAVE_SYS_IOCTL_H
|
||||
|
||||
/* Define if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if you have the `vprintf' function. */
|
||||
#undef HAVE_VPRINTF
|
||||
|
||||
/* gets set when configure --enable-io-failure-emulation */
|
||||
#undef IO_FAILURE_EMULATION
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
|
||||
if it is not supported. */
|
||||
#undef inline
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
+38
-22
@@ -1,29 +1,42 @@
|
||||
struct buffer_head {
|
||||
unsigned long b_blocknr;
|
||||
unsigned short b_dev;
|
||||
unsigned long b_size;
|
||||
char * b_data;
|
||||
unsigned long b_state;
|
||||
unsigned int b_count;
|
||||
unsigned int b_list ;
|
||||
void (*b_end_io)(struct buffer_head *bh, int uptodate);
|
||||
/*
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
|
||||
struct buffer_head * b_next;
|
||||
struct buffer_head * b_prev;
|
||||
struct buffer_head * b_hash_next;
|
||||
struct buffer_head * b_hash_prev;
|
||||
|
||||
struct buffer_head {
|
||||
unsigned long b_blocknr;
|
||||
unsigned short b_dev;
|
||||
unsigned long b_size;
|
||||
char * b_data;
|
||||
unsigned long b_state;
|
||||
unsigned int b_count;
|
||||
unsigned int b_list ;
|
||||
void (*b_start_io) (unsigned long);
|
||||
void (*b_end_io)(struct buffer_head *bh, int uptodate);
|
||||
|
||||
struct buffer_head * b_next;
|
||||
struct buffer_head * b_prev;
|
||||
struct buffer_head * b_hash_next;
|
||||
struct buffer_head * b_hash_prev;
|
||||
};
|
||||
|
||||
#define BH_Uptodate 0
|
||||
#define BH_Dirty 1
|
||||
#define BH_Lock 2
|
||||
#define BH_Do_not_flush 3
|
||||
|
||||
|
||||
#define buffer_uptodate(bh) test_bit(BH_Uptodate, &(bh)->b_state)
|
||||
#define buffer_dirty(bh) test_bit(BH_Dirty, &(bh)->b_state)
|
||||
#define buffer_locked(bh) test_bit(BH_Lock, &(bh)->b_state)
|
||||
#define buffer_clean(bh) !test_bit(BH_Dirty, &(bh)->b_state)
|
||||
#define buffer_do_not_flush(bh) test_bit(BH_Do_not_flush, &(bh)->b_state)
|
||||
#define mark_buffer_dirty(bh) set_bit(BH_Dirty, &(bh)->b_state)
|
||||
#define mark_buffer_uptodate(bh,i) set_bit(BH_Uptodate, &(bh)->b_state)
|
||||
#define mark_buffer_clean(bh) clear_bit(BH_Dirty, &(bh)->b_state)
|
||||
#define mark_buffer_do_not_flush(bh) set_bit(BH_Do_not_flush, &(bh)->b_state)
|
||||
#define clear_buffer_do_not_flush(bh) clear_bit(BH_Do_not_flush, &(bh)->b_state)
|
||||
|
||||
/*
|
||||
printf ("%s:%s:%u %p %p %p\n",
|
||||
__FILE__, __FUNCTION__, __LINE__,
|
||||
@@ -32,26 +45,29 @@ __FILE__, __FUNCTION__, __LINE__,
|
||||
__builtin_return_address (2));
|
||||
*/
|
||||
|
||||
#define mark_buffer_uptodate(bh,i) set_bit(BH_Uptodate, &(bh)->b_state)
|
||||
#define mark_buffer_clean(bh) clear_bit(BH_Dirty, &(bh)->b_state)
|
||||
|
||||
|
||||
void __wait_on_buffer (struct buffer_head * bh);
|
||||
struct buffer_head * getblk (int dev, int block, int size);
|
||||
struct buffer_head * reiserfs_getblk (int dev, int block, int size, int *repeat);
|
||||
struct buffer_head * getblk (int dev, unsigned long block, int size);
|
||||
struct buffer_head * reiserfs_getblk (int dev, unsigned long block, int size, int *repeat);
|
||||
|
||||
struct buffer_head * find_buffer (int dev, int block, int size);
|
||||
struct buffer_head * get_hash_table(dev_t dev, int block, int size);
|
||||
struct buffer_head * find_buffer (int dev, unsigned long block, int size);
|
||||
struct buffer_head * get_hash_table(dev_t dev, unsigned long block, int size);
|
||||
struct buffer_head * bread (int dev, unsigned long block, size_t size);
|
||||
struct buffer_head * reiserfs_bread (int dev, int block, int size, int *repeat);
|
||||
struct buffer_head * reiserfs_bread (int dev, unsigned long block, int size, int *repeat);
|
||||
int valid_offset (int fd, loff_t offset);
|
||||
int bwrite (struct buffer_head * bh);
|
||||
void brelse (struct buffer_head * bh);
|
||||
void bforget (struct buffer_head * bh);
|
||||
void check_and_free_buffer_mem (void);
|
||||
void init_rollback_file (char * rollback_file, int *bloksize, FILE * log);
|
||||
int open_rollback_file (char * rollback_file, FILE * log);
|
||||
void close_rollback_file ();
|
||||
void do_fsck_rollback (int fd_device, int fd_journal_device, FILE * log);
|
||||
|
||||
void flush_buffers (void);
|
||||
void flush_buffers (dev_t);
|
||||
void free_buffers (void);
|
||||
void invalidate_buffers (dev_t dev);
|
||||
|
||||
loff_t reiserfs_llseek (unsigned int fd, loff_t offset, unsigned int origin);
|
||||
|
||||
int user_confirmed (FILE * fp, char * q, char * yes);
|
||||
+116
-22
@@ -1,42 +1,136 @@
|
||||
/*
|
||||
* Copyright 1996-2000 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
|
||||
/* nothing abount reiserfs here */
|
||||
#include <endian.h>
|
||||
#include "swab.h"
|
||||
|
||||
void die (char * fmt, ...);
|
||||
#define POSITION_FOUND 8
|
||||
#define POSITION_NOT_FOUND 9
|
||||
|
||||
void die (char * fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
void * getmem (int size);
|
||||
void freemem (void * p);
|
||||
void checkmem (char * p, int size);
|
||||
void * expandmem (void * p, int size, int by);
|
||||
int get_mem_size (char * p);
|
||||
int is_mounted (char * device_name);
|
||||
int is_mounted_read_only (char * device_name);
|
||||
void check_and_free_mem (void);
|
||||
char * kdevname (int dev);
|
||||
|
||||
|
||||
int set_bit (int nr, void * addr);
|
||||
int clear_bit (int nr, void * addr);
|
||||
int test_bit(int nr, const void * addr);
|
||||
int find_first_zero_bit (const void *vaddr, unsigned size);
|
||||
int find_next_zero_bit (const void *vaddr, unsigned size, unsigned offset);
|
||||
|
||||
void print_how_far (unsigned long * passed, unsigned long total, int inc, int quiet);
|
||||
void print_how_far (FILE * fp, unsigned long * passed, unsigned long total, int inc, int quiet);
|
||||
void print_how_fast (unsigned long total,
|
||||
unsigned long passed, int cursor_pos);
|
||||
int user_confirmed (char * q, char * yes);
|
||||
unsigned long passed, int cursor_pos, int reset_time);
|
||||
__u32 get_random (void);
|
||||
int uuid_is_null(unsigned char * uuid);
|
||||
int generate_random_uuid (unsigned char * uuid);
|
||||
int uuid_is_correct (unsigned char * uuid);
|
||||
int set_uuid (const unsigned char * text, unsigned char * UUID);
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
int le_set_bit (int nr, void * addr);
|
||||
int le_clear_bit (int nr, void * addr);
|
||||
int le_test_bit(int nr, const void * addr);
|
||||
int le_find_first_zero_bit (const void *vaddr, unsigned size);
|
||||
int le_find_next_zero_bit (const void *vaddr, unsigned size, unsigned offset);
|
||||
# define cpu_to_le16(val) (val)
|
||||
# define le16_to_cpu(val) (val)
|
||||
# define cpu_to_le32(val) (val)
|
||||
# define le32_to_cpu(val) (val)
|
||||
# define cpu_to_le64(val) (val)
|
||||
# define le64_to_cpu(val) (val)
|
||||
# define set_bit(nr, addr) le_set_bit(nr, addr)
|
||||
# define clear_bit(nr, addr) le_clear_bit(nr, addr)
|
||||
# define test_bit(nr, addr) le_test_bit(nr, addr)
|
||||
# define find_first_zero_bit(vaddr, size) le_find_first_zero_bit(vaddr, size)
|
||||
# define find_next_zero_bit(vaddr, size, off) \
|
||||
le_find_next_zero_bit(vaddr, size, off)
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
|
||||
int be_set_bit (int nr, void * addr);
|
||||
int be_clear_bit (int nr, void * addr);
|
||||
int be_test_bit(int nr, const void * addr);
|
||||
int be_find_first_zero_bit (const void *vaddr, unsigned size);
|
||||
int be_find_next_zero_bit (const void *vaddr, unsigned size, unsigned offset);
|
||||
# define cpu_to_le16(val) swab16(val)
|
||||
# define le16_to_cpu(val) swab16(val)
|
||||
# define cpu_to_le32(val) swab32(val)
|
||||
# define le32_to_cpu(val) swab32(val)
|
||||
# define cpu_to_le64(val) swab64(val)
|
||||
# define le64_to_cpu(val) swab64(val)
|
||||
# define set_bit(nr, addr) be_set_bit(nr, addr)
|
||||
# define clear_bit(nr, addr) be_clear_bit(nr, addr)
|
||||
# define test_bit(nr, addr) be_test_bit(nr, addr)
|
||||
# define find_first_zero_bit(vaddr, size) be_find_first_zero_bit(vaddr, size)
|
||||
# define find_next_zero_bit(vaddr, size, off) \
|
||||
be_find_next_zero_bit(vaddr, size, off)
|
||||
#else
|
||||
# error "nuxi/pdp-endian archs are not supported"
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
int test_and_set_bit (int nr, void * addr);
|
||||
int test_and_clear_bit (int nr, void * addr);
|
||||
*/
|
||||
inline __u32 cpu_to_le32 (__u32 val);
|
||||
inline __u32 le32_to_cpu (__u32 val);
|
||||
inline __u16 cpu_to_le16 (__u16 val);
|
||||
inline __u16 le16_to_cpu (__u16 val);
|
||||
inline __u64 cpu_to_le64 (__u64 val);
|
||||
inline __u64 le64_to_cpu (__u64 val);
|
||||
|
||||
unsigned long count_blocks (char * filename, int blocksize, int fd);
|
||||
unsigned long count_blocks (char * filename, int blocksize);
|
||||
|
||||
mode_t get_st_mode (char * file_name);
|
||||
dev_t get_st_rdev (char * file_name);
|
||||
off64_t get_st_size (char * file_name);
|
||||
blkcnt64_t get_st_blocks (char * file_name);
|
||||
|
||||
|
||||
/* these are to access bitfield in endian safe manner */
|
||||
__u16 mask16 (int from, int count);
|
||||
__u32 mask32 (int from, int count);
|
||||
__u64 mask64 (int from, int count);
|
||||
|
||||
|
||||
int reiserfs_bin_search (void * key, void * base, __u32 num, int width,
|
||||
__u32 *ppos, comparison_fn_t comp_func);
|
||||
|
||||
struct block_handler {
|
||||
__u32 blocknr;
|
||||
dev_t device;
|
||||
};
|
||||
|
||||
int blocklist__is_block_saved (struct block_handler ** base, __u32 * count, __u32 blocknr, dev_t device, __u32 * position);
|
||||
void blocklist__insert_in_position (void ** base, __u32 * count, void * block_h, int elem_size, __u32 * position);
|
||||
int blockdev_list_compare (const void * block1, const void * block2);
|
||||
|
||||
|
||||
#define set_bit_field_XX(XX,vp,val,from,count) \
|
||||
{\
|
||||
__u##XX * p, tmp;\
|
||||
\
|
||||
/* make sure that given value can be put in 'count' bits */\
|
||||
if (val > (1 << count))\
|
||||
die ("set_bit_field: val %d is too big for %d bits", val, count);\
|
||||
\
|
||||
p = (__u##XX *)vp;\
|
||||
tmp = le##XX##_to_cpu (*p);\
|
||||
\
|
||||
/* clear 'count' bits starting from 'from'-th one */\
|
||||
tmp &= ~mask##XX (from, count);\
|
||||
\
|
||||
/* put given value in proper bits */\
|
||||
tmp |= (val << from);\
|
||||
\
|
||||
*p = cpu_to_le##XX (tmp);\
|
||||
}
|
||||
|
||||
|
||||
#define get_bit_field_XX(XX,vp,from,count) \
|
||||
\
|
||||
__u##XX * p, tmp;\
|
||||
\
|
||||
p = (__u##XX *)vp;\
|
||||
tmp = le##XX##_to_cpu (*p);\
|
||||
\
|
||||
/* clear all bits but 'count' bits starting from 'from'-th one */\
|
||||
tmp &= mask##XX (from, count);\
|
||||
\
|
||||
/* get value written in specified bits */\
|
||||
tmp >>= from;\
|
||||
return tmp;
|
||||
+612
-453
File diff suppressed because it is too large.
Load diff
+285
-82
@@ -1,11 +1,13 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#ifndef REISERFS_LIB_H
|
||||
#define REISERFS_LIB_H
|
||||
|
||||
typedef struct super_block * reiserfs_filsys_t;
|
||||
|
||||
typedef struct reiserfs_filsys reiserfs_filsys_t;
|
||||
|
||||
|
||||
#include "reiserfs_fs.h"
|
||||
|
||||
@@ -14,98 +16,187 @@ struct _bitmap {
|
||||
unsigned long bm_bit_size;
|
||||
char * bm_map;
|
||||
unsigned long bm_set_bits;
|
||||
int bm_dirty; /* used for fetched bitmap */
|
||||
};
|
||||
|
||||
typedef struct _bitmap * reiserfs_bitmap_t;
|
||||
typedef struct _bitmap reiserfs_bitmap_t;
|
||||
|
||||
struct super_block {
|
||||
int s_version; /* on-disk format version */
|
||||
reiserfs_bitmap_t bitmap; /* copy of reiserfs on-disk bitmap */
|
||||
typedef __u32 (*hashf_t) (const char *, int);
|
||||
|
||||
int s_dev; /* descriptor of opened block device file */
|
||||
int s_blocksize;
|
||||
struct buffer_head ** s_ap_bitmap; /* array of buffers containing bitmap
|
||||
blocks */
|
||||
struct buffer_head * s_sbh; /* buffer containing super block */
|
||||
struct reiserfs_super_block * s_rs; /* pointer to its b_data */
|
||||
int s_dirt;
|
||||
hashf_t s_hash_function; /* pointer to function which is used to sort
|
||||
names in directory. It is set by reiserfs_open
|
||||
if it is set in the super block, otherwise it
|
||||
is set by first is_properly_hashed */
|
||||
char * file_name; /* file name of underlying device */
|
||||
int s_flags;
|
||||
void * s_vp;
|
||||
int (*block_allocator) (reiserfs_filsys_t fs,
|
||||
struct reiserfs_filsys {
|
||||
int fs_blocksize;
|
||||
int fs_format; /* on-disk format version */
|
||||
hashf_t fs_hash_function; /* pointer to function which is used to sort
|
||||
names in directory. It is set by
|
||||
reiserfs_open if it is set in the super
|
||||
block, otherwise it is set by first
|
||||
is_properly_hashed */
|
||||
|
||||
char * fs_file_name; /* file name of underlying device */
|
||||
int fs_dev; /* descriptor of opened block device file */
|
||||
struct buffer_head * fs_super_bh; /* buffer containing super block */
|
||||
struct reiserfs_super_block * fs_ondisk_sb; /* pointer to its b_data */
|
||||
|
||||
|
||||
reiserfs_bitmap_t * fs_bitmap2; /* ondisk bitmap after
|
||||
reiserfs_open_ondisk_bitmap */
|
||||
|
||||
|
||||
/* opened journal fields */
|
||||
char * fs_j_file_name; /* file name of relocated journal device */
|
||||
int fs_journal_dev; /* descriptor of opened journal device */
|
||||
struct buffer_head * fs_jh_bh; /* buffer containing journal header */
|
||||
|
||||
/* badblocks */
|
||||
reiserfs_bitmap_t * fs_badblocks_bm;
|
||||
|
||||
int fs_dirt;
|
||||
int fs_flags;
|
||||
void * fs_vp;
|
||||
int (*block_allocator) (reiserfs_filsys_t * fs,
|
||||
unsigned long * free_blocknrs,
|
||||
unsigned long start, int amount_needed);
|
||||
int (*block_deallocator) (reiserfs_filsys_t fs, unsigned long block);
|
||||
int (*block_deallocator) (reiserfs_filsys_t * fs, unsigned long block);
|
||||
};
|
||||
|
||||
|
||||
struct _transaction {
|
||||
unsigned long mount_id;
|
||||
unsigned long trans_id;
|
||||
unsigned long desc_blocknr;
|
||||
unsigned long trans_len;
|
||||
unsigned long commit_blocknr;
|
||||
unsigned long next_trans_offset;
|
||||
};
|
||||
|
||||
typedef struct _transaction reiserfs_trans_t;
|
||||
|
||||
|
||||
/* reiserfslib.c */
|
||||
|
||||
reiserfs_filsys_t reiserfs_open (char * filename, int flags, int * error, void * vp);
|
||||
void reiserfs_read_bitmap_blocks (reiserfs_filsys_t);
|
||||
void reiserfs_free_bitmap_blocks (reiserfs_filsys_t);
|
||||
int no_reiserfs_found (reiserfs_filsys_t fs);
|
||||
void reiserfs_reopen (reiserfs_filsys_t fs, int flags);
|
||||
void reiserfs_flush (reiserfs_filsys_t fs);
|
||||
void reiserfs_free (reiserfs_filsys_t fs);
|
||||
void reiserfs_close (reiserfs_filsys_t fs);
|
||||
int reiserfs_new_blocknrs (reiserfs_filsys_t fs,
|
||||
void init_tb_struct (struct tree_balance * tb, reiserfs_filsys_t *, struct path * path, int size);
|
||||
|
||||
reiserfs_filsys_t * reiserfs_open (char * filename, int flags, int * error, void * vp);
|
||||
reiserfs_filsys_t * reiserfs_create (char * filename, int version, unsigned long block_count,
|
||||
int block_size, int default_journal, int new_format);
|
||||
void reiserfs_flush (reiserfs_filsys_t *);
|
||||
void reiserfs_free (reiserfs_filsys_t *);
|
||||
void reiserfs_close (reiserfs_filsys_t *);
|
||||
void reiserfs_reopen (reiserfs_filsys_t *, int flags);
|
||||
int is_opened_rw (reiserfs_filsys_t * fs);
|
||||
|
||||
struct key * get_next_key_2 (struct path * path);
|
||||
|
||||
/*
|
||||
void reiserfs_read_bitmap_blocks (reiserfs_filsys_t *);
|
||||
void reiserfs_free_bitmap_blocks (reiserfs_filsys_t *);
|
||||
*/
|
||||
int no_reiserfs_found (reiserfs_filsys_t *);
|
||||
int is_block_count_correct (unsigned long block_of_super_block, int block_size,
|
||||
unsigned long block_count, unsigned long journal_size);
|
||||
//unsigned long min_block_amount (int block_size, unsigned long journal_size);
|
||||
unsigned long get_size_of_journal_or_reserved_area (struct reiserfs_super_block * sb);
|
||||
|
||||
int reiserfs_new_blocknrs (reiserfs_filsys_t *,
|
||||
unsigned long * free_blocknrs, unsigned long start,
|
||||
int amount_needed);
|
||||
int reiserfs_free_block (reiserfs_filsys_t fs, unsigned long block);
|
||||
int spread_bitmaps (reiserfs_filsys_t fs);
|
||||
int filesystem_dirty (reiserfs_filsys_t fs);
|
||||
void mark_filesystem_dirty (reiserfs_filsys_t fs);
|
||||
int reiserfs_free_block (reiserfs_filsys_t *, unsigned long block);
|
||||
int spread_bitmaps (reiserfs_filsys_t *);
|
||||
int filesystem_dirty (reiserfs_filsys_t *);
|
||||
void mark_filesystem_dirty (reiserfs_filsys_t *);
|
||||
|
||||
void reiserfs_paste_into_item (reiserfs_filsys_t fs, struct path * path,
|
||||
void reiserfs_paste_into_item (reiserfs_filsys_t *, struct path * path,
|
||||
const void * body, int size);
|
||||
void reiserfs_insert_item (reiserfs_filsys_t fs, struct path * path,
|
||||
void reiserfs_insert_item (reiserfs_filsys_t *, struct path * path,
|
||||
struct item_head * ih, const void * body);
|
||||
|
||||
int reiserfs_find_entry (reiserfs_filsys_t fs, struct key * dir, char * name,
|
||||
int * min_gen_counter);
|
||||
int reiserfs_add_entry (reiserfs_filsys_t fs, struct key * dir, char * name,
|
||||
int reiserfs_locate_entry (reiserfs_filsys_t *, struct key * dir, char * name,
|
||||
struct path * path);
|
||||
int reiserfs_find_entry (reiserfs_filsys_t *, struct key * dir, char * name,
|
||||
int * min_gen_counter, struct key * key);
|
||||
int reiserfs_add_entry (reiserfs_filsys_t *, struct key * dir, char * name, int name_len,
|
||||
struct key * key, int fsck_need);
|
||||
|
||||
int _search_by_entry_key (reiserfs_filsys_t fs, struct key * key,
|
||||
struct path * path);
|
||||
|
||||
/*int reiserfs_bin_search (void * key, void * base, int num, int width,
|
||||
int *ppos, comparison_fn_t comp_func);*/
|
||||
struct key * uget_lkey (struct path * path);
|
||||
struct key * uget_rkey (struct path * path);
|
||||
int reiserfs_search_by_key_3 (reiserfs_filsys_t *, struct key * key,
|
||||
struct path * path);
|
||||
int reiserfs_search_by_key_4 (reiserfs_filsys_t *, struct key * key,
|
||||
struct path * path);
|
||||
int reiserfs_search_by_entry_key (reiserfs_filsys_t *, struct key * key,
|
||||
struct path * path);
|
||||
int usearch_by_position (reiserfs_filsys_t *, struct key * key, int version, struct path * path);
|
||||
struct key * reiserfs_next_key (struct path * path);
|
||||
void copy_key (void * to, void * from);
|
||||
void copy_short_key (void * to, void * from);
|
||||
void copy_item_head(void * p_v_to, void * p_v_from);
|
||||
int comp_keys (void * k1, void * k2);
|
||||
int comp_short_keys (void * p_s_key1, void * p_s_key2);
|
||||
int comp_keys (const void * k1, const void * k2);
|
||||
int comp_keys_3 (const void * k1, const void * k2);
|
||||
int comp_short_keys (const void * p_s_key1, const void * p_s_key2);
|
||||
int comp_items (struct item_head * p_s_ih, struct path * p_s_path);
|
||||
|
||||
int create_dir_sd (reiserfs_filsys_t * fs,
|
||||
struct path * path, struct key * key,
|
||||
void (*modify_item)(struct item_head *, void *));
|
||||
void make_sure_root_dir_exists (reiserfs_filsys_t * fs,
|
||||
void (*modyfy_item)(struct item_head *, void *),
|
||||
int ih_flags);
|
||||
|
||||
int create_badblock_bitmap (reiserfs_filsys_t * fs, char * badblocks_file);
|
||||
void add_badblock_list (reiserfs_filsys_t * fs, int no_badblock_in_tree_yet);
|
||||
|
||||
|
||||
extern struct key root_dir_key;
|
||||
extern struct key parent_root_dir_key;
|
||||
extern struct key lost_found_dir_key;
|
||||
extern __u16 root_dir_format;
|
||||
extern __u16 lost_found_dir_format;
|
||||
|
||||
|
||||
/* bitmap.c */
|
||||
int reiserfs_open_ondisk_bitmap (reiserfs_filsys_t *);
|
||||
int reiserfs_create_ondisk_bitmap (reiserfs_filsys_t *);
|
||||
void reiserfs_free_ondisk_bitmap (reiserfs_filsys_t *);
|
||||
void reiserfs_close_ondisk_bitmap (reiserfs_filsys_t *);
|
||||
int reiserfs_flush_to_ondisk_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t * fs);
|
||||
|
||||
reiserfs_bitmap_t reiserfs_create_bitmap (unsigned int bit_count);
|
||||
int reiserfs_expand_bitmap (reiserfs_bitmap_t bm, unsigned int bit_count);
|
||||
void reiserfs_delete_bitmap (reiserfs_bitmap_t bm);
|
||||
void reiserfs_bitmap_copy (reiserfs_bitmap_t to, reiserfs_bitmap_t from);
|
||||
int reiserfs_bitmap_compare (reiserfs_bitmap_t bm1, reiserfs_bitmap_t bm2);
|
||||
void reiserfs_bitmap_set_bit (reiserfs_bitmap_t bm, unsigned int bit_number);
|
||||
void reiserfs_bitmap_clear_bit (reiserfs_bitmap_t bm, unsigned int bit_number);
|
||||
reiserfs_bitmap_t * reiserfs_create_bitmap (unsigned int bit_count);
|
||||
int reiserfs_expand_bitmap (reiserfs_bitmap_t * bm, unsigned int bit_count);
|
||||
void reiserfs_shrink_bitmap (reiserfs_bitmap_t * bm, unsigned int bit_count);
|
||||
void reiserfs_delete_bitmap (reiserfs_bitmap_t * bm);
|
||||
void reiserfs_bitmap_copy (reiserfs_bitmap_t * to, reiserfs_bitmap_t * from);
|
||||
int reiserfs_bitmap_compare (reiserfs_bitmap_t * bm1, reiserfs_bitmap_t * bm2);
|
||||
void reiserfs_bitmap_disjunction (reiserfs_bitmap_t * disk, reiserfs_bitmap_t * cont);
|
||||
void reiserfs_bitmap_set_bit (reiserfs_bitmap_t * bm, unsigned int bit_number);
|
||||
void reiserfs_bitmap_clear_bit (reiserfs_bitmap_t * bm, unsigned int bit_number);
|
||||
|
||||
int reiserfs_bitmap_test_bit (reiserfs_bitmap_t bm, unsigned int bit_number);
|
||||
int reiserfs_bitmap_find_zero_bit (reiserfs_bitmap_t bm, unsigned long * start);
|
||||
int reiserfs_fetch_disk_bitmap (reiserfs_bitmap_t bm, reiserfs_filsys_t fs);
|
||||
int reiserfs_flush_bitmap (reiserfs_bitmap_t bm, reiserfs_filsys_t fs);
|
||||
void reiserfs_bitmap_zero (reiserfs_bitmap_t bm);
|
||||
void reiserfs_bitmap_fill (reiserfs_bitmap_t bm);
|
||||
int reiserfs_bitmap_ones (reiserfs_bitmap_t bm);
|
||||
int reiserfs_bitmap_zeros (reiserfs_bitmap_t bm);
|
||||
int reiserfs_bitmap_test_bit (reiserfs_bitmap_t * bm, unsigned int bit_number);
|
||||
int reiserfs_bitmap_find_zero_bit (reiserfs_bitmap_t * bm, unsigned long * start);
|
||||
/*int reiserfs_fetch_ondisk_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t *);*/
|
||||
/*int reiserfs_flush_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t *);*/
|
||||
void reiserfs_bitmap_zero (reiserfs_bitmap_t * bm);
|
||||
void reiserfs_bitmap_fill (reiserfs_bitmap_t * bm);
|
||||
int reiserfs_bitmap_ones (reiserfs_bitmap_t * bm);
|
||||
int reiserfs_bitmap_zeros (reiserfs_bitmap_t * bm);
|
||||
|
||||
void reiserfs_bitmap_save (char * filename, reiserfs_bitmap_t bm);
|
||||
reiserfs_bitmap_t reiserfs_bitmap_load (char * filename);
|
||||
void reiserfs_bitmap_invert (reiserfs_bitmap_t bm);
|
||||
FILE * open_file(char * filename, char * option);
|
||||
void close_file(FILE * fp);
|
||||
void reiserfs_bitmap_save (FILE * fp, reiserfs_bitmap_t * bm);
|
||||
|
||||
/* this probably should be in fsck */
|
||||
void reiserfs_begin_stage_info_save(FILE * file, unsigned long stage);
|
||||
void reiserfs_end_stage_info_save(FILE * file);
|
||||
int is_stage_magic_correct (FILE * fp);
|
||||
//void reiserfs_stage_info_save(struct fsck_data *, FILE * file);
|
||||
|
||||
reiserfs_bitmap_t * reiserfs_bitmap_load (FILE * fp);
|
||||
void reiserfs_bitmap_invert (reiserfs_bitmap_t * bm);
|
||||
|
||||
|
||||
int reiserfs_remove_entry (reiserfs_filsys_t fs, struct key * key);
|
||||
int reiserfs_remove_entry (reiserfs_filsys_t *, struct key * key);
|
||||
|
||||
|
||||
|
||||
@@ -115,21 +206,29 @@ int reiserfs_remove_entry (reiserfs_filsys_t fs, struct key * key);
|
||||
#define THE_INTERNAL 2
|
||||
#define THE_SUPER 3
|
||||
#define THE_JDESC 4
|
||||
#define THE_UNKNOWN 5
|
||||
#define HAS_IH_ARRAY 5
|
||||
#define THE_UNKNOWN 6
|
||||
|
||||
int is_reiserfs_magic_string (struct reiserfs_super_block * rs);
|
||||
int is_reiser2fs_magic_string (struct reiserfs_super_block * rs);
|
||||
int correct_direct_item_offset (__u64 offset, int format);
|
||||
int is_blocksize_correct (int blocksize);
|
||||
int is_reiserfs_3_5_magic_string (struct reiserfs_super_block * rs);
|
||||
int is_reiserfs_3_6_magic_string (struct reiserfs_super_block * rs);
|
||||
int is_reiserfs_jr_magic_string (struct reiserfs_super_block * rs);
|
||||
int does_look_like_super_block (struct reiserfs_super_block * rs, int blocksize);
|
||||
int is_any_reiserfs_magic_string (struct reiserfs_super_block * rs);
|
||||
int get_reiserfs_format (struct reiserfs_super_block * sb);
|
||||
int reiserfs_super_block_size (struct reiserfs_super_block * rs);
|
||||
/*int magic_2_version (struct reiserfs_super_block * rs);*/
|
||||
int is_prejournaled_reiserfs (struct reiserfs_super_block * rs);
|
||||
int does_desc_match_commit (struct reiserfs_journal_desc *desc,
|
||||
struct reiserfs_journal_commit *commit);
|
||||
int who_is_this (char * buf, int blocksize);
|
||||
int journal_size (struct super_block * s);
|
||||
int not_data_block (struct super_block * s, unsigned long block);
|
||||
int not_journalable (reiserfs_filsys_t fs, unsigned long block);
|
||||
int block_of_bitmap (reiserfs_filsys_t fs, unsigned long block);
|
||||
int block_of_journal (reiserfs_filsys_t fs, unsigned long block);
|
||||
char * which_block (int code);
|
||||
int get_journal_size (reiserfs_filsys_t *);
|
||||
int not_data_block (reiserfs_filsys_t *, unsigned long block);
|
||||
int not_journalable (reiserfs_filsys_t *, unsigned long block);
|
||||
int block_of_bitmap (reiserfs_filsys_t *, unsigned long block);
|
||||
int block_of_journal (reiserfs_filsys_t *, unsigned long block);
|
||||
int is_tree_node (struct buffer_head * bh, int level);
|
||||
int is_properly_hashed (reiserfs_filsys_t fs,
|
||||
int is_properly_hashed (reiserfs_filsys_t *,
|
||||
char * name, int namelen, __u32 offset);
|
||||
int dir_entry_bad_location (struct reiserfs_de_head * deh,
|
||||
struct item_head * ih, int first);
|
||||
@@ -140,6 +239,7 @@ void make_empty_dir_item_v1 (char * body, __u32 dirid, __u32 objid,
|
||||
__u32 par_dirid, __u32 par_objid);
|
||||
void make_empty_dir_item (char * body, __u32 dirid, __u32 objid,
|
||||
__u32 par_dirid, __u32 par_objid);
|
||||
int reiserfs_is_fs_consistent (reiserfs_filsys_t * fs);
|
||||
|
||||
|
||||
typedef void (*item_action_t) (struct buffer_head * bh, struct item_head * ih);
|
||||
@@ -159,41 +259,144 @@ void set_offset (int format, struct key * key, loff_t offset);
|
||||
void set_type_and_offset (int format, struct key * key, loff_t offset, int type);
|
||||
|
||||
|
||||
typedef int (*check_unfm_func_t) (reiserfs_filsys_t fs, __u32);
|
||||
int is_it_bad_item (reiserfs_filsys_t, struct item_head *, char *,
|
||||
typedef int (*check_unfm_func_t) (reiserfs_filsys_t *, __u32);
|
||||
int is_it_bad_item (reiserfs_filsys_t *, struct item_head *, char *,
|
||||
check_unfm_func_t, int bad_dir);
|
||||
int does_node_have_ih_array (char * buf, int blocksize);
|
||||
|
||||
|
||||
#define hash_func_is_unknown(fs) ((fs)->s_hash_function == 0)
|
||||
#define reiserfs_hash(fs) ((fs)->s_hash_function)
|
||||
|
||||
#define hash_func_is_unknown(fs) ((fs)->fs_hash_function == 0)
|
||||
#define reiserfs_hash(fs) ((fs)->fs_hash_function)
|
||||
|
||||
int known_hashes (void);
|
||||
char * code2name (int code);
|
||||
int func2code (hashf_t func);
|
||||
hashf_t code2func (int code);
|
||||
hashf_t name2func (char * hash);
|
||||
int find_hash_in_use (char * name, int namelen, __u32 hash_value_masked, int code_to_try_first);
|
||||
|
||||
int entry_length (struct item_head * ih, struct reiserfs_de_head * deh,
|
||||
int pos_in_item);
|
||||
char * name_in_entry (struct reiserfs_de_head * deh, int pos_in_item);
|
||||
int name_length (struct item_head * ih,
|
||||
int name_in_entry_length (struct item_head * ih,
|
||||
struct reiserfs_de_head * deh, int pos_in_item);
|
||||
int name_length (char * name, int key_format);
|
||||
|
||||
/* access to stat data fields */
|
||||
void get_set_sd_field (int field, struct item_head * ih, void * sd,
|
||||
void * value, int set);
|
||||
#define GET_SD_MODE 0
|
||||
#define GET_SD_SIZE 1
|
||||
#define GET_SD_NLINK 2
|
||||
#define GET_SD_BLOCKS 3
|
||||
#define GET_SD_FIRST_DIRECT_BYTE 4
|
||||
|
||||
#define get_sd_mode(ih,sd,pmode) get_set_sd_field (GET_SD_MODE, ih, sd, pmode, 0/*get*/)
|
||||
#define set_sd_mode(ih,sd,pmode) get_set_sd_field (GET_SD_MODE, ih, sd, pmode, 1/*set*/)
|
||||
|
||||
#define get_sd_size(ih,sd,psize) get_set_sd_field (GET_SD_SIZE, ih, sd, psize, 0/*get*/)
|
||||
#define set_sd_size(ih,sd,psize) get_set_sd_field (GET_SD_SIZE, ih, sd, psize, 1/*set*/)
|
||||
|
||||
#define get_sd_blocks(ih,sd,pblocks) get_set_sd_field (GET_SD_BLOCKS, ih, sd, pblocks, 0/*get*/)
|
||||
#define set_sd_blocks(ih,sd,pblocks) get_set_sd_field (GET_SD_BLOCKS, ih, sd, pblocks, 1/*set*/)
|
||||
|
||||
//#define get_sd_rdev(ih,sd,pblocks) get_set_sd_field (GET_SD_RDEV, ih, sd, pblocks, 0/*get*/)
|
||||
//#define set_sd_rdev(ih,sd,pblocks) get_set_sd_field (GET_SD_RDEV, ih, sd, pblocks, 1/*set*/)
|
||||
|
||||
//#define get_sd_generation(ih,sd,pblocks) get_set_sd_field (GET_SD_GENER, ih, sd, pblocks, 0/*get*/)
|
||||
//#define set_sd_generation(ih,sd,pblocks) get_set_sd_field (GET_SD_GENER, ih, sd, pblocks, 1/*set*/)
|
||||
|
||||
#define get_sd_nlink(ih,sd,pnlink) get_set_sd_field (GET_SD_NLINK, ih, sd, pnlink, 0/*get*/)
|
||||
#define set_sd_nlink(ih,sd,pnlink) get_set_sd_field (GET_SD_NLINK, ih, sd, pnlink, 1/*set*/)
|
||||
|
||||
#define get_sd_first_direct_byte(ih,sd,pfdb) get_set_sd_field (GET_SD_FIRST_DIRECT_BYTE, ih, sd, pfdb, 0/*get*/)
|
||||
#define set_sd_first_direct_byte(ih,sd,pfdb) get_set_sd_field (GET_SD_FIRST_DIRECT_BYTE, ih, sd, pfdb, 1/*set*/)
|
||||
|
||||
int is_objectid_used (reiserfs_filsys_t * fs, __u32 objectid);
|
||||
void mark_objectid_used (reiserfs_filsys_t * fs, __u32 objectid);
|
||||
|
||||
|
||||
|
||||
/* journal.c */
|
||||
int get_boundary_transactions (reiserfs_filsys_t *, reiserfs_trans_t *,
|
||||
reiserfs_trans_t *);
|
||||
int next_transaction (reiserfs_filsys_t *, reiserfs_trans_t *, reiserfs_trans_t);
|
||||
|
||||
int replay_one_transaction (reiserfs_filsys_t *, reiserfs_trans_t *);
|
||||
|
||||
typedef void (*action_on_trans_t) (reiserfs_filsys_t *, reiserfs_trans_t *);
|
||||
void for_each_transaction (reiserfs_filsys_t *, action_on_trans_t);
|
||||
|
||||
typedef void (*action_on_block_t) (reiserfs_filsys_t *, reiserfs_trans_t *,
|
||||
int index,
|
||||
unsigned long in_journal,
|
||||
unsigned long in_place);
|
||||
void for_each_block (reiserfs_filsys_t * fs, reiserfs_trans_t * trans,
|
||||
action_on_block_t action);
|
||||
|
||||
void reiserfs_only_reopen (reiserfs_filsys_t * fs, int flag);
|
||||
int reiserfs_open_journal (reiserfs_filsys_t *, char *, int flags);
|
||||
int reiserfs_create_journal (reiserfs_filsys_t * fs, char * j_filename,
|
||||
unsigned long offset, unsigned long len,
|
||||
int transaction_max_size);
|
||||
int reiserfs_journal_opened (reiserfs_filsys_t *);
|
||||
void reiserfs_flush_journal (reiserfs_filsys_t * fs);
|
||||
void reiserfs_free_journal (reiserfs_filsys_t * fs);
|
||||
void reiserfs_close_journal (reiserfs_filsys_t *);
|
||||
void reiserfs_reopen_journal (reiserfs_filsys_t * fs, int flag);
|
||||
__u32 advise_journal_max_trans_age (void);
|
||||
__u32 advise_journal_max_commit_age (void);
|
||||
__u32 advise_journal_max_batch (unsigned long journal_trans_max);
|
||||
__u32 advise_journal_max_trans_len (__u32 desired, __u32 journal_size, int blocksize);
|
||||
|
||||
|
||||
|
||||
/* prints.c */
|
||||
void print_indirect_item (FILE * fp, struct buffer_head * bh, int item_num);
|
||||
void print_block (FILE * fp, reiserfs_filsys_t, struct buffer_head * bh, ...);//int print_mode, int first, int last);
|
||||
void print_block (FILE * fp, reiserfs_filsys_t *, struct buffer_head * bh, ...);//int print_mode, int first, int last);
|
||||
int print_super_block (FILE * fp, reiserfs_filsys_t *, char * file_name, struct buffer_head * bh, int short_print);
|
||||
void print_journal (reiserfs_filsys_t *);
|
||||
void print_journal_header (reiserfs_filsys_t * fs);
|
||||
void reiserfs_warning (FILE * fp, const char * fmt, ...);
|
||||
char ftypelet (mode_t mode);
|
||||
void reiserfs_print_item (FILE * fp, struct buffer_head * bh,
|
||||
struct item_head * ih);
|
||||
void print_filesystem_state (FILE * fp, reiserfs_filsys_t * fs);
|
||||
void print_one_transaction (reiserfs_filsys_t * fs, reiserfs_trans_t * trans);
|
||||
void print_journal_params (FILE * fp, struct journal_params * jp);
|
||||
char * get_reiserfs_version (__u16 version);
|
||||
int can_we_format_it (char * device_name, int force);
|
||||
|
||||
#define reiserfs_panic(fmt, list...) \
|
||||
{\
|
||||
fflush (stdout);\
|
||||
fprintf (stderr, "%s %d %s\n", __FILE__, __LINE__, __FUNCTION__);\
|
||||
reiserfs_warning (stderr, fmt, ## list);\
|
||||
exit(4);\
|
||||
reiserfs_warning (stderr, (const char *)fmt, ## list);\
|
||||
reiserfs_warning (stderr, "\n" );\
|
||||
abort ();\
|
||||
}
|
||||
#define reiserfs_exit(val, fmt, list...) \
|
||||
{\
|
||||
fflush (stdout);\
|
||||
fprintf (stderr, "%s %d %s\n", __FILE__, __LINE__, __FUNCTION__);\
|
||||
reiserfs_warning (stderr, (const char *)fmt, ## list);\
|
||||
reiserfs_warning (stderr, "\n" );\
|
||||
exit (val);\
|
||||
}
|
||||
|
||||
#define check_forcing_ask_confirmation(force) \
|
||||
if (force < 1) {\
|
||||
/* avoid formatting it without being forced */\
|
||||
reiserfs_warning (stderr, "Use -f to force over\n");\
|
||||
return 0;\
|
||||
}\
|
||||
if (force < 2) {\
|
||||
if (!user_confirmed (stderr, "Continue (y/n):", "y\n"))\
|
||||
return 0;\
|
||||
}\
|
||||
|
||||
|
||||
#endif /* REISERFS_LIB_H */
|
||||
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,25 @@
|
||||
#ifndef _REISERFS_SWAB_H_
|
||||
#define _REISERFS_SWAB_H_
|
||||
/* Stolen from linux/include/linux/byteorder/swab.h */
|
||||
#define swab16(x) \
|
||||
((__u16)( \
|
||||
(((__u16)(x) & (__u16)0x00ffU) << 8) | \
|
||||
(((__u16)(x) & (__u16)0xff00U) >> 8) ))
|
||||
#define swab32(x) \
|
||||
((__u32)( \
|
||||
(((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
|
||||
(((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
|
||||
(((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
|
||||
(((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
|
||||
#define swab64(x) \
|
||||
((__u64)( \
|
||||
(__u64)(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56) ))
|
||||
|
||||
#endif /* _REISERFS_SWAB_H_ */
|
||||
@@ -3,21 +3,3 @@ noinst_LIBRARIES = libmisc.a
|
||||
libmisc_a_SOURCES = io.c misc.c
|
||||
##reiserfs.c
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+9
-8
@@ -1,6 +1,6 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -62,18 +62,18 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
noinst_LIBRARIES = libmisc.a
|
||||
|
||||
libmisc_a_SOURCES = io.c misc.c
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
@@ -175,15 +175,16 @@ distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
fi; \
|
||||
done
|
||||
io.o: io.c ../include/io.h ../include/misc.h
|
||||
misc.o: misc.c ../include/io.h
|
||||
io.o: io.c ../include/io.h ../include/misc.h ../include/swab.h \
|
||||
../include/config.h
|
||||
misc.o: misc.c ../include/swab.h ../include/io.h ../include/misc.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
|
||||
@@ -7,43 +7,89 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <asm/types.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
/*#include <linux/unistd.h>*/
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
#include "io.h"
|
||||
#include "misc.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
static int is_bad_block (unsigned long block)
|
||||
{
|
||||
#ifdef IO_FAILURE_EMULATION
|
||||
|
||||
/* this array similates bad blocks on the device */
|
||||
unsigned long bad_blocks [] =
|
||||
{
|
||||
8208, 8209, 8210
|
||||
/*, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19*/
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof (bad_blocks) / sizeof (bad_blocks[0]); i ++)
|
||||
if (bad_blocks [i] == block)
|
||||
return 1;
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* All buffers are in double linked cycled list. Buffers of tree are
|
||||
hashed by their block number. If getblk found buffer with wanted
|
||||
block number in hash queue it moves buffer to the end of list */
|
||||
/* All buffers are in double linked cycled list. If getblk found buffer with
|
||||
wanted block number in hash queue it moves buffer to the end of list. */
|
||||
|
||||
#define BLOCK_SIZE 1024
|
||||
#define MAX_NR_BUFFERS 16384
|
||||
static int g_nr_buffers;
|
||||
|
||||
|
||||
static unsigned long buffers_memory;
|
||||
|
||||
/* create buffers until we spend this fraction of system memory, this
|
||||
** is a hard limit on the amount of buffer ram used
|
||||
*/
|
||||
#define BUFFER_MEMORY_FRACTION 10
|
||||
|
||||
/* number of bytes in local buffer cache before we start forcing syncs
|
||||
** of dirty data and reusing unused buffers instead of allocating new
|
||||
** ones. If a flush doesn't find reusable buffers, new ones are
|
||||
** still allocated up to the BUFFER_MEMORY_FRACTION percentage
|
||||
**
|
||||
*/
|
||||
#define BUFFER_SOFT_LIMIT (500 * 1024)
|
||||
static int buffer_soft_limit = BUFFER_SOFT_LIMIT;
|
||||
|
||||
|
||||
#define NR_HASH_QUEUES 4096
|
||||
static struct buffer_head * g_a_hash_queues [NR_HASH_QUEUES];
|
||||
static struct buffer_head * g_buffer_list_head;
|
||||
static struct buffer_head * Buffer_list_head;
|
||||
static struct buffer_head * g_free_buffers = NULL ;
|
||||
static struct buffer_head * g_buffer_heads;
|
||||
static int buffer_hits = 0 ;
|
||||
static int buffer_misses = 0 ;
|
||||
static int buffer_reads = 0 ;
|
||||
static int buffer_writes = 0 ;
|
||||
|
||||
|
||||
|
||||
static void show_buffers (int dev, int size)
|
||||
static void _show_buffers(struct buffer_head **list, int dev, int size)
|
||||
{
|
||||
int all = 0;
|
||||
int dirty = 0;
|
||||
int in_use = 0; /* count != 0 */
|
||||
int free = 0;
|
||||
struct buffer_head * next = g_buffer_list_head;
|
||||
struct buffer_head * next;
|
||||
|
||||
next = *list;
|
||||
if (!next)
|
||||
return ;
|
||||
|
||||
for (;;) {
|
||||
if (!next)
|
||||
die ("show_buffers: buffer list is corrupted");
|
||||
if (next->b_dev == dev && next->b_size == size) {
|
||||
all ++;
|
||||
if (next->b_count != 0) {
|
||||
@@ -57,11 +103,19 @@ static void show_buffers (int dev, int size)
|
||||
}
|
||||
}
|
||||
next = next->b_next;
|
||||
if (next == g_buffer_list_head)
|
||||
if (next == *list)
|
||||
break;
|
||||
}
|
||||
|
||||
printf ("show_buffers (dev %d, size %d): free %d, count != 0 %d, dirty %d, all %d\n", dev, size, free, in_use, dirty, all);
|
||||
printf ("show_buffers (dev %d, size %d): free %d, count != 0 %d, dirty %d, all %d\n",
|
||||
dev, size, free, in_use, dirty, all);
|
||||
}
|
||||
|
||||
|
||||
static void show_buffers (int dev, int size)
|
||||
{
|
||||
_show_buffers(&Buffer_list_head, dev, size) ;
|
||||
_show_buffers(&g_free_buffers, dev, size) ;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,19 +155,20 @@ static void remove_from_hash_queue (struct buffer_head * bh)
|
||||
}
|
||||
|
||||
|
||||
static void put_buffer_list_end (struct buffer_head * bh)
|
||||
static void put_buffer_list_end (struct buffer_head **list,
|
||||
struct buffer_head * bh)
|
||||
{
|
||||
struct buffer_head * last = 0;
|
||||
|
||||
if (bh->b_prev || bh->b_next)
|
||||
die ("put_buffer_list_end: buffer list corrupted");
|
||||
|
||||
if (g_buffer_list_head == 0) {
|
||||
if (*list == 0) {
|
||||
bh->b_next = bh;
|
||||
bh->b_prev = bh;
|
||||
g_buffer_list_head = bh;
|
||||
*list = bh;
|
||||
} else {
|
||||
last = g_buffer_list_head->b_prev;
|
||||
last = (*list)->b_prev;
|
||||
|
||||
bh->b_next = last->b_next;
|
||||
bh->b_prev = last;
|
||||
@@ -123,41 +178,77 @@ static void put_buffer_list_end (struct buffer_head * bh)
|
||||
}
|
||||
|
||||
|
||||
static void remove_from_buffer_list (struct buffer_head * bh)
|
||||
static void remove_from_buffer_list (struct buffer_head **list,
|
||||
struct buffer_head * bh)
|
||||
{
|
||||
if (bh == bh->b_next) {
|
||||
g_buffer_list_head = 0;
|
||||
*list = 0;
|
||||
} else {
|
||||
bh->b_prev->b_next = bh->b_next;
|
||||
bh->b_next->b_prev = bh->b_prev;
|
||||
if (bh == g_buffer_list_head)
|
||||
g_buffer_list_head = bh->b_next;
|
||||
if (bh == *list)
|
||||
*list = bh->b_next;
|
||||
}
|
||||
|
||||
bh->b_next = bh->b_prev = 0;
|
||||
}
|
||||
|
||||
|
||||
static void put_buffer_list_head (struct buffer_head * bh)
|
||||
static void put_buffer_list_head (struct buffer_head **list,
|
||||
struct buffer_head * bh)
|
||||
{
|
||||
put_buffer_list_end (bh);
|
||||
g_buffer_list_head = bh;
|
||||
put_buffer_list_end (list, bh);
|
||||
*list = bh;
|
||||
}
|
||||
|
||||
/*
|
||||
#include <sys/mman.h>
|
||||
|
||||
static size_t estimate_memory_amount (void)
|
||||
{
|
||||
size_t len = 1;
|
||||
size_t max = 0;
|
||||
void * addr;
|
||||
|
||||
while (len > 0) {
|
||||
addr = mmap (0, len, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
if (errno != ENOMEM)
|
||||
die ("mmap failed: %m\n");
|
||||
break;
|
||||
}
|
||||
if (mlock (addr, len) != 0) {
|
||||
if (errno == EPERM)
|
||||
die ("No permission to run mlock");
|
||||
break;
|
||||
}
|
||||
|
||||
munlock (addr, len);
|
||||
munmap (addr, len);
|
||||
max = len;
|
||||
len *= 2;
|
||||
}
|
||||
|
||||
// * If we've looped, we don't want to return 0, we want to return the
|
||||
// * last successful len before we looped. In the event that mmap/mlock
|
||||
// * failed for len = 1, max will still be 0, so we don't get an invalid
|
||||
// * result
|
||||
return max;
|
||||
}
|
||||
*/
|
||||
|
||||
#define GROW_BUFFERS__NEW_BUFERS_PER_CALL 10
|
||||
/* creates number of new buffers and insert them into head of buffer list
|
||||
*/
|
||||
|
||||
/* creates number of new buffers and insert them into head of buffer list */
|
||||
static int grow_buffers (int size)
|
||||
{
|
||||
int i;
|
||||
struct buffer_head * bh, * tmp;
|
||||
|
||||
if (g_nr_buffers + GROW_BUFFERS__NEW_BUFERS_PER_CALL > MAX_NR_BUFFERS)
|
||||
return 0;
|
||||
|
||||
/* get memory for array of buffer heads */
|
||||
bh = (struct buffer_head *)getmem (GROW_BUFFERS__NEW_BUFERS_PER_CALL * sizeof (struct buffer_head) + sizeof (struct buffer_head *));
|
||||
bh = (struct buffer_head *)getmem (GROW_BUFFERS__NEW_BUFERS_PER_CALL *
|
||||
sizeof (struct buffer_head) + sizeof (struct buffer_head *));
|
||||
if (g_buffer_heads == 0)
|
||||
g_buffer_heads = bh;
|
||||
else {
|
||||
@@ -177,15 +268,15 @@ static int grow_buffers (int size)
|
||||
die ("grow_buffers: no memory for new buffer data");
|
||||
tmp->b_dev = 0;
|
||||
tmp->b_size = size;
|
||||
put_buffer_list_head (tmp);
|
||||
|
||||
g_nr_buffers ++;
|
||||
put_buffer_list_head (&g_free_buffers, tmp);
|
||||
}
|
||||
buffers_memory += GROW_BUFFERS__NEW_BUFERS_PER_CALL * size;
|
||||
g_nr_buffers += GROW_BUFFERS__NEW_BUFERS_PER_CALL;
|
||||
return GROW_BUFFERS__NEW_BUFERS_PER_CALL;
|
||||
}
|
||||
|
||||
|
||||
struct buffer_head * find_buffer (int dev, int block, int size)
|
||||
struct buffer_head * find_buffer (int dev, unsigned long block, int size)
|
||||
{
|
||||
struct buffer_head * next;
|
||||
|
||||
@@ -203,98 +294,117 @@ struct buffer_head * find_buffer (int dev, int block, int size)
|
||||
return next;
|
||||
}
|
||||
|
||||
void __wait_on_buffer (struct buffer_head * bh)
|
||||
|
||||
static struct buffer_head * get_free_buffer (struct buffer_head **list,
|
||||
int size)
|
||||
{
|
||||
}
|
||||
|
||||
struct buffer_head * get_hash_table(dev_t dev, int block, int size)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
|
||||
bh = find_buffer (dev, block, size);
|
||||
if (bh) {
|
||||
bh->b_count ++;
|
||||
}
|
||||
return bh;
|
||||
}
|
||||
|
||||
|
||||
static struct buffer_head * get_free_buffer (int size)
|
||||
{
|
||||
struct buffer_head * next = g_buffer_list_head;
|
||||
struct buffer_head * next;
|
||||
|
||||
next = *list;
|
||||
if (!next)
|
||||
return 0;
|
||||
|
||||
for (;;) {
|
||||
if (!next)
|
||||
die ("get_free_buffer: buffer list is corrupted");
|
||||
if (next->b_count == 0 && buffer_clean (next) && next->b_size == size) {
|
||||
remove_from_hash_queue (next);
|
||||
remove_from_buffer_list (next);
|
||||
put_buffer_list_end (next);
|
||||
remove_from_buffer_list (list, next);
|
||||
return next;
|
||||
}
|
||||
next = next->b_next;
|
||||
if (next == g_buffer_list_head)
|
||||
if (next == *list)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void sync_buffers (int size, int to_write)
|
||||
/* to_write == 0 when all blocks have to be flushed. Otherwise - write only
|
||||
buffers with b_count == 0 */
|
||||
static int sync_buffers (struct buffer_head **list, dev_t dev, int to_write)
|
||||
{
|
||||
struct buffer_head * next = g_buffer_list_head;
|
||||
struct buffer_head * next;
|
||||
int written = 0;
|
||||
|
||||
|
||||
restart:
|
||||
next = *list;
|
||||
if (!next)
|
||||
return 0;
|
||||
for (;;) {
|
||||
if (!next)
|
||||
die ("flush_buffer: buffer list is corrupted");
|
||||
die ("sync_buffers: buffer list is corrupted");
|
||||
|
||||
if ((!size || next->b_size == size) && buffer_dirty (next) && buffer_uptodate (next)) {
|
||||
written ++;
|
||||
bwrite (next);
|
||||
if (written == to_write)
|
||||
return;
|
||||
if (next->b_dev == dev && buffer_dirty (next) && buffer_uptodate (next)) {
|
||||
if ((to_write == 0 || next->b_count == 0) && !buffer_do_not_flush (next)) {
|
||||
bwrite (next);
|
||||
}
|
||||
}
|
||||
|
||||
/* if this buffer is reusable, put it onto the end of the free list */
|
||||
if (next->b_count == 0 && buffer_clean(next)) {
|
||||
remove_from_hash_queue (next);
|
||||
remove_from_buffer_list (list, next);
|
||||
put_buffer_list_end (&g_free_buffers, next);
|
||||
written++ ;
|
||||
if (written == to_write)
|
||||
return written;
|
||||
goto restart;
|
||||
}
|
||||
if (to_write && written >= to_write)
|
||||
return written;
|
||||
|
||||
next = next->b_next;
|
||||
if (next == g_buffer_list_head)
|
||||
if (next == *list)
|
||||
break;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
void flush_buffers (void)
|
||||
|
||||
void flush_buffers (dev_t dev)
|
||||
{
|
||||
sync_buffers (0, 0);
|
||||
if (!dev)
|
||||
die ("flush_buffers: device is not specifed");
|
||||
sync_buffers (&Buffer_list_head, dev, 0/*all*/);
|
||||
buffer_soft_limit = BUFFER_SOFT_LIMIT;
|
||||
}
|
||||
|
||||
|
||||
struct buffer_head * getblk (int dev, int block, int size)
|
||||
struct buffer_head * getblk (int dev, unsigned long block, int size)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
|
||||
bh = find_buffer (dev, block, size);
|
||||
if (bh) {
|
||||
if (0 && !buffer_uptodate (bh))
|
||||
die ("getblk: buffer must be uptodate");
|
||||
// move the buffer to the end of list
|
||||
/* move the buffer to the end of list */
|
||||
|
||||
/*checkmem (bh->b_data, bh->b_size);*/
|
||||
|
||||
remove_from_buffer_list (bh);
|
||||
put_buffer_list_end (bh);
|
||||
remove_from_buffer_list (&Buffer_list_head, bh);
|
||||
put_buffer_list_end (&Buffer_list_head, bh);
|
||||
bh->b_count ++;
|
||||
buffer_hits++ ;
|
||||
return bh;
|
||||
}
|
||||
buffer_misses++ ;
|
||||
|
||||
bh = get_free_buffer (size);
|
||||
if (bh == 0) {
|
||||
if (grow_buffers (size) == 0) {
|
||||
sync_buffers (size, 10);
|
||||
bh = get_free_buffer (&g_free_buffers, size);
|
||||
if (bh == NULL) {
|
||||
if (buffers_memory >= buffer_soft_limit) {
|
||||
if (sync_buffers (&Buffer_list_head, dev, 32) == 0) {
|
||||
grow_buffers(size);
|
||||
buffer_soft_limit = buffers_memory + GROW_BUFFERS__NEW_BUFERS_PER_CALL * size;
|
||||
}
|
||||
} else {
|
||||
if (grow_buffers(size) == 0)
|
||||
sync_buffers (&Buffer_list_head, dev, 32);
|
||||
}
|
||||
bh = get_free_buffer (size);
|
||||
if (bh == 0) {
|
||||
|
||||
bh = get_free_buffer (&g_free_buffers, size);
|
||||
if (bh == NULL) {
|
||||
show_buffers (dev, size);
|
||||
die ("getblk: no free buffers after grow_buffers and refill (%d)", g_nr_buffers);
|
||||
}
|
||||
@@ -309,17 +419,13 @@ struct buffer_head * getblk (int dev, int block, int size)
|
||||
clear_bit(BH_Dirty, &bh->b_state);
|
||||
clear_bit(BH_Uptodate, &bh->b_state);
|
||||
|
||||
put_buffer_list_end (&Buffer_list_head, bh);
|
||||
insert_into_hash_queue (bh);
|
||||
/*checkmem (bh->b_data, bh->b_size);*/
|
||||
|
||||
return bh;
|
||||
}
|
||||
|
||||
struct buffer_head * reiserfs_getblk (int dev, int block, int size, int *repeat)
|
||||
{
|
||||
return getblk (dev, block, size);
|
||||
}
|
||||
|
||||
|
||||
void brelse (struct buffer_head * bh)
|
||||
{
|
||||
@@ -328,7 +434,9 @@ void brelse (struct buffer_head * bh)
|
||||
if (bh->b_count == 0) {
|
||||
die ("brelse: can not free a free buffer %lu", bh->b_blocknr);
|
||||
}
|
||||
/*checkmem (bh->b_data, bh->b_size);*/
|
||||
|
||||
/*checkmem (bh->b_data, get_mem_size (bh->b_data));*/
|
||||
|
||||
bh->b_count --;
|
||||
}
|
||||
|
||||
@@ -336,72 +444,56 @@ void brelse (struct buffer_head * bh)
|
||||
void bforget (struct buffer_head * bh)
|
||||
{
|
||||
if (bh) {
|
||||
bh->b_state = 0;
|
||||
brelse (bh);
|
||||
remove_from_hash_queue (bh);
|
||||
remove_from_buffer_list (bh);
|
||||
put_buffer_list_head (bh);
|
||||
remove_from_buffer_list(&Buffer_list_head, bh);
|
||||
if (bh->b_count == 0)
|
||||
put_buffer_list_head(&g_free_buffers, bh);
|
||||
else
|
||||
put_buffer_list_head(&Buffer_list_head, bh);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
#if ! ( defined __USE_LARGEFILE64 || defined __USE_FILE_OFFSET64 )
|
||||
_syscall5 (int, _llseek, uint, fd, ulong, hi, ulong, lo,
|
||||
loff_t *, res, uint, wh);
|
||||
#endif
|
||||
|
||||
loff_t reiserfs_llseek (unsigned int fd, loff_t offset, unsigned int origin)
|
||||
{
|
||||
#if defined __USE_FILE_OFFSET64
|
||||
return lseek(fd, offset, origin);
|
||||
#elif defined __USE_LARGEFILE64
|
||||
return lseek64(fd, offset, origin);
|
||||
#else
|
||||
loff_t retval, result;
|
||||
retval = _llseek (fd, ((unsigned long long) offset) >> 32,
|
||||
((unsigned long long) offset) & 0xffffffff,
|
||||
&result, origin);
|
||||
return (retval != 0 ? (loff_t)-1 : result);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static int f_read(struct buffer_head * bh)
|
||||
{
|
||||
loff_t offset;
|
||||
ssize_t bytes;
|
||||
|
||||
buffer_reads++ ;
|
||||
|
||||
offset = (loff_t)bh->b_size * (loff_t)bh->b_blocknr;
|
||||
/*if (reiserfs_llseek (bh->b_dev, offset, SEEK_SET) == (loff_t)-1)*/
|
||||
if (lseek64 (bh->b_dev, offset, SEEK_SET) == (loff_t)-1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
bytes = read (bh->b_dev, bh->b_data, bh->b_size);
|
||||
if (bytes != (ssize_t)bh->b_size)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
struct buffer_head * bread (int dev, unsigned long block, size_t size)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
|
||||
/*
|
||||
if ((size == 32768 && (block == 16 || 1026)) ||
|
||||
(size == 4096 && (block == 128 || block == 8211))) {
|
||||
size = 10;
|
||||
if (is_bad_block (block))
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
bh = getblk (dev, block, size);
|
||||
|
||||
/*checkmem (bh->b_data, get_mem_size(bh->b_data));*/
|
||||
|
||||
if (buffer_uptodate (bh))
|
||||
return bh;
|
||||
|
||||
if (f_read(bh) == 0)
|
||||
{
|
||||
brelse(bh);
|
||||
return 0;
|
||||
if (f_read(bh) == 0 || is_bad_block (block)) {
|
||||
/* BAD BLOCK LIST SUPPORT
|
||||
die ("%s: Cannot read a block # %lu. Specify list of badblocks\n",*/
|
||||
die ("%s: Cannot read a block # %lu.\n",
|
||||
__FUNCTION__, bh->b_blocknr);
|
||||
}
|
||||
|
||||
mark_buffer_uptodate (bh, 0);
|
||||
@@ -415,81 +507,394 @@ int valid_offset( int fd, loff_t offset)
|
||||
loff_t res;
|
||||
|
||||
/*res = reiserfs_llseek (fd, offset, 0);*/
|
||||
res = lseek64 (fd, offset, 0);
|
||||
res = lseek64 (fd, offset, SEEK_SET);
|
||||
if (res < 0)
|
||||
return 0;
|
||||
|
||||
/* if (read (fd, &ch, 1) < 0) does not wirk on files */
|
||||
if (read (fd, &ch, 1) < 1)
|
||||
return 0;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
struct buffer_head * reiserfs_bread (int dev, int block, int size, int *repeat)
|
||||
{
|
||||
return bread (dev, block, size);
|
||||
#define ROLLBACK_FILE_START_MAGIC "_RollBackFileForReiserfsFSCK"
|
||||
|
||||
static struct block_handler * rollback_blocks_array;
|
||||
static __u32 rollback_blocks_number = 0;
|
||||
static FILE * s_rollback_file = 0;
|
||||
static FILE * log_file;
|
||||
static int do_rollback = 0;
|
||||
|
||||
static char * rollback_data;
|
||||
static int rollback_blocksize;
|
||||
|
||||
void init_rollback_file (char * rollback_file, int *blocksize, FILE * log) {
|
||||
char * string;
|
||||
struct stat64 buf;
|
||||
|
||||
if (rollback_file == NULL)
|
||||
return;
|
||||
|
||||
stat64(rollback_file, &buf);
|
||||
|
||||
s_rollback_file = fopen (rollback_file, "w+");
|
||||
if (s_rollback_file == NULL) {
|
||||
fprintf (stderr, "Cannot create file %s, work w/out a rollback file\n", rollback_file);
|
||||
return;
|
||||
}
|
||||
|
||||
rollback_blocksize = *blocksize;
|
||||
|
||||
string = ROLLBACK_FILE_START_MAGIC;
|
||||
fwrite (string, 28, 1, s_rollback_file);
|
||||
fwrite (&rollback_blocksize, sizeof (rollback_blocksize), 1, s_rollback_file);
|
||||
fwrite (&rollback_blocks_number, sizeof (rollback_blocks_number), 1, s_rollback_file);
|
||||
fflush(s_rollback_file);
|
||||
|
||||
rollback_data = getmem(rollback_blocksize);
|
||||
|
||||
// printf("\ncheckmem1");
|
||||
// fflush (stdout);
|
||||
// checkmem (rollback_data, get_mem_size((char *)rollback_data));
|
||||
// printf(" OK");
|
||||
|
||||
log_file = log;
|
||||
if (log_file)
|
||||
fprintf (log_file, "rollback: file (%s) initialize\n", rollback_file);
|
||||
|
||||
do_rollback = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void erase_rollback_file (char * rollback_file) {
|
||||
close_rollback_file ();
|
||||
unlink (rollback_file);
|
||||
}
|
||||
#endif
|
||||
|
||||
int open_rollback_file (char * rollback_file, FILE * log) {
|
||||
char string [28];
|
||||
struct stat64 buf;
|
||||
|
||||
if (rollback_file == NULL)
|
||||
return -1;
|
||||
|
||||
if (stat64(rollback_file, &buf)) {
|
||||
fprintf (stderr, "Cannot stat rollback file (%s)\n", rollback_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_rollback_file = fopen (rollback_file, "r+");
|
||||
if (s_rollback_file == NULL) {
|
||||
fprintf (stderr, "Cannot open file (%s)\n", rollback_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fread (string, 28, 1, s_rollback_file);
|
||||
if (!strcmp (string, ROLLBACK_FILE_START_MAGIC)) {
|
||||
fprintf (stderr, "Specified file (%s) does not look like a rollback file\n", rollback_file);
|
||||
fclose (s_rollback_file);
|
||||
s_rollback_file = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fread (&rollback_blocksize, sizeof (rollback_blocksize), 1, s_rollback_file);
|
||||
|
||||
if (rollback_blocksize <= 0) {
|
||||
fprintf(stderr, "rollback: wrong rollback blocksize, exit\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
log_file = log;
|
||||
if (log_file)
|
||||
fprintf (log_file, "rollback: file (%s) opened\n", rollback_file);
|
||||
|
||||
do_rollback = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void close_rollback_file () {
|
||||
if (s_rollback_file == 0)
|
||||
return;
|
||||
|
||||
if (!do_rollback) {
|
||||
if (fseek (s_rollback_file, 28 + sizeof(int), SEEK_SET) == (loff_t)-1)
|
||||
return;
|
||||
fwrite (&rollback_blocks_number, sizeof (rollback_blocksize), 1, s_rollback_file);
|
||||
if (log_file != 0)
|
||||
fprintf (log_file, "rollback: %d blocks backed up\n", rollback_blocks_number);
|
||||
}
|
||||
|
||||
fclose (s_rollback_file);
|
||||
|
||||
freemem (rollback_data);
|
||||
freemem (rollback_blocks_array);
|
||||
|
||||
// fprintf (stdout, "rollback: (%u) blocks saved, \n", rollback_blocks_number);
|
||||
|
||||
/* for (i = 0; i < rollback_blocks_number; i++)
|
||||
fprintf(stdout, "device (%Lu), block number (%u)\n",
|
||||
rollback_blocks_array [i].device,
|
||||
rollback_blocks_array [i].blocknr);
|
||||
fprintf(stdout, "\n");
|
||||
*/
|
||||
}
|
||||
|
||||
void do_fsck_rollback (int fd_device, int fd_journal_device, FILE * progress) {
|
||||
loff_t offset;
|
||||
|
||||
struct stat64 buf;
|
||||
int descriptor;
|
||||
ssize_t retval;
|
||||
int count_failed = 0;
|
||||
int count_rollbacked = 0;
|
||||
|
||||
dev_t b_dev;
|
||||
dev_t n_dev = 0;
|
||||
dev_t n_journal_dev = 0;
|
||||
unsigned long total, done = 0;
|
||||
|
||||
if (fd_device == 0) {
|
||||
fprintf(stderr, "rollback: unspecified device, exit\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd_journal_device) {
|
||||
if (!fstat64 (fd_journal_device, &buf)) {
|
||||
n_journal_dev = buf.st_rdev;
|
||||
} else {
|
||||
fprintf(stderr, "rollback: specified journal device cannot be stated\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!fstat64 (fd_device, &buf)) {
|
||||
n_dev = buf.st_rdev;
|
||||
} else {
|
||||
fprintf(stderr, "rollback: specified device cannot be stated, exit\n");
|
||||
return;
|
||||
}
|
||||
|
||||
rollback_data = getmem (rollback_blocksize);
|
||||
// printf("\ncheckmem2");
|
||||
// fflush (stdout);
|
||||
// checkmem (rollback_data, get_mem_size((char *)rollback_data));
|
||||
// printf(" OK");
|
||||
|
||||
fread (&rollback_blocks_number, sizeof (rollback_blocks_number), 1, s_rollback_file);
|
||||
|
||||
total = rollback_blocks_number;
|
||||
|
||||
while (1) {
|
||||
print_how_far (progress, &done, rollback_blocks_number, 1, 0/*not quiet*/);
|
||||
|
||||
descriptor = 0;
|
||||
if ((retval = fread (&b_dev, sizeof (b_dev), 1, s_rollback_file)) <= 0) {
|
||||
if (retval)
|
||||
fprintf (stderr, "rollback: fread: %s\n", strerror (errno));
|
||||
break;
|
||||
}
|
||||
if ((retval = fread (&offset, sizeof (offset), 1, s_rollback_file)) <= 0) {
|
||||
if (retval)
|
||||
fprintf (stderr, "rollback: fread: %s\n", strerror (errno));
|
||||
break;
|
||||
}
|
||||
|
||||
if ((retval = fread (rollback_data, rollback_blocksize, 1, s_rollback_file)) <= 0) {
|
||||
if (retval)
|
||||
fprintf (stderr, "rollback: fread: %s\n", strerror (errno));
|
||||
break;
|
||||
}
|
||||
|
||||
if (n_dev == b_dev)
|
||||
descriptor = fd_device;
|
||||
if ((n_journal_dev) && (n_journal_dev == b_dev))
|
||||
descriptor = fd_journal_device;
|
||||
|
||||
if (descriptor == 0) {
|
||||
fprintf(stderr, "rollback: block from unknown device, skip block\n");
|
||||
count_failed ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lseek64 (descriptor, offset, SEEK_SET) == (loff_t)-1) {
|
||||
fprintf(stderr, "device cannot be lseeked, skip block\n");
|
||||
count_failed ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (write (descriptor, rollback_data, rollback_blocksize) == -1) {
|
||||
fprintf (stderr, "rollback: write %d bytes returned error (block=%Ld, dev=%Ld): %s\n",
|
||||
rollback_blocksize, (long long)offset/rollback_blocksize, (long long)b_dev, strerror (errno));
|
||||
count_failed ++;
|
||||
} else {
|
||||
count_rollbacked ++;
|
||||
/*if you want to know what gets rollbacked, uncomment it*/
|
||||
/* if (log_file != 0 && log_file != stdout)
|
||||
fprintf (log_file, "rollback: block %Lu of device %Lu was restored\n",
|
||||
(loff_t)offset/rollback_blocksize, b_dev);
|
||||
*/
|
||||
// fprintf (stdout, "rollback: block (%Ld) written\n", (loff_t)offset/rollback_blocksize);
|
||||
}
|
||||
}
|
||||
|
||||
printf ("\n");
|
||||
if (log_file != 0)
|
||||
fprintf (log_file, "rollback: (%u) blocks restored\n", count_rollbacked);
|
||||
}
|
||||
|
||||
/*
|
||||
static void rollback__mark_block_saved (struct block_handler * rb_e) {
|
||||
if (rollback_blocks_array == NULL)
|
||||
rollback_blocks_array = getmem (ROLLBACK__INCREASE_BLOCK_NUMBER * sizeof (*rb_e));
|
||||
|
||||
if (rollback_blocks_number == get_mem_size ((void *)rollback_blocks_array) / sizeof (*rb_e))
|
||||
rollback_blocks_array = expandmem (rollback_blocks_array, get_mem_size((void *)rollback_blocks_array),
|
||||
ROLLBACK__INCREASE_BLOCK_NUMBER * sizeof (*rb_e));
|
||||
|
||||
// checkmem ((char *)rollback_blocks_array, get_mem_size((char *)rollback_blocks_array));
|
||||
|
||||
rollback_blocks_array[rollback_blocks_number] = *rb_e;
|
||||
rollback_blocks_number ++;
|
||||
qsort (rollback_blocks_array, rollback_blocks_number, sizeof (*rb_e), rollback_compare);
|
||||
|
||||
// printf("\ncheckmem3");
|
||||
// fflush (stdout);
|
||||
// checkmem ((char *)rollback_blocks_array, get_mem_size((char *)rollback_blocks_array));
|
||||
// printf(" OK");
|
||||
}
|
||||
*/
|
||||
/* for now - just make sure that bad blocks did not get here */
|
||||
int bwrite (struct buffer_head * bh)
|
||||
{
|
||||
loff_t offset;
|
||||
ssize_t bytes;
|
||||
size_t size;
|
||||
|
||||
if (is_bad_block (bh->b_blocknr)) {
|
||||
fprintf (stderr, "bwrite: bad block is going to be written: %lu\n",
|
||||
bh->b_blocknr);
|
||||
exit (4);
|
||||
}
|
||||
|
||||
if (!buffer_dirty (bh) || !buffer_uptodate (bh))
|
||||
return 0;
|
||||
|
||||
buffer_writes++ ;
|
||||
if (bh->b_start_io)
|
||||
/* this is used by undo feature of reiserfsck */
|
||||
bh->b_start_io (bh->b_blocknr);
|
||||
|
||||
size = bh->b_size;
|
||||
offset = (loff_t)size * (loff_t)bh->b_blocknr;
|
||||
|
||||
if (lseek64 (bh->b_dev, offset, SEEK_SET) == (loff_t)-1){
|
||||
fprintf (stderr, "bwrite: lseek to position %Ld (block=%lu, dev=%d): %s\n",
|
||||
offset, bh->b_blocknr, bh->b_dev, strerror (errno));
|
||||
(long long)offset, bh->b_blocknr, bh->b_dev, strerror (errno));
|
||||
exit (4); /* File system errors left uncorrected */
|
||||
}
|
||||
|
||||
if (s_rollback_file != NULL && bh->b_size == rollback_blocksize) {
|
||||
struct stat64 buf;
|
||||
__u32 position;
|
||||
struct block_handler block_h;
|
||||
|
||||
/*log previous content into log*/
|
||||
if (!fstat64 (bh->b_dev, &buf)) {
|
||||
block_h.blocknr = bh->b_blocknr;
|
||||
block_h.device = buf.st_rdev;
|
||||
if (reiserfs_bin_search (&block_h, rollback_blocks_array, rollback_blocks_number,
|
||||
sizeof (block_h), &position, blockdev_list_compare) != POSITION_FOUND) {
|
||||
/*read initial data from the disk*/
|
||||
if (read (bh->b_dev, rollback_data, bh->b_size) == bh->b_size) {
|
||||
fwrite (&buf.st_rdev, sizeof (buf.st_rdev), 1, s_rollback_file);
|
||||
fwrite (&offset, sizeof (offset), 1, s_rollback_file);
|
||||
fwrite (rollback_data, rollback_blocksize, 1, s_rollback_file);
|
||||
fflush(s_rollback_file);
|
||||
blocklist__insert_in_position ((void **)&rollback_blocks_array, &rollback_blocks_number, &block_h,
|
||||
sizeof(block_h), &position);
|
||||
/*if you want to know what gets saved, uncomment it*/
|
||||
/* if (log_file != 0 && log_file != stdout) {
|
||||
fprintf (log_file, "rollback: block %lu of device %Lu was backed up\n",
|
||||
bh->b_blocknr, buf.st_rdev);
|
||||
}
|
||||
*/
|
||||
|
||||
} else {
|
||||
fprintf (stderr, "bwrite: read (block=%lu, dev=%d): %s\n", bh->b_blocknr,
|
||||
bh->b_dev, strerror (errno));
|
||||
exit (4);
|
||||
}
|
||||
if (lseek64 (bh->b_dev, offset, SEEK_SET) == (loff_t)-1) {
|
||||
fprintf (stderr, "bwrite: lseek to position %Ld (block=%lu, dev=%d): %s\n",
|
||||
(long long)offset, bh->b_blocknr, bh->b_dev, strerror (errno));
|
||||
exit (4);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf (stderr, "bwrite: fstat of (%d) returned -1: %s\n", bh->b_dev, strerror (errno));
|
||||
}
|
||||
} else if (s_rollback_file != NULL) {
|
||||
fprintf (stderr, "rollback: block (%lu) has the size different from the fs uses, block skipped\n",
|
||||
bh->b_blocknr);
|
||||
}
|
||||
|
||||
bytes = write (bh->b_dev, bh->b_data, size);
|
||||
if (bytes != (ssize_t)size) {
|
||||
fprintf (stderr, "bwrite: write %d bytes returned %d (block=%ld, dev=%d): %s\n",
|
||||
size, bytes, bh->b_blocknr, bh->b_dev, strerror (errno));
|
||||
fprintf (stderr, "bwrite: write %ld bytes returned %ld (block=%ld, dev=%d): %s\n",
|
||||
(long)size, (long)bytes, bh->b_blocknr, bh->b_dev, strerror (errno));
|
||||
exit (4);
|
||||
}
|
||||
|
||||
mark_buffer_clean (bh);
|
||||
|
||||
if (bh->b_end_io) {
|
||||
bh->b_end_io(bh, 1) ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void check_and_free_buffer_mem (void)
|
||||
{
|
||||
int i = 0;
|
||||
struct buffer_head * next = g_buffer_list_head;
|
||||
static int _check_and_free_buffer_list(struct buffer_head *list) {
|
||||
struct buffer_head *next = list ;
|
||||
int count = 0 ;
|
||||
if (!list)
|
||||
return 0 ;
|
||||
|
||||
//sync_buffers (0, 0);
|
||||
for (;;) {
|
||||
if (!next)
|
||||
die ("check_and_free_buffer_mem: buffer list is corrupted");
|
||||
for(;;) {
|
||||
if (next->b_count != 0)
|
||||
fprintf (stderr, "check_and_free_buffer_mem: not free buffer (%ld, %ld, %d)",
|
||||
next->b_blocknr, next->b_size, next->b_count);
|
||||
fprintf (stderr, "check_and_free_buffer_mem: not free buffer (%x, %ld, %ld, %d)\n",
|
||||
next->b_dev, next->b_blocknr, next->b_size, next->b_count);
|
||||
|
||||
if (buffer_dirty (next) && buffer_uptodate (next))
|
||||
fprintf (stderr, "check_and_free_buffer_mem: dirty buffer %lu found\n",
|
||||
next->b_blocknr);
|
||||
fprintf (stderr, "check_and_free_buffer_mem: dirty buffer (%x %lu) found\n",
|
||||
next->b_dev, next->b_blocknr);
|
||||
|
||||
freemem (next->b_data);
|
||||
i ++;
|
||||
count++;
|
||||
next = next->b_next;
|
||||
if (next == g_buffer_list_head)
|
||||
break;
|
||||
if (next == list)
|
||||
break;
|
||||
}
|
||||
if (i != g_nr_buffers)
|
||||
die ("check_and_free_buffer_mem: found %d buffers, must be %d", i, g_nr_buffers);
|
||||
return count;
|
||||
}
|
||||
|
||||
void check_and_free_buffer_mem (void)
|
||||
{
|
||||
int count = 0;
|
||||
struct buffer_head * next ;
|
||||
|
||||
// printf("check and free buffer mem, hits %d misses %d reads %d writes %d\n", buffer_hits, buffer_misses, buffer_reads, buffer_writes) ;
|
||||
/*sync_buffers (0, 0);*/
|
||||
|
||||
count = _check_and_free_buffer_list(Buffer_list_head);
|
||||
count += _check_and_free_buffer_list(g_free_buffers);
|
||||
|
||||
if (count != g_nr_buffers)
|
||||
die ("check_and_free_buffer_mem: found %d buffers, must be %d", count, g_nr_buffers);
|
||||
|
||||
/* free buffer heads */
|
||||
while ((next = g_buffer_heads)) {
|
||||
@@ -506,3 +911,47 @@ void free_buffers (void)
|
||||
{
|
||||
check_and_free_buffer_mem ();
|
||||
}
|
||||
|
||||
|
||||
static void _invalidate_buffer_list(struct buffer_head *list, dev_t dev)
|
||||
{
|
||||
struct buffer_head * next;
|
||||
|
||||
if (!list)
|
||||
return;
|
||||
|
||||
next = list;
|
||||
|
||||
for (;;) {
|
||||
if (next->b_dev == dev) {
|
||||
if (buffer_dirty (next) || next->b_count)
|
||||
fprintf (stderr, "invalidate_buffers: dirty buffer or used buffer (%d %lu) found\n",
|
||||
next->b_count, next->b_blocknr);
|
||||
next->b_state = 0;
|
||||
remove_from_hash_queue (next);
|
||||
}
|
||||
next = next->b_next;
|
||||
if (next == list)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* forget all buffers of the given device */
|
||||
void invalidate_buffers (dev_t dev)
|
||||
{
|
||||
_invalidate_buffer_list(Buffer_list_head, dev) ;
|
||||
_invalidate_buffer_list(g_free_buffers, dev) ;
|
||||
}
|
||||
|
||||
|
||||
int user_confirmed (FILE * fp, char * q, char * yes)
|
||||
{
|
||||
char * answer = 0;
|
||||
size_t n = 0;
|
||||
|
||||
fprintf (fp, "%s", q);
|
||||
if (getline (&answer, &n, stdin) != strlen (yes) || strcmp (yes, answer))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
+543
-294
@@ -1,11 +1,13 @@
|
||||
/*
|
||||
* Copyright 1996, 1997, 1998 Hans Reiser
|
||||
* Copyright 1996-2002 Hans Reiser
|
||||
*/
|
||||
/*#define _GNU_SOURCE*/
|
||||
/*#define _FILE_OFFSET_BITS 64*/
|
||||
|
||||
/* for stat64() */
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
/* for getline() proto and _LARGEFILE64_SOURCE */
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@@ -13,114 +15,28 @@
|
||||
#include <stdlib.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <unistd.h>
|
||||
//#include <linux/unistd.h>
|
||||
//#include <sys/stat.h>
|
||||
|
||||
#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64)
|
||||
# define BLKGETSIZE64 _IOR(0x12, 114, sizeof(__u64))
|
||||
#endif
|
||||
|
||||
|
||||
#include "swab.h"
|
||||
|
||||
#include "io.h"
|
||||
#include "misc.h"
|
||||
|
||||
/*
|
||||
* These have been stolen somewhere from linux
|
||||
*/
|
||||
int set_bit (int nr, void * addr)
|
||||
{
|
||||
__u8 * p, mask;
|
||||
int retval;
|
||||
|
||||
p = (__u8 *)addr;
|
||||
p += nr >> 3;
|
||||
mask = 1 << (nr & 0x7);
|
||||
/*cli();*/
|
||||
retval = (mask & *p) != 0;
|
||||
*p |= mask;
|
||||
/*sti();*/
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int clear_bit (int nr, void * addr)
|
||||
{
|
||||
__u8 * p, mask;
|
||||
int retval;
|
||||
|
||||
p = (__u8 *)addr;
|
||||
p += nr >> 3;
|
||||
mask = 1 << (nr & 0x7);
|
||||
/*cli();*/
|
||||
retval = (mask & *p) != 0;
|
||||
*p &= ~mask;
|
||||
/*sti();*/
|
||||
return retval;
|
||||
}
|
||||
|
||||
int test_bit(int nr, const void * addr)
|
||||
{
|
||||
__u8 * p, mask;
|
||||
|
||||
p = (__u8 *)addr;
|
||||
p += nr >> 3;
|
||||
mask = 1 << (nr & 0x7);
|
||||
return ((mask & *p) != 0);
|
||||
}
|
||||
|
||||
int find_first_zero_bit (const void *vaddr, unsigned size)
|
||||
{
|
||||
const __u8 *p = vaddr, *addr = vaddr;
|
||||
int res;
|
||||
|
||||
if (!size)
|
||||
return 0;
|
||||
|
||||
size = (size >> 3) + ((size & 0x7) > 0);
|
||||
while (*p++ == 255) {
|
||||
if (--size == 0)
|
||||
return (p - addr) << 3;
|
||||
}
|
||||
|
||||
--p;
|
||||
for (res = 0; res < 8; res++)
|
||||
if (!test_bit (res, p))
|
||||
break;
|
||||
return (p - addr) * 8 + res;
|
||||
}
|
||||
|
||||
|
||||
int find_next_zero_bit (const void *vaddr, unsigned size, unsigned offset)
|
||||
{
|
||||
const __u8 *addr = vaddr;
|
||||
const __u8 *p = addr + (offset >> 3);
|
||||
int bit = offset & 7, res;
|
||||
|
||||
if (offset >= size)
|
||||
return size;
|
||||
|
||||
if (bit) {
|
||||
/* Look for zero in first char */
|
||||
for (res = bit; res < 8; res++)
|
||||
if (!test_bit (res, p))
|
||||
return (p - addr) * 8 + res;
|
||||
p++;
|
||||
}
|
||||
/* No zero yet, search remaining full bytes for a zero */
|
||||
res = find_first_zero_bit (p, size - 8 * (p - addr));
|
||||
return (p - addr) * 8 + res;
|
||||
}
|
||||
|
||||
|
||||
/*int test_and_set_bit (int nr, void * addr)
|
||||
{
|
||||
int oldbit = test_bit (nr, addr);
|
||||
set_bit (nr, addr);
|
||||
return oldbit;
|
||||
}
|
||||
|
||||
|
||||
int test_and_clear_bit (int nr, void * addr)
|
||||
{
|
||||
int oldbit = test_bit (nr, addr);
|
||||
clear_bit (nr, addr);
|
||||
return oldbit;
|
||||
}*/
|
||||
/* Debian modifications by Ed Boraas <ed@debian.org> */
|
||||
#include <sys/mount.h>
|
||||
/* End Debian mods */
|
||||
|
||||
|
||||
void die (char * fmt, ...)
|
||||
@@ -133,18 +49,17 @@ void die (char * fmt, ...)
|
||||
va_end (args);
|
||||
|
||||
fprintf (stderr, "\n%s\n\n\n", buf);
|
||||
exit (-1);
|
||||
abort ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define MEM_BEGIN "_mem_begin_"
|
||||
#define MEM_END "mem_end"
|
||||
#define MEM_FREED "__free_"
|
||||
#define CONTROL_SIZE (strlen (MEM_BEGIN) + 1 + sizeof (int) + strlen (MEM_END) + 1)
|
||||
|
||||
|
||||
static int get_mem_size (char * p)
|
||||
int get_mem_size (char * p)
|
||||
{
|
||||
char * begin;
|
||||
|
||||
@@ -189,7 +104,7 @@ void * getmem (int size)
|
||||
p += size;
|
||||
strcpy (p, MEM_END);
|
||||
|
||||
checkmem (mem, size);
|
||||
// checkmem (mem, size);
|
||||
|
||||
return mem;
|
||||
}
|
||||
@@ -223,7 +138,7 @@ void * expandmem (void * vp, int size, int by)
|
||||
if(by > 0)
|
||||
memset (mem + size, 0, by);
|
||||
strcpy (mem + size + by, MEM_END);
|
||||
checkmem (mem, size + by);
|
||||
// checkmem (mem, size + by);
|
||||
|
||||
return mem;
|
||||
}
|
||||
@@ -246,48 +161,81 @@ void freemem (void * vp)
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef int (*func_t) (char *);
|
||||
|
||||
static int is_readonly_dir (char * dir)
|
||||
{
|
||||
char * name;
|
||||
FILE * f;
|
||||
/*
|
||||
int fd;
|
||||
char template [1024];
|
||||
|
||||
name = tempnam (dir, 0);
|
||||
if (!name) {
|
||||
fprintf (stderr, "is_readonly: tempnam failed, think fs is not readonly\n");
|
||||
snprintf (template, 1024, "%s/testXXXXXX", dir);
|
||||
fd = mkstemp (template);
|
||||
if (fd >= 0) {
|
||||
close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f = fopen (name, "w");
|
||||
if (f) {
|
||||
unlink (name);
|
||||
free (name);
|
||||
*/
|
||||
if (utime (dir, 0) != -1)
|
||||
/* this is not ro mounted fs */
|
||||
return 0;
|
||||
}
|
||||
free (name);
|
||||
return (errno == EROFS) ? 1 : 0;
|
||||
}
|
||||
|
||||
int user_confirmed (char * q, char * yes)
|
||||
{
|
||||
char * answer = 0;
|
||||
size_t n = 0;
|
||||
|
||||
fprintf (stderr, "%s", q);
|
||||
if (getline (&answer, &n, stdin) != strlen (yes) || strcmp (yes, answer))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef __i386__
|
||||
|
||||
#include <unistd.h>
|
||||
#include <linux/unistd.h>
|
||||
|
||||
#define __NR_stat64 195
|
||||
_syscall2(long, stat64, char *, filename, struct stat *, statbuf);
|
||||
#define __NR_bad_stat64 195
|
||||
_syscall2(long, bad_stat64, char *, filename, struct stat64 *, statbuf);
|
||||
|
||||
#else
|
||||
|
||||
#define bad_stat64 stat64
|
||||
|
||||
#endif
|
||||
|
||||
/* yes, I know how ugly it is */
|
||||
#define return_stat_field(field) \
|
||||
struct stat st;\
|
||||
struct stat64 st64;\
|
||||
\
|
||||
if (bad_stat64 (file_name, &st64) == 0) {\
|
||||
return st64.st_##field;\
|
||||
} else if (stat (file_name, &st) == 0)\
|
||||
return st.st_##field;\
|
||||
\
|
||||
perror ("stat failed");\
|
||||
exit (1);\
|
||||
|
||||
|
||||
mode_t get_st_mode (char * file_name)
|
||||
{
|
||||
return_stat_field (mode);
|
||||
}
|
||||
|
||||
|
||||
/* may I look at this undocumented (at least in the info of libc 2.3.1-58)
|
||||
field? */
|
||||
dev_t get_st_rdev (char * file_name)
|
||||
{
|
||||
return_stat_field (rdev);
|
||||
}
|
||||
|
||||
|
||||
off64_t get_st_size (char * file_name)
|
||||
{
|
||||
return_stat_field (size);
|
||||
}
|
||||
|
||||
|
||||
blkcnt64_t get_st_blocks (char * file_name)
|
||||
{
|
||||
return_stat_field (blocks);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int _is_mounted (char * device_name, func_t f)
|
||||
@@ -297,27 +245,22 @@ static int _is_mounted (char * device_name, func_t f)
|
||||
struct mntent *mnt;
|
||||
struct statfs stfs;
|
||||
struct stat root_st;
|
||||
struct stat device_st;
|
||||
/* struct stat64 device_st64;*/
|
||||
int used_stat64 = 1;
|
||||
mode_t mode;
|
||||
|
||||
if (stat ("/", &root_st) == -1)
|
||||
die ("is_mounted: could not stat \"/\": %m\n");
|
||||
|
||||
if (stat64 (device_name, &device_st) == -1) {
|
||||
used_stat64 = 0;
|
||||
if (stat (device_name, &device_st) == -1)
|
||||
die ("is_mounted: could not stat file \"%s\": %m",
|
||||
device_name);
|
||||
}
|
||||
|
||||
if ((used_stat64 && !S_ISBLK (device_st.st_mode)) || !S_ISBLK (device_st.st_mode))
|
||||
/* not block device file could not be mounted */
|
||||
mode = get_st_mode (device_name);
|
||||
if (S_ISREG (mode))
|
||||
/* regular file can not be mounted */
|
||||
return 0;
|
||||
|
||||
if ((used_stat64 && root_st.st_dev == device_st.st_rdev) ||
|
||||
root_st.st_dev == device_st.st_rdev) {
|
||||
/* device is mounted as root */
|
||||
if (!S_ISBLK (mode))
|
||||
die ("is_mounted: %s is neither regular file nor block device", device_name);
|
||||
|
||||
if (root_st.st_dev == get_st_rdev (device_name)) {
|
||||
/* device is mounted as root. Check whether it is mounted read-only */
|
||||
return (f ? f ("/") : 1);
|
||||
}
|
||||
|
||||
@@ -327,17 +270,17 @@ static int _is_mounted (char * device_name, func_t f)
|
||||
/* proc filesystem is not mounted, or /proc/mounts does not
|
||||
exist */
|
||||
if (f)
|
||||
return (user_confirmed (" (could not figure out) Is filesystem mounted read-only? (Yes)",
|
||||
return (user_confirmed (stderr, " (could not figure out) Is filesystem mounted read-only? (Yes)",
|
||||
"Yes\n"));
|
||||
else
|
||||
return (user_confirmed (" (could not figure out) Is filesystem mounted? (Yes)",
|
||||
return (user_confirmed (stderr, " (could not figure out) Is filesystem mounted? (Yes)",
|
||||
"Yes\n"));
|
||||
}
|
||||
|
||||
retval = 0;
|
||||
while ((mnt = getmntent (fp)) != NULL)
|
||||
if (strcmp (device_name, mnt->mnt_fsname) == 0) {
|
||||
retval = (f ? f (mnt->mnt_dir) : 1);
|
||||
retval = (f ? f (mnt->mnt_dir) : 1/*mounted*/);
|
||||
break;
|
||||
}
|
||||
endmntent (fp);
|
||||
@@ -364,7 +307,7 @@ char buf2 [100];
|
||||
void print_how_fast (unsigned long passed, unsigned long total,
|
||||
int cursor_pos, int reset_time)
|
||||
{
|
||||
static time_t t0, t1;
|
||||
static time_t t0 = 0, t1 = 0, t2 = 0;
|
||||
int speed;
|
||||
int indent;
|
||||
|
||||
@@ -372,9 +315,14 @@ void print_how_fast (unsigned long passed, unsigned long total,
|
||||
time (&t0);
|
||||
|
||||
time (&t1);
|
||||
if (t1 != t0)
|
||||
if (t1 != t0) {
|
||||
speed = passed / (t1 - t0);
|
||||
else
|
||||
if (total - passed) {
|
||||
if (t1 - t2 < 1)
|
||||
return;
|
||||
t2 = t1;
|
||||
}
|
||||
} else
|
||||
speed = 0;
|
||||
|
||||
/* what has to be written */
|
||||
@@ -414,7 +362,8 @@ static void str_to_be (char * buf, int prosents)
|
||||
}
|
||||
|
||||
|
||||
void print_how_far (unsigned long * passed, unsigned long total,
|
||||
void print_how_far (FILE * fp,
|
||||
unsigned long * passed, unsigned long total,
|
||||
int inc, int quiet)
|
||||
{
|
||||
int percent;
|
||||
@@ -424,8 +373,8 @@ void print_how_far (unsigned long * passed, unsigned long total,
|
||||
|
||||
(*passed) += inc;
|
||||
if (*passed > total) {
|
||||
fprintf (stderr, "\nprint_how_far: total %lu has been reached already. cur=%lu\n",
|
||||
total, *passed);
|
||||
/* fprintf (fp, "\nprint_how_far: total %lu has been reached already. cur=%lu\n",
|
||||
total, *passed);*/
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -434,7 +383,7 @@ void print_how_far (unsigned long * passed, unsigned long total,
|
||||
str_to_be (progress_to_be, percent);
|
||||
|
||||
if (strlen (current_progress) != strlen (progress_to_be)) {
|
||||
fprintf (stderr, "%s", progress_to_be + strlen (current_progress));
|
||||
fprintf (fp, "%s", progress_to_be + strlen (current_progress));
|
||||
}
|
||||
|
||||
strcat (current_progress, progress_to_be + strlen (current_progress));
|
||||
@@ -443,149 +392,47 @@ void print_how_far (unsigned long * passed, unsigned long total,
|
||||
print_how_fast (*passed/* - inc*/, total, strlen (progress_to_be),
|
||||
(*passed == inc) ? 1 : 0);
|
||||
|
||||
fflush (stderr);
|
||||
fflush (fp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define ENDIANESS_NOT_DEFINED 0
|
||||
#define LITTLE_ENDIAN_ARCH 1
|
||||
#define BIG_ENDIAN_ARCH 2
|
||||
|
||||
static int endianess = ENDIANESS_NOT_DEFINED;
|
||||
|
||||
|
||||
static void find_endianess (void)
|
||||
{
|
||||
__u32 x = 0x0f0d0b09;
|
||||
char * s;
|
||||
|
||||
s = (char *)&x;
|
||||
|
||||
// little-endian is 1234
|
||||
if (s[0] == '\11' && s[1] == '\13' && s[2] == '\15' && s[3] == '\17')
|
||||
endianess = LITTLE_ENDIAN_ARCH;
|
||||
|
||||
// big-endian is 4321
|
||||
if (s[0] == '\17' && s[1] == '\15' && s[2] == '\13' && s[3] == '\11')
|
||||
die ("big-endian archs are not supported");
|
||||
|
||||
// nuxi/pdp-endian is 3412
|
||||
if (s[0] == '\15' && s[1] == '\17' && s[2] == '\11' && s[3] == '\13')
|
||||
die ("nuxi/pdp-endian archs are not supported");
|
||||
}
|
||||
|
||||
|
||||
// we used to use such function in the kernel stuff of reiserfs. Lets
|
||||
// have them in utils as well
|
||||
inline __u32 cpu_to_le32 (__u32 val)
|
||||
{
|
||||
if (endianess == ENDIANESS_NOT_DEFINED)
|
||||
find_endianess ();
|
||||
|
||||
if (endianess == LITTLE_ENDIAN_ARCH)
|
||||
return val;
|
||||
|
||||
die ("neither big- nor any other endian archs are supported yet ");
|
||||
|
||||
return ((val>>24) | ((val>>8)&0xFF00) |
|
||||
((val<<8)&0xFF0000) | (val<<24));
|
||||
}
|
||||
|
||||
|
||||
inline __u32 le32_to_cpu (__u32 val)
|
||||
{
|
||||
return cpu_to_le32 (val);
|
||||
}
|
||||
|
||||
|
||||
inline __u16 cpu_to_le16 (__u16 val)
|
||||
{
|
||||
return val;
|
||||
|
||||
if (endianess == ENDIANESS_NOT_DEFINED)
|
||||
find_endianess ();
|
||||
|
||||
if (endianess == LITTLE_ENDIAN_ARCH)
|
||||
return val;
|
||||
die ("neither big- nor pdp- endian arch are supported yet ");
|
||||
|
||||
return (val >> 8) | (val << 8);
|
||||
}
|
||||
|
||||
|
||||
inline __u16 le16_to_cpu (__u16 val)
|
||||
{
|
||||
/*printf ("%s:%u %p %p %p\n", __FILE__, __LINE__,
|
||||
__builtin_return_address (0),
|
||||
__builtin_return_address (1),
|
||||
__builtin_return_address (2));*/
|
||||
return val;
|
||||
return cpu_to_le16 (val);
|
||||
}
|
||||
|
||||
|
||||
inline __u64 cpu_to_le64 (__u64 val)
|
||||
{
|
||||
if (endianess == ENDIANESS_NOT_DEFINED)
|
||||
find_endianess ();
|
||||
|
||||
if (endianess == LITTLE_ENDIAN_ARCH)
|
||||
return val;
|
||||
die ("neither big- nor pdp- endian arch are supported yet ");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline __u64 le64_to_cpu (__u64 val)
|
||||
{
|
||||
return cpu_to_le64 (val);
|
||||
}
|
||||
|
||||
|
||||
/* Given a file descriptor and an offset, check whether the offset is
|
||||
a valid offset for the file - return 0 if it isn't valid or 1 if it
|
||||
is */
|
||||
loff_t reiserfs_llseek (unsigned int fd, loff_t offset, unsigned int origin);
|
||||
#if 0
|
||||
static int valid_offset( int fd, loff_t offset )
|
||||
{
|
||||
char ch;
|
||||
loff_t res;
|
||||
|
||||
/*res = reiserfs_llseek (fd, offset, 0);*/
|
||||
res = lseek64 (fd, offset, 0);
|
||||
if (res < 0)
|
||||
return 0;
|
||||
|
||||
if (read (fd, &ch, 1) < 1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* calculates number of blocks on device */
|
||||
unsigned long count_blocks (char * filename, int blocksize, int fd)
|
||||
/* calculates number of blocks in a file. Returns 0 for "sparse"
|
||||
regular files and files other than regular files and block devices */
|
||||
unsigned long count_blocks (char * filename, int blocksize)
|
||||
{
|
||||
loff_t high, low;
|
||||
int opened_here = 0;
|
||||
int fd;
|
||||
|
||||
if (fd < 0) {
|
||||
fd = open (filename, O_RDONLY);
|
||||
opened_here = 1;
|
||||
}
|
||||
if (fd < 0)
|
||||
if (!S_ISBLK (get_st_mode (filename)) && !S_ISREG (get_st_mode (filename)))
|
||||
return 0;
|
||||
|
||||
fd = open (filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
die ("count_blocks: open failed (%s)", strerror (errno));
|
||||
|
||||
#ifdef BLKGETSIZE64
|
||||
{
|
||||
__u64 size;
|
||||
unsigned long sz;
|
||||
|
||||
if (ioctl (fd, BLKGETSIZE64, &size) >= 0) {
|
||||
size /= blocksize;
|
||||
sz = size;
|
||||
if ((__u64)sz != size)
|
||||
die ("count_blocks: block device too large");
|
||||
return sz;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BLKGETSIZE
|
||||
{
|
||||
long size;
|
||||
unsigned long size;
|
||||
|
||||
if (ioctl (fd, BLKGETSIZE, &size) >= 0) {
|
||||
if (opened_here)
|
||||
close (fd);
|
||||
return size / (blocksize / 512);
|
||||
}
|
||||
}
|
||||
@@ -603,11 +450,413 @@ unsigned long count_blocks (char * filename, int blocksize, int fd)
|
||||
high = mid;
|
||||
}
|
||||
valid_offset (fd, 0);
|
||||
if (opened_here)
|
||||
close (fd);
|
||||
|
||||
close (fd);
|
||||
|
||||
return (low + 1) / (blocksize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* These have been stolen somewhere from linux
|
||||
*/
|
||||
int le_set_bit (int nr, void * addr)
|
||||
{
|
||||
__u8 * p, mask;
|
||||
int retval;
|
||||
|
||||
p = (__u8 *)addr;
|
||||
p += nr >> 3;
|
||||
mask = 1 << (nr & 0x7);
|
||||
/*cli();*/
|
||||
retval = (mask & *p) != 0;
|
||||
*p |= mask;
|
||||
/*sti();*/
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int le_clear_bit (int nr, void * addr)
|
||||
{
|
||||
__u8 * p, mask;
|
||||
int retval;
|
||||
|
||||
p = (__u8 *)addr;
|
||||
p += nr >> 3;
|
||||
mask = 1 << (nr & 0x7);
|
||||
/*cli();*/
|
||||
retval = (mask & *p) != 0;
|
||||
*p &= ~mask;
|
||||
/*sti();*/
|
||||
return retval;
|
||||
}
|
||||
|
||||
int le_test_bit(int nr, const void * addr)
|
||||
{
|
||||
__u8 * p, mask;
|
||||
|
||||
p = (__u8 *)addr;
|
||||
p += nr >> 3;
|
||||
mask = 1 << (nr & 0x7);
|
||||
return ((mask & *p) != 0);
|
||||
}
|
||||
|
||||
int le_find_first_zero_bit (const void *vaddr, unsigned size)
|
||||
{
|
||||
const __u8 *p = vaddr, *addr = vaddr;
|
||||
int res;
|
||||
|
||||
if (!size)
|
||||
return 0;
|
||||
|
||||
size = (size >> 3) + ((size & 0x7) > 0);
|
||||
while (*p++ == 255) {
|
||||
if (--size == 0)
|
||||
return (p - addr) << 3;
|
||||
}
|
||||
|
||||
--p;
|
||||
for (res = 0; res < 8; res++)
|
||||
if (!test_bit (res, p))
|
||||
break;
|
||||
return (p - addr) * 8 + res;
|
||||
}
|
||||
|
||||
|
||||
int le_find_next_zero_bit (const void *vaddr, unsigned size, unsigned offset)
|
||||
{
|
||||
const __u8 *addr = vaddr;
|
||||
const __u8 *p = addr + (offset >> 3);
|
||||
int bit = offset & 7, res;
|
||||
|
||||
if (offset >= size)
|
||||
return size;
|
||||
|
||||
if (bit) {
|
||||
/* Look for zero in first char */
|
||||
for (res = bit; res < 8; res++)
|
||||
if (!test_bit (res, p))
|
||||
return (p - addr) * 8 + res;
|
||||
p++;
|
||||
}
|
||||
/* No zero yet, search remaining full bytes for a zero */
|
||||
res = find_first_zero_bit (p, size - 8 * (p - addr));
|
||||
return (p - addr) * 8 + res;
|
||||
}
|
||||
|
||||
int be_set_bit (int nr, void * addr)
|
||||
{
|
||||
__u8 mask = 1 << (nr & 0x7);
|
||||
__u8 *p = (__u8 *) addr + (nr >> 3);
|
||||
__u8 old = *p;
|
||||
|
||||
*p |= mask;
|
||||
|
||||
return (old & mask) != 0;
|
||||
}
|
||||
|
||||
int be_clear_bit (int nr, void * addr)
|
||||
{
|
||||
__u8 mask = 1 << (nr & 0x07);
|
||||
__u8 *p = (unsigned char *) addr + (nr >> 3);
|
||||
__u8 old = *p;
|
||||
|
||||
*p = *p & ~mask;
|
||||
return (old & mask) != 0;
|
||||
}
|
||||
|
||||
int be_test_bit(int nr, const void * addr)
|
||||
{
|
||||
const __u8 *ADDR = (__const__ __u8 *) addr;
|
||||
|
||||
return ((ADDR[nr >> 3] >> (nr & 0x7)) & 1) != 0;
|
||||
}
|
||||
|
||||
int be_find_first_zero_bit (const void *vaddr, unsigned size)
|
||||
{
|
||||
return find_next_zero_bit( vaddr, size, 0 );
|
||||
}
|
||||
|
||||
static unsigned long ffz(unsigned long word)
|
||||
{
|
||||
unsigned long result = 0;
|
||||
|
||||
while(word & 1) {
|
||||
result++;
|
||||
word >>= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* stolen from linux/include/asm-mips/bitops.h:ext2_find_next_zero_bit()
|
||||
* the bitfield is assumed to be little endian, which is the case here,
|
||||
* since we're reading/writing from the disk in LE order */
|
||||
int be_find_next_zero_bit (const void *vaddr, unsigned size, unsigned offset)
|
||||
{
|
||||
__u32 *p = ((__u32 *) vaddr) + (offset >> 5);
|
||||
__u32 result = offset & ~31UL;
|
||||
__u32 tmp;
|
||||
|
||||
if (offset >= size)
|
||||
return size;
|
||||
size -= result;
|
||||
offset &= 31UL;
|
||||
if (offset) {
|
||||
tmp = *(p++);
|
||||
tmp |= swab32(~0UL >> (32-offset));
|
||||
if (size < 32)
|
||||
goto found_first;
|
||||
if (~tmp)
|
||||
goto found_middle;
|
||||
size -= 32;
|
||||
result += 32;
|
||||
}
|
||||
while (size & ~31UL) {
|
||||
if (~(tmp = *(p++)))
|
||||
goto found_middle;
|
||||
result += 32;
|
||||
size -= 32;
|
||||
}
|
||||
if (!size)
|
||||
return result;
|
||||
tmp = *p;
|
||||
|
||||
found_first:
|
||||
return result + ffz(swab32(tmp) | (~0UL << size));
|
||||
found_middle:
|
||||
return result + ffz(swab32(tmp));
|
||||
}
|
||||
|
||||
/* there are masks for certain bits */
|
||||
__u16 mask16 (int from, int count)
|
||||
{
|
||||
__u16 mask;
|
||||
|
||||
|
||||
mask = (0xffff >> from);
|
||||
mask <<= from;
|
||||
mask <<= (16 - from - count);
|
||||
mask >>= (16 - from - count);
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
__u32 mask32 (int from, int count)
|
||||
{
|
||||
__u32 mask;
|
||||
|
||||
|
||||
mask = (0xffffffff >> from);
|
||||
mask <<= from;
|
||||
mask <<= (32 - from - count);
|
||||
mask >>= (32 - from - count);
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
__u64 mask64 (int from, int count)
|
||||
{
|
||||
__u64 mask;
|
||||
|
||||
|
||||
mask = (0xffffffffffffffffLL >> from);
|
||||
mask <<= from;
|
||||
mask <<= (64 - from - count);
|
||||
mask >>= (64 - from - count);
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
__u32 get_random (void)
|
||||
{
|
||||
srandom (time (0));
|
||||
return random ();
|
||||
}
|
||||
|
||||
/* this implements binary search in the array 'base' among 'num' elements each
|
||||
of those is 'width' bytes long. 'comp_func' is used to compare keys */
|
||||
int reiserfs_bin_search (void * key, void * base, __u32 num, int width,
|
||||
__u32 * ppos, comparison_fn_t comp_func)
|
||||
{
|
||||
__u32 rbound, lbound, j;
|
||||
int ret;
|
||||
|
||||
if (num == 0 || base == NULL) {
|
||||
/* objectid map may be 0 elements long */
|
||||
*ppos = 0;
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
|
||||
lbound = 0;
|
||||
rbound = num - 1;
|
||||
|
||||
for (j = (rbound + lbound) / 2; lbound <= rbound; j = (rbound + lbound) / 2) {
|
||||
ret = comp_func ((void *)((char *)base + j * width), key ) ;
|
||||
if (ret < 0) { /* second is greater */
|
||||
lbound = j + 1;
|
||||
continue;
|
||||
|
||||
} else if (ret > 0) { /* first is greater */
|
||||
if (j == 0)
|
||||
break;
|
||||
rbound = j - 1;
|
||||
continue;
|
||||
} else { /* equal */
|
||||
*ppos = j;
|
||||
return POSITION_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
*ppos = lbound;
|
||||
return POSITION_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
#define BLOCKLIST__INCREASE_BLOCK_NUMBER 10
|
||||
|
||||
/*element is block number and device*/
|
||||
int blockdev_list_compare (const void * block1, const void * block2) {
|
||||
if (*(__u32 *)block1 < *(__u32 *)block2)
|
||||
return -1;
|
||||
if (*(__u32 *)block1 > *(__u32 *)block2)
|
||||
return 1;
|
||||
|
||||
if (*((__u32 *)block1 + 1) < *((__u32 *)block2 + 1))
|
||||
return -1;
|
||||
if (*((__u32 *)block1 + 1) > *((__u32 *)block2 + 1))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return -1 if smth found, otherwise return position which new item should be inserted into */
|
||||
/*
|
||||
int blocklist__is_block_saved (struct block_handler ** base, __u32 * count,
|
||||
__u32 blocknr, dev_t device, __u32 * position) {
|
||||
struct block_handler block_h;
|
||||
|
||||
*position = 0;
|
||||
|
||||
if (*base == NULL)
|
||||
return 0;
|
||||
|
||||
block_h.blocknr = blocknr;
|
||||
block_h.device = device;
|
||||
|
||||
if (reiserfs_bin_search (&block_h, *base, *count, sizeof (block_h),
|
||||
position, blocklist_compare) == POSITION_FOUND)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
void blocklist__insert_in_position (void ** base, __u32 * count, void * elem,
|
||||
int elem_size, __u32 * position) {
|
||||
if (elem_size == 0)
|
||||
return;
|
||||
|
||||
if (*base == NULL)
|
||||
*base = getmem (BLOCKLIST__INCREASE_BLOCK_NUMBER * elem_size);
|
||||
|
||||
if (*count == get_mem_size ((void *)*base) / elem_size)
|
||||
*base = expandmem (*base, get_mem_size((void *)*base),
|
||||
BLOCKLIST__INCREASE_BLOCK_NUMBER * elem_size);
|
||||
|
||||
if (*position < *count) {
|
||||
memmove (*base + (*position + 1),
|
||||
*base + (*position),
|
||||
(*count - *position) * elem_size);
|
||||
}
|
||||
|
||||
memcpy (*base + (char) *position * elem_size, elem, elem_size);
|
||||
*count+=1;
|
||||
}
|
||||
|
||||
static int get_random_bytes (void *out, int size) {
|
||||
int fd;
|
||||
|
||||
if ((fd = open("/dev/urandom", O_RDONLY)) == -1)
|
||||
return 1;
|
||||
|
||||
if (read(fd, out, size) <= 0) {
|
||||
close (fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int generate_random_uuid (unsigned char * uuid)
|
||||
{
|
||||
if (get_random_bytes(uuid, 16)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set the UUID variant to DCE */
|
||||
uuid[8] = (uuid[8] & 0x3F) | 0x80;
|
||||
/* Set UUID version to 4 --- truely random generation */
|
||||
uuid[6] = (uuid[6] & 0x0F) | 0x40;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uuid_is_correct (unsigned char * uuid)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
if (uuid[i])
|
||||
break;
|
||||
|
||||
if (i == 16)
|
||||
return 0;
|
||||
|
||||
if (!test_bit(7, &uuid[8]) || test_bit(6, &uuid[8]))
|
||||
return 0;
|
||||
|
||||
if (test_bit(7, &uuid[6]) || !test_bit(6, &uuid[6]) ||
|
||||
test_bit(5, &uuid[6]) || test_bit(4, &uuid[6]))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int parse_uuid (const unsigned char * in, unsigned char * uuid)
|
||||
{
|
||||
int i, j = 0;
|
||||
unsigned char frame[3];
|
||||
|
||||
if (strlen(in) != 36)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < 36; i++) {
|
||||
if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) {
|
||||
if (in[i] != '-')
|
||||
return 0;
|
||||
} else if (!isxdigit(in[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
frame[2] = 0;
|
||||
for (i = 0; i < 36; i ++) {
|
||||
if ((i == 8) || (i == 13) || (i == 18) || (i == 23))
|
||||
continue;
|
||||
|
||||
frame[0] = in[i++];
|
||||
frame[1] = in[i];
|
||||
uuid[j++] = strtoul(frame, NULL, 16);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int set_uuid (const unsigned char * text, unsigned char * UUID)
|
||||
{
|
||||
if (parse_uuid (text, UUID) || !uuid_is_correct(UUID))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,5 @@ mkreiserfs_SOURCES = mkreiserfs.c
|
||||
man_MANS = mkreiserfs.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
|
||||
INCLUDES = -I../include
|
||||
+11
-9
@@ -1,6 +1,6 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -62,6 +62,7 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
sbin_PROGRAMS = mkreiserfs
|
||||
|
||||
@@ -69,21 +70,21 @@ mkreiserfs_SOURCES = mkreiserfs.c
|
||||
man_MANS = mkreiserfs.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
|
||||
INCLUDES = -I../include
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
PROGRAMS = $(sbin_PROGRAMS)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
mkreiserfs_OBJECTS = mkreiserfs.o
|
||||
mkreiserfs_LDADD = $(LDADD)
|
||||
mkreiserfs_DEPENDENCIES = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
mkreiserfs_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
|
||||
$(top_srcdir)/reiserfscore/libcore.a
|
||||
mkreiserfs_LDFLAGS =
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@@ -238,7 +239,7 @@ distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
@@ -246,7 +247,8 @@ distdir: $(DISTFILES)
|
||||
fi; \
|
||||
done
|
||||
mkreiserfs.o: mkreiserfs.c ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h ../version.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
|
||||
+77
-36
@@ -1,62 +1,103 @@
|
||||
.\" -*- nroff -*-
|
||||
.\" Copyright 1996-2001 Hans Reiser.
|
||||
.\" Copyright 1996-2002 Hans Reiser.
|
||||
.\"
|
||||
.TH MKREISERFS 8 "March 2001" "Reiserfsprogs-3.x.0j"
|
||||
.TH MKREISERFS 8 "January 2002" "Reiserfsprogs-3.6.2"
|
||||
.SH NAME
|
||||
mkreiserfs \- create a Linux Reiserfs file system
|
||||
mkreiserfs \- create a Linux ReiserFS file system
|
||||
.SH SYNOPSIS
|
||||
.B mkreiserfs
|
||||
[
|
||||
.B -h
|
||||
.I r5
|
||||
|
|
||||
.I tea
|
||||
|
|
||||
.I rupasov
|
||||
] [
|
||||
.B \-v
|
||||
.I 1
|
||||
|
|
||||
.I 2
|
||||
] [
|
||||
.B -q
|
||||
]
|
||||
.I device
|
||||
[
|
||||
.I size-in-blocks
|
||||
]
|
||||
[ \fB-dfV\fR ]
|
||||
[ \fB-b\fR | \fB--block-size \fIN\fR ]
|
||||
[ \fB-h\fR | \fB--hash \fIHASH\fR ]
|
||||
[ \fB-u\fR | \fB--uuid \fIUUID\fR ]
|
||||
[ \fB-l\fR | \fB--label \fILABEL\fR ]
|
||||
[ \fB--format \fIFORMAT\fR ]
|
||||
[ \fB-j\fR | \fB--journal-device \fIFILE\fR ]
|
||||
[ \fB-s\fR | \fB--journal-size \fIN\fR ]
|
||||
[ \fB-o\fR | \fB--journal-offset \fIN\fR ]
|
||||
[ \fB-t\fR | \fB--transaction-max-size\fR \fIN\fR ] \fI device\fR
|
||||
[ \fIfilesystem-size\fR ]
|
||||
.SH DESCRIPTION
|
||||
It creates a Linux Reiserfs file system on a device
|
||||
It creates a Linux ReiserFS file system on a device
|
||||
(usually a disk partition).
|
||||
.TP
|
||||
.I device
|
||||
is the special file corresponding to the device (e.g /dev/hdXX for
|
||||
IDE disk partition or /dev/sdXX for SCSI disk partition).
|
||||
.TP
|
||||
.I block-count
|
||||
is the number of blocks on the device. If omitted, it will be
|
||||
.I filesystem-size
|
||||
size of filesystem in blocks. If omitted, it will be
|
||||
determined by
|
||||
.B mkreiserfs
|
||||
automatically.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-h \fIr5\fR |\fI tea\fR |\fI rupasov
|
||||
This specifies the name of hash function file names in directories
|
||||
will be sorted with. Choose one of the above. 'r5' is default.
|
||||
\fB-b\fR | \fB--block-size \fIN\fR
|
||||
\fIN\fR is block size in bytes. 4096 only for now.
|
||||
.TP
|
||||
\fB\-v \fI1\fR |\fI 2
|
||||
This specifies format new filsystem has to be of.
|
||||
\fB-h\fR | \fB--hash \fIHASH\fR
|
||||
\fIHASH\fR specifies the name of hash function file names in directories
|
||||
will be sorted with. Choose one of r5, rupasov, tea. r5 is default
|
||||
.TP
|
||||
\fB\-q\fR
|
||||
This makes the progress bar much less verbose. Useful when
|
||||
logged in via a slow link (e.g. serial console).
|
||||
\fB--format \fIFORMAT\fR
|
||||
\fIFORMAT\fR specifies a format new filsystem has to be of. Choose one
|
||||
of 3.5 and 3.6. If none is specified mkreiserfs will create format 3.6
|
||||
if running kernel is 2.4, 3.5 if 2.2 is running, and will refuse
|
||||
creation under other kernels.
|
||||
.TP
|
||||
\fB-u\fR | \fB--uuid \fIUUID\fR
|
||||
Set the universally unique identifier (\fB UUID \fR) of the filesystem to
|
||||
\fIUUID\fR (see also \fBuuidgen(8)\fR). The format of the UUID is a
|
||||
series of hex digits separated by hypthens, like this:
|
||||
"c1b9d5a2-f162-11cf-9ece-0020afc76f16". If the option skipped,
|
||||
mkreiserfs generates a new one.
|
||||
.TP
|
||||
\fB-l\fR | \fB--label \fILABEL\fR
|
||||
Set the volume label of the filesystem. \fILABEL\fR can be at most 16
|
||||
characters long; if it is longer than 16 characters, mkreiserfs will truncate it.
|
||||
.TP
|
||||
\fB-j\fR | \fB--journal-device \fIFILE\fR
|
||||
\fIFILE\fR is name of block device where the file system is to have
|
||||
journal on.
|
||||
.TP
|
||||
\fB-o\fR | \fB--journal-offset \fIN\fR
|
||||
\fIN\fR is an offset where journal starts when it is to be on a
|
||||
separate device. Default is 0. Makes no effect when journal is to be
|
||||
on a host device
|
||||
.TP
|
||||
\fB-s\fR | \fB--journal-size \fIN
|
||||
\fIN\fR is size of journal in blocks. When journal is to be on a
|
||||
separate device - its size defaults to number of blocks that device
|
||||
has. When journal is to be on a host device - its size defaults 8193
|
||||
and maximal possible value is 32749 (for blocksize 4k). Minimun is 513
|
||||
for both cases.
|
||||
.TP
|
||||
\fB-t\fR | \fB--transaction-max-size \fIN
|
||||
\fIN\fR is the maximum transaction size parameter for the journal. The
|
||||
default, and max possible, value is 1024 blocks. It should be less
|
||||
than half the size of the journal. If specifed incorrectly, it will be
|
||||
adjusted.
|
||||
.TP
|
||||
\fB-f\fR
|
||||
This forces mkreiserfs to continue even if device is either whole
|
||||
disk, or looks mounted or is not a block device. Specified more than
|
||||
once allows to avoid asking for confirmation.
|
||||
.TP
|
||||
\fB-d\fR
|
||||
This makes mkreiserfs to print debugging information during mkreiserfs.
|
||||
.TP
|
||||
\fB-V\fR
|
||||
This prints version and exits.
|
||||
|
||||
.SH AUTHOR
|
||||
This version of
|
||||
.B mkreiserfs
|
||||
has been written by Hans Reiser <reiser@idiom.com>.
|
||||
has been written by Edward Shishkin <edward@namesys.com>.
|
||||
.SH BUGS
|
||||
No other blocksizes but 4k are available.
|
||||
Please, report about other bugs to Hans Reiser <reiser@idiom.com>.
|
||||
Please, report about other bugs to
|
||||
the ReiserFS mail-list <reiserfs-list@namesys.com>
|
||||
.SH SEE ALSO
|
||||
.BR reiserfsck (8),
|
||||
.BR debugreiserfs (8)
|
||||
.BR debugreiserfs (8),
|
||||
.BR reiserfstune (8)
|
||||
+608
-360
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,5 @@
|
||||
noinst_LIBRARIES = libcore.a
|
||||
|
||||
libcore_a_SOURCES = do_balan.c fix_node.c hashes.c ibalance.c lbalance.c prints.c stree.c node_formats.c reiserfslib.c bitmap.c includes.h
|
||||
libcore_a_SOURCES = do_balan.c fix_node.c hashes.c ibalance.c lbalance.c prints.c \
|
||||
stree.c node_formats.c reiserfslib.c bitmap.c journal.c includes.h
|
||||
|
||||
INCLUDES = -I../include
|
||||
+28
-16
@@ -1,6 +1,6 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -62,24 +62,26 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
noinst_LIBRARIES = libcore.a
|
||||
|
||||
libcore_a_SOURCES = do_balan.c fix_node.c hashes.c ibalance.c lbalance.c prints.c stree.c node_formats.c reiserfslib.c bitmap.c includes.h
|
||||
libcore_a_SOURCES = do_balan.c fix_node.c hashes.c ibalance.c lbalance.c prints.c stree.c node_formats.c reiserfslib.c bitmap.c journal.c includes.h
|
||||
|
||||
INCLUDES = -I../include
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
libcore_a_LIBADD =
|
||||
libcore_a_OBJECTS = do_balan.o fix_node.o hashes.o ibalance.o \
|
||||
lbalance.o prints.o stree.o node_formats.o reiserfslib.o bitmap.o
|
||||
lbalance.o prints.o stree.o node_formats.o reiserfslib.o bitmap.o \
|
||||
journal.o
|
||||
AR = ar
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@@ -176,7 +178,7 @@ distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
@@ -184,26 +186,36 @@ distdir: $(DISTFILES)
|
||||
fi; \
|
||||
done
|
||||
bitmap.o: bitmap.c includes.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
do_balan.o: do_balan.c includes.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
fix_node.o: fix_node.c includes.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
hashes.o: hashes.c
|
||||
ibalance.o: ibalance.c includes.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
journal.o: journal.c includes.h ../include/io.h ../include/misc.h \
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
lbalance.o: lbalance.c includes.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
node_formats.o: node_formats.c includes.h ../include/io.h \
|
||||
../include/misc.h ../include/reiserfs_lib.h \
|
||||
../include/misc.h ../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
prints.o: prints.c includes.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
reiserfslib.o: reiserfslib.c includes.h ../include/io.h \
|
||||
../include/misc.h ../include/reiserfs_lib.h \
|
||||
../include/misc.h ../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
stree.o: stree.c includes.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
|
||||
+328
-92
@@ -1,25 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
/*
|
||||
* 2000/10/26 - Initial version.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "includes.h"
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
/* create clean bitmap */
|
||||
reiserfs_bitmap_t reiserfs_create_bitmap (unsigned int bit_count)
|
||||
reiserfs_bitmap_t * reiserfs_create_bitmap (unsigned int bit_count)
|
||||
{
|
||||
reiserfs_bitmap_t bm;
|
||||
reiserfs_bitmap_t * bm;
|
||||
|
||||
bm = getmem (sizeof (*bm));
|
||||
if (!bm)
|
||||
return 0;
|
||||
bm->bm_bit_size = bit_count;
|
||||
bm->bm_byte_size = (bit_count + 7) / 8;
|
||||
bm->bm_byte_size = ((unsigned long long)bit_count + 7) / 8;
|
||||
bm->bm_set_bits = 0;
|
||||
bm->bm_map = getmem (bm->bm_byte_size);
|
||||
if (!bm->bm_map) {
|
||||
@@ -32,7 +32,7 @@ reiserfs_bitmap_t reiserfs_create_bitmap (unsigned int bit_count)
|
||||
|
||||
/* Expand existing bitmap. Return non-zero if can't. FIXME: it is
|
||||
assumed that bit_count is new number of blocks to be addressed */
|
||||
int reiserfs_expand_bitmap (reiserfs_bitmap_t bm, unsigned int bit_count)
|
||||
int reiserfs_expand_bitmap (reiserfs_bitmap_t * bm, unsigned int bit_count)
|
||||
{
|
||||
unsigned int byte_count = ((bit_count + 7) / 8);
|
||||
char * new_map;
|
||||
@@ -50,8 +50,16 @@ int reiserfs_expand_bitmap (reiserfs_bitmap_t bm, unsigned int bit_count)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reiserfs_shrink_bitmap (reiserfs_bitmap_t * bm, unsigned int bit_count)
|
||||
{
|
||||
assert (bm->bm_bit_size >= bit_count);
|
||||
|
||||
bm->bm_byte_size = (bit_count + 7) / 8;
|
||||
bm->bm_bit_size = bit_count;
|
||||
}
|
||||
|
||||
/* bitmap destructor */
|
||||
void reiserfs_delete_bitmap (reiserfs_bitmap_t bm)
|
||||
void reiserfs_delete_bitmap (reiserfs_bitmap_t * bm)
|
||||
{
|
||||
freemem(bm->bm_map);
|
||||
bm->bm_map = NULL; /* to not reuse bitmap handle */
|
||||
@@ -61,19 +69,19 @@ void reiserfs_delete_bitmap (reiserfs_bitmap_t bm)
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_bitmap_copy (reiserfs_bitmap_t to, reiserfs_bitmap_t from)
|
||||
void reiserfs_bitmap_copy (reiserfs_bitmap_t * to, reiserfs_bitmap_t * from)
|
||||
{
|
||||
assert (to->bm_byte_size == from->bm_byte_size);
|
||||
memcpy (to->bm_map, from->bm_map, from->bm_byte_size);
|
||||
to->bm_bit_size = from->bm_bit_size;
|
||||
to->bm_set_bits = from->bm_set_bits;
|
||||
to->bm_dirty = 1;
|
||||
}
|
||||
|
||||
|
||||
int reiserfs_bitmap_compare (reiserfs_bitmap_t bm1, reiserfs_bitmap_t bm2)
|
||||
int reiserfs_bitmap_compare (reiserfs_bitmap_t * bm1, reiserfs_bitmap_t * bm2)
|
||||
{
|
||||
int bytes, bits;
|
||||
int i, diff;
|
||||
long unsigned i, diff;
|
||||
|
||||
assert (bm1->bm_byte_size == bm2->bm_byte_size &&
|
||||
bm1->bm_bit_size == bm2->bm_bit_size);
|
||||
@@ -82,50 +90,70 @@ int reiserfs_bitmap_compare (reiserfs_bitmap_t bm1, reiserfs_bitmap_t bm2)
|
||||
|
||||
/* compare full bytes */
|
||||
bytes = bm1->bm_bit_size / 8;
|
||||
bits = bytes * 8;
|
||||
if (memcmp (bm1->bm_map, bm2->bm_map, bytes)) {
|
||||
for (i = 0; i < bytes; i ++)
|
||||
if (bm1->bm_map [i] != bm2->bm_map[i]) {
|
||||
printf ("byte %d: bm1: %x bm2 %x\n", i, bm1->bm_map[i], bm2->bm_map[i]);
|
||||
for (i = 0; i < bits; i ++)
|
||||
if (reiserfs_bitmap_test_bit(bm1, i) != reiserfs_bitmap_test_bit(bm2, i))
|
||||
diff ++;
|
||||
}
|
||||
}
|
||||
|
||||
/* compare last byte of bitmap which can be used partially */
|
||||
bits = bm1->bm_bit_size % 8;
|
||||
if (bits) {
|
||||
int mask;
|
||||
for (i = bm1->bm_bit_size / 8 * 8; i < bm1->bm_bit_size / 8 * 8 + bits; i ++)
|
||||
if (reiserfs_bitmap_test_bit(bm1, i) != reiserfs_bitmap_test_bit(bm2, i))
|
||||
diff ++;
|
||||
|
||||
/* int mask;
|
||||
|
||||
mask = 255 >> (8 - bits);
|
||||
if ((bm1->bm_map [bytes] & mask) != (bm2->bm_map [bytes] & mask)) {
|
||||
printf ("last byte %d: bm1: %x bm2 %x\n", bytes, bm1->bm_map[bytes], bm2->bm_map[bytes]);
|
||||
diff ++;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return diff;
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_bitmap_set_bit (reiserfs_bitmap_t bm, unsigned int bit_number)
|
||||
void reiserfs_bitmap_disjunction (reiserfs_bitmap_t * to, reiserfs_bitmap_t * from)
|
||||
{
|
||||
int i;
|
||||
|
||||
assert (to->bm_byte_size == from->bm_byte_size &&
|
||||
to->bm_bit_size == from->bm_bit_size);
|
||||
|
||||
for (i = 0; i < to->bm_bit_size; i++) {
|
||||
if (test_bit(i, from->bm_map) && !test_bit(i, to->bm_map)) {
|
||||
set_bit(i, to->bm_map);
|
||||
to->bm_set_bits ++;
|
||||
to->bm_dirty = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_bitmap_set_bit (reiserfs_bitmap_t * bm, unsigned int bit_number)
|
||||
{
|
||||
assert(bit_number < bm->bm_bit_size);
|
||||
if (test_bit (bit_number, bm->bm_map))
|
||||
return;
|
||||
set_bit(bit_number, bm->bm_map);
|
||||
bm->bm_set_bits ++;
|
||||
bm->bm_dirty = 1;
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_bitmap_clear_bit (reiserfs_bitmap_t bm, unsigned int bit_number)
|
||||
void reiserfs_bitmap_clear_bit (reiserfs_bitmap_t * bm, unsigned int bit_number)
|
||||
{
|
||||
assert(bit_number < bm->bm_bit_size);
|
||||
if (!test_bit (bit_number, bm->bm_map))
|
||||
return;
|
||||
clear_bit (bit_number, bm->bm_map);
|
||||
bm->bm_set_bits --;
|
||||
bm->bm_dirty = 1;
|
||||
}
|
||||
|
||||
|
||||
int reiserfs_bitmap_test_bit (reiserfs_bitmap_t bm, unsigned int bit_number)
|
||||
int reiserfs_bitmap_test_bit (reiserfs_bitmap_t * bm, unsigned int bit_number)
|
||||
{
|
||||
if (bit_number >= bm->bm_bit_size)
|
||||
printf ("bit %u, bitsize %lu\n", bit_number, bm->bm_bit_size);
|
||||
@@ -134,19 +162,19 @@ int reiserfs_bitmap_test_bit (reiserfs_bitmap_t bm, unsigned int bit_number)
|
||||
}
|
||||
|
||||
|
||||
int reiserfs_bitmap_zeros (reiserfs_bitmap_t bm)
|
||||
int reiserfs_bitmap_zeros (reiserfs_bitmap_t * bm)
|
||||
{
|
||||
return bm->bm_bit_size - bm->bm_set_bits;
|
||||
}
|
||||
|
||||
|
||||
int reiserfs_bitmap_ones (reiserfs_bitmap_t bm)
|
||||
int reiserfs_bitmap_ones (reiserfs_bitmap_t * bm)
|
||||
{
|
||||
return bm->bm_set_bits;
|
||||
}
|
||||
|
||||
|
||||
int reiserfs_bitmap_find_zero_bit (reiserfs_bitmap_t bm, unsigned long * start)
|
||||
int reiserfs_bitmap_find_zero_bit (reiserfs_bitmap_t * bm, unsigned long * start)
|
||||
{
|
||||
unsigned int bit_nr = *start;
|
||||
assert(*start < bm->bm_bit_size);
|
||||
@@ -162,31 +190,57 @@ int reiserfs_bitmap_find_zero_bit (reiserfs_bitmap_t bm, unsigned long * start)
|
||||
}
|
||||
|
||||
|
||||
/* copy reiserfs filesystem bitmap into memory bitmap */
|
||||
int reiserfs_fetch_disk_bitmap (reiserfs_bitmap_t bm, reiserfs_filsys_t fs)
|
||||
/* read every bitmap block and copy their content into bitmap 'bm' */
|
||||
static int reiserfs_fetch_ondisk_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t * fs)
|
||||
{
|
||||
unsigned long to_copy;
|
||||
int copied;
|
||||
int i;
|
||||
int bytes;
|
||||
char * p;
|
||||
int unused_bits;
|
||||
int last_byte_unused_bits;
|
||||
unsigned long block;
|
||||
struct buffer_head * bh;
|
||||
|
||||
reiserfs_warning (stderr, "Fetching on-disk bitmap..");
|
||||
assert (bm->bm_bit_size == SB_BLOCK_COUNT (fs));
|
||||
|
||||
bytes = fs->s_blocksize;
|
||||
to_copy = (get_sb_block_count (fs->fs_ondisk_sb) + 7) / 8;
|
||||
|
||||
/*reiserfs_warning (stderr, "Fetching on-disk bitmap..");*/
|
||||
assert (bm->bm_byte_size == to_copy);
|
||||
|
||||
copied = fs->fs_blocksize;
|
||||
p = bm->bm_map;
|
||||
for (i = 0; i < SB_BMAP_NR (fs); i ++) {
|
||||
if ((i == (SB_BMAP_NR (fs) - 1)) && bm->bm_byte_size % fs->s_blocksize)
|
||||
bytes = bm->bm_byte_size % fs->s_blocksize;
|
||||
block = fs->fs_super_bh->b_blocknr + 1;
|
||||
|
||||
memcpy (p, SB_AP_BITMAP (fs)[i]->b_data, bytes);
|
||||
p += bytes;
|
||||
while (to_copy) {
|
||||
bh = bread (fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "reiserfs_fetch_ondisk_bitmap: "
|
||||
"bread failed reading bitmap (%lu)\n", block);
|
||||
bh = getblk (fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (!bh)
|
||||
reiserfs_panic ("reiserfs_fetch_ondisk_bitmap: getblk failed");
|
||||
memset (bh->b_data, 0xff, bh->b_size);
|
||||
mark_buffer_uptodate (bh, 1);
|
||||
}
|
||||
|
||||
if (to_copy < fs->fs_blocksize)
|
||||
copied = to_copy;
|
||||
memcpy (p, bh->b_data, copied);
|
||||
brelse (bh);
|
||||
p += copied;
|
||||
to_copy -= copied;
|
||||
|
||||
/* next bitmap block */
|
||||
if (spread_bitmaps (fs))
|
||||
block = (block / (fs->fs_blocksize * 8) + 1) * (fs->fs_blocksize * 8);
|
||||
else
|
||||
block ++;
|
||||
}
|
||||
|
||||
/* on disk bitmap has bits out of SB_BLOCK_COUNT set to 1, where as
|
||||
reiserfs_bitmap_t has those bits set to 0 */
|
||||
unused_bits = bm->bm_byte_size * 8 - bm->bm_bit_size;
|
||||
for (i = 0; i < unused_bits; i ++)
|
||||
last_byte_unused_bits = bm->bm_byte_size * 8 - bm->bm_bit_size;
|
||||
for (i = 0; i < last_byte_unused_bits; i ++)
|
||||
clear_bit (bm->bm_bit_size + i, bm->bm_map);
|
||||
|
||||
bm->bm_set_bits = 0;
|
||||
@@ -195,58 +249,96 @@ int reiserfs_fetch_disk_bitmap (reiserfs_bitmap_t bm, reiserfs_filsys_t fs)
|
||||
if (reiserfs_bitmap_test_bit (bm, i))
|
||||
bm->bm_set_bits ++;
|
||||
|
||||
/* unused part of last bitmap block is filled with 0s */
|
||||
if (bm->bm_bit_size % (fs->s_blocksize * 8))
|
||||
for (i = SB_BLOCK_COUNT (fs) % (fs->s_blocksize * 8); i < fs->s_blocksize * 8; i ++)
|
||||
if (!test_bit (i, SB_AP_BITMAP (fs)[SB_BMAP_NR (fs) - 1]->b_data)) {
|
||||
reiserfs_warning (stderr, "fetch_bitmap: on-disk bitmap is not padded properly\n");
|
||||
break;
|
||||
}
|
||||
|
||||
reiserfs_warning (stderr, "done\n");
|
||||
bm->bm_dirty = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* copy bitmap to buffers which hold on-disk bitmap */
|
||||
int reiserfs_flush_bitmap (reiserfs_bitmap_t bm, reiserfs_filsys_t fs)
|
||||
/* copy bitmap 'bm' to buffers which hold on-disk bitmap if bitmap was ever
|
||||
changed and return 1. Otherwise - return 0 */
|
||||
int reiserfs_flush_to_ondisk_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t * fs)
|
||||
{
|
||||
unsigned long to_copy;
|
||||
int copied;
|
||||
int i;
|
||||
int bytes;
|
||||
char * p;
|
||||
int last_byte_unused_bits;
|
||||
unsigned long block;
|
||||
struct buffer_head * bh;
|
||||
|
||||
bytes = fs->s_blocksize;
|
||||
|
||||
/* make sure that the device is big enough */
|
||||
bh = bread (fs->fs_dev, bm->bm_bit_size - 1, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "reiserfs_flush_to_ondisk_bitmap: bread failed for block %lu\n",
|
||||
bm->bm_bit_size - 1);
|
||||
/*
|
||||
bh = getblk (fs->fs_dev, bm->bm_bit_size - 1, fs->fs_blocksize);
|
||||
if (!bh)
|
||||
reiserfs_panic ("reiserfs_flush_to_ondisk_bitmap: getblk failed");
|
||||
mark_buffer_uptodate (bh, 1);
|
||||
mark_buffer_dirty (bh);
|
||||
bwrite (bh);*/
|
||||
}
|
||||
brelse (bh);
|
||||
|
||||
if (!bm->bm_dirty)
|
||||
return 0;
|
||||
|
||||
to_copy = bm->bm_byte_size;
|
||||
|
||||
copied = fs->fs_blocksize;
|
||||
p = bm->bm_map;
|
||||
for (i = 0; i < SB_BMAP_NR (fs); i ++) {
|
||||
if ((i == (SB_BMAP_NR (fs) - 1)) && (bm->bm_byte_size % fs->s_blocksize))
|
||||
bytes = bm->bm_byte_size % fs->s_blocksize;
|
||||
block = fs->fs_super_bh->b_blocknr + 1;
|
||||
|
||||
memcpy (SB_AP_BITMAP (fs)[i]->b_data, p, bytes);
|
||||
mark_buffer_dirty (SB_AP_BITMAP (fs)[i]);
|
||||
while (to_copy) {
|
||||
/* we bread to make sure that filesystem contains enough blocks */
|
||||
bh = getblk (fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (!bh)
|
||||
reiserfs_panic ("reiserfs_flush_to_ondisk_bitmap: "
|
||||
"getblk failed for (%lu)\n", block);
|
||||
memset (bh->b_data, 0xff, bh->b_size);
|
||||
mark_buffer_uptodate (bh, 1);
|
||||
|
||||
p += bytes;
|
||||
if (to_copy < fs->fs_blocksize)
|
||||
copied = to_copy;
|
||||
memcpy (bh->b_data, p, copied);
|
||||
if (copied == to_copy) {
|
||||
/* set unused bits of last byte of a bitmap to 1 */
|
||||
last_byte_unused_bits = bm->bm_byte_size * 8 - bm->bm_bit_size;
|
||||
for (i = 0; i < last_byte_unused_bits; i ++)
|
||||
set_bit ((bm->bm_bit_size % (fs->fs_blocksize * 8)) + i, bh->b_data);
|
||||
}
|
||||
mark_buffer_dirty (bh);
|
||||
brelse (bh);
|
||||
p += copied;
|
||||
to_copy -= copied;
|
||||
|
||||
/* next bitmap block */
|
||||
if (spread_bitmaps (fs))
|
||||
block = (block / (fs->fs_blocksize * 8) + 1) * (fs->fs_blocksize * 8);
|
||||
else
|
||||
block ++;
|
||||
}
|
||||
|
||||
/* unused part of last bitmap block is filled with 0s */
|
||||
if (bm->bm_bit_size % (fs->s_blocksize * 8))
|
||||
for (i = bm->bm_bit_size % (fs->s_blocksize * 8); i < fs->s_blocksize * 8; i ++)
|
||||
set_bit (i, SB_AP_BITMAP (fs)[SB_BMAP_NR (fs) - 1]->b_data);
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_bitmap_zero (reiserfs_bitmap_t bm)
|
||||
void reiserfs_bitmap_zero (reiserfs_bitmap_t * bm)
|
||||
{
|
||||
memset (bm->bm_map, 0, bm->bm_byte_size);
|
||||
bm->bm_set_bits = 0;
|
||||
bm->bm_dirty = 1;
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_bitmap_fill (reiserfs_bitmap_t bm)
|
||||
void reiserfs_bitmap_fill (reiserfs_bitmap_t * bm)
|
||||
{
|
||||
memset (bm->bm_map, 0xff, bm->bm_byte_size);
|
||||
bm->bm_set_bits = bm->bm_bit_size;
|
||||
bm->bm_dirty = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -260,23 +352,47 @@ void reiserfs_bitmap_fill (reiserfs_bitmap_t bm)
|
||||
#define BITMAP_START_MAGIC 374031
|
||||
#define BITMAP_END_MAGIC 7786472
|
||||
|
||||
void reiserfs_bitmap_save (char * filename, reiserfs_bitmap_t bm)
|
||||
|
||||
FILE * open_file (char * filename, char * option)
|
||||
{
|
||||
FILE * fp;
|
||||
FILE * fp = fopen (filename, option);
|
||||
if (!fp) {
|
||||
reiserfs_warning (stderr, "open_file: could not open file %s\n", filename);
|
||||
return 0;
|
||||
}
|
||||
reiserfs_warning (stderr, "Temp file opened by fsck: \"%s\" .. \n", filename);
|
||||
return fp;
|
||||
}
|
||||
|
||||
|
||||
void close_file (FILE * fp)
|
||||
{
|
||||
fclose (fp);
|
||||
/*reiserfs_warning (stderr, "done\n"); fflush (stderr);*/
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_bitmap_save (FILE * fp, reiserfs_bitmap_t * bm)
|
||||
{
|
||||
// FILE * fp;
|
||||
__u32 v;
|
||||
int zeros;
|
||||
int count;
|
||||
int i;
|
||||
int extents;
|
||||
long position;
|
||||
|
||||
fp = fopen (filename, "w+");
|
||||
/* fp = fopen (filename, "w+");
|
||||
if (!fp) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_save: could not save bitmap in %s: %m",
|
||||
filename);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
// reiserfs_warning (stderr, "Saving bitmap in \"%s\" .. ", filename); fflush (stderr);
|
||||
|
||||
|
||||
reiserfs_warning (stderr, "Saving bitmap in \"%s\" .. ", filename); fflush (stderr);
|
||||
|
||||
v = BITMAP_START_MAGIC;
|
||||
fwrite (&v, 4, 1, fp);
|
||||
@@ -286,10 +402,11 @@ void reiserfs_bitmap_save (char * filename, reiserfs_bitmap_t bm)
|
||||
|
||||
/*printf ("SAVE: bit_size - %d\n", v);*/
|
||||
|
||||
position = ftell(fp);
|
||||
|
||||
if (fseek (fp, 4, SEEK_CUR)) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_save: fseek failed: %m\n");
|
||||
fclose (fp);
|
||||
// fclose (fp);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -338,42 +455,106 @@ void reiserfs_bitmap_save (char * filename, reiserfs_bitmap_t bm)
|
||||
v = BITMAP_END_MAGIC;
|
||||
fwrite (&v, 4, 1, fp);
|
||||
|
||||
if (fseek (fp, 8, SEEK_SET)) {
|
||||
if (fseek (fp, position, SEEK_SET)) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_save: fseek failed: %m");
|
||||
fclose (fp);
|
||||
return;
|
||||
}
|
||||
|
||||
fwrite (&extents, 4, 1, fp);
|
||||
/*printf ("SAVE: extents %d\n", extents);*/
|
||||
|
||||
fclose (fp);
|
||||
|
||||
reiserfs_warning (stderr, "done\n"); fflush (stderr);
|
||||
if (fseek (fp, 0, SEEK_END)) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_save: fseek failed: %m");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
reiserfs_bitmap_t reiserfs_bitmap_load (char * filename)
|
||||
/* format of fsck dump file:
|
||||
after pass0
|
||||
magic number (32 bits)
|
||||
passed stage number
|
||||
bitmap of leaves
|
||||
bitmap of good_unfm
|
||||
bitmap of bad_unfm
|
||||
magic number (32 bits) */
|
||||
|
||||
#define FSCK_DUMP_START_MAGIC 374033
|
||||
#define FSCK_DUMP_END_MAGIC 7786470
|
||||
|
||||
|
||||
void reiserfs_begin_stage_info_save(FILE * file, unsigned long stage)
|
||||
{
|
||||
FILE * fp;
|
||||
__u32 v = FSCK_DUMP_START_MAGIC;
|
||||
fwrite (&v, 4, 1, file);
|
||||
fwrite (&stage, 4, 1, file);
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_end_stage_info_save(FILE * file)
|
||||
{
|
||||
__u32 v = FSCK_DUMP_END_MAGIC;
|
||||
fwrite (&v, 4, 1, file);
|
||||
}
|
||||
|
||||
|
||||
/*return last passed stage*/
|
||||
int is_stage_magic_correct (FILE * fp)
|
||||
{
|
||||
__u32 v;
|
||||
|
||||
if (fseek (fp, -4, SEEK_END)) {
|
||||
reiserfs_warning (stderr, "is_stage_magic_correct: fseek failed: %m\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fread (&v, 4, 1, fp);
|
||||
if (v != FSCK_DUMP_END_MAGIC) {
|
||||
reiserfs_warning (stderr, "is_stage_magic_correct: no magic found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fseek (fp, 0, SEEK_SET)) {
|
||||
reiserfs_warning (stderr, "is_stage_magic_correct: fseek failed: %m\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fread (&v, 4, 1, fp);
|
||||
if (v != FSCK_DUMP_START_MAGIC) {
|
||||
reiserfs_warning (stderr, "is_stage_magic_correct: no magic found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fread (&v, 4, 1, fp);
|
||||
if (v != PASS_0_DONE && v != PASS_1_DONE && v != TREE_IS_BUILT && v != SEMANTIC_DONE && v != LOST_FOUND_DONE) {
|
||||
reiserfs_warning (stderr, "is_stage_magic_correct: wrong pass found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (__u16)v;
|
||||
}
|
||||
|
||||
|
||||
reiserfs_bitmap_t * reiserfs_bitmap_load (FILE * fp)
|
||||
{
|
||||
// FILE * fp;
|
||||
__u32 v;
|
||||
int count;
|
||||
int i, j;
|
||||
int extents;
|
||||
int bit;
|
||||
reiserfs_bitmap_t bm;
|
||||
reiserfs_bitmap_t * bm;
|
||||
|
||||
fp = fopen (filename, "r");
|
||||
/* fp = fopen (filename, "r");
|
||||
if (!fp) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_load: fseek failed: %m\n");
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_load: fopen failed: %m\n");
|
||||
return 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
fread (&v, 4, 1, fp);
|
||||
if (v != BITMAP_START_MAGIC) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_load: "
|
||||
"no bitmap start magic found");
|
||||
fclose (fp);
|
||||
// fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -383,12 +564,10 @@ reiserfs_bitmap_t reiserfs_bitmap_load (char * filename)
|
||||
bm = reiserfs_create_bitmap (v);
|
||||
if (!bm) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_load: creation failed");
|
||||
fclose (fp);
|
||||
// fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
reiserfs_warning (stderr, "Loading bitmap from %s .. ", filename); fflush (stderr);
|
||||
|
||||
/*printf ("LOAD: bit_size - %d\n", v);*/
|
||||
|
||||
fread (&extents, 4, 1, fp);
|
||||
@@ -414,24 +593,24 @@ reiserfs_bitmap_t reiserfs_bitmap_load (char * filename)
|
||||
|
||||
/*printf ("LOAD: Endmagic %d\n", v);*/
|
||||
|
||||
fclose (fp);
|
||||
// fclose (fp);
|
||||
if (v != BITMAP_END_MAGIC) {
|
||||
reiserfs_warning (stderr, "reiserfs_bitmap_load: "
|
||||
"no bitmap end magic found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
reiserfs_warning (stderr, "%d bits set - done\n", reiserfs_bitmap_ones (bm));
|
||||
/* reiserfs_warning (stderr, "%d bits set - done\n", reiserfs_bitmap_ones (bm));*/
|
||||
fflush (stderr);
|
||||
return bm;
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_bitmap_invert (reiserfs_bitmap_t bm)
|
||||
void reiserfs_bitmap_invert (reiserfs_bitmap_t * bm)
|
||||
{
|
||||
int i;
|
||||
|
||||
reiserfs_warning (stderr, "Bitmap inverting..");fflush (stderr);
|
||||
/*reiserfs_warning (stderr, "Bitmap inverting..");fflush (stderr);*/
|
||||
for (i = 0; i < bm->bm_bit_size; i ++) {
|
||||
if (reiserfs_bitmap_test_bit (bm, i))
|
||||
reiserfs_bitmap_clear_bit (bm, i);
|
||||
@@ -439,10 +618,67 @@ void reiserfs_bitmap_invert (reiserfs_bitmap_t bm)
|
||||
reiserfs_bitmap_set_bit (bm, i);
|
||||
}
|
||||
|
||||
reiserfs_warning (stderr, "done\n");
|
||||
/*reiserfs_warning (stderr, "done\n");*/
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_free_ondisk_bitmap (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (fs->fs_bitmap2) {
|
||||
reiserfs_delete_bitmap (fs->fs_bitmap2);
|
||||
fs->fs_bitmap2 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* read bitmap blocks */
|
||||
int reiserfs_open_ondisk_bitmap (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
|
||||
if (fs->fs_bitmap2)
|
||||
reiserfs_panic ("%s: bitmap is initiaized already", __FUNCTION__);
|
||||
fs->fs_bitmap2 = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
if (!fs->fs_bitmap2)
|
||||
return 0;
|
||||
|
||||
if ( (get_sb_block_count (fs->fs_ondisk_sb) + fs->fs_blocksize * 8 - 1) / (fs->fs_blocksize * 8) !=
|
||||
get_sb_bmap_nr (fs->fs_ondisk_sb)) {
|
||||
reiserfs_warning (stderr, "%s: wrong either bitmaps number,\n", __FUNCTION__);
|
||||
reiserfs_warning (stderr, "count of blocks or blocksize, run with --rebuild-sb to fix it\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bh = bread (fs->fs_dev, fs->fs_bitmap2->bm_bit_size - 1, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "%s: bread failed for block %lu\n", __FUNCTION__, fs->fs_bitmap2->bm_bit_size - 1);
|
||||
reiserfs_warning (stderr, "\tYour partition is not big enough. Enlarge your partition or\n");
|
||||
reiserfs_warning (stderr, "\trun reiserfsck with --rebuild-sb to fix super block.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
brelse (bh);
|
||||
|
||||
reiserfs_fetch_ondisk_bitmap (fs->fs_bitmap2, fs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int reiserfs_create_ondisk_bitmap (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (fs->fs_bitmap2)
|
||||
reiserfs_panic ("create: bitmap is initiaized already");
|
||||
fs->fs_bitmap2 = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
|
||||
if (!fs->fs_bitmap2)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_close_ondisk_bitmap (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (!fs->fs_bitmap2)
|
||||
return;
|
||||
reiserfs_flush_to_ondisk_bitmap (fs->fs_bitmap2, fs);
|
||||
reiserfs_free_ondisk_bitmap (fs);
|
||||
}
|
||||
+83
-668
File diff suppressed because it is too large.
Load diff
+1032
-1621
File diff suppressed because it is too large.
Load diff
+12
-19
@@ -51,7 +51,7 @@ typedef __u32 u32;
|
||||
} while(0)
|
||||
|
||||
|
||||
u32 keyed_hash(const char *msg, int len)
|
||||
u32 keyed_hash(const signed char *msg, int len)
|
||||
{
|
||||
u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3};
|
||||
|
||||
@@ -61,8 +61,6 @@ u32 keyed_hash(const char *msg, int len)
|
||||
int i;
|
||||
|
||||
|
||||
// assert(len >= 0 && len < 256);
|
||||
|
||||
pad = (u32)len | ((u32)len << 8);
|
||||
pad |= pad << 16;
|
||||
|
||||
@@ -93,7 +91,6 @@ u32 keyed_hash(const char *msg, int len)
|
||||
|
||||
if (len >= 12)
|
||||
{
|
||||
//assert(len < 16);
|
||||
if (len >= 16)
|
||||
*(int *)0 = 0;
|
||||
|
||||
@@ -119,7 +116,6 @@ u32 keyed_hash(const char *msg, int len)
|
||||
}
|
||||
else if (len >= 8)
|
||||
{
|
||||
//assert(len < 12);
|
||||
if (len >= 12)
|
||||
*(int *)0 = 0;
|
||||
a = (u32)msg[ 0] |
|
||||
@@ -140,7 +136,6 @@ u32 keyed_hash(const char *msg, int len)
|
||||
}
|
||||
else if (len >= 4)
|
||||
{
|
||||
//assert(len < 8);
|
||||
if (len >= 8)
|
||||
*(int *)0 = 0;
|
||||
a = (u32)msg[ 0] |
|
||||
@@ -157,7 +152,6 @@ u32 keyed_hash(const char *msg, int len)
|
||||
}
|
||||
else
|
||||
{
|
||||
//assert(len < 4);
|
||||
if (len >= 4)
|
||||
*(int *)0 = 0;
|
||||
a = b = c = d = pad;
|
||||
@@ -170,12 +164,11 @@ u32 keyed_hash(const char *msg, int len)
|
||||
|
||||
TEACORE(FULLROUNDS);
|
||||
|
||||
/* return 0;*/
|
||||
return h0^h1;
|
||||
}
|
||||
|
||||
|
||||
u32 yura_hash (const char *msg, int len)
|
||||
u32 yura_hash (const signed char *msg, int len)
|
||||
{
|
||||
int j, pow;
|
||||
u32 a, c;
|
||||
@@ -211,23 +204,23 @@ u32 yura_hash (const char *msg, int len)
|
||||
}
|
||||
|
||||
|
||||
u32 r5_hash (const char *msg, int len)
|
||||
u32 r5_hash (const signed char *msg, int len)
|
||||
{
|
||||
u32 a=0;
|
||||
int i;
|
||||
u32 a=0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i ++) {
|
||||
a += msg[i] << 4;
|
||||
a += msg[i] >> 4;
|
||||
a *= 11;
|
||||
}
|
||||
return a;
|
||||
for (i = 0; i < len; i ++) {
|
||||
a += msg[i] << 4;
|
||||
a += msg[i] >> 4;
|
||||
a *= 11;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
#include <stdio.h>
|
||||
//#include <stddef.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
|
||||
+119
-294
@@ -34,10 +34,6 @@ static void internal_define_dest_src_infos (
|
||||
struct buffer_head ** cf
|
||||
)
|
||||
{
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
memset (dest_bi, 0, sizeof (struct buffer_info));
|
||||
memset (src_bi, 0, sizeof (struct buffer_info));
|
||||
#endif
|
||||
/* define dest, src, dest parent, dest position */
|
||||
switch (shift_mode) {
|
||||
case INTERNAL_SHIFT_FROM_S_TO_L: /* used in internal_shift_left */
|
||||
@@ -111,13 +107,14 @@ static void internal_define_dest_src_infos (
|
||||
* Insert count items into buffer cur before position to.
|
||||
* Items and node pointers are specified by inserted and bh respectively.
|
||||
*/
|
||||
static void internal_insert_childs (reiserfs_filsys_t fs,
|
||||
static void internal_insert_childs (reiserfs_filsys_t * fs,
|
||||
struct buffer_info * cur_bi,
|
||||
int to, int count,
|
||||
struct item_head * inserted,
|
||||
struct buffer_head ** bh)
|
||||
{
|
||||
struct buffer_head * cur = cur_bi->bi_bh;
|
||||
struct block_head * blkh;
|
||||
int nr;
|
||||
struct key * key;
|
||||
struct disk_child new_dc[2];
|
||||
@@ -128,15 +125,8 @@ static void internal_insert_childs (reiserfs_filsys_t fs,
|
||||
if (count <= 0)
|
||||
return;
|
||||
|
||||
nr = node_item_number (cur);
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if (count > 2)
|
||||
reiserfs_panic (0, "internal_insert_childs", "too many children (%d) are to be inserted", count);
|
||||
if (node_free_space (cur) < count * (KEY_SIZE + DC_SIZE))
|
||||
reiserfs_panic (0, "internal_insert_childs", "no enough free space (%d), needed %d bytes",
|
||||
node_free_space (cur), count * (KEY_SIZE + DC_SIZE));
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
blkh = B_BLK_HEAD (cur);
|
||||
nr = get_blkh_nr_items (blkh);
|
||||
|
||||
/* prepare space for count disk_child */
|
||||
dc = B_N_CHILD (cur,to+1);
|
||||
@@ -145,9 +135,10 @@ static void internal_insert_childs (reiserfs_filsys_t fs,
|
||||
|
||||
/* make disk child array for insertion */
|
||||
for (i = 0; i < count; i ++) {
|
||||
new_dc[i].dc_size = cpu_to_le16 (MAX_CHILD_SIZE(bh[i]) -
|
||||
node_free_space (bh[i]));
|
||||
new_dc[i].dc_block_number = cpu_to_le32 (bh[i]->b_blocknr);
|
||||
set_dc_child_size (new_dc + i,
|
||||
MAX_CHILD_SIZE(bh[i]->b_size) -
|
||||
get_blkh_free_space (B_BLK_HEAD (bh[i])));
|
||||
set_dc_child_blocknr (new_dc + i, bh[i]->b_blocknr);
|
||||
}
|
||||
memcpy (dc, new_dc, DC_SIZE * count);
|
||||
|
||||
@@ -163,13 +154,14 @@ static void internal_insert_childs (reiserfs_filsys_t fs,
|
||||
memcpy (key + 1, inserted + 1, KEY_SIZE);
|
||||
|
||||
/* sizes, item number */
|
||||
set_node_item_number (cur, nr + count);
|
||||
set_node_free_space (cur, node_free_space (cur) -
|
||||
count * (DC_SIZE + KEY_SIZE));
|
||||
set_blkh_nr_items (blkh, nr + count);
|
||||
set_blkh_free_space (blkh, get_blkh_free_space (blkh) - count * (DC_SIZE + KEY_SIZE));
|
||||
|
||||
mark_buffer_dirty (cur);
|
||||
|
||||
if (cur_bi->bi_parent) {
|
||||
B_N_CHILD (cur_bi->bi_parent,cur_bi->bi_position)->dc_size += count * (DC_SIZE + KEY_SIZE);
|
||||
dc = B_N_CHILD (cur_bi->bi_parent,cur_bi->bi_position);
|
||||
set_dc_child_size (dc, get_dc_child_size (dc) + count * (DC_SIZE + KEY_SIZE));
|
||||
mark_buffer_dirty (cur_bi->bi_parent);
|
||||
}
|
||||
|
||||
@@ -178,7 +170,7 @@ static void internal_insert_childs (reiserfs_filsys_t fs,
|
||||
|
||||
/* Delete del_num items and node pointers from buffer cur starting from *
|
||||
* the first_i'th item and first_p'th pointers respectively. */
|
||||
static void internal_delete_pointers_items (reiserfs_filsys_t fs,
|
||||
static void internal_delete_pointers_items (reiserfs_filsys_t * fs,
|
||||
struct buffer_info * cur_bi,
|
||||
int first_p, int first_i,
|
||||
int del_num)
|
||||
@@ -189,46 +181,17 @@ static void internal_delete_pointers_items (reiserfs_filsys_t fs,
|
||||
struct key * key;
|
||||
struct disk_child * dc;
|
||||
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if (cur == NULL)
|
||||
reiserfs_panic (0, "internal_delete_pointers_items1: buffer is 0");
|
||||
|
||||
if (del_num < 0)
|
||||
reiserfs_panic (0, "internal_delete_pointers_items2",
|
||||
"negative number of items (%d) can not be deleted", del_num);
|
||||
|
||||
if (first_p < 0 || first_p + del_num > B_NR_ITEMS (cur) + 1 || first_i < 0)
|
||||
reiserfs_panic (0, "internal_delete_pointers_items3",
|
||||
"first pointer order (%d) < 0 or "
|
||||
"no so many pointers (%d), only (%d) or "
|
||||
"first key order %d < 0", first_p,
|
||||
first_p + del_num, B_NR_ITEMS (cur) + 1, first_i);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
if ( del_num == 0 )
|
||||
return;
|
||||
|
||||
nr = (blkh = B_BLK_HEAD(cur))->blk_nr_item;
|
||||
blkh = B_BLK_HEAD(cur);
|
||||
nr = get_blkh_nr_items (blkh);
|
||||
|
||||
if ( first_p == 0 && del_num == nr + 1 ) {
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( first_i != 0 )
|
||||
reiserfs_panic (0, "internal_delete_pointers_items5",
|
||||
"first deleted key must have order 0, not %d", first_i);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
make_empty_node (cur_bi);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if (first_i + del_num > B_NR_ITEMS (cur)) {
|
||||
printk("first_i = %d del_num = %d\n",first_i,del_num);
|
||||
reiserfs_panic (0, "internal_delete_pointers_items4: :"
|
||||
"no so many keys (%d) in the node (%b)(%z)", first_i + del_num, cur, cur);
|
||||
}
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
|
||||
/* deleting */
|
||||
dc = B_N_CHILD (cur, first_p);
|
||||
|
||||
@@ -237,21 +200,23 @@ static void internal_delete_pointers_items (reiserfs_filsys_t fs,
|
||||
memmove (key, key + del_num, (nr - first_i - del_num) * KEY_SIZE + (nr + 1 - del_num) * DC_SIZE);
|
||||
|
||||
|
||||
/* sizes, item number */
|
||||
blkh->blk_nr_item -= del_num;
|
||||
blkh->blk_free_space += del_num * (KEY_SIZE + DC_SIZE);
|
||||
/* sizes, item number */
|
||||
set_blkh_nr_items (blkh, get_blkh_nr_items (blkh) - del_num);
|
||||
set_blkh_free_space (blkh, get_blkh_free_space (blkh) +
|
||||
del_num * (KEY_SIZE + DC_SIZE));
|
||||
|
||||
mark_buffer_dirty (cur);
|
||||
|
||||
if (cur_bi->bi_parent) {
|
||||
B_N_CHILD (cur_bi->bi_parent, cur_bi->bi_position)->dc_size -= del_num * (KEY_SIZE + DC_SIZE);
|
||||
dc = B_N_CHILD (cur_bi->bi_parent, cur_bi->bi_position);
|
||||
set_dc_child_size (dc, get_dc_child_size (dc) - del_num * (KEY_SIZE + DC_SIZE));
|
||||
mark_buffer_dirty (cur_bi->bi_parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* delete n node pointers and items starting from given position */
|
||||
static void internal_delete_childs (reiserfs_filsys_t fs,
|
||||
static void internal_delete_childs (reiserfs_filsys_t * fs,
|
||||
struct buffer_info * cur_bi,
|
||||
int from, int n)
|
||||
{
|
||||
@@ -270,7 +235,7 @@ static void internal_delete_childs (reiserfs_filsys_t fs,
|
||||
* last_first == FIRST_TO_LAST means, that we copy first items from src to tail of dest
|
||||
* last_first == LAST_TO_FIRST means, that we copy last items from src to head of dest
|
||||
*/
|
||||
static void internal_copy_pointers_items (reiserfs_filsys_t fs,
|
||||
static void internal_copy_pointers_items (reiserfs_filsys_t * fs,
|
||||
struct buffer_info * dest_bi,
|
||||
struct buffer_head * src,
|
||||
int last_first, int cpy_num)
|
||||
@@ -286,31 +251,12 @@ static void internal_copy_pointers_items (reiserfs_filsys_t fs,
|
||||
|
||||
nr_src = B_NR_ITEMS (src);
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( dest == NULL || src == NULL )
|
||||
reiserfs_panic (0, "internal_copy_pointers_items", "src (%p) or dest (%p) buffer is 0", src, dest);
|
||||
|
||||
if (last_first != FIRST_TO_LAST && last_first != LAST_TO_FIRST)
|
||||
reiserfs_panic (0, "internal_copy_pointers_items",
|
||||
"invalid last_first parameter (%d)", last_first);
|
||||
|
||||
if ( nr_src < cpy_num - 1 )
|
||||
reiserfs_panic (0, "internal_copy_pointers_items", "no so many items (%d) in src (%d)", cpy_num, nr_src);
|
||||
|
||||
if ( cpy_num < 0 )
|
||||
reiserfs_panic (0, "internal_copy_pointers_items", "cpy_num less than 0 (%d)", cpy_num);
|
||||
|
||||
if (cpy_num - 1 + B_NR_ITEMS(dest) > (int)MAX_NR_KEY(dest))
|
||||
reiserfs_panic (0, "internal_copy_pointers_items",
|
||||
"cpy_num (%d) + item number in dest (%d) can not be more than MAX_NR_KEY(%d)",
|
||||
cpy_num, B_NR_ITEMS(dest), MAX_NR_KEY(dest));
|
||||
#endif
|
||||
|
||||
if ( cpy_num == 0 )
|
||||
return;
|
||||
|
||||
/* coping */
|
||||
nr_dest = (blkh = B_BLK_HEAD(dest))->blk_nr_item;
|
||||
/* coping */
|
||||
blkh = B_BLK_HEAD (dest);
|
||||
nr_dest = get_blkh_nr_items (blkh);
|
||||
|
||||
/*dest_order = (last_first == LAST_TO_FIRST) ? 0 : nr_dest;*/
|
||||
/*src_order = (last_first == LAST_TO_FIRST) ? (nr_src - cpy_num + 1) : 0;*/
|
||||
@@ -336,13 +282,14 @@ static void internal_copy_pointers_items (reiserfs_filsys_t fs,
|
||||
memcpy (key, B_N_PDELIM_KEY (src, src_order), KEY_SIZE * (cpy_num - 1));
|
||||
|
||||
/* sizes, item number */
|
||||
blkh->blk_nr_item += cpy_num - 1;
|
||||
blkh->blk_free_space -= KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num;
|
||||
set_blkh_nr_items (blkh, get_blkh_nr_items (blkh) + cpy_num - 1);
|
||||
set_blkh_free_space (blkh, get_blkh_free_space (blkh) -
|
||||
(KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num));
|
||||
|
||||
mark_buffer_dirty (dest);
|
||||
if (dest_bi->bi_parent) {
|
||||
B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position)->dc_size +=
|
||||
KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num;
|
||||
dc = B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position);
|
||||
set_dc_child_size (dc, get_dc_child_size (dc) + KEY_SIZE * (cpy_num - 1) + DC_SIZE * cpy_num);
|
||||
mark_buffer_dirty (dest_bi->bi_parent);
|
||||
}
|
||||
|
||||
@@ -354,7 +301,7 @@ static void internal_copy_pointers_items (reiserfs_filsys_t fs,
|
||||
* last_first == FIRST_TO_LAST means, that we copy/delete first items from src.
|
||||
* last_first == LAST_TO_FIRST means, that we copy/delete last items from src.
|
||||
*/
|
||||
static void internal_move_pointers_items (reiserfs_filsys_t fs,
|
||||
static void internal_move_pointers_items (reiserfs_filsys_t * fs,
|
||||
struct buffer_info * dest_bi,
|
||||
struct buffer_info * src_bi,
|
||||
int last_first, int cpy_num, int del_par)
|
||||
@@ -380,7 +327,7 @@ static void internal_move_pointers_items (reiserfs_filsys_t fs,
|
||||
}
|
||||
|
||||
/* Insert n_src'th key of buffer src before n_dest'th key of buffer dest. */
|
||||
static void internal_insert_key (reiserfs_filsys_t fs,
|
||||
static void internal_insert_key (reiserfs_filsys_t * fs,
|
||||
struct buffer_info * dest_bi,
|
||||
int dest_position_before, /* insert key before key with n_dest number */
|
||||
struct buffer_head * src,
|
||||
@@ -391,26 +338,8 @@ static void internal_insert_key (reiserfs_filsys_t fs,
|
||||
struct block_head * blkh;
|
||||
struct key * key;
|
||||
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if (dest == NULL || src == NULL)
|
||||
reiserfs_panic (0, "internal_insert_key", "sourse(%p) or dest(%p) buffer is 0", src, dest);
|
||||
|
||||
if (dest_position_before < 0 || src_position < 0)
|
||||
reiserfs_panic (0, "internal_insert_key", "source(%d) or dest(%d) key number less than 0",
|
||||
src_position, dest_position_before);
|
||||
|
||||
if (dest_position_before > B_NR_ITEMS (dest) || src_position >= B_NR_ITEMS(src))
|
||||
reiserfs_panic (0, "internal_insert_key",
|
||||
"invalid position in dest (%d (key number %d)) or in src (%d (key number %d))",
|
||||
dest_position_before, B_NR_ITEMS (dest), src_position, B_NR_ITEMS(src));
|
||||
|
||||
if (B_BLK_HEAD(dest)->blk_free_space < KEY_SIZE)
|
||||
reiserfs_panic (0, "internal_insert_key",
|
||||
"no enough free space (%d) in dest buffer", B_BLK_HEAD(dest)->blk_free_space);
|
||||
#endif
|
||||
|
||||
nr = (blkh=B_BLK_HEAD(dest))->blk_nr_item;
|
||||
blkh = B_BLK_HEAD(dest);
|
||||
nr = get_blkh_nr_items (blkh);
|
||||
|
||||
/* prepare space for inserting key */
|
||||
key = B_N_PDELIM_KEY (dest, dest_position_before);
|
||||
@@ -420,13 +349,16 @@ static void internal_insert_key (reiserfs_filsys_t fs,
|
||||
memcpy (key, B_N_PDELIM_KEY(src, src_position), KEY_SIZE);
|
||||
|
||||
/* Change dirt, free space, item number fields. */
|
||||
blkh->blk_nr_item ++;
|
||||
blkh->blk_free_space -= KEY_SIZE;
|
||||
set_blkh_nr_items (blkh, get_blkh_nr_items (blkh) + 1);
|
||||
set_blkh_free_space (blkh, get_blkh_free_space (blkh) - KEY_SIZE);
|
||||
|
||||
mark_buffer_dirty (dest);
|
||||
|
||||
if (dest_bi->bi_parent) {
|
||||
B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position)->dc_size += KEY_SIZE;
|
||||
struct disk_child * dc;
|
||||
|
||||
dc = B_N_CHILD(dest_bi->bi_parent,dest_bi->bi_position);
|
||||
set_dc_child_size (dc, get_dc_child_size (dc) + KEY_SIZE);
|
||||
mark_buffer_dirty (dest_bi->bi_parent);
|
||||
}
|
||||
}
|
||||
@@ -453,16 +385,16 @@ static void internal_shift_left (int mode, /* INTERNAL_FROM_S_TO_L | INTERNAL_FR
|
||||
|
||||
if (pointer_amount) {
|
||||
/* insert delimiting key from common father of dest and src to node dest into position B_NR_ITEM(dest) */
|
||||
internal_insert_key (tb->tb_sb, &dest_bi, B_NR_ITEMS(dest_bi.bi_bh), cf, d_key_position);
|
||||
internal_insert_key (tb->tb_fs, &dest_bi, B_NR_ITEMS(dest_bi.bi_bh), cf, d_key_position);
|
||||
|
||||
if (B_NR_ITEMS(src_bi.bi_bh) == pointer_amount - 1) {
|
||||
if (src_bi.bi_position/*src->b_item_order*/ == 0)
|
||||
replace_key (tb->tb_sb, cf, d_key_position, src_bi.bi_parent/*src->b_parent*/, 0);
|
||||
replace_key (tb->tb_fs, cf, d_key_position, src_bi.bi_parent/*src->b_parent*/, 0);
|
||||
} else
|
||||
replace_key (tb->tb_sb, cf, d_key_position, src_bi.bi_bh, pointer_amount - 1);
|
||||
replace_key (tb->tb_fs, cf, d_key_position, src_bi.bi_bh, pointer_amount - 1);
|
||||
}
|
||||
/* last parameter is del_parameter */
|
||||
internal_move_pointers_items (tb->tb_sb, &dest_bi, &src_bi, FIRST_TO_LAST, pointer_amount, 0);
|
||||
internal_move_pointers_items (tb->tb_fs, &dest_bi, &src_bi, FIRST_TO_LAST, pointer_amount, 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -481,10 +413,10 @@ static void internal_shift1_left (struct tree_balance * tb,
|
||||
internal_define_dest_src_infos (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, &dest_bi, &src_bi, &d_key_position, &cf);
|
||||
|
||||
if ( pointer_amount > 0 ) /* insert lkey[h]-th key from CFL[h] to left neighbor L[h] */
|
||||
internal_insert_key (tb->tb_sb, &dest_bi, B_NR_ITEMS(dest_bi.bi_bh), cf, d_key_position);
|
||||
internal_insert_key (tb->tb_fs, &dest_bi, B_NR_ITEMS(dest_bi.bi_bh), cf, d_key_position);
|
||||
|
||||
/* last parameter is del_parameter */
|
||||
internal_move_pointers_items (tb->tb_sb, &dest_bi, &src_bi, FIRST_TO_LAST, pointer_amount, 1);
|
||||
internal_move_pointers_items (tb->tb_fs, &dest_bi, &src_bi, FIRST_TO_LAST, pointer_amount, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -509,22 +441,17 @@ static void internal_shift_right (int mode, /* INTERNAL_FROM_S_TO_R | INTERNAL_F
|
||||
|
||||
if (pointer_amount > 0) {
|
||||
/* insert delimiting key from common father of dest and src to dest node into position 0 */
|
||||
internal_insert_key (tb->tb_sb, &dest_bi, 0, cf, d_key_position);
|
||||
internal_insert_key (tb->tb_fs, &dest_bi, 0, cf, d_key_position);
|
||||
if (nr == pointer_amount - 1) {
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( src_bi.bi_bh != PATH_H_PBUFFER (tb->tb_path, h)/*tb->S[h]*/ || dest_bi.bi_bh != tb->R[h])
|
||||
reiserfs_panic (tb->tb_sb, "internal_shift_right", "src (%p) must be == tb->S[h](%p) when it disappears",
|
||||
src_bi.bi_bh, PATH_H_PBUFFER (tb->tb_path, h));
|
||||
#endif
|
||||
/* when S[h] disappers replace left delemiting key as well */
|
||||
if (tb->CFL[h])
|
||||
replace_key(tb->tb_sb, cf, d_key_position, tb->CFL[h], tb->lkey[h]);
|
||||
replace_key(tb->tb_fs, cf, d_key_position, tb->CFL[h], tb->lkey[h]);
|
||||
} else
|
||||
replace_key(tb->tb_sb, cf, d_key_position, src_bi.bi_bh, nr - pointer_amount);
|
||||
replace_key(tb->tb_fs, cf, d_key_position, src_bi.bi_bh, nr - pointer_amount);
|
||||
}
|
||||
|
||||
/* last parameter is del_parameter */
|
||||
internal_move_pointers_items (tb->tb_sb, &dest_bi, &src_bi, LAST_TO_FIRST, pointer_amount, 0);
|
||||
internal_move_pointers_items (tb->tb_fs, &dest_bi, &src_bi, LAST_TO_FIRST, pointer_amount, 0);
|
||||
}
|
||||
|
||||
/* Insert delimiting key to R[h].
|
||||
@@ -542,10 +469,10 @@ static void internal_shift1_right (struct tree_balance * tb,
|
||||
internal_define_dest_src_infos (INTERNAL_SHIFT_FROM_S_TO_R, tb, h, &dest_bi, &src_bi, &d_key_position, &cf);
|
||||
|
||||
if (pointer_amount > 0) /* insert rkey from CFR[h] to right neighbor R[h] */
|
||||
internal_insert_key (tb->tb_sb, &dest_bi, 0, cf, d_key_position);
|
||||
internal_insert_key (tb->tb_fs, &dest_bi, 0, cf, d_key_position);
|
||||
|
||||
/* last parameter is del_parameter */
|
||||
internal_move_pointers_items (tb->tb_sb, &dest_bi, &src_bi, LAST_TO_FIRST, pointer_amount, 1);
|
||||
internal_move_pointers_items (tb->tb_fs, &dest_bi, &src_bi, LAST_TO_FIRST, pointer_amount, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -568,13 +495,7 @@ static void balance_internal_when_delete (struct tree_balance * tb,
|
||||
|
||||
bi.bi_position = PATH_H_POSITION (tb->tb_path, h + 1);
|
||||
|
||||
internal_delete_childs (tb->tb_sb, &bi, child_pos, -insert_num);
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( tb->blknum[h] > 1 )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal_when_delete", "tb->blknum[%d]=%d when insert_size < 0",
|
||||
h, tb->blknum[h]);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
internal_delete_childs (tb->tb_fs, &bi, child_pos, -insert_num);
|
||||
|
||||
n = B_NR_ITEMS(tbSh);
|
||||
|
||||
@@ -582,15 +503,7 @@ static void balance_internal_when_delete (struct tree_balance * tb,
|
||||
if ( tb->blknum[h] == 0 ) {
|
||||
/* node S[h] (root of the tree) is empty now */
|
||||
struct buffer_head *new_root;
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if (n || B_BLK_HEAD (tbSh)->blk_free_space != MAX_CHILD_SIZE(tbSh) - DC_SIZE)
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal_when_delete", "buffer must have only 0 keys (%d)",
|
||||
n);
|
||||
|
||||
if (bi.bi_parent)
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal_when_delete", "root has parent (%p)", bi.bi_parent);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
struct reiserfs_super_block * sb;
|
||||
|
||||
/* choose a new root */
|
||||
if ( ! tb->L[h-1] || ! B_NR_ITEMS(tb->L[h-1]) )
|
||||
@@ -599,11 +512,12 @@ static void balance_internal_when_delete (struct tree_balance * tb,
|
||||
new_root = tb->L[h-1];
|
||||
|
||||
/* update super block's tree height and pointer to a root block */
|
||||
tb->tb_sb->s_rs->s_v1.s_root_block = cpu_to_le32 (new_root->b_blocknr);
|
||||
tb->tb_sb->s_rs->s_v1.s_tree_height = SB_TREE_HEIGHT (tb->tb_sb) - 1;
|
||||
sb = tb->tb_fs->fs_ondisk_sb;
|
||||
set_sb_root_block (sb, new_root->b_blocknr);
|
||||
set_sb_tree_height (sb, get_sb_tree_height (sb) - 1);
|
||||
|
||||
mark_buffer_dirty (tb->tb_sb->s_sbh);
|
||||
tb->tb_sb->s_dirt = 1;
|
||||
mark_buffer_dirty (tb->tb_fs->fs_super_bh);
|
||||
tb->tb_fs->fs_dirt = 1;
|
||||
|
||||
/* mark buffer S[h] not uptodate and put it in free list */
|
||||
reiserfs_invalidate_buffer(tb, tbSh, 1);
|
||||
@@ -613,13 +527,6 @@ static void balance_internal_when_delete (struct tree_balance * tb,
|
||||
}
|
||||
|
||||
if ( tb->L[h] && tb->lnum[h] == -B_NR_ITEMS(tb->L[h]) - 1 ) { /* join S[h] with L[h] */
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( tb->rnum[h] != 0 )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal_when_delete", "invalid tb->rnum[%d]==%d when joining S[h] with L[h]",
|
||||
h, tb->rnum[h]);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
internal_shift_left (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, n + 1);/*tb->L[h], tb->CFL[h], tb->lkey[h], tb->S[h], n+1);*/
|
||||
reiserfs_invalidate_buffer(tb, tbSh, 1); /* preserve not needed, internal, 1 mean free block */
|
||||
|
||||
@@ -627,46 +534,22 @@ static void balance_internal_when_delete (struct tree_balance * tb,
|
||||
}
|
||||
|
||||
if ( tb->R[h] && tb->rnum[h] == -B_NR_ITEMS(tb->R[h]) - 1 ) { /* join S[h] with R[h] */
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( tb->lnum[h] != 0 )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal_when_delete", "invalid tb->lnum[%d]==%d when joining S[h] with R[h]",
|
||||
h, tb->lnum[h]);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
internal_shift_right (INTERNAL_SHIFT_FROM_S_TO_R, tb, h, n + 1);
|
||||
reiserfs_invalidate_buffer (tb, tbSh, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( tb->lnum[h] < 0 ) { /* borrow from left neighbor L[h] */
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( tb->rnum[h] != 0 )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal_when_delete", "invalid tb->rnum[%d]==%d when borrow from L[h]",
|
||||
h, tb->rnum[h]);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
internal_shift_right (INTERNAL_SHIFT_FROM_L_TO_S, tb, h, -tb->lnum[h]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( tb->rnum[h] < 0 ) { /* borrow from right neighbor R[h] */
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( tb->lnum[h] != 0 )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal_when_delete", "invalid tb->lnum[%d]==%d when borrow from R[h]",
|
||||
h, tb->lnum[h]);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
internal_shift_left (INTERNAL_SHIFT_FROM_R_TO_S, tb, h, -tb->rnum[h]);/*tb->S[h], tb->CFR[h], tb->rkey[h], tb->R[h], -tb->rnum[h]);*/
|
||||
return;
|
||||
}
|
||||
|
||||
if ( tb->lnum[h] > 0 ) { /* split S[h] into two parts and put them into neighbors */
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( tb->rnum[h] == 0 || tb->lnum[h] + tb->rnum[h] != n + 1 )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal_when_delete",
|
||||
"invalid tb->lnum[%d]==%d or tb->rnum[%d]==%d when S[h](item number == %d) is split between them",
|
||||
h, tb->lnum[h], h, tb->rnum[h], n);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
internal_shift_left (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, tb->lnum[h]);/*tb->L[h], tb->CFL[h], tb->lkey[h], tb->S[h], tb->lnum[h]);*/
|
||||
internal_shift_right (INTERNAL_SHIFT_FROM_S_TO_R, tb, h, tb->rnum[h]);
|
||||
reiserfs_invalidate_buffer (tb, tbSh, 1);
|
||||
@@ -682,12 +565,6 @@ static void balance_internal_when_delete (struct tree_balance * tb,
|
||||
void replace_lkey (struct tree_balance * tb,
|
||||
int h, struct item_head * key)
|
||||
{
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if (tb->L[h] == NULL || tb->CFL[h] == NULL)
|
||||
reiserfs_panic (tb->tb_sb, "replace_lkey: 12255: "
|
||||
"L[h](%p) and CFL[h](%p) must exist in replace_lkey", tb->L[h], tb->CFL[h]);
|
||||
#endif
|
||||
|
||||
if (B_NR_ITEMS(PATH_H_PBUFFER(tb->tb_path, h)) == 0)
|
||||
return;
|
||||
|
||||
@@ -701,16 +578,6 @@ void replace_lkey (struct tree_balance * tb,
|
||||
void replace_rkey (struct tree_balance * tb,
|
||||
int h, struct item_head * key)
|
||||
{
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if (tb->R[h] == NULL || tb->CFR[h] == NULL)
|
||||
reiserfs_panic (tb->tb_sb, "replace_rkey: 12260: "
|
||||
"R[h](%p) and CFR[h](%p) must exist in replace_rkey", tb->R[h], tb->CFR[h]);
|
||||
|
||||
if (B_NR_ITEMS(tb->R[h]) == 0)
|
||||
reiserfs_panic (tb->tb_sb, "replace_rkey: 12265: "
|
||||
"R[h] can not be empty if it exists (item number=%d)", B_NR_ITEMS(tb->R[h]));
|
||||
#endif
|
||||
|
||||
memcpy (B_N_PDELIM_KEY(tb->CFR[h],tb->rkey[h]), key, KEY_SIZE);
|
||||
|
||||
mark_buffer_dirty (tb->CFR[h]);
|
||||
@@ -747,11 +614,6 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
struct buffer_head * new_insert_ptr = NULL;
|
||||
struct item_head * new_insert_key_addr = insert_key;
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( h < 1 )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal", "h (%d) can not be < 1 on internal level", h);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
order = ( tbSh ) ? PATH_H_POSITION (tb->tb_path, h + 1)/*tb->S[h]->b_item_order*/ : 0;
|
||||
|
||||
/* Using insert_size[h] calculate the number insert_num of items
|
||||
@@ -759,17 +621,6 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
insert_num = tb->insert_size[h]/((int)(KEY_SIZE + DC_SIZE));
|
||||
|
||||
/* Check whether insert_num is proper **/
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( insert_num < -2 || insert_num > 2 )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal",
|
||||
"incorrect number of items inserted to the internal node (%d)", insert_num);
|
||||
|
||||
if ( h > 1 && (insert_num > 1 || insert_num < -1) )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal",
|
||||
"incorrect number of items (%d) inserted to the internal node on a level (h=%d) higher than last internal level",
|
||||
insert_num, h);
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
/* Make balance in case insert_num < 0 */
|
||||
if ( insert_num < 0 ) {
|
||||
balance_internal_when_delete (tb, h, child_pos);
|
||||
@@ -780,7 +631,7 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
if ( tb->lnum[h] > 0 ) {
|
||||
/* shift lnum[h] items from S[h] to the left neighbor L[h].
|
||||
check how many of new items fall into L[h] or CFL[h] after shifting */
|
||||
n = B_BLK_HEAD(tb->L[h])->blk_nr_item; /* number of items in L[h] */
|
||||
n = get_blkh_nr_items (B_BLK_HEAD(tb->L[h])); /* number of items in L[h] */
|
||||
if ( tb->lnum[h] <= child_pos ) {
|
||||
/* new items don't fall into L[h] or CFL[h] */
|
||||
internal_shift_left (INTERNAL_SHIFT_FROM_S_TO_L, tb, h, tb->lnum[h]);
|
||||
@@ -793,7 +644,7 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
bi.bi_bh = tb->L[h];
|
||||
bi.bi_parent = tb->FL[h];
|
||||
bi.bi_position = get_left_neighbor_position (tb, h);
|
||||
internal_insert_childs (tb->tb_sb, &bi,/*tb->L[h], tb->S[h-1]->b_next*/ n + child_pos + 1,
|
||||
internal_insert_childs (tb->tb_fs, &bi,/*tb->L[h], tb->S[h-1]->b_next*/ n + child_pos + 1,
|
||||
insert_num,insert_key,insert_ptr);
|
||||
|
||||
insert_num = 0;
|
||||
@@ -808,16 +659,16 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
bi.bi_bh = tb->L[h];
|
||||
bi.bi_parent = tb->FL[h];
|
||||
bi.bi_position = get_left_neighbor_position (tb, h);
|
||||
internal_insert_childs (tb->tb_sb, &bi,/*tb->L[h], tb->S[h-1]->b_next,*/ n + child_pos + 1,k,
|
||||
internal_insert_childs (tb->tb_fs, &bi,/*tb->L[h], tb->S[h-1]->b_next,*/ n + child_pos + 1,k,
|
||||
insert_key,insert_ptr);
|
||||
|
||||
replace_lkey(tb, h, insert_key + k);
|
||||
|
||||
/* replace the first node-ptr in S[h] by node-ptr to insert_ptr[k] */
|
||||
(dc = B_N_CHILD(tbSh, 0))->dc_size =
|
||||
MAX_CHILD_SIZE(insert_ptr[k]) -
|
||||
B_BLK_HEAD(insert_ptr[k])->blk_free_space;
|
||||
dc->dc_block_number = insert_ptr[k]->b_blocknr;
|
||||
dc = B_N_CHILD(tbSh, 0);
|
||||
set_dc_child_size (dc, MAX_CHILD_SIZE(insert_ptr[k]->b_size) -
|
||||
get_blkh_free_space (B_BLK_HEAD(insert_ptr[k])));
|
||||
set_dc_child_blocknr (dc, insert_ptr[k]->b_blocknr);
|
||||
|
||||
mark_buffer_dirty (tbSh);
|
||||
|
||||
@@ -832,7 +683,7 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
if ( tb->rnum[h] > 0 ) {
|
||||
/*shift rnum[h] items from S[h] to the right neighbor R[h]*/
|
||||
/* check how many of new items fall into R or CFR after shifting */
|
||||
n = B_BLK_HEAD (tbSh)->blk_nr_item; /* number of items in S[h] */
|
||||
n = get_blkh_nr_items (B_BLK_HEAD (tbSh)); /* number of items in S[h] */
|
||||
if ( n - tb->rnum[h] >= child_pos )
|
||||
/* new items fall into S[h] */
|
||||
/*internal_shift_right(tb,h,tbSh,tb->CFR[h],tb->rkey[h],tb->R[h],tb->rnum[h]);*/
|
||||
@@ -847,7 +698,7 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
bi.bi_bh = tb->R[h];
|
||||
bi.bi_parent = tb->FR[h];
|
||||
bi.bi_position = get_right_neighbor_position (tb, h);
|
||||
internal_insert_childs (tb->tb_sb, &bi, /*tb->R[h],tb->S[h-1]->b_next*/ child_pos - n - insert_num + tb->rnum[h] - 1,
|
||||
internal_insert_childs (tb->tb_fs, &bi, /*tb->R[h],tb->S[h-1]->b_next*/ child_pos - n - insert_num + tb->rnum[h] - 1,
|
||||
insert_num,insert_key,insert_ptr);
|
||||
insert_num = 0;
|
||||
}
|
||||
@@ -863,15 +714,15 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
bi.bi_bh = tb->R[h];
|
||||
bi.bi_parent = tb->FR[h];
|
||||
bi.bi_position = get_right_neighbor_position (tb, h);
|
||||
internal_insert_childs (tb->tb_sb, &bi, /*tb->R[h], tb->R[h]->b_child,*/ 0, k, insert_key + 1, insert_ptr + 1);
|
||||
internal_insert_childs (tb->tb_fs, &bi, /*tb->R[h], tb->R[h]->b_child,*/ 0, k, insert_key + 1, insert_ptr + 1);
|
||||
|
||||
replace_rkey(tb, h, insert_key + insert_num - k - 1);
|
||||
|
||||
/* replace the first node-ptr in R[h] by node-ptr insert_ptr[insert_num-k-1]*/
|
||||
(dc = B_N_CHILD(tb->R[h], 0))->dc_size =
|
||||
MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]) -
|
||||
B_BLK_HEAD(insert_ptr[insert_num-k-1])->blk_free_space;
|
||||
dc->dc_block_number = insert_ptr[insert_num-k-1]->b_blocknr;
|
||||
dc = B_N_CHILD(tb->R[h], 0);
|
||||
set_dc_child_size (dc, MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]->b_size) -
|
||||
get_blkh_free_space (B_BLK_HEAD(insert_ptr[insert_num-k-1])));
|
||||
set_dc_child_blocknr (dc, insert_ptr[insert_num-k-1]->b_blocknr);
|
||||
|
||||
mark_buffer_dirty (tb->R[h]);
|
||||
|
||||
@@ -880,20 +731,8 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
}
|
||||
|
||||
/** Fill new node that appears instead of S[h] **/
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( tb->blknum[h] > 2 )
|
||||
reiserfs_panic(0, "balance_internal", "blknum can not be > 2 for internal level");
|
||||
if ( tb->blknum[h] < 0 )
|
||||
reiserfs_panic(0, "balance_internal", "blknum can not be < 0");
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
if ( ! tb->blknum[h] )
|
||||
{ /* node S[h] is empty now */
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( ! tbSh )
|
||||
reiserfs_panic(0,"balance_internal", "S[h] is equal NULL");
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
/* Mark buffer as invalid and put it to head of free list. */
|
||||
reiserfs_invalidate_buffer(tb, tbSh, 1);/* do not preserve, internal node*/
|
||||
return order;
|
||||
@@ -903,21 +742,23 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
/* create new root */
|
||||
struct disk_child * dc;
|
||||
struct buffer_head * tbSh_1 = PATH_H_PBUFFER (tb->tb_path, h - 1);
|
||||
|
||||
struct reiserfs_super_block * sb;
|
||||
|
||||
if ( tb->blknum[h] != 1 )
|
||||
reiserfs_panic(0, "balance_internal", "One new node required for creating the new root");
|
||||
/* S[h] = empty buffer from the list FEB. */
|
||||
tbSh = get_FEB (tb);
|
||||
B_BLK_HEAD(tbSh)->blk_level = h + 1;
|
||||
set_blkh_level (B_BLK_HEAD(tbSh), h + 1);
|
||||
|
||||
/* Put the unique node-pointer to S[h] that points to S[h-1]. */
|
||||
|
||||
(dc = B_N_CHILD(tbSh, 0))->dc_block_number = tbSh_1->b_blocknr;
|
||||
dc->dc_size = MAX_CHILD_SIZE (tbSh_1) - B_BLK_HEAD(tbSh_1)->blk_free_space;
|
||||
dc = B_N_CHILD(tbSh, 0);
|
||||
set_dc_child_size (dc, MAX_CHILD_SIZE (tbSh_1->b_size) - get_blkh_free_space (B_BLK_HEAD(tbSh_1)));
|
||||
set_dc_child_blocknr (dc, tbSh_1->b_blocknr);
|
||||
|
||||
tb->insert_size[h] -= DC_SIZE;
|
||||
B_BLK_HEAD(tbSh)->blk_free_space -= DC_SIZE;
|
||||
set_blkh_free_space (B_BLK_HEAD(tbSh),
|
||||
get_blkh_free_space (B_BLK_HEAD(tbSh)) - DC_SIZE);
|
||||
|
||||
mark_buffer_dirty (tbSh);
|
||||
|
||||
@@ -925,11 +766,12 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
PATH_OFFSET_PBUFFER(tb->tb_path, ILLEGAL_PATH_ELEMENT_OFFSET) = tbSh;
|
||||
|
||||
/* Change root in structure super block. */
|
||||
tb->tb_sb->s_rs->s_v1.s_root_block = cpu_to_le32 (tbSh->b_blocknr);
|
||||
tb->tb_sb->s_rs->s_v1.s_tree_height = cpu_to_le16 (SB_TREE_HEIGHT (tb->tb_sb) + 1);
|
||||
sb = tb->tb_fs->fs_ondisk_sb;
|
||||
set_sb_root_block (sb, tbSh->b_blocknr);
|
||||
set_sb_tree_height (sb, get_sb_tree_height (sb) + 1);
|
||||
|
||||
mark_buffer_dirty (tb->tb_sb->s_sbh);
|
||||
tb->tb_sb->s_dirt = 1;
|
||||
mark_buffer_dirty (tb->tb_fs->fs_super_bh);
|
||||
tb->tb_fs->fs_dirt = 1;
|
||||
}
|
||||
|
||||
if ( tb->blknum[h] == 2 ) {
|
||||
@@ -940,8 +782,7 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
/* S_new = free buffer from list FEB */
|
||||
S_new = get_FEB(tb);
|
||||
|
||||
B_BLK_HEAD(S_new)->blk_level = h + 1;
|
||||
|
||||
set_blkh_level (B_BLK_HEAD(S_new), h + 1);
|
||||
|
||||
dest_bi.bi_bh = S_new;
|
||||
dest_bi.bi_parent = 0;
|
||||
@@ -950,7 +791,7 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
src_bi.bi_parent = PATH_H_PPARENT (tb->tb_path, h);
|
||||
src_bi.bi_position = PATH_H_POSITION (tb->tb_path, h + 1);
|
||||
|
||||
n = B_BLK_HEAD(tbSh)->blk_nr_item; /* number of items in S[h] */
|
||||
n = get_blkh_nr_items (B_BLK_HEAD(tbSh)); /* number of items in S[h] */
|
||||
snum = (insert_num + n + 1)/2;
|
||||
if ( n - snum >= child_pos ) {
|
||||
/* new items don't fall into S_new */
|
||||
@@ -959,7 +800,7 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
memcpy (&new_insert_key,B_N_PDELIM_KEY(tbSh,n - snum),
|
||||
KEY_SIZE);
|
||||
/* last parameter is del_par */
|
||||
internal_move_pointers_items (tb->tb_sb, &dest_bi, &src_bi, LAST_TO_FIRST, snum, 0);
|
||||
internal_move_pointers_items (tb->tb_fs, &dest_bi, &src_bi, LAST_TO_FIRST, snum, 0);
|
||||
} else if ( n + insert_num - snum < child_pos ) {
|
||||
/* all new items fall into S_new */
|
||||
/* store the delimiting key for the next level */
|
||||
@@ -967,11 +808,11 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
memcpy(&new_insert_key,B_N_PDELIM_KEY(tbSh,n + insert_num - snum),
|
||||
KEY_SIZE);
|
||||
/* last parameter is del_par */
|
||||
internal_move_pointers_items (tb->tb_sb, &dest_bi, &src_bi, LAST_TO_FIRST, snum - insert_num, 0);
|
||||
internal_move_pointers_items (tb->tb_fs, &dest_bi, &src_bi, LAST_TO_FIRST, snum - insert_num, 0);
|
||||
/* internal_move_pointers_items(S_new,tbSh,1,snum - insert_num,0);*/
|
||||
|
||||
/* insert insert_num keys and node-pointers into S_new */
|
||||
internal_insert_childs (tb->tb_sb, &dest_bi, /*S_new,tb->S[h-1]->b_next,*/child_pos - n - insert_num + snum - 1,
|
||||
internal_insert_childs (tb->tb_fs, &dest_bi, /*S_new,tb->S[h-1]->b_next,*/child_pos - n - insert_num + snum - 1,
|
||||
insert_num,insert_key,insert_ptr);
|
||||
|
||||
insert_num = 0;
|
||||
@@ -980,22 +821,22 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
|
||||
/* some items fall into S_new, but some don't fall */
|
||||
/* last parameter is del_par */
|
||||
internal_move_pointers_items (tb->tb_sb, &dest_bi, &src_bi, LAST_TO_FIRST, n - child_pos + 1, 1);
|
||||
internal_move_pointers_items (tb->tb_fs, &dest_bi, &src_bi, LAST_TO_FIRST, n - child_pos + 1, 1);
|
||||
/* internal_move_pointers_items(S_new,tbSh,1,n - child_pos + 1,1);*/
|
||||
/* calculate number of new items that fall into S_new */
|
||||
k = snum - n + child_pos - 1;
|
||||
|
||||
internal_insert_childs (tb->tb_sb, &dest_bi, /*S_new,*/ 0, k, insert_key + 1, insert_ptr+1);
|
||||
internal_insert_childs (tb->tb_fs, &dest_bi, /*S_new,*/ 0, k, insert_key + 1, insert_ptr+1);
|
||||
|
||||
/* new_insert_key = insert_key[insert_num - k - 1] */
|
||||
memcpy(&new_insert_key,insert_key + insert_num - k - 1,
|
||||
KEY_SIZE);
|
||||
/* replace first node-ptr in S_new by node-ptr to insert_ptr[insert_num-k-1] */
|
||||
|
||||
(dc = B_N_CHILD(S_new,0))->dc_size =
|
||||
MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]) -
|
||||
B_BLK_HEAD(insert_ptr[insert_num-k-1])->blk_free_space;
|
||||
dc->dc_block_number = insert_ptr[insert_num-k-1]->b_blocknr;
|
||||
dc = B_N_CHILD(S_new,0);
|
||||
set_dc_child_size (dc, MAX_CHILD_SIZE(insert_ptr[insert_num-k-1]->b_size) -
|
||||
get_blkh_free_space (B_BLK_HEAD(insert_ptr[insert_num-k-1])));
|
||||
set_dc_child_blocknr (dc, insert_ptr[insert_num-k-1]->b_blocknr);
|
||||
|
||||
mark_buffer_dirty (S_new);
|
||||
|
||||
@@ -1003,50 +844,34 @@ int balance_internal (struct tree_balance * tb, /* tree_balance structure */
|
||||
}
|
||||
/* new_insert_ptr = node_pointer to S_new */
|
||||
new_insert_ptr = S_new;
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( buffer_locked(S_new) )
|
||||
reiserfs_panic (tb->tb_sb, "balance_internal", "locked buffer S_new[]");
|
||||
if (S_new->b_count != 1)
|
||||
if (!(buffer_journaled(S_new) && S_new->b_count == 2)) {
|
||||
printk ("REISERFS: balance_internal: S_new->b_count != 1 (%u)\n", S_new->b_count);
|
||||
}
|
||||
#endif /* CONFIG_REISERFS_CHECK */
|
||||
|
||||
/*
|
||||
S_new->b_count --;
|
||||
*/
|
||||
/*brelse(S_new);*/
|
||||
}
|
||||
|
||||
n = B_BLK_HEAD(tbSh)->blk_nr_item; /*number of items in S[h] */
|
||||
n = get_blkh_nr_items (B_BLK_HEAD(tbSh)); /*number of items in S[h] */
|
||||
|
||||
#ifndef FU //REISERFS_FSCK
|
||||
if ( -1 <= child_pos && child_pos <= n && insert_num > 0 ) {
|
||||
#else
|
||||
if ( 0 <= child_pos && child_pos <= n && insert_num > 0 ) {
|
||||
#endif
|
||||
bi.bi_bh = tbSh;
|
||||
bi.bi_parent = PATH_H_PPARENT (tb->tb_path, h);
|
||||
bi.bi_position = PATH_H_POSITION (tb->tb_path, h + 1);
|
||||
#ifndef FU //REISERFS_FSCK
|
||||
if (child_pos == -1) {
|
||||
/* this is a little different from original do_balance:
|
||||
here we insert the minimal keys in the tree, that has never happened when file system works */
|
||||
if (tb->CFL[h-1] || insert_num != 1 || h != 1)
|
||||
die ("balance_internal: invalid child_pos");
|
||||
/* insert_child (tb->S[h], tb->S[h-1], child_pos, insert_num, B_N_ITEM_HEAD(tb->S[0],0), insert_ptr);*/
|
||||
internal_insert_childs (tb->tb_sb, &bi, child_pos, insert_num, B_N_PITEM_HEAD (PATH_PLAST_BUFFER (tb->tb_path), 0), insert_ptr);
|
||||
} else
|
||||
#endif
|
||||
internal_insert_childs (tb->tb_sb,
|
||||
&bi, child_pos,insert_num,insert_key,insert_ptr);
|
||||
}
|
||||
|
||||
|
||||
memcpy (new_insert_key_addr,&new_insert_key,KEY_SIZE);
|
||||
insert_ptr[0] = new_insert_ptr;
|
||||
|
||||
return order;
|
||||
bi.bi_bh = tbSh;
|
||||
bi.bi_parent = PATH_H_PPARENT (tb->tb_path, h);
|
||||
bi.bi_position = PATH_H_POSITION (tb->tb_path, h + 1);
|
||||
if (child_pos == -1) {
|
||||
/* this is a little different from original do_balance:
|
||||
here we insert the minimal keys in the tree, that has never happened when file system works */
|
||||
if (tb->CFL[h-1] || insert_num != 1 || h != 1)
|
||||
die ("balance_internal: invalid child_pos");
|
||||
/* insert_child (tb->S[h], tb->S[h-1], child_pos, insert_num, B_N_ITEM_HEAD(tb->S[0],0), insert_ptr);*/
|
||||
internal_insert_childs (tb->tb_fs, &bi, child_pos, insert_num,
|
||||
B_N_PITEM_HEAD (PATH_PLAST_BUFFER (tb->tb_path), 0), insert_ptr);
|
||||
} else
|
||||
internal_insert_childs (tb->tb_fs, &bi, child_pos,insert_num,insert_key,insert_ptr);
|
||||
}
|
||||
|
||||
|
||||
memcpy (new_insert_key_addr,&new_insert_key,KEY_SIZE);
|
||||
insert_ptr[0] = new_insert_ptr;
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <asm/types.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -0,0 +1,711 @@
|
||||
/*
|
||||
* Copyright 2002 Hans Reiser
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
/* this provides for everybody who wants to deal with journal */
|
||||
int replay_one_transaction (reiserfs_filsys_t *, reiserfs_trans_t *);
|
||||
void for_each_transaction (reiserfs_filsys_t *, action_on_trans_t);
|
||||
void for_each_block (reiserfs_filsys_t *, reiserfs_trans_t *, action_on_block_t);
|
||||
int get_boundary_transactions (reiserfs_filsys_t *, reiserfs_trans_t *,
|
||||
reiserfs_trans_t *);
|
||||
int next_transaction (reiserfs_filsys_t *, reiserfs_trans_t *, reiserfs_trans_t);
|
||||
|
||||
/* compares description block with commit block. returns 0 if they differ, 1
|
||||
if they match */
|
||||
static int does_desc_match_commit (struct buffer_head *d_bh,
|
||||
struct buffer_head *c_bh)
|
||||
{
|
||||
return (get_commit_trans_id (c_bh) == get_desc_trans_id (d_bh) &&
|
||||
get_commit_trans_len (c_bh) == get_desc_trans_len (d_bh));
|
||||
}
|
||||
|
||||
|
||||
/* d_bh is descriptor, return number of block where commit block of this
|
||||
transaction is to be */
|
||||
unsigned long commit_expected (reiserfs_filsys_t * fs, struct buffer_head * d_bh)
|
||||
{
|
||||
unsigned long offset;
|
||||
struct journal_params * sb_jp;
|
||||
|
||||
|
||||
sb_jp = sb_jp (fs->fs_ondisk_sb);
|
||||
//desc = (struct reiserfs_journal_desc *)d_bh->b_data;
|
||||
offset = d_bh->b_blocknr - get_jp_journal_1st_block (sb_jp);
|
||||
return get_jp_journal_1st_block (sb_jp) +
|
||||
((offset + get_desc_trans_len (d_bh) + 1) % get_jp_journal_size (sb_jp));
|
||||
}
|
||||
|
||||
|
||||
/* d_bh contains journal descriptor, return number of block where descriptor
|
||||
block of next transaction should be */
|
||||
unsigned long next_desc_expected (reiserfs_filsys_t * fs, struct buffer_head * d_bh)
|
||||
{
|
||||
unsigned long offset;
|
||||
struct journal_params * sb_jp;
|
||||
|
||||
|
||||
sb_jp = sb_jp (fs->fs_ondisk_sb);
|
||||
//desc = (struct reiserfs_journal_desc *)d_bh->b_data;
|
||||
offset = d_bh->b_blocknr - get_jp_journal_1st_block (sb_jp);
|
||||
return get_jp_journal_1st_block (sb_jp) +
|
||||
((offset + get_desc_trans_len (d_bh) + 2) % get_jp_journal_size (sb_jp));
|
||||
}
|
||||
|
||||
|
||||
/**/
|
||||
int is_valid_transaction (reiserfs_filsys_t * fs, struct buffer_head * d_bh)
|
||||
{
|
||||
struct buffer_head * c_bh;
|
||||
|
||||
|
||||
if (!d_bh || who_is_this (d_bh->b_data, d_bh->b_size) != THE_JDESC)
|
||||
return 0;
|
||||
|
||||
/* read expected commit block and compare with descriptor block */
|
||||
c_bh = bread (fs->fs_journal_dev, commit_expected (fs, d_bh), fs->fs_blocksize);
|
||||
if (!c_bh)
|
||||
return 0;
|
||||
|
||||
if (does_desc_match_commit (d_bh, c_bh)) {
|
||||
brelse (c_bh);
|
||||
return 1;
|
||||
}
|
||||
brelse (c_bh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* read the journal and find the oldest and newest transactions, return numbe
|
||||
of transactions fond */
|
||||
int get_boundary_transactions (reiserfs_filsys_t * fs,
|
||||
reiserfs_trans_t * oldest,
|
||||
reiserfs_trans_t * newest)
|
||||
{
|
||||
struct reiserfs_super_block * sb;
|
||||
unsigned long j_cur;
|
||||
unsigned long j_start;
|
||||
unsigned long j_size;
|
||||
struct buffer_head * d_bh;
|
||||
__u32 newest_trans_id, oldest_trans_id, trans_id;
|
||||
int trans_nr;
|
||||
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
j_start = get_jp_journal_1st_block (sb_jp (sb));
|
||||
j_size = get_jp_journal_size (sb_jp (sb));
|
||||
|
||||
oldest_trans_id = 0xffffffff;
|
||||
newest_trans_id = 0;
|
||||
|
||||
trans_nr = 0;
|
||||
for (j_cur = 0; j_cur < j_size; j_cur ++) {
|
||||
d_bh = bread (fs->fs_journal_dev, j_start + j_cur, fs->fs_blocksize);
|
||||
if (!is_valid_transaction (fs, d_bh)) {
|
||||
brelse (d_bh);
|
||||
continue;
|
||||
}
|
||||
|
||||
trans_nr ++;
|
||||
|
||||
trans_id = get_desc_trans_id (d_bh);
|
||||
if (trans_id < oldest_trans_id) {
|
||||
oldest_trans_id = trans_id;
|
||||
|
||||
oldest->mount_id = get_desc_mount_id (d_bh);
|
||||
oldest->trans_id = get_desc_trans_id (d_bh);
|
||||
oldest->desc_blocknr = d_bh->b_blocknr;
|
||||
oldest->trans_len = get_desc_trans_len (d_bh);
|
||||
oldest->commit_blocknr = commit_expected (fs, d_bh);
|
||||
newest->next_trans_offset = next_desc_expected (fs, d_bh) - j_start;
|
||||
}
|
||||
|
||||
if (trans_id > newest_trans_id) {
|
||||
newest_trans_id = trans_id;
|
||||
|
||||
newest->mount_id = get_desc_mount_id (d_bh);
|
||||
newest->trans_id = get_desc_trans_id (d_bh);
|
||||
newest->desc_blocknr = d_bh->b_blocknr;
|
||||
newest->trans_len = get_desc_trans_len (d_bh);
|
||||
newest->commit_blocknr = commit_expected (fs, d_bh);
|
||||
newest->next_trans_offset = next_desc_expected (fs, d_bh) - j_start;
|
||||
}
|
||||
|
||||
j_cur += get_desc_trans_len (d_bh) + 1;
|
||||
brelse (d_bh);
|
||||
}
|
||||
|
||||
return trans_nr;
|
||||
}
|
||||
|
||||
#define TRANS_FOUND 1
|
||||
#define TRANS_LAST 2
|
||||
#define TRANS_NOT_FOUND 0
|
||||
|
||||
/* trans is a valid transaction. Look for valid transaction with smallest
|
||||
trans id which is bigger than the id of the current one */
|
||||
int next_transaction (reiserfs_filsys_t * fs, reiserfs_trans_t * trans, reiserfs_trans_t break_trans)
|
||||
{
|
||||
struct buffer_head * d_bh, * next_d_bh;
|
||||
int found;
|
||||
unsigned long j_start;
|
||||
unsigned long j_offset;
|
||||
unsigned long block;
|
||||
|
||||
|
||||
j_start = get_jp_journal_1st_block (sb_jp (fs->fs_ondisk_sb));
|
||||
|
||||
found = TRANS_NOT_FOUND;
|
||||
|
||||
/* make sure that 'trans' is a valid transaction */
|
||||
d_bh = bread (fs->fs_journal_dev, trans->desc_blocknr, fs->fs_blocksize);
|
||||
if (!is_valid_transaction (fs, d_bh))
|
||||
die ("next_transaction: valid transaction is expected");
|
||||
|
||||
block = next_desc_expected (fs, d_bh);
|
||||
j_offset = block - j_start;
|
||||
|
||||
while (1) {
|
||||
next_d_bh = bread (fs->fs_journal_dev, block, fs->fs_blocksize);
|
||||
if (is_valid_transaction (fs, next_d_bh))
|
||||
break;
|
||||
|
||||
brelse (next_d_bh);
|
||||
j_offset ++;
|
||||
block = j_start + (j_offset % get_jp_journal_size (sb_jp (fs->fs_ondisk_sb)));
|
||||
}
|
||||
|
||||
//next_desc = (struct reiserfs_journal_desc *)next_d_bh->b_data;
|
||||
|
||||
if (break_trans.trans_id >= get_desc_trans_id (next_d_bh)) {
|
||||
/* found transaction is newer */
|
||||
trans->mount_id = get_desc_mount_id (next_d_bh);
|
||||
trans->trans_id = get_desc_trans_id (next_d_bh);
|
||||
trans->desc_blocknr = next_d_bh->b_blocknr;
|
||||
trans->trans_len = get_desc_trans_len (next_d_bh);
|
||||
trans->commit_blocknr = commit_expected (fs, next_d_bh);
|
||||
trans->next_trans_offset = next_desc_expected (fs, next_d_bh) - j_start;
|
||||
found = TRANS_FOUND;
|
||||
if (break_trans.trans_id == get_desc_trans_id (next_d_bh))
|
||||
found = TRANS_LAST;
|
||||
}
|
||||
|
||||
brelse (d_bh);
|
||||
brelse (next_d_bh);
|
||||
return found;
|
||||
}
|
||||
|
||||
static void read_journal_write_in_place (reiserfs_filsys_t * fs, reiserfs_trans_t * trans, int index,
|
||||
unsigned long in_journal, unsigned long in_place)
|
||||
{
|
||||
struct buffer_head * j_bh, * bh;
|
||||
|
||||
j_bh = bread (fs->fs_journal_dev, in_journal, fs->fs_blocksize);
|
||||
if (!j_bh) {
|
||||
fprintf (stderr, "replay_one_transaction: transaction %lu: reading %lu block failed\n",
|
||||
trans->trans_id, in_journal);
|
||||
return;
|
||||
}
|
||||
if (not_journalable (fs, in_place)) {
|
||||
fprintf (stderr, "replay_one_transaction: transaction %lu: block %ld should not be journalled (%lu)\n",
|
||||
trans->trans_id, in_journal, in_place);
|
||||
brelse (j_bh);
|
||||
return;
|
||||
}
|
||||
|
||||
bh = getblk (fs->fs_dev, in_place, fs->fs_blocksize);
|
||||
|
||||
memcpy (bh->b_data, j_bh->b_data, bh->b_size);
|
||||
mark_buffer_dirty (bh);
|
||||
mark_buffer_uptodate (bh, 1);
|
||||
bwrite (bh);
|
||||
brelse (bh);
|
||||
brelse (j_bh);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* go through all blocks of transaction and call 'action' each of them */
|
||||
void for_each_block (reiserfs_filsys_t * fs, reiserfs_trans_t * trans,
|
||||
action_on_block_t action)
|
||||
{
|
||||
struct buffer_head * d_bh, * c_bh;
|
||||
struct reiserfs_journal_desc * desc;
|
||||
struct reiserfs_journal_commit * commit;
|
||||
unsigned long j_start, j_offset, j_size;
|
||||
int i;
|
||||
unsigned long block;
|
||||
int trans_half;
|
||||
|
||||
|
||||
d_bh = bread (fs->fs_journal_dev, trans->desc_blocknr, fs->fs_blocksize);
|
||||
if (!d_bh) {
|
||||
reiserfs_warning (stdout, "reading descriptor block %lu failed\n", trans->desc_blocknr);
|
||||
return;
|
||||
}
|
||||
|
||||
c_bh = bread (fs->fs_journal_dev, trans->commit_blocknr, fs->fs_blocksize);
|
||||
if (!c_bh) {
|
||||
reiserfs_warning (stdout, "reading commit block %lu failed\n", trans->commit_blocknr);
|
||||
brelse (d_bh);
|
||||
return;
|
||||
}
|
||||
|
||||
desc = (struct reiserfs_journal_desc *)(d_bh->b_data);
|
||||
commit = (struct reiserfs_journal_commit *)(c_bh->b_data);
|
||||
|
||||
/* first block of journal and size of journal */
|
||||
j_start = get_jp_journal_1st_block (sb_jp (fs->fs_ondisk_sb));
|
||||
j_size = get_jp_journal_size (sb_jp (fs->fs_ondisk_sb));
|
||||
|
||||
/* offset in the journal where the transaction starts */
|
||||
j_offset = trans->desc_blocknr - j_start + 1;
|
||||
|
||||
trans_half = journal_trans_half (d_bh->b_size);
|
||||
for (i = 0; i < trans->trans_len; i ++, j_offset ++) {
|
||||
if (i < trans_half)
|
||||
block = le32_to_cpu (desc->j2_realblock[i]);
|
||||
else
|
||||
block = le32_to_cpu (commit->j3_realblock[i - trans_half]);
|
||||
action (fs, trans, i, j_start + (j_offset % j_size), block);
|
||||
}
|
||||
|
||||
brelse (d_bh);
|
||||
brelse (c_bh);
|
||||
}
|
||||
|
||||
|
||||
/* transaction is supposed to be valid */
|
||||
int replay_one_transaction (reiserfs_filsys_t * fs,
|
||||
reiserfs_trans_t * trans)
|
||||
{
|
||||
for_each_block (fs, trans, read_journal_write_in_place);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void for_each_transaction (reiserfs_filsys_t * fs, action_on_trans_t action)
|
||||
{
|
||||
reiserfs_trans_t oldest, newest;
|
||||
int ret = 0;
|
||||
|
||||
if (!get_boundary_transactions (fs, &oldest, &newest))
|
||||
return;
|
||||
|
||||
while (1) {
|
||||
action (fs, &oldest);
|
||||
if ((ret == TRANS_LAST) || ((ret = next_transaction (fs, &oldest, newest)) == TRANS_NOT_FOUND) )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* user is allowed to specify journal size and ratio between journal size and
|
||||
max trans len. Max batch is calculated as 9/10 of max trans len. Max commit
|
||||
and trans ages are not tunable so far */
|
||||
static __u32 advise_journal_length (reiserfs_filsys_t * fs, __u32 desired)
|
||||
{
|
||||
if (!desired)
|
||||
return journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize);
|
||||
|
||||
if (desired < JOURNAL_MIN_SIZE + 1) {
|
||||
reiserfs_warning (stderr, "WARNING: Journal length is too small %u, resetting to minimal possible %u\n",
|
||||
desired, JOURNAL_MIN_SIZE + 1);
|
||||
return JOURNAL_MIN_SIZE;
|
||||
}
|
||||
|
||||
return desired;
|
||||
}
|
||||
|
||||
|
||||
unsigned long get_size_of_journal_or_reserved_area (struct reiserfs_super_block * sb)
|
||||
{
|
||||
if (is_reiserfs_jr_magic_string (sb))
|
||||
return get_sb_reserved_for_journal (sb);
|
||||
|
||||
/* with standard journal */
|
||||
return get_jp_journal_size (sb_jp (sb)) + 1;
|
||||
}
|
||||
|
||||
|
||||
__u32 advise_journal_max_trans_len (__u32 desired, __u32 journal_size, int blocksize)
|
||||
{
|
||||
__u32 saved;
|
||||
__u32 ratio = 1;
|
||||
|
||||
if (blocksize < 4096)
|
||||
ratio = 4096/blocksize;
|
||||
|
||||
saved = desired;
|
||||
if (!desired)
|
||||
desired = JOURNAL_TRANS_MAX/ratio;
|
||||
|
||||
if (journal_size / desired < JOURNAL_MIN_RATIO)
|
||||
desired = journal_size / JOURNAL_MIN_RATIO;
|
||||
|
||||
if (desired > JOURNAL_TRANS_MAX/ratio)
|
||||
desired = JOURNAL_TRANS_MAX/ratio;
|
||||
|
||||
if (desired < JOURNAL_TRANS_MIN/ratio)
|
||||
desired = JOURNAL_TRANS_MIN/ratio;
|
||||
|
||||
if (saved && saved != desired)
|
||||
reiserfs_warning (stderr,
|
||||
"WARNING: wrong transaction "
|
||||
"max size (%u). Changed to %u\n", saved, desired);
|
||||
return desired;
|
||||
}
|
||||
#if 0
|
||||
__u32 ret_val;
|
||||
ret_val = 0;
|
||||
if (!desired) ret_val = JOURNAL_TRANS_MAX;
|
||||
if (desired<journal_size/8) ret_val = journal_size/8;
|
||||
if (desired>journal_size/2) ret_val = journal_size/2;
|
||||
if (desired>JOURNAL_TRANS_MAX) ret_val = JOURNAL_TRANS_MAX;
|
||||
if (ret_val) {
|
||||
reiserfs_warning (stderr, "WARNING: Journal max trans length is wrong seting: %u, resetting to available possible %u\n",
|
||||
desired, ret_val);
|
||||
} else {
|
||||
ret_val = desired;
|
||||
}
|
||||
return ret_val;
|
||||
}
|
||||
#endif
|
||||
|
||||
__u32 advise_journal_max_batch (unsigned long journal_trans_max)
|
||||
{
|
||||
return journal_trans_max*JOURNAL_MAX_BATCH/JOURNAL_TRANS_MAX;
|
||||
}
|
||||
|
||||
|
||||
__u32 advise_journal_max_commit_age (void)
|
||||
{
|
||||
return JOURNAL_MAX_COMMIT_AGE;
|
||||
}
|
||||
|
||||
|
||||
__u32 advise_journal_max_trans_age (void)
|
||||
{
|
||||
return JOURNAL_MAX_TRANS_AGE;
|
||||
}
|
||||
|
||||
|
||||
/* read journal header and make sure that it matches with the filesystem
|
||||
opened */
|
||||
int reiserfs_open_journal (reiserfs_filsys_t * fs, char * j_filename, int flags)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
struct reiserfs_journal_header * j_head;
|
||||
struct reiserfs_super_block * sb;
|
||||
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
if (!j_filename) {
|
||||
if (is_reiserfs_jr_magic_string (sb)) {
|
||||
/* create a special file to access journal */
|
||||
return 0;
|
||||
}
|
||||
|
||||
j_filename = fs->fs_file_name;
|
||||
} else if (!is_reiserfs_jr_magic_string (sb)) {
|
||||
/* make sure that name specified is a correct name */
|
||||
if (strcmp (j_filename, fs->fs_file_name)) {
|
||||
reiserfs_warning (stderr, "Filesystem with standard journal found, "
|
||||
"wrong name of specified journal device %s \n", j_filename);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fs->fs_journal_dev = open (j_filename, flags | O_LARGEFILE);
|
||||
if (fs->fs_journal_dev == -1)
|
||||
return 0;
|
||||
|
||||
asprintf (&fs->fs_j_file_name, "%s", j_filename);
|
||||
|
||||
/* read journal header */
|
||||
bh = bread (fs->fs_journal_dev, get_jp_journal_1st_block (sb_jp (sb)) +
|
||||
get_jp_journal_size (sb_jp (sb)), fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "reiserfs_open_journal: bread failed reading "
|
||||
"journal header\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
j_head = (struct reiserfs_journal_header *)(bh->b_data);
|
||||
|
||||
if (is_reiserfs_jr_magic_string (sb)) {
|
||||
if (get_jp_journal_1st_block (&j_head->jh_journal) != get_jp_journal_1st_block (sb_jp (sb)) ||
|
||||
get_jp_journal_dev (&j_head->jh_journal) != get_jp_journal_dev (sb_jp (sb)) ||
|
||||
get_jp_journal_size (&j_head->jh_journal) != get_jp_journal_size (sb_jp (sb))) {
|
||||
reiserfs_warning (stderr, "reiserfs_open_journal: no journal found on %s\n", j_filename);
|
||||
brelse (bh);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fs->fs_jh_bh = bh;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* initialize super block's journal related fields and journal header fields. If
|
||||
len is 0 - make journal of default size */
|
||||
int reiserfs_create_journal (reiserfs_filsys_t * fs, char * j_filename,
|
||||
unsigned long offset,
|
||||
unsigned long len, /* journal size including journal header */
|
||||
int transaction_max_size)
|
||||
{
|
||||
struct stat st;
|
||||
struct buffer_head * bh;
|
||||
struct reiserfs_journal_header * jh;
|
||||
struct reiserfs_super_block * sb;
|
||||
unsigned long blocks;
|
||||
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
|
||||
if (!j_filename || !strcmp (j_filename, fs->fs_file_name)) {
|
||||
/* journal is to be on a host device, make sure that there is enough
|
||||
space for it */
|
||||
if (!len)
|
||||
len = journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize) + 1;
|
||||
|
||||
if (!is_block_count_correct (
|
||||
fs->fs_super_bh->b_blocknr, fs->fs_blocksize, get_sb_block_count (sb), len - 1)) {
|
||||
// if (get_sb_block_count (sb) < min_block_amount (fs->fs_blocksize, len)) {
|
||||
/* host device does not contain enough blocks */
|
||||
reiserfs_warning (stderr, "reiserfs_create_journal: "
|
||||
"can not create filesystem on %d blocks\n",
|
||||
get_sb_block_count (sb));
|
||||
return 0;
|
||||
}
|
||||
|
||||
j_filename = fs->fs_file_name;
|
||||
|
||||
/* journal is not on a separate device starts after super block and first
|
||||
bitmap. offset is ignored */
|
||||
offset = get_journal_start_must (fs);
|
||||
st.st_rdev = 0;
|
||||
} else {
|
||||
/* journal is to be on separate device */
|
||||
blocks = count_blocks (j_filename, fs->fs_blocksize);
|
||||
if (!len) {
|
||||
/* default size of a journal on a separate device is whole device */
|
||||
if (blocks < offset) {
|
||||
reiserfs_warning (stderr,
|
||||
"reiserfs_create_journal: "
|
||||
"offset is %lu, blocks on device %lu\n",
|
||||
offset, blocks);
|
||||
return 0;
|
||||
}
|
||||
len = blocks - offset;
|
||||
}
|
||||
|
||||
if (len > journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize) + 1)
|
||||
reiserfs_warning (stderr,
|
||||
"NOTE: journal new size %lu is bigger than default size %lu:\n"
|
||||
"this may slow down journal initializing and mounting. Hope it is ok.\n\n",
|
||||
len, journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize) + 1);
|
||||
|
||||
if (blocks < offset + len) {
|
||||
reiserfs_warning (stderr,
|
||||
"reiserfs_create_journal: "
|
||||
"no enough blocks on device %lu, needed %lu\n",
|
||||
blocks, offset + len);
|
||||
return 0;
|
||||
}
|
||||
if (stat (j_filename, &st) == -1) {
|
||||
reiserfs_warning (stderr, "reiserfs_create_journal: "
|
||||
"stat %s failed: %m\n", j_filename);
|
||||
return 0;
|
||||
}
|
||||
if (!S_ISBLK (st.st_mode)) {
|
||||
reiserfs_warning (stderr, "reiserfs_create_journal: "
|
||||
"%s is not a block device (%x)\n", j_filename, st.st_rdev);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fs->fs_journal_dev = open (j_filename, O_RDWR | O_LARGEFILE);
|
||||
if (fs->fs_journal_dev == -1) {
|
||||
reiserfs_warning (stderr, "reiserfs_create_journal: could not open %s: %m\n",
|
||||
j_filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
asprintf (&fs->fs_j_file_name, "%s", j_filename);
|
||||
|
||||
len = advise_journal_length (fs, len - 1) + 1;
|
||||
|
||||
/* get journal header */
|
||||
bh = getblk (fs->fs_journal_dev, offset + len - 1, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "reiserfs_create_journal: "
|
||||
"getblk failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* fill journal header */
|
||||
jh = (struct reiserfs_journal_header *)bh->b_data;
|
||||
set_jp_journal_1st_block (&jh->jh_journal, offset);
|
||||
set_jp_journal_dev (&jh->jh_journal, st.st_rdev);
|
||||
set_jp_journal_magic (&jh->jh_journal, get_random ());
|
||||
|
||||
set_jp_journal_size (&jh->jh_journal, len - 1);
|
||||
set_jp_journal_max_trans_len (&jh->jh_journal,
|
||||
advise_journal_max_trans_len(transaction_max_size, len - 1, fs->fs_blocksize));
|
||||
set_jp_journal_max_batch (&jh->jh_journal,
|
||||
advise_journal_max_batch (get_jp_journal_max_trans_len (&jh->jh_journal) ));
|
||||
set_jp_journal_max_commit_age (&jh->jh_journal, advise_journal_max_commit_age ());
|
||||
set_jp_journal_max_trans_age (&jh->jh_journal, advise_journal_max_trans_age ());
|
||||
|
||||
mark_buffer_uptodate (bh, 1);
|
||||
mark_buffer_dirty (bh);
|
||||
|
||||
fs->fs_jh_bh = bh;
|
||||
|
||||
/* make a copy of journal header in the super block */
|
||||
memcpy (sb_jp (sb), &jh->jh_journal, sizeof (struct journal_params));
|
||||
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* brelse journal header, flush all dirty buffers, close device, open, read
|
||||
journal header */
|
||||
void reiserfs_reopen_journal (reiserfs_filsys_t * fs, int flag)
|
||||
{
|
||||
unsigned long jh_block;
|
||||
|
||||
|
||||
if (!reiserfs_journal_opened (fs))
|
||||
return;
|
||||
|
||||
jh_block = fs->fs_jh_bh->b_blocknr;
|
||||
brelse (fs->fs_jh_bh);
|
||||
flush_buffers (fs->fs_journal_dev);
|
||||
invalidate_buffers (fs->fs_journal_dev);
|
||||
if (close (fs->fs_journal_dev))
|
||||
die ("reiserfs_reopen_journal: closed failed: %m");
|
||||
|
||||
fs->fs_journal_dev = open (fs->fs_j_file_name, flag | O_LARGEFILE);
|
||||
if (fs->fs_journal_dev == -1)
|
||||
die ("reiserfs_reopen_journal: could not reopen journal device");
|
||||
|
||||
fs->fs_jh_bh = bread (fs->fs_journal_dev, jh_block, fs->fs_blocksize);
|
||||
if (!fs->fs_jh_bh)
|
||||
die ("reiserfs_reopen_journal: reading journal header failed");
|
||||
}
|
||||
|
||||
|
||||
int reiserfs_journal_opened (reiserfs_filsys_t * fs)
|
||||
{
|
||||
return fs->fs_jh_bh ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_flush_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (!reiserfs_journal_opened (fs))
|
||||
return;
|
||||
flush_buffers (fs->fs_journal_dev);
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_free_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (!reiserfs_journal_opened (fs))
|
||||
return;
|
||||
brelse (fs->fs_jh_bh);
|
||||
fs->fs_jh_bh = 0;
|
||||
free (fs->fs_j_file_name);
|
||||
fs->fs_j_file_name = 0;
|
||||
}
|
||||
|
||||
|
||||
void reiserfs_close_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
reiserfs_flush_journal (fs);
|
||||
reiserfs_free_journal (fs);
|
||||
|
||||
}
|
||||
|
||||
/* update journal header */
|
||||
static void update_journal_header (struct buffer_head * bh_jh, reiserfs_trans_t trans) {
|
||||
struct reiserfs_journal_header * j_head;
|
||||
|
||||
j_head = (struct reiserfs_journal_header *)(bh_jh->b_data);
|
||||
|
||||
/* update journal header */
|
||||
set_jh_last_flushed (j_head, trans.trans_id);
|
||||
set_jh_mount_id (j_head, trans.mount_id);
|
||||
set_jh_replay_start_offset (j_head, trans.next_trans_offset);
|
||||
mark_buffer_dirty (bh_jh);
|
||||
bwrite (bh_jh);
|
||||
}
|
||||
|
||||
/* fixme: what should be done when not all transactions can be replayed in proper order? */
|
||||
int replay_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
struct reiserfs_journal_header * j_head;
|
||||
reiserfs_trans_t cur, newest, control;
|
||||
int replayed, ret = 0;
|
||||
|
||||
if (!reiserfs_journal_opened (fs))
|
||||
reiserfs_panic ("replay_journal: journal is not opened");
|
||||
|
||||
if (!is_opened_rw (fs))
|
||||
reiserfs_panic ("replay_journal: fs is not opened with write perms");
|
||||
|
||||
reiserfs_warning (stderr, "Replaying journal..\n");
|
||||
bh = fs->fs_jh_bh;
|
||||
|
||||
j_head = (struct reiserfs_journal_header *)(bh->b_data);
|
||||
control.mount_id = get_jh_mount_id (j_head);
|
||||
control.trans_id = get_jh_last_flushed (j_head);
|
||||
control.desc_blocknr = get_jh_replay_start_offset (j_head);
|
||||
|
||||
if (!get_boundary_transactions (fs, &cur, &newest)) {
|
||||
reiserfs_warning (stderr, "No transactions found\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (control.mount_id != newest.mount_id) {
|
||||
reiserfs_warning (stderr, "Journal header's mountid: %lu\n"
|
||||
"latest transaction found is of mountid %lu\n", control.mount_id, newest.mount_id);
|
||||
if (user_confirmed (stderr, "Should those transactions be replayed?(Y/n)[n]", "Y\n")) {
|
||||
control.mount_id = newest.mount_id;
|
||||
// control.trans_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
replayed = 0;
|
||||
while (1) {
|
||||
if (cur.mount_id == control.mount_id && cur.trans_id > control.trans_id) {
|
||||
reiserfs_warning (stderr, "trans replayed: mountid %lu, transid %lu, desc %lu, "
|
||||
"len %lu, commit %lu, next trans offset %lu\n",
|
||||
cur.mount_id, cur.trans_id, cur.desc_blocknr, cur.trans_len,
|
||||
cur.commit_blocknr, cur.next_trans_offset);
|
||||
replay_one_transaction (fs, &cur);
|
||||
update_journal_header (bh, cur);
|
||||
replayed ++;
|
||||
}
|
||||
if ((ret == TRANS_LAST) || ((ret = next_transaction (fs, &cur, newest)) == TRANS_NOT_FOUND) )
|
||||
break;
|
||||
}
|
||||
reiserfs_warning (stderr, "%d transactions replayed\n", replayed);
|
||||
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
bwrite (fs->fs_super_bh);
|
||||
|
||||
update_journal_header (bh, newest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+173
-422
File diff suppressed because it is too large.
Load diff
+716
-248
File diff suppressed because it is too large.
Load diff
+310
-256
@@ -37,7 +37,7 @@ static int _arginfo2 (const struct printf_info *info, size_t n,
|
||||
return len;\
|
||||
|
||||
|
||||
/* %z */
|
||||
/* %b */
|
||||
static int print_block_head (FILE * stream,
|
||||
const struct printf_info *info,
|
||||
const void *const *args)
|
||||
@@ -48,7 +48,7 @@ static int print_block_head (FILE * stream,
|
||||
|
||||
bh = *((const struct buffer_head **)(args[0]));
|
||||
len = asprintf (&buffer, "level=%d, nr_items=%d, free_space=%d rdkey",
|
||||
B_LEVEL (bh), B_NR_ITEMS (bh), node_free_space (bh));
|
||||
B_LEVEL (bh), B_NR_ITEMS (bh), B_FREE_SPACE (bh));
|
||||
FPRINTF;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ static int print_short_key (FILE * stream,
|
||||
int len;
|
||||
|
||||
key = *((const struct key **)(args[0]));
|
||||
len = asprintf (&buffer, "%u %u", key->k_dir_id, key->k_objectid);
|
||||
len = asprintf (&buffer, "%u %u", get_key_dirid (key),
|
||||
get_key_objectid (key));
|
||||
FPRINTF;
|
||||
}
|
||||
|
||||
@@ -78,8 +79,9 @@ static int print_key (FILE * stream,
|
||||
int len;
|
||||
|
||||
key = *((const struct key **)(args[0]));
|
||||
len = asprintf (&buffer, "%u %u 0x%Lx %s",
|
||||
key->k_dir_id, key->k_objectid, get_offset (key), key_of_what (key));
|
||||
len = asprintf (&buffer, "%u %u 0x%Lx %s (%d)",
|
||||
get_key_dirid (key), get_key_objectid (key),
|
||||
(unsigned long long)get_offset (key), key_of_what (key), get_type (key));
|
||||
FPRINTF;
|
||||
}
|
||||
|
||||
@@ -94,14 +96,14 @@ static int print_item_head (FILE * stream,
|
||||
int len;
|
||||
|
||||
ih = *((const struct item_head **)(args[0]));
|
||||
len = asprintf (&buffer, "%u %u 0x%Lx %s, "
|
||||
"len %u, entry count %u, fsck need %u, format %s",
|
||||
ih->ih_key.k_dir_id, ih->ih_key.k_objectid,
|
||||
get_offset (&ih->ih_key), key_of_what (&ih->ih_key),
|
||||
ih->ih_item_len, ih_entry_count (ih),
|
||||
ih->ih_format.fsck_need,
|
||||
ih_key_format (ih) == KEY_FORMAT_2 ? "new" :
|
||||
((ih_key_format (ih) == KEY_FORMAT_1) ? "old" : "BAD"));
|
||||
len = asprintf (&buffer, "%u %u 0x%Lx %s (%d), "
|
||||
"len %u, location %u entry count %u, fsck need %u, format %s",
|
||||
get_key_dirid (&ih->ih_key), get_key_objectid (&ih->ih_key),
|
||||
(unsigned long long)get_offset (&ih->ih_key), key_of_what (&ih->ih_key),
|
||||
get_type (&ih->ih_key), get_ih_item_len (ih), get_ih_location (ih),
|
||||
get_ih_entry_count (ih), get_ih_flags (ih),
|
||||
get_ih_key_format (ih) == KEY_FORMAT_2 ? "new" :
|
||||
((get_ih_key_format (ih) == KEY_FORMAT_1) ? "old" : "BAD"));
|
||||
FPRINTF;
|
||||
}
|
||||
|
||||
@@ -115,8 +117,8 @@ static int print_disk_child (FILE * stream,
|
||||
int len;
|
||||
|
||||
dc = *((const struct disk_child **)(args[0]));
|
||||
len = asprintf (&buffer, "[dc_number=%u, dc_size=%u]", le32_to_cpu (dc->dc_block_number),
|
||||
le16_to_cpu (dc->dc_size));
|
||||
len = asprintf (&buffer, "[dc_number=%u, dc_size=%u]", get_dc_child_blocknr (dc),
|
||||
get_dc_child_size (dc));
|
||||
FPRINTF;
|
||||
}
|
||||
|
||||
@@ -156,7 +158,7 @@ static int print_sd_mode (FILE * stream,
|
||||
const void *const *args)
|
||||
{
|
||||
int len = 0;
|
||||
mode_t mode;
|
||||
__u16 mode;
|
||||
|
||||
mode = *(mode_t *)args[0];
|
||||
len = fprintf (stream, "%c", ftypelet (mode));
|
||||
@@ -166,7 +168,23 @@ static int print_sd_mode (FILE * stream,
|
||||
return len;
|
||||
}
|
||||
|
||||
/* %U */
|
||||
static int print_sd_uuid (FILE * stream,
|
||||
const struct printf_info *info,
|
||||
const void *const *args)
|
||||
{
|
||||
int i;
|
||||
const unsigned char * uuid;
|
||||
int len = 0;
|
||||
|
||||
uuid = *((const unsigned char **)(args[0]));
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (i == 4 || i == 6 || i == 8 || i == 10)
|
||||
len += fprintf (stream, "-");
|
||||
len += fprintf(stream, "%02x", uuid[i]);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
void reiserfs_warning (FILE * fp, const char * fmt, ...)
|
||||
{
|
||||
@@ -182,6 +200,7 @@ void reiserfs_warning (FILE * fp, const char * fmt, ...)
|
||||
register_printf_function ('b', print_block_head, _arginfo);
|
||||
register_printf_function ('y', print_disk_child, _arginfo);
|
||||
register_printf_function ('M', print_sd_mode, _arginfo);
|
||||
register_printf_function ('U', print_sd_uuid, _arginfo);
|
||||
}
|
||||
|
||||
va_start (args, fmt);
|
||||
@@ -249,35 +268,8 @@ void print_path (struct tree_balance * tb, struct path * path)
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
void print_de (struct reiserfs_dir_entry * de)
|
||||
{
|
||||
reiserfs_warning ("entry key: [%k], object_key: [%u %u], b_blocknr=%lu, item_num=%d, pos_in_item=%d\n",
|
||||
&de->de_entry_key, de->de_dir_id, de->de_objectid,
|
||||
de->de_bh->b_blocknr, de->de_item_num, de->de_entry_num);
|
||||
}
|
||||
|
||||
static char * item_type (struct item_head * ih)
|
||||
{
|
||||
static char * types[] = {
|
||||
"SD", "DIR", "DRCT", "IND", "???"
|
||||
};
|
||||
|
||||
if (I_IS_STAT_DATA_ITEM(ih))
|
||||
return types[0];
|
||||
if (I_IS_DIRECTORY_ITEM(ih))
|
||||
return types[1];
|
||||
if (I_IS_DIRECT_ITEM(ih))
|
||||
return types[2];
|
||||
if (I_IS_INDIRECT_ITEM(ih))
|
||||
return types[3];
|
||||
return types[4];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void print_directory_item (FILE * fp, reiserfs_filsys_t fs,
|
||||
void print_directory_item (FILE * fp, reiserfs_filsys_t * fs,
|
||||
struct buffer_head * bh, struct item_head * ih)
|
||||
{
|
||||
int i;
|
||||
@@ -292,10 +284,10 @@ void print_directory_item (FILE * fp, reiserfs_filsys_t fs,
|
||||
//printk ("\n%2%-25s%-30s%-15s%-15s%-15s\n", " Name", "length", "Object key", "Hash", "Gen number", "Status");
|
||||
reiserfs_warning (fp, "%3s: %-25s%s%-22s%-12s%s\n", "###", "Name", "length", " Object key", " Hash", "Gen number");
|
||||
deh = B_I_DEH (bh, ih);
|
||||
for (i = 0; i < ih_entry_count (ih); i ++, deh ++) {
|
||||
for (i = 0; i < get_ih_entry_count (ih); i ++, deh ++) {
|
||||
if (dir_entry_bad_location (deh, ih, i == 0 ? 1 : 0)) {
|
||||
reiserfs_warning (fp, "%3d: wrong entry location %u, deh_offset %u\n",
|
||||
i, deh_location (deh), deh_offset (deh));
|
||||
i, get_deh_location (deh), get_deh_offset (deh));
|
||||
continue;
|
||||
}
|
||||
if (i && dir_entry_bad_location (deh - 1, ih, ((i - 1) == 0) ? 1 : 0))
|
||||
@@ -303,15 +295,19 @@ void print_directory_item (FILE * fp, reiserfs_filsys_t fs,
|
||||
length */
|
||||
namelen = 25;
|
||||
else
|
||||
namelen = name_length (ih, deh, i);
|
||||
namelen = name_in_entry_length (ih, deh, i);
|
||||
|
||||
name = name_in_entry (deh, i);
|
||||
reiserfs_warning (fp, "%3d: \"%-25.*s\"(%3d)%20K%12d%5d, loc %u, state %x %s\n",
|
||||
i, namelen, name, namelen,
|
||||
(struct key *)&(deh->deh_dir_id),
|
||||
GET_HASH_VALUE (deh->deh_offset), GET_GENERATION_NUMBER (deh->deh_offset),
|
||||
deh_location (deh), deh->deh_state,
|
||||
fs ? (is_properly_hashed (fs, name, namelen, deh_offset (deh)) ? "" : "(BROKEN)") : "??");
|
||||
(struct key *)&(deh->deh2_dir_id),
|
||||
GET_HASH_VALUE (get_deh_offset (deh)),
|
||||
GET_GENERATION_NUMBER (get_deh_offset (deh)),
|
||||
get_deh_location (deh), get_deh_state (deh),
|
||||
code2name (find_hash_in_use (name, namelen,
|
||||
GET_HASH_VALUE (get_deh_offset (deh)),
|
||||
fs ? get_sb_hash_code (fs->fs_ondisk_sb) : UNSET_HASH)));
|
||||
/*fs ? (is_properly_hashed (fs, name, namelen, deh_offset (deh)) ? "" : "(BROKEN)") : "??");*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,14 +324,14 @@ static void start_new_sequence (__u32 * start, int * len, __u32 new)
|
||||
|
||||
static int sequence_finished (__u32 start, int * len, __u32 new)
|
||||
{
|
||||
if (start == INT_MAX)
|
||||
if (le32_to_cpu (start) == INT_MAX)
|
||||
return 1;
|
||||
|
||||
if (start == 0 && new == 0) {
|
||||
(*len) ++;
|
||||
return 0;
|
||||
}
|
||||
if (start != 0 && (start + *len) == new) {
|
||||
if (start != 0 && (le32_to_cpu (start) + *len) == le32_to_cpu (new)) {
|
||||
(*len) ++;
|
||||
return 0;
|
||||
}
|
||||
@@ -348,9 +344,9 @@ static void print_sequence (FILE * fp, __u32 start, int len)
|
||||
return;
|
||||
|
||||
if (len == 1)
|
||||
reiserfs_warning (fp, " %d", start);
|
||||
reiserfs_warning (fp, " %d", le32_to_cpu (start));
|
||||
else
|
||||
reiserfs_warning (fp, " %d(%d)", start, len);
|
||||
reiserfs_warning (fp, " %d(%d)", le32_to_cpu (start), len);
|
||||
}
|
||||
|
||||
|
||||
@@ -364,10 +360,11 @@ void print_indirect_item (FILE * fp, struct buffer_head * bh, int item_num)
|
||||
ih = B_N_PITEM_HEAD (bh, item_num);
|
||||
unp = (__u32 *)B_I_PITEM (bh, ih);
|
||||
|
||||
if (ih->ih_item_len % UNFM_P_SIZE)
|
||||
if (get_ih_item_len (ih) % UNFM_P_SIZE)
|
||||
reiserfs_warning (fp, "print_indirect_item: invalid item len");
|
||||
|
||||
reiserfs_warning (fp, "%d pointers\n[ ", I_UNFM_NUM (ih));
|
||||
reiserfs_warning (fp, "%d pointer%s\n[", I_UNFM_NUM (ih),
|
||||
I_UNFM_NUM (ih) != 1 ? "s" : "" );
|
||||
for (j = 0; j < I_UNFM_NUM (ih); j ++) {
|
||||
if (sequence_finished (prev, &num, unp[j])) {
|
||||
print_sequence (fp, prev, num);
|
||||
@@ -389,32 +386,61 @@ char * timestamp (time_t t)
|
||||
|
||||
static int print_stat_data (FILE * fp, struct buffer_head * bh, struct item_head * ih, int alltimes)
|
||||
{
|
||||
struct stat_data * sd = (struct stat_data *)B_I_PITEM (bh, ih);
|
||||
struct stat_data_v1 * sd_v1 = (struct stat_data_v1 *)B_I_PITEM (bh, ih);
|
||||
int retval;
|
||||
|
||||
|
||||
/* we can not figure out whether it is new stat data or old by key_format
|
||||
macro. Stat data's key looks identical in both formats */
|
||||
if (ih_key_format (ih) == KEY_FORMAT_1) {
|
||||
reiserfs_warning (fp, "(OLD SD), mode %M, size %u, nlink %u, uid %d, FDB %d, mtime %s blocks %d",
|
||||
sd_v1->sd_mode, sd_v1->sd_size, sd_v1->sd_nlink, sd_v1->sd_uid,
|
||||
sd_v1->sd_first_direct_byte, timestamp (sd_v1->sd_mtime), sd_v1->u.sd_blocks);
|
||||
retval = (S_ISLNK (sd_v1->sd_mode)) ? 1 : 0;
|
||||
if (get_ih_key_format (ih) == KEY_FORMAT_1) {
|
||||
struct stat_data_v1 * sd_v1 = (struct stat_data_v1 *)B_I_PITEM (bh, ih);
|
||||
reiserfs_warning (fp, "(OLD SD), mode %M, size %u, nlink %u, uid %u, FDB %u, mtime %s blocks %u",
|
||||
sd_v1_mode(sd_v1), sd_v1_size(sd_v1), sd_v1_nlink(sd_v1),
|
||||
sd_v1_uid(sd_v1), sd_v1_first_direct_byte(sd_v1), timestamp
|
||||
(sd_v1_mtime(sd_v1)), sd_v1_blocks(sd_v1));
|
||||
retval = (S_ISLNK (sd_v1_mode(sd_v1))) ? 1 : 0;
|
||||
if (alltimes)
|
||||
reiserfs_warning (fp, "%s %s\n", timestamp (sd_v1_ctime(sd_v1)),
|
||||
timestamp (sd_v1_atime(sd_v1)));
|
||||
} else {
|
||||
reiserfs_warning (fp, "(NEW SD), mode %M, size %Lu, nlink %u, mtime %s blocks %d",
|
||||
sd->sd_mode, sd->sd_size, sd->sd_nlink,
|
||||
timestamp (sd->sd_mtime), sd->sd_blocks);
|
||||
retval = (S_ISLNK (sd->sd_mode)) ? 1 : 0;
|
||||
struct stat_data * sd = (struct stat_data *)B_I_PITEM (bh, ih);
|
||||
reiserfs_warning (fp, "(NEW SD), mode %M, size %Lu, nlink %u, mtime %s blocks %u, uid %u",
|
||||
sd_v2_mode(sd), sd_v2_size(sd), sd_v2_nlink(sd),
|
||||
timestamp (sd_v2_mtime(sd)), sd_v2_blocks(sd), sd_v2_uid(sd));
|
||||
retval = (S_ISLNK (sd_v2_mode(sd))) ? 1 : 0;
|
||||
if (alltimes)
|
||||
reiserfs_warning (fp, "%s %s\n", timestamp (sd_v2_ctime(sd)),
|
||||
timestamp (sd_v2_atime(sd)));
|
||||
}
|
||||
|
||||
if (alltimes)
|
||||
reiserfs_warning (fp, "%s %s\n", timestamp (sd->sd_ctime), timestamp (sd->sd_atime));
|
||||
reiserfs_warning (fp, "\n");
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/* used by debugreiserfs/scan.c */
|
||||
void reiserfs_print_item (FILE * fp, struct buffer_head * bh,
|
||||
struct item_head * ih)
|
||||
{
|
||||
reiserfs_warning (stdout, "block %lu, item %d: %H\n",
|
||||
bh->b_blocknr, ih - B_N_PITEM_HEAD (bh, 0), ih);
|
||||
if (is_stat_data_ih (ih)) {
|
||||
print_stat_data (fp, bh, ih, 0/*all times*/);
|
||||
return;
|
||||
}
|
||||
if (is_indirect_ih (ih)) {
|
||||
print_indirect_item (fp, bh, ih - B_N_PITEM_HEAD (bh, 0));
|
||||
return;
|
||||
}
|
||||
if (is_direct_ih (ih)) {
|
||||
reiserfs_warning (fp, "direct item: block %lu, start %d, %d bytes\n",
|
||||
bh->b_blocknr, get_ih_location (ih), get_ih_item_len (ih));
|
||||
return;
|
||||
}
|
||||
|
||||
print_directory_item (fp, 0, bh, ih);
|
||||
}
|
||||
|
||||
|
||||
/* this prints internal nodes (4 keys/items in line) (dc_number,
|
||||
dc_size)[k_dirid, k_objectid, k_offset, k_uniqueness](dc_number,
|
||||
dc_size)...*/
|
||||
@@ -453,36 +479,41 @@ static int print_internal (FILE * fp, struct buffer_head * bh, int first, int la
|
||||
|
||||
|
||||
static int is_symlink = 0;
|
||||
static int print_leaf (FILE * fp, reiserfs_filsys_t fs, struct buffer_head * bh,
|
||||
static int print_leaf (FILE * fp, reiserfs_filsys_t * fs, struct buffer_head * bh,
|
||||
int print_mode, int first, int last)
|
||||
{
|
||||
struct block_head * blkh;
|
||||
struct item_head * ih;
|
||||
int i;
|
||||
int from, to;
|
||||
int nr;
|
||||
|
||||
if (!is_leaf_node (bh))
|
||||
if (!is_tree_node (bh, DISK_LEAF_NODE_LEVEL))
|
||||
return 1;
|
||||
|
||||
|
||||
blkh = B_BLK_HEAD (bh);
|
||||
ih = B_N_PITEM_HEAD (bh,0);
|
||||
nr = get_blkh_nr_items (blkh);
|
||||
|
||||
reiserfs_warning (fp, "\n===================================================================\n");
|
||||
reiserfs_warning (fp, "LEAF NODE (%ld) contains %b\n", bh->b_blocknr, bh);
|
||||
reiserfs_warning (fp,
|
||||
"\n===================================================================\n");
|
||||
reiserfs_warning (fp, "LEAF NODE (%ld) contains %b (real items %d)\n",
|
||||
bh->b_blocknr, bh, nr);
|
||||
|
||||
if (!(print_mode & PRINT_LEAF_ITEMS)) {
|
||||
if (!(print_mode & PRINT_TREE_DETAILS)) {
|
||||
reiserfs_warning (fp, "FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n",
|
||||
&(ih->ih_key), &((ih + blkh->blk_nr_item - 1)->ih_key));
|
||||
&(ih->ih_key), &((ih + get_blkh_nr_items (blkh) - 1)->ih_key));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (first < 0 || first > blkh->blk_nr_item - 1)
|
||||
if (first < 0 || first > nr - 1)
|
||||
from = 0;
|
||||
else
|
||||
from = first;
|
||||
|
||||
if (last < 0 || last > blkh->blk_nr_item)
|
||||
to = blkh->blk_nr_item;
|
||||
if (last < 0 || last > nr)
|
||||
to = nr;
|
||||
else
|
||||
to = last;
|
||||
|
||||
@@ -493,20 +524,20 @@ static int print_leaf (FILE * fp, reiserfs_filsys_t fs, struct buffer_head * bh,
|
||||
"| | | |e/cn| | |need| |\n");
|
||||
for (i = from; i < to; i++) {
|
||||
reiserfs_warning (fp,
|
||||
"-------------------------------------------------------------------------------\n"
|
||||
"-------------------------------------------------------------------------------\n"
|
||||
"|%3d|%30H|\n", i, ih + i);
|
||||
|
||||
if (I_IS_STAT_DATA_ITEM(ih+i) && print_mode & PRINT_ITEM_DETAILS) {
|
||||
if (I_IS_STAT_DATA_ITEM(ih+i)) {
|
||||
is_symlink = print_stat_data (fp, bh, ih + i, 0/*all times*/);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (I_IS_DIRECTORY_ITEM(ih+i) && print_mode & PRINT_ITEM_DETAILS) {
|
||||
if (I_IS_DIRECTORY_ITEM(ih+i)) {
|
||||
print_directory_item (fp, fs, bh, ih+i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (I_IS_INDIRECT_ITEM(ih+i) && print_mode & PRINT_ITEM_DETAILS) {
|
||||
if (I_IS_INDIRECT_ITEM(ih+i)) {
|
||||
print_indirect_item (fp, bh, i);
|
||||
continue;
|
||||
}
|
||||
@@ -515,7 +546,7 @@ static int print_leaf (FILE * fp, reiserfs_filsys_t fs, struct buffer_head * bh,
|
||||
int j = 0;
|
||||
if (is_symlink || print_mode & PRINT_DIRECT_ITEMS) {
|
||||
reiserfs_warning (fp, "\"");
|
||||
while (j < ih[i].ih_item_len) {
|
||||
while (j < get_ih_item_len (&ih[i])) {
|
||||
if (B_I_PITEM(bh,ih+i)[j] == 10)
|
||||
reiserfs_warning (fp, "\\n");
|
||||
else
|
||||
@@ -532,83 +563,120 @@ static int print_leaf (FILE * fp, reiserfs_filsys_t fs, struct buffer_head * bh,
|
||||
}
|
||||
|
||||
|
||||
void print_journal_params (FILE * fp, struct journal_params * jp)
|
||||
{
|
||||
reiserfs_warning (fp, "\tDevice [0x%x]\n", get_jp_journal_dev (jp));
|
||||
reiserfs_warning (fp, "\tMagic [0x%x]\n", get_jp_journal_magic (jp));
|
||||
|
||||
reiserfs_warning (fp, "\tSize %u blocks (including 1 for journal header) (first block %u)\n",
|
||||
get_jp_journal_size (jp) + 1,
|
||||
get_jp_journal_1st_block (jp));
|
||||
reiserfs_warning (fp, "\tMax transaction length %u blocks\n", get_jp_journal_max_trans_len (jp));
|
||||
reiserfs_warning (fp, "\tMax batch size %u blocks\n", get_jp_journal_max_batch (jp));
|
||||
reiserfs_warning (fp, "\tMax commit age %u\n", get_jp_journal_max_commit_age (jp));
|
||||
/*reiserfs_warning (fp, "\tMax transaction age %u\n", get_jp_journal_max_trans_age (jp));*/
|
||||
}
|
||||
|
||||
/* return 1 if this is not super block */
|
||||
static int print_super_block (FILE * fp, struct buffer_head * bh)
|
||||
int print_super_block (FILE * fp, reiserfs_filsys_t * fs, char * file_name,
|
||||
struct buffer_head * bh, int short_print)
|
||||
{
|
||||
struct reiserfs_super_block * rs = (struct reiserfs_super_block *)(bh->b_data);
|
||||
int skipped, data_blocks;
|
||||
struct reiserfs_super_block * sb = (struct reiserfs_super_block *)(bh->b_data);
|
||||
dev_t rdev;
|
||||
int format = 0;
|
||||
|
||||
if (is_reiser2fs_magic_string (rs))
|
||||
reiserfs_warning (fp, "Super block of format 3.6 found on the 0x%x in block %ld\n",
|
||||
bh->b_dev, bh->b_blocknr);
|
||||
else if (is_reiserfs_magic_string (rs))
|
||||
reiserfs_warning (fp, "Super block of format 3.5 found on the 0x%x in block %ld\n",
|
||||
bh->b_dev, bh->b_blocknr);
|
||||
else if (is_prejournaled_reiserfs (rs)) {
|
||||
reiserfs_warning (fp, "Prejournaled reiserfs super block found. Not supported here. Use proper tools instead\n");
|
||||
return 1;
|
||||
} else
|
||||
// no reiserfs signature found in the block
|
||||
if (!does_look_like_super_block (sb, fs->fs_blocksize))
|
||||
return 1;
|
||||
|
||||
reiserfs_warning (fp, "Block count %u\n", rs_block_count (rs));
|
||||
reiserfs_warning (fp, "Blocksize %d\n", rs_blocksize (rs));
|
||||
reiserfs_warning (fp, "Free blocks %u\n", rs_free_blocks (rs));
|
||||
skipped = bh->b_blocknr; // FIXME: this would be confusing if
|
||||
// someone stores reiserfs super block in reiserfs ;)
|
||||
data_blocks = rs_block_count (rs) - skipped - 1 -
|
||||
rs_bmap_nr (rs) - (rs_journal_size (rs) + 1) - rs_free_blocks (rs);
|
||||
reiserfs_warning (fp, "Busy blocks (skipped %d, bitmaps - %d, journal blocks - %d\n"
|
||||
"1 super blocks, %d data blocks\n",
|
||||
skipped, rs_bmap_nr (rs),
|
||||
(rs_journal_size (rs) + 1), data_blocks);
|
||||
reiserfs_warning (fp, "Root block %u\n", rs_root_block (rs));
|
||||
reiserfs_warning (fp, "Journal block (first) %d\n", rs_journal_start (rs));
|
||||
reiserfs_warning (fp, "Journal dev %d\n", rs->s_v1.s_journal_dev);
|
||||
reiserfs_warning (fp, "Journal orig size %d\n", rs_journal_size (rs));
|
||||
reiserfs_warning (fp, "Filesystem state %s\n", (rs->s_v1.s_state == REISERFS_VALID_FS) ? "VALID" : "ERROR");
|
||||
if (fsck_state (rs) == TREE_IS_BUILT)
|
||||
reiserfs_warning (fp, "fsck pass 2 completion code set\n");
|
||||
rdev = get_st_rdev (file_name);
|
||||
|
||||
#if 0
|
||||
__u32 s_journal_trans_max ; /* max number of blocks in a transaction. */
|
||||
__u32 s_journal_block_count ; /* total size of the journal. can change over time */
|
||||
__u32 s_journal_max_batch ; /* max number of blocks to batch into a trans */
|
||||
__u32 s_journal_max_commit_age ; /* in seconds, how old can an async commit be */
|
||||
__u32 s_journal_max_trans_age ; /* in seconds, how old can a transaction be */
|
||||
#endif
|
||||
reiserfs_warning (fp, "Tree height %d\n", rs_tree_height (rs));
|
||||
reiserfs_warning (fp, "Reiserfs super block in block %lu on 0x%x of ",
|
||||
bh->b_blocknr, rdev);
|
||||
switch (get_reiserfs_format (sb)) {
|
||||
case REISERFS_FORMAT_3_5:
|
||||
reiserfs_warning (fp, "format 3.5 with ");
|
||||
format = 1;
|
||||
break;
|
||||
case REISERFS_FORMAT_3_6:
|
||||
reiserfs_warning (fp, "format 3.6 with ");
|
||||
format = 2;
|
||||
break;
|
||||
default:
|
||||
reiserfs_warning (fp, "unknown format with ");
|
||||
break;
|
||||
}
|
||||
if (is_reiserfs_jr_magic_string (sb))
|
||||
reiserfs_warning (fp, "non-");
|
||||
reiserfs_warning (fp, "standard journal\n");
|
||||
if (short_print) {
|
||||
reiserfs_warning (fp, "Blocks (total/free): %u/%u by %d bytes\n",
|
||||
get_sb_block_count (sb), get_sb_free_blocks (sb), get_sb_block_size (sb));
|
||||
} else {
|
||||
reiserfs_warning (fp, "Count of blocks on the device: %u\n", get_sb_block_count (sb));
|
||||
reiserfs_warning (fp, "Number of bitmaps: %u\n", get_sb_bmap_nr (sb));
|
||||
reiserfs_warning (fp, "Blocksize: %d\n", get_sb_block_size (sb));
|
||||
reiserfs_warning (fp, "Free blocks (count of blocks - used [journal, "
|
||||
"bitmaps, data, reserved] blocks): %u\n", get_sb_free_blocks (sb));
|
||||
reiserfs_warning (fp, "Root block: %u\n", get_sb_root_block (sb));
|
||||
}
|
||||
reiserfs_warning (fp, "Filesystem is %scleanly umounted\n",
|
||||
(get_sb_umount_state (sb) == REISERFS_CLEANLY_UMOUNTED) ? "" : "NOT ");
|
||||
|
||||
if (short_print)
|
||||
return 0;
|
||||
reiserfs_warning (fp, "Tree height: %d\n", get_sb_tree_height (sb));
|
||||
reiserfs_warning (fp, "Hash function used to sort names: %s\n",
|
||||
code2name (rs_hash (rs)));
|
||||
reiserfs_warning (fp, "Objectid map size %d, max %d\n", rs_objectid_map_size (rs),
|
||||
rs_objectid_map_max_size (rs));
|
||||
reiserfs_warning (fp, "Version %d\n", rs_version (rs));
|
||||
code2name (get_sb_hash_code (sb)));
|
||||
reiserfs_warning (fp, "Objectid map size %d, max %d\n", get_sb_oid_cursize (sb),
|
||||
get_sb_oid_maxsize (sb));
|
||||
reiserfs_warning (fp, "Journal parameters:\n");
|
||||
print_journal_params (fp, sb_jp (sb));
|
||||
reiserfs_warning (fp, "Blocks reserved by journal: %u\n",
|
||||
get_sb_reserved_for_journal (sb));
|
||||
reiserfs_warning (fp, "Fs state field: 0x%x\n", get_sb_fs_state (sb));
|
||||
reiserfs_warning (fp, "sb_version: %u\n", get_sb_version (sb));
|
||||
if (format == 2) {
|
||||
reiserfs_warning (fp, "inode generation number: %u\n", get_sb_v2_inode_generation (sb));
|
||||
reiserfs_warning (fp, "UUID: %U\n", sb->s_uuid);
|
||||
reiserfs_warning (fp, "LABEL: %.16s\n", sb->s_label);
|
||||
reiserfs_warning (fp, "Set flags in SB:\n");
|
||||
reiserfs_warning (fp, "\t%s\n", ((get_sb_v2_flag (sb, reiserfs_attrs_cleared)) ? "ATTRIBUTES CLEAN" : ""));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void print_filesystem_state (FILE * fp, reiserfs_filsys_t * fs)
|
||||
{
|
||||
reiserfs_warning (fp, "\nFilesystem state: ");
|
||||
if (reiserfs_is_fs_consistent (fs))
|
||||
reiserfs_warning (fp, "consistent\n\n");
|
||||
else
|
||||
reiserfs_warning (fp, "consistency is not checked after last mounting\n\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int print_desc_block (FILE * fp, struct buffer_head * bh)
|
||||
{
|
||||
struct reiserfs_journal_desc * desc;
|
||||
|
||||
desc = (struct reiserfs_journal_desc *)(bh->b_data);
|
||||
|
||||
if (memcmp(desc->j_magic, JOURNAL_DESC_MAGIC, 8))
|
||||
if (memcmp(get_jd_magic (bh), JOURNAL_DESC_MAGIC, 8))
|
||||
return 1;
|
||||
|
||||
reiserfs_warning (fp, "Desc block %lu (j_trans_id %ld, j_mount_id %ld, j_len %ld)",
|
||||
bh->b_blocknr, desc->j_trans_id, desc->j_mount_id, desc->j_len);
|
||||
reiserfs_warning (fp, "Desc block %lu (j_trans_id %ld, j_mount_id %ld, j_len %ld)\n",
|
||||
bh->b_blocknr, get_desc_trans_id (bh),
|
||||
get_desc_mount_id (bh), get_desc_trans_len (bh));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void print_block (FILE * fp, reiserfs_filsys_t fs,
|
||||
void print_block (FILE * fp, reiserfs_filsys_t * fs,
|
||||
struct buffer_head * bh, ...)//int print_mode, int first, int last)
|
||||
{
|
||||
va_list args;
|
||||
int mode, first, last;
|
||||
char * file_name;
|
||||
|
||||
va_start (args, bh);
|
||||
|
||||
@@ -620,8 +688,9 @@ void print_block (FILE * fp, reiserfs_filsys_t fs,
|
||||
mode = va_arg (args, int);
|
||||
first = va_arg (args, int);
|
||||
last = va_arg (args, int);
|
||||
file_name = (fs) ? fs->fs_file_name : NULL ;
|
||||
if (print_desc_block (fp, bh))
|
||||
if (print_super_block (fp, bh))
|
||||
if (print_super_block (fp, fs, file_name, bh, 0))
|
||||
if (print_leaf (fp, fs, bh, mode, first, last))
|
||||
if (print_internal (fp, bh, first, last))
|
||||
reiserfs_warning (fp, "Block %ld contains unformatted data\n", bh->b_blocknr);
|
||||
@@ -709,21 +778,24 @@ void print_tb (int mode, int item_pos, int pos_in_item, struct tree_balance * tb
|
||||
}
|
||||
|
||||
|
||||
static void print_bmap_block (FILE * fp, int i, struct buffer_head * bmap, int blocks, int silent)
|
||||
static void print_bmap_block (FILE * fp, int i, unsigned long block, char * map, int blocks, int silent, int blocksize)
|
||||
{
|
||||
int j, k;
|
||||
int bits = bmap->b_size * 8;
|
||||
int bits = blocksize * 8;
|
||||
int zeros = 0, ones = 0;
|
||||
|
||||
reiserfs_warning (fp, "#%d: block %lu: ", i, bmap->b_blocknr);
|
||||
|
||||
if (test_bit (0, bmap->b_data)) {
|
||||
reiserfs_warning (fp, "#%d: block %lu: ", i, block);
|
||||
|
||||
blocks = blocksize * 8;
|
||||
|
||||
if (test_bit (0, map)) {
|
||||
/* first block addressed by this bitmap block is used */
|
||||
ones ++;
|
||||
if (!silent)
|
||||
reiserfs_warning (fp, "Busy (%d-", i * bits);
|
||||
for (j = 1; j < blocks; j ++) {
|
||||
while (test_bit (j, bmap->b_data)) {
|
||||
while (test_bit (j, map)) {
|
||||
ones ++;
|
||||
if (j == blocks - 1) {
|
||||
if (!silent)
|
||||
@@ -735,7 +807,7 @@ static void print_bmap_block (FILE * fp, int i, struct buffer_head * bmap, int b
|
||||
if (!silent)
|
||||
reiserfs_warning (fp, "%d) Free(%d-", j - 1 + i * bits, j + i * bits);
|
||||
|
||||
while (!test_bit (j, bmap->b_data)) {
|
||||
while (!test_bit (j, map)) {
|
||||
zeros ++;
|
||||
if (j == blocks - 1) {
|
||||
if (!silent)
|
||||
@@ -757,7 +829,7 @@ static void print_bmap_block (FILE * fp, int i, struct buffer_head * bmap, int b
|
||||
reiserfs_warning (fp, "Free (%d-", i * bits);
|
||||
for (j = 1; j < blocks; j ++) {
|
||||
k = 0;
|
||||
while (!test_bit (j, bmap->b_data)) {
|
||||
while (!test_bit (j, map)) {
|
||||
k ++;
|
||||
if (j == blocks - 1) {
|
||||
if (!silent)
|
||||
@@ -772,7 +844,7 @@ static void print_bmap_block (FILE * fp, int i, struct buffer_head * bmap, int b
|
||||
reiserfs_warning (fp, "%d) Busy(%d-", j - 1 + i * bits, j + i * bits);
|
||||
|
||||
k = 0;
|
||||
while (test_bit (j, bmap->b_data)) {
|
||||
while (test_bit (j, map)) {
|
||||
ones ++;
|
||||
if (j == blocks - 1) {
|
||||
if (!silent)
|
||||
@@ -795,155 +867,137 @@ static void print_bmap_block (FILE * fp, int i, struct buffer_head * bmap, int b
|
||||
}
|
||||
|
||||
|
||||
/* if silent == 1, do not print details */
|
||||
void print_bmap (FILE * fp, reiserfs_filsys_t s, int silent)
|
||||
/* read bitmap of disk and print details */
|
||||
void print_bmap (FILE * fp, reiserfs_filsys_t * fs, int silent)
|
||||
{
|
||||
int bmapnr = SB_BMAP_NR (s);
|
||||
struct reiserfs_super_block * sb;
|
||||
int bmap_nr;
|
||||
int i;
|
||||
int blocks = s->s_blocksize * 8; /* adressed by bitmap */
|
||||
int bits_per_block;
|
||||
int blocks;
|
||||
unsigned long block;
|
||||
struct buffer_head * bh;
|
||||
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
bmap_nr = get_sb_bmap_nr (sb);
|
||||
bits_per_block = fs->fs_blocksize * 8;
|
||||
blocks = bits_per_block;
|
||||
|
||||
reiserfs_warning (fp, "Bitmap blocks are:\n");
|
||||
for (i = 0; i < bmapnr; i ++) {
|
||||
|
||||
if (i == bmapnr - 1)
|
||||
if (SB_BLOCK_COUNT (s) % (s->s_blocksize * 8))
|
||||
blocks = SB_BLOCK_COUNT (s) % (s->s_blocksize * 8);
|
||||
print_bmap_block (fp, i, SB_AP_BITMAP(s)[i], blocks, silent);
|
||||
}
|
||||
|
||||
/* check unused part of last bitmap */
|
||||
{
|
||||
int bad_unused_bitmap = 0;
|
||||
int ones;
|
||||
|
||||
ones = s->s_blocksize * 8 - SB_BLOCK_COUNT (s) % (s->s_blocksize * 8);
|
||||
if (ones == s->s_blocksize * 8)
|
||||
ones = 0;
|
||||
|
||||
for (i = s->s_blocksize * 8; --i >= blocks; )
|
||||
if (!test_bit (i, SB_AP_BITMAP (s)[bmapnr - 1]->b_data))
|
||||
bad_unused_bitmap ++;
|
||||
|
||||
if (bad_unused_bitmap) {
|
||||
reiserfs_warning (fp, "Unused part of bitmap is wrong: should be %d ones, found %d zeros\n",
|
||||
ones, bad_unused_bitmap);
|
||||
block = fs->fs_super_bh->b_blocknr + 1;
|
||||
for (i = 0; i < bmap_nr; i ++) {
|
||||
bh = bread (fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (!bh) {
|
||||
reiserfs_warning (stderr, "print_bmap: bread failed for %d: %lu\n", i, block);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (i == bmap_nr - 1)
|
||||
if (get_sb_block_count (sb) % bits_per_block)
|
||||
blocks = get_sb_block_count (sb) % bits_per_block;
|
||||
print_bmap_block (fp, i, block, bh->b_data, blocks, silent, fs->fs_blocksize);
|
||||
brelse (bh);
|
||||
|
||||
if (spread_bitmaps (fs))
|
||||
block = (block / (fs->fs_blocksize * 8) + 1) * (fs->fs_blocksize * 8);
|
||||
else
|
||||
block ++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_objectid_map (FILE * fp, reiserfs_filsys_t fs)
|
||||
void print_objectid_map (FILE * fp, reiserfs_filsys_t * fs)
|
||||
{
|
||||
int i;
|
||||
struct reiserfs_super_block * rs;
|
||||
struct reiserfs_super_block * sb;
|
||||
__u32 * omap;
|
||||
|
||||
rs = fs->s_rs;
|
||||
if (fs->s_version == REISERFS_VERSION_2)
|
||||
omap = (__u32 *)(rs + 1);
|
||||
else if (fs->s_version == REISERFS_VERSION_1)
|
||||
omap = (__u32 *)((struct reiserfs_super_block_v1 *)rs + 1);
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
if (fs->fs_format == REISERFS_FORMAT_3_6)
|
||||
omap = (__u32 *)(sb + 1);
|
||||
else if (fs->fs_format == REISERFS_FORMAT_3_5)
|
||||
omap = (__u32 *)((struct reiserfs_super_block_v1 *)sb + 1);
|
||||
else {
|
||||
reiserfs_warning (fp, "print_objectid_map: proper signature is not found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
reiserfs_warning (fp, "Map of objectids (super block size %d)\n", (char *)omap - (char *)rs);
|
||||
reiserfs_warning (fp, "Map of objectids (super block size %d)\n",
|
||||
(char *)omap - (char *)sb);
|
||||
|
||||
for (i = 0; i < SB_OBJECTID_MAP_SIZE (fs); i ++) {
|
||||
for (i = 0; i < get_sb_oid_cursize (sb); i ++) {
|
||||
if (i % 2 == 0)
|
||||
reiserfs_warning (fp, "busy(%u-%u) ", omap[i], omap[i+1] - 1);
|
||||
reiserfs_warning (fp, "busy(%u-%u) ", le32_to_cpu (omap[i]),
|
||||
le32_to_cpu (omap[i+1]) - 1);
|
||||
else
|
||||
reiserfs_warning (fp, "free(%u-%u) ",
|
||||
omap[i], ((i+1) == SB_OBJECTID_MAP_SIZE (fs)) ? -1 : omap[i+1] - 1);
|
||||
le32_to_cpu (omap[i]),
|
||||
((i+1) == get_sb_oid_cursize (sb)) ? -1 : (le32_to_cpu (omap[i+1]) - 1));
|
||||
}
|
||||
|
||||
reiserfs_warning (fp, "\nObject id array has size %d (max %d):", SB_OBJECTID_MAP_SIZE (fs),
|
||||
SB_OBJECTID_MAP_MAXSIZE (fs));
|
||||
reiserfs_warning (fp, "\nObject id array has size %d (max %d):",
|
||||
get_sb_oid_cursize (sb), get_sb_oid_maxsize (sb));
|
||||
|
||||
for (i = 0; i < SB_OBJECTID_MAP_SIZE (fs); i ++)
|
||||
reiserfs_warning (fp, "%s%u ", i % 2 ? "" : "*", omap[i]);
|
||||
for (i = 0; i < get_sb_oid_cursize (sb); i ++)
|
||||
reiserfs_warning (fp, "%s%u ", i % 2 ? "" : "*", le32_to_cpu (omap[i]));
|
||||
reiserfs_warning (fp, "\n");
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* the below is from fileutils-4.0-66 (shortened) */
|
||||
|
||||
/* Look at read, write, and execute bits in BITS and set
|
||||
flags in CHARS accordingly. */
|
||||
|
||||
static void
|
||||
rwx (short unsigned int bits, char *chars)
|
||||
void print_journal_header (reiserfs_filsys_t * fs)
|
||||
{
|
||||
chars[0] = (bits & S_IRUSR) ? 'r' : '-';
|
||||
chars[1] = (bits & S_IWUSR) ? 'w' : '-';
|
||||
chars[2] = (bits & S_IXUSR) ? 'x' : '-';
|
||||
}
|
||||
struct reiserfs_journal_header * j_head;
|
||||
|
||||
/* snip */
|
||||
|
||||
/* Return a character indicating the type of file described by
|
||||
file mode BITS:
|
||||
'd' for directories
|
||||
'b' for block special files
|
||||
'c' for character special files
|
||||
'l' for symbolic links
|
||||
's' for sockets
|
||||
'p' for fifos
|
||||
'-' for regular files
|
||||
'?' for any other file type. */
|
||||
|
||||
static char
|
||||
ftypelet (long int bits)
|
||||
{
|
||||
#ifdef S_ISBLK
|
||||
if (S_ISBLK (bits))
|
||||
return 'b';
|
||||
#endif
|
||||
if (S_ISCHR (bits))
|
||||
return 'c';
|
||||
if (S_ISDIR (bits))
|
||||
return 'd';
|
||||
if (S_ISREG (bits))
|
||||
return '-';
|
||||
#ifdef S_ISFIFO
|
||||
if (S_ISFIFO (bits))
|
||||
return 'p';
|
||||
#endif
|
||||
#ifdef S_ISLNK
|
||||
if (S_ISLNK (bits))
|
||||
return 'l';
|
||||
#endif
|
||||
#ifdef S_ISSOCK
|
||||
if (S_ISSOCK (bits))
|
||||
return 's';
|
||||
#endif
|
||||
|
||||
return '?';
|
||||
}
|
||||
|
||||
/* Like filemodestring, but only the relevant part of the `struct stat'
|
||||
is given as an argument. */
|
||||
|
||||
static void
|
||||
mode_string (short unsigned int mode, char *str)
|
||||
{
|
||||
str[0] = ftypelet ((long) mode);
|
||||
rwx ((mode & 0700) << 0, &str[1]);
|
||||
rwx ((mode & 0070) << 3, &str[4]);
|
||||
rwx ((mode & 0007) << 6, &str[7]);
|
||||
j_head = (struct reiserfs_journal_header *)(fs->fs_jh_bh->b_data);
|
||||
reiserfs_warning (stdout, "Journal header (block #%lu of %s):\n"
|
||||
"\tj_last_flush_trans_id %ld\n"
|
||||
"\tj_first_unflushed_offset %ld\n"
|
||||
"\tj_mount_id %ld\n",
|
||||
fs->fs_jh_bh->b_blocknr, fs->fs_j_file_name,
|
||||
get_jh_last_flushed (j_head),
|
||||
get_jh_replay_start_offset (j_head),
|
||||
get_jh_mount_id (j_head));
|
||||
print_journal_params (stdout, &j_head->jh_journal);
|
||||
}
|
||||
|
||||
|
||||
char * st_mode2string (short unsigned int mode, char * buf)
|
||||
static void print_trans_element (reiserfs_filsys_t * fs, reiserfs_trans_t * trans,
|
||||
int index, unsigned long in_journal, unsigned long in_place)
|
||||
{
|
||||
mode_string (mode, buf);
|
||||
buf[10] = 0;
|
||||
return buf;
|
||||
if (index % 8 == 0)
|
||||
reiserfs_warning (stdout, "#%d\t", index);
|
||||
|
||||
reiserfs_warning (stdout, "%lu->%lu%s ", in_journal, in_place,
|
||||
block_of_bitmap (fs, in_place) ? "B" : "");
|
||||
if ((index + 1) % 8 == 0 || index == trans->trans_len - 1)
|
||||
reiserfs_warning (stdout, "\n");
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
void print_one_transaction (reiserfs_filsys_t * fs, reiserfs_trans_t * trans)
|
||||
{
|
||||
reiserfs_warning (stdout, "Mountid %u, transid %u, desc %lu, length %u, commit %lu\n",
|
||||
trans->mount_id, trans->trans_id,
|
||||
trans->desc_blocknr,
|
||||
trans->trans_len, trans->commit_blocknr);
|
||||
for_each_block (fs, trans, print_trans_element);
|
||||
}
|
||||
|
||||
|
||||
/* print all valid transactions and found dec blocks */
|
||||
void print_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
if (!reiserfs_journal_opened (fs)) {
|
||||
reiserfs_warning (stderr, "print_journal: journal is not opened\n");
|
||||
return;
|
||||
}
|
||||
print_journal_header (fs);
|
||||
|
||||
for_each_transaction (fs, print_one_transaction);
|
||||
}
|
||||
|
||||
+971
-274
File diff suppressed because it is too large.
Load diff
+101
-162
@@ -40,15 +40,7 @@
|
||||
/* Does the buffer contain a disk block which is in the tree. */
|
||||
inline int B_IS_IN_TREE (struct buffer_head * p_s_bh)
|
||||
{
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( node_level (p_s_bh) > MAX_HEIGHT ) {
|
||||
reiserfs_panic(0, "PAP-1010: B_IS_IN_TREE: block (%b) has too big level (%z)",
|
||||
p_s_bh, p_s_bh);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ( node_level (p_s_bh) != FREE_LEVEL );
|
||||
return ( get_blkh_level (B_BLK_HEAD (p_s_bh)) != FREE_LEVEL );
|
||||
}
|
||||
|
||||
|
||||
@@ -58,18 +50,20 @@ inline int B_IS_IN_TREE (struct buffer_head * p_s_bh)
|
||||
0 if key1 = key2
|
||||
1 if key1 > key2
|
||||
*/
|
||||
int comp_short_keys (void * k1, void * k2)
|
||||
{
|
||||
__u32 * p_s_key1, * p_s_key2;
|
||||
int n_key_length = REISERFS_SHORT_KEY_LEN;
|
||||
|
||||
p_s_key1 = (__u32 *)k1;
|
||||
p_s_key2 = (__u32 *)k2;
|
||||
int comp_short_keys (const void * k1, const void * k2)
|
||||
{
|
||||
int n_key_length = REISERFS_SHORT_KEY_LEN;
|
||||
__u32 * p_s_key1 = (__u32 *)k1;
|
||||
__u32 * p_s_key2 = (__u32 *)k2;
|
||||
__u32 u1, u2;
|
||||
|
||||
for( ; n_key_length--; ++p_s_key1, ++p_s_key2 ) {
|
||||
if ( *p_s_key1 < *p_s_key2 )
|
||||
u1 = le32_to_cpu(*p_s_key1) ;
|
||||
u2 = le32_to_cpu(*p_s_key2) ;
|
||||
if ( u1 < u2 )
|
||||
return -1;
|
||||
if ( *p_s_key1 > *p_s_key2 )
|
||||
if ( u1 > u2 )
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -77,36 +71,53 @@ int comp_short_keys (void * k1, void * k2)
|
||||
}
|
||||
|
||||
|
||||
int comp_keys_3 (const void * p1, const void * p2)
|
||||
{
|
||||
int retval;
|
||||
const struct key * k1 = p1;
|
||||
const struct key * k2 = p2;
|
||||
loff_t off1, off2;
|
||||
|
||||
retval = comp_short_keys (k1, k2);
|
||||
if (retval)
|
||||
return retval;
|
||||
off1 = get_offset(k1) ;
|
||||
off2 = get_offset(k2) ;
|
||||
if (off1 < off2)
|
||||
return -1;
|
||||
|
||||
if (off1 > off2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Compare keys using all 4 key fields.
|
||||
Returns: -1 if key1 < key2
|
||||
0 if key1 = key2
|
||||
1 if key1 > key2
|
||||
*/
|
||||
int comp_keys (void * p1, void * p2)
|
||||
int comp_keys (const void * p1, const void * p2)
|
||||
{
|
||||
int retval;
|
||||
struct key * k1, * k2;
|
||||
const struct key * k1 = p1;
|
||||
const struct key * k2 = p2;
|
||||
__u32 u1, u2;
|
||||
|
||||
k1 = p1;
|
||||
k2 = p2;
|
||||
|
||||
retval = comp_short_keys (k1, k2);
|
||||
retval = comp_keys_3 (k1, k2);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
if (get_offset (k1) < get_offset (k2))
|
||||
return -1;
|
||||
u1 = get_type (k1);
|
||||
u2 = get_type (k2);
|
||||
|
||||
if (get_offset (k1) > get_offset (k2))
|
||||
return 1;
|
||||
if (u1 < u2)
|
||||
return -1;
|
||||
|
||||
/* this part is needed only when tail conversion is in progress */
|
||||
if (get_type (k1) < get_type (k2))
|
||||
return -1;
|
||||
|
||||
if (get_type (k1) > get_type (k2))
|
||||
return 1;
|
||||
if (u1 > u2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -155,14 +166,6 @@ inline int bin_search (
|
||||
return ITEM_NOT_FOUND;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
extern struct tree_balance * cur_tb;
|
||||
extern struct tree_balance init_tb;
|
||||
extern int init_item_pos, init_pos_in_item, init_mode;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Minimal possible key. It is never in the tree. */
|
||||
struct key MIN_KEY = {0, 0, {{0, 0},}};
|
||||
|
||||
@@ -176,26 +179,17 @@ struct key MAX_KEY = {0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff},}};
|
||||
there is no delimiting key in the tree (buffer is first or last buffer in
|
||||
tree), and in this case we return a special key, either MIN_KEY or
|
||||
MAX_KEY. */
|
||||
inline struct key * get_lkey (
|
||||
struct path * p_s_chk_path,
|
||||
struct super_block * p_s_sb
|
||||
) {
|
||||
int n_position, n_path_offset = p_s_chk_path->path_length;
|
||||
struct key * get_lkey (struct path * p_s_chk_path,
|
||||
reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct reiserfs_super_block * sb;
|
||||
int n_position, n_path_offset = p_s_chk_path->path_length;
|
||||
struct buffer_head * p_s_parent;
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( n_path_offset < FIRST_PATH_ELEMENT_OFFSET )
|
||||
reiserfs_panic(p_s_sb,"PAP-5010: get_lkey: illegal offset in the path");
|
||||
#endif
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
/* While not higher in path than first element. */
|
||||
while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) {
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( ! buffer_uptodate(PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
|
||||
reiserfs_panic(p_s_sb, "PAP-5020: get_lkey: parent is not uptodate");
|
||||
#endif
|
||||
|
||||
/* Parent at the path is not in the tree now. */
|
||||
if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
|
||||
return &MAX_KEY;
|
||||
@@ -203,7 +197,7 @@ inline struct key * get_lkey (
|
||||
if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) )
|
||||
return &MAX_KEY;
|
||||
/* Check whether parent at the path really points to the child. */
|
||||
if ( B_N_CHILD_NUM(p_s_parent, n_position) !=
|
||||
if ( get_dc_child_blocknr (B_N_CHILD (p_s_parent, n_position)) !=
|
||||
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr )
|
||||
return &MAX_KEY;
|
||||
/* Return delimiting key if position in the parent is not equal to zero. */
|
||||
@@ -212,33 +206,24 @@ inline struct key * get_lkey (
|
||||
}
|
||||
/* Return MIN_KEY if we are in the root of the buffer tree. */
|
||||
if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
|
||||
SB_ROOT_BLOCK (p_s_sb) )
|
||||
get_sb_root_block (sb) )
|
||||
return &MIN_KEY;
|
||||
return &MAX_KEY;
|
||||
}
|
||||
|
||||
|
||||
/* Get delimiting key of the buffer at the path and its right neighbor. */
|
||||
inline struct key * get_rkey (
|
||||
struct path * p_s_chk_path,
|
||||
struct super_block * p_s_sb
|
||||
) {
|
||||
struct key * get_rkey (struct path * p_s_chk_path,
|
||||
reiserfs_filsys_t * fs)
|
||||
{
|
||||
struct reiserfs_super_block * sb;
|
||||
int n_position,
|
||||
n_path_offset = p_s_chk_path->path_length;
|
||||
struct buffer_head * p_s_parent;
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( n_path_offset < FIRST_PATH_ELEMENT_OFFSET )
|
||||
reiserfs_panic(p_s_sb,"PAP-5030: get_rkey: illegal offset in the path");
|
||||
#endif
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) {
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( ! buffer_uptodate(PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
|
||||
reiserfs_panic(p_s_sb, "PAP-5040: get_rkey: parent is not uptodate");
|
||||
#endif
|
||||
|
||||
/* Parent at the path is not in the tree now. */
|
||||
if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
|
||||
return &MIN_KEY;
|
||||
@@ -246,7 +231,7 @@ inline struct key * get_rkey (
|
||||
if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) )
|
||||
return &MIN_KEY;
|
||||
/* Check whether parent at the path really points to the child. */
|
||||
if ( B_N_CHILD_NUM(p_s_parent, n_position) !=
|
||||
if ( get_dc_child_blocknr (B_N_CHILD (p_s_parent, n_position)) !=
|
||||
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr )
|
||||
return &MIN_KEY;
|
||||
/* Return delimiting key if position in the parent is not the last one. */
|
||||
@@ -255,7 +240,7 @@ inline struct key * get_rkey (
|
||||
}
|
||||
/* Return MAX_KEY if we are in the root of the buffer tree. */
|
||||
if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
|
||||
SB_ROOT_BLOCK (p_s_sb) )
|
||||
get_sb_root_block (sb) )
|
||||
return &MAX_KEY;
|
||||
return &MIN_KEY;
|
||||
}
|
||||
@@ -271,37 +256,21 @@ inline struct key * get_rkey (
|
||||
static inline int key_in_buffer (
|
||||
struct path * p_s_chk_path, /* Path which should be checked. */
|
||||
struct key * p_s_key, /* Key which should be checked. */
|
||||
struct super_block * p_s_sb /* Super block pointer. */
|
||||
reiserfs_filsys_t * fs /* Super block pointer. */
|
||||
) {
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( ! p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET ||
|
||||
p_s_chk_path->path_length > MAX_HEIGHT )
|
||||
reiserfs_panic(p_s_sb, "PAP-5050: key_in_buffer: pointer to the key(%p) is NULL or illegal path length(%d)",
|
||||
p_s_key, p_s_chk_path->path_length);
|
||||
|
||||
if ( PATH_PLAST_BUFFER(p_s_chk_path)->b_dev == NODEV )
|
||||
reiserfs_panic(p_s_sb, "PAP-5060: key_in_buffer: device must not be NODEV");
|
||||
#endif
|
||||
|
||||
if ( COMP_KEYS(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1 )
|
||||
if ( COMP_KEYS(get_lkey(p_s_chk_path, fs), p_s_key) == 1 )
|
||||
return 0;
|
||||
if ( COMP_KEYS(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 )
|
||||
if ( COMP_KEYS(p_s_key, get_rkey(p_s_chk_path, fs)) != -1 )
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Release all buffers in the path. */
|
||||
void pathrelse (struct path * p_s_search_path)
|
||||
{
|
||||
int n_path_offset = p_s_search_path->path_length;
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET )
|
||||
reiserfs_panic(NULL, "PAP-5090: pathrelse: illegal path offset");
|
||||
#endif
|
||||
|
||||
while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET )
|
||||
brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
|
||||
|
||||
@@ -331,28 +300,29 @@ void pathrelse (struct path * p_s_search_path)
|
||||
key. search_by_key returns a path that must be checked for the
|
||||
correctness of the top of the path but need not be checked for the
|
||||
correctness of the bottom of the path */
|
||||
int search_by_key(
|
||||
struct super_block * p_s_sb, /* Super block. */
|
||||
struct key * p_s_key, /* Key to search. */
|
||||
struct path * p_s_search_path,/* This structure was allocated and initialized by
|
||||
the calling function. It is filled up by this
|
||||
function. */
|
||||
int * p_n_repeat, /* Whether schedule occured. */
|
||||
int n_stop_level /* How far down the tree to search.*/
|
||||
) {
|
||||
dev_t n_dev = p_s_sb->s_dev;
|
||||
int n_repeat,
|
||||
n_block_number = SB_ROOT_BLOCK (p_s_sb),
|
||||
expected_level = SB_TREE_HEIGHT (p_s_sb),
|
||||
n_block_size = p_s_sb->s_blocksize;
|
||||
int search_by_key (reiserfs_filsys_t * fs,
|
||||
struct key * p_s_key, /* Key to search */
|
||||
struct path * p_s_search_path,/* This structure was
|
||||
allocated and
|
||||
initialized by the
|
||||
calling
|
||||
function. It is
|
||||
filled up by this
|
||||
function. */
|
||||
int n_stop_level) /* How far down the tree to search.*/
|
||||
{
|
||||
struct reiserfs_super_block * sb;
|
||||
int n_block_number,
|
||||
expected_level,
|
||||
n_block_size = fs->fs_blocksize;
|
||||
struct buffer_head * p_s_bh;
|
||||
struct path_element * p_s_last_element;
|
||||
int n_retval;
|
||||
int right_neighbor_of_leaf_node;
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
int n_repeat_counter = 0;
|
||||
#endif
|
||||
|
||||
sb = fs->fs_ondisk_sb;
|
||||
n_block_number = get_sb_root_block (sb);
|
||||
expected_level = get_sb_tree_height (sb);
|
||||
|
||||
/* As we add each node to a path we increase its count. This
|
||||
means that we must be careful to release all nodes in a path
|
||||
@@ -360,90 +330,59 @@ int search_by_key(
|
||||
struct, as we do here. */
|
||||
pathrelse (p_s_search_path);
|
||||
|
||||
*p_n_repeat = CARRY_ON;
|
||||
|
||||
/* With each iteration of this loop we search through the items in
|
||||
the current node, and calculate the next current node(next path
|
||||
element) for the next iteration of this loop.. */
|
||||
while ( 1 ) {
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
if ( !(++n_repeat_counter % 50000) )
|
||||
printk ("PAP-5100: search_by_key(pid %u): there were %d searches from the tree_root lokking for key %p\n",
|
||||
current->pid, n_repeat_counter, p_s_key);
|
||||
#endif
|
||||
|
||||
/* prep path to have another element added to it. */
|
||||
p_s_last_element = PATH_OFFSET_PELEMENT(p_s_search_path, ++p_s_search_path->path_length);
|
||||
expected_level --;
|
||||
n_repeat = CARRY_ON;
|
||||
|
||||
/* Read the next tree node, and set the last element in the
|
||||
path to have a pointer to it. */
|
||||
if ( ! (p_s_bh = p_s_last_element->pe_buffer =
|
||||
reiserfs_bread(n_dev, n_block_number, n_block_size, &n_repeat)) ) {
|
||||
bread (fs->fs_dev, n_block_number, n_block_size)) ) {
|
||||
p_s_search_path->path_length --;
|
||||
pathrelse(p_s_search_path);
|
||||
*p_n_repeat |= n_repeat;
|
||||
return IO_ERROR;
|
||||
}
|
||||
|
||||
*p_n_repeat |= n_repeat;
|
||||
|
||||
/* It is possible that schedule occured. We must check whether
|
||||
the key to search is still in the tree rooted from the
|
||||
current buffer. If not then repeat search from the root. */
|
||||
if ( n_repeat != CARRY_ON &&
|
||||
(!B_IS_IN_TREE (p_s_bh) || (! key_in_buffer(p_s_search_path, p_s_key, p_s_sb))) ) {
|
||||
pathrelse (p_s_search_path);
|
||||
if (!B_IS_IN_TREE (p_s_bh) ||
|
||||
! key_in_buffer(p_s_search_path, p_s_key, fs))
|
||||
reiserfs_panic ("search_by_key: something wrong with the tree");
|
||||
|
||||
/* Get the root block number so that we can repeat the
|
||||
search starting from the root. */
|
||||
n_block_number = SB_ROOT_BLOCK (p_s_sb);
|
||||
expected_level = SB_TREE_HEIGHT (p_s_sb);
|
||||
right_neighbor_of_leaf_node = 0;
|
||||
|
||||
/* repeat search from the root */
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_REISERFS_CHECK
|
||||
|
||||
if ( ! key_in_buffer(p_s_search_path, p_s_key, p_s_sb) )
|
||||
reiserfs_panic(p_s_sb, "PAP-5130: search_by_key: key is not in the buffer");
|
||||
if ( cur_tb ) {
|
||||
/* print_tb (init_mode, init_item_pos, init_pos_in_item, &init_tb, "5140");*/
|
||||
reiserfs_panic(p_s_sb, "PAP-5140: search_by_key: schedule occurred in do_balance!");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// make sure, that the node contents look like a nod of
|
||||
// certain level
|
||||
/* make sure, that the node contents look like a node of
|
||||
certain level */
|
||||
if (!is_tree_node (p_s_bh, expected_level)) {
|
||||
print_block (stderr, 0, p_s_bh, 3, -1, -1);
|
||||
reiserfs_panic ("vs-5150: search_by_key: expeced level %d", expected_level);
|
||||
pathrelse (p_s_search_path);
|
||||
return IO_ERROR;
|
||||
reiserfs_panic ("search_by_key: expected level %d", expected_level);
|
||||
}
|
||||
|
||||
/* ok, we have acquired next formatted node in the tree */
|
||||
n_retval = bin_search (p_s_key, B_N_PITEM_HEAD(p_s_bh, 0), B_NR_ITEMS(p_s_bh),
|
||||
is_leaf_node (p_s_bh) ? IH_SIZE : KEY_SIZE, &(p_s_last_element->pe_position));
|
||||
if (node_level (p_s_bh) == n_stop_level)
|
||||
if (get_blkh_level (B_BLK_HEAD (p_s_bh)) == n_stop_level)
|
||||
return n_retval;
|
||||
|
||||
/* we are not in the stop level */
|
||||
if (n_retval == ITEM_FOUND)
|
||||
/* item has been found, so we choose the pointer which is to the right of the found one */
|
||||
/* item has been found, so we choose the pointer which is
|
||||
to the right of the found one */
|
||||
p_s_last_element->pe_position++;
|
||||
/* if item was not found we choose the position which is to the left of the found item. This
|
||||
requires no code, bin_search did it already.*/
|
||||
|
||||
/* if item was not found we choose the position which is to
|
||||
the left of the found item. This requires no code,
|
||||
bin_search did it already.*/
|
||||
|
||||
/* So we have chosen a position in the current node which is an
|
||||
internal node. Now we calculate child block number by position in the node. */
|
||||
n_block_number = B_N_CHILD_NUM(p_s_bh, p_s_last_element->pe_position);
|
||||
/* So we have chosen a position in the current node which is
|
||||
an internal node. Now we calculate child block number by
|
||||
position in the node. */
|
||||
n_block_number = get_dc_child_blocknr (B_N_CHILD (p_s_bh, p_s_last_element->pe_position));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,14 +393,14 @@ int bin_search_in_dir_item (struct item_head * ih, struct reiserfs_de_head * deh
|
||||
int rbound, lbound, j;
|
||||
|
||||
lbound = 0;
|
||||
rbound = ih_entry_count (ih) - 1;
|
||||
rbound = get_ih_entry_count (ih) - 1;
|
||||
|
||||
for (j = (rbound + lbound) / 2; lbound <= rbound; j = (rbound + lbound) / 2) {
|
||||
if (get_offset (key) < deh_offset (deh + j)) {
|
||||
if (get_offset (key) < get_deh_offset (deh + j)) {
|
||||
rbound = j - 1;
|
||||
continue;
|
||||
}
|
||||
if (get_offset (key) > deh_offset (deh + j)) {
|
||||
if (get_offset (key) > get_deh_offset (deh + j)) {
|
||||
lbound = j + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
+37
-15
@@ -1,16 +1,18 @@
|
||||
%define reiserfsprogsversion 3.6.2
|
||||
|
||||
Vendor: Hans Reiser
|
||||
Distribution: Hans Reiser
|
||||
Name: reiserfsprogs
|
||||
Release: 1
|
||||
Copyright: 2001 Hans Reiser
|
||||
Copyright: 2002 Hans Reiser
|
||||
Group: Unsorted
|
||||
|
||||
Packager: anthon@mnt.org
|
||||
|
||||
Version: 3.x.0j
|
||||
Version: %{reiserfsprogsversion}
|
||||
Summary: utilities belonging to the Reiser filesystem
|
||||
Source: reiserfsprogs-%{version}.tar.gz
|
||||
BuildRoot: /var/tmp/rpm-reiserfsprogs
|
||||
Source: reiserfsprogs-%{reiserfsprogsversion}.tar.gz
|
||||
BuildRoot: %{_tmppath}/rpmbuildroot-%{name}
|
||||
%description
|
||||
|
||||
The reiserfsprogs package contains programs for creating (mkreiserfs),
|
||||
@@ -22,21 +24,25 @@ Authors:
|
||||
Hans Reiser <reiser@namesys.com>
|
||||
Vitaly Fertman <vetalf@inbox.ru>
|
||||
Alexander Zarochentcev <zam@namesys.com>
|
||||
Vladimir Saveliev <vs@namesys.botik.ru>
|
||||
Vladimir Saveliev <monstr@namesys.com>
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
# Jeff Johnson states that RPM doesn't delete obviouse crap like / if
|
||||
# buildroot is set differently since RPM 3.0.4 (rpm mailing list 2001-04-10)
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
%setup -q -n reiserfsprogs-%{reiserfsprogsversion}
|
||||
# %patch
|
||||
%build
|
||||
MANDIR=$(dirname $(dirname $(man -w fsck | cut -d ' ' -f 1)))
|
||||
./configure --prefix="" --mandir=$MANDIR
|
||||
make all
|
||||
%{__make} all
|
||||
%install
|
||||
mkdir -p $RPM_BUILD_ROOT/sbin
|
||||
make DESTDIR=$RPM_BUILD_ROOT install
|
||||
mkdir -p $RPM_BUILD_ROOT/sbin
|
||||
%{__make} DESTDIR=$RPM_BUILD_ROOT install
|
||||
# do we need this?
|
||||
cd $RPM_BUILD_ROOT/sbin
|
||||
ln -sf reiserfsck fsck.reiserfs
|
||||
cd $RPM_BUILD_ROOT/sbin
|
||||
%{__ln_s} -f reiserfsck fsck.reiserfs
|
||||
%{__ln_s} -f mkreiserfs mkfs.reiserfs
|
||||
|
||||
# __os_install_post is normally executed after %install disable it
|
||||
%define ___build_post %{nil}
|
||||
@@ -46,7 +52,7 @@ Vladimir Saveliev <vs@namesys.botik.ru>
|
||||
# now we have all the files execpt for docs, but their owner is unimportant
|
||||
cd $RPM_BUILD_ROOT
|
||||
|
||||
rm -f rpm-filelist
|
||||
%{__rm} -f rpm-filelist
|
||||
# we do not have special directories to make
|
||||
#find . -type d \
|
||||
# | sed '1,2d;s,^\.,\%attr(-\,root\,root) \%dir ,' >> rpm-filelist
|
||||
@@ -55,8 +61,24 @@ find . -type f \
|
||||
find . -type l \
|
||||
| sed 's,^\.,\%attr(-\,root\,root) ,' >> rpm-filelist
|
||||
|
||||
%post
|
||||
CONFIG=/usr/src/linux/.config
|
||||
|
||||
if [ -f $CONFIG ] ; then
|
||||
source $CONFIG
|
||||
fi
|
||||
|
||||
if [ -z $CONFIG_REISERFS_FS ] ; then
|
||||
echo -e "\nIn $CONFIG , you probably have to set:"
|
||||
if [ "$CONFIG_EXPERIMENTAL" != "y" ] ; then
|
||||
echo -e 'CONFIG_EXPERIMENTAL=y'
|
||||
fi
|
||||
echo -e 'CONFIG_REISERFS_FS=y\n or'
|
||||
echo -e 'CONFIG_REISERFS_FS=m'
|
||||
echo -e 'and recompile and reboot your kernel if you cannot use the\nreiserfsprogs utilities'
|
||||
fi
|
||||
|
||||
%clean
|
||||
# in case some overrides buildroot with / don't remove the whole tree
|
||||
rm -rf /var/tmp/rpm-reiserfsprogs
|
||||
%files -f /var/tmp/rpm-reiserfsprogs/rpm-filelist
|
||||
%{__rm} -rf $RPM_BUILD_ROOT
|
||||
%files -f %{buildroot}/rpm-filelist
|
||||
%doc README
|
||||
@@ -4,6 +4,5 @@ resize_reiserfs_SOURCES = fe.c resize_reiserfs.c do_shrink.c resize.h
|
||||
man_MANS = resize_reiserfs.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
|
||||
INCLUDES = -I../include
|
||||
+16
-14
@@ -1,6 +1,6 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
@@ -62,6 +62,7 @@ MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
sbin_PROGRAMS = resize_reiserfs
|
||||
|
||||
@@ -69,22 +70,21 @@ resize_reiserfs_SOURCES = fe.c resize_reiserfs.c do_shrink.c resize.h
|
||||
man_MANS = resize_reiserfs.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
|
||||
|
||||
INCLUDES = -I../include
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
PROGRAMS = $(sbin_PROGRAMS)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
resize_reiserfs_OBJECTS = fe.o resize_reiserfs.o do_shrink.o
|
||||
resize_reiserfs_LDADD = $(LDADD)
|
||||
resize_reiserfs_DEPENDENCIES = ../lib/libmisc.a \
|
||||
../reiserfscore/libcore.a
|
||||
resize_reiserfs_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
|
||||
$(top_srcdir)/reiserfscore/libcore.a
|
||||
resize_reiserfs_LDFLAGS =
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@@ -239,7 +239,7 @@ distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
@@ -247,12 +247,14 @@ distdir: $(DISTFILES)
|
||||
fi; \
|
||||
done
|
||||
do_shrink.o: do_shrink.c resize.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h ../version.h
|
||||
fe.o: fe.c resize.h ../include/io.h ../include/misc.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h ../version.h
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
fe.o: fe.c resize.h ../include/io.h ../include/misc.h ../include/swab.h \
|
||||
../include/reiserfs_lib.h ../include/reiserfs_fs.h \
|
||||
../include/config.h ../version.h
|
||||
resize_reiserfs.o: resize_reiserfs.c resize.h ../include/io.h \
|
||||
../include/misc.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../version.h
|
||||
../include/misc.h ../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
|
||||
+67
-68
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
#include <time.h>
|
||||
#include "resize.h"
|
||||
#include <time.h>
|
||||
|
||||
|
||||
static unsigned long int_node_cnt = 0, int_moved_cnt = 0;
|
||||
@@ -15,33 +15,31 @@ static unsigned long unused_block;
|
||||
static unsigned long blocks_used;
|
||||
static int block_count_mismatch = 0;
|
||||
|
||||
static reiserfs_bitmap_t bmp;
|
||||
static reiserfs_filsys_t fs;
|
||||
static struct reiserfs_super_block * rs;
|
||||
static reiserfs_bitmap_t * bmp;
|
||||
static struct reiserfs_super_block * ondisk_sb;
|
||||
|
||||
/* abnornal exit from block reallocation process */
|
||||
static void quit_resizer()
|
||||
static void quit_resizer(reiserfs_filsys_t * fs)
|
||||
{
|
||||
/* save changes to bitmap blocks */
|
||||
reiserfs_flush_bitmap (bmp, fs);
|
||||
reiserfs_close (fs);
|
||||
/* leave fs in ERROR state */
|
||||
die ("resize_reiserfs: fs shrinking was not completed successfully, run reiserfsck.\n");
|
||||
DIE ("fs shrinking was not completed successfully, run reiserfsck.");
|
||||
}
|
||||
|
||||
/* block moving */
|
||||
static unsigned long move_generic_block(unsigned long block, unsigned long bnd, int h)
|
||||
static unsigned long move_generic_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h)
|
||||
{
|
||||
struct buffer_head * bh, * bh2;
|
||||
|
||||
/* primitive fsck */
|
||||
if (block > rs_block_count(rs)) {
|
||||
if (block > get_sb_block_count(ondisk_sb)) {
|
||||
fprintf(stderr, "resize_reiserfs: invalid block number (%lu) found.\n", block);
|
||||
quit_resizer();
|
||||
quit_resizer(fs);
|
||||
}
|
||||
/* progress bar, 3D style :) */
|
||||
if (opt_verbose)
|
||||
print_how_far(&total_node_cnt, blocks_used, 1, 0);
|
||||
print_how_far(stderr, &total_node_cnt, blocks_used, 1, 0);
|
||||
else
|
||||
total_node_cnt ++;
|
||||
|
||||
@@ -55,16 +53,16 @@ static unsigned long move_generic_block(unsigned long block, unsigned long bnd,
|
||||
return 0;
|
||||
|
||||
/* move wrong block */
|
||||
bh = bread(fs->s_dev, block, fs->s_blocksize);
|
||||
bh = bread(fs->fs_dev, block, fs->fs_blocksize);
|
||||
|
||||
reiserfs_bitmap_find_zero_bit(bmp, &unused_block);
|
||||
if (unused_block == 0 || unused_block >= bnd) {
|
||||
fputs ("resize_reiserfs: can\'t find free block\n", stderr);
|
||||
quit_resizer();
|
||||
quit_resizer(fs);
|
||||
}
|
||||
|
||||
/* blocknr changing */
|
||||
bh2 = getblk(fs->s_dev, unused_block, fs->s_blocksize);
|
||||
bh2 = getblk(fs->fs_dev, unused_block, fs->fs_blocksize);
|
||||
memcpy(bh2->b_data, bh->b_data, bh2->b_size);
|
||||
reiserfs_bitmap_clear_bit(bmp, block);
|
||||
reiserfs_bitmap_set_bit(bmp, unused_block);
|
||||
@@ -79,11 +77,11 @@ static unsigned long move_generic_block(unsigned long block, unsigned long bnd,
|
||||
return unused_block;
|
||||
}
|
||||
|
||||
static unsigned long move_unformatted_block(unsigned long block, unsigned long bnd, int h)
|
||||
static unsigned long move_unformatted_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h)
|
||||
{
|
||||
unsigned long b;
|
||||
unfm_node_cnt++;
|
||||
b = move_generic_block(block, bnd, h);
|
||||
b = move_generic_block(fs, block, bnd, h);
|
||||
if (b)
|
||||
unfm_moved_cnt++;
|
||||
return b;
|
||||
@@ -91,7 +89,7 @@ static unsigned long move_unformatted_block(unsigned long block, unsigned long b
|
||||
|
||||
|
||||
/* recursive function processing all tree nodes */
|
||||
static unsigned long move_formatted_block(unsigned long block, unsigned long bnd, int h)
|
||||
static unsigned long move_formatted_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
struct item_head *ih;
|
||||
@@ -99,7 +97,9 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
|
||||
int node_is_internal = 0;
|
||||
int i, j;
|
||||
|
||||
bh = bread(fs->s_dev, block, fs->s_blocksize);
|
||||
bh = bread(fs->fs_dev, block, fs->fs_blocksize);
|
||||
if (!bh)
|
||||
reiserfs_panic ("move_formatted_block: bread failed");
|
||||
|
||||
if (is_leaf_node (bh)) {
|
||||
|
||||
@@ -116,7 +116,7 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
|
||||
|
||||
if (indirect [j] == 0) /* hole */
|
||||
continue;
|
||||
unfm_block = move_unformatted_block(le32_to_cpu (indirect [j]), bnd, h + 1);
|
||||
unfm_block = move_unformatted_block(fs, le32_to_cpu (indirect [j]), bnd, h + 1);
|
||||
if (unfm_block) {
|
||||
indirect [j] = cpu_to_le32 (unfm_block);
|
||||
mark_buffer_dirty(bh);
|
||||
@@ -131,14 +131,14 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
|
||||
|
||||
for (i=0; i <= B_NR_ITEMS(bh); i++) {
|
||||
unsigned long moved_block;
|
||||
moved_block = move_formatted_block(B_N_CHILD_NUM(bh, i), bnd, h+1);
|
||||
moved_block = move_formatted_block(fs, get_dc_child_blocknr (B_N_CHILD (bh, i)), bnd, h+1);
|
||||
if (moved_block) {
|
||||
set_dc_block_number (bh, i, moved_block);
|
||||
set_dc_child_blocknr (B_N_CHILD (bh, i), moved_block);
|
||||
mark_buffer_dirty(bh);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
die ("resize_reiserfs: block (%lu) has invalid format\n", block);
|
||||
DIE ("block (%lu) has invalid format\n", block);
|
||||
}
|
||||
|
||||
if (buffer_dirty(bh)) {
|
||||
@@ -148,7 +148,7 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
|
||||
|
||||
brelse(bh);
|
||||
|
||||
new_blocknr = move_generic_block(block, bnd, h);
|
||||
new_blocknr = move_generic_block(fs, block, bnd, h);
|
||||
if (new_blocknr) {
|
||||
if (node_is_internal)
|
||||
int_moved_cnt++;
|
||||
@@ -159,14 +159,13 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
|
||||
return new_blocknr;
|
||||
}
|
||||
|
||||
int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
|
||||
int shrink_fs(reiserfs_filsys_t * fs, unsigned long blocks)
|
||||
{
|
||||
unsigned long n_root_block;
|
||||
unsigned int bmap_nr_new;
|
||||
unsigned long int i;
|
||||
|
||||
fs = reiserfs;
|
||||
rs = fs->s_rs;
|
||||
|
||||
ondisk_sb = fs->fs_ondisk_sb;
|
||||
|
||||
/* warn about alpha version */
|
||||
{
|
||||
@@ -178,37 +177,40 @@ int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
|
||||
"Backup of you data is recommended.\n\n"
|
||||
"Do you want to continue? [y/N]:"
|
||||
);
|
||||
fflush(stdout);
|
||||
c = getchar();
|
||||
if (c != 'y' && c != 'Y')
|
||||
exit(1);
|
||||
}
|
||||
|
||||
bmap_nr_new = (blocks - 1) / (8 * fs->s_blocksize) + 1;
|
||||
bmap_nr_new = (blocks - 1) / (8 * fs->fs_blocksize) + 1;
|
||||
|
||||
/* is shrinking possible ? */
|
||||
if (rs_block_count(rs) - blocks > rs_free_blocks(rs) + rs_bmap_nr(rs) - bmap_nr_new) {
|
||||
if (get_sb_block_count(ondisk_sb) - blocks > get_sb_free_blocks(ondisk_sb) + get_sb_bmap_nr(ondisk_sb) - bmap_nr_new) {
|
||||
fprintf(stderr, "resize_reiserfs: can\'t shrink fs; too many blocks already allocated\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
reiserfs_reopen(fs, O_RDWR);
|
||||
set_state (fs->s_rs, REISERFS_ERROR_FS);
|
||||
mark_buffer_uptodate(SB_BUFFER_WITH_SB(fs), 1);
|
||||
mark_buffer_dirty(SB_BUFFER_WITH_SB(fs));
|
||||
bwrite(SB_BUFFER_WITH_SB(fs));
|
||||
if (!reiserfs_open_ondisk_bitmap (fs))
|
||||
DIE("cannot open ondisk bitmap");
|
||||
bmp = fs->fs_bitmap2;
|
||||
ondisk_sb = fs->fs_ondisk_sb;
|
||||
|
||||
set_sb_fs_state (fs->fs_ondisk_sb, REISERFS_CORRUPTED);
|
||||
mark_buffer_uptodate(fs->fs_super_bh, 1);
|
||||
mark_buffer_dirty(fs->fs_super_bh);
|
||||
bwrite(fs->fs_super_bh);
|
||||
|
||||
/* calculate number of data blocks */
|
||||
blocks_used =
|
||||
SB_BLOCK_COUNT(fs)
|
||||
- SB_FREE_BLOCKS(fs)
|
||||
- SB_BMAP_NR(fs)
|
||||
- SB_JOURNAL_SIZE(fs)
|
||||
- REISERFS_DISK_OFFSET_IN_BYTES / fs->s_blocksize
|
||||
get_sb_block_count(fs->fs_ondisk_sb)
|
||||
- get_sb_free_blocks(fs->fs_ondisk_sb)
|
||||
- get_sb_bmap_nr(fs->fs_ondisk_sb)
|
||||
- get_jp_journal_size(sb_jp (fs->fs_ondisk_sb))
|
||||
- REISERFS_DISK_OFFSET_IN_BYTES / fs->fs_blocksize
|
||||
- 2; /* superblock itself and 1 descriptor after the journal */
|
||||
|
||||
bmp = reiserfs_create_bitmap(rs_block_count(rs));
|
||||
reiserfs_fetch_disk_bitmap(bmp, fs);
|
||||
|
||||
unused_block = 1;
|
||||
|
||||
if (opt_verbose) {
|
||||
@@ -216,9 +218,9 @@ int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
n_root_block = move_formatted_block(rs_root_block(rs), blocks, 0);
|
||||
n_root_block = move_formatted_block(fs, get_sb_root_block(ondisk_sb), blocks, 0);
|
||||
if (n_root_block) {
|
||||
set_root_block (rs, n_root_block);
|
||||
set_sb_root_block (ondisk_sb, n_root_block);
|
||||
}
|
||||
|
||||
if (opt_verbose)
|
||||
@@ -237,33 +239,30 @@ int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
|
||||
" doesn\'t match data block count %lu from super block\n",
|
||||
(unsigned long)total_node_cnt, blocks_used);
|
||||
}
|
||||
#if 0
|
||||
printf("check for used blocks in truncated region\n");
|
||||
|
||||
#if 1
|
||||
{
|
||||
unsigned long l;
|
||||
for (l = blocks; l < rs_block_count(rs); l++)
|
||||
if (is_block_used(bmp, l))
|
||||
printf("<%lu>", l);
|
||||
printf("\n");
|
||||
unsigned long l;
|
||||
|
||||
/* make sure that none of truncated block are in use */
|
||||
printf("check for used blocks in truncated region\n");
|
||||
for (l = blocks; l < fs->fs_bitmap2->bm_bit_size; l ++) {
|
||||
if ((l % (fs->fs_blocksize * 8)) == 0)
|
||||
continue;
|
||||
if (reiserfs_bitmap_test_bit (fs->fs_bitmap2, l))
|
||||
printf ("<%lu>", l);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
reiserfs_free_bitmap_blocks(fs);
|
||||
|
||||
set_free_blocks (rs, rs_free_blocks(rs) - (rs_block_count(rs) - blocks) + (rs_bmap_nr(rs) - bmap_nr_new));
|
||||
set_block_count (rs, blocks);
|
||||
set_bmap_nr (rs, bmap_nr_new);
|
||||
|
||||
reiserfs_read_bitmap_blocks(fs);
|
||||
|
||||
for (i = blocks; i < bmap_nr_new * fs->s_blocksize; i++)
|
||||
reiserfs_bitmap_set_bit(bmp, i);
|
||||
#if 0
|
||||
PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (SB_BLOCK_COUNT(s) - blocks) + (SB_BMAP_NR(s) - bmap_nr_new));
|
||||
PUT_SB_BLOCK_COUNT(s, blocks);
|
||||
PUT_SB_BMAP_NR(s, bmap_nr_new);
|
||||
#endif
|
||||
reiserfs_flush_bitmap(bmp, fs);
|
||||
|
||||
reiserfs_shrink_bitmap (fs->fs_bitmap2, blocks);
|
||||
|
||||
set_sb_free_blocks (ondisk_sb, get_sb_free_blocks(ondisk_sb)
|
||||
- (get_sb_block_count(ondisk_sb) - blocks)
|
||||
+ (get_sb_bmap_nr(ondisk_sb) - bmap_nr_new));
|
||||
set_sb_block_count (ondisk_sb, blocks);
|
||||
set_sb_bmap_nr (ondisk_sb, bmap_nr_new);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#include "resize.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
@@ -24,25 +24,28 @@
|
||||
#include "io.h"
|
||||
#include "misc.h"
|
||||
#include "reiserfs_lib.h"
|
||||
#include "../include/config.h"
|
||||
#include "../version.h"
|
||||
|
||||
|
||||
#define print_usage_and_exit()\
|
||||
die ("Usage: %s [-s[+|-]#[G|M|K]] [-fqv] device", argv[0])
|
||||
#define print_usage_and_exit() {\
|
||||
fprintf (stderr, "Usage: %s [-s[+|-]#[G|M|K]] [-fqv] device\n\n", argv[0]);\
|
||||
exit(16);\
|
||||
}
|
||||
|
||||
#define DIE(form, args...) die("%s: " form "\n", g_progname , ## args)
|
||||
|
||||
/* reiserfs_resize.c */
|
||||
extern struct buffer_head * g_sb_bh;
|
||||
extern char * g_progname;
|
||||
|
||||
extern int opt_force;
|
||||
extern int opt_verbose;
|
||||
extern int opt_nowrite;
|
||||
extern int opt_safe;
|
||||
|
||||
int expand_fs(struct super_block * s, unsigned long block_count_new);
|
||||
|
||||
/* fe.c */
|
||||
int resize_fs_online(char * devname, unsigned long blocks);
|
||||
|
||||
/* do_shrink.c */
|
||||
int shrink_fs(struct super_block * s, unsigned long blocks);
|
||||
int shrink_fs(reiserfs_filsys_t *, unsigned long blocks);
|
||||
@@ -1,14 +1,17 @@
|
||||
.\" -*- nroff -*-
|
||||
.\" Copyright 1996-2001 Hans Reiser.
|
||||
.\" Copyright 1996-2002 Hans Reiser.
|
||||
.\"
|
||||
.TH RESIZE_REISERFS 8 "March 2001" "Reiserfsprogs-3.x.0j"
|
||||
.TH RESIZE_REISERFS 8 "January 2002" "Reiserfsprogs-3.6.2"
|
||||
.SH NAME
|
||||
resize_reiserfs \- Reiserfs filesystem resizer
|
||||
.SH SYNOPSIS
|
||||
.BR resize_reiserfs
|
||||
[
|
||||
.B \-s
|
||||
.IR \fR[\fB+\fR|\fB\- ]\fIsize [\fBK\fR|\fBM\fR|\fBG\fR]
|
||||
.IR \fR[\fB+\fR|\fB\- ]\fIsize\fB[\fBK\fR|\fBM\fR|\fBG\fR]
|
||||
] [
|
||||
.B \-j
|
||||
.IR \fR\fIdev
|
||||
] [
|
||||
.B \-fqv
|
||||
]
|
||||
@@ -68,6 +71,9 @@ you do not make it smaller than the reduced size of the reiserfs filesystem.
|
||||
.BR \-s\ [+|\-]\fIsize
|
||||
Set the new size in bytes.
|
||||
.TP
|
||||
.BR \-j\ \fIdev
|
||||
Set the journal device name.
|
||||
.TP
|
||||
.BR \-f
|
||||
Force, do not perform checks.
|
||||
.TP
|
||||
@@ -112,5 +118,6 @@ has been written by Alexander Zarochentcev <zam@namesys.com>.
|
||||
Please, report about the bugs to Alexander Zarochentcev <zam@namesys.com> or
|
||||
to Hans Reiser <reiser@namesys.com>.
|
||||
.SH SEE ALSO
|
||||
.BR cfsck (8),
|
||||
.BR cfdisk (8),
|
||||
.BR reiserfsck (8),
|
||||
.BR debugreiserfs (8)
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -10,29 +10,15 @@
|
||||
*/
|
||||
|
||||
#include "resize.h"
|
||||
#include <libgen.h>
|
||||
|
||||
int opt_force = 0;
|
||||
int opt_verbose = 1; /* now "verbose" option is default */
|
||||
int opt_nowrite = 0;
|
||||
int opt_safe = 0;
|
||||
int opt_skipj = 0;
|
||||
|
||||
#if 0
|
||||
/* Given a file descriptor and an offset, check whether the offset is
|
||||
a valid offset for the file - return 0 if it isn't valid or 1 if it
|
||||
is */
|
||||
int valid_offset( int fd, loff_t offset )
|
||||
{
|
||||
char ch;
|
||||
|
||||
if (lseek64 (fd, offset, 0) < 0)
|
||||
return 0;
|
||||
|
||||
if (read (fd, &ch, 1) < 1)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
char * g_progname;
|
||||
|
||||
/* calculate the new fs size (in blocks) from old fs size and the string
|
||||
representation of new size */
|
||||
@@ -76,10 +62,10 @@ static void sb_report(struct reiserfs_super_block * sb1,
|
||||
"block count %d (%d)\n"
|
||||
"free blocks %d (%d)\n"
|
||||
"bitmap block count %d (%d)\n",
|
||||
rs_blocksize(sb1),
|
||||
rs_block_count(sb1), rs_block_count(sb2),
|
||||
rs_free_blocks(sb1), rs_free_blocks(sb2),
|
||||
rs_bmap_nr(sb1), rs_bmap_nr(sb2));
|
||||
get_sb_block_size(sb1),
|
||||
get_sb_block_count(sb1), get_sb_block_count(sb2),
|
||||
get_sb_free_blocks(sb1), get_sb_free_blocks(sb2),
|
||||
get_sb_bmap_nr(sb1), get_sb_bmap_nr(sb2));
|
||||
};
|
||||
|
||||
/* conditional bwrite */
|
||||
@@ -94,62 +80,63 @@ static int bwrite_cond (struct buffer_head * bh)
|
||||
}
|
||||
|
||||
|
||||
/* the first one of the mainest functions */
|
||||
int expand_fs (reiserfs_filsys_t fs, unsigned long block_count_new) {
|
||||
int block_r, block_r_new;
|
||||
/* the first one of the most important functions */
|
||||
static int expand_fs (reiserfs_filsys_t * fs, unsigned long block_count_new) {
|
||||
unsigned int bmap_nr_new, bmap_nr_old;
|
||||
int i;
|
||||
struct reiserfs_super_block * sb;
|
||||
|
||||
reiserfs_bitmap_t bmp;
|
||||
struct reiserfs_super_block * rs = fs->s_rs;
|
||||
|
||||
reiserfs_reopen(fs, O_RDWR);
|
||||
set_state (fs->s_rs, REISERFS_ERROR_FS);
|
||||
bwrite_cond(SB_BUFFER_WITH_SB(fs));
|
||||
if (!reiserfs_open_ondisk_bitmap (fs))
|
||||
DIE("cannot open ondisk bitmap");
|
||||
|
||||
bmp = reiserfs_create_bitmap(rs_block_count(rs));
|
||||
if (!bmp)
|
||||
die ("cannot create bitmap\n");
|
||||
reiserfs_fetch_disk_bitmap(bmp, fs);
|
||||
reiserfs_free_bitmap_blocks(fs);
|
||||
if (reiserfs_expand_bitmap(bmp, block_count_new))
|
||||
die ("cannot expand bitmap\n");
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
/* clean bits in old bitmap tail */
|
||||
for (i = rs_block_count(rs);
|
||||
i < rs_bmap_nr(rs) * rs_blocksize(rs) * 8 && i < block_count_new;
|
||||
i++) {
|
||||
reiserfs_bitmap_clear_bit(bmp, i);
|
||||
}
|
||||
set_sb_fs_state (fs->fs_ondisk_sb, REISERFS_CORRUPTED);
|
||||
|
||||
bwrite_cond(fs->fs_super_bh);
|
||||
|
||||
|
||||
if (reiserfs_expand_bitmap(fs->fs_bitmap2, block_count_new))
|
||||
DIE("cannot expand bitmap\n");
|
||||
|
||||
/* count used bits in last bitmap block */
|
||||
block_r = rs_block_count(rs) - ((rs_bmap_nr(rs) - 1) * rs_blocksize(rs) * 8);
|
||||
|
||||
/* count bitmap blocks in new fs */
|
||||
bmap_nr_new = (block_count_new - 1) / (rs_blocksize(rs) * 8) + 1;
|
||||
block_r_new = block_count_new - (bmap_nr_new - 1) * rs_blocksize(rs) * 8;
|
||||
|
||||
bmap_nr_old = rs_bmap_nr(rs);
|
||||
bmap_nr_new = (block_count_new - 1) / (fs->fs_blocksize * 8) + 1;
|
||||
bmap_nr_old = get_sb_bmap_nr(sb);
|
||||
|
||||
/* update super block buffer*/
|
||||
set_free_blocks (rs, rs_free_blocks(rs) + block_count_new
|
||||
- rs_block_count(rs) - (bmap_nr_new - rs_bmap_nr(rs)));
|
||||
set_block_count (rs, block_count_new);
|
||||
set_bmap_nr (rs, bmap_nr_new);
|
||||
set_sb_free_blocks (sb, get_sb_free_blocks(sb) +
|
||||
(block_count_new - get_sb_block_count(sb)) -
|
||||
(bmap_nr_new - bmap_nr_old));
|
||||
set_sb_block_count (sb, block_count_new);
|
||||
set_sb_bmap_nr (sb, bmap_nr_new);
|
||||
|
||||
reiserfs_read_bitmap_blocks(fs);
|
||||
for (i = bmap_nr_old; i < bmap_nr_new; i++) /* fix new bitmap blocks */
|
||||
reiserfs_bitmap_set_bit(bmp, SB_AP_BITMAP(fs)[i]->b_blocknr);
|
||||
reiserfs_flush_bitmap(bmp, fs);
|
||||
/* mark new bitmap blocks as used */
|
||||
for (i = bmap_nr_old; i < bmap_nr_new; i++)
|
||||
reiserfs_bitmap_set_bit (fs->fs_bitmap2, i * fs->fs_blocksize * 8);
|
||||
|
||||
/* normally, this is done by reiserfs_bitmap_set_bit, but if we
|
||||
** haven't actually added any bitmap blocks, the bitmap won't be dirtied.
|
||||
**
|
||||
** In memory, reiserfsprogs puts zeros for the bits past the end of
|
||||
** the old filesystem. But, on disk that bitmap is full of ones.
|
||||
** we explicitly dirty the bitmap here to make sure the zeros get written
|
||||
** to disk
|
||||
*/
|
||||
fs->fs_bitmap2->bm_dirty = 1 ;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char * bytes_count_str = NULL;
|
||||
char * devname;
|
||||
reiserfs_filsys_t fs;
|
||||
struct reiserfs_super_block * rs;
|
||||
char * jdevice_name = NULL;
|
||||
reiserfs_filsys_t * fs;
|
||||
struct reiserfs_super_block * sb;
|
||||
|
||||
int c;
|
||||
int error;
|
||||
@@ -158,15 +145,20 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
unsigned long block_count_new;
|
||||
|
||||
print_banner ("resize_reiserfs");
|
||||
g_progname = basename(argv[0]);
|
||||
print_banner (g_progname);
|
||||
|
||||
while ((c = getopt(argc, argv, "fvcqs:")) != EOF) {
|
||||
while ((c = getopt(argc, argv, "fvcqks:j:")) != EOF) {
|
||||
switch (c) {
|
||||
case 's' :
|
||||
if (!optarg)
|
||||
die("%s: Missing argument to -s option", argv[0]);
|
||||
DIE("Missing argument to -s option");
|
||||
bytes_count_str = optarg;
|
||||
break;
|
||||
case 'j' :
|
||||
if (!optarg)
|
||||
DIE("Missing argument to -j option");
|
||||
jdevice_name = optarg;
|
||||
case 'f':
|
||||
opt_force = 1;
|
||||
break;
|
||||
@@ -183,6 +175,9 @@ int main(int argc, char *argv[]) {
|
||||
case 'q':
|
||||
opt_verbose = 0;
|
||||
break;
|
||||
case 'k':
|
||||
opt_skipj = 1;
|
||||
break;
|
||||
default:
|
||||
print_usage_and_exit ();
|
||||
}
|
||||
@@ -194,21 +189,27 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
fs = reiserfs_open(devname, O_RDONLY, &error, 0);
|
||||
if (!fs)
|
||||
die ("%s: can not open '%s': %s", argv[0], devname, strerror(error));
|
||||
DIE ("cannot open '%s': %s", devname, strerror(error));
|
||||
if (!reiserfs_open_journal (fs, jdevice_name, O_RDONLY)) {
|
||||
if (!opt_skipj)
|
||||
DIE ("can not open journal of '%s'", devname);
|
||||
}
|
||||
|
||||
/* forced to continue without journal available/specified */
|
||||
|
||||
if (no_reiserfs_found (fs)) {
|
||||
die ("resize_reiserfs: no reiserfs found on the device");
|
||||
DIE ("no reiserfs found on the device.");
|
||||
}
|
||||
if (!spread_bitmaps (fs)) {
|
||||
die ("resize_reiserfs: cannot resize reiserfs in old (not spread bitmap) format.\n");
|
||||
DIE ("cannot resize reiserfs in old (not spread bitmap) format.");
|
||||
}
|
||||
|
||||
rs = fs->s_rs;
|
||||
sb = fs->fs_ondisk_sb;
|
||||
|
||||
if(bytes_count_str) { /* new fs size is specified by user */
|
||||
block_count_new = calc_new_fs_size(rs_block_count(rs), fs->s_blocksize, bytes_count_str);
|
||||
block_count_new = calc_new_fs_size(get_sb_block_count(sb), fs->fs_blocksize, bytes_count_str);
|
||||
} else { /* use whole device */
|
||||
block_count_new = count_blocks(devname, fs->s_blocksize, -1);
|
||||
block_count_new = count_blocks(devname, fs->fs_blocksize);
|
||||
}
|
||||
|
||||
if (is_mounted (devname)) {
|
||||
@@ -216,34 +217,50 @@ int main(int argc, char *argv[]) {
|
||||
return resize_fs_online(devname, block_count_new);
|
||||
}
|
||||
|
||||
if (rs_state(rs) != REISERFS_VALID_FS)
|
||||
die ("%s: the file system isn't in valid state\n", argv[0]);
|
||||
if (!reiserfs_is_fs_consistent (fs)) {
|
||||
reiserfs_warning (stderr, "\n\nresize_reiserfs: run reiserfsck --check first\n\n");
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (get_sb_umount_state(sb) != REISERFS_CLEANLY_UMOUNTED)
|
||||
/* fixme: shouldn't we check for something like: fsck guarantees: fs is ok */
|
||||
DIE ("the file system isn't in valid state.");
|
||||
|
||||
if (block_count_new >= get_sb_block_count(sb)) {
|
||||
if (block_count_new == get_sb_block_count(sb)) {
|
||||
reiserfs_warning (stderr, "%s already is of the needed size. Nothing to be done\n\n", devname);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if(!valid_offset(fs->fs_dev, (loff_t) block_count_new * fs->fs_blocksize - 1)) {
|
||||
reiserfs_warning (stderr, "%s is of %lu blocks size only with reiserfs of %d blocks\nsize on it. "\
|
||||
"You are trying to expant reiserfs up to %lu blocks size.\nYou probably forgot to expand your "\
|
||||
"partition size.\n\n", devname, count_blocks (devname, fs->fs_blocksize),
|
||||
get_sb_block_count(sb), block_count_new);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
if(!valid_offset(fs->s_dev, (loff_t) block_count_new * fs->s_blocksize - 1))
|
||||
die ("%s: %s too small", argv[0], devname);
|
||||
|
||||
sb_old = 0; /* Needed to keep idiot compiler from issuing false warning */
|
||||
/* save SB for reporting */
|
||||
if(opt_verbose) {
|
||||
sb_old = getmem(SB_SIZE);
|
||||
memcpy(sb_old, SB_DISK_SUPER_BLOCK(fs), SB_SIZE);
|
||||
memcpy(sb_old, fs->fs_ondisk_sb, SB_SIZE);
|
||||
}
|
||||
|
||||
if (block_count_new == SB_BLOCK_COUNT(fs))
|
||||
die ("%s: Calculated fs size is the same as the previous one.", argv[0]);
|
||||
|
||||
if (block_count_new > SB_BLOCK_COUNT(fs))
|
||||
expand_fs(fs, block_count_new);
|
||||
else
|
||||
shrink_fs(fs, block_count_new);
|
||||
error = (block_count_new > get_sb_block_count(fs->fs_ondisk_sb)) ? expand_fs(fs, block_count_new) : shrink_fs(fs, block_count_new);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if(opt_verbose) {
|
||||
sb_report(rs, sb_old);
|
||||
sb_report(fs->fs_ondisk_sb, sb_old);
|
||||
freemem(sb_old);
|
||||
}
|
||||
|
||||
set_state (rs, REISERFS_VALID_FS);
|
||||
bwrite_cond(SB_BUFFER_WITH_SB(fs));
|
||||
set_sb_fs_state (fs->fs_ondisk_sb, REISERFS_CONSISTENT);
|
||||
bwrite_cond(fs->fs_super_bh);
|
||||
|
||||
if (opt_verbose) {
|
||||
printf("\nSyncing..");
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
sbin_PROGRAMS = reiserfstune
|
||||
|
||||
reiserfstune_SOURCES = tune.c tune.h
|
||||
|
||||
man_MANS = reiserfstune.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
SHELL = @SHELL@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
libexecdir = @libexecdir@
|
||||
datadir = @datadir@
|
||||
sysconfdir = @sysconfdir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
localstatedir = @localstatedir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
mandir = @mandir@
|
||||
includedir = @includedir@
|
||||
oldincludedir = /usr/include
|
||||
|
||||
DESTDIR =
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
|
||||
top_builddir = ..
|
||||
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
transform = @program_transform_name@
|
||||
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
CC = @CC@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
sbindir = @sbindir@
|
||||
|
||||
sbin_PROGRAMS = reiserfstune
|
||||
|
||||
reiserfstune_SOURCES = tune.c tune.h
|
||||
|
||||
man_MANS = reiserfstune.8
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
||||
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
PROGRAMS = $(sbin_PROGRAMS)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
reiserfstune_OBJECTS = tune.o
|
||||
reiserfstune_LDADD = $(LDADD)
|
||||
reiserfstune_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
|
||||
$(top_srcdir)/reiserfscore/libcore.a
|
||||
reiserfstune_LDFLAGS =
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
man8dir = $(mandir)/man8
|
||||
MANS = $(man_MANS)
|
||||
|
||||
NROFF = nroff
|
||||
DIST_COMMON = Makefile.am Makefile.in
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = tar
|
||||
GZIP_ENV = --best
|
||||
SOURCES = $(reiserfstune_SOURCES)
|
||||
OBJECTS = $(reiserfstune_OBJECTS)
|
||||
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .S .c .o .s
|
||||
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps tune/Makefile
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
|
||||
mostlyclean-sbinPROGRAMS:
|
||||
|
||||
clean-sbinPROGRAMS:
|
||||
-test -z "$(sbin_PROGRAMS)" || rm -f $(sbin_PROGRAMS)
|
||||
|
||||
distclean-sbinPROGRAMS:
|
||||
|
||||
maintainer-clean-sbinPROGRAMS:
|
||||
|
||||
install-sbinPROGRAMS: $(sbin_PROGRAMS)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(mkinstalldirs) $(DESTDIR)$(sbindir)
|
||||
@list='$(sbin_PROGRAMS)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
|
||||
$(INSTALL_PROGRAM) $$p $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-sbinPROGRAMS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
list='$(sbin_PROGRAMS)'; for p in $$list; do \
|
||||
rm -f $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
|
||||
done
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.s.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.S.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.o core *.core
|
||||
|
||||
clean-compile:
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
maintainer-clean-compile:
|
||||
|
||||
reiserfstune: $(reiserfstune_OBJECTS) $(reiserfstune_DEPENDENCIES)
|
||||
@rm -f reiserfstune
|
||||
$(LINK) $(reiserfstune_LDFLAGS) $(reiserfstune_OBJECTS) $(reiserfstune_LDADD) $(LIBS)
|
||||
|
||||
install-man8:
|
||||
$(mkinstalldirs) $(DESTDIR)$(man8dir)
|
||||
@list='$(man8_MANS)'; \
|
||||
l2='$(man_MANS)'; for i in $$l2; do \
|
||||
case "$$i" in \
|
||||
*.8*) list="$$list $$i" ;; \
|
||||
esac; \
|
||||
done; \
|
||||
for i in $$list; do \
|
||||
if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \
|
||||
else file=$$i; fi; \
|
||||
ext=`echo $$i | sed -e 's/^.*\\.//'`; \
|
||||
inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
|
||||
inst=`echo $$inst | sed '$(transform)'`.$$ext; \
|
||||
echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man8dir)/$$inst"; \
|
||||
$(INSTALL_DATA) $$file $(DESTDIR)$(man8dir)/$$inst; \
|
||||
done
|
||||
|
||||
uninstall-man8:
|
||||
@list='$(man8_MANS)'; \
|
||||
l2='$(man_MANS)'; for i in $$l2; do \
|
||||
case "$$i" in \
|
||||
*.8*) list="$$list $$i" ;; \
|
||||
esac; \
|
||||
done; \
|
||||
for i in $$list; do \
|
||||
ext=`echo $$i | sed -e 's/^.*\\.//'`; \
|
||||
inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
|
||||
inst=`echo $$inst | sed '$(transform)'`.$$ext; \
|
||||
echo " rm -f $(DESTDIR)$(man8dir)/$$inst"; \
|
||||
rm -f $(DESTDIR)$(man8dir)/$$inst; \
|
||||
done
|
||||
install-man: $(MANS)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(MAKE) $(AM_MAKEFLAGS) install-man8
|
||||
uninstall-man:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
$(MAKE) $(AM_MAKEFLAGS) uninstall-man8
|
||||
|
||||
tags: TAGS
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
here=`pwd` && cd $(srcdir) \
|
||||
&& mkid -f$$here/ID $$unique $(LISP)
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|
||||
|
||||
mostlyclean-tags:
|
||||
|
||||
clean-tags:
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID
|
||||
|
||||
maintainer-clean-tags:
|
||||
|
||||
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
|
||||
|
||||
subdir = tune
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
fi; \
|
||||
done
|
||||
tune.o: tune.c tune.h ../include/io.h ../include/misc.h \
|
||||
../include/swab.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../include/config.h ../version.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
dvi-am:
|
||||
dvi: dvi-am
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
installcheck-am:
|
||||
installcheck: installcheck-am
|
||||
install-exec-am: install-sbinPROGRAMS
|
||||
install-exec: install-exec-am
|
||||
|
||||
install-data-am: install-man
|
||||
install-data: install-data-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
install: install-am
|
||||
uninstall-am: uninstall-sbinPROGRAMS uninstall-man
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(PROGRAMS) $(MANS)
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
installdirs:
|
||||
$(mkinstalldirs) $(DESTDIR)$(sbindir) $(DESTDIR)$(mandir)/man8
|
||||
|
||||
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-rm -f Makefile $(CONFIG_CLEAN_FILES)
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
mostlyclean-am: mostlyclean-sbinPROGRAMS mostlyclean-compile \
|
||||
mostlyclean-tags mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
clean-am: clean-sbinPROGRAMS clean-compile clean-tags clean-generic \
|
||||
mostlyclean-am
|
||||
|
||||
clean: clean-am
|
||||
|
||||
distclean-am: distclean-sbinPROGRAMS distclean-compile distclean-tags \
|
||||
distclean-generic clean-am
|
||||
|
||||
distclean: distclean-am
|
||||
|
||||
maintainer-clean-am: maintainer-clean-sbinPROGRAMS \
|
||||
maintainer-clean-compile maintainer-clean-tags \
|
||||
maintainer-clean-generic distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: mostlyclean-sbinPROGRAMS distclean-sbinPROGRAMS \
|
||||
clean-sbinPROGRAMS maintainer-clean-sbinPROGRAMS uninstall-sbinPROGRAMS \
|
||||
install-sbinPROGRAMS mostlyclean-compile distclean-compile \
|
||||
clean-compile maintainer-clean-compile install-man8 uninstall-man8 \
|
||||
install-man uninstall-man tags mostlyclean-tags distclean-tags \
|
||||
clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \
|
||||
check-am installcheck-am installcheck install-exec-am install-exec \
|
||||
install-data-am install-data install-am install uninstall-am uninstall \
|
||||
all-redirect all-am all installdirs mostlyclean-generic \
|
||||
distclean-generic clean-generic maintainer-clean-generic clean \
|
||||
mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
@@ -0,0 +1,147 @@
|
||||
.\" -*- nroff -*-
|
||||
.\" Copyright 1996-2002 Hans Reiser.
|
||||
.\"
|
||||
.TH REISERFSTUNE 8 "January 2002" "Reiserfsprogs-3.6.2"
|
||||
.SH NAME
|
||||
reiserfstune
|
||||
.SH SYNOPSIS
|
||||
.B reiserfstune
|
||||
[ \fB-f\fR ]
|
||||
[ \fB-j\fR | \fB--journal-device\fR \fIFILE\fR ]
|
||||
[ \fB--no-journal-available\fR ]
|
||||
[ \fB--journal-new-device\fR \fIFILE\fR ]
|
||||
[ \fB-s\fR | \fB--journal-new-size\fR \fIN\fR ]
|
||||
[ \fB-o\fR | \fB--journal-new-offset\fR \fIN\fR ]
|
||||
[ \fB-t\fR | \fB--max-transaction-size\fR \fIN\fR ]
|
||||
[ \fB-u\fR | \fB--uuid \fIUUID\fR ]
|
||||
[ \fB-l\fR | \fB--label \fILABEL\fR ]
|
||||
.I device
|
||||
.SH DESCRIPTION
|
||||
\fBreiserfstune\fR is used for tuning the ReiserFS
|
||||
journal. It can change two parameters (journal size and maximum
|
||||
transaction size), and it can move the journal's location to a new specified
|
||||
block device. (The old ReiserFS's journal may be
|
||||
kept unused, or discarded at the user's option.) Note: At the time of
|
||||
writing this feature was implemented for a special release of
|
||||
ReiserFS, and was not expected to be put into the mainstream kernel
|
||||
until approximately Linux 2.5. This means that if you have the stock
|
||||
kernel you must apply a special patch. Without this patch the kernel
|
||||
will refuse to mount the newly modified file system. We will charge
|
||||
$25 to explain this to you if you ask us why it doesn't work.
|
||||
.PP
|
||||
Perhaps the most interesting application of this code is to put the
|
||||
journal on a solid state disk.
|
||||
.TP
|
||||
\fIdevice
|
||||
is the special file corresponding to the newly specified block device (e.g
|
||||
/dev/hdXX for IDE disk partition or /dev/sdXX for the SCSI disk partition).
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB-j\fR | \fB--journal-device\fR \fIFILE
|
||||
\fIFILE\fR is the file name of the block device the file system has
|
||||
the current journal (the one prior to running reiserfstune) on. This option is required when the journal is
|
||||
already on a separate device from the main data device (although it
|
||||
can be avoided with \fB--no-journal-available\fR). If you don't
|
||||
specify journal device by this option, reiserfstune suppose that
|
||||
journal is on main device.
|
||||
.TP
|
||||
\fB--no-journal-available
|
||||
allows \fBreiserfstune\fR to continue when the current journal's block
|
||||
device is no longer available. This might happen if a disk goes bad
|
||||
and you remove it (and run fsck).
|
||||
.TP
|
||||
\fB--journal-new-device \fIFILE
|
||||
\fIFILE\fR is the file name of the block device which will contain the
|
||||
new journal for the file system. If you don't specify this,
|
||||
reiserfstune supposes that journal device remains the same.
|
||||
.TP
|
||||
\fB \-s\fR | \fB\--journal-new-size \fIN
|
||||
\fIN\fR is the size parameter for the new journal. When journal is to
|
||||
be on a separate device - its size defaults to number of blocks that
|
||||
device has. When journal is to be on the same device as the filesytem - its size defaults
|
||||
to amount of blocks allocated for journal by \fImkreiserfs\fR when it
|
||||
created the filesystem. Minimum is 513 for
|
||||
both cases.
|
||||
.TP
|
||||
\fB \-o\fR | \fB\--journal-new-offset \fIN
|
||||
\fIN\fR is an offset in blocks where journal will starts from when journal is to
|
||||
be on a separate device. Default is 0. Has no effect when journal is
|
||||
to be on the same device as the filesystem. Most users have no need
|
||||
to use this feature. It can be used when you want the journals from
|
||||
multiple filesystems to reside on the same device, and you don't want
|
||||
to or cannot partition that device.
|
||||
.TP
|
||||
\fB \-t\fR | \fB\--maximal-transaction-size \fIN
|
||||
\fI\fR is the maximum transaction size parameter for the new
|
||||
journal. The default, and max possible, value is 1024 blocks. It
|
||||
should be less than half the size of the journal. If specifed
|
||||
incorrectly, it will be adjusted.
|
||||
.TP
|
||||
\fB\-f\fR | \fB--force\fR
|
||||
Normally \fBreiserfstune\fR will refuse to change a journal of a
|
||||
file system that was created before this journal relocation code. This
|
||||
is because if you change the journal, you cannot go back (without special
|
||||
option \fB--make-journal-standard\fR) to an old kernel that lacks this feature and be able to use your filesytem. This option forces it to do that. Specified more
|
||||
than once it allows to avoid asking for confirmation.
|
||||
.TP
|
||||
\fB--make-journal-standard\fR
|
||||
As it was mentioned above, if your file system has non-standard journal,
|
||||
it can not be mounted on the kernel without journal relocation
|
||||
code. The thing can be changed, the only condition is that there is reserved
|
||||
area on main device of the standard journal size 8193 blocks (it will be so for
|
||||
instance if you convert standard journal to non-standard). Just
|
||||
specify this option when you relocate journal back, or without relocation
|
||||
if you already have it on main device.
|
||||
.TP
|
||||
\fB-u\fR | \fB--uuid \fIUUID\fR
|
||||
Set the universally unique identifier (\fB UUID \fR) of the filesystem to
|
||||
\fIUUID\fR (see also \fBuuidgen(8)\fR). The format of the UUID is a
|
||||
series of hex digits separated by hypthens, like this:
|
||||
"c1b9d5a2-f162-11cf-9ece-0020afc76f16".
|
||||
.TP
|
||||
\fB-l\fR | \fB--label \fILABEL\fR
|
||||
Set the volume label of the filesystem. \fILABEL\fR can be at most 16
|
||||
characters long; if it is longer than 16 characters, reiserfstune will truncate it.
|
||||
.SH POSSIBLE SCENARIOS OF USING REISERFSTUNE:
|
||||
1. You have ReiserFS on /dev/hda1, and you wish to have
|
||||
it working with its journal on the device /dev/journal
|
||||
.nf
|
||||
.IP
|
||||
boot kernel patched with special "relocatable journal support" patch
|
||||
reiserfstune /dev/hda1 --journal-new-device /dev/journal -f
|
||||
mount /dev/hda1 and use.
|
||||
You would like to change max transaction size to 512 blocks
|
||||
reiserfstune -t 512 /dev/hda1
|
||||
You would like to use your file system on another kernel that doesn't
|
||||
contain relocatable journal support.
|
||||
umount /dev/hda1
|
||||
reiserfstune /dev/hda1 -j /dev/journal --journal-new-device /dev/hda1 --make-journal-standard
|
||||
mount /dev/hda1 and use.
|
||||
.LP
|
||||
2. You would like to have ReiserFS on /dev/hda1 and to be able to
|
||||
switch between different journals including journal located on the
|
||||
device containing the filesystem.
|
||||
.nf
|
||||
.IP
|
||||
boot kernel patched with special "relocatable journal support" patch
|
||||
mkreiserfs /dev/hda1
|
||||
you got solid state disk (perhaps /dev/sda, they typically look like scsi disks)
|
||||
reiserfstune --journal-new-device /dev/sda1 -f /dev/hda1
|
||||
Your scsi device dies, it is three in the morning, you have an extra IDE device
|
||||
lying around
|
||||
reiserfsck --no-journal-available /dev/hda1
|
||||
or
|
||||
reiserfsck --rebuild-tree --no-journal-available /dev/hda1
|
||||
reiserfstune --no-journal-available --journal-new-device /dev/hda1 /dev/hda1
|
||||
using /dev/hda1 under patched kernel
|
||||
.SH AUTHOR
|
||||
This version of \fBreiserfstune\fR has been written by Vladimir
|
||||
Demidov <vova@namesys.com> and Edward Shishkin <edward@namesys.com>.
|
||||
.SH BUGS
|
||||
Please repoort bugs to the ReiserFS mail list <reiserfs-list@namesys.com>
|
||||
.SH SEE ALSO
|
||||
.BR reiserfsck (8),
|
||||
.BR debugreiserfs (8),
|
||||
.BR mkreiserfs (8)
|
||||
|
||||
|
||||
+563
@@ -0,0 +1,563 @@
|
||||
/*
|
||||
* Copyright 2002 Hans Reiser
|
||||
*/
|
||||
#include "tune.h"
|
||||
|
||||
char *program_name;
|
||||
|
||||
static void message( const char * fmt, ... )
|
||||
__attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
static void message( const char * fmt, ... )
|
||||
{
|
||||
char *buf;
|
||||
va_list args;
|
||||
|
||||
buf = NULL;
|
||||
va_start( args, fmt );
|
||||
vasprintf( &buf, fmt, args );
|
||||
va_end( args );
|
||||
|
||||
if( buf ) {
|
||||
fprintf( stderr, "%s: %s\n", program_name, buf );
|
||||
free( buf );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
reiserfs_filsys_t * fs;
|
||||
|
||||
static void print_usage_and_exit(void)
|
||||
{
|
||||
message ("Usage: %s [options] "
|
||||
" device [block-count]\n"
|
||||
"\n"
|
||||
"Options:\n\n"
|
||||
" -j | --journal-device file\n"
|
||||
" --journal-new-device file\n"
|
||||
" -o | --journal-new-offset N\n"
|
||||
" -s | --journal-new-size N\n"
|
||||
" -t | --transaction-max-size N\n"
|
||||
" --no-journal-available\n"
|
||||
" --make-journal-standard\n"
|
||||
/*"\t-p | --keep-old-journal-param (keep parametrs from old journal to new one)\n"*/
|
||||
" -u | --uuid UUID|random\n"
|
||||
" -l | --label LABEL\n"
|
||||
" -f | --force \n", program_name);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
unsigned long Journal_size = 0;
|
||||
int Max_trans_size = JOURNAL_TRANS_MAX;
|
||||
int Offset = 0;
|
||||
__u16 Options = 0;
|
||||
int Force = 0;
|
||||
char * LABEL;
|
||||
unsigned char UUID[16];
|
||||
|
||||
static int should_make_journal_non_standard (int force)
|
||||
{
|
||||
message ("ATTENTION! Filesystem with standard journal found. ");
|
||||
check_forcing_ask_confirmation (force);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int should_make_journal_standard (reiserfs_filsys_t * fs, char * j_new_dev_name)
|
||||
{
|
||||
if (!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb))
|
||||
return 0;
|
||||
|
||||
if (!user_confirmed (stderr, "ATTENTION! Filesystem with non-standard journal "
|
||||
"found. Continue? (y/n):", "y\n")) {
|
||||
exit(1);
|
||||
}
|
||||
/* make sure journal is on main device, it has default size
|
||||
and the file system has non-standard magic */
|
||||
|
||||
if (j_new_dev_name) {
|
||||
/* new journal was specified - check if it is available */
|
||||
if (strcmp (j_new_dev_name, fs->fs_file_name)) {
|
||||
message ("Can not create standard journal on separated device %s",
|
||||
j_new_dev_name);
|
||||
return 0;
|
||||
}
|
||||
if (Journal_size && (Journal_size != journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize))) {
|
||||
message ("Can not create standard journal of the size %lu",
|
||||
Journal_size);
|
||||
return 0;
|
||||
}
|
||||
if (Max_trans_size && (Max_trans_size != JOURNAL_TRANS_MAX)) {
|
||||
message ("Can not create standard journal with the transaction "
|
||||
"max size %u", Max_trans_size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* new journal was not specified - check ondisk journal params */
|
||||
if (get_jp_journal_dev(sb_jp(fs->fs_ondisk_sb))) {
|
||||
message ("Can not create standard journal on separated device [0x%x]",
|
||||
get_jp_journal_dev(sb_jp(fs->fs_ondisk_sb)));
|
||||
return 0;
|
||||
}
|
||||
if(get_jp_journal_size(sb_jp(fs->fs_ondisk_sb))!= journal_default_size (fs->fs_super_bh->b_blocknr, fs->fs_blocksize)){
|
||||
message ("Can not create standard journal of the size %u",
|
||||
get_jp_journal_size(sb_jp(fs->fs_ondisk_sb)));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int set_standard_journal_params (reiserfs_filsys_t * fs)
|
||||
{
|
||||
/* ondisk superblock update */
|
||||
|
||||
if (get_sb_version(fs->fs_ondisk_sb) == 0)
|
||||
memcpy (fs->fs_ondisk_sb->s_v1.s_magic, REISERFS_3_5_SUPER_MAGIC_STRING,
|
||||
strlen (REISERFS_3_5_SUPER_MAGIC_STRING));
|
||||
else if (get_sb_version(fs->fs_ondisk_sb) == 2)
|
||||
memcpy (fs->fs_ondisk_sb->s_v1.s_magic, REISERFS_3_6_SUPER_MAGIC_STRING,
|
||||
strlen (REISERFS_3_6_SUPER_MAGIC_STRING));
|
||||
else {
|
||||
message ("Can not set standard reiserfs magic: unknown format found %u,"
|
||||
" try reiserfsck first", get_sb_version(fs->fs_ondisk_sb));
|
||||
return 0;
|
||||
}
|
||||
if (get_jp_journal_max_trans_len(sb_jp(fs->fs_ondisk_sb)) != JOURNAL_TRANS_MAX)
|
||||
set_jp_journal_max_trans_len(sb_jp(fs->fs_ondisk_sb), JOURNAL_TRANS_MAX);
|
||||
if (get_jp_journal_max_batch(sb_jp(fs->fs_ondisk_sb)) != JOURNAL_MAX_BATCH)
|
||||
set_jp_journal_max_batch(sb_jp(fs->fs_ondisk_sb), JOURNAL_MAX_BATCH);
|
||||
if (get_jp_journal_max_commit_age(sb_jp(fs->fs_ondisk_sb)) != JOURNAL_MAX_COMMIT_AGE)
|
||||
set_jp_journal_max_commit_age(sb_jp(fs->fs_ondisk_sb), JOURNAL_MAX_COMMIT_AGE);
|
||||
if (get_jp_journal_max_trans_age(sb_jp(fs->fs_ondisk_sb)) != JOURNAL_MAX_TRANS_AGE)
|
||||
set_jp_journal_max_trans_age(sb_jp(fs->fs_ondisk_sb), JOURNAL_MAX_TRANS_AGE);
|
||||
set_sb_reserved_for_journal (fs->fs_ondisk_sb, 0);
|
||||
|
||||
/* journal_header update */
|
||||
|
||||
((struct reiserfs_journal_header *)(fs->fs_jh_bh->b_data)) -> jh_journal =
|
||||
*(sb_jp(fs->fs_ondisk_sb));
|
||||
return 1;
|
||||
}
|
||||
|
||||
void zero_journal (reiserfs_filsys_t * fs)
|
||||
{
|
||||
int i;
|
||||
struct buffer_head * bh;
|
||||
unsigned long done;
|
||||
unsigned long start, len;
|
||||
|
||||
|
||||
fprintf (stderr, "Initializing journal - ");
|
||||
|
||||
start = get_jp_journal_1st_block (sb_jp (fs->fs_ondisk_sb));
|
||||
len = get_jp_journal_size (sb_jp (fs->fs_ondisk_sb));
|
||||
done = 0;
|
||||
for (i = 0; i < len; i ++) {
|
||||
print_how_far (stderr, &done, len, 1, 1/*be quiet*/);
|
||||
bh = getblk (fs->fs_journal_dev, start + i, fs->fs_blocksize);
|
||||
if (!bh)
|
||||
die ("zero_journal: getblk failed");
|
||||
memset (bh->b_data, 0, bh->b_size);
|
||||
mark_buffer_dirty (bh);
|
||||
mark_buffer_uptodate (bh, 1);
|
||||
bwrite (bh);
|
||||
brelse (bh);
|
||||
}
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
fflush (stderr);
|
||||
}
|
||||
|
||||
|
||||
static int str2int (char * str)
|
||||
{
|
||||
int val;
|
||||
char * tmp;
|
||||
|
||||
val = (int) strtol (str, &tmp, 0);
|
||||
if (*tmp)
|
||||
die ("%s: strtol is unable to make an integer of %s\n", program_name, str);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
static void set_transaction_max_size (char * str)
|
||||
{
|
||||
Max_trans_size = str2int( str );
|
||||
}
|
||||
|
||||
|
||||
/* journal must fit into number of blocks pointed by first bitmap */
|
||||
static void set_journal_device_size (char * str)
|
||||
{
|
||||
Journal_size = str2int (str) ;
|
||||
}
|
||||
|
||||
|
||||
static void set_offset_in_journal_device (char * str)
|
||||
{
|
||||
Offset = str2int( str );
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
reiserfs_filsys_t * fs;
|
||||
char * device_name;
|
||||
char * jdevice_name;
|
||||
char * j_new_device_name;
|
||||
int c;
|
||||
static int flag;
|
||||
struct reiserfs_journal_header * j_head;
|
||||
reiserfs_trans_t old, new;
|
||||
int Is_journal_or_maxtrans_size_specified = 0;
|
||||
|
||||
program_name = strrchr( argv[ 0 ], '/' );
|
||||
program_name = program_name ? ++ program_name : argv[ 0 ];
|
||||
|
||||
print_banner (program_name);
|
||||
|
||||
if (argc < 2)
|
||||
print_usage_and_exit ();
|
||||
|
||||
device_name = 0;
|
||||
jdevice_name = 0;
|
||||
j_new_device_name = 0;
|
||||
|
||||
while (1) {
|
||||
static struct option options[] = {
|
||||
{"journal-device", required_argument, 0, 'j'},
|
||||
{"journal-new-device", required_argument, &flag, OPT_NEW_J},
|
||||
{"journal-new-size", required_argument, 0, 's'},
|
||||
{"transaction-max-size", required_argument, 0, 't'},
|
||||
{"journal-new-offset", required_argument, 0, 'o'},
|
||||
{"no-journal-available", no_argument, &flag, OPT_SKIP_J},
|
||||
/*{"keep-old-journal-param", no_argument, 0, 'p'},*/
|
||||
{"uuid", required_argument, 0, 'u'},
|
||||
{"label", required_argument, 0, 'l'},
|
||||
{"force", no_argument, 0, 'f'},
|
||||
{"really-force", no_argument, &flag, OPT_SUPER_FORCE},
|
||||
{"make-journal-standard", no_argument, &flag, OPT_STANDARD},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
int option_index;
|
||||
|
||||
c = getopt_long (argc, argv, "j:s:t:o:fu:l:",
|
||||
options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
/* long-only optins */
|
||||
if (flag == OPT_NEW_J) {
|
||||
Options |= OPT_NEW_J;
|
||||
j_new_device_name = optarg;
|
||||
}
|
||||
if (flag == OPT_SKIP_J) {
|
||||
Options |= OPT_SKIP_J;
|
||||
}
|
||||
if (flag == OPT_SUPER_FORCE) {
|
||||
Options |=OPT_SUPER_FORCE;
|
||||
}
|
||||
if (flag == OPT_STANDARD) {
|
||||
Options |=OPT_STANDARD;
|
||||
}
|
||||
break;
|
||||
case 'j': /* --journal-device */
|
||||
jdevice_name = optarg;
|
||||
break;
|
||||
|
||||
case 's': /* --journal-new-size */
|
||||
set_journal_device_size (optarg);
|
||||
Is_journal_or_maxtrans_size_specified = 1;
|
||||
break;
|
||||
|
||||
case 't': /* --transaction-max-size */
|
||||
set_transaction_max_size (optarg);
|
||||
Is_journal_or_maxtrans_size_specified = 1;
|
||||
break;
|
||||
|
||||
case 'o': /* --offset */
|
||||
set_offset_in_journal_device (optarg);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
/* forces replacing standard journal with non-standard
|
||||
one. Specified more than once - allows to avoid asking for
|
||||
confirmation */
|
||||
Force ++;
|
||||
break;
|
||||
case 'u':
|
||||
/* UUID */
|
||||
if (!strcmp(optarg, "random")) {
|
||||
if (generate_random_uuid (UUID))
|
||||
message ("failed to genetate UUID\n");
|
||||
} else {
|
||||
if (set_uuid (optarg, UUID)) {
|
||||
message ("wrong UUID specified\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'l':
|
||||
/* LABEL */
|
||||
LABEL = optarg;
|
||||
break;
|
||||
#if 0
|
||||
case 'J': /* --journal-new-device */
|
||||
Options |= OPT_NEW_J;
|
||||
j_new_device_name = optarg;
|
||||
break;
|
||||
|
||||
case 'u': /* --no-journal-available */
|
||||
Options |= OPT_SKIPJ;
|
||||
break;
|
||||
|
||||
case 'p': /* --keep-old-journal-param */
|
||||
Options |= OPT_KEEPO;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
print_usage_and_exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (optind != argc - 1)
|
||||
print_usage_and_exit ();
|
||||
|
||||
/* device to be formatted */
|
||||
device_name = argv [optind];
|
||||
|
||||
if (!jdevice_name && !(Options & OPT_SKIP_J))
|
||||
jdevice_name = device_name;
|
||||
|
||||
if (jdevice_name && (Options & OPT_SKIP_J)) {
|
||||
message ("either specify journal device, "
|
||||
"or choose the option --no-journal-awailable");
|
||||
return 1;
|
||||
}
|
||||
fs = reiserfs_open (device_name, O_RDONLY, 0, NULL);
|
||||
if (no_reiserfs_found(fs)) {
|
||||
message ("Cannot open reiserfs on %s", device_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* now we try to open journal, it makes sence if there is no the flag
|
||||
NEED_TUNE in ondisk superblock */
|
||||
if (get_jp_journal_magic(sb_jp(fs->fs_ondisk_sb)) != NEED_TUNE) {
|
||||
if (!reiserfs_open_journal (fs, jdevice_name, O_RDONLY)) {
|
||||
if (!(Options & OPT_SKIP_J)) {
|
||||
message ("Unable to open old journal.");
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
if (!reiserfs_is_fs_consistent (fs)) {
|
||||
message ("Check filesystem consistency first");
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
/* forced to continue without journal available/specifed */
|
||||
}
|
||||
}
|
||||
|
||||
/* journal was opened or it wasn't opened but the option
|
||||
--no-journal-available has been specified by user */
|
||||
|
||||
/* make sure filesystem is not mounted */
|
||||
if (is_mounted (fs->fs_file_name)) {
|
||||
/* fixme: it can not be mounted, btw */
|
||||
message ("can not rebuild journal of mounted filesystem");
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* in spite of journal was opened, the file system can be non-consistent or
|
||||
there are non-replayed transaction in journal,
|
||||
make sure it isn't (if there is no the flag NEED_TUNE in ondisk superblock */
|
||||
if (get_jp_journal_magic(sb_jp(fs->fs_ondisk_sb)) != NEED_TUNE &&
|
||||
reiserfs_journal_opened (fs)) {
|
||||
j_head = (struct reiserfs_journal_header *)(fs->fs_jh_bh->b_data);
|
||||
if (get_boundary_transactions(fs, &old, &new)) {
|
||||
if (new.trans_id != get_jh_last_flushed(j_head)) {
|
||||
if (!(Options & OPT_SUPER_FORCE)) {
|
||||
message ("There are non-replayed transaction in old journal,"
|
||||
" check filesystem consistency first");
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!reiserfs_is_fs_consistent (fs)) {
|
||||
message ("Check filesystem consistency first");
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
reiserfs_reopen (fs, O_RDWR);
|
||||
|
||||
/* set UUID and LABEL if specified */
|
||||
if (fs->fs_format == REISERFS_FORMAT_3_6) {
|
||||
if (uuid_is_correct (UUID)) {
|
||||
memcpy (fs->fs_ondisk_sb->s_uuid, UUID, 16);
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
}
|
||||
|
||||
if (LABEL != NULL) {
|
||||
if (strlen (LABEL) > 16)
|
||||
message ("Specified LABEL is longer then 16 characters, will be truncated\n");
|
||||
strncpy (fs->fs_ondisk_sb->s_label, LABEL, 16);
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
}
|
||||
fs->fs_dirt = 1;
|
||||
} else {
|
||||
if (uuid_is_correct (UUID))
|
||||
reiserfs_panic ("UUID cannot be specified for 3.5 format\n");
|
||||
if (LABEL)
|
||||
reiserfs_panic ("LABEL cannot be specified for 3.5 format\n");
|
||||
}
|
||||
|
||||
if (!j_new_device_name) {
|
||||
/* new journal device hasn't been specify */
|
||||
printf ("Current parameters:\n");
|
||||
print_filesystem_state (stdout, fs);
|
||||
print_block (stdout, fs, fs->fs_super_bh);
|
||||
printf ("Current journal parameters:\n");
|
||||
print_journal_params (stdout, sb_jp (fs->fs_ondisk_sb));
|
||||
|
||||
if ((Options & OPT_STANDARD)
|
||||
&& should_make_journal_standard(fs, j_new_device_name)) {
|
||||
if (set_standard_journal_params (fs)) {
|
||||
printf ("\nNew parameters:\n");
|
||||
print_filesystem_state (stdout, fs);
|
||||
print_block (stdout, fs, fs->fs_super_bh);
|
||||
printf ("New journal parameters:\n");
|
||||
print_journal_params (stdout, sb_jp (fs->fs_ondisk_sb));
|
||||
mark_buffer_dirty (fs->fs_super_bh);
|
||||
mark_buffer_uptodate (fs->fs_super_bh, 1);
|
||||
mark_buffer_dirty (fs->fs_jh_bh);
|
||||
mark_buffer_uptodate (fs->fs_jh_bh, 1);
|
||||
reiserfs_close (fs);
|
||||
printf ("Syncing.."); fflush (stdout);
|
||||
sync ();
|
||||
printf ("ok\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (Is_journal_or_maxtrans_size_specified)
|
||||
/* new journal device hasn't been specified, but
|
||||
journal size or max transaction size have been, so we suppose
|
||||
that journal device remains the same */
|
||||
j_new_device_name = jdevice_name;
|
||||
else {
|
||||
/* the only parameter has been specified is device_name, so
|
||||
there is nothing to do */
|
||||
reiserfs_close (fs);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* new journal device has been specified */
|
||||
/* make sure new journal device is block device file */
|
||||
if (!can_we_format_it (j_new_device_name, Force)) {
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!strcmp (device_name, j_new_device_name)) {
|
||||
unsigned long reserved, journal_size;
|
||||
/* we have to put journal on main device. It is only possible if there
|
||||
is enough space reserved by mkreiserfs */
|
||||
|
||||
if (!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb))
|
||||
/* standard journal */
|
||||
reserved = get_jp_journal_size(sb_jp(fs->fs_ondisk_sb)) + 1;
|
||||
else
|
||||
/* non-standard journal */
|
||||
reserved = get_sb_reserved_for_journal (fs->fs_ondisk_sb);
|
||||
|
||||
journal_size = (Journal_size ? Journal_size : journal_default_size(fs->fs_super_bh->b_blocknr, fs->fs_blocksize));
|
||||
|
||||
/* journal_size = (Journal_size ? Journal_size : // specified
|
||||
(fs->fs_blocksize == 1024 ? (fs->fs_blocksize) * 8 - 3 -
|
||||
REISERFS_DISK_OFFSET_IN_BYTES / fs->fs_blocksize :
|
||||
JOURNAL_DEFAULT_SIZE + 1)); // default
|
||||
*/
|
||||
if (journal_size > reserved) {
|
||||
message ("There is no enough space reserved for journal on main "
|
||||
"device (journal_size=%lu, reserved=%lu\n", journal_size,
|
||||
reserved);
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
message ("Current journal parameters:");
|
||||
print_journal_params (stdout, sb_jp (fs->fs_ondisk_sb));
|
||||
|
||||
if (!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb)) {
|
||||
/* we have standard journal, so check if we can convert it
|
||||
to non-standard one */
|
||||
if (!should_make_journal_non_standard (Force)) {
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (is_reiserfs_3_6_magic_string (fs->fs_ondisk_sb))
|
||||
set_sb_version (fs->fs_ondisk_sb, REISERFS_FORMAT_3_6);
|
||||
else if (is_reiserfs_3_5_magic_string (fs->fs_ondisk_sb))
|
||||
set_sb_version (fs->fs_ondisk_sb, REISERFS_FORMAT_3_5);
|
||||
else {
|
||||
message ("Could not convert from unknown version, try reiserfsck first");
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
memcpy (fs->fs_ondisk_sb->s_v1.s_magic, REISERFS_JR_SUPER_MAGIC_STRING,
|
||||
strlen (REISERFS_JR_SUPER_MAGIC_STRING));
|
||||
set_sb_reserved_for_journal (fs->fs_ondisk_sb,
|
||||
get_jp_journal_size (sb_jp(fs->fs_ondisk_sb)) + 1);
|
||||
}
|
||||
|
||||
/* now we are going to close old journal and to create a new one */
|
||||
reiserfs_close_journal (fs);
|
||||
|
||||
if (!reiserfs_create_journal (fs, j_new_device_name, Offset,
|
||||
Journal_size, Max_trans_size)) {
|
||||
message ("Could not create new journal");
|
||||
reiserfs_close (fs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Options & OPT_STANDARD)
|
||||
if (should_make_journal_standard (fs, j_new_device_name))
|
||||
set_standard_journal_params (fs);
|
||||
|
||||
message ("New journal parameters:");
|
||||
print_journal_params (stdout, sb_jp (fs->fs_ondisk_sb));
|
||||
|
||||
print_block (stdout, fs, fs->fs_super_bh);
|
||||
|
||||
if (Force < 2) {
|
||||
message ("ATTENTION: YOU ARE ABOUT TO SETUP THE NEW JOURNAL FOR THE \"%s\"!\n"
|
||||
"AREA OF \"%s\" DEDICATED FOR JOURNAL WILL BE ZEROED!",
|
||||
device_name, j_new_device_name);
|
||||
|
||||
if (!user_confirmed (stderr, "Continue (y/n):", "y\n")) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
zero_journal (fs);
|
||||
reiserfs_close (fs);
|
||||
|
||||
printf ("Syncing.."); fflush (stdout);
|
||||
sync ();
|
||||
printf ("ok\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2002 Hans Reiser, licensing governed by ../README
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <asm/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <linux/kdev_t.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <getopt.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "io.h"
|
||||
#include "misc.h"
|
||||
#include "reiserfs_lib.h"
|
||||
#include "../include/config.h"
|
||||
#include "../version.h"
|
||||
|
||||
/* main.c */
|
||||
extern reiserfs_filsys_t * fs;
|
||||
|
||||
|
||||
/*
|
||||
* options
|
||||
*/
|
||||
#define OPT_SUPER_FORCE 0x0010
|
||||
#define OPT_OLD_J 0x0100
|
||||
#define OPT_NEW_J 0x0200
|
||||
#define OPT_SIZEJ 0x0400
|
||||
#define OPT_TMAXS 0x0800
|
||||
#define OPT_OFSET 0x1000
|
||||
#define OPT_SKIP_J 0x2000
|
||||
#define OPT_KEEPO 0x4000
|
||||
#define OPT_FORCE 0x8000
|
||||
#define OPT_STANDARD 0x0020
|
||||
|
||||
extern char *program_name;
|
||||
@@ -1,9 +1,7 @@
|
||||
/*
|
||||
* Copyright 2000 Hans Reiser
|
||||
* Copyright 2002 Hans Reiser
|
||||
*/
|
||||
|
||||
#define REISERFSPROGS_VERSION "3.x.0j"
|
||||
|
||||
#define print_banner(prog) \
|
||||
fprintf (stderr, "\n<-------------%s, 2001------------->\nreiserfsprogs %s\n", \
|
||||
prog, REISERFSPROGS_VERSION)
|
||||
fprintf (stderr, "\n<-------------%s, 2002------------->\nreiserfsprogs %s\n\n", \
|
||||
prog, VERSION)
|
||||
Reference in new issue
Block a user