balloc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * linux/fs/ext2/balloc.c
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * Enhanced block allocation by Stephen Tweedie (sct@redhat.com), 1993
  10. * Big-endian to little-endian byte-swapping/bitmaps by
  11. * David S. Miller (davem@caip.rutgers.edu), 1995
  12. */
  13. #include <linux/config.h>
  14. #include "ext2.h"
  15. #include <linux/quotaops.h>
  16. #include <linux/sched.h>
  17. #include <linux/buffer_head.h>
  18. #include <linux/capability.h>
  19. /*
  20. * balloc.c contains the blocks allocation and deallocation routines
  21. */
  22. /*
  23. * The free blocks are managed by bitmaps. A file system contains several
  24. * blocks groups. Each group contains 1 bitmap block for blocks, 1 bitmap
  25. * block for inodes, N blocks for the inode table and data blocks.
  26. *
  27. * The file system contains group descriptors which are located after the
  28. * super block. Each descriptor contains the number of the bitmap block and
  29. * the free blocks count in the block. The descriptors are loaded in memory
  30. * when a file system is mounted (see ext2_read_super).
  31. */
  32. #define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
  33. struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
  34. unsigned int block_group,
  35. struct buffer_head ** bh)
  36. {
  37. unsigned long group_desc;
  38. unsigned long offset;
  39. struct ext2_group_desc * desc;
  40. struct ext2_sb_info *sbi = EXT2_SB(sb);
  41. if (block_group >= sbi->s_groups_count) {
  42. ext2_error (sb, "ext2_get_group_desc",
  43. "block_group >= groups_count - "
  44. "block_group = %d, groups_count = %lu",
  45. block_group, sbi->s_groups_count);
  46. return NULL;
  47. }
  48. group_desc = block_group >> EXT2_DESC_PER_BLOCK_BITS(sb);
  49. offset = block_group & (EXT2_DESC_PER_BLOCK(sb) - 1);
  50. if (!sbi->s_group_desc[group_desc]) {
  51. ext2_error (sb, "ext2_get_group_desc",
  52. "Group descriptor not loaded - "
  53. "block_group = %d, group_desc = %lu, desc = %lu",
  54. block_group, group_desc, offset);
  55. return NULL;
  56. }
  57. desc = (struct ext2_group_desc *) sbi->s_group_desc[group_desc]->b_data;
  58. if (bh)
  59. *bh = sbi->s_group_desc[group_desc];
  60. return desc + offset;
  61. }
  62. /*
  63. * Read the bitmap for a given block_group, reading into the specified
  64. * slot in the superblock's bitmap cache.
  65. *
  66. * Return buffer_head on success or NULL in case of failure.
  67. */
  68. static struct buffer_head *
  69. read_block_bitmap(struct super_block *sb, unsigned int block_group)
  70. {
  71. struct ext2_group_desc * desc;
  72. struct buffer_head * bh = NULL;
  73. desc = ext2_get_group_desc (sb, block_group, NULL);
  74. if (!desc)
  75. goto error_out;
  76. bh = sb_bread(sb, le32_to_cpu(desc->bg_block_bitmap));
  77. if (!bh)
  78. ext2_error (sb, "read_block_bitmap",
  79. "Cannot read block bitmap - "
  80. "block_group = %d, block_bitmap = %u",
  81. block_group, le32_to_cpu(desc->bg_block_bitmap));
  82. error_out:
  83. return bh;
  84. }
  85. /*
  86. * Set sb->s_dirt here because the superblock was "logically" altered. We
  87. * need to recalculate its free blocks count and flush it out.
  88. */
  89. static int reserve_blocks(struct super_block *sb, int count)
  90. {
  91. struct ext2_sb_info *sbi = EXT2_SB(sb);
  92. struct ext2_super_block *es = sbi->s_es;
  93. unsigned free_blocks;
  94. unsigned root_blocks;
  95. free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
  96. root_blocks = le32_to_cpu(es->s_r_blocks_count);
  97. if (free_blocks < count)
  98. count = free_blocks;
  99. if (free_blocks < root_blocks + count && !capable(CAP_SYS_RESOURCE) &&
  100. sbi->s_resuid != current->fsuid &&
  101. (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
  102. /*
  103. * We are too close to reserve and we are not privileged.
  104. * Can we allocate anything at all?
  105. */
  106. if (free_blocks > root_blocks)
  107. count = free_blocks - root_blocks;
  108. else
  109. return 0;
  110. }
  111. percpu_counter_mod(&sbi->s_freeblocks_counter, -count);
  112. sb->s_dirt = 1;
  113. return count;
  114. }
  115. static void release_blocks(struct super_block *sb, int count)
  116. {
  117. if (count) {
  118. struct ext2_sb_info *sbi = EXT2_SB(sb);
  119. percpu_counter_mod(&sbi->s_freeblocks_counter, count);
  120. sb->s_dirt = 1;
  121. }
  122. }
  123. static int group_reserve_blocks(struct ext2_sb_info *sbi, int group_no,
  124. struct ext2_group_desc *desc, struct buffer_head *bh, int count)
  125. {
  126. unsigned free_blocks;
  127. if (!desc->bg_free_blocks_count)
  128. return 0;
  129. spin_lock(sb_bgl_lock(sbi, group_no));
  130. free_blocks = le16_to_cpu(desc->bg_free_blocks_count);
  131. if (free_blocks < count)
  132. count = free_blocks;
  133. desc->bg_free_blocks_count = cpu_to_le16(free_blocks - count);
  134. spin_unlock(sb_bgl_lock(sbi, group_no));
  135. mark_buffer_dirty(bh);
  136. return count;
  137. }
  138. static void group_release_blocks(struct super_block *sb, int group_no,
  139. struct ext2_group_desc *desc, struct buffer_head *bh, int count)
  140. {
  141. if (count) {
  142. struct ext2_sb_info *sbi = EXT2_SB(sb);
  143. unsigned free_blocks;
  144. spin_lock(sb_bgl_lock(sbi, group_no));
  145. free_blocks = le16_to_cpu(desc->bg_free_blocks_count);
  146. desc->bg_free_blocks_count = cpu_to_le16(free_blocks + count);
  147. spin_unlock(sb_bgl_lock(sbi, group_no));
  148. sb->s_dirt = 1;
  149. mark_buffer_dirty(bh);
  150. }
  151. }
  152. /* Free given blocks, update quota and i_blocks field */
  153. void ext2_free_blocks (struct inode * inode, unsigned long block,
  154. unsigned long count)
  155. {
  156. struct buffer_head *bitmap_bh = NULL;
  157. struct buffer_head * bh2;
  158. unsigned long block_group;
  159. unsigned long bit;
  160. unsigned long i;
  161. unsigned long overflow;
  162. struct super_block * sb = inode->i_sb;
  163. struct ext2_sb_info * sbi = EXT2_SB(sb);
  164. struct ext2_group_desc * desc;
  165. struct ext2_super_block * es = sbi->s_es;
  166. unsigned freed = 0, group_freed;
  167. if (block < le32_to_cpu(es->s_first_data_block) ||
  168. block + count < block ||
  169. block + count > le32_to_cpu(es->s_blocks_count)) {
  170. ext2_error (sb, "ext2_free_blocks",
  171. "Freeing blocks not in datazone - "
  172. "block = %lu, count = %lu", block, count);
  173. goto error_return;
  174. }
  175. ext2_debug ("freeing block(s) %lu-%lu\n", block, block + count - 1);
  176. do_more:
  177. overflow = 0;
  178. block_group = (block - le32_to_cpu(es->s_first_data_block)) /
  179. EXT2_BLOCKS_PER_GROUP(sb);
  180. bit = (block - le32_to_cpu(es->s_first_data_block)) %
  181. EXT2_BLOCKS_PER_GROUP(sb);
  182. /*
  183. * Check to see if we are freeing blocks across a group
  184. * boundary.
  185. */
  186. if (bit + count > EXT2_BLOCKS_PER_GROUP(sb)) {
  187. overflow = bit + count - EXT2_BLOCKS_PER_GROUP(sb);
  188. count -= overflow;
  189. }
  190. brelse(bitmap_bh);
  191. bitmap_bh = read_block_bitmap(sb, block_group);
  192. if (!bitmap_bh)
  193. goto error_return;
  194. desc = ext2_get_group_desc (sb, block_group, &bh2);
  195. if (!desc)
  196. goto error_return;
  197. if (in_range (le32_to_cpu(desc->bg_block_bitmap), block, count) ||
  198. in_range (le32_to_cpu(desc->bg_inode_bitmap), block, count) ||
  199. in_range (block, le32_to_cpu(desc->bg_inode_table),
  200. sbi->s_itb_per_group) ||
  201. in_range (block + count - 1, le32_to_cpu(desc->bg_inode_table),
  202. sbi->s_itb_per_group))
  203. ext2_error (sb, "ext2_free_blocks",
  204. "Freeing blocks in system zones - "
  205. "Block = %lu, count = %lu",
  206. block, count);
  207. for (i = 0, group_freed = 0; i < count; i++) {
  208. if (!ext2_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
  209. bit + i, bitmap_bh->b_data)) {
  210. ext2_error(sb, __FUNCTION__,
  211. "bit already cleared for block %lu", block + i);
  212. } else {
  213. group_freed++;
  214. }
  215. }
  216. mark_buffer_dirty(bitmap_bh);
  217. if (sb->s_flags & MS_SYNCHRONOUS)
  218. sync_dirty_buffer(bitmap_bh);
  219. group_release_blocks(sb, block_group, desc, bh2, group_freed);
  220. freed += group_freed;
  221. if (overflow) {
  222. block += count;
  223. count = overflow;
  224. goto do_more;
  225. }
  226. error_return:
  227. brelse(bitmap_bh);
  228. release_blocks(sb, freed);
  229. DQUOT_FREE_BLOCK(inode, freed);
  230. }
  231. static int grab_block(spinlock_t *lock, char *map, unsigned size, int goal)
  232. {
  233. int k;
  234. char *p, *r;
  235. if (!ext2_test_bit(goal, map))
  236. goto got_it;
  237. repeat:
  238. if (goal) {
  239. /*
  240. * The goal was occupied; search forward for a free
  241. * block within the next XX blocks.
  242. *
  243. * end_goal is more or less random, but it has to be
  244. * less than EXT2_BLOCKS_PER_GROUP. Aligning up to the
  245. * next 64-bit boundary is simple..
  246. */
  247. k = (goal + 63) & ~63;
  248. goal = ext2_find_next_zero_bit(map, k, goal);
  249. if (goal < k)
  250. goto got_it;
  251. /*
  252. * Search in the remainder of the current group.
  253. */
  254. }
  255. p = map + (goal >> 3);
  256. r = memscan(p, 0, (size - goal + 7) >> 3);
  257. k = (r - map) << 3;
  258. if (k < size) {
  259. /*
  260. * We have succeeded in finding a free byte in the block
  261. * bitmap. Now search backwards to find the start of this
  262. * group of free blocks - won't take more than 7 iterations.
  263. */
  264. for (goal = k; goal && !ext2_test_bit (goal - 1, map); goal--)
  265. ;
  266. goto got_it;
  267. }
  268. k = ext2_find_next_zero_bit ((u32 *)map, size, goal);
  269. if (k < size) {
  270. goal = k;
  271. goto got_it;
  272. }
  273. return -1;
  274. got_it:
  275. if (ext2_set_bit_atomic(lock, goal, (void *) map))
  276. goto repeat;
  277. return goal;
  278. }
  279. /*
  280. * ext2_new_block uses a goal block to assist allocation. If the goal is
  281. * free, or there is a free block within 32 blocks of the goal, that block
  282. * is allocated. Otherwise a forward search is made for a free block; within
  283. * each block group the search first looks for an entire free byte in the block
  284. * bitmap, and then for any free bit if that fails.
  285. * This function also updates quota and i_blocks field.
  286. */
  287. int ext2_new_block(struct inode *inode, unsigned long goal,
  288. u32 *prealloc_count, u32 *prealloc_block, int *err)
  289. {
  290. struct buffer_head *bitmap_bh = NULL;
  291. struct buffer_head *gdp_bh; /* bh2 */
  292. struct ext2_group_desc *desc;
  293. int group_no; /* i */
  294. int ret_block; /* j */
  295. int group_idx; /* k */
  296. int target_block; /* tmp */
  297. int block = 0;
  298. struct super_block *sb = inode->i_sb;
  299. struct ext2_sb_info *sbi = EXT2_SB(sb);
  300. struct ext2_super_block *es = sbi->s_es;
  301. unsigned group_size = EXT2_BLOCKS_PER_GROUP(sb);
  302. unsigned prealloc_goal = es->s_prealloc_blocks;
  303. unsigned group_alloc = 0, es_alloc, dq_alloc;
  304. int nr_scanned_groups;
  305. if (!prealloc_goal--)
  306. prealloc_goal = EXT2_DEFAULT_PREALLOC_BLOCKS - 1;
  307. if (!prealloc_count || *prealloc_count)
  308. prealloc_goal = 0;
  309. if (DQUOT_ALLOC_BLOCK(inode, 1)) {
  310. *err = -EDQUOT;
  311. goto out;
  312. }
  313. while (prealloc_goal && DQUOT_PREALLOC_BLOCK(inode, prealloc_goal))
  314. prealloc_goal--;
  315. dq_alloc = prealloc_goal + 1;
  316. es_alloc = reserve_blocks(sb, dq_alloc);
  317. if (!es_alloc) {
  318. *err = -ENOSPC;
  319. goto out_dquot;
  320. }
  321. ext2_debug ("goal=%lu.\n", goal);
  322. if (goal < le32_to_cpu(es->s_first_data_block) ||
  323. goal >= le32_to_cpu(es->s_blocks_count))
  324. goal = le32_to_cpu(es->s_first_data_block);
  325. group_no = (goal - le32_to_cpu(es->s_first_data_block)) / group_size;
  326. desc = ext2_get_group_desc (sb, group_no, &gdp_bh);
  327. if (!desc) {
  328. /*
  329. * gdp_bh may still be uninitialised. But group_release_blocks
  330. * will not touch it because group_alloc is zero.
  331. */
  332. goto io_error;
  333. }
  334. group_alloc = group_reserve_blocks(sbi, group_no, desc,
  335. gdp_bh, es_alloc);
  336. if (group_alloc) {
  337. ret_block = ((goal - le32_to_cpu(es->s_first_data_block)) %
  338. group_size);
  339. brelse(bitmap_bh);
  340. bitmap_bh = read_block_bitmap(sb, group_no);
  341. if (!bitmap_bh)
  342. goto io_error;
  343. ext2_debug("goal is at %d:%d.\n", group_no, ret_block);
  344. ret_block = grab_block(sb_bgl_lock(sbi, group_no),
  345. bitmap_bh->b_data, group_size, ret_block);
  346. if (ret_block >= 0)
  347. goto got_block;
  348. group_release_blocks(sb, group_no, desc, gdp_bh, group_alloc);
  349. group_alloc = 0;
  350. }
  351. ext2_debug ("Bit not found in block group %d.\n", group_no);
  352. /*
  353. * Now search the rest of the groups. We assume that
  354. * i and desc correctly point to the last group visited.
  355. */
  356. nr_scanned_groups = 0;
  357. retry:
  358. for (group_idx = 0; !group_alloc &&
  359. group_idx < sbi->s_groups_count; group_idx++) {
  360. group_no++;
  361. if (group_no >= sbi->s_groups_count)
  362. group_no = 0;
  363. desc = ext2_get_group_desc(sb, group_no, &gdp_bh);
  364. if (!desc)
  365. goto io_error;
  366. group_alloc = group_reserve_blocks(sbi, group_no, desc,
  367. gdp_bh, es_alloc);
  368. }
  369. if (!group_alloc) {
  370. *err = -ENOSPC;
  371. goto out_release;
  372. }
  373. brelse(bitmap_bh);
  374. bitmap_bh = read_block_bitmap(sb, group_no);
  375. if (!bitmap_bh)
  376. goto io_error;
  377. ret_block = grab_block(sb_bgl_lock(sbi, group_no), bitmap_bh->b_data,
  378. group_size, 0);
  379. if (ret_block < 0) {
  380. /*
  381. * If a free block counter is corrupted we can loop inifintely.
  382. * Detect that here.
  383. */
  384. nr_scanned_groups++;
  385. if (nr_scanned_groups > 2 * sbi->s_groups_count) {
  386. ext2_error(sb, "ext2_new_block",
  387. "corrupted free blocks counters");
  388. goto io_error;
  389. }
  390. /*
  391. * Someone else grabbed the last free block in this blockgroup
  392. * before us. Retry the scan.
  393. */
  394. group_release_blocks(sb, group_no, desc, gdp_bh, group_alloc);
  395. group_alloc = 0;
  396. goto retry;
  397. }
  398. got_block:
  399. ext2_debug("using block group %d(%d)\n",
  400. group_no, desc->bg_free_blocks_count);
  401. target_block = ret_block + group_no * group_size +
  402. le32_to_cpu(es->s_first_data_block);
  403. if (target_block == le32_to_cpu(desc->bg_block_bitmap) ||
  404. target_block == le32_to_cpu(desc->bg_inode_bitmap) ||
  405. in_range(target_block, le32_to_cpu(desc->bg_inode_table),
  406. sbi->s_itb_per_group))
  407. ext2_error (sb, "ext2_new_block",
  408. "Allocating block in system zone - "
  409. "block = %u", target_block);
  410. if (target_block >= le32_to_cpu(es->s_blocks_count)) {
  411. ext2_error (sb, "ext2_new_block",
  412. "block(%d) >= blocks count(%d) - "
  413. "block_group = %d, es == %p ", ret_block,
  414. le32_to_cpu(es->s_blocks_count), group_no, es);
  415. goto io_error;
  416. }
  417. block = target_block;
  418. /* OK, we _had_ allocated something */
  419. ext2_debug("found bit %d\n", ret_block);
  420. dq_alloc--;
  421. es_alloc--;
  422. group_alloc--;
  423. /*
  424. * Do block preallocation now if required.
  425. */
  426. write_lock(&EXT2_I(inode)->i_meta_lock);
  427. if (group_alloc && !*prealloc_count) {
  428. unsigned n;
  429. for (n = 0; n < group_alloc && ++ret_block < group_size; n++) {
  430. if (ext2_set_bit_atomic(sb_bgl_lock(sbi, group_no),
  431. ret_block,
  432. (void*) bitmap_bh->b_data))
  433. break;
  434. }
  435. *prealloc_block = block + 1;
  436. *prealloc_count = n;
  437. es_alloc -= n;
  438. dq_alloc -= n;
  439. group_alloc -= n;
  440. }
  441. write_unlock(&EXT2_I(inode)->i_meta_lock);
  442. mark_buffer_dirty(bitmap_bh);
  443. if (sb->s_flags & MS_SYNCHRONOUS)
  444. sync_dirty_buffer(bitmap_bh);
  445. ext2_debug ("allocating block %d. ", block);
  446. *err = 0;
  447. out_release:
  448. group_release_blocks(sb, group_no, desc, gdp_bh, group_alloc);
  449. release_blocks(sb, es_alloc);
  450. out_dquot:
  451. DQUOT_FREE_BLOCK(inode, dq_alloc);
  452. out:
  453. brelse(bitmap_bh);
  454. return block;
  455. io_error:
  456. *err = -EIO;
  457. goto out_release;
  458. }
  459. unsigned long ext2_count_free_blocks (struct super_block * sb)
  460. {
  461. struct ext2_group_desc * desc;
  462. unsigned long desc_count = 0;
  463. int i;
  464. #ifdef EXT2FS_DEBUG
  465. unsigned long bitmap_count, x;
  466. struct ext2_super_block *es;
  467. lock_super (sb);
  468. es = EXT2_SB(sb)->s_es;
  469. desc_count = 0;
  470. bitmap_count = 0;
  471. desc = NULL;
  472. for (i = 0; i < EXT2_SB(sb)->s_groups_count; i++) {
  473. struct buffer_head *bitmap_bh;
  474. desc = ext2_get_group_desc (sb, i, NULL);
  475. if (!desc)
  476. continue;
  477. desc_count += le16_to_cpu(desc->bg_free_blocks_count);
  478. bitmap_bh = read_block_bitmap(sb, i);
  479. if (!bitmap_bh)
  480. continue;
  481. x = ext2_count_free(bitmap_bh, sb->s_blocksize);
  482. printk ("group %d: stored = %d, counted = %lu\n",
  483. i, le16_to_cpu(desc->bg_free_blocks_count), x);
  484. bitmap_count += x;
  485. brelse(bitmap_bh);
  486. }
  487. printk("ext2_count_free_blocks: stored = %lu, computed = %lu, %lu\n",
  488. (long)le32_to_cpu(es->s_free_blocks_count),
  489. desc_count, bitmap_count);
  490. unlock_super (sb);
  491. return bitmap_count;
  492. #else
  493. for (i = 0; i < EXT2_SB(sb)->s_groups_count; i++) {
  494. desc = ext2_get_group_desc (sb, i, NULL);
  495. if (!desc)
  496. continue;
  497. desc_count += le16_to_cpu(desc->bg_free_blocks_count);
  498. }
  499. return desc_count;
  500. #endif
  501. }
  502. static inline int
  503. block_in_use(unsigned long block, struct super_block *sb, unsigned char *map)
  504. {
  505. return ext2_test_bit ((block -
  506. le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block)) %
  507. EXT2_BLOCKS_PER_GROUP(sb), map);
  508. }
  509. static inline int test_root(int a, int b)
  510. {
  511. int num = b;
  512. while (a > num)
  513. num *= b;
  514. return num == a;
  515. }
  516. static int ext2_group_sparse(int group)
  517. {
  518. if (group <= 1)
  519. return 1;
  520. return (test_root(group, 3) || test_root(group, 5) ||
  521. test_root(group, 7));
  522. }
  523. /**
  524. * ext2_bg_has_super - number of blocks used by the superblock in group
  525. * @sb: superblock for filesystem
  526. * @group: group number to check
  527. *
  528. * Return the number of blocks used by the superblock (primary or backup)
  529. * in this group. Currently this will be only 0 or 1.
  530. */
  531. int ext2_bg_has_super(struct super_block *sb, int group)
  532. {
  533. if (EXT2_HAS_RO_COMPAT_FEATURE(sb,EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
  534. !ext2_group_sparse(group))
  535. return 0;
  536. return 1;
  537. }
  538. /**
  539. * ext2_bg_num_gdb - number of blocks used by the group table in group
  540. * @sb: superblock for filesystem
  541. * @group: group number to check
  542. *
  543. * Return the number of blocks used by the group descriptor table
  544. * (primary or backup) in this group. In the future there may be a
  545. * different number of descriptor blocks in each group.
  546. */
  547. unsigned long ext2_bg_num_gdb(struct super_block *sb, int group)
  548. {
  549. if (EXT2_HAS_RO_COMPAT_FEATURE(sb,EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
  550. !ext2_group_sparse(group))
  551. return 0;
  552. return EXT2_SB(sb)->s_gdb_count;
  553. }