Skip to content

Commit c762c8e

Browse files
committed
Many files:
Checkin of work to date. (Pretty much completely working now.)
1 parent 05e112a commit c762c8e

13 files changed

+1456
-368
lines changed

resize/Makefile.in

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,28 @@ INSTALL = @INSTALL@
1212
@MCONFIG@
1313

1414
PROGS= resize2fs
15+
TEST_PROGS= test_extent
1516
MANPAGES= resize2fs.8
1617

17-
RESIZE_OBJS= inodemap.o resize2fs.o main.o
18+
RESIZE_OBJS= extent.o ext2_block_move.o ext2_inode_move.o resize2fs.o \
19+
main.o sim_progress.o
1820

19-
SRCS= $(srcdir)/inodemap.c \
21+
TEST_EXTENT_OBJS= extent.o test_extent.o
22+
23+
SRCS= $(srcdir)/extent.c \
24+
$(srcdir)/ext2_block_move.c \
25+
$(srcdir)/ext2_inode_move.c \
2026
$(srcdir)/resize2fs.c \
21-
$(srcdir)/main.c
27+
$(srcdir)/main.c \
28+
$(srcdir)/sim_progress.c
2229

23-
LIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBCOM_ERR) $(LIBUUID)
24-
DEPLIBS= $(LIBEXT2FS) $(LIBE2P) $(LIBCOM_ERR) $(LIBUUID)
30+
LIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBUUID)
31+
DEPLIBS= $(LIBEXT2FS) $(LIBCOM_ERR) $(LIBUUID)
2532

2633
.c.o:
2734
$(CC) -c $(ALL_CFLAGS) $< -o $@
2835

29-
all:: $(PROGS) $(MANPAGES)
36+
all:: $(PROGS) $(TEST_PROGS) $(MANPAGES)
3037

3138
resize2fs: $(RESIZE_OBJS) $(DEPLIBS)
3239
$(CC) $(ALL_LDFLAGS) -o resize2fs $(RESIZE_OBJS) $(LIBS)
@@ -35,6 +42,9 @@ resize2fs.8: $(SUBSTITUTE) $(srcdir)/resize2fs.8.in
3542
-$(CHMOD) +x $(SUBSTITUTE)
3643
$(SUBSTITUTE) $(srcdir)/resize2fs.8.in resize2fs.8
3744

45+
test_extent: $(TEST_EXTENT_OBJS)
46+
$(CC) $(ALL_LDFLAGS) -o test_extent $(TEST_EXTENT_OBJS) $(LIBS)
47+
3848
installdirs:
3949
$(top_srcdir)/mkinstalldirs $(DESTDIR)$(usbindir) \
4050
$(DESTDIR)$(man8dir) $(DESTDIR)$(cat8dir)
@@ -56,13 +66,52 @@ uninstall:
5666
$(RM) -f $(man8dir)/$$i; \
5767
done
5868

69+
test_extent.out: test_extent $(srcdir)/test_extent.in
70+
./test_extent < $(srcdir)/test_extent.in > test_extent.out
71+
72+
check: test_extent.out
73+
@if cmp -s test_extent.out $(srcdir)/test_extent.in ; then \
74+
echo "Test succeeded." ; \
75+
else \
76+
echo "Test failed!" ; \
77+
diff test_extent.out $(srcdir)/test_extent.in ; \
78+
exit 1 ; \
79+
fi
80+
5981
clean:
60-
$(RM) -f $(PROGS) $(MANPAGES) \#* *.s *.o *.a *~ core
82+
$(RM) -f $(PROGS) $(TEST_PROGS) $(MANPAGES) \#* *.s *.o *.a *~ core \
83+
test_extent.out
6184

6285
mostlyclean: clean
6386
distclean: clean
6487
$(RM) -f .depend Makefile
6588

