summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0011-Copy-files-into-the-filesystem-a-piece-at-a-time.patch
diff options
context:
space:
mode:
authorDexuan Cui <dexuan.cui@intel.com>2012-03-29 00:35:09 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-04-02 04:31:48 +0100
commit79c806cb404c2d85aeec45b40ea6adbeae9f6346 (patch)
tree5627bb72a24373b931e6a3d4190335bc904cfd88 /meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0011-Copy-files-into-the-filesystem-a-piece-at-a-time.patch
parent84b7541abc2d7e59c22891219fce97d320d3bb33 (diff)
downloadpoky-79c806cb404c2d85aeec45b40ea6adbeae9f6346.tar.gz
genext2fs: support large files and filesystems without using large amounts of memory
update_to_1.95.patch was generated by making a diff bewteen the 1.4.1 release and the latest 1.9.5 version in the cvs repo: http://genext2fs.cvs.sourceforge.net/viewvc/genext2fs/genext2fs/genext2fs.c?revision=1.95 The patches 0001-0019 come from mailing list of genext2fs-devel http://sourceforge.net/mailarchive/forum.php?forum_name=genext2fs-devel&max_rows=100&style=flat&viewmonth=201106 (From OE-Core rev: 8f17e499cf91191727c8767e839738cb39c21655) Signed-off-by: Dexuan Cui <dexuan.cui@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0011-Copy-files-into-the-filesystem-a-piece-at-a-time.patch')
-rw-r--r--meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0011-Copy-files-into-the-filesystem-a-piece-at-a-time.patch103
1 files changed, 103 insertions, 0 deletions
diff --git a/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0011-Copy-files-into-the-filesystem-a-piece-at-a-time.patch b/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0011-Copy-files-into-the-filesystem-a-piece-at-a-time.patch
new file mode 100644
index 0000000000..52dec56d5f
--- /dev/null
+++ b/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0011-Copy-files-into-the-filesystem-a-piece-at-a-time.patch
@@ -0,0 +1,103 @@
1Upstream-Status: inappropriate
2
3From 0a7d5b11e62e54f88ce3a49d0c2327d537b3f531 Mon Sep 17 00:00:00 2001
4From: Corey Minyard <cminyard@mvista.com>
5Date: Sun, 5 Jun 2011 15:42:24 -0500
6Subject: [PATCH 11/19] Copy files into the filesystem a piece at a time
7
8Instead of malloc-ing and entire files-worth of memory, reading it in,
9and writing it to the filesystem, do it a piece at a time. This allows
10very large files to be supported.
11
12Also, use off_t and make it 64-bits so it supports filesystems and files
13larger than 2GB. Full support for >2GB files is not quite here, that
14requires rev 1 filesystem support, which is coming later.
15---
16 genext2fs.c | 35 +++++++++++++++++++++++------------
17 1 files changed, 23 insertions(+), 12 deletions(-)
18
19diff --git a/genext2fs.c b/genext2fs.c
20index f79438d..8a7f589 100644
21--- a/genext2fs.c
22+++ b/genext2fs.c
23@@ -53,6 +53,12 @@
24 // along with -q, -P, -U
25
26
27+/*
28+ * Allow fseeko/off_t to be 64-bit offsets to allow filesystems and
29+ * individual files >2GB.
30+ */
31+#define _FILE_OFFSET_BITS 64
32+
33 #include <config.h>
34 #include <stdio.h>
35
36@@ -603,7 +609,6 @@ struct hdlinks_s
37 typedef struct
38 {
39 FILE *f;
40- uint8 *data;
41 superblock *sb;
42 groupdescriptor *gd;
43 uint32 nheadblocks;
44@@ -1907,30 +1912,38 @@ mklink_fs(filesystem *fs, uint32 parent_nod, const char *name, size_t size, uint
45 return nod;
46 }
47
48+#define COPY_BLOCKS 16
49+#define CB_SIZE (COPY_BLOCKS * BLOCKSIZE)
50+
51 // make a file from a FILE*
52 static uint32
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)
55 {
56 uint8 * b;
57 uint32 nod = mknod_fs(fs, parent_nod, name, mode|FM_IFREG, uid, gid, 0, 0, ctime, mtime);
58 nod_info *ni;
59 inode *node = get_nod(fs, nod, &ni);
60+ size_t readbytes;
61 inode_pos ipos;
62
63+
64+ b = malloc(CB_SIZE);
65+ if (!b)
66+ error_msg_and_die("mkfile_fs: out of memory");
67 inode_pos_init(fs, &ipos, nod, INODE_POS_TRUNCATE, NULL);
68 node->i_size = size;
69- if (size) {
70- if(!(b = (uint8*)calloc(rndup(size, BLOCKSIZE), 1)))
71- error_msg_and_die("not enough mem to read file '%s'", name);
72- if(f)
73- if (fread(b, size, 1, f) != 1) // FIXME: ugly. use mmap() ...
74- error_msg_and_die("fread failed");
75+ while (size) {
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);
82- free(b);
83+ rndup(readbytes, BLOCKSIZE) / BLOCKSIZE);
84+ size -= readbytes;
85 }
86 inode_pos_finish(fs, &ipos);
87 put_nod(ni);
88+ free(b);
89 return nod;
90 }
91
92@@ -2306,8 +2319,6 @@ alloc_fs(int swapit, char *fname, uint32 nbblocks, FILE *srcfile)
93 if (!fs->hdlinks.hdl)
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);
98
99 if (strcmp(fname, "-") == 0)
100 fs->f = tmpfile();
101--
1021.7.4.1
103