aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2012-10-11 11:28:37 -0400
committerJeff Mahoney <jeffm@suse.com>2012-10-11 11:28:37 -0400
commit99c89460c3220b5dddc5b43ac1e96767f678ef44 (patch)
treeabddeaa5bd282d850e5a7887b814936e6d7c3e8a
parentb69459eb802ace45677c9a12d909f70beff3de18 (diff)
downloadreiserfsprogs-99c89460c3220b5dddc5b43ac1e96767f678ef44.tar.gz
Imported reiserfsprogs-3.6.4v3.6.4
-rw-r--r--ChangeLog49
-rw-r--r--acconfig.h3
-rwxr-xr-xconfigure2
-rw-r--r--configure.in2
-rw-r--r--debugreiserfs/debugreiserfs.89
-rw-r--r--debugreiserfs/debugreiserfs.c33
-rw-r--r--debugreiserfs/debugreiserfs.h18
-rw-r--r--debugreiserfs/pack.c2
-rw-r--r--debugreiserfs/recover.c173
-rw-r--r--debugreiserfs/scan.c222
-rw-r--r--fsck/Makefile.am2
-rw-r--r--fsck/Makefile.in7
-rw-r--r--fsck/check.c323
-rw-r--r--fsck/check_tree.c572
-rw-r--r--fsck/fsck.h18
-rw-r--r--fsck/lost+found.c20
-rw-r--r--fsck/main.c335
-rw-r--r--fsck/pass0.c395
-rw-r--r--fsck/pass1.c175
-rw-r--r--fsck/pass2.c190
-rw-r--r--fsck/pass4.c38
-rw-r--r--fsck/reiserfsck.815
-rw-r--r--fsck/semantic_check.c260
-rw-r--r--fsck/semantic_rebuild.c188
-rw-r--r--fsck/super.c174
-rw-r--r--fsck/ubitmap.c9
-rw-r--r--fsck/ufile.c439
-rw-r--r--fsck/ustree.c3
-rw-r--r--include/misc.h74
-rw-r--r--include/reiserfs_fs.h40
-rw-r--r--include/reiserfs_lib.h4
-rw-r--r--include/stamp-h.in1
-rw-r--r--include/swab.h25
-rw-r--r--lib/io.c44
-rw-r--r--lib/misc.c336
-rw-r--r--mkreiserfs/mkreiserfs.82
-rw-r--r--mkreiserfs/mkreiserfs.c1
-rw-r--r--reiserfscore/bitmap.c27
-rw-r--r--reiserfscore/do_balan.c93
-rw-r--r--reiserfscore/fix_node.c23
-rw-r--r--reiserfscore/hashes.c5
-rw-r--r--reiserfscore/ibalance.c3
-rw-r--r--reiserfscore/includes.h3
-rw-r--r--reiserfscore/journal.c37
-rw-r--r--reiserfscore/lbalance.c3
-rw-r--r--reiserfscore/node_formats.c20
-rw-r--r--reiserfscore/prints.c73
-rw-r--r--reiserfscore/reiserfslib.c158
-rw-r--r--reiserfscore/stree.c6
-rw-r--r--reiserfsprogs.spec2
-rw-r--r--resize_reiserfs/resize_reiserfs.82
-rw-r--r--tune/reiserfstune.82
52 files changed, 2258 insertions, 2402 deletions
diff --git a/ChangeLog b/ChangeLog
index f8ae6a0..3fd2c05 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,58 @@
+2002-09-24
+ *reiserfsck
+ bitmap handling was improved: fix-fixable fixes not only those
+ blocks of bitmap which are wrongly marked as unused, but those
+ which are wrongly marked as used also.
+2002-09-10
+ * reiserfsck
+ fix-fixable fixes item header formats, check complains about
+ wrong ones.
+ * reiserfsck
+ check/fix-fixable does not complain about/fix file sizes if
+ safe link exists.
+2002-08-30
+ * reiserfsck
+ user recieves a warning if dma mode/speed is descreased - it
+ could happen due to hardware problems.
+2002-08-20
+ * reiserfsprogs
+ Warning/error messages were changed to more user friendly form.
+2002-08-15
+ * reiserfsck
+ Correction of nlinks on fix-fixable was disabled, because
+ fix-fixable zeroes nlinks on the first pass and wants to
+ increment them on semantic pass. But semantic pass is skipped
+ if there are fatal corruptions.
+2002-08-11
+ * reiserfsck
+ exit codes were fixed
+2002-08-08
+ * reiserfsck
+ a critical bug in journal replaying was fixed.
+ * reiserfsprogs
+ called 3.6.3.
+2002-06-06
+ * reiserfsck
+ speedup for pass2: avoid checking whether a file body should
+ be rewritten every time we have another item to insert into it.
+2002-05-30
+ * reiserfsck
+ speedup for pass2: avoid checking whether a file should be
+ relocated on every insertion of a new item into it. Check it
+ only for the first time.
2002-06-27
* reiserfsprogs
called 3.6.2
-2002-05-23
+2002-05-20
* 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-15
+ * reiserfsck
+ speedup for pass2: insertion by many pointers at once was
+ added
2002-05-10
* reiserfsck
fix-fixable is able to fix wrong nlinks.
diff --git a/acconfig.h b/acconfig.h
new file mode 100644
index 0000000..37eddd1
--- /dev/null
+++ b/acconfig.h
@@ -0,0 +1,3 @@
+/*
+ * Copyright 1996, 1997 Hans Reiser, see reiserfs/README for licensing and copyright details
+ */
diff --git a/configure b/configure
index efa751d..c7e9a02 100755
--- a/configure
+++ b/configure
@@ -1150,7 +1150,7 @@ fi
PACKAGE=reiserfsprogs
-VERSION=3.6.2
+VERSION=3.6.4
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
{ { echo "$as_me:1156: error: source directory already configured; run \"make distclean\" there first" >&5
diff --git a/configure.in b/configure.in
index 0e5a3e3..13156ff 100644
--- a/configure.in
+++ b/configure.in
@@ -1,7 +1,7 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(version.h)
-AM_INIT_AUTOMAKE(reiserfsprogs, 3.6.2)
+AM_INIT_AUTOMAKE(reiserfsprogs, 3.6.4)
dnl We install in /sbin, the utils are to be available on boot
dnl AC_PREFIX(/)
diff --git a/debugreiserfs/debugreiserfs.8 b/debugreiserfs/debugreiserfs.8
index 78541f7..fac7a1d 100644
--- a/debugreiserfs/debugreiserfs.8
+++ b/debugreiserfs/debugreiserfs.8
@@ -1,13 +1,13 @@
.\" -*- nroff -*-
.\" Copyright 1996-2002 Hans Reiser.
.\"
-.TH DEBUGREISERFS 8 "January 2002" "Reiserfsprogs 3.6.2"
+.TH DEBUGREISERFS 8 "January 2002" "Reiserfsprogs 3.6.4"
.SH NAME
debugreiserfs
.SH SYNOPSIS
.B debugreiserfs
[
-.B -dJmoqpS
+.B -dDJmoqpS
] [
.B -j \fIdevice
] [
@@ -36,7 +36,10 @@ journal into archive with other metadata
print journal header.
.TP
.B -d
-print formatted nodes of the filesystem
+print formatted nodes of the internal tree of the filesystem
+.TP
+.B -D
+print formatted nodes of all used blocks of the filesystem
.TP
.B -m
print contents of bitmap (not very useful)
diff --git a/debugreiserfs/debugreiserfs.c b/debugreiserfs/debugreiserfs.c
index d22e3ea..3e3feb9 100644
--- a/debugreiserfs/debugreiserfs.c
+++ b/debugreiserfs/debugreiserfs.c
@@ -11,13 +11,14 @@ reiserfs_filsys_t * fs;
#define print_usage_and_exit() {\
fprintf (stderr, "Usage: %s [options] device\n\n\
Options:\n\
- -d\t\tprint blocks details\n\
+ -d\t\tprint blocks details of the internal tree\n\
+ -D\t\tprint blocks details of all used blocks\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\
-p\t\tsend filesystem metadata to stdout\n\
- -S\t\tgo through whole device when running -p\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\n", argv[0]);\
exit (16);\
@@ -28,13 +29,14 @@ Options:\n\
-B file\textract list of badblocks\n\
Undocumented options:
- -a map_file\n\tstore to the file the map of file. Is used with -n, -N, -r\n
+ -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\
-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 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\
-C\tallow to change reiserfs metadata\n\
-r\tprint map file content.\n\
@@ -100,7 +102,7 @@ static void print_disk_tree (reiserfs_filsys_t * fs, unsigned long block_nr)
static void print_disk_blocks (reiserfs_filsys_t * fs)
{
- int j;
+ int j, type;
unsigned long done = 0, total;
struct buffer_head * bh;
@@ -118,13 +120,14 @@ static void print_disk_blocks (reiserfs_filsys_t * fs)
continue;
}
- if (who_is_this (bh->b_data, bh->b_size) != THE_UNKNOWN)
+ type = who_is_this (bh->b_data, bh->b_size);
+ if (type != THE_UNKNOWN)
print_block (stdout, fs, bh, PRINT_TREE_DETAILS | PRINT_DIRECT_ITEMS, -1, -1);
- if (is_internal_node (bh))
+ if (type == THE_INTERNAL)
g_stat_info.nr_internals ++;
- else if (is_leaf_node (bh))
+ else if (type == THE_LEAF)
g_stat_info.nr_leaves ++;
-
+
brelse (bh);
}
fprintf (stderr, "\n");
@@ -203,7 +206,7 @@ static char * parse_options (struct debugreiserfs_data * data, int argc, char *
data->scan_area = USED_BLOCKS;
data->mode = DO_DUMP;
- while ((c = getopt (argc, argv, "a:b:C:SU1:psn:NrdDomj:J:qt")) != EOF) {
+ while ((c = getopt (argc, argv, "a:b:C:SU1:psn:Nfr:dDomj:J:qt")) != EOF) {
switch (c) {
case 'a': /* -r will read this, -n and -N will write to it */
asprintf (&data->map_file, "%s", optarg);
@@ -264,7 +267,12 @@ static char * parse_options (struct debugreiserfs_data * data, int argc, char *
data->mode = DO_LOOK_FOR_NAME;
break;
+ case 'f':
+ data->mode = DO_FILE_MAP;
+ break;
+
case 'r':
+ asprintf (&data->recovery_file, "%s", optarg);
data->mode = DO_RECOVER;
break;
@@ -558,6 +566,11 @@ int main (int argc, char * argv[])
do_scan (fs);
break;
+ case DO_FILE_MAP:
+ print_map(fs);
+ break;
+
+
case DO_RECOVER:
do_recover (fs);
break;
diff --git a/debugreiserfs/debugreiserfs.h b/debugreiserfs/debugreiserfs.h
index 1ee70da..2950354 100644
--- a/debugreiserfs/debugreiserfs.h
+++ b/debugreiserfs/debugreiserfs.h
@@ -40,6 +40,8 @@ extern reiserfs_filsys_t * fs;
#define DO_LOOK_FOR_NAME 10 /* -N */
#define DO_SCAN_JOURNAL 11 /* -J */
#define DO_EXTRACT_BADBLOCKS 12
+#define DO_FILE_MAP 13
+
/*first bits are in reiserfs_fs.b*/
#define PRINT_JOURNAL 0x10
@@ -221,7 +223,8 @@ struct debugreiserfs_data {
char * pattern; /* for -n */
char * device_name;
char * journal_device_name; /* for -j */
- char * map_file; /* for -n, -N and -r */
+ char * map_file; /* for -n, -N and -f */
+ char * recovery_file; /* for -r */
unsigned long options; /* -q only yet*/
int JJ;
@@ -238,7 +241,7 @@ struct debugreiserfs_data {
#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 recovery_file(fs) (data(fs)->recovery_file)
#define be_quiet(fs) (data(fs)->options & BE_QUIET)
@@ -256,3 +259,14 @@ void do_scan (reiserfs_filsys_t * fs);
/* journal.c */
void scan_journal (reiserfs_filsys_t * fs);
+
+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 */
+};
+
+
diff --git a/debugreiserfs/pack.c b/debugreiserfs/pack.c
index 87f0051..4a3d155 100644
--- a/debugreiserfs/pack.c
+++ b/debugreiserfs/pack.c
@@ -536,7 +536,7 @@ static void send_block (reiserfs_filsys_t * fs, struct buffer_head * bh, int sen
case HAS_IH_ARRAY:
having_ih_array ++;
- fprintf (stderr, "BROKEN BLOCK HEAD %lu\n", bh->b_blocknr);
+// fprintf (stderr, "BROKEN BLOCK HEAD %lu\n", bh->b_blocknr);
pack_full_block (fs, bh);
break;
diff --git a/debugreiserfs/recover.c b/debugreiserfs/recover.c
index ce476b9..7a65835 100644
--- a/debugreiserfs/recover.c
+++ b/debugreiserfs/recover.c
@@ -130,6 +130,7 @@ void do_recover (reiserfs_filsys_t fs)
/* 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;
@@ -146,7 +147,7 @@ static void read_map (FILE * fp)
if (v32 != MAP_MAGIC)
reiserfs_panic ("read_map: no magic found");
- /* device name length and name itself */
+ // device name length and name itself
fread (&v32, sizeof (v32), 1, fp);
buf = realloc (buf, v32);
if (!buf)
@@ -154,32 +155,32 @@ static void read_map (FILE * fp)
fread (buf, v32, 1, fp);
reiserfs_warning (stdout, "\"%s\": ", buf);
- /* file name length and name itself*/
+ // 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 */
+ // 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");
- */
+
+ //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 */
+ // 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 */
+ // read list of data block numbers
fread (buf, 4, v32, fp);
if (!do_recover) {
@@ -189,10 +190,10 @@ static void read_map (FILE * fp)
}
}
- /* main tail length */
+ // main tail length
fread (&v32, sizeof (v32), 1, fp);
if (v32) {
- /* there is tail */
+ // there is tail
buf = realloc (buf, v32);
if (!buf)
reiserfs_panic ("realloc failed");
@@ -236,3 +237,151 @@ void do_recover (reiserfs_filsys_t * fs)
fclose (fp);
}
+*/
+
+#include <limits.h>
+
+static long int get_answer(long int max) {
+ char *answer, *tmp;
+ size_t n = 0;
+ long int result = 0;
+
+ do {
+ printf("Which should be left?: ");
+ getline (&answer, &n, stdin);
+ result = strtol (answer, &tmp, 0);
+ if ((errno != ERANGE) && (result < max) && (result >= 0) &&
+ (answer != tmp))
+ break;
+ } while (1);
+ return result;
+}
+
+static void recover_items(FILE *fp, reiserfs_filsys_t * fs, FILE *target_file) {
+ struct buffer_head *bh, *bh_pointed;
+ struct item_head *ih;
+ struct saved_item item, *cur;
+ int size = sizeof(struct saved_item) - sizeof(struct saved_item *);
+ struct saved_item *map = NULL;
+ __u32 map_size = 0;
+ int i, start = 0, j;
+ __u64 offset = 0, length;
+ long int result = 0;
+ unsigned long unfm_ptr;
+
+ while (fread(&item, size, 1, fp) == 1) {
+ map_size += sizeof(struct saved_item);
+ map = realloc(map, map_size);
+ memcpy((void *)map + map_size - sizeof(struct saved_item), &item, size);
+ }
+
+ for (i = 1, cur = map + 1; i <= map_size / sizeof(struct saved_item); i++, cur++) {
+ bh = bread (fs->fs_dev, (cur - 1)->si_block, fs->fs_blocksize);
+ if (!bh) {
+ reiserfs_warning (fp, "bread failed\n");
+ continue;
+ }
+
+ if (i == map_size / sizeof(struct saved_item)) {
+ if (start != -1) {
+ reiserfs_print_item(stdout, bh, B_N_PITEM_HEAD (bh, (cur - 1)->si_item_num));
+ result = get_answer((long int)i - start) + start;
+ } else {
+ result = i - 1;
+ }
+
+ start = -1;
+ } else if (is_direntry_ih(&(cur - 1)->si_ih)) {
+ brelse(bh);
+ continue;
+ } else {
+ length = get_bytes_number(&(cur - 1)->si_ih, fs->fs_blocksize);
+ if (offset < get_offset(&(cur - 1)->si_ih.ih_key) +
+ get_bytes_number(&(cur - 1)->si_ih, fs->fs_blocksize))
+ offset = get_offset(&(cur - 1)->si_ih.ih_key) + (length ? length - 1 : 0);
+
+ if (offset >= get_offset(&cur->si_ih.ih_key)) {
+ /* Problem interval */
+ if (start == -1)
+ start = i - 1;
+
+ printf("Problem item %d:\n", i - start - 1);
+ reiserfs_print_item(stdout, bh, B_N_PITEM_HEAD (bh, (cur - 1)->si_item_num));
+ } else if (start != -1) {
+ /* problem interval finished */
+ printf("Problem item %d:\n", i - start - 1);
+ reiserfs_print_item(stdout, bh, B_N_PITEM_HEAD (bh, (cur - 1)->si_item_num));
+
+ result = get_answer((long int)i - start) + start;
+ start = -1;
+ } else {
+ result = i - 1;
+ }
+ }
+ brelse(bh);
+
+ if (start != -1)
+ continue;
+
+ printf("write %ld\n", result);
+
+ bh = bread (fs->fs_dev, (map + result)->si_block, fs->fs_blocksize);
+ if (!bh) {
+ reiserfs_warning (fp, "bread failed\n");
+ continue;
+ }
+
+ fseek(target_file, get_offset(&(map + result)->si_ih.ih_key) - 1, SEEK_SET);
+ ih = B_N_PITEM_HEAD (bh, (map + result)->si_item_num);
+ if (is_direct_ih(ih)) {
+ 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]);
+ if (!unfm_ptr) {
+ fseek(target_file, fs->fs_blocksize, SEEK_CUR);
+ continue;
+ }
+ bh_pointed = bread (fs->fs_dev, unfm_ptr, fs->fs_blocksize);
+ if (!bh_pointed) {
+ reiserfs_warning (fp, "bread failed\n");
+ continue;
+ }
+ fwrite(bh_pointed->b_data, fs->fs_blocksize, 1, target_file);
+ brelse(bh_pointed);
+ }
+ }
+ brelse(bh);
+ }
+
+ free(map);
+}
+
+void do_recover(reiserfs_filsys_t * fs) {
+ FILE *fp, *recovery;
+
+ if (map_file (fs)) {
+ fp = fopen (map_file (fs), "r");
+ if (fp == 0) {
+ reiserfs_warning (stderr, "fopen failed: %m\n");
+ return;
+ }
+ } else {
+ reiserfs_warning (stderr, "Reading file map from stdin..\n");
+ fflush (stderr);
+ fp = stdin;
+ }
+
+ if (!(recovery = fopen(recovery_file(fs), "w+"))) {
+ reiserfs_warning (stderr, "fopen failed: %m\n");
+ return;
+ }
+
+
+ recover_items(fp, fs, recovery);
+
+ if (fp != stdin)
+ fclose (fp);
+
+ fclose(recovery);
+}
diff --git a/debugreiserfs/scan.c b/debugreiserfs/scan.c
index 3c34b53..c0b1a23 100644
--- a/debugreiserfs/scan.c
+++ b/debugreiserfs/scan.c
@@ -27,15 +27,6 @@ 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;
@@ -330,7 +321,7 @@ static int have_to_append (struct item_head * ih)
tail_start = (off & ~(fs->fs_blocksize - 1)) + 1;
- /* find correct tail first */
+ // 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)
@@ -338,7 +329,7 @@ static int have_to_append (struct item_head * ih)
return 0;
}
}
- /* there was no this tail yet */
+ // there was no this tail yet
return 1;
}
return 0;
@@ -366,7 +357,7 @@ static void do_append (struct item_head * ih, void * data)
int tail_start;
int skip;
- /* find correct tail first */
+ // 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 ++) {
@@ -382,7 +373,7 @@ static void do_append (struct item_head * ih, void * data)
return;
}
}
- /* allocate memory for new tail */
+ // allocate memory for new tail
map.tails = realloc (map.tails, (map.tail_nr + 1) * sizeof (struct tail));
if (!map.tails)
reiserfs_panic ("realloc failed");
@@ -397,10 +388,10 @@ static void do_append (struct item_head * ih, void * data)
}
-/* map contains */
+// map contains
static void do_overwrite (struct item_head * ih, void * data)
{
- int skip; /* now may bytes/pointers to skip */
+ int skip; // now may bytes/pointers to skip
int to_compare;
int to_append;
loff_t off = get_offset (&ih->ih_key);
@@ -430,11 +421,11 @@ static void do_overwrite (struct item_head * ih, void * data)
int tail_start;
int i;
- /* find correct tail first */
+ // 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 */
+ // 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);
@@ -465,7 +456,7 @@ static void map_one_item (struct saved_item * item)
struct item_head * ih;
void * data;
- /* read the block containing the item */
+ // 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");
@@ -485,42 +476,7 @@ static void map_one_item (struct saved_item * item)
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 */
+// flush map which is in variable map
static void flush_map (reiserfs_filsys_t * fs,
struct key * dir,
char * name,
@@ -534,7 +490,7 @@ static void flush_map (reiserfs_filsys_t * fs,
if (!map_file (fs))
asprintf (&map_file (fs), "%s", ".map");
- /*reiserfs_warning (stderr, "Saving maps into %s\n", map_file (fs));*/
+ //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");
@@ -544,38 +500,38 @@ static void flush_map (reiserfs_filsys_t * fs,
v32 = MAP_MAGIC;
fwrite (&v32, sizeof (v32), 1, fp);
- /* device name */
+ // 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 */
+ // 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 */
+ // short key of a directory
fwrite (dir, SHORT_KEY_SIZE, 1, fp);
- /* short key of file */
+ // short key of file
fwrite (key, SHORT_KEY_SIZE, 1, fp);
- /* list of data block pointers */
+ // 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 */
+ // 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 */
+ // 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 */
+ // no tail
v32 = 0;
fwrite (&v32, sizeof (v32), 1, fp);
}
@@ -587,7 +543,42 @@ static void flush_map (reiserfs_filsys_t * fs,
}
-/* write map of file to a map file */
+// write map of file to a map file
+/*
+
+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;
+ }
+}
+
static void make_file_map (const void *nodep, VISIT value, int level)
{
struct saved_name * name;
@@ -601,13 +592,13 @@ static void make_file_map (const void *nodep, VISIT value, int level)
&name->parent_dirid, name->name);
if (name->items) {
- /* initialize the map */
+ // initialize the map
memset (&map, 0, sizeof (struct file_map));
- /* make a map of file */
+ // make a map of file
twalk (name->items, map_item_list);
- /* write map to a file */
+ // write map to a file
flush_map (fs, (struct key *)&name->parent_dirid, name->name,
(struct key *)&name->dirid);
@@ -624,34 +615,93 @@ static void make_file_map (const void *nodep, VISIT value, int level)
}
}
}
+*/
-/* 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;
+static void print_items(FILE *fp, reiserfs_filsys_t * fs) {
+ struct buffer_head *bh;
+ struct item_head *ih;
+ struct saved_item item;
+ int size = sizeof(struct saved_item) - sizeof(struct saved_item *);
- if (fp == 0) {
- fp = fopen ("file.list", "w+");
- if (!fp)
- reiserfs_panic ("could open file.list: %m");
+ while (fread(&item, size, 1, fp) == 1) {
+ bh = bread (fs->fs_dev, item.si_block, fs->fs_blocksize);
+ if (!bh) {
+ reiserfs_warning (fp, "bread failed\n");
+ continue;
+ }
+ ih = B_N_PITEM_HEAD (bh, item.si_item_num);
+ reiserfs_print_item(stdout, bh, ih);
+ brelse(bh);
+ }
+}
+
+void print_map(reiserfs_filsys_t * fs) {
+ FILE * fp;
+
+ if (map_file (fs)) {
+ fp = fopen (map_file (fs), "r");
+ if (fp == 0) {
+ reiserfs_warning (stderr, "fopen failed: %m\n");
+ return;
+ }
+ } else {
+ reiserfs_warning (stderr, "Reading file map from stdin..\n");
+ fflush (stderr);
+ fp = stdin;
}
+
+ print_items(fp, fs);
+
+ if (fp != stdin)
+ fclose (fp);
+}
+
+
+static FILE *fp = 0;
+static void save_items(const void *nodep, VISIT value, int level) {
+ struct saved_item *item;
+
+
+ if (value != leaf && value != postorder)
+ return;
+
+ item = *(struct saved_item **)nodep;
+
+ while (item) {
+ fwrite(item, sizeof(struct saved_item) - sizeof(struct saved_item *), 1, fp);
+ item = item->si_next;
+ }
+}
+
+static void make_map(const void *nodep, VISIT value, int level) {
+ struct saved_name * name;
+ char *file_name = 0;
+ static int nr = 0;
+
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);
+ asprintf(&file_name, "%s.%d", map_file(fs), ++nr);
+ reiserfs_warning (stdout, "%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);
+ free(file_name);
}
}
}
-
-
/* store map if it is a regular file */
static void locate_file (reiserfs_filsys_t * fs, struct key * key)
{
@@ -932,10 +982,10 @@ void do_scan (reiserfs_filsys_t * fs)
/*twalk (name_index, print_file);*/
/* create map for every file in */
- twalk (name_index, make_file_map);
+ twalk (name_index, make_map);
/* print names of files we have map of in a file 'file.list' */
- twalk (name_index, print_name);
+ /*twalk (name_index, print_name);*/
}
diff --git a/fsck/Makefile.am b/fsck/Makefile.am
index 8b72d3f..29d7b4a 100644
--- a/fsck/Makefile.am
+++ b/fsck/Makefile.am
@@ -2,7 +2,7 @@ sbin_PROGRAMS = reiserfsck
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
+ufile.c check_tree.c info.c super.c fsck.h
man_MANS = reiserfsck.8
EXTRA_DIST = $(man_MANS)
diff --git a/fsck/Makefile.in b/fsck/Makefile.in
index 1e4174f..bd929cd 100644
--- a/fsck/Makefile.in
+++ b/fsck/Makefile.in
@@ -66,7 +66,7 @@ sbindir = @sbindir@
sbin_PROGRAMS = reiserfsck
-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
+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_tree.c info.c super.c fsck.h
man_MANS = reiserfsck.8
@@ -85,7 +85,7 @@ LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
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
+ufile.o check_tree.o info.o super.o
reiserfsck_LDADD = $(LDADD)
reiserfsck_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
$(top_srcdir)/reiserfscore/libcore.a
@@ -250,9 +250,6 @@ distdir: $(DISTFILES)
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
-check.o: check.c fsck.h ../include/io.h ../include/misc.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/swab.h ../include/reiserfs_lib.h \
../include/reiserfs_fs.h
diff --git a/fsck/check.c b/fsck/check.c
deleted file mode 100644
index bbd178e..0000000
--- a/fsck/check.c
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * Copyright 1996, 1997 Hans Reiser
- */
-
-#include "fsck.h"
-
-
-/* this goes through buffers checking delimiting keys
- */
-
-struct buffer_head * g_left = 0;
-struct buffer_head * g_right = 0;
-struct key * g_dkey = 0;
-
-
-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 < 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");
-}
-
-
-static void check_items (struct buffer_head * bh)
-{
- int i;
- struct item_head * ih;
-
- for (i = 0; i < B_NR_ITEMS (bh); i++)
- {
- ih = B_N_PITEM_HEAD (bh, i);
-
- if (is_direntry_ih (ih))
- check_directory_item (ih, bh);
-
- }
-}
-
-
-static void compare_neighboring_leaves_in_pass1 (void)
-{
- struct key * left = B_N_PKEY (g_left, B_NR_ITEMS (g_left) - 1);
-
- if (comp_keys (left, B_N_PKEY (g_right, 0)) != -1/*SECOND_GREATER*/)
- die ("compare_neighboring_leaves_in_pass1: left key is greater, that the right one");
-
- if (/*comp_keys (B_PRIGHT_DELIM_KEY (g_left), g_dkey) == FIRST_GREATER ||*/
- comp_keys (g_dkey, B_N_PKEY (g_right, 0))) {
- reiserfs_panic (0, "compare_neighboring_leaves_in_pass1: dkey %k, first key in right %k",
- g_dkey, B_N_PKEY (g_right, 0));
- }
-
- check_items (g_left);
-
- /*&&&&&&&&&&&&&&&&&&&&&&&&&&
- for (i = 0, ih = B_N_PITEM_HEAD (g_left, i); i < B_NR_ITEMS (g_left); i ++, ih ++)
- if (is_item_accessed (ih) == YES)
- die ("compare_neighboring_leaves_in_pass1: item marked as accessed in g_left");
- for (i = 0, ih = B_N_PITEM_HEAD (g_right, i); i < B_NR_ITEMS (g_right); i ++, ih ++)
- if (is_item_accessed (ih) == YES)
- die ("compare_neighboring_leaves_in_pass1: item marked as accessed in g_right");
- &&&&&&&&&&&&&&&&&&&&&&&&&&&*/
-
-}
-
-
-static void is_there_unaccessed_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 (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",
- bh->b_blocknr);
- }
- }
-}
-
-
-static void compare_neighboring_leaves_after_all (void)
-{
- struct item_head * left = B_N_PITEM_HEAD(g_left, B_NR_ITEMS (g_left) - 1);
- struct item_head * right = B_N_PITEM_HEAD(g_right, 0);
- /* struct key * left = B_N_PKEY (g_left, B_NR_ITEMS (g_left) - 1);
- struct key * right = B_N_PKEY (g_right, 0);*/
-
- /*
- if (comp_keys (&left->ih_key, B_PRIGHT_DELIM_KEY (g_left)) != SECOND_GREATER)
- die ("compare_neighboring_leaves_after_all: invalid right delimiting key");
- */
- if (comp_keys (&left->ih_key, B_N_PKEY (g_right, 0)) != -1/*SECOND_GREATER*/)
- die ("compare_neighboring_leaves_after_all: left key is greater than the right one");
-
- if (//comp_le_keys (B_PRIGHT_DELIM_KEY (g_left), g_dkey) != KEYS_IDENTICAL ||
- comp_keys (g_dkey, B_N_PKEY (g_right, 0))) {
- reiserfs_panic (0, "compare_neighboring_leaves_after all: invalid delimiting keys from left to right (%k %k)",
- g_dkey, B_N_PKEY (g_right, 0));
- }
-
- if (!not_of_one_file (&left->ih_key, &right->ih_key)) {
- // items of one file: check offset correctness
- if (is_direct_ih (left) || is_indirect_ih (left))
- //if (get_offset(&right->ih_key) != get_offset(&left->ih_key) + get_bytes_number (g_left, left /*B_NR_ITEMS (g_left) - 1*/, 0, CHECK_FREE_BYTES))
- if (get_offset(&right->ih_key) != get_offset(&left->ih_key) + get_bytes_number (left, g_left->b_size))
- die ("compare_neighboring_leaves_after all: hole between items or items are overlapped");
- }
- is_there_unaccessed_items (g_left);
-
-}
-
-
-typedef void (check_function_t)(void);
-
-
-/* only directory item can be fatally bad */
-static int is_leaf_bad_xx (struct buffer_head * bh)
-{
- int i;
- struct item_head * ih;
-
- if (!is_leaf_node (bh))
- return 0;
- for (i = 0, ih = B_N_PITEM_HEAD (bh, 0); i < B_NR_ITEMS (bh); i ++, ih ++)
- if (is_bad_item (bh, ih, B_I_PITEM (bh, ih))) {
- return 1;
- }
- return 0;
-}
-
-
-static void reiserfsck_check_tree (int dev, unsigned long block, int size, check_function_t comp_func)
-{
- struct buffer_head * bh;
- int what_node;
-
- bh = bread (dev, block, size);
- if (bh == 0)
- reiserfs_panic("reiserfsck_check_tree: unable to read %lu block on device 0x%x\n",
- block, dev);
-
- if (!B_IS_IN_TREE (bh)) {
- reiserfs_panic (0, "reiserfsck_check_tree: buffer (%b %z) not in tree", bh, bh);
- }
-
- what_node = who_is_this (bh->b_data, bh->b_size);
- if (what_node != THE_LEAF && what_node != THE_INTERNAL)
- die ("Not formatted node");
-
- if (!is_block_used (bh->b_blocknr))
- die ("Not marked as used");
-
- if (is_leaf_node (bh) && is_leaf_bad_xx (bh))
- die ("Bad leaf %lu", bh->b_blocknr);
-
- if (is_internal_node(bh) && is_internal_bad (bh))
- die ("bad internal");
-
- if (is_internal_node (bh)) {
- int i;
- struct disk_child * dc;
-
- dc = B_N_CHILD (bh, 0);
- for (i = 0; i <= B_NR_ITEMS (bh); i ++, dc ++) {
- 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)) {
- g_right = bh;
- if (g_left != 0 && g_dkey != 0) {
- comp_func ();
- brelse (g_left);
- }
- g_left = g_right;
- return;
- } else {
- reiserfs_panic ("reiserfsck_check_tree: block %lu has bad block type (%b)",
- bh->b_blocknr, bh);
- }
- brelse (bh);
-}
-
-static void reiserfsck_check_cached_tree (int dev, unsigned long block, int size)
-{
- struct buffer_head * bh;
- int what_node;
-
- bh = find_buffer(dev, block, size);
- if (bh == 0)
- return;
- if (!buffer_uptodate (bh)) {
- die ("reiserfsck_check_cached_tree: found notuptodate buffer");
- }
-
- bh->b_count ++;
-
- if (!B_IS_IN_TREE (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);
- if ((what_node != THE_LEAF && what_node != THE_INTERNAL) ||
- !is_block_used (bh->b_blocknr) ||
- (is_leaf_node (bh) && is_leaf_bad (bh)) ||
- (is_internal_node(bh) && is_internal_bad (bh)))
- die ("reiserfsck_check_cached_tree: bad node in the tree");
- if (is_internal_node (bh)) {
- int i;
- struct disk_child * dc;
-
- dc = B_N_CHILD (bh, 0);
- for (i = 0; i <= B_NR_ITEMS (bh); i ++, dc ++) {
- 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)) {
- brelse (bh);
- return;
- } else {
- reiserfs_panic ("reiserfsck_check_cached_tree: block %lu has bad block type (%b)",
- bh->b_blocknr, bh);
- }
- brelse (bh);
-}
-
-
-void reiserfsck_tree_check (check_function_t how_to_compare_neighbors)
-{
- g_left = 0;
- g_dkey = 0;
- reiserfsck_check_tree (fs->fs_dev, get_sb_root_block (fs->fs_ondisk_sb),
- fs->fs_blocksize, how_to_compare_neighbors);
- brelse (g_right);
-}
-
-
-void reiserfsck_check_pass1 ()
-{
- /* if (opt_check == 1)*/
- reiserfsck_tree_check (compare_neighboring_leaves_in_pass1);
-}
-
-void check_cached_tree ()
-{
- reiserfsck_check_cached_tree (fs->fs_dev, get_sb_root_block (fs->fs_ondisk_sb),
- fs->fs_blocksize);
-}
-
-void reiserfsck_check_after_all ()
-{
- reiserfsck_tree_check (compare_neighboring_leaves_after_all);
-}
-
-#if 0
-static int is_bad_sd (struct item_head * ih, char * item)
-{
- struct stat_data * sd = (struct stat_data *)item;
-
- if (!S_ISDIR (sd->sd_mode) && !S_ISREG(sd->sd_mode) &&
- !S_ISCHR (sd->sd_mode) && !S_ISBLK(sd->sd_mode) &&
- !S_ISLNK (sd->sd_mode) && !S_ISFIFO(sd->sd_mode) &&
- !S_ISSOCK(sd->sd_mode)) {
- fsck_log ("file %k unexpected mode encountered 0%o\n", &ih->ih_key, sd->sd_mode);
- }
- return 0;
-}
-#endif
-
-
-
-#include <sys/ioctl.h>
-#include <sys/mount.h>
-
-
-unsigned long blocks_on_device (int dev, int blocksize)
-{
- unsigned long size;
-
- if (ioctl (dev, BLKGETSIZE, &size) >= 0) {
- return size / (blocksize / 512);
- }
- if (ioctl (dev, BLKGETSIZE, &size) >= 0) {
- return size / (blocksize / 512);
- } else {
- struct stat stat_buf;
- memset(&stat_buf, '\0', sizeof(struct stat));
- if(fstat(dev, &stat_buf) >= 0) {
- return stat_buf.st_size / (blocksize / 512);
- } else {
- die ("can not calculate device size\n");
- }
- }
- return 0;
-}
-
-
-int is_internal_bad (struct buffer_head * bh)
-{
- struct key * key;
-
- int i;
-
- if (!is_internal_node(bh))
- return 0;
- for (i = 0; i < B_NR_ITEMS (bh); i ++) {
- key = B_N_PDELIM_KEY (bh, i);
- 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;
-}
-
-
diff --git a/fsck/check_tree.c b/fsck/check_tree.c
index 621afb6..1a83ab0 100644
--- a/fsck/check_tree.c
+++ b/fsck/check_tree.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1999 Hans Reiser
+ * Copyright 1999, 2000, 2001, 2002 Hans Reiser
*/
#include "fsck.h"
@@ -64,7 +64,6 @@ int should_be_relocated (struct key * key)
//
//
-// check S+ tree of the file system
//
// check_fs_tree stops and recommends to run fsck --rebuild-tree when:
// 1. read fails
@@ -124,7 +123,7 @@ static void init_control_bitmap (reiserfs_filsys_t * fs)
control_bitmap = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
if (!control_bitmap)
- die ("init_control_bitmap: could not create control bitmap");
+ die ("init_control_bitmap: Failed to allocate a control bitmap.");
/*printf ("Initially number of zeros in control bitmap %d\n", reiserfs_bitmap_zeros (control_bitmap));*/
@@ -157,7 +156,7 @@ static void init_control_bitmap (reiserfs_filsys_t * fs)
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_control_bitmap: wrong super block");
+ die ("init_control_bitmap: Wrong super block location. You must run --rebuild-sb.");
block = get_journal_start_must (fs);
@@ -177,11 +176,10 @@ static void init_control_bitmap (reiserfs_filsys_t * fs)
s_free_blocks - we can fix that */
static void handle_bitmaps (reiserfs_filsys_t * fs)
{
- int diff, problem = 0;
+ int problem = 0;
if (tree_scanning_failed) {
- fsck_progress ("Could not scan whole tree. "
- "--rebuild-tree is required\n");
+ fsck_progress ("Could not scan the internal tree. --rebuild-tree is required\n");
return;
}
@@ -189,22 +187,21 @@ static void handle_bitmaps (reiserfs_filsys_t * fs)
/* check free block counter */
if (get_sb_free_blocks (fs->fs_ondisk_sb) != reiserfs_bitmap_zeros (control_bitmap)) {
- fsck_log ("free block count %lu mismatches with a correct one %lu. \n",
- get_sb_free_blocks (fs->fs_ondisk_sb),
+/* fsck_log ("vpf-10630: The count of free blocks in the on-disk bitmap (%lu) mismatches "
+ "with the correct one (%lu).\n", get_sb_free_blocks (fs->fs_ondisk_sb),
reiserfs_bitmap_zeros (control_bitmap));
+*/
problem++;
-// one_more_corruption (fs, fatal); /* for now */
}
- diff = reiserfs_bitmap_compare (source_bitmap, control_bitmap);
- if (diff) {
- fsck_log ("on-disk bitmap does not match to the correct one. \n", diff);
- problem++;
- }
+ if (reiserfs_bitmap_compare (source_bitmap, control_bitmap))
+ problem++;
if (problem) {
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
- fsck_progress ("Trying to fix bitmap ..\n", diff);
+ fsck_log ("vpf-10630: The on-disk and the correct bitmaps differs. "
+ "Will be fixed later.\n");
+// fsck_progress ("Trying to fix bitmap ..\n");
/* mark blocks as used in source bitmap if they are used in control bitmap */
reiserfs_bitmap_disjunction (source_bitmap, control_bitmap);
/* change used blocks count accordinly source bitmap,
@@ -212,17 +209,19 @@ static void handle_bitmaps (reiserfs_filsys_t * fs)
set_sb_free_blocks (fs->fs_ondisk_sb, reiserfs_bitmap_zeros (source_bitmap));
reiserfs_bitmap_copy (fs->fs_bitmap2, source_bitmap);
mark_buffer_dirty (fs->fs_super_bh);
- /* check again */
+/*
+ // check again
if ((diff = reiserfs_bitmap_compare (source_bitmap, control_bitmap)) != 0) {
- /* do not mark them as fatal or fixable because one can live with leaked space.
- So this is not a fatal corruption, and fix-fixable cannot fix it */
-// one_more_corruption (fs, fatal);
+ // do not mark them as fatal or fixable because one can live with leaked space.
+ // So this is not a fatal corruption, and fix-fixable cannot fix it
fsck_progress (" bitmaps were not recovered. \n"
"\tYou can either run rebuild-tree or live with %d leaked blocks\n", diff);
} else {
- fsck_progress ("ok\n");
+ fsck_progress ("finished\n");
}
- } else {
+*/
+ } else if (problem) {
+ fsck_log ("vpf-10640: The on-disk and the correct bitmaps differs.\n");
while (problem) {
/* fixable corruptions because we can try to recover them w/out rebuilding the tree */
one_more_corruption (fs, fixable);
@@ -230,7 +229,7 @@ static void handle_bitmaps (reiserfs_filsys_t * fs)
}
}
} else
- fsck_progress ("ok\n");
+ fsck_progress ("finished\n");
return;
}
@@ -269,15 +268,6 @@ static int bad_block_number (reiserfs_filsys_t * fs, unsigned long block)
static int got_already (reiserfs_filsys_t * fs, unsigned long block)
{
-#if 0
- if (0/*opt_fsck_mode == FSCK_FAST_REBUILD*/){
- if (is_block_used(block)){
- fsck_log ("block %lu is in tree already\n", block);
- return 1;
- }
- } else {
-#endif
-
if (did_we_meet_it (block)) {
/* block is in tree at least twice */
return 1;
@@ -295,14 +285,14 @@ static int bad_block_head (reiserfs_filsys_t * fs, struct buffer_head * bh)
blkh = B_BLK_HEAD (bh);
if (get_blkh_nr_items (blkh) > (bh->b_size - BLKH_SIZE) / IH_SIZE) {
- fsck_log ("block %lu has wrong blk_nr_items (%z)\n",
- bh->b_blocknr, bh);
+ fsck_log ("block %lu: The number of items (%u) exceeds the limit.\n",
+ bh->b_blocknr, get_blkh_nr_items (blkh));
one_more_corruption (fs, fatal);
return 1;
}
if (who_is_this (bh->b_data, bh->b_size) != THE_LEAF) {
- fsck_log ("leaf %lu has wrong structure\n", bh->b_blocknr);
+ fsck_log ("block %lu: The block has wrong structure of items.\n", bh->b_blocknr);
one_more_corruption (fs, fatal);
return 1;
}
@@ -313,11 +303,11 @@ static int bad_block_head (reiserfs_filsys_t * fs, struct buffer_head * bh)
if (get_blkh_free_space (blkh) !=
sum_length - BLKH_SIZE - IH_SIZE * get_blkh_nr_items (blkh))
{
- fsck_log ("block (%lu) has wrong blk_free_space (%lu) should be (%lu)",
+ fsck_log ("block %lu: The free space (%lu) is incorrect, should be (%lu)",
bh->b_blocknr, get_blkh_free_space (blkh), sum_length - BLKH_SIZE - IH_SIZE * get_blkh_nr_items (blkh) );
if (fsck_mode(fs) == FSCK_FIX_FIXABLE) {
set_blkh_free_space (blkh, sum_length - BLKH_SIZE - IH_SIZE * get_blkh_nr_items (blkh));
- fsck_log (" - fixed on (%lu)\n", get_blkh_free_space (blkh));
+ fsck_log (" - corrected\n");
mark_buffer_dirty (bh);
} else {
fsck_log ("\n");
@@ -333,19 +323,16 @@ static int bad_block_head (reiserfs_filsys_t * fs, struct buffer_head * bh)
static int bad_stat_data (reiserfs_filsys_t * fs, struct buffer_head * bh, struct item_head * ih)
{
unsigned long objectid;
- __u32 pos;
- __u32 links;
struct stat_data * sd;
+ __u32 pos;
+// __u32 links;
+
-/*
- if (opt_fsck_mode == FSCK_FAST_REBUILD)
- return 0;
-*/
objectid = get_key_objectid (&ih->ih_key);
if (!is_objectid_used (fs, objectid)) {
/* FIXME: this could be cured right here */
- fsck_log ("\nbad_stat_data: %lu is marked free, but used by an object %k\n",
- objectid, &ih->ih_key);
+ fsck_log ("bad_stat_data: The objectid (%lu) is marked free, but used by an object %k\n",
+ objectid, &ih->ih_key);
/* if it is FIX_FIXABLE we flush objectid map at the end
no way to call one_less_corruption later
@@ -355,8 +342,7 @@ static int bad_stat_data (reiserfs_filsys_t * fs, struct buffer_head * bh, struc
}
if (is_objectid_really_used (proper_id_map (fs), objectid, &pos)) {
- fsck_log ("\nbad_stat_data: %lu is shared by at least two files\n",
- objectid);
+ fsck_log ("bad_stat_data: The objectid (%lu) is shared by at least two files\n", objectid);
if (fsck_mode (fs) == FSCK_FIX_FIXABLE)
to_be_relocated (&ih->ih_key);
@@ -366,27 +352,22 @@ static int bad_stat_data (reiserfs_filsys_t * fs, struct buffer_head * bh, struc
}
sd = (struct stat_data *)B_I_PITEM(bh,ih);
- if (fsck_mode (fs) == FSCK_CHECK) {
- get_sd_nlink (ih, sd, &links);
- if (S_ISDIR(sd->sd_mode)) {
- if (links < 2) {
- fsck_log ("%s: block %lu, [%k], directory SD has bad nlink number\n",
- __FUNCTION__, bh->b_blocknr, &ih->ih_key);
- one_more_corruption (fs, fixable);
- }
- } else {
- if (links == 0) {
- fsck_log ("%s: block %lu, [%k], SD has bad nlink number\n",
- __FUNCTION__, bh->b_blocknr, &ih->ih_key);
- one_more_corruption (fs, fixable);
- }
+/* Check this on semantic_check pass.
+ get_sd_nlink (ih, sd, &links);
+ if (S_ISDIR(sd->sd_mode)) {
+ if (links < 2) {
+ fsck_log ("%s: block %lu: The directory StatData %k has bad nlink number (%u)\n",
+ __FUNCTION__, bh->b_blocknr, &ih->ih_key, links);
+ one_more_corruption (fs, fatal);
}
} else {
- links = 0;
- set_sd_nlink (ih, sd, &links);
- mark_buffer_dirty (bh);
+ if (links == 0) {
+ fsck_log ("%s: block %lu: The StatData %k has bad nlink number (%u)\n",
+ __FUNCTION__, bh->b_blocknr, &ih->ih_key);
+ one_more_corruption (fs, fatal);
+ }
}
-
+*/
__mark_objectid_really_used (proper_id_map (fs), objectid, pos);
return 0;
}
@@ -401,7 +382,7 @@ static int bad_direct_item (reiserfs_filsys_t * fs, struct buffer_head * bh, str
inline void handle_one_pointer (reiserfs_filsys_t * fs, struct buffer_head * bh, __u32 * ptr) {
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
- fsck_log (" - fixed");
+ fsck_log (" - zeroed");
*ptr = 0;
mark_buffer_dirty (bh);
} else {
@@ -478,8 +459,8 @@ static int bad_indirect_item (reiserfs_filsys_t * fs, struct buffer_head * bh,
__u32 * ind = (__u32 *)B_I_PITEM (bh, ih);
if (get_ih_item_len (ih) % 4) {
- fsck_log ("%s: block %lu: item (%H) has bad length\n",
- __FUNCTION__, bh->b_blocknr, ih);
+ fsck_log ("%s: block %lu: The item (%H) has the bad length (%u)\n",
+ __FUNCTION__, bh->b_blocknr, ih, get_ih_item_len (ih));
one_more_corruption (fs, fatal);
return 1;
}
@@ -497,17 +478,16 @@ static int bad_indirect_item (reiserfs_filsys_t * fs, struct buffer_head * bh,
/* check unformatted node pointer and mark it used in the
control bitmap */
if (bad_block_number (fs, le32_to_cpu (ind [i]))) {
- fsck_log ("%s: block %lu: item %H has bad pointer %d: %lu",
- __FUNCTION__, bh->b_blocknr, ih, i, le32_to_cpu (ind [i]));
+ fsck_log ("%s: block %lu: The item %k has the bad pointer (%d) to the block (%lu)",
+ __FUNCTION__, bh->b_blocknr, &ih->ih_key, i, le32_to_cpu (ind [i]));
handle_one_pointer (fs, bh, &ind[i]);
fsck_log ("\n");
continue;
}
if (got_already (fs, le32_to_cpu (ind [i]))) {
- fsck_log ("%s: block %lu: item %H has a pointer %d "
- "to the block %lu which is in tree already",
- __FUNCTION__, bh->b_blocknr, ih, i, le32_to_cpu (ind [i]));
+ fsck_log ("%s: block %lu: The item (%H) has the bad pointer (%d) to the block (%lu), "
+ "which is in tree already", __FUNCTION__, bh->b_blocknr, ih, i, le32_to_cpu (ind [i]));
handle_one_pointer (fs, bh, &ind [i]);
fsck_log ("\n");
continue;
@@ -537,26 +517,25 @@ static int bad_directory_item (reiserfs_filsys_t * fs, struct buffer_head * bh,
char * name;
int namelen;
struct reiserfs_de_head * deh = B_I_DEH (bh, ih);
- int min_entry_size = 1;/* we have no way to understand whether the
- filesystem were created in 3.6 format or
+ int min_entry_size = 1;/* We have no way to understand whether the
+ filesystem was created in 3.6 format or
converted to it. So, we assume that minimal name
length is 1 */
__u16 state;
-
/* make sure item looks like a directory */
if (get_ih_item_len (ih) / (DEH_SIZE + min_entry_size) < get_ih_entry_count (ih)) {
/* entry count can not be that big */
- fsck_log ("%s: block %lu: directory item %H has corrupted structure\n",
- __FUNCTION__, bh->b_blocknr, ih);
+ fsck_log ("%s: block %lu: The directory item %k has the exsessively big entry count (%u)\n",
+ __FUNCTION__, bh->b_blocknr, &ih->ih_key, get_ih_entry_count (ih));
one_more_corruption (fs, fatal);
return 1;
}
if (get_deh_location (&deh[get_ih_entry_count (ih) - 1]) != DEH_SIZE * get_ih_entry_count (ih)) {
/* last entry should start right after array of dir entry headers */
- fsck_log ("%s: block %lu: directory item %H has corrupted structure\n",
- __FUNCTION__, bh->b_blocknr, ih);
+ fsck_log ("%s: block %lu: The directory item %k has the corrupted entry structure\n",
+ __FUNCTION__, bh->b_blocknr, &ih->ih_key);
one_more_corruption (fs, fatal);
return 1;
}
@@ -566,8 +545,8 @@ static int bad_directory_item (reiserfs_filsys_t * fs, struct buffer_head * bh,
namelen = name_in_entry_length (ih, deh, i);
name = name_in_entry (deh, i);
if (!is_properly_hashed (fs, name, namelen, get_deh_offset (deh))) {
- fsck_log ("%s: block %lu: directory item %H has hashed bad entry\n",
- __FUNCTION__, bh->b_blocknr, ih);
+ fsck_log ("%s: block %lu: The directory item %k has a not properly hashed entry (%d)\n",
+ __FUNCTION__, bh->b_blocknr, &ih->ih_key, i);
one_more_corruption (fs, fatal);
return 1;
}
@@ -578,14 +557,14 @@ static int bad_directory_item (reiserfs_filsys_t * fs, struct buffer_head * bh,
/* ok, items looks like a directory */
for (i = 0; i < get_ih_entry_count (ih); i ++, deh ++) {
if (get_deh_state (deh) != state) {
- fsck_log ("bad_directory_item: block %lu: item %H has entry "
- "\"%.*s\" with wrong deh_state %o - expected %o",
- bh->b_blocknr, ih, name_in_entry_length (ih, deh, i),
- name_in_entry (deh, i), get_deh_state (deh), state );
+ fsck_log ("bad_directory_item: block %lu: The directory item %k has the entry (%d) "
+ "\"%.*s\" with a not legal state (%o), (%o) expected",
+ bh->b_blocknr, &ih->ih_key, i, name_in_entry_length (ih, deh, i),
+ name_in_entry (deh, i), get_deh_state (deh), state);
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
set_deh_state (deh, 1 << DEH_Visible2);
mark_buffer_dirty (bh);
- fsck_log (" - fixed");
+ fsck_log (" - corrected\n");
} else
one_more_corruption (fs, fixable);
@@ -600,20 +579,58 @@ static int bad_directory_item (reiserfs_filsys_t * fs, struct buffer_head * bh,
static int bad_item (reiserfs_filsys_t * fs, struct buffer_head * bh, int num)
{
struct item_head * ih;
+ int format;
ih = B_N_PITEM_HEAD (bh, num);
+ if ((get_ih_flags(ih)) != 0) {
+ if (fsck_mode(fs) == FSCK_CHECK) {
+ one_more_corruption (fs, fixable);
+ fsck_log ("%s: vpf-10570: block %lu: The item header (%d) has not cleaned flags.\n",
+ __FUNCTION__, bh->b_blocknr, num);
+ } else {
+ fsck_log ("%s: vpf-10580: block %lu: Flags in the item header (%d) were cleaned\n",
+ __FUNCTION__, bh->b_blocknr, num);
+ clean_ih_flags(ih);
+ mark_buffer_dirty(bh);
+ }
+ }
+
+
+ if (is_stat_data_ih(ih) && get_ih_item_len(ih) == SD_SIZE)
+ format = KEY_FORMAT_2;
+ else if (is_stat_data_ih(ih) && get_ih_item_len(ih) == SD_V1_SIZE)
+ format = KEY_FORMAT_1;
+ else
+ format = key_format(&ih->ih_key);
+
+ if (format != get_ih_key_format(ih)) {
+ if (fsck_mode(fs) == FSCK_CHECK) {
+ one_more_corruption (fs, fixable);
+ fsck_log ("%s: vpf-10710: block %lu: The format (%d) specified in the item header (%d) "
+ "differs from the key format (%d).\n", __FUNCTION__, bh->b_blocknr,
+ get_ih_key_format(ih), num, format);
+ } else {
+ fsck_log ("%s: vpf-10720: block %lu: The format (%d) specified in the item header (%d) "
+ "was fixed to the key format (%d).\n", __FUNCTION__, bh->b_blocknr,
+ get_ih_key_format(ih), num, format);
+
+ set_ih_key_format(ih, format);
+ mark_buffer_dirty(bh);
+ }
+ }
+
if (get_key_dirid (&ih->ih_key) == (__u32)-1) {
if (get_key_objectid (&ih->ih_key) != (__u32)-1) {
/* safe link can be
- -1 object_id 0x1 -2 (truncate) or
- -1 object_id blocksize+1 -1 (unlink)
+ -1 object_id 0x1 INDIRECT (truncate) or
+ -1 object_id blocksize+1 DIRECT (unlink)
*/
if (is_direct_ih(ih))
if (get_offset(&ih->ih_key) == fs->fs_blocksize + 1)
if (get_ih_item_len (ih) == 4) {
- /*fsck_log("vpf-00010: safe link found [%k]\n", &ih->ih_key);*/
+ /*fsck_log("vpf-00010: safe link found %k\n", &ih->ih_key);*/
fsck_check_stat(fs)->safe ++;
return 0;
}
@@ -621,7 +638,7 @@ static int bad_item (reiserfs_filsys_t * fs, struct buffer_head * bh, int num)
if (is_indirect_ih(ih))
if(get_offset(&ih->ih_key) == 0x1)
if (get_ih_item_len (ih) == 4) {
- /*fsck_log("vpf-00020: safe link found [%k]\n", &ih->ih_key);*/
+ /*fsck_log("vpf-00020: safe link found %k\n", &ih->ih_key);*/
fsck_check_stat(fs)->safe ++;
return 0;
}
@@ -630,7 +647,8 @@ static int bad_item (reiserfs_filsys_t * fs, struct buffer_head * bh, int num)
/* dir_id == -1 can be used only by safe links */
one_more_corruption (fs, fatal);
- fsck_log ("%s: vpf-10290: block %lu item with wrong key (%k) found\n", __FUNCTION__, bh->b_blocknr, &ih->ih_key);
+ fsck_log ("%s: vpf-10290: block %lu, item %d: The item has a wrong key %k\n",
+ __FUNCTION__, num, bh->b_blocknr, &ih->ih_key);
return 1;
} else {
@@ -644,12 +662,14 @@ static int bad_item (reiserfs_filsys_t * fs, struct buffer_head * bh, int num)
} else {*/
one_more_corruption (fs, fatal);
- fsck_log ("%s: vpf-10300: block %lu item with wrong key (%k) found\n", __FUNCTION__, bh->b_blocknr, &ih->ih_key);
+ fsck_log ("%s: vpf-10300: block %lu, item %d: The item has a wrong key %k\n",
+ __FUNCTION__, num, bh->b_blocknr, &ih->ih_key);
return 1;
}
} else if (get_key_objectid (&ih->ih_key) == (__u32)-1) {
one_more_corruption (fs, fatal);
- fsck_log ("%s: vpf-10310: block %lu item with wrong key (%k) found\n", __FUNCTION__, bh->b_blocknr, &ih->ih_key);
+ fsck_log ("%s: vpf-10310: block %lu, item %d: The item has a wrong key %k\n",
+ __FUNCTION__, num, bh->b_blocknr, &ih->ih_key);
return 1;
}
@@ -751,13 +771,13 @@ static int bad_leaf (reiserfs_filsys_t * fs, struct buffer_head * bh)
for (i = 0; i < B_NR_ITEMS (bh); i ++) {
if (bad_item (fs, bh, i)) {
- fsck_log ("bad_leaf: block %lu has invalid item %d: %H\n",
- bh->b_blocknr, i, B_N_PITEM_HEAD (bh, i));
+ fsck_log ("bad_leaf: block %lu, item %d: The corrupted item found (%H)\n",
+ bh->b_blocknr, i, B_N_PITEM_HEAD (bh, i));
}
if (i && bad_pair (fs, bh, i)) {
- fsck_log ("bad_leaf: block %lu has wrong order of items [%d, %d]: %k %k\n",
- bh->b_blocknr, i-1, i, &B_N_PITEM_HEAD (bh, i-1)->ih_key, &B_N_PITEM_HEAD (bh, i)->ih_key);
+ fsck_log ("bad_leaf: block %lu, items %d and %d: The wrong order of items: %k, %k\n",
+ bh->b_blocknr, i-1, i, &B_N_PITEM_HEAD (bh, i-1)->ih_key, &B_N_PITEM_HEAD (bh, i)->ih_key);
}
}
return 0;
@@ -772,16 +792,16 @@ static int bad_internal (reiserfs_filsys_t * fs, struct buffer_head * bh)
if (i != B_NR_ITEMS (bh) && i != B_NR_ITEMS (bh) - 1)
/* make sure that keys are in increasing order */
if (comp_keys (B_N_PDELIM_KEY (bh, i), B_N_PDELIM_KEY (bh, i + 1)) != -1) {
- fsck_log ("%s: vpf-10320: block %lu has wrong order of keys %k, %k\n",
- __FUNCTION__, bh->b_blocknr, B_N_PDELIM_KEY (bh, i), B_N_PDELIM_KEY (bh, i + 1));
+ fsck_log ("%s: vpf-10320: block %lu, items %d and %d: The wrong order of items: %k, %k\n",
+ __FUNCTION__, bh->b_blocknr, i, i+1, B_N_PDELIM_KEY (bh, i), B_N_PDELIM_KEY (bh, i + 1));
one_more_corruption (fs, fatal);
return 1;
}
/* make sure that the child is correct */
if (bad_block_number (fs, get_dc_child_blocknr (B_N_CHILD (bh,i)))) {
- fsck_log ("%s: vpf-10330: block %lu: has bad pointer %d: %lu\n",
- __FUNCTION__, bh->b_blocknr, i, get_dc_child_blocknr (B_N_CHILD (bh,i)));
+ fsck_log ("%s: vpf-10330: block %lu, item %d: The internal item points to the not legal block (%lu)\n",
+ __FUNCTION__, bh->b_blocknr, i, get_dc_child_blocknr (B_N_CHILD (bh,i)));
one_more_corruption (fs, fatal);
return 1;
}
@@ -804,21 +824,21 @@ static int bad_node (reiserfs_filsys_t * fs, struct buffer_head ** path,
struct buffer_head ** pbh = &path[h];
if (B_LEVEL (*pbh) != h_to_level (fs, h)) {
- fsck_log ("node (%lu) with wrong level (%d) found in the tree (should be %d)\n",
- (*pbh)->b_blocknr, B_LEVEL (*pbh), h_to_level (fs, h));
+ fsck_log ("block %lu: The level of the node (%d) is not correct, (%d) expected\n",
+ (*pbh)->b_blocknr, B_LEVEL (*pbh), h_to_level (fs, h));
one_more_corruption (fs, fatal);
return 1;
}
if (bad_block_number (fs, (*pbh)->b_blocknr)) {
one_more_corruption (fs, fatal);
- fsck_log ("%s: vpf-10340: wrong block number %lu found in the tree\n",
+ fsck_log ("%s: vpf-10340: The node in the wrong block number (%lu) found in the tree\n",
__FUNCTION__, (*pbh)->b_blocknr);
return 1;
}
if (got_already (fs, (*pbh)->b_blocknr)) {
- fsck_log ("%s: vpf-10350: block number %lu is already in the tree\n",
+ fsck_log ("%s: vpf-10350: The block (%lu) is used more then once in the tree.\n",
__FUNCTION__, (*pbh)->b_blocknr);
one_more_corruption (fs, fatal);
return 1;
@@ -843,7 +863,8 @@ static int get_pos (struct buffer_head * bh, unsigned long block)
if (get_dc_child_blocknr (B_N_CHILD (bh, i)) == block)
return i;
}
- die ("get_pos: position for block %lu not found", block);
+ die ("An internal pointer to the block (%lu) cannot be found in the node (%lu)",
+ block, bh->b_blocknr);
return 0;
}
@@ -892,7 +913,7 @@ static int bad_path (reiserfs_filsys_t * fs, struct buffer_head ** path, int h1)
// path[h] is leaf
if (h != h1)
- die ("bad_path: wrong path");
+ die ("bad_path: The leaf is expected as the last element in the path");
if (h)
pos = get_pos (path[h - 1], path[h]->b_blocknr);
@@ -901,8 +922,8 @@ static int bad_path (reiserfs_filsys_t * fs, struct buffer_head ** path, int h1)
if (dk && comp_keys (dk, B_N_PKEY (path[h], 0))) {
/* left delimiting key must be equal to the key of 0-th item in the
node */
- fsck_log ("bad_path: left delimiting key %k must be equal to %k (block %lu, pos %d)\n",
- dk, B_N_PKEY (path[h], 0), path[h]->b_blocknr, 0);
+ fsck_log ("bad_path: The left delimiting key %k of the node (%lu) must be equal to the first element's "
+ "key %k within the node.\n", dk, path[h]->b_blocknr, B_N_PKEY (path[h], 0));
one_more_corruption (fs, fatal);
return 1;
}
@@ -910,11 +931,10 @@ static int bad_path (reiserfs_filsys_t * fs, struct buffer_head ** path, int h1)
dk = rkey (path, h);
if (dk && comp_keys (dk, B_N_PKEY (path[h],
get_blkh_nr_items (B_BLK_HEAD (path[h])) - 1)) != 1) {
- /* right delimiting key must be bigger than the key of the last item
- in the node */
- fsck_log ("bad_path: right delimiting key %k must be equal to %k (block %lu, pos %d)\n",
- dk, B_N_PKEY (path[h], get_blkh_nr_items (B_BLK_HEAD (path[h])) - 1),
- path[h]->b_blocknr, get_blkh_nr_items (B_BLK_HEAD (path[h])) - 1);
+ /* right delimiting key must be greater than the key of the last item in the node */
+ fsck_log ("bad_path: The right delimiting key %k of the node (%lu) must be greater then the last (%d) element's"
+ "key %k within the node.\n", dk, path[h]->b_blocknr, get_blkh_nr_items (B_BLK_HEAD (path[h])) - 1,
+ B_N_PKEY (path[h], get_blkh_nr_items (B_BLK_HEAD (path[h])) - 1));
one_more_corruption (fs, fatal);
return 1;
}
@@ -924,17 +944,15 @@ static int bad_path (reiserfs_filsys_t * fs, struct buffer_head ** path, int h1)
BLKH_SIZE != path[h]->b_size))
{
/* wrong dc_size */
-
- fsck_log ("bad_path: wrong sum of dc_size %d (block %lu, pos %d) ",
- get_dc_child_size (B_N_CHILD(path[h-1],pos)), path[h-1]->b_blocknr, pos);
- fsck_log ("free space %d (block %lu) and BLKH_SIZE %lu",
- get_blkh_free_space ((struct block_head *)path[h]->b_data),
- path[h]->b_blocknr, BLKH_SIZE);
+ fsck_log ("bad_path: block %lu, pointer %d: The used space (%d) of the child block (%lu)",
+ path[h-1]->b_blocknr, pos, get_dc_child_size (B_N_CHILD(path[h-1],pos)), path[h]->b_blocknr);
+ fsck_log (" is not equal to the (blocksize (4096) - free space (%d) - header size (%u))",
+ get_blkh_free_space ((struct block_head *)path[h]->b_data), BLKH_SIZE);
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
set_dc_child_size (B_N_CHILD(path[h-1],pos), path[h]->b_size -
get_blkh_free_space ((struct block_head *)path[h]->b_data) - BLKH_SIZE);
- fsck_log (" - fixed (%lu)\n", get_dc_child_size (B_N_CHILD(path[h-1],pos)));
+ fsck_log (" - corrected to (%lu)\n", get_dc_child_size (B_N_CHILD(path[h-1],pos)));
mark_buffer_dirty (path[h-1]);
} else {
one_more_corruption (fs, fixable);
@@ -960,22 +978,25 @@ static void after_check_fs_tree (reiserfs_filsys_t * fs) {
fs->fs_dirt = 1;
reiserfs_flush_to_ondisk_bitmap (fs->fs_bitmap2, fs);
reiserfs_flush (fs);
- }
- reiserfs_delete_bitmap (source_bitmap);
+ reiserfs_bitmap_delta (source_bitmap, control_bitmap);
+ fsck_deallocate_bitmap(fs) = source_bitmap;
+ } else
+ reiserfs_delete_bitmap (source_bitmap);
+
reiserfs_delete_bitmap (control_bitmap);
flush_buffers (fs->fs_dev);
}
-/* pass the S+ tree of filesystem */
+/* pass internal tree of filesystem */
void check_fs_tree (reiserfs_filsys_t * fs)
{
before_check_fs_tree (fs);
- fsck_progress ("Checking S+tree..");
+ fsck_progress ("Checking internal tree..");
pass_through_tree (fs, bad_node, bad_path);
- /* S+ tree is correct (including all objects have correct
+ /* internal tree is correct (including all objects have correct
sequences of items) */
- fsck_progress ("ok\n");
+ fsck_progress ("finished\n");
/* compare created bitmap with the original */
handle_bitmaps (fs);
@@ -988,7 +1009,7 @@ static int clean_attributes_handler (reiserfs_filsys_t * fs, struct buffer_head
int i;
if (B_LEVEL (bh) != h_to_level (fs, h)) {
- reiserfs_panic ("node (%lu) with wrong level (%d) found in the tree (should be %d)\n",
+ reiserfs_panic ("The node (%lu) with wrong level (%d) found in the tree, (%d) expected\n",
bh->b_blocknr, B_LEVEL (bh), h_to_level (fs, h));
}
@@ -1012,296 +1033,3 @@ void do_clean_attributes (reiserfs_filsys_t * fs) {
mark_buffer_dirty (fs->fs_super_bh);
}
-#if 0
-
-void remove_internal_pointer(struct super_block * s, struct buffer_head ** path)
-{
- int h = 0;
- int pos, items;
- __u32 block;
-
-
- while (path[h])
- h ++;
-
- h--;
- block = path[h]->b_blocknr;
- printf("\nremove pointer to (%d) block", block);
- brelse(path[h]);
- path[h] = 0;
- h--;
- while (h>=0)
- {
- if (B_NR_ITEMS(path[h]) <= 1)
- {
- block = path[h]->b_blocknr;
- brelse(path[h]);
- path[h] = 0;
- mark_block_free(block);
- /*unmark_block_formatted(block);*/
- used_blocks++;
- h --;
- continue;
- }
- pos = get_pos (path[h], block);
- if (pos)
- {
- memmove (B_N_CHILD(path[h],pos), B_N_CHILD(path[h],pos+1),
- s->s_blocksize - BLKH_SIZE - B_NR_ITEMS(path[h])*KEY_SIZE - DC_SIZE*(pos+1));
- memmove(B_N_PDELIM_KEY(path[h],pos-1), B_N_PDELIM_KEY(path[h],pos),
- s->s_blocksize - BLKH_SIZE - (pos)*KEY_SIZE);
- }else{
- __u32 move_block = path[h]->b_blocknr;
- int move_to_pos;
- int height = h;
-
- while(--height >= 0)
- {
- move_to_pos = get_pos (path[height], move_block);
- if (move_to_pos == 0){
- move_block = path[height]->b_blocknr;
- continue;
- }
- *B_N_PDELIM_KEY(path[height], move_to_pos-1) = *B_N_PDELIM_KEY(path[h], 0);
- break;
- }
-
- memmove (B_N_CHILD(path[h], 0), B_N_CHILD(path[h], 1),
- s->s_blocksize - BLKH_SIZE - B_NR_ITEMS(path[h])*KEY_SIZE - DC_SIZE);
- memmove(B_N_PDELIM_KEY(path[h], 0), B_N_PDELIM_KEY(path[h], 1),
- s->s_blocksize - BLKH_SIZE - KEY_SIZE);
- }
- set_node_item_number(path[h], node_item_number(path[h]) - 1);
- mark_buffer_dirty(path[h], 1);
- break;
- }
- if (h == -1)
- {
- SB_DISK_SUPER_BLOCK(s)->s_root_block = ~0;
- SB_DISK_SUPER_BLOCK(s)->s_tree_height = ~0;
- mark_buffer_dirty(SB_BUFFER_WITH_SB(s), 1);
- }
-}
-
-void handle_buffer(struct super_block * s, struct buffer_head * bh)
-{
- int i, j;
- struct item_head * ih;
-
- if (is_leaf_node (bh))
- {
- for (i = 0, ih = B_N_PITEM_HEAD (bh, 0); i < B_NR_ITEMS (bh); i ++, ih ++)
- {
- if (is_indirect_ih(ih))
- for (j = 0; j < I_UNFM_NUM (ih); j ++)
- if (B_I_POS_UNFM_POINTER(bh,ih,j)){
- /*mark_block_unformatted(le32_to_cpu(B_I_POS_UNFM_POINTER(bh,ih,j)));*/
- mark_block_used(le32_to_cpu(B_I_POS_UNFM_POINTER(bh,ih,j)));
- used_blocks++;
- }
- if (is_stat_data_ih (ih)) {
- /*add_event (STAT_DATA_ITEMS);*/
- if (ih_key_format(ih) == KEY_FORMAT_1)
- ((struct stat_data_v1 *)B_I_PITEM(bh,ih))->sd_nlink = 0;
- else
- ((struct stat_data *)B_I_PITEM(bh,ih))->sd_nlink = 0;
- mark_buffer_dirty(bh, 1);
- }
- }
- }
- mark_block_used(bh->b_blocknr);
-// we_met_it(s, bh->b_blocknr);
- used_blocks++;
-}
-
-/* bh must be formatted node. blk_level must be tree_height - h + 1 */
-static int handle_node (struct super_block * s, struct buffer_head ** path, int h)
-{
- if (bad_node(s, path, h)){
- remove_internal_pointer(s, path);
- return 1;
- }
- handle_buffer(s, path[h]);
- return 0;
-}
-
-/* are all delimiting keys correct */
-static int handle_path (struct super_block * s, struct buffer_head ** path, int h)
-{
- if (bad_path(s, path, h)){
- remove_internal_pointer(s, path);
- return 1;
- }
- return 0;
-}
-
-//return 1 to run rebuild tree from scratch
-void check_internal_structure(struct super_block * s)
-{
- /* control bitmap is used to keep all blocks we should not put into tree again */
- /* used bitmap is used to keep all inserted blocks. The same as control bitmap plus unfm blocks */
-// init_control_bitmap(s);
-
- printf ("Checking S+tree..");
-
- pass_through_tree (s, handle_node, handle_path);
-
-// compare_bitmaps(s);
- printf ("ok\n");
-}
-
-#endif
-/*
-int check_sb (reiserfs_filsys_t * fs)
-{
-
-
- reiserfs_panic ("Not ready");
- return 0;
-#if 0
- int format_sb = 0;
- int problem = 0;
- struct reiserfs_super_block * sb;
- __u32 block_count;
- unsigned long j_1st_block;
- int sb_version;
-
- sb = fs->fs_ondisk_sb;
- j_1st_block = get_jp_journal_1st_block (sb_jp (sb));
-
- // in (REISERFS_DISK_OFFSET_IN_BYTES / 4096) block
- if ((is_reiser2fs_magic_string (sb) || is_reiser2fs_jr_magic_string (sb) )&&
- j_1st_block == get_journal_new_start_must (fs)) {
- // 3.6 or >=3.5.22
- printf("\t 3.6.x format SB found\n");
- format_sb = 1;
- goto good_format;
- }
-
- if ( (is_reiserfs_magic_string (sb) ||is_reiser2fs_jr_magic_string (sb) ) &&
- j_1st_block == get_journal_new_start_must (fs)) {
- // >3.5.9(10) and <=3.5.21
- printf("\t>=3.5.9 format SB found\n");
- format_sb = 2;
- goto good_format;
- }
-
- // in 2 block
- if ( (is_reiser2fs_magic_string (sb) || is_reiser2fs_jr_magic_string (sb) ) &&
- j_1st_block == get_journal_old_start_must (sb)) {
- // <3.5.9(10) converted to new format
- printf("\t< 3.5.9(10) SB converted to new format found \n");
- format_sb = 3;
- goto good_format;
- }
-
- if ( (is_reiserfs_magic_string (sb) ||is_reiser2fs_jr_magic_string (sb) ) &&
- j_1st_block == get_journal_old_start_must (sb)) {
- // <3.5.9(10)
- printf("\t< 3.5.9(10) format SB found\n");
- format_sb = 4;
- goto good_format;
- }
- else
- die("check SB: wrong SB format found\n");
-
-good_format:
-
- printf("\n\t%d-%d\n", get_sb_block_count (sb), get_sb_free_blocks (sb));
- if (fs->fs_blocksize != 4096) {
- //???
- fsck_log("check SB: specified block size (%d) is not correct must be 4096\n",
- fs->fs_blocksize);
- problem++;
- }
-
- //for 4096 blocksize only
- if ((get_sb_tree_height (sb) < DISK_LEAF_NODE_LEVEL + 1) ||
- (get_sb_tree_height (sb) > MAX_HEIGHT)){
- fsck_log ("check SB: wrong tree height (%d)\n", get_sb_tree_height (sb));
- problem++;
- }
-
- block_count = count_blocks (fs->fs_file_name, fs->fs_blocksize);
-
- if (get_sb_block_count (sb) > block_count){
- fsck_log ("check SB: specified block number (%d) is too high\n",
- get_sb_block_count (sb));
- problem++;
- }
-
- if ((get_sb_root_block (sb) >= block_count)) {
- fsck_log ("check SB: specified root block number (%d) is too high\n",
- get_sb_root_block (sb));
- problem++;
- }
-
- if (get_sb_free_blocks (sb) > get_sb_block_count (sb)) {
- fsck_log ("check SB: specified free block number (%d) is too high\n",
- get_sb_free_blocks (sb));
- problem++;
- }
-
- if (get_sb_state (sb) != REISERFS_VALID_FS && get_sb_state (sb) != REISERFS_ERROR_FS){
- fsck_log ("check SB: unknown (%d) state\n", get_sb_state (sb));
- problem++;
- }
-
- if (get_sb_bmap_nr (sb) != (get_sb_block_count (sb) + (fs->fs_blocksize * 8 - 1)) / (fs->fs_blocksize * 8)) {
- fsck_log("check SB: wrong bitmap number (%d)\n", get_sb_bmap_nr (sb));
- problem++;
- }
-
- sb_version = get_sb_version (sb);
- if (sb_version == REISERFS_VERSION_3 || sb_version == REISERFS_VERSION_2 || sb_version == REISERFS_VERSION_1) {
- if (!((sb_version == REISERFS_VERSION_3 ||sb_version == REISERFS_VERSION_2) && (format_sb == 1 || format_sb == 3)) &&
- !(sb_version == REISERFS_VERSION_1 && (format_sb == 2 || format_sb == 4))) {
- fsck_log("check SB: wrong SB version == %d, format == %d\n",
- sb_version, format_sb);
- problem++;
- }
- } else {
- fsck_log ("check SB: wrong SB version (%d)\n", sb_version);
- problem++;
- }
-
- if ((sb_version == REISERFS_VERSION_3 ||sb_version == REISERFS_VERSION_2) &&
- // FIXME:
- (get_sb_hash_code (sb) < 1 || get_sb_hash_code (sb) > 3)) {
- fsck_log("check SB: wrong hash (%d)\n", get_sb_hash_code (sb));
- problem++;
- }
-
-
- if ((sb_version == REISERFS_VERSION_3 ||sb_version == REISERFS_VERSION_2) ?
- (get_sb_oid_maxsize (sb) != ((fs->fs_blocksize - SB_SIZE) / sizeof(__u32) / 2 * 2)) :
- (get_sb_oid_maxsize (sb) != ((fs->fs_blocksize - SB_SIZE_V1) / sizeof(__u32) / 2 * 2))) {
- fsck_log("check SB: objectid map corrupted max_size == %d\n",
- get_sb_oid_maxsize (sb));
- problem++;
- }
-
- if (get_sb_oid_cursize (sb) < 2 ||
- get_sb_oid_cursize (sb) > get_sb_oid_maxsize (sb)) {
- fsck_log("check SB: objectid map corrupted cur_size == %d\n",
- get_sb_oid_cursize (sb));
- problem++;
- }
-
- if (get_jp_journal_size (sb_jp (sb)) < JOURNAL_DEFAULT_SIZE/32 ){
- fsck_log("check SB: specified journal size (%d) is not correct must be not less that %d\n",
- get_jp_journal_size (sb_jp (sb)), JOURNAL_DEFAULT_SIZE/32);
- problem++;
- }
-
- if (!problem) {
- fsck_progress ("\t No problem found\n");
- } else if (fsck_log_file (fs) != stderr)
- fsck_progress ("Look for super block corruptions in the log file\n");
-
- return format_sb;
-
-#endif
-}
-
-*/
diff --git a/fsck/fsck.h b/fsck/fsck.h
index fd2099e..fc9da78 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -13,7 +13,6 @@
#include <asm/types.h>
#include <sys/vfs.h>
#include <errno.h>
-#include <unistd.h>
#include <time.h>
#include <asm/types.h>
#include <assert.h>
@@ -37,7 +36,6 @@ int main (int argc, char * argv []);
#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 */
@@ -66,7 +64,6 @@ 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_good_unformatted (unsigned long block);
void mark_good_unformatted (unsigned long block);
int is_bad_unformatted (unsigned long block);
@@ -75,9 +72,7 @@ int are_there_allocable_blocks (int amout_needed);
unsigned long alloc_block (void);
void make_allocable (unsigned long block);
void register_uninsertable (unsigned long block);
-unsigned long how_many_uninsertables_were_there (void);
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 (reiserfs_filsys_t *);
@@ -114,15 +109,15 @@ 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);
+void insert_item_separately (struct item_head * ih, char * item, int was_in_tree);
+void save_item (struct si ** head, struct item_head * ih, char * item, __u32 blocknr);
struct si * save_and_delete_file_item (struct si * si, struct path * path);
void take_bad_blocks_put_into_tree (void);
void rewrite_object (struct item_head * ih, int do_remap);
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);
+//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);
@@ -141,6 +136,8 @@ 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 item_head * sd_ih, void * sd, __u64 * size, __u32 * blocks, int mark_passed_items, int * symlink);
+int delete_N_items_after_key(struct key * start_key, struct si ** save_here, int skip_dir_items, int n_to_delete);
+void rewrite_file (struct item_head * ih, int should_relocate, int should_change_ih);
@@ -200,7 +197,6 @@ int is_bad_directory (struct item_head * ih, char * item, int dev, int blocksize
/* check_tree.c */
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);
@@ -410,6 +406,7 @@ struct check_info {
unsigned long safe;
unsigned long unfm_pointers;
unsigned long zero_unfm_pointers;
+ reiserfs_bitmap_t * deallocate_bitmap;
};
@@ -456,6 +453,7 @@ struct fsck_data {
#define fsck_allocable_bitmap(fs) fsck_data(fs)->rebuild.allocable_bitmap
#define fsck_uninsertables(fs) fsck_data(fs)->rebuild.uninsertables
+#define fsck_deallocate_bitmap(fs) fsck_data(fs)->check.deallocate_bitmap
#define fsck_interactive(fs) (fsck_data(fs)->options & OPT_INTERACTIVE)
//#define fsck_fix_fixable(fs) (fsck_data(fs)->options & OPT_FIX_FIXABLE)
@@ -516,5 +514,5 @@ fflush (fsck_progress_file(fs));\
#define fsck_exit(fmt, list...) \
{\
reiserfs_warning (fsck_progress_file(fs), fmt, ## list);\
-exit (4);\
+exit (16);\
}
diff --git a/fsck/lost+found.c b/fsck/lost+found.c
index 17fdb1a..f92fef3 100644
--- a/fsck/lost+found.c
+++ b/fsck/lost+found.c
@@ -154,7 +154,7 @@ static __u64 _look_for_lost (reiserfs_filsys_t * fs, int link_lost_dirs)
relocate_dir (&tmp_ih, 1);
lost_found_pass_stat (fs)->oid_sharing_dirs_relocated ++;
} else {
- relocate_file (&tmp_ih, 1);
+ rewrite_file (&tmp_ih, 1, 1);
lost_found_pass_stat (fs)->oid_sharing_files_relocated ++;
}
}
@@ -185,7 +185,7 @@ static __u64 _look_for_lost (reiserfs_filsys_t * fs, int link_lost_dirs)
/*fsck_progress ("\tChecking lost dir \"%s\":", lost_name);*/
rebuild_semantic_pass (&obj_key, &lost_found_dir_key, /*dot_dot*/0, /*reloc_ih*/0);
erase_name (strlen (lost_name));
- /*fsck_progress ("ok\n");*/
+ /*fsck_progress ("finished\n");*/
lost_found_pass_stat (fs)->lost_found_dirs ++;
} else {
@@ -235,12 +235,12 @@ static __u64 _look_for_lost (reiserfs_filsys_t * fs, int link_lost_dirs)
marked DEH_Lost_found flag */
fsck_progress ("Checking lost+found directory.."); fflush (stdout);
check_semantic_tree (&lost_found_dir_key, &root_dir_key, 0, 1/* lost+found*/);
- fsck_progress ("ok\n");
+ fsck_progress ("finished\n");
#endif
if (!link_lost_dirs && lost_files)
- fsck_log ("look_for_lost: %d files seem to left not linked to lost+found\n",
- lost_files);
+ fsck_log ("look_for_lost: %d files seem to be left not linked to lost+found\n",
+ lost_files);
return size;
@@ -264,7 +264,7 @@ static void save_lost_found_result (reiserfs_filsys_t * fs)
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",
+ fsck_progress ("pass 0: Could not rename the temporary file temp_fsck_file.deleteme to %s",
state_dump_file (fs));
}
@@ -299,7 +299,7 @@ void after_lost_found (reiserfs_filsys_t * fs)
fs->fs_dirt = 1;
reiserfs_flush_to_ondisk_bitmap (fsck_new_bitmap(fs), fs);
reiserfs_flush (fs);
- fsck_progress ("done\n");
+ fsck_progress ("finished\n");
stage_report (0x3a, fs);
@@ -316,7 +316,7 @@ void after_lost_found (reiserfs_filsys_t * fs)
fs->fs_dirt = 1;
reiserfs_close (fs);
- exit (4);
+ exit(0);
}
void pass_3a_look_for_lost (reiserfs_filsys_t * fs)
@@ -348,11 +348,11 @@ void pass_3a_look_for_lost (reiserfs_filsys_t * fs)
&gen_counter, &lost_found_dir_key);
if (!objectid) {
- reiserfs_panic ("look_for_lost: 'lost+found' direntry not found");
+ reiserfs_panic ("look_for_lost: The entry 'lost+found' could not be found in the root directory.");
}
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",
+ reiserfs_panic ("look_for_lost: The StatData of the 'lost+found' directory %K could not be found",
&lost_found_dir_key);
ih = get_ih (&path);
sd = get_item (&path);
diff --git a/fsck/main.c b/fsck/main.c
index 7850acb..44efea5 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -45,7 +45,7 @@ fsck_progress ("Usage: %s [mode] [options] "\
" \t\t\tdo not open nor replay journal\n"\
" -S | --scan-whole-partition\n"\
" \t\t\tbuild tree of all blocks of the device\n", argv[0]);\
- exit (16);\
+ exit(16);\
}
/*
@@ -98,10 +98,6 @@ static char * parse_options (struct fsck_data * data, int argc, char * argv [])
{"rebuild-tree", no_argument, &mode, FSCK_REBUILD},
{"rollback-fsck-changes", no_argument, &mode, FSCK_ROLLBACK_CHANGES},
{"clean-attributes", no_argument, &mode, FSCK_CLEAN_ATTRIBUTES},
-/*
- {"fast-rebuild", no_argument, &opt_fsck_mode, FSCK_FAST_REBUILD},
-*/
-
/* options */
{"logfile", required_argument, 0, 'l'},
{"interactive", no_argument, 0, 'i'},
@@ -163,7 +159,7 @@ static char * parse_options (struct fsck_data * data, int argc, char * argv [])
/*asprintf (&data->log_file_name, "%s", optarg);*/
data->log = fopen (optarg, "w");
if (!data->log)
- fprintf (stderr, "reiserfsck: could not open \'%s\': %m", optarg);
+ fprintf (stderr, "reiserfsck: Cannot not open \'%s\': %m", optarg);
break;
case 'n': /* --nolog */
@@ -202,7 +198,7 @@ static char * parse_options (struct fsck_data * data, int argc, char * argv [])
case 'h': /* --hash: suppose that this hash was used on a filesystem */
asprintf (&data->rebuild.defined_hash, "%s", optarg);
if (name2func (data->rebuild.defined_hash) == 0)
- reiserfs_panic ("reiserfsck: unknown hash is defined: %s",
+ reiserfs_panic ("reiserfsck: Unknown hash is defined: %s",
data->rebuild.defined_hash);
data->options |= OPT_HASH_DEFINED;
break;
@@ -254,7 +250,6 @@ static char * parse_options (struct fsck_data * data, int argc, char * argv [])
/* only one non-option argument is permitted */
print_usage_and_exit();
-
if (mode != FSCK_REBUILD &&
(data->rebuild.scan_area == EXTERN_BITMAP ||
data->rebuild.scan_area == ALL_BLOCKS ||
@@ -284,34 +279,55 @@ static char * parse_options (struct fsck_data * data, int argc, char * argv [])
data->mode = mode;
if (!data->log)
- data->log = stdout;
+ data->log = stdout;
+
+ if (data->journal_dev_name == NULL)
+ data->journal_dev_name = argv[optind];
return argv[optind];
}
#define REBUILD_WARNING \
-" **********************************************************\n\
- ** This is an experimental version of reiserfsck, **\n\
- ** !! MAKE A BACKUP FIRST !! **\n\
- ** Don't run this program unless something is broken. **\n\
- ** Some types of random FS damage can be recovered from **\n\
- ** by this program, which basically throws away **\n\
- ** the internal nodes of the tree and then reconstructs **\n\
- ** them. This program is for use only by the desperate, **\n\
- ** and is of only beta quality. If you are using the **\n\
- ** latest reiserfsprogs and it fails please email **\n\
- ** bug reports to reiserfs-list@namesys.com. **\n\
- **********************************************************\n\
+" *************************************************************\n\
+ ** Do not run rebuild-tree unless something is broken and **\n\
+ ** MAKE A BACKUP before using it. If you have bad sectors **\n\
+ ** on a drive it is usually a bad idea to continue using **\n\
+ ** it. Then you probably should get a working hard drive, **\n\
+ ** copy the file system from the bad drive to the good one **\n\
+ ** -- dd_rescue is a good tool for that -- and only then **\n\
+ ** run this program. **\n\
+ ** If you are using the latest reiserfsprogs and it fails **\n\
+ ** please email bug reports to reiserfs-list@namesys.com, **\n\
+ ** providing as much information as possible -- your **\n\
+ ** hardware, kernel, patches, settings, all reiserfsck **\n\
+ ** messages (including version), the reiserfsck logfile, **\n\
+ ** check the syslog file for any related information. **\n\
+ ** If you would like advice on using this program, support **\n\
+ ** is available for $25 at www.namesys.com/support.html. **\n\
+ *************************************************************\n\
\nWill rebuild the filesystem (%s) tree\n"
+#define START_WARNING \
+" *************************************************************\n\
+ ** If you are using the latest reiserfsprogs and it fails **\n\
+ ** please email bug reports to reiserfs-list@namesys.com, **\n\
+ ** providing as much information as possible -- your **\n\
+ ** hardware, kernel, patches, settings, all reiserfsk **\n\
+ ** messages (including version), the reiserfsck logfile, **\n\
+ ** check the syslog file for any related information. **\n\
+ ** If you would like advice on using this program, support **\n\
+ ** is available for $25 at www.namesys.com/support.html. **\n\
+ *************************************************************\n\
+\n"
+
#define AUTO_WARNING \
" **********************************************************\n\
** WARNING: You seem to be running this automatically. **\n\
** You are almost certainly doing it by mistake as **\n\
** a result of some script that doesn't know what it **\n\
- ** does. Doing nothing, rerun without -a and -p if you **\n\
- ** really intend to do this. **\n\
+ ** does. Nothing will be done. If you really intend to **\n\
+ ** run reiserfsck, rerun it without -a and -p options. **\n\
**********************************************************\n\n"
void warn_what_will_be_done (char * file_name, struct fsck_data * data)
@@ -320,34 +336,35 @@ void warn_what_will_be_done (char * file_name, struct fsck_data * data)
warn_to = (data->progress ?: stderr);
-// reiserfs_warning (warn_to, START_WARNING);
-
+ if (data->mode == FSCK_REBUILD)
+ reiserfs_warning (warn_to, REBUILD_WARNING, file_name);
+ else
+ reiserfs_warning (warn_to, START_WARNING);
+
/* warn about fsck mode */
switch (data->mode) {
case FSCK_CHECK:
reiserfs_warning (warn_to,
- "Will read-only check consistency of the filesystem on %s\n",
- file_name);
+ "Will read-only check consistency of the filesystem on %s\n", file_name);
break;
case FSCK_FIX_FIXABLE:
reiserfs_warning (warn_to,
- "Will check consistency of the filesystem on %s\n", file_name);
- reiserfs_warning (fsck_progress_file(fs),
- "Will fix what can be fixed w/o --rebuild-tree\n");
+ "Will check consistency of the filesystem on %s\n", file_name);
+ reiserfs_warning (warn_to,
+ "and will fix what can be fixed w/o --rebuild-tree\n");
break;
case FSCK_SB:
reiserfs_warning (warn_to,
- "Will check superblock and rebuild it if needed\n");
+ "Will check superblock and rebuild it if needed\n");
break;
case FSCK_REBUILD:
- reiserfs_warning (warn_to, REBUILD_WARNING, file_name);
if (data->options & OPT_SAVE_PASSES_DUMP) {
reiserfs_warning (warn_to,
- "Will run only 1 step of rebuilding, write state file '%s' and exit\n",
+ "Will run only 1 step of the rebuilding, write state file '%s' and exit\n",
data->rebuild.passes_dump_file_name);
} else if (data->options & OPT_INTERACTIVE)
reiserfs_warning (warn_to,
@@ -356,15 +373,12 @@ void warn_what_will_be_done (char * file_name, struct fsck_data * data)
if (data->rebuild.bitmap_file_name)
reiserfs_warning (warn_to,
- "Will try to load bitmap of leaves from file '%s'\n",
- data->rebuild.bitmap_file_name);
+ "Will try to load a bitmap--of all ReiserFS leaves in the partition--from the file \n'%s'\n",
+ data->rebuild.bitmap_file_name);
if (data->options & OPT_ADJUST_FILE_SIZE)
reiserfs_warning (warn_to,
- "\tWill fix following non-critical things:\n"
- "\t\tunknown file modes will be set to regular files\n"
- "\t\tfile sizes will be set to real file size\n"
- "\t\tfiles sharing busy inode number will be relocated\n");
+ "\tWill set file sizes in their metadata to real file sizes actually found by fsck.\n");
if (data->options & OPT_HASH_DEFINED)
reiserfs_warning (warn_to,
@@ -401,10 +415,76 @@ void warn_what_will_be_done (char * file_name, struct fsck_data * data)
(data->log == stdout) ? "stdout" : (data->log_file_name ?: "fsck.run"));
if (!user_confirmed (warn_to,
- "\nDo you want to run this program?[N/Yes] (note need to type Yes):", "Yes\n"))
+ "\nDo you want to run this program?[N/Yes] (note need to type Yes if you do):", "Yes\n"))
exit (0);
}
+static dma_info_t dma_info;
+static dma_info_t old_dma_info;
+
+void check_dma() {
+ old_dma_info = dma_info;
+ if (get_dma_info(&dma_info) == -1) {
+ fsck_log("get_dma_info failed %s\n", strerror (errno));
+ return;
+ }
+
+ if (dma_info.dma != old_dma_info.dma) {
+ if (dma_info.dma == 0) {
+ printf("\n********************************************************************\n");
+ printf("* Warning: It was just detected that dma mode was turned off while *\n");
+ printf("* operating -- probably due to some problem with your hardware. *\n");
+ printf("* Please check your hardware and have a look into the syslog file. *\n");
+ printf("* Note: run of rebuild-tree on faulty hardware may destroy your *\n");
+ printf("* data. *\n");
+ printf("********************************************************************\n");
+ if (fsck_log_file (fs) != stdout)
+ fsck_log("WARNING: dma mode has been turned off.\n");
+ }
+ }
+ if (dma_info.speed != old_dma_info.speed) {
+ if (dma_info.speed < old_dma_info.speed) {
+ printf("\n********************************************************************\n");
+ printf("* Warning:It was just detected that dma speed was descreased while *\n");
+ printf("* operating -- probably due to some problem with your hardware. *\n");
+ printf("* Please check your hardware and have a look into the syslog file. *\n");
+ printf("* Note: run of rebuild-tree on faulty hardware may destroy your *\n");
+ printf("* data. *\n");
+ printf("********************************************************************\n");
+ if (fsck_log_file (fs) != stdout)
+ fsck_log("WARNING: dma speed has been descreased.\n");
+ }
+ }
+
+ alarm(1);
+}
+
+void register_timer() {
+ memset(&dma_info, 0, sizeof(dma_info));
+ memset(&old_dma_info, 0, sizeof(old_dma_info));
+
+ dma_info.fd = fs->fs_dev;
+
+ if (prepare_dma_check(&dma_info) != 0)
+ return;
+
+ if (get_dma_info(&dma_info) == -1) {
+ fsck_log("get_dma_info failed %s\n", strerror (errno));
+ return;
+ }
+
+ if (dma_info.dma == 0) {
+ printf("\n******************************************************\n");
+ printf("* Warning: The dma on your hard drive is turned off. *\n");
+ printf("* This may really slow down the fsck process. *\n");
+ printf("******************************************************\n");
+ if (fsck_log_file (fs) != stdout)
+ fsck_log("WARNING: DMA is turned off\n");
+ }
+
+ signal(SIGALRM, check_dma);
+ alarm(1);
+}
static void reset_super_block (reiserfs_filsys_t * fs)
{
@@ -416,7 +496,7 @@ static void reset_super_block (reiserfs_filsys_t * fs)
set_sb_root_block (sb, ~0);
set_sb_tree_height (sb, ~0);
- /* make file system invalid unless fsck done () */
+ /* make file system invalid unless fsck finished () */
set_sb_fs_state (sb, get_sb_fs_state (sb) || REISERFS_CORRUPTED);
/*
@@ -452,6 +532,8 @@ static void reset_super_block (reiserfs_filsys_t * fs)
set_jp_journal_dev (sb_jp(sb), 0);
set_jp_journal_magic (sb_jp(sb) ,0);
set_sb_reserved_for_journal (sb, 0);
+ set_jp_journal_1st_block (sb_jp(sb), get_journal_start_must (fs));
+ set_jp_journal_size (sb_jp(sb), journal_default_size (fs->fs_super_bh->b_blocknr, 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)),
@@ -489,8 +571,8 @@ static int where_to_start_from (reiserfs_filsys_t * fs)
/**/
return START_FROM_THE_BEGINNING;
- /* ok, we asked to restart - we can only do that if there is file saved
- during previous runs */
+ /* We are able to perform the next step only if there is a file with the previous
+ * step results. */
fp = open_file (state_dump_file (fs), "r");
if (fp == 0) {
set_sb_fs_state (fs->fs_ondisk_sb, 0);
@@ -507,7 +589,7 @@ static int where_to_start_from (reiserfs_filsys_t * fs)
switch (last_run_state) {
case PASS_0_DONE:
/* skip pass 0 */
- if (!fsck_user_confirmed (fs, "Pass 0 seems done. Start from pass 1?(Yes)",
+ if (!fsck_user_confirmed (fs, "Pass 0 seems finished. Start from pass 1?(Yes)",
"Yes\n", 1))
fsck_exit ("Run without -d then\n");
@@ -517,7 +599,7 @@ static int where_to_start_from (reiserfs_filsys_t * fs)
case PASS_1_DONE:
/* skip pass 1 */
- if (!fsck_user_confirmed (fs, "Passes 0 and 1 seems done. Start from pass 2?(Yes)",
+ if (!fsck_user_confirmed (fs, "Passes 0 and 1 seems finished. Start from pass 2?(Yes)",
"Yes\n", 1))
fsck_exit ("Run without -d then\n");
@@ -526,7 +608,7 @@ static int where_to_start_from (reiserfs_filsys_t * fs)
return START_FROM_PASS_2;
case TREE_IS_BUILT:
- if (!fsck_user_confirmed (fs, "S+ tree of filesystem looks built. Skip rebuilding?(Yes)",
+ if (!fsck_user_confirmed (fs, "Internal tree of filesystem looks built. Skip rebuilding?(Yes)",
"Yes\n", 1))
fsck_exit ("Run without -d then\n");
@@ -534,14 +616,14 @@ static int where_to_start_from (reiserfs_filsys_t * fs)
fclose (fp);
return START_FROM_SEMANTIC;
case SEMANTIC_DONE:
- if (!fsck_user_confirmed (fs, "Passes 0 and 1 seems done. Start from pass 2?(Yes)",
+ if (!fsck_user_confirmed (fs, "Passes 0 and 1 seems finished. Start from pass 2?(Yes)",
"Yes\n", 1))
fsck_exit ("Run without -d then\n");
load_semantic_result (fp, fs);
fclose (fp);
return START_FROM_LOST_FOUND;
case LOST_FOUND_DONE:
- if (!fsck_user_confirmed (fs, "Passes 0 and 1 seems done. Start from pass 2?(Yes)",
+ if (!fsck_user_confirmed (fs, "Passes 0 and 1 seems finished. Start from pass 2?(Yes)",
"Yes\n", 1))
fsck_exit ("Run without -d then\n");
load_lost_found_result (fs);
@@ -559,12 +641,13 @@ static void mark_filesystem_consistent (reiserfs_filsys_t * fs)
return;
if (!reiserfs_journal_opened (fs)) {
- /* make sure journal is not standard */
+ /* make sure journal is not standard */
if (!is_reiserfs_jr_magic_string (fs->fs_ondisk_sb))
- die ("File system with standard journal that has to be open");
- /* mark filesystem such that it is not mountable until new journal
- device is defined */
- fsck_progress ("WARNING: You must use reiserfstune to specify new journal\n");
+ die ("Filesystem with standard journal must be opened.");
+
+ fsck_progress ("WARNING: You must use reiserfstune to specify a new journal before mounting it.\n");
+ /* mark filesystem such that it is not mountable until
+ * new journaldevice is defined */
set_jp_journal_magic (sb_jp (fs->fs_ondisk_sb), NEED_TUNE);
}
@@ -577,11 +660,12 @@ static void mark_filesystem_consistent (reiserfs_filsys_t * fs)
static void reiserfsck_replay_journal () {
/* keep the super_block in the separate memory to avoid problems with replayed broken parameters */
fs->fs_ondisk_sb = getmem (fs->fs_blocksize);
- memcpy (fs->fs_ondisk_sb, fs->fs_super_bh->b_data, sizeof (fs->fs_blocksize));
+ memcpy (fs->fs_ondisk_sb, fs->fs_super_bh->b_data, fs->fs_blocksize);
replay_journal (fs);
/* get rid of SB copy */
+ memcpy (fs->fs_super_bh->b_data, fs->fs_ondisk_sb, fs->fs_blocksize);
freemem (fs->fs_ondisk_sb);
fs->fs_ondisk_sb = (struct reiserfs_super_block *)fs->fs_super_bh->b_data;
@@ -611,9 +695,9 @@ static void the_end (reiserfs_filsys_t * fs)
/* write all dirty blocks */
fsck_progress ("Syncing..");
fs->fs_dirt = 1;
+ clean_after_dma_check(fs->fs_dev, &dma_info);
reiserfs_close (fs);
-// sync ();
- fsck_progress ("done\n");
+ fsck_progress ("finished\n");
}
@@ -623,8 +707,8 @@ static void rebuild_tree (reiserfs_filsys_t * fs)
if (is_mounted (fs->fs_file_name)) {
- fsck_progress ("rebuild_tree: can not rebuild tree of mounted filesystem\n");
- return;
+ fsck_progress ("rebuild_tree: Cannot rebuild tree of mounted filesystem\n");
+ exit(16);
}
init_rollback_file (state_rollback_file(fs), &fs->fs_blocksize, fsck_data(fs)->log);
@@ -633,9 +717,9 @@ static void rebuild_tree (reiserfs_filsys_t * fs)
/* FIXME: for regular file take care of of file size */
if (!reiserfs_open_ondisk_bitmap (fs)) {
- fsck_progress ("reiserfsck: could not open bitmap\n");
+ fsck_progress ("reiserfsck: Could not open bitmap\n");
reiserfs_close (fs);
- exit(0);
+ exit(8);
}
/* rebuild starts with journal replaying */
@@ -690,23 +774,23 @@ static void prepare_fs_for_pass_through_tree (reiserfs_filsys_t * fs)
if (is_mounted (fs->fs_file_name)) {
/* filesystem seems mounted. */
if (fsck_mode (fs) == FSCK_CLEAN_ATTRIBUTES) {
- fsck_progress ("Device %s is mounted, cannot clean attributes on mounted device\n",
+ fsck_progress ("Partition %s is mounted, cannot clean attributes on mounted device\n",
fs->fs_file_name);
reiserfs_close (fs);
- exit (0);
+ exit(16);
}
if (!is_mounted_read_only (fs->fs_file_name)) {
- fsck_progress ("Device %s is mounted w/ write permissions, can not check it\n",
+ fsck_progress ("Partition %s is mounted w/ write permissions, cannot check it\n",
fs->fs_file_name);
reiserfs_close (fs);
- exit (0);
+ exit(16);
}
if (!reiserfs_journal_opened (fs))
/* just to make sure */
reiserfs_panic ("Journal is not opened");
- fsck_progress ("Filesystem seems mounted read-only. Skipping journal replay..\n");
+ fsck_progress ("Filesystem seems mounted read-only. Skipping journal replay.\n");
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
fsck_progress ("--fix-fixable ignored\n");
@@ -726,19 +810,19 @@ static void clean_attributes (reiserfs_filsys_t * fs) {
time (&t);
if (get_sb_umount_state (fs->fs_ondisk_sb) != REISERFS_CLEANLY_UMOUNTED) {
- fsck_progress ("Filesystem does not look like cleanly umounted\n"
- "Check consistency of the partition first.\n");
- exit(0);
+ fsck_progress ("Filesystem does not look cleanly umounted\n"
+ "Check consistency of the partition first.\n");
+ exit(16);
}
if (get_sb_fs_state (fs->fs_ondisk_sb) != REISERFS_CONSISTENT) {
fsck_progress ("Filesystem seems to be in unconsistent state.\n"
"Check consistency of the partition first.\n");
- exit(0);
+ exit(16);
}
if (get_reiserfs_format (fs->fs_ondisk_sb) != REISERFS_FORMAT_3_6) {
fsck_progress ("Filesystems of 3_5 format do not support extended attributes.\n");
- exit(0);
+ exit(16);
}
fsck_progress ("###########\n"
"reiserfsck --clean-attributes started at %s"
@@ -750,6 +834,7 @@ static void clean_attributes (reiserfs_filsys_t * fs) {
do_clean_attributes (fs);
+ clean_after_dma_check(fs->fs_dev, &dma_info);
reiserfs_close (fs);
close_rollback_file ();
@@ -782,9 +867,9 @@ static void check_fs (reiserfs_filsys_t * fs)
init_rollback_file (state_rollback_file(fs), &fs->fs_blocksize, fsck_data(fs)->log);
if (!reiserfs_open_ondisk_bitmap (fs)) {
- fsck_progress ("reiserfsck: could not open bitmap\n");
+ fsck_progress ("reiserfsck: Could not open bitmap\n");
reiserfs_close (fs);
- exit(0);
+ exit(8);
}
prepare_fs_for_pass_through_tree (fs);
@@ -794,7 +879,7 @@ static void check_fs (reiserfs_filsys_t * fs)
semantic_check ();
if (fsck_data (fs)->check.fatal_corruptions) {
- fsck_progress ("There were found %d corruptions which can be fixed only during --rebuild-tree\n",
+ fsck_progress ("%d found corruptions can be fixed only during --rebuild-tree\n",
fsck_data (fs)->check.fatal_corruptions);
set_sb_fs_state (fs->fs_ondisk_sb, REISERFS_CORRUPTED);
mark_buffer_dirty (fs->fs_super_bh);
@@ -803,11 +888,11 @@ static void check_fs (reiserfs_filsys_t * fs)
/* fixable corruptions found */
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
/* fixable corruptions found and fix-fixable has not fixed them, do rebuild-tree */
- fsck_log ("Fatal error occured: %d fixable corruptions found after fix-fixable.\n",
+ fsck_log ("Fatal error: %d fixable corruptions found after fix-fixable.\n",
fsck_data (fs)->check.fixable_corruptions);
retval = 2;
} else {
- fsck_progress ("There were found %d corruptions which can be fixed with --fix-fixable\n",
+ fsck_progress ("%d found corruptions can be fixed with --fix-fixable\n",
fsck_data (fs)->check.fixable_corruptions);
retval = 1;
}
@@ -828,16 +913,16 @@ static void check_fs (reiserfs_filsys_t * fs)
}
free_id_map (proper_id_map (fs));
+ clean_after_dma_check(fs->fs_dev, &dma_info);
reiserfs_close (fs);
close_rollback_file ();
-// sync();
time (&t);
fsck_progress ("###########\n"
"reiserfsck finished at %s"
"###########\n", ctime (&t));
- exit (retval);
+ exit(retval);
}
static int open_devices_for_rollback (char * file_name, struct fsck_data * data) {
@@ -846,7 +931,7 @@ static int open_devices_for_rollback (char * file_name, struct fsck_data * data)
fd = open (file_name, O_RDWR | O_LARGEFILE);
if (fd == -1) {
- reiserfs_warning (stderr, "reiserfsck: could not open device %s\"", file_name);
+ reiserfs_warning (stderr, "reiserfsck: Cannot not open the fs partition %s\"", file_name);
return -1;
}
@@ -858,7 +943,7 @@ static int open_devices_for_rollback (char * file_name, struct fsck_data * data)
if (data->journal_dev_name && strcmp (data->journal_dev_name, file_name)) {
fs->fs_journal_dev = open (data->journal_dev_name, O_RDWR | O_LARGEFILE);
if (fs->fs_journal_dev == -1) {
- reiserfs_warning (stderr, "cannot open journal device\n");
+ reiserfs_warning (stderr, "Cannot open journal partition\n");
return -1;
}
}
@@ -891,52 +976,9 @@ static void fsck_rollback (reiserfs_filsys_t * fs) {
"reiserfsck finished at %s"
"###########\n", ctime (&t));
- exit (0);
-}
-
-static void fast_rebuild (reiserfs_filsys_t * fs)
-{
-#ifdef FAST_REBUILD_READY /* and tested */
- if (opt_fsck_mode == FSCK_FAST_REBUILD) {
- __u32 root_block = SB_ROOT_BLOCK(fs);
- reopen_read_write (file_name);
- printf ("Replaying log..");
- if (fsck_skip_journal (fs))
- reiserfsck_replay_journal ();
- printf ("done\n");
- if (opt_fsck == 1)
- printf ("ReiserFS : checking %s\n",file_name);
- else
- printf ("Rebuilding..\n");
-
-
- reset_super_block (fs);
- SB_DISK_SUPER_BLOCK(fs)->s_root_block = cpu_to_le32 (root_block);
- init_bitmaps (fs);
-
- /* 1,2. building of the tree */
- recover_internal_tree(fs);
-
- /* 3. semantic pass */
- pass3_semantic ();
-
- /* if --lost+found is set - link unaccessed directories to
- lost+found directory */
- look_for_lost (fs);
-
- /* 4. look for unaccessed items in the leaves */
- pass4_check_unaccessed_items ();
-
- end_fsck ();
- }
-#endif /* FAST REBUILD READY */
-
- reiserfs_panic ("Fast rebuild is not ready");
-
+ exit(0);
}
-
-
int main (int argc, char * argv [])
{
char * file_name;
@@ -956,19 +998,11 @@ int main (int argc, char * argv [])
screen_savebuffer=getmem(screen_width+1);
memset(screen_savebuffer,0,screen_savebuffer_len+1);
- /* initially assigned in semantic.c, but non-constant initializers are
- * illegal - jdm */
-/*
- root_dir_key.k2_dir_id = cpu_to_le32(root_dir_key.k2_dir_id);
- root_dir_key.k2_objectid = cpu_to_le32(root_dir_key.k2_objectid);
- parent_root_dir_key.k2_dir_id = cpu_to_le32(parent_root_dir_key.k2_dir_id);
- parent_root_dir_key.k2_objectid = cpu_to_le32(parent_root_dir_key.k2_objectid);
-*/
lost_found_dir_key.k2_dir_id = cpu_to_le32(lost_found_dir_key.k2_dir_id);
lost_found_dir_key.k2_objectid = cpu_to_le32(lost_found_dir_key.k2_objectid);
- /* this is only needed (and works) when running under 2.4 on regural files */
+ /* this is only needed (and works) when running under 2.4 on regular files */
if (setrlimit (RLIMIT_FSIZE, &rlim) == -1) {
- reiserfs_warning (stderr, "could not setrlimit: %m\n");
+ reiserfs_warning (stderr, "Cannot change the system limit for file size with setrlimit: %m\n");
}
data = getmem (sizeof (struct fsck_data));
@@ -989,7 +1023,7 @@ int main (int argc, char * argv [])
data->options |= OPT_QUIET;
data->progress = fopen ("fsck.run", "a+");
if (!data->progress)
- reiserfs_panic ("reiserfsck: could not open \"fsck.run\"");
+ reiserfs_panic ("reiserfsck: Cannot not open \"fsck.run\"");
if (data->log == stdout)
/* no log file specifed - redirect log into 'fsck.run' */
@@ -997,13 +1031,13 @@ int main (int argc, char * argv [])
retval = fork ();
if (retval == -1)
- reiserfs_panic ("reiserfsck: fork failed: %m");
+ reiserfs_panic ("reiserfsck: Fork failed: %m");
if (retval != 0) {
- return 0;
+ return 8;
}
- reiserfs_warning (stderr, "\nreiserfsck is running in background as [%d],\n"
- "make sure that it get enough confirmation from stdin\n\n",
- getpid ());
+ reiserfs_warning (stderr, "\nReiserfsck is running in background as [%d],\n"
+ "make sure that it gets all the confirmations from stdin that it requests.\n\n",
+ getpid ());
}
@@ -1012,34 +1046,34 @@ int main (int argc, char * argv [])
if (data->mode == FSCK_ROLLBACK_CHANGES) {
if (open_devices_for_rollback (file_name, data) == -1)
- exit (1);
+ exit(8);
} else {
fs = reiserfs_open (file_name, O_RDONLY, 0, data);
if (data->mode != FSCK_SB) {
if (no_reiserfs_found (fs))
- die ("reiserfsck: could not open filesystem on \"%s\"", file_name);
+ die ("reiserfsck: Cannot not open filesystem on \"%s\"", file_name);
if (data->mode == AUTO) {
print_super_block (stdout, fs, fs->fs_file_name, fs->fs_super_bh, 1);
reiserfs_close(fs);
- exit (0);
+ exit(0);
}
if (fsck_skip_journal (fs) && !is_reiserfs_jr_magic_string (fs->fs_ondisk_sb)) {
reiserfs_warning (stderr, "Filesystem with standard journal found, "
- "--no-journal-availabel is ignored\n");
+ "--no-journal-available is ignored\n");
fsck_data(fs)->options &= ~OPT_SKIP_JOURNAL;
}
if (!fsck_skip_journal (fs)) {
if (!reiserfs_open_journal (fs, data->journal_dev_name, O_RDONLY)) {
- fsck_progress ("reiserfsck: either make journal device available or use --no-journal-available\n");
- fsck_progress (" if you have the standard journal or if your device is available\n");
- fsck_progress (" and you specified it correctly, you have to run rebuild-sb\n");
+ fsck_progress ("\nEither make journal partition available or use --no-journal-available\n");
+ fsck_progress ("If you have the standard journal or if your partition is available\n");
+ fsck_progress ("and you specified it correctly, you must run rebuild-sb\n");
reiserfs_close (fs);
- return 0;
+ return 8;
}
}
@@ -1049,6 +1083,7 @@ int main (int argc, char * argv [])
data->options &= ~BADBLOCKS_FILE;
}
}
+ register_timer();
}
}
@@ -1067,15 +1102,13 @@ int main (int argc, char * argv [])
rebuild_tree (fs);
break;
- case FSCK_FAST_REBUILD:
- fast_rebuild (fs);
- break;
case FSCK_ROLLBACK_CHANGES:
fsck_rollback (fs);
break;
case FSCK_CLEAN_ATTRIBUTES:
clean_attributes (fs);
}
- return 16;
+
+ return 8;
}
diff --git a/fsck/pass0.c b/fsck/pass0.c
index fcf27c2..d52b137 100644
--- a/fsck/pass0.c
+++ b/fsck/pass0.c
@@ -6,10 +6,12 @@
-/* pass 0 scans the partition (used part). It creates two maps which will be
- used on the pass 1. These are a map of nodes looking like leaves and a map
- of "bad" unformatted nodes. After pass 0 we can detect unformatted node
- pointers pointing to leaves.*/
+/*
+ * Pass0 scans the used part of the partition. It creates two maps which will
+ * be used on the pass 1. These are a map of nodes looking like leaves and
+ * a map of "bad" unformatted nodes. After pass 0 we can detect unformatted
+ * node pointers pointing to leaves.
+ */
/* leaves */
@@ -134,7 +136,7 @@ static int correct_key_format (struct item_head * ih)
return 0;
}
- die ("stat data of wrong length");
+ die ("stat_data item of the wrong length");
}
if (key_format (&ih->ih_key) != get_ih_key_format (ih)) {
@@ -148,7 +150,7 @@ static int correct_key_format (struct item_head * ih)
/*fsck_log ("correct_key_format: %H made of indirect type\n", ih);*/
set_type (key_format (&ih->ih_key), &ih->ih_key, TYPE_INDIRECT);
if (get_offset (&ih->ih_key) % fs->fs_blocksize != 1)
- fsck_log ("correct_key_format: %H wrong offset of in indirect item\n", ih);
+ fsck_log ("correct_key_format: Item header's key has the wrong offset %H\n", ih);
dirty = 1;
}
@@ -269,7 +271,7 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
#ifdef DEBUG_VERIFY_DENTRY
direntries = getmem (ih_entry_count (ih) * sizeof (int));
- printf ("entries with bad locations: ");
+ printf ("Entries with bad locations within the directory: ");
for (i = 0; i < ih_entry_count (ih); i ++) {
if (de_bad_location (deh + i))
printf ("%d ", i);
@@ -290,17 +292,17 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
}
name = name_in_entry (deh + i, i);
- /* we found a name, but we not always we can get its length as
- it depends on deh_location of previous entry */
+ /* Although we found a name, we not always can get its length as
+ it depends on deh_location of previous entry. */
name_len = try_to_get_name_length (ih, deh + i, i);
#ifdef DEBUG_VERIFY_DENTRY
if (name_len == 0)
- printf ("trying to find name length for %d-th entry\n", i);
+ printf ("Trying to find the name length for %d-th entry\n", i);
#endif /* DEBUG_VERIFY_DENTRY */
if (is_dot (name, name_len)) {
if (i != 0)
- fsck_log ("block %lu: item %d: \".\" is %d-th entry\n",
+ fsck_log ("block %lu: item %d: \".\" must be the first entry, but it is the %d-th entry\n",
bh->b_blocknr, item_num, i);
/* check and fix "." */
@@ -358,20 +360,14 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
return 1;
}
-
-
if (!name_len) {
- fsck_log ("pass0: block %lu, item %H: entry %d. found a name \"%.*s\" "
- "matching to deh_offset %u. FIXME: should set deh_location "
- "of previous entry (not ready)\n",
- bh->b_blocknr, ih, i, j, name, get_deh_offset (deh + i));
+ fsck_log ("%s: block %lu, item %H: Found a name \"%.*s\" for %d-th entry "
+ "matching to the hash %u.\n", __FUNCTION__,
+ bh->b_blocknr, ih, j, name, i, get_deh_offset (deh + i));
/* FIXME: if next byte is 0 we think that the name is aligned to 8 byte boundary */
if (i) {
- set_deh_offset (&deh[i - 1], get_deh_location (deh + i) +
+ set_deh_location (&deh[i - 1], get_deh_location (deh + i) +
((name[j] || fs->fs_format == REISERFS_FORMAT_3_5) ? j : ROUND_UP (j)));
- /*
- deh[i - 1].deh_location = cpu_to_le16 (deh_location (deh + i) +
- ((name[j] || fs->s_version == REISERFS_VERSION_1) ? j : ROUND_UP (j)));*/
mark_de_good_location (deh + i - 1);
mark_buffer_dirty (bh);
}
@@ -392,7 +388,7 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
} /* for */
#ifdef DEBUG_VERIFY_DENTRY
- printf ("entries with mismatching deh_offsets: ");
+ printf ("Entries with mismatching hash: ");
for (i = 0; i < ih_entry_count (ih); i ++) {
if (de_bad_offset (deh + i))
printf ("%d ", i);
@@ -430,8 +426,8 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
if (!de_bad (deh + i) &&
get_deh_location (deh + i) != (DEH_SIZE * get_ih_entry_count (ih))) {
/* free space in the directory item */
- fsck_log ("verify_direntry: block %lu, item %H has free space\n",
- bh->b_blocknr, ih);
+ fsck_log ("%s: block %lu, item %H: Directory item has a free space - deleting\n",
+ __FUNCTION__, bh->b_blocknr, ih);
cut_entry (fs, bh, item_num, get_ih_entry_count (ih), 0);
}
if (get_deh_location (deh + i) != (DEH_SIZE * get_ih_entry_count (ih))) {
@@ -448,7 +444,7 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
} /* for */
#ifdef DEBUG_VERIFY_DENTRY
- printf ("entries with fixed deh_locations: ");
+ printf ("Entries with fixed deh_locations: ");
for (i = 0; i < ih_entry_count (ih); i ++) {
if (direntries [i])
printf ("%d ", i);
@@ -478,7 +474,6 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
bad = 0;
tmp = *ih;
-#if 1
/* mark enries of /lost+found as bad */
deh = B_I_DEH (bh, ih);
for (i = 0; i < get_ih_entry_count (ih); i ++, deh ++) {
@@ -495,10 +490,9 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
continue;
/* entry in lost+found */
- printf ("%s - will be deleted\n", buf);
+// printf ("%s - will be deleted\n", buf);
mark_de_bad_offset (deh);
}
-#endif
/* delete entries which are marked bad */
for (i = 0; i < get_ih_entry_count (ih); i ++) {
@@ -516,20 +510,21 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
}
if (bad == get_ih_entry_count (&tmp)) {
- fsck_log ("pass0: block %lu, item %H - all entries were deleted\n", bh->b_blocknr, &tmp);
+ fsck_log ("%s: block %lu, item %H: All entries were deleted from the directory\n",
+ __FUNCTION__, bh->b_blocknr, &tmp);
return -1;
}
deh = B_I_DEH (bh, ih);
if (get_offset (&ih->ih_key) != get_deh_offset (deh)) {
- fsck_log ("verify_direntry: block %lu, item %H: k_offset and deh_offset %u mismatched\n",
- bh->b_blocknr, ih, get_deh_offset (deh));
+ fsck_log ("verify_direntry: block %lu, item %H: Key's offset %k must match the directory's hash (%u) - changed.\n",
+ bh->b_blocknr, ih, &ih->ih_key, get_deh_offset (deh));
set_offset (key_format (&ih->ih_key), &ih->ih_key, get_deh_offset (deh));
mark_buffer_dirty (bh);
}
if (bad)
- fsck_log ("pass0: block %lu, item %H: %d entries were deleted of \n",
+ fsck_log ("pass0: block %lu, item %H: %d entries were deleted\n",
bh->b_blocknr, &tmp, bad);
return 0;
@@ -538,13 +533,13 @@ static int verify_directory_item (reiserfs_filsys_t * fs, struct buffer_head * b
static int does_it_fit_into_dev (__u64 offset) {
- return ( UNFM_P_SIZE * offset / MAX_ITEM_LEN(fs->fs_blocksize) < fs->fs_blocksize * get_sb_block_count (fs->fs_ondisk_sb)) ?
- 1 : 0;
-/*
- offset / blocksize - unfp count
- UNFM_P_SIZE * offset / blocksize / MAX_ITEM_LEN - count of blocks to store it
- blocksize * UNFM_P_SIZE * offset / blocksize / MAX_ITEM_LEN - size to store it
+/*
+ Count of unformatted pointers - offset / blocksize
+ Count of blocks to store them - UNFM_P_SIZE * offset / blocksize / MAX_ITEM_LEN
+ Size to store it - blocksize * UNFM_P_SIZE * offset / blocksize / MAX_ITEM_LEN
*/
+ return ( UNFM_P_SIZE * offset / MAX_ITEM_LEN(fs->fs_blocksize) <
+ fs->fs_blocksize * get_sb_block_count (fs->fs_ondisk_sb)) ? 1 : 0;
}
@@ -578,7 +573,7 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
int bad_order;
- /* delete all safe links and */
+ /* Delete all safe links. */
for (i = get_blkh_nr_items (B_BLK_HEAD (bh)) - 1; i >= 0; i--) {
if (get_key_dirid (&B_N_PITEM_HEAD (bh, i)->ih_key) == -1) {
delete_item (fs, bh, i);
@@ -591,15 +586,19 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
bad_order = 0;
for (i = 0; i < (nr_items = get_blkh_nr_items (B_BLK_HEAD (bh))); i ++, ih ++) {
+ if (is_indirect_ih(ih) && (get_ih_item_len (ih) % 4 != 0)) {
+ set_type(get_ih_key_format(ih), &ih->ih_key, TYPE_UNKNOWN);
+ dirty = 1;
+ }
+
if (type_unknown (&ih->ih_key)) {
if ((get_ih_item_len (ih) == SD_SIZE) || (get_ih_item_len (ih) == SD_V1_SIZE)) {
set_type_and_offset (KEY_FORMAT_1, &ih->ih_key, SD_OFFSET, TYPE_STAT_DATA);
dirty = 1;
- fsck_log("pass0: vpf-10100: block %lu, item (%d), unknown type of item of SD size," \
- " type set to TYPE_STAT_DATA (%k)\n",
- bh->b_blocknr, i, &ih->ih_key);
+ fsck_log("pass0: vpf-10100: block %lu, item (%d): Unknown item type of StatData size,"
+ " type set to StatData %k\n", bh->b_blocknr, i, &ih->ih_key);
} else {
- fsck_log("pass0: vpf-10110: block %lu, item (%d), unknown item type found (%k) - delete\n",
+ fsck_log("pass0: vpf-10110: block %lu, item (%d): Unknown item type found %k - deleted\n",
bh->b_blocknr, i, &ih->ih_key);
delete_item (fs, bh, i);
goto start_again;
@@ -636,31 +635,33 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
item will be deleted */
if (i && !is_stat_data_ih (ih)) {
- /* previous item has not a wrong short_key */
- fsck_log ("pass0: vpf-10120: block %lu: item %d: (%k) fixed to ", bh->b_blocknr, i, &ih->ih_key);
+ /* previous item has a wrong short_key */
+ fsck_log ("pass0: vpf-10120: block %lu: item %d: Wrong key %k, corrected to ",
+ bh->b_blocknr, i, &ih->ih_key);
set_key_dirid (&ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
- fsck_log ("(%k)\n", &ih->ih_key);
+ fsck_log ("%k\n", &ih->ih_key);
dirty = 1;
} else if ((i < nr_items - 1) && !is_stat_data_ih (ih + 1)) {
if (!is_wrong_short_key(&(ih + 1)->ih_key)) {
- fsck_log ("pass0: vpf-10130: block %lu: item %d: (%k) fixed to ", bh->b_blocknr, i, &ih->ih_key);
+ fsck_log ("pass0: vpf-10130: block %lu: item %d: Wrong key %k, corrected to ",
+ bh->b_blocknr, i, &ih->ih_key);
set_key_dirid (&ih->ih_key, get_key_dirid (&(ih + 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih + 1)->ih_key));
/* set_offset (KEY_FORMAT_1, &ih->ih_key, 0);
set_type (KEY_FORMAT_1, &ih->ih_key, TYPE_STAT_DATA);*/
- fsck_log ("(%k)\n", &ih->ih_key);
+ fsck_log ("%k\n", &ih->ih_key);
dirty = 1;
goto start_again;
} else {
- fsck_log ("pass0: vpf-10140: block %lu: items %d and %d have bad short keys (%k), (%k), both deleted\n",
+ fsck_log ("pass0: vpf-10140: block %lu: items %d and %d have bad short keys %k, %k, both deleted\n",
bh->b_blocknr, i, i+1, &ih->ih_key, &(ih + 1)->ih_key);
delete_item (fs, bh, i);
delete_item (fs, bh, i);
goto start_again;
}
} else {
- fsck_log ("pass0: vpf-10150: block %lu: item %d with wrong id (%k) - deleted\n",
+ fsck_log ("pass0: vpf-10150: block %lu: item %d: Wrong key %k, deleted\n",
bh->b_blocknr, i, &ih->ih_key);
delete_item (fs, bh, i);
goto start_again;
@@ -674,19 +675,19 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
/* i or i+1 item should be SD or i+1 should be direct item */
if ((get_ih_item_len (ih) == SD_SIZE) || (get_ih_item_len (ih) == SD_V1_SIZE)) {
/* make i as SD */
- fsck_log("pass0: vpf-10400: block %lu, item (%d), make %k fixed to SD\n",
- bh->b_blocknr, i, &ih->ih_key);
+ fsck_log("pass0: vpf-10400: block %lu, item %d: Wrong order of items - "
+ "change the type of the key %k to StatData\n", bh->b_blocknr, i, &ih->ih_key);
set_type_and_offset (KEY_FORMAT_1, &ih->ih_key, SD_OFFSET, TYPE_STAT_DATA);
dirty = 1;
} else if ((get_ih_item_len (ih+1) == SD_SIZE) || (get_ih_item_len (ih+1) == SD_V1_SIZE)) {
/* make i+1 as SD */
- fsck_log("pass0: vpf-10410: block %lu, item (%d), make %k fixed to SD\n",
- bh->b_blocknr, i + 1, &(ih + 1)->ih_key);
+ fsck_log("pass0: vpf-10410: block %lu, item %d: Wrong order of items - "
+ "change the type of the key %k to StatData\n", bh->b_blocknr, i + 1, &(ih + 1)->ih_key);
set_type_and_offset (KEY_FORMAT_1, &(ih + 1)->ih_key, SD_OFFSET, TYPE_STAT_DATA);
dirty = 1;
} else {
- fsck_log("pass0: vpf-10420: block %lu, item (%d), make %k fixed to DIRECT\n",
- bh->b_blocknr, i+1, &ih->ih_key);
+ fsck_log("pass0: vpf-10420: block %lu, item %d: Wrong order of items - "
+ "change the type of the key %k to Direct\n", bh->b_blocknr, i+1, &(ih + 1)->ih_key);
set_type (get_ih_key_format(ih+1), &(ih + 1)->ih_key, TYPE_DIRECT);
dirty = 1;
}
@@ -703,19 +704,22 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if ((i > 1) && get_key_dirid (&(ih - 2)->ih_key) == get_key_dirid (&(ih - 1)->ih_key)) {
/* fix i-th */
if (!is_stat_data_ih (ih)) {
- fsck_log("pass0: vpf-10430: block %lu, item (%d), wrong order of items dir_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10430: block %lu, item %d: Wrong order of items - "
+ "change the dir_id of the key %k to %lu\n",
bh->b_blocknr, i, &ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));
set_key_dirid (&ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));
dirty = 1;
} else if (i + 1 < nr_items) {
- fsck_log("pass0: vpf-10440: block %lu, item (%d), wrong order of items dir_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10440: block %lu, item %d: Wrong order of items - "
+ "change the dir_id of the key %k to %lu\n",
bh->b_blocknr, i, &ih->ih_key, get_key_dirid (&(ih + 1)->ih_key));
set_key_dirid (&ih->ih_key, get_key_dirid (&(ih + 1)->ih_key));
dirty = 1;
}
} else
if ((i + 1 < nr_items) && get_key_dirid (&ih->ih_key) == get_key_dirid (&(ih + 1)->ih_key)) {
- fsck_log("pass0: vpf-10450: block %lu, item (%d), wrong order of items dir_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10450: block %lu, item %d: Wrong order of items - "
+ "change the dir_id of the key %k to %lu\n",
bh->b_blocknr, i - 1, &(ih - 1)->ih_key, get_key_dirid (&ih->ih_key));
/* fix (i - 1)-th */
set_key_dirid (&(ih - 1)->ih_key, get_key_dirid (&ih->ih_key));
@@ -728,7 +732,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if ((get_key_dirid (&(ih - 1)->ih_key) == get_key_dirid (&(ih + 1)->ih_key)) &&
(get_key_dirid (&(ih - 1)->ih_key) != get_key_dirid (&ih->ih_key)))
{
- fsck_log("pass0: vpf-10460: block %lu, item (%d), wrong order of items dir_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10460: block %lu, item %d: Wrong order of items - "
+ "change the dir_id of the key %k to %lu\n",
bh->b_blocknr, i, &ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));
set_key_dirid (&ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));
dirty = 1;
@@ -737,7 +742,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if ((get_key_objectid (&(ih - 1)->ih_key) == get_key_objectid (&(ih + 1)->ih_key)) &&
(get_key_objectid (&(ih - 1)->ih_key) != get_key_objectid (&ih->ih_key)))
{
- fsck_log("pass0: vpf-10470: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10470: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i, &ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
dirty = 1;
@@ -745,7 +751,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if ((get_key_objectid (&(ih - 1)->ih_key) == get_key_objectid (&ih->ih_key)) &&
(get_key_objectid (&(ih - 1)->ih_key) != get_key_objectid (&(ih + 1)->ih_key)))
{
- fsck_log("pass0: vpf-10480: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10480: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i + 1, &(ih+1)->ih_key, get_key_objectid (&(ih - 1)->ih_key));
set_key_objectid (&(ih + 1)->ih_key, get_key_objectid (&(ih - 1)->ih_key));
dirty = 1;
@@ -753,15 +760,17 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if ((get_key_objectid (&ih->ih_key) == get_key_objectid (&(ih + 1)->ih_key)) &&
(get_key_objectid (&(ih - 1)->ih_key) != get_key_objectid (&(ih + 1)->ih_key)))
{
- fsck_log("pass0: vpf-10490: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
- bh->b_blocknr, i - 1, &(ih-1)->ih_key, &(ih + 1)->ih_key);
+ fsck_log("pass0: vpf-10490: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
+ bh->b_blocknr, i - 1, &(ih-1)->ih_key, get_key_objectid (&(ih + 1)->ih_key));
set_key_objectid (&(ih - 1)->ih_key, get_key_objectid (&(ih + 1)->ih_key));
dirty = 1;
}
if ((get_key_dirid (&(ih - 1)->ih_key) == get_key_dirid (&ih->ih_key)) &&
(get_key_dirid (&(ih - 1)->ih_key) != get_key_dirid (&(ih + 1)->ih_key)))
{
- fsck_log("pass0: vpf-10500: block %lu, item (%d), wrong order of items dir_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10500: block %lu, item %d: Wrong order of items - "
+ "change the dir_id of the key %k to %lu\n",
bh->b_blocknr, i + 1, &(ih+1)->ih_key, get_key_dirid (&(ih - 1)->ih_key));
set_key_dirid (&(ih + 1)->ih_key, get_key_dirid (&(ih - 1)->ih_key));
dirty = 1;
@@ -769,7 +778,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if ((get_key_dirid (&ih->ih_key) == get_key_dirid (&(ih + 1)->ih_key)) &&
(get_key_dirid (&(ih - 1)->ih_key) != get_key_dirid (&(ih + 1)->ih_key)))
{
- fsck_log("pass0: vpf-10510: block %lu, item (%d), wrong order of items dir_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10510: block %lu, item %d: Wrong order of items - "
+ "change the dir_id of the key %k to %lu\n",
bh->b_blocknr, i - 1, &(ih-1)->ih_key, get_key_dirid (&(ih + 1)->ih_key));
set_key_dirid (&(ih - 1)->ih_key, get_key_dirid (&(ih + 1)->ih_key));
dirty = 1;
@@ -782,7 +792,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
get_key_objectid (&(ih - 1)->ih_key) >= get_key_objectid (&ih->ih_key)) {
if ((i + 1 < nr_items) && !is_stat_data_ih (ih + 1)) {
if (get_key_objectid (&(ih - 1)->ih_key) < get_key_objectid (&(ih + 1)->ih_key)) {
- fsck_log("pass0: vpf-10520: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10520: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i - 1, &(ih-1)->ih_key, get_key_objectid (&(ih + 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih + 1)->ih_key));
dirty = 1;
@@ -820,22 +831,26 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if (i <= 1) {
/* take bigger */
if (comp_short_keys (&(ih - 1)->ih_key, &ih->ih_key) == 1) {
- fsck_log("pass0: vpf-10530: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10530: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i, &ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
} else {
- fsck_log("pass0: vpf-10540: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10540: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i - 1, &(ih - 1)->ih_key, get_key_objectid (&ih->ih_key));
set_key_objectid (&(ih - 1)->ih_key, get_key_objectid (&ih->ih_key));
}
} else {
/* take smaller */
if (comp_short_keys (&(ih - 1)->ih_key, &ih->ih_key) == 1) {
- fsck_log("pass0: vpf-10550: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10550: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i - 1, &(ih - 1)->ih_key, get_key_objectid (&ih->ih_key));
set_key_objectid (&(ih - 1)->ih_key, get_key_objectid (&ih->ih_key));
} else {
- fsck_log("pass0: vpf-10560: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10560: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i, &ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
}
@@ -843,13 +858,15 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
dirty = 1;
} else if (!test_bit (1, &err) && !test_bit (3, &err)) {
/* take i - 1 */
- fsck_log("pass0: vpf-10570: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10590: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i, &ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
dirty = 1;
} else if (!test_bit (2, &err) && !test_bit (4, &err)) {
/* take i */
- fsck_log("pass0: vpf-10580: block %lu, item (%d), wrong order of items object_id of %k fixed to %lu\n",
+ fsck_log("pass0: vpf-10600: block %lu, item %d: Wrong order of items - "
+ "change the object_id of the key %k to %lu\n",
bh->b_blocknr, i - 1, &(ih - 1)->ih_key, get_key_objectid (&ih->ih_key));
set_key_objectid (&(ih - 1)->ih_key, get_key_objectid (&ih->ih_key));
dirty = 1;
@@ -865,14 +882,14 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
get_key_dirid (&ih->ih_key) != get_key_dirid (&(ih - 1)->ih_key) ||
get_offset (&ih->ih_key) != 1) {
if (is_direntry_ih (ih)) {
- fsck_log ("pass0: vpf-10160: block %lu: item %d: no \".\" entry found in "
+ fsck_log ("pass0: vpf-10160: block %lu: item %d: No \".\" entry found in "
"the first item of a directory\n", bh->b_blocknr, i);
set_key_dirid (&ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
dirty = 1;
} else {
- fsck_log ("pass0: vpf-10170: block %lu: item %d: (%k) fixed to ",
- bh->b_blocknr, i, &ih->ih_key);
+ fsck_log ("pass0: vpf-10170: block %lu: item %d: Wrong order of items - "
+ "the item \n\t%H fixed to ", bh->b_blocknr, i, ih);
set_key_dirid (&ih->ih_key, get_key_dirid (&(ih - 1)->ih_key));
set_key_objectid (&ih->ih_key, get_key_objectid (&(ih - 1)->ih_key));
@@ -896,7 +913,7 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
}
set_ih_key_format (ih, KEY_FORMAT_1);
}
- fsck_log ("%k\n", &ih->ih_key);
+ fsck_log ("\n\t%H\n", ih);
dirty = 1;
}
}
@@ -910,7 +927,7 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
/* delete item if it is not in correct order of object items */
if (i && not_of_one_file (&ih->ih_key, &(ih - 1)->ih_key) &&
!is_stat_data_ih (ih)) {
- fsck_log ("pass0: vpf-10180: block %lu: item %d: %k follows non stat item %k - deleted\n",
+ fsck_log ("pass0: vpf-10180: block %lu: item %d: The item %k, which follows non StatData item %k, is deleted\n",
bh->b_blocknr, i, &ih->ih_key, &(ih - 1)->ih_key);
delete_item (fs, bh, i);
goto start_again;
@@ -925,32 +942,44 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
/* not SD, not direntry */
if (i && comp_short_keys (&(ih - 1)->ih_key, &ih->ih_key) == 0) {
if (is_stat_data_ih (ih - 1)) {
- if (get_offset (&ih->ih_key) != 1) {
+ if (get_offset (&ih->ih_key) != 1) {
set_offset(key_format(&ih->ih_key), &ih->ih_key, 1);
dirty = 1;
}
} else if (is_indirect_ih (ih - 1) && is_direct_ih (ih)) {
- if (get_offset (&ih->ih_key) !=
- get_offset(&(ih - 1)->ih_key) + I_UNFM_NUM (ih - 1) * fs->fs_blocksize)
- {
+ if (get_offset (&ih->ih_key) !=
+ get_offset(&(ih - 1)->ih_key) + I_UNFM_NUM (ih - 1) * fs->fs_blocksize)
+ {
set_offset(key_format(&ih->ih_key), &ih->ih_key,
- get_offset(&(ih - 1)->ih_key) + I_UNFM_NUM (ih - 1) * fs->fs_blocksize);
+ get_offset(&(ih - 1)->ih_key) + I_UNFM_NUM (ih - 1) * fs->fs_blocksize);
dirty = 1;
- }
+ }
} else {
- /* not first item in the leaf after neither stat data nor indirect */
- fsck_log("pass0: vpf-10250: block %lu, item (%d), wrong order of items (%k, %k) - delete\n",
- bh->b_blocknr, i, &(ih - 1)->ih_key, &ih->ih_key);
+ /* if indirect item or not the first direct item in the leaf */
+ fsck_log("pass0: vpf-10250: block %lu, item %d: The item %k with wrong type is deleted\n",
+ bh->b_blocknr, i, &ih->ih_key);
delete_item (fs, bh, i);
goto start_again;
}
+
+ if (is_direct_ih (ih)) {
+ if (STORE_TAIL_IN_UNFM (get_offset (&ih->ih_key) + get_ih_item_len (ih) - 1,
+ get_ih_item_len (ih), bh->b_size))
+ {
+ fsck_log("pass0: vpf-10700: block %lu, item %d: The item with wrong offset"
+ " or length found %k, len % lu - deleted\n", bh->b_blocknr, i, &ih->ih_key,
+ get_ih_item_len (ih));
+ delete_item (fs, bh, i);
+ goto start_again;
+ }
+ }
} else {
/*first item in the node or first item of the file */
if (i) {
/* first item of the file, but not SD - delete */
- fsck_log("pass0: vpf-10190: block %lu, item (%d), item without stat data found (%k) - delete\n",
- bh->b_blocknr, i, &ih->ih_key);
+ fsck_log("pass0: vpf-10190: block %lu, item %d: The item %k, which follows non StatData"
+ " item %k, is deleted\n", bh->b_blocknr, i, &ih->ih_key, &(ih - 1)->ih_key );
delete_item (fs, bh, i);
goto start_again;
}
@@ -959,8 +988,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
offset = (__u64)get_offset (&ih->ih_key);
if (is_indirect_ih (ih)) {
if (offset % fs->fs_blocksize != 1) {
- fsck_log("pass0: vpf-10200: block %lu, item (%d), wrong item offset (%k) - delete\n",
- bh->b_blocknr, i, &ih->ih_key);
+ fsck_log("pass0: vpf-10200: block %lu, item %d: The item %k with wrong offset is deleted\n",
+ bh->b_blocknr, i, &ih->ih_key);
delete_item (fs, bh, i);
goto start_again;
}
@@ -969,8 +998,9 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if (is_direct_ih (ih)) {
if (!correct_direct_item_offset (get_offset (&ih->ih_key), key_format (&ih->ih_key)) ||
STORE_TAIL_IN_UNFM (offset + get_ih_item_len (ih) - 1, get_ih_item_len (ih), bh->b_size)) {
- fsck_log("pass0: vpf-10210: block %lu, item (%d), wrong item offset (%k) - delete\n",
- bh->b_blocknr, i, &ih->ih_key);
+ fsck_log("pass0: vpf-10210: block %lu, item %d: The item with wrong offset ",
+ bh->b_blocknr, i);
+ fsck_log("or length found %k, len % lu - deleted\n", &ih->ih_key, get_ih_item_len (ih));
delete_item (fs, bh, i);
goto start_again;
}
@@ -978,11 +1008,12 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
offset += get_bytes_number (ih, fs->fs_blocksize);
if (!does_it_fit_into_dev (offset)) {
- fsck_log("pass0: vpf-10230: block %lu, item (%d) offset is too big (%k) - delete\n",
+ fsck_log("pass0: vpf-10230: block %lu, item %d: The item offset is is too big %k - deleted\n",
bh->b_blocknr, i, &ih->ih_key);
delete_item (fs, bh, i);
goto start_again;
- }
+ }
+
}
}
@@ -992,8 +1023,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
/* previous item has key not smaller than the key of currect item */
if (is_stat_data_ih (ih - 1) && !is_stat_data_ih (ih)) {
/* fix key of stat data such as if it was stat data of that item */
- fsck_log ("pass0: block %lu: %d-th item %k is out of order, made a stat data of %d-th (%k)\n",
- bh->b_blocknr, i - 1, &(ih - 1)->ih_key, i, &ih->ih_key);
+ fsck_log ("pass0: block %lu, items %d, %d: Wrong order of items - make the StatData item %k of the file %k\n",
+ bh->b_blocknr, i - 1, i, &(ih - 1)->ih_key, &ih->ih_key);
set_key_dirid (&(ih - 1)->ih_key, get_key_dirid (&ih->ih_key));
set_key_objectid (&(ih - 1)->ih_key, get_key_objectid (&ih->ih_key));
set_offset (KEY_FORMAT_1, &(ih - 1)->ih_key, 0);
@@ -1009,14 +1040,14 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
switch (retval) {
case 0:
/* delete upper item */
- fsck_log ("pass0: block %lu: %d-th (upper) item (%k) is out of order, deleted\n",
+ fsck_log ("pass0: block %lu, item %d (upper): Item %k is out of order - deleted\n",
bh->b_blocknr, i - 1, &(ih - 1)->ih_key);
delete_item (fs, bh, i - 1);
goto start_again;
case 1:
/* delete lower item */
- fsck_log ("pass0: block %lu: %d-th (lower) item (%k) is out of order, deleted\n",
+ fsck_log ("pass0: block %lu, item %d (lower): Item %k is out of order - deleted\n",
bh->b_blocknr, i, &ih->ih_key);
delete_item (fs, bh, i);
goto start_again;
@@ -1029,23 +1060,23 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
switch (retval) {
case 0:
/* delete lower item */
- fsck_log ("pass0: block %lu: %d-th (lower) item (%k) is out of order, deleted\n",
+ fsck_log ("pass0: block %lu, item %d (lower): Item %k is out of order - deleted\n",
bh->b_blocknr, i, &ih->ih_key);
delete_item (fs, bh, i);
goto start_again;
case 1:
/* delete upper item */
- fsck_log ("pass0: block %lu: %d-th (upper) item (%k) is out of order, deleted\n",
+ fsck_log ("pass0: block %lu, %d (upper): Item %k is out of order - deleted\n",
bh->b_blocknr, i - 1, &(ih - 1)->ih_key);
delete_item (fs, bh, i - 1);
goto start_again;
default:
- /* there wer only two items in a node, so we could not
+ /* there were only two items in a node, so we could not
decide what to delete, go and ask user */
}
- fsck_log ("pass0: block %lu, items %d,%d, which of these items looks better (other will be deleted)?\n"
+ fsck_log ("pass0: block %lu, items %d and %d: Which of these items looks better (the other will be deleted.)?\n"
"%k\n%k\n", bh->b_blocknr, i-1, i, &(ih - 1)->ih_key, &ih->ih_key);
if (fsck_user_confirmed (fs, "1 or 2?", "1\n", 1))
delete_item (fs, bh, i - 1);
@@ -1057,8 +1088,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
if (is_stat_data_ih (ih) && (get_ih_item_len (ih) != SD_SIZE &&
get_ih_item_len (ih) != SD_V1_SIZE)) {
- fsck_log ("pass0: block %lu, item %d, stat data of wrong length %k - deleted\n",
- bh->b_blocknr, i, &ih->ih_key);
+ fsck_log ("pass0: block %lu, item %d: StatData item of wrong length found %H - deleted\n",
+ bh->b_blocknr, i, ih);
delete_item (fs, bh, i);
goto start_again;
}
@@ -1078,8 +1109,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
(file_format != KEY_FORMAT_UNDEFINED) &&
(file_format != get_ih_key_format (ih)))
{
- fsck_log("pass0: vpf-10240: block %lu, item (%d), item format (%H) is not equal to SD format (%d) - delete\n",
- bh->b_blocknr, i, ih, file_format);
+ fsck_log("pass0: vpf-10240: block %lu, item (%d): Item %k, which format (%d) is not equal to StatData "
+ "format (%d), is deleted\n", bh->b_blocknr, i, &ih->ih_key, get_ih_key_format(ih), file_format);
delete_item (fs, bh, i);
file_format = KEY_FORMAT_UNDEFINED;
goto start_again;
@@ -1092,7 +1123,7 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
get_sd_mode (ih - 1, B_I_PITEM (bh, ih - 1), &mode);
if (not_a_directory (B_I_PITEM (bh, ih - 1)) && is_direntry_ih (ih)) {
/* make SD mode SD of dir */
- fsck_log ("pass0: block %lu, item %d: directory %K with wrong mode (%M), fixed to ",
+ fsck_log ("pass0: block %lu, item %d: The directory %K has the wrong mode (%M), corrected to ",
bh->b_blocknr, i, &ih->ih_key, mode);
mode &= ~S_IFMT;
mode |= S_IFDIR;
@@ -1101,7 +1132,7 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
dirty = 1;
} else if (!not_a_directory (B_I_PITEM (bh, ih - 1)) && !is_direntry_ih (ih)) {
/* make SD mode SD of regular file */
- fsck_log ("pass0: block %lu, item %d: not directory %K with wrong mode (%M), fixed to ",
+ fsck_log ("pass0: block %lu, item %d: Not the directory %K has the wrong mode (%M), corrected to ",
bh->b_blocknr, i, &ih->ih_key, mode);
mode &= ~S_IFMT;
mode |= S_IFREG;
@@ -1110,7 +1141,7 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
dirty = 1;
}
if (not_a_regfile (B_I_PITEM (bh, ih - 1)) && is_indirect_ih (ih)) {
- fsck_log ("pass0: block %lu, item %d: file %K having indirect item with wrong mode (%M), fixed to ",
+ fsck_log ("pass0: block %lu, item %d: The file %K has the wrong mode (%M), corrected to ",
bh->b_blocknr, i, &ih->ih_key, mode);
mode &= ~S_IFMT;
mode |= S_IFREG;
@@ -1137,8 +1168,8 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
/*DEBUG*/
if (!is_stat_data_ih (ih) && get_offset (&ih->ih_key) == 0)
- reiserfs_panic ("block %lu: item %d, zero offset found %k (%d)\n", bh->b_blocknr, i, &ih->ih_key);
-
+ reiserfs_panic ("block %lu, item %d: Zero offset can have StatData items only, but found %k\n",
+ bh->b_blocknr, i, &ih->ih_key);
if (!is_indirect_ih (ih))
continue;
@@ -1152,15 +1183,15 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
get_offset (&tmp_key) + get_bytes_number (ih, bh->b_size) - 1);
if (get_offset (&tmp_key) < get_offset (&ih->ih_key)) {
- fsck_log ("pass0: block %lu, item %d, %k is wrong - deleted\n",
- bh->b_blocknr, i, &ih->ih_key);
+ fsck_log ("pass0: block %lu, item %d: The item, which has wrong offset %k, is deleted\n",
+ bh->b_blocknr, i, &ih->ih_key);
delete_item (fs, bh, i);
goto start_again;
}
}
/* temporary ugly fix */
-/*
+/*
if (i && is_stat_data_ih (ih - 1) && !not_of_one_file (&ih->ih_key, &(ih - 1)->ih_key)) {
__u16 mode;
@@ -1214,15 +1245,20 @@ static void pass0_correct_leaf (reiserfs_filsys_t * fs,
/* mark all objectids in use */
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;
+
mark_objectid_really_used (proper_id_map (fs), get_key_dirid (&ih->ih_key));
mark_objectid_really_used (proper_id_map (fs), get_key_objectid (&ih->ih_key));
+ if (is_direntry_ih(ih)) {
+ for (j = 0, deh = B_I_DEH (bh, ih); j < get_ih_entry_count (ih); j ++, deh++)
+ mark_objectid_really_used(proper_id_map (fs), get_deh_objectid(deh));
+ }
}
if (get_blkh_nr_items (B_BLK_HEAD (bh)) < 1) {
/* pass 1 will skip this */
pass_0_stat (fs)->all_contents_removed ++;
- fsck_log ("pass0: block %lu got all items deleted\n",
- bh->b_blocknr);
+// fsck_log ("pass0: block %lu: All items were deleted.\n", bh->b_blocknr);
} else {
/* pass1 will use this bitmap */
pass0_mark_leaf (bh->b_blocknr);
@@ -1240,14 +1276,16 @@ static int is_bad_sd (struct item_head * ih, char * item)
struct stat_data * sd = (struct stat_data *)item;
if (get_key_offset_v1 (&ih->ih_key) || get_key_uniqueness (&ih->ih_key)) {
- reiserfs_warning (stderr, "Bad SD? %k\n", &ih->ih_key);
+ fsck_log ("vpf-10610: StatData item %k has non zero offset found.\n",
+ &ih->ih_key);
return 1;
}
if (get_ih_item_len (ih) == SD_V1_SIZE) {
/* looks like old stat data */
if (get_ih_key_format (ih) != KEY_FORMAT_1)
- fsck_log ("item %H has wrong format\n", ih);
+ fsck_log ("vpf-10620: StatData item %k has wrong format.\n",
+ &ih->ih_key);
return 0;
}
@@ -1270,7 +1308,7 @@ int is_bad_directory (struct item_head * ih, char * item, int dev, int blocksize
__u32 prev_offset = 0;
__u16 prev_location = get_ih_item_len (ih);
int min_entry_size = 1;/* we have no way to understand whether the
- filesystem were created in 3.6 format or
+ filesystem wes created in 3.6 format or
converted to it. So, we assume that minimal name
length is 1 */
@@ -1371,16 +1409,15 @@ int is_leaf_bad (struct buffer_head * bh)
for (i = 0, ih = B_N_PITEM_HEAD (bh, 0); i < B_NR_ITEMS (bh); i ++, ih ++) {
if (is_bad_item (bh, ih, B_I_PITEM (bh, ih))) {
- fsck_log ("is_leaf_bad: block %lu: %d-th item (%H) is bad\n",
+ fsck_log ("is_leaf_bad: block %lu, item %d: The corrupted item found (%H)\n",
bh->b_blocknr, i, ih);
bad = 1;
continue;
}
if (i && bad_pair (fs, bh, i)) {
- fsck_log ("is_leaf_bad: block %luL %d-th item (%H) and "
- "the next one (%H) are in wrong order\n",
- bh->b_blocknr, i - 1, ih - 1, ih);
+ fsck_log ("is_leaf_bad: block %lu items %d and %d: Wrong order of items:"
+ "\n\t%H\n\t%H\n", bh->b_blocknr, i - 1, i, ih - 1, ih);
bad = 1;
}
}
@@ -1399,7 +1436,7 @@ static int is_to_be_read (reiserfs_filsys_t * fs, unsigned long block)
static void do_pass_0 (reiserfs_filsys_t * fs)
{
struct buffer_head * bh;
- int i;
+ unsigned long i;
int what_node;
unsigned long done = 0, total;
@@ -1422,7 +1459,7 @@ static void do_pass_0 (reiserfs_filsys_t * fs)
}
brelse (bh);
reiserfs_free (fs);
- exit(4);
+ exit(0);
}
@@ -1436,19 +1473,18 @@ static void do_pass_0 (reiserfs_filsys_t * fs)
bh = bread (fs->fs_dev, i, fs->fs_blocksize);
if (!bh) {
- /* we were reading one block at time, and failed, so mark
- block bad */
- fsck_progress ("pass0: reading block %lu failed\n", i);
+ /* we were reading one block at time, and failed, so mark block bad */
+ fsck_progress ("%s: Reading of the block %lu failed\n", __FUNCTION__, i);
continue;
}
if (fs->fs_badblocks_bm && reiserfs_bitmap_test_bit (fs->fs_badblocks_bm, i))
- reiserfs_panic ("%s: Should not read bad block\n", __FUNCTION__);
+ reiserfs_panic ("The block (%lu), specified in badblock list, was read.", i);
if (not_data_block (fs, i)) {
- /* blck which could not be pointed by indirect item */
+ /* block which could not be pointed by indirect item */
if (!(block_of_journal (fs, i) && fsck_data(fs)->rebuild.use_journal_area))
- reiserfs_panic ("not data block found, %lu", i);
+ reiserfs_panic ("The block (%lu) from non data area was read.", i);
}
pass_0_stat (fs)->dealt_with ++;
@@ -1499,8 +1535,8 @@ int is_good_unformatted (unsigned long block)
/* this is for check only. With this we make sure that all pointers we
put into tree on pass 1 do not point to leaves (FIXME), do not
- point to journal, bitmap, etc, do not point out of fs boundary and
- are marked used in on-disk bitmap */
+ point to journal, bitmap, etc, do not point out of fs boundary (and
+ are marked used in on-disk bitmap - this condition skipped for now). */
int still_bad_unfm_ptr_1 (unsigned long block)
{
if (!block)
@@ -1508,15 +1544,15 @@ int still_bad_unfm_ptr_1 (unsigned long block)
if (pass0_is_leaf (block))
return 1;
if (pass0_is_bad_unfm (block) && !is_bad_unfm_in_tree_once (block))
- return 1;
+ return 2;
if (not_data_block (fs, block))
- return 1;
+ return 3;
/*
if (!was_block_used (block))
- return 1;
+ return 4;
*/
if (block >= get_sb_block_count (fs->fs_ondisk_sb))
- return 1;
+ return 5;
return 0;
}
@@ -1541,11 +1577,11 @@ int are_there_allocable_blocks (int amout_needed)
if (reiserfs_bitmap_zeros (fsck_allocable_bitmap (fs)) < amout_needed) {
int zeros = 0, i;
- fsck_progress ("Hmm, there are not enough allocable blocks, checking bitmap...");
+ fsck_progress ("Not enough allocable blocks, checking bitmap...");
for (i = 0; i < fsck_allocable_bitmap (fs)->bm_bit_size; i ++)
if (!reiserfs_bitmap_test_bit (fsck_allocable_bitmap (fs), i))
zeros ++;
- fsck_progress ("there are %d zeros, btw\n", zeros);
+ fsck_progress ("there are %d allocable blocks, btw\n", zeros);
return 0;
}
return 1;
@@ -1557,7 +1593,7 @@ unsigned long alloc_block (void)
unsigned long block = 0; /* FIXME: start point could be used */
if (reiserfs_bitmap_find_zero_bit (fsck_allocable_bitmap (fs), &block)) {
- die ("alloc_block: allocable blocks counter is wrong");
+ die ("alloc_block: Allocable blocks counter is wrong");
return 0;
}
reiserfs_bitmap_set_bit (fsck_allocable_bitmap (fs), block);
@@ -1570,19 +1606,6 @@ void make_allocable (unsigned long block)
reiserfs_bitmap_clear_bit (fsck_allocable_bitmap (fs), block);
}
-/*
-unsigned long how_many_uninsertables_were_there (void)
-{
- return fsck_data (fs)->rebuild.uninsertable_leaves;
-}
-
-
-unsigned long how_many_items_were_saved (void)
-{
- return fsck_data (fs)->rebuild.saved_on_pass1;
-}
-*/
-
static void choose_hash_function (reiserfs_filsys_t * fs)
{
unsigned long max;
@@ -1603,8 +1626,8 @@ static void choose_hash_function (reiserfs_filsys_t * fs)
}
if (fsck_data (fs)->rebuild.hash_hits [i])
- fsck_log ("%s got %lu hits\n", code2name (i),
- fsck_data (fs)->rebuild.hash_hits [i]);
+ fsck_log ("%lu directory entries were hashed with %s hash.\n",
+ fsck_data (fs)->rebuild.hash_hits [i], code2name(i));
}
if (max == 0 || hash_code == 0) {
@@ -1613,17 +1636,17 @@ static void choose_hash_function (reiserfs_filsys_t * fs)
hash_code = get_sb_hash_code (fs->fs_ondisk_sb);
if (!hash_code)
hash_code = DEFAULT_HASH;
- fsck_log ("Could not find hash in use. Using %s\n",
+ fsck_log ("Could not find a hash in use. Using %s\n",
code2name (hash_code));
}
/* compare the most appropriate hash with the hash set in super block */
if (hash_code != get_sb_hash_code (fs->fs_ondisk_sb)) {
- set_sb_hash_code (fs->fs_ondisk_sb, hash_code);
- fsck_progress ("Selected hash (%s) does not match to one set in super block (%s).\n",
+ fsck_progress ("Selected hash (%s) does not match to the hash set in the super block (%s).\n",
code2name (hash_code), code2name (get_sb_hash_code (fs->fs_ondisk_sb)));
- } else {
- fsck_progress ("\t%s hash is selected\n", code2name (hash_code));
- }
+ set_sb_hash_code (fs->fs_ondisk_sb, hash_code);
+ }
+ fsck_progress ("\t%s hash is selected\n", code2name (hash_code));
+
reiserfs_hash (fs) = code2func (hash_code);
}
@@ -1643,7 +1666,7 @@ static void init_source_bitmap (reiserfs_filsys_t * fs)
case ALL_BLOCKS:
fsck_source_bitmap (fs) = reiserfs_create_bitmap (block_count);
reiserfs_bitmap_fill (fsck_source_bitmap (fs));
- fsck_progress ("Whole device (%d blocks) is to be scanned\n",
+ fsck_progress ("The whole partition (%d blocks) is to be scanned\n",
reiserfs_bitmap_ones (fsck_source_bitmap (fs)));
break;
@@ -1659,10 +1682,10 @@ static void init_source_bitmap (reiserfs_filsys_t * fs)
case EXTERN_BITMAP:
fp = fopen (fsck_data (fs)->rebuild.bitmap_file_name, "r");
if (!fp)
- reiserfs_panic ("init_bitmap: could not load bitmap: %m\n");
+ reiserfs_panic ("Could not load bitmap: %m\n");
fsck_source_bitmap (fs) = reiserfs_bitmap_load (fp);
if (!fsck_source_bitmap (fs))
- reiserfs_panic ("could not load fitmap from \"%s\"",
+ reiserfs_panic ("Could not load fitmap from \"%s\"",
fsck_data (fs)->rebuild.bitmap_file_name);
fsck_progress ("%d blocks marked used in extern bitmap\n",
reiserfs_bitmap_ones (fsck_source_bitmap (fs)));
@@ -1684,7 +1707,7 @@ static void init_source_bitmap (reiserfs_filsys_t * fs)
/* bitmap is definitely broken, mark all blocks of this bitmap block as used */
bits_amount = (reserved < fs->fs_blocksize * 8) ? reserved : fs->fs_blocksize * 8;
- fsck_log("%s: bitmap %lu (of %lu bits) is wrong - make all blocks [%lu - %lu] as used\n",
+ fsck_log("%s: Bitmap %lu (of %lu bits) is wrong - mark all blocks [%lu - %lu] as used\n",
__FUNCTION__, i, bits_amount, i * fs->fs_blocksize * 8,
fs->fs_blocksize * 8 * i + bits_amount);
@@ -1721,7 +1744,7 @@ static void init_source_bitmap (reiserfs_filsys_t * fs)
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_source_bitmap: wrong super block");
+ die ("init_source_bitmap: Wrong super block location, you must run --rebuild-sb.");
block = get_journal_start_must (fs);
@@ -1782,8 +1805,8 @@ static void save_pass_0_result (reiserfs_filsys_t * fs)
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));
+ fsck_progress ("%s: Could not rename the temporary file temp_fsck_file.deleteme to %s",
+ __FUNCTION__, state_dump_file (fs));
}
@@ -1822,7 +1845,7 @@ static void after_pass_0 (reiserfs_filsys_t * fs)
fsck_progress ("Flushing..");
fs->fs_dirt = 1;
reiserfs_flush (fs);
- fsck_progress ("done\n");
+ fsck_progress ("finished\n");
stage_report (0, fs);
@@ -1848,7 +1871,7 @@ static void after_pass_0 (reiserfs_filsys_t * fs)
"###########\n", ctime (&t));
fs->fs_dirt = 1;
reiserfs_close (fs);
- exit (4);
+ exit(0);
}
@@ -1856,7 +1879,7 @@ void pass_0 (reiserfs_filsys_t * fs)
{
if (get_reiserfs_format (fs->fs_ondisk_sb) != fs->fs_format ||
get_reiserfs_format (fs->fs_ondisk_sb) == REISERFS_FORMAT_UNKNOWN)
- reiserfs_panic ("pass 0: version mismatch found, you should run --rebuild-sb");
+ reiserfs_panic ("pass 0: ReiserFS format version mismatch found, you should run --rebuild-sb");
fsck_progress ("\nPass 0:\n");
if (fsck_log_file (fs) != stderr)
@@ -1872,31 +1895,3 @@ void pass_0 (reiserfs_filsys_t * fs)
after_pass_0 (fs);
}
-
-
-
-
-#if 0
-
-/* node looks like a leaf (block head and ih_item_length & ih_location
- of item_head array are correct. This function recovers (tries to) node's key
- table and directory items. */
-static void recover_leaf (reiserfs_filsys_t * fs, struct buffer_head * bh)
-{
- int i;
- struct item_head * ih;
-
- /* mark transparently corrupted items - bad */
- ih = B_N_PITEM_HEAD (bh, 0);
- for (i = 0; i < node_item_number (bh); i ++, ih ++) {
- if (type_unknown (&ih->ih_key) ||
- ih->ih_key.k_dir_id == 0 ||
- ih->ih_key.k_objectid) {
- mark_ih_bad (ih);
- continue;
- }
- }
-}
-
-#endif
-
diff --git a/fsck/pass1.c b/fsck/pass1.c
index 58fc609..bea2575 100644
--- a/fsck/pass1.c
+++ b/fsck/pass1.c
@@ -76,13 +76,28 @@ static void stat_data_in_tree (struct buffer_head *bh,
zero_nlink (ih, B_I_PITEM (bh, ih));
}
+static char *still_bad_unfm_ptr_to_string (int val) {
+ switch (val) {
+ case 1:
+ return "a leaf";
+ case 2:
+ return "shared between a few files";
+ case 3:
+ return "not a data block";
+ case 4:
+ return "not used in on-disk bitmap";
+ case 5:
+ return "out of partition boundary";
+ }
+ return "";
+}
/* this just marks blocks pointed by an indirect item as used in the
new bitmap */
static void indirect_in_tree (struct buffer_head * bh,
struct item_head * ih)
{
- int i;
+ int i, ret;
__u32 * unp;
__u32 unfm_ptr;
@@ -92,11 +107,10 @@ 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);
-
+ if ((ret = still_bad_unfm_ptr_1 (unfm_ptr)))
+ reiserfs_panic ("%s: block %lu: The file %k points to the block (%u) which is %s",
+ __FUNCTION__, bh->b_blocknr, &ih->ih_key, unfm_ptr, still_bad_unfm_ptr_to_string(ret));
+
mark_block_used (unfm_ptr, 1);
}
}
@@ -120,7 +134,6 @@ static void insert_pointer (struct buffer_head * bh, struct path * path)
{
struct item_head * ih;
char * body;
- int zeros_number;
int retval;
struct tree_balance tb;
@@ -147,9 +160,8 @@ static void insert_pointer (struct buffer_head * bh, struct path * path)
ih = 0;
body = (char *)bh;
//memmode = 0;
- zeros_number = 0;
-
- do_balance (&tb, ih, body, M_INTERNAL, zeros_number);
+
+ do_balance (&tb, ih, body, M_INTERNAL, 0);
leaf_is_in_tree_now (bh);
}
@@ -194,7 +206,10 @@ int balance_condition_2_fails (struct buffer_head * new, struct path * path)
INITIALIZE_PATH(path_to_right_neighbor);
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");
+ reiserfs_panic ("%s: block %lu, pointer %d: The left delimiting key %k of the block (%lu) is wrong,"
+ "the item cannot be found", __FUNCTION__, PATH_H_PBUFFER(path, 1)->b_blocknr, pos,
+ right_dkey, get_dc_child_blocknr(B_N_CHILD (bh, pos + 1)));
+
used_space = B_CHILD_SIZE (PATH_PLAST_BUFFER (&path_to_right_neighbor));
pathrelse (&path_to_right_neighbor);
}
@@ -324,7 +339,7 @@ static void pass1_correct_leaf (reiserfs_filsys_t * fs,
int i, j;
struct item_head * ih;
__u32 * ind_item;
- unsigned long unfm_ptr;
+ __u32 unfm_ptr;
int dirty = 0;
@@ -350,17 +365,18 @@ static void pass1_correct_leaf (reiserfs_filsys_t * fs,
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,
+ fsck_log ("pass1: block %lu, item %d, entry %d: The entry \"%.*s\" of the %k is hashed with %s "
+ "whereas proper hash is %s", bh->b_blocknr, i, j, name_len, name, &ih->ih_key,
code2name (hash_code), code2name (get_sb_hash_code (fs->fs_ondisk_sb)));
if (get_ih_entry_count (ih) == 1) {
delete_item (fs, bh, i);
+ fsck_log(" - the only entry - item was deleted\n");
i --;
ih --;
break;
} else {
cut_entry (fs, bh, i, j, 1);
+ fsck_log(" - deleted\n");
j --;
deh = B_I_DEH (bh, ih);
}
@@ -385,8 +401,8 @@ static void pass1_correct_leaf (reiserfs_filsys_t * fs,
/* this corruption of indirect item had to be fixed in pass0 */
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);
+ reiserfs_panic ("%s: block %lu, item %d, pointer %d: The wrong pointer (%u) in the file %K. "
+ "Must be fixed on pass0.", __FUNCTION__, bh->b_blocknr, i, j, unfm_ptr, &ih->ih_key);
/* 1. zero slots pointing to a leaf */
if (is_used_leaf (unfm_ptr)) {
@@ -419,65 +435,6 @@ static void pass1_correct_leaf (reiserfs_filsys_t * fs,
mark_buffer_dirty (bh);
}
-
-/*######### has to die ##########*/
-/* append item to end of list. Set head if it is 0. For indirect item
- set wrong unformatted node pointers to 0 */
-void save_item (struct si ** head, struct buffer_head * bh, struct item_head * ih, char * item)
-{
- struct si * si, * cur;
-
- if (is_bad_item (bh, ih, item/*, fs->s_blocksize, fs->s_dev*/)) {
- return;
- }
-
- if (is_indirect_ih (ih)) {
- fsck_progress ("save_item (block %lu: %H (should not happen)\n", ih);
- }
-
- pass_1_stat (fs)->saved_items ++;
-
- si = getmem (sizeof (*si));
- 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, get_ih_item_len(ih));
-
- // changed by XB
- si->last_known = NULL;
-
- if (*head == 0)
- *head = si;
- else {
- cur = *head;
- // changed by XB
- // while (cur->si_next)
- // cur = cur->si_next;
-
- {
- int count = 0;
- int speedcount = 0;
-
- while (cur->si_next) {
- if (cur->last_known!=NULL) {
- cur = cur->last_known; // speed up to the end if the chain
- speedcount++;
- } else {
- cur = cur->si_next;
- count++;
- }
- }
-
- if ((*head)!=cur) // no self referencing loop please
- (*head)->last_known = cur;
- }
-
- cur->si_next = si;
- }
- return;
-}
-
-
struct si * remove_saved_item (struct si * si)
{
struct si * tmp = si->si_next;
@@ -487,31 +444,6 @@ struct si * remove_saved_item (struct si * si)
return tmp;
}
-
-#if 0
-static void save_items (struct si ** head, 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 ++) {
- save_item (head, bh, ih, B_I_PITEM (bh, ih));
- }
-}
-
-/* insert_item_separately */
-static void put_saved_items_into_tree_1 (struct si * si)
-{
- while (si) {
- insert_item_separately (&(si->si_ih), si->si_dnm_data,
- 0/*was not in tree*/);
- si = remove_saved_item (si);
- }
-}
-#endif
-
-
/* 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)
@@ -545,7 +477,7 @@ static void init_new_bitmap (reiserfs_filsys_t * fs)
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");
+ die ("init_new_bitmap: Wrong super block location, you must run --rebuild-sb.");
block = get_journal_start_must (fs);
@@ -557,7 +489,7 @@ static void init_new_bitmap (reiserfs_filsys_t * fs)
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",
+ reiserfs_panic ("%s: The block pointer to not data area, must be fixed on the pass0.\n",
__FUNCTION__);
reiserfs_bitmap_set_bit (fsck_new_bitmap (fs), i);
}
@@ -584,7 +516,7 @@ static void init_new_bitmap (reiserfs_filsys_t * fs)
continue */
static void find_allocable_blocks (reiserfs_filsys_t * fs)
{
- int i;
+ unsigned long i;
fsck_progress ("Looking for allocable blocks .. ");
@@ -600,7 +532,7 @@ static void find_allocable_blocks (reiserfs_filsys_t * fs)
continue;
if (is_good_unformatted (i) && is_bad_unformatted (i))
- die ("find_allocable_blocks: bad and good unformatted");
+ die ("find_allocable_blocks: The block (%lu) is masr as good and as bad at once.", i);
if (is_good_unformatted (i) || is_bad_unformatted (i)) {
/* blocks which were pointed once or more thn onec from indirect
@@ -617,7 +549,7 @@ static void find_allocable_blocks (reiserfs_filsys_t * fs)
pass_1_stat (fs)->allocable_blocks ++;
}
}
- fsck_progress ("ok\n");
+ fsck_progress ("fininshed\n");
fs->block_allocator = reiserfsck_reiserfs_new_blocknrs;
fs->block_deallocator = reiserfsck_reiserfs_free_block;
@@ -668,7 +600,7 @@ static void save_pass_1_result (reiserfs_filsys_t * fs)
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",
+ fsck_progress ("pass 1: Could not rename the temporary file temp_fsck_file.deleteme to %s",
state_dump_file (fs));
}
@@ -708,7 +640,7 @@ extern reiserfs_bitmap_t * leaves_bitmap;
static void do_pass_1 (reiserfs_filsys_t * fs)
{
struct buffer_head * bh;
- int i;
+ unsigned long i;
int what_node;
unsigned long done = 0, total;
@@ -728,13 +660,13 @@ static void do_pass_1 (reiserfs_filsys_t * fs)
if (!bh) {
/* we were reading one block at time, and failed, so mark
block bad */
- fsck_progress ("pass1: reading block %lu failed\n", i);
+ fsck_progress ("pass1: Reading of the block %lu failed\n", i);
continue;
}
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. "
+ fsck_progress ("build_the_tree: Nothing but leaves are expected. "
"Block %lu - %s\n", i,
(what_node == THE_INTERNAL) ? "internal" : "??");
brelse (bh);
@@ -744,7 +676,7 @@ static void do_pass_1 (reiserfs_filsys_t * fs)
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 (%u) is in tree already\n", i);
+ die ("build_the_tree: The leaf (%lu) is in the tree already\n", i);
/* fprintf (block_list, "leaf %d\n", i + j);*/
pass_1_stat (fs)->leaves ++;
@@ -762,11 +694,8 @@ static void do_pass_1 (reiserfs_filsys_t * fs)
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);
+ fsck_log ("is_leaf_bad: WARNING: The leaf (%lu) is formatted badly. Will be handled on the the pass2.\n",
+ bh->b_blocknr);
mark_block_uninsertable (bh->b_blocknr);
brelse (bh);
continue;
@@ -824,7 +753,7 @@ static void after_pass_1 (reiserfs_filsys_t * fs)
fsck_progress ("Flushing..");
fs->fs_dirt = 1;
reiserfs_flush (fs);
- fsck_progress ("done\n");
+ fsck_progress ("finished\n");
stage_report (1, fs);
@@ -851,7 +780,7 @@ static void after_pass_1 (reiserfs_filsys_t * fs)
"###########\n", ctime (&t));
fs->fs_dirt = 1;
reiserfs_close (fs);
- exit (4);
+ exit(0);
}
@@ -871,13 +800,3 @@ void pass_1 (reiserfs_filsys_t * fs)
after_pass_1 (fs);
}
-
-#if 0
-
-/* pass the S+ tree of filesystem */
-void recover_internal_tree (struct super_block * s)
-{
- check_internal_structure(s);
- build_the_tree();
-}
-#endif
diff --git a/fsck/pass2.c b/fsck/pass2.c
index 023f036..b3a91a1 100644
--- a/fsck/pass2.c
+++ b/fsck/pass2.c
@@ -36,9 +36,7 @@ struct relocated {
struct relocated * relocated_list;
-/* return objectid the object has to be remapped with */
-__u32 objectid_for_relocation (struct key * key)
-{
+__u32 get_relocated_objectid_from_list (struct key * key) {
struct relocated * cur;
cur = relocated_list;
@@ -50,6 +48,17 @@ __u32 objectid_for_relocation (struct key * key)
return cur->new_objectid;
cur = cur->next;
}
+ return 0;
+}
+
+/* return objectid the object has to be remapped with */
+__u32 objectid_for_relocation (struct key * key)
+{
+ struct relocated * cur;
+ __u32 cur_id;
+
+ if ((cur_id = get_relocated_objectid_from_list (key)) != 0)
+ return cur_id;
cur = getmem (sizeof (struct relocated));
cur->old_dir_id = get_key_dirid (key);
@@ -57,16 +66,15 @@ __u32 objectid_for_relocation (struct key * 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, get_key_dirid (key), cur->new_objectid);
+/* fsck_log ("relocation: (%K) is relocated to (%lu, %lu)\n",
+ key, get_key_dirid (key), cur->new_objectid);*/
return cur->new_objectid;
}
/* this item is in tree. All unformatted pointer are correct. Do not
check them */
-static void save_item_2 (struct si ** head, struct item_head * ih,
- char * item, __u32 blocknr)
+void save_item (struct si ** head, struct item_head * ih, char * item, __u32 blocknr)
{
struct si * si, * cur;
@@ -93,7 +101,7 @@ struct si * save_and_delete_file_item (struct si * si, struct path * path)
struct buffer_head * bh = PATH_PLAST_BUFFER (path);
struct item_head * ih = PATH_PITEM_HEAD (path);
- save_item_2 (&si, ih, B_I_PITEM (bh, ih), bh->b_blocknr);
+ save_item (&si, ih, B_I_PITEM (bh, ih), bh->b_blocknr);
/* delete item temporary - do not free unformatted nodes */
reiserfsck_delete_item (path, 1/*temporary*/);
@@ -130,9 +138,6 @@ 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 */
@@ -140,6 +145,21 @@ int should_relocate (struct item_head * ih)
break;
}
+ if (is_stat_data_ih (path_ih)) {
+ fix_obviously_wrong_sd_mode (&path);
+ if (ih_checked (path_ih)) {
+ /* we have checked it already */
+ pathrelse (&path);
+
+ if (get_relocated_objectid_from_list (&path_ih->ih_key))
+ return 1; /* it was relocated */
+ break;
+ } else {
+ mark_ih_checked (path_ih);
+ mark_buffer_dirty (get_bh(&path));
+ }
+ }
+
/* ok, item found, but make sure that it is not a directory one */
if ((is_stat_data_ih (path_ih) && !not_a_directory (get_item (&path))) ||
(is_direntry_ih (path_ih))) {
@@ -155,95 +175,6 @@ int should_relocate (struct item_head * ih)
}
-/* delete all items (but directory ones) with the same key 'ih' has
- (including stat data of not a directory) and put them back at the
- other place */
-void relocate_file (struct item_head * ih, int change_ih)
-{
- struct key key;
- struct key * rkey;
- struct path path;
- struct item_head * path_ih;
- struct si * si;
- __u32 new_objectid;
-
-
- /* starting with the leftmost one - look for all items of file,
- store them and delete */
- key = ih->ih_key;
- set_type_and_offset (KEY_FORMAT_1, &key, SD_OFFSET, TYPE_STAT_DATA);
-
- si = 0;
- while (1) {
- 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)) {
- /* file continues in the right neighbor */
- key = *rkey;
- pathrelse (&path);
- continue;
- }
- /* there is no more items with this key */
- pathrelse (&path);
- 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 */
- pathrelse (&path);
- break;
- }
-
- /* ok, item found, but make sure that it is not a directory one */
- if ((is_stat_data_ih (path_ih) && !not_a_directory (get_item (&path))) ||
- (is_direntry_ih (path_ih))) {
- /* item of directory found. Leave it in the tree */
- key = path_ih->ih_key;
- set_offset (KEY_FORMAT_1, &key, get_offset (&key) + 1);
- pathrelse (&path);
- continue;
- }
-
- si = save_and_delete_file_item (si, &path);
- }
-
-
- if (si || change_ih) {
- int moved_items;
- struct key old, new;
-
- /* get new objectid for relocation or get objectid with which file
- was relocated already */
- new_objectid = objectid_for_relocation (&ih->ih_key);
- if (change_ih)
- set_key_objectid (&ih->ih_key, new_objectid);
-
- moved_items = 0;
-
- /* put all items removed back into tree */
- while (si) {
- /*fsck_log ("relocate_file: move %H to ", &si->si_ih);*/
- old = si->si_ih.ih_key;
- 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*/);
- si = remove_saved_item (si);
- moved_items ++;
- }
- if (moved_items)
- fsck_log ("relocate_file: %d items of file %K moved to %K\n",
- moved_items, &old, &new);
- }
-}
-
-
/* this works for both new and old stat data */
#define st_mode(sd) le16_to_cpu(((struct stat_data *)(sd))->sd_mode)
@@ -300,12 +231,12 @@ static void put_sd_into_tree (struct item_head * new_ih, char * new_item)
/* new item is a stat data of a directory. So we have to
relocate all items which have the same short key and are of
not a directory */
- relocate_file (new_ih, 0/*do not change new_ih*/);
+ rewrite_file (new_ih, 1, 0/*do not change new_ih*/);
} else {
/* new item is a stat data of something else but directory. If
there are items of directory - we have to relocate the file */
if (should_relocate (new_ih))
- relocate_file (new_ih, 1/*change new_ih*/);
+ rewrite_file (new_ih, 1, 1/*change new_ih*/);
}
/* if we will have to insert item into tree - it is ready */
@@ -322,17 +253,17 @@ static void put_sd_into_tree (struct item_head * new_ih, char * new_item)
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)..",
+ fsck_log ("put_sd_into_tree: Inserting the StatData %K, mode (%M)...",
&(new_ih->ih_key), st_mode (new_item));
if (stat_data_v1 (new_ih)) {
/* sd to be inserted is of V1, where as sd in the tree
is of V2 */
- fsck_log ("found newer in the tree (%M), skip inserting\n",
+ fsck_log ("found newer in the tree, mode (%M), insersion was skipped.\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",
+ fsck_log ("older sd, mode (%M), is replaced with it.\n",
st_mode (get_item (&path)));
reiserfsck_delete_item (&path, 0/*not temporary*/);
@@ -364,7 +295,7 @@ static void put_directory_item_into_tree (struct item_head * comingih, char * it
/* if there are anything with this key but a directory - move it
somewhere else */
- relocate_file (comingih, 0/* do not change ih */);
+ rewrite_file (comingih, 1, 0/* do not change ih */);
deh = (struct reiserfs_de_head *)item;
@@ -373,7 +304,8 @@ static void put_directory_item_into_tree (struct item_head * comingih, char * it
namelen = name_in_entry_length (comingih, deh, i);
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);
+ reiserfs_panic ("put_directory_item_into_tree: The entry (%d) \"%.*s\" of the directory %k has"
+ " badly hashed entry", i, namelen, name, &comingih->ih_key);
asprintf (&buf, "%.*s", namelen, name);
/* 1 for fsck is important: if there is no any items of this
@@ -427,16 +359,13 @@ void insert_item_separately (struct item_head * ih,
char * item, int was_in_tree)
{
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);
+ reiserfs_panic ("insert_item_separately: The item being inserted has the bad key %H", ih);
if (is_stat_data_ih (ih)) {
put_sd_into_tree (ih, item);
} else if (is_direntry_ih (ih)) {
put_directory_item_into_tree (ih, item);
} else {
- if (!was_in_tree && should_relocate (ih))
- relocate_file (ih, 1/*change new_ih*/);
-
reiserfsck_file_write (ih, item, was_in_tree);
}
}
@@ -498,8 +427,8 @@ static void save_pass_2_result (reiserfs_filsys_t * fs)
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));
+ fsck_progress ("%s: Could not rename the temporary file temp_fsck_file.deleteme to %s",
+ __FUNCTION__, state_dump_file (fs));
}
@@ -537,36 +466,36 @@ static void do_pass_2 (reiserfs_filsys_t * fs) {
if (!total)
return;
- fsck_progress ("\nPass2:\n");
+ fsck_progress ("\nPass 2:\n");
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",
+ fsck_log ("pass_2: Reading of the block (%lu) failed on the device 0x%x\n",
j, fs->fs_dev);
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);
+ fsck_log ("%s: The block (%lu) is in the tree already. Should not happen.\n",
+ __FUNCTION__, 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);
+ fsck_log ("%s: The block (%b), marked as a leaf on the first two passes, is not a leaf! Will be skipped.\n",
+ __FUNCTION__, bh);
goto next;
}
-
-
-// fsck_log ("block %lu is being inserted\n", bh->b_blocknr);
-// fflush(fsck_log_file (fs));
-
+/*
+ fsck_log ("block %lu is being inserted\n", bh->b_blocknr);
+ check_buffers_mem(fsck_log_file (fs));
+ fflush(fsck_log_file (fs));
+*/
if (i) {
/* insert all not SD items */
put_not_stat_data_items (bh);
@@ -606,10 +535,11 @@ static void after_pass_2 (reiserfs_filsys_t * fs)
/* 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");
+/* if (reiserfs_bitmap_compare (fsck_allocable_bitmap (fs), fsck_new_bitmap(fs))) {
+ fsck_log ("Allocable bitmap differs from the 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);
@@ -621,12 +551,12 @@ static void after_pass_2 (reiserfs_filsys_t * fs)
fs->fs_dirt = 1;
reiserfs_flush_to_ondisk_bitmap (fs->fs_bitmap2, fs);
reiserfs_flush (fs);
- fsck_progress ("done\n");
+ fsck_progress ("finished\n");
/* fixme: should be optional */
/* fsck_progress ("Tree is built. Checking it - ");
reiserfsck_check_pass1 ();
- fsck_progress ("done\n");*/
+ fsck_progress ("finished\n");*/
stage_report (2, fs);
@@ -653,7 +583,7 @@ static void after_pass_2 (reiserfs_filsys_t * fs)
"###########\n", ctime (&t));
fs->fs_dirt = 1;
reiserfs_close (fs);
- exit (4);
+ exit(0);
}
@@ -670,7 +600,7 @@ void pass_2 (reiserfs_filsys_t * fs)
do_pass_2 (fs);
after_pass_2 (fs);
-
+
if (get_sb_root_block (fs->fs_ondisk_sb) == -1)
die ("\n\nNo reiserfs metadata found");
}
diff --git a/fsck/pass4.c b/fsck/pass4.c
index a724517..da90257 100644
--- a/fsck/pass4.c
+++ b/fsck/pass4.c
@@ -3,30 +3,6 @@
*/
#include "fsck.h"
-/*
-void get_next_key (struct path * path, int i, struct key * key)
-{
- struct buffer_head * bh = PATH_PLAST_BUFFER (path);
- struct key * rkey;
-
-
- if (i < B_NR_ITEMS (bh) - 1) {
- // 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
- copy_key (key, rkey);
- } else {
- // there is no next item
- memset (key, 0xff, KEY_SIZE);
- }
-}
-*/
-
void pass_4_check_unaccessed_items (void)
{
struct key key;
@@ -51,8 +27,6 @@ void pass_4_check_unaccessed_items (void)
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)) {
PATH_LAST_POSITION (&path) = i;
rdkey = get_next_key_2 (&path);
@@ -67,6 +41,12 @@ void pass_4_check_unaccessed_items (void)
goto cont;
}
+
+ if (get_ih_flags(ih) != 0) {
+ clean_ih_flags(ih);
+ mark_buffer_dirty(bh);
+ }
+
}
PATH_LAST_POSITION(&path) = i - 1;
rdkey = reiserfs_next_key (&path);
@@ -82,7 +62,7 @@ void pass_4_check_unaccessed_items (void)
pathrelse (&path);
- fsck_progress ("done\n");
+ fsck_progress ("finished\n");
stage_report (4, fs);
/* after pass 4 */
@@ -100,6 +80,8 @@ void pass_4_check_unaccessed_items (void)
flush_objectid_map (proper_id_map (fs), fs);
reiserfs_flush_to_ondisk_bitmap (fs->fs_bitmap2, fs);
reiserfs_flush (fs);
- fsck_progress ("done\n");
+ fsck_progress ("finished\n");
+
+
return;
}
diff --git a/fsck/reiserfsck.8 b/fsck/reiserfsck.8
index 5a8bdd7..a57cd8f 100644
--- a/fsck/reiserfsck.8
+++ b/fsck/reiserfsck.8
@@ -1,7 +1,7 @@
.\" -*- nroff -*-
.\" Copyright 1996-2002 Hans Reiser.
.\"
-.TH REISERFSCK 8 "January 2002" "Reiserfsprogs-3.6.2"
+.TH REISERFSCK 8 "January 2002" "Reiserfsprogs-3.6.4"
.SH NAME
reiserfsck \- check a Linux Reiserfs file system
.SH SYNOPSIS
@@ -142,6 +142,19 @@ the whole partition before proceeding. Then run \fBreiserfsck --rebuild-tree
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 EXIT CODES
+\freiserfsck\fR uses the following exit codes:
+.br
+\ 0\ \-\ No errors.
+.br
+\ 1\ \-\ Errors found, \fresierfsck\fR \fB--fix-fixable\fR needs to be launched.
+.br
+\ 2\ \-\ Errors found, \fresierfsck\fR \fB--rebuild-tree\fR needs to be launched.
+.br
+\ 8\ \-\ Operational error.
+.br
+\ 16\ \-\ Usage or syntax error.
+.br
.SH AUTHOR
This version of \fBreiserfsck\fR has been written by Vitaly Fertman <vitaly@namesys.com>
and Vladimir Saveliev <vs@namesys.com>.
diff --git a/fsck/semantic_check.c b/fsck/semantic_check.c
index 47b9f2d..8034439 100644
--- a/fsck/semantic_check.c
+++ b/fsck/semantic_check.c
@@ -3,12 +3,15 @@
*/
#include "fsck.h"
+static struct key *trunc_links = NULL;
+static __u32 links_num = 0;
+
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_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,
+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);
@@ -36,7 +39,7 @@ static int check_path_key(struct key * key)
while(cur != NULL)
{
if (!comp_short_keys(&cur->key, key)) {
- fsck_log("\nsemantic check: directory %k has 2 names ", key);
+ fsck_log("\nsemantic check: The directory %k has 2 names.", key);
return LOOP_FOUND;
}
cur = cur->next;
@@ -44,9 +47,9 @@ static int check_path_key(struct key * key)
return 0;
}
-static int add_path_key(struct key * key, int check)
+static int add_path_key(struct key * key)
{
- if (check && check_path_key(key))
+ if (check_path_key(key))
return LOOP_FOUND;
if (tail_key == NULL)
@@ -68,7 +71,7 @@ static int add_path_key(struct key * key, int check)
void del_path_key()
{
if (tail_key == NULL)
- die("wrong path_key structure");
+ die("Wrong path_key structure");
if (tail_key->prev == NULL)
{
@@ -90,15 +93,16 @@ static int check_check_regular_file (struct path * path, void * sd,
// 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;
+ __u64 real_size, sd_size;
+ __u32 blocks, sd_blocks; /* proper values and value in stat data */
+ __u32 first_direct_byte, sd_first_direct_byte;
struct buffer_head * bh;
struct item_head * ih, sd_ih;
int fix_sd;
int symlnk = 0;
int retval = OK;
+ __u32 tmp_position;
ih = get_ih (path);
@@ -108,12 +112,13 @@ static int check_check_regular_file (struct path * path, void * sd,
/* this objectid is used already */
*new_ih = *ih;
pathrelse (path);
- relocate_file (new_ih, 1);
+ rewrite_file (new_ih, 1, 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");
+ reiserfs_panic ("check_check_regular_file: Could not find a StatData of "
+ "the relocated file %K", &new_ih->ih_key);
/* stat data is marked unreachable again due to relocation, fix that */
ih = get_ih (path);
bh = get_bh (path);
@@ -129,11 +134,12 @@ static int check_check_regular_file (struct path * path, void * sd,
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);
-
+ get_sd_size (ih, sd, &sd_size);
+ get_sd_blocks (ih, sd, &sd_blocks);
+
+/*
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
- /* check and set nlink first */
+ // check and set nlink first
nlink ++;
set_sd_nlink (ih, sd, &nlink);
mark_buffer_dirty (bh);
@@ -141,9 +147,10 @@ static int check_check_regular_file (struct path * path, void * sd,
if (nlink > 1)
return OK;
}
-
+*/
+
if (!is_new_file)
- get_sd_first_direct_byte (ih, sd, &saved_first_direct_byte);
+ get_sd_first_direct_byte (ih, sd, &sd_first_direct_byte);
if (S_ISLNK (mode))
symlnk = 1;
@@ -152,27 +159,38 @@ static int check_check_regular_file (struct path * path, void * sd,
// 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) {
+ if (are_file_items_correct (&sd_ih, sd, &real_size, &blocks, 0/* do not mark reachable */,
+ &symlnk) != 1)
+ {
one_more_corruption (fs, fatal);
- fsck_log ("check_regular_file: broken file found %K\n", &sd_ih.ih_key);
+ fsck_log ("check_regular_file: The file %K with the corrupted structure found\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*/);
+ &first_direct_byte, sd_first_direct_byte, real_size);
+
+ if (reiserfs_bin_search(&sd_ih.ih_key, trunc_links, links_num, sizeof(sd_ih.ih_key),
+ &tmp_position, comp_short_keys) != POSITION_FOUND)
+ {
+ 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, sd_size, 0/*not dir*/);
+ } else {
+ real_size = sd_size;
+ }
- fix_sd += wrong_st_blocks (&sd_ih.ih_key, &blocks, saved_blocks, mode, is_new_file);
+ fix_sd += wrong_st_blocks (&sd_ih.ih_key, &blocks, sd_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");
+ fsck_log ("check_regular_file: A StatData of the file %K cannot be "
+ "found\n", &sd_ih.ih_key);
one_more_corruption (fs, fatal);
return STAT_DATA_NOT_FOUND;
}
@@ -195,12 +213,9 @@ static int check_check_regular_file (struct path * path, void * sd,
}
/* 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)
+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, __u32 * pos_in_item, int dir_format)
{
INITIALIZE_PATH (path);
char * dir_item;
@@ -216,7 +231,8 @@ 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);
+ reiserfs_panic ("get_next_directory_item: The current directory %k cannot be found",
+ key);
/* leaf containing directory item */
bh = PATH_PLAST_BUFFER (&path);
@@ -229,15 +245,15 @@ start_again:
(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");
+ fsck_log ("get_next_directory_item: The %s %k cannot be found in %k",
+ (retval == POSITION_NOT_FOUND) ? "entry" : "directory", key, &ih->ih_key);
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");
+ fsck_log (" - entry was added\n");
goto start_again;
} else {
one_more_corruption (fs, fixable);
@@ -278,13 +294,14 @@ start_again:
/* "." 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)));
+ fsck_log ("get_next_directory_item: The entry \".\" of the directory %K "
+ "pointes to %K, instead of %K", key, (struct key *)(&(deh->deh2_dir_id)),
+ key);
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");
+ fsck_log (" - corrected\n");
} else
fsck_log ("\n");
}
@@ -293,13 +310,13 @@ start_again:
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);
+ fsck_log ("get_next_directory_item: The entry \"..\" of the directory %K "
+ "pointes to %K, instead of %K", key, (struct key *)(&(deh->deh2_dir_id)));
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");
+ fsck_log (" - corrected\n");
} else
fsck_log ("\n");
}
@@ -328,7 +345,8 @@ start_again:
}
/* semantic pass of --check */
-static int check_semantic_pass (struct key * key, struct key * parent, int dot_dot, struct item_head * new_ih)
+static int check_semantic_pass (struct key * key, struct key * parent, int dot_dot,
+ struct item_head * new_ih)
{
struct path path;
void * sd;
@@ -343,8 +361,8 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
struct key next_item_key, entry_key, object_key;
__u64 dir_size = 0;
__u32 blocks;
- __u64 saved_size;
- __u32 saved_blocks;
+ __u64 sd_size;
+ __u32 sd_blocks;
int fix_sd;
int relocate;
int dir_format = 0;
@@ -355,7 +373,7 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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");
+ fsck_log ("check_semantic_pass: The key %k must be key of a StatData\n", key);
one_more_corruption (fs, fatal);
return STAT_DATA_NOT_FOUND;
}
@@ -377,18 +395,25 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
one_more_corruption (fs, fixable);
return OK;
}
-
+
+ if (nlink == 0) {
+ fsck_log ("%s: block %lu: The StatData %k has bad nlink number (%u)\n",
+ __FUNCTION__, get_bh(&path)->b_blocknr, &ih->ih_key, nlink);
+ one_more_corruption (fs, fatal);
+ }
+
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);
+ reiserfs_panic ("check_semantic_pass: Memory is not prepared for relocation of "
+ "%K", &ih->ih_key);
*new_ih = *ih;
pathrelse (&path);
sem_pass_stat (fs)->oid_sharing_dirs_relocated ++;
@@ -398,25 +423,26 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
retval = RELOCATED;
goto start_again;
}
-
+
+
+/*
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
- /* it looks like stat data of a directory found */
+ // it looks like stat data of a directory found
if (nlink) {
- /* we saw this directory already */
+ // we saw this directory already
if (!dot_dot) {
- /* this name is not ".." - and hard links are not allowed on
- directories */
+ // this name is not ".." - and hard links are not allowed on directories
pathrelse (&path);
return STAT_DATA_NOT_FOUND;
} else {
- /* ".." found */
+ // ".." 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*/
+ } // do not run it for dot_dot on check at all
nlink = 2;
if (get_key_objectid (key) == REISERFS_ROOT_OBJECTID)
@@ -424,7 +450,8 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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;
@@ -432,8 +459,8 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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_size (ih, sd, &sd_size);
+ get_sd_blocks (ih, sd, &sd_blocks);
get_sd_mode (ih, sd, &mode);
dir_format = (get_ih_item_len (get_ih (&path)) == SD_SIZE) ? KEY_FORMAT_2 : KEY_FORMAT_1;
@@ -449,7 +476,9 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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) {
+ 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;
@@ -475,14 +504,17 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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));
+ fsck_log ("Entry %K (\"%.*s\") in the directory %K is not formated "
+ "properly - deleted\n", (struct key *)&(deh->deh2_dir_id),
+ namelen, name, &tmp_ih.ih_key);
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);
+ 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));
+ fsck_log ("Entry %K (\"%.*s\") in the directory %K is not formated "
+ "properly.\n", (struct key *)&(deh->deh2_dir_id), namelen, name,
+ &tmp_ih.ih_key);
one_more_corruption (fs, fixable);
}
}
@@ -492,16 +524,17 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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);
+ fsck_log ("check_semantic_pass: Hash mismatch detected for (%.*s) in "
+ "directory %K\n", namelen, name, &tmp_ih.ih_key);
}
- 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))) {
+ if (is_dot (name, namelen) || (is_dot_dot (name, namelen))) {
/* 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);
+ if ((retval = add_path_key (&object_key)) == 0) {
+ retval = check_semantic_pass (&object_key, key,
+ is_dot_dot(name, namelen), &relocated_ih);
del_path_key ();
}
}
@@ -515,8 +548,8 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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);
+ fsck_log ("check_semantic_pass: Name \"%.*s\" in directory %K points to "
+ "nowhere\n", namelen, name, &tmp_ih.ih_key);
case LOOP_FOUND:
if (fsck_mode (fs) == FSCK_FIX_FIXABLE) {
reiserfs_remove_entry (fs, &entry_key);
@@ -528,8 +561,8 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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);
+ fsck_log ("check_semantic_pass: Name \"%.*s\" in directory %K points a "
+ "directory without body\n", namelen, name, &tmp_ih.ih_key);
/* fixme: stat data should be deleted as well */
/*
@@ -544,18 +577,19 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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");
+ fsck_log("Cannot find a name of the relocated file %K in the directory "
+ "%K\n", &entry_key, &tmp_ih.ih_key);
} 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);
+ fsck_log ("The directory %K pointing to %K (\"%.*s\") updated to point "
+ "to ", &tmp_ih.ih_key, &tmp_deh->deh2_dir_id, namelen, name);
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);
+ fsck_log ("%K (\"%.*s\")\n", &tmp_deh->deh2_dir_id, namelen, name);
mark_buffer_dirty (get_bh (&path));
}
dir_size += DEH_SIZE + entry_len;
@@ -583,15 +617,16 @@ static int check_semantic_pass (struct key * key, struct key * parent, int dot_d
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_blocks (key, &blocks, sd_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*/);
+ fs->fs_blocksize, &dir_size, sd_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");
+ fsck_log ("check_semantic_tree: The StatData of the file %K was not found\n",
+ key);
one_more_corruption(fs, fatal);
return STAT_DATA_NOT_FOUND;
}
@@ -626,7 +661,9 @@ int check_safe_links ()
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)) {
+ if (get_blkh_nr_items ( B_BLK_HEAD (get_bh(&safe_link_path))) <=
+ PATH_LAST_POSITION (&safe_link_path))
+ {
pathrelse (&safe_link_path);
break;
}
@@ -640,7 +677,8 @@ int check_safe_links ()
}
if (get_ih_item_len (tmp_ih) != 4)
- reiserfs_panic ("safe link cannot be of size %d", get_ih_item_len (tmp_ih));
+ reiserfs_panic ("Safe Link %k cannot be of the size %d",
+ &tmp_ih->ih_key, 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));
@@ -652,29 +690,44 @@ int check_safe_links ()
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);
+ fsck_log ("Invalid safe link %k: cannot find the pointed object (%K)\n",
+ &tmp_ih->ih_key, &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);
+ fsck_log ("Invalid safe link %k: cannot find the pointed object (%K) - "
+ "safe link was deleted\n", &tmp_ih->ih_key, &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) {
+ /* Truncate */
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);
+ fsck_log ("Invalid 'truncate' safe link %k, cannot happen for "
+ "directory (%K)\n", &tmp_ih->ih_key, &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);
+ fsck_log ("Invalid 'truncate' safe link %k, cannot happen for "
+ "a directory (%K) - safe link was deleted\n", &tmp_ih->ih_key, &key);
*(__u32 *)get_item(&safe_link_path) = (__u32)0;
pathrelse (&path);
reiserfsck_delete_item (&safe_link_path, 0);
continue;
}
+ } else {
+ /* save 'safe truncate links' to avoid swaring on wrong sizes. */
+ __u32 position;
+
+ if (reiserfs_bin_search (&key, trunc_links, links_num, sizeof(key),
+ &position, comp_short_keys) != POSITION_FOUND)
+ {
+ blocklist__insert_in_position(&key, (void **)&trunc_links, &links_num,
+ sizeof(key), &position);
+ }
}
}
pathrelse (&path);
@@ -684,48 +737,59 @@ int check_safe_links ()
return OK;
}
+void release_safe_links () {
+ freemem(trunc_links);
+}
+
/* 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;
+ goto clean;
}
if (fsck_data (fs)->check.fatal_corruptions) {
fsck_progress ("Fatal corruptions were found, Semantic pass skipped\n");
- return;
+ goto clean;
}
-
-
- fsck_progress ("Checking Semantic tree...\n");
+
+ 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));
+ 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));
+ 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;
}
+ check_safe_links ();
+
if (check_semantic_pass (&root_dir_key, &parent_root_dir_key, 0, 0) != OK) {
- fsck_log ("check_semantic_tree: no root directory found");
+ fsck_log ("check_semantic_tree: No root directory found");
one_more_corruption (fs, fatal);
}
- check_safe_links ();
+ release_safe_links ();
if (fsck_mode(fs) == FSCK_FIX_FIXABLE) {
reiserfs_delete_bitmap (fs->fs_bitmap2);
+ reiserfs_bitmap_delta (fsck_new_bitmap (fs), fsck_deallocate_bitmap (fs));
fs->fs_bitmap2 = fsck_new_bitmap (fs);
- reiserfs_delete_bitmap (fsck_allocable_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");
+ fsck_progress ("finished\n");
+
+clean:
+ if (fsck_deallocate_bitmap (fs))
+ reiserfs_delete_bitmap (fsck_deallocate_bitmap (fs));
}
diff --git a/fsck/semantic_rebuild.c b/fsck/semantic_rebuild.c
index 6f58126..a00ce19 100644
--- a/fsck/semantic_rebuild.c
+++ b/fsck/semantic_rebuild.c
@@ -19,9 +19,12 @@ void print_name (char * name, int len)
return;
if ( len + screen_curr_pos + 1 > screen_savebuffer_len) {
- char *t = expandmem(screen_savebuffer, screen_savebuffer_len + 1, len + screen_curr_pos - screen_savebuffer_len + 1);
+ char *t;
+
+ t = expandmem(screen_savebuffer, screen_savebuffer_len + 1,
+ len + screen_curr_pos - screen_savebuffer_len + 1);
if (!t) {
- printf("\nNot enough memory\n");
+ fsck_progress("\nOut of memory\n");
return; // ????
}
screen_savebuffer = t;
@@ -37,7 +40,8 @@ void print_name (char * name, int len)
screen_savebuffer[screen_curr_pos]=0;
if ( screen_width < screen_curr_pos ) {
- printf("\r... %.*s",screen_width - 4, screen_savebuffer + ( screen_curr_pos - (screen_width - 4)));
+ printf("\r... %.*s",screen_width - 4,
+ screen_savebuffer + ( screen_curr_pos - (screen_width - 4)));
} else
printf("/%.*s", len, screen_savebuffer + screen_curr_pos - len);
@@ -66,13 +70,14 @@ void erase_name (int len)
} else {
screen_curr_pos-=len+1;
if (screen_curr_pos < 0 )
- die("semantic_rebuild.c: run out of buffer data in erase_name!\n");
+ die("%s: Get out of buffer's data!\n", __FUNCTION__);
screen_savebuffer[screen_curr_pos]=0;
printf("\r");
if (screen_curr_pos >= screen_width ) {
int t_preface=MIN(screen_curr_pos-screen_width,4);
- printf("%.*s%.*s", t_preface, "... ", screen_width-t_preface - 1, screen_savebuffer + ( screen_curr_pos - (screen_width - t_preface)) + 1);
+ printf("%.*s%.*s", t_preface, "... ", screen_width-t_preface - 1,
+ screen_savebuffer + ( screen_curr_pos - (screen_width - t_preface)) + 1);
} else {
int space_used=printf("%s", screen_savebuffer);
for ( i=space_used; i < screen_width; i++)
@@ -97,8 +102,9 @@ int wrong_st_size (struct key * key, loff_t max_file_size, int blocksize,
if (is_dir) {
/* directory size must match to the sum of length of its entries */
- fsck_log ("dir %K has wrong sd_size %Ld, has to be %Ld\n",
- key, sd_size, *size);
+ fsck_log ("vpf-10650: The directory %K has the wrong size in the StatData "
+ "(%Ld)%s(%Ld)\n", key, sd_size, fsck_mode(fs) == FSCK_CHECK ?
+ ", should be " : " - corrected to ", *size);
return 1;
}
@@ -106,8 +112,8 @@ int wrong_st_size (struct key * key, loff_t max_file_size, int blocksize,
/* size in stat data can be bigger than size calculated by items */
if (fsck_adjust_file_size (fs)) {
/* but it -o is given - fix that */
- fsck_log ("file %K has too big file size sd_size %Ld - fixed to %Ld\n",
- key, sd_size, *size);
+ fsck_log ("vpf-10660: The file %K has too big size in the StatData (%Ld) "
+ "- corrected to (%Ld)\n", key, sd_size, *size);
sem_pass_stat (fs)->fixed_sizes ++;
return 1;
}
@@ -117,7 +123,9 @@ int wrong_st_size (struct key * key, loff_t max_file_size, int blocksize,
if (!(*size % blocksize)) {
/* last item is indirect */
- if (((sd_size & ~(blocksize - 1)) == (*size - blocksize)) && sd_size % blocksize) {
+ if (((sd_size & ~(blocksize - 1)) == (*size - blocksize)) &&
+ sd_size % blocksize)
+ {
/* size in stat data is correct */
*size = sd_size;
return 0;
@@ -134,8 +142,9 @@ int wrong_st_size (struct key * key, loff_t max_file_size, int blocksize,
}
}
- fsck_log ("file %K has wrong sd_size %Ld, has to be %Ld\n",
- key, sd_size, *size);
+ fsck_log ("vpf-10670: The file %K has wrong size in StatData (%Ld)%s(%Ld)\n", key,
+ sd_size, fsck_mode(fs) == FSCK_CHECK ? ", should be " : " - corrected to ",
+ *size);
sem_pass_stat (fs)->fixed_sizes ++;
return 1;
}
@@ -154,20 +163,23 @@ int wrong_st_size (struct key * key, loff_t max_file_size, int blocksize,
| file, dir, link | blocks | generation | blocks |
|------------------------------------------------------------------|
*/
-int wrong_st_blocks (struct key * key, __u32 * blocks, __u32 sd_blocks, __u16 mode, int new_format)
+int wrong_st_blocks (struct key * key, __u32 * blocks, __u32 sd_blocks, __u16 mode,
+ int new_format)
{
int ret = 0;
if (S_ISREG (mode) || S_ISLNK (mode) || S_ISDIR (mode)) {
if (*blocks != sd_blocks) {
- fsck_log ("%s %K has wrong sd_blocks %u, has to be %u\n",
- S_ISDIR (mode) ? "dir" : "file", key, sd_blocks, *blocks);
+ fsck_log ("vpf-10680: The %s %K has the wrong block count in the StatData "
+ "(%u)%s(%u)\n", S_ISDIR (mode) ? "directory" : "file", key, sd_blocks,
+ fsck_mode(fs) == FSCK_CHECK ? ", should be " : " - corrected to ", *blocks);
ret = 1;
}
} else if (new_format || (S_ISFIFO (mode) || S_ISSOCK (mode))) {
if (sd_blocks != 0) {
- fsck_log ("node %K has wrong sd_blocks %u, has to be %u\n",
- key, sd_blocks, 0);
+ fsck_log ("vpf-10690: The object %K has the wrong block count in the StatData "
+ "(%u)%s(%u)\n", key, sd_blocks, fsck_mode(fs) == FSCK_CHECK ?
+ ", should be " : " - corrected to ", 0);
*blocks = 0;
ret = 1;
}
@@ -195,12 +207,14 @@ int wrong_st_rdev (struct key * key, __u32 * sd_rdev, __u16 mode, int new_format
}
*/
/* only regular files and symlinks may have items but stat
- data. Symlink shold have body */
+ data. Symlink should have body */
int wrong_mode (struct key * key, __u16 * mode, __u64 real_size, int symlink)
{
int retval = 0;
if (S_ISLNK (*mode) && !symlink) {
- fsck_log ("file %K (%M) is too big to be symlink - try as regfile\n", key, *mode);
+ fsck_log ("The file %K (%M) is too big to be the symlink%s regfile\n",
+ key, *mode, fsck_mode(fs) == FSCK_CHECK ? ", should be the" : " - corrected "
+ "to the");
*mode &= ~S_IFMT;
*mode |= S_IFREG;
retval = 1;
@@ -217,7 +231,12 @@ int wrong_mode (struct key * key, __u16 * mode, __u64 real_size, int symlink)
}
/* there are items, so change file mode to regular file. Otherwise
- file bodies do not get deleted */
- fsck_log ("file %K (%M) has body, try mode as %M\n", key, *mode, (S_IFREG | 0600));
+ if (fsck_mode(fs) == FSCK_CHECK) {
+ fsck_log ("The object %K has wrong mode (%M)\n", key, *mode);
+ } else {
+ fsck_log("The object %K has wrong mode (%M) - corrected to %M\n",
+ key, *mode, (S_IFREG | 0600));
+ }
*mode = (S_IFREG | 0600);
return 1;
}
@@ -232,8 +251,15 @@ int wrong_first_direct_byte (struct key * key, int blocksize,
/* there is no direct item */
*first_direct_byte = NO_BYTES_IN_DIRECT_ITEM;
if (sd_first_direct_byte != NO_BYTES_IN_DIRECT_ITEM) {
- fsck_log ("%K has no direct items and first direct byte in SD == %d\n",
- key, sd_first_direct_byte);
+ if (fsck_mode(fs) == FSCK_CHECK) {
+ fsck_log ("The file %K: The wrong info about the tail in the StatData, "
+ "first_direct_byte (%d) - should be (%d)\n", key,
+ sd_first_direct_byte, *first_direct_byte);
+ } else {
+ fsck_log ("The file %K: The wrong info about the tail in the StatData, "
+ "first_direct_byte (%d) - corrected to (%d)\n", key,
+ sd_first_direct_byte, *first_direct_byte);
+ }
return 1;
}
return 0;
@@ -242,8 +268,16 @@ int wrong_first_direct_byte (struct key * key, int blocksize,
/* there is direct item */
*first_direct_byte = (get_offset (key) & ~(blocksize - 1)) + 1;
if (*first_direct_byte != sd_first_direct_byte) {
- fsck_log ("file %k has wrong first direct byte in SD (%d), has to be %d\n",
- key, sd_first_direct_byte, *first_direct_byte);
+ if (fsck_mode(fs) == FSCK_CHECK) {
+ fsck_log ("The file %K: The wrong info about the tail in the StatData, "
+ "first_direct_byte (%d) - should be (%d)\n", key, sd_first_direct_byte,
+ *first_direct_byte);
+ } else {
+ fsck_log ("The file %K: The wrong info about the tail in the StatData, "
+ "first_direct_byte (%d) - corrected to (%d)\n", key, sd_first_direct_byte,
+ *first_direct_byte);
+ }
+
return 1;
}
return 0;
@@ -262,7 +296,6 @@ void relocate_dir (struct item_head * ih, int change_ih)
struct si * si;
__u32 new_objectid;
-
/* starting with the leftmost one - look for all items of file,
store them and delete */
key = ih->ih_key;
@@ -312,7 +345,7 @@ void relocate_dir (struct item_head * ih, int change_ih)
if (!si) {
- fsck_progress ("relocate_dir: no directory %K items found\n", &key);
+ fsck_log ("relocate_dir: WARNING: No one item of the directory %K found\n", &key);
return;
}
@@ -324,9 +357,9 @@ void relocate_dir (struct item_head * ih, int change_ih)
/* put all items removed back into tree */
while (si) {
- fsck_log ("relocate_dir: move %H to ", &si->si_ih);
+ fsck_log ("relocate_dir: Moving %k to ", &si->si_ih.ih_key);
set_key_objectid (&si->si_ih.ih_key, new_objectid);
- fsck_log ("%H\n", &si->si_ih);
+ fsck_log ("%k\n", &si->si_ih.ih_key);
if (get_offset (&(si->si_ih.ih_key)) == DOT_OFFSET) {
/* fix "." entry to point to a directtory properly */
struct reiserfs_de_head * deh;
@@ -370,11 +403,12 @@ int rebuild_check_regular_file (struct path * path, void * sd,
/* this objectid is used already */
*new_ih = *ih;
pathrelse (path);
- relocate_file (new_ih, 1);
+ rewrite_file (new_ih, 1, 1);
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 ("rebuild_check_regular_file: could not find stat data of relocated file");
+ reiserfs_panic ("%s: Could not find the StatData of the relocated file %k",
+ __FUNCTION__, &(new_ih->ih_key));
/* stat data is marked unreachable again due to relocation, fix that */
ih = get_ih (path);
bh = get_bh (path);
@@ -440,7 +474,7 @@ int rebuild_check_regular_file (struct path * path, void * sd,
/* 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)
- die ("rebuild_check_regular_file: stat data not found");
+ reiserfs_panic ("%s: The StatData of the file %k could not be found", __FUNCTION__, &sd_ih.ih_key);
bh = get_bh (path);
ih = get_ih (path);
@@ -483,7 +517,7 @@ static char * get_next_directory_item (struct key * key, /* on return this will
if ((retval = reiserfs_search_by_entry_key (fs, key, &path)) != POSITION_FOUND)
- reiserfs_panic ("get_next_directory_item: %k is not found", key);
+ reiserfs_panic ("get_next_directory_item: The current directory %k cannot be found", key);
/* leaf containing directory item */
bh = PATH_PLAST_BUFFER (&path);
@@ -497,7 +531,7 @@ static char * get_next_directory_item (struct key * key, /* on return this will
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);
+ fsck_log ("get_next_directory_item: The entry \"..\" cannot be found in %k\n", &ih->ih_key);
pathrelse (&path);
return 0;
}
@@ -520,24 +554,24 @@ static char * get_next_directory_item (struct key * key, /* on return this will
/* "." 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)));
+ fsck_log ("get_next_directory_item: The entry \".\" of the directory %K pointes to %K, instead of %K",
+ key, (struct key *)(&(deh->deh2_dir_id)), key);
set_deh_dirid (deh, get_key_dirid (key));
set_deh_objectid (deh, get_key_objectid (key));
mark_buffer_dirty (bh);
- fsck_log (" - fixed\n");
+ fsck_log (" - corrected\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: \"..\" points to [%K], "
- "should point to [%K]", key, (struct key *)(&(deh->deh2_dir_id)), parent);
+ fsck_log ("get_next_directory_item: The entry \"..\" of the directory %K pointes to %K, instead of %K",
+ key, (struct key *)(&(deh->deh2_dir_id)), parent);
set_deh_dirid (deh, get_key_dirid (parent));
set_deh_objectid (deh, get_key_objectid (parent));
mark_buffer_dirty (bh);
- fsck_log (" - fixed\n");
+ fsck_log (" - corrected\n");
}
}
}
@@ -596,26 +630,32 @@ int fix_obviously_wrong_sd_mode (struct path * path) {
if (not_a_directory (get_item (path)) && is_direntry_key (next_key)) {
/* make SD mode SD of dir */
get_sd_mode (get_ih (path), get_item (path), &mode);
- fsck_log ("directory %K had broken mode %M, ", &get_ih(path)->ih_key, mode);
+ fsck_log ("The directory %K had wrong mode %M", &get_ih(path)->ih_key, mode);
+
if (fsck_mode(fs) != FSCK_CHECK) {
mode &= ~S_IFMT;
mode |= S_IFDIR;
- fsck_log ("fixed to %M\n", mode);
+ fsck_log (" - corrected to %M\n", mode);
set_sd_mode (get_ih (path), get_item (path), &mode);
mark_buffer_dirty (get_bh(path));
+ } else {
+ fsck_log ("\n");
}
retval = 1;
} else if (!not_a_directory (get_item (path)) && !is_direntry_key (next_key)) {
/* make SD mode SD of regular file */
get_sd_mode (get_ih (path), get_item (path), &mode);
- fsck_log ("file %K had broken mode %M, ", &get_ih(path)->ih_key, mode);
+ fsck_log ("The file %K had wrong mode %M", &get_ih(path)->ih_key, mode);
if (fsck_mode(fs) != FSCK_CHECK) {
mode &= ~S_IFMT;
mode |= S_IFREG;
- fsck_log ("fixed to %M\n", mode);
+ fsck_log (" - corrected to %M\n", mode);
set_sd_mode (get_ih (path), get_item (path), &mode);
mark_buffer_dirty (get_bh(path));
+ } else {
+ fsck_log ("\n");
}
+
retval = 1;
}
@@ -655,15 +695,14 @@ int rebuild_semantic_pass (struct key * key, struct key * parent, int dot_dot,
start_again: /* when directory was relocated */
if (!KEY_IS_STAT_DATA_KEY (key))
- reiserfs_panic ("rebuild_semantic_pass: key %k must be key of a stat data",
- key);
+ reiserfs_panic ("rebuild_semantic_pass: The key %k must be key of a StatData", key);
/* look for stat data of an object */
if (reiserfs_search_by_key_4 (fs, key, &path) == ITEM_NOT_FOUND) {
pathrelse (&path);
if (is_rootdir_key (key))
/* root directory has to exist at this point */
- reiserfs_panic ("rebuild_semantic_pass: root directory not found");
+ reiserfs_panic ("rebuild_semantic_pass: The root directory StatData was not found");
return STAT_DATA_NOT_FOUND;
}
@@ -703,8 +742,7 @@ int rebuild_semantic_pass (struct key * key, struct key * parent, int dot_dot,
if (relocate) {
if (!new_ih)
- reiserfs_panic ("rebuild_semantic_pass: can not relocate %K",
- &ih->ih_key);
+ reiserfs_panic ("rebuild_semantic_pass: Memory is not prepared for relocation of %K", &ih->ih_key);
*new_ih = *ih;
pathrelse (&path);
sem_pass_stat (fs)->oid_sharing_dirs_relocated ++;
@@ -821,8 +859,8 @@ int rebuild_semantic_pass (struct key * key, struct key * parent, int dot_dot,
if ((dir_format == KEY_FORMAT_2) && (entry_len % 8 != 0)) {
/* not alighed directory of new format - delete it */
- fsck_log ("name \"%.*s\" in directory %K of wrong format, %K - fixed\n",
- namelen, name, &tmp_ih.ih_key, (struct key *)&(deh->deh2_dir_id));
+ fsck_log ("Entry %K (\"%.*s\") in the directory %K is not formated properly - deleted\n",
+ (struct key *)&(deh->deh2_dir_id), namelen, name, &tmp_ih.ih_key);
reiserfs_remove_entry (fs, &entry_key);
entry_len = name_length (name, dir_format);
reiserfs_add_entry (fs, key, name, entry_len,
@@ -831,8 +869,8 @@ int rebuild_semantic_pass (struct key * key, struct key * parent, int dot_dot,
/*
if ((dir_format == KEY_FORMAT_1) && (namelen != entry_len)) {
// aligned entry in directory of old format - remove and insert it back
- fsck_log ("name \"%.*s\" in directory %K of wrong format, %K - fixed\n",
- namelen, name, &tmp_ih.ih_key, (struct key *)&(deh->deh2_dir_id));
+ fsck_log ("Entry %K (\"%.*s\") in the directory %K is not formated properly - deleted\n",
+ (struct key *)&(deh->deh2_dir_id), namelen, name, &tmp_ih.ih_key);
reiserfs_remove_entry (fs, &entry_key);
entry_len = name_length (name, dir_format);
reiserfs_add_entry (fs, key, name, entry_len,
@@ -847,7 +885,8 @@ int rebuild_semantic_pass (struct key * key, struct key * parent, int dot_dot,
print_name (name, namelen);
if (!is_properly_hashed (fs, name, namelen, get_deh_offset (deh)))
- reiserfs_panic ("rebuild_semantic_pass: name has to be hashed properly");
+ reiserfs_panic ("rebuild_semantic_pass: Hash mismatch detected for (\"%.*s\") in directory %K\n",
+ namelen, name, &tmp_ih.ih_key);
retval1 = rebuild_semantic_pass (&object_key, key, is_dot_dot (name, namelen), &relocated_ih);
@@ -867,8 +906,8 @@ int rebuild_semantic_pass (struct key * key, struct key * parent, int dot_dot,
dir_size += DEH_SIZE + entry_len;
continue;
}
- fsck_log ("name \"%.*s\" in directory %K points to nowhere %K - removed\n",
- namelen, name, &tmp_ih.ih_key, (struct key *)&(deh->deh2_dir_id));
+ fsck_log ("%s: The entry %K (\"%.*s\") in directory %K points to nowhere - is removed\n",
+ __FUNCTION__, &object_key, namelen, name, &tmp_ih.ih_key);
reiserfs_remove_entry (fs, &entry_key);
sem_pass_stat (fs)->deleted_entries ++;
break;
@@ -876,14 +915,15 @@ int rebuild_semantic_pass (struct key * key, struct key * parent, int dot_dot,
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");
+ fsck_log ("WARNING: Cannot find the name of the relocated file %K in the directory %K\n",
+ &object_key, &tmp_ih.ih_key);
} 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);
+ fsck_log ("The entry %K (\"%.*s\") in directory %K updated to point to ",
+ &object_key, namelen, name, &tmp_ih.ih_key);
set_deh_dirid (tmp_deh, get_key_dirid (&relocated_ih.ih_key));
set_deh_objectid (tmp_deh, get_key_objectid (&relocated_ih.ih_key));
@@ -922,7 +962,7 @@ int rebuild_semantic_pass (struct key * key, struct key * parent, int dot_dot,
if (fix_sd) {
/* 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)
- die ("rebuild_semantic_pass: stat data not found");
+ reiserfs_panic ("rebuild_semantic_pass: The StatData of the file %K was not found", key);
bh = get_bh (&path);
ih = get_ih (&path);
@@ -975,13 +1015,13 @@ void zero_nlink (struct item_head * ih, void * sd)
int zero = 0;
if (get_ih_item_len (ih) == SD_V1_SIZE && get_ih_key_format (ih) != KEY_FORMAT_1) {
- fsck_log ("zero_nlink: %H had wrong keys format %d, fixed to %d",
- ih, get_ih_key_format (ih), KEY_FORMAT_1);
+ fsck_log ("zero_nlink: The StatData %k of the wrong format version (%d) - corrected to (%d)\n",
+ ih, get_ih_key_format (ih), KEY_FORMAT_1);
set_ih_key_format (ih, KEY_FORMAT_1);
}
if (get_ih_item_len (ih) == SD_SIZE && get_ih_key_format (ih) != KEY_FORMAT_2) {
- fsck_log ("zero_nlink: %H had wrong keys format %d, fixed to %d",
- ih, get_ih_key_format (ih), KEY_FORMAT_2);
+ fsck_log ("zero_nlink: The StatData %k of the wrong format version (%d) - corrected to (%d)\n",
+ ih, get_ih_key_format (ih), KEY_FORMAT_2);
set_ih_key_format (ih, KEY_FORMAT_2);
}
@@ -1019,8 +1059,8 @@ static void make_sure_lost_found_exists (reiserfs_filsys_t * fs)
if (!retval) {
objectid = get_unused_objectid (fs);
if (!objectid) {
- fsck_progress ("make_sure_lost_found_exists: could not get objectid"
- " for \"/lost+found\", will not link lost files\n");
+ fsck_progress ("Could not allocate an objectid for \"/lost+found\", \
+ lost files will not be linked\n");
return;
}
set_key_dirid (&lost_found_dir_key, REISERFS_ROOT_OBJECTID);
@@ -1041,8 +1081,8 @@ static void make_sure_lost_found_exists (reiserfs_filsys_t * fs)
fix_obviously_wrong_sd_mode (&path);
if (not_a_directory (get_item (&path))) {
- fsck_progress ("make_sure_lost_found_exists: \"/lost+found\" is "
- "not a directory, will not link lost files\n");
+ fsck_progress ("\"/lost+found\" exists, but it is not a directory, \
+ lost files will not be linked\n");
set_key_objectid (&lost_found_dir_key, 0);
pathrelse (&path);
return;
@@ -1064,7 +1104,7 @@ static void make_sure_lost_found_exists (reiserfs_filsys_t * fs)
if (item_len) {
if (reiserfs_search_by_key_4 (fs, &root_dir_key, &path) == ITEM_NOT_FOUND)
- reiserfs_panic ("make_sure_lost_found_exists: root sd must exists");
+ reiserfs_panic ("%s: StatData of the root directory must exists", __FUNCTION__);
bh = get_bh (&path);
ih = get_ih (&path);
@@ -1082,12 +1122,12 @@ static void make_sure_lost_found_exists (reiserfs_filsys_t * fs)
return;
}
+/* Result of the rebuild pass will be saved in the state file which is needed to start
+ * fsck again from the next pass. */
static void save_rebuild_semantic_result (reiserfs_filsys_t * fs) {
FILE * file;
int retval;
- /* save bitmaps with which we will be able start reiserfs from
- pass 1 */
file = open_file ("temp_fsck_file.deleteme", "w+");
if (!file)
return;
@@ -1099,8 +1139,8 @@ static void save_rebuild_semantic_result (reiserfs_filsys_t * fs) {
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));
+ fsck_progress ("%s: Could not rename the temporary file temp_fsck_file.deleteme to %s",
+ __FUNCTION__, state_dump_file (fs));
}
/* we have nothing to load from a state file, but we have to fetch
@@ -1140,7 +1180,7 @@ static void after_pass_3 (reiserfs_filsys_t * fs)
fs->fs_dirt = 1;
reiserfs_flush_to_ondisk_bitmap (fsck_new_bitmap(fs), fs);
reiserfs_flush (fs);
- fsck_progress ("done\n");
+ fsck_progress ("finished\n");
stage_report (3, fs);
@@ -1157,7 +1197,7 @@ static void after_pass_3 (reiserfs_filsys_t * fs)
fs->fs_dirt = 1;
reiserfs_close (fs);
- exit (4);
+ exit(0);
}
/* this is part of rebuild tree */
diff --git a/fsck/super.c b/fsck/super.c
index c4d4f91..4bb4f2e 100644
--- a/fsck/super.c
+++ b/fsck/super.c
@@ -24,6 +24,142 @@ int what_fs_version ()
return version;
}
+#define super_error(exit_code, text) { \
+ fsck_log(text); \
+ return exit_code; \
+}
+
+/*
+int check_sb (reiserfs_filsys_t * fs) {
+ int magic = 0, version = 0;
+
+ if (!is_blocksize_correct (fs->fs_blocksize))
+ super_error(-1, "Wrong blocksize found in the super block\n");
+
+ if (is_reiserfs_3_6_magic_string (sb))
+ magic = 2;
+ else if (is_reiserfs_3_5_magic_string (sb))
+ magic = 1;
+ else if (is_reiserfs_jr_magic_string (sb))
+ magic = 3;
+ else
+ super_error(-1, "Invalid magic found in the super block.\n");
+
+ if (magic == 1 || magic == 2) {
+ if (fsck_data (fs)->journal_dev_name)
+ fsck_log("Reiserfs with standard journal found, but there was specified a "
+ "journal dev\n");
+
+ standard_journal = 1;
+ } else {
+ if (!fsck_data (fs)->journal_dev_name)
+ super_error(-1, "Reiserfs with non standard journal found, but there was not "
+ "specified any journal dev\n");
+
+ standard_journal = 0;
+ }
+
+ if (get_sb_version (sb) != REISERFS_FORMAT_3_6 && get_sb_version (sb) != REISERFS_FORMAT_3_5)
+ super_error(-1, "Invalid format found in the super block.\n");
+
+ if (is_new_sb_location(fs->fs_super_bh->b_blocknr, fs->fs_blocksize))
+ {
+ if (magic == 3)
+ version = get_sb_version (sb) == REISERFS_FORMAT_3_6 ? 1 : 2;
+ else
+ version = magic == 2 ? 1 : 2;
+ } else if (is_old_sb_location(fs->fs_super_bh->b_blocknr, fs->fs_blocksize)) {
+ if (magic == 3)
+ version = get_sb_version (sb) == REISERFS_FORMAT_3_6 ? 3 : 4;
+ else
+ version = magic == 2 ? 3 : 4;
+ } else
+ die("Super block in the wong block(%d).\n", fs->fs_super_bh->b_blocknr);
+
+ if (version == 0)
+ die ("FS format must be figured out here.\n");
+
+ if (get_sb_block_count (sb) > count_blocks (filename, fs->fs_blocksize))
+ super_error(-1, "Invalid block count found in the super block.\n");
+
+ if (get_sb_block_size (sb) != fs->fs_blocksize)
+ super_error(-1, "Invalid block size found in the super block (%lu).\n",
+ get_sb_block_size (sb));
+
+//Non needed from here
+ p_oid_maxsize = (fs->fs_blocksize - reiserfs_super_block_size (sb)) / sizeof(__u32) / 2 * 2;
+ if (get_sb_oid_maxsize (sb) != p_oid_maxsize)
+ super_error(-1, "Invalid objectid map max size found in the super block (%lu).\n",
+ get_sb_oid_maxsize (sb));
+
+ if (get_sb_oid_cursize (sb) == 1 || get_sb_oid_cursize (sb) > get_sb_oid_maxsize (sb))
+ super_error(-1, "Invalid objectid map found in the super block (%lu).\n",
+ get_sb_oid_cursize (sb));
+
+ if (get_sb_root_block (sb) > block_count && get_sb_root_block (sb) != ~0)
+ fsck_log("Invalid root block found in the super block (%lu).\n",
+ get_sb_root_block (sb));
+
+ if (get_sb_free_blocks (sb) > block_count)
+ fsck_log ("Invalid free block count found in the super block (%lu).\n",
+ get_sb_free_blocks (sb));
+
+ if (get_sb_tree_height (sb) && ((get_sb_tree_height (sb) < DISK_LEAF_NODE_LEVEL + 1) ||
+ (get_sb_tree_height (sb) > MAX_HEIGHT) && (get_sb_tree_height (sb) != ~0)))
+ super_error(-1, "Invalid tree height found in the super block (%lu).\n",
+ get_sb_tree_height (sb));
+
+ if (get_sb_hash_code (sb) && code2name (get_sb_hash_code (sb)) == 0)
+ super_error(-1, "Invalid hash found in the super block (%lu).\n",
+ get_sb_hash_code (sb));
+
+ if (version == 1 || version == 3) {
+ if (!uuid_is_correct(sb->s_uuid))
+ fsck_log ("Invalid uuid found, you should generate a new one.\n");
+
+ if (sb->s_flags & 0xfffffffe)
+ fsck_log ("rebuild-sb: super block flags found (%u), zeroed\n", sb->s_flags);
+ }
+
+//Not needed till here.
+
+ p_bmap_nr = (block_count + (fs->fs_blocksize * 8 - 1)) / (fs->fs_blocksize * 8);
+ if (get_sb_bmap_nr (sb) != p_bmap_nr)
+ super_error(-1, "Invalid bitmap number found in the super block (%lu).\n",
+ get_sb_bmap_nr (sb));
+
+ if (!fsck_skip_journal (fs) && standard_journal == 1) {
+ if (get_jp_journal_dev (sb_jp(sb)) != 0)
+ super_error(-1, "Invalid journal device found (%lu).\n", get_jp_journal_dev (sb_jp(sb)));
+
+ if (get_jp_journal_1st_block (sb_jp(sb)) != get_journal_start_must (fs))
+ super_error(-1, "Invalid journal first block found (%lu).\n", get_jp_journal_1st_block (sb_jp(sb)));
+
+ if (get_jp_journal_size (sb_jp(sb)) != journal_default_size(fs->fs_super_bh->b_blocknr, fs->fs_blocksize))
+ super_error(-1, "Invalid journal size found (%lu).\n", get_jp_journal_size (sb_jp(sb)) + 1);
+
+
+
+ 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());
+ }
+
+
+}
+*/
+
void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * data)
{
int version = 0;
@@ -59,9 +195,9 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
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");
+ reiserfs_exit (16, "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");
+ reiserfs_exit (16, "rebuild_sb: wrong block size specified, only divisible by 1024 are supported currently\n");
} else
retval = 4096;
@@ -79,7 +215,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
/* 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");
+ reiserfs_exit (16, "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;
@@ -89,7 +225,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
} 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");
+ reiserfs_exit (16, "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))
@@ -100,7 +236,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
} 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");
+ reiserfs_exit (16, "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*/
@@ -122,7 +258,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
magic_was_found = 3;
}
} else
- reiserfs_exit (1, "we opened device but there is no magic and there is no correct superbblock format found");
+ reiserfs_exit (16, "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;
@@ -134,7 +270,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
if (get_sb_block_count (sb) != block_count) {
do {
- printf("\nDid you use resiser(y/n)[n]: ");
+ printf("\nDid you use resizer(y/n)[n]: ");
getline (&answer, &n, stdin);
} while (strcmp ("y\n", answer) && strcmp ("n\n", answer) && strcmp ("\n", answer));
if (!strcmp ("y\n", answer)) {
@@ -163,7 +299,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
fd = open (filename, O_RDWR | O_LARGEFILE);
if (fd == -1)
- reiserfs_exit (1, "rebuils_sb: cannot open device %s", filename);
+ reiserfs_exit (8, "rebuils_sb: cannot open device %s", filename);
version = what_fs_version ();
@@ -175,9 +311,9 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
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");
+ reiserfs_exit (16, "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");
+ reiserfs_exit (16, "rebuild_sb: wrong block size specified, only divisible by 1024 are supported currently\n");
} else
retval = 4096;
}
@@ -210,8 +346,8 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
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);
+ printf("\nSpecify journal device with -j option.\n");
+ exit(16);
}
standard_journal = 1;
} else {
@@ -303,7 +439,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
}
}
if (sb->s_flags != 0 && sb->s_flags != 1) {
- fsck_log ("rebuild-sb: super block flags found, zeroed\n",
+ fsck_log ("rebuild-sb: super block flags found (%u), zeroed\n",
sb->s_flags);
sb->s_flags = 0;
}
@@ -395,7 +531,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
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");
+ reiserfs_exit (16, "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
@@ -445,7 +581,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
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");
+ reiserfs_exit(16, "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);
@@ -454,7 +590,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
/* 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");
+ reiserfs_exit(16, "rebuild_sb: offset is much then device size\n");
}
/* default size if magic was not found is device size - journal_1st_block;
@@ -474,7 +610,7 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
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");
+ reiserfs_exit(16, "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);
@@ -483,10 +619,10 @@ void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * dat
/* 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");
+ reiserfs_exit(16, "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");
+ reiserfs_exit(16, "rebuild-sb: journal header is not found, wrong dev/offset/size configuration\n");
}
jh = (struct reiserfs_journal_header *)fs->fs_jh_bh->b_data;
diff --git a/fsck/ubitmap.c b/fsck/ubitmap.c
index 7342a02..1e43901 100644
--- a/fsck/ubitmap.c
+++ b/fsck/ubitmap.c
@@ -48,20 +48,13 @@ int is_block_used (unsigned long block)
return reiserfs_bitmap_test_bit (fsck_new_bitmap (fs), 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 (check_hardware)
- check_hardware_msg();
+ check_memory_msg();
die ("mark_block_used: (%lu) used already", block);
}
diff --git a/fsck/ufile.c b/fsck/ufile.c
index 86aa6c7..a8abf83 100644
--- a/fsck/ufile.c
+++ b/fsck/ufile.c
@@ -13,13 +13,6 @@ static int are_items_in_the_same_node (struct path * path)
return (PATH_LAST_POSITION (path) < B_NR_ITEMS (PATH_PLAST_BUFFER (path)) - 1) ? 1 : 0;
}
-
-int do_make_tails ()
-{
- return 1;/*SB_MAKE_TAIL_FLAG (&g_sb) == MAKE_TAILS ? YES : NO;*/
-}
-
-
static void cut_last_unfm_pointer (struct path * path, struct item_head * ih)
{
set_ih_free_space(ih, 0);
@@ -62,16 +55,18 @@ static unsigned long indirect_to_direct (struct path * path, __u64 len, int syml
if (unfm_ptr && (unfm_bh = bread (bh->b_dev, unfm_ptr, bh->b_size))) {
/* we can read the block */
buf = unfm_bh->b_data;
+
} else {
- /* we cannot read the block */
+ /* we cannot read the block */
if (unfm_ptr)
- fsck_log ("indirect_to_direct: could not read block %lu (%K)\n", unfm_ptr, &ih->ih_key);
+ fsck_log ("indirect_to_direct: Reading of the block (%lu), pointed to by the file %K, failed\n",
+ unfm_ptr, &ih->ih_key);
memset (bad_drct, 0, fs->fs_blocksize);
buf = bad_drct;
}
/*
if (len > MAX_DIRECT_ITEM_LEN (fs->fs_blocksize)) {
- fsck_log ("indirect_to_direct: caanot create such a long item %d (%K), "
+ fsck_log ("indirect_to_direct: canot create such a long item %d (%K), "
"Cutting it down to %d byte\n", len, &ih->ih_key, MAX_DIRECT_ITEM_LEN (fs->fs_blocksize) - 8);
len = MAX_DIRECT_ITEM_LEN (fs->fs_blocksize) - 8;
}
@@ -84,14 +79,15 @@ static unsigned long indirect_to_direct (struct path * path, __u64 len, int syml
set_ih_item_len (&ins_ih, (get_ih_key_format (ih) == KEY_FORMAT_2) ? ROUND_UP(len) : len);
set_ih_free_space (&ins_ih, MAX_US_INT);
-
+ mark_ih_become_tail(ih);
+ mark_buffer_dirty(bh);
// last last unformatted node pointer
path->pos_in_item = I_UNFM_NUM (ih) - 1;
cut_last_unfm_pointer (path, ih);
/* insert direct item */
if (reiserfs_search_by_key_4 (fs, &(ins_ih.ih_key), path) == ITEM_FOUND)
- die ("indirect_to_direct: key must be not found");
+ reiserfs_panic ("indirect_to_direct: The direct item %k should not exist yet.", &(ins_ih.ih_key));
reiserfsck_insert_item (path, &ins_ih, (const char *)(buf));
brelse (unfm_bh);
@@ -100,8 +96,8 @@ static unsigned long indirect_to_direct (struct path * path, __u64 len, int syml
return get_offset (&ins_ih.ih_key); //offset;
}
-
-__u64 get_min_bytes_number (struct item_head * ih, int blocksize)
+/*
+static __u64 get_min_bytes_number (struct item_head * ih, int blocksize)
{
switch (get_type (&ih->ih_key)) {
case TYPE_DIRECT:
@@ -116,53 +112,75 @@ __u64 get_min_bytes_number (struct item_head * ih, int blocksize)
fsck_log ("get_min_bytes_number: called for wrong type of item %H\n", ih);
return 0;
}
+*/
-/* start_key is the key after which all items need to be deleted
+/* start_key is the key after which N items need to be deleted
save_here is a pointer where deleted items need to be saved if save is set.
+ start_key is the first undeleted item.
+ return whether we are sure there is nothing else of this file
*/
-static void delete_file_items_after_key(struct key * start_key, struct si ** save_here) {
+int delete_N_items_after_key(struct key * start_key, struct si ** save_here, int skip_dir_items, int n_to_delete) {
struct path path;
- struct key key = *start_key;
+// struct key key = *start_key;
struct key * rkey;
+ int count = 0;
while (1) {
- reiserfs_search_by_key_4 (fs, &key, &path);
+ reiserfs_search_by_key_4 (fs, start_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)) {
+ if (rkey && !not_of_one_file (start_key, rkey)) {
/* file continues in the right neighbor */
- copy_key (&key, rkey);
+ copy_key (start_key, rkey);
pathrelse (&path);
continue;
}
/* there is no more items with this key */
pathrelse (&path);
- break;
+ return 1;
}
if (is_stat_data_ih (get_ih(&path)))
fix_obviously_wrong_sd_mode (&path);
rkey = &(get_ih (&path))->ih_key;
- if (not_of_one_file (&key, rkey)) {
+ if (not_of_one_file (start_key, rkey)) {
/* there are no more item with this key */
pathrelse (&path);
- break;
+ return 1;
}
+ copy_key (start_key, rkey);
/* ok, item found, but make sure that it is not a directory one */
if ((is_stat_data_key (rkey) && !not_a_directory (get_item (&path))) ||
(is_direntry_key (rkey)))
- reiserfs_panic ("rewrite_file: no directory items of %K are expected", &key);
-
+ {
+ if (skip_dir_items) {
+ /* item of directory found. Leave it in the tree */
+ set_offset (KEY_FORMAT_1, start_key, get_offset (start_key) + 1);
+ pathrelse (&path);
+ continue;
+ } else {
+ reiserfs_panic ("delete_N_items_after_key: No directory item of %K are "
+ "expected", start_key);
+ }
+ }
if (save_here != NULL)
*save_here = save_and_delete_file_item (*save_here, &path);
else
reiserfsck_delete_item (&path, 0);
+
+ count++;
+
+ if (count == n_to_delete)
+ break;
+
+ pathrelse (&path);
}
-}
+ return 0;
+}
/* returns 1 when file looks correct, -1 if directory items appeared
there, 0 - only holes in the file found */
@@ -203,7 +221,7 @@ int are_file_items_correct (struct item_head * sd_ih, void * sd, __u64 * size, _
do {
retval = usearch_by_position (fs, key, key_version, &path);
if (retval == POSITION_FOUND && path.pos_in_item != 0)
- die ("are_file_items_correct: all bytes we look for must be found at position 0");
+ die ("are_file_items_correct: All bytes we look for must be first items byte (position 0).");
switch (retval) {
case POSITION_FOUND:/**/
@@ -248,17 +266,17 @@ int are_file_items_correct (struct item_head * sd_ih, void * sd, __u64 * size, _
if (!(*symlink) && key_version != get_ih_key_format (ih)) {
if (fsck_mode(fs) == FSCK_CHECK) {
- fsck_log("are_file_items_correct: vpf-10250: block %lu, item (%d), item format (%H)"\
+ fsck_log("are_file_items_correct: vpf-10250: block %lu, item (%d): The item format (%H)"\
" is not equal to SD format (%d)\n",
get_bh(&path)->b_blocknr, PATH_LAST_POSITION(&path), ih, key_version);
one_more_corruption (fs, fixable);
} else {
- fsck_log("are_file_items_correct: vpf-10280: block %lu, item (%d), item format (%H)"\
- " is not equal to SD format (%d) - delete\n",
+ fsck_log("are_file_items_correct: vpf-10280: block %lu, item (%d): The item format (%H)"\
+ " is not equal to SD format (%d) - item was deleted\n",
get_bh(&path)->b_blocknr, PATH_LAST_POSITION(&path), ih, key_version);
pathrelse (&path);
- delete_file_items_after_key (key, NULL);
+ delete_N_items_after_key (key, NULL, 0 /* do not skip dir items */, 0);
return 1;
}
}
@@ -296,12 +314,15 @@ int are_file_items_correct (struct item_head * sd_ih, void * sd, __u64 * size, _
if (will_convert) {
if (fsck_mode (fs) == FSCK_CHECK) {
/* here it can be symlink only */
- fsck_log ("are_file_items_correct: the indirect item should be converted back to direct %K\n", &ih->ih_key);
+ fsck_log ("are_file_items_correct: The indirect item should be converted back"
+ " to direct %K\n", &ih->ih_key);
one_more_corruption (fs, fixable);
pathrelse (&path);
} else {
__u32 * ind = (__u32 *)get_item(&path);
- fsck_log ("are_file_items_correct: convert the indirect item back to direct %K\n", &ih->ih_key);
+ /* DEBUG message.
+ fsck_log ("are_file_items_correct: The indirect item is converted back to direct %K\n", &ih->ih_key);
+ */
if (ind [I_UNFM_NUM (ih) - 1] == 0)
*blocks += (fs->fs_blocksize >> 9);
sd_first_direct_byte = indirect_to_direct (&path, sd_size - last_unfm_offset + 1, *symlink);
@@ -316,11 +337,8 @@ int are_file_items_correct (struct item_head * sd_ih, void * sd, __u64 * size, _
}
/* next item is item of this file */
- if ((is_indirect_ih (ih) &&
- (get_offset (&ih->ih_key) + fs->fs_blocksize * I_UNFM_NUM (ih) != get_offset (next_key))) ||
- (is_direct_ih (ih) &&
- (get_offset (&ih->ih_key) + get_ih_item_len (ih) != get_offset (next_key))))
- {
+ if (get_offset (&ih->ih_key) + get_bytes_number(ih, fs->fs_blocksize) != get_offset (next_key))
+ {
/* next item has incorrect offset (hole or overlapping) */
pathrelse (&path);
return 0;
@@ -333,9 +351,10 @@ int are_file_items_correct (struct item_head * sd_ih, void * sd, __u64 * size, _
}
/* items are of different types or are in different nodes */
+/*
if (get_offset (&ih->ih_key) + get_bytes_number (ih, fs->fs_blocksize) != get_offset (next_key))
{
- /* indirect item free space is not set properly */
+ // indirect item free space is not set properly
if (!is_indirect_ih (ih) ) //|| get_ih_free_space(ih) == 0)
fsck_log ("are_file_items_correct: "
"item must be indirect and must have invalid free space (%H)", ih);
@@ -346,27 +365,27 @@ int are_file_items_correct (struct item_head * sd_ih, void * sd, __u64 * size, _
mark_buffer_dirty (PATH_PLAST_BUFFER (&path));
}
}
-
+*/
/* next item exists */
set_type_and_offset(key_version, key, get_offset (next_key), get_type(next_key));
if (comp_keys (key, next_key))
- reiserfs_panic ("are_file_items_correct: keys do not match %k and %k", key, next_key);
+ reiserfs_panic ("are_file_items_correct: Internal tree is in inconsistent state, "
+ "the current item key %K and the next key %K must match", key, next_key);
pathrelse (&path);
break;
case POSITION_NOT_FOUND:
- // we always must have next key found. Exception is first
- // byte. It does not have to exist
-
+ /* We always must have next key found. Exception is first byte. It does not have to exist */
if (get_offset (key) != 1)
- die ("are_file_items_correct: key not found byte can be not found only when it is first byte of file");
+ reiserfs_panic ("are_file_items_correct: Position (offset == %llu) in the middle of"
+ "the file %K was not found.", get_offset(key), key);
pathrelse (&path);
return 0;
case FILE_NOT_FOUND:
if (get_offset (key) != 1)
- die ("are_file_items_correct: there is no items of this file, byte 0 found though");
+ reiserfs_panic ("are_file_items_correct: File %K must be found as we found its StatData.", key);
pathrelse (&path);
return 1;
@@ -376,18 +395,23 @@ int are_file_items_correct (struct item_head * sd_ih, void * sd, __u64 * size, _
}
} while (1);
- die ("are_file_items_correct: code can not reach here");
+ die ("are_file_items_correct: Cannot reach here");
return 0;
}
/* delete all items and put them back (after that file should have
- correct sequence of items.It is very similar to
- pass2.c:relocate_file () and should_relocate () */
-static void rewrite_file (struct item_head * ih)
+ correct sequence of items.
+ if should_relocate is specified then it relocates items to a new id.
+ if should_change_ih is specified then the key in ih is changed also. */
+void rewrite_file (struct item_head * ih, int should_relocate, int should_change_ih)
{
struct key key;
struct si * si;
+ __u32 new_objectid = 0;
+ int moved_items;
+ struct key old, new;
+ int nothing_else = 0;
/* starting with the leftmost one - look for all items of file,
store and delete and */
@@ -395,41 +419,79 @@ static void rewrite_file (struct item_head * ih)
set_type_and_offset (KEY_FORMAT_1, &key, SD_OFFSET, TYPE_STAT_DATA);
si = 0;
- delete_file_items_after_key (&key, &si);
+ nothing_else = 0;
- if (si && should_relocate (&(si->si_ih)))
- relocate_file (&(si->si_ih), 1);
+ nothing_else = delete_N_items_after_key (&key, &si, should_relocate /* do not skip dir items */, 10);
+
+ if (should_relocate && (si || should_change_ih)) {
+ /* get new objectid for relocation or get objectid with which file
+ was relocated already */
+ new_objectid = objectid_for_relocation (&ih->ih_key);
+ if (should_change_ih)
+ set_key_objectid (&ih->ih_key, new_objectid);
+
+ if (si) {
+ old = si->si_ih.ih_key;
+ set_key_objectid (&(si->si_ih.ih_key), new_objectid);
+ new = si->si_ih.ih_key;
+ }
+ }
+
+ moved_items = 0;
- /* put all items back into tree */
while (si) {
- insert_item_separately (&(si->si_ih), si->si_dnm_data, 1/*was in tree*/);
- si = remove_saved_item (si);
+ while (si && (nothing_else || si->si_next)) {
+ if (should_relocate) {
+ set_key_objectid (&(si->si_ih.ih_key), new_objectid);
+ moved_items ++;
+ }
+
+ insert_item_separately (&(si->si_ih), si->si_dnm_data, 1/*was in tree*/);
+ si = remove_saved_item (si);
+ }
+ if (!nothing_else)
+ nothing_else = delete_N_items_after_key (&key, &si, should_relocate /* do not skip dir items */, 10);
}
-}
+ if (moved_items)
+ fsck_log ("rewrite_file: %d items of file %K moved to %K\n",
+ moved_items, &old, &new);
+
+}
/* file must have correct sequence of items and tail must be stored in
- unformatted pointer */
-static int make_file_writeable (struct item_head * sd_ih, void * sd)
+ unformatted pointer;
+ pos in bh is a position of SD */
+static int make_file_writeable (struct buffer_head * bh, int pos)
+/* struct item_head * sd_ih, void * sd */
{
- struct item_head sd_ih_copy;
- struct stat_data sd_copy;
+ struct item_head *sd_ih = B_N_PITEM_HEAD (bh, pos);
+ struct item_head sd_ih_copy;
+ struct stat_data *sd = (struct stat_data *)B_N_PITEM (bh, pos);
+ struct stat_data sd_copy;
__u64 size;
__u32 blocks;
- int retval, symlink;
__u16 mode;
+ int retval, symlink;
sd_ih_copy = *sd_ih;
memcpy (&sd_copy, sd, get_ih_item_len (sd_ih));
get_sd_mode (sd_ih, sd, &mode);
symlink = S_ISLNK(mode);
+ if (ih_writable(sd_ih))
+ return 1;
+ else {
+ mark_ih_writable(sd_ih);
+ mark_buffer_dirty (bh);
+ }
+
retval = are_file_items_correct (&sd_ih_copy, &sd_copy, &size, &blocks, 0/*do not mark accessed*/, &symlink);
if (retval == 1)
/* file looks correct */
return 1;
- rewrite_file (sd_ih);
+ rewrite_file (sd_ih, 0, 0);
/*fsck_data (fs)->rebuild.rewritten ++;*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
@@ -437,7 +499,8 @@ static int make_file_writeable (struct item_head * sd_ih, void * sd)
size = 0;
if (are_file_items_correct (&sd_ih_copy, &sd_copy, &size, &blocks, 0/*do not mark accessed*/, &symlink) == 0) {
- fsck_progress ("file still incorrect %K\n", &sd_ih->ih_key);
+ fsck_log("WARNING: file was rewritten but still is not correct %K\n", &sd_ih->ih_key);
+ return -1;
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
@@ -448,17 +511,18 @@ static int make_file_writeable (struct item_head * sd_ih, void * sd)
/* this inserts __first__ indirect item (having k_offset == 1 and only
one unfm pointer) into tree */
-int create_first_item_of_file (struct item_head * ih, char * item, struct path * path,
- int *pos_in_coming_item, int was_in_tree)
+int create_first_item_of_file (struct item_head * ih, char * item, struct path * path, int was_in_tree)
{
__u32 unfm_ptr;
+ __u32 * ni = 0;
struct buffer_head * unbh;
struct item_head indih;
- int retval;
+ int retval, i;
__u32 free_sp = 0;
mark_item_unreachable (&indih);
copy_key (&(indih.ih_key), &(ih->ih_key));
+ set_ih_item_len (&indih, UNFM_P_SIZE);
if (get_offset (&ih->ih_key) > fs->fs_blocksize) {
/* insert indirect item containing 0 unfm pointer */
@@ -493,21 +557,27 @@ int create_first_item_of_file (struct item_head * ih, char * item, struct path *
retval = len;
} else {
/* take first unformatted pointer from an indirect item */
- unfm_ptr = *(__u32 *)item;/*B_I_POS_UNFM_POINTER (bh, ih, 0);*/
- if (!was_in_tree) {
- if (still_bad_unfm_ptr_2 (le32_to_cpu (unfm_ptr)))
- die ("create_first_item_of_file: bad unfm pointer %d", le32_to_cpu (unfm_ptr));
- mark_block_used (le32_to_cpu (unfm_ptr), 0);
- }
-
//free_sp = ih_get_free_space(0, ih, item);
/* free_sp = 0;//get_ih_free_space (ih);
set_ih_free_space (&indih, ((get_ih_item_len(ih) == UNFM_P_SIZE) ? free_sp : 0));
if (get_ih_item_len (ih) != UNFM_P_SIZE)
free_sp = 0;
*/
- retval = fs->fs_blocksize - free_sp;
- (*pos_in_coming_item) ++;
+
+ set_ih_item_len (&indih, get_ih_item_len (ih));
+ ni = getmem (get_ih_item_len (ih));
+ memcpy (ni, (item), get_ih_item_len (ih));
+
+ if (!was_in_tree) {
+ for (i = 0; i < I_UNFM_NUM (ih); i++) {
+ if (still_bad_unfm_ptr_2 (le32_to_cpu (ni[i])))
+ reiserfs_panic ("create_first_item_of_file: The file %K has a pointer to the bad block (%u)",
+ &ih->ih_key, le32_to_cpu (unfm_ptr));
+ mark_block_used (le32_to_cpu (ni[i]), 0);
+ }
+ }
+
+ retval = fs->fs_blocksize * get_ih_item_len (ih) / UNFM_P_SIZE;
}
}
@@ -516,9 +586,12 @@ int create_first_item_of_file (struct item_head * ih, char * item, struct path *
set_offset (key_format (&(ih->ih_key)), &indih.ih_key, 1);
set_type (key_format (&(ih->ih_key)), &indih.ih_key, TYPE_INDIRECT);
- set_ih_item_len (&indih, UNFM_P_SIZE);
-
- reiserfsck_insert_item (path, &indih, (const char *)&unfm_ptr);
+ if (ni) {
+ reiserfsck_insert_item (path, &indih, (const char *)ni);
+ freemem (ni);
+ } else {
+ reiserfsck_insert_item (path, &indih, (const char *)&unfm_ptr);
+ }
/* update sd_first_direct_byte */
/*
@@ -582,7 +655,7 @@ static void direct2indirect2 (unsigned long unfm, struct path * path, int keep_f
struct item_head * ih;
struct key key;
struct buffer_head * unbh;
- struct unfm_nodeinfo ni;
+ __u32 ni;
int copied = 0;
int file_format;
@@ -627,8 +700,7 @@ static void direct2indirect2 (unsigned long unfm, struct path * path, int keep_f
set_offset (file_format, &key, get_offset (&key) - copied);
// set_offset (ih_key_format (ih), &key, get_offset (&key) - copied);
// key.k_offset -= copied;
- ni.unfm_nodenum = cpu_to_le32 (unbh->b_blocknr);
- ni.unfm_freespace = (keep_free_space == 1) ? cpu_to_le16 (fs->fs_blocksize - copied) : 0;
+ ni = cpu_to_le32 (unbh->b_blocknr);
if (usearch_by_position (fs, &key, file_format, path) == FILE_NOT_FOUND) {
@@ -637,18 +709,21 @@ static void direct2indirect2 (unsigned long unfm, struct path * path, int keep_f
copy_key (&(insih.ih_key), &key);
set_ih_key_format (&insih, file_format);
set_type (get_ih_key_format (&insih), &insih.ih_key, TYPE_INDIRECT);
- set_ih_free_space (&insih, le16_to_cpu (ni.unfm_freespace));
-// insih.u.ih_free_space = ni.unfm_freespace;
+ set_ih_free_space (&insih, 0);
mark_item_unreachable (&insih);
set_ih_item_len (&insih, UNFM_P_SIZE);
mark_ih_was_tail (&insih);
- reiserfsck_insert_item (path, &insih, (const char *)&(ni.unfm_nodenum));
+ reiserfsck_insert_item (path, &insih, (const char *)&(ni));
} else {
ih = PATH_PITEM_HEAD (path);
- if (!is_indirect_ih (ih) || get_offset (&key) != get_bytes_number (ih, fs->fs_blocksize) + get_offset (&ih->ih_key))
- die ("direct2indirect: incorrect item found in %lu block", PATH_PLAST_BUFFER(path)->b_blocknr);
-
+ if (!is_indirect_ih(ih))
+ reiserfs_panic ("%s: The item, which is supposed to be deleted, found in the tree - %k",
+ __FUNCTION__, &ih->ih_key);
+ if (get_bytes_number (ih, fs->fs_blocksize) + get_offset (&ih->ih_key) != get_offset (&key))
+ reiserfs_panic ("%s: The item %k with the wrong offset found in the block %lu block",
+ __FUNCTION__, &ih->ih_key, PATH_PLAST_BUFFER(path)->b_blocknr);
+
mark_ih_was_tail (ih);
mark_buffer_dirty (get_bh(path));
reiserfsck_paste_into_item (path, (const char *)&ni, UNFM_P_SIZE);
@@ -697,7 +772,7 @@ static void direct2indirect2 (unsigned long unfm, struct path * path, int keep_f
if (usearch_by_position (fs, &key, file_format, path) != POSITION_FOUND ||
!is_indirect_ih (PATH_PITEM_HEAD (path)))
- die ("direct2indirect: position not found");
+ reiserfs_panic ("direct2indirect: The data %k, which are supposed to be converted, are not found", &key);
return;
}
@@ -713,28 +788,28 @@ static int append_to_unformatted_node (struct item_head * comingih, struct item_
int zero_number;
__u32 unfm_ptr;
+ bh = PATH_PLAST_BUFFER (path);
+ unfm_ptr = le32_to_cpu (B_I_POS_UNFM_POINTER (bh, ih, I_UNFM_NUM (ih) - 1));
+
/* append to free space of the last unformatted node of indirect item ih */
if (*free_sp /*ih->u.ih_free_space*/ < coming_len)
{
-
*free_sp = get_offset (&ih->ih_key) + fs->fs_blocksize * I_UNFM_NUM (ih) - get_offset (&comingih->ih_key);
if (*free_sp < coming_len)
- die ("reiserfsck_append_file: there is no enough free space in unformatted node");
+ reiserfs_panic ("%s: block %lu: The unformatted node %u, pointed by the file %k, has not enough free space"
+ "for appending %llu bytes", __FUNCTION__, bh->b_blocknr, unfm_ptr, &ih->ih_key, coming_len);
}
-
end_of_data = fs->fs_blocksize - *free_sp;
zero_number = offset - end_of_data;
- bh = PATH_PLAST_BUFFER (path);
-
- unfm_ptr = le32_to_cpu (B_I_POS_UNFM_POINTER (bh, ih, I_UNFM_NUM (ih) - 1));
-
- /*if (unfm_ptr != 0 && unfm_ptr < SB_BLOCK_COUNT (fs))*/
+ /*if (unfm_ptr != 0 && unfm_ptr < SB_BLOCK_COUNT (fs))*/
if (unfm_ptr && !not_data_block (fs, unfm_ptr))
{
unbh = bread (fs->fs_dev, unfm_ptr, fs->fs_blocksize);
if (!is_block_used (unfm_ptr))
- die ("append_to_unformatted_node: unused block %d", unfm_ptr);
+ reiserfs_panic ("%s: block %lu: The unformatted node %u, pointed by the file %k, is marked as unused",
+ __FUNCTION__, bh->b_blocknr, unfm_ptr, &ih->ih_key);
+
if (unbh == 0)
unfm_ptr = 0;
} else {
@@ -794,15 +869,16 @@ static void adjust_free_space (struct buffer_head * bh, struct item_head * ih, s
int reiserfsck_append_file (struct item_head * comingih, char * item, int pos, struct path * path,
int was_in_tree)
{
- struct unfm_nodeinfo ni;
+ __u32 * ni;
struct buffer_head * unbh;
int retval;
struct item_head * ih = PATH_PITEM_HEAD (path);
__u16 keep_free_space;
__u32 bytes_number;
+ int i, count = 0;
if (!is_indirect_ih (ih))
- die ("reiserfsck_append_file: can not append to non-indirect item");
+ reiserfs_panic ("reiserfsck_append_file: Operation is not allowed for non-indirect item %k", &ih->ih_key);
//keep_free_space = ih_get_free_space(PATH_PLAST_BUFFER (path), PATH_PITEM_HEAD(path), 0);
keep_free_space = 0;//get_ih_free_space (ih);
@@ -834,70 +910,81 @@ int reiserfsck_append_file (struct item_head * comingih, char * item, int pos, s
// mark_buffer_uptodate (unbh, 0);
mark_buffer_uptodate (unbh, 1);
- ni.unfm_nodenum = cpu_to_le32 (unbh->b_blocknr);
- ni.unfm_freespace = cpu_to_le16 (fs->fs_blocksize - coming_len - (get_offset (&comingih->ih_key) % unbh->b_size - 1));
+ ni = getmem (UNFM_P_SIZE);
+ *ni = cpu_to_le32 (unbh->b_blocknr);
+ count = 1;
+
brelse (unbh);
retval = coming_len;
} else {
/* coming item is indirect item */
- //bytes_number = get_bytes_number (PATH_PLAST_BUFFER (path), PATH_PITEM_HEAD(path), 0, CHECK_FREE_BYTES);
+
bytes_number = get_bytes_number (ih, fs->fs_blocksize);
if (get_offset (&comingih->ih_key) + pos * fs->fs_blocksize != get_offset (&ih->ih_key) + bytes_number)
- fsck_log ("reiserfsck_append_file: can not append indirect item (%H) to the %H\n",
- comingih, ih);
+ reiserfs_panic ("reiserfsck_append_file: file %K: Cannot append indirect pointers of the offset "
+ "(%LLu) at the position %LLu\n", &comingih->ih_key, get_offset (&comingih->ih_key) + pos * fs->fs_blocksize,
+ get_offset (&ih->ih_key) + bytes_number);
/* take unformatted pointer from an indirect item */
- ni.unfm_nodenum = *(__u32 *)(item + pos * UNFM_P_SIZE);/*B_I_POS_UNFM_POINTER (bh, ih, pos);*/
-
+ count = I_UNFM_NUM(comingih) - pos;
+ ni = getmem (count * UNFM_P_SIZE);
+ memcpy (ni, (item + pos * UNFM_P_SIZE), count * UNFM_P_SIZE);
+
if (!was_in_tree) {
- if (still_bad_unfm_ptr_2 (le32_to_cpu (ni.unfm_nodenum)))
- die ("reiserfsck_append_file: bad unfm pointer %u", le32_to_cpu (ni.unfm_nodenum));
- mark_block_used (le32_to_cpu (ni.unfm_nodenum), 0);
+ for (i = 0; i < count; i++ ) {
+ if (still_bad_unfm_ptr_2 (le32_to_cpu (ni[i])))
+ die ("reiserfsck_append_file: Trying to insert a pointer to illegal block (%u)", le32_to_cpu (ni[i]));
+ mark_block_used (le32_to_cpu (ni[i]), 0);
+ }
}
- ni.unfm_freespace = cpu_to_le16 (((pos == (I_UNFM_NUM (comingih) - 1)) ?
- //ih_get_free_space(0, comingih, item) /*comingih->u.ih_free_space*/ : 0);
- get_ih_free_space (comingih) /*comingih->u.ih_free_space*/ : 0));
- ni.unfm_freespace = 0;
- retval = fs->fs_blocksize - le16_to_cpu (ni.unfm_freespace);
+ retval = fs->fs_blocksize * count;
}
- reiserfsck_paste_into_item (path, (const char *)&ni, UNFM_P_SIZE);
+ reiserfsck_paste_into_item (path, (const char *)ni, count * UNFM_P_SIZE);
+ freemem (ni);
return retval;
}
-
int must_there_be_a_hole (struct item_head * comingih, struct path * path)
{
struct item_head * ih = PATH_PITEM_HEAD (path);
- int keep_free_space;
if (is_direct_ih (ih)) {
- direct2indirect2 (0, path, keep_free_space = 1);
+ direct2indirect2 (0, path, 1);
ih = PATH_PITEM_HEAD (path);
}
path->pos_in_item = I_UNFM_NUM (ih);
+
+ return (get_offset (&comingih->ih_key) - get_offset (&ih->ih_key)) / fs->fs_blocksize - I_UNFM_NUM (ih);
+/*
if (get_offset (&ih->ih_key) + (I_UNFM_NUM (ih) + 1) * fs->fs_blocksize <= get_offset (&comingih->ih_key))
return 1;
- return 0;
+ return 0;*/
}
-int reiserfs_append_zero_unfm_ptr (struct path * path)
+int reiserfs_append_zero_unfm_ptr (struct path * path, int p_count)
{
- struct unfm_nodeinfo ni;
- int keep_free_space;
-
- ni.unfm_nodenum = 0;
- ni.unfm_freespace = 0;
+ __u32 * ni;
+ int count;
if (is_direct_ih (PATH_PITEM_HEAD (path)))
/* convert direct item to indirect */
- direct2indirect2 (0, path, keep_free_space = 0);
+ direct2indirect2 (0, path, 0);
- reiserfsck_paste_into_item (path, (const char *)&ni, UNFM_P_SIZE);
+ count = MAX_INDIRECT_ITEM_LEN (fs->fs_blocksize) / UNFM_P_SIZE;
+
+ if (p_count <= count)
+ count = p_count;
+
+ ni = getmem (count * UNFM_P_SIZE);
+ memset (ni, 0, count * UNFM_P_SIZE);
+
+ reiserfsck_paste_into_item (path, (const char *)ni, count * UNFM_P_SIZE);
+ freemem(ni);
return 0;
}
@@ -923,25 +1010,26 @@ static int overwrite_by_direct_item (struct item_head * comingih, char * item, s
/**/
unbh = bread (fs->fs_dev, unfm_ptr, bh->b_size);
if (!is_block_used (unfm_ptr))
- die ("overwrite_by_direct_item: unused block %d", unfm_ptr);
+ die ("overwrite_by_direct_item: block %lu, item %d, pointer %d: The pointed block"
+ "(%u) being overwritten is marked as unused.", bh->b_blocknr, PATH_LAST_POSITION(path),
+ path->pos_in_item, unfm_ptr);
if (unbh == 0)
unfm_ptr = 0;
}
if (unfm_ptr == 0 || unfm_ptr >= get_sb_block_count (fs->fs_ondisk_sb)) {
- unbh = reiserfsck_get_new_buffer (bh->b_blocknr);
- memset (unbh->b_data, 0, unbh->b_size);
- B_I_POS_UNFM_POINTER (bh, ih, path->pos_in_item) = cpu_to_le32 (unbh->b_blocknr);
- mark_buffer_dirty (bh);
+ if ((unbh = reiserfsck_get_new_buffer (bh->b_blocknr)) != NULL) {
+ memset (unbh->b_data, 0, unbh->b_size);
+ B_I_POS_UNFM_POINTER (bh, ih, path->pos_in_item) = cpu_to_le32 (unbh->b_blocknr);
+ mark_buffer_dirty (bh);
+ } else {
+ die ("overwrite_by_direct_item: Could not allocate a new block for new data");
+ }
}
- if (!unbh) {
- die ("overwrite_by_direct_item: could not put direct item in");
- }
-
offset = (get_offset (&comingih->ih_key) % bh->b_size) - 1;
- if (offset + coming_len > MAX_DIRECT_ITEM_LEN (bh->b_size))
- die ("overwrite_by_direct_item: direct item too long (offset=%lu, length=%u)",
- ( long unsigned ) get_offset (&comingih->ih_key),
+ if (offset + coming_len > bh->b_size)
+ die ("overwrite_by_direct_item: The length of the file after insertion (offset=%lu, length=%u)"
+ "will exceed the maximal possible length.", ( long unsigned ) get_offset (&comingih->ih_key),
( unsigned ) coming_len);
memcpy (unbh->b_data + offset, item, coming_len);
@@ -1081,19 +1169,21 @@ static int reiserfsck_overwrite_file (struct item_head * comingih, char * item,
if (not_of_one_file (ih, &(comingih->ih_key)))
- reiserfs_panic ("reiserfsck_overwrite_file: found [%K], new item [%K]",
- &ih->ih_key, &comingih->ih_key);
+ reiserfs_panic ("reiserfsck_overwrite_file: The file to be overwritten %K must be of"
+ " the same as the new data %K", &ih->ih_key, &comingih->ih_key);
if (is_direct_ih (ih)) {
unfm_ptr = 0;
if (is_indirect_ih (comingih)) {
if (get_offset (&ih->ih_key) % fs->fs_blocksize != 1)
- die ("reiserfsck_overwrite_file: second part of tail can not be overwritten by indirect item");
+ reiserfs_panic ("reiserfsck_overwrite_file: The second part of the tail %k can not"
+ " be overwritten by indirect item %k", &ih->ih_key, &comingih->ih_key);
/* use pointer from coming indirect item */
unfm_ptr = le32_to_cpu (*(__u32 *)(item + *pos_in_coming_item * UNFM_P_SIZE));
if (!was_in_tree) {
if (still_bad_unfm_ptr_2 (unfm_ptr))
- die ("reiserfsck_overwrite_file: still bad ");
+ die ("reiserfsck_overwrite_file: The pointer to the unformatted block (%u)"
+ " points to the bad area.", unfm_ptr);
}
}
/* */
@@ -1104,7 +1194,8 @@ static int reiserfsck_overwrite_file (struct item_head * comingih, char * item,
written = overwrite_by_direct_item (comingih, item, path);
} else {
if (was_in_tree)
- die ("reiserfsck_overwrite_file: item we are going to overwrite with could not be in the tree yet");
+ reiserfs_panic ("reiserfsck_overwrite_file: Item %k we are going to overwrite with"
+ " %k cannot not be in the tree yet", &ih->ih_key, &comingih->ih_key);
written = overwrite_by_indirect_item (comingih, (__u32 *)item, path, pos_in_coming_item);
}
@@ -1122,18 +1213,20 @@ int reiserfsck_file_write (struct item_head * ih, char * item, int was_in_tree)
struct key key;
int file_format = KEY_FORMAT_UNDEFINED;
int symlink = 0;
-/* __u64 size;
- __u32 blocks;*/
+ int relocated = 0;
if (!was_in_tree) {
__u16 mode;
-
- // we already inserted all SD items. If we cannot find SD of this item - skip it
+
+ /* We already inserted all SD items. If we cannot find SD of this item - skip it */
memset (&key, 0, sizeof (key));
+
+check_again:
copy_short_key (&key, &(ih->ih_key));
if (reiserfs_search_by_key_4 (fs, &key, &path) != ITEM_FOUND) {
- fsck_log ("vpf-10260: no SD found, item skipped (%H)\n", ih);
+ fsck_log ("vpf-10260: The file we are inserting the new item (%H) into has not"
+ " StatData, insertion was skipped\n", ih);
pathrelse (&path);
return 0;
}
@@ -1144,16 +1237,25 @@ int reiserfsck_file_write (struct item_head * ih, char * item, int was_in_tree)
symlink = S_ISLNK(mode);
if (!symlink && file_format != get_ih_key_format (ih)) {
- fsck_log ("vpf-10270: item to be inserted is of different format then found SD,"\
- " item skipped \n\t(%H)\n\t(%H)\n", ih, get_ih(&path));
+ fsck_log ("vpf-10270: The file we are inserting the new item into has the different"
+ " format then found StatData, insertion was skipped\n\tSD: (%H)\n\tNew:(%H)\n",
+ ih, get_ih(&path));
pathrelse (&path);
return 0;
}
- if (make_file_writeable (get_ih(&path), get_item (&path)) == -1) {
- /* write was not completed. Skip that item. Maybe it should be
- saved to lost_found */
- fsck_progress ("reiserfsck_file_write: skip writing %H\n", ih);
+ if (!relocated && should_relocate (ih)) {
+ rewrite_file (ih, 1, 1/*change new_ih*/);
+ pathrelse(&path);
+ relocated = 1;
+ goto check_again;
+ }
+
+ if (make_file_writeable (get_bh(&path), get_item_pos (&path)) == -1) {
+ /* write was not completed. Skip that item. Maybe it should be saved to lost_found */
+ fsck_log ("reiserfsck_file_write: WARNING: The file we are inserting the new item %k into was"
+ " not recovered and is still in inconsistent state, insertion was skipped\n", &ih->ih_key);
+ pathrelse(&path);
return 0;
}
@@ -1168,9 +1270,17 @@ int reiserfsck_file_write (struct item_head * ih, char * item, int was_in_tree)
while (count) {
retval = usearch_by_position (fs, &key, key_format (&key), &path);
+
+ /* if there are items of bigger offset than we are looking for and
+ there is no item between wamted offset and SD, insert first item */
+ if (retval == POSITION_NOT_FOUND &&
+ ( PATH_LAST_POSITION (&path) >= B_NR_ITEMS (get_bh(&path)) ||
+ get_offset (&get_ih(&path)->ih_key) > get_offset (&key)))
+ retval = FILE_NOT_FOUND;
if (retval == DIRECTORY_FOUND)
- reiserfs_panic ("directory found %k", key);
+ reiserfs_panic ("The directory was found at the place of the file we are going to insert"
+ " the item %k into", key);
if (retval == POSITION_FOUND) {
written = reiserfsck_overwrite_file (ih, item, &path, &pos_in_coming_item, was_in_tree);
@@ -1178,7 +1288,7 @@ int reiserfsck_file_write (struct item_head * ih, char * item, int was_in_tree)
set_offset (key_format (&key), &key, get_offset (&key) + written);
}
if (retval == FILE_NOT_FOUND) {
- written = create_first_item_of_file (ih, item, &path, &pos_in_coming_item, was_in_tree);
+ written = create_first_item_of_file (ih, item, &path, was_in_tree);
count -= written;
set_offset (key_format (&key), &key, get_offset (&key) + written );
@@ -1190,17 +1300,18 @@ int reiserfsck_file_write (struct item_head * ih, char * item, int was_in_tree)
mark_buffer_dirty (get_bh(&path));
}
- if (must_there_be_a_hole (ih, &path) == 1)
+ if ((written = must_there_be_a_hole (ih, &path)) > 0)
{
- reiserfs_append_zero_unfm_ptr (&path);
+ reiserfs_append_zero_unfm_ptr (&path, written);
}else {
- count -= reiserfsck_append_file (ih, item, pos_in_coming_item, &path, was_in_tree);
- set_offset (key_format (&key), &key, get_offset (&key) + fs->fs_blocksize);
- pos_in_coming_item ++;
+ written = reiserfsck_append_file (ih, item, pos_in_coming_item, &path, was_in_tree);
+ count -= written;
+ set_offset (key_format (&key), &key, get_offset (&key) + written);
+ pos_in_coming_item += written / fs->fs_blocksize;
}
}
if (count < 0)
- reiserfs_panic ("reiserfsck_file_write: %K: count < 0 (%d)",
+ reiserfs_panic ("reiserfsck_file_write: We wrote into the file %K more bytes than needed - count (%d) < 0.",
&key, count);
pathrelse (&path);
}
diff --git a/fsck/ustree.c b/fsck/ustree.c
index 9a41178..9edcb6b 100644
--- a/fsck/ustree.c
+++ b/fsck/ustree.c
@@ -244,7 +244,8 @@ void pass_through_tree (reiserfs_filsys_t * fs, do_after_read_t action1,
if (action1)
if ((problem = action1 (fs, path, h))) {
- fsck_log ("whole subtree skipped\n");
+ fsck_log (" the problem in the internal node occured (%lu), whole subtree is skipped\n",
+ path[h]->b_blocknr);
fsck_data (fs)->check.bad_nodes++;
if (h == 0) {
diff --git a/include/misc.h b/include/misc.h
index 97308a6..3149207 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -3,12 +3,20 @@
*/
/* nothing abount reiserfs here */
+
+#ifndef REISERFS_MISC_H
+#define REISERFS_MISC_H
+
#include <endian.h>
#include "swab.h"
+#include <linux/major.h>
+#include <signal.h>
+#include <unistd.h>
#define POSITION_FOUND 8
#define POSITION_NOT_FOUND 9
+void check_memory_msg(void);
void die (char * fmt, ...) __attribute__ ((format (printf, 1, 2)));
void * getmem (int size);
void freemem (void * p);
@@ -20,6 +28,17 @@ int is_mounted_read_only (char * device_name);
void check_and_free_mem (void);
char * kdevname (int dev);
+typedef struct dma_info {
+ int fd;
+ struct stat64 stat;
+ int support_type;
+ int dma;
+ __u64 speed;
+} dma_info_t;
+
+int prepare_dma_check(dma_info_t *dma_info);
+int get_dma_info(dma_info_t *dma_info);
+void clean_after_dma_check(int fd, dma_info_t *dma_info);
void print_how_far (FILE * fp, unsigned long * passed, unsigned long total, int inc, int quiet);
void print_how_fast (unsigned long total,
@@ -30,6 +49,7 @@ int generate_random_uuid (unsigned char * uuid);
int uuid_is_correct (unsigned char * uuid);
int set_uuid (const unsigned char * text, unsigned char * UUID);
+#include <asm/bitops.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
int le_set_bit (int nr, void * addr);
int le_clear_bit (int nr, void * addr);
@@ -42,31 +62,14 @@ int le_find_next_zero_bit (const void *vaddr, unsigned size, unsigned offset);
# 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
@@ -95,8 +98,10 @@ struct block_handler {
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 blocklist__is_block_saved (struct block_handler ** base, __u32 * count, __u32 blocknr,
+ dev_t device, __u32 * position);
+void blocklist__insert_in_position (void * block_h, void ** base, __u32 * count,
+ int elem_size, __u32 * position);
int blockdev_list_compare (const void * block1, const void * block2);
@@ -134,3 +139,34 @@ int blockdev_list_compare (const void * block1, const void * block2);
/* get value written in specified bits */\
tmp >>= from;\
return tmp;
+
+
+#ifndef MAJOR
+#define MAJOR(rdev) ((rdev)>>8)
+#define MINOR(rdev) ((rdev) & 0xff)
+#endif /* MAJOR */
+
+#ifndef SCSI_DISK_MAJOR
+#define SCSI_DISK_MAJOR(maj) ((maj) == SCSI_DISK0_MAJOR || \
+ ((maj) >= SCSI_DISK1_MAJOR && (maj) <= SCSI_DISK7_MAJOR))
+#endif /* SCSI_DISK_MAJOR */
+
+#ifndef SCSI_BLK_MAJOR
+#define SCSI_BLK_MAJOR(maj) (SCSI_DISK_MAJOR(maj) || (maj) == SCSI_CDROM_MAJOR)
+#endif /* SCSI_BLK_MAJOR */
+
+#ifndef IDE_DISK_MAJOR
+#ifdef IDE9_MAJOR
+#define IDE_DISK_MAJOR(maj) ((maj) == IDE0_MAJOR || (maj) == IDE1_MAJOR || \
+ (maj) == IDE2_MAJOR || (maj) == IDE3_MAJOR || \
+ (maj) == IDE4_MAJOR || (maj) == IDE5_MAJOR || \
+ (maj) == IDE6_MAJOR || (maj) == IDE7_MAJOR || \
+ (maj) == IDE8_MAJOR || (maj) == IDE9_MAJOR)
+#else
+#define IDE_DISK_MAJOR(maj) ((maj) == IDE0_MAJOR || (maj) == IDE1_MAJOR || \
+ (maj) == IDE2_MAJOR || (maj) == IDE3_MAJOR || \
+ (maj) == IDE4_MAJOR || (maj) == IDE5_MAJOR)
+#endif /* IDE9_MAJOR */
+#endif /* IDE_DISK_MAJOR */
+
+#endif /* REISERFS_MISC_H */
diff --git a/include/reiserfs_fs.h b/include/reiserfs_fs.h
index eaa01d8..291eee7 100644
--- a/include/reiserfs_fs.h
+++ b/include/reiserfs_fs.h
@@ -426,6 +426,8 @@ struct reiserfs_journal_header {
__u32 jh_mount_id ;
struct journal_params jh_journal;
+
+ __u32 jh_last_check_mount_id; /* the mount id of the fs during the last reiserfsck --check. */
};
@@ -492,11 +494,9 @@ struct offset_v2 {
} __attribute__ ((__packed__));
-/* Key of the object drop determines its location in the S+tree, and is
- composed of 4 components */
+/* Key of the object determines object's location in the tree, composed of 4 components */
struct key {
- __u32 k2_dir_id; /* packing locality: by default parent directory object
- id */
+ __u32 k2_dir_id; /* packing locality: by default parent directory object id */
__u32 k2_objectid; /* object identifier */
union {
struct offset_v1 k2_offset_v1;
@@ -640,9 +640,11 @@ void set_ih_key_format (struct item_head * ih, __u16 val);
( ! not_of_one_file(p_s_ih, p_s_key) && \
I_OFF_BYTE_IN_ITEM(p_s_ih, get_offset (p_s_key), n_blocksize) )
-#define IH_Bad 0
-#define IH_Unreachable 1
-#define IH_WAS_TAIL 2
+#define IH_Unreachable 0
+#define IH_Was_Tail 1
+#define IH_Checked 2
+#define IH_Writable 3
+
/* Bad item flag is set temporary by recover_leaf */
/*
@@ -670,16 +672,23 @@ extern_inline __u16 unmark_item_bad( struct item_head *ih )
/* Unreachable bit is set on tree rebuilding and is cleared in semantic pass */
#define clean_ih_flags(ih) set_ih_flags (ih, 0)
-#define ih_reachable(ih) (!(get_ih_flags (ih) & (1 << IH_Unreachable)))
+#define ih_reachable(ih) (!(get_ih_flags (ih) & (1 << IH_Unreachable)))
#define mark_ih_reachable(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_Unreachable))
#define mark_ih_unreachable(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_Unreachable))
-#define ih_was_tail(ih) (get_ih_flags (ih) & (1 << IH_WAS_TAIL))
-#define mark_ih_was_tail(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_WAS_TAIL))
-#define mark_ih_become_tail(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_WAS_TAIL))
+#define ih_was_tail(ih) (get_ih_flags (ih) & (1 << IH_Was_Tail))
+#define mark_ih_was_tail(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_Was_Tail))
+#define mark_ih_become_tail(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_Was_Tail))
+
+#define ih_checked(ih) (get_ih_flags (ih) & (1 << IH_Checked))
+#define mark_ih_checked(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_Checked))
+#define clear_ih_checked(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_Checked))
+#define ih_writable(ih) (get_ih_flags (ih) & (1 << IH_Writable))
+#define mark_ih_writable(ih) set_ih_flags (ih, get_ih_flags (ih) | (1 << IH_Writable))
+#define clear_ih_writable(ih) set_ih_flags (ih, get_ih_flags (ih) & ~(1 << IH_Writable))
-/* maximal length of item */
+/* maximal length of item */
#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE)
#define MIN_ITEM_LEN 1
@@ -690,7 +699,7 @@ extern_inline __u16 unmark_item_bad( struct item_head *ih )
/*
- * Picture represents a leaf of the S+tree
+ * Picture represents a leaf of internal tree
* ______________________________________________________
* | | Array of | | |
* |Block | Object-Item | F r e e | Objects- |
@@ -837,7 +846,7 @@ struct stat_data {
//
#define SD_SIZE (sizeof(struct stat_data))
-// there are two ways: to check length of item or ih_version field
+// there are two ways: to check length of item or ih_format field
// (for old stat data it is set to 0 (KEY_FORMAT_1))
#define stat_data_v1(ih) (get_ih_key_format (ih) == KEY_FORMAT_1)
@@ -1424,7 +1433,8 @@ struct buffer_info {
/* get stat-data */
#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )B_I_PITEM(bh,ih) )
-#define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_V1_SIZE - UNFM_P_SIZE)
+#define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE)
+#define MAX_INDIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - IH_SIZE)
/* indirect items consist of entries which contain blocknrs, pos
indicates which entry, and B_I_POS_UNFM_POINTER resolves to the
diff --git a/include/reiserfs_lib.h b/include/reiserfs_lib.h
index de13de6..a3c30ef 100644
--- a/include/reiserfs_lib.h
+++ b/include/reiserfs_lib.h
@@ -170,6 +170,7 @@ 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_delta (reiserfs_bitmap_t * base, reiserfs_bitmap_t * exclude);
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);
@@ -214,7 +215,7 @@ 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 does_look_like_super_block (struct reiserfs_super_block * rs);
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);
@@ -368,6 +369,7 @@ 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);\
diff --git a/include/stamp-h.in b/include/stamp-h.in
index e69de29..9788f70 100644
--- a/include/stamp-h.in
+++ b/include/stamp-h.in
@@ -0,0 +1 @@
+timestamp
diff --git a/include/swab.h b/include/swab.h
index 40c7c8a..35e3e80 100644
--- a/include/swab.h
+++ b/include/swab.h
@@ -1,25 +1,8 @@
+/*
+ * Copyright 2002 by Hans Reiser, licensing governed by reiserfs/README
+ */
#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) ))
+#include <linux/byteorder/swab.h>
#endif /* _REISERFS_SWAB_H_ */
diff --git a/lib/io.c b/lib/io.c
index d24dbe3..8c0b621 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1996, 1997 Hans Reiser, see reiserfs/README for licensing and copyright details
+ * Copyright 1996-2002 Hans Reiser, see reiserfs/README for licensing and copyright details
*/
#define _GNU_SOURCE
@@ -18,6 +18,18 @@
#include "misc.h"
#include "config.h"
+void check_memory_msg (void) {
+ fprintf(stderr,
+ "\nThe problem has occurred looks like a hardware problem. Send us the bug\n"
+ "report only if the second run dies at the same place with the same block\n"
+ "number.\n");
+}
+
+void check_hd_msg (void) {
+ fprintf(stderr,
+ "\nThe problem has occurred looks like a hardware problem.\n"
+ "Check your hard drive for badblocks.\n");
+}
static int is_bad_block (unsigned long block)
{
@@ -492,8 +504,8 @@ struct buffer_head * bread (int dev, unsigned long block, size_t size)
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);
+ check_hd_msg();
+ die ("%s: Cannot read the block (%lu).\n", __FUNCTION__, bh->b_blocknr);
}
mark_buffer_uptodate (bh, 0);
@@ -776,7 +788,7 @@ int bwrite (struct buffer_head * bh)
if (is_bad_block (bh->b_blocknr)) {
fprintf (stderr, "bwrite: bad block is going to be written: %lu\n",
bh->b_blocknr);
- exit (4);
+ exit(8);
}
if (!buffer_dirty (bh) || !buffer_uptodate (bh))
@@ -793,7 +805,7 @@ int bwrite (struct buffer_head * bh)
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); /* File system errors left uncorrected */
+ exit(8); /* File system errors left uncorrected */
}
if (s_rollback_file != NULL && bh->b_size == rollback_blocksize) {
@@ -801,7 +813,7 @@ int bwrite (struct buffer_head * bh)
__u32 position;
struct block_handler block_h;
- /*log previous content into log*/
+ /*log previous content into the log*/
if (!fstat64 (bh->b_dev, &buf)) {
block_h.blocknr = bh->b_blocknr;
block_h.device = buf.st_rdev;
@@ -813,8 +825,8 @@ int bwrite (struct buffer_head * bh)
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);
+ blocklist__insert_in_position(&block_h, (void **)&rollback_blocks_array,
+ &rollback_blocks_number, 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",
@@ -825,27 +837,28 @@ int bwrite (struct buffer_head * bh)
} else {
fprintf (stderr, "bwrite: read (block=%lu, dev=%d): %s\n", bh->b_blocknr,
bh->b_dev, strerror (errno));
- exit (4);
+ exit(8);
}
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);
+ exit(8);
}
}
} else {
- fprintf (stderr, "bwrite: fstat of (%d) returned -1: %s\n", bh->b_dev, strerror (errno));
+ 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);
+ 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 %ld bytes returned %ld (block=%ld, dev=%d): %s\n",
(long)size, (long)bytes, bh->b_blocknr, bh->b_dev, strerror (errno));
- exit (4);
+ exit(8);
}
mark_buffer_clean (bh);
@@ -887,7 +900,8 @@ 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) ;
+// 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);
diff --git a/lib/misc.c b/lib/misc.c
index 16becf9..fbb2f61 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -19,6 +19,8 @@
#include <time.h>
#include <utime.h>
#include <ctype.h>
+#include <linux/hdreg.h>
+#include <dirent.h>
#include <unistd.h>
//#include <linux/unistd.h>
@@ -48,7 +50,7 @@ void die (char * fmt, ...)
vsprintf (buf, fmt, args);
va_end (args);
- fprintf (stderr, "\n%s\n\n\n", buf);
+ fprintf (stderr, "\n%s\n", buf);
abort ();
}
@@ -208,7 +210,7 @@ _syscall2(long, bad_stat64, char *, filename, struct stat64 *, statbuf);
return st.st_##field;\
\
perror ("stat failed");\
- exit (1);\
+ exit (8);\
mode_t get_st_mode (char * file_name)
@@ -404,6 +406,8 @@ unsigned long count_blocks (char * filename, int blocksize)
{
loff_t high, low;
int fd;
+ unsigned long sz;
+ __u64 size;
if (!S_ISBLK (get_st_mode (filename)) && !S_ISREG (get_st_mode (filename)))
return 0;
@@ -414,15 +418,11 @@ unsigned long count_blocks (char * filename, int blocksize)
#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;
+ return (size / 4096) * 4096 / blocksize;
}
}
#endif
@@ -430,10 +430,9 @@ unsigned long count_blocks (char * filename, int blocksize)
#ifdef BLKGETSIZE
{
- unsigned long size;
-
- if (ioctl (fd, BLKGETSIZE, &size) >= 0) {
- return size / (blocksize / 512);
+ if (ioctl (fd, BLKGETSIZE, &sz) >= 0) {
+ size = sz;
+ return (size * 512 / 4096) * 4096 / blocksize;
}
}
#endif
@@ -453,181 +452,11 @@ unsigned long count_blocks (char * filename, int blocksize)
close (fd);
- return (low + 1) / (blocksize);
+ return (low + 1) * 4096 / 4096 / 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)
{
@@ -713,7 +542,7 @@ int reiserfs_bin_search (void * key, void * base, __u32 num, int width,
}
-#define BLOCKLIST__INCREASE_BLOCK_NUMBER 10
+#define BLOCKLIST__ELEMENT_NUMBER 10
/*element is block number and device*/
int blockdev_list_compare (const void * block1, const void * block2) {
@@ -751,17 +580,18 @@ int blocklist__is_block_saved (struct block_handler ** base, __u32 * count,
return 0;
}
*/
-void blocklist__insert_in_position (void ** base, __u32 * count, void * elem,
- int elem_size, __u32 * position) {
+void blocklist__insert_in_position (void *elem, void **base, __u32 *count, int elem_size,
+ __u32 * position)
+{
if (elem_size == 0)
return;
if (*base == NULL)
- *base = getmem (BLOCKLIST__INCREASE_BLOCK_NUMBER * elem_size);
+ *base = getmem (BLOCKLIST__ELEMENT_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);
+ BLOCKLIST__ELEMENT_NUMBER * elem_size);
if (*position < *count) {
memmove (*base + (*position + 1),
@@ -860,3 +690,135 @@ int set_uuid (const unsigned char * text, unsigned char * UUID)
return 0;
}
+/* 0 - dma is not supported, scsi or regular file */
+/* 1 - xt drive */
+/* 2 - ide drive */
+static void get_dma_support(dma_info_t *dma_info){
+ if (S_ISREG(dma_info->stat.st_mode))
+ dma_info->stat.st_rdev = dma_info->stat.st_dev;
+
+ if (IDE_DISK_MAJOR(MAJOR(dma_info->stat.st_rdev))) {
+ dma_info->support_type = 2;
+ return;
+ }
+
+#ifdef XT_DISK_MAJOR
+ if (MAJOR(dma_info->stat.st_rdev) == XT_DISK_MAJOR) {
+ dma_info->support_type = 1;
+ return;
+ }
+#endif
+ dma_info->support_type = 0;
+}
+
+/*
+ * Return values:
+ * 0 - ok;
+ * 1 - preparation cannot be done
+ * -1 - preparation failed
+ */
+int prepare_dma_check(dma_info_t *dma_info) {
+ DIR *dir;
+ struct dirent *dirent;
+ struct stat64 stat;
+ dev_t rdev;
+ int rem;
+ char buf[256];
+
+#ifndef HDIO_GET_DMA
+ return -1;
+#endif
+
+ if (fstat64(dma_info->fd, &dma_info->stat))
+ die("stat64 on device failed\n");
+
+ get_dma_support(dma_info);
+
+ /* dma should be supported */
+ if (dma_info->support_type == 0)
+ return 1;
+
+ if (dma_info->support_type == 2) {
+ rdev = dma_info->stat.st_rdev;
+
+ if ((rem = (MINOR(rdev) % 64)) != 0) {
+ rdev -= rem;
+ if(!(dir = opendir("/dev/"))) {
+ dma_info->support_type = 1;
+ return 0;
+ }
+
+ while ((dirent = readdir(dir)) != NULL) {
+ if (strncmp(dirent->d_name, ".", 1) == 0 || strncmp(dirent->d_name, "..", 2) == 0)
+ continue;
+ memset(buf, 0, 256);
+ strncat(buf, "/dev/", 5);
+ strncat(buf, dirent->d_name, strlen(dirent->d_name));
+ if (stat64(buf, &stat))
+ break;
+ if (S_ISBLK(stat.st_mode) && stat.st_rdev == rdev)
+ {
+ dma_info->stat = stat;
+ dma_info->fd = open(buf, O_RDONLY | O_LARGEFILE);
+ closedir(dir);
+ return 0;
+ }
+ }
+ closedir(dir);
+ dma_info->support_type = 1;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int is_dma_on (int fd) {
+#ifdef HDIO_GET_DMA
+ static long parm;
+ if (ioctl(fd, HDIO_GET_DMA, &parm))
+ return -1;
+ else
+ return parm;
+#endif
+ return 0;
+}
+
+
+static __u64 dma_speed(int fd, int support_type) {
+ static struct hd_driveid id;
+ __u64 speed = 0;
+
+ if (support_type != 2)
+ return 0;
+
+#ifdef HDIO_OBSOLETE_IDENTITY
+ if (!ioctl(fd, HDIO_GET_IDENTITY, &id) ||
+ !ioctl(fd, HDIO_OBSOLETE_IDENTITY)) {
+#else
+ if (!ioctl(fd, HDIO_GET_IDENTITY, &id)) {
+#endif
+ speed |= (__u64)id.dma_1word & ~(__u64)0xff;
+ speed |= ((__u64)id.dma_mword & ~(__u64)0xff) << 16;
+ speed |= ((__u64)id.dma_ultra & ~(__u64)0xff) << 32;
+ } else if (errno == -ENOMSG)
+ return -1;
+ else
+ return -1;
+
+ return speed;
+}
+
+int get_dma_info(dma_info_t *dma_info) {
+ if ((dma_info->dma = is_dma_on(dma_info->fd)) == -1)
+ return -1;
+ if ((dma_info->speed = dma_speed(dma_info->fd, dma_info->support_type)) == (__u64)-1)
+ return -1;
+ return 0;
+}
+
+void clean_after_dma_check(int fd, dma_info_t *dma_info) {
+ signal(SIGALRM, SIG_IGN);
+ if (dma_info->fd && fd != dma_info->fd)
+ close(dma_info->fd);
+}
diff --git a/mkreiserfs/mkreiserfs.8 b/mkreiserfs/mkreiserfs.8
index 5eaec33..0afaf01 100644
--- a/mkreiserfs/mkreiserfs.8
+++ b/mkreiserfs/mkreiserfs.8
@@ -1,7 +1,7 @@
.\" -*- nroff -*-
.\" Copyright 1996-2002 Hans Reiser.
.\"
-.TH MKREISERFS 8 "January 2002" "Reiserfsprogs-3.6.2"
+.TH MKREISERFS 8 "January 2002" "Reiserfsprogs-3.6.4"
.SH NAME
mkreiserfs \- create a Linux ReiserFS file system
.SH SYNOPSIS
diff --git a/mkreiserfs/mkreiserfs.c b/mkreiserfs/mkreiserfs.c
index 1f7c4a1..8d15004 100644
--- a/mkreiserfs/mkreiserfs.c
+++ b/mkreiserfs/mkreiserfs.c
@@ -28,7 +28,6 @@
#include <time.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
-#include <linux/major.h>
#include <sys/stat.h>
#include <linux/kdev_t.h>
#include <sys/utsname.h>
diff --git a/reiserfscore/bitmap.c b/reiserfscore/bitmap.c
index b3b09da..8c08725 100644
--- a/reiserfscore/bitmap.c
+++ b/reiserfscore/bitmap.c
@@ -113,7 +113,12 @@ int reiserfs_bitmap_compare (reiserfs_bitmap_t * bm1, reiserfs_bitmap_t * bm2)
return diff;
}
-
+/*
+ Does X | Y for every bit of the bitmap `to`, where
+ X - bit of the `to` bitmap,
+ Y - `from` bitmap.
+ Save result in the `to` bitmap.
+*/
void reiserfs_bitmap_disjunction (reiserfs_bitmap_t * to, reiserfs_bitmap_t * from)
{
int i;
@@ -130,6 +135,26 @@ void reiserfs_bitmap_disjunction (reiserfs_bitmap_t * to, reiserfs_bitmap_t * fr
}
}
+/*
+ Does X & !Y for every bit of the bitmap `base`, where
+ X - bit of the `base` bitmap,
+ Y - `exclude` bitmap.
+ Save result in the `base` bitmap.
+*/
+void reiserfs_bitmap_delta (reiserfs_bitmap_t * base, reiserfs_bitmap_t * exclude) {
+ int i;
+
+ assert (base->bm_byte_size == exclude->bm_byte_size &&
+ base->bm_bit_size == exclude->bm_bit_size);
+
+ for (i = 0; i < base->bm_bit_size; i++) {
+ if (test_bit(i, exclude->bm_map) && test_bit(i, base->bm_map)) {
+ clear_bit(i, base->bm_map);
+ base->bm_set_bits --;
+ base->bm_dirty = 1;
+ }
+ }
+}
void reiserfs_bitmap_set_bit (reiserfs_bitmap_t * bm, unsigned int bit_number)
{
diff --git a/reiserfscore/do_balan.c b/reiserfscore/do_balan.c
index f771869..10e0734 100644
--- a/reiserfscore/do_balan.c
+++ b/reiserfscore/do_balan.c
@@ -1,5 +1,6 @@
/*
- * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details
+ * Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Hans Reiser, see
+ * reiserfs/README for licensing and copyright details
*/
/* Now we have all buffers that must be used in balancing of the tree */
@@ -181,7 +182,7 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
const char * body, /* body of inserted item or bytes to paste */
int flag, /* i - insert, d - delete, c - cut, p - paste
(see comment to do_balance) */
- int zeros_number, /* will be commented later */
+ int zeros_number, /* it is always 0 */
struct item_head * insert_key, /* in our processing of one level we sometimes determine what
must be inserted into the next higher level. This insertion
@@ -247,7 +248,8 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
/* Calculate key component, item length and body to insert into S[0] */
//ih->ih_key.k_offset += tb->lbytes;
- set_offset (key_format (&ih->ih_key), &ih->ih_key, get_offset (&ih->ih_key) + tb->lbytes);
+ set_offset (key_format (&ih->ih_key), &ih->ih_key, get_offset (&ih->ih_key) +
+ tb->lbytes * (is_indirect_ih(ih) ? tb->tb_fs->fs_blocksize / UNFM_P_SIZE : 1) );
set_ih_item_len (ih, new_item_len);
if ( tb->lbytes > zeros_number ) {
body += (tb->lbytes - zeros_number);
@@ -318,8 +320,8 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
/* regular object */
if ( tb->lbytes >= pos_in_item ) {
/* appended item will be in L[0] in whole */
- int l_n;
- struct key * key;
+ int l_n, temp_n;
+ struct key * key;
/* this bytes number must be appended to the last item of L[h] */
l_n = tb->lbytes - pos_in_item;
@@ -338,14 +340,18 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
get_ih_item_len (B_N_PITEM_HEAD(tb->L[0],n+item_pos-ret_val)),
l_n,body, zeros_number > l_n ? l_n : zeros_number);
+
/* 0-th item in S0 can be only of DIRECT type when l_n != 0*/
//B_N_PKEY (tbS0, 0)->k_offset += l_n;z
key = B_N_PKEY (tbS0, 0);
- set_offset (key_format (key), key, get_offset (key) + l_n);
+ temp_n = (is_indirect_ih(B_N_PITEM_HEAD (tb->L[0], n + item_pos - ret_val))) ?
+ (l_n / UNFM_P_SIZE) * tb->tb_fs->fs_blocksize : l_n;
+
+ set_offset (key_format (key), key, get_offset (key) + temp_n);
//B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0])->k_offset += l_n;
key = B_N_PDELIM_KEY(tb->CFL[0],tb->lkey[0]);
- set_offset (key_format (key), key, get_offset (key) + l_n);
+ set_offset (key_format (key), key, get_offset (key) + temp_n);
/* Calculate new body, position in item and insert_size[0] */
if ( l_n > zeros_number ) {
@@ -397,8 +403,7 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
/* if appended item is indirect item, put unformatted node into un list */
if (I_IS_INDIRECT_ITEM (pasted))
- set_ih_free_space (pasted, ((struct unfm_nodeinfo*)body)->unfm_freespace);
- //pasted->u.ih_free_space = ((struct unfm_nodeinfo*)body)->unfm_freespace;
+ set_ih_free_space (pasted, 0);
tb->insert_size[0] = 0;
zeros_number = 0;
@@ -427,8 +432,9 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
/* new item or its part falls to R[0] */
if ( item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1 ) {
/* part of new item falls into R[0] */
- int old_key_comp, old_len, r_zeros_number;
+ loff_t old_key_comp, old_len, r_zeros_number;
const char * r_body;
+ loff_t multiplyer;
leaf_shift_right(tb, tb->rnum[0] - 1, -1);
@@ -436,22 +442,24 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
old_key_comp = get_offset (&ih->ih_key);
old_len = get_ih_item_len (ih);
+ multiplyer = is_indirect_ih(ih) ? tb->tb_fs->fs_blocksize / UNFM_P_SIZE : 1;
/* Calculate key component and item length to insert into R[0] */
//ih->ih_key.k_offset += (old_len - tb->rbytes);
- set_offset (key_format (&ih->ih_key), &ih->ih_key, old_key_comp + old_len - tb->rbytes);
+ set_offset (key_format (&ih->ih_key), &ih->ih_key, old_key_comp +
+ (old_len - tb->rbytes) * multiplyer );
set_ih_item_len (ih, tb->rbytes);
/* Insert part of the item into R[0] */
bi.bi_bh = tb->R[0];
bi.bi_parent = tb->FR[0];
bi.bi_position = get_right_neighbor_position (tb, 0);
- if ( get_offset (&ih->ih_key) - old_key_comp > zeros_number ) {
+ if (old_len - tb->rbytes > zeros_number ) {
r_zeros_number = 0;
- r_body = body + get_offset (&ih->ih_key) - old_key_comp - zeros_number;
+ r_body = body + old_len - tb->rbytes - zeros_number;
}
- else {
+ else { /* zeros_number is always 0 */
r_body = body;
- r_zeros_number = zeros_number - (get_offset (&ih->ih_key) - old_key_comp);
+ r_zeros_number = zeros_number - old_len - tb->rbytes;
zeros_number -= r_zeros_number;
}
@@ -552,13 +560,20 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
if ( (n_rem = tb->insert_size[0] - tb->rbytes) < 0 )
n_rem = 0;
- //B_N_PKEY(tb->R[0],0)->k_offset += n_rem;
- key = B_N_PKEY(tb->R[0],0);
- set_offset (key_format (key), key, get_offset (key) + n_rem);
+ {
+ unsigned long temp_rem = n_rem;
+
+ if (is_indirect_key(B_N_PKEY(tb->R[0],0)))
+ temp_rem = (n_rem / UNFM_P_SIZE) * tb->tb_fs->fs_blocksize;
- //B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])->k_offset += n_rem;
- key = B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0]);
- set_offset (key_format (key), key, get_offset (key) + n_rem);
+ //B_N_PKEY(tb->R[0],0)->k_offset += n_rem;
+ key = B_N_PKEY(tb->R[0],0);
+ set_offset (key_format (key), key, get_offset (key) + temp_rem);
+
+ //B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0])->k_offset += n_rem;
+ key = B_N_PDELIM_KEY(tb->CFR[0],tb->rkey[0]);
+ set_offset (key_format (key), key, get_offset (key) + temp_rem);
+ }
mark_buffer_dirty (tb->CFR[0]);
@@ -579,8 +594,7 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
leaf_paste_in_buffer(tb->tb_fs, &bi, 0, n_shift, tb->insert_size[0] - n_rem, r_body, r_zeros_number);
if (I_IS_INDIRECT_ITEM(B_N_PITEM_HEAD(tb->R[0],0))) {
- set_ih_free_space (B_N_PITEM_HEAD(tb->R[0],0), ((struct unfm_nodeinfo*)body)->unfm_freespace);
- //B_N_PITEM_HEAD(tb->R[0],0)->u.ih_free_space = ((struct unfm_nodeinfo*)body)->unfm_freespace;
+ set_ih_free_space (B_N_PITEM_HEAD(tb->R[0],0), 0);
}
tb->insert_size[0] = n_rem;
@@ -616,8 +630,7 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
}
if (I_IS_INDIRECT_ITEM (pasted))
- //pasted->u.ih_free_space = ((struct unfm_nodeinfo*)body)->unfm_freespace;
- set_ih_free_space (pasted, ((struct unfm_nodeinfo*)body)->unfm_freespace);
+ set_ih_free_space (pasted, 0);
zeros_number = tb->insert_size[0] = 0;
}
}
@@ -679,6 +692,7 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
/* part of new item falls into S_new[i] */
int old_key_comp, old_len, r_zeros_number;
const char * r_body;
+ loff_t multiplyer;
/* Move snum[i]-1 items from S[0] to S_new[i] */
leaf_move_items (LEAF_FROM_S_TO_SNEW, tb, snum[i] - 1, -1, S_new[i]);
@@ -686,10 +700,12 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
/* Remember key component and item length */
old_key_comp = get_offset (&ih->ih_key);
old_len = get_ih_item_len (ih);
+ multiplyer = is_indirect_ih(ih) ? tb->tb_fs->fs_blocksize / UNFM_P_SIZE : 1;
/* Calculate key component and item length to insert into S_new[i] */
//ih->ih_key.k_offset += (old_len - sbytes[i]);
- set_offset (key_format (&ih->ih_key), &ih->ih_key, old_key_comp + old_len - sbytes[i]);
+ set_offset (key_format (&ih->ih_key), &ih->ih_key, old_key_comp +
+ (old_len - sbytes[i]) * multiplyer);
set_ih_item_len (ih, sbytes[i]);
@@ -698,13 +714,13 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
bi.bi_parent = 0;
bi.bi_position = 0;
- if ( get_offset (&ih->ih_key) - old_key_comp > zeros_number ) {
+ if ( old_len - sbytes[i] > zeros_number ) {
r_zeros_number = 0;
- r_body = body + (get_offset (&ih->ih_key) - old_key_comp) - zeros_number;
+ r_body = body + (old_len - sbytes[i]) - zeros_number;
}
else {
r_body = body;
- r_zeros_number = zeros_number - (get_offset (&ih->ih_key) - old_key_comp);
+ r_zeros_number = zeros_number - (old_len - sbytes[i]);
zeros_number -= r_zeros_number;
}
@@ -809,15 +825,20 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
leaf_paste_in_buffer(tb->tb_fs, &bi, 0, n_shift, tb->insert_size[0]-n_rem, r_body,r_zeros_number);
tmp = B_N_PITEM_HEAD (S_new[i], 0);
if (I_IS_INDIRECT_ITEM(tmp)) {
+/*
if (n_rem)
reiserfs_panic ("PAP-12230: balance_leaf: "
"invalid action with indirect item");
- //tmp->u.ih_free_space = ((struct unfm_nodeinfo*)body)->unfm_freespace;
- set_ih_free_space (tmp, ((struct unfm_nodeinfo*)body)->unfm_freespace);
- }
+ set_ih_free_space (tmp, 0);
+*/
+ set_ih_free_space (tmp, 0);
+ set_offset( key_format (&tmp->ih_key), &tmp->ih_key, get_offset(&tmp->ih_key) +
+ (n_rem / UNFM_P_SIZE) * tb->tb_fs->fs_blocksize);
+ } else
+ set_offset (key_format (&tmp->ih_key), &tmp->ih_key, get_offset (&tmp->ih_key) + n_rem);
//B_N_PKEY(S_new[i],0)->k_offset += n_rem;
- set_offset (key_format (&tmp->ih_key), &tmp->ih_key, get_offset (&tmp->ih_key) + n_rem);
+//
tb->insert_size[0] = n_rem;
if ( ! n_rem )
@@ -845,8 +866,7 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
/* if we paste to indirect item update ih_free_space */
if (I_IS_INDIRECT_ITEM (pasted))
- //pasted->u.ih_free_space = ((struct unfm_nodeinfo*)body)->unfm_freespace;
- set_ih_free_space (pasted, ((struct unfm_nodeinfo*)body)->unfm_freespace);
+ set_ih_free_space (pasted, 0);
zeros_number = tb->insert_size[0] = 0;
}
} else {
@@ -914,8 +934,7 @@ static int balance_leaf(/*struct reiserfs_transaction_handle *th, */
leaf_paste_in_buffer (tb->tb_fs, &bi, item_pos, pos_in_item, tb->insert_size[0], body, zeros_number);
if (I_IS_INDIRECT_ITEM (pasted)) {
- //pasted->u.ih_free_space = ((struct unfm_nodeinfo*)body)->unfm_freespace;
- set_ih_free_space (pasted, ((struct unfm_nodeinfo*)body)->unfm_freespace);
+ set_ih_free_space (pasted, 0);
}
tb->insert_size[0] = 0;
}
diff --git a/reiserfscore/fix_node.c b/reiserfscore/fix_node.c
index 4968faa..7e004b9 100644
--- a/reiserfscore/fix_node.c
+++ b/reiserfscore/fix_node.c
@@ -1,5 +1,6 @@
/*
- * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details
+ * Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Hans Reiser, see
+ * reiserfs/README for licensing and copyright details
*/
/**
@@ -365,7 +366,7 @@ static int check_left (struct tree_balance * tb, int h, int cur_free)
}
- reiserfs_panic (0, "vs: 8065: check_left: all items fit in the left neighbor");
+ reiserfs_panic (0, "vs-8065: check_left: all items fit in the left neighbor");
return 0;
}
@@ -1474,12 +1475,12 @@ static int ip_check_balance (/*struct reiserfs_transaction_handle *th,*/ struct
int lfree, sfree, rfree /* free space in L, S and R */;
- /* nver is short for number of vertixes, and lnver is the number if we
+ /* nver is short for number of vertices, and lnver is the number if we
shift to the left, rnver is the number if we shift to the right, and
lrnver is the number if we shift in both directions. The goal is to
- minimize first the number of vertixes, and second, the number of
- vertixes whose contents are changed by shifting, and third the number
- of uncached vertixes whose contents are changed by shifting and must be
+ minimize first the number of vertices, and second, the number of
+ vertices whose contents are changed by shifting, and third the number
+ of uncached vertices whose contents are changed by shifting and must be
read from disk. */
int nver, lnver, rnver, lrnver;
@@ -1642,7 +1643,7 @@ static int ip_check_balance (/*struct reiserfs_transaction_handle *th,*/ struct
/* calculate number of blocks S[h] must be split into when l_shift_num
first items and l_shift_bytes of the right most liquid item to be
shifted are shifted to the left neighbor, as well as number of
- items in each part of the splitted node (s012 numbers), and number
+ items in each part of the split node (s012 numbers), and number
of bytes (s1bytes) of the shared drop which flow to S1 if any */
lset = LEFT_SHIFT_NO_FLOW;
lnver = get_num_ver (vn->vn_mode, tb, h,
@@ -1754,7 +1755,7 @@ static int ip_check_balance (/*struct reiserfs_transaction_handle *th,*/ struct
/* Check whether current node S[h] is balanced when Decreasing its size by
- * Deleting or Cutting for INTERNAL node of S+tree.
+ * Deleting or Cutting for INTERNAL node of internal tree.
* Calculate parameters for balancing for current level h.
* Parameters:
* tb tree_balance structure;
@@ -1767,7 +1768,7 @@ static int ip_check_balance (/*struct reiserfs_transaction_handle *th,*/ struct
* -2 - no disk space.
*
* Note: Items of internal nodes have fixed size, so the balance condition for
- * the internal part of S+tree is as for the B-trees.
+ * the internal part of internal tree is as for the B-trees.
*/
static int dc_check_balance_internal (struct tree_balance * tb, int h)
{
@@ -1911,7 +1912,7 @@ static int dc_check_balance_internal (struct tree_balance * tb, int h)
/* Check whether current node S[h] is balanced when Decreasing its size by
- * Deleting or Truncating for LEAF node of S+tree.
+ * Deleting or Truncating for LEAF node of internal tree.
* Calculate parameters for balancing for current level h.
* Parameters:
* tb tree_balance structure;
@@ -2279,7 +2280,7 @@ int fix_nodes (int n_op_mode, struct tree_balance * p_s_tb,
p_s_tb->insert_size[n_h + 1] = (DC_SIZE + KEY_SIZE) * (p_s_tb->blknum[n_h] - 1);
}
- return CARRY_ON; /* go ahead and balsnce */
+ return CARRY_ON; /* go ahead and balance */
}
diff --git a/reiserfscore/hashes.c b/reiserfscore/hashes.c
index 930e83a..041ad55 100644
--- a/reiserfscore/hashes.c
+++ b/reiserfscore/hashes.c
@@ -1,4 +1,9 @@
/*
+ * Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Hans Reiser, see
+ * reiserfs/README for licensing and copyright details
+ */
+
+/*
* Keyed 32-bit hash function using TEA in a Davis-Meyer function
* H0 = Key
* Hi = E Mi(Hi-1) + Hi-1
diff --git a/reiserfscore/ibalance.c b/reiserfscore/ibalance.c
index 7766ab9..53c68fc 100644
--- a/reiserfscore/ibalance.c
+++ b/reiserfscore/ibalance.c
@@ -1,5 +1,6 @@
/*
- * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details
+ * Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Hans Reiser, see
+ * reiserfs/README for licensing and copyright details
*/
#include "includes.h"
diff --git a/reiserfscore/includes.h b/reiserfscore/includes.h
index 2e6aabd..f501cc6 100644
--- a/reiserfscore/includes.h
+++ b/reiserfscore/includes.h
@@ -1,5 +1,6 @@
/*
- * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
+ * Copyright 2000, 2001, 2002 by Hans Reiser, licensing governed by
+ * reiserfs/README
*/
#define _GNU_SOURCE
#include <stdio.h>
diff --git a/reiserfscore/journal.c b/reiserfscore/journal.c
index 4f53e23..97250cb 100644
--- a/reiserfscore/journal.c
+++ b/reiserfscore/journal.c
@@ -4,7 +4,7 @@
#include "includes.h"
-/* this provides for everybody who wants to deal with journal */
+/* this is provided for anybody 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);
@@ -38,7 +38,7 @@ unsigned long commit_expected (reiserfs_filsys_t * fs, struct buffer_head * d_bh
}
-/* d_bh contains journal descriptor, return number of block where descriptor
+/* d_bh contains journal descriptor, returns 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)
{
@@ -77,8 +77,8 @@ int is_valid_transaction (reiserfs_filsys_t * fs, struct buffer_head * d_bh)
}
-/* read the journal and find the oldest and newest transactions, return numbe
- of transactions fond */
+/* read the journal and find the oldest and newest transactions, return number
+ of transactions found */
int get_boundary_transactions (reiserfs_filsys_t * fs,
reiserfs_trans_t * oldest,
reiserfs_trans_t * newest)
@@ -91,7 +91,6 @@ int get_boundary_transactions (reiserfs_filsys_t * fs,
__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));
@@ -119,7 +118,7 @@ int get_boundary_transactions (reiserfs_filsys_t * fs,
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;
+ oldest->next_trans_offset = next_desc_expected (fs, d_bh) - j_start;
}
if (trans_id > newest_trans_id) {
@@ -145,7 +144,7 @@ int get_boundary_transactions (reiserfs_filsys_t * fs,
#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 */
+ trans id which is greater 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;
@@ -439,18 +438,28 @@ int reiserfs_open_journal (reiserfs_filsys_t * fs, char * j_filename, int flags)
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;
+ 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;
}
+ } else {
+ if (get_jp_journal_dev (sb_jp(sb)) != 0 ||
+ get_jp_journal_1st_block (sb_jp(sb)) != get_journal_start_must (fs) ||
+ get_jp_journal_size (sb_jp(sb)) != journal_default_size(fs->fs_super_bh->b_blocknr, fs->fs_blocksize))
+ {
+ reiserfs_warning (stderr, "reiserfs_open_journal: wrong journal parameters found in the super block.\n");
+ 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,
@@ -479,7 +488,7 @@ int reiserfs_create_journal (reiserfs_filsys_t * fs, char * j_filename,
// 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",
+ "cannot create filesystem on %d blocks\n",
get_sb_block_count (sb));
return 0;
}
@@ -507,7 +516,7 @@ int reiserfs_create_journal (reiserfs_filsys_t * fs, char * j_filename,
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"
+ "NOTE: journal new size %lu is greater 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);
diff --git a/reiserfscore/lbalance.c b/reiserfscore/lbalance.c
index 2800e78..c2645dc 100644
--- a/reiserfscore/lbalance.c
+++ b/reiserfscore/lbalance.c
@@ -1,5 +1,6 @@
/*
- * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details
+ * Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Hans Reiser, see
+ * reiserfs/README for licensing and copyright details
*/
#include "includes.h"
diff --git a/reiserfscore/node_formats.c b/reiserfscore/node_formats.c
index 28cc349..119e099 100644
--- a/reiserfscore/node_formats.c
+++ b/reiserfscore/node_formats.c
@@ -1,5 +1,6 @@
/*
- * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
+ * Copyright 2000, 2001, 2002 by Hans Reiser, licensing governed by
+ * reiserfs/README
*/
@@ -235,11 +236,14 @@ int is_prejournaled_reiserfs (struct reiserfs_super_block * rs)
strlen(REISERFS_3_5_SUPER_MAGIC_STRING)));
}
-int does_look_like_super_block (struct reiserfs_super_block * sb, int blocksize) {
- if (is_any_reiserfs_magic_string (sb) && blocksize == get_sb_block_size (sb))
- return 1;
-
- return 0;
+int does_look_like_super_block (struct reiserfs_super_block * sb) {
+ if (!is_any_reiserfs_magic_string (sb))
+ return 0;
+
+ if (!is_blocksize_correct(get_sb_block_size (sb)))
+ return 0;
+
+ return 1;
}
@@ -248,7 +252,7 @@ int does_look_like_super_block (struct reiserfs_super_block * sb, int blocksize)
int who_is_this (char * buf, int blocksize)
{
/* super block? */
- if (does_look_like_super_block ((void *)buf, blocksize))
+ if (does_look_like_super_block ((void *)buf))
return THE_SUPER;
if (does_node_look_like_a_leaf (buf, blocksize))
@@ -1350,6 +1354,6 @@ void mark_objectid_used (reiserfs_filsys_t * fs, __u32 objectid)
int is_blocksize_correct (int blocksize)
{
- return ((blocksize % 1024) ? 0 : 1);
+ return ((blocksize == 0) || (blocksize % 1024) ? 0 : 1);
}
diff --git a/reiserfscore/prints.c b/reiserfscore/prints.c
index 13a7c91..f43b5bd 100644
--- a/reiserfscore/prints.c
+++ b/reiserfscore/prints.c
@@ -1,5 +1,6 @@
/*
- * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details
+ * Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Hans Reiser, see
+ * reiserfs/README for licensing and copyright details
*/
#include "includes.h"
@@ -7,25 +8,47 @@
#include <limits.h>
#include <printf.h>
+#define PA_KEY (PA_LAST)
+#define PA_BUFFER_HEAD (PA_LAST + 1)
+#define PA_ITEM_HEAD (PA_LAST + 2)
+#define PA_DISK_CHILD (PA_LAST + 3)
-static int _arginfo (const struct printf_info *info, size_t n,
- int *argtypes)
-{
+
+static int _arginfo_b (const struct printf_info *info, size_t n, int *argtypes) {
if (n > 0)
- argtypes[0] = PA_POINTER;
+ argtypes[0] = PA_BUFFER_HEAD | PA_FLAG_PTR;
return 1;
}
-#if 0
-static int _arginfo2 (const struct printf_info *info, size_t n,
- int *argtypes)
-{
+static int _arginfo_K (const struct printf_info *info, size_t n, int *argtypes) {
+ if (n > 0)
+ argtypes[0] = PA_KEY | PA_FLAG_PTR;
+ return 1;
+}
+
+static int _arginfo_H (const struct printf_info *info, size_t n, int *argtypes) {
+ if (n > 0)
+ argtypes[0] = PA_ITEM_HEAD | PA_FLAG_PTR;
+ return 1;
+}
+
+static int _arginfo_y (const struct printf_info *info, size_t n, int *argtypes) {
if (n > 0)
- argtypes[0] = PA_INT;
+ argtypes[0] = PA_DISK_CHILD | PA_FLAG_PTR;
return 1;
}
-#endif
+static int _arginfo_M (const struct printf_info *info, size_t n, int *argtypes) {
+ if (n > 0)
+ argtypes[0] = PA_INT | PA_FLAG_SHORT | PA_FLAG_PTR;
+ return 1;
+}
+
+static int _arginfo_U (const struct printf_info *info, size_t n, int *argtypes) {
+ if (n > 0)
+ argtypes[0] = (PA_CHAR|PA_FLAG_PTR);
+ return 1;
+}
#define FPRINTF \
if (len == -1) {\
@@ -63,7 +86,7 @@ static int print_short_key (FILE * stream,
int len;
key = *((const struct key **)(args[0]));
- len = asprintf (&buffer, "%u %u", get_key_dirid (key),
+ len = asprintf (&buffer, "[%u %u]", get_key_dirid (key),
get_key_objectid (key));
FPRINTF;
}
@@ -79,7 +102,7 @@ static int print_key (FILE * stream,
int len;
key = *((const struct key **)(args[0]));
- len = asprintf (&buffer, "%u %u 0x%Lx %s (%d)",
+ 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;
@@ -186,7 +209,7 @@ static int print_sd_uuid (FILE * stream,
return len;
}
-void reiserfs_warning (FILE * fp, const char * fmt, ...)
+void reiserfs_warning (FILE * fp, const char * fmt, ...)
{
static int registered = 0;
va_list args;
@@ -194,13 +217,13 @@ void reiserfs_warning (FILE * fp, const char * fmt, ...)
if (!registered) {
registered = 1;
- register_printf_function ('K', print_short_key, _arginfo);
- register_printf_function ('k', print_key, _arginfo);
- register_printf_function ('H', print_item_head, _arginfo);
- 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);
+ register_printf_function ('K', print_short_key, _arginfo_K);
+ register_printf_function ('k', print_key, _arginfo_K);
+ register_printf_function ('H', print_item_head, _arginfo_H);
+ register_printf_function ('b', print_block_head, _arginfo_b);
+ register_printf_function ('y', print_disk_child, _arginfo_y);
+ register_printf_function ('M', print_sd_mode, _arginfo_M);
+ register_printf_function ('U', print_sd_uuid, _arginfo_U);
}
va_start (args, fmt);
@@ -389,7 +412,7 @@ static int print_stat_data (FILE * fp, struct buffer_head * bh, struct item_head
int retval;
- /* we can not figure out whether it is new stat data or old by key_format
+ /* we cannot figure out if it is new stat data or old by key_format
macro. Stat data's key looks identical in both formats */
if (get_ih_key_format (ih) == KEY_FORMAT_1) {
struct stat_data_v1 * sd_v1 = (struct stat_data_v1 *)B_I_PITEM (bh, ih);
@@ -421,8 +444,8 @@ static int print_stat_data (FILE * fp, struct buffer_head * bh, struct item_head
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);
+ reiserfs_warning (fp, "block %lu, item %d: %H\n",
+ bh->b_blocknr, (ih - B_N_PITEM_HEAD (bh, 0))/sizeof(struct item_head), ih);
if (is_stat_data_ih (ih)) {
print_stat_data (fp, bh, ih, 0/*all times*/);
return;
@@ -585,7 +608,7 @@ int print_super_block (FILE * fp, reiserfs_filsys_t * fs, char * file_name,
dev_t rdev;
int format = 0;
- if (!does_look_like_super_block (sb, fs->fs_blocksize))
+ if (!does_look_like_super_block (sb))
return 1;
rdev = get_st_rdev (file_name);
diff --git a/reiserfscore/reiserfslib.c b/reiserfscore/reiserfslib.c
index 1b92c0b..454a593 100644
--- a/reiserfscore/reiserfslib.c
+++ b/reiserfscore/reiserfslib.c
@@ -1,9 +1,8 @@
/*
- * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
+ * Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
*/
#include "includes.h"
-#include <linux/major.h>
#include <linux/kdev_t.h>
struct key root_dir_key = {0, 0, {{0, 0},}};
@@ -81,9 +80,7 @@ reiserfs_filsys_t * reiserfs_open (char * filename, int flags, int *error, void
} else {
sb = (struct reiserfs_super_block *)bh->b_data;
- if (is_any_reiserfs_magic_string (sb))
- /* fixme: we could make some check to make sure that super
- block looks correctly */
+ if (does_look_like_super_block (sb))
goto found;
/* reiserfs signature is not found at the i-th 4k block */
@@ -93,6 +90,7 @@ reiserfs_filsys_t * reiserfs_open (char * filename, int flags, int *error, void
reiserfs_warning (stderr, "reiserfs_open: neither new nor old reiserfs format "
"found on %s\n", filename);
+
if (error)
*error = 0;
freemem (fs);
@@ -101,9 +99,9 @@ reiserfs_filsys_t * reiserfs_open (char * filename, int flags, int *error, void
return fs;
found:
-
+
fs->fs_blocksize = get_sb_block_size (sb);
-
+
/* check block size on the filesystem */
if (fs->fs_blocksize != 4096) {
i = bh->b_blocknr * 4096 / fs->fs_blocksize;
@@ -115,13 +113,7 @@ reiserfs_filsys_t * reiserfs_open (char * filename, int flags, int *error, void
freemem (fs);
return 0;
}
- sb = (struct reiserfs_super_block *)bh->b_data;
- if (!does_look_like_super_block (sb, fs->fs_blocksize)) {
- reiserfs_warning (stderr, "reiserfs_open: no reiserfs in %d, size %d\n",
- i, fs->fs_blocksize);
- freemem (fs);
- return 0;
- }
+ sb = (struct reiserfs_super_block *)bh->b_data;
}
fs->fs_hash_function = code2func (get_sb_hash_code (sb));
@@ -1185,34 +1177,8 @@ int can_we_format_it (char * device_name, int force)
reiserfs_warning (stderr, "%s is not a block special device", device_name);
check_forcing_ask_confirmation (force);
} else {
- /* from e2progs-1.18/misc/mke2fs.c */
-
-
-/*FIXME: it should be probably rewritten for 2.5 later*/
-#ifndef MAJOR
-#define MAJOR(dev) ((dev)>>8)
-#define MINOR(dev) ((dev) & 0xff)
-#endif
-#ifndef SCSI_BLK_MAJOR
-#define SCSI_BLK_MAJOR(M) ((M) == SCSI_DISK_MAJOR || (M) == SCSI_CDROM_MAJOR)
-#endif
-
-#ifndef IDE_DISK_MAJOR
-#ifdef IDE9_MAJOR
-#define IDE_DISK_MAJOR(M) (MAJOR(rdev) == IDE0_MAJOR || MAJOR(rdev) == IDE1_MAJOR || \
- MAJOR(rdev) == IDE2_MAJOR || MAJOR(rdev) == IDE3_MAJOR || \
- MAJOR(rdev) == IDE4_MAJOR || MAJOR(rdev) == IDE5_MAJOR || \
- MAJOR(rdev) == IDE6_MAJOR || MAJOR(rdev) == IDE7_MAJOR || \
- MAJOR(rdev) == IDE8_MAJOR || MAJOR(rdev) == IDE9_MAJOR)
-#else
-#define IDE_DISK_MAJOR(M) (MAJOR(rdev) == IDE0_MAJOR || MAJOR(rdev) == IDE1_MAJOR || \
- MAJOR(rdev) == IDE2_MAJOR || MAJOR(rdev) == IDE3_MAJOR || \
- MAJOR(rdev) == IDE4_MAJOR || MAJOR(rdev) == IDE5_MAJOR)
-#endif
-#endif
-
- if ((IDE_DISK_MAJOR (MAJOR(rdev)) && MINOR (rdev) % 64 == 0) ||
- (SCSI_BLK_MAJOR (MAJOR(rdev)) && MINOR (rdev) % 16 == 0)) {
+ if ((IDE_DISK_MAJOR (MAJOR(rdev)) && MINOR(rdev) % 64 == 0) ||
+ (SCSI_BLK_MAJOR (MAJOR(rdev)) && MINOR(rdev) % 16 == 0)) {
/* /dev/hda or similar */
reiserfs_warning (stderr, "%s is entire device, not just one partition!",
device_name);
@@ -1223,107 +1189,6 @@ int can_we_format_it (char * device_name, int force)
return 1;
}
-
-#if 0
-/*tune*/
-#define check_forcing_ask_confirmation() \
- if (!Force) {\
- /* avoid formatting it without being forced */\
- reiserfs_warning (stderr, "Use -f to force over\n");\
- return 0;\
- }\
- if (Force == 1) {\
- if (!user_confirmed (stderr, "Continue (y/n):", "y\n"))\
- return 0;\
- }\
-
-
-/* we only can use a file for filesystem or journal if it is either not
- mounted block device or regular file and we are forced to use it */
-static int can_we_format_it (char * device_name)
-{
- mode_t mode;
- dev_t rdev;
-
-
- if (is_mounted (device_name)) {
- /* device looks mounted */
- message("'%s' looks mounted.\n", device_name);
- check_forcing_ask_confirmation ();
- }
-
- mode = get_st_mode (device_name);
- rdev = get_st_rdev (device_name);
-
- if (!S_ISBLK (mode)) {
- /* file is not a block device */
- message("Can not create a journal on not a block device file %s\n", device_name);
- exit (1);
- } else {
- /* from e2progs-1.18/misc/mke2fs.c */
- if ((MAJOR (rdev) == HD_MAJOR && MINOR (rdev) % 64 == 0) ||
- (SCSI_BLK_MAJOR (rdev) && MINOR (rdev) % 16 == 0)) {
- /* /dev/hda or similar */
- message("%s is entire device, not just one partition!\n",
- device_name);
- check_forcing_ask_confirmation ();
- }
- }
-
- return 1;
-}
-
-
-/*mkreiserfs*/
-/* we only can use a file for filesystem or journal if it is either not
- mounted block device or regular file and we are forced to use it */
-static int can_we_format_it (char * device_name, int force)
-{
- mode_t mode;
- dev_t rdev;
-
- if (is_mounted (device_name)) {
- /* device looks mounted */
- message("'%s' looks mounted.", device_name);
- check_forcing_ask_confirmation ();
- }
-
- mode = get_st_mode (device_name);
- rdev = get_st_rdev (device_name);
-
- if (!S_ISBLK (mode)) {
- /* file is not a block device */
- message("%s is not a block special device", device_name);
- check_forcing_ask_confirmation ();
- } else {
- if (((MAJOR (rdev) == IDE0_MAJOR ||
- MAJOR (rdev) == IDE1_MAJOR ||
- MAJOR (rdev) == IDE2_MAJOR ||
- MAJOR (rdev) == IDE3_MAJOR ||
- MAJOR (rdev) == IDE4_MAJOR ||
- MAJOR (rdev) == IDE5_MAJOR ||
- MAJOR (rdev) == IDE6_MAJOR ||
- MAJOR (rdev) == IDE7_MAJOR ||
- MAJOR (rdev) == IDE8_MAJOR ||
- MAJOR (rdev) == IDE9_MAJOR) &&
- MINOR (rdev) % 64 == 0) ||
- (SCSI_BLK_MAJOR (MAJOR (rdev)) &&
- MINOR (rdev) % 16 == 0)) {
- /* /dev/hda or similar */
- message("%s is entire device, not just one partition!",
- device_name);
- check_forcing_ask_confirmation ();
- }
- }
-
- return 1;
-}
-
-#endif
-
-
-
-
int create_badblock_bitmap (reiserfs_filsys_t * fs, char * badblocks_file) {
FILE * fd;
char buf[128];
@@ -1368,7 +1233,7 @@ void add_badblock_list (reiserfs_filsys_t * fs, int no_badblock_in_tree_yet) {
struct item_head * tmp_ih;
struct item_head badblock_ih;
// char item[UNFM_P_SIZE];
- struct unfm_nodeinfo ni;
+ __u32 ni;
__u64 offset;
__u32 i, j;
@@ -1416,7 +1281,6 @@ void add_badblock_list (reiserfs_filsys_t * fs, int no_badblock_in_tree_yet) {
set_type (KEY_FORMAT_2, &badblock_ih.ih_key, TYPE_INDIRECT);
j = 0;
- ni.unfm_freespace = 0;
/* insert all badblock pointers */
for (i = 0; i < fs->fs_badblocks_bm->bm_bit_size; i++) {
@@ -1427,7 +1291,7 @@ void add_badblock_list (reiserfs_filsys_t * fs, int no_badblock_in_tree_yet) {
offset = j * fs->fs_blocksize + 1;
set_offset (KEY_FORMAT_2, &badblock_ih.ih_key, offset);
- ni.unfm_nodenum = cpu_to_le32 (i);
+ ni = cpu_to_le32 (i);
retval = usearch_by_position (fs, &badblock_ih.ih_key, key_format (&badblock_ih.ih_key), &badblock_path);
@@ -1436,7 +1300,7 @@ void add_badblock_list (reiserfs_filsys_t * fs, int no_badblock_in_tree_yet) {
init_tb_struct (&tb, fs, &badblock_path, IH_SIZE + get_ih_item_len(&badblock_ih));
if (fix_nodes (/*tb.transaction_handle,*/ M_INSERT, &tb, &badblock_ih/*, body*/) != CARRY_ON)
die ("reiserfsck_insert_item: fix_nodes failed");
- do_balance (/*tb.transaction_handle,*/ &tb, &badblock_ih, (void *)&ni.unfm_nodenum , M_INSERT, 0/*zero num*/);
+ do_balance (/*tb.transaction_handle,*/ &tb, &badblock_ih, (void *)&ni , M_INSERT, 0/*zero num*/);
// reiserfsck_insert_item (&badblock_path, &badblock_ih, item);
diff --git a/reiserfscore/stree.c b/reiserfscore/stree.c
index cde7c7e..9c53928 100644
--- a/reiserfscore/stree.c
+++ b/reiserfscore/stree.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details
+ * Copyright 1996-2002 Hans Reiser, see reiserfs/README for licensing and copyright details
*/
/*
@@ -9,7 +9,7 @@
*/
/*
- * This file contains functions dealing with S+tree
+ * This file contains functions dealing with internal tree
*
* comp_keys
* comp_short_keys
@@ -280,7 +280,7 @@ void pathrelse (struct path * p_s_search_path)
/**************************************************************************
* Algorithm SearchByKey *
- * look for item in the Disk S+Tree by its key *
+ * look for item in internal tree on the disk by its key *
* Input: p_s_sb - super block *
* p_s_key - pointer to the key to search *
* Output: true value - 1 - found, 0 - not found *
diff --git a/reiserfsprogs.spec b/reiserfsprogs.spec
index 8f30758..8dfd901 100644
--- a/reiserfsprogs.spec
+++ b/reiserfsprogs.spec
@@ -1,4 +1,4 @@
-%define reiserfsprogsversion 3.6.2
+%define reiserfsprogsversion 3.6.4
Vendor: Hans Reiser
Distribution: Hans Reiser
diff --git a/resize_reiserfs/resize_reiserfs.8 b/resize_reiserfs/resize_reiserfs.8
index 1bcb99c..f03034d 100644
--- a/resize_reiserfs/resize_reiserfs.8
+++ b/resize_reiserfs/resize_reiserfs.8
@@ -1,7 +1,7 @@
.\" -*- nroff -*-
.\" Copyright 1996-2002 Hans Reiser.
.\"
-.TH RESIZE_REISERFS 8 "January 2002" "Reiserfsprogs-3.6.2"
+.TH RESIZE_REISERFS 8 "January 2002" "Reiserfsprogs-3.6.4"
.SH NAME
resize_reiserfs \- Reiserfs filesystem resizer
.SH SYNOPSIS
diff --git a/tune/reiserfstune.8 b/tune/reiserfstune.8
index bce332d..b9dd728 100644
--- a/tune/reiserfstune.8
+++ b/tune/reiserfstune.8
@@ -1,7 +1,7 @@
.\" -*- nroff -*-
.\" Copyright 1996-2002 Hans Reiser.
.\"
-.TH REISERFSTUNE 8 "January 2002" "Reiserfsprogs-3.6.2"
+.TH REISERFSTUNE 8 "January 2002" "Reiserfsprogs-3.6.4"
.SH NAME
reiserfstune
.SH SYNOPSIS