89+
#
90+
# Kludge to create a "special" e2fsprogs distribution file.
91+
#
92+
93+
SRCROOT = `echo e2fsprogs-@E2FSPROGS_VERSION@ | sed -e 's/-WIP//' \
94+
-e 's/pre-//' -e 's/-PLUS//'`
95+
TAR=tar
96+
97+
$(top_srcdir)/.exclude-file:
98+
(cd $(top_srcdir)/.. ; find e2fsprogs \( -name \*~ -o -name \*.orig \
99+
-o -name CVS -o -name \*.rej \) -print \
100+
> .exclude-file)
101+
echo "$(SRCROOT)/build" >> $(top_srcdir)/.exclude-file
102+
echo "$(SRCROOT)/rpm.log" >> $(top_srcdir)/.exclude-file
103+
echo "$(SRCROOT)/.exclude-file" >> $(top_srcdir)/.exclude-file
104+
echo $(SRCROOT)/e2fsprogs-@E2FSPROGS_VERSION@.tar.gz \
105+
>> $(top_srcdir)/.exclude-file
106+
107+
source_tar_file: $(top_srcdir)/.exclude-file
108+
(cd $(top_srcdir)/..; a=$(SRCROOT); rm -f $$a ; ln -sf e2fsprogs $$a ; \
109+
$(TAR) -c -h -v -f - \
110+
-X $$a/.exclude-file $$a | \
111+
gzip -9 > e2fsprogs-@E2FSPROGS_VERSION@.tar.gz)
112+
rm -f $(top_srcdir)/.exclude-file
113+
114+
66115
# +++ Dependency line eater +++
67116
#
68117
# Makefile dependencies follow. This must be the last section in

resize/NOTES

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
TODO
22

3-
*) Inode table relocation
4-
5-
*) Inode relocation
6-
7-
*) Summary information collection
8-

