Many files:
resize2fs.h: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
ext2_block_move.c, ext2_inode_move.c, extent.c, resize2fs.c,
resize2fs.h: Rename variables named "new" to "new_block",
"new_inode", or "new_loc" to avoid C++ reserved word
clash.
ext2_block_move.c, ext2_inode_move.c, extent.c, resize2fs.c,
sim_progress.c: Use ext2fs_get_memory(),
ext2fs_free_memory(), et. al., instead of malloc() and
free().
ext2_block_move.c, ext2_inode_move.c, extent.c: Explicitly cast
all assignments from void * to be compatible with C++.
banalysis.c, banalysis.h, ext2_inode_move.c, ext2_block_move.c:
Change private to priv_data to avoid C++ namespace clash.
ChangeLog, badblocks.8.in:
badblocks.8.in: Add documentation for the -s option.
diff --git a/misc/ChangeLog b/misc/ChangeLog
index 859ebc6..51a2969 100644
--- a/misc/ChangeLog
+++ b/misc/ChangeLog
@@ -1,3 +1,7 @@
+Mon Dec 1 17:01:04 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * badblocks.8.in: Add documentation for the -s option.
+
Fri Oct 24 23:37:52 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
* fsck.c:
diff --git a/misc/badblocks.8.in b/misc/badblocks.8.in
index 88adb34..a9eacd8 100644
--- a/misc/badblocks.8.in
+++ b/misc/badblocks.8.in
@@ -13,6 +13,9 @@
output_file
]
[
+.B \-s
+]
+[
.B \-v
]
[
@@ -39,6 +42,10 @@
.B badblocks
displays the list on its standard output.
.TP
+.I -s
+Show the progress of the scan by writing out the block numbers as they
+are checked.
+.TP
.I -v
Verbose mode.
.TP
diff --git a/resize/ChangeLog b/resize/ChangeLog
index 31504a6..f4a5fff 100644
--- a/resize/ChangeLog
+++ b/resize/ChangeLog
@@ -1,3 +1,26 @@
+Mon Jan 19 09:12:28 1998 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * resize2fs.h: If EXT2_FLAT_INCLUDES is defined, then assume all
+ of the ext2-specific header files are in a flat directory.
+
+ * ext2_block_move.c, ext2_inode_move.c, extent.c, resize2fs.c,
+ resize2fs.h: Rename variables named "new" to "new_block",
+ "new_inode", or "new_loc" to avoid C++ reserved word
+ clash.
+
+ * ext2_block_move.c, ext2_inode_move.c, extent.c, resize2fs.c,
+ sim_progress.c: Use ext2fs_get_memory(),
+ ext2fs_free_memory(), et. al., instead of malloc() and
+ free().
+
+ * ext2_block_move.c, ext2_inode_move.c, extent.c: Explicitly cast
+ all assignments from void * to be compatible with C++.
+
+Mon Dec 29 19:09:45 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * banalysis.c, banalysis.h, ext2_inode_move.c, ext2_block_move.c:
+ Change private to priv_data to avoid C++ namespace clash.
+
Mon Nov 3 14:45:06 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
* resize2fs.h: Remove STDC magic, since everyone is STDC these days.
diff --git a/resize/banalysis.c b/resize/banalysis.c
index 5b02d22..638ed75 100644
--- a/resize/banalysis.c
+++ b/resize/banalysis.c
@@ -22,14 +22,14 @@
struct process_block_struct {
struct ext2_block_analyzer_funcs *funcs;
struct ext2_inode_context *ctx;
- void *private;
+ void *priv_data;
};
static int process_block(ext2_filsys fs, blk_t *block_nr,
int blockcnt, blk_t ref_block,
- int ref_offset, void *private)
+ int ref_offset, void *priv_data)
{
- struct process_block_struct *pb = private;
+ struct process_block_struct *pb = priv_data;
blk_t new_block;
struct ext2_block_relocate_entry ent;
@@ -37,7 +37,7 @@
ref_offset = blockcnt;
new_block = pb->funcs->block_analyze(fs, *block_nr, ref_block,
- ref_offset, pb->ctx, pb->private);
+ ref_offset, pb->ctx, pb->priv_data);
if (new_block) {
ent.new = new_block;
ent.offset = ref_offset;
@@ -56,7 +56,7 @@
errcode_t ext2_block_analyze(ext2_filsys fs,
struct ext2_block_analyzer_funcs *funcs,
ext2_brel block_relocation_table,
- void *private)
+ void *priv_data)
{
ino_t ino;
struct ext2_inode inode;
@@ -71,7 +71,7 @@
return retval;
pb.funcs = funcs;
- pb.private = private;
+ pb.priv_data = priv_data;
pb.ctx = &ctx;
block_buf = malloc(fs->blocksize * 3);
@@ -81,7 +81,7 @@
retval = ext2fs_get_next_inode(scan, &ino, &inode);
if (retval)
return retval;
- ctx.ctx = private;
+ ctx.ctx = priv_data;
ctx.brel = block_relocation_table;
while (ino) {
if ((inode.i_links_count == 0) ||
@@ -93,7 +93,7 @@
ctx.error = 0;
if (funcs->pre_analyze &&
- !(*funcs->pre_analyze)(fs, &ctx, private))
+ !(*funcs->pre_analyze)(fs, &ctx, priv_data))
goto next;
retval = ext2fs_block_iterate2(fs, ino, 0, block_buf,
@@ -102,7 +102,7 @@
return retval;
if (funcs->post_analyze)
- (funcs->post_analyze)(fs, &ctx, private);
+ (funcs->post_analyze)(fs, &ctx, priv_data);
next:
retval = ext2fs_get_next_inode(scan, &ino, &inode);
diff --git a/resize/banalysis.h b/resize/banalysis.h
index 247413a..18cf98e 100644
--- a/resize/banalysis.h
+++ b/resize/banalysis.h
@@ -13,18 +13,18 @@
struct ext2_block_analyzer_funcs {
int (*pre_analyze)(ext2_filsys fs,
struct ext2_inode_context *icontext,
- void *private);
+ void *priv_data);
blk_t (*block_analyze)(ext2_filsys fs, blk_t blk,
blk_t ref_block, int ref_offset,
struct ext2_inode_context *icontext,
- void *private);
+ void *priv_data);
void (*post_analyze)(ext2_filsys fs,
struct ext2_inode_context *icontext,
- void *private);
+ void *priv_data);
};
errcode_t ext2_block_analyze(ext2_filsys fs,
struct ext2_block_analyzer_funcs *funcs,
ext2_brel block_relocation_table,
- void *private);
+ void *priv_data);
diff --git a/resize/ext2_block_move.c b/resize/ext2_block_move.c
index 3170e95..bcddb1d 100644
--- a/resize/ext2_block_move.c
+++ b/resize/ext2_block_move.c
@@ -21,23 +21,23 @@
static int process_block(ext2_filsys fs, blk_t *block_nr,
int blockcnt, blk_t ref_block,
- int ref_offset, void *private)
+ int ref_offset, void *priv_data)
{
- struct process_block_struct *pb = private;
+ struct process_block_struct *pb;
errcode_t retval;
- blk_t block, new;
+ blk_t block, new_block;
int ret = 0;
+ pb = (struct process_block_struct *) priv_data;
block = *block_nr;
-
- new = ext2fs_extent_translate(pb->bmap, block);
- if (new) {
- *block_nr = new;
+ new_block = ext2fs_extent_translate(pb->bmap, block);
+ if (new_block) {
+ *block_nr = new_block;
ret |= BLOCK_CHANGED;
#ifdef RESIZE2FS_DEBUG
if (pb->flags & RESIZE_DEBUG_BMOVE)
printf("ino=%ld, blockcnt=%d, %u->%u\n", pb->ino,
- blockcnt, block, new);
+ blockcnt, block, new_block);
#endif
}
@@ -56,7 +56,7 @@
errcode_t ext2fs_block_move(ext2_resize_t rfs)
{
ext2_extent bmap;
- blk_t blk, old, new;
+ blk_t blk, old_blk, new_blk;
ext2_filsys fs = rfs->new_fs;
ext2_filsys old_fs = rfs->old_fs;
ino_t ino;
@@ -64,17 +64,18 @@
errcode_t retval;
struct process_block_struct pb;
ext2_inode_scan scan = 0;
- char *block_buf;
+ char *block_buf = 0;
int size, c;
int to_move, moved;
ext2_sim_progmeter progress = 0;
- new = fs->super->s_first_data_block;
+ new_blk = fs->super->s_first_data_block;
if (!rfs->itable_buf) {
- rfs->itable_buf = malloc(fs->blocksize *
- fs->inode_blocks_per_group);
- if (!rfs->itable_buf)
- return ENOMEM;
+ retval = ext2fs_get_mem(fs->blocksize *
+ fs->inode_blocks_per_group,
+ (void **) &rfs->itable_buf);
+ if (retval)
+ return retval;
}
retval = ext2fs_create_extent_table(&bmap, 0);
if (retval)
@@ -93,18 +94,18 @@
continue;
while (1) {
- if (new >= fs->super->s_blocks_count) {
+ if (new_blk >= fs->super->s_blocks_count) {
retval = ENOSPC;
goto errout;
}
- if (!ext2fs_test_block_bitmap(fs->block_map, new) &&
+ if (!ext2fs_test_block_bitmap(fs->block_map, new_blk) &&
!ext2fs_test_block_bitmap(rfs->reserve_blocks,
- new))
+ new_blk))
break;
- new++;
+ new_blk++;
}
- ext2fs_mark_block_bitmap(fs->block_map, new);
- ext2fs_add_extent_entry(bmap, blk, new);
+ ext2fs_mark_block_bitmap(fs->block_map, new_blk);
+ ext2fs_add_extent_entry(bmap, blk, new_blk);
to_move++;
}
if (to_move == 0)
@@ -123,28 +124,28 @@
}
while (1) {
- retval = ext2fs_iterate_extent(bmap, &old, &new, &size);
+ retval = ext2fs_iterate_extent(bmap, &old_blk, &new_blk, &size);
if (retval) goto errout;
if (!size)
break;
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_BMOVE)
printf("Moving %d blocks %u->%u\n", size,
- old, new);
+ old_blk, new_blk);
#endif
do {
c = size;
if (c > fs->inode_blocks_per_group)
c = fs->inode_blocks_per_group;
- retval = io_channel_read_blk(fs->io, old, c,
+ retval = io_channel_read_blk(fs->io, old_blk, c,
rfs->itable_buf);
if (retval) goto errout;
- retval = io_channel_write_blk(fs->io, new, c,
+ retval = io_channel_write_blk(fs->io, new_blk, c,
rfs->itable_buf);
if (retval) goto errout;
size -= c;
- new += c;
- old += c;
+ new_blk += c;
+ old_blk += c;
moved += c;
io_channel_flush(fs->io);
if (progress)
@@ -167,11 +168,9 @@
pb.bmap = bmap;
pb.flags = rfs->flags;
- block_buf = malloc(old_fs->blocksize * 3);
- if (!block_buf) {
- retval = ENOMEM;
+ retval = ext2fs_get_mem(old_fs->blocksize * 3, (void **) &block_buf);
+ if (retval)
goto errout;
- }
/*
* We're going to initialize the dblist while we're at it.
@@ -229,6 +228,8 @@
ext2fs_free_extent_table(bmap);
if (scan)
ext2fs_close_inode_scan(scan);
+ if (block_buf)
+ ext2fs_free_mem((void **) &block_buf);
return retval;
}
diff --git a/resize/ext2_inode_move.c b/resize/ext2_inode_move.c
index 3ec74b8..6b3600f 100644
--- a/resize/ext2_inode_move.c
+++ b/resize/ext2_inode_move.c
@@ -19,9 +19,9 @@
};
static errcode_t progress_callback(ext2_filsys fs, ext2_inode_scan scan,
- dgrp_t group, void * private)
+ dgrp_t group, void * priv_data)
{
- struct callback_info *cb = private;
+ struct callback_info *cb = (struct callback_info *) priv_data;
if (!cb->progress)
return 0;
@@ -40,10 +40,10 @@
static int check_and_change_inodes(ino_t dir, int entry,
struct ext2_dir_entry *dirent, int offset,
- int blocksize, char *buf, void *private)
+ int blocksize, char *buf, void *priv_data)
{
- struct istruct *is = private;
- ino_t new;
+ struct istruct *is = (struct istruct *) priv_data;
+ ino_t new_inode;
if (is->progress && offset == 0) {
ext2fs_progress_update(is->progress, ++is->num);
@@ -52,18 +52,18 @@
if (!dirent->inode)
return 0;
- new = ext2fs_extent_translate(is->imap, dirent->inode);
+ new_inode = ext2fs_extent_translate(is->imap, dirent->inode);
- if (!new)
+ if (!new_inode)
return 0;
#ifdef RESIZE2FS_DEBUG
if (is->flags & RESIZE_DEBUG_INODEMAP)
printf("Inode translate (dir=%ld, name=%.*s, %u->%ld)\n",
dir, dirent->name_len, dirent->name,
- dirent->inode, new);
+ dirent->inode, new_inode);
#endif
- dirent->inode = new;
+ dirent->inode = new_inode;
return DIRENT_CHANGED;
}
@@ -80,12 +80,13 @@
static int process_block(ext2_filsys fs, blk_t *block_nr,
int blockcnt, blk_t ref_block,
- int ref_offset, void *private)
+ int ref_offset, void *priv_data)
{
- struct process_block_struct *pb = private;
+ struct process_block_struct *pb;
errcode_t retval;
int ret = 0;
+ pb = (struct process_block_struct *) priv_data;
retval = ext2fs_add_dir_block(fs->dblist, pb->ino,
*block_nr, blockcnt);
if (retval) {
@@ -99,7 +100,7 @@
{
ext2_inode_scan scan = 0;
errcode_t retval;
- char *block_buf;
+ char *block_buf = 0;
struct process_block_struct pb;
ext2_sim_progmeter progress = 0;
ino_t ino;
@@ -110,11 +111,9 @@
pb.error = 0;
- block_buf = malloc(fs->blocksize * 3);
- if (!block_buf) {
- retval = ENOMEM;
+ retval = ext2fs_get_mem(fs->blocksize * 3, (void **) &block_buf);
+ if (retval)
goto errout;
- }
/*
* We're going to initialize the dblist while we're at it.
@@ -170,13 +169,15 @@
ext2fs_progress_close(progress);
if (scan)
ext2fs_close_inode_scan(scan);
+ if (block_buf)
+ ext2fs_free_mem((void **) &block_buf);
return retval;
}
errcode_t ext2fs_inode_move(ext2_resize_t rfs)
{
- ino_t ino, new;
+ ino_t ino, new_inode;
struct ext2_inode inode;
ext2_inode_scan scan = NULL;
ext2_extent imap;
@@ -217,7 +218,7 @@
}
callback_info.progress = progress;
- new = EXT2_FIRST_INODE(rfs->new_fs->super);
+ new_inode = EXT2_FIRST_INODE(rfs->new_fs->super);
/*
* First, copy all of the inodes that need to be moved
* elsewhere in the inode table
@@ -237,28 +238,28 @@
*/
while (1) {
if (!ext2fs_test_inode_bitmap(rfs->new_fs->inode_map,
- new))
+ new_inode))
break;
- new++;
- if (new > rfs->new_fs->super->s_inodes_count) {
+ new_inode++;
+ if (new_inode > rfs->new_fs->super->s_inodes_count) {
retval = ENOSPC;
goto errout;
}
}
- ext2fs_mark_inode_bitmap(rfs->new_fs->inode_map, new);
- retval = ext2fs_write_inode(rfs->old_fs, new, &inode);
+ ext2fs_mark_inode_bitmap(rfs->new_fs->inode_map, new_inode);
+ retval = ext2fs_write_inode(rfs->old_fs, new_inode, &inode);
if (retval) goto errout;
- group = (new-1) / EXT2_INODES_PER_GROUP(rfs->new_fs->super);
+ group = (new_inode-1) / EXT2_INODES_PER_GROUP(rfs->new_fs->super);
if (LINUX_S_ISDIR(inode.i_mode))
rfs->new_fs->group_desc[group].bg_used_dirs_count++;
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_INODEMAP)
- printf("Inode moved %ld->%ld\n", ino, new);
+ printf("Inode moved %ld->%ld\n", ino, new_inode);
#endif
- ext2fs_add_extent_entry(imap, ino, new);
+ ext2fs_add_extent_entry(imap, ino, new_inode);
}
io_channel_flush(rfs->new_fs->io);
if (progress) {
diff --git a/resize/extent.c b/resize/extent.c
index 0f0ef4c..b51e653 100644
--- a/resize/extent.c
+++ b/resize/extent.c
@@ -15,7 +15,7 @@
#include "resize2fs.h"
struct ext2_extent_entry {
- __u32 old, new;
+ __u32 old_loc, new_loc;
int size;
};
@@ -32,25 +32,29 @@
*/
errcode_t ext2fs_create_extent_table(ext2_extent *ret_extent, int size)
{
- ext2_extent new;
+ ext2_extent extent;
+ errcode_t retval;
+
+ retval = ext2fs_get_mem(sizeof(struct _ext2_extent),
+ (void **) &extent);
+ if (retval)
+ return retval;
+ memset(extent, 0, sizeof(struct _ext2_extent));
- new = malloc(sizeof(struct _ext2_extent));
- if (!new)
- return ENOMEM;
- memset(new, 0, sizeof(struct _ext2_extent));
+ extent->size = size ? size : 50;
+ extent->cursor = 0;
+ extent->num = 0;
+ extent->sorted = 1;
- new->size = size ? size : 50;
- new->cursor = 0;
- new->num = 0;
- new->sorted = 1;
-
- new->list = malloc(sizeof(struct ext2_extent_entry) * new->size);
- if (!new->list) {
- free(new);
- return ENOMEM;
+ retval = ext2fs_get_mem(sizeof(struct ext2_extent_entry) *
+ extent->size, (void **) &extent->list);
+ if (retval) {
+ free(extent);
+ return retval;
}
- memset(new->list, 0, sizeof(struct ext2_extent_entry) * new->size);
- *ret_extent = new;
+ memset(extent->list, 0,
+ sizeof(struct ext2_extent_entry) * extent->size);
+ *ret_extent = extent;
return 0;
}
@@ -60,30 +64,29 @@
void ext2fs_free_extent_table(ext2_extent extent)
{
if (extent->list)
- free(extent->list);
+ ext2fs_free_mem((void **) &extent->list);
extent->list = 0;
extent->size = 0;
extent->num = 0;
- free(extent);
+ ext2fs_free_mem((void **) &extent);
}
/*
* Add an entry to the extent table
*/
-errcode_t ext2fs_add_extent_entry(ext2_extent extent, __u32 old, __u32 new)
+errcode_t ext2fs_add_extent_entry(ext2_extent extent, __u32 old_loc, __u32 new_loc)
{
- struct ext2_extent_entry *p;
- int newsize;
- int curr;
- struct ext2_extent_entry *ent;
+ struct ext2_extent_entry *ent;
+ errcode_t retval;
+ int newsize;
+ int curr;
if (extent->num >= extent->size) {
newsize = extent->size + 100;
- p = realloc(extent->list,
- sizeof(struct ext2_extent_entry) * newsize);
- if (!p)
- return ENOMEM;
- extent->list = p;
+ retval = ext2fs_resize_mem(sizeof(struct ext2_extent_entry) *
+ newsize, (void **) &extent->list);
+ if (retval)
+ return retval;
extent->size = newsize;
}
curr = extent->num;
@@ -94,20 +97,20 @@
* extent
*/
ent--;
- if ((ent->old + ent->size == old) &&
- (ent->new + ent->size == new)) {
+ if ((ent->old_loc + ent->size == old_loc) &&
+ (ent->new_loc + ent->size == new_loc)) {
ent->size++;
return 0;
}
/*
* Now see if we're going to ruin the sorting
*/
- if (ent->old + ent->size > old)
+ if (ent->old_loc + ent->size > old_loc)
extent->sorted = 0;
ent++;
}
- ent->old = old;
- ent->new = new;
+ ent->old_loc = old_loc;
+ ent->new_loc = new_loc;
ent->size = 1;
extent->num++;
return 0;
@@ -118,17 +121,20 @@
*/
static int extent_cmp(const void *a, const void *b)
{
- const struct ext2_extent_entry *db_a = a;
- const struct ext2_extent_entry *db_b = b;
+ const struct ext2_extent_entry *db_a;
+ const struct ext2_extent_entry *db_b;
- return (db_a->old - db_b->old);
+ db_a = (struct ext2_extent_entry *) a;
+ db_b = (struct ext2_extent_entry *) b;
+
+ return (db_a->old_loc - db_b->old_loc);
}
/*
* Given an inode map and inode number, look up the old inode number
- * and return the new inode number
+ * and return the new inode number.
*/
-__u32 ext2fs_extent_translate(ext2_extent extent, __u32 old)
+__u32 ext2fs_extent_translate(ext2_extent extent, __u32 old_loc)
{
int low, high, mid;
ino_t lowval, highval;
@@ -149,24 +155,24 @@
mid = low;
else {
/* Interpolate for efficiency */
- lowval = extent->list[low].old;
- highval = extent->list[high].old;
+ lowval = extent->list[low].old_loc;
+ highval = extent->list[high].old_loc;
- if (old < lowval)
+ if (old_loc < lowval)
range = 0;
- else if (old > highval)
+ else if (old_loc > highval)
range = 1;
else
- range = ((float) (old - lowval)) /
+ range = ((float) (old_loc - lowval)) /
(highval - lowval);
mid = low + ((int) (range * (high-low)));
}
#endif
- if ((old >= extent->list[mid].old) &&
- (old < extent->list[mid].old + extent->list[mid].size))
- return (extent->list[mid].new +
- (old - extent->list[mid].old));
- if (old < extent->list[mid].old)
+ if ((old_loc >= extent->list[mid].old_loc) &&
+ (old_loc < extent->list[mid].old_loc + extent->list[mid].size))
+ return (extent->list[mid].new_loc +
+ (old_loc - extent->list[mid].old_loc));
+ if (old_loc < extent->list[mid].old_loc)
high = mid-1;
else
low = mid+1;
@@ -186,35 +192,35 @@
fprintf(out, "#\tNum=%d, Size=%d, Cursor=%d, Sorted=%d\n",
extent->num, extent->size, extent->cursor, extent->sorted);
for (i=0, ent=extent->list; i < extent->num; i++, ent++) {
- fprintf(out, "#\t\t %u -> %u (%d)\n", ent->old,
- ent->new, ent->size);
+ fprintf(out, "#\t\t %u -> %u (%d)\n", ent->old_loc,
+ ent->new_loc, ent->size);
}
}
/*
* Iterate over the contents of the extent table
*/
-errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old,
- __u32 *new, int *size)
+errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old_loc,
+ __u32 *new_loc, int *size)
{
struct ext2_extent_entry *ent;
- if (!old) {
+ if (!old_loc) {
extent->cursor = 0;
return 0;
}
if (extent->cursor >= extent->num) {
- *old = 0;
- *new = 0;
+ *old_loc = 0;
+ *new_loc = 0;
*size = 0;
return 0;
}
ent = extent->list + extent->cursor++;
- *old = ent->old;
- *new = ent->new;
+ *old_loc = ent->old_loc;
+ *new_loc = ent->new_loc;
*size = ent->size;
return 0;
}
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 1345708..7bb0382 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -34,7 +34,6 @@
ino_t real_end;
blk_t blk, group_block;
unsigned long i, j;
- struct ext2_group_desc *new;
int old_numblocks, numblocks, adjblocks;
ext2_sim_progmeter progress = 0;
@@ -124,11 +123,10 @@
* Reallocate the group descriptors as necessary.
*/
if (rfs->old_fs->desc_blocks != fs->desc_blocks) {
- new = realloc(fs->group_desc,
- fs->desc_blocks * fs->blocksize);
- if (!new)
- return ENOMEM;
- fs->group_desc = new;
+ retval = ext2fs_resize_mem(fs->desc_blocks * fs->blocksize,
+ (void **) &fs->group_desc);
+ if (retval)
+ return retval;
}
/*
@@ -161,11 +159,11 @@
retval = 0;
goto errout;
}
- rfs->itable_buf = malloc(fs->blocksize * fs->inode_blocks_per_group);
- if (!rfs->itable_buf) {
- retval = ENOMEM;
+ retval = ext2fs_get_mem(fs->blocksize * fs->inode_blocks_per_group,
+ (void **) &rfs->itable_buf);
+ if (retval)
goto errout;
- }
+
memset(rfs->itable_buf, 0, fs->blocksize * fs->inode_blocks_per_group);
group_block = fs->super->s_first_data_block +
rfs->old_fs->group_desc_count * fs->super->s_blocks_per_group;
@@ -534,7 +532,7 @@
int i, n, num, max, size, diff;
ext2_filsys fs = rfs->new_fs;
char *cp;
- blk_t old, new;
+ blk_t old_blk, new_blk;
errcode_t retval, err;
ext2_sim_progmeter progress = 0;
int to_move, moved;
@@ -545,9 +543,9 @@
size = fs->blocksize * fs->inode_blocks_per_group;
if (!rfs->itable_buf) {
- rfs->itable_buf = malloc(size);
- if (!rfs->itable_buf)
- return ENOMEM;
+ retval = ext2fs_get_mem(size, (void **) &rfs->itable_buf);
+ if (retval)
+ return retval;
}
/*
@@ -570,21 +568,21 @@
}
for (i=0; i < max; i++) {
- old = rfs->old_fs->group_desc[i].bg_inode_table;
- new = fs->group_desc[i].bg_inode_table;
- diff = new - old;
+ old_blk = rfs->old_fs->group_desc[i].bg_inode_table;
+ new_blk = fs->group_desc[i].bg_inode_table;
+ diff = new_blk - old_blk;
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE)
printf("Itable move group %d block "
"%u->%u (diff %d)\n",
- i, old, new, diff);
+ i, old_blk, new_blk, diff);
#endif
if (!diff)
continue;
- retval = io_channel_read_blk(fs->io, old,
+ retval = io_channel_read_blk(fs->io, old_blk,
fs->inode_blocks_per_group,
rfs->itable_buf);
if (retval)
@@ -606,16 +604,16 @@
if (n > diff)
num -= n;
- retval = io_channel_write_blk(fs->io, new,
+ retval = io_channel_write_blk(fs->io, new_blk,
num, rfs->itable_buf);
if (retval) {
- io_channel_write_blk(fs->io, old,
+ io_channel_write_blk(fs->io, old_blk,
num, rfs->itable_buf);
goto backout;
}
if (n > diff) {
retval = io_channel_write_blk(fs->io,
- old + fs->inode_blocks_per_group,
+ old_blk + fs->inode_blocks_per_group,
diff, rfs->itable_buf - fs->blocksize * diff);
if (retval)
goto backout;
@@ -644,17 +642,17 @@
while (--i >= 0) {
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE)
- printf("Group %d block %u->%u\n", i, new, old);
+ printf("Group %d block %u->%u\n", i, new_blk, old_blk);
#endif
- old = rfs->old_fs->group_desc[i].bg_inode_table;
- new = fs->group_desc[i].bg_inode_table;
+ old_blk = rfs->old_fs->group_desc[i].bg_inode_table;
+ new_blk = fs->group_desc[i].bg_inode_table;
- err = io_channel_read_blk(fs->io, new,
+ err = io_channel_read_blk(fs->io, new_blk,
fs->inode_blocks_per_group,
rfs->itable_buf);
if (err)
continue;
- err = io_channel_write_blk(fs->io, old,
+ err = io_channel_write_blk(fs->io, old_blk,
fs->inode_blocks_per_group,
rfs->itable_buf);
}
@@ -736,9 +734,10 @@
/*
* Create the data structure
*/
- rfs = malloc(sizeof(struct ext2_resize_struct));
- if (!rfs)
- return ENOMEM;
+ retval = ext2fs_get_mem(sizeof(struct ext2_resize_struct),
+ (void **) &rfs);
+ if (retval)
+ return retval;
memset(rfs, 0, sizeof(struct ext2_resize_struct));
rfs->old_fs = fs;
@@ -788,8 +787,8 @@
ext2fs_free(rfs->old_fs);
if (rfs->itable_buf)
- free(rfs->itable_buf);
- free(rfs);
+ ext2fs_free_mem((void **) &rfs->itable_buf);
+ ext2fs_free_mem((void **) &rfs);
return 0;
@@ -797,7 +796,7 @@
if (rfs->new_fs)
ext2fs_free(rfs->new_fs);
if (rfs->itable_buf)
- free(rfs->itable_buf);
- free(rfs);
+ ext2fs_free_mem((void **) &rfs->itable_buf);
+ ext2fs_free_mem((void **) &rfs);
return retval;
}
diff --git a/resize/resize2fs.h b/resize/resize2fs.h
index 3cf21b9..ed133ec 100644
--- a/resize/resize2fs.h
+++ b/resize/resize2fs.h
@@ -25,9 +25,15 @@
#ifdef HAVE_LINUX_FS_H
#include <linux/fs.h>
#endif
-#include <linux/ext2_fs.h>
+#if EXT2_FLAT_INCLUDES
+#include "ext2_fs.h"
+#include "ext2fs.h"
+#else
+#include <linux/ext2_fs.h>
#include "ext2fs/ext2fs.h"
+#endif
+
/*
* For the extent map
@@ -76,11 +82,11 @@
int size);
extern void ext2fs_free_extent_table(ext2_extent extent);
extern errcode_t ext2fs_add_extent_entry(ext2_extent extent,
- __u32 old, __u32 new);
-extern __u32 ext2fs_extent_translate(ext2_extent extent, __u32 old);
+ __u32 old_loc, __u32 new_loc);
+extern __u32 ext2fs_extent_translate(ext2_extent extent, __u32 old_loc);
extern void ext2fs_extent_dump(ext2_extent extent, FILE *out);
-extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old,
- __u32 *new, int *size);
+extern errcode_t ext2fs_iterate_extent(ext2_extent extent, __u32 *old_loc,
+ __u32 *new_loc, int *size);
/* sim_progress.c */
extern errcode_t ext2fs_progress_init(ext2_sim_progmeter *ret_prog,
diff --git a/resize/sim_progress.c b/resize/sim_progress.c
index 1e30d11..850c860 100644
--- a/resize/sim_progress.c
+++ b/resize/sim_progress.c
@@ -69,17 +69,19 @@
int labelwidth, int barwidth,
__u32 maxdone, int flags)
{
- ext2_sim_progmeter prog;
+ ext2_sim_progmeter prog;
+ errcode_t retval;
- prog = malloc(sizeof(struct ext2_sim_progress));
+ retval = ext2fs_get_mem(sizeof(struct ext2_sim_progress),
+ (void **) &prog);
if (!prog)
- return ENOMEM;
+ return retval;
memset(prog, 0, sizeof(struct ext2_sim_progress));
- prog->label = malloc(strlen(label)+1);
- if (!prog->label) {
+ retval = ext2fs_get_mem(strlen(label)+1, (void **) &prog->label);
+ if (retval) {
free(prog);
- return ENOMEM;
+ return retval;
}
strcpy(prog->label, label);
prog->labelwidth = labelwidth;
@@ -99,8 +101,8 @@
{
if (prog->label)
- free(prog->label);
- free(prog);
+ ext2fs_free_mem((void **) &prog->label);
+ ext2fs_free_mem((void **) &prog);
printf("\n");
return;
}