diff options
author | Marcin Slusarz <marcin.slusarz@gmail.com> | 2008-02-08 07:20:33 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-08 12:22:35 -0500 |
commit | 66e1da3f47d5aaa278d116e72d2f8e8f204cdca3 (patch) | |
tree | aab724a6ccc5da3f6d64eb3cff3e9ac92b0b940b /fs/udf/super.c | |
parent | deae6cfcdc206f68e89346295909a2629f0e0606 (diff) |
udf: convert macros related to bitmaps to functions
convert UDF_SB_ALLOC_BITMAP macro to udf_sb_alloc_bitmap function
convert UDF_SB_FREE_BITMAP macro to udf_sb_free_bitmap function
Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: Ben Fennema <bfennema@falcon.csc.calpoly.edu>
Acked-by: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/udf/super.c')
-rw-r--r-- | fs/udf/super.c | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/fs/udf/super.c b/fs/udf/super.c index 913ece8eec61..86aa2238bc7b 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c | |||
@@ -937,6 +937,39 @@ static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, | |||
937 | root->logicalBlockNum, root->partitionReferenceNum); | 937 | root->logicalBlockNum, root->partitionReferenceNum); |
938 | } | 938 | } |
939 | 939 | ||
940 | static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index) | ||
941 | { | ||
942 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[index]; | ||
943 | struct udf_bitmap *bitmap; | ||
944 | int nr_groups; | ||
945 | int size; | ||
946 | |||
947 | /* TODO: move calculating of nr_groups into helper function */ | ||
948 | nr_groups = (map->s_partition_len + | ||
949 | (sizeof(struct spaceBitmapDesc) << 3) + | ||
950 | (sb->s_blocksize * 8) - 1) / | ||
951 | (sb->s_blocksize * 8); | ||
952 | size = sizeof(struct udf_bitmap) + | ||
953 | (sizeof(struct buffer_head *) * nr_groups); | ||
954 | |||
955 | if (size <= PAGE_SIZE) | ||
956 | bitmap = kmalloc(size, GFP_KERNEL); | ||
957 | else | ||
958 | bitmap = vmalloc(size); /* TODO: get rid of vmalloc */ | ||
959 | |||
960 | if (bitmap == NULL) { | ||
961 | udf_error(sb, __FUNCTION__, | ||
962 | "Unable to allocate space for bitmap " | ||
963 | "and %d buffer_head pointers", nr_groups); | ||
964 | return NULL; | ||
965 | } | ||
966 | |||
967 | memset(bitmap, 0x00, size); | ||
968 | bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1); | ||
969 | bitmap->s_nr_groups = nr_groups; | ||
970 | return bitmap; | ||
971 | } | ||
972 | |||
940 | static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | 973 | static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) |
941 | { | 974 | { |
942 | struct partitionDesc *p; | 975 | struct partitionDesc *p; |
@@ -987,7 +1020,7 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | |||
987 | i, map->s_uspace.s_table->i_ino); | 1020 | i, map->s_uspace.s_table->i_ino); |
988 | } | 1021 | } |
989 | if (phd->unallocSpaceBitmap.extLength) { | 1022 | if (phd->unallocSpaceBitmap.extLength) { |
990 | UDF_SB_ALLOC_BITMAP(sb, i, s_uspace); | 1023 | map->s_uspace.s_bitmap = udf_sb_alloc_bitmap(sb, i); |
991 | if (map->s_uspace.s_bitmap != NULL) { | 1024 | if (map->s_uspace.s_bitmap != NULL) { |
992 | map->s_uspace.s_bitmap->s_extLength = | 1025 | map->s_uspace.s_bitmap->s_extLength = |
993 | le32_to_cpu(phd->unallocSpaceBitmap.extLength); | 1026 | le32_to_cpu(phd->unallocSpaceBitmap.extLength); |
@@ -1017,7 +1050,7 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) | |||
1017 | i, map->s_fspace.s_table->i_ino); | 1050 | i, map->s_fspace.s_table->i_ino); |
1018 | } | 1051 | } |
1019 | if (phd->freedSpaceBitmap.extLength) { | 1052 | if (phd->freedSpaceBitmap.extLength) { |
1020 | UDF_SB_ALLOC_BITMAP(sb, i, s_fspace); | 1053 | map->s_fspace.s_bitmap = udf_sb_alloc_bitmap(sb, i); |
1021 | if (map->s_fspace.s_bitmap != NULL) { | 1054 | if (map->s_fspace.s_bitmap != NULL) { |
1022 | map->s_fspace.s_bitmap->s_extLength = | 1055 | map->s_fspace.s_bitmap->s_extLength = |
1023 | le32_to_cpu(phd->freedSpaceBitmap.extLength); | 1056 | le32_to_cpu(phd->freedSpaceBitmap.extLength); |
@@ -1504,6 +1537,22 @@ static void udf_close_lvid(struct super_block *sb) | |||
1504 | } | 1537 | } |
1505 | } | 1538 | } |
1506 | 1539 | ||
1540 | static void udf_sb_free_bitmap(struct udf_bitmap *bitmap) | ||
1541 | { | ||
1542 | int i; | ||
1543 | int nr_groups = bitmap->s_nr_groups; | ||
1544 | int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups); | ||
1545 | |||
1546 | for (i = 0; i < nr_groups; i++) | ||
1547 | if (bitmap->s_block_bitmap[i]) | ||
1548 | brelse(bitmap->s_block_bitmap[i]); | ||
1549 | |||
1550 | if (size <= PAGE_SIZE) | ||
1551 | kfree(bitmap); | ||
1552 | else | ||
1553 | vfree(bitmap); | ||
1554 | } | ||
1555 | |||
1507 | /* | 1556 | /* |
1508 | * udf_read_super | 1557 | * udf_read_super |
1509 | * | 1558 | * |
@@ -1689,9 +1738,9 @@ error_out: | |||
1689 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) | 1738 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
1690 | iput(map->s_fspace.s_table); | 1739 | iput(map->s_fspace.s_table); |
1691 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) | 1740 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
1692 | UDF_SB_FREE_BITMAP(sb, sbi->s_partition, s_uspace); | 1741 | udf_sb_free_bitmap(map->s_uspace.s_bitmap); |
1693 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) | 1742 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
1694 | UDF_SB_FREE_BITMAP(sb, sbi->s_partition, s_fspace); | 1743 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); |
1695 | if (map->s_partition_type == UDF_SPARABLE_MAP15) | 1744 | if (map->s_partition_type == UDF_SPARABLE_MAP15) |
1696 | for (i = 0; i < 4; i++) | 1745 | for (i = 0; i < 4; i++) |
1697 | brelse(map->s_type_specific.s_sparing.s_spar_map[i]); | 1746 | brelse(map->s_type_specific.s_sparing.s_spar_map[i]); |
@@ -1767,9 +1816,9 @@ static void udf_put_super(struct super_block *sb) | |||
1767 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) | 1816 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
1768 | iput(map->s_fspace.s_table); | 1817 | iput(map->s_fspace.s_table); |
1769 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) | 1818 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
1770 | UDF_SB_FREE_BITMAP(sb, sbi->s_partition, s_uspace); | 1819 | udf_sb_free_bitmap(map->s_uspace.s_bitmap); |
1771 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) | 1820 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
1772 | UDF_SB_FREE_BITMAP(sb, sbi->s_partition, s_fspace); | 1821 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); |
1773 | if (map->s_partition_type == UDF_SPARABLE_MAP15) | 1822 | if (map->s_partition_type == UDF_SPARABLE_MAP15) |
1774 | for (i = 0; i < 4; i++) | 1823 | for (i = 0; i < 4; i++) |
1775 | brelse(map->s_type_specific.s_sparing.s_spar_map[i]); | 1824 | brelse(map->s_type_specific.s_sparing.s_spar_map[i]); |