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

+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;
}