5 * Block allocation handling routines for the OSTA-UDF(tm) filesystem.
8 * E-mail regarding any portion of the Linux UDF file system should be
9 * directed to the development team mailing list (run by majordomo):
10 * linux_udf@hpesjro.fc.hp.com
13 * This file is distributed under the terms of the GNU General Public
14 * License (GPL). Copies of the GPL can be obtained from:
15 * ftp://prep.ai.mit.edu/pub/gnu/GPL
16 * Each contributing author retains all rights to their own work.
18 * (C) 1999-2001 Ben Fennema
19 * (C) 1999 Stelias Computing Inc
23 * 02/24/99 blf Created.
29 #include <linux/locks.h>
30 #include <linux/quotaops.h>
31 #include <asm/bitops.h>
36 #define udf_clear_bit(nr,addr) ext2_clear_bit(nr,addr)
37 #define udf_set_bit(nr,addr) ext2_set_bit(nr,addr)
38 #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr)
39 #define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size)
40 #define udf_find_next_one_bit(addr, size, offset) find_next_one_bit(addr, size, offset)
42 #define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x)
43 #define leNUM_to_cpup(x,y) xleNUM_to_cpup(x,y)
44 #define xleNUM_to_cpup(x,y) (le ## x ## _to_cpup(y))
45 #define uintBPL_t uint(BITS_PER_LONG)
46 #define uint(x) xuint(x)
47 #define xuint(x) uint ## x ## _t
49 extern inline int find_next_one_bit (void * addr, int size, int offset)
51 uintBPL_t * p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG);
52 uintBPL_t result = offset & ~(BITS_PER_LONG-1);
58 offset &= (BITS_PER_LONG-1);
61 tmp = leBPL_to_cpup(p++);
62 tmp &= ~0UL << offset;
63 if (size < BITS_PER_LONG)
67 size -= BITS_PER_LONG;
68 result += BITS_PER_LONG;
70 while (size & ~(BITS_PER_LONG-1))
72 if ((tmp = leBPL_to_cpup(p++)))
74 result += BITS_PER_LONG;
75 size -= BITS_PER_LONG;
79 tmp = leBPL_to_cpup(p);
81 tmp &= ~0UL >> (BITS_PER_LONG-size);
83 return result + ffz(~tmp);
86 #define find_first_one_bit(addr, size)\
87 find_next_one_bit((addr), (size), 0)
89 static int read_block_bitmap(struct super_block * sb,
90 struct udf_bitmap *bitmap, unsigned int block, unsigned long bitmap_nr)
92 struct buffer_head *bh = NULL;
96 loc.logicalBlockNum = bitmap->s_extPosition;
97 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
99 bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block));
104 bitmap->s_block_bitmap[bitmap_nr] = bh;
108 static int __load_block_bitmap(struct super_block * sb,
109 struct udf_bitmap *bitmap, unsigned int block_group)
112 int nr_groups = bitmap->s_nr_groups;
114 if (block_group >= nr_groups)
116 udf_debug("block_group (%d) > nr_groups (%d)\n", block_group, nr_groups);
119 if (bitmap->s_block_bitmap[block_group])
123 retval = read_block_bitmap(sb, bitmap, block_group, block_group);
130 static inline int load_block_bitmap(struct super_block * sb,
131 struct udf_bitmap *bitmap, unsigned int block_group)
135 slot = __load_block_bitmap(sb, bitmap, block_group);
140 if (!bitmap->s_block_bitmap[slot])
146 static void udf_bitmap_free_blocks(struct super_block * sb,
147 struct inode * inode,
148 struct udf_bitmap *bitmap, lb_addr bloc, uint32_t offset, uint32_t count)
150 struct buffer_head * bh = NULL;
152 unsigned long block_group;
156 unsigned long overflow;
159 if (bloc.logicalBlockNum < 0 ||
160 (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum))
162 udf_debug("%d < %d || %d + %d > %d\n",
163 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
164 UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum));
168 block = bloc.logicalBlockNum + offset + (sizeof(struct spaceBitmapDesc) << 3);
172 block_group = block >> (sb->s_blocksize_bits + 3);
173 bit = block % (sb->s_blocksize << 3);
176 * Check to see if we are freeing blocks across a group boundary.
178 if (bit + count > (sb->s_blocksize << 3))
180 overflow = bit + count - (sb->s_blocksize << 3);
183 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
187 bh = bitmap->s_block_bitmap[bitmap_nr];
188 for (i=0; i < count; i++)
190 if (udf_set_bit(bit + i, bh->b_data))
192 udf_debug("bit %ld already set\n", bit + i);
193 udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]);
198 DQUOT_FREE_BLOCK(inode, 1);
199 if (UDF_SB_LVIDBH(sb))
201 UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] =
202 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)])+1);
206 mark_buffer_dirty(bh);
215 if (UDF_SB_LVIDBH(sb))
216 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
221 static int udf_bitmap_prealloc_blocks(struct super_block * sb,
222 struct inode * inode,
223 struct udf_bitmap *bitmap, uint16_t partition, uint32_t first_block,
224 uint32_t block_count)
227 int bit, block, block_group, group_start;
228 int nr_groups, bitmap_nr;
229 struct buffer_head *bh;
233 if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition))
236 if (first_block + block_count > UDF_SB_PARTLEN(sb, partition))
237 block_count = UDF_SB_PARTLEN(sb, partition) - first_block;
240 nr_groups = (UDF_SB_PARTLEN(sb, partition) +
241 (sizeof(struct spaceBitmapDesc) << 3) + (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8);
242 block = first_block + (sizeof(struct spaceBitmapDesc) << 3);
243 block_group = block >> (sb->s_blocksize_bits + 3);
244 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
246 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
249 bh = bitmap->s_block_bitmap[bitmap_nr];
251 bit = block % (sb->s_blocksize << 3);
253 while (bit < (sb->s_blocksize << 3) && block_count > 0)
255 if (!udf_test_bit(bit, bh->b_data))
257 else if (DQUOT_PREALLOC_BLOCK(inode, 1))
259 else if (!udf_clear_bit(bit, bh->b_data))
261 udf_debug("bit already cleared for block %d\n", bit);
262 DQUOT_FREE_BLOCK(inode, 1);
270 mark_buffer_dirty(bh);
274 if (UDF_SB_LVIDBH(sb))
276 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
277 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count);
278 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
285 static int udf_bitmap_new_block(struct super_block * sb,
286 struct inode * inode,
287 struct udf_bitmap *bitmap, uint16_t partition, uint32_t goal, int *err)
289 int newbit, bit=0, block, block_group, group_start;
290 int end_goal, nr_groups, bitmap_nr, i;
291 struct buffer_head *bh = NULL;
299 if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition))
302 nr_groups = bitmap->s_nr_groups;
303 block = goal + (sizeof(struct spaceBitmapDesc) << 3);
304 block_group = block >> (sb->s_blocksize_bits + 3);
305 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
307 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
310 bh = bitmap->s_block_bitmap[bitmap_nr];
311 ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start);
313 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize)
315 bit = block % (sb->s_blocksize << 3);
317 if (udf_test_bit(bit, bh->b_data))
321 end_goal = (bit + 63) & ~63;
322 bit = udf_find_next_one_bit(bh->b_data, end_goal, bit);
325 ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3));
326 newbit = (ptr - ((char *)bh->b_data)) << 3;
327 if (newbit < sb->s_blocksize << 3)
332 newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit);
333 if (newbit < sb->s_blocksize << 3)
340 for (i=0; i<(nr_groups*2); i++)
343 if (block_group >= nr_groups)
345 group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
347 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
350 bh = bitmap->s_block_bitmap[bitmap_nr];
353 ptr = memscan((char *)bh->b_data + group_start, 0xFF, sb->s_blocksize - group_start);
354 if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize)
356 bit = (ptr - ((char *)bh->b_data)) << 3;
362 bit = udf_find_next_one_bit((char *)bh->b_data, sb->s_blocksize << 3, group_start << 3);
363 if (bit < sb->s_blocksize << 3)
367 if (i >= (nr_groups*2))
372 if (bit < sb->s_blocksize << 3)
375 bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3);
376 if (bit >= sb->s_blocksize << 3)
383 for (i=0; i<7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--);
388 * Check quota for allocation of this block.
390 if (inode && DQUOT_ALLOC_BLOCK(inode, 1))
397 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
398 (sizeof(struct spaceBitmapDesc) << 3);
400 if (!udf_clear_bit(bit, bh->b_data))
402 udf_debug("bit already cleared for block %d\n", bit);
406 mark_buffer_dirty(bh);
408 if (UDF_SB_LVIDBH(sb))
410 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
411 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1);
412 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
425 static void udf_table_free_blocks(struct super_block * sb,
426 struct inode * inode,
427 struct inode * table, lb_addr bloc, uint32_t offset, uint32_t count)
430 uint32_t nextoffset, oextoffset, elen;
431 lb_addr nbloc, obloc, eloc;
432 struct buffer_head *obh, *nbh;
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);
464 obh = nbh = udf_tread(sb, udf_get_lb_pblock(sb, nbloc, 0));
465 atomic_inc(&nbh->b_count);
467 while (count && (etype =
468 udf_next_aext(table, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1)) != -1)
470 if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) ==
473 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits))
475 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
476 start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
477 elen = (etype << 30) | (0x40000000 - sb->s_blocksize);
481 elen = (etype << 30) |
482 (elen + (count << sb->s_blocksize_bits));
486 udf_write_aext(table, obloc, &oextoffset, eloc, elen, obh, 1);
488 else if (eloc.logicalBlockNum == (end + 1))
490 if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits))
492 count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
493 end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
494 eloc.logicalBlockNum -=
495 ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
496 elen = (etype << 30) | (0x40000000 - sb->s_blocksize);
500 eloc.logicalBlockNum = start;
501 elen = (etype << 30) |
502 (elen + (count << sb->s_blocksize_bits));
506 udf_write_aext(table, obloc, &oextoffset, eloc, elen, obh, 1);
509 if (memcmp(&nbloc, &obloc, sizeof(lb_addr)))
513 udf_release_data(obh);
514 atomic_inc(&nbh->b_count);
519 oextoffset = nextoffset;
524 /* NOTE: we CANNOT use udf_add_aext here, as it can try to allocate
525 a new block, and since we hold the super block lock already
526 very bad things would happen :)
528 We copy the behavior of udf_add_aext, but instead of
529 trying to allocate a new block close to the existing one,
530 we just steal a block from the extent we are trying to add.
532 It would be nice if the blocks were close together, but it
537 short_ad *sad = NULL;
539 struct allocExtDesc *aed;
541 eloc.logicalBlockNum = start;
542 elen = EXT_RECORDED_ALLOCATED |
543 (count << sb->s_blocksize_bits);
545 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
546 adsize = sizeof(short_ad);
547 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
548 adsize = sizeof(long_ad);
551 udf_release_data(obh);
552 udf_release_data(nbh);
556 if (nextoffset + (2 * adsize) > sb->s_blocksize)
561 udf_release_data(obh);
564 oextoffset = nextoffset;
566 /* Steal a block from the extent being free'd */
567 nbloc.logicalBlockNum = eloc.logicalBlockNum;
568 eloc.logicalBlockNum ++;
569 elen -= sb->s_blocksize;
571 if (!(nbh = udf_tread(sb,
572 udf_get_lb_pblock(sb, nbloc, 0))))
574 udf_release_data(obh);
577 aed = (struct allocExtDesc *)(nbh->b_data);
578 aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum);
579 if (nextoffset + adsize > sb->s_blocksize)
581 loffset = nextoffset;
582 aed->lengthAllocDescs = cpu_to_le32(adsize);
583 sptr = (obh)->b_data + nextoffset - adsize;
584 dptr = nbh->b_data + sizeof(struct allocExtDesc);
585 memcpy(dptr, sptr, adsize);
586 nextoffset = sizeof(struct allocExtDesc) + adsize;
590 loffset = nextoffset + adsize;
591 aed->lengthAllocDescs = cpu_to_le32(0);
592 sptr = (obh)->b_data + nextoffset;
593 nextoffset = sizeof(struct allocExtDesc);
595 if (memcmp(&UDF_I_LOCATION(table), &obloc, sizeof(lb_addr)))
597 aed = (struct allocExtDesc *)(obh)->b_data;
598 aed->lengthAllocDescs =
599 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
603 UDF_I_LENALLOC(table) += adsize;
604 mark_inode_dirty(table);
607 if (UDF_SB_UDFREV(sb) >= 0x0200)
608 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
609 nbloc.logicalBlockNum, sizeof(tag));
611 udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
612 nbloc.logicalBlockNum, sizeof(tag));
613 switch (UDF_I_ALLOCTYPE(table))
615 case ICBTAG_FLAG_AD_SHORT:
617 sad = (short_ad *)sptr;
618 sad->extLength = cpu_to_le32(
619 EXT_NEXT_EXTENT_ALLOCDECS |
621 sad->extPosition = cpu_to_le32(nbloc.logicalBlockNum);
624 case ICBTAG_FLAG_AD_LONG:
626 lad = (long_ad *)sptr;
627 lad->extLength = cpu_to_le32(
628 EXT_NEXT_EXTENT_ALLOCDECS |
630 lad->extLocation = cpu_to_lelb(nbloc);
634 udf_update_tag(obh->b_data, loffset);
635 mark_buffer_dirty(obh);
638 if (elen) /* It's possible that stealing the block emptied the extent */
640 udf_write_aext(table, nbloc, &nextoffset, eloc, elen, nbh, 1);
642 if (!memcmp(&UDF_I_LOCATION(table), &nbloc, sizeof(lb_addr)))
644 UDF_I_LENALLOC(table) += adsize;
645 mark_inode_dirty(table);
649 aed = (struct allocExtDesc *)nbh->b_data;
650 aed->lengthAllocDescs =
651 cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
652 udf_update_tag(nbh->b_data, nextoffset);
653 mark_buffer_dirty(nbh);
658 udf_release_data(nbh);
659 udf_release_data(obh);
667 static int udf_table_prealloc_blocks(struct super_block * sb,
668 struct inode * inode,
669 struct inode *table, uint16_t partition, uint32_t first_block,
670 uint32_t block_count)
673 uint32_t extoffset, elen, adsize;
675 struct buffer_head *bh;
678 if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition))
681 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
682 adsize = sizeof(short_ad);
683 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
684 adsize = sizeof(long_ad);
690 extoffset = sizeof(struct unallocSpaceEntry);
691 bloc = UDF_I_LOCATION(table);
693 bh = udf_tread(sb, udf_get_lb_pblock(sb, bloc, 0));
694 eloc.logicalBlockNum = 0xFFFFFFFF;
696 while (first_block != eloc.logicalBlockNum && (etype =
697 udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
699 udf_debug("eloc=%d, elen=%d, first_block=%d\n",
700 eloc.logicalBlockNum, elen, first_block);
701 ; /* empty loop body */
704 if (first_block == eloc.logicalBlockNum)
708 alloc_count = (elen >> sb->s_blocksize_bits);
709 if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count))
711 else if (alloc_count > block_count)
713 alloc_count = block_count;
714 eloc.logicalBlockNum += alloc_count;
715 elen -= (alloc_count << sb->s_blocksize_bits);
716 udf_write_aext(table, bloc, &extoffset, eloc, (etype << 30) | elen, bh, 1);
719 udf_delete_aext(table, bloc, extoffset, eloc, (etype << 30) | elen, bh);
724 udf_release_data(bh);
726 if (alloc_count && UDF_SB_LVIDBH(sb))
728 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
729 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-alloc_count);
730 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
737 static int udf_table_new_block(struct super_block * sb,
738 struct inode * inode,
739 struct inode *table, uint16_t partition, uint32_t goal, int *err)
741 uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF;
742 uint32_t newblock = 0, adsize;
743 uint32_t extoffset, goal_extoffset, elen, goal_elen = 0;
744 lb_addr bloc, goal_bloc, eloc, goal_eloc;
745 struct buffer_head *bh, *goal_bh;
750 if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
751 adsize = sizeof(short_ad);
752 else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
753 adsize = sizeof(long_ad);
759 if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition))
762 /* We search for the closest matching block to goal. If we find a exact hit,
763 we stop. Otherwise we keep going till we run out of extents.
764 We store the buffer_head, bloc, and extoffset of the current closest
765 match and use that when we are done.
768 extoffset = sizeof(struct unallocSpaceEntry);
769 bloc = UDF_I_LOCATION(table);
771 goal_bh = bh = udf_tread(sb, udf_get_lb_pblock(sb, bloc, 0));
772 atomic_inc(&goal_bh->b_count);
774 while (spread && (etype =
775 udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
777 if (goal >= eloc.logicalBlockNum)
779 if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits))
782 nspread = goal - eloc.logicalBlockNum -
783 (elen >> sb->s_blocksize_bits);
786 nspread = eloc.logicalBlockNum - goal;
788 if (nspread < spread)
793 udf_release_data(goal_bh);
795 atomic_inc(&goal_bh->b_count);
798 goal_extoffset = extoffset - adsize;
800 goal_elen = (etype << 30) | elen;
804 udf_release_data(bh);
806 if (spread == 0xFFFFFFFF)
808 udf_release_data(goal_bh);
813 /* Only allocate blocks from the beginning of the extent.
814 That way, we only delete (empty) extents, never have to insert an
815 extent because of splitting */
816 /* This works, but very poorly.... */
818 newblock = goal_eloc.logicalBlockNum;
819 goal_eloc.logicalBlockNum ++;
820 goal_elen -= sb->s_blocksize;
822 if (inode && DQUOT_ALLOC_BLOCK(inode, 1))
824 udf_release_data(goal_bh);
831 udf_write_aext(table, goal_bloc, &goal_extoffset, goal_eloc, goal_elen, goal_bh, 1);
833 udf_delete_aext(table, goal_bloc, goal_extoffset, goal_eloc, goal_elen, goal_bh);
834 udf_release_data(goal_bh);
836 if (UDF_SB_LVIDBH(sb))
838 UDF_SB_LVID(sb)->freeSpaceTable[partition] =
839 cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition])-1);
840 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
849 inline void udf_free_blocks(struct super_block * sb,
850 struct inode * inode,
851 lb_addr bloc, uint32_t offset, uint32_t count)
853 uint16_t partition = bloc.partitionReferenceNum;
855 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP)
857 return udf_bitmap_free_blocks(sb, inode,
858 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
859 bloc, offset, count);
861 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
863 return udf_table_free_blocks(sb, inode,
864 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
865 bloc, offset, count);
867 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
869 return udf_bitmap_free_blocks(sb, inode,
870 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
871 bloc, offset, count);
873 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
875 return udf_table_free_blocks(sb, inode,
876 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
877 bloc, offset, count);
883 inline int udf_prealloc_blocks(struct super_block * sb,
884 struct inode * inode,
885 uint16_t partition, uint32_t first_block, uint32_t block_count)
887 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP)
889 return udf_bitmap_prealloc_blocks(sb, inode,
890 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
891 partition, first_block, block_count);
893 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
895 return udf_table_prealloc_blocks(sb, inode,
896 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
897 partition, first_block, block_count);
899 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
901 return udf_bitmap_prealloc_blocks(sb, inode,
902 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
903 partition, first_block, block_count);
905 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
907 return udf_table_prealloc_blocks(sb, inode,
908 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
909 partition, first_block, block_count);
915 inline int udf_new_block(struct super_block * sb,
916 struct inode * inode,
917 uint16_t partition, uint32_t goal, int *err)
919 if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP)
921 return udf_bitmap_new_block(sb, inode,
922 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
923 partition, goal, err);
925 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE)
927 return udf_table_new_block(sb, inode,
928 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
929 partition, goal, err);
931 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP)
933 return udf_bitmap_new_block(sb, inode,
934 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
935 partition, goal, err);
937 else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE)
939 return udf_table_new_block(sb, inode,
940 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
941 partition, goal, err);