summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0003-Add-get_blkmap-and-put_blkmap.patch
blob: 1442dfaaed20893f9826ba0fc1cc15dc42a0b156 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
Upstream-Status: inappropriate

From c196bdeae7932c5d54bbdb7e7574d3cdae46ad02 Mon Sep 17 00:00:00 2001
From: Corey Minyard <cminyard@mvista.com>
Date: Sat, 4 Jun 2011 22:04:24 -0500
Subject: [PATCH 03/19] Add get_blkmap and put_blkmap.

Add routines for getting an putting a block map.  This does not do
anything functional, but is getting ready for when blockmaps are
byteswapped when being read and written.
---
 genext2fs.c |   84 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 57 insertions(+), 27 deletions(-)

diff --git a/genext2fs.c b/genext2fs.c
index bd06369..0b5ba6f 100644
--- a/genext2fs.c
+++ b/genext2fs.c
@@ -837,6 +837,36 @@ put_blk(blk_info *bi)
 {
 }
 
+// Used by get_blkmap/put_blkmap to hold information about an block map
+// owned by the user.
+typedef struct
+{
+	blk_info *bi;
+} blkmap_info;
+
+// Return a given block map from a filesystem.  Make sure to call
+// put_blkmap when you are done with it.
+static inline uint32 *
+get_blkmap(filesystem *fs, uint32 blk, blkmap_info **rbmi)
+{
+	blkmap_info *bmi;
+	uint8 *b;
+
+	bmi = malloc(sizeof(*bmi));
+	if (!bmi)
+		error_msg_and_die("get_blkmap: out of memory");
+	b = get_blk(fs, blk, &bmi->bi);
+	*rbmi = bmi;
+	return (uint32 *) b;
+}
+
+static inline void
+put_blkmap(blkmap_info *bmi)
+{
+	put_blk(bmi->bi);
+	free(bmi);
+}
+
 // Used by get_nod/put_nod to hold information about an inode owned
 // by the user.
 typedef struct
