1 Upstream-Status: inappropriate
3 From fd1f52c435099eab199f2b06eb411aab337d7f47 Mon Sep 17 00:00:00 2001
4 From: Corey Minyard <cminyard@mvista.com>
5 Date: Tue, 7 Jun 2011 07:29:53 -0500
6 Subject: [PATCH 18/19] Handle files changing while we are working
8 Files may change or be deleted between the lstat and the actual
9 operation to read them and put them into the target filesystem.
10 Handle this more gracefully. Warn on file deletions, and handle
11 whatever size is read, not whatever size happens to be in the
12 inode when we stat-ed it.
14 Also clear the data to the end of an file's last block, to keep
17 genext2fs.c | 30 ++++++++++++++++++------------
18 1 files changed, 18 insertions(+), 12 deletions(-)
20 diff --git a/genext2fs.c b/genext2fs.c
21 index 485393c..28ba94f 100644
24 @@ -1942,19 +1942,30 @@ fs_upgrade_rev1_largefile(filesystem *fs)
26 // make a file from a FILE*
28 -mkfile_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode, off_t size, FILE *f, uid_t uid, gid_t gid, uint32 ctime, uint32 mtime)
29 +mkfile_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode, FILE *f, uid_t uid, gid_t gid, uint32 ctime, uint32 mtime)
32 uint32 nod = mknod_fs(fs, parent_nod, name, mode|FM_IFREG, uid, gid, 0, 0, ctime, mtime);
34 inode *node = get_nod(fs, nod, &ni);
42 error_msg_and_die("mkfile_fs: out of memory");
43 inode_pos_init(fs, &ipos, nod, INODE_POS_TRUNCATE, NULL);
44 + readbytes = fread(b, 1, CB_SIZE, f);
46 + fullsize = rndup(readbytes, BLOCKSIZE);
47 + // Fill to end of block with zeros.
48 + memset(b + readbytes, 0, fullsize - readbytes);
49 + extend_inode_blk(fs, &ipos, b, fullsize / BLOCKSIZE);
51 + readbytes = fread(b, 1, CB_SIZE, f);
53 if (size > 0x7fffffff) {
54 if (fs->sb->s_rev_level < 1)
55 fs_upgrade_rev1_largefile(fs);
56 @@ -1962,15 +1973,6 @@ mkfile_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode, off_
58 node->i_dir_acl = size >> 32;
61 - readbytes = fread(b, 1, CB_SIZE, f);
62 - if ((size < CB_SIZE && readbytes != size)
63 - || (size >= CB_SIZE && readbytes != CB_SIZE))
64 - error_msg_and_die("fread failed");
65 - extend_inode_blk(fs, &ipos, b,
66 - rndup(readbytes, BLOCKSIZE) / BLOCKSIZE);
69 inode_pos_finish(fs, &ipos);
72 @@ -2256,8 +2258,12 @@ add2fs_from_dir(filesystem *fs, uint32 this_nod, int squash_uids, int squash_per
76 - fh = xfopen(dent->d_name, "rb");
77 - nod = mkfile_fs(fs, this_nod, name, mode, st.st_size, fh, uid, gid, ctime, mtime);
78 + fh = fopen(dent->d_name, "rb");
80 + error_msg("Unable to open file %s", dent->d_name);
83 + nod = mkfile_fs(fs, this_nod, name, mode, fh, uid, gid, ctime, mtime);