summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0005-Make-filesystem-struct-not-an-overloay.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/0005-Make-filesystem-struct-not-an-overloay.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/0005-Make-filesystem-struct-not-an-overloay.patch')
-rw-r--r--meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0005-Make-filesystem-struct-not-an-overloay.patch374
1 files changed, 374 insertions, 0 deletions
diff --git a/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0005-Make-filesystem-struct-not-an-overloay.patch b/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0005-Make-filesystem-struct-not-an-overloay.patch
new file mode 100644
index 0000000000..ccc33feaac
--- /dev/null
+++ b/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0005-Make-filesystem-struct-not-an-overloay.patch
@@ -0,0 +1,374 @@
1Upstream-Status: inappropriate
2
3From f2090608aef32f3012b1c5943b73314176bce832 Mon Sep 17 00:00:00 2001
4From: Corey Minyard <cminyard@mvista.com>
5Date: Sun, 5 Jun 2011 10:09:51 -0500
6Subject: [PATCH 05/19] Make filesystem struct not an overloay
7
8Having the filesystem structure just be a big overlay for the raw data
9means you can't easily carry along any useful metadata in it. So
10modify the filesystem structure to not be an overlay, but allocate the
11data and various pieces to be components inside the structure.
12---
13 genext2fs.c | 150 +++++++++++++++++++++++++++++++++--------------------------
14 1 files changed, 84 insertions(+), 66 deletions(-)
15
16diff --git a/genext2fs.c b/genext2fs.c
17index 03d1b27..46c9605 100644
18--- a/genext2fs.c
19+++ b/genext2fs.c
20@@ -233,8 +233,8 @@ struct stats {
21
22 // Number of groups in the filesystem
23 #define GRP_NBGROUPS(fs) \
24- (((fs)->sb.s_blocks_count - fs->sb.s_first_data_block + \
25- (fs)->sb.s_blocks_per_group - 1) / (fs)->sb.s_blocks_per_group)
26+ (((fs)->sb->s_blocks_count - fs->sb->s_first_data_block + \
27+ (fs)->sb->s_blocks_per_group - 1) / (fs)->sb->s_blocks_per_group)
28
29 // Get/put group block bitmap (bbm) given the group number
30 #define GRP_GET_GROUP_BBM(fs,grp,bi) ( get_blk((fs),(fs)->gd[(grp)].bg_block_bitmap,(bi)) )
31@@ -245,7 +245,7 @@ struct stats {
32 #define GRP_PUT_GROUP_IBM(bi) ( put_blk((bi)) )
33
34 // Given an inode number find the group it belongs to
35-#define GRP_GROUP_OF_INODE(fs,nod) ( ((nod)-1) / (fs)->sb.s_inodes_per_group)
36+#define GRP_GROUP_OF_INODE(fs,nod) ( ((nod)-1) / (fs)->sb->s_inodes_per_group)
37
38 //Given an inode number get/put the inode bitmap that covers it
39 #define GRP_GET_INODE_BITMAP(fs,nod,bi) \
40@@ -255,10 +255,10 @@ struct stats {
41
42 //Given an inode number find its offset within the inode bitmap that covers it
43 #define GRP_IBM_OFFSET(fs,nod) \
44- ( (nod) - GRP_GROUP_OF_INODE((fs),(nod))*(fs)->sb.s_inodes_per_group )
45+ ( (nod) - GRP_GROUP_OF_INODE((fs),(nod))*(fs)->sb->s_inodes_per_group )
46
47 // Given a block number find the group it belongs to
48-#define GRP_GROUP_OF_BLOCK(fs,blk) ( ((blk)-1) / (fs)->sb.s_blocks_per_group)
49+#define GRP_GROUP_OF_BLOCK(fs,blk) ( ((blk)-1) / (fs)->sb->s_blocks_per_group)
50
51 //Given a block number get/put the block bitmap that covers it
52 #define GRP_GET_BLOCK_BITMAP(fs,blk,bi) \
53@@ -268,7 +268,7 @@ struct stats {
54
55 //Given a block number find its offset within the block bitmap that covers it
56 #define GRP_BBM_OFFSET(fs,blk) \
57- ( (blk) - GRP_GROUP_OF_BLOCK((fs),(blk))*(fs)->sb.s_blocks_per_group )
58+ ( (blk) - GRP_GROUP_OF_BLOCK((fs),(blk))*(fs)->sb->s_blocks_per_group )
59
60
61 // used types
62@@ -577,9 +577,10 @@ typedef struct
63 #if BLOCKSIZE == 1024
64 typedef struct
65 {
66- block zero; // The famous block 0
67- superblock sb; // The superblock
68- groupdescriptor gd[0]; // The group descriptors
69+ uint8 *data;
70+ superblock *sb;
71+ groupdescriptor *gd;
72+ uint32 nheadblocks;
73 } filesystem;
74 #else
75 #error UNHANDLED BLOCKSIZE
76@@ -830,7 +831,7 @@ typedef struct
77 static inline uint8 *
78 get_blk(filesystem *fs, uint32 blk, blk_info **rbi)
79 {
80- return (uint8*)fs + blk*BLOCKSIZE;
81+ return fs->data + blk*BLOCKSIZE;
82 }
83
84 static inline void
85@@ -1079,9 +1080,9 @@ alloc_blk(filesystem *fs, uint32 nod)
86 error_msg_and_die("couldn't allocate a block (no free space)");
87 if(!(fs->gd[grp].bg_free_blocks_count--))
88 error_msg_and_die("group descr %d. free blocks count == 0 (corrupted fs?)",grp);
89- if(!(fs->sb.s_free_blocks_count--))
90+ if(!(fs->sb->s_free_blocks_count--))
91 error_msg_and_die("superblock free blocks count == 0 (corrupted fs?)");
92- return fs->sb.s_blocks_per_group*grp + bk;
93+ return fs->sb->s_blocks_per_group*grp + bk;
94 }
95
96 // free a block
97@@ -1091,12 +1092,12 @@ free_blk(filesystem *fs, uint32 bk)
98 uint32 grp;
99 blk_info *bi;
100
101- grp = bk / fs->sb.s_blocks_per_group;
102- bk %= fs->sb.s_blocks_per_group;
103+ grp = bk / fs->sb->s_blocks_per_group;
104+ bk %= fs->sb->s_blocks_per_group;
105 deallocate(get_blk(fs, fs->gd[grp].bg_block_bitmap, &bi), bk);
106 put_blk(bi);
107 fs->gd[grp].bg_free_blocks_count++;
108- fs->sb.s_free_blocks_count++;
109+ fs->sb->s_free_blocks_count++;
110 }
111
112 // allocate an inode
113@@ -1114,7 +1115,7 @@ alloc_nod(filesystem *fs)
114 /* find the one with the most free blocks and allocate node there */
115 /* Idea from find_group_dir in fs/ext2/ialloc.c in 2.4.19 kernel */
116 /* We do it for all inodes. */
117- avefreei = fs->sb.s_free_inodes_count / nbgroups;
118+ avefreei = fs->sb->s_free_inodes_count / nbgroups;
119 for(grp=0; grp<nbgroups; grp++) {
120 if (fs->gd[grp].bg_free_inodes_count < avefreei ||
121 fs->gd[grp].bg_free_inodes_count == 0)
122@@ -1129,9 +1130,9 @@ alloc_nod(filesystem *fs)
123 put_blk(bi);
124 if(!(fs->gd[best_group].bg_free_inodes_count--))
125 error_msg_and_die("group descr. free blocks count == 0 (corrupted fs?)");
126- if(!(fs->sb.s_free_inodes_count--))
127+ if(!(fs->sb->s_free_inodes_count--))
128 error_msg_and_die("superblock free blocks count == 0 (corrupted fs?)");
129- return fs->sb.s_inodes_per_group*best_group+nod;
130+ return fs->sb->s_inodes_per_group*best_group+nod;
131 }
132
133 // print a bitmap allocation
134@@ -1451,7 +1452,7 @@ extend_blk(filesystem *fs, uint32 nod, block b, int amount)
135 while(create)
136 {
137 int i, copyb = 0;
138- if(!(fs->sb.s_reserved[200] & OP_HOLES))
139+ if(!(fs->sb->s_reserved[200] & OP_HOLES))
140 copyb = 1;
141 else
142 for(i = 0; i < BLOCKSIZE / 4; i++)
143@@ -2133,7 +2134,7 @@ swap_goodfs(filesystem *fs)
144 uint32 i;
145 nod_info *ni;
146
147- for(i = 1; i < fs->sb.s_inodes_count; i++)
148+ for(i = 1; i < fs->sb->s_inodes_count; i++)
149 {
150 inode *nod = get_nod(fs, i, &ni);
151 if(nod->i_mode & FM_IFDIR)
152@@ -2158,17 +2159,17 @@ swap_goodfs(filesystem *fs)
153 }
154 for(i=0;i<GRP_NBGROUPS(fs);i++)
155 swap_gd(&(fs->gd[i]));
156- swap_sb(&fs->sb);
157+ swap_sb(fs->sb);
158 }
159
160 static void
161 swap_badfs(filesystem *fs)
162 {
163 uint32 i;
164- swap_sb(&fs->sb);
165+ swap_sb(fs->sb);
166 for(i=0;i<GRP_NBGROUPS(fs);i++)
167 swap_gd(&(fs->gd[i]));
168- for(i = 1; i < fs->sb.s_inodes_count; i++)
169+ for(i = 1; i < fs->sb->s_inodes_count; i++)
170 {
171 nod_info *ni;
172 inode *nod = get_nod(fs, i, &ni);
173@@ -2242,24 +2243,32 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
174 free_blocks = nbblocks - overhead_per_group*nbgroups - 1 /*boot block*/;
175 free_blocks_per_group = nbblocks_per_group - overhead_per_group;
176
177- if(!(fs = (filesystem*)calloc(nbblocks, BLOCKSIZE)))
178+ fs = malloc(sizeof(*fs));
179+ if (!fs)
180 error_msg_and_die("not enough memory for filesystem");
181+ fs->nheadblocks = (((nbgroups * sizeof(groupdescriptor))
182+ + sizeof(superblock) + (BLOCKSIZE - 1))
183+ / BLOCKSIZE);
184+ if(!(fs->data = calloc(nbblocks, BLOCKSIZE)))
185+ error_msg_and_die("not enough memory for filesystem");
186+ fs->sb = (superblock *) (fs->data + BLOCKSIZE);
187+ fs->gd = (groupdescriptor *) (fs->sb + 1);
188
189 // create the superblock for an empty filesystem
190- fs->sb.s_inodes_count = nbinodes_per_group * nbgroups;
191- fs->sb.s_blocks_count = nbblocks;
192- fs->sb.s_r_blocks_count = nbresrvd;
193- fs->sb.s_free_blocks_count = free_blocks;
194- fs->sb.s_free_inodes_count = fs->sb.s_inodes_count - EXT2_FIRST_INO + 1;
195- fs->sb.s_first_data_block = first_block;
196- fs->sb.s_log_block_size = BLOCKSIZE >> 11;
197- fs->sb.s_log_frag_size = BLOCKSIZE >> 11;
198- fs->sb.s_blocks_per_group = nbblocks_per_group;
199- fs->sb.s_frags_per_group = nbblocks_per_group;
200- fs->sb.s_inodes_per_group = nbinodes_per_group;
201- fs->sb.s_wtime = fs_timestamp;
202- fs->sb.s_magic = EXT2_MAGIC_NUMBER;
203- fs->sb.s_lastcheck = fs_timestamp;
204+ fs->sb->s_inodes_count = nbinodes_per_group * nbgroups;
205+ fs->sb->s_blocks_count = nbblocks;
206+ fs->sb->s_r_blocks_count = nbresrvd;
207+ fs->sb->s_free_blocks_count = free_blocks;
208+ fs->sb->s_free_inodes_count = fs->sb->s_inodes_count - EXT2_FIRST_INO + 1;
209+ fs->sb->s_first_data_block = first_block;
210+ fs->sb->s_log_block_size = BLOCKSIZE >> 11;
211+ fs->sb->s_log_frag_size = BLOCKSIZE >> 11;
212+ fs->sb->s_blocks_per_group = nbblocks_per_group;
213+ fs->sb->s_frags_per_group = nbblocks_per_group;
214+ fs->sb->s_inodes_per_group = nbinodes_per_group;
215+ fs->sb->s_wtime = fs_timestamp;
216+ fs->sb->s_magic = EXT2_MAGIC_NUMBER;
217+ fs->sb->s_lastcheck = fs_timestamp;
218
219 // set up groupdescriptors
220 for(i=0, bbmpos=gdsz+2, ibmpos=bbmpos+1, itblpos=ibmpos+1;
221@@ -2301,7 +2310,7 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
222 /* Inode bitmap */
223 ibm = get_blk(fs,fs->gd[i].bg_inode_bitmap, &bi);
224 //non-filesystem inodes
225- for(j = fs->sb.s_inodes_per_group+1; j <= BLOCKSIZE * 8; j++)
226+ for(j = fs->sb->s_inodes_per_group+1; j <= BLOCKSIZE * 8; j++)
227 allocate(ibm, j);
228
229 //system inodes
230@@ -2332,7 +2341,7 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
231 put_dir(&dw);
232
233 // make lost+found directory and reserve blocks
234- if(fs->sb.s_r_blocks_count)
235+ if(fs->sb->s_r_blocks_count)
236 {
237 inode *node;
238 uint8 *b;
239@@ -2344,23 +2353,23 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
240 /* We run into problems with e2fsck if directory lost+found grows
241 * bigger than this. Need to find out why this happens - sundar
242 */
243- if (fs->sb.s_r_blocks_count > fs->sb.s_blocks_count * MAX_RESERVED_BLOCKS )
244- fs->sb.s_r_blocks_count = fs->sb.s_blocks_count * MAX_RESERVED_BLOCKS;
245- for(i = 1; i < fs->sb.s_r_blocks_count; i++)
246+ if (fs->sb->s_r_blocks_count > fs->sb->s_blocks_count * MAX_RESERVED_BLOCKS )
247+ fs->sb->s_r_blocks_count = fs->sb->s_blocks_count * MAX_RESERVED_BLOCKS;
248+ for(i = 1; i < fs->sb->s_r_blocks_count; i++)
249 extend_blk(fs, nod, b, 1);
250 free_workblk(b);
251 node = get_nod(fs, nod, &ni);
252- node->i_size = fs->sb.s_r_blocks_count * BLOCKSIZE;
253+ node->i_size = fs->sb->s_r_blocks_count * BLOCKSIZE;
254 put_nod(ni);
255 }
256
257 // administrative info
258- fs->sb.s_state = 1;
259- fs->sb.s_max_mnt_count = 20;
260+ fs->sb->s_state = 1;
261+ fs->sb->s_max_mnt_count = 20;
262
263 // options for me
264 if(holes)
265- fs->sb.s_reserved[200] |= OP_HOLES;
266+ fs->sb->s_reserved[200] |= OP_HOLES;
267
268 return fs;
269 }
270@@ -2377,20 +2386,29 @@ load_fs(FILE * fh, int swapit)
271 fssize = (fssize + BLOCKSIZE - 1) / BLOCKSIZE;
272 if(fssize < 16) // totally arbitrary
273 error_msg_and_die("too small filesystem");
274- if(!(fs = (filesystem*)calloc(fssize, BLOCKSIZE)))
275+ fs = malloc(sizeof(*fs));
276+ if (!fs)
277+ error_msg_and_die("not enough memory for filesystem");
278+ if(!(fs->data = calloc(fssize, BLOCKSIZE)))
279 error_msg_and_die("not enough memory for filesystem");
280- if(fread(fs, BLOCKSIZE, fssize, fh) != fssize)
281+ if(fread(fs->data, BLOCKSIZE, fssize, fh) != fssize)
282 perror_msg_and_die("input filesystem image");
283+ fs->sb = (superblock *) (fs->data + BLOCKSIZE);
284+ fs->gd = (groupdescriptor *) (fs->sb + 1);
285 if(swapit)
286 swap_badfs(fs);
287- if(fs->sb.s_rev_level || (fs->sb.s_magic != EXT2_MAGIC_NUMBER))
288+ if(fs->sb->s_rev_level || (fs->sb->s_magic != EXT2_MAGIC_NUMBER))
289 error_msg_and_die("not a suitable ext2 filesystem");
290+ fs->nheadblocks = (((GRP_NBGROUPS(fs) * sizeof(groupdescriptor))
291+ + sizeof(superblock) + (BLOCKSIZE - 1))
292+ / BLOCKSIZE);
293 return fs;
294 }
295
296 static void
297 free_fs(filesystem *fs)
298 {
299+ free(fs->data);
300 free(fs);
301 }
302
303@@ -2645,19 +2663,19 @@ print_fs(filesystem *fs)
304 uint8 *ibm;
305
306 printf("%d blocks (%d free, %d reserved), first data block: %d\n",
307- fs->sb.s_blocks_count, fs->sb.s_free_blocks_count,
308- fs->sb.s_r_blocks_count, fs->sb.s_first_data_block);
309- printf("%d inodes (%d free)\n", fs->sb.s_inodes_count,
310- fs->sb.s_free_inodes_count);
311+ fs->sb->s_blocks_count, fs->sb->s_free_blocks_count,
312+ fs->sb->s_r_blocks_count, fs->sb->s_first_data_block);
313+ printf("%d inodes (%d free)\n", fs->sb->s_inodes_count,
314+ fs->sb->s_free_inodes_count);
315 printf("block size = %d, frag size = %d\n",
316- fs->sb.s_log_block_size ? (fs->sb.s_log_block_size << 11) : 1024,
317- fs->sb.s_log_frag_size ? (fs->sb.s_log_frag_size << 11) : 1024);
318+ fs->sb->s_log_block_size ? (fs->sb->s_log_block_size << 11) : 1024,
319+ fs->sb->s_log_frag_size ? (fs->sb->s_log_frag_size << 11) : 1024);
320 printf("number of groups: %d\n",GRP_NBGROUPS(fs));
321 printf("%d blocks per group,%d frags per group,%d inodes per group\n",
322- fs->sb.s_blocks_per_group, fs->sb.s_frags_per_group,
323- fs->sb.s_inodes_per_group);
324+ fs->sb->s_blocks_per_group, fs->sb->s_frags_per_group,
325+ fs->sb->s_inodes_per_group);
326 printf("Size of inode table: %d blocks\n",
327- (int)(fs->sb.s_inodes_per_group * sizeof(inode) / BLOCKSIZE));
328+ (int)(fs->sb->s_inodes_per_group * sizeof(inode) / BLOCKSIZE));
329 for (i = 0; i < GRP_NBGROUPS(fs); i++) {
330 printf("Group No: %d\n", i+1);
331 printf("block bitmap: block %d,inode bitmap: block %d, inode table: block %d\n",
332@@ -2665,12 +2683,12 @@ print_fs(filesystem *fs)
333 fs->gd[i].bg_inode_table);
334 printf("block bitmap allocation:\n");
335 print_bm(GRP_GET_GROUP_BBM(fs, i, &bi),
336- fs->sb.s_blocks_per_group);
337+ fs->sb->s_blocks_per_group);
338 GRP_PUT_GROUP_BBM(bi);
339 printf("inode bitmap allocation:\n");
340 ibm = GRP_GET_GROUP_IBM(fs, i, &bi);
341- print_bm(ibm, fs->sb.s_inodes_per_group);
342- for (i = 1; i <= fs->sb.s_inodes_per_group; i++)
343+ print_bm(ibm, fs->sb->s_inodes_per_group);
344+ for (i = 1; i <= fs->sb->s_inodes_per_group; i++)
345 if (allocated(ibm, i))
346 print_inode(fs, i);
347 GRP_PUT_GROUP_IBM(bi);
348@@ -2680,11 +2698,11 @@ print_fs(filesystem *fs)
349 static void
350 dump_fs(filesystem *fs, FILE * fh, int swapit)
351 {
352- uint32 nbblocks = fs->sb.s_blocks_count;
353- fs->sb.s_reserved[200] = 0;
354+ uint32 nbblocks = fs->sb->s_blocks_count;
355+ fs->sb->s_reserved[200] = 0;
356 if(swapit)
357 swap_goodfs(fs);
358- if(fwrite(fs, BLOCKSIZE, nbblocks, fh) < nbblocks)
359+ if(fwrite(fs->data, BLOCKSIZE, nbblocks, fh) < nbblocks)
360 perror_msg_and_die("output filesystem image");
361 if(swapit)
362 swap_badfs(fs);
363@@ -2944,7 +2962,7 @@ main(int argc, char **argv)
364
365 if(emptyval) {
366 uint32 b;
367- for(b = 1; b < fs->sb.s_blocks_count; b++) {
368+ for(b = 1; b < fs->sb->s_blocks_count; b++) {
369 blk_info *bi;
370 if(!allocated(GRP_GET_BLOCK_BITMAP(fs,b,&bi),
371 GRP_BBM_OFFSET(fs,b))) {
372--
3731.7.4.1
374