@@ -1020,12 +1050,12 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 {
 	uint32 *bkref = 0;
 	uint32 bk = 0;
+	blkmap_info *bmi1 = NULL, *bmi2 = NULL, *bmi3 = NULL;
 	uint32 *b;
 	int extend = 0, reduce = 0;
 	inode *inod;
 	nod_info *ni;
 	uint32 *iblk;
-	blk_info *bi1 = NULL, *bi2 = NULL, *bi3 = NULL;
 
 	if(create && (*create) < 0)
 		reduce = 1;
@@ -1072,7 +1102,7 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 			iblk[bw->bpdir] = alloc_blk(fs,nod);
 		if(reduce) // free indirect block
 			free_blk(fs, iblk[bw->bpdir]);
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
 		bkref = &b[bw->bpind];
 		if(extend) // allocate first block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1083,7 +1113,7 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 	else if((bw->bpdir == EXT2_IND_BLOCK) && (bw->bpind < BLOCKSIZE/4 - 1))
 	{
 		bw->bpind++;
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
 		bkref = &b[bw->bpind];
 		if(extend) // allocate block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1101,12 +1131,12 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 			iblk[bw->bpdir] = alloc_blk(fs,nod);
 		if(reduce) // free double indirect block
 			free_blk(fs, iblk[bw->bpdir]);
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
 		if(extend) // allocate first indirect block
 			b[bw->bpind] = alloc_blk(fs,nod);
 		if(reduce) // free  firstindirect block
 			free_blk(fs, b[bw->bpind]);
-		b = (uint32*)get_blk(fs, b[bw->bpind], &bi1);
+		b = get_blkmap(fs, b[bw->bpind], &bmi2);
 		bkref = &b[bw->bpdind];
 		if(extend) // allocate first block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1117,8 +1147,8 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 	else if((bw->bpdir == EXT2_DIND_BLOCK) && (bw->bpdind < BLOCKSIZE/4 - 1))
 	{
 		bw->bpdind++;
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
-		b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
+		b = get_blkmap(fs, b[bw->bpind], &bmi2);
 		bkref = &b[bw->bpdind];
 		if(extend) // allocate block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1131,12 +1161,12 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 		bw->bnum++;
 		bw->bpdind = 0;
 		bw->bpind++;
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
 		if(extend) // allocate indirect block
 			b[bw->bpind] = alloc_blk(fs,nod);
 		if(reduce) // free indirect block
 			free_blk(fs, b[bw->bpind]);
-		b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
+		b = get_blkmap(fs, b[bw->bpind], &bmi2);
 		bkref = &b[bw->bpdind];
 		if(extend) // allocate first block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1159,17 +1189,17 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 			iblk[bw->bpdir] = alloc_blk(fs,nod);
 		if(reduce) // free triple indirect block
 			free_blk(fs, iblk[bw->bpdir]);
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
 		if(extend) // allocate first double indirect block
 			b[bw->bpind] = alloc_blk(fs,nod);
 		if(reduce) // free first double indirect block
 			free_blk(fs, b[bw->bpind]);
-		b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
+		b = get_blkmap(fs, b[bw->bpind], &bmi2);
 		if(extend) // allocate first indirect block
 			b[bw->bpdind] = alloc_blk(fs,nod);
 		if(reduce) // free first indirect block
 			free_blk(fs, b[bw->bpind]);
-		b = (uint32*)get_blk(fs, b[bw->bpdind], &bi3);
+		b = get_blkmap(fs, b[bw->bpdind], &bmi3);
 		bkref = &b[bw->bptind];
 		if(extend) // allocate first data block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1183,9 +1213,9 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 		  (bw->bptind < BLOCKSIZE/4 -1) )
 	{
 		bw->bptind++;
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
-		b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
-		b = (uint32*)get_blk(fs, b[bw->bpdind], &bi3);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
+		b = get_blkmap(fs, b[bw->bpind], &bmi2);
+		b = get_blkmap(fs, b[bw->bpdind], &bmi3);
 		bkref = &b[bw->bptind];
 		if(extend) // allocate data block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1202,13 +1232,13 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 		bw->bnum++;
 		bw->bptind = 0;
 		bw->bpdind++;
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
-		b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
+		b = get_blkmap(fs, b[bw->bpind], &bmi2);
 		if(extend) // allocate single indirect block
 			b[bw->bpdind] = alloc_blk(fs,nod);
 		if(reduce) // free indirect block
 			free_blk(fs, b[bw->bpind]);
-		b = (uint32*)get_blk(fs, b[bw->bpdind], &bi3);
+		b = get_blkmap(fs, b[bw->bpdind], &bmi3);
 		bkref = &b[bw->bptind];
 		if(extend) // allocate first data block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1225,17 +1255,17 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 		bw->bpdind = 0;
 		bw->bptind = 0;
 		bw->bpind++;
-		b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
+		b = get_blkmap(fs, iblk[bw->bpdir], &bmi1);
 		if(extend) // allocate double indirect block
 			b[bw->bpind] = alloc_blk(fs,nod);
 		if(reduce) // free double indirect block
 			free_blk(fs, b[bw->bpind]);
-		b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
+		b = get_blkmap(fs, b[bw->bpind], &bmi2);
 		if(extend) // allocate single indirect block
 			b[bw->bpdind] = alloc_blk(fs,nod);
 		if(reduce) // free indirect block
 			free_blk(fs, b[bw->bpind]);
-		b = (uint32*)get_blk(fs, b[bw->bpdind], &bi3);
+		b = get_blkmap(fs, b[bw->bpdind], &bmi3);
 		bkref = &b[bw->bptind];
 		if(extend) // allocate first block
 			*bkref = hole ? 0 : alloc_blk(fs,nod);
@@ -1247,12 +1277,12 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
 	/* End change for walking triple indirection */
 
 	bk = *bkref;
-	if (bi3)
-		put_blk(bi3);
-	if (bi2)
-		put_blk(bi2);
-	if (bi1)
-		put_blk(bi1);
+	if (bmi3)
+		put_blkmap(bmi3);
+	if (bmi2)
+		put_blkmap(bmi2);
+	if (bmi1)
+		put_blkmap(bmi1);
 
 	if(bk)
 	{
-- 
1.7.4.1