summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0002-Add-put_blk-and-put_nod-routines.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0002-Add-put_blk-and-put_nod-routines.patch')
-rw-r--r--meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0002-Add-put_blk-and-put_nod-routines.patch1123
1 files changed, 1123 insertions, 0 deletions
diff --git a/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0002-Add-put_blk-and-put_nod-routines.patch b/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0002-Add-put_blk-and-put_nod-routines.patch
new file mode 100644
index 0000000000..ddcd052edc
--- /dev/null
+++ b/meta/recipes-devtools/genext2fs/genext2fs-1.4.1/0002-Add-put_blk-and-put_nod-routines.patch
@@ -0,0 +1,1123 @@
1Upstream-Status: inappropriate
2
3From 8dd6e604777ffeb4d30921592f199cd9bcc8a3e2 Mon Sep 17 00:00:00 2001
4From: Corey Minyard <cminyard@mvista.com>
5Date: Sat, 4 Jun 2011 15:23:29 -0500
6Subject: [PATCH 02/19] Add put_blk and put_nod routines
7
8Add the routines to mark that we are done with a block or inode, and
9add the info structures so that get and put will work. This doesn't
10do anything functionally, just getting ready for future changes.
11
12Most of the changes are pretty straightforward. There were changes in
13get_nod() because it could use a later block than the one actually
14fetches. And walk_bw() needed some special handling to avoid using data
15after the put routine.
16---
17 genext2fs.c | 480 ++++++++++++++++++++++++++++++++++++++++-------------------
18 1 files changed, 330 insertions(+), 150 deletions(-)
19
20diff --git a/genext2fs.c b/genext2fs.c
21index 284862d..bd06369 100644
22--- a/genext2fs.c
23+++ b/genext2fs.c
24@@ -236,18 +236,22 @@ struct stats {
25 (((fs)->sb.s_blocks_count - fs->sb.s_first_data_block + \
26 (fs)->sb.s_blocks_per_group - 1) / (fs)->sb.s_blocks_per_group)
27
28-// Get group block bitmap (bbm) given the group number
29-#define GRP_GET_GROUP_BBM(fs,grp) ( get_blk((fs),(fs)->gd[(grp)].bg_block_bitmap) )
30+// Get/put group block bitmap (bbm) given the group number
31+#define GRP_GET_GROUP_BBM(fs,grp,bi) ( get_blk((fs),(fs)->gd[(grp)].bg_block_bitmap,(bi)) )
32+#define GRP_PUT_GROUP_BBM(bi) ( put_blk((bi)) )
33
34-// Get group inode bitmap (ibm) given the group number
35-#define GRP_GET_GROUP_IBM(fs,grp) ( get_blk((fs),(fs)->gd[(grp)].bg_inode_bitmap) )
36+// Get/put group inode bitmap (ibm) given the group number
37+#define GRP_GET_GROUP_IBM(fs,grp,bi) ( get_blk((fs),(fs)->gd[(grp)].bg_inode_bitmap,(bi)) )
38+#define GRP_PUT_GROUP_IBM(bi) ( put_blk((bi)) )
39
40 // Given an inode number find the group it belongs to
41 #define GRP_GROUP_OF_INODE(fs,nod) ( ((nod)-1) / (fs)->sb.s_inodes_per_group)
42
43-//Given an inode number get the inode bitmap that covers it
44-#define GRP_GET_INODE_BITMAP(fs,nod) \
45- ( GRP_GET_GROUP_IBM((fs),GRP_GROUP_OF_INODE((fs),(nod))) )
46+//Given an inode number get/put the inode bitmap that covers it
47+#define GRP_GET_INODE_BITMAP(fs,nod,bi) \
48+ ( GRP_GET_GROUP_IBM((fs),GRP_GROUP_OF_INODE((fs),(nod)),(bi)) )
49+#define GRP_PUT_INODE_BITMAP(bi) \
50+ ( GRP_PUT_GROUP_IBM((bi)) )
51
52 //Given an inode number find its offset within the inode bitmap that covers it
53 #define GRP_IBM_OFFSET(fs,nod) \
54@@ -256,9 +260,11 @@ struct stats {
55 // Given a block number find the group it belongs to
56 #define GRP_GROUP_OF_BLOCK(fs,blk) ( ((blk)-1) / (fs)->sb.s_blocks_per_group)
57
58-//Given a block number get the block bitmap that covers it
59-#define GRP_GET_BLOCK_BITMAP(fs,blk) \
60- ( GRP_GET_GROUP_BBM((fs),GRP_GROUP_OF_BLOCK((fs),(blk))) )
61+//Given a block number get/put the block bitmap that covers it
62+#define GRP_GET_BLOCK_BITMAP(fs,blk,bi) \
63+ ( GRP_GET_GROUP_BBM((fs),GRP_GROUP_OF_BLOCK((fs),(blk)),(bi)) )
64+#define GRP_PUT_BLOCK_BITMAP(bi) \
65+ ( GRP_PUT_GROUP_BBM((bi)) )
66
67 //Given a block number find its offset within the block bitmap that covers it
68 #define GRP_BBM_OFFSET(fs,blk) \
69@@ -811,24 +817,59 @@ allocated(block b, uint32 item)
70 return b[(item-1) / 8] & (1 << ((item-1) % 8));
71 }
72
73-// return a given block from a filesystem
74+// Used by get_blk/put_blk to hold information about a block owned
75+// by the user.
76+typedef struct
77+{
78+ int dummy;
79+} blk_info;
80+
81+// Return a given block from a filesystem. Make sure to call
82+// put_blk when you are done with it.
83 static inline uint8 *
84-get_blk(filesystem *fs, uint32 blk)
85+get_blk(filesystem *fs, uint32 blk, blk_info **rbi)
86 {
87 return (uint8*)fs + blk*BLOCKSIZE;
88 }
89
90-// return a given inode from a filesystem
91+static inline void
92+put_blk(blk_info *bi)
93+{
94+}
95+
96+// Used by get_nod/put_nod to hold information about an inode owned
97+// by the user.
98+typedef struct
99+{
100+ blk_info *bi;
101+} nod_info;
102+
103+// Return a given inode from a filesystem. Make sure to call put_nod()
104+// when you are done with the inode.
105 static inline inode *
106-get_nod(filesystem *fs, uint32 nod)
107+get_nod(filesystem *fs, uint32 nod, nod_info **rni)
108 {
109- int grp,offset;
110+ int grp, offset, boffset;
111 inode *itab;
112+ nod_info *ni;
113
114- offset = GRP_IBM_OFFSET(fs,nod);
115+ offset = GRP_IBM_OFFSET(fs,nod) - 1;
116+ boffset = offset / (BLOCKSIZE / sizeof(inode));
117+ offset %= BLOCKSIZE / sizeof(inode);
118 grp = GRP_GROUP_OF_INODE(fs,nod);
119- itab = (inode *)get_blk(fs, fs->gd[grp].bg_inode_table);
120- return itab+offset-1;
121+ ni = malloc(sizeof(*ni));
122+ if (!ni)
123+ error_msg_and_die("get_nod: out of memory");
124+ itab = (inode *)get_blk(fs, fs->gd[grp].bg_inode_table + boffset, &ni->bi);
125+ *rni = ni;
126+ return itab+offset;
127+}
128+
129+static inline void
130+put_nod(nod_info *ni)
131+{
132+ put_blk(ni->bi);
133+ free(ni);
134 }
135
136 // allocate a given block/inode in the bitmap
137@@ -870,12 +911,17 @@ alloc_blk(filesystem *fs, uint32 nod)
138 {
139 uint32 bk=0;
140 uint32 grp,nbgroups;
141+ blk_info *bi;
142
143 grp = GRP_GROUP_OF_INODE(fs,nod);
144 nbgroups = GRP_NBGROUPS(fs);
145- if(!(bk = allocate(get_blk(fs,fs->gd[grp].bg_block_bitmap), 0))) {
146- for(grp=0;grp<nbgroups && !bk;grp++)
147- bk=allocate(get_blk(fs,fs->gd[grp].bg_block_bitmap),0);
148+ bk = allocate(get_blk(fs, fs->gd[grp].bg_block_bitmap, &bi), 0);
149+ put_blk(bi);
150+ if (!bk) {
151+ for (grp=0; grp<nbgroups && !bk; grp++) {
152+ bk = allocate(get_blk(fs, fs->gd[grp].bg_block_bitmap, &bi), 0);
153+ put_blk(bi);
154+ }
155 grp--;
156 }
157 if (!bk)
158@@ -892,10 +938,12 @@ static void
159 free_blk(filesystem *fs, uint32 bk)
160 {
161 uint32 grp;
162+ blk_info *bi;
163
164 grp = bk / fs->sb.s_blocks_per_group;
165 bk %= fs->sb.s_blocks_per_group;
166- deallocate(get_blk(fs,fs->gd[grp].bg_block_bitmap), bk);
167+ deallocate(get_blk(fs, fs->gd[grp].bg_block_bitmap, &bi), bk);
168+ put_blk(bi);
169 fs->gd[grp].bg_free_blocks_count++;
170 fs->sb.s_free_blocks_count++;
171 }
172@@ -906,6 +954,7 @@ alloc_nod(filesystem *fs)
173 {
174 uint32 nod,best_group=0;
175 uint32 grp,nbgroups,avefreei;
176+ blk_info *bi;
177
178 nbgroups = GRP_NBGROUPS(fs);
179
180@@ -923,8 +972,10 @@ alloc_nod(filesystem *fs)
181 fs->gd[grp].bg_free_blocks_count > fs->gd[best_group].bg_free_blocks_count)
182 best_group = grp;
183 }
184- if (!(nod = allocate(get_blk(fs,fs->gd[best_group].bg_inode_bitmap),0)))
185+ if (!(nod = allocate(get_blk(fs, fs->gd[best_group].bg_inode_bitmap,
186+ &bi), 0)))
187 error_msg_and_die("couldn't allocate an inode (no free inode)");
188+ put_blk(bi);
189 if(!(fs->gd[best_group].bg_free_inodes_count--))
190 error_msg_and_die("group descr. free blocks count == 0 (corrupted fs?)");
191 if(!(fs->sb.s_free_inodes_count--))
192@@ -968,24 +1019,35 @@ static uint32
193 walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
194 {
195 uint32 *bkref = 0;
196+ uint32 bk = 0;
197 uint32 *b;
198 int extend = 0, reduce = 0;
199+ inode *inod;
200+ nod_info *ni;
201+ uint32 *iblk;
202+ blk_info *bi1 = NULL, *bi2 = NULL, *bi3 = NULL;
203+
204 if(create && (*create) < 0)
205 reduce = 1;
206- if(bw->bnum >= get_nod(fs, nod)->i_blocks / INOBLK)
207+ inod = get_nod(fs, nod, &ni);
208+ if(bw->bnum >= inod->i_blocks / INOBLK)
209 {
210 if(create && (*create) > 0)
211 {
212 (*create)--;
213 extend = 1;
214 }
215- else
216+ else
217+ {
218+ put_nod(ni);
219 return WALK_END;
220+ }
221 }
222+ iblk = inod->i_block;
223 // first direct block
224 if(bw->bpdir == EXT2_INIT_BLOCK)
225 {
226- bkref = &get_nod(fs, nod)->i_block[bw->bpdir = 0];
227+ bkref = &iblk[bw->bpdir = 0];
228 if(extend) // allocate first block
229 *bkref = hole ? 0 : alloc_blk(fs,nod);
230 if(reduce) // free first block
231@@ -994,7 +1056,7 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
232 // direct block
233 else if(bw->bpdir < EXT2_NDIR_BLOCKS)
234 {
235- bkref = &get_nod(fs, nod)->i_block[++bw->bpdir];
236+ bkref = &iblk[++bw->bpdir];
237 if(extend) // allocate block
238 *bkref = hole ? 0 : alloc_blk(fs,nod);
239 if(reduce) // free block
240@@ -1007,10 +1069,10 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
241 bw->bpdir = EXT2_IND_BLOCK;
242 bw->bpind = 0;
243 if(extend) // allocate indirect block
244- get_nod(fs, nod)->i_block[bw->bpdir] = alloc_blk(fs,nod);
245+ iblk[bw->bpdir] = alloc_blk(fs,nod);
246 if(reduce) // free indirect block
247- free_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
248- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
249+ free_blk(fs, iblk[bw->bpdir]);
250+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
251 bkref = &b[bw->bpind];
252 if(extend) // allocate first block
253 *bkref = hole ? 0 : alloc_blk(fs,nod);
254@@ -1021,7 +1083,7 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
255 else if((bw->bpdir == EXT2_IND_BLOCK) && (bw->bpind < BLOCKSIZE/4 - 1))
256 {
257 bw->bpind++;
258- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
259+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
260 bkref = &b[bw->bpind];
261 if(extend) // allocate block
262 *bkref = hole ? 0 : alloc_blk(fs,nod);
263@@ -1036,15 +1098,15 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
264 bw->bpind = 0;
265 bw->bpdind = 0;
266 if(extend) // allocate double indirect block
267- get_nod(fs, nod)->i_block[bw->bpdir] = alloc_blk(fs,nod);
268+ iblk[bw->bpdir] = alloc_blk(fs,nod);
269 if(reduce) // free double indirect block
270- free_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
271- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
272+ free_blk(fs, iblk[bw->bpdir]);
273+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
274 if(extend) // allocate first indirect block
275 b[bw->bpind] = alloc_blk(fs,nod);
276 if(reduce) // free firstindirect block
277 free_blk(fs, b[bw->bpind]);
278- b = (uint32*)get_blk(fs, b[bw->bpind]);
279+ b = (uint32*)get_blk(fs, b[bw->bpind], &bi1);
280 bkref = &b[bw->bpdind];
281 if(extend) // allocate first block
282 *bkref = hole ? 0 : alloc_blk(fs,nod);
283@@ -1055,8 +1117,8 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
284 else if((bw->bpdir == EXT2_DIND_BLOCK) && (bw->bpdind < BLOCKSIZE/4 - 1))
285 {
286 bw->bpdind++;
287- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
288- b = (uint32*)get_blk(fs, b[bw->bpind]);
289+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
290+ b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
291 bkref = &b[bw->bpdind];
292 if(extend) // allocate block
293 *bkref = hole ? 0 : alloc_blk(fs,nod);
294@@ -1069,12 +1131,12 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
295 bw->bnum++;
296 bw->bpdind = 0;
297 bw->bpind++;
298- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
299+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
300 if(extend) // allocate indirect block
301 b[bw->bpind] = alloc_blk(fs,nod);
302 if(reduce) // free indirect block
303 free_blk(fs, b[bw->bpind]);
304- b = (uint32*)get_blk(fs, b[bw->bpind]);
305+ b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
306 bkref = &b[bw->bpdind];
307 if(extend) // allocate first block
308 *bkref = hole ? 0 : alloc_blk(fs,nod);
309@@ -1094,20 +1156,20 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
310 bw->bpdind = 0;
311 bw->bptind = 0;
312 if(extend) // allocate triple indirect block
313- get_nod(fs, nod)->i_block[bw->bpdir] = alloc_blk(fs,nod);
314+ iblk[bw->bpdir] = alloc_blk(fs,nod);
315 if(reduce) // free triple indirect block
316- free_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
317- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
318+ free_blk(fs, iblk[bw->bpdir]);
319+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
320 if(extend) // allocate first double indirect block
321 b[bw->bpind] = alloc_blk(fs,nod);
322 if(reduce) // free first double indirect block
323 free_blk(fs, b[bw->bpind]);
324- b = (uint32*)get_blk(fs, b[bw->bpind]);
325+ b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
326 if(extend) // allocate first indirect block
327 b[bw->bpdind] = alloc_blk(fs,nod);
328 if(reduce) // free first indirect block
329 free_blk(fs, b[bw->bpind]);
330- b = (uint32*)get_blk(fs, b[bw->bpdind]);
331+ b = (uint32*)get_blk(fs, b[bw->bpdind], &bi3);
332 bkref = &b[bw->bptind];
333 if(extend) // allocate first data block
334 *bkref = hole ? 0 : alloc_blk(fs,nod);
335@@ -1121,9 +1183,9 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
336 (bw->bptind < BLOCKSIZE/4 -1) )
337 {
338 bw->bptind++;
339- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
340- b = (uint32*)get_blk(fs, b[bw->bpind]);
341- b = (uint32*)get_blk(fs, b[bw->bpdind]);
342+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
343+ b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
344+ b = (uint32*)get_blk(fs, b[bw->bpdind], &bi3);
345 bkref = &b[bw->bptind];
346 if(extend) // allocate data block
347 *bkref = hole ? 0 : alloc_blk(fs,nod);
348@@ -1140,13 +1202,13 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
349 bw->bnum++;
350 bw->bptind = 0;
351 bw->bpdind++;
352- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
353- b = (uint32*)get_blk(fs, b[bw->bpind]);
354+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
355+ b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
356 if(extend) // allocate single indirect block
357 b[bw->bpdind] = alloc_blk(fs,nod);
358 if(reduce) // free indirect block
359 free_blk(fs, b[bw->bpind]);
360- b = (uint32*)get_blk(fs, b[bw->bpdind]);
361+ b = (uint32*)get_blk(fs, b[bw->bpdind], &bi3);
362 bkref = &b[bw->bptind];
363 if(extend) // allocate first data block
364 *bkref = hole ? 0 : alloc_blk(fs,nod);
365@@ -1163,17 +1225,17 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
366 bw->bpdind = 0;
367 bw->bptind = 0;
368 bw->bpind++;
369- b = (uint32*)get_blk(fs, get_nod(fs, nod)->i_block[bw->bpdir]);
370+ b = (uint32*)get_blk(fs, iblk[bw->bpdir], &bi1);
371 if(extend) // allocate double indirect block
372 b[bw->bpind] = alloc_blk(fs,nod);
373 if(reduce) // free double indirect block
374 free_blk(fs, b[bw->bpind]);
375- b = (uint32*)get_blk(fs, b[bw->bpind]);
376+ b = (uint32*)get_blk(fs, b[bw->bpind], &bi2);
377 if(extend) // allocate single indirect block
378 b[bw->bpdind] = alloc_blk(fs,nod);
379 if(reduce) // free indirect block
380 free_blk(fs, b[bw->bpind]);
381- b = (uint32*)get_blk(fs, b[bw->bpdind]);
382+ b = (uint32*)get_blk(fs, b[bw->bpdind], &bi3);
383 bkref = &b[bw->bptind];
384 if(extend) // allocate first block
385 *bkref = hole ? 0 : alloc_blk(fs,nod);
386@@ -1184,15 +1246,28 @@ walk_bw(filesystem *fs, uint32 nod, blockwalker *bw, int32 *create, uint32 hole)
387 error_msg_and_die("file too big !");
388 /* End change for walking triple indirection */
389
390- if(*bkref)
391+ bk = *bkref;
392+ if (bi3)
393+ put_blk(bi3);
394+ if (bi2)
395+ put_blk(bi2);
396+ if (bi1)
397+ put_blk(bi1);
398+
399+ if(bk)
400 {
401+ blk_info *bi;
402+ uint8 *block;
403 bw->bnum++;
404- if(!reduce && !allocated(GRP_GET_BLOCK_BITMAP(fs,*bkref), GRP_BBM_OFFSET(fs,*bkref)))
405- error_msg_and_die("[block %d of inode %d is unallocated !]", *bkref, nod);
406+ block = GRP_GET_BLOCK_BITMAP(fs,bk,&bi);
407+ if(!reduce && !allocated(block, GRP_BBM_OFFSET(fs,bk)))
408+ error_msg_and_die("[block %d of inode %d is unallocated !]", bk, nod);
409+ GRP_PUT_BLOCK_BITMAP(bi);
410 }
411 if(extend)
412- get_nod(fs, nod)->i_blocks = bw->bnum * INOBLK;
413- return *bkref;
414+ inod->i_blocks = bw->bnum * INOBLK;
415+ put_nod(ni);
416+ return bk;
417 }
418
419 // add blocks to an inode (file/dir/etc...)
420@@ -1202,15 +1277,19 @@ extend_blk(filesystem *fs, uint32 nod, block b, int amount)
421 int create = amount;
422 blockwalker bw, lbw;
423 uint32 bk;
424+ nod_info *ni;
425+ inode *inod;
426+
427+ inod = get_nod(fs, nod, &ni);
428 init_bw(&bw);
429 if(amount < 0)
430 {
431 uint32 i;
432- for(i = 0; i < get_nod(fs, nod)->i_blocks / INOBLK + amount; i++)
433+ for(i = 0; i < inod->i_blocks / INOBLK + amount; i++)
434 walk_bw(fs, nod, &bw, 0, 0);
435 while(walk_bw(fs, nod, &bw, &create, 0) != WALK_END)
436 /*nop*/;
437- get_nod(fs, nod)->i_blocks += amount * INOBLK;
438+ inod->i_blocks += amount * INOBLK;
439 }
440 else
441 {
442@@ -1232,8 +1311,11 @@ extend_blk(filesystem *fs, uint32 nod, block b, int amount)
443 }
444 if((bk = walk_bw(fs, nod, &bw, &create, !copyb)) == WALK_END)
445 break;
446- if(copyb)
447- memcpy(get_blk(fs, bk), b + BLOCKSIZE * (amount - create - 1), BLOCKSIZE);
448+ if(copyb) {
449+ blk_info *bi;
450+ memcpy(get_blk(fs, bk, &bi), b + BLOCKSIZE * (amount - create - 1), BLOCKSIZE);
451+ put_blk(bi);
452+ }
453 }
454 }
455 }
456@@ -1245,12 +1327,14 @@ add2dir(filesystem *fs, uint32 dnod, uint32 nod, const char* name)
457 blockwalker bw;
458 uint32 bk;
459 uint8 *b;
460+ blk_info *bi;
461 directory *d;
462 int reclen, nlen;
463 inode *node;
464 inode *pnode;
465+ nod_info *dni, *ni;
466
467- pnode = get_nod(fs, dnod);
468+ pnode = get_nod(fs, dnod, &dni);
469 if((pnode->i_mode & FM_IFMT) != FM_IFDIR)
470 error_msg_and_die("can't add '%s' to a non-directory", name);
471 if(!*name)
472@@ -1264,7 +1348,7 @@ add2dir(filesystem *fs, uint32 dnod, uint32 nod, const char* name)
473 init_bw(&bw);
474 while((bk = walk_bw(fs, dnod, &bw, 0, 0)) != WALK_END) // for all blocks in dir
475 {
476- b = get_blk(fs, bk);
477+ b = get_blk(fs, bk, &bi);
478 // for all dir entries in block
479 for(d = (directory*)b; (int8*)d + sizeof(*d) < (int8*)b + BLOCKSIZE; d = (directory*)((int8*)d + d->d_rec_len))
480 {
481@@ -1272,11 +1356,12 @@ add2dir(filesystem *fs, uint32 dnod, uint32 nod, const char* name)
482 if((!d->d_inode) && (d->d_rec_len >= reclen))
483 {
484 d->d_inode = nod;
485- node = get_nod(fs, nod);
486+ node = get_nod(fs, nod, &ni);
487 node->i_links_count++;
488 d->d_name_len = nlen;
489 strncpy(d->d_name, name, nlen);
490- return;
491+ put_nod(ni);
492+ goto out;
493 }
494 // if entry with enough room (last one?), shrink it & use it
495 if(d->d_rec_len >= (sizeof(directory) + rndup(d->d_name_len, 4) + reclen))
496@@ -1287,11 +1372,12 @@ add2dir(filesystem *fs, uint32 dnod, uint32 nod, const char* name)
497 d = (directory*) (((int8*)d) + d->d_rec_len);
498 d->d_rec_len = reclen;
499 d->d_inode = nod;
500- node = get_nod(fs, nod);
501+ node = get_nod(fs, nod, &ni);
502 node->i_links_count++;
503 d->d_name_len = nlen;
504 strncpy(d->d_name, name, nlen);
505- return;
506+ put_nod(ni);
507+ goto out;
508 }
509 }
510 }
511@@ -1300,14 +1386,17 @@ add2dir(filesystem *fs, uint32 dnod, uint32 nod, const char* name)
512 error_msg_and_die("get_workblk() failed.");
513 d = (directory*)b;
514 d->d_inode = nod;
515- node = get_nod(fs, nod);
516+ node = get_nod(fs, nod, &ni);
517 node->i_links_count++;
518+ put_nod(ni);
519 d->d_rec_len = BLOCKSIZE;
520 d->d_name_len = nlen;
521 strncpy(d->d_name, name, nlen);
522 extend_blk(fs, dnod, b, 1);
523- get_nod(fs, dnod)->i_size += BLOCKSIZE;
524+ pnode->i_size += BLOCKSIZE;
525 free_workblk(b);
526+out:
527+ put_nod(dni);
528 }
529
530 // find an entry in a directory
531@@ -1316,16 +1405,20 @@ find_dir(filesystem *fs, uint32 nod, const char * name)
532 {
533 blockwalker bw;
534 uint32 bk;
535+ blk_info *bi;
536 int nlen = strlen(name);
537 init_bw(&bw);
538 while((bk = walk_bw(fs, nod, &bw, 0, 0)) != WALK_END)
539 {
540 directory *d;
541 uint8 *b;
542- b = get_blk(fs, bk);
543+ b = get_blk(fs, bk, &bi);
544 for(d = (directory*)b; (int8*)d + sizeof(*d) < (int8*)b + BLOCKSIZE; d = (directory*)((int8*)d + d->d_rec_len))
545- if(d->d_inode && (nlen == d->d_name_len) && !strncmp(d->d_name, name, nlen))
546+ if(d->d_inode && (nlen == d->d_name_len) && !strncmp(d->d_name, name, nlen)) {
547+ put_blk(bi);
548 return d->d_inode;
549+ }
550+ put_blk(bi);
551 }
552 return 0;
553 }
554@@ -1361,10 +1454,12 @@ void
555 chmod_fs(filesystem *fs, uint32 nod, uint16 mode, uint16 uid, uint16 gid)
556 {
557 inode *node;
558- node = get_nod(fs, nod);
559+ nod_info *ni;
560+ node = get_nod(fs, nod, &ni);
561 node->i_mode = (node->i_mode & ~FM_IMASK) | (mode & FM_IMASK);
562 node->i_uid = uid;
563 node->i_gid = gid;
564+ put_nod(ni);
565 }
566
567 // create a simple inode
568@@ -1373,33 +1468,34 @@ mknod_fs(filesystem *fs, uint32 parent_nod, const char *name, uint16 mode, uint1
569 {
570 uint32 nod;
571 inode *node;
572+ nod_info *ni;
573+
574+ nod = alloc_nod(fs);
575+ node = get_nod(fs, nod, &ni);
576+ node->i_mode = mode;
577+ add2dir(fs, parent_nod, nod, name);
578+ switch(mode & FM_IFMT)
579 {
580- nod = alloc_nod(fs);
581- node = get_nod(fs, nod);
582- node->i_mode = mode;
583- add2dir(fs, parent_nod, nod, name);
584- switch(mode & FM_IFMT)
585- {
586- case FM_IFLNK:
587- mode = FM_IFLNK | FM_IRWXU | FM_IRWXG | FM_IRWXO;
588- break;
589- case FM_IFBLK:
590- case FM_IFCHR:
591- ((uint8*)get_nod(fs, nod)->i_block)[0] = minor;
592- ((uint8*)get_nod(fs, nod)->i_block)[1] = major;
593- break;
594- case FM_IFDIR:
595- add2dir(fs, nod, nod, ".");
596- add2dir(fs, nod, parent_nod, "..");
597- fs->gd[GRP_GROUP_OF_INODE(fs,nod)].bg_used_dirs_count++;
598- break;
599- }
600+ case FM_IFLNK:
601+ mode = FM_IFLNK | FM_IRWXU | FM_IRWXG | FM_IRWXO;
602+ break;
603+ case FM_IFBLK:
604+ case FM_IFCHR:
605+ ((uint8*)node->i_block)[0] = minor;
606+ ((uint8*)node->i_block)[1] = major;
607+ break;
608+ case FM_IFDIR:
609+ add2dir(fs, nod, nod, ".");
610+ add2dir(fs, nod, parent_nod, "..");
611+ fs->gd[GRP_GROUP_OF_INODE(fs,nod)].bg_used_dirs_count++;
612+ break;
613 }
614 node->i_uid = uid;
615 node->i_gid = gid;
616 node->i_atime = mtime;
617 node->i_ctime = ctime;
618 node->i_mtime = mtime;
619+ put_nod(ni);
620 return nod;
621 }
622
623@@ -1416,14 +1512,19 @@ static uint32
624 mklink_fs(filesystem *fs, uint32 parent_nod, const char *name, size_t size, uint8 *b, uid_t uid, gid_t gid, uint32 ctime, uint32 mtime)
625 {
626 uint32 nod = mknod_fs(fs, parent_nod, name, FM_IFLNK | FM_IRWXU | FM_IRWXG | FM_IRWXO, uid, gid, 0, 0, ctime, mtime);
627- extend_blk(fs, nod, 0, - (int)get_nod(fs, nod)->i_blocks / INOBLK);
628- get_nod(fs, nod)->i_size = size;
629+ nod_info *ni;
630+ inode *node = get_nod(fs, nod, &ni);
631+
632+ extend_blk(fs, nod, 0, - (int)node->i_blocks / INOBLK);
633+ node->i_size = size;
634 if(size <= 4 * (EXT2_TIND_BLOCK+1))
635 {
636- strncpy((char*)get_nod(fs, nod)->i_block, (char*)b, size);
637+ strncpy((char *)node->i_block, (char *)b, size);
638+ put_nod(ni);
639 return nod;
640 }
641 extend_blk(fs, nod, b, rndup(size, BLOCKSIZE) / BLOCKSIZE);
642+ put_nod(ni);
643 return nod;
644 }
645
646@@ -1433,8 +1534,11 @@ mkfile_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode, size
647 {
648 uint8 * b;
649 uint32 nod = mknod_fs(fs, parent_nod, name, mode|FM_IFREG, uid, gid, 0, 0, ctime, mtime);
650- extend_blk(fs, nod, 0, - (int)get_nod(fs, nod)->i_blocks / INOBLK);
651- get_nod(fs, nod)->i_size = size;
652+ nod_info *ni;
653+ inode *node = get_nod(fs, nod, &ni);
654+
655+ extend_blk(fs, nod, 0, - (int)node->i_blocks / INOBLK);
656+ node->i_size = size;
657 if (size) {
658 if(!(b = (uint8*)calloc(rndup(size, BLOCKSIZE), 1)))
659 error_msg_and_die("not enough mem to read file '%s'", name);
660@@ -1444,6 +1548,7 @@ mkfile_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode, size
661 extend_blk(fs, nod, b, rndup(size, BLOCKSIZE) / BLOCKSIZE);
662 free(b);
663 }
664+ put_nod(ni);
665 return nod;
666 }
667
668@@ -1766,6 +1871,7 @@ swap_goodblocks(filesystem *fs, inode *nod)
669 uint32 i,j;
670 int done=0;
671 uint32 *b,*b2;
672+ blk_info *bi, *bi2, *bi3;
673
674 uint32 nblk = nod->i_blocks / INOBLK;
675 if((nod->i_size && !nblk) || ((nod->i_mode & FM_IFBLK) == FM_IFBLK) || ((nod->i_mode & FM_IFCHR) == FM_IFCHR))
676@@ -1773,7 +1879,8 @@ swap_goodblocks(filesystem *fs, inode *nod)
677 nod->i_block[i] = swab32(nod->i_block[i]);
678 if(nblk <= EXT2_IND_BLOCK)
679 return;
680- swap_block(get_blk(fs, nod->i_block[EXT2_IND_BLOCK]));
681+ swap_block(get_blk(fs, nod->i_block[EXT2_IND_BLOCK], &bi));
682+ put_blk(bi);
683 if(nblk <= EXT2_DIND_BLOCK + BLOCKSIZE/4)
684 return;
685 /* Currently this will fail b'cos the number of blocks as stored
686@@ -1791,29 +1898,37 @@ swap_goodblocks(filesystem *fs, inode *nod)
687 // ths function needs to be fixed for the same reasons - Xav
688 assert(nod->i_block[EXT2_DIND_BLOCK] != 0);
689 for(i = 0; i < BLOCKSIZE/4; i++)
690- if(nblk > EXT2_IND_BLOCK + BLOCKSIZE/4 + (BLOCKSIZE/4)*i )
691- swap_block(get_blk(fs, ((uint32*)get_blk(fs, nod->i_block[EXT2_DIND_BLOCK]))[i]));
692- swap_block(get_blk(fs, nod->i_block[EXT2_DIND_BLOCK]));
693+ if(nblk > EXT2_IND_BLOCK + BLOCKSIZE/4 + (BLOCKSIZE/4)*i ) {
694+ swap_block(get_blk(fs, ((uint32*)get_blk(fs, nod->i_block[EXT2_DIND_BLOCK], &bi))[i], &bi2));
695+ put_blk(bi);
696+ put_blk(bi2);
697+ }
698+ swap_block(get_blk(fs, nod->i_block[EXT2_DIND_BLOCK], &bi));
699+ put_blk(bi);
700 if(nblk <= EXT2_IND_BLOCK + BLOCKSIZE/4 + BLOCKSIZE/4 * BLOCKSIZE/4)
701 return;
702 /* Adding support for triple indirection */
703- b = (uint32*)get_blk(fs,nod->i_block[EXT2_TIND_BLOCK]);
704+ b = (uint32*)get_blk(fs,nod->i_block[EXT2_TIND_BLOCK], &bi);
705 for(i=0;i < BLOCKSIZE/4 && !done ; i++) {
706- b2 = (uint32*)get_blk(fs,b[i]);
707+ b2 = (uint32*)get_blk(fs,b[i], &bi2);
708 for(j=0; j<BLOCKSIZE/4;j++) {
709 if (nblk > ( EXT2_IND_BLOCK + BLOCKSIZE/4 +
710 (BLOCKSIZE/4)*(BLOCKSIZE/4) +
711 i*(BLOCKSIZE/4)*(BLOCKSIZE/4) +
712- j*(BLOCKSIZE/4)) )
713- swap_block(get_blk(fs,b2[j]));
714+ j*(BLOCKSIZE/4)) ) {
715+ swap_block(get_blk(fs,b2[j],&bi3));
716+ put_blk(bi3);
717+ }
718 else {
719 done = 1;
720 break;
721 }
722 }
723 swap_block((uint8 *)b2);
724+ put_blk(bi2);
725 }
726 swap_block((uint8 *)b);
727+ put_blk(bi);
728 return;
729 }
730
731@@ -1823,6 +1938,7 @@ swap_badblocks(filesystem *fs, inode *nod)
732 uint32 i,j;
733 int done=0;
734 uint32 *b,*b2;
735+ blk_info *bi, *bi2, *bi3;
736
737 uint32 nblk = nod->i_blocks / INOBLK;
738 if((nod->i_size && !nblk) || ((nod->i_mode & FM_IFBLK) == FM_IFBLK) || ((nod->i_mode & FM_IFCHR) == FM_IFCHR))
739@@ -1830,35 +1946,44 @@ swap_badblocks(filesystem *fs, inode *nod)
740 nod->i_block[i] = swab32(nod->i_block[i]);
741 if(nblk <= EXT2_IND_BLOCK)
742 return;
743- swap_block(get_blk(fs, nod->i_block[EXT2_IND_BLOCK]));
744+ swap_block(get_blk(fs, nod->i_block[EXT2_IND_BLOCK], &bi));
745+ put_blk(bi);
746 if(nblk <= EXT2_DIND_BLOCK + BLOCKSIZE/4)
747 return;
748 /* See comment in swap_goodblocks */
749 assert(nod->i_block[EXT2_DIND_BLOCK] != 0);
750- swap_block(get_blk(fs, nod->i_block[EXT2_DIND_BLOCK]));
751+ swap_block(get_blk(fs, nod->i_block[EXT2_DIND_BLOCK], &bi));
752+ put_blk(bi);
753 for(i = 0; i < BLOCKSIZE/4; i++)
754- if(nblk > EXT2_IND_BLOCK + BLOCKSIZE/4 + (BLOCKSIZE/4)*i )
755- swap_block(get_blk(fs, ((uint32*)get_blk(fs, nod->i_block[EXT2_DIND_BLOCK]))[i]));
756+ if(nblk > EXT2_IND_BLOCK + BLOCKSIZE/4 + (BLOCKSIZE/4)*i ) {
757+ swap_block(get_blk(fs, ((uint32*)get_blk(fs, nod->i_block[EXT2_DIND_BLOCK],&bi))[i], &bi2));
758+ put_blk(bi);
759+ put_blk(bi2);
760+ }
761 if(nblk <= EXT2_IND_BLOCK + BLOCKSIZE/4 + BLOCKSIZE/4 * BLOCKSIZE/4)
762 return;
763 /* Adding support for triple indirection */
764- b = (uint32*)get_blk(fs,nod->i_block[EXT2_TIND_BLOCK]);
765+ b = (uint32*)get_blk(fs,nod->i_block[EXT2_TIND_BLOCK],&bi);
766 swap_block((uint8 *)b);
767 for(i=0;i < BLOCKSIZE/4 && !done ; i++) {
768- b2 = (uint32*)get_blk(fs,b[i]);
769+ b2 = (uint32*)get_blk(fs,b[i],&bi2);
770 swap_block((uint8 *)b2);
771 for(j=0; j<BLOCKSIZE/4;j++) {
772 if (nblk > ( EXT2_IND_BLOCK + BLOCKSIZE/4 +
773 (BLOCKSIZE/4)*(BLOCKSIZE/4) +
774 i*(BLOCKSIZE/4)*(BLOCKSIZE/4) +
775- j*(BLOCKSIZE/4)) )
776- swap_block(get_blk(fs,b2[j]));
777+ j*(BLOCKSIZE/4)) ) {
778+ swap_block(get_blk(fs,b2[j],&bi3));
779+ put_blk(bi3);
780+ }
781 else {
782 done = 1;
783 break;
784 }
785 }
786+ put_blk(bi2);
787 }
788+ put_blk(bi);
789 return;
790 }
791
792@@ -1867,9 +1992,11 @@ static void
793 swap_goodfs(filesystem *fs)
794 {
795 uint32 i;
796+ nod_info *ni;
797+
798 for(i = 1; i < fs->sb.s_inodes_count; i++)
799 {
800- inode *nod = get_nod(fs, i);
801+ inode *nod = get_nod(fs, i, &ni);
802 if(nod->i_mode & FM_IFDIR)
803 {
804 blockwalker bw;
805@@ -1879,13 +2006,16 @@ swap_goodfs(filesystem *fs)
806 {
807 directory *d;
808 uint8 *b;
809- b = get_blk(fs, bk);
810+ blk_info *bi;
811+ b = get_blk(fs, bk, &bi);
812 for(d = (directory*)b; (int8*)d + sizeof(*d) < (int8*)b + BLOCKSIZE; d = (directory*)((int8*)d + swab16(d->d_rec_len)))
813 swap_dir(d);
814+ put_blk(bi);
815 }
816 }
817 swap_goodblocks(fs, nod);
818 swap_nod(nod);
819+ put_nod(ni);
820 }
821 for(i=0;i<GRP_NBGROUPS(fs);i++)
822 swap_gd(&(fs->gd[i]));
823@@ -1901,7 +2031,8 @@ swap_badfs(filesystem *fs)
824 swap_gd(&(fs->gd[i]));
825 for(i = 1; i < fs->sb.s_inodes_count; i++)
826 {
827- inode *nod = get_nod(fs, i);
828+ nod_info *ni;
829+ inode *nod = get_nod(fs, i, &ni);
830 swap_nod(nod);
831 swap_badblocks(fs, nod);
832 if(nod->i_mode & FM_IFDIR)
833@@ -1913,9 +2044,11 @@ swap_badfs(filesystem *fs)
834 {
835 directory *d;
836 uint8 *b;
837- b = get_blk(fs, bk);
838+ blk_info *bi;
839+ b = get_blk(fs, bk, &bi);
840 for(d = (directory*)b; (int8*)d + sizeof(*d) < (int8*)b + BLOCKSIZE; d = (directory*)((int8*)d + d->d_rec_len))
841 swap_dir(d);
842+ put_blk(bi);
843 }
844 }
845 }
846@@ -1936,6 +2069,8 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
847 uint32 j;
848 uint8 *bbm,*ibm;
849 inode *itab0;
850+ blk_info *bi;
851+ nod_info *ni;
852
853 if(nbresrvd < 0)
854 error_msg_and_die("reserved blocks value is invalid. Note: options have changed, see --help or the man page.");
855@@ -2014,9 +2149,8 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
856 /* Mark non-filesystem blocks and inodes as allocated */
857 /* Mark system blocks and inodes as allocated */
858 for(i = 0; i<nbgroups;i++) {
859-
860 /* Block bitmap */
861- bbm = get_blk(fs,fs->gd[i].bg_block_bitmap);
862+ bbm = get_blk(fs,fs->gd[i].bg_block_bitmap, &bi);
863 //non-filesystem blocks
864 for(j = fs->gd[i].bg_free_blocks_count
865 + overhead_per_group + 1; j <= BLOCKSIZE * 8; j++)
866@@ -2024,9 +2158,10 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
867 //system blocks
868 for(j = 1; j <= overhead_per_group; j++)
869 allocate(bbm, j);
870+ put_blk(bi);
871
872 /* Inode bitmap */
873- ibm = get_blk(fs,fs->gd[i].bg_inode_bitmap);
874+ ibm = get_blk(fs,fs->gd[i].bg_inode_bitmap, &bi);
875 //non-filesystem inodes
876 for(j = fs->sb.s_inodes_per_group+1; j <= BLOCKSIZE * 8; j++)
877 allocate(ibm, j);
878@@ -2035,6 +2170,7 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
879 if(i == 0)
880 for(j = 1; j < EXT2_FIRST_INO; j++)
881 allocate(ibm, j);
882+ put_blk(bi);
883 }
884
885 // make root inode and directory
886@@ -2042,13 +2178,14 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
887 /* Also increment the directory count for group 0 */
888 fs->gd[0].bg_free_inodes_count--;
889 fs->gd[0].bg_used_dirs_count = 1;
890- itab0 = (inode *)get_blk(fs,fs->gd[0].bg_inode_table);
891- itab0[EXT2_ROOT_INO-1].i_mode = FM_IFDIR | FM_IRWXU | FM_IRGRP | FM_IROTH | FM_IXGRP | FM_IXOTH;
892- itab0[EXT2_ROOT_INO-1].i_ctime = fs_timestamp;
893- itab0[EXT2_ROOT_INO-1].i_mtime = fs_timestamp;
894- itab0[EXT2_ROOT_INO-1].i_atime = fs_timestamp;
895- itab0[EXT2_ROOT_INO-1].i_size = BLOCKSIZE;
896- itab0[EXT2_ROOT_INO-1].i_links_count = 2;
897+ itab0 = get_nod(fs, EXT2_ROOT_INO, &ni);
898+ itab0->i_mode = FM_IFDIR | FM_IRWXU | FM_IRGRP | FM_IROTH | FM_IXGRP | FM_IXOTH;
899+ itab0->i_ctime = fs_timestamp;
900+ itab0->i_mtime = fs_timestamp;
901+ itab0->i_atime = fs_timestamp;
902+ itab0->i_size = BLOCKSIZE;
903+ itab0->i_links_count = 2;
904+ put_nod(ni);
905
906 if(!(b = get_workblk()))
907 error_msg_and_die("get_workblk() failed.");
908@@ -2067,6 +2204,8 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
909 // make lost+found directory and reserve blocks
910 if(fs->sb.s_r_blocks_count)
911 {
912+ inode *node;
913+
914 nod = mkdir_fs(fs, EXT2_ROOT_INO, "lost+found", FM_IRWXU, 0, 0, fs_timestamp, fs_timestamp);
915 memset(b, 0, BLOCKSIZE);
916 ((directory*)b)->d_rec_len = BLOCKSIZE;
917@@ -2077,7 +2216,9 @@ init_fs(int nbblocks, int nbinodes, int nbresrvd, int holes, uint32 fs_timestamp
918 fs->sb.s_r_blocks_count = fs->sb.s_blocks_count * MAX_RESERVED_BLOCKS;
919 for(i = 1; i < fs->sb.s_r_blocks_count; i++)
920 extend_blk(fs, nod, b, 1);
921- get_nod(fs, nod)->i_size = fs->sb.s_r_blocks_count * BLOCKSIZE;
922+ node = get_nod(fs, nod, &ni);
923+ node->i_size = fs->sb.s_r_blocks_count * BLOCKSIZE;
924+ put_nod(ni);
925 }
926 free_workblk(b);
927
928@@ -2153,16 +2294,23 @@ write_blocks(filesystem *fs, uint32 nod, FILE* f)
929 {
930 blockwalker bw;
931 uint32 bk;
932- int32 fsize = get_nod(fs, nod)->i_size;
933+ nod_info *ni;
934+ inode *node = get_nod(fs, nod, &ni);
935+ int32 fsize = node->i_size;
936+ blk_info *bi;
937+
938 init_bw(&bw);
939 while((bk = walk_bw(fs, nod, &bw, 0, 0)) != WALK_END)
940 {
941 if(fsize <= 0)
942 error_msg_and_die("wrong size while saving inode %d", nod);
943- if(fwrite(get_blk(fs, bk), (fsize > BLOCKSIZE) ? BLOCKSIZE : fsize, 1, f) != 1)
944+ if(fwrite(get_blk(fs, bk, &bi),
945+ (fsize > BLOCKSIZE) ? BLOCKSIZE : fsize, 1, f) != 1)
946 error_msg_and_die("error while saving inode %d", nod);
947+ put_blk(bi);
948 fsize -= BLOCKSIZE;
949 }
950+ put_nod(ni);
951 }
952
953
954@@ -2171,8 +2319,11 @@ static void
955 print_dev(filesystem *fs, uint32 nod)
956 {
957 int minor, major;
958- minor = ((uint8*)get_nod(fs, nod)->i_block)[0];
959- major = ((uint8*)get_nod(fs, nod)->i_block)[1];
960+ nod_info *ni;
961+ inode *node = get_nod(fs, nod, &ni);
962+ minor = ((uint8*)node->i_block)[0];
963+ major = ((uint8*)node->i_block)[1];
964+ put_nod(ni);
965 printf("major: %d, minor: %d\n", major, minor);
966 }
967
968@@ -2188,7 +2339,8 @@ print_dir(filesystem *fs, uint32 nod)
969 {
970 directory *d;
971 uint8 *b;
972- b = get_blk(fs, bk);
973+ blk_info *bi;
974+ b = get_blk(fs, bk, &bi);
975 for(d = (directory*)b; (int8*)d + sizeof(*d) < (int8*)b + BLOCKSIZE; d = (directory*)((int8*)d + d->d_rec_len))
976 if(d->d_inode)
977 {
978@@ -2198,6 +2350,7 @@ print_dir(filesystem *fs, uint32 nod)
979 putchar(d->d_name[i]);
980 printf("' (inode %d): rec_len: %d (name_len: %d)\n", d->d_inode, d->d_rec_len, d->d_name_len);
981 }
982+ put_blk(bi);
983 }
984 }
985
986@@ -2205,14 +2358,18 @@ print_dir(filesystem *fs, uint32 nod)
987 static void
988 print_link(filesystem *fs, uint32 nod)
989 {
990- if(!get_nod(fs, nod)->i_blocks)
991- printf("links to '%s'\n", (char*)get_nod(fs, nod)->i_block);
992+ nod_info *ni;
993+ inode *node = get_nod(fs, nod, &ni);
994+
995+ if(!node->i_blocks)
996+ printf("links to '%s'\n", (char*)node->i_block);
997 else
998 {
999 printf("links to '");
1000 write_blocks(fs, nod, stdout);
1001 printf("'\n");
1002 }
1003+ put_nod(ni);
1004 }
1005
1006 // make a ls-like printout of permissions
1007@@ -2281,8 +2438,12 @@ print_inode(filesystem *fs, uint32 nod)
1008 {
1009 char *s;
1010 char perms[11];
1011- if(!get_nod(fs, nod)->i_mode)
1012- return;
1013+ nod_info *ni;
1014+ inode *node = get_nod(fs, nod, &ni);
1015+ blk_info *bi;
1016+
1017+ if(!node->i_mode)
1018+ goto out;
1019 switch(nod)
1020 {
1021 case EXT2_BAD_INO:
1022@@ -2304,15 +2465,18 @@ print_inode(filesystem *fs, uint32 nod)
1023 default:
1024 s = (nod >= EXT2_FIRST_INO) ? "normal" : "unknown reserved";
1025 }
1026- printf("inode %d (%s, %d links): ", nod, s, get_nod(fs, nod)->i_links_count);
1027- if(!allocated(GRP_GET_INODE_BITMAP(fs,nod), GRP_IBM_OFFSET(fs,nod)))
1028+ printf("inode %d (%s, %d links): ", nod, s, node->i_links_count);
1029+ if(!allocated(GRP_GET_INODE_BITMAP(fs,nod,&bi), GRP_IBM_OFFSET(fs,nod)))
1030 {
1031+ GRP_PUT_INODE_BITMAP(bi);
1032 printf("unallocated\n");
1033- return;
1034+ goto out;
1035 }
1036- make_perms(get_nod(fs, nod)->i_mode, perms);
1037- printf("%s, size: %d byte%s (%d block%s)\n", perms, plural(get_nod(fs, nod)->i_size), plural(get_nod(fs, nod)->i_blocks / INOBLK));
1038- switch(get_nod(fs, nod)->i_mode & FM_IFMT)
1039+ GRP_PUT_INODE_BITMAP(bi);
1040+ make_perms(node->i_mode, perms);
1041+ printf("%s, size: %d byte%s (%d block%s)\n", perms,
1042+ plural(node->i_size), plural(node->i_blocks / INOBLK));
1043+ switch(node->i_mode & FM_IFMT)
1044 {
1045 case FM_IFSOCK:
1046 list_blocks(fs, nod);
1047@@ -2340,6 +2504,8 @@ print_inode(filesystem *fs, uint32 nod)
1048 list_blocks(fs, nod);
1049 }
1050 printf("Done with inode %d\n",nod);
1051+out:
1052+ put_nod(ni);
1053 }
1054
1055 // describes various fields in a filesystem
1056@@ -2347,6 +2513,7 @@ static void
1057 print_fs(filesystem *fs)
1058 {
1059 uint32 i;
1060+ blk_info *bi;
1061 uint8 *ibm;
1062
1063 printf("%d blocks (%d free, %d reserved), first data block: %d\n",
1064@@ -2369,13 +2536,16 @@ print_fs(filesystem *fs)
1065 fs->gd[i].bg_block_bitmap, fs->gd[i].bg_inode_bitmap,
1066 fs->gd[i].bg_inode_table);
1067 printf("block bitmap allocation:\n");
1068- print_bm(GRP_GET_GROUP_BBM(fs, i),fs->sb.s_blocks_per_group);
1069+ print_bm(GRP_GET_GROUP_BBM(fs, i, &bi),
1070+ fs->sb.s_blocks_per_group);
1071+ GRP_PUT_GROUP_BBM(bi);
1072 printf("inode bitmap allocation:\n");
1073- ibm = GRP_GET_GROUP_IBM(fs, i);
1074+ ibm = GRP_GET_GROUP_IBM(fs, i, &bi);
1075 print_bm(ibm, fs->sb.s_inodes_per_group);
1076 for (i = 1; i <= fs->sb.s_inodes_per_group; i++)
1077 if (allocated(ibm, i))
1078 print_inode(fs, i);
1079+ GRP_PUT_GROUP_IBM(bi);
1080 }
1081 }
1082
1083@@ -2646,9 +2816,17 @@ main(int argc, char **argv)
1084
1085 if(emptyval) {
1086 uint32 b;
1087- for(b = 1; b < fs->sb.s_blocks_count; b++)
1088- if(!allocated(GRP_GET_BLOCK_BITMAP(fs,b),GRP_BBM_OFFSET(fs,b)))
1089- memset(get_blk(fs, b), emptyval, BLOCKSIZE);
1090+ for(b = 1; b < fs->sb.s_blocks_count; b++) {
1091+ blk_info *bi;
1092+ if(!allocated(GRP_GET_BLOCK_BITMAP(fs,b,&bi),
1093+ GRP_BBM_OFFSET(fs,b))) {
1094+ blk_info *bi2;
1095+ memset(get_blk(fs, b, &bi2), emptyval,
1096+ BLOCKSIZE);
1097+ put_blk(bi2);
1098+ }
1099+ GRP_PUT_BLOCK_BITMAP(bi);
1100+ }
1101 }
1102 if(verbose)
1103 print_fs(fs);
1104@@ -2658,13 +2836,15 @@ main(int argc, char **argv)
1105 char fname[MAX_FILENAME];
1106 char *p;
1107 FILE *fh;
1108+ nod_info *ni;
1109 if(!(nod = find_path(fs, EXT2_ROOT_INO, gopt[i])))
1110 error_msg_and_die("path %s not found in filesystem", gopt[i]);
1111 while((p = strchr(gopt[i], '/')))
1112 *p = '_';
1113 SNPRINTF(fname, MAX_FILENAME-1, "%s.blk", gopt[i]);
1114 fh = xfopen(fname, "wb");
1115- fprintf(fh, "%d:", get_nod(fs, nod)->i_size);
1116+ fprintf(fh, "%d:", get_nod(fs, nod, &ni)->i_size);
1117+ put_nod(ni);
1118 flist_blocks(fs, nod, fh);
1119 fclose(fh);
1120 }
1121--
11221.7.4.1
1123