Imported reiserfsprogs-3.6.18

This commit is contained in:
Jeff Mahoney committed 2012-10-11 11:30:57 -04:00
1 parent 18057cdad6
commit 3078c83c48
64 files changed
+6508 -1071

No files matched your search

+2 -3
View File
@@ -1,7 +1,6 @@
sbin_PROGRAMS = debugreiserfs unpack
sbin_PROGRAMS = debugreiserfs
debugreiserfs_SOURCES = debugreiserfs.c pack.c stat.c corruption.c scan.c recover.c
unpack_SOURCES = unpack.c pack.c debugreiserfs.h
debugreiserfs_SOURCES = debugreiserfs.c pack.c unpack.c stat.c corruption.c scan.c recover.c debugreiserfs.h
man_MANS = debugreiserfs.8
EXTRA_DIST = $(man_MANS)
+28 -24
View File
@@ -1,7 +1,7 @@
# Makefile.in generated by automake 1.7.2 from Makefile.am.
# Makefile.in generated by automake 1.7.6 from Makefile.am.
# @configure_input@
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -35,6 +35,7 @@ POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
host_triplet = @host@
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
@@ -63,7 +64,11 @@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
MAKEINFO = @MAKEINFO@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
@@ -85,12 +90,21 @@ ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
@@ -105,35 +119,29 @@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
sbin_PROGRAMS = debugreiserfs unpack
sbin_PROGRAMS = debugreiserfs
debugreiserfs_SOURCES = debugreiserfs.c pack.c stat.c corruption.c scan.c recover.c
unpack_SOURCES = unpack.c pack.c debugreiserfs.h
debugreiserfs_SOURCES = debugreiserfs.c pack.c unpack.c stat.c corruption.c scan.c recover.c debugreiserfs.h
man_MANS = debugreiserfs.8
EXTRA_DIST = $(man_MANS)
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
subdir = debugreiserfs
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES =
sbin_PROGRAMS = debugreiserfs$(EXEEXT) unpack$(EXEEXT)
sbin_PROGRAMS = debugreiserfs$(EXEEXT)
PROGRAMS = $(sbin_PROGRAMS)
am_debugreiserfs_OBJECTS = debugreiserfs.$(OBJEXT) pack.$(OBJEXT) \
stat.$(OBJEXT) corruption.$(OBJEXT) scan.$(OBJEXT) \
recover.$(OBJEXT)
unpack.$(OBJEXT) stat.$(OBJEXT) corruption.$(OBJEXT) \
scan.$(OBJEXT) recover.$(OBJEXT)
debugreiserfs_OBJECTS = $(am_debugreiserfs_OBJECTS)
debugreiserfs_LDADD = $(LDADD)
debugreiserfs_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
$(top_srcdir)/reiserfscore/libcore.a
debugreiserfs_LDFLAGS =
am_unpack_OBJECTS = unpack.$(OBJEXT) pack.$(OBJEXT)
unpack_OBJECTS = $(am_unpack_OBJECTS)
unpack_LDADD = $(LDADD)
unpack_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
$(top_srcdir)/reiserfscore/libcore.a
unpack_LDFLAGS =
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -146,21 +154,21 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
DIST_SOURCES = $(debugreiserfs_SOURCES) $(unpack_SOURCES)
DIST_SOURCES = $(debugreiserfs_SOURCES)
NROFF = nroff
MANS = $(man_MANS)
DIST_COMMON = Makefile.am Makefile.in
SOURCES = $(debugreiserfs_SOURCES) $(unpack_SOURCES)
SOURCES = $(debugreiserfs_SOURCES)
all: all-am
.SUFFIXES:
.SUFFIXES: .c .o .obj
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu debugreiserfs/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
sbinPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
install-sbinPROGRAMS: $(sbin_PROGRAMS)
@@ -189,9 +197,6 @@ clean-sbinPROGRAMS:
debugreiserfs$(EXEEXT): $(debugreiserfs_OBJECTS) $(debugreiserfs_DEPENDENCIES)
@rm -f debugreiserfs$(EXEEXT)
$(LINK) $(debugreiserfs_LDFLAGS) $(debugreiserfs_OBJECTS) $(debugreiserfs_LDADD) $(LIBS)
unpack$(EXEEXT): $(unpack_OBJECTS) $(unpack_DEPENDENCIES)
@rm -f unpack$(EXEEXT)
$(LINK) $(unpack_LDFLAGS) $(unpack_OBJECTS) $(unpack_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT) core *.core
@@ -213,7 +218,7 @@ distclean-depend:
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
@am__fastdepCC_TRUE@ then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@@ -224,7 +229,7 @@ distclean-depend:
.c.obj:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
@am__fastdepCC_TRUE@ then mv "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@@ -371,7 +376,6 @@ all-am: Makefile $(PROGRAMS) $(MANS)
installdirs:
$(mkinstalldirs) $(DESTDIR)$(sbindir) $(DESTDIR)$(man8dir)
install: install-am
install-exec: install-exec-am
install-data: install-data-am
+3 -1
View File
@@ -4,6 +4,7 @@
*/
#include "debugreiserfs.h"
#include <time.h>
extern struct reiserfs_fsstat g_stat_info;
@@ -488,7 +489,8 @@ void do_one_corruption_in_one_block (reiserfs_filsys_t * fs,
"not so many unfm ptrs in it\n");
return;
}
* ((__u32 *)B_I_PITEM (bh, ih) + pos_in_item) = get_sb_block_count (fs->fs_ondisk_sb) + 100;
d32_put((__u32 *)B_I_PITEM (bh, ih), pos_in_item,
get_sb_block_count (fs->fs_ondisk_sb) + 100);
break;
case 'D': /* delete item */
+38 -30
View File
@@ -1,13 +1,13 @@
.\" -*- nroff -*-
.\" Copyright 1996-2004 Hans Reiser.
.\"
.TH DEBUGREISERFS 8 "February 2004" "Reiserfsprogs 3.6.13"
.TH DEBUGREISERFS 8 "February 2004" "Reiserfsprogs 3.6.18"
.SH NAME
debugreiserfs \- debugging tool for the ReiserFS filesystem
debugreiserfs \- The debugging tool for the ReiserFS filesystem.
.SH SYNOPSIS
.B debugreiserfs
[
.B -dDJmoqpS
.B -dDJmoqpuSV
] [
.B -j \fIdevice
] [
@@ -21,69 +21,77 @@ debugreiserfs \- debugging tool for the ReiserFS filesystem
.\" ] [
.I device
.SH DESCRIPTION
It helps sometimes to solve problems with reiserfs filesystems. Being
called without options it prints super block of reiserfs filesystem found
\fBdebugreiserfs\fR sometimes helps to solve problems with reiserfs filesystems.
When run without options it prints the super block of the ReiserFS filesystem found
on the \fIdevice\fR.
.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).
an IDE disk partition or /dev/sdXX for a SCSI disk partition).
.SH OPTIONS
.TP
\fB-j\fR \fIdevice\fR
print contents of journal. Also with the option -p it allows to pack
journal into archive with other metadata
prints the contents of the journal. The option -p allows it to pack the journal
with other metadata into the archive.
.TP
\fB-J\fR
print journal header.
prints the journal header.
.TP
.B -d
print formatted nodes of the internal tree of the filesystem
prints the formatted nodes of the internal tree of the filesystem.
.TP
.B -D
print formatted nodes of all used blocks of the filesystem
prints the formatted nodes of all used blocks of the filesystem.
.TP
.B -m
print contents of bitmap (not very useful)
prints the contents of the bitmap (slightly useful).
.TP
.B -o
print objectid map (not very useful)
prints the objectid map (slightly useful).
.TP
\fB-B\fR \fIfile\fR
extract the filesystem list of bad blocks to the specified file.
takes the list of bad blocks stored in the internal ReiserFS tree and translates it
into an ascii list written to the specified file.
.TP
\fB-1\fR \fIblocknumber\fR
print specified block of the filesystem
prints the specified block of the filesystem.
.TP
.\" \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.
extracts the filesystem's metadata with \fBdebugreiserfs\fR -p /dev/xxx | gzip -c >
xxx.gz. None of your data are packed unless a filesystem corruption presents when
the whole block having this corruption is packed. You send us the output, and we use
it to create a filesystem with the same strucure as yours using \fBdebugreiserfs -u\fR.
When the data file is not too large, this usually allows us to quickly reproduce
and debug the problem.
.TP
.B -u
builds the ReiserFS filesystem image with gunzip -c xxx.gz | \fBdebugreiserfs\fR
-u /dev/image of the previously packed metadata with \fBdebugreiserfs -p\fR. The
result image is not the same as the original filesystem, because mostly only metadata
were packed with \fBdebugreiserfs -p\fR, but the filesystem structure is completely
recreated.
.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.
deals with blocks marked used in the filesystem bitmap only. With this option
set \fBdebugreiserfs\fR will work with the entire device.
.TP
.B -q
Suppress showing speed of progress when
When
.\" -s or
-p is in use
-p is in use, suppress showing the speed of progress.
.SH AUTHOR
This version of \fBdebugreiserfs\fR has been written by Hans Reiser <reiser@namesys.com>.
This version of \fBdebugreiserfs\fR has been written by Vitaly Fertman
<vitaly@namesys.com>.
.SH BUGS
There are probably few of them. Please, report bugs to ReiserFS mail-list <reiserfs-list@namesys.com>.
Please report bugs to the ReiserFS developers <reiserfs-dev@namesys.com>, providing
as much information as possible--your hardware, kernel, patches, settings, all printed
messages; check the syslog file for any related information.
.SH SEE ALSO
.BR reiserfsck (8),
.BR mkreiserfs (8)
+44 -20
View File
@@ -16,11 +16,13 @@ Options:\n\
-m\t\tprint bitmap blocks\n\
-o\t\tprint objectid map\n\n\
-J\t\tprint journal header\n\
-j journal_device\n\t\tprint journal\n\
-j filename\n\t\tprint journal located on the device 'filename'\n\
\t\tstores the journal in the specified file 'filename.\n\
-p\t\tsend filesystem metadata to stdout\n\
-u\t\tread stdin and unpack the metadata\n\
-S\t\thandle all blocks, not only used\n\
-1 block\tblock to print\n\
-q\t\tno speed info (for -p, -s and -n)\n\
-q\t\tno speed info\n\
-V\t\tprint version and exit\n\n", argv[0]);\
exit (16);\
}
@@ -29,18 +31,29 @@ Options:\n\
Undocumented options:
-a map_file\n\tstore to the file the map of file. Is used with -n, -N, -r, -f\n
-f creates a file map.\n
-S\t\tgo through whole device when running -p, -s or -n\n\
-U\t\tgo through unused blocks only when running -p, -s or -n\n\
-f \tprints the file map specified by -a.\n
-n name\n\stcan device for specific name in reiserfs directories\n\
-N \tscan tree for specific key in reiserfs directories\n\
-k \tscan device either for specific key or for any metadata\n\
-r name\n\trecovers the file spacified by -a to the 'name' file.\n\
-S\t\tgo through whole device when running -p, -k or -n\n\
-U\t\tgo through unused blocks only when running -p, -k or -n\n\
-D\t\tprint blocks details scanning the device, not the tree as -d does\n\
-b bitmap_file\n\t\trunning -p, -s or -n read blocks marked in this bitmap only\n\
-n\tscan device for specific name in reiserfs directories\n\
-N\tscan tree for specific key in reiserfs directories\n\
-s\tscan device either for specific key or for any metadata\n\
-b bitmap_file\n\t\trunning -p, -k or -n read blocks marked in this bitmap only\n\
-C\tallow to change reiserfs metadata\n\
-r\tprint map file content.\n\
-J\tsearch block numbers in the journal\n\
-t\tstat the device\n\
-v\tverboes unpack, prints the block number of every block being unpacked\n\
To build a map of a file blocks by name:
debugreiserfs device -a mapfile -n filename
To build a map of a file blocks by key:
debugreiserfs device -a mapfile -k
To extract some:
debugreiserfs device -a mapfile -r filename > backup
*/
#if 1
@@ -98,11 +111,9 @@ static void print_disk_tree (reiserfs_filsys_t * fs, unsigned long block_nr)
for (i = 0; i < count; i++, ih++) {
if (is_indirect_ih(ih)) {
__u32 * ind_item = (__u32 *)B_I_PITEM (bh, ih);
__u32 unfm_ptr;
for (j = 0; j < (int)I_UNFM_NUM (ih); j ++) {
unfm_ptr = le32_to_cpu (ind_item [j]);
if (unfm_ptr) {
if (d32_get (ind_item, j)) {
g_stat_info.nr_unformatted += 1;
}
}
@@ -229,7 +240,7 @@ static char * parse_options (struct debugreiserfs_data * data, int argc, char *
else
program_name = argv[ 0 ];
while ((c = getopt (argc, argv, "a:b:C:F:SU1:psn:Nfr:dDomj:JqtZl:LVB:")) != EOF) {
while ((c = getopt (argc, argv, "a:b:C:F:SU1:pkn:Nfr:dDomj:JqtZl:LVB:uv")) != EOF) {
switch (c) {
case 'a': /* -r will read this, -n and -N will write to it */
asprintf (&data->map_file, "%s", optarg);
@@ -237,18 +248,18 @@ static char * parse_options (struct debugreiserfs_data * data, int argc, char *
case 'b':
/* will load bitmap from a file and read only blocks
marked in it. This is for -p and -s */
marked in it. This is for -p and -k */
asprintf (&data->input_bitmap, "%s", optarg);
data->scan_area = EXTERN_BITMAP;
break;
case 'S':
/* have debugreiserfs -p or -s to read all the device */
/* have debugreiserfs -p or -k to read all the device */
data->scan_area = ALL_BLOCKS;
break;
case 'U':
/* have debugreiserfs -p or -s to read unused blocks only */
/* have debugreiserfs -p or -k to read unused blocks only */
data->scan_area = UNUSED_BLOCKS;
break;
@@ -277,11 +288,15 @@ static char * parse_options (struct debugreiserfs_data * data, int argc, char *
data->mode = DO_PACK;
break;
case 'u':
data->mode = DO_UNPACK;
break;
case 't':
data->mode = DO_STAT;
break;
case 's':
case 'k':
/* read the device and print reiserfs blocks which contain defined key */
data->mode = DO_SCAN;
break;
@@ -366,6 +381,9 @@ static char * parse_options (struct debugreiserfs_data * data, int argc, char *
case 'V':
data->mode = DO_NOTHING;
break;
case 'v':
data->options |= BE_VERBOSE;
break;
}
}
@@ -527,8 +545,8 @@ static void callback_badblock_print(reiserfs_filsys_t *fs,
tmp_ih = get_ih(badblock_path);
ind_item = (__u32 *)get_item(badblock_path);
for (i = 0; i < I_UNFM_NUM(tmp_ih); i++, ind_item++)
fprintf (fd, "%u\n", le32_to_cpu (*ind_item));
for (i = 0; i < I_UNFM_NUM(tmp_ih); i++)
fprintf (fd, "%u\n", d32_get (ind_item, i));
pathrelse (badblock_path);
}
@@ -639,6 +657,12 @@ int main (int argc, char * argv[])
data = getmem (sizeof (struct debugreiserfs_data));
file_name = parse_options (data, argc, argv);
if (data->mode == DO_UNPACK) {
do_unpack(file_name, data->journal_device_name,
data->input_bitmap, data->options & BE_VERBOSE);
return 0;
}
fs = reiserfs_open (file_name, O_RDONLY, &error, data, 0);
if (no_reiserfs_found (fs)) {
+22 -23
View File
@@ -2,27 +2,21 @@
* Copyright 2000-2004 by Hans Reiser, licensing governed by
* reiserfsprogs/README
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <malloc.h>
#include <sys/types.h>
#include <asm/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifndef HAVE_CONFIG_H
# include "config.h"
#endif
#include "io.h"
#include "misc.h"
#include "reiserfs_lib.h"
#include "../include/config.h"
#include "../version.h"
#include <string.h>
#include <errno.h>
extern reiserfs_filsys_t * fs;
@@ -38,14 +32,15 @@ extern reiserfs_filsys_t * fs;
#define DO_RECOVER 6
#define DO_TEST 7
#define DO_PACK 8 /* -p extract meta data of reiserfs filesystem */
#define DO_STAT 9
#define DO_SCAN_FOR_NAME 10 /* -n */
#define DO_LOOK_FOR_NAME 11 /* -N */
#define DO_SCAN_JOURNAL 12 /* -J */
#define DO_EXTRACT_BADBLOCKS 13
#define DO_FILE_MAP 14
#define DO_ZERO_BITMAP 15
#define DO_NOTHING 16
#define DO_UNPACK 9 /* -u create the fs by the givem metadata */
#define DO_STAT 10
#define DO_SCAN_FOR_NAME 11 /* -n */
#define DO_LOOK_FOR_NAME 12 /* -N */
#define DO_SCAN_JOURNAL 13 /* -J */
#define DO_EXTRACT_BADBLOCKS 14
#define DO_FILE_MAP 15
#define DO_ZERO_BITMAP 16
#define DO_NOTHING 17
/*first bits are in reiserfs_fs.b*/
@@ -54,6 +49,7 @@ extern reiserfs_filsys_t * fs;
#define PRINT_BITMAP 0x40
#define PRINT_OBJECTID_MAP 0x80
#define BE_QUIET 0x100
#define BE_VERBOSE 0x200
/* these moved to reiserfs_fs.h */
//#define PRINT_TREE_DETAILS
@@ -272,13 +268,16 @@ void do_scan (reiserfs_filsys_t * fs);
/* journal.c */
void scan_journal (reiserfs_filsys_t * fs);
/* unpack.c */
extern int do_unpack(char *host, char *j_filename, char *filename, int verbose);
void print_map(reiserfs_filsys_t * fs);
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 */
int si_item_num, si_entry_pos;
struct saved_item *si_next; /* list of items having the same key */
};
/*
+9 -7
View File
@@ -114,7 +114,7 @@ static void pack_direct (struct packed_item * pi, struct buffer_head * bh,
set_pi_mask (pi, get_pi_mask (pi) | IH_FREE_SPACE);
if (get_pi_mask(pi) & SAFE_LINK)
set_key_dirid(&ih->ih_key, le32_to_cpu(*(__u32 *)B_I_PITEM (bh, ih)) );
set_key_dirid(&ih->ih_key, d32_get((__u32 *)B_I_PITEM (bh, ih), 0) );
/* send key components which are to be sent */
pack_ih (pi, ih);
@@ -127,8 +127,9 @@ 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] == 0 && ind_item [i - 1] == 0) || /* hole continues */
le32_to_cpu (ind_item [i]) == le32_to_cpu (ind_item [i - 1]) + 1) { /* subsequent blocks */
if ((d32_get(ind_item, i) == 0 && d32_get(ind_item, i - 1) == 0) ||
d32_get(ind_item, i) == d32_get(ind_item, i - 1) + 1)
{
len ++;
if (len > 2)
return 1;
@@ -161,7 +162,7 @@ static void pack_indirect (struct packed_item * pi, struct buffer_head * bh,
if (get_pi_mask(pi) & SAFE_LINK)
set_key_dirid(&ih->ih_key, le32_to_cpu(*ind_item) );
set_key_dirid(&ih->ih_key, d32_get(ind_item, 0));
pack_ih (pi, ih);
@@ -177,12 +178,13 @@ static void pack_indirect (struct packed_item * pi, struct buffer_head * bh,
fwrite32 (&ind_item [0]);
for (i = 1, len = 1; i < I_UNFM_NUM (ih); i ++) {
if ((ind_item [i] == 0 && ind_item [i - 1] == 0) || /* hole continues */
ind_item [i] == ind_item[ i - 1] + 1) { /* subsequent blocks */
if ((d32_get(ind_item, i) == 0 && d32_get(ind_item, i - 1) == 0) ||
d32_get(ind_item, i) == d32_get(ind_item, i - 1) + 1)
{
len ++;
} else {
fwrite_le16 (&len);
fwrite32 (&ind_item[i]);
fwrite32 ((char *)(ind_item + i));
len = 1;
}
}
+3 -3
View File
@@ -265,7 +265,7 @@ static void recover_items(FILE *fp, reiserfs_filsys_t * fs, FILE *target_file) {
int size = sizeof(struct saved_item) - sizeof(struct saved_item *);
struct saved_item *map = NULL;
__u32 map_size = 0;
int start = 0;
int start = -1;
unsigned int i, j;
__u64 offset = 0, length;
long int result = 0;
@@ -293,7 +293,7 @@ static void recover_items(FILE *fp, reiserfs_filsys_t * fs, FILE *target_file) {
}
start = -1;
} else if (is_direntry_ih(&(cur - 1)->si_ih)) {
} else if (is_direntry_ih(&(cur - 1)->si_ih) || is_stat_data_ih(&(cur - 1)->si_ih)) {
brelse(bh);
continue;
} else {
@@ -339,7 +339,7 @@ static void recover_items(FILE *fp, reiserfs_filsys_t * fs, FILE *target_file) {
fwrite(B_I_PITEM(bh, ih), (map + result)->si_ih.ih2_item_len, 1, target_file);
} else if (is_indirect_ih(ih)) {
for (j = 0; j < I_UNFM_NUM (ih); j ++) {
unfm_ptr = le32_to_cpu (((__u32 *)B_I_PITEM(bh, ih))[j]);
unfm_ptr = d32_get((__u32 *)B_I_PITEM(bh, ih), j);
if (!unfm_ptr) {
fseek(target_file, fs->fs_blocksize, SEEK_CUR);
continue;
+163 -75
View File
@@ -51,7 +51,7 @@ struct saved_name {
/* 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 item_head * ih, int pos)
{
struct saved_item * new;
void * vp;
@@ -62,6 +62,7 @@ static void store_item (struct saved_name * name, struct buffer_head * bh,
new->si_block = bh->b_blocknr;
new->si_item_num = ih - B_N_PITEM_HEAD (bh, 0);
new->si_next = 0;
new->si_entry_pos = pos;
vp = tfind (new, &name->items, comp_keys);
if (vp) {
@@ -122,8 +123,10 @@ static int name_found (struct saved_name * name, struct saved_name ** name_in)
cur = *name_in;
while (cur) {
if (!not_of_one_file (&name->dirid, &cur->dirid) &&
!not_of_one_file (&name->parent_dirid, &cur->parent_dirid)) {
!not_of_one_file (&name->parent_dirid, &cur->parent_dirid))
{
cur->count ++;
*name_in = cur;
return 1;
}
cur = cur->name_next;
@@ -251,12 +254,86 @@ static void scan_for_name (struct buffer_head * bh)
return;
}
static struct saved_name *scan_for_key(struct key *key) {
char *name;
struct saved_name * new, *name_in;
asprintf (&name, "%u_%u", get_key_dirid (key), get_key_objectid (key));
new = obstack_alloc (&name_store, sizeof (struct saved_name) + strlen(name));
/* pointed object */
new->dirid = get_key_dirid (key);
new->objectid = get_key_objectid (key);
/* pointer to first name which points the same key */
new->first_name = 0;
/* where this name is from */
new->parent_dirid = 0;
new->parent_objectid = 0;
new->block = 0;
new->count = 1;
new->items = 0;
/* name */
new->name_len = strlen(name);
memcpy (new->name, name, new->name_len);
new->name [new->name_len] = 0;
new->name_next = 0;
free(name);
if (name_found (new, &name_in)) {
/* there was already exactly this name */
obstack_free (&name_store, new);
return name_in;
}
saved_names ++;
add_name (new, name_in);
return new;
}
static int comp_token_key(struct buffer_head *bh, struct item_head *ih, struct key *key) {
struct reiserfs_de_head * deh;
int j, ih_entry_count = 0;
int min_entry_size = 1;
if ((get_key_dirid(&ih->ih_key) == get_key_dirid(key) ||
get_key_dirid(key) == ~(__u32)0) &&
(get_key_objectid(&ih->ih_key) == get_key_objectid(key) ||
get_key_objectid(key) == ~(__u32)0))
return -1;
if (!is_direntry_ih (ih))
return 0;
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))
{
return j;
}
}
return 0;
}
/* 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, i_num;
static void scan_items (struct buffer_head * bh, struct key *key) {
int i, i_num, pos;
struct item_head * ih;
struct saved_name * name_in_store;
void * res;
@@ -265,15 +342,21 @@ static void scan_items (struct buffer_head * bh)
ih = B_N_PITEM_HEAD (bh, 0);
i_num = leaf_item_number_estimate(bh);
for (i = 0; i < i_num; i ++, ih ++) {
res = tfind (&ih->ih_key, &key_index, comp_pointed);
if (!res)
/* there were no names pointing to this key */
continue;
if (key) {
if (!(pos = comp_token_key(bh, ih, key)))
continue;
/* name pointing to this key found */
name_in_store = *(struct saved_name **)res;
name_in_store = scan_for_key(&ih->ih_key);
} else {
if (!(res = tfind (&ih->ih_key, &key_index, comp_pointed)))
continue;
store_item (name_in_store, bh, ih);
/* name pointing to this key found */
name_in_store = *(struct saved_name **)res;
pos = -1;
}
store_item (name_in_store, bh, ih, pos);
}
}
@@ -674,7 +757,21 @@ static void save_items(const void *nodep, VISIT value, int level) {
item = *(struct saved_item **)nodep;
while (item) {
fwrite(item, sizeof(struct saved_item) - sizeof(struct saved_item *), 1, fp);
if (fp) {
fwrite(item, sizeof(struct saved_item) - sizeof(struct saved_item *), 1, fp);
} else {
if (is_direntry_ih (&item->si_ih) && item->si_entry_pos != -1) {
reiserfs_warning(log_to, "block %lu, item %d (%H): entry %d\n",
item->si_block, item->si_item_num,
&item->si_ih, item->si_entry_pos);
} else {
reiserfs_warning(log_to, "block %lu, item %d belongs to file %K: %H\n",
item->si_block, item->si_item_num, &item->si_ih.ih_key,
&item->si_ih);
}
}
item = item->si_next;
}
}
@@ -688,23 +785,27 @@ static void make_map(const void *nodep, VISIT value, int level) {
if (value == leaf || value == postorder) {
while (name) {
asprintf(&file_name, "%s.%d", map_file(fs), ++nr);
reiserfs_warning (log_to, "%d - (%d): [%K]:\"%s\": stored in the %s\n",
nr, name->count, &name->parent_dirid, name->name, file_name);
if (fp == 0) {
fp = fopen (file_name, "w+");
if (!fp)
reiserfs_panic ("could open %s: %m", file_name);
if (map_file(fs)) {
asprintf(&file_name, "%s.%d", map_file(fs), ++nr);
reiserfs_warning (log_to, "%d - (%d): [%K]:\"%s\": stored in the %s\n",
nr, name->count, &name->parent_dirid, name->name, file_name);
if (fp == 0) {
fp = fopen (file_name, "w+");
if (!fp)
reiserfs_panic ("could open %s: %m", file_name);
}
}
if (name->items)
twalk (name->items, save_items);
name = name->name_next;
fclose(fp);
fp = NULL;
free(file_name);
if (fp) {
fclose(fp);
fp = NULL;
free(file_name);
}
}
}
}
@@ -807,6 +908,7 @@ static void look_for_name (reiserfs_filsys_t * fs)
}
}
#if 0
static void scan_for_key (struct buffer_head * bh, struct key * key)
{
int i, j, i_num;
@@ -849,8 +951,7 @@ static void scan_for_key (struct buffer_head * bh, struct key * key)
}
return;
}
#endif
void do_scan (reiserfs_filsys_t * fs)
{
@@ -900,48 +1001,24 @@ void do_scan (reiserfs_filsys_t * fs)
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:
case HAS_IH_ARRAY:
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);
if (debug_mode (fs) == DO_SCAN_FOR_NAME) {
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;
}
break;
default:
reiserfs_bitmap_clear_bit (input_bitmap (fs), i);
break;
type = who_is_this (bh->b_data, bh->b_size);
if (type == THE_LEAF || type == HAS_IH_ARRAY)
scan_for_name (bh);
else
reiserfs_bitmap_clear_bit (input_bitmap (fs), i);
brelse (bh);
print_how_far (stderr, &done, total, 1, be_quiet (fs));
}
brelse (bh);
print_how_far (stderr, &done, total, 1, be_quiet (fs));
}
fprintf (stderr, "\n");
@@ -951,9 +1028,6 @@ void do_scan (reiserfs_filsys_t * fs)
fflush (stderr);
if (debug_mode (fs) != DO_SCAN_FOR_NAME)
return;
/* step 2: */
done = 0;
total = reiserfs_bitmap_ones (input_bitmap (fs));
@@ -969,13 +1043,27 @@ void do_scan (reiserfs_filsys_t * fs)
continue;
}
type = who_is_this (bh->b_data, bh->b_size);
if (type != THE_LEAF && type != HAS_IH_ARRAY) {
brelse (bh);
continue;
switch (type) {
case THE_JDESC:
if (!get_key_dirid (&key))
printf ("block %lu is journal descriptor\n", i);
break;
case THE_SUPER:
if (!get_key_dirid (&key))
printf ("block %lu is reiserfs super block\n", i);
break;
case THE_INTERNAL:
if (!get_key_dirid (&key))
printf ("block %lu is reiserfs internal node\n", i);
break;
case THE_LEAF:
case HAS_IH_ARRAY:
scan_items (bh, (debug_mode (fs) == DO_SCAN_FOR_NAME ? NULL : &key));
break;
default:
break;
}
scan_items (bh);
brelse (bh);
print_how_far (stderr, &done, total, 1, be_quiet (fs));
}
+20 -36
View File
@@ -9,8 +9,8 @@
#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\
-j filename makes unpack to store journal in specified file\n", argv[0]);
-b filename saves bitmap of blocks unpacked to filename\n\
-j filename stores journal in the filename\n", argv[0]);
/* when super block gets unpacked for the first time - create a bitmap
@@ -235,7 +235,7 @@ static void unpack_indirect (struct packed_item * pi, struct buffer_head * bh,
ind_item = (__u32 *)B_I_PITEM (bh, ih);
if (get_pi_mask(pi) & SAFE_LINK) {
*ind_item = cpu_to_le32(get_key_dirid(&ih->ih_key));
d32_put(ind_item, 0, get_key_dirid(&ih->ih_key));
set_key_dirid(&ih->ih_key, (__u32)-1);
return;
}
@@ -250,12 +250,12 @@ static void unpack_indirect (struct packed_item * pi, struct buffer_head * bh,
__u32 base;
fread32 (ind_item);
fread_le16 (&v16);
base = le32_to_cpu(ind_item[0]);
base = d32_get(ind_item, 0);
for (i = 1; i < v16; i ++) {
if (ind_item[0] != 0)
ind_item [i] = cpu_to_le32(base + i);
if (base != 0)
d32_put(ind_item, i, base + i);
else
ind_item [i] = 0;
d32_put(ind_item, i, 0);
}
ind_item += i;
}
@@ -274,7 +274,7 @@ static void unpack_direct (struct packed_item * pi, struct buffer_head * bh,
set_ih_entry_count (ih, 0xffff);
if (get_pi_mask(pi) & SAFE_LINK) {
*d_item = cpu_to_le32(get_key_dirid(&ih->ih_key));
d32_put(d_item, 0, get_key_dirid(&ih->ih_key));
set_key_dirid(&ih->ih_key, (__u32)-1);
} else {
memset (d_item, 'a', get_pi_item_len(pi));
@@ -583,43 +583,27 @@ out:
}
int main (int argc, char ** argv)
{
int do_unpack(char *host, char *j_filename, char *filename, int verbose) {
int fd, fdj = -2;
int c;
char * j_filename;
char * filename = ".bitmap";
struct rlimit lim = {0xffffffff, 0xffffffff};
print_banner ("unpack");
struct rlimit lim = {RLIM_INFINITY, RLIM_INFINITY};
if (filename == NULL)
filename = ".bitmap";
if (j_filename)
Default_journal = 0;
/* with this 2.4.0-test9's file_write does not send SIGXFSZ */
if (setrlimit (RLIMIT_FSIZE, &lim)) {
fprintf (stderr, "sertlimit failed: %m\n");
}
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 (misc_device_mounted(host) > 0) {
fprintf(stderr, "%s seems mounted, umount it first\n", host);
return 0;
}
if (optind != argc - 1)
/* only one non-option argument is permitted */
print_usage_and_exit();
if (misc_device_mounted(argv[optind]) > 0)
reiserfs_panic ("%s seems mounted, umount it first\n", argv[optind]);
fd = open (argv[optind], O_RDWR | O_LARGEFILE);
fd = open (host, O_RDWR | O_LARGEFILE);
if (fd == -1) {
perror ("open failed");
return 0;