resize/ext2_block_move.c

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/*
2+
* ext2_block_move.c --- ext2resizer block mover
3+
*
4+
* Copyright (C) 1997 Theodore Ts'o
5+
*
6+
* %Begin-Header%
7+
* All rights reserved.
8+
* %End-Header%
9+
*/
10+
11+
#include "resize2fs.h"
12+
13+
struct process_block_struct {
14+
ino_t ino;
15+
struct ext2_inode * inode;
16+
ext2_extent bmap;
17+
errcode_t error;
18+
int is_dir;
19+
int flags;
20+
};
21+
22+
static int process_block(ext2_filsys fs, blk_t *block_nr,
23+
int blockcnt, blk_t ref_block,
24+
int ref_offset, void *private)
25+
{
26+
struct process_block_struct *pb = private;
27+
errcode_t retval;
28+
blk_t block, new;
29+
int ret = 0;
30+
31+
block = *block_nr;
32+
33+
new = ext2fs_extent_translate(pb->bmap, block);
34+
if (new) {
35+
*block_nr = new;
36+
ret |= BLOCK_CHANGED;
37+
if (pb->flags & RESIZE_DEBUG_BMOVE)
38+
printf("ino=%ld, blockcnt=%d, %u->%u\n", pb->ino,
39+
blockcnt, block, new);
40+
}
41+
42+
if (pb->is_dir) {
43+
retval = ext2fs_add_dir_block(fs->dblist, pb->ino,
44+
*block_nr, blockcnt);
45+
if (retval) {
46+
pb->error = retval;
47+
ret |= BLOCK_ABORT;
48+
}
49+
}
50+
51+
return ret;
52+
}
53+
54+
errcode_t ext2fs_block_move(ext2_resize_t rfs)
55+
{
56+
ext2_extent bmap;
57+
blk_t blk, old, new;
58+
ext2_filsys fs = rfs->new_fs;
59+
ext2_filsys old_fs = rfs->old_fs;
60+
ino_t ino;
61+
struct ext2_inode inode;
62+
errcode_t retval;
63+
struct process_block_struct pb;
64+
ext2_inode_scan scan = 0;
65+
char *block_buf;
66+
int size, c;
67+
int to_move, moved;
68+
ext2_sim_progmeter progress = 0;
69+
70+
new = fs->super->s_first_data_block;
71+
if (!rfs->itable_buf) {
72+
rfs->itable_buf = malloc(fs->blocksize *
73+
fs->inode_blocks_per_group);
74+
if (!rfs->itable_buf)
75+
return ENOMEM;
76+
}
77+
retval = ext2fs_create_extent_table(&bmap, 0);
78+
if (retval)
79+
return retval;
80+
81+
/*
82+
* The first step is to figure out where all of the blocks
83+
* will go.
84+
*/
85+
to_move = moved = 0;
86+
for (blk = old_fs->super->s_first_data_block;
87+
blk < old_fs->super->s_blocks_count; blk++) {
88+
if (!ext2fs_test_block_bitmap(old_fs->block_map, blk))
89+
continue;
90+
if (!ext2fs_test_block_bitmap(rfs->move_blocks, blk))
91+
continue;
92+
93+
while (1) {
94+
if (new >= fs->super->s_blocks_count) {
95+
retval = ENOSPC;
96+
goto errout;
97+
}
98+
if (!ext2fs_test_block_bitmap(fs->block_map, new) &&
99+
!ext2fs_test_block_bitmap(rfs->reserve_blocks,
100+
new))
101+
break;
102+
new++;
103+
}
104+
ext2fs_mark_block_bitmap(fs->block_map, new);
105+
ext2fs_add_extent_entry(bmap, blk, new);
106+
to_move++;
107+
}
108+
if (to_move == 0)
109+
return 0;
110+
/*
111+
* Step two is to actually move the blocks
112+
*/
113+
retval = ext2fs_iterate_extent(bmap, 0, 0, 0);
114+
if (retval) goto errout;
115+
116+
if (rfs->flags & RESIZE_PERCENT_COMPLETE) {
117+
retval = ext2fs_progress_init(&progress,
118+
"Relocating blocks", 30, 40, to_move, 0);
119+
if (retval)
120+
return retval;
121+
}
122+
123+
while (1) {
124+
retval = ext2fs_iterate_extent(bmap, &old, &new, &size);
125+
if (retval) goto errout;
126+
if (!size)
127+
break;
128+
if (rfs->flags & RESIZE_DEBUG_BMOVE)
129+
printf("Moving %d blocks %u->%u\n", size,
130+
old, new);
131+
do {
132+
c = size;
133+
if (c > fs->inode_blocks_per_group)
134+
c = fs->inode_blocks_per_group;
135+
retval = io_channel_read_blk(fs->io, old, c,
136+
rfs->itable_buf);
137+
if (retval) goto errout;
138+
retval = io_channel_write_blk(fs->io, new, c,
139+
rfs->itable_buf);
140+
if (retval) goto errout;
141+
size -= c;
142+
new += c;
143+
old += c;
144+
moved += c;
145+
io_channel_flush(fs->io);
146+
if (progress)
147+
ext2fs_progress_update(progress, moved);
148+
} while (size > 0);
149+
io_channel_flush(fs->io);
150+
}
151+
if (progress) {
152+
ext2fs_progress_close(progress);
153+
progress = 0;
154+
}
155+
156+
/*
157+
* Step 3 is where we update the block pointers
158+
*/
159+
retval = ext2fs_open_inode_scan(old_fs, 0, &scan);
160+
if (retval) goto errout;
161+
162+
pb.error = 0;
163+
pb.bmap = bmap;
164+
pb.flags = rfs->flags;
165+
166+
block_buf = malloc(old_fs->blocksize * 3);
167+
if (!block_buf) {
168+
retval = ENOMEM;
169+
goto errout;
170+
}
171+
172+
/*
173+
* We're going to initialize the dblist while we're at it.
174+
*/
175+
if (old_fs->dblist) {
176+
ext2fs_free_dblist(old_fs->dblist);
177+
old_fs->dblist = NULL;
178+
}
179+
retval = ext2fs_init_dblist(old_fs, 0);
180+
if (retval)
181+
return retval;
182+
183+
retval = ext2fs_get_next_inode(scan, &ino, &inode);
184+
if (retval) goto errout;
185+
186+
if (rfs->flags & RESIZE_PERCENT_COMPLETE) {
187+
retval = ext2fs_progress_init(&progress,
188+
"Updating block references", 30, 40,
189+
old_fs->super->s_inodes_count, 0);
190+
if (retval)
191+
return retval;
192+
}
193+
194+
while (ino) {
195+
if ((inode.i_links_count == 0) ||
196+
!ext2fs_inode_has_valid_blocks(&inode))
197+
goto next;
198+
199+
pb.ino = ino;
200+
pb.inode = &inode;
201+
202+
pb.is_dir = LINUX_S_ISDIR(inode.i_mode);
203+
204+
retval = ext2fs_block_iterate2(old_fs, ino, 0, block_buf,
205+
process_block, &pb);
206+
if (retval)
207+
goto errout;
208+
if (pb.error) {
209+
retval = pb.error;
210+
goto errout;
211+
}
212+
213+
next:
214+
if (progress)
215+
ext2fs_progress_update(progress, ino);
216+
retval = ext2fs_get_next_inode(scan, &ino, &inode);
217+
if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE)
218+
goto next;
219+
}
220+
retval = 0;
221+
errout:
222+
if (progress)
223+
ext2fs_progress_close(progress);
224+
225+
ext2fs_free_extent_table(bmap);
226+
if (scan)
227+
ext2fs_close_inode_scan(scan);
228+
return retval;
229+
}
230+

0 commit comments

Comments
 (0)