1 Upstream-Status: inappropriate
3 From 0a7d5b11e62e54f88ce3a49d0c2327d537b3f531 Mon Sep 17 00:00:00 2001
4 From: Corey Minyard <cminyard@mvista.com>
5 Date: Sun, 5 Jun 2011 15:42:24 -0500
6 Subject: [PATCH 11/19] Copy files into the filesystem a piece at a time
8 Instead of malloc-ing and entire files-worth of memory, reading it in,
9 and writing it to the filesystem, do it a piece at a time. This allows
10 very large files to be supported.
12 Also, use off_t and make it 64-bits so it supports filesystems and files
13 larger than 2GB. Full support for >2GB files is not quite here, that
14 requires rev 1 filesystem support, which is coming later.
16 genext2fs.c | 35 +++++++++++++++++++++++------------
17 1 files changed, 23 insertions(+), 12 deletions(-)
19 diff --git a/genext2fs.c b/genext2fs.c
20 index f79438d..8a7f589 100644
24 // along with -q, -P, -U
28 + * Allow fseeko/off_t to be 64-bit offsets to allow filesystems and
29 + * individual files >2GB.
31 +#define _FILE_OFFSET_BITS 64
36 @@ -603,7 +609,6 @@ struct hdlinks_s
44 @@ -1907,30 +1912,38 @@ mklink_fs(filesystem *fs, uint32 parent_nod, const char *name, size_t size, uint
48 +#define COPY_BLOCKS 16
49 +#define CB_SIZE (COPY_BLOCKS * BLOCKSIZE)
51 // make a file from a FILE*
53 -mkfile_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode, size_t size, FILE *f, uid_t uid, gid_t gid, uint32 ctime, uint32 mtime)
54 +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)
57 uint32 nod = mknod_fs(fs, parent_nod, name, mode|FM_IFREG, uid, gid, 0, 0, ctime, mtime);
59 inode *node = get_nod(fs, nod, &ni);
64 + b = malloc(CB_SIZE);
66 + error_msg_and_die("mkfile_fs: out of memory");
67 inode_pos_init(fs, &ipos, nod, INODE_POS_TRUNCATE, NULL);
70 - if(!(b = (uint8*)calloc(rndup(size, BLOCKSIZE), 1)))
71 - error_msg_and_die("not enough mem to read file '%s'", name);
73 - if (fread(b, size, 1, f) != 1) // FIXME: ugly. use mmap() ...
74 - error_msg_and_die("fread failed");
76 + readbytes = fread(b, 1, CB_SIZE, f);
77 + if ((size < CB_SIZE && readbytes != size)
78 + || (size >= CB_SIZE && readbytes != CB_SIZE))
79 + error_msg_and_die("fread failed");
80 extend_inode_blk(fs, &ipos, b,
81 - rndup(size, BLOCKSIZE) / BLOCKSIZE);
83 + rndup(readbytes, BLOCKSIZE) / BLOCKSIZE);
86 inode_pos_finish(fs, &ipos);
92 @@ -2306,8 +2319,6 @@ alloc_fs(int swapit, char *fname, uint32 nbblocks, FILE *srcfile)
94 error_msg_and_die("Not enough memory");
95 fs->hdlinks.count = 0 ;
96 - fs->sb = (superblock *) (fs->data + BLOCKSIZE);
97 - fs->gd = (groupdescriptor *) (fs->sb + 1);
99 if (strcmp(fname, "-") == 0)