Initial commit -- seeded with reiserfsprogs 3.x.0j
This commit is contained in:
commit
e7102bdb66
77 files changed
+33513
No files matched your search
@@ -0,0 +1,9 @@
|
||||
sbin_PROGRAMS = resize_reiserfs
|
||||
|
||||
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
|
||||
@@ -0,0 +1,331 @@
|
||||
# Makefile.in generated automatically by automake 1.4 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
SHELL = @SHELL@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
libexecdir = @libexecdir@
|
||||
datadir = @datadir@
|
||||
sysconfdir = @sysconfdir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
localstatedir = @localstatedir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
mandir = @mandir@
|
||||
includedir = @includedir@
|
||||
oldincludedir = /usr/include
|
||||
|
||||
DESTDIR =
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
|
||||
top_builddir = ..
|
||||
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
transform = @program_transform_name@
|
||||
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
CC = @CC@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
VERSION = @VERSION@
|
||||
|
||||
sbin_PROGRAMS = resize_reiserfs
|
||||
|
||||
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
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_CLEAN_FILES =
|
||||
PROGRAMS = $(sbin_PROGRAMS)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
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_LDFLAGS =
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
man8dir = $(mandir)/man8
|
||||
MANS = $(man_MANS)
|
||||
|
||||
NROFF = nroff
|
||||
DIST_COMMON = Makefile.am Makefile.in
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = tar
|
||||
GZIP_ENV = --best
|
||||
SOURCES = $(resize_reiserfs_SOURCES)
|
||||
OBJECTS = $(resize_reiserfs_OBJECTS)
|
||||
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .S .c .o .s
|
||||
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps resize_reiserfs/Makefile
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
|
||||
mostlyclean-sbinPROGRAMS:
|
||||
|
||||
clean-sbinPROGRAMS:
|
||||
-test -z "$(sbin_PROGRAMS)" || rm -f $(sbin_PROGRAMS)
|
||||
|
||||
distclean-sbinPROGRAMS:
|
||||
|
||||
maintainer-clean-sbinPROGRAMS:
|
||||
|
||||
install-sbinPROGRAMS: $(sbin_PROGRAMS)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(mkinstalldirs) $(DESTDIR)$(sbindir)
|
||||
@list='$(sbin_PROGRAMS)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
echo " $(INSTALL_PROGRAM) $$p $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
|
||||
$(INSTALL_PROGRAM) $$p $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-sbinPROGRAMS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
list='$(sbin_PROGRAMS)'; for p in $$list; do \
|
||||
rm -f $(DESTDIR)$(sbindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
|
||||
done
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.s.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.S.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.o core *.core
|
||||
|
||||
clean-compile:
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
maintainer-clean-compile:
|
||||
|
||||
resize_reiserfs: $(resize_reiserfs_OBJECTS) $(resize_reiserfs_DEPENDENCIES)
|
||||
@rm -f resize_reiserfs
|
||||
$(LINK) $(resize_reiserfs_LDFLAGS) $(resize_reiserfs_OBJECTS) $(resize_reiserfs_LDADD) $(LIBS)
|
||||
|
||||
install-man8:
|
||||
$(mkinstalldirs) $(DESTDIR)$(man8dir)
|
||||
@list='$(man8_MANS)'; \
|
||||
l2='$(man_MANS)'; for i in $$l2; do \
|
||||
case "$$i" in \
|
||||
*.8*) list="$$list $$i" ;; \
|
||||
esac; \
|
||||
done; \
|
||||
for i in $$list; do \
|
||||
if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \
|
||||
else file=$$i; fi; \
|
||||
ext=`echo $$i | sed -e 's/^.*\\.//'`; \
|
||||
inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
|
||||
inst=`echo $$inst | sed '$(transform)'`.$$ext; \
|
||||
echo " $(INSTALL_DATA) $$file $(DESTDIR)$(man8dir)/$$inst"; \
|
||||
$(INSTALL_DATA) $$file $(DESTDIR)$(man8dir)/$$inst; \
|
||||
done
|
||||
|
||||
uninstall-man8:
|
||||
@list='$(man8_MANS)'; \
|
||||
l2='$(man_MANS)'; for i in $$l2; do \
|
||||
case "$$i" in \
|
||||
*.8*) list="$$list $$i" ;; \
|
||||
esac; \
|
||||
done; \
|
||||
for i in $$list; do \
|
||||
ext=`echo $$i | sed -e 's/^.*\\.//'`; \
|
||||
inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \
|
||||
inst=`echo $$inst | sed '$(transform)'`.$$ext; \
|
||||
echo " rm -f $(DESTDIR)$(man8dir)/$$inst"; \
|
||||
rm -f $(DESTDIR)$(man8dir)/$$inst; \
|
||||
done
|
||||
install-man: $(MANS)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(MAKE) $(AM_MAKEFLAGS) install-man8
|
||||
uninstall-man:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
$(MAKE) $(AM_MAKEFLAGS) uninstall-man8
|
||||
|
||||
tags: TAGS
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
here=`pwd` && cd $(srcdir) \
|
||||
&& mkid -f$$here/ID $$unique $(LISP)
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|
||||
|
||||
mostlyclean-tags:
|
||||
|
||||
clean-tags:
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID
|
||||
|
||||
maintainer-clean-tags:
|
||||
|
||||
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
|
||||
|
||||
subdir = resize_reiserfs
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
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
|
||||
resize_reiserfs.o: resize_reiserfs.c resize.h ../include/io.h \
|
||||
../include/misc.h ../include/reiserfs_lib.h \
|
||||
../include/reiserfs_fs.h ../version.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
dvi-am:
|
||||
dvi: dvi-am
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
installcheck-am:
|
||||
installcheck: installcheck-am
|
||||
install-exec-am: install-sbinPROGRAMS
|
||||
install-exec: install-exec-am
|
||||
|
||||
install-data-am: install-man
|
||||
install-data: install-data-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
install: install-am
|
||||
uninstall-am: uninstall-sbinPROGRAMS uninstall-man
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(PROGRAMS) $(MANS)
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
installdirs:
|
||||
$(mkinstalldirs) $(DESTDIR)$(sbindir) $(DESTDIR)$(mandir)/man8
|
||||
|
||||
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-rm -f Makefile $(CONFIG_CLEAN_FILES)
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
mostlyclean-am: mostlyclean-sbinPROGRAMS mostlyclean-compile \
|
||||
mostlyclean-tags mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
clean-am: clean-sbinPROGRAMS clean-compile clean-tags clean-generic \
|
||||
mostlyclean-am
|
||||
|
||||
clean: clean-am
|
||||
|
||||
distclean-am: distclean-sbinPROGRAMS distclean-compile distclean-tags \
|
||||
distclean-generic clean-am
|
||||
|
||||
distclean: distclean-am
|
||||
|
||||
maintainer-clean-am: maintainer-clean-sbinPROGRAMS \
|
||||
maintainer-clean-compile maintainer-clean-tags \
|
||||
maintainer-clean-generic distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: mostlyclean-sbinPROGRAMS distclean-sbinPROGRAMS \
|
||||
clean-sbinPROGRAMS maintainer-clean-sbinPROGRAMS uninstall-sbinPROGRAMS \
|
||||
install-sbinPROGRAMS mostlyclean-compile distclean-compile \
|
||||
clean-compile maintainer-clean-compile install-man8 uninstall-man8 \
|
||||
install-man uninstall-man tags mostlyclean-tags distclean-tags \
|
||||
clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \
|
||||
check-am installcheck-am installcheck install-exec-am install-exec \
|
||||
install-data-am install-data install-am install uninstall-am uninstall \
|
||||
all-redirect all-am all installdirs mostlyclean-generic \
|
||||
distclean-generic clean-generic maintainer-clean-generic clean \
|
||||
mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
#include <time.h>
|
||||
#include "resize.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 total_node_cnt = 0;
|
||||
static unsigned long total_moved_cnt = 0;
|
||||
|
||||
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;
|
||||
|
||||
/* abnornal exit from block reallocation process */
|
||||
static void quit_resizer()
|
||||
{
|
||||
/* 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");
|
||||
}
|
||||
|
||||
/* block moving */
|
||||
static unsigned long move_generic_block(unsigned long block, unsigned long bnd, int h)
|
||||
{
|
||||
struct buffer_head * bh, * bh2;
|
||||
|
||||
/* primitive fsck */
|
||||
if (block > rs_block_count(rs)) {
|
||||
fprintf(stderr, "resize_reiserfs: invalid block number (%lu) found.\n", block);
|
||||
quit_resizer();
|
||||
}
|
||||
/* progress bar, 3D style :) */
|
||||
if (opt_verbose)
|
||||
print_how_far(&total_node_cnt, blocks_used, 1, 0);
|
||||
else
|
||||
total_node_cnt ++;
|
||||
|
||||
/* infinite loop check */
|
||||
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 */
|
||||
return 0;
|
||||
|
||||
/* move wrong block */
|
||||
bh = bread(fs->s_dev, block, fs->s_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();
|
||||
}
|
||||
|
||||
/* blocknr changing */
|
||||
bh2 = getblk(fs->s_dev, unused_block, fs->s_blocksize);
|
||||
memcpy(bh2->b_data, bh->b_data, bh2->b_size);
|
||||
reiserfs_bitmap_clear_bit(bmp, block);
|
||||
reiserfs_bitmap_set_bit(bmp, unused_block);
|
||||
|
||||
brelse(bh);
|
||||
mark_buffer_uptodate(bh2,1);
|
||||
mark_buffer_dirty(bh2);
|
||||
bwrite(bh2);
|
||||
brelse(bh2);
|
||||
|
||||
total_moved_cnt++;
|
||||
return unused_block;
|
||||
}
|
||||
|
||||
static unsigned long move_unformatted_block(unsigned long block, unsigned long bnd, int h)
|
||||
{
|
||||
unsigned long b;
|
||||
unfm_node_cnt++;
|
||||
b = move_generic_block(block, bnd, h);
|
||||
if (b)
|
||||
unfm_moved_cnt++;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
/* recursive function processing all tree nodes */
|
||||
static unsigned long move_formatted_block(unsigned long block, unsigned long bnd, int h)
|
||||
{
|
||||
struct buffer_head * bh;
|
||||
struct item_head *ih;
|
||||
unsigned long new_blocknr = 0;
|
||||
int node_is_internal = 0;
|
||||
int i, j;
|
||||
|
||||
bh = bread(fs->s_dev, block, fs->s_blocksize);
|
||||
|
||||
if (is_leaf_node (bh)) {
|
||||
|
||||
leaf_node_cnt++;
|
||||
|
||||
for (i=0; i < B_NR_ITEMS(bh); i++) {
|
||||
ih = B_N_PITEM_HEAD(bh, i);
|
||||
if (is_indirect_ih(ih)) {
|
||||
__u32 * indirect;
|
||||
|
||||
indirect = (__u32 *)B_I_PITEM (bh, ih);
|
||||
for (j = 0; j < I_UNFM_NUM(ih); j++) {
|
||||
unsigned long unfm_block;
|
||||
|
||||
if (indirect [j] == 0) /* hole */
|
||||
continue;
|
||||
unfm_block = move_unformatted_block(le32_to_cpu (indirect [j]), bnd, h + 1);
|
||||
if (unfm_block) {
|
||||
indirect [j] = cpu_to_le32 (unfm_block);
|
||||
mark_buffer_dirty(bh);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (is_internal_node (bh)) { /* internal node */
|
||||
|
||||
int_node_cnt++;
|
||||
node_is_internal = 1;
|
||||
|
||||
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);
|
||||
if (moved_block) {
|
||||
set_dc_block_number (bh, i, moved_block);
|
||||
mark_buffer_dirty(bh);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
die ("resize_reiserfs: block (%lu) has invalid format\n", block);
|
||||
}
|
||||
|
||||
if (buffer_dirty(bh)) {
|
||||
mark_buffer_uptodate(bh,1);
|
||||
bwrite(bh);
|
||||
}
|
||||
|
||||
brelse(bh);
|
||||
|
||||
new_blocknr = move_generic_block(block, bnd, h);
|
||||
if (new_blocknr) {
|
||||
if (node_is_internal)
|
||||
int_moved_cnt++;
|
||||
else
|
||||
leaf_moved_cnt++;
|
||||
}
|
||||
|
||||
return new_blocknr;
|
||||
}
|
||||
|
||||
int shrink_fs(reiserfs_filsys_t reiserfs, unsigned long blocks)
|
||||
{
|
||||
unsigned long n_root_block;
|
||||
unsigned int bmap_nr_new;
|
||||
unsigned long int i;
|
||||
|
||||
fs = reiserfs;
|
||||
rs = fs->s_rs;
|
||||
|
||||
/* 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]:"
|
||||
);
|
||||
c = getchar();
|
||||
if (c != 'y' && c != 'Y')
|
||||
exit(1);
|
||||
}
|
||||
|
||||
bmap_nr_new = (blocks - 1) / (8 * fs->s_blocksize) + 1;
|
||||
|
||||
/* is shrinking possible ? */
|
||||
if (rs_block_count(rs) - blocks > rs_free_blocks(rs) + rs_bmap_nr(rs) - 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));
|
||||
|
||||
/* 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
|
||||
- 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) {
|
||||
printf("Processing the tree: ");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
n_root_block = move_formatted_block(rs_root_block(rs), blocks, 0);
|
||||
if (n_root_block) {
|
||||
set_root_block (rs, 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);
|
||||
|
||||
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);
|
||||
}
|
||||
#if 0
|
||||
printf("check for used blocks in truncated region\n");
|
||||
{
|
||||
unsigned long l;
|
||||
for (l = blocks; l < rs_block_count(rs); l++)
|
||||
if (is_block_used(bmp, 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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
#include "resize.h"
|
||||
|
||||
|
||||
/* the front-end for kernel on-line resizer */
|
||||
int resize_fs_online(char * devname, unsigned long blocks)
|
||||
{
|
||||
static char buf[40];
|
||||
FILE * f;
|
||||
struct mntent * mnt;
|
||||
|
||||
if ((f = setmntent (MOUNTED, "r")) == NULL)
|
||||
goto fail;
|
||||
|
||||
while ((mnt = getmntent (f)) != NULL)
|
||||
if(strcmp(devname, mnt->mnt_fsname) == 0) {
|
||||
|
||||
if (strcmp(mnt->mnt_type,"reiserfs"))
|
||||
die ("resize_reiserfs: can\'t resize fs other than reiserfs\n");
|
||||
|
||||
sprintf(buf,"resize=%lu", blocks);
|
||||
|
||||
if (mount(mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type,
|
||||
(unsigned long)(MS_MGC_VAL | MS_REMOUNT), buf))
|
||||
die ("resize_reiserfs: remount failed: %s\n", strerror(errno));
|
||||
|
||||
endmntent(f);
|
||||
return 0;
|
||||
}
|
||||
fail:
|
||||
die ("resize_reiserfs: can't find mount entry\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <asm/types.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <mntent.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if __GLIBC__ >= 2
|
||||
#include <sys/mount.h>
|
||||
#else
|
||||
#include <linux/fs.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "io.h"
|
||||
#include "misc.h"
|
||||
#include "reiserfs_lib.h"
|
||||
#include "../version.h"
|
||||
|
||||
|
||||
#define print_usage_and_exit()\
|
||||
die ("Usage: %s [-s[+|-]#[G|M|K]] [-fqv] device", argv[0])
|
||||
|
||||
|
||||
/* reiserfs_resize.c */
|
||||
extern struct buffer_head * g_sb_bh;
|
||||
|
||||
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);
|
||||
@@ -0,0 +1,116 @@
|
||||
.\" -*- nroff -*-
|
||||
.\" Copyright 1996-2001 Hans Reiser.
|
||||
.\"
|
||||
.TH RESIZE_REISERFS 8 "March 2001" "Reiserfsprogs-3.x.0j"
|
||||
.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]
|
||||
] [
|
||||
.B \-fqv
|
||||
]
|
||||
.I device
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B resize_reiserfs
|
||||
tool resizes an unmounted reiserfs file system. It enlarges or shrinks an
|
||||
reiserfs file system located on a
|
||||
.I device
|
||||
so that it will have
|
||||
.I size
|
||||
bytes or size=old_size +(\-)
|
||||
.I size
|
||||
bytes if the + or \- prefix is used.
|
||||
If the
|
||||
.B \-s
|
||||
option is not specified, the filesystem will be resized to fill the
|
||||
given device.
|
||||
The
|
||||
.I size
|
||||
parameter may have one of the optional modifiers
|
||||
.BR K ", " M ", " G ,
|
||||
which means the
|
||||
.I size
|
||||
parameter is given in kilo\-, mega\-, gigabytes respectively.
|
||||
.PP
|
||||
The
|
||||
.B resize_reiserfs
|
||||
program does not manipulate the size of the device. If you wish to
|
||||
enlarge a filesystem, you must make sure you expand the underlying
|
||||
device first. This can be done using
|
||||
.BR cfdisk (8)
|
||||
for partitions, by deleting the partition and recreating it with a
|
||||
larger size (assuming there is free space
|
||||
.I after
|
||||
the partition in question). Make sure you re\-create it with the
|
||||
same starting disk cylinder as before! Otherwise, the resize operation
|
||||
will certainly not work, and you may lose your entire filesystem.
|
||||
.PP
|
||||
The
|
||||
.B resize_reiserfs
|
||||
program allows to grow a reiserfs on-line if there is a free
|
||||
space on block
|
||||
.I device.
|
||||
|
||||
.PP
|
||||
If you wish to shrink an reiserfs partition, first use
|
||||
.B resize_reiserfs
|
||||
to shrink the file system. You may then use
|
||||
.BR cfdisk (8)
|
||||
to shrink the device. When shrinking the size of the device, make sure
|
||||
you do not make it smaller than the reduced size of the reiserfs filesystem.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BR \-s\ [+|\-]\fIsize
|
||||
Set the new size in bytes.
|
||||
.TP
|
||||
.BR \-f
|
||||
Force, do not perform checks.
|
||||
.TP
|
||||
.BR \-q
|
||||
Do not print anything but error messages.
|
||||
.TP
|
||||
.BR \-v
|
||||
Turn on extra progress status messages (default).
|
||||
|
||||
.SH RETURN VALUES
|
||||
0 Resizing successful.
|
||||
.TP
|
||||
\-1 In another case.
|
||||
|
||||
.SH EXAMPLES
|
||||
The following example shows how to test
|
||||
.B resize_reiserfs\fR.
|
||||
Suppose 2Gb reiserfs filesystem is created on the device /dev/hda8
|
||||
and is mounted on /mnt.
|
||||
For shrinking the device we need to unmount it first, then run
|
||||
.B resize_reiserfs
|
||||
with a
|
||||
.I size \fR parameter (in this case -1Gb):
|
||||
.PP
|
||||
\ df
|
||||
.br
|
||||
\ umount /mnt
|
||||
.br
|
||||
\ resize_reiserfs -s -1G /dev/hda8
|
||||
.br
|
||||
\ mount /dev/hda8 /mnt
|
||||
.br
|
||||
\ df /mnt
|
||||
|
||||
.SH WARNING
|
||||
Note that this is a BETA program and may corrupt filesystems.
|
||||
.SH AUTHOR
|
||||
This version of
|
||||
.B resize_reiserfs
|
||||
has been written by Alexander Zarochentcev <zam@namesys.com>.
|
||||
.SH BUGS
|
||||
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 debugreiserfs (8)
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
|
||||
*/
|
||||
|
||||
/*
|
||||
* Written by Alexander Zarochentcev.
|
||||
*
|
||||
* FS resize utility
|
||||
*
|
||||
*/
|
||||
|
||||
#include "resize.h"
|
||||
|
||||
int opt_force = 0;
|
||||
int opt_verbose = 1; /* now "verbose" option is default */
|
||||
int opt_nowrite = 0;
|
||||
int opt_safe = 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
|
||||
|
||||
/* calculate the new fs size (in blocks) from old fs size and the string
|
||||
representation of new size */
|
||||
static unsigned long calc_new_fs_size(unsigned long count, int bs,
|
||||
char *bytes_str)
|
||||
{
|
||||
long long int bytes;
|
||||
unsigned long blocks;
|
||||
int c;
|
||||
|
||||
bytes = atoll(bytes_str);
|
||||
c = bytes_str[strlen(bytes_str) - 1];
|
||||
|
||||
switch (c) {
|
||||
case 'G':
|
||||
case 'g':
|
||||
bytes *= 1024;
|
||||
case 'M':
|
||||
case 'm':
|
||||
bytes *= 1024;
|
||||
case 'K':
|
||||
case 'k':
|
||||
bytes *= 1024;
|
||||
}
|
||||
|
||||
blocks = bytes / bs;
|
||||
|
||||
if (bytes_str[0] == '+' || bytes_str[0] == '-')
|
||||
return (count + blocks);
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/* print some fs parameters */
|
||||
static void sb_report(struct reiserfs_super_block * sb1,
|
||||
struct reiserfs_super_block * sb2)
|
||||
{
|
||||
printf(
|
||||
"ReiserFS report:\n"
|
||||
"blocksize %d\n"
|
||||
"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));
|
||||
};
|
||||
|
||||
/* conditional bwrite */
|
||||
static int bwrite_cond (struct buffer_head * bh)
|
||||
{
|
||||
if(!opt_nowrite) {
|
||||
mark_buffer_uptodate(bh,1);
|
||||
mark_buffer_dirty(bh);
|
||||
bwrite(bh);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
unsigned int bmap_nr_new, bmap_nr_old;
|
||||
int i;
|
||||
|
||||
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");
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char * bytes_count_str = NULL;
|
||||
char * devname;
|
||||
reiserfs_filsys_t fs;
|
||||
struct reiserfs_super_block * rs;
|
||||
|
||||
int c;
|
||||
int error;
|
||||
|
||||
struct reiserfs_super_block *sb_old;
|
||||
|
||||
unsigned long block_count_new;
|
||||
|
||||
print_banner ("resize_reiserfs");
|
||||
|
||||
while ((c = getopt(argc, argv, "fvcqs:")) != EOF) {
|
||||
switch (c) {
|
||||
case 's' :
|
||||
if (!optarg)
|
||||
die("%s: Missing argument to -s option", argv[0]);
|
||||
bytes_count_str = optarg;
|
||||
break;
|
||||
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;
|
||||
default:
|
||||
print_usage_and_exit ();
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc )
|
||||
print_usage_and_exit();
|
||||
devname = argv[optind];
|
||||
|
||||
fs = reiserfs_open(devname, O_RDONLY, &error, 0);
|
||||
if (!fs)
|
||||
die ("%s: can not open '%s': %s", argv[0], devname, strerror(error));
|
||||
|
||||
if (no_reiserfs_found (fs)) {
|
||||
die ("resize_reiserfs: no reiserfs found on the device");
|
||||
}
|
||||
if (!spread_bitmaps (fs)) {
|
||||
die ("resize_reiserfs: cannot resize reiserfs in old (not spread bitmap) format.\n");
|
||||
}
|
||||
|
||||
rs = fs->s_rs;
|
||||
|
||||
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);
|
||||
} else { /* use whole device */
|
||||
block_count_new = count_blocks(devname, fs->s_blocksize, -1);
|
||||
}
|
||||
|
||||
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(!valid_offset(fs->s_dev, (loff_t) block_count_new * fs->s_blocksize - 1))
|
||||
die ("%s: %s too small", argv[0], devname);
|
||||
|
||||
sb_old = 0; /* Needed to keep idiot compiler from issuing false warning */
|
||||
/* save SB for reporting */
|
||||
if(opt_verbose) {
|
||||
sb_old = getmem(SB_SIZE);
|
||||
memcpy(sb_old, SB_DISK_SUPER_BLOCK(fs), SB_SIZE);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if(opt_verbose) {
|
||||
sb_report(rs, sb_old);
|
||||
freemem(sb_old);
|
||||
}
|
||||
|
||||
set_state (rs, REISERFS_VALID_FS);
|
||||
bwrite_cond(SB_BUFFER_WITH_SB(fs));
|
||||
|
||||
if (opt_verbose) {
|
||||
printf("\nSyncing..");
|
||||
fflush(stdout);
|
||||
}
|
||||
reiserfs_close (fs);
|
||||
if (opt_verbose)
|
||||
printf("done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user