Whamcloud - gitweb
11cad6306c0f9c7762494ce97e74f88e0d3da40c
[tools/e2fsprogs.git] / e2fsck / pass1b.c
1 /*
2  * pass1b.c --- Pass #1b of e2fsck
3  *
4  * This file contains pass1B, pass1C, and pass1D of e2fsck.  They are
5  * only invoked if pass 1 discovered blocks which are in use by more
6  * than one inode.
7  * 
8  * Pass1B scans the data blocks of all the inodes again, generating a
9  * complete list of duplicate blocks and which inodes have claimed
10  * them.
11  *
12  * Pass1C does a tree-traversal of the filesystem, to determine the
13  * parent directories of these inodes.  This step is necessary so that
14  * e2fsck can print out the pathnames of affected inodes.
15  *
16  * Pass1D is a reconciliation pass.  For each inode with duplicate
17  * blocks, the user is prompted if s/he would like to clone the file
18  * (so that the file gets a fresh copy of the duplicated blocks) or
19  * simply to delete the file.
20  * 
21  * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
22  *
23  * %Begin-Header%
24  * This file may be redistributed under the terms of the GNU Public
25  * License.
26  * %End-Header%
27  * 
28  */
29
30 #include <time.h>
31 #ifdef HAVE_ERRNO_H
32 #include <errno.h>
33 #endif
34
35 #include <et/com_err.h>
36 #include "e2fsck.h"
37
38 #include "problem.h"
39
40 /*
41  * This is structure is allocated for each time that a block is
42  * claimed by more than one file.  So if a particular block is claimed
43  * by 3 files, then three copies of this structure will be allocated,
44  * one for each conflict.
45  *
46  * The linked list structure is as follows:
47  *
48  * dup_blk -->  block #34  --> block #35  --> block #47
49  *              inode #12      inode #14      inode #17
50  *              num_bad = 3    num_bad = 2    num_bad = 2
51  *                |              |               |
52  *                V              V               V
53  *              block #34      block #35      block #47
54  *              inode #14      inode #15      inode #23
55  *                |
56  *                V
57  *              block #34
58  *              inode #15
59  *
60  * The num_bad field indicates how many inodes are sharing a
61  * particular block, and is only stored in the first element of the
62  * linked list for a particular block.  As the block conflicts are
63  * resolved, num_bad is decremented; when it reaches 1, then we no
64  * longer need to worry about that block.
65  */
66 struct dup_block {
67         blk_t           block;          /* Block number */
68         ino_t           ino;            /* Inode number */
69         int             num_bad;
70         /* Pointer to next dup record with different block */
71         struct dup_block *next_block;
72         /* Pointer to next dup record with different inode */
73         struct dup_block *next_inode;
74 };
75
76 /*
77  * This structure stores information about a particular inode which
78  * is sharing blocks with other inodes.  This information is collected
79  * to display to the user, so that the user knows what files he or she
80  * is dealing with, when trying to decide how to resolve the conflict
81  * of multiply-claimed blocks.
82  */
83 struct dup_inode {
84         ino_t                   ino, dir;
85         int                     num_dupblocks;
86         struct ext2_inode       inode;
87         struct dup_inode        *next;
88 };
89
90 static int process_pass1b_block(ext2_filsys fs, blk_t   *blocknr,
91                                 e2_blkcnt_t blockcnt, blk_t ref_blk, 
92                                 int ref_offset, void *priv_data);
93 static void delete_file(e2fsck_t ctx, struct dup_inode *dp,
94                         char *block_buf);
95 static int clone_file(e2fsck_t ctx, struct dup_inode *dp, char* block_buf);
96 static int check_if_fs_block(e2fsck_t ctx, blk_t test_blk);
97
98 static void pass1b(e2fsck_t ctx, char *block_buf);
99 static void pass1c(e2fsck_t ctx, char *block_buf);
100 static void pass1d(e2fsck_t ctx, char *block_buf);
101
102 static struct dup_block *dup_blk = 0;
103 static struct dup_inode *dup_ino = 0;
104 static int dup_inode_count = 0;
105
106 static ext2fs_inode_bitmap inode_dup_map;
107
108 /*
109  * Main procedure for handling duplicate blocks
110  */
111 void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf)
112 {
113         ext2_filsys             fs = ctx->fs;
114         struct dup_block        *p, *q, *next_p, *next_q;
115         struct dup_inode        *r, *next_r;
116         struct problem_context  pctx;
117
118         clear_problem_context(&pctx);
119         
120         pctx.errcode = ext2fs_allocate_inode_bitmap(fs,
121                       _("multiply claimed inode map"), &inode_dup_map);
122         if (pctx.errcode) {
123                 fix_problem(ctx, PR_1B_ALLOCATE_IBITMAP_ERROR, &pctx);
124                 ctx->flags |= E2F_FLAG_ABORT;
125                 return;
126         }
127         
128         pass1b(ctx, block_buf);
129         pass1c(ctx, block_buf);
130         pass1d(ctx, block_buf);
131
132         /*
133          * Time to free all of the accumulated data structures that we
134          * don't need anymore.
135          */
136         ext2fs_free_inode_bitmap(inode_dup_map); inode_dup_map = 0;
137         ext2fs_free_block_bitmap(ctx->block_dup_map); ctx->block_dup_map = 0;
138         for (p = dup_blk; p; p = next_p) {
139                 next_p = p->next_block;
140                 for (q = p; q; q = next_q) {
141                         next_q = q->next_inode;
142                         ext2fs_free_mem((void **) &q);
143                 }
144         }
145         for (r = dup_ino; r; r = next_r) {
146                 next_r = r->next;
147                 ext2fs_free_mem((void **) &r);
148         }
149 }
150
151 /*
152  * Scan the inodes looking for inodes that contain duplicate blocks.
153  */
154 struct process_block_struct {
155         ino_t   ino;
156         int     dup_blocks;
157         e2fsck_t ctx;
158         struct problem_context *pctx;
159 };
160
161 static void pass1b(e2fsck_t ctx, char *block_buf)
162 {
163         ext2_filsys fs = ctx->fs;
164         ino_t   ino;
165         struct ext2_inode inode;
166         ext2_inode_scan scan;
167         struct process_block_struct pb;
168         struct dup_inode *dp;
169         struct problem_context pctx;
170
171         clear_problem_context(&pctx);
172         
173         fix_problem(ctx, PR_1B_PASS_HEADER, &pctx);
174         pctx.errcode = ext2fs_open_inode_scan(fs, ctx->inode_buffer_blocks,
175                                               &scan);
176         if (pctx.errcode) {
177                 fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
178                 ctx->flags |= E2F_FLAG_ABORT;
179                 return;
180         }
181         pctx.errcode = ext2fs_get_next_inode(scan, &ino, &inode);
182         if (pctx.errcode) {
183                 fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
184                 ctx->flags |= E2F_FLAG_ABORT;
185                 return;
186         }
187         ctx->stashed_inode = &inode;
188         pb.ctx = ctx;
189         pb.pctx = &pctx;
190         pctx.str = "pass1b";
191         while (ino) {
192                 pctx.ino = ctx->stashed_ino = ino;
193                 if ((ino != EXT2_BAD_INO) &&
194                     (!ext2fs_test_inode_bitmap(ctx->inode_used_map, ino) ||
195                      !ext2fs_inode_has_valid_blocks(&inode)))
196                         goto next;
197
198                 pb.ino = ino;
199                 pb.dup_blocks = 0;
200                 pctx.errcode = ext2fs_block_iterate2(fs, ino, 0, block_buf,
201                                               process_pass1b_block, &pb);
202                 if (pb.dup_blocks) {
203                         end_problem_latch(ctx, PR_LATCH_DBLOCK);
204                         dp = (struct dup_inode *) e2fsck_allocate_memory(ctx,
205                                     sizeof(struct dup_inode),
206                                     "duplicate inode record");
207                         dp->ino = ino;
208                         dp->dir = 0;
209                         dp->inode = inode;
210                         dp->num_dupblocks = pb.dup_blocks;
211                         dp->next = dup_ino;
212                         dup_ino = dp;
213                         if (ino != EXT2_BAD_INO)
214                                 dup_inode_count++;
215                 }
216                 if (pctx.errcode)
217                         fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
218         next:
219                 pctx.errcode = ext2fs_get_next_inode(scan, &ino, &inode);
220                 if (pctx.errcode == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE)
221                         goto next;
222                 if (pctx.errcode) {
223                         fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
224                         ctx->flags |= E2F_FLAG_ABORT;
225                         return;
226                 }
227         }
228         ext2fs_close_inode_scan(scan);
229         fs->get_blocks = 0;
230         fs->check_directory = 0;
231 }
232
233 static int process_pass1b_block(ext2_filsys fs,
234                                 blk_t   *block_nr,
235                                 e2_blkcnt_t blockcnt,
236                                 blk_t ref_blk, 
237                                 int ref_offset,                          
238                                 void *priv_data)
239 {
240         struct process_block_struct *p;
241         struct dup_block *dp, *q, *r;
242         int i;
243         e2fsck_t ctx;
244
245         if (HOLE_BLKADDR(*block_nr))
246                 return 0;
247         p = (struct process_block_struct *) priv_data;
248         ctx = p->ctx;
249         
250         if (ext2fs_test_block_bitmap(ctx->block_dup_map, *block_nr)) {
251                 /* OK, this is a duplicate block */
252                 if (p->ino != EXT2_BAD_INO) {
253                         p->pctx->blk = *block_nr;
254                         fix_problem(ctx, PR_1B_DUP_BLOCK, p->pctx);
255                 }
256                 p->dup_blocks++;
257                 ext2fs_mark_block_bitmap(ctx->block_dup_map, *block_nr);
258                 ext2fs_mark_inode_bitmap(inode_dup_map, p->ino);
259                 dp = (struct dup_block *) e2fsck_allocate_memory(ctx,
260                                             sizeof(struct dup_block),
261                                             "duplicate block record");
262                 dp->block = *block_nr;
263                 dp->ino = p->ino;
264                 dp->num_bad = 0;
265                 q = dup_blk;
266                 while (q) {
267                         if (q->block == *block_nr)
268                                 break;
269                         q = q->next_block;
270                 }
271                 if (q) {
272                         dp->next_inode = q->next_inode;
273                         q->next_inode = dp;
274                 } else {
275                         dp->next_block = dup_blk;
276                         dup_blk = dp;
277                 }
278         }
279         /*
280          * Set the num_bad field
281          */
282         for (q = dup_blk; q; q = q->next_block) {
283                 i = 0;
284                 for (r = q; r; r = r->next_inode)
285                         i++;
286                 q->num_bad = i;
287         }
288         return 0;
289 }
290
291 /*
292  * Pass 1c: Scan directories for inodes with duplicate blocks.  This
293  * is used so that we can print pathnames when prompting the user for
294  * what to do.
295  */
296 struct search_dir_struct {
297         int             count;
298         ino_t           first_inode;
299         ino_t           max_inode;
300 };
301
302 static int search_dirent_proc(ino_t dir, int entry,
303                               struct ext2_dir_entry *dirent,
304                               int offset, int blocksize,
305                               char *buf, void *priv_data)
306 {
307         struct search_dir_struct *sd;
308         struct dup_inode        *p;
309
310         sd = (struct search_dir_struct *) priv_data;
311
312         if (dirent->inode > sd->max_inode)
313                 /* Should abort this inode, but not everything */
314                 return 0;       
315
316         if (!dirent->inode || (entry < DIRENT_OTHER_FILE) ||
317             !ext2fs_test_inode_bitmap(inode_dup_map, dirent->inode))
318                 return 0;
319
320         for (p = dup_ino; p; p = p->next) {
321                 if ((p->ino >= sd->first_inode) && 
322                     (p->ino == dirent->inode))
323                         break;
324         }
325
326         if (!p || p->dir)
327                 return 0;
328
329         p->dir = dir;
330         sd->count--;
331
332         return(sd->count ? 0 : DIRENT_ABORT);
333 }
334
335
336 static void pass1c(e2fsck_t ctx, char *block_buf)
337 {
338         ext2_filsys fs = ctx->fs;
339         struct dup_inode        *p;
340         int     inodes_left = dup_inode_count;
341         struct search_dir_struct sd;
342         struct problem_context pctx;
343
344         clear_problem_context(&pctx);
345
346         fix_problem(ctx, PR_1C_PASS_HEADER, &pctx);
347
348         /*
349          * First check to see if any of the inodes with dup blocks is
350          * a special inode.  (Note that the bad block inode isn't
351          * counted.)
352          */
353         for (p = dup_ino; p; p = p->next) {
354                 if ((p->ino < EXT2_FIRST_INODE(fs->super)) &&
355                     (p->ino != EXT2_BAD_INO))
356                         inodes_left--;
357         }
358
359         /*
360          * Search through all directories to translate inodes to names
361          * (by searching for the containing directory for that inode.)
362          */
363         sd.count = inodes_left;
364         sd.first_inode = EXT2_FIRST_INODE(fs->super);
365         sd.max_inode = fs->super->s_inodes_count;
366         ext2fs_dblist_dir_iterate(fs->dblist, 0, block_buf,
367                                   search_dirent_proc, &sd);
368 }       
369
370 static void pass1d(e2fsck_t ctx, char *block_buf)
371 {
372         ext2_filsys fs = ctx->fs;
373         struct dup_inode        *p, *s;
374         struct dup_block        *q, *r;
375         ino_t   *shared;
376         int     shared_len;
377         int     i;
378         int     file_ok;
379         int     meta_data = 0;
380         struct problem_context pctx;
381
382         clear_problem_context(&pctx);
383         
384         fix_problem(ctx, PR_1D_PASS_HEADER, &pctx);
385         e2fsck_read_bitmaps(ctx);
386
387         pctx.num = dup_inode_count;
388         fix_problem(ctx, PR_1D_NUM_DUP_INODES, &pctx);
389         shared = (ino_t *) e2fsck_allocate_memory(ctx,
390                                 sizeof(ino_t) * dup_inode_count,
391                                 "Shared inode list");
392         for (p = dup_ino; p; p = p->next) {
393                 shared_len = 0;
394                 file_ok = 1;
395                 if (p->ino == EXT2_BAD_INO)
396                         continue;
397
398                 /*
399                  * Search through the duplicate records to see which
400                  * inodes share blocks with this one
401                  */
402                 for (q = dup_blk; q; q = q->next_block) {
403                         /*
404                          * See if this block is used by this inode.
405                          * If it isn't, continue.
406                          */
407                         for (r = q; r; r = r->next_inode)
408                                 if (r->ino == p->ino)
409                                         break;
410                         if (!r)
411                                 continue;
412                         if (q->num_bad > 1)
413                                 file_ok = 0;
414                         if (check_if_fs_block(ctx, q->block)) {
415                                 file_ok = 0;
416                                 meta_data = 1;
417                         }
418                         
419                         /*
420                          * Add all inodes used by this block to the
421                          * shared[] --- which is a unique list, so
422                          * if an inode is already in shared[], don't
423                          * add it again.
424                          */
425                         for (r = q; r; r = r->next_inode) {
426                                 if (r->ino == p->ino)
427                                         continue;
428                                 for (i = 0; i < shared_len; i++)
429                                         if (shared[i] == r->ino)
430                                                 break;
431                                 if (i == shared_len) {
432                                         shared[shared_len++] = r->ino;
433                                 }
434                         }
435                 }
436
437                 /*
438                  * Report the inode that we are working on
439                  */
440                 pctx.inode = &p->inode;
441                 pctx.ino = p->ino;
442                 pctx.dir = p->dir;
443                 pctx.blkcount = p->num_dupblocks;
444                 pctx.num = meta_data ? shared_len+1 : shared_len;
445                 fix_problem(ctx, PR_1D_DUP_FILE, &pctx);
446                 pctx.blkcount = 0;
447                 pctx.num = 0;
448                 
449                 if (meta_data)
450                         fix_problem(ctx, PR_1D_SHARE_METADATA, &pctx);
451                 
452                 for (i = 0; i < shared_len; i++) {
453                         for (s = dup_ino; s; s = s->next)
454                                 if (s->ino == shared[i])
455                                         break;
456                         if (!s)
457                                 continue;
458                         /*
459                          * Report the inode that we are sharing with
460                          */
461                         pctx.inode = &s->inode;
462                         pctx.ino = s->ino;
463                         pctx.dir = s->dir;
464                         fix_problem(ctx, PR_1D_DUP_FILE_LIST, &pctx);
465                 }
466                 if (file_ok) {
467                         fix_problem(ctx, PR_1D_DUP_BLOCKS_DEALT, &pctx);
468                         continue;
469                 }
470                 if (fix_problem(ctx, PR_1D_CLONE_QUESTION, &pctx)) {
471                         pctx.errcode = clone_file(ctx, p, block_buf);
472                         if (pctx.errcode)
473                                 fix_problem(ctx, PR_1D_CLONE_ERROR, &pctx);
474                         else
475                                 continue;
476                 }
477                 if (fix_problem(ctx, PR_1D_DELETE_QUESTION, &pctx))
478                         delete_file(ctx, p, block_buf);
479                 else
480                         ext2fs_unmark_valid(fs);
481         }
482         ext2fs_free_mem((void **) &shared);
483 }
484
485 static int delete_file_block(ext2_filsys fs,
486                              blk_t      *block_nr,
487                              e2_blkcnt_t blockcnt,
488                              blk_t ref_block,
489                              int ref_offset, 
490                              void *priv_data)
491 {
492         struct process_block_struct *pb;
493         struct dup_block *p;
494         e2fsck_t ctx;
495
496         pb = (struct process_block_struct *) priv_data;
497         ctx = pb->ctx;
498
499         if (HOLE_BLKADDR(*block_nr))
500                 return 0;
501
502         if (ext2fs_test_block_bitmap(ctx->block_dup_map, *block_nr)) {
503                 for (p = dup_blk; p; p = p->next_block)
504                         if (p->block == *block_nr)
505                                 break;
506                 if (p) {
507                         p->num_bad--;
508                         if (p->num_bad == 1)
509                                 ext2fs_unmark_block_bitmap(ctx->block_dup_map,
510                                                            *block_nr);
511                 } else
512                         com_err("delete_file_block", 0,
513                             _("internal error; can't find dup_blk for %d\n"),
514                                 *block_nr);
515         } else {
516                 ext2fs_unmark_block_bitmap(ctx->block_found_map, *block_nr);
517                 ext2fs_unmark_block_bitmap(fs->block_map, *block_nr);
518         }
519                 
520         return 0;
521 }
522                 
523 static void delete_file(e2fsck_t ctx, struct dup_inode *dp, char* block_buf)
524 {
525         ext2_filsys fs = ctx->fs;
526         struct process_block_struct pb;
527         struct ext2_inode       inode;
528         struct problem_context  pctx;
529
530         clear_problem_context(&pctx);
531         pctx.ino = pb.ino = dp->ino;
532         pb.dup_blocks = dp->num_dupblocks;
533         pb.ctx = ctx;
534         pctx.str = "delete_file";
535
536         pctx.errcode = ext2fs_block_iterate2(fs, dp->ino, 0, block_buf,
537                                        delete_file_block, &pb);
538         if (pctx.errcode)
539                 fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
540         ext2fs_unmark_inode_bitmap(ctx->inode_used_map, dp->ino);
541         ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, dp->ino);
542         if (ctx->inode_bad_map)
543                 ext2fs_unmark_inode_bitmap(ctx->inode_bad_map, dp->ino);
544         ext2fs_unmark_inode_bitmap(fs->inode_map, dp->ino);
545         ext2fs_mark_ib_dirty(fs);
546         ext2fs_mark_bb_dirty(fs);
547         e2fsck_read_inode(ctx, dp->ino, &inode, "delete_file");
548         inode.i_links_count = 0;
549         inode.i_dtime = time(0);
550         e2fsck_write_inode(ctx, dp->ino, &inode, "delete_file");
551 }
552
553 struct clone_struct {
554         errcode_t       errcode;
555         ino_t           dir;
556         char    *buf;
557         e2fsck_t ctx;
558 };
559
560 static int clone_file_block(ext2_filsys fs,
561                             blk_t       *block_nr,
562                             e2_blkcnt_t blockcnt,
563                             blk_t ref_block,
564                             int ref_offset, 
565                             void *priv_data)
566 {
567         struct dup_block *p;
568         blk_t   new_block;
569         errcode_t       retval;
570         struct clone_struct *cs = (struct clone_struct *) priv_data;
571         e2fsck_t ctx;
572
573         ctx = cs->ctx;
574         
575         if (HOLE_BLKADDR(*block_nr))
576                 return 0;
577
578         if (ext2fs_test_block_bitmap(ctx->block_dup_map, *block_nr)) {
579                 for (p = dup_blk; p; p = p->next_block)
580                         if (p->block == *block_nr)
581                                 break;
582                 if (p) {
583                         retval = ext2fs_new_block(fs, 0, ctx->block_found_map,
584                                                   &new_block);
585                         if (retval) {
586                                 cs->errcode = retval;
587                                 return BLOCK_ABORT;
588                         }
589                         if (cs->dir) {
590                                 retval = ext2fs_set_dir_block(fs->dblist,
591                                       cs->dir, new_block, blockcnt);
592                                 if (retval) {
593                                         cs->errcode = retval;
594                                         return BLOCK_ABORT;
595                                 }
596                         }
597                         retval = io_channel_read_blk(fs->io, *block_nr, 1,
598                                                      cs->buf);
599                         if (retval) {
600                                 cs->errcode = retval;
601                                 return BLOCK_ABORT;
602                         }
603                         retval = io_channel_write_blk(fs->io, new_block, 1,
604                                                       cs->buf);
605                         if (retval) {
606                                 cs->errcode = retval;
607                                 return BLOCK_ABORT;
608                         }
609                         p->num_bad--;
610                         if (p->num_bad == 1 &&
611                             !check_if_fs_block(ctx, *block_nr))
612                                 ext2fs_unmark_block_bitmap(ctx->block_dup_map,
613                                                            *block_nr);
614                         *block_nr = new_block;
615                         ext2fs_mark_block_bitmap(ctx->block_found_map,
616                                                  new_block);
617                         ext2fs_mark_block_bitmap(fs->block_map, new_block);
618                         return BLOCK_CHANGED;
619                 } else
620                         com_err("clone_file_block", 0,
621                             _("internal error; can't find dup_blk for %d\n"),
622                                 *block_nr);
623         }
624         return 0;
625 }
626                 
627 static int clone_file(e2fsck_t ctx, struct dup_inode *dp, char* block_buf)
628 {
629         ext2_filsys fs = ctx->fs;
630         errcode_t       retval;
631         struct clone_struct cs;
632         struct problem_context  pctx;
633
634         clear_problem_context(&pctx);
635         cs.errcode = 0;
636         cs.dir = 0;
637         cs.ctx = ctx;
638         retval = ext2fs_get_mem(fs->blocksize, (void **) &cs.buf);
639         if (retval)
640                 return retval;
641
642         if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, dp->ino))
643                 cs.dir = dp->ino;
644
645         pctx.ino = dp->ino;
646         pctx.str = "clone_file";
647         pctx.errcode = ext2fs_block_iterate2(fs, dp->ino, 0, block_buf,
648                                       clone_file_block, &cs);
649         ext2fs_mark_bb_dirty(fs);
650         ext2fs_free_mem((void **) &cs.buf);
651         if (pctx.errcode) {
652                 fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
653                 return pctx.errcode;
654         }
655         if (cs.errcode) {
656                 com_err("clone_file", cs.errcode,
657                         _("returned from clone_file_block"));
658                 return cs.errcode;
659         }
660         return 0;
661 }
662
663 /*
664  * This routine returns 1 if a block overlaps with one of the superblocks,
665  * group descriptors, inode bitmaps, or block bitmaps.
666  */
667 static int check_if_fs_block(e2fsck_t ctx, blk_t test_block)
668 {
669         ext2_filsys fs = ctx->fs;
670         blk_t   block;
671         int     i;
672         
673         block = fs->super->s_first_data_block;
674         for (i = 0; i < fs->group_desc_count; i++) {
675
676                 /* Check superblocks/block group descriptros */
677                 if (ext2fs_bg_has_super(fs, i)) {
678                         if (test_block >= block &&
679                             (test_block <= block + fs->desc_blocks))
680                                 return 1;
681                 }
682                 
683                 /* Check the inode table */
684                 if ((fs->group_desc[i].bg_inode_table) &&
685                     (test_block >= fs->group_desc[i].bg_inode_table) &&
686                     (test_block < (fs->group_desc[i].bg_inode_table +
687                                    fs->inode_blocks_per_group)))
688                         return 1;
689
690                 /* Check the bitmap blocks */
691                 if ((test_block == fs->group_desc[i].bg_block_bitmap) ||
692                     (test_block == fs->group_desc[i].bg_inode_bitmap))
693                         return 1;
694                 
695                 block += fs->super->s_blocks_per_group;
696         }
697         return 0;
698 }