diff options
author | David Woodhouse <dwmw2@infradead.org> | 2007-07-23 05:20:10 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2007-07-23 05:20:10 -0400 |
commit | 39fe5434cb9de5da40510028b17b96bc4eb312b3 (patch) | |
tree | 7a02a317b9ad57da51ca99887c119e779ccf3f13 /fs/udf/balloc.c | |
parent | 0fc72b81d3111d114ab378935b1cf07680ca1289 (diff) | |
parent | f695baf2df9e0413d3521661070103711545207a (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'fs/udf/balloc.c')
-rw-r--r-- | fs/udf/balloc.c | 543 |
1 files changed, 231 insertions, 312 deletions
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index 4cec91015681..276f7207a564 100644 --- a/fs/udf/balloc.c +++ b/fs/udf/balloc.c | |||
@@ -41,18 +41,17 @@ | |||
41 | #define uint(x) xuint(x) | 41 | #define uint(x) xuint(x) |
42 | #define xuint(x) __le ## x | 42 | #define xuint(x) __le ## x |
43 | 43 | ||
44 | static inline int find_next_one_bit (void * addr, int size, int offset) | 44 | static inline int find_next_one_bit(void *addr, int size, int offset) |
45 | { | 45 | { |
46 | uintBPL_t * p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG); | 46 | uintBPL_t *p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG); |
47 | int result = offset & ~(BITS_PER_LONG-1); | 47 | int result = offset & ~(BITS_PER_LONG - 1); |
48 | unsigned long tmp; | 48 | unsigned long tmp; |
49 | 49 | ||
50 | if (offset >= size) | 50 | if (offset >= size) |
51 | return size; | 51 | return size; |
52 | size -= result; | 52 | size -= result; |
53 | offset &= (BITS_PER_LONG-1); | 53 | offset &= (BITS_PER_LONG - 1); |
54 | if (offset) | 54 | if (offset) { |
55 | { | ||
56 | tmp = leBPL_to_cpup(p++); | 55 | tmp = leBPL_to_cpup(p++); |
57 | tmp &= ~0UL << offset; | 56 | tmp &= ~0UL << offset; |
58 | if (size < BITS_PER_LONG) | 57 | if (size < BITS_PER_LONG) |
@@ -62,8 +61,7 @@ static inline int find_next_one_bit (void * addr, int size, int offset) | |||
62 | size -= BITS_PER_LONG; | 61 | size -= BITS_PER_LONG; |
63 | result += BITS_PER_LONG; | 62 | result += BITS_PER_LONG; |
64 | } | 63 | } |
65 | while (size & ~(BITS_PER_LONG-1)) | 64 | while (size & ~(BITS_PER_LONG - 1)) { |
66 | { | ||
67 | if ((tmp = leBPL_to_cpup(p++))) | 65 | if ((tmp = leBPL_to_cpup(p++))) |
68 | goto found_middle; | 66 | goto found_middle; |
69 | result += BITS_PER_LONG; | 67 | result += BITS_PER_LONG; |
@@ -73,7 +71,7 @@ static inline int find_next_one_bit (void * addr, int size, int offset) | |||
73 | return result; | 71 | return result; |
74 | tmp = leBPL_to_cpup(p); | 72 | tmp = leBPL_to_cpup(p); |
75 | found_first: | 73 | found_first: |
76 | tmp &= ~0UL >> (BITS_PER_LONG-size); | 74 | tmp &= ~0UL >> (BITS_PER_LONG - size); |
77 | found_middle: | 75 | found_middle: |
78 | return result + ffz(~tmp); | 76 | return result + ffz(~tmp); |
79 | } | 77 | } |
@@ -81,8 +79,9 @@ found_middle: | |||
81 | #define find_first_one_bit(addr, size)\ | 79 | #define find_first_one_bit(addr, size)\ |
82 | find_next_one_bit((addr), (size), 0) | 80 | find_next_one_bit((addr), (size), 0) |
83 | 81 | ||
84 | static int read_block_bitmap(struct super_block * sb, | 82 | static int read_block_bitmap(struct super_block *sb, |
85 | struct udf_bitmap *bitmap, unsigned int block, unsigned long bitmap_nr) | 83 | struct udf_bitmap *bitmap, unsigned int block, |
84 | unsigned long bitmap_nr) | ||
86 | { | 85 | { |
87 | struct buffer_head *bh = NULL; | 86 | struct buffer_head *bh = NULL; |
88 | int retval = 0; | 87 | int retval = 0; |
@@ -92,38 +91,39 @@ static int read_block_bitmap(struct super_block * sb, | |||
92 | loc.partitionReferenceNum = UDF_SB_PARTITION(sb); | 91 | loc.partitionReferenceNum = UDF_SB_PARTITION(sb); |
93 | 92 | ||
94 | bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block)); | 93 | bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block)); |
95 | if (!bh) | 94 | if (!bh) { |
96 | { | ||
97 | retval = -EIO; | 95 | retval = -EIO; |
98 | } | 96 | } |
99 | bitmap->s_block_bitmap[bitmap_nr] = bh; | 97 | bitmap->s_block_bitmap[bitmap_nr] = bh; |
100 | return retval; | 98 | return retval; |
101 | } | 99 | } |
102 | 100 | ||
103 | static int __load_block_bitmap(struct super_block * sb, | 101 | static int __load_block_bitmap(struct super_block *sb, |
104 | struct udf_bitmap *bitmap, unsigned int block_group) | 102 | struct udf_bitmap *bitmap, |
103 | unsigned int block_group) | ||
105 | { | 104 | { |
106 | int retval = 0; | 105 | int retval = 0; |
107 | int nr_groups = bitmap->s_nr_groups; | 106 | int nr_groups = bitmap->s_nr_groups; |
108 | 107 | ||
109 | if (block_group >= nr_groups) | 108 | if (block_group >= nr_groups) { |
110 | { | 109 | udf_debug("block_group (%d) > nr_groups (%d)\n", block_group, |
111 | udf_debug("block_group (%d) > nr_groups (%d)\n", block_group, nr_groups); | 110 | nr_groups); |
112 | } | 111 | } |
113 | 112 | ||
114 | if (bitmap->s_block_bitmap[block_group]) | 113 | if (bitmap->s_block_bitmap[block_group]) { |
115 | return block_group; | 114 | return block_group; |
116 | else | 115 | } else { |
117 | { | 116 | retval = read_block_bitmap(sb, bitmap, block_group, |
118 | retval = read_block_bitmap(sb, bitmap, block_group, block_group); | 117 | block_group); |
119 | if (retval < 0) | 118 | if (retval < 0) |
120 | return retval; | 119 | return retval; |
121 | return block_group; | 120 | return block_group; |
122 | } | 121 | } |
123 | } | 122 | } |
124 | 123 | ||
125 | static inline int load_block_bitmap(struct super_block * sb, | 124 | static inline int load_block_bitmap(struct super_block *sb, |
126 | struct udf_bitmap *bitmap, unsigned int block_group) | 125 | struct udf_bitmap *bitmap, |
126 | unsigned int block_group) | ||
127 | { | 127 | { |
128 | int slot; | 128 | int slot; |
129 | 129 | ||
@@ -138,13 +138,14 @@ static inline int load_block_bitmap(struct super_block * sb, | |||
138 | return slot; | 138 | return slot; |
139 | } | 139 | } |
140 | 140 | ||
141 | static void udf_bitmap_free_blocks(struct super_block * sb, | 141 | static void udf_bitmap_free_blocks(struct super_block *sb, |
142 | struct inode * inode, | 142 | struct inode *inode, |
143 | struct udf_bitmap *bitmap, | 143 | struct udf_bitmap *bitmap, |
144 | kernel_lb_addr bloc, uint32_t offset, uint32_t count) | 144 | kernel_lb_addr bloc, uint32_t offset, |
145 | uint32_t count) | ||
145 | { | 146 | { |
146 | struct udf_sb_info *sbi = UDF_SB(sb); | 147 | struct udf_sb_info *sbi = UDF_SB(sb); |
147 | struct buffer_head * bh = NULL; | 148 | struct buffer_head *bh = NULL; |
148 | unsigned long block; | 149 | unsigned long block; |
149 | unsigned long block_group; | 150 | unsigned long block_group; |
150 | unsigned long bit; | 151 | unsigned long bit; |
@@ -154,11 +155,10 @@ static void udf_bitmap_free_blocks(struct super_block * sb, | |||
154 | 155 | ||
155 | mutex_lock(&sbi->s_alloc_mutex); | 156 | mutex_lock(&sbi->s_alloc_mutex); |
156 | if (bloc.logicalBlockNum < 0 || | 157 | if (bloc.logicalBlockNum < 0 || |
157 | (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) | 158 | (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) { |
158 | { | ||
159 | udf_debug("%d < %d || %d + %d > %d\n", | 159 | udf_debug("%d < %d || %d + %d > %d\n", |
160 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | 160 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, |
161 | UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); | 161 | UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); |
162 | goto error_return; | 162 | goto error_return; |
163 | } | 163 | } |
164 | 164 | ||
@@ -172,8 +172,7 @@ do_more: | |||
172 | /* | 172 | /* |
173 | * Check to see if we are freeing blocks across a group boundary. | 173 | * Check to see if we are freeing blocks across a group boundary. |
174 | */ | 174 | */ |
175 | if (bit + count > (sb->s_blocksize << 3)) | 175 | if (bit + count > (sb->s_blocksize << 3)) { |
176 | { | ||
177 | overflow = bit + count - (sb->s_blocksize << 3); | 176 | overflow = bit + count - (sb->s_blocksize << 3); |
178 | count -= overflow; | 177 | count -= overflow; |
179 | } | 178 | } |
@@ -182,27 +181,21 @@ do_more: | |||
182 | goto error_return; | 181 | goto error_return; |
183 | 182 | ||
184 | bh = bitmap->s_block_bitmap[bitmap_nr]; | 183 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
185 | for (i=0; i < count; i++) | 184 | for (i = 0; i < count; i++) { |
186 | { | 185 | if (udf_set_bit(bit + i, bh->b_data)) { |
187 | if (udf_set_bit(bit + i, bh->b_data)) | ||
188 | { | ||
189 | udf_debug("bit %ld already set\n", bit + i); | 186 | udf_debug("bit %ld already set\n", bit + i); |
190 | udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]); | 187 | udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]); |
191 | } | 188 | } else { |
192 | else | ||
193 | { | ||
194 | if (inode) | 189 | if (inode) |
195 | DQUOT_FREE_BLOCK(inode, 1); | 190 | DQUOT_FREE_BLOCK(inode, 1); |
196 | if (UDF_SB_LVIDBH(sb)) | 191 | if (UDF_SB_LVIDBH(sb)) { |
197 | { | ||
198 | UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = | 192 | UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = |
199 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)])+1); | 193 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]) + 1); |
200 | } | 194 | } |
201 | } | 195 | } |
202 | } | 196 | } |
203 | mark_buffer_dirty(bh); | 197 | mark_buffer_dirty(bh); |
204 | if (overflow) | 198 | if (overflow) { |
205 | { | ||
206 | block += count; | 199 | block += count; |
207 | count = overflow; | 200 | count = overflow; |
208 | goto do_more; | 201 | goto do_more; |
@@ -215,10 +208,11 @@ error_return: | |||
215 | return; | 208 | return; |
216 | } | 209 | } |
217 | 210 | ||
218 | static int udf_bitmap_prealloc_blocks(struct super_block * sb, | 211 | static int udf_bitmap_prealloc_blocks(struct super_block *sb, |
219 | struct inode * inode, | 212 | struct inode *inode, |
220 | struct udf_bitmap *bitmap, uint16_t partition, uint32_t first_block, | 213 | struct udf_bitmap *bitmap, |
221 | uint32_t block_count) | 214 | uint16_t partition, uint32_t first_block, |
215 | uint32_t block_count) | ||
222 | { | 216 | { |
223 | struct udf_sb_info *sbi = UDF_SB(sb); | 217 | struct udf_sb_info *sbi = UDF_SB(sb); |
224 | int alloc_count = 0; | 218 | int alloc_count = 0; |
@@ -235,7 +229,8 @@ static int udf_bitmap_prealloc_blocks(struct super_block * sb, | |||
235 | 229 | ||
236 | repeat: | 230 | repeat: |
237 | nr_groups = (UDF_SB_PARTLEN(sb, partition) + | 231 | nr_groups = (UDF_SB_PARTLEN(sb, partition) + |
238 | (sizeof(struct spaceBitmapDesc) << 3) + (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8); | 232 | (sizeof(struct spaceBitmapDesc) << 3) + |
233 | (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8); | ||
239 | block = first_block + (sizeof(struct spaceBitmapDesc) << 3); | 234 | block = first_block + (sizeof(struct spaceBitmapDesc) << 3); |
240 | block_group = block >> (sb->s_blocksize_bits + 3); | 235 | block_group = block >> (sb->s_blocksize_bits + 3); |
241 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); | 236 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); |
@@ -247,31 +242,28 @@ repeat: | |||
247 | 242 | ||
248 | bit = block % (sb->s_blocksize << 3); | 243 | bit = block % (sb->s_blocksize << 3); |
249 | 244 | ||
250 | while (bit < (sb->s_blocksize << 3) && block_count > 0) | 245 | while (bit < (sb->s_blocksize << 3) && block_count > 0) { |
251 | { | 246 | if (!udf_test_bit(bit, bh->b_data)) { |
252 | if (!udf_test_bit(bit, bh->b_data)) | ||
253 | goto out; | 247 | goto out; |
254 | else if (DQUOT_PREALLOC_BLOCK(inode, 1)) | 248 | } else if (DQUOT_PREALLOC_BLOCK(inode, 1)) { |
255 | goto out; | 249 | goto out; |
256 | else if (!udf_clear_bit(bit, bh->b_data)) | 250 | } else if (!udf_clear_bit(bit, bh->b_data)) { |
257 | { | ||
258 | udf_debug("bit already cleared for block %d\n", bit); | 251 | udf_debug("bit already cleared for block %d\n", bit); |
259 | DQUOT_FREE_BLOCK(inode, 1); | 252 | DQUOT_FREE_BLOCK(inode, 1); |
260 | goto out; | 253 | goto out; |
261 | } | 254 | } |
262 | block_count --; | 255 | block_count--; |
263 | alloc_count ++; | 256 | alloc_count++; |
264 | bit ++; | 257 | bit++; |
265 | block ++; | 258 | block++; |
266 | } | 259 | } |
267 | mark_buffer_dirty(bh); | 260 | mark_buffer_dirty(bh); |
268 | if (block_count > 0) | 261 | if (block_count > 0) |
269 | goto repeat; | 262 | goto repeat; |
270 | out: | 263 | out: |
271 | if (UDF_SB_LVIDBH(sb)) | 264 | if (UDF_SB_LVIDBH(sb)) { |
272 | { | ||
273 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = | 265 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = |
274 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count); | 266 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - alloc_count); |
275 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | 267 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); |
276 | } | 268 | } |
277 | sb->s_dirt = 1; | 269 | sb->s_dirt = 1; |
@@ -279,12 +271,13 @@ out: | |||
279 | return alloc_count; | 271 | return alloc_count; |
280 | } | 272 | } |
281 | 273 | ||
282 | static int udf_bitmap_new_block(struct super_block * sb, | 274 | static int udf_bitmap_new_block(struct super_block *sb, |
283 | struct inode * inode, | 275 | struct inode *inode, |
284 | struct udf_bitmap *bitmap, uint16_t partition, uint32_t goal, int *err) | 276 | struct udf_bitmap *bitmap, uint16_t partition, |
277 | uint32_t goal, int *err) | ||
285 | { | 278 | { |
286 | struct udf_sb_info *sbi = UDF_SB(sb); | 279 | struct udf_sb_info *sbi = UDF_SB(sb); |
287 | int newbit, bit=0, block, block_group, group_start; | 280 | int newbit, bit = 0, block, block_group, group_start; |
288 | int end_goal, nr_groups, bitmap_nr, i; | 281 | int end_goal, nr_groups, bitmap_nr, i; |
289 | struct buffer_head *bh = NULL; | 282 | struct buffer_head *bh = NULL; |
290 | char *ptr; | 283 | char *ptr; |
@@ -306,38 +299,35 @@ repeat: | |||
306 | if (bitmap_nr < 0) | 299 | if (bitmap_nr < 0) |
307 | goto error_return; | 300 | goto error_return; |
308 | bh = bitmap->s_block_bitmap[bitmap_nr]; | 301 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
309 | ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start); | 302 | ptr = memscan((char *)bh->b_data + group_start, 0xFF, |
303 | sb->s_blocksize - group_start); | ||
310 | 304 | ||
311 | if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) | 305 | if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) { |
312 | { | ||
313 | bit = block % (sb->s_blocksize << 3); | 306 | bit = block % (sb->s_blocksize << 3); |
314 | |||
315 | if (udf_test_bit(bit, bh->b_data)) | 307 | if (udf_test_bit(bit, bh->b_data)) |
316 | { | ||
317 | goto got_block; | 308 | goto got_block; |
318 | } | 309 | |
319 | end_goal = (bit + 63) & ~63; | 310 | end_goal = (bit + 63) & ~63; |
320 | bit = udf_find_next_one_bit(bh->b_data, end_goal, bit); | 311 | bit = udf_find_next_one_bit(bh->b_data, end_goal, bit); |
321 | if (bit < end_goal) | 312 | if (bit < end_goal) |
322 | goto got_block; | 313 | goto got_block; |
314 | |||
323 | ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3)); | 315 | ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3)); |
324 | newbit = (ptr - ((char *)bh->b_data)) << 3; | 316 | newbit = (ptr - ((char *)bh->b_data)) << 3; |
325 | if (newbit < sb->s_blocksize << 3) | 317 | if (newbit < sb->s_blocksize << 3) { |
326 | { | ||
327 | bit = newbit; | 318 | bit = newbit; |
328 | goto search_back; | 319 | goto search_back; |
329 | } | 320 | } |
321 | |||
330 | newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit); | 322 | newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit); |
331 | if (newbit < sb->s_blocksize << 3) | 323 | if (newbit < sb->s_blocksize << 3) { |
332 | { | ||
333 | bit = newbit; | 324 | bit = newbit; |
334 | goto got_block; | 325 | goto got_block; |
335 | } | 326 | } |
336 | } | 327 | } |
337 | 328 | ||
338 | for (i=0; i<(nr_groups*2); i++) | 329 | for (i = 0; i < (nr_groups * 2); i++) { |
339 | { | 330 | block_group++; |
340 | block_group ++; | ||
341 | if (block_group >= nr_groups) | 331 | if (block_group >= nr_groups) |
342 | block_group = 0; | 332 | block_group = 0; |
343 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); | 333 | group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc); |
@@ -346,24 +336,22 @@ repeat: | |||
346 | if (bitmap_nr < 0) | 336 | if (bitmap_nr < 0) |
347 | goto error_return; | 337 | goto error_return; |
348 | bh = bitmap->s_block_bitmap[bitmap_nr]; | 338 | bh = bitmap->s_block_bitmap[bitmap_nr]; |
349 | if (i < nr_groups) | 339 | if (i < nr_groups) { |
350 | { | 340 | ptr = memscan((char *)bh->b_data + group_start, 0xFF, |
351 | ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start); | 341 | sb->s_blocksize - group_start); |
352 | if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) | 342 | if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) { |
353 | { | ||
354 | bit = (ptr - ((char *)bh->b_data)) << 3; | 343 | bit = (ptr - ((char *)bh->b_data)) << 3; |
355 | break; | 344 | break; |
356 | } | 345 | } |
357 | } | 346 | } else { |
358 | else | 347 | bit = udf_find_next_one_bit((char *)bh->b_data, |
359 | { | 348 | sb->s_blocksize << 3, |
360 | bit = udf_find_next_one_bit((char *)bh->b_data, sb->s_blocksize << 3, group_start << 3); | 349 | group_start << 3); |
361 | if (bit < sb->s_blocksize << 3) | 350 | if (bit < sb->s_blocksize << 3) |
362 | break; | 351 | break; |
363 | } | 352 | } |
364 | } | 353 | } |
365 | if (i >= (nr_groups*2)) | 354 | if (i >= (nr_groups * 2)) { |
366 | { | ||
367 | mutex_unlock(&sbi->s_alloc_mutex); | 355 | mutex_unlock(&sbi->s_alloc_mutex); |
368 | return newblock; | 356 | return newblock; |
369 | } | 357 | } |
@@ -371,22 +359,21 @@ repeat: | |||
371 | goto search_back; | 359 | goto search_back; |
372 | else | 360 | else |
373 | bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3); | 361 | bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3); |
374 | if (bit >= sb->s_blocksize << 3) | 362 | if (bit >= sb->s_blocksize << 3) { |
375 | { | ||
376 | mutex_unlock(&sbi->s_alloc_mutex); | 363 | mutex_unlock(&sbi->s_alloc_mutex); |
377 | return 0; | 364 | return 0; |
378 | } | 365 | } |
379 | 366 | ||
380 | search_back: | 367 | search_back: |
381 | for (i=0; i<7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--); | 368 | for (i = 0; i < 7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--) |
369 | ; /* empty loop */ | ||
382 | 370 | ||
383 | got_block: | 371 | got_block: |
384 | 372 | ||
385 | /* | 373 | /* |
386 | * Check quota for allocation of this block. | 374 | * Check quota for allocation of this block. |
387 | */ | 375 | */ |
388 | if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) | 376 | if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) { |
389 | { | ||
390 | mutex_unlock(&sbi->s_alloc_mutex); | 377 | mutex_unlock(&sbi->s_alloc_mutex); |
391 | *err = -EDQUOT; | 378 | *err = -EDQUOT; |
392 | return 0; | 379 | return 0; |
@@ -395,18 +382,16 @@ got_block: | |||
395 | newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - | 382 | newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) - |
396 | (sizeof(struct spaceBitmapDesc) << 3); | 383 | (sizeof(struct spaceBitmapDesc) << 3); |
397 | 384 | ||
398 | if (!udf_clear_bit(bit, bh->b_data)) | 385 | if (!udf_clear_bit(bit, bh->b_data)) { |
399 | { | ||
400 | udf_debug("bit already cleared for block %d\n", bit); | 386 | udf_debug("bit already cleared for block %d\n", bit); |
401 | goto repeat; | 387 | goto repeat; |
402 | } | 388 | } |
403 | 389 | ||
404 | mark_buffer_dirty(bh); | 390 | mark_buffer_dirty(bh); |
405 | 391 | ||
406 | if (UDF_SB_LVIDBH(sb)) | 392 | if (UDF_SB_LVIDBH(sb)) { |
407 | { | ||
408 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = | 393 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = |
409 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1); | 394 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - 1); |
410 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | 395 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); |
411 | } | 396 | } |
412 | sb->s_dirt = 1; | 397 | sb->s_dirt = 1; |
@@ -420,10 +405,11 @@ error_return: | |||
420 | return 0; | 405 | return 0; |
421 | } | 406 | } |
422 | 407 | ||
423 | static void udf_table_free_blocks(struct super_block * sb, | 408 | static void udf_table_free_blocks(struct super_block *sb, |
424 | struct inode * inode, | 409 | struct inode *inode, |
425 | struct inode * table, | 410 | struct inode *table, |
426 | kernel_lb_addr bloc, uint32_t offset, uint32_t count) | 411 | kernel_lb_addr bloc, uint32_t offset, |
412 | uint32_t count) | ||
427 | { | 413 | { |
428 | struct udf_sb_info *sbi = UDF_SB(sb); | 414 | struct udf_sb_info *sbi = UDF_SB(sb); |
429 | uint32_t start, end; | 415 | uint32_t start, end; |
@@ -435,11 +421,10 @@ static void udf_table_free_blocks(struct super_block * sb, | |||
435 | 421 | ||
436 | mutex_lock(&sbi->s_alloc_mutex); | 422 | mutex_lock(&sbi->s_alloc_mutex); |
437 | if (bloc.logicalBlockNum < 0 || | 423 | if (bloc.logicalBlockNum < 0 || |
438 | (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) | 424 | (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) { |
439 | { | ||
440 | udf_debug("%d < %d || %d + %d > %d\n", | 425 | udf_debug("%d < %d || %d + %d > %d\n", |
441 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, | 426 | bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count, |
442 | UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); | 427 | UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)); |
443 | goto error_return; | 428 | goto error_return; |
444 | } | 429 | } |
445 | 430 | ||
@@ -447,10 +432,9 @@ static void udf_table_free_blocks(struct super_block * sb, | |||
447 | but.. oh well */ | 432 | but.. oh well */ |
448 | if (inode) | 433 | if (inode) |
449 | DQUOT_FREE_BLOCK(inode, count); | 434 | DQUOT_FREE_BLOCK(inode, count); |
450 | if (UDF_SB_LVIDBH(sb)) | 435 | if (UDF_SB_LVIDBH(sb)) { |
451 | { | ||
452 | UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = | 436 | UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] = |
453 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)])+count); | 437 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]) + count); |
454 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | 438 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); |
455 | } | 439 | } |
456 | 440 | ||
@@ -462,74 +446,59 @@ static void udf_table_free_blocks(struct super_block * sb, | |||
462 | epos.block = oepos.block = UDF_I_LOCATION(table); | 446 | epos.block = oepos.block = UDF_I_LOCATION(table); |
463 | epos.bh = oepos.bh = NULL; | 447 | epos.bh = oepos.bh = NULL; |
464 | 448 | ||
465 | while (count && (etype = | 449 | while (count && |
466 | udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) | 450 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
467 | { | 451 | if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == start)) { |
468 | if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == | 452 | if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) { |
469 | start)) | ||
470 | { | ||
471 | if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) | ||
472 | { | ||
473 | count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 453 | count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); |
474 | start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 454 | start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); |
475 | elen = (etype << 30) | (0x40000000 - sb->s_blocksize); | 455 | elen = (etype << 30) | (0x40000000 - sb->s_blocksize); |
476 | } | 456 | } else { |
477 | else | 457 | elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits)); |
478 | { | ||
479 | elen = (etype << 30) | | ||
480 | (elen + (count << sb->s_blocksize_bits)); | ||
481 | start += count; | 458 | start += count; |
482 | count = 0; | 459 | count = 0; |
483 | } | 460 | } |
484 | udf_write_aext(table, &oepos, eloc, elen, 1); | 461 | udf_write_aext(table, &oepos, eloc, elen, 1); |
485 | } | 462 | } else if (eloc.logicalBlockNum == (end + 1)) { |
486 | else if (eloc.logicalBlockNum == (end + 1)) | 463 | if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) { |
487 | { | ||
488 | if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) | ||
489 | { | ||
490 | count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 464 | count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); |
491 | end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | 465 | end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); |
492 | eloc.logicalBlockNum -= | 466 | eloc.logicalBlockNum -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); |
493 | ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits); | ||
494 | elen = (etype << 30) | (0x40000000 - sb->s_blocksize); | 467 | elen = (etype << 30) | (0x40000000 - sb->s_blocksize); |
495 | } | 468 | } else { |
496 | else | ||
497 | { | ||
498 | eloc.logicalBlockNum = start; | 469 | eloc.logicalBlockNum = start; |
499 | elen = (etype << 30) | | 470 | elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits)); |
500 | (elen + (count << sb->s_blocksize_bits)); | ||
501 | end -= count; | 471 | end -= count; |
502 | count = 0; | 472 | count = 0; |
503 | } | 473 | } |
504 | udf_write_aext(table, &oepos, eloc, elen, 1); | 474 | udf_write_aext(table, &oepos, eloc, elen, 1); |
505 | } | 475 | } |
506 | 476 | ||
507 | if (epos.bh != oepos.bh) | 477 | if (epos.bh != oepos.bh) { |
508 | { | ||
509 | i = -1; | 478 | i = -1; |
510 | oepos.block = epos.block; | 479 | oepos.block = epos.block; |
511 | brelse(oepos.bh); | 480 | brelse(oepos.bh); |
512 | get_bh(epos.bh); | 481 | get_bh(epos.bh); |
513 | oepos.bh = epos.bh; | 482 | oepos.bh = epos.bh; |
514 | oepos.offset = 0; | 483 | oepos.offset = 0; |
515 | } | 484 | } else { |
516 | else | ||
517 | oepos.offset = epos.offset; | 485 | oepos.offset = epos.offset; |
486 | } | ||
518 | } | 487 | } |
519 | 488 | ||
520 | if (count) | 489 | if (count) { |
521 | { | 490 | /* |
522 | /* NOTE: we CANNOT use udf_add_aext here, as it can try to allocate | 491 | * NOTE: we CANNOT use udf_add_aext here, as it can try to allocate |
523 | a new block, and since we hold the super block lock already | 492 | * a new block, and since we hold the super block lock already |
524 | very bad things would happen :) | 493 | * very bad things would happen :) |
525 | 494 | * | |
526 | We copy the behavior of udf_add_aext, but instead of | 495 | * We copy the behavior of udf_add_aext, but instead of |
527 | trying to allocate a new block close to the existing one, | 496 | * trying to allocate a new block close to the existing one, |
528 | we just steal a block from the extent we are trying to add. | 497 | * we just steal a block from the extent we are trying to add. |
529 | 498 | * | |
530 | It would be nice if the blocks were close together, but it | 499 | * It would be nice if the blocks were close together, but it |
531 | isn't required. | 500 | * isn't required. |
532 | */ | 501 | */ |
533 | 502 | ||
534 | int adsize; | 503 | int adsize; |
535 | short_ad *sad = NULL; | 504 | short_ad *sad = NULL; |
@@ -540,40 +509,35 @@ static void udf_table_free_blocks(struct super_block * sb, | |||
540 | elen = EXT_RECORDED_ALLOCATED | | 509 | elen = EXT_RECORDED_ALLOCATED | |
541 | (count << sb->s_blocksize_bits); | 510 | (count << sb->s_blocksize_bits); |
542 | 511 | ||
543 | if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) | 512 | if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) { |
544 | adsize = sizeof(short_ad); | 513 | adsize = sizeof(short_ad); |
545 | else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) | 514 | } else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) { |
546 | adsize = sizeof(long_ad); | 515 | adsize = sizeof(long_ad); |
547 | else | 516 | } else { |
548 | { | ||
549 | brelse(oepos.bh); | 517 | brelse(oepos.bh); |
550 | brelse(epos.bh); | 518 | brelse(epos.bh); |
551 | goto error_return; | 519 | goto error_return; |
552 | } | 520 | } |
553 | 521 | ||
554 | if (epos.offset + (2 * adsize) > sb->s_blocksize) | 522 | if (epos.offset + (2 * adsize) > sb->s_blocksize) { |
555 | { | ||
556 | char *sptr, *dptr; | 523 | char *sptr, *dptr; |
557 | int loffset; | 524 | int loffset; |
558 | 525 | ||
559 | brelse(oepos.bh); | 526 | brelse(oepos.bh); |
560 | oepos = epos; | 527 | oepos = epos; |
561 | 528 | ||
562 | /* Steal a block from the extent being free'd */ | 529 | /* Steal a block from the extent being free'd */ |
563 | epos.block.logicalBlockNum = eloc.logicalBlockNum; | 530 | epos.block.logicalBlockNum = eloc.logicalBlockNum; |
564 | eloc.logicalBlockNum ++; | 531 | eloc.logicalBlockNum++; |
565 | elen -= sb->s_blocksize; | 532 | elen -= sb->s_blocksize; |
566 | 533 | ||
567 | if (!(epos.bh = udf_tread(sb, | 534 | if (!(epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, epos.block, 0)))) { |
568 | udf_get_lb_pblock(sb, epos.block, 0)))) | ||
569 | { | ||
570 | brelse(oepos.bh); | 535 | brelse(oepos.bh); |
571 | goto error_return; | 536 | goto error_return; |
572 | } | 537 | } |
573 | aed = (struct allocExtDesc *)(epos.bh->b_data); | 538 | aed = (struct allocExtDesc *)(epos.bh->b_data); |
574 | aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum); | 539 | aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum); |
575 | if (epos.offset + adsize > sb->s_blocksize) | 540 | if (epos.offset + adsize > sb->s_blocksize) { |
576 | { | ||
577 | loffset = epos.offset; | 541 | loffset = epos.offset; |
578 | aed->lengthAllocDescs = cpu_to_le32(adsize); | 542 | aed->lengthAllocDescs = cpu_to_le32(adsize); |
579 | sptr = UDF_I_DATA(inode) + epos.offset - | 543 | sptr = UDF_I_DATA(inode) + epos.offset - |
@@ -582,73 +546,59 @@ static void udf_table_free_blocks(struct super_block * sb, | |||
582 | dptr = epos.bh->b_data + sizeof(struct allocExtDesc); | 546 | dptr = epos.bh->b_data + sizeof(struct allocExtDesc); |
583 | memcpy(dptr, sptr, adsize); | 547 | memcpy(dptr, sptr, adsize); |
584 | epos.offset = sizeof(struct allocExtDesc) + adsize; | 548 | epos.offset = sizeof(struct allocExtDesc) + adsize; |
585 | } | 549 | } else { |
586 | else | ||
587 | { | ||
588 | loffset = epos.offset + adsize; | 550 | loffset = epos.offset + adsize; |
589 | aed->lengthAllocDescs = cpu_to_le32(0); | 551 | aed->lengthAllocDescs = cpu_to_le32(0); |
590 | sptr = oepos.bh->b_data + epos.offset; | 552 | sptr = oepos.bh->b_data + epos.offset; |
591 | epos.offset = sizeof(struct allocExtDesc); | 553 | epos.offset = sizeof(struct allocExtDesc); |
592 | 554 | ||
593 | if (oepos.bh) | 555 | if (oepos.bh) { |
594 | { | ||
595 | aed = (struct allocExtDesc *)oepos.bh->b_data; | 556 | aed = (struct allocExtDesc *)oepos.bh->b_data; |
596 | aed->lengthAllocDescs = | 557 | aed->lengthAllocDescs = |
597 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 558 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); |
598 | } | 559 | } else { |
599 | else | ||
600 | { | ||
601 | UDF_I_LENALLOC(table) += adsize; | 560 | UDF_I_LENALLOC(table) += adsize; |
602 | mark_inode_dirty(table); | 561 | mark_inode_dirty(table); |
603 | } | 562 | } |
604 | } | 563 | } |
605 | if (UDF_SB_UDFREV(sb) >= 0x0200) | 564 | if (UDF_SB_UDFREV(sb) >= 0x0200) |
606 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1, | 565 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1, |
607 | epos.block.logicalBlockNum, sizeof(tag)); | 566 | epos.block.logicalBlockNum, sizeof(tag)); |
608 | else | 567 | else |
609 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1, | 568 | udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1, |
610 | epos.block.logicalBlockNum, sizeof(tag)); | 569 | epos.block.logicalBlockNum, sizeof(tag)); |
611 | switch (UDF_I_ALLOCTYPE(table)) | 570 | |
612 | { | 571 | switch (UDF_I_ALLOCTYPE(table)) { |
613 | case ICBTAG_FLAG_AD_SHORT: | 572 | case ICBTAG_FLAG_AD_SHORT: |
614 | { | ||
615 | sad = (short_ad *)sptr; | 573 | sad = (short_ad *)sptr; |
616 | sad->extLength = cpu_to_le32( | 574 | sad->extLength = cpu_to_le32( |
617 | EXT_NEXT_EXTENT_ALLOCDECS | | 575 | EXT_NEXT_EXTENT_ALLOCDECS | |
618 | sb->s_blocksize); | 576 | sb->s_blocksize); |
619 | sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum); | 577 | sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum); |
620 | break; | 578 | break; |
621 | } | ||
622 | case ICBTAG_FLAG_AD_LONG: | 579 | case ICBTAG_FLAG_AD_LONG: |
623 | { | ||
624 | lad = (long_ad *)sptr; | 580 | lad = (long_ad *)sptr; |
625 | lad->extLength = cpu_to_le32( | 581 | lad->extLength = cpu_to_le32( |
626 | EXT_NEXT_EXTENT_ALLOCDECS | | 582 | EXT_NEXT_EXTENT_ALLOCDECS | |
627 | sb->s_blocksize); | 583 | sb->s_blocksize); |
628 | lad->extLocation = cpu_to_lelb(epos.block); | 584 | lad->extLocation = cpu_to_lelb(epos.block); |
629 | break; | 585 | break; |
630 | } | ||
631 | } | 586 | } |
632 | if (oepos.bh) | 587 | if (oepos.bh) { |
633 | { | ||
634 | udf_update_tag(oepos.bh->b_data, loffset); | 588 | udf_update_tag(oepos.bh->b_data, loffset); |
635 | mark_buffer_dirty(oepos.bh); | 589 | mark_buffer_dirty(oepos.bh); |
636 | } | 590 | } else { |
637 | else | ||
638 | mark_inode_dirty(table); | 591 | mark_inode_dirty(table); |
592 | } | ||
639 | } | 593 | } |
640 | 594 | ||
641 | if (elen) /* It's possible that stealing the block emptied the extent */ | 595 | if (elen) { /* It's possible that stealing the block emptied the extent */ |
642 | { | ||
643 | udf_write_aext(table, &epos, eloc, elen, 1); | 596 | udf_write_aext(table, &epos, eloc, elen, 1); |
644 | 597 | ||
645 | if (!epos.bh) | 598 | if (!epos.bh) { |
646 | { | ||
647 | UDF_I_LENALLOC(table) += adsize; | 599 | UDF_I_LENALLOC(table) += adsize; |
648 | mark_inode_dirty(table); | 600 | mark_inode_dirty(table); |
649 | } | 601 | } else { |
650 | else | ||
651 | { | ||
652 | aed = (struct allocExtDesc *)epos.bh->b_data; | 602 | aed = (struct allocExtDesc *)epos.bh->b_data; |
653 | aed->lengthAllocDescs = | 603 | aed->lengthAllocDescs = |
654 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); | 604 | cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); |
@@ -667,10 +617,10 @@ error_return: | |||
667 | return; | 617 | return; |
668 | } | 618 | } |
669 | 619 | ||
670 | static int udf_table_prealloc_blocks(struct super_block * sb, | 620 | static int udf_table_prealloc_blocks(struct super_block *sb, |
671 | struct inode * inode, | 621 | struct inode *inode, |
672 | struct inode *table, uint16_t partition, uint32_t first_block, | 622 | struct inode *table, uint16_t partition, |
673 | uint32_t block_count) | 623 | uint32_t first_block, uint32_t block_count) |
674 | { | 624 | { |
675 | struct udf_sb_info *sbi = UDF_SB(sb); | 625 | struct udf_sb_info *sbi = UDF_SB(sb); |
676 | int alloc_count = 0; | 626 | int alloc_count = 0; |
@@ -695,40 +645,36 @@ static int udf_table_prealloc_blocks(struct super_block * sb, | |||
695 | epos.bh = NULL; | 645 | epos.bh = NULL; |
696 | eloc.logicalBlockNum = 0xFFFFFFFF; | 646 | eloc.logicalBlockNum = 0xFFFFFFFF; |
697 | 647 | ||
698 | while (first_block != eloc.logicalBlockNum && (etype = | 648 | while (first_block != eloc.logicalBlockNum && |
699 | udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) | 649 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
700 | { | ||
701 | udf_debug("eloc=%d, elen=%d, first_block=%d\n", | 650 | udf_debug("eloc=%d, elen=%d, first_block=%d\n", |
702 | eloc.logicalBlockNum, elen, first_block); | 651 | eloc.logicalBlockNum, elen, first_block); |
703 | ; /* empty loop body */ | 652 | ; /* empty loop body */ |
704 | } | 653 | } |
705 | 654 | ||
706 | if (first_block == eloc.logicalBlockNum) | 655 | if (first_block == eloc.logicalBlockNum) { |
707 | { | ||
708 | epos.offset -= adsize; | 656 | epos.offset -= adsize; |
709 | 657 | ||
710 | alloc_count = (elen >> sb->s_blocksize_bits); | 658 | alloc_count = (elen >> sb->s_blocksize_bits); |
711 | if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) | 659 | if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) { |
712 | alloc_count = 0; | 660 | alloc_count = 0; |
713 | else if (alloc_count > block_count) | 661 | } else if (alloc_count > block_count) { |
714 | { | ||
715 | alloc_count = block_count; | 662 | alloc_count = block_count; |
716 | eloc.logicalBlockNum += alloc_count; | 663 | eloc.logicalBlockNum += alloc_count; |
717 | elen -= (alloc_count << sb->s_blocksize_bits); | 664 | elen -= (alloc_count << sb->s_blocksize_bits); |
718 | udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1); | 665 | udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1); |
719 | } | 666 | } else { |
720 | else | ||
721 | udf_delete_aext(table, epos, eloc, (etype << 30) | elen); | 667 | udf_delete_aext(table, epos, eloc, (etype << 30) | elen); |
722 | } | 668 | } |
723 | else | 669 | } else { |
724 | alloc_count = 0; | 670 | alloc_count = 0; |
671 | } | ||
725 | 672 | ||
726 | brelse(epos.bh); | 673 | brelse(epos.bh); |
727 | 674 | ||
728 | if (alloc_count && UDF_SB_LVIDBH(sb)) | 675 | if (alloc_count && UDF_SB_LVIDBH(sb)) { |
729 | { | ||
730 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = | 676 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = |
731 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count); | 677 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - alloc_count); |
732 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | 678 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); |
733 | sb->s_dirt = 1; | 679 | sb->s_dirt = 1; |
734 | } | 680 | } |
@@ -736,9 +682,10 @@ static int udf_table_prealloc_blocks(struct super_block * sb, | |||
736 | return alloc_count; | 682 | return alloc_count; |
737 | } | 683 | } |
738 | 684 | ||
739 | static int udf_table_new_block(struct super_block * sb, | 685 | static int udf_table_new_block(struct super_block *sb, |
740 | struct inode * inode, | 686 | struct inode *inode, |
741 | struct inode *table, uint16_t partition, uint32_t goal, int *err) | 687 | struct inode *table, uint16_t partition, |
688 | uint32_t goal, int *err) | ||
742 | { | 689 | { |
743 | struct udf_sb_info *sbi = UDF_SB(sb); | 690 | struct udf_sb_info *sbi = UDF_SB(sb); |
744 | uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF; | 691 | uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF; |
@@ -765,30 +712,26 @@ static int udf_table_new_block(struct super_block * sb, | |||
765 | we stop. Otherwise we keep going till we run out of extents. | 712 | we stop. Otherwise we keep going till we run out of extents. |
766 | We store the buffer_head, bloc, and extoffset of the current closest | 713 | We store the buffer_head, bloc, and extoffset of the current closest |
767 | match and use that when we are done. | 714 | match and use that when we are done. |
768 | */ | 715 | */ |
769 | epos.offset = sizeof(struct unallocSpaceEntry); | 716 | epos.offset = sizeof(struct unallocSpaceEntry); |
770 | epos.block = UDF_I_LOCATION(table); | 717 | epos.block = UDF_I_LOCATION(table); |
771 | epos.bh = goal_epos.bh = NULL; | 718 | epos.bh = goal_epos.bh = NULL; |
772 | 719 | ||
773 | while (spread && (etype = | 720 | while (spread && |
774 | udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) | 721 | (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
775 | { | 722 | if (goal >= eloc.logicalBlockNum) { |
776 | if (goal >= eloc.logicalBlockNum) | ||
777 | { | ||
778 | if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) | 723 | if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) |
779 | nspread = 0; | 724 | nspread = 0; |
780 | else | 725 | else |
781 | nspread = goal - eloc.logicalBlockNum - | 726 | nspread = goal - eloc.logicalBlockNum - |
782 | (elen >> sb->s_blocksize_bits); | 727 | (elen >> sb->s_blocksize_bits); |
783 | } | 728 | } else { |
784 | else | ||
785 | nspread = eloc.logicalBlockNum - goal; | 729 | nspread = eloc.logicalBlockNum - goal; |
730 | } | ||
786 | 731 | ||
787 | if (nspread < spread) | 732 | if (nspread < spread) { |
788 | { | ||
789 | spread = nspread; | 733 | spread = nspread; |
790 | if (goal_epos.bh != epos.bh) | 734 | if (goal_epos.bh != epos.bh) { |
791 | { | ||
792 | brelse(goal_epos.bh); | 735 | brelse(goal_epos.bh); |
793 | goal_epos.bh = epos.bh; | 736 | goal_epos.bh = epos.bh; |
794 | get_bh(goal_epos.bh); | 737 | get_bh(goal_epos.bh); |
@@ -802,8 +745,7 @@ static int udf_table_new_block(struct super_block * sb, | |||
802 | 745 | ||
803 | brelse(epos.bh); | 746 | brelse(epos.bh); |
804 | 747 | ||
805 | if (spread == 0xFFFFFFFF) | 748 | if (spread == 0xFFFFFFFF) { |
806 | { | ||
807 | brelse(goal_epos.bh); | 749 | brelse(goal_epos.bh); |
808 | mutex_unlock(&sbi->s_alloc_mutex); | 750 | mutex_unlock(&sbi->s_alloc_mutex); |
809 | return 0; | 751 | return 0; |
@@ -815,11 +757,10 @@ static int udf_table_new_block(struct super_block * sb, | |||
815 | /* This works, but very poorly.... */ | 757 | /* This works, but very poorly.... */ |
816 | 758 | ||
817 | newblock = goal_eloc.logicalBlockNum; | 759 | newblock = goal_eloc.logicalBlockNum; |
818 | goal_eloc.logicalBlockNum ++; | 760 | goal_eloc.logicalBlockNum++; |
819 | goal_elen -= sb->s_blocksize; | 761 | goal_elen -= sb->s_blocksize; |
820 | 762 | ||
821 | if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) | 763 | if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) { |
822 | { | ||
823 | brelse(goal_epos.bh); | 764 | brelse(goal_epos.bh); |
824 | mutex_unlock(&sbi->s_alloc_mutex); | 765 | mutex_unlock(&sbi->s_alloc_mutex); |
825 | *err = -EDQUOT; | 766 | *err = -EDQUOT; |
@@ -832,10 +773,9 @@ static int udf_table_new_block(struct super_block * sb, | |||
832 | udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); | 773 | udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); |
833 | brelse(goal_epos.bh); | 774 | brelse(goal_epos.bh); |
834 | 775 | ||
835 | if (UDF_SB_LVIDBH(sb)) | 776 | if (UDF_SB_LVIDBH(sb)) { |
836 | { | ||
837 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = | 777 | UDF_SB_LVID(sb)->freeSpaceTable[partition] = |
838 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1); | 778 | cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - 1); |
839 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | 779 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); |
840 | } | 780 | } |
841 | 781 | ||
@@ -845,105 +785,84 @@ static int udf_table_new_block(struct super_block * sb, | |||
845 | return newblock; | 785 | return newblock; |
846 | } | 786 | } |
847 | 787 | ||
848 | inline void udf_free_blocks(struct super_block * sb, | 788 | inline void udf_free_blocks(struct super_block *sb, |
849 | struct inode * inode, | 789 | struct inode *inode, |
850 | kernel_lb_addr bloc, uint32_t offset, uint32_t count) | 790 | kernel_lb_addr bloc, uint32_t offset, |
791 | uint32_t count) | ||
851 | { | 792 | { |
852 | uint16_t partition = bloc.partitionReferenceNum; | 793 | uint16_t partition = bloc.partitionReferenceNum; |
853 | 794 | ||
854 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) | 795 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) { |
855 | { | ||
856 | return udf_bitmap_free_blocks(sb, inode, | 796 | return udf_bitmap_free_blocks(sb, inode, |
857 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, | 797 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, |
858 | bloc, offset, count); | 798 | bloc, offset, count); |
859 | } | 799 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) { |
860 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) | ||
861 | { | ||
862 | return udf_table_free_blocks(sb, inode, | 800 | return udf_table_free_blocks(sb, inode, |
863 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, | 801 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, |
864 | bloc, offset, count); | 802 | bloc, offset, count); |
865 | } | 803 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) { |
866 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) | ||
867 | { | ||
868 | return udf_bitmap_free_blocks(sb, inode, | 804 | return udf_bitmap_free_blocks(sb, inode, |
869 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, | 805 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, |
870 | bloc, offset, count); | 806 | bloc, offset, count); |
871 | } | 807 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) { |
872 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) | ||
873 | { | ||
874 | return udf_table_free_blocks(sb, inode, | 808 | return udf_table_free_blocks(sb, inode, |
875 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, | 809 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, |
876 | bloc, offset, count); | 810 | bloc, offset, count); |
877 | } | 811 | } else { |
878 | else | ||
879 | return; | 812 | return; |
813 | } | ||
880 | } | 814 | } |
881 | 815 | ||
882 | inline int udf_prealloc_blocks(struct super_block * sb, | 816 | inline int udf_prealloc_blocks(struct super_block *sb, |
883 | struct inode * inode, | 817 | struct inode *inode, |
884 | uint16_t partition, uint32_t first_block, uint32_t block_count) | 818 | uint16_t partition, uint32_t first_block, |
819 | uint32_t block_count) | ||
885 | { | 820 | { |
886 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) | 821 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) { |
887 | { | ||
888 | return udf_bitmap_prealloc_blocks(sb, inode, | 822 | return udf_bitmap_prealloc_blocks(sb, inode, |
889 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, | 823 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, |
890 | partition, first_block, block_count); | 824 | partition, first_block, block_count); |
891 | } | 825 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) { |
892 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) | ||
893 | { | ||
894 | return udf_table_prealloc_blocks(sb, inode, | 826 | return udf_table_prealloc_blocks(sb, inode, |
895 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, | 827 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, |
896 | partition, first_block, block_count); | 828 | partition, first_block, block_count); |
897 | } | 829 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) { |
898 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) | ||
899 | { | ||
900 | return udf_bitmap_prealloc_blocks(sb, inode, | 830 | return udf_bitmap_prealloc_blocks(sb, inode, |
901 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, | 831 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, |
902 | partition, first_block, block_count); | 832 | partition, first_block, block_count); |
903 | } | 833 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) { |
904 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) | ||
905 | { | ||
906 | return udf_table_prealloc_blocks(sb, inode, | 834 | return udf_table_prealloc_blocks(sb, inode, |
907 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, | 835 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, |
908 | partition, first_block, block_count); | 836 | partition, first_block, block_count); |
909 | } | 837 | } else { |
910 | else | ||
911 | return 0; | 838 | return 0; |
839 | } | ||
912 | } | 840 | } |
913 | 841 | ||
914 | inline int udf_new_block(struct super_block * sb, | 842 | inline int udf_new_block(struct super_block *sb, |
915 | struct inode * inode, | 843 | struct inode *inode, |
916 | uint16_t partition, uint32_t goal, int *err) | 844 | uint16_t partition, uint32_t goal, int *err) |
917 | { | 845 | { |
918 | int ret; | 846 | int ret; |
919 | 847 | ||
920 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) | 848 | if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) { |
921 | { | ||
922 | ret = udf_bitmap_new_block(sb, inode, | 849 | ret = udf_bitmap_new_block(sb, inode, |
923 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, | 850 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, |
924 | partition, goal, err); | 851 | partition, goal, err); |
925 | return ret; | 852 | return ret; |
926 | } | 853 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) { |
927 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) | ||
928 | { | ||
929 | return udf_table_new_block(sb, inode, | 854 | return udf_table_new_block(sb, inode, |
930 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, | 855 | UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table, |
931 | partition, goal, err); | 856 | partition, goal, err); |
932 | } | 857 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) { |
933 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) | ||
934 | { | ||
935 | return udf_bitmap_new_block(sb, inode, | 858 | return udf_bitmap_new_block(sb, inode, |
936 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, | 859 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap, |
937 | partition, goal, err); | 860 | partition, goal, err); |
938 | } | 861 | } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) { |
939 | else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) | ||
940 | { | ||
941 | return udf_table_new_block(sb, inode, | 862 | return udf_table_new_block(sb, inode, |
942 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, | 863 | UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table, |
943 | partition, goal, err); | 864 | partition, goal, err); |
944 | } | 865 | } else { |
945 | else | ||
946 | { | ||
947 | *err = -EIO; | 866 | *err = -EIO; |
948 | return 0; | 867 | return 0; |
949 | } | 868 | } |