Imported reiserfsprogs-3.6.2

This commit is contained in:
Jeff Mahoney committed 2012-10-11 11:27:42 -04:00
1 parent e7102bdb66
commit b69459eb80
86 files changed
+23136 -13423

No files matched your search

+1 -2
View File
@@ -4,6 +4,5 @@ resize_reiserfs_SOURCES = fe.c resize_reiserfs.c do_shrink.c resize.h
man_MANS = resize_reiserfs.8
EXTRA_DIST = $(man_MANS)
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
INCLUDES = -I../include
+16 -14
View File
@@ -1,6 +1,6 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -62,6 +62,7 @@ MAKEINFO = @MAKEINFO@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
VERSION = @VERSION@
sbindir = @sbindir@
sbin_PROGRAMS = resize_reiserfs
@@ -69,22 +70,21 @@ resize_reiserfs_SOURCES = fe.c resize_reiserfs.c do_shrink.c resize.h
man_MANS = resize_reiserfs.8
EXTRA_DIST = $(man_MANS)
LDADD = ../lib/libmisc.a ../reiserfscore/libcore.a
INCLUDES = -I../include
LDADD = $(top_srcdir)/lib/libmisc.a $(top_srcdir)/reiserfscore/libcore.a
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../include/config.h
CONFIG_CLEAN_FILES =
PROGRAMS = $(sbin_PROGRAMS)
DEFS = @DEFS@ -I. -I$(srcdir)
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
resize_reiserfs_OBJECTS = fe.o resize_reiserfs.o do_shrink.o
resize_reiserfs_LDADD = $(LDADD)
resize_reiserfs_DEPENDENCIES = ../lib/libmisc.a \
../reiserfscore/libcore.a
resize_reiserfs_DEPENDENCIES = $(top_srcdir)/lib/libmisc.a \
$(top_srcdir)/reiserfscore/libcore.a
resize_reiserfs_LDFLAGS =
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -239,7 +239,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
@@ -247,12 +247,14 @@ distdir: $(DISTFILES)
fi; \
done
do_shrink.o: do_shrink.c resize.h ../include/io.h ../include/misc.h \
../include/reiserfs_lib.h ../include/reiserfs_fs.h ../version.h
fe.o: fe.c resize.h ../include/io.h ../include/misc.h \
../include/reiserfs_lib.h ../include/reiserfs_fs.h ../version.h
../include/swab.h ../include/reiserfs_lib.h \
../include/reiserfs_fs.h ../include/config.h ../version.h
fe.o: fe.c resize.h ../include/io.h ../include/misc.h ../include/swab.h \
../include/reiserfs_lib.h ../include/reiserfs_fs.h \
../include/config.h ../version.h
resize_reiserfs.o: resize_reiserfs.c resize.h ../include/io.h \
../include/misc.h ../include/reiserfs_lib.h \
../include/reiserfs_fs.h ../version.h
../include/misc.h ../include/swab.h ../include/reiserfs_lib.h \
../include/reiserfs_fs.h ../include/config.h ../version.h
info-am:
info: info-am
+68 -69
View File
@@ -1,8 +1,8 @@
/*
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
*/
#include <time.h>
#include "resize.h"
#include <time.h>
static unsigned long int_node_cnt = 0, int_moved_cnt = 0;
@@ -15,33 +15,31 @@ static unsigned long unused_block;
static unsigned long blocks_used;
static int block_count_mismatch = 0;
static reiserfs_bitmap_t bmp;
static reiserfs_filsys_t fs;
static struct reiserfs_super_block * rs;
static reiserfs_bitmap_t * bmp;
static struct reiserfs_super_block * ondisk_sb;
/* abnornal exit from block reallocation process */
static void quit_resizer()
static void quit_resizer(reiserfs_filsys_t * fs)
{
/* save changes to bitmap blocks */
reiserfs_flush_bitmap (bmp, fs);
reiserfs_close (fs);
/* leave fs in ERROR state */
die ("resize_reiserfs: fs shrinking was not completed successfully, run reiserfsck.\n");
DIE ("fs shrinking was not completed successfully, run reiserfsck.");
}
/* block moving */
static unsigned long move_generic_block(unsigned long block, unsigned long bnd, int h)
static unsigned long move_generic_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h)
{
struct buffer_head * bh, * bh2;
/* primitive fsck */
if (block > rs_block_count(rs)) {
if (block > get_sb_block_count(ondisk_sb)) {
fprintf(stderr, "resize_reiserfs: invalid block number (%lu) found.\n", block);
quit_resizer();
quit_resizer(fs);
}
/* progress bar, 3D style :) */
if (opt_verbose)
print_how_far(&total_node_cnt, blocks_used, 1, 0);
print_how_far(stderr, &total_node_cnt, blocks_used, 1, 0);
else
total_node_cnt ++;
@@ -55,16 +53,16 @@ static unsigned long move_generic_block(unsigned long block, unsigned long bnd,
return 0;
/* move wrong block */
bh = bread(fs->s_dev, block, fs->s_blocksize);
bh = bread(fs->fs_dev, block, fs->fs_blocksize);
reiserfs_bitmap_find_zero_bit(bmp, &unused_block);
if (unused_block == 0 || unused_block >= bnd) {
fputs ("resize_reiserfs: can\'t find free block\n", stderr);
quit_resizer();
quit_resizer(fs);
}
/* blocknr changing */
bh2 = getblk(fs->s_dev, unused_block, fs->s_blocksize);
bh2 = getblk(fs->fs_dev, unused_block, fs->fs_blocksize);
memcpy(bh2->b_data, bh->b_data, bh2->b_size);
reiserfs_bitmap_clear_bit(bmp, block);
reiserfs_bitmap_set_bit(bmp, unused_block);
@@ -79,11 +77,11 @@ static unsigned long move_generic_block(unsigned long block, unsigned long bnd,
return unused_block;
}
static unsigned long move_unformatted_block(unsigned long block, unsigned long bnd, int h)
static unsigned long move_unformatted_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h)
{
unsigned long b;
unfm_node_cnt++;
b = move_generic_block(block, bnd, h);
b = move_generic_block(fs, block, bnd, h);
if (b)
unfm_moved_cnt++;
return b;
@@ -91,7 +89,7 @@ static unsigned long move_unformatted_block(unsigned long block, unsigned long b
/* recursive function processing all tree nodes */
static unsigned long move_formatted_block(unsigned long block, unsigned long bnd, int h)
static unsigned long move_formatted_block(reiserfs_filsys_t * fs, unsigned long block, unsigned long bnd, int h)
{
struct buffer_head * bh;
struct item_head *ih;
@@ -99,7 +97,9 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
int node_is_internal = 0;
int i, j;
bh = bread(fs->s_dev, block, fs->s_blocksize);
bh = bread(fs->fs_dev, block, fs->fs_blocksize);
if (!bh)
reiserfs_panic ("move_formatted_block: bread failed");
if (is_leaf_node (bh)) {
@@ -116,7 +116,7 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
if (indirect [j] == 0) /* hole */
continue;
unfm_block = move_unformatted_block(le32_to_cpu (indirect [j]), bnd, h + 1);
unfm_block = move_unformatted_block(fs, le32_to_cpu (indirect [j]), bnd, h + 1);
if (unfm_block) {
indirect [j] = cpu_to_le32 (unfm_block);
mark_buffer_dirty(bh);
@@ -131,14 +131,14 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
for (i=0; i <= B_NR_ITEMS(bh); i++) {
unsigned long moved_block;
moved_block = move_formatted_block(B_N_CHILD_NUM(bh, i), bnd, h+1);
moved_block = move_formatted_block(fs, get_dc_child_blocknr (B_N_CHILD (bh, i)), bnd, h+1);
if (moved_block) {
set_dc_block_number (bh, i, moved_block);
set_dc_child_blocknr (B_N_CHILD (bh, i), moved_block);
mark_buffer_dirty(bh);
}
}
} else {
die ("resize_reiserfs: block (%lu) has invalid format\n", block);
DIE ("block (%lu) has invalid format\n", block);
}
if (buffer_dirty(bh)) {
@@ -148,7 +148,7 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
brelse(bh);
new_blocknr = move_generic_block(block, bnd, h);
new_blocknr = move_generic_block(fs, block, bnd, h);
if (new_blocknr) {
if (node_is_internal)
int_moved_cnt++;
@@ -159,14 +159,13 @@ static unsigned long move_formatted_block(unsigned long block, unsigned long bnd
return new_blocknr;
}
int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
int shrink_fs(reiserfs_filsys_t * fs, unsigned long blocks)
{
unsigned long n_root_block;
unsigned int bmap_nr_new;
unsigned long int i;
fs = reiserfs;
rs = fs->s_rs;
ondisk_sb = fs->fs_ondisk_sb;
/* warn about alpha version */
{
@@ -178,37 +177,40 @@ int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
"Backup of you data is recommended.\n\n"
"Do you want to continue? [y/N]:"
);
fflush(stdout);
c = getchar();
if (c != 'y' && c != 'Y')
exit(1);
}
bmap_nr_new = (blocks - 1) / (8 * fs->s_blocksize) + 1;
bmap_nr_new = (blocks - 1) / (8 * fs->fs_blocksize) + 1;
/* is shrinking possible ? */
if (rs_block_count(rs) - blocks > rs_free_blocks(rs) + rs_bmap_nr(rs) - bmap_nr_new) {
if (get_sb_block_count(ondisk_sb) - blocks > get_sb_free_blocks(ondisk_sb) + get_sb_bmap_nr(ondisk_sb) - bmap_nr_new) {
fprintf(stderr, "resize_reiserfs: can\'t shrink fs; too many blocks already allocated\n");
return -1;
}
reiserfs_reopen(fs, O_RDWR);
set_state (fs->s_rs, REISERFS_ERROR_FS);
mark_buffer_uptodate(SB_BUFFER_WITH_SB(fs), 1);
mark_buffer_dirty(SB_BUFFER_WITH_SB(fs));
bwrite(SB_BUFFER_WITH_SB(fs));
if (!reiserfs_open_ondisk_bitmap (fs))
DIE("cannot open ondisk bitmap");
bmp = fs->fs_bitmap2;
ondisk_sb = fs->fs_ondisk_sb;
set_sb_fs_state (fs->fs_ondisk_sb, REISERFS_CORRUPTED);
mark_buffer_uptodate(fs->fs_super_bh, 1);
mark_buffer_dirty(fs->fs_super_bh);
bwrite(fs->fs_super_bh);
/* calculate number of data blocks */
blocks_used =
SB_BLOCK_COUNT(fs)
- SB_FREE_BLOCKS(fs)
- SB_BMAP_NR(fs)
- SB_JOURNAL_SIZE(fs)
- REISERFS_DISK_OFFSET_IN_BYTES / fs->s_blocksize
get_sb_block_count(fs->fs_ondisk_sb)
- get_sb_free_blocks(fs->fs_ondisk_sb)
- get_sb_bmap_nr(fs->fs_ondisk_sb)
- get_jp_journal_size(sb_jp (fs->fs_ondisk_sb))
- REISERFS_DISK_OFFSET_IN_BYTES / fs->fs_blocksize
- 2; /* superblock itself and 1 descriptor after the journal */
bmp = reiserfs_create_bitmap(rs_block_count(rs));
reiserfs_fetch_disk_bitmap(bmp, fs);
unused_block = 1;
if (opt_verbose) {
@@ -216,9 +218,9 @@ int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
fflush(stdout);
}
n_root_block = move_formatted_block(rs_root_block(rs), blocks, 0);
n_root_block = move_formatted_block(fs, get_sb_root_block(ondisk_sb), blocks, 0);
if (n_root_block) {
set_root_block (rs, n_root_block);
set_sb_root_block (ondisk_sb, n_root_block);
}
if (opt_verbose)
@@ -237,33 +239,30 @@ int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
" doesn\'t match data block count %lu from super block\n",
(unsigned long)total_node_cnt, blocks_used);
}
#if 0
printf("check for used blocks in truncated region\n");
#if 1
{
unsigned long l;
for (l = blocks; l < rs_block_count(rs); l++)
if (is_block_used(bmp, l))
printf("<%lu>", l);
printf("\n");
unsigned long l;
/* make sure that none of truncated block are in use */
printf("check for used blocks in truncated region\n");
for (l = blocks; l < fs->fs_bitmap2->bm_bit_size; l ++) {
if ((l % (fs->fs_blocksize * 8)) == 0)
continue;
if (reiserfs_bitmap_test_bit (fs->fs_bitmap2, l))
printf ("<%lu>", l);
}
printf("\n");
}
#endif /* 0 */
reiserfs_free_bitmap_blocks(fs);
set_free_blocks (rs, rs_free_blocks(rs) - (rs_block_count(rs) - blocks) + (rs_bmap_nr(rs) - bmap_nr_new));
set_block_count (rs, blocks);
set_bmap_nr (rs, bmap_nr_new);
reiserfs_read_bitmap_blocks(fs);
for (i = blocks; i < bmap_nr_new * fs->s_blocksize; i++)
reiserfs_bitmap_set_bit(bmp, i);
#if 0
PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (SB_BLOCK_COUNT(s) - blocks) + (SB_BMAP_NR(s) - bmap_nr_new));
PUT_SB_BLOCK_COUNT(s, blocks);
PUT_SB_BMAP_NR(s, bmap_nr_new);
#endif
reiserfs_flush_bitmap(bmp, fs);
reiserfs_shrink_bitmap (fs->fs_bitmap2, blocks);
set_sb_free_blocks (ondisk_sb, get_sb_free_blocks(ondisk_sb)
- (get_sb_block_count(ondisk_sb) - blocks)
+ (get_sb_bmap_nr(ondisk_sb) - bmap_nr_new));
set_sb_block_count (ondisk_sb, blocks);
set_sb_bmap_nr (ondisk_sb, bmap_nr_new);
return 0;
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
*/
#include "resize.h"
+10 -7
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
*/
#define _GNU_SOURCE
@@ -24,25 +24,28 @@
#include "io.h"
#include "misc.h"
#include "reiserfs_lib.h"
#include "../include/config.h"
#include "../version.h"
#define print_usage_and_exit()\
die ("Usage: %s [-s[+|-]#[G|M|K]] [-fqv] device", argv[0])
#define print_usage_and_exit() {\
fprintf (stderr, "Usage: %s [-s[+|-]#[G|M|K]] [-fqv] device\n\n", argv[0]);\
exit(16);\
}
#define DIE(form, args...) die("%s: " form "\n", g_progname , ## args)
/* reiserfs_resize.c */
extern struct buffer_head * g_sb_bh;
extern char * g_progname;
extern int opt_force;
extern int opt_verbose;
extern int opt_nowrite;
extern int opt_safe;
int expand_fs(struct super_block * s, unsigned long block_count_new);
/* fe.c */
int resize_fs_online(char * devname, unsigned long blocks);
/* do_shrink.c */
int shrink_fs(struct super_block * s, unsigned long blocks);
int shrink_fs(reiserfs_filsys_t *, unsigned long blocks);
+11 -4
View File
@@ -1,14 +1,17 @@
.\" -*- nroff -*-
.\" Copyright 1996-2001 Hans Reiser.
.\" Copyright 1996-2002 Hans Reiser.
.\"
.TH RESIZE_REISERFS 8 "March 2001" "Reiserfsprogs-3.x.0j"
.TH RESIZE_REISERFS 8 "January 2002" "Reiserfsprogs-3.6.2"
.SH NAME
resize_reiserfs \- Reiserfs filesystem resizer
.SH SYNOPSIS
.BR resize_reiserfs
[
.B \-s
.IR \fR[\fB+\fR|\fB\- ]\fIsize [\fBK\fR|\fBM\fR|\fBG\fR]
.IR \fR[\fB+\fR|\fB\- ]\fIsize\fB[\fBK\fR|\fBM\fR|\fBG\fR]
] [
.B \-j
.IR \fR\fIdev
] [
.B \-fqv
]
@@ -68,6 +71,9 @@ you do not make it smaller than the reduced size of the reiserfs filesystem.
.BR \-s\ [+|\-]\fIsize
Set the new size in bytes.
.TP
.BR \-j\ \fIdev
Set the journal device name.
.TP
.BR \-f
Force, do not perform checks.
.TP
@@ -112,5 +118,6 @@ has been written by Alexander Zarochentcev <zam@namesys.com>.
Please, report about the bugs to Alexander Zarochentcev <zam@namesys.com> or
to Hans Reiser <reiser@namesys.com>.
.SH SEE ALSO
.BR cfsck (8),
.BR cfdisk (8),
.BR reiserfsck (8),
.BR debugreiserfs (8)
+105 -88
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
* Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
*/
/*
@@ -10,29 +10,15 @@
*/
#include "resize.h"
#include <libgen.h>
int opt_force = 0;
int opt_verbose = 1; /* now "verbose" option is default */
int opt_nowrite = 0;
int opt_safe = 0;
int opt_skipj = 0;
#if 0
/* Given a file descriptor and an offset, check whether the offset is
a valid offset for the file - return 0 if it isn't valid or 1 if it
is */
int valid_offset( int fd, loff_t offset )
{
char ch;
if (lseek64 (fd, offset, 0) < 0)
return 0;
if (read (fd, &ch, 1) < 1)
return 0;
return 1;
}
#endif
char * g_progname;
/* calculate the new fs size (in blocks) from old fs size and the string
representation of new size */
@@ -76,10 +62,10 @@ static void sb_report(struct reiserfs_super_block * sb1,
"block count %d (%d)\n"
"free blocks %d (%d)\n"
"bitmap block count %d (%d)\n",
rs_blocksize(sb1),
rs_block_count(sb1), rs_block_count(sb2),
rs_free_blocks(sb1), rs_free_blocks(sb2),
rs_bmap_nr(sb1), rs_bmap_nr(sb2));
get_sb_block_size(sb1),
get_sb_block_count(sb1), get_sb_block_count(sb2),
get_sb_free_blocks(sb1), get_sb_free_blocks(sb2),
get_sb_bmap_nr(sb1), get_sb_bmap_nr(sb2));
};
/* conditional bwrite */
@@ -94,63 +80,64 @@ static int bwrite_cond (struct buffer_head * bh)
}
/* the first one of the mainest functions */
int expand_fs (reiserfs_filsys_t fs, unsigned long block_count_new) {
int block_r, block_r_new;
/* the first one of the most important functions */
static int expand_fs (reiserfs_filsys_t * fs, unsigned long block_count_new) {
unsigned int bmap_nr_new, bmap_nr_old;
int i;
struct reiserfs_super_block * sb;
reiserfs_bitmap_t bmp;
struct reiserfs_super_block * rs = fs->s_rs;
reiserfs_reopen(fs, O_RDWR);
set_state (fs->s_rs, REISERFS_ERROR_FS);
bwrite_cond(SB_BUFFER_WITH_SB(fs));
bmp = reiserfs_create_bitmap(rs_block_count(rs));
if (!bmp)
die ("cannot create bitmap\n");
reiserfs_fetch_disk_bitmap(bmp, fs);
reiserfs_free_bitmap_blocks(fs);
if (reiserfs_expand_bitmap(bmp, block_count_new))
die ("cannot expand bitmap\n");
if (!reiserfs_open_ondisk_bitmap (fs))
DIE("cannot open ondisk bitmap");
sb = fs->fs_ondisk_sb;
set_sb_fs_state (fs->fs_ondisk_sb, REISERFS_CORRUPTED);
bwrite_cond(fs->fs_super_bh);
if (reiserfs_expand_bitmap(fs->fs_bitmap2, block_count_new))
DIE("cannot expand bitmap\n");
/* clean bits in old bitmap tail */
for (i = rs_block_count(rs);
i < rs_bmap_nr(rs) * rs_blocksize(rs) * 8 && i < block_count_new;
i++) {
reiserfs_bitmap_clear_bit(bmp, i);
}
/* count used bits in last bitmap block */
block_r = rs_block_count(rs) - ((rs_bmap_nr(rs) - 1) * rs_blocksize(rs) * 8);
/* count bitmap blocks in new fs */
bmap_nr_new = (block_count_new - 1) / (rs_blocksize(rs) * 8) + 1;
block_r_new = block_count_new - (bmap_nr_new - 1) * rs_blocksize(rs) * 8;
bmap_nr_old = rs_bmap_nr(rs);
bmap_nr_new = (block_count_new - 1) / (fs->fs_blocksize * 8) + 1;
bmap_nr_old = get_sb_bmap_nr(sb);
/* update super block buffer*/
set_free_blocks (rs, rs_free_blocks(rs) + block_count_new
- rs_block_count(rs) - (bmap_nr_new - rs_bmap_nr(rs)));
set_block_count (rs, block_count_new);
set_bmap_nr (rs, bmap_nr_new);
set_sb_free_blocks (sb, get_sb_free_blocks(sb) +
(block_count_new - get_sb_block_count(sb)) -
(bmap_nr_new - bmap_nr_old));
set_sb_block_count (sb, block_count_new);
set_sb_bmap_nr (sb, bmap_nr_new);
reiserfs_read_bitmap_blocks(fs);
for (i = bmap_nr_old; i < bmap_nr_new; i++) /* fix new bitmap blocks */
reiserfs_bitmap_set_bit(bmp, SB_AP_BITMAP(fs)[i]->b_blocknr);
reiserfs_flush_bitmap(bmp, fs);
/* mark new bitmap blocks as used */
for (i = bmap_nr_old; i < bmap_nr_new; i++)
reiserfs_bitmap_set_bit (fs->fs_bitmap2, i * fs->fs_blocksize * 8);
/* normally, this is done by reiserfs_bitmap_set_bit, but if we
** haven't actually added any bitmap blocks, the bitmap won't be dirtied.
**
** In memory, reiserfsprogs puts zeros for the bits past the end of
** the old filesystem. But, on disk that bitmap is full of ones.
** we explicitly dirty the bitmap here to make sure the zeros get written
** to disk
*/
fs->fs_bitmap2->bm_dirty = 1 ;
return 0;
}
int main(int argc, char *argv[]) {
char * bytes_count_str = NULL;
char * devname;
reiserfs_filsys_t fs;
struct reiserfs_super_block * rs;
char * jdevice_name = NULL;
reiserfs_filsys_t * fs;
struct reiserfs_super_block * sb;
int c;
int error;
@@ -158,15 +145,20 @@ int main(int argc, char *argv[]) {
unsigned long block_count_new;
print_banner ("resize_reiserfs");
g_progname = basename(argv[0]);
print_banner (g_progname);
while ((c = getopt(argc, argv, "fvcqs:")) != EOF) {
while ((c = getopt(argc, argv, "fvcqks:j:")) != EOF) {
switch (c) {
case 's' :
if (!optarg)
die("%s: Missing argument to -s option", argv[0]);
if (!optarg)
DIE("Missing argument to -s option");
bytes_count_str = optarg;
break;
case 'j' :
if (!optarg)
DIE("Missing argument to -j option");
jdevice_name = optarg;
case 'f':
opt_force = 1;
break;
@@ -183,6 +175,9 @@ int main(int argc, char *argv[]) {
case 'q':
opt_verbose = 0;
break;
case 'k':
opt_skipj = 1;
break;
default:
print_usage_and_exit ();
}
@@ -194,56 +189,78 @@ int main(int argc, char *argv[]) {
fs = reiserfs_open(devname, O_RDONLY, &error, 0);
if (!fs)
die ("%s: can not open '%s': %s", argv[0], devname, strerror(error));
DIE ("cannot open '%s': %s", devname, strerror(error));
if (!reiserfs_open_journal (fs, jdevice_name, O_RDONLY)) {
if (!opt_skipj)
DIE ("can not open journal of '%s'", devname);
}
/* forced to continue without journal available/specified */
if (no_reiserfs_found (fs)) {
die ("resize_reiserfs: no reiserfs found on the device");
DIE ("no reiserfs found on the device.");
}
if (!spread_bitmaps (fs)) {
die ("resize_reiserfs: cannot resize reiserfs in old (not spread bitmap) format.\n");
DIE ("cannot resize reiserfs in old (not spread bitmap) format.");
}
rs = fs->s_rs;
sb = fs->fs_ondisk_sb;
if(bytes_count_str) { /* new fs size is specified by user */
block_count_new = calc_new_fs_size(rs_block_count(rs), fs->s_blocksize, bytes_count_str);
block_count_new = calc_new_fs_size(get_sb_block_count(sb), fs->fs_blocksize, bytes_count_str);
} else { /* use whole device */
block_count_new = count_blocks(devname, fs->s_blocksize, -1);
block_count_new = count_blocks(devname, fs->fs_blocksize);
}
if (is_mounted (devname)) {
reiserfs_close(fs);
return resize_fs_online(devname, block_count_new);
}
if (rs_state(rs) != REISERFS_VALID_FS)
die ("%s: the file system isn't in valid state\n", argv[0]);
}
if (!reiserfs_is_fs_consistent (fs)) {
reiserfs_warning (stderr, "\n\nresize_reiserfs: run reiserfsck --check first\n\n");
reiserfs_close (fs);
return 1;
}
if (get_sb_umount_state(sb) != REISERFS_CLEANLY_UMOUNTED)
/* fixme: shouldn't we check for something like: fsck guarantees: fs is ok */
DIE ("the file system isn't in valid state.");
if(!valid_offset(fs->s_dev, (loff_t) block_count_new * fs->s_blocksize - 1))
die ("%s: %s too small", argv[0], devname);
if (block_count_new >= get_sb_block_count(sb)) {
if (block_count_new == get_sb_block_count(sb)) {
reiserfs_warning (stderr, "%s already is of the needed size. Nothing to be done\n\n", devname);
exit (1);
}
if(!valid_offset(fs->fs_dev, (loff_t) block_count_new * fs->fs_blocksize - 1)) {
reiserfs_warning (stderr, "%s is of %lu blocks size only with reiserfs of %d blocks\nsize on it. "\
"You are trying to expant reiserfs up to %lu blocks size.\nYou probably forgot to expand your "\
"partition size.\n\n", devname, count_blocks (devname, fs->fs_blocksize),
get_sb_block_count(sb), block_count_new);
exit (1);
}
}
sb_old = 0; /* Needed to keep idiot compiler from issuing false warning */
/* save SB for reporting */
if(opt_verbose) {
sb_old = getmem(SB_SIZE);
memcpy(sb_old, SB_DISK_SUPER_BLOCK(fs), SB_SIZE);
memcpy(sb_old, fs->fs_ondisk_sb, SB_SIZE);
}
if (block_count_new == SB_BLOCK_COUNT(fs))
die ("%s: Calculated fs size is the same as the previous one.", argv[0]);
if (block_count_new > SB_BLOCK_COUNT(fs))
expand_fs(fs, block_count_new);
else
shrink_fs(fs, block_count_new);
error = (block_count_new > get_sb_block_count(fs->fs_ondisk_sb)) ? expand_fs(fs, block_count_new) : shrink_fs(fs, block_count_new);
if (error)
return error;
if(opt_verbose) {
sb_report(rs, sb_old);
sb_report(fs->fs_ondisk_sb, sb_old);
freemem(sb_old);
}
set_state (rs, REISERFS_VALID_FS);
bwrite_cond(SB_BUFFER_WITH_SB(fs));
set_sb_fs_state (fs->fs_ondisk_sb, REISERFS_CONSISTENT);
bwrite_cond(fs->fs_super_bh);
if (opt_verbose) {
printf("\nSyncing..");