balloc.c 17 KB

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