Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * balloc.c |
| 3 | * |
| 4 | * PURPOSE |
| 5 | * Block allocation handling routines for the OSTA-UDF(tm) filesystem. |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * COPYRIGHT |
| 8 | * This file is distributed under the terms of the GNU General Public |
| 9 | * License (GPL). Copies of the GPL can be obtained from: |
| 10 | * ftp://prep.ai.mit.edu/pub/gnu/GPL |
| 11 | * Each contributing author retains all rights to their own work. |
| 12 | * |
| 13 | * (C) 1999-2001 Ben Fennema |
| 14 | * (C) 1999 Stelias Computing Inc |
| 15 | * |
| 16 | * HISTORY |
| 17 | * |
| 18 | * 02/24/99 blf Created. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "udfdecl.h" |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/bitops.h> |
| 25 | |
| 26 | #include "udf_i.h" |
| 27 | #include "udf_sb.h" |
| 28 | |
Akinobu Mita | 9ad1e1e | 2011-03-23 16:42:11 -0700 | [diff] [blame] | 29 | #define udf_clear_bit __test_and_clear_bit_le |
| 30 | #define udf_set_bit __test_and_set_bit_le |
| 31 | #define udf_test_bit test_bit_le |
| 32 | #define udf_find_next_one_bit find_next_bit_le |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 34 | static int read_block_bitmap(struct super_block *sb, |
| 35 | struct udf_bitmap *bitmap, unsigned int block, |
| 36 | unsigned long bitmap_nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
| 38 | struct buffer_head *bh = NULL; |
| 39 | int retval = 0; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 40 | struct kernel_lb_addr loc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | loc.logicalBlockNum = bitmap->s_extPosition; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 43 | loc.partitionReferenceNum = UDF_SB(sb)->s_partition; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 45 | bh = udf_tread(sb, udf_get_lb_pblock(sb, &loc, block)); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 46 | if (!bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | retval = -EIO; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | bitmap->s_block_bitmap[bitmap_nr] = bh; |
| 50 | return retval; |
| 51 | } |
| 52 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 53 | static int __load_block_bitmap(struct super_block *sb, |
| 54 | struct udf_bitmap *bitmap, |
| 55 | unsigned int block_group) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
| 57 | int retval = 0; |
| 58 | int nr_groups = bitmap->s_nr_groups; |
| 59 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 60 | if (block_group >= nr_groups) { |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 61 | udf_debug("block_group (%d) > nr_groups (%d)\n", |
| 62 | block_group, nr_groups); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Fabian Frederick | 6fbaad8 | 2015-03-10 21:44:33 +0100 | [diff] [blame] | 65 | if (bitmap->s_block_bitmap[block_group]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return block_group; |
Fabian Frederick | 6fbaad8 | 2015-03-10 21:44:33 +0100 | [diff] [blame] | 67 | |
| 68 | retval = read_block_bitmap(sb, bitmap, block_group, block_group); |
| 69 | if (retval < 0) |
| 70 | return retval; |
| 71 | |
| 72 | return block_group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 75 | static inline int load_block_bitmap(struct super_block *sb, |
| 76 | struct udf_bitmap *bitmap, |
| 77 | unsigned int block_group) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | int slot; |
| 80 | |
| 81 | slot = __load_block_bitmap(sb, bitmap, block_group); |
| 82 | |
| 83 | if (slot < 0) |
| 84 | return slot; |
| 85 | |
| 86 | if (!bitmap->s_block_bitmap[slot]) |
| 87 | return -EIO; |
| 88 | |
| 89 | return slot; |
| 90 | } |
| 91 | |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 92 | static void udf_add_free_space(struct super_block *sb, u16 partition, u32 cnt) |
Marcin Slusarz | 742ba02 | 2008-02-08 04:20:40 -0800 | [diff] [blame] | 93 | { |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 94 | struct udf_sb_info *sbi = UDF_SB(sb); |
Marcin Slusarz | 742ba02 | 2008-02-08 04:20:40 -0800 | [diff] [blame] | 95 | struct logicalVolIntegrityDesc *lvid; |
| 96 | |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 97 | if (!sbi->s_lvid_bh) |
| 98 | return; |
Marcin Slusarz | 742ba02 | 2008-02-08 04:20:40 -0800 | [diff] [blame] | 99 | |
| 100 | lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data; |
marcin.slusarz@gmail.com | c2104fd | 2008-01-30 22:03:57 +0100 | [diff] [blame] | 101 | le32_add_cpu(&lvid->freeSpaceTable[partition], cnt); |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 102 | udf_updated_lvid(sb); |
Marcin Slusarz | 742ba02 | 2008-02-08 04:20:40 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 105 | static void udf_bitmap_free_blocks(struct super_block *sb, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 106 | struct udf_bitmap *bitmap, |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 107 | struct kernel_lb_addr *bloc, |
| 108 | uint32_t offset, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 109 | uint32_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | struct udf_sb_info *sbi = UDF_SB(sb); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 112 | struct buffer_head *bh = NULL; |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 113 | struct udf_part_map *partmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | unsigned long block; |
| 115 | unsigned long block_group; |
| 116 | unsigned long bit; |
| 117 | unsigned long i; |
| 118 | int bitmap_nr; |
| 119 | unsigned long overflow; |
| 120 | |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 121 | mutex_lock(&sbi->s_alloc_mutex); |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 122 | partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; |
Dan Carpenter | 69ecbbe | 2010-03-15 11:21:13 +0300 | [diff] [blame] | 123 | if (bloc->logicalBlockNum + count < count || |
| 124 | (bloc->logicalBlockNum + count) > partmap->s_partition_len) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 125 | udf_debug("%d < %d || %d + %d > %d\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 126 | bloc->logicalBlockNum, 0, |
| 127 | bloc->logicalBlockNum, count, |
| 128 | partmap->s_partition_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | goto error_return; |
| 130 | } |
| 131 | |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 132 | block = bloc->logicalBlockNum + offset + |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 133 | (sizeof(struct spaceBitmapDesc) << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 135 | do { |
| 136 | overflow = 0; |
| 137 | block_group = block >> (sb->s_blocksize_bits + 3); |
| 138 | bit = block % (sb->s_blocksize << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 140 | /* |
| 141 | * Check to see if we are freeing blocks across a group boundary. |
| 142 | */ |
| 143 | if (bit + count > (sb->s_blocksize << 3)) { |
| 144 | overflow = bit + count - (sb->s_blocksize << 3); |
| 145 | count -= overflow; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 147 | bitmap_nr = load_block_bitmap(sb, bitmap, block_group); |
| 148 | if (bitmap_nr < 0) |
| 149 | goto error_return; |
| 150 | |
| 151 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
| 152 | for (i = 0; i < count; i++) { |
| 153 | if (udf_set_bit(bit + i, bh->b_data)) { |
| 154 | udf_debug("bit %ld already set\n", bit + i); |
| 155 | udf_debug("byte=%2x\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 156 | ((char *)bh->b_data)[(bit + i) >> 3]); |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 157 | } |
| 158 | } |
Jan Kara | 7abc2e4 | 2010-10-20 22:32:02 +0200 | [diff] [blame] | 159 | udf_add_free_space(sb, sbi->s_partition, count); |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 160 | mark_buffer_dirty(bh); |
| 161 | if (overflow) { |
| 162 | block += count; |
| 163 | count = overflow; |
| 164 | } |
| 165 | } while (overflow); |
| 166 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 167 | error_return: |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 168 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 171 | static int udf_bitmap_prealloc_blocks(struct super_block *sb, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 172 | struct udf_bitmap *bitmap, |
| 173 | uint16_t partition, uint32_t first_block, |
| 174 | uint32_t block_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 177 | int alloc_count = 0; |
| 178 | int bit, block, block_group, group_start; |
| 179 | int nr_groups, bitmap_nr; |
| 180 | struct buffer_head *bh; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 181 | __u32 part_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 183 | mutex_lock(&sbi->s_alloc_mutex); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 184 | part_len = sbi->s_partmaps[partition].s_partition_len; |
Roel Kluin | 3391faa | 2009-06-22 23:12:29 +0200 | [diff] [blame] | 185 | if (first_block >= part_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | goto out; |
| 187 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 188 | if (first_block + block_count > part_len) |
| 189 | block_count = part_len - first_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 191 | do { |
| 192 | nr_groups = udf_compute_nr_groups(sb, partition); |
| 193 | block = first_block + (sizeof(struct spaceBitmapDesc) << 3); |
| 194 | block_group = block >> (sb->s_blocksize_bits + 3); |
| 195 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 197 | bitmap_nr = load_block_bitmap(sb, bitmap, block_group); |
| 198 | if (bitmap_nr < 0) |
| 199 | goto out; |
| 200 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 202 | bit = block % (sb->s_blocksize << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 204 | while (bit < (sb->s_blocksize << 3) && block_count > 0) { |
Jan Kara | 3635046 | 2010-05-19 16:28:56 +0200 | [diff] [blame] | 205 | if (!udf_clear_bit(bit, bh->b_data)) |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 206 | goto out; |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 207 | block_count--; |
| 208 | alloc_count++; |
| 209 | bit++; |
| 210 | block++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
Marcin Slusarz | 4daa1b8 | 2008-02-08 04:20:41 -0800 | [diff] [blame] | 212 | mark_buffer_dirty(bh); |
| 213 | } while (block_count > 0); |
| 214 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 215 | out: |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 216 | udf_add_free_space(sb, partition, -alloc_count); |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 217 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return alloc_count; |
| 219 | } |
| 220 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 221 | static int udf_bitmap_new_block(struct super_block *sb, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 222 | struct udf_bitmap *bitmap, uint16_t partition, |
| 223 | uint32_t goal, int *err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 225 | struct udf_sb_info *sbi = UDF_SB(sb); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 226 | int newbit, bit = 0, block, block_group, group_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | int end_goal, nr_groups, bitmap_nr, i; |
| 228 | struct buffer_head *bh = NULL; |
| 229 | char *ptr; |
| 230 | int newblock = 0; |
| 231 | |
| 232 | *err = -ENOSPC; |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 233 | mutex_lock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 235 | repeat: |
Roel Kluin | 3391faa | 2009-06-22 23:12:29 +0200 | [diff] [blame] | 236 | if (goal >= sbi->s_partmaps[partition].s_partition_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | goal = 0; |
| 238 | |
| 239 | nr_groups = bitmap->s_nr_groups; |
| 240 | block = goal + (sizeof(struct spaceBitmapDesc) << 3); |
| 241 | block_group = block >> (sb->s_blocksize_bits + 3); |
| 242 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); |
| 243 | |
| 244 | bitmap_nr = load_block_bitmap(sb, bitmap, block_group); |
| 245 | if (bitmap_nr < 0) |
| 246 | goto error_return; |
| 247 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 248 | ptr = memscan((char *)bh->b_data + group_start, 0xFF, |
| 249 | sb->s_blocksize - group_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 251 | if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | bit = block % (sb->s_blocksize << 3); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 253 | if (udf_test_bit(bit, bh->b_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | goto got_block; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | end_goal = (bit + 63) & ~63; |
| 257 | bit = udf_find_next_one_bit(bh->b_data, end_goal, bit); |
| 258 | if (bit < end_goal) |
| 259 | goto got_block; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 260 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 261 | ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, |
| 262 | sb->s_blocksize - ((bit + 7) >> 3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | newbit = (ptr - ((char *)bh->b_data)) << 3; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 264 | if (newbit < sb->s_blocksize << 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | bit = newbit; |
| 266 | goto search_back; |
| 267 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 268 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 269 | newbit = udf_find_next_one_bit(bh->b_data, |
| 270 | sb->s_blocksize << 3, bit); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 271 | if (newbit < sb->s_blocksize << 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | bit = newbit; |
| 273 | goto got_block; |
| 274 | } |
| 275 | } |
| 276 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 277 | for (i = 0; i < (nr_groups * 2); i++) { |
| 278 | block_group++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (block_group >= nr_groups) |
| 280 | block_group = 0; |
| 281 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); |
| 282 | |
| 283 | bitmap_nr = load_block_bitmap(sb, bitmap, block_group); |
| 284 | if (bitmap_nr < 0) |
| 285 | goto error_return; |
| 286 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 287 | if (i < nr_groups) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 288 | ptr = memscan((char *)bh->b_data + group_start, 0xFF, |
| 289 | sb->s_blocksize - group_start); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 290 | if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | bit = (ptr - ((char *)bh->b_data)) << 3; |
| 292 | break; |
| 293 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 294 | } else { |
Dirk Behme | 6f644e5 | 2011-02-22 14:04:19 -0500 | [diff] [blame] | 295 | bit = udf_find_next_one_bit(bh->b_data, |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 296 | sb->s_blocksize << 3, |
| 297 | group_start << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | if (bit < sb->s_blocksize << 3) |
| 299 | break; |
| 300 | } |
| 301 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 302 | if (i >= (nr_groups * 2)) { |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 303 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return newblock; |
| 305 | } |
| 306 | if (bit < sb->s_blocksize << 3) |
| 307 | goto search_back; |
| 308 | else |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 309 | bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, |
| 310 | group_start << 3); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 311 | if (bit >= sb->s_blocksize << 3) { |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 312 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 316 | search_back: |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 317 | i = 0; |
| 318 | while (i < 7 && bit > (group_start << 3) && |
| 319 | udf_test_bit(bit - 1, bh->b_data)) { |
| 320 | ++i; |
| 321 | --bit; |
| 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 324 | got_block: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 326 | (sizeof(struct spaceBitmapDesc) << 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 328 | if (!udf_clear_bit(bit, bh->b_data)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | udf_debug("bit already cleared for block %d\n", bit); |
| 330 | goto repeat; |
| 331 | } |
| 332 | |
| 333 | mark_buffer_dirty(bh); |
| 334 | |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 335 | udf_add_free_space(sb, partition, -1); |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 336 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | *err = 0; |
| 338 | return newblock; |
| 339 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 340 | error_return: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | *err = -EIO; |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 342 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 346 | static void udf_table_free_blocks(struct super_block *sb, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 347 | struct inode *table, |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 348 | struct kernel_lb_addr *bloc, |
| 349 | uint32_t offset, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 350 | uint32_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
| 352 | struct udf_sb_info *sbi = UDF_SB(sb); |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 353 | struct udf_part_map *partmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | uint32_t start, end; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 355 | uint32_t elen; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 356 | struct kernel_lb_addr eloc; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 357 | struct extent_position oepos, epos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | int8_t etype; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 359 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 361 | mutex_lock(&sbi->s_alloc_mutex); |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 362 | partmap = &sbi->s_partmaps[bloc->partitionReferenceNum]; |
Dan Carpenter | 69ecbbe | 2010-03-15 11:21:13 +0300 | [diff] [blame] | 363 | if (bloc->logicalBlockNum + count < count || |
| 364 | (bloc->logicalBlockNum + count) > partmap->s_partition_len) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 365 | udf_debug("%d < %d || %d + %d > %d\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 366 | bloc->logicalBlockNum, 0, |
| 367 | bloc->logicalBlockNum, count, |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 368 | partmap->s_partition_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | goto error_return; |
| 370 | } |
| 371 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 372 | iinfo = UDF_I(table); |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 373 | udf_add_free_space(sb, sbi->s_partition, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 375 | start = bloc->logicalBlockNum + offset; |
| 376 | end = bloc->logicalBlockNum + offset + count - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 378 | epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | elen = 0; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 380 | epos.block = oepos.block = iinfo->i_location; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 381 | epos.bh = oepos.bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 383 | while (count && |
| 384 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 385 | if (((eloc.logicalBlockNum + |
| 386 | (elen >> sb->s_blocksize_bits)) == start)) { |
| 387 | if ((0x3FFFFFFF - elen) < |
| 388 | (count << sb->s_blocksize_bits)) { |
| 389 | uint32_t tmp = ((0x3FFFFFFF - elen) >> |
| 390 | sb->s_blocksize_bits); |
| 391 | count -= tmp; |
| 392 | start += tmp; |
| 393 | elen = (etype << 30) | |
| 394 | (0x40000000 - sb->s_blocksize); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 395 | } else { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 396 | elen = (etype << 30) | |
| 397 | (elen + |
| 398 | (count << sb->s_blocksize_bits)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | start += count; |
| 400 | count = 0; |
| 401 | } |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 402 | udf_write_aext(table, &oepos, &eloc, elen, 1); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 403 | } else if (eloc.logicalBlockNum == (end + 1)) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 404 | if ((0x3FFFFFFF - elen) < |
| 405 | (count << sb->s_blocksize_bits)) { |
| 406 | uint32_t tmp = ((0x3FFFFFFF - elen) >> |
| 407 | sb->s_blocksize_bits); |
| 408 | count -= tmp; |
| 409 | end -= tmp; |
| 410 | eloc.logicalBlockNum -= tmp; |
| 411 | elen = (etype << 30) | |
| 412 | (0x40000000 - sb->s_blocksize); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 413 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | eloc.logicalBlockNum = start; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 415 | elen = (etype << 30) | |
| 416 | (elen + |
| 417 | (count << sb->s_blocksize_bits)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | end -= count; |
| 419 | count = 0; |
| 420 | } |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 421 | udf_write_aext(table, &oepos, &eloc, elen, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 424 | if (epos.bh != oepos.bh) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 425 | oepos.block = epos.block; |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 426 | brelse(oepos.bh); |
| 427 | get_bh(epos.bh); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 428 | oepos.bh = epos.bh; |
| 429 | oepos.offset = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 430 | } else { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 431 | oepos.offset = epos.offset; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 435 | if (count) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 436 | /* |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 437 | * NOTE: we CANNOT use udf_add_aext here, as it can try to |
| 438 | * allocate a new block, and since we hold the super block |
| 439 | * lock already very bad things would happen :) |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 440 | * |
| 441 | * We copy the behavior of udf_add_aext, but instead of |
| 442 | * trying to allocate a new block close to the existing one, |
| 443 | * we just steal a block from the extent we are trying to add. |
| 444 | * |
| 445 | * It would be nice if the blocks were close together, but it |
| 446 | * isn't required. |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 447 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | int adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | eloc.logicalBlockNum = start; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 452 | elen = EXT_RECORDED_ALLOCATED | |
| 453 | (count << sb->s_blocksize_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 455 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 456 | adsize = sizeof(struct short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 457 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 458 | adsize = sizeof(struct long_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 459 | else { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 460 | brelse(oepos.bh); |
| 461 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | goto error_return; |
| 463 | } |
| 464 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 465 | if (epos.offset + (2 * adsize) > sb->s_blocksize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | /* Steal a block from the extent being free'd */ |
Jan Kara | fcea62b | 2015-12-23 14:21:13 +0100 | [diff] [blame] | 467 | udf_setup_indirect_aext(table, eloc.logicalBlockNum, |
| 468 | &epos); |
| 469 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 470 | eloc.logicalBlockNum++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | elen -= sb->s_blocksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 474 | /* It's possible that stealing the block emptied the extent */ |
Jan Kara | fcea62b | 2015-12-23 14:21:13 +0100 | [diff] [blame] | 475 | if (elen) |
| 476 | __udf_add_aext(table, &epos, &eloc, elen, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 479 | brelse(epos.bh); |
| 480 | brelse(oepos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 482 | error_return: |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 483 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | return; |
| 485 | } |
| 486 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 487 | static int udf_table_prealloc_blocks(struct super_block *sb, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 488 | struct inode *table, uint16_t partition, |
| 489 | uint32_t first_block, uint32_t block_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
| 491 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 492 | int alloc_count = 0; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 493 | uint32_t elen, adsize; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 494 | struct kernel_lb_addr eloc; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 495 | struct extent_position epos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | int8_t etype = -1; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 497 | struct udf_inode_info *iinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Roel Kluin | 3391faa | 2009-06-22 23:12:29 +0200 | [diff] [blame] | 499 | if (first_block >= sbi->s_partmaps[partition].s_partition_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | return 0; |
| 501 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 502 | iinfo = UDF_I(table); |
| 503 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 504 | adsize = sizeof(struct short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 505 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 506 | adsize = sizeof(struct long_ad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | else |
| 508 | return 0; |
| 509 | |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 510 | mutex_lock(&sbi->s_alloc_mutex); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 511 | epos.offset = sizeof(struct unallocSpaceEntry); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 512 | epos.block = iinfo->i_location; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 513 | epos.bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | eloc.logicalBlockNum = 0xFFFFFFFF; |
| 515 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 516 | while (first_block != eloc.logicalBlockNum && |
| 517 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | udf_debug("eloc=%d, elen=%d, first_block=%d\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 519 | eloc.logicalBlockNum, elen, first_block); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 520 | ; /* empty loop body */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 523 | if (first_block == eloc.logicalBlockNum) { |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 524 | epos.offset -= adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | alloc_count = (elen >> sb->s_blocksize_bits); |
Jan Kara | 3635046 | 2010-05-19 16:28:56 +0200 | [diff] [blame] | 527 | if (alloc_count > block_count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | alloc_count = block_count; |
| 529 | eloc.logicalBlockNum += alloc_count; |
| 530 | elen -= (alloc_count << sb->s_blocksize_bits); |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 531 | udf_write_aext(table, &epos, &eloc, |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 532 | (etype << 30) | elen, 1); |
| 533 | } else |
| 534 | udf_delete_aext(table, epos, eloc, |
| 535 | (etype << 30) | elen); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 536 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | alloc_count = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 540 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 542 | if (alloc_count) |
| 543 | udf_add_free_space(sb, partition, -alloc_count); |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 544 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | return alloc_count; |
| 546 | } |
| 547 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 548 | static int udf_table_new_block(struct super_block *sb, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 549 | struct inode *table, uint16_t partition, |
| 550 | uint32_t goal, int *err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
| 552 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 553 | uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF; |
| 554 | uint32_t newblock = 0, adsize; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 555 | uint32_t elen, goal_elen = 0; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 556 | struct kernel_lb_addr eloc, uninitialized_var(goal_eloc); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 557 | struct extent_position epos, goal_epos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | int8_t etype; |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 559 | struct udf_inode_info *iinfo = UDF_I(table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | *err = -ENOSPC; |
| 562 | |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 563 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 564 | adsize = sizeof(struct short_ad); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 565 | else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG) |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 566 | adsize = sizeof(struct long_ad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | else |
| 568 | return newblock; |
| 569 | |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 570 | mutex_lock(&sbi->s_alloc_mutex); |
Roel Kluin | 3391faa | 2009-06-22 23:12:29 +0200 | [diff] [blame] | 571 | if (goal >= sbi->s_partmaps[partition].s_partition_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | goal = 0; |
| 573 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 574 | /* We search for the closest matching block to goal. If we find |
| 575 | a exact hit, we stop. Otherwise we keep going till we run out |
| 576 | of extents. We store the buffer_head, bloc, and extoffset |
| 577 | of the current closest match and use that when we are done. |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 578 | */ |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 579 | epos.offset = sizeof(struct unallocSpaceEntry); |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 580 | epos.block = iinfo->i_location; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 581 | epos.bh = goal_epos.bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 583 | while (spread && |
| 584 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 585 | if (goal >= eloc.logicalBlockNum) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 586 | if (goal < eloc.logicalBlockNum + |
| 587 | (elen >> sb->s_blocksize_bits)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | nspread = 0; |
| 589 | else |
| 590 | nspread = goal - eloc.logicalBlockNum - |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 591 | (elen >> sb->s_blocksize_bits); |
| 592 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | nspread = eloc.logicalBlockNum - goal; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 596 | if (nspread < spread) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | spread = nspread; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 598 | if (goal_epos.bh != epos.bh) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 599 | brelse(goal_epos.bh); |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 600 | goal_epos.bh = epos.bh; |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 601 | get_bh(goal_epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 603 | goal_epos.block = epos.block; |
| 604 | goal_epos.offset = epos.offset - adsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | goal_eloc = eloc; |
| 606 | goal_elen = (etype << 30) | elen; |
| 607 | } |
| 608 | } |
| 609 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 610 | brelse(epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 612 | if (spread == 0xFFFFFFFF) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 613 | brelse(goal_epos.bh); |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 614 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | /* Only allocate blocks from the beginning of the extent. |
| 619 | That way, we only delete (empty) extents, never have to insert an |
| 620 | extent because of splitting */ |
| 621 | /* This works, but very poorly.... */ |
| 622 | |
| 623 | newblock = goal_eloc.logicalBlockNum; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 624 | goal_eloc.logicalBlockNum++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | goal_elen -= sb->s_blocksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
| 627 | if (goal_elen) |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 628 | udf_write_aext(table, &goal_epos, &goal_eloc, goal_elen, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | else |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 630 | udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 631 | brelse(goal_epos.bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 633 | udf_add_free_space(sb, partition, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 635 | mutex_unlock(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | *err = 0; |
| 637 | return newblock; |
| 638 | } |
| 639 | |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 640 | void udf_free_blocks(struct super_block *sb, struct inode *inode, |
| 641 | struct kernel_lb_addr *bloc, uint32_t offset, |
| 642 | uint32_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | { |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 644 | uint16_t partition = bloc->partitionReferenceNum; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 645 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 647 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 648 | udf_bitmap_free_blocks(sb, map->s_uspace.s_bitmap, |
Jan Kara | e650b94 | 2008-12-01 13:06:10 +0100 | [diff] [blame] | 649 | bloc, offset, count); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 650 | } else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) { |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 651 | udf_table_free_blocks(sb, map->s_uspace.s_table, |
Jan Kara | e650b94 | 2008-12-01 13:06:10 +0100 | [diff] [blame] | 652 | bloc, offset, count); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 653 | } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) { |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 654 | udf_bitmap_free_blocks(sb, map->s_fspace.s_bitmap, |
Jan Kara | e650b94 | 2008-12-01 13:06:10 +0100 | [diff] [blame] | 655 | bloc, offset, count); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 656 | } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) { |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 657 | udf_table_free_blocks(sb, map->s_fspace.s_table, |
Jan Kara | e650b94 | 2008-12-01 13:06:10 +0100 | [diff] [blame] | 658 | bloc, offset, count); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 659 | } |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 660 | |
| 661 | if (inode) { |
| 662 | inode_sub_bytes(inode, |
| 663 | ((sector_t)count) << sb->s_blocksize_bits); |
| 664 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 667 | inline int udf_prealloc_blocks(struct super_block *sb, |
| 668 | struct inode *inode, |
| 669 | uint16_t partition, uint32_t first_block, |
| 670 | uint32_t block_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 672 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; |
Fabian Frederick | 1be440d | 2015-03-15 10:54:23 +0100 | [diff] [blame] | 673 | int allocated; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 674 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 675 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 676 | allocated = udf_bitmap_prealloc_blocks(sb, |
| 677 | map->s_uspace.s_bitmap, |
| 678 | partition, first_block, |
| 679 | block_count); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 680 | else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 681 | allocated = udf_table_prealloc_blocks(sb, |
| 682 | map->s_uspace.s_table, |
| 683 | partition, first_block, |
| 684 | block_count); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 685 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 686 | allocated = udf_bitmap_prealloc_blocks(sb, |
| 687 | map->s_fspace.s_bitmap, |
| 688 | partition, first_block, |
| 689 | block_count); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 690 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 691 | allocated = udf_table_prealloc_blocks(sb, |
| 692 | map->s_fspace.s_table, |
| 693 | partition, first_block, |
| 694 | block_count); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 695 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | return 0; |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 697 | |
| 698 | if (inode && allocated > 0) |
| 699 | inode_add_bytes(inode, allocated << sb->s_blocksize_bits); |
| 700 | return allocated; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 703 | inline int udf_new_block(struct super_block *sb, |
| 704 | struct inode *inode, |
| 705 | uint16_t partition, uint32_t goal, int *err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 707 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 708 | int block; |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 709 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 710 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 711 | block = udf_bitmap_new_block(sb, |
| 712 | map->s_uspace.s_bitmap, |
| 713 | partition, goal, err); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 714 | else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 715 | block = udf_table_new_block(sb, |
| 716 | map->s_uspace.s_table, |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 717 | partition, goal, err); |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 718 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
| 719 | block = udf_bitmap_new_block(sb, |
| 720 | map->s_fspace.s_bitmap, |
| 721 | partition, goal, err); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 722 | else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 723 | block = udf_table_new_block(sb, |
| 724 | map->s_fspace.s_table, |
| 725 | partition, goal, err); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 726 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | *err = -EIO; |
| 728 | return 0; |
| 729 | } |
Jan Kara | fd4287d | 2012-02-16 13:00:14 +0100 | [diff] [blame] | 730 | if (inode && block) |
| 731 | inode_add_bytes(inode, sb->s_blocksize); |
| 732 | return block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |