home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.0 / LINUX-1.0 / LINUX-1 / linux / fs / ext2 / ialloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-08  |  15.9 KB  |  578 lines

  1. /*
  2.  *  linux/fs/ext2/ialloc.c
  3.  *
  4.  *  Copyright (C) 1992, 1993, 1994  Remy Card (card@masi.ibp.fr)
  5.  *                                  Laboratoire MASI - Institut Blaise Pascal
  6.  *                                  Universite Pierre et Marie Curie (Paris VI)
  7.  *
  8.  *  BSD ufs-inspired inode and directory allocation by 
  9.  *  Stephen Tweedie (sct@dcs.ed.ac.uk), 1993
  10.  */
  11.  
  12. /*
  13.  * ialloc.c contains the inodes allocation and deallocation routines
  14.  */
  15.  
  16. /*
  17.  * The free inodes are managed by bitmaps.  A file system contains several
  18.  * blocks groups.  Each group contains 1 bitmap block for blocks, 1 bitmap
  19.  * block for inodes, N blocks for the inode table and data blocks.
  20.  *
  21.  * The file system contains group descriptors which are located after the
  22.  * super block.  Each descriptor contains the number of the bitmap block and
  23.  * the free blocks count in the block.  The descriptors are loaded in memory
  24.  * when a file system is mounted (see ext2_read_super).
  25.  */
  26.  
  27. #include <linux/fs.h>
  28. #include <linux/ext2_fs.h>
  29. #include <linux/sched.h>
  30. #include <linux/stat.h>
  31. #include <linux/string.h>
  32. #include <linux/locks.h>
  33.  
  34. #include <asm/bitops.h>
  35.  
  36. static inline int find_first_zero_bit (unsigned long * addr, unsigned size)
  37. {
  38.     int res;
  39.  
  40.     if (!size)
  41.         return 0;
  42.     __asm__("
  43.         cld
  44.         movl $-1,%%eax
  45.         repe; scasl
  46.         je 1f
  47.         subl $4,%%edi
  48.         movl (%%edi),%%eax
  49.         notl %%eax
  50.         bsfl %%eax,%%edx
  51.         jmp 2f
  52. 1:        xorl %%edx,%%edx
  53. 2:        subl %%ebx,%%edi
  54.         shll $3,%%edi
  55.         addl %%edi,%%edx"
  56.         : "=d" (res)
  57.         : "c" ((size + 31) >> 5), "D" (addr), "b" (addr)
  58.         : "ax", "bx", "cx", "di");
  59.     return res;
  60. }
  61.  
  62. static struct ext2_group_desc * get_group_desc (struct super_block * sb,
  63.                         unsigned int block_group,
  64.                         struct buffer_head ** bh)
  65. {
  66.     unsigned long group_desc;
  67.     unsigned long desc;
  68.     struct ext2_group_desc * gdp;
  69.  
  70.     if (block_group >= sb->u.ext2_sb.s_groups_count)
  71.         ext2_panic (sb, "get_group_desc",
  72.                 "block_group >= groups_count\n"
  73.                 "block_group = %d, groups_count = %lu",
  74.                 block_group, sb->u.ext2_sb.s_groups_count);
  75.  
  76.     group_desc = block_group / EXT2_DESC_PER_BLOCK(sb);
  77.     desc = block_group % EXT2_DESC_PER_BLOCK(sb);
  78.     if (!sb->u.ext2_sb.s_group_desc[group_desc])
  79.         ext2_panic (sb, "get_group_desc",
  80.                 "Group descriptor not loaded\n"
  81.                 "block_group = %d, group_desc = %lu, desc = %lu",
  82.                  block_group, group_desc, desc);
  83.     gdp = (struct ext2_group_desc *) 
  84.         sb->u.ext2_sb.s_group_desc[group_desc]->b_data;
  85.     if (bh)
  86.         *bh = sb->u.ext2_sb.s_group_desc[group_desc];
  87.     return gdp + desc;
  88. }
  89.  
  90. static void read_inode_bitmap (struct super_block * sb,
  91.                    unsigned long block_group,
  92.                    unsigned int bitmap_nr)
  93. {
  94.     struct ext2_group_desc * gdp;
  95.     struct buffer_head * bh;
  96.  
  97.     gdp = get_group_desc (sb, block_group, NULL);
  98.     bh = bread (sb->s_dev, gdp->bg_inode_bitmap, sb->s_blocksize);
  99.     if (!bh)
  100.         ext2_panic (sb, "read_inode_bitmap", "Cannot read inode bitmap\n"
  101.                 "block_group = %lu, inode_bitmap = %lu",
  102.                 block_group, gdp->bg_inode_bitmap);
  103.     sb->u.ext2_sb.s_inode_bitmap_number[bitmap_nr] = block_group;
  104.     sb->u.ext2_sb.s_inode_bitmap[bitmap_nr] = bh;
  105. }
  106.  
  107. /*
  108.  * load_inode_bitmap loads the inode bitmap for a blocks group
  109.  *
  110.  * It maintains a cache for the last bitmaps loaded.  This cache is managed
  111.  * with a LRU algorithm.
  112.  *
  113.  * Notes:
  114.  * 1/ There is one cache per mounted file system.
  115.  * 2/ If the file system contains less than EXT2_MAX_GROUP_LOADED groups,
  116.  *    this function reads the bitmap without maintaining a LRU cache.
  117.  */
  118. static int load_inode_bitmap (struct super_block * sb,
  119.                   unsigned int block_group)
  120. {
  121.     int i, j;
  122.     unsigned long inode_bitmap_number;
  123.     struct buffer_head * inode_bitmap;
  124.  
  125.     if (block_group >= sb->u.ext2_sb.s_groups_count)
  126.         ext2_panic (sb, "load_inode_bitmap",
  127.                 "block_group >= groups_count\n"
  128.                 "block_group = %d, groups_count = %lu",
  129.                  block_group, sb->u.ext2_sb.s_groups_count);
  130.     if (sb->u.ext2_sb.s_loaded_inode_bitmaps > 0 &&
  131.         sb->u.ext2_sb.s_inode_bitmap_number[0] == block_group)
  132.         return 0;
  133.     if (sb->u.ext2_sb.s_groups_count <= EXT2_MAX_GROUP_LOADED) {
  134.         if (sb->u.ext2_sb.s_inode_bitmap[block_group]) {
  135.             if (sb->u.ext2_sb.s_inode_bitmap_number[block_group] != block_group)
  136.                 ext2_panic (sb, "load_inode_bitmap",
  137.                         "block_group != inode_bitmap_number");
  138.             else
  139.                 return block_group;
  140.         } else {
  141.             read_inode_bitmap (sb, block_group, block_group);
  142.             return block_group;
  143.         }
  144.     }
  145.  
  146.     for (i = 0; i < sb->u.ext2_sb.s_loaded_inode_bitmaps &&
  147.             sb->u.ext2_sb.s_inode_bitmap_number[i] != block_group;
  148.          i++)
  149.         ;
  150.     if (i < sb->u.ext2_sb.s_loaded_inode_bitmaps &&
  151.           sb->u.ext2_sb.s_inode_bitmap_number[i] == block_group) {
  152.         inode_bitmap_number = sb->u.ext2_sb.s_inode_bitmap_number[i];
  153.         inode_bitmap = sb->u.ext2_sb.s_inode_bitmap[i];
  154.         for (j = i; j > 0; j--) {
  155.             sb->u.ext2_sb.s_inode_bitmap_number[j] =
  156.                 sb->u.ext2_sb.s_inode_bitmap_number[j - 1];
  157.             sb->u.ext2_sb.s_inode_bitmap[j] =
  158.                 sb->u.ext2_sb.s_inode_bitmap[j - 1];
  159.         }
  160.         sb->u.ext2_sb.s_inode_bitmap_number[0] = inode_bitmap_number;
  161.         sb->u.ext2_sb.s_inode_bitmap[0] = inode_bitmap;
  162.     } else {
  163.         if (sb->u.ext2_sb.s_loaded_inode_bitmaps < EXT2_MAX_GROUP_LOADED)
  164.             sb->u.ext2_sb.s_loaded_inode_bitmaps++;
  165.         else
  166.             brelse (sb->u.ext2_sb.s_inode_bitmap[EXT2_MAX_GROUP_LOADED - 1]);
  167.         for (j = sb->u.ext2_sb.s_loaded_inode_bitmaps - 1; j > 0; j--) {
  168.             sb->u.ext2_sb.s_inode_bitmap_number[j] =
  169.                 sb->u.ext2_sb.s_inode_bitmap_number[j - 1];
  170.             sb->u.ext2_sb.s_inode_bitmap[j] =
  171.                 sb->u.ext2_sb.s_inode_bitmap[j - 1];
  172.         }
  173.         read_inode_bitmap (sb, block_group, 0);
  174.     }
  175.     return 0;
  176. }
  177.  
  178. /*
  179.  * This function sets the deletion time for the inode
  180.  *
  181.  * This may be used one day by an 'undelete' program
  182.  */
  183. static void set_inode_dtime (struct inode * inode,
  184.                  struct ext2_group_desc * gdp)
  185. {
  186.     unsigned long inode_block;
  187.     struct buffer_head * bh;
  188.     struct ext2_inode * raw_inode;
  189.  
  190.     inode_block = gdp->bg_inode_table + (((inode->i_ino - 1) %
  191.             EXT2_INODES_PER_GROUP(inode->i_sb)) /
  192.             EXT2_INODES_PER_BLOCK(inode->i_sb));
  193.     bh = bread (inode->i_sb->s_dev, inode_block, inode->i_sb->s_blocksize);
  194.     if (!bh)
  195.         ext2_panic (inode->i_sb, "set_inode_dtime",
  196.                 "Cannot load inode table block\n"
  197.                 "inode=%lu, inode_block=%lu",
  198.                 inode->i_ino, inode_block);
  199.     raw_inode = ((struct ext2_inode *) bh->b_data) +
  200.             (((inode->i_ino - 1) %
  201.             EXT2_INODES_PER_GROUP(inode->i_sb)) %
  202.             EXT2_INODES_PER_BLOCK(inode->i_sb));
  203.     raw_inode->i_links_count = 0;
  204.     raw_inode->i_dtime = CURRENT_TIME;
  205.     bh->b_dirt = 1;
  206.     if (IS_SYNC(inode)) {
  207.         ll_rw_block (WRITE, 1, &bh);
  208.         wait_on_buffer (bh);
  209.     }
  210.     brelse (bh);
  211. }
  212.  
  213. void ext2_free_inode (struct inode * inode)
  214. {
  215.     struct super_block * sb;
  216.     struct buffer_head * bh;
  217.     struct buffer_head * bh2;
  218.     unsigned long block_group;
  219.     unsigned long bit;
  220.     int bitmap_nr;
  221.     struct ext2_group_desc * gdp;
  222.     struct ext2_super_block * es;
  223.  
  224.     if (!inode)
  225.         return;
  226.     if (!inode->i_dev) {
  227.         printk ("ext2_free_inode: inode has no device\n");
  228.         return;
  229.     }
  230.     if (inode->i_count > 1) {
  231.         printk ("ext2_free_inode: inode has count=%d\n",
  232.             inode->i_count);
  233.         return;
  234.     }
  235.     if (inode->i_nlink) {
  236.         printk ("ext2_free_inode: inode has nlink=%d\n",
  237.             inode->i_nlink);
  238.         return;
  239.     }
  240.     if (!inode->i_sb) {
  241.         printk("ext2_free_inode: inode on nonexistent device\n");
  242.         return;
  243.     }
  244.  
  245.     ext2_debug ("freeing inode %lu\n", inode->i_ino);
  246.  
  247.     sb = inode->i_sb;
  248.     lock_super (sb);
  249.     if (inode->i_ino < EXT2_FIRST_INO ||
  250.         inode->i_ino > sb->u.ext2_sb.s_es->s_inodes_count) {
  251.         ext2_error (sb, "free_inode",
  252.                 "reserved inode or nonexistent inode");
  253.         unlock_super (sb);
  254.         return;
  255.     }
  256.     es = sb->u.ext2_sb.s_es;
  257.     block_group = (inode->i_ino - 1) / EXT2_INODES_PER_GROUP(sb);
  258.     bit = (inode->i_ino - 1) % EXT2_INODES_PER_GROUP(sb);
  259.     bitmap_nr = load_inode_bitmap (sb, block_group);
  260.     bh = sb->u.ext2_sb.s_inode_bitmap[bitmap_nr];
  261.     if (!clear_bit (bit, bh->b_data))
  262.         ext2_warning (sb, "ext2_free_inode",
  263.                   "bit already cleared for inode %lu", inode->i_ino);
  264.     else {
  265.         gdp = get_group_desc (sb, block_group, &bh2);
  266.         gdp->bg_free_inodes_count++;
  267.         if (S_ISDIR(inode->i_mode))
  268.             gdp->bg_used_dirs_count--;
  269.         bh2->b_dirt = 1;
  270.         es->s_free_inodes_count++;
  271.         sb->u.ext2_sb.s_sbh->b_dirt = 1;
  272.         set_inode_dtime (inode, gdp);
  273.     }
  274.     bh->b_dirt = 1;
  275.     if (sb->s_flags & MS_SYNC) {
  276.         ll_rw_block (WRITE, 1, &bh);
  277.         wait_on_buffer (bh);
  278.     }
  279.  
  280.     sb->s_dirt = 1;
  281.     clear_inode (inode);
  282.     unlock_super (sb);
  283. }
  284.  
  285. /*
  286.  * This function increments the inode version number
  287.  *
  288.  * This may be used one day by the NFS server
  289.  */
  290. static void inc_inode_version (struct inode * inode,
  291.                    struct ext2_group_desc *gdp,
  292.                    int mode)
  293. {
  294.     unsigned long inode_block;
  295.     struct buffer_head * bh;
  296.     struct ext2_inode * raw_inode;
  297.  
  298.     inode_block = gdp->bg_inode_table + (((inode->i_ino - 1) %
  299.             EXT2_INODES_PER_GROUP(inode->i_sb)) /
  300.             EXT2_INODES_PER_BLOCK(inode->i_sb));
  301.     bh = bread (inode->i_sb->s_dev, inode_block, inode->i_sb->s_blocksize);
  302.     if (!bh) {
  303.         ext2_error (inode->i_sb, "inc_inode_version",
  304.                 "Cannot load inode table block"
  305.                 "inode=%lu, inode_block=%lu\n",
  306.                 inode->i_ino, inode_block);
  307.         inode->u.ext2_i.i_version = 1;
  308.         return;
  309.     }
  310.     raw_inode = ((struct ext2_inode *) bh->b_data) +
  311.             (((inode->i_ino - 1) %
  312.             EXT2_INODES_PER_GROUP(inode->i_sb)) %
  313.             EXT2_INODES_PER_BLOCK(inode->i_sb));
  314.     raw_inode->i_version++;
  315.     inode->u.ext2_i.i_version = raw_inode->i_version;
  316.     bh->b_dirt = 1;
  317.     brelse (bh);
  318. }
  319.  
  320. /*
  321.  * There are two policies for allocating an inode.  If the new inode is
  322.  * a directory, then a forward search is made for a block group with both
  323.  * free space and a low directory-to-inode ratio; if that fails, then of
  324.  * the groups with above-average free space, that group with the fewest
  325.  * directories already is chosen.
  326.  *
  327.  * For other inodes, search forward from the parent directory\'s block
  328.  * group to find a free inode.
  329.  */
  330. struct inode * ext2_new_inode (const struct inode * dir, int mode)
  331. {
  332.     struct super_block * sb;
  333.     struct buffer_head * bh;
  334.     struct buffer_head * bh2;
  335.     int i, j, avefreei;
  336.     struct inode * inode;
  337.     int bitmap_nr;
  338.     struct ext2_group_desc * gdp;
  339.     struct ext2_group_desc * tmp;
  340.     struct ext2_super_block * es;
  341.  
  342.     if (!dir || !(inode = get_empty_inode ()))
  343.         return NULL;
  344.     sb = dir->i_sb;
  345.     inode->i_sb = sb;
  346.     inode->i_flags = sb->s_flags;
  347.     lock_super (sb);
  348.     es = sb->u.ext2_sb.s_es;
  349. repeat:
  350.     gdp = NULL; i=0;
  351.     
  352.     if (S_ISDIR(mode)) {
  353.         avefreei = es->s_free_inodes_count /
  354.             sb->u.ext2_sb.s_groups_count;
  355. /* I am not yet convinced that this next bit is necessary.
  356.         i = dir->u.ext2_i.i_block_group;
  357.         for (j = 0; j < sb->u.ext2_sb.s_groups_count; j++) {
  358.             tmp = get_group_desc (sb, i, &bh2);
  359.             if ((tmp->bg_used_dirs_count << 8) < 
  360.                 tmp->bg_free_inodes_count) {
  361.                 gdp = tmp;
  362.                 break;
  363.             }
  364.             else
  365.             i = ++i % sb->u.ext2_sb.s_groups_count;
  366.         }
  367. */
  368.         if (!gdp) {
  369.             for (j = 0; j < sb->u.ext2_sb.s_groups_count; j++) {
  370.                 tmp = get_group_desc (sb, j, &bh2);
  371.                 if (tmp->bg_free_inodes_count &&
  372.                     tmp->bg_free_inodes_count >= avefreei) {
  373.                     if (!gdp || 
  374.                         (tmp->bg_free_blocks_count >
  375.                          gdp->bg_free_blocks_count)) {
  376.                         i = j;
  377.                         gdp = tmp;
  378.                     }
  379.                 }
  380.             }
  381.         }
  382.     }
  383.     else 
  384.     {
  385.         /*
  386.          * Try to place the inode in it's parent directory
  387.          */
  388.         i = dir->u.ext2_i.i_block_group;
  389.         tmp = get_group_desc (sb, i, &bh2);
  390.         if (tmp->bg_free_inodes_count)
  391.             gdp = tmp;
  392.         else
  393.         {
  394.             /*
  395.              * Use a quadratic hash to find a group with a
  396.              * free inode
  397.              */
  398.             for (j = 1; j < sb->u.ext2_sb.s_groups_count; j <<= 1) {
  399.                 i += j;
  400.                 if (i >= sb->u.ext2_sb.s_groups_count)
  401.                     i -= sb->u.ext2_sb.s_groups_count;
  402.                 tmp = get_group_desc (sb, i, &bh2);
  403.                 if (tmp->bg_free_inodes_count) {
  404.                     gdp = tmp;
  405.                     break;
  406.                 }
  407.             }
  408.         }
  409.         if (!gdp) {
  410.             /*
  411.              * That failed: try linear search for a free inode
  412.              */
  413.             i = dir->u.ext2_i.i_block_group + 1;
  414.             for (j = 2; j < sb->u.ext2_sb.s_groups_count; j++) {
  415.                 if (++i >= sb->u.ext2_sb.s_groups_count)
  416.                     i = 0;
  417.                 tmp = get_group_desc (sb, i, &bh2);
  418.                 if (tmp->bg_free_inodes_count) {
  419.                     gdp = tmp;
  420.                     break;
  421.                 }
  422.             }
  423.         }
  424.     }
  425.  
  426.     if (!gdp) {
  427.         unlock_super (sb);
  428.         iput(inode);
  429.         return NULL;
  430.     }
  431.     bitmap_nr = load_inode_bitmap (sb, i);
  432.     bh = sb->u.ext2_sb.s_inode_bitmap[bitmap_nr];
  433.     if ((j = find_first_zero_bit ((unsigned long *) bh->b_data,
  434.                       EXT2_INODES_PER_GROUP(sb))) <
  435.         EXT2_INODES_PER_GROUP(sb)) {
  436.         if (set_bit (j, bh->b_data)) {
  437.             ext2_warning (sb, "ext2_new_inode",
  438.                       "bit already set for inode %d", j);
  439.             goto repeat;
  440.         }
  441.         bh->b_dirt = 1;
  442.         if (sb->s_flags & MS_SYNC) {
  443.             ll_rw_block (WRITE, 1, &bh);
  444.             wait_on_buffer (bh);
  445.         }
  446.     } else {
  447.         if (gdp->bg_free_inodes_count != 0) {
  448.             ext2_error (sb, "ext2_new_inode",
  449.                     "Free inodes count corrupted in group %d",
  450.                     i);
  451.             unlock_super (sb);
  452.             iput (inode);
  453.             return NULL;
  454.         }
  455.         goto repeat;
  456.     }
  457.     j += i * EXT2_INODES_PER_GROUP(sb) + 1;
  458.     if (j < EXT2_FIRST_INO || j > es->s_inodes_count) {
  459.         ext2_error (sb, "ext2_new_inode",
  460.                 "reserved inode or inode > inodes count\n"
  461.                 "block_group = %d,inode=%d", i, j);
  462.         unlock_super (sb);
  463.         iput (inode);
  464.         return NULL;
  465.     }
  466.     gdp->bg_free_inodes_count--;
  467.     if (S_ISDIR(mode))
  468.         gdp->bg_used_dirs_count++;
  469.     bh2->b_dirt = 1;
  470.     es->s_free_inodes_count--;
  471.     sb->u.ext2_sb.s_sbh->b_dirt = 1;
  472.     sb->s_dirt = 1;
  473.     inode->i_mode = mode;
  474.     inode->i_sb = sb;
  475.     inode->i_count = 1;
  476.     inode->i_nlink = 1;
  477.     inode->i_dev = sb->s_dev;
  478.     inode->i_uid = current->euid;
  479.     if (test_opt (sb, GRPID))
  480.         inode->i_gid = dir->i_gid;
  481.     else if (dir->i_mode & S_ISGID) {
  482.         inode->i_gid = dir->i_gid;
  483.         if (S_ISDIR(mode))
  484.             mode |= S_ISGID;
  485.     } else
  486.         inode->i_gid = current->egid;
  487.     inode->i_dirt = 1;
  488.     inode->i_ino = j;
  489.     inode->i_blksize = sb->s_blocksize;
  490.     inode->i_blocks = 0;
  491.     inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
  492.     inode->u.ext2_i.i_flags = dir->u.ext2_i.i_flags;
  493.     inode->u.ext2_i.i_faddr = 0;
  494.     inode->u.ext2_i.i_frag = 0;
  495.     inode->u.ext2_i.i_fsize = 0;
  496.     inode->u.ext2_i.i_file_acl = 0;
  497.     inode->u.ext2_i.i_dir_acl = 0;
  498.     inode->u.ext2_i.i_dtime = 0;
  499.     inode->u.ext2_i.i_block_group = i;
  500.     inode->i_op = NULL;
  501.     if (inode->u.ext2_i.i_flags & EXT2_SYNC_FL)
  502.         inode->i_flags |= MS_SYNC;
  503.     insert_inode_hash(inode);
  504.     inc_inode_version (inode, gdp, mode);
  505.  
  506.     ext2_debug ("allocating inode %lu\n", inode->i_ino);
  507.  
  508.     unlock_super (sb);
  509.     return inode;
  510. }
  511.  
  512. unsigned long ext2_count_free_inodes (struct super_block * sb)
  513. {
  514. #ifdef EXT2FS_DEBUG
  515.     struct ext2_super_block * es;
  516.     unsigned long desc_count, bitmap_count, x;
  517.     int bitmap_nr;
  518.     struct ext2_group_desc * gdp;
  519.     int i;
  520.  
  521.     lock_super (sb);
  522.     es = sb->u.ext2_sb.s_es;
  523.     desc_count = 0;
  524.     bitmap_count = 0;
  525.     gdp = NULL;
  526.     for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++) {
  527.         gdp = get_group_desc (sb, i, NULL);
  528.         desc_count += gdp->bg_free_inodes_count;
  529.         bitmap_nr = load_inode_bitmap (sb, i);
  530.         x = ext2_count_free (sb->u.ext2_sb.s_inode_bitmap[bitmap_nr],
  531.                      EXT2_INODES_PER_GROUP(sb) / 8);
  532.         printk ("group %d: stored = %d, counted = %lu\n",
  533.             i, gdp->bg_free_inodes_count, x);
  534.         bitmap_count += x;
  535.     }
  536.     printk("ext2_count_free_inodes: stored = %lu, computed = %lu, %lu\n",
  537.         es->s_free_inodes_count, desc_count, bitmap_count);
  538.     unlock_super (sb);
  539.     return desc_count;
  540. #else
  541.     return sb->u.ext2_sb.s_es->s_free_inodes_count;
  542. #endif
  543. }
  544.  
  545. void ext2_check_inodes_bitmap (struct super_block * sb)
  546. {
  547.     struct ext2_super_block * es;
  548.     unsigned long desc_count, bitmap_count, x;
  549.     int bitmap_nr;
  550.     struct ext2_group_desc * gdp;
  551.     int i;
  552.  
  553.     lock_super (sb);
  554.     es = sb->u.ext2_sb.s_es;
  555.     desc_count = 0;
  556.     bitmap_count = 0;
  557.     gdp = NULL;
  558.     for (i = 0; i < sb->u.ext2_sb.s_groups_count; i++) {
  559.         gdp = get_group_desc (sb, i, NULL);
  560.         desc_count += gdp->bg_free_inodes_count;
  561.         bitmap_nr = load_inode_bitmap (sb, i);
  562.         x = ext2_count_free (sb->u.ext2_sb.s_inode_bitmap[bitmap_nr],
  563.                      EXT2_INODES_PER_GROUP(sb) / 8);
  564.         if (gdp->bg_free_inodes_count != x)
  565.             ext2_error (sb, "ext2_check_inodes_bitmap",
  566.                     "Wrong free inodes count in group %d, "
  567.                     "stored = %d, counted = %lu", i,
  568.                     gdp->bg_free_inodes_count, x);
  569.         bitmap_count += x;
  570.     }
  571.     if (es->s_free_inodes_count != bitmap_count)
  572.         ext2_error (sb, "ext2_check_inodes_bitmap",
  573.                 "Wrong free inodes count in super block, "
  574.                 "stored = %lu, counted = %lu",
  575.                 es->s_free_inodes_count, bitmap_count);
  576.     unlock_super (sb);
  577. }
  578.