cleanup: run indent with the Linux Kernel style across all code

Over the years, the reiserfs kernel code has been gradually cleaned up
to be more readable. This patch does the same to the progs code.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
This commit is contained in:
Jeff Mahoney committed 2013-08-26 17:14:42 -04:00
1 parent b23d40f723
commit 47cff72748
51 files changed
+27279 -25108

No files matched your search

+842 -773
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+66 -82
View File
@@ -17,32 +17,30 @@
#include <string.h>
#include <errno.h>
extern reiserfs_filsys_t * fs;
extern reiserfs_filsys_t *fs;
/*
* modes
*/
#define DO_DUMP 1 /* not a real dump, just printing to stdout contents of
tree nodes */
#define DO_CORRUPT_ONE 2 /* used to make filesystem corruption and then test fsck */
#define DO_CORRUPT_FILE 3 /* used to make filesystem corruption and then test fsck, the list of corruption is set on the file */
#define DO_DUMP 1 /* not a real dump, just printing to stdout contents of
tree nodes */
#define DO_CORRUPT_ONE 2 /* used to make filesystem corruption and then test fsck */
#define DO_CORRUPT_FILE 3 /* used to make filesystem corruption and then test fsck, the list of corruption is set on the file */
#define DO_RANDOM_CORRUPTION 4
#define DO_SCAN 5
#define DO_RECOVER 6
#define DO_TEST 7
#define DO_PACK 8 /* -p extract meta data of reiserfs filesystem */
#define DO_UNPACK 9 /* -u create the fs by the givem metadata */
#define DO_PACK 8 /* -p extract meta data of reiserfs filesystem */
#define DO_UNPACK 9 /* -u create the fs by the givem metadata */
#define DO_STAT 10
#define DO_SCAN_FOR_NAME 11 /* -n */
#define DO_LOOK_FOR_NAME 12 /* -N */
#define DO_SCAN_JOURNAL 13 /* -J */
#define DO_SCAN_FOR_NAME 11 /* -n */
#define DO_LOOK_FOR_NAME 12 /* -N */
#define DO_SCAN_JOURNAL 13 /* -J */
#define DO_EXTRACT_BADBLOCKS 14
#define DO_FILE_MAP 15
#define DO_ZERO 16
#define DO_NOTHING 17
/*first bits are in reiserfs_fs.b*/
#define PRINT_JOURNAL 0x10
#define PRINT_JOURNAL_HEADER 0x20
@@ -52,11 +50,10 @@ extern reiserfs_filsys_t * fs;
#define BE_VERBOSE 0x200
/* these moved to reiserfs_fs.h */
//#define PRINT_TREE_DETAILS
//#define PRINT_DETAILS
//#define PRINT_ITEM_DETAILS
//#define PRINT_DIRECT_ITEMS
//#define PRINT_TREE_DETAILS
//#define PRINT_DETAILS
//#define PRINT_ITEM_DETAILS
//#define PRINT_DIRECT_ITEMS
// the leaf is stored in compact form:
// start magic number
@@ -70,8 +67,6 @@ extern reiserfs_filsys_t * fs;
#define LEAF_START_MAGIC 0xa6
#define LEAF_END_MAGIC 0x5a
#define FULL_BLOCK_START_MAGIC 0xb6
#define FULL_BLOCK_END_MAGIC 0x6b
#define UNFORMATTED_BITMAP_START_MAGIC 0xc7
@@ -88,40 +83,36 @@ extern reiserfs_filsys_t * fs;
#define MAP_MAGIC 0xe9
#define MAP_END_MAGIC 0x9e
/* 12 bits of mask are used to define */
#define NEW_FORMAT 0x01 /* 1. 0 here means - old format, 1 - new format */
#define DIR_ID 0x02 /* 2. dir_id is stored */
#define OBJECT_ID 0x04 /* 3. objectid is stored */
#define OFFSET_BITS_32 0x08 /* 4. offset is stored as 32 bit */
#define OFFSET_BITS_64 0x10 /* 5. offset is stored as 64 bit */
#define IH_ENTRY_COUNT 0x20 /* 6. ih_free_space/ih_entry_count is stored */
#define NEW_FORMAT 0x01 /* 1. 0 here means - old format, 1 - new format */
#define DIR_ID 0x02 /* 2. dir_id is stored */
#define OBJECT_ID 0x04 /* 3. objectid is stored */
#define OFFSET_BITS_32 0x08 /* 4. offset is stored as 32 bit */
#define OFFSET_BITS_64 0x10 /* 5. offset is stored as 64 bit */
#define IH_ENTRY_COUNT 0x20 /* 6. ih_free_space/ih_entry_count is stored */
#define IH_FREE_SPACE 0x20
#define IH_FORMAT 0x40 /* 7. ih_format is stored */
#define WITH_SD_FIRST_DIRECT_BYTE 0x80 /* 8. for old stat data first_direct_byte is stored */
#define NLINK_BITS_32 0x0100 /* 9. nlinks stored in 32 bits */
#define SIZE_BITS_64 0x0200 /* 10. size has to be stored in 64 bit */
#define WHOLE_INDIRECT 0x0400 /* 11. indirect item is stored with compression */
#define SAFE_LINK 0x0800 /* 11. indirect item is stored with compression */
#define IH_FORMAT 0x40 /* 7. ih_format is stored */
#define WITH_SD_FIRST_DIRECT_BYTE 0x80 /* 8. for old stat data first_direct_byte is stored */
#define NLINK_BITS_32 0x0100 /* 9. nlinks stored in 32 bits */
#define SIZE_BITS_64 0x0200 /* 10. size has to be stored in 64 bit */
#define WHOLE_INDIRECT 0x0400 /* 11. indirect item is stored with compression */
#define SAFE_LINK 0x0800 /* 11. indirect item is stored with compression */
#define TYPE_MASK 0x3 /* two lowest bits are used to store item type */
#define TYPE_MASK 0x3 /* two lowest bits are used to store item type */
//#define MASK_MASK 0xffffc /* what is packed: dirid, objectid, etc */
#define ITEM_LEN_MASK 0xfff00000 /* contents of ih_item_len of item_head */
#define ITEM_LEN_MASK 0xfff00000 /* contents of ih_item_len of item_head */
struct packed_item {
__u32 type_2_mask_18_len_12;
__u32 type_2_mask_18_len_12;
};
/* defined as inlines in both pack.c and unpack.c */
inline void set_pi_type( struct packed_item *pi, __u32 val );
inline __u32 get_pi_type( const struct packed_item *pi );
inline void set_pi_mask( struct packed_item *pi, __u32 val );
inline __u32 get_pi_mask( const struct packed_item *pi );
inline void set_pi_item_len( struct packed_item *pi, __u32 val );
inline __u32 get_pi_item_len( const struct packed_item *pi );
inline void set_pi_type(struct packed_item *pi, __u32 val);
inline __u32 get_pi_type(const struct packed_item *pi);
inline void set_pi_mask(struct packed_item *pi, __u32 val);
inline __u32 get_pi_mask(const struct packed_item *pi);
inline void set_pi_item_len(struct packed_item *pi, __u32 val);
inline __u32 get_pi_item_len(const struct packed_item *pi);
#define HAS_DIR_ID 0x01
#define HAS_GEN_COUNTER 0x02
@@ -131,15 +122,14 @@ inline __u32 get_pi_item_len( const struct packed_item *pi );
#define R5 0x20
struct packed_dir_entry {
__u8 mask;
__u16 entrylen;
__u8 mask;
__u16 entrylen;
};
/* packed_dir_entry.mask is *always* endian safe, since it's 8 bit */
#define get_pe_entrylen(pe) (le16_to_cpu((pe)->entrylen))
#define set_pe_entrylen(pe,v) ((pe)->entrylen = cpu_to_le16(v))
#define fread8(pv) fread (pv, sizeof (__u8), 1, stdin)
#define fread_le16(pv)\
@@ -163,13 +153,11 @@ struct packed_dir_entry {
*pv = le64_to_cpu(tmp); \
}
#define fread8(pv) fread (pv, sizeof (__u8), 1, stdin)
#define fread16(pv) fread (pv, sizeof (__u16), 1, stdin)
#define fread32(pv) fread (pv, sizeof (__u32), 1, stdin)
#define fread64(pv) fread (pv, sizeof (__u64), 1, stdin)
#define fwrite_le16(pv)\
{\
__u16 tmp = cpu_to_le16(*(pv));\
@@ -209,30 +197,29 @@ if (fwrite (pv, sizeof (__u64), 1, stdout) != 1)\
sent_bytes += 8;\
}
struct debugreiserfs_data {
int mode; /* DO_DUMP | DO_PACK | DO_CORRUPT_ONE... */
int mode; /* DO_DUMP | DO_PACK | DO_CORRUPT_ONE... */
#define USED_BLOCKS 1
#define EXTERN_BITMAP 2
#define ALL_BLOCKS 3
#define UNUSED_BLOCKS 4
int scan_area; /* for -p, -s and -n */
char * input_bitmap; /* when ->scan_area is set to EXTERN_BITMAP */
reiserfs_bitmap_t * bitmap; /* bitmap is read from ->input_bitmap */
unsigned long block; /* set by -B. this is a must for -C, option for -p and -d */
char * pattern; /* for -n */
char * device_name;
char * journal_device_name; /* for -j */
char * map_file; /* for -n, -N and -f */
char * recovery_file; /* for -r */
int scan_area; /* for -p, -s and -n */
char *input_bitmap; /* when ->scan_area is set to EXTERN_BITMAP */
reiserfs_bitmap_t *bitmap; /* bitmap is read from ->input_bitmap */
unsigned long block; /* set by -B. this is a must for -C, option for -p and -d */
char *pattern; /* for -n */
char *device_name;
char *journal_device_name; /* for -j */
char *map_file; /* for -n, -N and -f */
char *recovery_file; /* for -r */
unsigned long options; /* -q only yet */
int JJ;
/* log file name and handle */
char *log_file_name;
FILE *log;
unsigned long options; /* -q only yet*/
int JJ;
/* log file name and handle */
char * log_file_name;
FILE * log ;
};
#define data(fs) ((struct debugreiserfs_data *)((fs)->fs_vp))
@@ -251,33 +238,33 @@ struct debugreiserfs_data {
#define be_quiet(fs) (data(fs)->options & BE_QUIET)
/* stat.c */
void do_stat (reiserfs_filsys_t * fs);
void do_stat(reiserfs_filsys_t *fs);
/* corruption.c */
void do_corrupt_one_block (reiserfs_filsys_t * fs, char * fline);
void do_leaves_corruption (reiserfs_filsys_t * fs, unsigned long nr_leaves_cr);
void do_bitmap_corruption (reiserfs_filsys_t * fs);
void do_fs_random_corrupt (reiserfs_filsys_t * fs);
void do_corrupt_one_block(reiserfs_filsys_t *fs, char *fline);
void do_leaves_corruption(reiserfs_filsys_t *fs, unsigned long nr_leaves_cr);
void do_bitmap_corruption(reiserfs_filsys_t *fs);
void do_fs_random_corrupt(reiserfs_filsys_t *fs);
/* recover.c */
void do_recover (reiserfs_filsys_t * fs);
void do_recover(reiserfs_filsys_t *fs);
/* scan.c */
void do_scan (reiserfs_filsys_t * fs);
void do_scan(reiserfs_filsys_t *fs);
/* journal.c */
void scan_journal (reiserfs_filsys_t * fs);
void scan_journal(reiserfs_filsys_t *fs);
/* unpack.c */
extern int do_unpack(char *host, char *j_filename, char *filename, int verbose);
void print_map(reiserfs_filsys_t * fs);
void print_map(reiserfs_filsys_t *fs);
struct saved_item {
struct item_head si_ih;
unsigned long si_block;
int si_item_num, si_entry_pos;
struct saved_item *si_next; /* list of items having the same key */
struct item_head si_ih;
unsigned long si_block;
int si_item_num, si_entry_pos;
struct saved_item *si_next; /* list of items having the same key */
};
/*
@@ -289,6 +276,3 @@ struct saved_item {
fill-column: 80
End:
*/
+532 -543
View File
File diff suppressed because it is too large. Load diff
+287 -237
View File
@@ -5,7 +5,6 @@
#include "debugreiserfs.h"
#if 0
/* this reads stdin and recover file of given key: */
@@ -16,119 +15,139 @@
..
then recover_file will read every block, look there specified file and put it into
*/
void do_recover (reiserfs_filsys_t fs)
void do_recover(reiserfs_filsys_t fs)
{
char name [100];
char * line = 0;
int n = 0;
int fd;
struct reiserfs_key key = {0, 0, };
struct buffer_head * bh;
struct item_head * ih;
unsigned long block;
char code;
loff_t recovered = 0;
int i, j;
reiserfs_bitmap_t bitmap;
int used, not_used;
char name[100];
char *line = 0;
int n = 0;
int fd;
struct reiserfs_key key = { 0, 0, };
struct buffer_head *bh;
struct item_head *ih;
unsigned long block;
char code;
loff_t recovered = 0;
int i, j;
reiserfs_bitmap_t bitmap;
int used, not_used;
bitmap = reiserfs_create_bitmap (SB_BLOCK_COUNT (fs));
reiserfs_fetch_disk_bitmap (bitmap, fs);
/* we check how many blocks recoverd items point to are free or used */
used = 0;
not_used = 0;
bitmap = reiserfs_create_bitmap(SB_BLOCK_COUNT(fs));
reiserfs_fetch_disk_bitmap(bitmap, fs);
/* we check how many blocks recoverd items point to are free or used */
used = 0;
not_used = 0;
fd = 0;
while (getline (&line, &n, stdin) != -1) {
if (line [0] == '#' || line [0] == '\n')
continue;
switch (line [0]) {
case 'K':
/* get a key of file which is to be recovered */
if (sscanf (line, "%c %u %u\n", &code, &key.k_dir_id, &key.k_objectid) != 3) {
die ("recover_file: wrong input K format");
}
printf ("Recovering file (%u, %u)\n", key.k_dir_id, key.k_objectid);
break;
case 'N':
/* get a file name */
recovered = 0;
if (sscanf (line, "%c %s\n", &code, name) != 2) {
die ("recover_file: wrong input N format");
}
fd = open (name, O_RDWR | O_CREAT | O_EXCL, 0644);
if (fd == -1)
die ("recover_file: could not create file %s: %s",
name,strerror (errno));
printf ("Recovering file %s..\n", name);
break;
case 'B':
if (!fd)
die ("recover_file: file name is not specified");
if (sscanf (line, "%c %lu\n", &code, &block) != 2) {
die ("recover_file: wrong input B format");
}
bh = bread (fs->s_dev, block, fs->s_blocksize);
if (!bh) {
printf ("reading block %lu failed\n", block);
continue;
}
printf ("working with block %lu..\n", block);
ih = B_N_PITEM_HEAD (bh, 0);
for (i = 0; i < node_item_number (bh); i ++, ih ++) {
__u32 * indirect;
struct buffer_head * tmp_bh;
if (!is_indirect_ih (ih) || key.k_dir_id != ih->ih_key.k_dir_id ||
key.k_objectid != ih->ih_key.k_objectid)
continue;
indirect = (__u32 *)B_I_PITEM (bh, ih);
for (j = 0; j < I_UNFM_NUM (ih); j ++) {
block = le32_to_cpu (indirect [j]);
if (!block)
fd = 0;
while (getline(&line, &n, stdin) != -1) {
if (line[0] == '#' || line[0] == '\n')
continue;
tmp_bh = bread (fs->s_dev, block, fs->s_blocksize);
if (!tmp_bh) {
printf ("reading block %Lu failed\n", (loff_t)block * fs->s_blocksize);
continue;
}
if (lseek64 (fd, get_offset (&ih->ih_key) + j * fs->s_blocksize - 1,
SEEK_SET) == (loff_t)-1) {
printf ("llseek failed to pos %Ld\n", (loff_t)block * fs->s_blocksize);
brelse (tmp_bh);
continue;
}
if (reiserfs_bitmap_test_bit (bitmap, block))
used ++;
else
not_used ++;
/*printf ("block of file %Ld gets block %lu\n",
(get_offset (&ih->ih_key) - 1) / fs->s_blocksize + j, block);*/
if (write (fd, tmp_bh->b_data, tmp_bh->b_size) != tmp_bh->b_size) {
printf ("write failed to pos %Ld\n", (loff_t)block * fs->s_blocksize);
brelse (tmp_bh);
continue;
}
recovered += fs->s_blocksize;
brelse (tmp_bh);
switch (line[0]) {
case 'K':
/* get a key of file which is to be recovered */
if (sscanf
(line, "%c %u %u\n", &code, &key.k_dir_id,
&key.k_objectid) != 3) {
die("recover_file: wrong input K format");
}
printf("Recovering file (%u, %u)\n", key.k_dir_id,
key.k_objectid);
break;
case 'N':
/* get a file name */
recovered = 0;
if (sscanf(line, "%c %s\n", &code, name) != 2) {
die("recover_file: wrong input N format");
}
fd = open(name, O_RDWR | O_CREAT | O_EXCL, 0644);
if (fd == -1)
die("recover_file: could not create file %s: %s", name, strerror(errno));
printf("Recovering file %s..\n", name);
break;
case 'B':
if (!fd)
die("recover_file: file name is not specified");
if (sscanf(line, "%c %lu\n", &code, &block) != 2) {
die("recover_file: wrong input B format");
}
bh = bread(fs->s_dev, block, fs->s_blocksize);
if (!bh) {
printf("reading block %lu failed\n", block);
continue;
}
printf("working with block %lu..\n", block);
ih = B_N_PITEM_HEAD(bh, 0);
for (i = 0; i < node_item_number(bh); i++, ih++) {
__u32 *indirect;
struct buffer_head *tmp_bh;
if (!is_indirect_ih(ih)
|| key.k_dir_id != ih->ih_key.k_dir_id
|| key.k_objectid != ih->ih_key.k_objectid)
continue;
indirect = (__u32 *) B_I_PITEM(bh, ih);
for (j = 0; j < I_UNFM_NUM(ih); j++) {
block = le32_to_cpu(indirect[j]);
if (!block)
continue;
tmp_bh =
bread(fs->s_dev, block,
fs->s_blocksize);
if (!tmp_bh) {
printf
("reading block %Lu failed\n",
(loff_t) block *
fs->s_blocksize);
continue;
}
if (lseek64
(fd,
get_offset(&ih->ih_key) +
j * fs->s_blocksize - 1,
SEEK_SET) == (loff_t) - 1) {
printf
("llseek failed to pos %Ld\n",
(loff_t) block *
fs->s_blocksize);
brelse(tmp_bh);
continue;
}
if (reiserfs_bitmap_test_bit
(bitmap, block))
used++;
else
not_used++;
/*printf ("block of file %Ld gets block %lu\n",
(get_offset (&ih->ih_key) - 1) / fs->s_blocksize + j, block); */
if (write
(fd, tmp_bh->b_data,
tmp_bh->b_size) !=
tmp_bh->b_size) {
printf
("write failed to pos %Ld\n",
(loff_t) block *
fs->s_blocksize);
brelse(tmp_bh);
continue;
}
recovered += fs->s_blocksize;
brelse(tmp_bh);
}
}
brelse(bh);
break;
}
}
brelse (bh);
break;
}
}
printf ("recover_file: %Ld bytes recovered of file %s, key %u %u, %d blocks are free and %d are used\n",
recovered, name, key.k_dir_id, key.k_objectid, not_used, used);
printf
("recover_file: %Ld bytes recovered of file %s, key %u %u, %d blocks are free and %d are used\n",
recovered, name, key.k_dir_id, key.k_objectid, not_used, used);
}
#endif
/* read a file containing map of one or more files and either recover
them or just print info */
/*
@@ -140,7 +159,6 @@ static void read_map (FILE * fp)
__u32 ids [4];
int do_recover = 0;
buf = 0;
while (1) {
if (fread (&v32, sizeof (v32), 1, fp) != 1)
@@ -215,8 +233,7 @@ static void read_map (FILE * fp)
free (buf);
}
void do_recover (reiserfs_filsys_t * fs)
void do_recover (reiserfs_filsys_t *fs)
{
FILE * fp;
@@ -242,148 +259,181 @@ void do_recover (reiserfs_filsys_t * fs)
#include <limits.h>
static long int get_answer(long int max) {
char *answer, *tmp;
size_t n = 0;
long int result = 0;
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;
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 start = -1;
unsigned int i, j;
__u64 offset = 0, length;
long int result = 0;
unsigned long unfm_ptr;
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 start = -1;
unsigned int i, 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;
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);
}
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(i - start) + start;
} else {
result = i - 1;
}
start = -1;
} else if (is_direntry_ih(&(cur - 1)->si_ih) || is_stat_data_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 = d32_get((__u32 *)B_I_PITEM(bh, ih), j);
if (!unfm_ptr) {
fseek(target_file, fs->fs_blocksize, SEEK_CUR);
continue;
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;
}
bh_pointed = bread (fs->fs_dev, unfm_ptr, fs->fs_blocksize);
if (!bh_pointed) {
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(i - start) + start;
} else {
result = i - 1;
}
start = -1;
} else if (is_direntry_ih(&(cur - 1)->si_ih)
|| is_stat_data_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;
}
}
fwrite(bh_pointed->b_data, fs->fs_blocksize, 1, target_file);
brelse(bh_pointed);
}
}
brelse(bh);
}
brelse(bh);
free(map);
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 =
d32_get((__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;
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;
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;
}
} 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;
}
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);
recover_items(fp, fs, recovery);
if (fp != stdin)
fclose(fp);
fclose(recovery);
}
+826 -780
View File
File diff suppressed because it is too large. Load diff
+156 -168
View File
@@ -10,65 +10,59 @@
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
/* try to find blocks which contain only items which are */
/* read blocks marked in debug_bitmap and collect statistic of it:
number of stat data */
struct {
unsigned long all;
unsigned long items [5];
unsigned long unique_keys; /* keys of stat datas */
unsigned long unique_entry_keys; /* keys which appear in directory entries */
unsigned long names; /* dir entries but "." and ".." */
unsigned long dir_blocks; /* block containing only one directory item */
unsigned long unique_items;
unsigned long leaves;
unsigned long blocks_to_skip;
unsigned long all;
unsigned long items[5];
unsigned long unique_keys; /* keys of stat datas */
unsigned long unique_entry_keys; /* keys which appear in directory entries */
unsigned long names; /* dir entries but "." and ".." */
unsigned long dir_blocks; /* block containing only one directory item */
unsigned long unique_items;
unsigned long leaves;
unsigned long blocks_to_skip;
} fs_stat;
/* store unique item heads */
struct obstack items;
/* tree sorting item heades by comp_items_1 */
void * items_tree;
void *items_tree;
static int comp_items_1 (const void * p1, const void * p2)
static int comp_items_1(const void *p1, const void *p2)
{
int retval;
struct item_head * ih1, * ih2;
int retval;
struct item_head *ih1, *ih2;
/*
if (*(int *)p1 != *(int *)p2)
retval = 1;
else
retval = 0;
*/
retval = comp_keys (p1, p2);
/*retval = comp_short_keys (p1, p2);*/
if (retval)
return retval;
/*
if (*(int *)p1 != *(int *)p2)
retval = 1;
else
retval = 0;
*/
retval = comp_keys(p1, p2);
/*retval = comp_short_keys (p1, p2); */
if (retval)
return retval;
ih1 = (struct item_head *)p1;
ih2 = (struct item_head *)p2;
ih1 = (struct item_head *)p1;
ih2 = (struct item_head *)p2;
if (get_ih_item_len(ih1) < get_ih_item_len(ih2))
return -1;
if (get_ih_item_len(ih1) > get_ih_item_len(ih2))
return 1;
if (get_ih_entry_count(ih1) < get_ih_entry_count(ih2))
return -1;
if (get_ih_entry_count(ih1) > get_ih_entry_count(ih2))
return 1;
if (get_ih_item_len (ih1) < get_ih_item_len (ih2))
return -1;
if (get_ih_item_len (ih1) > get_ih_item_len (ih2))
return 1;
if (get_ih_entry_count (ih1) < get_ih_entry_count (ih2))
return -1;
if (get_ih_entry_count (ih1) > get_ih_entry_count (ih2))
return 1;
return 0;
return 0;
}
/*
static void print_node (const void *nodep, VISIT value, int level)
{
@@ -88,64 +82,61 @@ static void print_node (const void *nodep, VISIT value, int level)
}
*/
static int is_unique_item (struct obstack * ostack, void ** tree, void * ih)
static int is_unique_item(struct obstack *ostack, void **tree, void *ih)
{
void * res;
void * key1;
void *res;
void *key1;
key1 = obstack_copy (ostack, ih, IH_SIZE);
res = tsearch (key1, tree, comp_items_1);
if (!res)
reiserfs_panic ("Too many keys found");
key1 = obstack_copy(ostack, ih, IH_SIZE);
res = tsearch(key1, tree, comp_items_1);
if (!res)
reiserfs_panic("Too many keys found");
/* twalk (*tree, print_node);*/
/* reiserfs_warning (stderr, "\n\n");*/
if (*(void **)res != key1) {
/* key is in tree already, remove it from obstack */
/*reiserfs_warning (stdout, "%H is skipped\n", ih);fflush (stdout);*/
obstack_free (ostack, key1);
return 0;
}
if (*(void **)res != key1) {
/* key is in tree already, remove it from obstack */
/*reiserfs_warning (stdout, "%H is skipped\n", ih);fflush (stdout); */
obstack_free(ostack, key1);
return 0;
}
/*reiserfs_warning (stdout, "%k is added\n", ih);fflush (stdout);*/
return 1;
/*reiserfs_warning (stdout, "%k is added\n", ih);fflush (stdout); */
return 1;
}
static void stat1_the_leaf (reiserfs_filsys_t * fs, struct buffer_head * bh)
static void stat1_the_leaf(reiserfs_filsys_t *fs, struct buffer_head *bh)
{
int i, i_num;
struct item_head * ih;
int is_there_unique_item;
int i, i_num;
struct item_head *ih;
int is_there_unique_item;
ih = B_N_PITEM_HEAD(bh, 0);
is_there_unique_item = 0;
i_num = leaf_item_number_estimate(bh);
for (i = 0; i < i_num; i++, ih++) {
/* count all items */
fs_stat.all++;
ih = B_N_PITEM_HEAD (bh, 0);
is_there_unique_item = 0;
i_num = leaf_item_number_estimate(bh);
for (i = 0; i < i_num; i ++, ih ++) {
/* count all items */
fs_stat.all ++;
if (is_unique_item (&items, &items_tree, ih)) {
/* this is item we have not seen yet */
fs_stat.unique_items ++;
is_there_unique_item ++;
if (is_unique_item(&items, &items_tree, ih)) {
/* this is item we have not seen yet */
fs_stat.unique_items++;
is_there_unique_item++;
}
}
}
if (!is_there_unique_item) {
/* the node contains only items we have seen already. so we will skip
it */
fs_stat.blocks_to_skip ++;
reiserfs_bitmap_clear_bit (input_bitmap (fs), bh->b_blocknr);
} else {
ih = B_N_PITEM_HEAD (bh, 0);
/* node contains at least one unique item. We will put it in, count items of each type */
for (i = 0; i < i_num; i ++, ih ++) {
fs_stat.items [get_type (&ih->ih_key)] ++;
if (!is_there_unique_item) {
/* the node contains only items we have seen already. so we will skip
it */
fs_stat.blocks_to_skip++;
reiserfs_bitmap_clear_bit(input_bitmap(fs), bh->b_blocknr);
} else {
ih = B_N_PITEM_HEAD(bh, 0);
/* node contains at least one unique item. We will put it in, count items of each type */
for (i = 0; i < i_num; i++, ih++) {
fs_stat.items[get_type(&ih->ih_key)]++;
}
}
}
}
/*
@@ -161,17 +152,16 @@ static void stat2_the_leaf (struct buffer_head * bh)
}
*/
void do_stat (reiserfs_filsys_t * fs)
void do_stat(reiserfs_filsys_t *fs)
{
unsigned long i;
unsigned long done, total;
struct buffer_head * bh;
int type;
FILE * fp;
unsigned long i;
unsigned long done, total;
struct buffer_head *bh;
int type;
FILE *fp;
obstack_init (&items);
items_tree = 0;
obstack_init(&items);
items_tree = 0;
/*
bh = bread (fs->s_dev, 8211, fs->s_blocksize);
@@ -180,95 +170,93 @@ void do_stat (reiserfs_filsys_t * fs)
return;
*/
/* pass 0 of stating */
total = reiserfs_bitmap_ones (input_bitmap (fs));
done = 0;
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
if (!reiserfs_bitmap_test_bit (input_bitmap (fs), i))
continue;
/* pass 0 of stating */
total = reiserfs_bitmap_ones(input_bitmap(fs));
done = 0;
for (i = 0; i < get_sb_block_count(fs->fs_ondisk_sb); i++) {
if (!reiserfs_bitmap_test_bit(input_bitmap(fs), i))
continue;
print_how_far (stderr, &done, total, 1, be_quiet (fs));
print_how_far(stderr, &done, total, 1, be_quiet(fs));
bh = bread (fs->fs_dev, i, fs->fs_blocksize);
if (!bh) {
printf ("could not read block %lu\n", i);
continue;
bh = bread(fs->fs_dev, i, fs->fs_blocksize);
if (!bh) {
printf("could not read block %lu\n", i);
continue;
}
type = who_is_this(bh->b_data, bh->b_size);
if (type != THE_LEAF && type != HAS_IH_ARRAY) {
reiserfs_bitmap_clear_bit(input_bitmap(fs), i);
brelse(bh);
continue;
}
fs_stat.leaves++;
stat1_the_leaf(fs, bh);
brelse(bh);
}
type = who_is_this (bh->b_data, bh->b_size);
if (type != THE_LEAF && type != HAS_IH_ARRAY) {
reiserfs_bitmap_clear_bit (input_bitmap (fs), i);
brelse (bh);
continue;
}
fs_stat.leaves ++;
stat1_the_leaf (fs, bh);
brelse (bh);
}
reiserfs_warning (stderr, "\nThere were found on the '%s' device:\n"
"\tleaves %lu\n"
"\ttotal number of items %lu\n"
"\tblocks containing at least one unique item %lu\n"
"\tblocks which can be skipped %lu\n"
"\t\tstat data %lu\n"
"\t\tindirect %lu\n"
"\t\tdirect %lu\n"
"\t\tdirectory items %lu\n"
"\tunique items %lu\n",
/*
"\tnames there (but \".\" and \"..\") %lu\n"
"\tpointing to unique keys %lu\n"
"other items %lu\n"
"blocks containing only 1 dir item %lu\n",
*/
fs->fs_file_name,
fs_stat.leaves,
fs_stat.all,
fs_stat.leaves - fs_stat.blocks_to_skip,
fs_stat.blocks_to_skip,
fs_stat.items [TYPE_STAT_DATA],
fs_stat.items [TYPE_INDIRECT],
fs_stat.items [TYPE_DIRECT],
fs_stat.items [TYPE_DIRENTRY],
fs_stat.unique_items);
reiserfs_warning(stderr, "\nThere were found on the '%s' device:\n"
"\tleaves %lu\n"
"\ttotal number of items %lu\n"
"\tblocks containing at least one unique item %lu\n"
"\tblocks which can be skipped %lu\n"
"\t\tstat data %lu\n"
"\t\tindirect %lu\n"
"\t\tdirect %lu\n"
"\t\tdirectory items %lu\n" "\tunique items %lu\n",
/*
"\tnames there (but \".\" and \"..\") %lu\n"
"\tpointing to unique keys %lu\n"
"other items %lu\n"
"blocks containing only 1 dir item %lu\n",
*/
fs->fs_file_name,
fs_stat.leaves,
fs_stat.all,
fs_stat.leaves - fs_stat.blocks_to_skip,
fs_stat.blocks_to_skip,
fs_stat.items[TYPE_STAT_DATA],
fs_stat.items[TYPE_INDIRECT],
fs_stat.items[TYPE_DIRECT],
fs_stat.items[TYPE_DIRENTRY], fs_stat.unique_items);
/*
fs_stat.names,
fs_stat.unique_keys,
fs_stat.items [4],
fs_stat.dir_blocks);
*/
if (!input_bitmap_file_name(fs))
if (!input_bitmap_file_name(fs))
return;
fp = fopen(input_bitmap_file_name(fs), "w");
if (!fp) {
reiserfs_exit(1, "could not open %s to save bitmap: %m\n",
input_bitmap_file_name(fs));
}
reiserfs_warning(stderr, "Updated bitmap contains %u blocks marked\n",
reiserfs_bitmap_ones(input_bitmap(fs)));
reiserfs_bitmap_save(fp, input_bitmap(fs));
fclose(fp);
return;
fp = fopen (input_bitmap_file_name(fs), "w");
if (!fp) {
reiserfs_exit (1, "could not open %s to save bitmap: %m\n",
input_bitmap_file_name(fs));
}
reiserfs_warning (stderr, "Updated bitmap contains %u blocks marked\n",
reiserfs_bitmap_ones (input_bitmap (fs)));
reiserfs_bitmap_save (fp, input_bitmap (fs));
fclose (fp);
return;
/* pass 2 of stating */
reiserfs_warning(stderr,
"Looking for blocks containing only keys not pointed by any of entries\n");
total = reiserfs_bitmap_ones(input_bitmap(fs));
done = 0;
for (i = 0; i < get_sb_block_count(fs->fs_ondisk_sb); i++) {
if (!reiserfs_bitmap_test_bit(input_bitmap(fs), i))
continue;
print_how_far(stderr, &done, total, 1, be_quiet(fs));
/* pass 2 of stating */
reiserfs_warning (stderr, "Looking for blocks containing only keys not pointed by any of entries\n");
total = reiserfs_bitmap_ones (input_bitmap (fs));
done = 0;
for (i = 0; i < get_sb_block_count (fs->fs_ondisk_sb); i ++) {
if (!reiserfs_bitmap_test_bit (input_bitmap (fs), i))
continue;
print_how_far (stderr, &done, total, 1, be_quiet (fs));
bh = bread (fs->fs_dev, i, fs->fs_blocksize);
if (!bh) {
printf ("could not read block %lu\n", i);
continue;
bh = bread(fs->fs_dev, i, fs->fs_blocksize);
if (!bh) {
printf("could not read block %lu\n", i);
continue;
}
/*stat2_the_leaf (bh); */
}
/*stat2_the_leaf (bh);*/
}
}
+498 -501
View File
File diff suppressed because it is too large. Load diff
+876 -836
View File
File diff suppressed because it is too large. Load diff
+228 -238
View File
@@ -21,8 +21,8 @@
#include "../version.h"
/* main.c */
extern reiserfs_filsys_t * fs;
int main (int argc, char * argv []);
extern reiserfs_filsys_t *fs;
int main(int argc, char *argv[]);
/* Exit codes. */
#define EXIT_OK 0
@@ -30,7 +30,7 @@ int main (int argc, char * argv []);
#define EXIT_REBOOT 2
#define EXIT_FATAL 4
#define EXIT_FIXABLE 6
#define EXIT_OPER 8 /* Some operation returns error. */
#define EXIT_OPER 8 /* Some operation returns error. */
#define EXIT_USER 16
/*
@@ -43,7 +43,7 @@ int main (int argc, char * argv []);
#define FSCK_REBUILD 4
#define FSCK_ROLLBACK_CHANGES 5
#define FSCK_CLEAN_ATTRIBUTES 7
#define FSCK_AUTO 8 /* -a || -p specified */
#define FSCK_AUTO 8 /* -a || -p specified */
/* temporary */
#define DO_TEST 9
@@ -65,90 +65,91 @@ int main (int argc, char * argv []);
#define BADBLOCKS_FILE 1 << 10
#define OPT_FORCE 1 << 11
/* pass0.c */
void pass_0 (reiserfs_filsys_t *);
void load_pass_0_result (FILE *, reiserfs_filsys_t *);
void pass_0(reiserfs_filsys_t *);
void load_pass_0_result(FILE *, reiserfs_filsys_t *);
int leaf_structure_check(reiserfs_filsys_t * fs, struct buffer_head * bh);
int leaf_structure_check(reiserfs_filsys_t *fs, struct buffer_head *bh);
int is_used_leaf (unsigned long block);
int is_good_unformatted (unsigned long block);
void mark_good_unformatted (unsigned long block);
int is_bad_unformatted (unsigned long block);
int is_used_leaf(unsigned long block);
int is_good_unformatted(unsigned long block);
void mark_good_unformatted(unsigned long block);
int is_bad_unformatted(unsigned long block);
int are_there_allocable_blocks (unsigned int amout_needed);
unsigned long alloc_block (void);
void make_allocable (unsigned long block);
void register_uninsertable (unsigned long block);
void register_saved_item (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 *);
int are_there_allocable_blocks(unsigned int amout_needed);
unsigned long alloc_block(void);
void make_allocable(unsigned long block);
void register_uninsertable(unsigned long block);
void register_saved_item(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 *);
void delete_aux_bitmaps ();
void set_aux_bitmaps(reiserfs_bitmap_t * leaves, reiserfs_bitmap_t * good, reiserfs_bitmap_t * bad);
void delete_aux_bitmaps();
void set_aux_bitmaps(reiserfs_bitmap_t *leaves, reiserfs_bitmap_t *good,
reiserfs_bitmap_t *bad);
#define __is_marked(name,block) reiserfs_bitmap_test_bit (name##_bitmap, block)
#define __mark(name,block) reiserfs_bitmap_set_bit (name##_bitmap, block)
#define __unmark(name,block) reiserfs_bitmap_clear_bit (name##_bitmap, block)
/* unformatted in tree */
extern reiserfs_bitmap_t * bad_unfm_in_tree_once_bitmap;
extern reiserfs_bitmap_t *bad_unfm_in_tree_once_bitmap;
#define is_bad_unfm_in_tree_once(block) __is_marked (bad_unfm_in_tree_once, block)
#define mark_bad_unfm_in_tree_once(block) __mark (bad_unfm_in_tree_once, block)
/* pass1.c */
void pass_1 (reiserfs_filsys_t *);
void load_pass_1_result (FILE *, reiserfs_filsys_t *);
struct buffer_head * make_buffer (int dev, unsigned long blocknr, int size, char * data);
void build_the_tree (void);
void pass_1(reiserfs_filsys_t *);
void load_pass_1_result(FILE *, reiserfs_filsys_t *);
struct buffer_head *make_buffer(int dev, unsigned long blocknr, int size,
char *data);
void build_the_tree(void);
extern int g_unaccessed_items;
int is_item_reachable (struct item_head * ih);
void mark_item_reachable (struct item_head * ih, struct buffer_head * bh);
void mark_item_unreachable (struct item_head * ih);
struct si * remove_saved_item (struct si * si);
int tree_is_empty (void);
void make_single_leaf_tree (struct buffer_head * bh);
int is_item_reachable(struct item_head *ih);
void mark_item_reachable(struct item_head *ih, struct buffer_head *bh);
void mark_item_unreachable(struct item_head *ih);
struct si *remove_saved_item(struct si *si);
int tree_is_empty(void);
void make_single_leaf_tree(struct buffer_head *bh);
/* pass2.c */
void pass_2 (reiserfs_filsys_t *);
void load_pass_2_result (reiserfs_filsys_t *);
void insert_item_separately (struct item_head * ih, char * item, int was_in_tree);
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 reiserfs_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);
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 save_item(struct si **head, struct item_head *ih, char *item,
__u32 blocknr);
struct si *save_and_delete_file_item(struct si *si, struct reiserfs_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);
int should_relocate (struct item_head * ih);
void relocate_dir (struct item_head * ih, int change_ih);
void link_relocated_files(void);
int should_relocate(struct item_head *ih);
void relocate_dir(struct item_head *ih, int change_ih);
extern __u32 objectid_for_relocation (struct reiserfs_key *key);
extern __u32 objectid_for_relocation(struct reiserfs_key *key);
extern void linked_already(struct reiserfs_key *new_key);
/* file.c */
struct si {
struct item_head si_ih;
char * si_dnm_data;
struct si * si_next;
__u32 si_blocknr;
struct item_head si_ih;
char *si_dnm_data;
struct si *si_next;
__u32 si_blocknr;
// changed by XB;
struct si * last_known;
// changed by XB;
struct si *last_known;
};
void put_saved_items_into_tree (struct si *);
int reiserfsck_file_write (struct item_head * ih, char * item, int was_in_tree);
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 reiserfs_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);
void put_saved_items_into_tree(struct si *);
int reiserfsck_file_write(struct item_head *ih, char *item, int was_in_tree);
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 reiserfs_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);
/* semantic.c */
@@ -159,64 +160,64 @@ void rewrite_file (struct item_head * ih, int should_relocate, int should_change
#define RELOCATED -3
#define LOOP_FOUND -4
void load_semantic_result (FILE *, reiserfs_filsys_t *);
void load_semantic_result(FILE *, reiserfs_filsys_t *);
void pass_3_semantic (reiserfs_filsys_t *);
void semantic_check (void);
int check_semantic_tree (struct reiserfs_key *key, struct reiserfs_key *parent, int is_dot_dot, int lost_found, struct item_head * new_ih);
void zero_nlink (struct item_head * ih, void * sd);
int not_a_directory (void * sd);
int not_a_regfile (void * sd);
int fix_obviously_wrong_sd_mode (struct reiserfs_path *path);
int is_dot_dot (char * name, int namelen);
int is_dot (char * name, int namelen);
/*void create_dir_sd (reiserfs_filsys_t * fs,
void pass_3_semantic(reiserfs_filsys_t *);
void semantic_check(void);
int check_semantic_tree(struct reiserfs_key *key, struct reiserfs_key *parent,
int is_dot_dot, int lost_found,
struct item_head *new_ih);
void zero_nlink(struct item_head *ih, void *sd);
int not_a_directory(void *sd);
int not_a_regfile(void *sd);
int fix_obviously_wrong_sd_mode(struct reiserfs_path *path);
int is_dot_dot(char *name, int namelen);
int is_dot(char *name, int namelen);
/*void create_dir_sd (reiserfs_filsys_t *fs,
struct reiserfs_path *path, struct reiserfs_key *key);*/
int rebuild_check_regular_file (struct reiserfs_path *path, void * sd,
struct item_head * new_ih);
int rebuild_semantic_pass (struct reiserfs_key *key, struct reiserfs_key *parent, int is_dot_dot,
struct item_head * new_ih);
int rebuild_check_regular_file(struct reiserfs_path *path, void *sd,
struct item_head *new_ih);
int rebuild_semantic_pass(struct reiserfs_key *key, struct reiserfs_key *parent,
int is_dot_dot, struct item_head *new_ih);
/* lost+found.c */
void pass_3a_look_for_lost (reiserfs_filsys_t *);
void pass_3a_look_for_lost(reiserfs_filsys_t *);
void load_lost_found_result (reiserfs_filsys_t *);
void load_lost_found_result(reiserfs_filsys_t *);
/* pass4.c */
void pass_4_check_unaccessed_items (void);
void pass_4_check_unaccessed_items(void);
/* check.c */
int is_leaf_bad (struct buffer_head * bh);
int is_bad_item (struct buffer_head * bh, struct item_head *, char *);
int is_leaf_bad(struct buffer_head *bh);
int is_bad_item(struct buffer_head *bh, struct item_head *, char *);
/*int check_file_system (void);*/
void reiserfsck_check_pass1 (void);
void reiserfsck_check_pass1(void);
/*char * bad_name (char * name, int namelen);*/
/* to test result of direcotry item recovering on pass 0 */
int is_bad_directory (struct item_head * ih, char * item, int dev, int blocksize);
int is_bad_directory(struct item_head *ih, char *item, int dev, int blocksize);
//extern int bad_block_number (struct super_block * s, blocknr_t block);
/* check_tree.c */
void check_fs_tree (reiserfs_filsys_t *);
void do_clean_attributes (reiserfs_filsys_t * fs);
int bad_pair (reiserfs_filsys_t *, struct buffer_head * bh, int i);
int bad_leaf_2 (reiserfs_filsys_t *, struct buffer_head * bh);
void check_fs_tree(reiserfs_filsys_t *);
void do_clean_attributes(reiserfs_filsys_t *fs);
int bad_pair(reiserfs_filsys_t *, struct buffer_head *bh, int i);
int bad_leaf_2(reiserfs_filsys_t *, struct buffer_head *bh);
#if 0
extern int should_be_relocated (struct reiserfs_key *key);
extern void to_be_relocated (struct reiserfs_key *key);
extern int should_be_relocated(struct reiserfs_key *key);
extern void to_be_relocated(struct reiserfs_key *key);
extern void clear_relocated_list(void);
#endif
/* ustree.c */
void reiserfsck_paste_into_item (struct reiserfs_path *path, const char * body, int size);
void reiserfsck_insert_item (struct reiserfs_path *path, struct item_head * ih, const char * body);
void reiserfsck_delete_item (struct reiserfs_path *path, int temporary);
void reiserfsck_cut_from_item (struct reiserfs_path *path, int cut_size);
void reiserfsck_paste_into_item(struct reiserfs_path *path, const char *body,
int size);
void reiserfsck_insert_item(struct reiserfs_path *path, struct item_head *ih,
const char *body);
void reiserfsck_delete_item(struct reiserfs_path *path, int temporary);
void reiserfsck_cut_from_item(struct reiserfs_path *path, int cut_size);
/*typedef int (comp3_function_t)(void * key1, void * key2, int version);*/
/*typedef int (comp_function_t)(struct reiserfs_key *key1, struct reiserfs_key *key2);*/
/*int ubin_search_id(__u32 * id, __u32 * base, __u32 number, __u32 * pos);*/
@@ -225,29 +226,29 @@ void reiserfsck_cut_from_item (struct reiserfs_path *path, int cut_size);
comp3_function_t comp_func, int version);
int usearch_by_entry_key (struct super_block * s, struct reiserfs_key *key, struct reiserfs_path *path);*/
typedef int do_after_read_t (reiserfs_filsys_t *, struct buffer_head **, int h);
typedef int do_on_full_path_t (reiserfs_filsys_t *, struct buffer_head **, int);
void pass_through_tree (reiserfs_filsys_t *, do_after_read_t, do_on_full_path_t, int depth);
typedef int do_after_read_t(reiserfs_filsys_t *, struct buffer_head **, int h);
typedef int do_on_full_path_t(reiserfs_filsys_t *, struct buffer_head **, int);
void pass_through_tree(reiserfs_filsys_t *, do_after_read_t, do_on_full_path_t,
int depth);
/* bitmap.c */
int reiserfsck_reiserfs_new_blocknrs (reiserfs_filsys_t * fs,
unsigned long * pblocknrs,
unsigned long start_from,
int amount_needed);
int reiserfsck_reiserfs_free_block (reiserfs_filsys_t * fs, unsigned long block);
struct buffer_head * reiserfsck_get_new_buffer (unsigned long start);
int is_block_used (unsigned long block);
void mark_block_used (unsigned long block, int check_hardware);
void mark_block_uninsertable (unsigned long block);
int is_block_uninsertable (unsigned long block);
int reiserfsck_reiserfs_new_blocknrs(reiserfs_filsys_t *fs,
unsigned long *pblocknrs,
unsigned long start_from,
int amount_needed);
int reiserfsck_reiserfs_free_block(reiserfs_filsys_t *fs, unsigned long block);
struct buffer_head *reiserfsck_get_new_buffer(unsigned long start);
int is_block_used(unsigned long block);
void mark_block_used(unsigned long block, int check_hardware);
void mark_block_uninsertable(unsigned long block);
int is_block_uninsertable(unsigned long block);
/* objectid.c */
int comp_ids(const void *p1, const void *p2);
typedef struct id_map {
void **index;
__u32 count, last_used;
void **index;
__u32 count, last_used;
} id_map_t;
id_map_t *id_map_init();
@@ -255,174 +256,165 @@ void id_map_free(id_map_t *);
int id_map_test(id_map_t *map, __u32 id);
int id_map_mark(id_map_t *map, __u32 id);
__u32 id_map_alloc(id_map_t *map);
void id_map_flush(struct id_map * map, reiserfs_filsys_t * fs);
void id_map_flush(struct id_map *map, reiserfs_filsys_t *fs);
/* FIXME: Needs to be implemented
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t * fs);
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t *fs);
void reiserfs_objectid_map_save (FILE * fp, struct id_map * id_map);
struct id_map * reiserfs_objectid_map_load (FILE * fp);
*/
void mark_formatted_pointed_by_indirect (__u32);
int is_formatted_pointed_by_indirect (__u32);
void mark_formatted_pointed_by_indirect(__u32);
int is_formatted_pointed_by_indirect(__u32);
#define MAP_NOT_PACKED 0
#define MAP_PACKED 1
struct pass0_stat {
unsigned long dealt_with; /* number of blocks read during pass 0 */
unsigned long leaves; /* blocks looking like reiserfs leaves found */
unsigned long leaves_corrected;
unsigned long all_contents_removed;
unsigned long too_old_leaves; /* these are leaves which contains
direntries with different hash from the
one specified with -h */
unsigned long wrong_pointers; /* pointers in indirect items pointing to
wrong area */
unsigned long pointed; /* pointers blocks of device pointed by all
indirect items */
unsigned long dealt_with; /* number of blocks read during pass 0 */
unsigned long leaves; /* blocks looking like reiserfs leaves found */
unsigned long leaves_corrected;
unsigned long all_contents_removed;
unsigned long too_old_leaves; /* these are leaves which contains
direntries with different hash from the
one specified with -h */
unsigned long wrong_pointers; /* pointers in indirect items pointing to
wrong area */
unsigned long pointed; /* pointers blocks of device pointed by all
indirect items */
};
struct pass1_stat {
unsigned long leaves; /* leaves found in pass0 to build tree off */
unsigned long inserted_leaves; /* number of leaves inserted by pointers */
unsigned long pointed_leaves; /* pointers in indirect items which pointed
to leaves (zeroed) */
unsigned long uninsertable_leaves;
unsigned long non_unique_pointers; /* pointers to already pointed unformatted nodes */
unsigned long correct_pointers;
unsigned long saved_items; /* items saved on pass1: should be 0 */
unsigned long allocable_blocks; /* allocable blocks before pass 1 starts */
unsigned long leaves; /* leaves found in pass0 to build tree off */
unsigned long inserted_leaves; /* number of leaves inserted by pointers */
unsigned long pointed_leaves; /* pointers in indirect items which pointed
to leaves (zeroed) */
unsigned long uninsertable_leaves;
unsigned long non_unique_pointers; /* pointers to already pointed unformatted nodes */
unsigned long correct_pointers;
unsigned long saved_items; /* items saved on pass1: should be 0 */
unsigned long allocable_blocks; /* allocable blocks before pass 1 starts */
};
struct pass2_stat {
unsigned long leaves; /* leaves inserted item by item */
unsigned long safe_non_unique_pointers; /* these are just the same pointers */
unsigned long relocated;
unsigned long shared_objectids;
unsigned long rewritten;
unsigned long leaves; /* leaves inserted item by item */
unsigned long safe_non_unique_pointers; /* these are just the same pointers */
unsigned long relocated;
unsigned long shared_objectids;
unsigned long rewritten;
};
struct semantic_stat {
unsigned long oid_sharing_files_relocated;
unsigned long regular_files;
unsigned long directories;
unsigned long symlinks;
unsigned long broken_files;
unsigned long others;
unsigned long fixed_sizes;
unsigned long oid_sharing;
unsigned long oid_sharing_dirs_relocated;
unsigned long deleted_entries;
unsigned long oid_sharing_files_relocated;
unsigned long regular_files;
unsigned long directories;
unsigned long symlinks;
unsigned long broken_files;
unsigned long others;
unsigned long fixed_sizes;
unsigned long oid_sharing;
unsigned long oid_sharing_dirs_relocated;
unsigned long deleted_entries;
};
struct lost_found_stat {
unsigned long dir_recovered;
unsigned long empty_lost_dirs;
unsigned long lost_found;
unsigned long lost_found_files;
unsigned long lost_found_dirs;
unsigned long oid_sharing;
unsigned long oid_sharing_dirs_relocated;
unsigned long oid_sharing_files_relocated;
unsigned long dir_recovered;
unsigned long empty_lost_dirs;
unsigned long lost_found;
unsigned long lost_found_files;
unsigned long lost_found_dirs;
unsigned long oid_sharing;
unsigned long oid_sharing_dirs_relocated;
unsigned long oid_sharing_files_relocated;
};
struct pass_4_stat {
unsigned long deleted_items;
unsigned long deleted_items;
};
struct rebuild_info {
union {
struct pass0_stat pass0;
struct pass1_stat pass1;
struct pass2_stat pass2;
struct {
struct semantic_stat semantic;
struct lost_found_stat lost_found;
} tree;
struct pass_4_stat pass4;
} pass_u;
union {
struct pass0_stat pass0;
struct pass1_stat pass1;
struct pass2_stat pass2;
struct {
struct semantic_stat semantic;
struct lost_found_stat lost_found;
} tree;
struct pass_4_stat pass4;
} pass_u;
/* bitmaps */
reiserfs_bitmap_t * source_bitmap;
reiserfs_bitmap_t * new_bitmap;
reiserfs_bitmap_t * allocable_bitmap;
reiserfs_bitmap_t * uninsertables;
/* bitmaps */
reiserfs_bitmap_t *source_bitmap;
reiserfs_bitmap_t *new_bitmap;
reiserfs_bitmap_t *allocable_bitmap;
reiserfs_bitmap_t *uninsertables;
char * bitmap_file_name;
/*char * new_bitmap_file_name;*/
char * passes_dump_file_name; /* after pass 0, 1 or 2 reiserfsck can store
data with which it will be able to start
from the point it stopped last time at */
char *bitmap_file_name;
/*char * new_bitmap_file_name; */
char *passes_dump_file_name; /* after pass 0, 1 or 2 reiserfsck can store
data with which it will be able to start
from the point it stopped last time at */
unsigned short mode;
unsigned long options;
unsigned short mode;
unsigned long options;
/* rollback file */
char * rollback_file;
/* hash hits stat */
int hash_amount;
unsigned long * hash_hits;
char * defined_hash;
/* rollback file */
char *rollback_file;
/* hash hits stat */
int hash_amount;
unsigned long *hash_hits;
char *defined_hash;
#define USED_BLOCKS 1
#define EXTERN_BITMAP 2
#define ALL_BLOCKS 3
int scan_area;
int use_journal_area;
int test;
int scan_area;
int use_journal_area;
int test;
};
struct check_info {
unsigned long bad_nodes;
unsigned long fatal_corruptions;
unsigned long fixable_corruptions;
unsigned long bad_nodes;
unsigned long fatal_corruptions;
unsigned long fixable_corruptions;
// unsigned long badblocks_corruptions;
unsigned long leaves;
unsigned long internals;
unsigned long dirs;
unsigned long files;
unsigned long safe;
unsigned long unfm_pointers;
unsigned long zero_unfm_pointers;
reiserfs_bitmap_t * deallocate_bitmap;
unsigned long leaves;
unsigned long internals;
unsigned long dirs;
unsigned long files;
unsigned long safe;
unsigned long unfm_pointers;
unsigned long zero_unfm_pointers;
reiserfs_bitmap_t *deallocate_bitmap;
};
struct fsck_data {
unsigned short mode; /* check, rebuild, etc*/
unsigned long options;
unsigned long mounted;
unsigned short mode; /* check, rebuild, etc */
unsigned long options;
unsigned long mounted;
struct rebuild_info rebuild;
struct check_info check;
struct rebuild_info rebuild;
struct check_info check;
char * journal_dev_name;
/* log file name and handle */
char * log_file_name;
FILE * log;
char *journal_dev_name;
/* log file name and handle */
char *log_file_name;
FILE *log;
/* this is a file where reiserfsck will explain what it is doing. This is
usually stderr. But when -g is specified - reiserfsck runs in the
background and append progress information into 'fsck.run' */
FILE * progress;
/* this is a file where reiserfsck will explain what it is doing. This is
usually stderr. But when -g is specified - reiserfsck runs in the
background and append progress information into 'fsck.run' */
FILE *progress;
/* objectid maps */
id_map_t * proper_id_map;
id_map_t * semantic_id_map; /* this objectid map is used to
cure objectid sharing problem */
/* objectid maps */
id_map_t *proper_id_map;
id_map_t *semantic_id_map; /* this objectid map is used to
cure objectid sharing problem */
};
#define fsck_data(fs) ((struct fsck_data *)((fs)->fs_vp))
#define pass_0_stat(fs) (&(fsck_data(fs)->rebuild.pass_u.pass0))
#define pass_1_stat(fs) (&(fsck_data(fs)->rebuild.pass_u.pass1))
@@ -433,7 +425,6 @@ struct fsck_data {
#define fsck_check_stat(fs) (&(fsck_data(fs)->check))
#define proper_id_map(s) fsck_data(s)->proper_id_map
#define semantic_id_map(s) fsck_data(s)->semantic_id_map
@@ -464,7 +455,6 @@ struct fsck_data {
#define fsck_skip_journal(fs) (fsck_data(fs)->options & OPT_SKIP_JOURNAL)
#define fsck_yes_all(fs) (fsck_data(fs)->options & OPT_YES)
#define fsck_mode(fs) (fsck_data(fs)->mode)
#define fsck_log_file(fs) (fsck_data(fs)->log)
#define fsck_progress_file(fs) ((fs && fsck_data(fs)->progress) ? fsck_data(fs)->progress : stderr)
@@ -475,15 +465,15 @@ struct fsck_data {
/* name of file where we store rollback data */
#define state_rollback_file(fs) fsck_data(fs)->rebuild.rollback_file
int fsck_user_confirmed (reiserfs_filsys_t * fs, char * q, char * a, int default_answer);
void stage_report (int, reiserfs_filsys_t *);
int fsck_user_confirmed(reiserfs_filsys_t *fs, char *q, char *a,
int default_answer);
void stage_report(int, reiserfs_filsys_t *);
/* journal.c */
int replay_journal (reiserfs_filsys_t *);
int replay_journal(reiserfs_filsys_t *);
/*pass1: rebuild super block*/
void rebuild_sb (reiserfs_filsys_t * fs, char * filename, struct fsck_data * data);
void rebuild_sb(reiserfs_filsys_t *fs, char *filename, struct fsck_data *data);
#define fsck_log(fmt, list...) \
{\
+189 -151
View File
@@ -5,172 +5,210 @@
#include "fsck.h"
int fsck_user_confirmed (reiserfs_filsys_t * fs, char * q, char * a, int default_answer)
int fsck_user_confirmed(reiserfs_filsys_t *fs, char *q, char *a,
int default_answer)
{
if (!fsck_interactive (fs))
return default_answer;
return user_confirmed (fsck_progress_file (fs), q, a);
if (!fsck_interactive(fs))
return default_answer;
return user_confirmed(fsck_progress_file(fs), q, a);
}
void stage_report (int pass, reiserfs_filsys_t * fs)
void stage_report(int pass, reiserfs_filsys_t *fs)
{
switch (pass) {
case 0:
{
struct pass0_stat * stat;
switch (pass) {
case 0:
{
struct pass0_stat *stat;
/* what has been done on pass 0 */
stat = pass_0_stat (fs);
fsck_progress ("\tRead blocks (but not data blocks) %lu\n", stat->dealt_with);
fsck_progress ("\t\tLeaves among those %lu\n", stat->leaves);
if (stat->leaves_corrected)
fsck_progress ("\t\t\t- corrected leaves %lu\n", stat->leaves_corrected);
if (stat->all_contents_removed)
fsck_progress ("\t\t\t- leaves all contents of which could not be saved and deleted %lu\n",
stat->all_contents_removed);
if (stat->too_old_leaves)
fsck_progress ("\t\t\t- too old leaves %lu (skipped)\n", stat->too_old_leaves);
if (stat->wrong_pointers)
fsck_progress ("\t\tpointers in indirect items to wrong area %lu (zeroed)\n",
stat->wrong_pointers);
fsck_progress ("\t\tObjectids found %lu\n", proper_id_map(fs)->count);
}
break;
case 1:
{
struct pass1_stat * stat;
/* what has been done on pass 0 */
stat = pass_0_stat(fs);
fsck_progress
("\tRead blocks (but not data blocks) %lu\n",
stat->dealt_with);
fsck_progress("\t\tLeaves among those %lu\n",
stat->leaves);
if (stat->leaves_corrected)
fsck_progress("\t\t\t- corrected leaves %lu\n",
stat->leaves_corrected);
if (stat->all_contents_removed)
fsck_progress
("\t\t\t- leaves all contents of which could not be saved and deleted %lu\n",
stat->all_contents_removed);
if (stat->too_old_leaves)
fsck_progress
("\t\t\t- too old leaves %lu (skipped)\n",
stat->too_old_leaves);
if (stat->wrong_pointers)
fsck_progress
("\t\tpointers in indirect items to wrong area %lu (zeroed)\n",
stat->wrong_pointers);
fsck_progress("\t\tObjectids found %lu\n",
proper_id_map(fs)->count);
}
break;
/* what has been done on pass 1 */
stat = pass_1_stat (fs);
fsck_progress ("\t%lu leaves read\n", stat->leaves);
fsck_progress ("\t\t%lu inserted\n", stat->inserted_leaves);
if (stat->pointed_leaves)
fsck_progress ("\t\t\t- pointers in indirect items pointing to metadata %lu (zeroed)\n",
stat->pointed_leaves);
if (stat->saved_items)
fsck_progress ("\tSaved %lu items\n", stat->saved_items);
if (stat->uninsertable_leaves)
fsck_progress ("\t\t%lu not inserted\n", stat->uninsertable_leaves);
if (stat->non_unique_pointers)
fsck_progress ("\tnon-unique pointers in indirect items (zeroed) %lu\n",
stat->non_unique_pointers);
}
break;
case 1:
{
struct pass1_stat *stat;
case 2:
{
struct pass2_stat * stat;
/* what has been done on pass 1 */
stat = pass_1_stat(fs);
fsck_progress("\t%lu leaves read\n", stat->leaves);
fsck_progress("\t\t%lu inserted\n",
stat->inserted_leaves);
if (stat->pointed_leaves)
fsck_progress
("\t\t\t- pointers in indirect items pointing to metadata %lu (zeroed)\n",
stat->pointed_leaves);
if (stat->saved_items)
fsck_progress("\tSaved %lu items\n",
stat->saved_items);
if (stat->uninsertable_leaves)
fsck_progress("\t\t%lu not inserted\n",
stat->uninsertable_leaves);
if (stat->non_unique_pointers)
fsck_progress
("\tnon-unique pointers in indirect items (zeroed) %lu\n",
stat->non_unique_pointers);
}
break;
/* what has been done on pass 2 */
stat = pass_2_stat (fs);
if (stat->leaves)
fsck_progress ("\tLeaves inserted item by item %lu\n", stat->leaves);
if (stat->safe_non_unique_pointers)
fsck_progress ("\t%lu \n",
stat->safe_non_unique_pointers);
if (stat->shared_objectids)
fsck_progress ("\t%lu shared objectids\n", stat->shared_objectids);
if (stat->relocated)
fsck_progress ("\tFiles relocated because of key conflicts with a directory %lu\n",
stat->relocated);
if (stat->rewritten)
fsck_progress ("\tFiles rewritten %lu\n", stat->rewritten);
}
break;
case 2:
{
struct pass2_stat *stat;
case 3: /* semantic */
{
struct semantic_stat * stat;
/* what has been done on pass 2 */
stat = pass_2_stat(fs);
if (stat->leaves)
fsck_progress
("\tLeaves inserted item by item %lu\n",
stat->leaves);
if (stat->safe_non_unique_pointers)
fsck_progress("\t%lu \n",
stat->safe_non_unique_pointers);
if (stat->shared_objectids)
fsck_progress("\t%lu shared objectids\n",
stat->shared_objectids);
if (stat->relocated)
fsck_progress
("\tFiles relocated because of key conflicts with a directory %lu\n",
stat->relocated);
if (stat->rewritten)
fsck_progress("\tFiles rewritten %lu\n",
stat->rewritten);
}
break;
/* what has been done on the semantic pass */
stat = sem_pass_stat (fs);
fsck_progress ("\tFiles found: %ld\n", stat->regular_files);
fsck_progress ("\tDirectories found: %ld\n", stat->directories);
if (stat->symlinks)
fsck_progress ("\tSymlinks found: %ld\n", stat->symlinks);
if (stat->others)
fsck_progress ("\tOthers: %ld\n", stat->others);
if (stat->broken_files)
fsck_progress ("\tBroken (of files/symlinks/others): %ld\n", stat->broken_files);
if (stat->fixed_sizes)
fsck_progress ("\tFiles with fixed size: %ld\n", stat->fixed_sizes);
if (stat->deleted_entries)
fsck_progress ("\tNames pointing to nowhere (removed): %ld\n", stat->deleted_entries);
if (stat->oid_sharing)
fsck_progress ("\tObjects having used objectids: %lu\n", stat->oid_sharing);
if (stat->oid_sharing_files_relocated)
fsck_progress ("\t\tfiles fixed %lu\n", stat->oid_sharing_files_relocated);
if (stat->oid_sharing_dirs_relocated)
fsck_progress ("\t\tdirs fixed %lu\n", stat->oid_sharing_dirs_relocated);
}
break;
case 0x3a: /* lost+found pass */
{
struct lost_found_stat * stat;
case 3: /* semantic */
{
struct semantic_stat *stat;
/* what has been done on the semantic pass */
stat = lost_found_pass_stat (fs);
if (stat->lost_found)
fsck_progress ("\tObjects without names %lu\n",
stat->lost_found);
if (stat->empty_lost_dirs)
fsck_progress ("\tEmpty lost dirs removed %lu\n",
stat->empty_lost_dirs);
if (stat->lost_found_dirs)
fsck_progress ("\tDirs linked to /lost+found: %lu\n",
stat->lost_found_dirs);
if (stat->dir_recovered)
fsck_progress ("\t\tDirs without stat data found %lu\n",
stat->dir_recovered);
/* what has been done on the semantic pass */
stat = sem_pass_stat(fs);
fsck_progress("\tFiles found: %ld\n",
stat->regular_files);
fsck_progress("\tDirectories found: %ld\n",
stat->directories);
if (stat->symlinks)
fsck_progress("\tSymlinks found: %ld\n",
stat->symlinks);
if (stat->others)
fsck_progress("\tOthers: %ld\n", stat->others);
if (stat->broken_files)
fsck_progress
("\tBroken (of files/symlinks/others): %ld\n",
stat->broken_files);
if (stat->fixed_sizes)
fsck_progress("\tFiles with fixed size: %ld\n",
stat->fixed_sizes);
if (stat->deleted_entries)
fsck_progress
("\tNames pointing to nowhere (removed): %ld\n",
stat->deleted_entries);
if (stat->oid_sharing)
fsck_progress
("\tObjects having used objectids: %lu\n",
stat->oid_sharing);
if (stat->oid_sharing_files_relocated)
fsck_progress("\t\tfiles fixed %lu\n",
stat->
oid_sharing_files_relocated);
if (stat->oid_sharing_dirs_relocated)
fsck_progress("\t\tdirs fixed %lu\n",
stat->oid_sharing_dirs_relocated);
}
break;
if (stat->lost_found_files)
fsck_progress ("\tFiles linked to /lost+found %lu\n",
stat->lost_found_files);
if (stat->oid_sharing)
fsck_progress ("\tObjects having used objectids: %lu\n", stat->oid_sharing);
if (stat->oid_sharing_files_relocated)
fsck_progress ("\t\tfiles fixed %lu\n", stat->oid_sharing_files_relocated);
if (stat->oid_sharing_dirs_relocated)
fsck_progress ("\t\tdirs fixed %lu\n", stat->oid_sharing_dirs_relocated);
}
break;
case 0x3a: /* lost+found pass */
{
struct lost_found_stat *stat;
case 4: /* removing of unreachable */
{
struct pass_4_stat * stat;
/* what has been done on the semantic pass */
stat = lost_found_pass_stat(fs);
if (stat->lost_found)
fsck_progress("\tObjects without names %lu\n",
stat->lost_found);
if (stat->empty_lost_dirs)
fsck_progress("\tEmpty lost dirs removed %lu\n",
stat->empty_lost_dirs);
if (stat->lost_found_dirs)
fsck_progress
("\tDirs linked to /lost+found: %lu\n",
stat->lost_found_dirs);
if (stat->dir_recovered)
fsck_progress
("\t\tDirs without stat data found %lu\n",
stat->dir_recovered);
/* what has been done on the semantic pass */
stat = pass_4_stat (fs);
if (stat->deleted_items)
fsck_progress ("\tDeleted unreachable items %lu\n",
stat->deleted_items);
}
break;
if (stat->lost_found_files)
fsck_progress
("\tFiles linked to /lost+found %lu\n",
stat->lost_found_files);
if (stat->oid_sharing)
fsck_progress
("\tObjects having used objectids: %lu\n",
stat->oid_sharing);
if (stat->oid_sharing_files_relocated)
fsck_progress("\t\tfiles fixed %lu\n",
stat->
oid_sharing_files_relocated);
if (stat->oid_sharing_dirs_relocated)
fsck_progress("\t\tdirs fixed %lu\n",
stat->oid_sharing_dirs_relocated);
}
break;
case 5:
fsck_progress ("There are on the filesystem:\n"
"\tLeaves %lu\n\tInternal nodes %lu\n"
"\tDirectories %lu\n\tOther files %lu\n"
"\tData block pointers %lu (%lu of them are zero)\n"
"\tSafe links %lu\n",
fsck_check_stat (fs)->leaves,
fsck_check_stat (fs)->internals,
fsck_check_stat (fs)->dirs,
fsck_check_stat (fs)->files,
fsck_check_stat (fs)->unfm_pointers,
fsck_check_stat (fs)->zero_unfm_pointers,
fsck_check_stat (fs)->safe);
} /* switch */
case 4: /* removing of unreachable */
{
struct pass_4_stat *stat;
memset (&fsck_data (fs)->rebuild.pass_u, 0, sizeof (fsck_data (fs)->rebuild.pass_u));
/* what has been done on the semantic pass */
stat = pass_4_stat(fs);
if (stat->deleted_items)
fsck_progress
("\tDeleted unreachable items %lu\n",
stat->deleted_items);
}
break;
case 5:
fsck_progress("There are on the filesystem:\n"
"\tLeaves %lu\n\tInternal nodes %lu\n"
"\tDirectories %lu\n\tOther files %lu\n"
"\tData block pointers %lu (%lu of them are zero)\n"
"\tSafe links %lu\n",
fsck_check_stat(fs)->leaves,
fsck_check_stat(fs)->internals,
fsck_check_stat(fs)->dirs,
fsck_check_stat(fs)->files,
fsck_check_stat(fs)->unfm_pointers,
fsck_check_stat(fs)->zero_unfm_pointers,
fsck_check_stat(fs)->safe);
} /* switch */
memset(&fsck_data(fs)->rebuild.pass_u, 0,
sizeof(fsck_data(fs)->rebuild.pass_u));
}
+359 -312
View File
@@ -5,368 +5,415 @@
#include "fsck.h"
void erase_name(int len);
void print_name(char *name, int len);
void erase_name (int len);
void print_name (char * name, int len);
void modify_item (struct item_head * ih, void * item);
void modify_item(struct item_head *ih, void *item);
/* fixme: search_by_key is not needed after any add_entry */
static __u64 _look_for_lost (reiserfs_filsys_t * fs, int link_lost_dirs)
static __u64 _look_for_lost(reiserfs_filsys_t *fs, int link_lost_dirs)
{
struct reiserfs_key key, prev_key, * rdkey;
INITIALIZE_REISERFS_PATH(path);
int item_pos;
struct buffer_head * bh;
struct item_head * ih;
unsigned long leaves;
int is_it_dir;
static int lost_files = 0; /* looking for lost dirs we calculate amount of
lost files, so that when we will look for
lost files we will be able to stop when
there are no lost files anymore */
int retval;
__u64 size;
struct reiserfs_key key, prev_key, *rdkey;
INITIALIZE_REISERFS_PATH(path);
int item_pos;
struct buffer_head *bh;
struct item_head *ih;
unsigned long leaves;
int is_it_dir;
static int lost_files = 0; /* looking for lost dirs we calculate amount of
lost files, so that when we will look for
lost files we will be able to stop when
there are no lost files anymore */
int retval;
__u64 size;
key = root_dir_key;
key = root_dir_key;
if (!link_lost_dirs && !lost_files) {
/* we have to look for lost files but we know already that there are
no any */
return 0;
}
fsck_progress ("Looking for lost %s:\n", link_lost_dirs ? "directories" : "files");
leaves = 0;
/* total size of added entries */
size = 0;
while (1) {
retval = reiserfs_search_by_key_4 (fs, &key, &path);
/* fixme: we assume path ends up with a leaf */
bh = get_bh (&path);
item_pos = get_item_pos (&path);
if (retval != ITEM_FOUND) {
if (item_pos == get_blkh_nr_items (B_BLK_HEAD (bh))) {
rdkey = uget_rkey (&path);
if (!rdkey) {
pathrelse (&path);
break;
}
key = *rdkey;
pathrelse (&path);
continue;
}
/* we are on the item in the buffer */
}
/* print ~ how many leaves were scanned and how fast it was */
if (!fsck_quiet (fs))
print_how_fast (leaves++, 0, 50, 0);
for (ih = get_ih (&path); item_pos < get_blkh_nr_items (B_BLK_HEAD (bh)); item_pos ++, ih ++, PATH_LAST_POSITION(&path)++) {
if (is_item_reachable (ih))
continue;
/* found item which can not be reached */
if (!is_direntry_ih (ih) && !is_stat_data_ih (ih)) {
continue;
}
if (is_direntry_ih (ih)) {
/* if this directory has no stat data - try to recover it */
struct reiserfs_key sd;
struct reiserfs_path tmp;
sd = ih->ih_key;
set_type_and_offset (KEY_FORMAT_1, &sd, SD_OFFSET, TYPE_STAT_DATA);
if (reiserfs_search_by_key_4 (fs, &sd, &tmp) == ITEM_FOUND) {
/* should not happen - because if there were a stat data -
we would have done with the whole directory */
pathrelse (&tmp);
continue;
}
lost_found_pass_stat (fs)->dir_recovered ++;
create_dir_sd (fs, &tmp, &sd, modify_item);
id_map_mark(proper_id_map (fs), get_key_objectid (&sd));
key = sd;
pathrelse (&path);
goto cont;
}
/* stat data marked "not having name" found */
if (is_stat_data_ih (get_ih(&path)))
fix_obviously_wrong_sd_mode (&path);
is_it_dir = ((not_a_directory (B_I_PITEM (bh,ih))) ? 0 : 1);
if (is_it_dir) {
struct reiserfs_key tmp_key;
INITIALIZE_REISERFS_PATH(tmp_path);
struct item_head * tmp_ih;
/* there is no need to link empty lost directories into /lost+found */
tmp_key = ih->ih_key;
set_type_and_offset (KEY_FORMAT_1, &tmp_key, 0xffffffff, TYPE_DIRENTRY);
reiserfs_search_by_key_4 (fs, &tmp_key, &tmp_path);
tmp_ih = get_ih (&tmp_path);
tmp_ih --;
if (not_of_one_file (&tmp_key, tmp_ih))
reiserfs_panic ("not directory found");
if (!is_direntry_ih (tmp_ih) ||
(get_deh_offset (B_I_DEH (get_bh (&tmp_path), tmp_ih) +
get_ih_entry_count (tmp_ih) - 1) == DOT_DOT_OFFSET)) {
/* last directory item is either stat data or empty
directory item - do not link this dir into lost+found */
lost_found_pass_stat (fs)->empty_lost_dirs ++;
pathrelse (&tmp_path);
continue;
}
pathrelse (&tmp_path);
}
if (link_lost_dirs && !is_it_dir) {
/* we are looking for directories and it is not a dir */
lost_files ++;
continue;
}
lost_found_pass_stat (fs)->lost_found ++;
{
struct reiserfs_key obj_key = {0, 0, {{0, 0},}};
char * lost_name;
struct item_head tmp_ih;
/* key to continue */
key = ih->ih_key;
set_key_objectid (&key, get_key_objectid (&key) + 1);
tmp_ih = *ih;
if (id_map_test(semantic_id_map (fs), get_key_objectid (&ih->ih_key))) {
/* objectid is used, relocate an object */
lost_found_pass_stat (fs)->oid_sharing ++;
if (is_it_dir) {
relocate_dir (&tmp_ih, 1);
lost_found_pass_stat (fs)->oid_sharing_dirs_relocated ++;
} else {
rewrite_file (&tmp_ih, 1, 1);
lost_found_pass_stat (fs)->oid_sharing_files_relocated ++;
}
linked_already(&tmp_ih.ih_key);
} else {
if (!is_it_dir)
id_map_mark(semantic_id_map (fs), get_key_objectid (&ih->ih_key));
}
asprintf (&lost_name, "%u_%u", get_key_dirid (&tmp_ih.ih_key),
get_key_objectid (&tmp_ih.ih_key));
/* entry in lost+found directory will point to this key */
set_key_dirid (&obj_key, get_key_dirid (&tmp_ih.ih_key));
set_key_objectid (&obj_key, get_key_objectid (&tmp_ih.ih_key));
pathrelse (&path);
/* 0 does not mean anyting - item with "." and ".." already
exists and reached, so only name will be added */
size += reiserfs_add_entry (fs, &lost_found_dir_key, lost_name,
name_length (lost_name, lost_found_dir_format), &obj_key, 0/*fsck_need*/);
if (is_it_dir) {
/* fixme: we hope that if we will try to pull all the
directory right now - then there will be less
lost_found things */
print_name (lost_name, strlen (lost_name));
/*fsck_progress ("\tChecking lost dir \"%s\":", lost_name);*/
rebuild_semantic_pass (&obj_key, &lost_found_dir_key, /*dot_dot*/0, /*reloc_ih*/0);
erase_name (strlen (lost_name));
/*fsck_progress ("finished\n");*/
lost_found_pass_stat (fs)->lost_found_dirs ++;
} else {
if (reiserfs_search_by_key_4 (fs, &obj_key, &path) != ITEM_FOUND)
reiserfs_panic ("look_for_lost: lost file stat data %K not found",
&obj_key);
/* check_regular_file does not mark stat data reachable */
mark_item_reachable (get_ih (&path), get_bh (&path));
rebuild_check_regular_file (&path, get_item (&path), 0/*reloc_ih*/);
pathrelse (&path);
lost_found_pass_stat (fs)->lost_found_files ++;
lost_files --;
}
free (lost_name);
goto cont;
}
} /* for */
prev_key = key;
PATH_LAST_POSITION(&path) = item_pos - 1;
rdkey = reiserfs_next_key (&path);
if (rdkey)
key = *rdkey;
else
break;
if (comp_keys (&prev_key, &key) != -1)
reiserfs_panic ("pass_3a: key must grow 2: prev=%k next=%k",
&prev_key, &key);
pathrelse (&path);
cont:
if (!link_lost_dirs && !lost_files) {
break;
/* we have to look for lost files but we know already that there are
no any */
return 0;
}
}
pathrelse (&path);
fsck_progress("Looking for lost %s:\n",
link_lost_dirs ? "directories" : "files");
leaves = 0;
/* total size of added entries */
size = 0;
while (1) {
retval = reiserfs_search_by_key_4(fs, &key, &path);
/* fixme: we assume path ends up with a leaf */
bh = get_bh(&path);
item_pos = get_item_pos(&path);
if (retval != ITEM_FOUND) {
if (item_pos == get_blkh_nr_items(B_BLK_HEAD(bh))) {
rdkey = uget_rkey(&path);
if (!rdkey) {
pathrelse(&path);
break;
}
key = *rdkey;
pathrelse(&path);
continue;
}
/* we are on the item in the buffer */
}
/* print ~ how many leaves were scanned and how fast it was */
if (!fsck_quiet(fs))
print_how_fast(leaves++, 0, 50, 0);
for (ih = get_ih(&path);
item_pos < get_blkh_nr_items(B_BLK_HEAD(bh));
item_pos++, ih++, PATH_LAST_POSITION(&path)++) {
if (is_item_reachable(ih))
continue;
/* found item which can not be reached */
if (!is_direntry_ih(ih) && !is_stat_data_ih(ih)) {
continue;
}
if (is_direntry_ih(ih)) {
/* if this directory has no stat data - try to recover it */
struct reiserfs_key sd;
struct reiserfs_path tmp;
sd = ih->ih_key;
set_type_and_offset(KEY_FORMAT_1, &sd,
SD_OFFSET, TYPE_STAT_DATA);
if (reiserfs_search_by_key_4(fs, &sd, &tmp) ==
ITEM_FOUND) {
/* should not happen - because if there were a stat data -
we would have done with the whole directory */
pathrelse(&tmp);
continue;
}
lost_found_pass_stat(fs)->dir_recovered++;
create_dir_sd(fs, &tmp, &sd, modify_item);
id_map_mark(proper_id_map(fs),
get_key_objectid(&sd));
key = sd;
pathrelse(&path);
goto cont;
}
/* stat data marked "not having name" found */
if (is_stat_data_ih(get_ih(&path)))
fix_obviously_wrong_sd_mode(&path);
is_it_dir =
((not_a_directory(B_I_PITEM(bh, ih))) ? 0 : 1);
if (is_it_dir) {
struct reiserfs_key tmp_key;
INITIALIZE_REISERFS_PATH(tmp_path);
struct item_head *tmp_ih;
/* there is no need to link empty lost directories into /lost+found */
tmp_key = ih->ih_key;
set_type_and_offset(KEY_FORMAT_1, &tmp_key,
0xffffffff, TYPE_DIRENTRY);
reiserfs_search_by_key_4(fs, &tmp_key,
&tmp_path);
tmp_ih = get_ih(&tmp_path);
tmp_ih--;
if (not_of_one_file(&tmp_key, tmp_ih))
reiserfs_panic("not directory found");
if (!is_direntry_ih(tmp_ih) ||
(get_deh_offset
(B_I_DEH(get_bh(&tmp_path), tmp_ih) +
get_ih_entry_count(tmp_ih) - 1) ==
DOT_DOT_OFFSET)) {
/* last directory item is either stat data or empty
directory item - do not link this dir into lost+found */
lost_found_pass_stat(fs)->
empty_lost_dirs++;
pathrelse(&tmp_path);
continue;
}
pathrelse(&tmp_path);
}
if (link_lost_dirs && !is_it_dir) {
/* we are looking for directories and it is not a dir */
lost_files++;
continue;
}
lost_found_pass_stat(fs)->lost_found++;
{
struct reiserfs_key obj_key =
{ 0, 0, {{0, 0},} };
char *lost_name;
struct item_head tmp_ih;
/* key to continue */
key = ih->ih_key;
set_key_objectid(&key,
get_key_objectid(&key) + 1);
tmp_ih = *ih;
if (id_map_test
(semantic_id_map(fs),
get_key_objectid(&ih->ih_key))) {
/* objectid is used, relocate an object */
lost_found_pass_stat(fs)->oid_sharing++;
if (is_it_dir) {
relocate_dir(&tmp_ih, 1);
lost_found_pass_stat(fs)->
oid_sharing_dirs_relocated++;
} else {
rewrite_file(&tmp_ih, 1, 1);
lost_found_pass_stat(fs)->
oid_sharing_files_relocated++;
}
linked_already(&tmp_ih.ih_key);
} else {
if (!is_it_dir)
id_map_mark(semantic_id_map(fs),
get_key_objectid
(&ih->ih_key));
}
asprintf(&lost_name, "%u_%u",
get_key_dirid(&tmp_ih.ih_key),
get_key_objectid(&tmp_ih.ih_key));
/* entry in lost+found directory will point to this key */
set_key_dirid(&obj_key,
get_key_dirid(&tmp_ih.ih_key));
set_key_objectid(&obj_key,
get_key_objectid(&tmp_ih.
ih_key));
pathrelse(&path);
/* 0 does not mean anyting - item with "." and ".." already
exists and reached, so only name will be added */
size +=
reiserfs_add_entry(fs, &lost_found_dir_key,
lost_name,
name_length(lost_name,
lost_found_dir_format),
&obj_key,
0 /*fsck_need */ );
if (is_it_dir) {
/* fixme: we hope that if we will try to pull all the
directory right now - then there will be less
lost_found things */
print_name(lost_name,
strlen(lost_name));
/*fsck_progress ("\tChecking lost dir \"%s\":", lost_name); */
rebuild_semantic_pass(&obj_key,
&lost_found_dir_key,
/*dot_dot */ 0,
/*reloc_ih */ 0);
erase_name(strlen(lost_name));
/*fsck_progress ("finished\n"); */
lost_found_pass_stat(fs)->
lost_found_dirs++;
} else {
if (reiserfs_search_by_key_4
(fs, &obj_key, &path) != ITEM_FOUND)
reiserfs_panic
("look_for_lost: lost file stat data %K not found",
&obj_key);
/* check_regular_file does not mark stat data reachable */
mark_item_reachable(get_ih(&path),
get_bh(&path));
rebuild_check_regular_file(&path,
get_item
(&path),
0
/*reloc_ih */
);
pathrelse(&path);
lost_found_pass_stat(fs)->
lost_found_files++;
lost_files--;
}
free(lost_name);
goto cont;
}
} /* for */
prev_key = key;
PATH_LAST_POSITION(&path) = item_pos - 1;
rdkey = reiserfs_next_key(&path);
if (rdkey)
key = *rdkey;
else
break;
if (comp_keys(&prev_key, &key) != -1)
reiserfs_panic
("pass_3a: key must grow 2: prev=%k next=%k",
&prev_key, &key);
pathrelse(&path);
cont:
if (!link_lost_dirs && !lost_files) {
break;
}
}
pathrelse(&path);
#if 0
/* check names added we just have added to/lost+found. Those names are
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 ("finished\n");
/* check names added we just have added to/lost+found. Those names are
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("finished\n");
#endif
return size;
return size;
}
static void save_lost_found_result (reiserfs_filsys_t * fs)
static void save_lost_found_result(reiserfs_filsys_t *fs)
{
FILE * file;
int retval;
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;
/* save bitmaps with which we will be able start reiserfs from
pass 1 */
file = open_file("temp_fsck_file.deleteme", "w+");
if (!file)
return;
reiserfs_begin_stage_info_save (file, LOST_FOUND_DONE);
reiserfs_end_stage_info_save (file);
close_file (file);
reiserfs_begin_stage_info_save(file, LOST_FOUND_DONE);
reiserfs_end_stage_info_save(file);
close_file(file);
retval = rename ("temp_fsck_file.deleteme", state_dump_file (fs));
if (retval != 0)
fsck_progress ("pass 0: Could not rename the temporary file temp_fsck_file.deleteme to %s",
state_dump_file (fs));
retval = rename("temp_fsck_file.deleteme", state_dump_file(fs));
if (retval != 0)
fsck_progress
("pass 0: Could not rename the temporary file temp_fsck_file.deleteme to %s",
state_dump_file(fs));
}
/* we have nothing to load from a state file, but we have to fetch
on-disk bitmap, copy it to allocable bitmap, and fetch objectid
map */
void load_lost_found_result (reiserfs_filsys_t * fs)
void load_lost_found_result(reiserfs_filsys_t *fs)
{
fsck_new_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
reiserfs_bitmap_copy (fsck_new_bitmap (fs), fs->fs_bitmap2);
fsck_new_bitmap(fs) =
reiserfs_create_bitmap(get_sb_block_count(fs->fs_ondisk_sb));
reiserfs_bitmap_copy(fsck_new_bitmap(fs), fs->fs_bitmap2);
fsck_allocable_bitmap (fs) = reiserfs_create_bitmap (get_sb_block_count (fs->fs_ondisk_sb));
reiserfs_bitmap_copy (fsck_allocable_bitmap (fs), fs->fs_bitmap2);
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;
fs->block_allocator = reiserfsck_reiserfs_new_blocknrs;
fs->block_deallocator = reiserfsck_reiserfs_free_block;
/* we need objectid map on semantic pass to be able to relocate files */
proper_id_map (fs) = id_map_init();
/* Not implemented yet.
fetch_objectid_map (proper_id_map (fs), fs);
*/
/* we need objectid map on semantic pass to be able to relocate files */
proper_id_map(fs) = id_map_init();
/* Not implemented yet.
fetch_objectid_map (proper_id_map (fs), fs);
*/
}
void after_lost_found (reiserfs_filsys_t * fs)
void after_lost_found(reiserfs_filsys_t *fs)
{
/* update super block: objectid map, fsck state */
set_sb_fs_state (fs->fs_ondisk_sb, LOST_FOUND_DONE);
mark_buffer_dirty (fs->fs_super_bh);
/* update super block: objectid map, fsck state */
set_sb_fs_state(fs->fs_ondisk_sb, LOST_FOUND_DONE);
mark_buffer_dirty(fs->fs_super_bh);
/* write all dirty blocks */
fsck_progress ("Flushing..");
id_map_flush(proper_id_map (fs), fs);
fs->fs_dirt = 1;
reiserfs_flush_to_ondisk_bitmap (fsck_new_bitmap(fs), fs);
reiserfs_flush (fs);
fsck_progress ("finished\n");
/* write all dirty blocks */
fsck_progress("Flushing..");
id_map_flush(proper_id_map(fs), fs);
fs->fs_dirt = 1;
reiserfs_flush_to_ondisk_bitmap(fsck_new_bitmap(fs), fs);
reiserfs_flush(fs);
fsck_progress("finished\n");
stage_report (0x3a, fs);
stage_report(0x3a, fs);
if (!fsck_run_one_step (fs)) {
if (fsck_user_confirmed (fs, "Continue? (Yes):", "Yes\n", 1))
/* reiserfsck continues */
return;
}
if (!fsck_run_one_step(fs)) {
if (fsck_user_confirmed(fs, "Continue? (Yes):", "Yes\n", 1))
/* reiserfsck continues */
return;
}
save_lost_found_result (fs);
save_lost_found_result(fs);
id_map_free(proper_id_map (fs));
proper_id_map (fs) = 0;
id_map_free(proper_id_map(fs));
proper_id_map(fs) = 0;
fs->fs_dirt = 1;
reiserfs_close (fs);
exit(EXIT_OK);
fs->fs_dirt = 1;
reiserfs_close(fs);
exit(EXIT_OK);
}
void pass_3a_look_for_lost (reiserfs_filsys_t * fs)
void pass_3a_look_for_lost(reiserfs_filsys_t *fs)
{
INITIALIZE_REISERFS_PATH(path);
struct item_head * ih;
void * sd;
__u64 size, sd_size;
__u32 blocks;
__u16 mode;
__u32 objectid;
unsigned int gen_counter;
fsck_progress ("Pass 3a (looking for lost dir/files):\n");
INITIALIZE_REISERFS_PATH(path);
struct item_head *ih;
void *sd;
__u64 size, sd_size;
__u32 blocks;
__u16 mode;
__u32 objectid;
unsigned int gen_counter;
fsck_progress("Pass 3a (looking for lost dir/files):\n");
/* when warnings go not to stderr - separate them in the log */
if (fsck_log_file (fs) != stderr)
fsck_log ("####### Pass 3a (lost+found pass) #########\n");
/* when warnings go not to stderr - separate them in the log */
if (fsck_log_file(fs) != stderr)
fsck_log("####### Pass 3a (lost+found pass) #########\n");
/* look for lost dirs first */
size = _look_for_lost(fs, 1);
/* look for lost dirs first */
size = _look_for_lost (fs, 1);
/* link files which are still lost */
size += _look_for_lost(fs, 0);
/* link files which are still lost */
size += _look_for_lost (fs, 0);
/* update /lost+found sd_size and sd_blocks (nlink is correct already) */
/* update /lost+found sd_size and sd_blocks (nlink is correct already) */
objectid = reiserfs_find_entry(fs, &root_dir_key, "lost+found",
&gen_counter, &lost_found_dir_key);
objectid = reiserfs_find_entry (fs, &root_dir_key, "lost+found",
&gen_counter, &lost_found_dir_key);
if (!objectid) {
reiserfs_panic
("look_for_lost: The entry 'lost+found' could not be found in the root directory.");
}
if (!objectid) {
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: The StatData of the 'lost+found' directory %K could not be found",
&lost_found_dir_key);
ih = get_ih(&path);
sd = get_item(&path);
get_sd_size(ih, sd, &sd_size);
size += sd_size;
blocks = dir_size2st_blocks(size);
if (reiserfs_search_by_key_4 (fs, &lost_found_dir_key, &path) != ITEM_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);
get_sd_size (ih, sd, &sd_size);
size += sd_size;
blocks = dir_size2st_blocks (size);
set_sd_size(ih, sd, &size);
set_sd_blocks(ih, sd, &blocks);
set_sd_size (ih, sd, &size);
set_sd_blocks (ih, sd, &blocks);
/* make lost+found to be drwx------ */
mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
set_sd_mode(ih, sd, &mode);
/* make lost+found to be drwx------ */
mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR;
set_sd_mode (ih, sd, &mode);
mark_buffer_dirty(get_bh(&path));
pathrelse(&path);
mark_buffer_dirty (get_bh (&path));
pathrelse (&path);
after_lost_found (fs);
after_lost_found(fs);
}
+1188 -1082
View File
File diff suppressed because it is too large. Load diff
+1925 -1587
View File
File diff suppressed because it is too large. Load diff
+649 -634
View File
File diff suppressed because it is too large. Load diff
+491 -490
View File
File diff suppressed because it is too large. Load diff
+66 -65
View File
@@ -5,86 +5,87 @@
#include "fsck.h"
void pass_4_check_unaccessed_items (void)
void pass_4_check_unaccessed_items(void)
{
struct reiserfs_key key;
struct reiserfs_path path;
int i;
struct buffer_head * bh;
struct item_head * ih;
unsigned long items;
struct reiserfs_key *rdkey;
struct reiserfs_key key;
struct reiserfs_path path;
int i;
struct buffer_head *bh;
struct item_head *ih;
unsigned long items;
struct reiserfs_key *rdkey;
path.path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
key = root_dir_key;
fsck_progress ("Pass 4 - ");
items = 0;
path.path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
key = root_dir_key;
while (reiserfs_search_by_key_4 (fs, &key, &path) == ITEM_FOUND) {
bh = PATH_PLAST_BUFFER (&path);
fsck_progress("Pass 4 - ");
items = 0;
/* print ~ how many leaves were scanned and how fast it was */
if (!fsck_quiet (fs))
print_how_fast (items++, 0, 50, 0);
while (reiserfs_search_by_key_4(fs, &key, &path) == ITEM_FOUND) {
bh = PATH_PLAST_BUFFER(&path);
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;
/* print ~ how many leaves were scanned and how fast it was */
if (!fsck_quiet(fs))
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 = reiserfs_next_key(&path);
if (rdkey)
key = *rdkey;
else
memset(&key, 0xff, KEY_SIZE);
pass_4_stat(fs)->deleted_items++;
reiserfsck_delete_item(&path, 0);
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);
if (rdkey)
key = *rdkey;
key = *rdkey;
else
memset (&key, 0xff, KEY_SIZE);
pass_4_stat (fs)->deleted_items ++;
reiserfsck_delete_item (&path, 0);
memset(&key, 0xff, KEY_SIZE);
goto cont;
}
if (get_ih_flags(ih) != 0) {
clean_ih_flags(ih);
mark_buffer_dirty(bh);
}
pathrelse(&path);
cont:
/* to make gcc 3.2 do not sware here */ ;
}
PATH_LAST_POSITION(&path) = i - 1;
rdkey = reiserfs_next_key (&path);
if (rdkey)
key = *rdkey;
else
memset (&key, 0xff, KEY_SIZE);
pathrelse (&path);
cont:
/* to make gcc 3.2 do not sware here */;
}
pathrelse(&path);
pathrelse (&path);
fsck_progress("finished\n");
stage_report(4, fs);
fsck_progress ("finished\n");
stage_report (4, fs);
/* after pass 4 */
/* after pass 4 */
/* put bitmap on place */
reiserfs_bitmap_copy(fs->fs_bitmap2, fsck_new_bitmap(fs));
/* put bitmap on place */
reiserfs_bitmap_copy (fs->fs_bitmap2, fsck_new_bitmap (fs));
/* update super block */
set_sb_free_blocks(fs->fs_ondisk_sb,
reiserfs_bitmap_zeros(fsck_new_bitmap(fs)));
mark_buffer_dirty(fs->fs_super_bh);
/* update super block */
set_sb_free_blocks (fs->fs_ondisk_sb, reiserfs_bitmap_zeros (fsck_new_bitmap (fs)));
mark_buffer_dirty (fs->fs_super_bh);
/* write all dirty blocks */
fsck_progress("Flushing..");
fs->fs_dirt = 1;
id_map_flush(proper_id_map(fs), fs);
reiserfs_flush_to_ondisk_bitmap(fs->fs_bitmap2, fs);
reiserfs_flush(fs);
fsck_progress("finished\n");
/* write all dirty blocks */
fsck_progress ("Flushing..");
fs->fs_dirt = 1;
id_map_flush(proper_id_map (fs), fs);
reiserfs_flush_to_ondisk_bitmap (fs->fs_bitmap2, fs);
reiserfs_flush (fs);
fsck_progress ("finished\n");
return;
return;
}
+757 -649
View File
File diff suppressed because it is too large. Load diff
+1052 -961
View File
File diff suppressed because it is too large. Load diff
+787 -667
View File
File diff suppressed because it is too large. Load diff
+48 -109
View File
@@ -40,151 +40,90 @@
*/
/* is blocks used (marked by 1 in new bitmap) in the tree which is being built
(as leaf, internal, bitmap, or unformatted node) */
int is_block_used (unsigned long block)
int is_block_used(unsigned long block)
{
return reiserfs_bitmap_test_bit (fsck_new_bitmap (fs), block);
return reiserfs_bitmap_test_bit(fsck_new_bitmap(fs), block);
}
void mark_block_used (unsigned long block, int check_hardware)
void mark_block_used(unsigned long block, int check_hardware)
{
if (!block)
return;
if (is_block_used (block)) {
if (check_hardware)
check_memory_msg();
die ("mark_block_used: (%lu) used already", block);
}
if (!block)
return;
if (is_block_used(block)) {
if (check_hardware)
check_memory_msg();
die("mark_block_used: (%lu) used already", block);
}
reiserfs_bitmap_set_bit (fsck_new_bitmap (fs), block);
reiserfs_bitmap_set_bit(fsck_new_bitmap(fs), block);
}
void mark_block_free (unsigned long block)
void mark_block_free(unsigned long block)
{
if (!is_block_used (block))
die ("mark_block_free: (%lu) is free already", block);
if (!is_block_used(block))
die("mark_block_free: (%lu) is free already", block);
reiserfs_bitmap_clear_bit (fsck_new_bitmap (fs), block);
reiserfs_bitmap_clear_bit(fsck_new_bitmap(fs), block);
}
int is_block_uninsertable (unsigned long block)
int is_block_uninsertable(unsigned long block)
{
return !reiserfs_bitmap_test_bit (fsck_uninsertables (fs), block);
return !reiserfs_bitmap_test_bit(fsck_uninsertables(fs), block);
}
/* uninsertable block is marked by bit clearing */
void mark_block_uninsertable (unsigned long block)
void mark_block_uninsertable(unsigned long block)
{
if (is_block_uninsertable (block))
die ("mark_block_uninsertable: (%lu) is uninsertable already", block);
if (is_block_uninsertable(block))
die("mark_block_uninsertable: (%lu) is uninsertable already",
block);
reiserfs_bitmap_clear_bit (fsck_uninsertables (fs), block);
/* we do not need thsi actually */
pass_1_stat (fs)->uninsertable_leaves ++;
reiserfs_bitmap_clear_bit(fsck_uninsertables(fs), block);
/* we do not need thsi actually */
pass_1_stat(fs)->uninsertable_leaves++;
}
/* FIXME: should be able to work around no disk space */
int reiserfsck_reiserfs_new_blocknrs (reiserfs_filsys_t * fs,
unsigned long * free_blocknrs,
unsigned long start, int amount_needed)
int reiserfsck_reiserfs_new_blocknrs(reiserfs_filsys_t *fs,
unsigned long *free_blocknrs,
unsigned long start, int amount_needed)
{
int i;
int i;
if (!are_there_allocable_blocks (amount_needed))
die ("out of disk space");
for (i = 0; i < amount_needed; i ++) {
free_blocknrs[i] = alloc_block ();
if (!free_blocknrs[i])
die ("reiserfs_new_blocknrs: 0 is allocated");
mark_block_used (free_blocknrs[i], 0);
}
return CARRY_ON;
if (!are_there_allocable_blocks(amount_needed))
die("out of disk space");
for (i = 0; i < amount_needed; i++) {
free_blocknrs[i] = alloc_block();
if (!free_blocknrs[i])
die("reiserfs_new_blocknrs: 0 is allocated");
mark_block_used(free_blocknrs[i], 0);
}
return CARRY_ON;
}
// FIXME: do you check readability of a block? If f_read fails - you
// free block in bitmap or if you mark bad blocks used to avoid their
// allocation in future you should have bad block counter in a super
// block. Another minor issue: users of _get_new_buffer expect buffer
// to be filled with 0s
struct buffer_head * reiserfsck_get_new_buffer (unsigned long start)
struct buffer_head *reiserfsck_get_new_buffer(unsigned long start)
{
unsigned long blocknr = 0;
struct buffer_head * bh = NULL;
unsigned long blocknr = 0;
struct buffer_head *bh = NULL;
reiserfs_new_blocknrs (fs, &blocknr, start, 1);
bh = getblk (fs->fs_dev, blocknr, fs->fs_blocksize);
return bh;
reiserfs_new_blocknrs(fs, &blocknr, start, 1);
bh = getblk(fs->fs_dev, blocknr, fs->fs_blocksize);
return bh;
}
/* free block in new bitmap */
int reiserfsck_reiserfs_free_block (reiserfs_filsys_t * fs, unsigned long block)
int reiserfsck_reiserfs_free_block(reiserfs_filsys_t *fs, unsigned long block)
{
mark_block_free (block);
mark_block_free(block);
/* put it back to pool of blocks for allocation */
make_allocable (block);
return 0;
/* put it back to pool of blocks for allocation */
make_allocable(block);
return 0;
}
+1129 -937
View File
File diff suppressed because it is too large. Load diff
+210 -196
View File
@@ -5,7 +5,6 @@
#include "fsck.h"
/* when --check fsck builds a map of objectids of files it finds in the tree
when --rebuild-tree - fsck builds map of objectids it inserts into tree */
@@ -28,111 +27,116 @@ typedef struct sb_id_map {
} sb_id_map_t;
*/
id_map_t *id_map_init() {
id_map_t *map;
__u32 i;
map = getmem(sizeof(id_map_t));
map->index = mem_alloc(INDEX_COUNT * sizeof(void *));
id_map_t *id_map_init()
{
id_map_t *map;
__u32 i;
for (i = 0; i < INDEX_COUNT; i++) {
if (map->index[i] != (void *)0)
map->index[i] = (void *)0;
}
map = getmem(sizeof(id_map_t));
map->index = mem_alloc(INDEX_COUNT * sizeof(void *));
id_map_mark(map, 0);
id_map_mark(map, 1);
for (i = 0; i < INDEX_COUNT; i++) {
if (map->index[i] != (void *)0)
map->index[i] = (void *)0;
}
/* id == 0 should not be there, just for convinient usage */
map->count--;
return map;
id_map_mark(map, 0);
id_map_mark(map, 1);
/* id == 0 should not be there, just for convinient usage */
map->count--;
return map;
}
void id_map_free(id_map_t *map) {
__u32 i;
for (i = 0; i < INDEX_COUNT; i++) {
if (map->index[i] != (void *)0 && map->index[i] != (void *)1)
freemem(map->index[i]);
}
freemem(map->index);
freemem(map);
void id_map_free(id_map_t *map)
{
__u32 i;
for (i = 0; i < INDEX_COUNT; i++) {
if (map->index[i] != (void *)0 && map->index[i] != (void *)1)
freemem(map->index[i]);
}
freemem(map->index);
freemem(map);
}
int id_map_test(id_map_t *map, __u32 id) {
void **interval = id_map_interval(map, id);
int id_map_test(id_map_t *map, __u32 id)
{
void **interval = id_map_interval(map, id);
if (*interval == (void *)0)
return 0;
if (*interval == (void *)1)
return 1;
return misc_test_bit(id % BM_INTERVAL, *interval);
}
int id_map_mark(id_map_t *map, __u32 id)
{
void **interval = id_map_interval(map, id);
if (*interval == (void *)0)
*interval = getmem(ALLOC_SIZE);
if (*interval == (void *)1)
return 1;
if (misc_test_bit(id % BM_INTERVAL, *interval))
return 1;
misc_set_bit(id % BM_INTERVAL, *interval);
(*(__u16 *) id_map_local_count(*interval))++;
map->count++;
if ((*(__u16 *) id_map_local_count(*interval)) == BM_INTERVAL) {
/* Dealloc fully used bitmap */
freemem(*interval);
*interval = (void *)1;
}
if (map->last_used < (id / BM_INTERVAL))
map->last_used = id / BM_INTERVAL;
if (*interval == (void *)0)
return 0;
if (*interval == (void *)1)
return 1;
return misc_test_bit(id % BM_INTERVAL, *interval);
}
int id_map_mark(id_map_t *map, __u32 id) {
void **interval = id_map_interval(map, id);
if (*interval == (void *)0)
*interval = getmem(ALLOC_SIZE);
if (*interval == (void *)1)
return 1;
if (misc_test_bit(id % BM_INTERVAL, *interval))
return 1;
misc_set_bit(id % BM_INTERVAL, *interval);
(*(__u16 *)id_map_local_count(*interval))++;
map->count++;
if ((*(__u16 *)id_map_local_count(*interval)) == BM_INTERVAL) {
/* Dealloc fully used bitmap */
freemem(*interval);
*interval = (void *)1;
}
if (map->last_used < (id / BM_INTERVAL))
map->last_used = id / BM_INTERVAL;
return 0;
}
/* call this for proper_id_map only!! */
__u32 id_map_alloc(id_map_t *map) {
__u32 i, zero_count;
__u32 id = 0, first = ~(__u32)0;
__u32 id_map_alloc(id_map_t *map)
{
__u32 i, zero_count;
__u32 id = 0, first = ~(__u32) 0;
for (i = 0, zero_count = 0; zero_count < 10 && i < INDEX_COUNT - 1; i++) {
if (map->index[i] == (void *)0) {
if (zero_count == 0)
first = i;
zero_count++;
} else if (map->index[i] != (void *)1)
break;
}
for (i = 0, zero_count = 0; zero_count < 10 && i < INDEX_COUNT - 1; i++) {
if (map->index[i] == (void *)0) {
if (zero_count == 0)
first = i;
if (map->index[i] != (void *)1 && map->index[i] != (void *)0) {
id = misc_find_first_zero_bit(map->index[i], BM_INTERVAL);
if (id >= BM_INTERVAL)
die ("Id is out of interval size, interval looks corrupted.");
id += i * BM_INTERVAL;
} else if (first != ~(__u32)0) {
id = first * BM_INTERVAL;
if (id == 0)
id = 2;
} else
die ("%s: No more free objectid is available.", __FUNCTION__);
zero_count++;
} else if (map->index[i] != (void *)1)
break;
}
id_map_mark(map, id);
if (map->index[i] != (void *)1 && map->index[i] != (void *)0) {
id = misc_find_first_zero_bit(map->index[i], BM_INTERVAL);
if (id >= BM_INTERVAL)
die("Id is out of interval size, interval looks corrupted.");
return id;
id += i * BM_INTERVAL;
} else if (first != ~(__u32) 0) {
id = first * BM_INTERVAL;
if (id == 0)
id = 2;
} else
die("%s: No more free objectid is available.", __FUNCTION__);
id_map_mark(map, id);
return id;
}
/* this could be used if some more sofisticated flushing will be needed. */
@@ -143,133 +147,143 @@ static void sb_id_map_pack(sb_id_map_t *map) {
map->m_used_slot_count = 2;
}*/
static __u32 id_map_next_bound(id_map_t *map, __u32 start) {
__u32 index = start / BM_INTERVAL;
__u32 offset = start % BM_INTERVAL;
int look_for;
if (map->index[index] == (void *)0)
look_for = 1;
else if (map->index[index] == (void *)1)
look_for = 0;
else
look_for = !misc_test_bit(offset, map->index[index]);
static __u32 id_map_next_bound(id_map_t *map, __u32 start)
{
__u32 index = start / BM_INTERVAL;
__u32 offset = start % BM_INTERVAL;
int look_for;
offset++;
if (map->index[index] == (void *)0)
look_for = 1;
else if (map->index[index] == (void *)1)
look_for = 0;
else
look_for = !misc_test_bit(offset, map->index[index]);
offset++;
start_again:
if (look_for) {
while (index < INDEX_COUNT && map->index[index] == (void *)0)
index++;
if (index == INDEX_COUNT)
return 0;
if (map->index[index] == (void *)1)
return index * BM_INTERVAL;
offset = misc_find_next_set_bit(map->index[index], BM_INTERVAL, offset);
if (offset >= BM_INTERVAL) {
offset = 0;
index++;
goto start_again;
}
return index * BM_INTERVAL + offset;
} else {
while (index < INDEX_COUNT && map->index[index] == (void *)1)
index++;
if (index == INDEX_COUNT)
return 0;
if (map->index[index] == (void *)0)
return index * BM_INTERVAL;
if (look_for) {
while (index < INDEX_COUNT && map->index[index] == (void *)0)
index++;
offset = misc_find_next_zero_bit(map->index[index], BM_INTERVAL, offset);
if (offset >= BM_INTERVAL) {
offset = 0;
index++;
goto start_again;
if (index == INDEX_COUNT)
return 0;
if (map->index[index] == (void *)1)
return index * BM_INTERVAL;
offset =
misc_find_next_set_bit(map->index[index], BM_INTERVAL,
offset);
if (offset >= BM_INTERVAL) {
offset = 0;
index++;
goto start_again;
}
return index * BM_INTERVAL + offset;
} else {
while (index < INDEX_COUNT && map->index[index] == (void *)1)
index++;
if (index == INDEX_COUNT)
return 0;
if (map->index[index] == (void *)0)
return index * BM_INTERVAL;
offset =
misc_find_next_zero_bit(map->index[index], BM_INTERVAL,
offset);
if (offset >= BM_INTERVAL) {
offset = 0;
index++;
goto start_again;
}
return index * BM_INTERVAL + offset;
}
return index * BM_INTERVAL + offset;
}
}
void id_map_flush(struct id_map * map, reiserfs_filsys_t * fs) {
int size, max, i;
__u32 id, prev_id;
__u32 * sb_objectid_map;
void id_map_flush(struct id_map *map, reiserfs_filsys_t *fs)
{
int size, max, i;
__u32 id, prev_id;
__u32 *sb_objectid_map;
size = reiserfs_super_block_size (fs->fs_ondisk_sb);
sb_objectid_map = (__u32 *)((char *)(fs->fs_ondisk_sb) + size);
size = reiserfs_super_block_size(fs->fs_ondisk_sb);
sb_objectid_map = (__u32 *) ((char *)(fs->fs_ondisk_sb) + size);
max = ((fs->fs_blocksize - size) >> 3 << 1);
set_sb_oid_maxsize (fs->fs_ondisk_sb, max);
id = 1;
sb_objectid_map[0] = cpu_to_le32(1);
max = ((fs->fs_blocksize - size) >> 3 << 1);
set_sb_oid_maxsize(fs->fs_ondisk_sb, max);
for (i = 1; i < max - 1; i++) {
id = id_map_next_bound(map, id);
sb_objectid_map[i] = cpu_to_le32(id);
if (id == 0) {
if (i % 2)
die ("%s: Used interval is not closed on flushing.", __FUNCTION__);
break;
id = 1;
sb_objectid_map[0] = cpu_to_le32(1);
for (i = 1; i < max - 1; i++) {
id = id_map_next_bound(map, id);
sb_objectid_map[i] = cpu_to_le32(id);
if (id == 0) {
if (i % 2)
die("%s: Used interval is not closed on flushing.", __FUNCTION__);
break;
}
}
}
if (map->index[map->last_used] == (void *)0)
die ("Object id map looks corrupted - last used interval cannot be zeroed.");
i++;
if (i == max) {
if (id == 0)
die ("Objectid interval does not contain any set bit what is expected.");
if (map->index[map->last_used] == (void *)1) {
prev_id = BM_INTERVAL - 1;
} else {
prev_id = ~(__u32)0;
if (id < map->last_used * BM_INTERVAL)
id = 0;
else
id %= BM_INTERVAL;
if (misc_test_bit(id, map->index[map->last_used]))
prev_id = id;
while ((id = misc_find_next_set_bit(map->index[map->last_used],
BM_INTERVAL, (id + 1))) != BM_INTERVAL)
{
prev_id = id;
}
if (map->index[map->last_used] == (void *)0)
die("Object id map looks corrupted - last used interval cannot be zeroed.");
if (prev_id == ~(__u32)0)
die ("Objectid interval does not contain any set bit what is expected.");
i++;
prev_id++;
if (i == max) {
if (id == 0)
die("Objectid interval does not contain any set bit what is expected.");
if (map->index[map->last_used] == (void *)1) {
prev_id = BM_INTERVAL - 1;
} else {
prev_id = ~(__u32) 0;
if (id < map->last_used * BM_INTERVAL)
id = 0;
else
id %= BM_INTERVAL;
if (misc_test_bit(id, map->index[map->last_used]))
prev_id = id;
while ((id =
misc_find_next_set_bit(map->
index[map->last_used],
BM_INTERVAL,
(id + 1))) !=
BM_INTERVAL) {
prev_id = id;
}
if (prev_id == ~(__u32) 0)
die("Objectid interval does not contain any set bit what is expected.");
prev_id++;
}
sb_objectid_map[max - 1] =
cpu_to_le32(prev_id + map->last_used * BM_INTERVAL);
} else {
i--;
memset(sb_objectid_map + i, 0, (max - i) * sizeof(__u32));
}
sb_objectid_map[max - 1] = cpu_to_le32(prev_id + map->last_used * BM_INTERVAL);
} else {
i--;
memset(sb_objectid_map + i, 0, (max - i) * sizeof (__u32));
}
set_sb_oid_cursize (fs->fs_ondisk_sb, i);
set_sb_oid_cursize(fs->fs_ondisk_sb, i);
}
/* FIXME: these 3 methods must be implemented also.
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t * fs)
void fetch_objectid_map (struct id_map * map, reiserfs_filsys_t *fs)
{
int sb_size;
__u32 * sb_objectid_map;
+191 -182
View File
@@ -6,106 +6,114 @@
#include "fsck.h"
#include "progbar.h"
struct tree_balance * cur_tb = 0;
struct tree_balance *cur_tb = 0;
void reiserfsck_paste_into_item (struct reiserfs_path *path, const char * body, int size)
void reiserfsck_paste_into_item(struct reiserfs_path *path, const char *body,
int size)
{
struct tree_balance tb;
init_tb_struct (&tb, fs, path, size);
if (fix_nodes (/*tb.transaction_handle,*/ M_PASTE, &tb, 0/*ih*/) != CARRY_ON)
//fix_nodes(options, tree_balance, ih_to_option, body_to_option)
die ("reiserfsck_paste_into_item: fix_nodes failed");
do_balance (/*tb.transaction_handle,*/ &tb, 0, body, M_PASTE, 0/*zero num*/);
struct tree_balance tb;
init_tb_struct(&tb, fs, path, size);
if (fix_nodes( /*tb.transaction_handle, */ M_PASTE, &tb, 0 /*ih */ ) !=
CARRY_ON)
//fix_nodes(options, tree_balance, ih_to_option, body_to_option)
die("reiserfsck_paste_into_item: fix_nodes failed");
do_balance( /*tb.transaction_handle, */ &tb, 0, body, M_PASTE,
0 /*zero num */ );
}
void reiserfsck_insert_item (struct reiserfs_path *path, struct item_head * ih, const char * body)
void reiserfsck_insert_item(struct reiserfs_path *path, struct item_head *ih,
const char *body)
{
struct tree_balance tb;
init_tb_struct (&tb, fs, path, IH_SIZE + get_ih_item_len(ih));
if (fix_nodes (/*tb.transaction_handle,*/ M_INSERT, &tb, ih/*, body*/) != CARRY_ON)
die ("reiserfsck_insert_item: fix_nodes failed");
do_balance (/*tb.transaction_handle,*/ &tb, ih, body, M_INSERT, 0/*zero num*/);
struct tree_balance tb;
init_tb_struct(&tb, fs, path, IH_SIZE + get_ih_item_len(ih));
if (fix_nodes
( /*tb.transaction_handle, */ M_INSERT, &tb,
ih /*, body */ ) != CARRY_ON)
die("reiserfsck_insert_item: fix_nodes failed");
do_balance( /*tb.transaction_handle, */ &tb, ih, body, M_INSERT,
0 /*zero num */ );
}
static void free_unformatted_nodes (struct item_head * ih, struct buffer_head * bh)
static void free_unformatted_nodes(struct item_head *ih, struct buffer_head *bh)
{
__u32 * punfm = (__u32 *)B_I_PITEM (bh, ih);
unsigned int i;
__u32 *punfm = (__u32 *) B_I_PITEM(bh, ih);
unsigned int i;
for (i = 0; i < I_UNFM_NUM (ih); i ++) {
__u32 unfm = d32_get (punfm, i);
if (unfm != 0) {
struct buffer_head * to_be_forgotten;
for (i = 0; i < I_UNFM_NUM(ih); i++) {
__u32 unfm = d32_get(punfm, i);
if (unfm != 0) {
struct buffer_head *to_be_forgotten;
to_be_forgotten = find_buffer (fs->fs_dev, unfm, fs->fs_blocksize);
if (to_be_forgotten) {
//atomic_inc(&to_be_forgotten->b_count);
to_be_forgotten->b_count ++;
bforget (to_be_forgotten);
}
to_be_forgotten =
find_buffer(fs->fs_dev, unfm, fs->fs_blocksize);
if (to_be_forgotten) {
//atomic_inc(&to_be_forgotten->b_count);
to_be_forgotten->b_count++;
bforget(to_be_forgotten);
}
reiserfs_free_block (fs, unfm);
reiserfs_free_block(fs, unfm);
}
}
}
}
void reiserfsck_delete_item (struct reiserfs_path *path, int temporary)
void reiserfsck_delete_item(struct reiserfs_path *path, int temporary)
{
struct tree_balance tb;
struct item_head * ih = PATH_PITEM_HEAD (path);
if (is_indirect_ih (ih) && !temporary)
free_unformatted_nodes (ih, PATH_PLAST_BUFFER (path));
struct tree_balance tb;
struct item_head *ih = PATH_PITEM_HEAD(path);
init_tb_struct (&tb, fs, path, -(IH_SIZE + get_ih_item_len(ih)));
if (is_indirect_ih(ih) && !temporary)
free_unformatted_nodes(ih, PATH_PLAST_BUFFER(path));
if (fix_nodes (/*tb.transaction_handle,*/ M_DELETE, &tb, 0/*ih*/) != CARRY_ON)
die ("reiserfsck_delete_item: fix_nodes failed");
do_balance (/*tb.transaction_handle,*/ &tb, 0, 0, M_DELETE, 0/*zero num*/);
init_tb_struct(&tb, fs, path, -(IH_SIZE + get_ih_item_len(ih)));
if (fix_nodes( /*tb.transaction_handle, */ M_DELETE, &tb, 0 /*ih */ ) !=
CARRY_ON)
die("reiserfsck_delete_item: fix_nodes failed");
do_balance( /*tb.transaction_handle, */ &tb, 0, 0, M_DELETE,
0 /*zero num */ );
}
void reiserfsck_cut_from_item (struct reiserfs_path *path, int cut_size)
void reiserfsck_cut_from_item(struct reiserfs_path *path, int cut_size)
{
struct tree_balance tb;
struct item_head * ih;
struct tree_balance tb;
struct item_head *ih;
if (cut_size >= 0)
die ("reiserfsck_cut_from_item: cut size == %d", cut_size);
if (cut_size >= 0)
die("reiserfsck_cut_from_item: cut size == %d", cut_size);
if (is_indirect_ih (ih = PATH_PITEM_HEAD (path))) {
struct buffer_head *bh = PATH_PLAST_BUFFER (path);
__u32 unfm_ptr = d32_get ((__u32 *)B_I_PITEM(bh, ih), I_UNFM_NUM (ih) - 1);
if (unfm_ptr != 0) {
struct buffer_head * to_be_forgotten;
if (is_indirect_ih(ih = PATH_PITEM_HEAD(path))) {
struct buffer_head *bh = PATH_PLAST_BUFFER(path);
__u32 unfm_ptr =
d32_get((__u32 *) B_I_PITEM(bh, ih), I_UNFM_NUM(ih) - 1);
if (unfm_ptr != 0) {
struct buffer_head *to_be_forgotten;
to_be_forgotten = find_buffer (fs->fs_dev, unfm_ptr, fs->fs_blocksize);
if (to_be_forgotten) {
//atomic_inc(&to_be_forgotten->b_count);
to_be_forgotten->b_count ++;
bforget (to_be_forgotten);
}
reiserfs_free_block (fs, unfm_ptr);
to_be_forgotten =
find_buffer(fs->fs_dev, unfm_ptr, fs->fs_blocksize);
if (to_be_forgotten) {
//atomic_inc(&to_be_forgotten->b_count);
to_be_forgotten->b_count++;
bforget(to_be_forgotten);
}
reiserfs_free_block(fs, unfm_ptr);
}
}
}
init_tb_struct(&tb, fs, path, cut_size);
init_tb_struct (&tb, fs, path, cut_size);
if (fix_nodes( /*tb.transaction_handle, */ M_CUT, &tb, 0) != CARRY_ON)
die("reiserfsck_cut_from_item: fix_nodes failed");
if (fix_nodes (/*tb.transaction_handle,*/ M_CUT, &tb, 0) != CARRY_ON)
die ("reiserfsck_cut_from_item: fix_nodes failed");
do_balance (/*tb.transaction_handle,*/ &tb, 0, 0, M_CUT, 0/*zero num*/);
do_balance( /*tb.transaction_handle, */ &tb, 0, 0, M_CUT,
0 /*zero num */ );
}
/* uget_rkey is utils clone of stree.c/get_rkey */
/*
struct reiserfs_key *uget_rkey (struct reiserfs_path *path)
@@ -143,147 +151,148 @@ struct reiserfs_key *uget_rkey (struct reiserfs_path *path)
}
*/
static unsigned long first_child (struct buffer_head * bh)
static unsigned long first_child(struct buffer_head *bh)
{
return get_dc_child_blocknr (B_N_CHILD (bh, 0));
return get_dc_child_blocknr(B_N_CHILD(bh, 0));
}
#if 0
static unsigned long last_child (struct buffer_head * bh)
static unsigned long last_child(struct buffer_head *bh)
{
return child_block_number (bh, node_item_number (bh));
return child_block_number(bh, node_item_number(bh));
}
#endif
static unsigned long get_child (int pos, struct buffer_head * parent)
static unsigned long get_child(int pos, struct buffer_head *parent)
{
if (pos == -1)
return -1;
if (pos == -1)
return -1;
if (pos > B_NR_ITEMS (parent))
die ("get_child: no child found, should not happen: %d of %d", pos, B_NR_ITEMS (parent));
return get_dc_child_blocknr (B_N_CHILD (parent, pos));
if (pos > B_NR_ITEMS(parent))
die("get_child: no child found, should not happen: %d of %d",
pos, B_NR_ITEMS(parent));
return get_dc_child_blocknr(B_N_CHILD(parent, pos));
}
static void print (int cur, int total)
static void print(int cur, int total)
{
if (fsck_quiet (fs))
return;
printf ("/%3d (of %3d)", cur, total);fflush (stdout);
if (fsck_quiet(fs))
return;
printf("/%3d (of %3d)", cur, total);
fflush(stdout);
}
/* erase /XXX(of XXX) */
static void erase (void)
static void erase(void)
{
if (fsck_quiet (fs))
return;
printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b");
printf (" ");
printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b");
fflush (stdout);
if (fsck_quiet(fs))
return;
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
printf(" ");
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b");
fflush(stdout);
}
void pass_through_tree (reiserfs_filsys_t * fs, do_after_read_t action1,
do_on_full_path_t action2, int depth)
void pass_through_tree(reiserfs_filsys_t *fs, do_after_read_t action1,
do_on_full_path_t action2, int depth)
{
struct buffer_head * path[MAX_HEIGHT] = {0,};
int total[MAX_HEIGHT] = {0,};
int cur[MAX_HEIGHT] = {0,};
int h = 0;
unsigned long block = get_sb_root_block (fs->fs_ondisk_sb);
int problem;
struct spinner spinner;
struct buffer_head *path[MAX_HEIGHT] = { 0, };
int total[MAX_HEIGHT] = { 0, };
int cur[MAX_HEIGHT] = { 0, };
int h = 0;
unsigned long block = get_sb_root_block(fs->fs_ondisk_sb);
int problem;
struct spinner spinner;
spinner_init(&spinner, fsck_progress_file(fs));
spinner_init(&spinner, fsck_progress_file(fs));
if (block >= get_sb_block_count(fs->fs_ondisk_sb)
|| not_data_block(fs, block)) {
die("\nBad root block %lu. (--rebuild-tree did not complete)\n",
block);
}
if (block >= get_sb_block_count (fs->fs_ondisk_sb) || not_data_block (fs, block)) {
die ("\nBad root block %lu. (--rebuild-tree did not complete)\n", block);
}
while (1) {
problem = 0;
while ( 1 ) {
problem = 0;
if (path[h])
die("pass_through_tree: empty slot expected");
if (h)
print(cur[h - 1], total[h - 1]);
if (path[h])
die ("pass_through_tree: empty slot expected");
if (h)
print (cur[h - 1], total[h - 1]);
if (fs->fs_badblocks_bm
&& reiserfs_bitmap_test_bit(fs->fs_badblocks_bm, block)) {
fsck_log
("%s: block %lu specified in badblock list found in tree, whole subtree skipped\n",
__FUNCTION__, block);
fsck_data(fs)->check.bad_nodes++;
one_more_corruption(fs, FATAL);
if (fs->fs_badblocks_bm && reiserfs_bitmap_test_bit (fs->fs_badblocks_bm, block)) {
fsck_log ("%s: block %lu specified in badblock list found in tree, whole subtree skipped\n",
__FUNCTION__, block);
fsck_data (fs)->check.bad_nodes++;
one_more_corruption (fs, FATAL);
if (h == 0) {
brelse(path[h]);
path[h] = 0;
break;
}
problem = 1;
} else {
if (h == 0) {
brelse (path[h]);
path[h] = 0;
break;
}
problem = 1;
} else {
spinner_touch(&spinner);
path[h] = bread(fs->fs_dev, block, fs->fs_blocksize);
if (path[h] == 0)
/* FIXME: handle case when read failed */
die("pass_through_tree: unable to read %lu block on device 0x%x\n", block, fs->fs_dev);
spinner_touch(&spinner);
path[h] = bread (fs->fs_dev, block, fs->fs_blocksize);
if (path[h] == 0)
/* FIXME: handle case when read failed */
die ("pass_through_tree: unable to read %lu block on device 0x%x\n",
block, fs->fs_dev);
if (action1)
if ((problem = action1(fs, path, h))) {
fsck_log
(" the problem in the internal node occured (%lu), whole subtree is skipped\n",
path[h]->b_blocknr);
fsck_data(fs)->check.bad_nodes++;
if (action1)
if ((problem = action1 (fs, path, h))) {
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) {
brelse (path[h]);
path[h] = 0;
break;
}
if (h == 0) {
brelse(path[h]);
path[h] = 0;
break;
}
}
}
/* Time to stop. */
if (h == depth)
problem++;
if (problem || is_leaf_node(path[h])) {
if (!problem && action2)
action2(fs, path, h);
brelse(path[h]);
if (h)
erase();
while (h && (cur[h - 1] == total[h - 1] || problem)) {
problem = 0;
path[h] = 0;
h--;
brelse(path[h]);
if (h)
erase();
}
if (h == 0) {
path[h] = 0;
break;
}
block = get_child(cur[h - 1], path[h - 1]);
cur[h - 1]++;
path[h] = 0;
continue;
}
total[h] = B_NR_ITEMS(path[h]) + 1;
cur[h] = 1;
block = first_child(path[h]);
h++;
}
/* Time to stop. */
if (h == depth)
problem ++;
if (problem || is_leaf_node (path[h])) {
if (!problem && action2)
action2 (fs, path, h);
brelse (path[h]);
if (h)
erase ();
while (h && (cur[h-1] == total[h-1] || problem)) {
problem = 0;
path[h] = 0;
h --;
brelse (path[h]);
if (h)
erase ();
}
if (h == 0) {
path[h] = 0;
break;
}
block = get_child (cur[h - 1], path[h-1]);
cur[h - 1] ++;
path[h] = 0;
continue;
}
total[h] = B_NR_ITEMS (path[h]) + 1;
cur[h] = 1;
block = first_child (path[h]);
h ++;
}
spinner_clear(&spinner);
spinner_clear(&spinner);
}
+35 -35
View File
@@ -18,20 +18,20 @@
#include "misc.h"
struct buffer_head {
unsigned long b_blocknr;
int b_dev;
unsigned long b_size;
char * b_data;
unsigned long b_state;
unsigned int b_count;
unsigned int b_list ;
void (*b_start_io) (unsigned long);
void (*b_end_io)(struct buffer_head *bh, int uptodate);
struct buffer_head * b_next;
struct buffer_head * b_prev;
struct buffer_head * b_hash_next;
struct buffer_head * b_hash_prev;
unsigned long b_blocknr;
int b_dev;
unsigned long b_size;
char *b_data;
unsigned long b_state;
unsigned int b_count;
unsigned int b_list;
void (*b_start_io) (unsigned long);
void (*b_end_io) (struct buffer_head * bh, int uptodate);
struct buffer_head *b_next;
struct buffer_head *b_prev;
struct buffer_head *b_hash_next;
struct buffer_head *b_hash_prev;
};
#define BH_Uptodate 0
@@ -39,7 +39,6 @@ struct buffer_head {
#define BH_Lock 2
#define BH_Do_not_flush 3
#define buffer_uptodate(bh) misc_test_bit(BH_Uptodate, &(bh)->b_state)
#define buffer_dirty(bh) misc_test_bit(BH_Dirty, &(bh)->b_state)
#define buffer_locked(bh) misc_test_bit(BH_Lock, &(bh)->b_state)
@@ -59,27 +58,28 @@ __FILE__, __FUNCTION__, __LINE__,
__builtin_return_address (2));
*/
void __wait_on_buffer(struct buffer_head *bh);
struct buffer_head *getblk(int dev, unsigned long block, int size);
struct buffer_head *reiserfs_getblk(int dev, unsigned long block, int size,
int *repeat);
struct buffer_head *find_buffer(int dev, unsigned long block,
unsigned long size);
struct buffer_head *get_hash_table(dev_t dev, unsigned long block, int size);
struct buffer_head *bread(int dev, unsigned long block, size_t size);
struct buffer_head *reiserfs_bread(int dev, unsigned long block, int size,
int *repeat);
int bwrite(struct buffer_head *bh);
void brelse(struct buffer_head *bh);
void bforget(struct buffer_head *bh);
void init_rollback_file(char *rollback_file, unsigned int *blocksize,
FILE * log);
int open_rollback_file(char *rollback_file, FILE * log);
void close_rollback_file();
void do_fsck_rollback(int fd_device, int fd_journal_device, FILE * log);
void __wait_on_buffer (struct buffer_head * bh);
struct buffer_head * getblk (int dev, unsigned long block, int size);
struct buffer_head * reiserfs_getblk (int dev, unsigned long block, int size, int *repeat);
struct buffer_head * find_buffer (int dev, unsigned long block, unsigned long size);
struct buffer_head * get_hash_table(dev_t dev, unsigned long block, int size);
struct buffer_head * bread (int dev, unsigned long block, size_t size);
struct buffer_head * reiserfs_bread (int dev, unsigned long block, int size, int *repeat);
int bwrite (struct buffer_head * bh);
void brelse (struct buffer_head * bh);
void bforget (struct buffer_head * bh);
void init_rollback_file (char * rollback_file, unsigned int *blocksize,
FILE * log);
int open_rollback_file (char * rollback_file, FILE * log);
void close_rollback_file ();
void do_fsck_rollback (int fd_device, int fd_journal_device, FILE * log);
void flush_buffers (int);
void free_buffers (void);
void invalidate_buffers (int);
void flush_buffers(int);
void free_buffers(void);
void invalidate_buffers(int);
#endif
+60 -54
View File
@@ -35,60 +35,72 @@
#define INVAL_PTR (void *)-1
void check_memory_msg(void);
void die (char * fmt, ...) __attribute__ ((format (printf, 1, 2)));
void * getmem (int size);
void die(char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
void *getmem(int size);
void *mem_alloc(int size);
void freemem (void * p);
void checkmem (char * p, int size);
void * expandmem (void * p, int size, int by);
unsigned int get_mem_size (char * p);
void check_and_free_mem (void);
char * kdevname (int dev);
void freemem(void *p);
void checkmem(char *p, int size);
void *expandmem(void *p, int size, int by);
unsigned int get_mem_size(char *p);
void check_and_free_mem(void);
char *kdevname(int dev);
typedef enum mount_flags {
MF_NOT_MOUNTED = 0x0,
MF_RO = 0x1,
MF_RW = 0x2
MF_NOT_MOUNTED = 0x0,
MF_RO = 0x1,
MF_RW = 0x2
} mount_flags_t;
typedef struct mount_hint {
char *point; /* Mount point. */
__u32 psize; /* Mount point buffer size. */
__u32 flags; /* Mount flags. */
char *point; /* Mount point. */
__u32 psize; /* Mount point buffer size. */
__u32 flags; /* Mount flags. */
} mount_hint_t;
struct mntent *misc_mntent(char *device);
int misc_device_mounted(char *device);
typedef struct dma_info {
int fd;
struct stat st;
int support_type;
int dma;
__u64 speed;
int fd;
struct stat st;
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);
int valid_offset( int fd, loff_t offset);
unsigned long count_blocks (char * filename, int blocksize);
int valid_offset(int fd, loff_t offset);
unsigned long count_blocks(char *filename, int blocksize);
void print_how_far (FILE * fp, unsigned long *passed, unsigned long total, unsigned int inc, int quiet);
void print_how_fast (unsigned long total,
unsigned long passed, int cursor_pos, int reset_time);
__u32 get_random (void);
void print_how_far(FILE * fp, unsigned long *passed, unsigned long total,
unsigned int inc, int quiet);
void print_how_fast(unsigned long total, unsigned long passed, int cursor_pos,
int reset_time);
__u32 get_random(void);
int user_confirmed (FILE * fp, char * q, char * yes);
int user_confirmed(FILE * fp, char *q, char *yes);
extern inline int misc_set_bit (unsigned long long nr, void * addr);
extern inline int misc_clear_bit (unsigned long long nr, void * addr);
extern inline int misc_test_bit(unsigned long long nr, const void * addr);
extern inline unsigned long long misc_find_first_zero_bit (const void *vaddr, unsigned long long size);
extern inline unsigned long long misc_find_next_zero_bit (const void *vaddr, unsigned long long size, unsigned long long offset);
extern inline unsigned long long misc_find_next_set_bit(const void *vaddr, unsigned long long size, unsigned long long offset);
extern inline unsigned long long misc_find_first_set_bit (const void *vaddr, unsigned long long size);
extern inline int misc_set_bit(unsigned long long nr, void *addr);
extern inline int misc_clear_bit(unsigned long long nr, void *addr);
extern inline int misc_test_bit(unsigned long long nr, const void *addr);
extern inline unsigned long long misc_find_first_zero_bit(const void *vaddr,
unsigned long long
size);
extern inline unsigned long long misc_find_next_zero_bit(const void *vaddr,
unsigned long long
size,
unsigned long long
offset);
extern inline unsigned long long misc_find_next_set_bit(const void *vaddr,
unsigned long long size,
unsigned long long
offset);
extern inline unsigned long long misc_find_first_set_bit(const void *vaddr,
unsigned long long
size);
#define STAT_FIELD_H(Field, Type) \
inline Type misc_device_##Field(char *device);
@@ -98,25 +110,24 @@ STAT_FIELD_H(rdev, dev_t);
STAT_FIELD_H(size, off_t);
STAT_FIELD_H(blocks, blkcnt_t);
__u16 mask16 (int from, int count);
__u32 mask32 (int from, int count);
__u64 mask64 (int from, int count);
__u16 mask16(int from, int count);
__u32 mask32(int from, int count);
__u64 mask64(int from, int count);
int reiserfs_bin_search (void * key, void * base, __u32 num, int width,
__u32 *ppos, __compar_fn_t comp_func);
int reiserfs_bin_search(void *key, void *base, __u32 num, int width,
__u32 * ppos, __compar_fn_t comp_func);
struct block_handler {
__u32 blocknr;
dev_t device;
__u32 blocknr;
dev_t device;
};
int blocklist__is_block_saved (struct block_handler ** base, __u32 * count, __u32 blocknr,
dev_t device, __u32 * position);
void blocklist__insert_in_position (void * block_h, void ** base, __u32 * count,
int elem_size, __u32 * position);
int blockdev_list_compare (const void * block1, const void * block2);
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);
#define set_bit_field_XX(XX,vp,val,from,count) \
{\
__u##XX * p, tmp;\
@@ -137,7 +148,6 @@ int blockdev_list_compare (const void * block1, const void * block2);
*p = cpu_to_le##XX (tmp);\
}
#define get_bit_field_XX(XX,vp,from,count) \
\
__u##XX * p, tmp;\
@@ -152,19 +162,16 @@ int blockdev_list_compare (const void * block1, const void * block2);
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 */
@@ -183,5 +190,4 @@ int blockdev_list_compare (const void * block1, const void * block2);
#endif /* IDE9_MAJOR */
#endif /* IDE_DISK_MAJOR */
#endif /* REISERFS_MISC_H */
+5 -5
View File
@@ -20,12 +20,12 @@ struct spinner {
FILE *file;
};
void progbar_init(struct progbar *ctx, const char *units, FILE *fp);
void progbar_clear(struct progbar * ctx);
int progbar_update(struct progbar * ctx, const char *label, int curr, int max,
unsigned int dpynum);
void progbar_init(struct progbar *ctx, const char *units, FILE * fp);
void progbar_clear(struct progbar *ctx);
int progbar_update(struct progbar *ctx, const char *label, int curr, int max,
unsigned int dpynum);
void spinner_init(struct spinner *spinner, FILE *fp);
void spinner_init(struct spinner *spinner, FILE * fp);
void spinner_touch(struct spinner *spinner);
void spinner_clear(struct spinner *spinner);
+313 -387
View File
File diff suppressed because it is too large. Load diff
+240 -239
View File
@@ -14,145 +14,150 @@ typedef struct reiserfs_filsys reiserfs_filsys_t;
#include "reiserfs_fs.h"
struct _bitmap {
unsigned long bm_byte_size;
unsigned long bm_bit_size;
char * bm_map;
unsigned long bm_set_bits;
int bm_dirty; /* used for fetched bitmap */
unsigned long bm_byte_size;
unsigned long bm_bit_size;
char *bm_map;
unsigned long bm_set_bits;
int bm_dirty; /* used for fetched bitmap */
};
typedef struct _bitmap reiserfs_bitmap_t;
typedef __u32 (*hashf_t) (const char *, int);
typedef __u32(*hashf_t) (const char *, int);
struct reiserfs_filsys {
unsigned int fs_blocksize;
int fs_format; /* on-disk format version */
hashf_t fs_hash_function; /* pointer to function which is used to sort
names in directory. It is set by
reiserfs_open if it is set in the super
block, otherwise it is set by first
is_properly_hashed */
char * fs_file_name; /* file name of underlying device */
int fs_dev; /* descriptor of opened block device file */
struct buffer_head * fs_super_bh; /* buffer containing super block */
struct reiserfs_super_block * fs_ondisk_sb; /* pointer to its b_data */
unsigned int fs_blocksize;
int fs_format; /* on-disk format version */
hashf_t fs_hash_function; /* pointer to function which is used to sort
names in directory. It is set by
reiserfs_open if it is set in the super
block, otherwise it is set by first
is_properly_hashed */
char *fs_file_name; /* file name of underlying device */
int fs_dev; /* descriptor of opened block device file */
struct buffer_head *fs_super_bh; /* buffer containing super block */
struct reiserfs_super_block *fs_ondisk_sb; /* pointer to its b_data */
reiserfs_bitmap_t * fs_bitmap2; /* ondisk bitmap after
reiserfs_open_ondisk_bitmap */
reiserfs_bitmap_t *fs_bitmap2; /* ondisk bitmap after
reiserfs_open_ondisk_bitmap */
/* opened journal fields */
char *fs_j_file_name; /* file name of relocated journal device */
int fs_journal_dev; /* descriptor of opened journal device */
struct buffer_head *fs_jh_bh; /* buffer containing journal header */
/* opened journal fields */
char * fs_j_file_name; /* file name of relocated journal device */
int fs_journal_dev; /* descriptor of opened journal device */
struct buffer_head * fs_jh_bh; /* buffer containing journal header */
/* badblocks */
reiserfs_bitmap_t *fs_badblocks_bm;
/* badblocks */
reiserfs_bitmap_t * fs_badblocks_bm;
int fs_dirt;
int fs_flags;
void * fs_vp;
int (*block_allocator) (reiserfs_filsys_t * fs,
unsigned long * free_blocknrs,
unsigned long start, int amount_needed);
int (*block_deallocator) (reiserfs_filsys_t * fs, unsigned long block);
int fs_dirt;
int fs_flags;
void *fs_vp;
int (*block_allocator) (reiserfs_filsys_t *fs,
unsigned long *free_blocknrs,
unsigned long start, int amount_needed);
int (*block_deallocator) (reiserfs_filsys_t *fs, unsigned long block);
};
struct _transaction {
unsigned long mount_id;
unsigned long trans_id;
unsigned long desc_blocknr;
unsigned long trans_len;
unsigned long commit_blocknr;
unsigned long next_trans_offset;
unsigned long mount_id;
unsigned long trans_id;
unsigned long desc_blocknr;
unsigned long trans_len;
unsigned long commit_blocknr;
unsigned long next_trans_offset;
};
typedef struct _transaction reiserfs_trans_t;
/* reiserfslib.c */
void init_tb_struct (struct tree_balance * tb, reiserfs_filsys_t *, struct reiserfs_path *path, int size);
void init_tb_struct(struct tree_balance *tb, reiserfs_filsys_t *,
struct reiserfs_path *path, int size);
reiserfs_filsys_t * reiserfs_open (char * filename, int flags, int * error, void * vp, int skip_check);
reiserfs_filsys_t * reiserfs_create (char * filename, int version, unsigned long block_count,
int block_size, int default_journal, int new_format);
void reiserfs_flush (reiserfs_filsys_t *);
void reiserfs_free (reiserfs_filsys_t *);
void reiserfs_close (reiserfs_filsys_t *);
void reiserfs_reopen (reiserfs_filsys_t *, int flags);
int is_opened_rw (reiserfs_filsys_t * fs);
reiserfs_filsys_t *reiserfs_open(char *filename, int flags, int *error,
void *vp, int skip_check);
reiserfs_filsys_t *reiserfs_create(char *filename, int version,
unsigned long block_count, int block_size,
int default_journal, int new_format);
void reiserfs_flush(reiserfs_filsys_t *);
void reiserfs_free(reiserfs_filsys_t *);
void reiserfs_close(reiserfs_filsys_t *);
void reiserfs_reopen(reiserfs_filsys_t *, int flags);
int is_opened_rw(reiserfs_filsys_t *fs);
/*
void reiserfs_read_bitmap_blocks (reiserfs_filsys_t *);
void reiserfs_free_bitmap_blocks (reiserfs_filsys_t *);
*/
int no_reiserfs_found (reiserfs_filsys_t *);
int no_reiserfs_found(reiserfs_filsys_t *);
int block_size_ok(int blocksize, int force);
int is_block_count_correct (unsigned long block_of_super_block, unsigned int block_size,
unsigned long block_count, unsigned long journal_size);
int is_block_count_correct(unsigned long block_of_super_block,
unsigned int block_size, unsigned long block_count,
unsigned long journal_size);
//unsigned long min_block_amount (int block_size, unsigned long journal_size);
unsigned long get_size_of_journal_or_reserved_area (struct reiserfs_super_block * sb);
unsigned long get_size_of_journal_or_reserved_area(struct reiserfs_super_block
*sb);
int reiserfs_new_blocknrs (reiserfs_filsys_t *,
unsigned long * free_blocknrs, unsigned long start,
int amount_needed);
int reiserfs_free_block (reiserfs_filsys_t *, unsigned long block);
int spread_bitmaps (reiserfs_filsys_t *);
int filesystem_dirty (reiserfs_filsys_t *);
void mark_filesystem_dirty (reiserfs_filsys_t *);
int reiserfs_new_blocknrs(reiserfs_filsys_t *,
unsigned long *free_blocknrs, unsigned long start,
int amount_needed);
int reiserfs_free_block(reiserfs_filsys_t *, unsigned long block);
int spread_bitmaps(reiserfs_filsys_t *);
int filesystem_dirty(reiserfs_filsys_t *);
void mark_filesystem_dirty(reiserfs_filsys_t *);
void reiserfs_paste_into_item (reiserfs_filsys_t *, struct reiserfs_path *path,
const void * body, int size);
void reiserfs_insert_item (reiserfs_filsys_t *, struct reiserfs_path *path,
struct item_head * ih, const void * body);
void reiserfs_paste_into_item(reiserfs_filsys_t *, struct reiserfs_path *path,
const void *body, int size);
void reiserfs_insert_item(reiserfs_filsys_t *, struct reiserfs_path *path,
struct item_head *ih, const void *body);
int reiserfs_locate_entry (reiserfs_filsys_t *, struct reiserfs_key *dir, char * name,
struct reiserfs_path *path);
int reiserfs_find_entry (reiserfs_filsys_t *, struct reiserfs_key *dir, char * name,
unsigned int * min_gen_counter, struct reiserfs_key *key);
int reiserfs_add_entry (reiserfs_filsys_t *, struct reiserfs_key *dir, char * name, int name_len,
struct reiserfs_key *key, __u16 fsck_need);
int reiserfs_locate_entry(reiserfs_filsys_t *, struct reiserfs_key *dir,
char *name, struct reiserfs_path *path);
int reiserfs_find_entry(reiserfs_filsys_t *, struct reiserfs_key *dir,
char *name, unsigned int *min_gen_counter,
struct reiserfs_key *key);
int reiserfs_add_entry(reiserfs_filsys_t *, struct reiserfs_key *dir,
char *name, int name_len, struct reiserfs_key *key,
__u16 fsck_need);
struct reiserfs_key *uget_lkey (struct reiserfs_path *path);
struct reiserfs_key *uget_rkey (struct reiserfs_path *path);
int reiserfs_search_by_key_3 (reiserfs_filsys_t *, struct reiserfs_key *key,
struct reiserfs_path *path);
int reiserfs_search_by_key_4 (reiserfs_filsys_t *, struct reiserfs_key *key,
struct reiserfs_path *path);
int reiserfs_search_by_entry_key (reiserfs_filsys_t *, struct reiserfs_key *key,
struct reiserfs_path *path);
int usearch_by_position (reiserfs_filsys_t *, struct reiserfs_key *key, int version, struct reiserfs_path *path);
struct reiserfs_key *reiserfs_next_key (struct reiserfs_path *path);
void copy_key (void * to, void * from);
void copy_short_key (void * to, void * from);
void copy_item_head(void * p_v_to, void * p_v_from);
int comp_keys (const void * k1, const void * k2);
int comp_keys_3 (const void * k1, const void * k2);
int comp_short_keys (const void * p_s_key1, const void * p_s_key2);
int comp_items (struct item_head * p_s_ih, struct reiserfs_path *p_s_path);
struct reiserfs_key *uget_lkey(struct reiserfs_path *path);
struct reiserfs_key *uget_rkey(struct reiserfs_path *path);
int reiserfs_search_by_key_3(reiserfs_filsys_t *, struct reiserfs_key *key,
struct reiserfs_path *path);
int reiserfs_search_by_key_4(reiserfs_filsys_t *, struct reiserfs_key *key,
struct reiserfs_path *path);
int reiserfs_search_by_entry_key(reiserfs_filsys_t *, struct reiserfs_key *key,
struct reiserfs_path *path);
int usearch_by_position(reiserfs_filsys_t *, struct reiserfs_key *key,
int version, struct reiserfs_path *path);
struct reiserfs_key *reiserfs_next_key(struct reiserfs_path *path);
void copy_key(void *to, void *from);
void copy_short_key(void *to, void *from);
void copy_item_head(void *p_v_to, void *p_v_from);
int comp_keys(const void *k1, const void *k2);
int comp_keys_3(const void *k1, const void *k2);
int comp_short_keys(const void *p_s_key1, const void *p_s_key2);
int comp_items(struct item_head *p_s_ih, struct reiserfs_path *p_s_path);
__u32 hash_value (hashf_t func, char * name, int namelen);
__u32 hash_value(hashf_t func, char *name, int namelen);
int create_dir_sd (reiserfs_filsys_t * fs,
struct reiserfs_path *path, struct reiserfs_key *key,
void (*modify_item)(struct item_head *, void *));
void make_sure_root_dir_exists (reiserfs_filsys_t * fs,
void (*modyfy_item)(struct item_head *, void *),
int ih_flags);
int create_dir_sd(reiserfs_filsys_t *fs,
struct reiserfs_path *path, struct reiserfs_key *key,
void (*modify_item) (struct item_head *, void *));
void make_sure_root_dir_exists(reiserfs_filsys_t *fs,
void (*modyfy_item) (struct item_head *, void *),
int ih_flags);
typedef void (*badblock_func_t) (reiserfs_filsys_t *fs,
struct reiserfs_path *badblock_path,
typedef void (*badblock_func_t) (reiserfs_filsys_t *fs,
struct reiserfs_path *badblock_path,
void *data);
void mark_badblock(reiserfs_filsys_t *fs, struct reiserfs_path *badblock_path, void *data);
int create_badblock_bitmap (reiserfs_filsys_t * fs, char * badblocks_file);
void add_badblock_list (reiserfs_filsys_t * fs, int no_badblock_in_tree_yet);
void badblock_list(reiserfs_filsys_t * fs, badblock_func_t action, void *data);
void mark_badblock(reiserfs_filsys_t *fs, struct reiserfs_path *badblock_path,
void *data);
int create_badblock_bitmap(reiserfs_filsys_t *fs, char *badblocks_file);
void add_badblock_list(reiserfs_filsys_t *fs, int no_badblock_in_tree_yet);
void badblock_list(reiserfs_filsys_t *fs, badblock_func_t action, void *data);
#define reiserfs_fs_bmap_nr(fs) reiserfs_bmap_nr(get_sb_block_count(fs->fs_ondisk_sb), fs->fs_blocksize)
#define reiserfs_bmap_nr(count, blk_size) ((count - 1) / (blk_size * 8) + 1)
#define reiserfs_bmap_over(nr) (nr > ((1LL << 16) - 1))
@@ -163,52 +168,51 @@ extern struct reiserfs_key lost_found_dir_key;
extern __u16 root_dir_format;
extern __u16 lost_found_dir_format;
/* bitmap.c */
int reiserfs_open_ondisk_bitmap (reiserfs_filsys_t *);
int reiserfs_create_ondisk_bitmap (reiserfs_filsys_t *);
void reiserfs_free_ondisk_bitmap (reiserfs_filsys_t *);
void reiserfs_close_ondisk_bitmap (reiserfs_filsys_t *);
int reiserfs_flush_to_ondisk_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t * fs);
int reiserfs_open_ondisk_bitmap(reiserfs_filsys_t *);
int reiserfs_create_ondisk_bitmap(reiserfs_filsys_t *);
void reiserfs_free_ondisk_bitmap(reiserfs_filsys_t *);
void reiserfs_close_ondisk_bitmap(reiserfs_filsys_t *);
int reiserfs_flush_to_ondisk_bitmap(reiserfs_bitmap_t *bm,
reiserfs_filsys_t *fs);
unsigned int reiserfs_calc_bmap_nr(reiserfs_filsys_t *fs, unsigned int blocks);
reiserfs_bitmap_t * reiserfs_create_bitmap (unsigned int bit_count);
int reiserfs_expand_bitmap (reiserfs_bitmap_t * bm, unsigned int bit_count);
void reiserfs_shrink_bitmap (reiserfs_bitmap_t * bm, unsigned int bit_count);
void reiserfs_delete_bitmap (reiserfs_bitmap_t * bm);
void reiserfs_bitmap_copy (reiserfs_bitmap_t * to, reiserfs_bitmap_t * from);
int reiserfs_bitmap_compare (reiserfs_bitmap_t * bm1, reiserfs_bitmap_t * bm2);
void reiserfs_bitmap_disjunction (reiserfs_bitmap_t * disk, reiserfs_bitmap_t * cont);
void reiserfs_bitmap_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);
reiserfs_bitmap_t *reiserfs_create_bitmap(unsigned int bit_count);
int reiserfs_expand_bitmap(reiserfs_bitmap_t *bm, unsigned int bit_count);
void reiserfs_shrink_bitmap(reiserfs_bitmap_t *bm, unsigned int bit_count);
void reiserfs_delete_bitmap(reiserfs_bitmap_t *bm);
void reiserfs_bitmap_copy(reiserfs_bitmap_t *to, reiserfs_bitmap_t *from);
int reiserfs_bitmap_compare(reiserfs_bitmap_t *bm1, reiserfs_bitmap_t *bm2);
void reiserfs_bitmap_disjunction(reiserfs_bitmap_t *disk,
reiserfs_bitmap_t *cont);
void reiserfs_bitmap_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);
int reiserfs_bitmap_test_bit (reiserfs_bitmap_t * bm, unsigned int bit_number);
int reiserfs_bitmap_find_zero_bit (reiserfs_bitmap_t * bm, unsigned long * start);
/*int reiserfs_fetch_ondisk_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t *);*/
/*int reiserfs_flush_bitmap (reiserfs_bitmap_t * bm, reiserfs_filsys_t *);*/
void reiserfs_bitmap_zero (reiserfs_bitmap_t * bm);
void reiserfs_bitmap_fill (reiserfs_bitmap_t * bm);
unsigned int reiserfs_bitmap_ones (reiserfs_bitmap_t * bm);
unsigned int reiserfs_bitmap_zeros (reiserfs_bitmap_t * bm);
int reiserfs_bitmap_test_bit(reiserfs_bitmap_t *bm, unsigned int bit_number);
int reiserfs_bitmap_find_zero_bit(reiserfs_bitmap_t *bm, unsigned long *start);
/*int reiserfs_fetch_ondisk_bitmap (reiserfs_bitmap_t *bm, reiserfs_filsys_t *);*/
/*int reiserfs_flush_bitmap (reiserfs_bitmap_t *bm, reiserfs_filsys_t *);*/
void reiserfs_bitmap_zero(reiserfs_bitmap_t *bm);
void reiserfs_bitmap_fill(reiserfs_bitmap_t *bm);
unsigned int reiserfs_bitmap_ones(reiserfs_bitmap_t *bm);
unsigned int reiserfs_bitmap_zeros(reiserfs_bitmap_t *bm);
FILE * open_file(char * filename, char * option);
FILE *open_file(char *filename, char *option);
void close_file(FILE * fp);
void reiserfs_bitmap_save (FILE * fp, reiserfs_bitmap_t * bm);
void reiserfs_bitmap_save(FILE * fp, reiserfs_bitmap_t *bm);
/* this probably should be in fsck */
void reiserfs_begin_stage_info_save(FILE * file, unsigned long stage);
void reiserfs_end_stage_info_save(FILE * file);
int is_stage_magic_correct (FILE * fp);
int is_stage_magic_correct(FILE * fp);
//void reiserfs_stage_info_save(struct fsck_data *, FILE * file);
reiserfs_bitmap_t * reiserfs_bitmap_load (FILE * fp);
void reiserfs_bitmap_invert (reiserfs_bitmap_t * bm);
int reiserfs_remove_entry (reiserfs_filsys_t *, struct reiserfs_key *key);
reiserfs_bitmap_t *reiserfs_bitmap_load(FILE * fp);
void reiserfs_bitmap_invert(reiserfs_bitmap_t *bm);
int reiserfs_remove_entry(reiserfs_filsys_t *, struct reiserfs_key *key);
/* node_formats.c */
@@ -219,85 +223,85 @@ int reiserfs_remove_entry (reiserfs_filsys_t *, struct reiserfs_key *key);
#define HAS_IH_ARRAY 5
#define THE_UNKNOWN 6
int is_blocksize_correct (unsigned 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 is_any_reiserfs_magic_string (struct reiserfs_super_block * rs);
int get_reiserfs_format (struct reiserfs_super_block * sb);
int reiserfs_super_block_size (struct reiserfs_super_block * rs);
int is_blocksize_correct(unsigned 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 is_any_reiserfs_magic_string(struct reiserfs_super_block *rs);
int get_reiserfs_format(struct reiserfs_super_block *sb);
int reiserfs_super_block_size(struct reiserfs_super_block *rs);
/*int magic_2_version (struct reiserfs_super_block * rs);*/
int is_prejournaled_reiserfs (struct reiserfs_super_block * rs);
int who_is_this (char * buf, int blocksize);
int is_prejournaled_reiserfs(struct reiserfs_super_block *rs);
int who_is_this(char *buf, int blocksize);
int leaf_count_ih(char * buf, int blocksize);
int leaf_free_space_estimate(char * buf, int blocksize);
int is_a_leaf(char * buf, int blocksize);
int leaf_item_number_estimate(struct buffer_head * bh);
char * which_block (int code);
int get_journal_size (reiserfs_filsys_t *);
int not_data_block (reiserfs_filsys_t *, unsigned long block);
int not_journalable (reiserfs_filsys_t *, unsigned long block);
int block_of_bitmap (reiserfs_filsys_t *, unsigned long block);
int block_of_journal (reiserfs_filsys_t *, unsigned long block);
int is_tree_node (struct buffer_head * bh, int level);
int is_properly_hashed (reiserfs_filsys_t *,
char * name, int namelen, __u32 offset);
int dir_entry_bad_location (struct reiserfs_de_head * deh,
struct item_head * ih, int first);
void make_dir_stat_data (int blocksize, int key_format,
__u32 dirid, __u32 objectid,
struct item_head * ih, void * sd);
void make_empty_dir_item_v1 (char * body, __u32 dirid, __u32 objid,
__u32 par_dirid, __u32 par_objid);
void make_empty_dir_item (char * body, __u32 dirid, __u32 objid,
__u32 par_dirid, __u32 par_objid);
int reiserfs_is_fs_consistent (reiserfs_filsys_t * fs);
int leaf_count_ih(char *buf, int blocksize);
int leaf_free_space_estimate(char *buf, int blocksize);
int is_a_leaf(char *buf, int blocksize);
int leaf_item_number_estimate(struct buffer_head *bh);
char *which_block(int code);
int get_journal_size(reiserfs_filsys_t *);
int not_data_block(reiserfs_filsys_t *, unsigned long block);
int not_journalable(reiserfs_filsys_t *, unsigned long block);
int block_of_bitmap(reiserfs_filsys_t *, unsigned long block);
int block_of_journal(reiserfs_filsys_t *, unsigned long block);
int is_tree_node(struct buffer_head *bh, int level);
int is_properly_hashed(reiserfs_filsys_t *,
char *name, int namelen, __u32 offset);
int dir_entry_bad_location(struct reiserfs_de_head *deh,
struct item_head *ih, int first);
void make_dir_stat_data(int blocksize, int key_format,
__u32 dirid, __u32 objectid,
struct item_head *ih, void *sd);
void make_empty_dir_item_v1(char *body, __u32 dirid, __u32 objid,
__u32 par_dirid, __u32 par_objid);
void make_empty_dir_item(char *body, __u32 dirid, __u32 objid,
__u32 par_dirid, __u32 par_objid);
int reiserfs_is_fs_consistent(reiserfs_filsys_t *fs);
typedef void (*item_action_t) (struct buffer_head * bh, struct item_head * ih);
typedef void (*item_head_action_t) (struct item_head * ih);
void for_every_item (struct buffer_head * bh, item_head_action_t action,
item_action_t * actions);
int key_format (const struct reiserfs_key *key);
unsigned long long get_offset (const struct reiserfs_key *key);
int uniqueness2type (__u32 uniqueness);
__u32 type2uniqueness (int type);
int get_type (const struct reiserfs_key *key);
char * key_of_what (const struct reiserfs_key *key);
int type_unknown (struct reiserfs_key *key);
void set_type (int format, struct reiserfs_key *key, int type);
void set_offset (int format, struct reiserfs_key *key, loff_t offset);
void set_type_and_offset (int format, struct reiserfs_key *key, loff_t offset, int type);
void for_every_item(struct buffer_head *bh, item_head_action_t action,
item_action_t *actions);
int key_format(const struct reiserfs_key *key);
unsigned long long get_offset(const struct reiserfs_key *key);
int uniqueness2type(__u32 uniqueness);
__u32 type2uniqueness(int type);
int get_type(const struct reiserfs_key *key);
char *key_of_what(const struct reiserfs_key *key);
int type_unknown(struct reiserfs_key *key);
void set_type(int format, struct reiserfs_key *key, int type);
void set_offset(int format, struct reiserfs_key *key, loff_t offset);
void set_type_and_offset(int format, struct reiserfs_key *key, loff_t offset,
int type);
typedef int (*check_unfm_func_t) (reiserfs_filsys_t *, __u32);
int is_it_bad_item (reiserfs_filsys_t *, struct item_head *, char *,
check_unfm_func_t, int bad_dir);
int is_it_bad_item(reiserfs_filsys_t *, struct item_head *, char *,
check_unfm_func_t, int bad_dir);
#define hash_func_is_unknown(fs) ((fs)->fs_hash_function == 0)
#define reiserfs_hash(fs) ((fs)->fs_hash_function)
int known_hashes (void);
char *code2name (unsigned int code);
int func2code (hashf_t func);
hashf_t code2func (unsigned int code);
hashf_t name2func (char * hash);
int find_hash_in_use (char * name, int namelen, __u32 deh_offset, unsigned int code_to_try_first);
int known_hashes(void);
char *code2name(unsigned int code);
int func2code(hashf_t func);
hashf_t code2func(unsigned int code);
hashf_t name2func(char *hash);
int find_hash_in_use(char *name, int namelen, __u32 deh_offset,
unsigned int code_to_try_first);
int entry_length (struct item_head * ih, struct reiserfs_de_head * deh,
int pos_in_item);
char * name_in_entry (struct reiserfs_de_head * deh, int pos_in_item);
int name_in_entry_length (struct item_head * ih,
struct reiserfs_de_head * deh, int pos_in_item);
int name_length (char * name, int key_format);
int entry_length(struct item_head *ih, struct reiserfs_de_head *deh,
int pos_in_item);
char *name_in_entry(struct reiserfs_de_head *deh, int pos_in_item);
int name_in_entry_length(struct item_head *ih,
struct reiserfs_de_head *deh, int pos_in_item);
int name_length(char *name, int key_format);
/* access to stat data fields */
void get_set_sd_field (int field, struct item_head * ih, void * sd,
void * value, int set);
void get_set_sd_field(int field, struct item_head *ih, void *sd,
void *value, int set);
#define GET_SD_MODE 0
#define GET_SD_SIZE 1
#define GET_SD_NLINK 2
@@ -325,61 +329,58 @@ void get_set_sd_field (int field, struct item_head * ih, void * sd,
#define get_sd_first_direct_byte(ih,sd,pfdb) get_set_sd_field (GET_SD_FIRST_DIRECT_BYTE, ih, sd, pfdb, 0/*get*/)
#define set_sd_first_direct_byte(ih,sd,pfdb) get_set_sd_field (GET_SD_FIRST_DIRECT_BYTE, ih, sd, pfdb, 1/*set*/)
int is_objectid_used (reiserfs_filsys_t * fs, __u32 objectid);
void mark_objectid_used (reiserfs_filsys_t * fs, __u32 objectid);
int is_objectid_used(reiserfs_filsys_t *fs, __u32 objectid);
void mark_objectid_used(reiserfs_filsys_t *fs, __u32 objectid);
/* journal.c */
int get_boundary_transactions (reiserfs_filsys_t *, reiserfs_trans_t *,
reiserfs_trans_t *);
int next_transaction (reiserfs_filsys_t *, reiserfs_trans_t *, reiserfs_trans_t);
int get_boundary_transactions(reiserfs_filsys_t *, reiserfs_trans_t *,
reiserfs_trans_t *);
int next_transaction(reiserfs_filsys_t *, reiserfs_trans_t *, reiserfs_trans_t);
int replay_one_transaction (reiserfs_filsys_t *, reiserfs_trans_t *);
int replay_one_transaction(reiserfs_filsys_t *, reiserfs_trans_t *);
typedef void (*action_on_trans_t) (reiserfs_filsys_t *, reiserfs_trans_t *);
void for_each_transaction (reiserfs_filsys_t *, action_on_trans_t);
void for_each_transaction(reiserfs_filsys_t *, action_on_trans_t);
typedef void (*action_on_block_t) (reiserfs_filsys_t *, reiserfs_trans_t *,
unsigned int index,
unsigned long in_journal,
unsigned long in_place);
void for_each_block (reiserfs_filsys_t * fs, reiserfs_trans_t * trans,
action_on_block_t action);
void for_each_block(reiserfs_filsys_t *fs, reiserfs_trans_t *trans,
action_on_block_t action);
int reiserfs_open_journal (reiserfs_filsys_t *, char *, int flags);
int reiserfs_open_journal(reiserfs_filsys_t *, char *, int flags);
int reiserfs_journal_params_check(reiserfs_filsys_t *fs);
int reiserfs_create_journal (reiserfs_filsys_t * fs, char * j_filename,
unsigned long offset, unsigned long len,
int transaction_max_size, int force);
int reiserfs_journal_opened (reiserfs_filsys_t *);
void reiserfs_flush_journal (reiserfs_filsys_t * fs);
void reiserfs_free_journal (reiserfs_filsys_t * fs);
void reiserfs_close_journal (reiserfs_filsys_t *);
void reiserfs_reopen_journal (reiserfs_filsys_t * fs, int flag);
__u32 advise_journal_max_trans_age (void);
__u32 advise_journal_max_commit_age (void);
__u32 advise_journal_max_batch (unsigned long journal_trans_max);
__u32 advise_journal_max_trans_len (__u32 desired, __u32 journal_size, int blocksize, int verbose);
int reiserfs_create_journal(reiserfs_filsys_t *fs, char *j_filename,
unsigned long offset, unsigned long len,
int transaction_max_size, int force);
int reiserfs_journal_opened(reiserfs_filsys_t *);
void reiserfs_flush_journal(reiserfs_filsys_t *fs);
void reiserfs_free_journal(reiserfs_filsys_t *fs);
void reiserfs_close_journal(reiserfs_filsys_t *);
void reiserfs_reopen_journal(reiserfs_filsys_t *fs, int flag);
__u32 advise_journal_max_trans_age(void);
__u32 advise_journal_max_commit_age(void);
__u32 advise_journal_max_batch(unsigned long journal_trans_max);
__u32 advise_journal_max_trans_len(__u32 desired, __u32 journal_size,
int blocksize, int verbose);
/* prints.c */
void print_indirect_item (FILE * fp, struct buffer_head * bh, int item_num);
void print_block (FILE * fp, reiserfs_filsys_t *, struct buffer_head * bh, ...);//int print_mode, int first, int last);
int print_super_block (FILE * fp, reiserfs_filsys_t *, char * file_name, struct buffer_head * bh, int short_print);
void print_journal (reiserfs_filsys_t *);
void print_journal_header (reiserfs_filsys_t * fs);
void reiserfs_warning (FILE * fp, const char * fmt, ...);
char ftypelet (mode_t mode);
void reiserfs_print_item (FILE * fp, struct buffer_head * bh,
struct item_head * ih);
void print_filesystem_state (FILE * fp, reiserfs_filsys_t * fs);
void print_one_transaction (reiserfs_filsys_t * fs, reiserfs_trans_t * trans);
void print_journal_params (FILE * fp, struct journal_params * jp);
char * get_reiserfs_version (__u16 version);
int can_we_format_it (char * device_name, int force);
void print_indirect_item(FILE * fp, struct buffer_head *bh, int item_num);
void print_block(FILE * fp, reiserfs_filsys_t *, struct buffer_head *bh, ...); //int print_mode, int first, int last);
int print_super_block(FILE * fp, reiserfs_filsys_t *, char *file_name,
struct buffer_head *bh, int short_print);
void print_journal(reiserfs_filsys_t *);
void print_journal_header(reiserfs_filsys_t *fs);
void reiserfs_warning(FILE * fp, const char *fmt, ...);
char ftypelet(mode_t mode);
void reiserfs_print_item(FILE * fp, struct buffer_head *bh,
struct item_head *ih);
void print_filesystem_state(FILE * fp, reiserfs_filsys_t *fs);
void print_one_transaction(reiserfs_filsys_t *fs, reiserfs_trans_t *trans);
void print_journal_params(FILE * fp, struct journal_params *jp);
char *get_reiserfs_version(__u16 version);
int can_we_format_it(char *device_name, int force);
#define reiserfs_panic(fmt, list...) \
{\
-1
View File
@@ -41,7 +41,6 @@
(__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56) )); \
})
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define cpu_to_le16(val) (val)
+737 -682
View File
File diff suppressed because it is too large. Load diff
+575 -577
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -17,7 +17,7 @@ time_t parse_time(char *str)
if (strcmp(str, "now") == 0) {
return (time(0));
}
memset(&ts, 0, sizeof (ts));
memset(&ts, 0, sizeof(ts));
#ifdef HAVE_STRPTIME
strptime(str, "%Y%m%d%H%M%S", &ts);
#else
@@ -32,6 +32,6 @@ time_t parse_time(char *str)
#endif
if (ts.tm_mday == 0)
reiserfs_warning(stderr, "Couldn't parse date/time "
"specifier: %s", str);
"specifier: %s", str);
return (mktime(&ts));
}
+19 -23
View File
@@ -8,19 +8,18 @@
static char bar[128], spaces[128];
static const char spinner[] = "\\|/-";
void progbar_init(struct progbar *ctx, const char *units, FILE *fp)
void progbar_init(struct progbar *ctx, const char *units, FILE * fp)
{
memset(ctx, 0, sizeof (*ctx));
memset(ctx, 0, sizeof(*ctx));
if (!bar[0])
memset(bar, '=', sizeof(bar)-1);
memset(bar, '=', sizeof(bar) - 1);
if (!spaces[0])
memset(spaces, ' ', sizeof(spaces)-1);
memset(spaces, ' ', sizeof(spaces) - 1);
strncpy(ctx->units, units, sizeof(ctx->units));
ctx->file = fp;
}
void progbar_clear(struct progbar * ctx)
void progbar_clear(struct progbar *ctx)
{
if (!(ctx->flags & E2F_FLAG_PROG_BAR))
return;
@@ -30,17 +29,17 @@ void progbar_clear(struct progbar * ctx)
ctx->flags &= ~E2F_FLAG_PROG_BAR;
}
int progbar_update(struct progbar * ctx, const char *label, int curr, int max,
unsigned int dpynum)
int progbar_update(struct progbar *ctx, const char *label, int curr, int max,
unsigned int dpynum)
{
int i;
unsigned int tick;
struct timeval tv;
int i;
unsigned int tick;
struct timeval tv;
int dpywidth;
int fixed_percent;
assert (curr >= 0);
assert (max > 0);
float percent = ((float) curr) / ((float) max) * 100;
float percent = ((float)curr) / ((float)max) * 100;
if (ctx->flags & E2F_FLAG_PROG_SUPPRESS)
return 0;
@@ -50,7 +49,7 @@ int progbar_update(struct progbar * ctx, const char *label, int curr, int max,
* percentage hasn't changed, then we skip out right
* away.
*/
fixed_percent = (int) ((10 * percent) + 0.5);
fixed_percent = (int)((10 * percent) + 0.5);
if (ctx->progress_last_percent == fixed_percent)
return 0;
ctx->progress_last_percent = fixed_percent;
@@ -71,7 +70,7 @@ int progbar_update(struct progbar * ctx, const char *label, int curr, int max,
* Advance the spinner, and note that the progress bar
* will be on the screen
*/
ctx->progress_pos = (ctx->progress_pos+1) & 3;
ctx->progress_pos = (ctx->progress_pos + 1) & 3;
ctx->flags |= E2F_FLAG_PROG_BAR;
dpywidth = 66 - strlen(label);
@@ -81,8 +80,8 @@ int progbar_update(struct progbar * ctx, const char *label, int curr, int max,
i = ((percent * dpywidth) + 50) / 100;
fprintf(ctx->file, "\r%s: |%s%s", label,
bar + (sizeof(bar) - (i+1)),
spaces + (sizeof(spaces) - (dpywidth - i + 1)));
bar + (sizeof(bar) - (i + 1)),
spaces + (sizeof(spaces) - (dpywidth - i + 1)));
if (fixed_percent == 1000)
fputc('|', ctx->file);
else
@@ -100,21 +99,18 @@ int progbar_update(struct progbar * ctx, const char *label, int curr, int max,
return 0;
}
void
spinner_init(struct spinner *ctx, FILE *fp)
void spinner_init(struct spinner *ctx, FILE * fp)
{
memset(ctx, 0, sizeof (*ctx));
memset(ctx, 0, sizeof(*ctx));
ctx->file = fp;
}
void
spinner_touch(struct spinner *ctx)
void spinner_touch(struct spinner *ctx)
{
fprintf(ctx->file, "%c", spinner[ctx->count++ % 4]);
}
void
spinner_clear(struct spinner *ctx)
void spinner_clear(struct spinner *ctx)
{
fputs("", ctx->file);
}
+539 -543
View File
File diff suppressed because it is too large. Load diff
+506 -492
View File
File diff suppressed because it is too large. Load diff
+1445 -938
View File
File diff suppressed because it is too large. Load diff
+1910 -1766
View File
File diff suppressed because it is too large. Load diff
+102 -135
View File
@@ -24,8 +24,6 @@
#include <asm/types.h>
#define DELTA 0x9E3779B9
#define FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */
#define PARTROUNDS 6 /* 6 gets complete mixing */
@@ -55,113 +53,82 @@ typedef __u32 u32;
h1 += b1; \
} while(0)
u32 keyed_hash(const signed char *msg, int len)
{
u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3};
u32 k[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3 };
u32 h0 = k[0], h1 = k[1];
u32 a, b, c, d;
u32 pad;
int i;
pad = (u32)len | ((u32)len << 8);
pad = (u32) len | ((u32) len << 8);
pad |= pad << 16;
while(len >= 16)
{
a = (u32)msg[ 0] |
(u32)msg[ 1] << 8 |
(u32)msg[ 2] << 16|
(u32)msg[ 3] << 24;
b = (u32)msg[ 4] |
(u32)msg[ 5] << 8 |
(u32)msg[ 6] << 16|
(u32)msg[ 7] << 24;
c = (u32)msg[ 8] |
(u32)msg[ 9] << 8 |
(u32)msg[10] << 16|
(u32)msg[11] << 24;
d = (u32)msg[12] |
(u32)msg[13] << 8 |
(u32)msg[14] << 16|
(u32)msg[15] << 24;
while (len >= 16) {
a = (u32) msg[0] |
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
b = (u32) msg[4] |
(u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
c = (u32) msg[8] |
(u32) msg[9] << 8 |
(u32) msg[10] << 16 | (u32) msg[11] << 24;
d = (u32) msg[12] |
(u32) msg[13] << 8 |
(u32) msg[14] << 16 | (u32) msg[15] << 24;
TEACORE(PARTROUNDS);
len -= 16;
msg += 16;
}
if (len >= 12)
{
if (len >= 12) {
if (len >= 16)
*(int *)0 = 0;
*(int *)0 = 0;
a = (u32)msg[ 0] |
(u32)msg[ 1] << 8 |
(u32)msg[ 2] << 16|
(u32)msg[ 3] << 24;
b = (u32)msg[ 4] |
(u32)msg[ 5] << 8 |
(u32)msg[ 6] << 16|
(u32)msg[ 7] << 24;
c = (u32)msg[ 8] |
(u32)msg[ 9] << 8 |
(u32)msg[10] << 16|
(u32)msg[11] << 24;
a = (u32) msg[0] |
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
b = (u32) msg[4] |
(u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
c = (u32) msg[8] |
(u32) msg[9] << 8 |
(u32) msg[10] << 16 | (u32) msg[11] << 24;
d = pad;
for(i = 12; i < len; i++)
{
for (i = 12; i < len; i++) {
d <<= 8;
d |= msg[i];
}
}
else if (len >= 8)
{
} else if (len >= 8) {
if (len >= 12)
*(int *)0 = 0;
a = (u32)msg[ 0] |
(u32)msg[ 1] << 8 |
(u32)msg[ 2] << 16|
(u32)msg[ 3] << 24;
b = (u32)msg[ 4] |
(u32)msg[ 5] << 8 |
(u32)msg[ 6] << 16|
(u32)msg[ 7] << 24;
*(int *)0 = 0;
a = (u32) msg[0] |
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
b = (u32) msg[4] |
(u32) msg[5] << 8 | (u32) msg[6] << 16 | (u32) msg[7] << 24;
c = d = pad;
for(i = 8; i < len; i++)
{
for (i = 8; i < len; i++) {
c <<= 8;
c |= msg[i];
}
}
else if (len >= 4)
{
} else if (len >= 4) {
if (len >= 8)
*(int *)0 = 0;
a = (u32)msg[ 0] |
(u32)msg[ 1] << 8 |
(u32)msg[ 2] << 16|
(u32)msg[ 3] << 24;
*(int *)0 = 0;
a = (u32) msg[0] |
(u32) msg[1] << 8 | (u32) msg[2] << 16 | (u32) msg[3] << 24;
b = c = d = pad;
for(i = 4; i < len; i++)
{
for (i = 4; i < len; i++) {
b <<= 8;
b |= msg[i];
}
}
else
{
} else {
if (len >= 4)
*(int *)0 = 0;
*(int *)0 = 0;
a = b = c = d = pad;
for(i = 0; i < len; i++)
{
for (i = 0; i < len; i++) {
a <<= 8;
a |= msg[i];
}
@@ -169,83 +136,83 @@ u32 keyed_hash(const signed char *msg, int len)
TEACORE(FULLROUNDS);
return h0^h1;
return h0 ^ h1;
}
u32 yura_hash (const signed char *msg, int len)
u32 yura_hash(const signed char *msg, int len)
{
int j, pow;
u32 a, c;
int i;
for (pow=1,i=1; i < len; i++) pow = pow * 10;
if (len == 1)
a = msg[0]-48;
else
a = (msg[0] - 48) * pow;
for (i=1; i < len; i++) {
c = msg[i] - 48;
for (pow=1,j=i; j < len-1; j++) pow = pow * 10;
a = a + c * pow;
}
for (; i < 40; i++) {
c = '0' - 48;
for (pow=1,j=i; j < len-1; j++) pow = pow * 10;
a = a + c * pow;
}
for (; i < 256; i++) {
c = i;
for (pow=1,j=i; j < len-1; j++) pow = pow * 10;
a = a + c * pow;
}
a = a << 7;
return a;
int j, pow;
u32 a, c;
int i;
for (pow = 1, i = 1; i < len; i++)
pow = pow * 10;
if (len == 1)
a = msg[0] - 48;
else
a = (msg[0] - 48) * pow;
for (i = 1; i < len; i++) {
c = msg[i] - 48;
for (pow = 1, j = i; j < len - 1; j++)
pow = pow * 10;
a = a + c * pow;
}
for (; i < 40; i++) {
c = '0' - 48;
for (pow = 1, j = i; j < len - 1; j++)
pow = pow * 10;
a = a + c * pow;
}
for (; i < 256; i++) {
c = i;
for (pow = 1, j = i; j < len - 1; j++)
pow = pow * 10;
a = a + c * pow;
}
a = a << 7;
return a;
}
u32 r5_hash (const signed char *msg, int len)
u32 r5_hash(const signed char *msg, int len)
{
u32 a=0;
int i;
for (i = 0; i < len; i ++) {
a += msg[i] << 4;
a += msg[i] >> 4;
a *= 11;
}
return a;
}
u32 a = 0;
int i;
for (i = 0; i < len; i++) {
a += msg[i] << 4;
a += msg[i] >> 4;
a *= 11;
}
return a;
}
#if 0
#include <stdio.h>
int main (void)
int main(void)
{
char * name = 0;
size_t n = 0;
char *name = 0;
size_t n = 0;
while (1) {
getline (&name, &n, stdin);
if (!strcmp (name, "\n"))
break;
name [strlen (name) - 1] = 0;
printf ("tea %lu\n, r5 %lu\nyura %lu\n",
keyed_hash (name, strlen (name)) & 0x7fffff80,
r5_hash (name, strlen (name)) & 0x7fffff80,
yura_hash (name, strlen (name)) & 0x7fffff80);
free (name);
name = 0;
n = 0;
}
while (1) {
getline(&name, &n, stdin);
if (!strcmp(name, "\n"))
break;
name[strlen(name) - 1] = 0;
printf("tea %lu\n, r5 %lu\nyura %lu\n",
keyed_hash(name, strlen(name)) & 0x7fffff80,
r5_hash(name, strlen(name)) & 0x7fffff80,
yura_hash(name, strlen(name)) & 0x7fffff80);
free(name);
name = 0;
n = 0;
}
}
#endif
+764 -708
View File
File diff suppressed because it is too large. Load diff
+728 -698
View File
File diff suppressed because it is too large. Load diff
+971 -882
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+876 -813
View File
File diff suppressed because it is too large. Load diff
+1177 -1137
View File
File diff suppressed because it is too large. Load diff
+270 -252
View File
@@ -37,14 +37,12 @@
*/
#include "includes.h"
/* Does the buffer contain a disk block which is in the tree. */
inline int B_IS_IN_TREE (struct buffer_head * p_s_bh)
inline int B_IS_IN_TREE(struct buffer_head *p_s_bh)
{
return ( get_blkh_level (B_BLK_HEAD (p_s_bh)) != FREE_LEVEL );
return (get_blkh_level(B_BLK_HEAD(p_s_bh)) != FREE_LEVEL);
}
/*
Compare keys using REISERFS_SHORT_KEY_LEN fields.
Returns: -1 if key1 < key2
@@ -52,78 +50,75 @@ inline int B_IS_IN_TREE (struct buffer_head * p_s_bh)
1 if key1 > key2
*/
int comp_short_keys (const void * k1, const void * k2)
int comp_short_keys(const void *k1, const void *k2)
{
int n_key_length = REISERFS_SHORT_KEY_LEN;
__u32 * p_s_key1 = (__u32 *)k1;
__u32 * p_s_key2 = (__u32 *)k2;
__u32 u1, u2;
int n_key_length = REISERFS_SHORT_KEY_LEN;
__u32 *p_s_key1 = (__u32 *) k1;
__u32 *p_s_key2 = (__u32 *) k2;
__u32 u1, u2;
for( ; n_key_length--; ++p_s_key1, ++p_s_key2 ) {
u1 = d32_get(p_s_key1, 0) ;
u2 = d32_get(p_s_key2, 0) ;
if ( u1 < u2 )
return -1;
if ( u1 > u2 )
return 1;
}
for (; n_key_length--; ++p_s_key1, ++p_s_key2) {
u1 = d32_get(p_s_key1, 0);
u2 = d32_get(p_s_key2, 0);
if (u1 < u2)
return -1;
if (u1 > u2)
return 1;
}
return 0;
return 0;
}
int comp_keys_3 (const void * p1, const void * p2)
int comp_keys_3(const void *p1, const void *p2)
{
int retval;
const struct reiserfs_key *k1 = p1;
const struct reiserfs_key *k2 = p2;
loff_t off1, off2;
int retval;
const struct reiserfs_key *k1 = p1;
const struct reiserfs_key *k2 = p2;
loff_t off1, off2;
retval = comp_short_keys (k1, k2);
if (retval)
return retval;
off1 = get_offset(k1) ;
off2 = get_offset(k2) ;
if (off1 < off2)
return -1;
retval = comp_short_keys(k1, k2);
if (retval)
return retval;
off1 = get_offset(k1);
off2 = get_offset(k2);
if (off1 < off2)
return -1;
if (off1 > off2)
return 1;
if (off1 > off2)
return 1;
return 0;
return 0;
}
/*
Compare keys using all 4 key fields.
Returns: -1 if key1 < key2
0 if key1 = key2
1 if key1 > key2
*/
int comp_keys (const void * p1, const void * p2)
int comp_keys(const void *p1, const void *p2)
{
int retval;
const struct reiserfs_key *k1 = p1;
const struct reiserfs_key *k2 = p2;
__u32 u1, u2;
int retval;
const struct reiserfs_key *k1 = p1;
const struct reiserfs_key *k2 = p2;
__u32 u1, u2;
retval = comp_keys_3 (k1, k2);
if (retval)
return retval;
retval = comp_keys_3(k1, k2);
if (retval)
return retval;
u1 = get_type (k1);
u2 = get_type (k2);
u1 = get_type(k1);
u2 = get_type(k2);
if (u1 < u2)
return -1;
if (u1 < u2)
return -1;
if (u1 > u2)
return 1;
if (u1 > u2)
return 1;
return 0;
return 0;
}
/**************************************************************************
* Binary search toolkit function *
* Search for an item in the array by the item key *
@@ -138,42 +133,51 @@ int comp_keys (const void * p1, const void * p2)
there are no possible items, and we have not found it. With each examination we
cut the number of possible items it could be by one more than half rounded down,
or we find it. */
int bin_search (
void * p_v_key, /* Key to search for. */
void * p_v_base, /* First item in the array. */
int p_n_num, /* Number of items in the array. */
int p_n_width, /* Item size in the array.
searched. Lest the reader be
confused, note that this is crafted
as a general function, and when it
is applied specifically to the array
of item headers in a node, p_n_width
is actually the item header size not
the item size. */
unsigned int * p_n_pos /* Number of the searched
for element. */
) {
int n_rbound, n_lbound, n_j;
int bin_search(void *p_v_key, /* Key to search for. */
void *p_v_base, /* First item in the array. */
int p_n_num, /* Number of items in the array. */
int p_n_width, /* Item size in the array.
searched. Lest the reader be
confused, note that this is crafted
as a general function, and when it
is applied specifically to the array
of item headers in a node, p_n_width
is actually the item header size not
the item size. */
unsigned int *p_n_pos /* Number of the searched
for element. */
)
{
int n_rbound, n_lbound, n_j;
for ( n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0))/2; n_lbound <= n_rbound; n_j = (n_rbound + n_lbound)/2 )
switch( COMP_KEYS((struct reiserfs_key *)((char * )p_v_base + n_j * p_n_width), p_v_key) ) {
case -1: n_lbound = n_j + 1; continue;
case 1: n_rbound = n_j - 1; continue;
case 0: *p_n_pos = n_j; return ITEM_FOUND; /* Key found in the array. */
}
for (n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0)) / 2;
n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2)
switch (COMP_KEYS
((struct reiserfs_key *)((char *)p_v_base +
n_j * p_n_width), p_v_key)) {
case -1:
n_lbound = n_j + 1;
continue;
case 1:
n_rbound = n_j - 1;
continue;
case 0:
*p_n_pos = n_j;
return ITEM_FOUND; /* Key found in the array. */
}
/* bin_search did not find given key, it returns position of key,
that is minimal and greater than the given one. */
*p_n_pos = n_lbound;
return ITEM_NOT_FOUND;
/* bin_search did not find given key, it returns position of key,
that is minimal and greater than the given one. */
*p_n_pos = n_lbound;
return ITEM_NOT_FOUND;
}
/* Minimal possible key. It is never in the tree. */
struct reiserfs_key MIN_KEY = {0, 0, {{0, 0},}};
struct reiserfs_key MIN_KEY = { 0, 0, {{0, 0},} };
/* Maximal possible key. It is never in the tree. */
struct reiserfs_key MAX_KEY = {0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff},}};
struct reiserfs_key MAX_KEY =
{ 0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff},} };
/* Get delimiting key of the buffer by looking for it in the buffers in the
path, starting from the bottom of the path, and going upwards. We must
@@ -181,73 +185,82 @@ struct reiserfs_key MAX_KEY = {0xffffffff, 0xffffffff, {{0xffffffff, 0xffffffff
there is no delimiting key in the tree (buffer is first or last buffer in
tree), and in this case we return a special key, either MIN_KEY or
MAX_KEY. */
struct reiserfs_key *get_lkey (struct reiserfs_path *p_s_chk_path,
reiserfs_filsys_t * fs)
struct reiserfs_key *get_lkey(struct reiserfs_path *p_s_chk_path,
reiserfs_filsys_t *fs)
{
struct reiserfs_super_block * sb;
int n_position, n_path_offset = p_s_chk_path->path_length;
struct buffer_head * p_s_parent;
sb = fs->fs_ondisk_sb;
struct reiserfs_super_block *sb;
int n_position, n_path_offset = p_s_chk_path->path_length;
struct buffer_head *p_s_parent;
/* While not higher in path than first element. */
while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) {
/* Parent at the path is not in the tree now. */
if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
return &MAX_KEY;
/* Check whether position in the parent is correct. */
if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) )
return &MAX_KEY;
/* Check whether parent at the path really points to the child. */
if ( get_dc_child_blocknr (B_N_CHILD (p_s_parent, n_position)) !=
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr )
return &MAX_KEY;
/* Return delimiting key if position in the parent is not equal to zero. */
if ( n_position )
return B_N_PDELIM_KEY(p_s_parent, n_position - 1);
}
/* Return MIN_KEY if we are in the root of the buffer tree. */
if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
get_sb_root_block (sb) )
return &MIN_KEY;
return &MAX_KEY;
sb = fs->fs_ondisk_sb;
/* While not higher in path than first element. */
while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
/* Parent at the path is not in the tree now. */
if (!B_IS_IN_TREE
(p_s_parent =
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
return &MAX_KEY;
/* Check whether position in the parent is correct. */
if ((n_position =
PATH_OFFSET_POSITION(p_s_chk_path,
n_path_offset)) >
B_NR_ITEMS(p_s_parent))
return &MAX_KEY;
/* Check whether parent at the path really points to the child. */
if (get_dc_child_blocknr(B_N_CHILD(p_s_parent, n_position)) !=
PATH_OFFSET_PBUFFER(p_s_chk_path,
n_path_offset + 1)->b_blocknr)
return &MAX_KEY;
/* Return delimiting key if position in the parent is not equal to zero. */
if (n_position)
return B_N_PDELIM_KEY(p_s_parent, n_position - 1);
}
/* Return MIN_KEY if we are in the root of the buffer tree. */
if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
b_blocknr == get_sb_root_block(sb))
return &MIN_KEY;
return &MAX_KEY;
}
/* Get delimiting key of the buffer at the path and its right neighbor. */
struct reiserfs_key *get_rkey (struct reiserfs_path *p_s_chk_path,
reiserfs_filsys_t * fs)
struct reiserfs_key *get_rkey(struct reiserfs_path *p_s_chk_path,
reiserfs_filsys_t *fs)
{
struct reiserfs_super_block * sb;
int n_position,
n_path_offset = p_s_chk_path->path_length;
struct buffer_head * p_s_parent;
struct reiserfs_super_block *sb;
int n_position, n_path_offset = p_s_chk_path->path_length;
struct buffer_head *p_s_parent;
sb = fs->fs_ondisk_sb;
sb = fs->fs_ondisk_sb;
while ( n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET ) {
/* Parent at the path is not in the tree now. */
if ( ! B_IS_IN_TREE(p_s_parent = PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)) )
return &MIN_KEY;
/* Check whether position in the parrent is correct. */
if ( (n_position = PATH_OFFSET_POSITION(p_s_chk_path, n_path_offset)) > B_NR_ITEMS(p_s_parent) )
return &MIN_KEY;
/* Check whether parent at the path really points to the child. */
if ( get_dc_child_blocknr (B_N_CHILD (p_s_parent, n_position)) !=
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset + 1)->b_blocknr )
return &MIN_KEY;
/* Return delimiting key if position in the parent is not the last one. */
if ( n_position != B_NR_ITEMS(p_s_parent) )
return B_N_PDELIM_KEY(p_s_parent, n_position);
}
/* Return MAX_KEY if we are in the root of the buffer tree. */
if ( PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
get_sb_root_block (sb) )
return &MAX_KEY;
return &MIN_KEY;
while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
/* Parent at the path is not in the tree now. */
if (!B_IS_IN_TREE
(p_s_parent =
PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)))
return &MIN_KEY;
/* Check whether position in the parrent is correct. */
if ((n_position =
PATH_OFFSET_POSITION(p_s_chk_path,
n_path_offset)) >
B_NR_ITEMS(p_s_parent))
return &MIN_KEY;
/* Check whether parent at the path really points to the child. */
if (get_dc_child_blocknr(B_N_CHILD(p_s_parent, n_position)) !=
PATH_OFFSET_PBUFFER(p_s_chk_path,
n_path_offset + 1)->b_blocknr)
return &MIN_KEY;
/* Return delimiting key if position in the parent is not the last one. */
if (n_position != B_NR_ITEMS(p_s_parent))
return B_N_PDELIM_KEY(p_s_parent, n_position);
}
/* Return MAX_KEY if we are in the root of the buffer tree. */
if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)->
b_blocknr == get_sb_root_block(sb))
return &MAX_KEY;
return &MIN_KEY;
}
/* Check whether a key is contained in the tree rooted from a buffer at a
path. This works by looking at the left and right delimiting keys for the
buffer in the last path_element in the path. These delimiting keys are
@@ -255,31 +268,30 @@ struct reiserfs_key *get_rkey (struct reiserfs_path *p_s_chk_path,
the first or last node in the tree order then one of the delimiting keys
may be absent, and in this case get_lkey and get_rkey return a special key
which is MIN_KEY or MAX_KEY. */
static inline int key_in_buffer (
struct reiserfs_path * p_s_chk_path, /* Path which should be checked. */
struct reiserfs_key * p_s_key, /* Key which should be checked. */
reiserfs_filsys_t * fs /* Super block pointer. */
) {
static inline int key_in_buffer(struct reiserfs_path *p_s_chk_path, /* Path which should be checked. */
struct reiserfs_key *p_s_key, /* Key which should be checked. */
reiserfs_filsys_t *fs /* Super block pointer. */
)
{
if ( COMP_KEYS(get_lkey(p_s_chk_path, fs), p_s_key) == 1 )
return 0;
if ( COMP_KEYS(p_s_key, get_rkey(p_s_chk_path, fs)) != -1 )
return 0;
return 1;
if (COMP_KEYS(get_lkey(p_s_chk_path, fs), p_s_key) == 1)
return 0;
if (COMP_KEYS(p_s_key, get_rkey(p_s_chk_path, fs)) != -1)
return 0;
return 1;
}
/* Release all buffers in the path. */
void pathrelse (struct reiserfs_path *p_s_search_path)
void pathrelse(struct reiserfs_path *p_s_search_path)
{
int n_path_offset = p_s_search_path->path_length;
while ( n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET )
brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
int n_path_offset = p_s_search_path->path_length;
p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
}
/**************************************************************************
* Algorithm SearchByKey *
* look for item in internal tree on the disk by its key *
@@ -302,115 +314,121 @@ void pathrelse (struct reiserfs_path *p_s_search_path)
key. search_by_key returns a path that must be checked for the
correctness of the top of the path but need not be checked for the
correctness of the bottom of the path */
int search_by_key (reiserfs_filsys_t * fs,
struct reiserfs_key *p_s_key, /* Key to search */
struct reiserfs_path *p_s_search_path,/* This structure was
allocated and
initialized by the
calling
function. It is
filled up by this
function. */
int n_stop_level) /* How far down the tree to search.*/
{
struct reiserfs_super_block * sb;
unsigned int n_block_number,
expected_level,
n_block_size = fs->fs_blocksize;
struct buffer_head * p_s_bh;
struct reiserfs_path_element * p_s_last_element;
int n_retval;
int search_by_key(reiserfs_filsys_t *fs, struct reiserfs_key *p_s_key, /* Key to search */
struct reiserfs_path *p_s_search_path, /* This structure was
allocated and
initialized by the
calling
function. It is
filled up by this
function. */
int n_stop_level)
{ /* How far down the tree to search. */
struct reiserfs_super_block *sb;
unsigned int n_block_number,
expected_level, n_block_size = fs->fs_blocksize;
struct buffer_head *p_s_bh;
struct reiserfs_path_element *p_s_last_element;
int n_retval;
sb = fs->fs_ondisk_sb;
n_block_number = get_sb_root_block(sb);
expected_level = get_sb_tree_height(sb);
sb = fs->fs_ondisk_sb;
n_block_number = get_sb_root_block (sb);
expected_level = get_sb_tree_height (sb);
/* As we add each node to a path we increase its count. This
means that we must be careful to release all nodes in a path
before we either discard the path struct or re-use the path
struct, as we do here. */
pathrelse (p_s_search_path);
/* As we add each node to a path we increase its count. This
means that we must be careful to release all nodes in a path
before we either discard the path struct or re-use the path
struct, as we do here. */
pathrelse(p_s_search_path);
/* With each iteration of this loop we search through the items in
the current node, and calculate the next current node(next path
element) for the next iteration of this loop.. */
while (1) {
/* With each iteration of this loop we search through the items in
the current node, and calculate the next current node(next path
element) for the next iteration of this loop.. */
while ( 1 ) {
/* prep path to have another element added to it. */
p_s_last_element =
PATH_OFFSET_PELEMENT(p_s_search_path,
++p_s_search_path->path_length);
expected_level--;
/* prep path to have another element added to it. */
p_s_last_element = PATH_OFFSET_PELEMENT(p_s_search_path, ++p_s_search_path->path_length);
expected_level --;
/* Read the next tree node, and set the last element in the
path to have a pointer to it. */
if (!(p_s_bh = p_s_last_element->pe_buffer =
bread(fs->fs_dev, n_block_number, n_block_size))) {
p_s_search_path->path_length--;
pathrelse(p_s_search_path);
return IO_ERROR;
}
/* Read the next tree node, and set the last element in the
path to have a pointer to it. */
if ( ! (p_s_bh = p_s_last_element->pe_buffer =
bread (fs->fs_dev, n_block_number, n_block_size)) ) {
p_s_search_path->path_length --;
pathrelse(p_s_search_path);
return IO_ERROR;
/* It is possible that schedule occured. We must check whether
the key to search is still in the tree rooted from the
current buffer. If not then repeat search from the root. */
if (!B_IS_IN_TREE(p_s_bh) ||
!key_in_buffer(p_s_search_path, p_s_key, fs))
reiserfs_panic
("search_by_key: something wrong with the tree");
/* make sure, that the node contents look like a node of
certain level */
if (!is_tree_node(p_s_bh, expected_level)) {
print_block(stderr, 0, p_s_bh, 3, -1, -1);
reiserfs_panic("search_by_key: expected level %d",
expected_level);
}
/* ok, we have acquired next formatted node in the tree */
n_retval =
bin_search(p_s_key, B_N_PITEM_HEAD(p_s_bh, 0),
B_NR_ITEMS(p_s_bh),
is_leaf_node(p_s_bh) ? IH_SIZE : KEY_SIZE,
&(p_s_last_element->pe_position));
if (get_blkh_level(B_BLK_HEAD(p_s_bh)) == n_stop_level)
return n_retval;
/* we are not in the stop level */
if (n_retval == ITEM_FOUND)
/* item has been found, so we choose the pointer which is
to the right of the found one */
p_s_last_element->pe_position++;
/* if item was not found we choose the position which is to
the left of the found item. This requires no code,
bin_search did it already. */
/* So we have chosen a position in the current node which is
an internal node. Now we calculate child block number by
position in the node. */
n_block_number =
get_dc_child_blocknr(B_N_CHILD
(p_s_bh,
p_s_last_element->pe_position));
}
/* It is possible that schedule occured. We must check whether
the key to search is still in the tree rooted from the
current buffer. If not then repeat search from the root. */
if (!B_IS_IN_TREE (p_s_bh) ||
! key_in_buffer(p_s_search_path, p_s_key, fs))
reiserfs_panic ("search_by_key: something wrong with the tree");
/* make sure, that the node contents look like a node of
certain level */
if (!is_tree_node (p_s_bh, expected_level)) {
print_block (stderr, 0, p_s_bh, 3, -1, -1);
reiserfs_panic ("search_by_key: expected level %d", expected_level);
}
/* ok, we have acquired next formatted node in the tree */
n_retval = bin_search (p_s_key, B_N_PITEM_HEAD(p_s_bh, 0), B_NR_ITEMS(p_s_bh),
is_leaf_node (p_s_bh) ? IH_SIZE : KEY_SIZE, &(p_s_last_element->pe_position));
if (get_blkh_level (B_BLK_HEAD (p_s_bh)) == n_stop_level)
return n_retval;
/* we are not in the stop level */
if (n_retval == ITEM_FOUND)
/* item has been found, so we choose the pointer which is
to the right of the found one */
p_s_last_element->pe_position++;
/* if item was not found we choose the position which is to
the left of the found item. This requires no code,
bin_search did it already.*/
/* So we have chosen a position in the current node which is
an internal node. Now we calculate child block number by
position in the node. */
n_block_number = get_dc_child_blocknr (B_N_CHILD (p_s_bh, p_s_last_element->pe_position));
}
}
int bin_search_in_dir_item (struct item_head * ih, struct reiserfs_de_head * deh,
struct reiserfs_key *key, int * pos_in_item)
int bin_search_in_dir_item(struct item_head *ih, struct reiserfs_de_head *deh,
struct reiserfs_key *key, int *pos_in_item)
{
int rbound, lbound, j;
int rbound, lbound, j;
lbound = 0;
rbound = get_ih_entry_count (ih) - 1;
lbound = 0;
rbound = get_ih_entry_count(ih) - 1;
for (j = (rbound + lbound) / 2; lbound <= rbound; j = (rbound + lbound) / 2) {
if (get_offset (key) < get_deh_offset (deh + j)) {
rbound = j - 1;
continue;
for (j = (rbound + lbound) / 2; lbound <= rbound;
j = (rbound + lbound) / 2) {
if (get_offset(key) < get_deh_offset(deh + j)) {
rbound = j - 1;
continue;
}
if (get_offset(key) > get_deh_offset(deh + j)) {
lbound = j + 1;
continue;
}
/* key found */
*pos_in_item = j;
return POSITION_FOUND;
}
if (get_offset (key) > get_deh_offset (deh + j)) {
lbound = j + 1;
continue;
}
/* key found */
*pos_in_item = j;
return POSITION_FOUND;
}
*pos_in_item = lbound;
return POSITION_NOT_FOUND;
*pos_in_item = lbound;
return POSITION_NOT_FOUND;
}
+131 -120
View File
@@ -6,9 +6,9 @@
#include "resize.h"
#include <time.h>
static unsigned long int_node_cnt = 0, int_moved_cnt = 0;
static unsigned long leaf_node_cnt = 0, leaf_moved_cnt = 0;
static unsigned long unfm_node_cnt = 0, unfm_moved_cnt = 0;
static unsigned long int_node_cnt = 0, int_moved_cnt = 0;
static unsigned long leaf_node_cnt = 0, leaf_moved_cnt = 0;
static unsigned long unfm_node_cnt = 0, unfm_moved_cnt = 0;
static unsigned long total_node_cnt = 0;
static unsigned long total_moved_cnt = 0;
@@ -16,25 +16,25 @@ static unsigned long unused_block;
static unsigned long blocks_used;
static int block_count_mismatch = 0;
static reiserfs_bitmap_t * bmp;
static struct reiserfs_super_block * ondisk_sb;
static reiserfs_bitmap_t *bmp;
static struct reiserfs_super_block *ondisk_sb;
/* abnornal exit from block reallocation process */
static void quit_resizer(reiserfs_filsys_t * fs)
static void quit_resizer(reiserfs_filsys_t *fs)
{
/* save changes to bitmap blocks */
reiserfs_close (fs);
reiserfs_close(fs);
/* leave fs in ERROR state */
reiserfs_exit(1, "fs shrinking was not completed successfully, "
"run reiserfsck.");
}
/* block moving */
static unsigned long move_generic_block(reiserfs_filsys_t * fs,
unsigned long block,
static unsigned long move_generic_block(reiserfs_filsys_t *fs,
unsigned long block,
unsigned long bnd, int h)
{
struct buffer_head * bh, * bh2;
struct buffer_head *bh, *bh2;
/* primitive fsck */
if (block > get_sb_block_count(ondisk_sb)) {
@@ -42,31 +42,32 @@ static unsigned long move_generic_block(reiserfs_filsys_t * fs,
"(%lu) found.\n", block);
quit_resizer(fs);
}
/* progress bar, 3D style :) */
if (opt_verbose)
print_how_far(stderr, &total_node_cnt, blocks_used, 1, 0);
print_how_far(stderr, &total_node_cnt, blocks_used, 1, 0);
else
total_node_cnt ++;
total_node_cnt++;
/* infinite loop check */
if( total_node_cnt > blocks_used && !block_count_mismatch) {
fputs("resize_reiserfs: warning: block count exeeded\n",stderr);
if (total_node_cnt > blocks_used && !block_count_mismatch) {
fputs("resize_reiserfs: warning: block count exeeded\n",
stderr);
block_count_mismatch = 1;
}
if (block < bnd) /* block will not be moved */
if (block < bnd) /* block will not be moved */
return 0;
/* move wrong block */
/* move wrong block */
bh = bread(fs->fs_dev, block, fs->fs_blocksize);
if (!bh)
reiserfs_exit (1, "move_generic_block: bread failed.\n");
reiserfs_exit(1, "move_generic_block: bread failed.\n");
reiserfs_bitmap_find_zero_bit(bmp, &unused_block);
if (unused_block == 0 || unused_block >= bnd) {
fputs ("resize_reiserfs: can\'t find free block\n", stderr);
fputs("resize_reiserfs: can\'t find free block\n", stderr);
quit_resizer(fs);
}
@@ -77,7 +78,7 @@ static unsigned long move_generic_block(reiserfs_filsys_t * fs,
reiserfs_bitmap_set_bit(bmp, unused_block);
brelse(bh);
mark_buffer_uptodate(bh2,1);
mark_buffer_uptodate(bh2, 1);
mark_buffer_dirty(bh2);
bwrite(bh2);
brelse(bh2);
@@ -86,83 +87,97 @@ static unsigned long move_generic_block(reiserfs_filsys_t * fs,
return unused_block;
}
static unsigned long move_unformatted_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h)
static unsigned long move_unformatted_block(reiserfs_filsys_t *fs,
unsigned long block,
unsigned long bnd, int h)
{
unsigned long b;
unfm_node_cnt++;
b = move_generic_block(fs, block, bnd, h);
if (b)
unfm_moved_cnt++;
return b;
return b;
}
/* recursive function processing all tree nodes */
static unsigned long move_formatted_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h)
static unsigned long move_formatted_block(reiserfs_filsys_t *fs,
unsigned long block,
unsigned long bnd, int h)
{
struct buffer_head * bh;
struct buffer_head *bh;
struct item_head *ih;
unsigned long new_blocknr = 0;
int node_is_internal = 0;
unsigned int i, j;
bh = bread(fs->fs_dev, block, fs->fs_blocksize);
if (!bh)
reiserfs_exit (1, "move_formatted_block: bread failed");
if (is_leaf_node (bh)) {
reiserfs_exit(1, "move_formatted_block: bread failed");
if (is_leaf_node(bh)) {
leaf_node_cnt++;
for (i = 0; i < B_NR_ITEMS(bh); i++) {
ih = B_N_PITEM_HEAD(bh, i);
/* skip the bad blocks. */
if (get_key_objectid (&ih->ih_key) == BADBLOCK_OBJID &&
get_key_dirid (&ih->ih_key) == BADBLOCK_DIRID)
if (get_key_objectid(&ih->ih_key) == BADBLOCK_OBJID &&
get_key_dirid(&ih->ih_key) == BADBLOCK_DIRID)
continue;
if (is_indirect_ih(ih)) {
__u32 * indirect;
__u32 *indirect;
indirect = (__u32 *)B_I_PITEM (bh, ih);
indirect = (__u32 *) B_I_PITEM(bh, ih);
for (j = 0; j < I_UNFM_NUM(ih); j++) {
unsigned long unfm_block;
unsigned long unfm_block;
if (d32_get (indirect, j) == 0) /* hole */
if (d32_get(indirect, j) == 0) /* hole */
continue;
unfm_block = move_unformatted_block(fs, d32_get (indirect, j), bnd, h + 1);
unfm_block =
move_unformatted_block(fs,
d32_get
(indirect,
j), bnd,
h + 1);
if (unfm_block) {
d32_put (indirect, j, unfm_block);
d32_put(indirect, j,
unfm_block);
mark_buffer_dirty(bh);
}
}
}
}
}
} else if (is_internal_node (bh)) { /* internal node */
} else if (is_internal_node(bh)) { /* internal node */
int_node_cnt++;
node_is_internal = 1;
for (i=0; i <= B_NR_ITEMS(bh); i++) {
for (i = 0; i <= B_NR_ITEMS(bh); i++) {
unsigned long moved_block;
moved_block = move_formatted_block(fs, get_dc_child_blocknr (B_N_CHILD (bh, i)), bnd, h+1);
moved_block =
move_formatted_block(fs,
get_dc_child_blocknr(B_N_CHILD
(bh, i)),
bnd, h + 1);
if (moved_block) {
set_dc_child_blocknr (B_N_CHILD (bh, i), moved_block);
set_dc_child_blocknr(B_N_CHILD(bh, i),
moved_block);
mark_buffer_dirty(bh);
}
}
}
} else {
DIE ("block (%lu) has invalid format\n", block);
DIE("block (%lu) has invalid format\n", block);
}
if (buffer_dirty(bh)) {
mark_buffer_uptodate(bh,1);
mark_buffer_uptodate(bh, 1);
bwrite(bh);
}
brelse(bh);
brelse(bh);
new_blocknr = move_generic_block(fs, block, bnd, h);
if (new_blocknr) {
if (node_is_internal)
@@ -170,40 +185,38 @@ static unsigned long move_formatted_block(reiserfs_filsys_t * fs, unsigned long
else
leaf_moved_cnt++;
}
return new_blocknr;
}
int shrink_fs(reiserfs_filsys_t * fs, long long int blocks)
int shrink_fs(reiserfs_filsys_t *fs, long long int blocks)
{
unsigned long n_root_block;
unsigned int bmap_nr_new;
unsigned long bad_count;
ondisk_sb = fs->fs_ondisk_sb;
bmap_nr_new = (blocks - 1) / (8 * fs->fs_blocksize) + 1;
/* is shrinking possible ? */
if (get_sb_block_count(ondisk_sb) - blocks >
get_sb_free_blocks(ondisk_sb) + reiserfs_fs_bmap_nr(fs) - bmap_nr_new)
{
fprintf(stderr, "resize_reiserfs: can\'t shrink fs; too many "
"blocks already allocated\n");
return -1;
if (get_sb_block_count(ondisk_sb) - blocks >
get_sb_free_blocks(ondisk_sb) + reiserfs_fs_bmap_nr(fs) -
bmap_nr_new) {
fprintf(stderr,
"resize_reiserfs: can\'t shrink fs; too many "
"blocks already allocated\n");
return -1;
}
/* warn about alpha version */
{
int c;
printf(
"You are running BETA version of reiserfs shrinker.\n"
"This version is only for testing or VERY CAREFUL use.\n"
"Backup of you data is recommended.\n\n"
"Do you want to continue? [y/N]:"
);
printf("You are running BETA version of reiserfs shrinker.\n"
"This version is only for testing or VERY CAREFUL use.\n"
"Backup of you data is recommended.\n\n"
"Do you want to continue? [y/N]:");
fflush(stdout);
c = getchar();
if (c != 'y' && c != 'Y')
@@ -211,24 +224,22 @@ int shrink_fs(reiserfs_filsys_t * fs, long long int blocks)
}
reiserfs_reopen(fs, O_RDWR);
if (reiserfs_open_ondisk_bitmap (fs))
reiserfs_exit(1, "cannot open ondisk bitmap");
if (reiserfs_open_ondisk_bitmap(fs))
reiserfs_exit(1, "cannot open ondisk bitmap");
bmp = fs->fs_bitmap2;
ondisk_sb = fs->fs_ondisk_sb;
set_sb_fs_state (fs->fs_ondisk_sb, FS_ERROR);
set_sb_fs_state(fs->fs_ondisk_sb, FS_ERROR);
mark_buffer_uptodate(fs->fs_super_bh, 1);
mark_buffer_dirty(fs->fs_super_bh);
bwrite(fs->fs_super_bh);
/* calculate number of data blocks */
blocks_used =
get_sb_block_count(fs->fs_ondisk_sb)
/* calculate number of data blocks */
blocks_used = get_sb_block_count(fs->fs_ondisk_sb)
- get_sb_free_blocks(fs->fs_ondisk_sb)
- reiserfs_fs_bmap_nr(fs)
- get_jp_journal_size(sb_jp (fs->fs_ondisk_sb))
- REISERFS_DISK_OFFSET_IN_BYTES / fs->fs_blocksize
- 2; /* superblock itself and 1 descriptor after the journal */
- get_jp_journal_size(sb_jp(fs->fs_ondisk_sb))
- REISERFS_DISK_OFFSET_IN_BYTES / fs->fs_blocksize - 2; /* superblock itself and 1 descriptor after the journal */
unused_block = 1;
@@ -237,64 +248,64 @@ int shrink_fs(reiserfs_filsys_t * fs, long long int blocks)
fflush(stdout);
}
n_root_block = move_formatted_block(fs, get_sb_root_block(ondisk_sb),
blocks, 0);
n_root_block = move_formatted_block(fs, get_sb_root_block(ondisk_sb),
blocks, 0);
if (n_root_block)
set_sb_root_block (ondisk_sb, n_root_block);
set_sb_root_block(ondisk_sb, n_root_block);
if (opt_verbose)
printf ("\n\nnodes processed (moved):\n"
"int %lu (%lu),\n"
"leaves %lu (%lu),\n"
"unfm %lu (%lu),\n"
"total %lu (%lu).\n\n",
int_node_cnt, int_moved_cnt,
leaf_node_cnt, leaf_moved_cnt,
unfm_node_cnt, unfm_moved_cnt,
(unsigned long)total_node_cnt, total_moved_cnt);
printf("\n\nnodes processed (moved):\n"
"int %lu (%lu),\n"
"leaves %lu (%lu),\n"
"unfm %lu (%lu),\n"
"total %lu (%lu).\n\n",
int_node_cnt, int_moved_cnt,
leaf_node_cnt, leaf_moved_cnt,
unfm_node_cnt, unfm_moved_cnt,
(unsigned long)total_node_cnt, total_moved_cnt);
if (block_count_mismatch) {
fprintf(stderr, "resize_reiserfs: data block count %lu"
" doesn\'t match data block count %lu from super block\n",
(unsigned long)total_node_cnt, blocks_used);
fprintf(stderr, "resize_reiserfs: data block count %lu"
" doesn\'t match data block count %lu from super block\n",
(unsigned long)total_node_cnt, blocks_used);
}
{
unsigned long l;
unsigned long l;
/* make sure that none of truncated block are in use */
printf("check for used blocks in truncated region\n");
for (l = blocks; l < fs->fs_bitmap2->bm_bit_size; l ++) {
if ((l % (fs->fs_blocksize * 8)) == 0)
continue;
if (reiserfs_bitmap_test_bit (fs->fs_bitmap2, l))
printf ("<%lu>", l);
}
printf("\n");
/* make sure that none of truncated block are in use */
printf("check for used blocks in truncated region\n");
for (l = blocks; l < fs->fs_bitmap2->bm_bit_size; l++) {
if ((l % (fs->fs_blocksize * 8)) == 0)
continue;
if (reiserfs_bitmap_test_bit(fs->fs_bitmap2, l))
printf("<%lu>", l);
}
printf("\n");
}
badblock_list(fs, mark_badblock, NULL);
if (fs->fs_badblocks_bm) {
bad_count = reiserfs_bitmap_ones(fs->fs_badblocks_bm);
reiserfs_shrink_bitmap (fs->fs_badblocks_bm, blocks);
reiserfs_shrink_bitmap(fs->fs_badblocks_bm, blocks);
add_badblock_list(fs, 1);
bad_count -= reiserfs_bitmap_ones(fs->fs_badblocks_bm);
} else
bad_count = 0;
reiserfs_shrink_bitmap (fs->fs_bitmap2, blocks);
set_sb_free_blocks (ondisk_sb, get_sb_free_blocks(ondisk_sb)
- (get_sb_block_count(ondisk_sb) - blocks)
+ (reiserfs_fs_bmap_nr(fs) - bmap_nr_new)
+ bad_count);
set_sb_block_count (ondisk_sb, blocks);
set_sb_bmap_nr (ondisk_sb, bmap_nr_new);
reiserfs_shrink_bitmap(fs->fs_bitmap2, blocks);
set_sb_bmap_nr (fs->fs_ondisk_sb,
reiserfs_bmap_over(bmap_nr_new) ? 0 : bmap_nr_new);
set_sb_free_blocks(ondisk_sb, get_sb_free_blocks(ondisk_sb)
- (get_sb_block_count(ondisk_sb) - blocks)
+ (reiserfs_fs_bmap_nr(fs) - bmap_nr_new)
+ bad_count);
set_sb_block_count(ondisk_sb, blocks);
set_sb_bmap_nr(ondisk_sb, bmap_nr_new);
set_sb_bmap_nr(fs->fs_ondisk_sb,
reiserfs_bmap_over(bmap_nr_new) ? 0 : bmap_nr_new);
return 0;
}
+7 -9
View File
@@ -6,23 +6,21 @@
#include "resize.h"
/* the front-end for kernel on-line resizer */
int resize_fs_online(char * devname, long long int blocks) {
int resize_fs_online(char *devname, long long int blocks)
{
struct mntent *mnt;
char buf[40];
/* Find the mount entry. */
if ((mnt = misc_mntent(devname)) == NULL)
die ("resize_reiserfs: can't find mount entry\n");
die("resize_reiserfs: can't find mount entry\n");
sprintf(buf,"resize=%lld", blocks);
sprintf(buf, "resize=%lld", blocks);
if (mount(mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type,
(unsigned long)(MS_MGC_VAL << 16 | MS_REMOUNT), buf))
{
die ("resize_reiserfs: remount failed: %s\n",
strerror(errno));
(unsigned long)(MS_MGC_VAL << 16 | MS_REMOUNT), buf)) {
die("resize_reiserfs: remount failed: %s\n", strerror(errno));
}
return 0;
}
+3 -3
View File
@@ -32,8 +32,8 @@
#define DIE(form, args...) die("%s: " form "\n", g_progname , ## args)
/* reiserfs_resize.c */
extern struct buffer_head * g_sb_bh;
extern char * g_progname;
extern struct buffer_head *g_sb_bh;
extern char *g_progname;
extern int opt_force;
extern int opt_verbose;
@@ -41,7 +41,7 @@ extern int opt_nowrite;
extern int opt_safe;
/* fe.c */
extern int resize_fs_online(char * devname, long long int blocks);
extern int resize_fs_online(char *devname, long long int blocks);
/* do_shrink.c */
extern int shrink_fs(reiserfs_filsys_t *, long long int blocks);
+275 -267
View File
@@ -17,334 +17,342 @@
int opt_banner = 0;
int opt_force = 0;
int opt_verbose = 1; /* now "verbose" option is default */
int opt_verbose = 1; /* now "verbose" option is default */
int opt_nowrite = 0;
int opt_safe = 0;
int opt_skipj = 0;
char * g_progname;
char *g_progname;
/* calculate the new fs size (in blocks) from old fs size and the string
representation of new size */
static long long int calc_new_fs_size(unsigned long count,
unsigned int bs,
char *bytes_str)
static long long int calc_new_fs_size(unsigned long count,
unsigned int bs, char *bytes_str)
{
long long int bytes;
long long int blocks;
char *end;
int rel;
long long int bytes;
long long int blocks;
char *end;
int rel;
end = bytes_str + strlen(bytes_str) - 1;
rel = bytes_str[0] == '+' || bytes_str[0] == '-';
bytes = strtoll(bytes_str, &bytes_str, 10);
/* Some error occured while convertion or the specified
string is not valid. */
if (bytes == LONG_LONG_MIN || bytes == LONG_LONG_MAX ||
(bytes_str != end && bytes_str != end + 1))
return -EINVAL;
end = bytes_str + strlen(bytes_str) - 1;
rel = bytes_str[0] == '+' || bytes_str[0] == '-';
bytes = strtoll(bytes_str, &bytes_str, 10);
switch (*end) {
case 'G':
case 'g':
bytes *= 1024;
case 'M':
case 'm':
bytes *= 1024;
case 'K':
case 'k':
bytes *= 1024;
}
blocks = bytes / bs;
/* Some error occured while convertion or the specified
string is not valid. */
if (bytes == LONG_LONG_MIN || bytes == LONG_LONG_MAX ||
(bytes_str != end && bytes_str != end + 1))
return -EINVAL;
return rel ? count + blocks : blocks;
switch (*end) {
case 'G':
case 'g':
bytes *= 1024;
case 'M':
case 'm':
bytes *= 1024;
case 'K':
case 'k':
bytes *= 1024;
}
blocks = bytes / bs;
return rel ? count + blocks : blocks;
}
/* print some fs parameters */
static void sb_report(struct reiserfs_super_block * sb1,
struct reiserfs_super_block * sb2)
static void sb_report(struct reiserfs_super_block *sb1,
struct reiserfs_super_block *sb2)
{
printf(
"ReiserFS report:\n"
"blocksize %u\n"
"block count %u (%u)\n"
"free blocks %u (%u)\n"
"bitmap block count %u (%u)\n",
get_sb_block_size(sb1),
get_sb_block_count(sb1), get_sb_block_count(sb2),
get_sb_free_blocks(sb1), get_sb_free_blocks(sb2),
get_sb_bmap_nr(sb1), get_sb_bmap_nr(sb2));
printf("ReiserFS report:\n"
"blocksize %u\n"
"block count %u (%u)\n"
"free blocks %u (%u)\n"
"bitmap block count %u (%u)\n",
get_sb_block_size(sb1),
get_sb_block_count(sb1), get_sb_block_count(sb2),
get_sb_free_blocks(sb1), get_sb_free_blocks(sb2),
get_sb_bmap_nr(sb1), get_sb_bmap_nr(sb2));
};
/* conditional bwrite */
static int bwrite_cond (struct buffer_head * bh)
static int bwrite_cond(struct buffer_head *bh)
{
if(!opt_nowrite) {
mark_buffer_uptodate(bh,1);
mark_buffer_dirty(bh);
bwrite(bh);
}
return 0;
if (!opt_nowrite) {
mark_buffer_uptodate(bh, 1);
mark_buffer_dirty(bh);
bwrite(bh);
}
return 0;
}
/* the first one of the most important functions */
static int expand_fs (reiserfs_filsys_t * fs, long long int block_count_new) {
unsigned int bmap_nr_new, bmap_nr_old;
struct reiserfs_super_block * sb;
unsigned int i;
static int expand_fs(reiserfs_filsys_t *fs, long long int block_count_new)
{
unsigned int bmap_nr_new, bmap_nr_old;
struct reiserfs_super_block *sb;
unsigned int i;
reiserfs_reopen(fs, O_RDWR);
if (reiserfs_open_ondisk_bitmap(fs))
reiserfs_exit(1, "cannot open ondisk bitmap");
reiserfs_reopen(fs, O_RDWR);
if (reiserfs_open_ondisk_bitmap (fs))
reiserfs_exit(1, "cannot open ondisk bitmap");
sb = fs->fs_ondisk_sb;
sb = fs->fs_ondisk_sb;
set_sb_fs_state(fs->fs_ondisk_sb, FS_ERROR);
set_sb_fs_state (fs->fs_ondisk_sb, FS_ERROR);
bwrite_cond(fs->fs_super_bh);
bwrite_cond(fs->fs_super_bh);
if (reiserfs_expand_bitmap(fs->fs_bitmap2, block_count_new))
reiserfs_exit(1, "cannot expand bitmap\n");
/* count bitmap blocks in new fs */
bmap_nr_new = (block_count_new - 1) / (fs->fs_blocksize * 8) + 1;
bmap_nr_old = reiserfs_fs_bmap_nr(fs);
if (reiserfs_expand_bitmap(fs->fs_bitmap2, block_count_new))
reiserfs_exit(1, "cannot expand bitmap\n");
/* update super block buffer */
set_sb_free_blocks(sb, get_sb_free_blocks(sb) +
(block_count_new - get_sb_block_count(sb)) -
(bmap_nr_new - bmap_nr_old));
set_sb_block_count(sb, block_count_new);
set_sb_bmap_nr(fs->fs_ondisk_sb,
reiserfs_bmap_over(bmap_nr_new) ? 0 : bmap_nr_new);
/* count bitmap blocks in new fs */
bmap_nr_new = (block_count_new - 1) / (fs->fs_blocksize * 8) + 1;
bmap_nr_old = reiserfs_fs_bmap_nr(fs);
/* update super block buffer*/
set_sb_free_blocks (sb, get_sb_free_blocks(sb) +
(block_count_new - get_sb_block_count(sb)) -
(bmap_nr_new - bmap_nr_old));
set_sb_block_count (sb, block_count_new);
/* mark new bitmap blocks as used */
for (i = bmap_nr_old; i < bmap_nr_new; i++)
reiserfs_bitmap_set_bit(fs->fs_bitmap2,
i * fs->fs_blocksize * 8);
set_sb_bmap_nr (fs->fs_ondisk_sb,
reiserfs_bmap_over(bmap_nr_new) ? 0 : bmap_nr_new);
/* normally, this is done by reiserfs_bitmap_set_bit, but if we
** haven't actually added any bitmap blocks, the bitmap won't be dirtied.
**
** In memory, reiserfsprogs puts zeros for the bits past the end of
** the old filesystem. But, on disk that bitmap is full of ones.
** we explicitly dirty the bitmap here to make sure the zeros get written
** to disk
*/
fs->fs_bitmap2->bm_dirty = 1;
/* mark new bitmap blocks as used */
for (i = bmap_nr_old; i < bmap_nr_new; i++)
reiserfs_bitmap_set_bit (fs->fs_bitmap2, i * fs->fs_blocksize * 8);
/* normally, this is done by reiserfs_bitmap_set_bit, but if we
** haven't actually added any bitmap blocks, the bitmap won't be dirtied.
**
** In memory, reiserfsprogs puts zeros for the bits past the end of
** the old filesystem. But, on disk that bitmap is full of ones.
** we explicitly dirty the bitmap here to make sure the zeros get written
** to disk
*/
fs->fs_bitmap2->bm_dirty = 1 ;
return 0;
return 0;
}
static int resizer_check_fs_size(reiserfs_filsys_t *fs, long long int new_size) {
if (new_size < 0) {
reiserfs_warning(stderr, "\nresizer_reiserfs: the new size "
"value is wrong.\n\n");
return new_size;
}
if (new_size == get_sb_block_count(fs->fs_ondisk_sb)) {
reiserfs_warning (stderr, "%s already is of the needed size. "
"Nothing to be done\n\n", fs->fs_file_name);
return 1;
}
if (new_size < get_sb_block_count(fs->fs_ondisk_sb)) {
if (misc_device_mounted(fs->fs_file_name) > 0) {
reiserfs_warning (stderr, "Can't shrink filesystem on-line.\n\n");
return 1;
static int resizer_check_fs_size(reiserfs_filsys_t *fs, long long int new_size)
{
if (new_size < 0) {
reiserfs_warning(stderr, "\nresizer_reiserfs: the new size "
"value is wrong.\n\n");
return new_size;
}
}
if (new_size >= get_sb_block_count(fs->fs_ondisk_sb)) {
loff_t offset = (loff_t)new_size * fs->fs_blocksize - 1;
if(!valid_offset(fs->fs_dev, offset)) {
reiserfs_warning (stderr, "%s is of %lu blocks size only with "
"reiserfs of %u blocks\nsize on it. You are "
"trying to expand reiserfs up to %lu blocks "
"size.\nYou probably forgot to expand your "
"partition size.\n\n", fs->fs_file_name,
count_blocks(fs->fs_file_name, fs->fs_blocksize),
get_sb_block_count(fs->fs_ondisk_sb), new_size);
return 1;
if (new_size == get_sb_block_count(fs->fs_ondisk_sb)) {
reiserfs_warning(stderr, "%s already is of the needed size. "
"Nothing to be done\n\n", fs->fs_file_name);
return 1;
}
}
return 0;
if (new_size < get_sb_block_count(fs->fs_ondisk_sb)) {
if (misc_device_mounted(fs->fs_file_name) > 0) {
reiserfs_warning(stderr,
"Can't shrink filesystem on-line.\n\n");
return 1;
}
}
if (new_size >= get_sb_block_count(fs->fs_ondisk_sb)) {
loff_t offset = (loff_t) new_size * fs->fs_blocksize - 1;
if (!valid_offset(fs->fs_dev, offset)) {
reiserfs_warning(stderr,
"%s is of %lu blocks size only with "
"reiserfs of %u blocks\nsize on it. You are "
"trying to expand reiserfs up to %lu blocks "
"size.\nYou probably forgot to expand your "
"partition size.\n\n",
fs->fs_file_name,
count_blocks(fs->fs_file_name,
fs->fs_blocksize),
get_sb_block_count(fs->fs_ondisk_sb),
new_size);
return 1;
}
}
return 0;
}
int main(int argc, char *argv[]) {
char * bytes_count_str = NULL;
char * devname;
char * jdevice_name = NULL;
reiserfs_filsys_t * fs;
struct reiserfs_super_block * sb;
int main(int argc, char *argv[])
{
char *bytes_count_str = NULL;
char *devname;
char *jdevice_name = NULL;
reiserfs_filsys_t *fs;
struct reiserfs_super_block *sb;
int c;
int error;
int c;
int error;
struct reiserfs_super_block *sb_old;
struct reiserfs_super_block *sb_old;
long long int block_count_new;
long long int block_count_new;
g_progname = basename(argv[0]);
if (argc < 2)
print_usage_and_exit();
while ((c = getopt(argc, argv, "fvcqks:j:V")) != EOF) {
switch (c) {
case 's' :
if (!optarg)
reiserfs_exit(1, "Missing argument to -s option");
bytes_count_str = optarg;
break;
case 'j' :
if (!optarg)
reiserfs_exit(1, "Missing argument to -j option");
jdevice_name = optarg;
case 'f':
opt_force = 1;
break;
case 'v':
opt_verbose++;
break;
case 'n':
/* no nowrite option at this moment */
/* opt_nowrite = 1; */
break;
case 'c':
opt_safe = 1;
break;
case 'q':
opt_verbose = 0;
break;
case 'k':
opt_skipj = 1;
break;
case 'V':
opt_banner++;
break;
default:
print_usage_and_exit ();
g_progname = basename(argv[0]);
if (argc < 2)
print_usage_and_exit();
while ((c = getopt(argc, argv, "fvcqks:j:V")) != EOF) {
switch (c) {
case 's':
if (!optarg)
reiserfs_exit(1,
"Missing argument to -s option");
bytes_count_str = optarg;
break;
case 'j':
if (!optarg)
reiserfs_exit(1,
"Missing argument to -j option");
jdevice_name = optarg;
case 'f':
opt_force = 1;
break;
case 'v':
opt_verbose++;
break;
case 'n':
/* no nowrite option at this moment */
/* opt_nowrite = 1; */
break;
case 'c':
opt_safe = 1;
break;
case 'q':
opt_verbose = 0;
break;
case 'k':
opt_skipj = 1;
break;
case 'V':
opt_banner++;
break;
default:
print_usage_and_exit();
}
}
}
print_banner (g_progname);
if (opt_banner)
exit(0);
print_banner(g_progname);
devname = argv[optind];
if (opt_banner)
exit(0);
fs = reiserfs_open(devname, O_RDONLY, &error, 0, 1);
if (!fs) {
if (error) {
reiserfs_exit(1, "cannot open '%s': %s",
devname, strerror(error));
} else {
exit(1);
devname = argv[optind];
fs = reiserfs_open(devname, O_RDONLY, &error, 0, 1);
if (!fs) {
if (error) {
reiserfs_exit(1, "cannot open '%s': %s",
devname, strerror(error));
} else {
exit(1);
}
}
}
if (reiserfs_open_journal (fs, jdevice_name, O_RDWR | O_LARGEFILE)) {
reiserfs_exit(1, "Failed to open the journal device (%s).",
jdevice_name);
}
if (reiserfs_journal_params_check(fs)) {
if (!opt_skipj) {
reiserfs_exit(1, "Wrong journal parameters detected on (%s)",
jdevice_name);
} else {
reiserfs_close_journal(fs);
if (reiserfs_open_journal(fs, jdevice_name, O_RDWR | O_LARGEFILE)) {
reiserfs_exit(1, "Failed to open the journal device (%s).",
jdevice_name);
}
}
/* forced to continue without journal available/specified */
if (reiserfs_journal_params_check(fs)) {
if (!opt_skipj) {
reiserfs_exit(1,
"Wrong journal parameters detected on (%s)",
jdevice_name);
} else {
reiserfs_close_journal(fs);
}
}
if (no_reiserfs_found (fs)) {
reiserfs_exit(1, "no reiserfs found on the device.");
}
if (!spread_bitmaps (fs)) {
reiserfs_exit(1, "cannot resize reiserfs in old (not spread "
"bitmap) format.");
}
/* forced to continue without journal available/specified */
sb = fs->fs_ondisk_sb;
if (no_reiserfs_found(fs)) {
reiserfs_exit(1, "no reiserfs found on the device.");
}
/* If size change was specified by user, calculate it,
otherwise take the whole device. */
block_count_new = bytes_count_str ?
calc_new_fs_size(get_sb_block_count(sb),
if (!spread_bitmaps(fs)) {
reiserfs_exit(1, "cannot resize reiserfs in old (not spread "
"bitmap) format.");
}
sb = fs->fs_ondisk_sb;
/* If size change was specified by user, calculate it,
otherwise take the whole device. */
block_count_new = bytes_count_str ?
calc_new_fs_size(get_sb_block_count(sb),
fs->fs_blocksize, bytes_count_str) :
count_blocks(devname, fs->fs_blocksize);
if (resizer_check_fs_size(fs, block_count_new))
return 1;
if (resizer_check_fs_size(fs, block_count_new))
return 1;
if (misc_device_mounted(devname) > 0) {
if (misc_device_mounted(devname) > 0) {
reiserfs_close(fs);
error = resize_fs_online(devname, block_count_new);
reiserfs_warning(stderr,
"\n\nresize_reiserfs: On-line resizing %s.\n\n",
error ? "failed" : "finished successfully");
return error;
}
if (!reiserfs_is_fs_consistent(fs)) {
reiserfs_warning(stderr,
"\n\nresize_reiserfs: run reiserfsck --check "
"first\n\n");
reiserfs_close(fs);
return 1;
}
if (get_sb_umount_state(sb) != FS_CLEANLY_UMOUNTED)
/* fixme: shouldn't we check for something like: fsck guarantees: fs is ok */
reiserfs_exit(1, "the file system isn't in valid state.");
/* Needed to keep idiot compiler from issuing false warning */
sb_old = 0;
/* save SB for reporting */
if (opt_verbose) {
sb_old = getmem(SB_SIZE);
memcpy(sb_old, fs->fs_ondisk_sb, SB_SIZE);
}
error = (block_count_new > get_sb_block_count(fs->fs_ondisk_sb)) ?
expand_fs(fs, block_count_new) : shrink_fs(fs, block_count_new);
if (error) {
reiserfs_warning(stderr,
"\n\nresize_reiserfs: Resizing failed.\n\n ");
return error;
}
if (opt_verbose) {
sb_report(fs->fs_ondisk_sb, sb_old);
freemem(sb_old);
}
set_sb_fs_state(fs->fs_ondisk_sb, FS_CONSISTENT);
bwrite_cond(fs->fs_super_bh);
if (opt_verbose) {
printf("\nSyncing..");
fflush(stdout);
}
reiserfs_close(fs);
error = resize_fs_online(devname, block_count_new);
reiserfs_warning(stderr, "\n\nresize_reiserfs: On-line resizing %s.\n\n",
error ? "failed" : "finished successfully");
return error;
}
if (opt_verbose)
printf("done\n");
if (!reiserfs_is_fs_consistent (fs)) {
reiserfs_warning (stderr, "\n\nresize_reiserfs: run reiserfsck --check "
"first\n\n");
reiserfs_close (fs);
return 1;
}
reiserfs_warning(stderr, "\n\nresize_reiserfs: Resizing finished "
"successfully.\n\n ");
if (get_sb_umount_state(sb) != FS_CLEANLY_UMOUNTED)
/* fixme: shouldn't we check for something like: fsck guarantees: fs is ok */
reiserfs_exit(1, "the file system isn't in valid state.");
/* Needed to keep idiot compiler from issuing false warning */
sb_old = 0;
/* save SB for reporting */
if(opt_verbose) {
sb_old = getmem(SB_SIZE);
memcpy(sb_old, fs->fs_ondisk_sb, SB_SIZE);
}
error = (block_count_new > get_sb_block_count(fs->fs_ondisk_sb)) ?
expand_fs(fs, block_count_new) : shrink_fs(fs, block_count_new);
if (error) {
reiserfs_warning(stderr, "\n\nresize_reiserfs: Resizing failed.\n\n ");
return error;
}
if(opt_verbose) {
sb_report(fs->fs_ondisk_sb, sb_old);
freemem(sb_old);
}
set_sb_fs_state (fs->fs_ondisk_sb, FS_CONSISTENT);
bwrite_cond(fs->fs_super_bh);
if (opt_verbose) {
printf("\nSyncing..");
fflush(stdout);
}
reiserfs_close (fs);
if (opt_verbose)
printf("done\n");
reiserfs_warning(stderr, "\n\nresize_reiserfs: Resizing finished "
"successfully.\n\n ");
return 0;
return 0;
}
+703 -647
View File
File diff suppressed because it is too large. Load diff