5 * Block allocation handling routines for the OSTA-UDF(tm) filesystem.
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.
13 * (C) 1999-2001 Ben Fennema
14 * (C) 1999 Stelias Computing Inc
18 * 02/24/99 blf Created.
24 #include <linux/quotaops.h>
25 #include <linux/buffer_head.h>
26 #include <linux/bitops.h>
31 #define udf_clear_bit(nr,addr) ext2_clear_bit(nr,addr)
32 #define udf_set_bit(nr,addr) ext2_set_bit(nr,addr)
33 #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr)
34 #define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size)
35 #define udf_find_next_one_bit(addr, size, offset) find_next_one_bit(addr, size, offset)
37 #define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x)
38 #define leNUM_to_cpup(x,y) xleNUM_to_cpup(x,y)
39 #define xleNUM_to_cpup(x,y) (le ## x ## _to_cpup(y))
40 #define uintBPL_t uint(BITS_PER_LONG)
41 #define uint(x) xuint(x)
42 #define xuint(x) __le ## x
44 static inline int find_next_one_bit (void * addr, int size, int offset)
46 uintBPL_t * p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG);
47 int result = offset & ~(BITS_PER_LONG-1);
53 offset &= (BITS_PER_LONG-1);
56 tmp = leBPL_to_cpup(p++);
57 tmp &= ~0UL << offset;
58 if (size < BITS_PER_LONG)
62 size -= BITS_PER_LONG;
63 result += BITS_PER_LONG;
65 while (size & ~(BITS_PER_LONG-1))
67 if ((tmp = leBPL_to_cpup(p++)))
69 result += BITS_PER_LONG;
70 size -= BITS_PER_LONG;
74 tmp = leBPL_to_cpup(p);
76 tmp &= ~0UL >> (BITS_PER_LONG-size);
78 return result + ffz(~tmp);
81 #define find_first_one_bit(addr, size)\
82 find_next_one_bit((addr), (size), 0)
84 static int read_block_bitmap(struct super_block * sb,
85 struct udf_bitmap *bitmap, unsigned int block, unsigned long bitmap_nr)
87 struct buffer_head *bh = NULL;
91 loc.logicalBlockNum = bitmap->s_extPosition;
92 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
94 bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block));
99 bitmap->s_block_bitmap[bitmap_nr] = bh;
103 static int __load_block_bitmap(struct super_block * sb,
104 struct udf_bitmap *bitmap, unsigned int block_group)
107 int nr_groups = bitmap->s_nr_groups;
109 if (block_group >= nr_groups)
111 udf_debug("block_group (%d) > nr_groups (%d)\n", block_group, nr_groups);
114 if (bitmap->s_block_bitmap[block_group])
118 retval = read_block_bitmap(sb, bitmap, block_group, block_group);
125 static inline int load_block_bitmap(struct super_block * sb,
126 struct udf_bitmap *bitmap, unsigned int block_group)
130 slot = __load_block_bitmap(sb, bitmap, block_group);
135 if (!bitmap->s_block_bitmap[slot])
141 static void udf_bitmap_free_blocks(struct super_block * sb,
142 struct inode * inode,
143 struct udf_bitmap *bitmap,
144 kernel_lb_addr bloc, uint32_t offset, uint32_t count)
146 struct udf_sb_info *sbi = UDF_SB(sb);
147 struct buffer_head * bh = NULL;
149 unsigned long block_group;
153 unsigned long overflow;
155 down(&sbi->s_alloc_sem);
156 if (bloc.logicalBlockNum < 0 ||
157 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum))
159 udf_debug("%d < %d || %d + %d > %d\n",
160 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
161 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum));
165 block = bloc.logicalBlockNum + offset + (sizeof(struct spaceBitmapDesc) << 3);
169 block_group = block >> (sb->s_blocksize_bits + 3);
170 bit = block % (sb->s_blocksize << 3);
173 * Check to see if we are freeing blocks across a group boundary.
175 if (bit + count > (sb->s_blocksize << 3))
177 overflow = bit + count - (sb->s_blocksize << 3);
180 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
184 bh = bitmap->s_block_bitmap[bitmap_nr];
185 for (i=0; i < count; i++)
187 if (udf_set_bit(bit + i, bh->b_data))
189 udf_debug("bit %ld already set\n", bit + i);
190 udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]);
195 DQUOT_FREE_BLOCK(inode, 1);
196 if (UDF_SB_LVIDBH(sb))
198 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);
203 mark_buffer_dirty(bh);
212 if (UDF_SB_LVIDBH(sb))
213 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
214 up(&sbi->s_alloc_sem);
218 static int udf_bitmap_prealloc_blocks(struct super_block * sb,
219 struct inode * inode,
220 struct udf_bitmap *bitmap, uint16_t partition, uint32_t first_block,
221 uint32_t block_count)
223 struct udf_sb_info *sbi = UDF_SB(sb);
225 int bit, block, block_group, group_start;
226 int nr_groups, bitmap_nr;
227 struct buffer_head *bh;
229 down(&sbi->s_alloc_sem);
230 if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition))
233 if (first_block + block_count > UDF_SB_PARTLEN(sb, partition))
234 block_count = UDF_SB_PARTLEN(sb, partition) - first_block;
237 nr_groups = (UDF_SB_PARTLEN(sb, partition) +
238 (sizeof(struct spaceBitmapDesc) << 3) + (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8);
239 block = first_block + (sizeof(struct spaceBitmapDesc) << 3);
240 block_group = block >> (sb->s_blocksize_bits + 3);
241 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
243 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
246 bh = bitmap->s_block_bitmap[bitmap_nr];
248 bit = block % (sb->s_blocksize << 3);
250 while (bit < (sb->s_blocksize << 3) && block_count > 0)
252 if (!udf_test_bit(bit, bh->b_data))
254 else if (DQUOT_PREALLOC_BLOCK(inode, 1))
256 else if (!udf_clear_bit(bit, bh->b_data))
258 udf_debug("bit already cleared for block %d\n", bit);
259 DQUOT_FREE_BLOCK(inode, 1);
267 mark_buffer_dirty(bh);
271 if (UDF_SB_LVIDBH(sb))
273 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
274 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count);
275 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
278 up(&sbi->s_alloc_sem);
282 static int udf_bitmap_new_block(struct super_block * sb,
283 struct inode * inode,
284 struct udf_bitmap *bitmap, uint16_t partition, uint32_t goal, int *err)
286 struct udf_sb_info *sbi = UDF_SB(sb);
287 int newbit, bit=0, block, block_group, group_start;
288 int end_goal, nr_groups, bitmap_nr, i;
289 struct buffer_head *bh = NULL;
294 down(&sbi->s_alloc_sem);
297 if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition))
300 nr_groups = bitmap->s_nr_groups;
301 block = goal + (sizeof(struct spaceBitmapDesc) << 3);
302 block_group = block >> (sb->s_blocksize_bits + 3);
303 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
305 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
308 bh = bitmap->s_block_bitmap[bitmap_nr];
309 ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start);
311 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize)
313 bit = block % (sb->s_blocksize << 3);
315 if (udf_test_bit(bit, bh->b_data))
319 end_goal = (bit + 63) & ~63;
320 bit = udf_find_next_one_bit(bh->b_data, end_goal, bit);
323 ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3));
324 newbit = (ptr - ((char *)bh->b_data)) << 3;
325 if (newbit < sb->s_blocksize << 3)
330 newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit);
331 if (newbit < sb->s_blocksize << 3)
338 for (i=0; i<(nr_groups*2); i++)
341 if (block_group >= nr_groups)
343 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
345 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
348 bh = bitmap->s_block_bitmap[bitmap_nr];
351 ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start);
352 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize)
354 bit = (ptr - ((char *)bh->b_data)) << 3;
360 bit = udf_find_next_one_bit((char *)bh->b_data, sb->s_blocksize << 3, group_start << 3);
361 if (bit < sb->s_blocksize << 3)
365 if (i >= (nr_groups*2))
367 up(&sbi->s_alloc_sem);
370 if (bit < sb->s_blocksize << 3)
373 bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3);
374 if (bit >= sb->s_blocksize << 3)
376 up(&sbi->s_alloc_sem);
381 for (i=0; i<7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--);
386 * Check quota for allocation of this block.
388 if (inode && DQUOT_ALLOC_BLOCK(inode, 1))
390 up(&sbi->s_alloc_sem);
395 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
396 (sizeof(struct spaceBitmapDesc) << 3);
398 if (!udf_clear_bit(bit, bh->b_data))
400 udf_debug("bit already cleared for block %d\n", bit);
404 mark_buffer_dirty(bh);
406 if (UDF_SB_LVIDBH(sb))
408 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
409 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1);
410 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
413 up(&sbi->s_alloc_sem);
419 up(&sbi->s_alloc_sem);
423 static void udf_table_free_blocks(struct super_block * sb,
424 struct inode * inode,
425 struct inode * table,
426 kernel_lb_addr bloc, uint32_t offset, uint32_t count)
428 struct udf_sb_info *sbi = UDF_SB(sb);
430 uint32_t nextoffset, oextoffset, elen;
431 kernel_lb_addr nbloc, obloc, eloc;
432 struct buffer_head *obh, *nbh;
436 down(&sbi->s_alloc_sem);
437 if (bloc.logicalBlockNum < 0 ||
438 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum))
440 udf_debug("%d < %d || %d + %d > %d\n",
441 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
442 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum));
446 /* We do this up front - There are some error conditions that could occure,
449 DQUOT_FREE_BLOCK(inode, count);
450 if (UDF_SB_LVIDBH(sb))
452 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);
454 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
457 start = bloc.logicalBlockNum + offset;
458 end = bloc.logicalBlockNum + offset + count - 1;
460 oextoffset = nextoffset = sizeof(struct unallocSpaceEntry);
462 obloc = nbloc = UDF_I_LOCATION(table);
466 while (count && (etype =
467 udf_next_aext(table, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1)) != -1)
469 if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) ==
472 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits))
474 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
475 start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
476 elen = (etype << 30) | (0x40000000 - sb->s_blocksize);
480 elen = (etype << 30) |
481 (elen + (count << sb->s_blocksize_bits));
485 udf_write_aext(table, obloc, &oextoffset, eloc, elen, obh, 1);
487 else if (eloc.logicalBlockNum == (end + 1))
489 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits))
491 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
492 end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
493 eloc.logicalBlockNum -=
494 ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
495 elen = (etype << 30) | (0x40000000 - sb->s_blocksize);
499 eloc.logicalBlockNum = start;
500 elen = (etype << 30) |
501 (elen + (count << sb->s_blocksize_bits));
505 udf_write_aext(table, obloc, &oextoffset, eloc, elen, obh, 1);
512 udf_release_data(obh);
513 atomic_inc(&nbh->b_count);
518 oextoffset = nextoffset;
523 /* NOTE: we CANNOT use udf_add_aext here, as it can try to allocate
524 a new block, and since we hold the super block lock already
525 very bad things would happen :)
527 We copy the behavior of udf_add_aext, but instead of
528 trying to allocate a new block close to the existing one,
529 we just steal a block from the extent we are trying to add.
531 It would be nice if the blocks were close together, but it
536 short_ad *sad = NULL;
538 struct allocExtDesc *aed;
540 eloc.logicalBlockNum = start;
541 elen = EXT_RECORDED_ALLOCATED |
542 (count << sb->s_blocksize_bits);
544 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
545 adsize = sizeof(short_ad);
546 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
547 adsize = sizeof(long_ad);
550 udf_release_data(obh);
551 udf_release_data(nbh);
555 if (nextoffset + (2 * adsize) > sb->s_blocksize)
560 udf_release_data(obh);
563 oextoffset = nextoffset;
565 /* Steal a block from the extent being free'd */
566 nbloc.logicalBlockNum = eloc.logicalBlockNum;
567 eloc.logicalBlockNum ++;
568 elen -= sb->s_blocksize;
570 if (!(nbh = udf_tread(sb,
571 udf_get_lb_pblock(sb, nbloc, 0))))
573 udf_release_data(obh);
576 aed = (struct allocExtDesc *)(nbh->b_data);
577 aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum);
578 if (nextoffset + adsize > sb->s_blocksize)
580 loffset = nextoffset;
581 aed->lengthAllocDescs = cpu_to_le32(adsize);
583 sptr = UDF_I_DATA(inode) + nextoffset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode) - adsize;
585 sptr = obh->b_data + nextoffset - adsize;
586 dptr = nbh->b_data + sizeof(struct allocExtDesc);
587 memcpy(dptr, sptr, adsize);
588 nextoffset = sizeof(struct allocExtDesc) + adsize;
592 loffset = nextoffset + adsize;
593 aed->lengthAllocDescs = cpu_to_le32(0);
594 sptr = (obh)->b_data + nextoffset;
595 nextoffset = sizeof(struct allocExtDesc);
599 aed = (struct allocExtDesc *)(obh)->b_data;
600 aed->lengthAllocDescs =
601 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
605 UDF_I_LENALLOC(table) += adsize;
606 mark_inode_dirty(table);
609 if (UDF_SB_UDFREV(sb) >= 0x0200)
610 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
611 nbloc.logicalBlockNum, sizeof(tag));
613 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
614 nbloc.logicalBlockNum, sizeof(tag));
615 switch (UDF_I_ALLOCTYPE(table))
617 case ICBTAG_FLAG_AD_SHORT:
619 sad = (short_ad *)sptr;
620 sad->extLength = cpu_to_le32(
621 EXT_NEXT_EXTENT_ALLOCDECS |
623 sad->extPosition = cpu_to_le32(nbloc.logicalBlockNum);
626 case ICBTAG_FLAG_AD_LONG:
628 lad = (long_ad *)sptr;
629 lad->extLength = cpu_to_le32(
630 EXT_NEXT_EXTENT_ALLOCDECS |
632 lad->extLocation = cpu_to_lelb(nbloc);
638 udf_update_tag(obh->b_data, loffset);
639 mark_buffer_dirty(obh);
642 mark_inode_dirty(table);
645 if (elen) /* It's possible that stealing the block emptied the extent */
647 udf_write_aext(table, nbloc, &nextoffset, eloc, elen, nbh, 1);
651 UDF_I_LENALLOC(table) += adsize;
652 mark_inode_dirty(table);
656 aed = (struct allocExtDesc *)nbh->b_data;
657 aed->lengthAllocDescs =
658 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
659 udf_update_tag(nbh->b_data, nextoffset);
660 mark_buffer_dirty(nbh);
665 udf_release_data(nbh);
666 udf_release_data(obh);
670 up(&sbi->s_alloc_sem);
674 static int udf_table_prealloc_blocks(struct super_block * sb,
675 struct inode * inode,
676 struct inode *table, uint16_t partition, uint32_t first_block,
677 uint32_t block_count)
679 struct udf_sb_info *sbi = UDF_SB(sb);
681 uint32_t extoffset, elen, adsize;
682 kernel_lb_addr bloc, eloc;
683 struct buffer_head *bh;
686 if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition))
689 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
690 adsize = sizeof(short_ad);
691 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
692 adsize = sizeof(long_ad);
696 down(&sbi->s_alloc_sem);
697 extoffset = sizeof(struct unallocSpaceEntry);
698 bloc = UDF_I_LOCATION(table);
701 eloc.logicalBlockNum = 0xFFFFFFFF;
703 while (first_block != eloc.logicalBlockNum && (etype =
704 udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
706 udf_debug("eloc=%d, elen=%d, first_block=%d\n",
707 eloc.logicalBlockNum, elen, first_block);
708 ; /* empty loop body */
711 if (first_block == eloc.logicalBlockNum)
715 alloc_count = (elen >> sb->s_blocksize_bits);
716 if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count))
718 else if (alloc_count > block_count)
720 alloc_count = block_count;
721 eloc.logicalBlockNum += alloc_count;
722 elen -= (alloc_count << sb->s_blocksize_bits);
723 udf_write_aext(table, bloc, &extoffset, eloc, (etype << 30) | elen, bh, 1);
726 udf_delete_aext(table, bloc, extoffset, eloc, (etype << 30) | elen, bh);
731 udf_release_data(bh);
733 if (alloc_count && UDF_SB_LVIDBH(sb))
735 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
736 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count);
737 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
740 up(&sbi->s_alloc_sem);
744 static int udf_table_new_block(struct super_block * sb,
745 struct inode * inode,
746 struct inode *table, uint16_t partition, uint32_t goal, int *err)
748 struct udf_sb_info *sbi = UDF_SB(sb);
749 uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF;
750 uint32_t newblock = 0, adsize;
751 uint32_t extoffset, goal_extoffset, elen, goal_elen = 0;
752 kernel_lb_addr bloc, goal_bloc, eloc, goal_eloc;
753 struct buffer_head *bh, *goal_bh;
758 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
759 adsize = sizeof(short_ad);
760 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
761 adsize = sizeof(long_ad);
765 down(&sbi->s_alloc_sem);
766 if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition))
769 /* We search for the closest matching block to goal. If we find a exact hit,
770 we stop. Otherwise we keep going till we run out of extents.
771 We store the buffer_head, bloc, and extoffset of the current closest
772 match and use that when we are done.
775 extoffset = sizeof(struct unallocSpaceEntry);
776 bloc = UDF_I_LOCATION(table);
780 while (spread && (etype =
781 udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
783 if (goal >= eloc.logicalBlockNum)
785 if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits))
788 nspread = goal - eloc.logicalBlockNum -
789 (elen >> sb->s_blocksize_bits);
792 nspread = eloc.logicalBlockNum - goal;
794 if (nspread < spread)
799 udf_release_data(goal_bh);
801 atomic_inc(&goal_bh->b_count);
804 goal_extoffset = extoffset - adsize;
806 goal_elen = (etype << 30) | elen;
810 udf_release_data(bh);
812 if (spread == 0xFFFFFFFF)
814 udf_release_data(goal_bh);
815 up(&sbi->s_alloc_sem);
819 /* Only allocate blocks from the beginning of the extent.
820 That way, we only delete (empty) extents, never have to insert an
821 extent because of splitting */
822 /* This works, but very poorly.... */
824 newblock = goal_eloc.logicalBlockNum;
825 goal_eloc.logicalBlockNum ++;
826 goal_elen -= sb->s_blocksize;
828 if (inode && DQUOT_ALLOC_BLOCK(inode, 1))
830 udf_release_data(goal_bh);
831 up(&sbi->s_alloc_sem);
837 udf_write_aext(table, goal_bloc, &goal_extoffset, goal_eloc, goal_elen, goal_bh, 1);
839 udf_delete_aext(table, goal_bloc, goal_extoffset, goal_eloc, goal_elen, goal_bh);
840 udf_release_data(goal_bh);
842 if (UDF_SB_LVIDBH(sb))
844 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
845 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1);
846 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
850 up(&sbi->s_alloc_sem);
855 inline void udf_free_blocks(struct super_block * sb,
856 struct inode * inode,
857 kernel_lb_addr bloc, uint32_t offset, uint32_t count)
859 uint16_t partition = bloc.partitionReferenceNum;
861 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP)
863 return udf_bitmap_free_blocks(sb, inode,
864 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
865 bloc, offset, count);
867 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
869 return udf_table_free_blocks(sb, inode,
870 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
871 bloc, offset, count);
873 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
875 return udf_bitmap_free_blocks(sb, inode,
876 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
877 bloc, offset, count);
879 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
881 return udf_table_free_blocks(sb, inode,
882 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
883 bloc, offset, count);
889 inline int udf_prealloc_blocks(struct super_block * sb,
890 struct inode * inode,
891 uint16_t partition, uint32_t first_block, uint32_t block_count)
893 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP)
895 return udf_bitmap_prealloc_blocks(sb, inode,
896 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
897 partition, first_block, block_count);
899 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
901 return udf_table_prealloc_blocks(sb, inode,
902 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
903 partition, first_block, block_count);
905 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
907 return udf_bitmap_prealloc_blocks(sb, inode,
908 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
909 partition, first_block, block_count);
911 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
913 return udf_table_prealloc_blocks(sb, inode,
914 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
915 partition, first_block, block_count);
921 inline int udf_new_block(struct super_block * sb,
922 struct inode * inode,
923 uint16_t partition, uint32_t goal, int *err)
925 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP)
927 return udf_bitmap_new_block(sb, inode,
928 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
929 partition, goal, err);
931 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
933 return udf_table_new_block(sb, inode,
934 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
935 partition, goal, err);
937 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
939 return udf_bitmap_new_block(sb, inode,
940 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
941 partition, goal, err);
943 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
945 return udf_table_new_block(sb, inode,
946 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
947 partition, goal, err);