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_next_one_bit(addr, size, offset) \
35 ext2_find_next_bit(addr, size, offset)
37 static int read_block_bitmap(struct super_block
*sb
,
38 struct udf_bitmap
*bitmap
, unsigned int block
,
39 unsigned long bitmap_nr
)
41 struct buffer_head
*bh
= NULL
;
43 struct kernel_lb_addr loc
;
45 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
46 loc
.partitionReferenceNum
= UDF_SB(sb
)->s_partition
;
48 bh
= udf_tread(sb
, udf_get_lb_pblock(sb
, &loc
, block
));
52 bitmap
->s_block_bitmap
[bitmap_nr
] = bh
;
56 static int __load_block_bitmap(struct super_block
*sb
,
57 struct udf_bitmap
*bitmap
,
58 unsigned int block_group
)
61 int nr_groups
= bitmap
->s_nr_groups
;
63 if (block_group
>= nr_groups
) {
64 udf_debug("block_group (%d) > nr_groups (%d)\n", block_group
,
68 if (bitmap
->s_block_bitmap
[block_group
]) {
71 retval
= read_block_bitmap(sb
, bitmap
, block_group
,
79 static inline int load_block_bitmap(struct super_block
*sb
,
80 struct udf_bitmap
*bitmap
,
81 unsigned int block_group
)
85 slot
= __load_block_bitmap(sb
, bitmap
, block_group
);
90 if (!bitmap
->s_block_bitmap
[slot
])
96 static void udf_add_free_space(struct super_block
*sb
, u16 partition
, u32 cnt
)
98 struct udf_sb_info
*sbi
= UDF_SB(sb
);
99 struct logicalVolIntegrityDesc
*lvid
;
104 lvid
= (struct logicalVolIntegrityDesc
*)sbi
->s_lvid_bh
->b_data
;
105 le32_add_cpu(&lvid
->freeSpaceTable
[partition
], cnt
);
106 udf_updated_lvid(sb
);
109 static void udf_bitmap_free_blocks(struct super_block
*sb
,
111 struct udf_bitmap
*bitmap
,
112 struct kernel_lb_addr
*bloc
,
116 struct udf_sb_info
*sbi
= UDF_SB(sb
);
117 struct buffer_head
*bh
= NULL
;
118 struct udf_part_map
*partmap
;
120 unsigned long block_group
;
124 unsigned long overflow
;
126 mutex_lock(&sbi
->s_alloc_mutex
);
127 partmap
= &sbi
->s_partmaps
[bloc
->partitionReferenceNum
];
128 if (bloc
->logicalBlockNum
< 0 ||
129 (bloc
->logicalBlockNum
+ count
) >
130 partmap
->s_partition_len
) {
131 udf_debug("%d < %d || %d + %d > %d\n",
132 bloc
->logicalBlockNum
, 0, bloc
->logicalBlockNum
,
133 count
, partmap
->s_partition_len
);
137 block
= bloc
->logicalBlockNum
+ offset
+
138 (sizeof(struct spaceBitmapDesc
) << 3);
142 block_group
= block
>> (sb
->s_blocksize_bits
+ 3);
143 bit
= block
% (sb
->s_blocksize
<< 3);
146 * Check to see if we are freeing blocks across a group boundary.
148 if (bit
+ count
> (sb
->s_blocksize
<< 3)) {
149 overflow
= bit
+ count
- (sb
->s_blocksize
<< 3);
152 bitmap_nr
= load_block_bitmap(sb
, bitmap
, block_group
);
156 bh
= bitmap
->s_block_bitmap
[bitmap_nr
];
157 for (i
= 0; i
< count
; i
++) {
158 if (udf_set_bit(bit
+ i
, bh
->b_data
)) {
159 udf_debug("bit %ld already set\n", bit
+ i
);
160 udf_debug("byte=%2x\n",
161 ((char *)bh
->b_data
)[(bit
+ i
) >> 3]);
164 dquot_free_block(inode
, 1);
165 udf_add_free_space(sb
, sbi
->s_partition
, 1);
168 mark_buffer_dirty(bh
);
176 mutex_unlock(&sbi
->s_alloc_mutex
);
179 static int udf_bitmap_prealloc_blocks(struct super_block
*sb
,
181 struct udf_bitmap
*bitmap
,
182 uint16_t partition
, uint32_t first_block
,
183 uint32_t block_count
)
185 struct udf_sb_info
*sbi
= UDF_SB(sb
);
187 int bit
, block
, block_group
, group_start
;
188 int nr_groups
, bitmap_nr
;
189 struct buffer_head
*bh
;
192 mutex_lock(&sbi
->s_alloc_mutex
);
193 part_len
= sbi
->s_partmaps
[partition
].s_partition_len
;
194 if (first_block
>= part_len
)
197 if (first_block
+ block_count
> part_len
)
198 block_count
= part_len
- first_block
;
201 nr_groups
= udf_compute_nr_groups(sb
, partition
);
202 block
= first_block
+ (sizeof(struct spaceBitmapDesc
) << 3);
203 block_group
= block
>> (sb
->s_blocksize_bits
+ 3);
204 group_start
= block_group
? 0 : sizeof(struct spaceBitmapDesc
);
206 bitmap_nr
= load_block_bitmap(sb
, bitmap
, block_group
);
209 bh
= bitmap
->s_block_bitmap
[bitmap_nr
];
211 bit
= block
% (sb
->s_blocksize
<< 3);
213 while (bit
< (sb
->s_blocksize
<< 3) && block_count
> 0) {
214 if (!udf_test_bit(bit
, bh
->b_data
))
216 else if (dquot_prealloc_block(inode
, 1))
218 else if (!udf_clear_bit(bit
, bh
->b_data
)) {
219 udf_debug("bit already cleared for block %d\n", bit
);
220 dquot_free_block(inode
, 1);
228 mark_buffer_dirty(bh
);
229 } while (block_count
> 0);
232 udf_add_free_space(sb
, partition
, -alloc_count
);
233 mutex_unlock(&sbi
->s_alloc_mutex
);
237 static int udf_bitmap_new_block(struct super_block
*sb
,
239 struct udf_bitmap
*bitmap
, uint16_t partition
,
240 uint32_t goal
, int *err
)
242 struct udf_sb_info
*sbi
= UDF_SB(sb
);
243 int newbit
, bit
= 0, block
, block_group
, group_start
;
244 int end_goal
, nr_groups
, bitmap_nr
, i
;
245 struct buffer_head
*bh
= NULL
;
250 mutex_lock(&sbi
->s_alloc_mutex
);
253 if (goal
>= sbi
->s_partmaps
[partition
].s_partition_len
)
256 nr_groups
= bitmap
->s_nr_groups
;
257 block
= goal
+ (sizeof(struct spaceBitmapDesc
) << 3);
258 block_group
= block
>> (sb
->s_blocksize_bits
+ 3);
259 group_start
= block_group
? 0 : sizeof(struct spaceBitmapDesc
);
261 bitmap_nr
= load_block_bitmap(sb
, bitmap
, block_group
);
264 bh
= bitmap
->s_block_bitmap
[bitmap_nr
];
265 ptr
= memscan((char *)bh
->b_data
+ group_start
, 0xFF,
266 sb
->s_blocksize
- group_start
);
268 if ((ptr
- ((char *)bh
->b_data
)) < sb
->s_blocksize
) {
269 bit
= block
% (sb
->s_blocksize
<< 3);
270 if (udf_test_bit(bit
, bh
->b_data
))
273 end_goal
= (bit
+ 63) & ~63;
274 bit
= udf_find_next_one_bit(bh
->b_data
, end_goal
, bit
);
278 ptr
= memscan((char *)bh
->b_data
+ (bit
>> 3), 0xFF,
279 sb
->s_blocksize
- ((bit
+ 7) >> 3));
280 newbit
= (ptr
- ((char *)bh
->b_data
)) << 3;
281 if (newbit
< sb
->s_blocksize
<< 3) {
286 newbit
= udf_find_next_one_bit(bh
->b_data
,
287 sb
->s_blocksize
<< 3, bit
);
288 if (newbit
< sb
->s_blocksize
<< 3) {
294 for (i
= 0; i
< (nr_groups
* 2); i
++) {
296 if (block_group
>= nr_groups
)
298 group_start
= block_group
? 0 : sizeof(struct spaceBitmapDesc
);
300 bitmap_nr
= load_block_bitmap(sb
, bitmap
, block_group
);
303 bh
= bitmap
->s_block_bitmap
[bitmap_nr
];
305 ptr
= memscan((char *)bh
->b_data
+ group_start
, 0xFF,
306 sb
->s_blocksize
- group_start
);
307 if ((ptr
- ((char *)bh
->b_data
)) < sb
->s_blocksize
) {
308 bit
= (ptr
- ((char *)bh
->b_data
)) << 3;
312 bit
= udf_find_next_one_bit((char *)bh
->b_data
,
313 sb
->s_blocksize
<< 3,
315 if (bit
< sb
->s_blocksize
<< 3)
319 if (i
>= (nr_groups
* 2)) {
320 mutex_unlock(&sbi
->s_alloc_mutex
);
323 if (bit
< sb
->s_blocksize
<< 3)
326 bit
= udf_find_next_one_bit(bh
->b_data
, sb
->s_blocksize
<< 3,
328 if (bit
>= sb
->s_blocksize
<< 3) {
329 mutex_unlock(&sbi
->s_alloc_mutex
);
335 while (i
< 7 && bit
> (group_start
<< 3) &&
336 udf_test_bit(bit
- 1, bh
->b_data
)) {
344 * Check quota for allocation of this block.
347 int ret
= dquot_alloc_block(inode
, 1);
350 mutex_unlock(&sbi
->s_alloc_mutex
);
356 newblock
= bit
+ (block_group
<< (sb
->s_blocksize_bits
+ 3)) -
357 (sizeof(struct spaceBitmapDesc
) << 3);
359 if (!udf_clear_bit(bit
, bh
->b_data
)) {
360 udf_debug("bit already cleared for block %d\n", bit
);
364 mark_buffer_dirty(bh
);
366 udf_add_free_space(sb
, partition
, -1);
367 mutex_unlock(&sbi
->s_alloc_mutex
);
373 mutex_unlock(&sbi
->s_alloc_mutex
);
377 static void udf_table_free_blocks(struct super_block
*sb
,
380 struct kernel_lb_addr
*bloc
,
384 struct udf_sb_info
*sbi
= UDF_SB(sb
);
385 struct udf_part_map
*partmap
;
388 struct kernel_lb_addr eloc
;
389 struct extent_position oepos
, epos
;
392 struct udf_inode_info
*iinfo
;
394 mutex_lock(&sbi
->s_alloc_mutex
);
395 partmap
= &sbi
->s_partmaps
[bloc
->partitionReferenceNum
];
396 if (bloc
->logicalBlockNum
< 0 ||
397 (bloc
->logicalBlockNum
+ count
) >
398 partmap
->s_partition_len
) {
399 udf_debug("%d < %d || %d + %d > %d\n",
400 bloc
->logicalBlockNum
, 0, bloc
->logicalBlockNum
, count
,
401 partmap
->s_partition_len
);
405 iinfo
= UDF_I(table
);
406 /* We do this up front - There are some error conditions that
407 could occure, but.. oh well */
409 dquot_free_block(inode
, count
);
410 udf_add_free_space(sb
, sbi
->s_partition
, count
);
412 start
= bloc
->logicalBlockNum
+ offset
;
413 end
= bloc
->logicalBlockNum
+ offset
+ count
- 1;
415 epos
.offset
= oepos
.offset
= sizeof(struct unallocSpaceEntry
);
417 epos
.block
= oepos
.block
= iinfo
->i_location
;
418 epos
.bh
= oepos
.bh
= NULL
;
421 (etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1) {
422 if (((eloc
.logicalBlockNum
+
423 (elen
>> sb
->s_blocksize_bits
)) == start
)) {
424 if ((0x3FFFFFFF - elen
) <
425 (count
<< sb
->s_blocksize_bits
)) {
426 uint32_t tmp
= ((0x3FFFFFFF - elen
) >>
427 sb
->s_blocksize_bits
);
430 elen
= (etype
<< 30) |
431 (0x40000000 - sb
->s_blocksize
);
433 elen
= (etype
<< 30) |
435 (count
<< sb
->s_blocksize_bits
));
439 udf_write_aext(table
, &oepos
, &eloc
, elen
, 1);
440 } else if (eloc
.logicalBlockNum
== (end
+ 1)) {
441 if ((0x3FFFFFFF - elen
) <
442 (count
<< sb
->s_blocksize_bits
)) {
443 uint32_t tmp
= ((0x3FFFFFFF - elen
) >>
444 sb
->s_blocksize_bits
);
447 eloc
.logicalBlockNum
-= tmp
;
448 elen
= (etype
<< 30) |
449 (0x40000000 - sb
->s_blocksize
);
451 eloc
.logicalBlockNum
= start
;
452 elen
= (etype
<< 30) |
454 (count
<< sb
->s_blocksize_bits
));
458 udf_write_aext(table
, &oepos
, &eloc
, elen
, 1);
461 if (epos
.bh
!= oepos
.bh
) {
463 oepos
.block
= epos
.block
;
469 oepos
.offset
= epos
.offset
;
475 * NOTE: we CANNOT use udf_add_aext here, as it can try to
476 * allocate a new block, and since we hold the super block
477 * lock already very bad things would happen :)
479 * We copy the behavior of udf_add_aext, but instead of
480 * trying to allocate a new block close to the existing one,
481 * we just steal a block from the extent we are trying to add.
483 * It would be nice if the blocks were close together, but it
488 struct short_ad
*sad
= NULL
;
489 struct long_ad
*lad
= NULL
;
490 struct allocExtDesc
*aed
;
492 eloc
.logicalBlockNum
= start
;
493 elen
= EXT_RECORDED_ALLOCATED
|
494 (count
<< sb
->s_blocksize_bits
);
496 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
497 adsize
= sizeof(struct short_ad
);
498 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
499 adsize
= sizeof(struct long_ad
);
506 if (epos
.offset
+ (2 * adsize
) > sb
->s_blocksize
) {
507 unsigned char *sptr
, *dptr
;
513 /* Steal a block from the extent being free'd */
514 epos
.block
.logicalBlockNum
= eloc
.logicalBlockNum
;
515 eloc
.logicalBlockNum
++;
516 elen
-= sb
->s_blocksize
;
518 epos
.bh
= udf_tread(sb
,
519 udf_get_lb_pblock(sb
, &epos
.block
, 0));
524 aed
= (struct allocExtDesc
*)(epos
.bh
->b_data
);
525 aed
->previousAllocExtLocation
=
526 cpu_to_le32(oepos
.block
.logicalBlockNum
);
527 if (epos
.offset
+ adsize
> sb
->s_blocksize
) {
528 loffset
= epos
.offset
;
529 aed
->lengthAllocDescs
= cpu_to_le32(adsize
);
530 sptr
= iinfo
->i_ext
.i_data
+ epos
.offset
532 dptr
= epos
.bh
->b_data
+
533 sizeof(struct allocExtDesc
);
534 memcpy(dptr
, sptr
, adsize
);
535 epos
.offset
= sizeof(struct allocExtDesc
) +
538 loffset
= epos
.offset
+ adsize
;
539 aed
->lengthAllocDescs
= cpu_to_le32(0);
541 sptr
= oepos
.bh
->b_data
+ epos
.offset
;
542 aed
= (struct allocExtDesc
*)
544 le32_add_cpu(&aed
->lengthAllocDescs
,
547 sptr
= iinfo
->i_ext
.i_data
+
549 iinfo
->i_lenAlloc
+= adsize
;
550 mark_inode_dirty(table
);
552 epos
.offset
= sizeof(struct allocExtDesc
);
554 if (sbi
->s_udfrev
>= 0x0200)
555 udf_new_tag(epos
.bh
->b_data
, TAG_IDENT_AED
,
556 3, 1, epos
.block
.logicalBlockNum
,
559 udf_new_tag(epos
.bh
->b_data
, TAG_IDENT_AED
,
560 2, 1, epos
.block
.logicalBlockNum
,
563 switch (iinfo
->i_alloc_type
) {
564 case ICBTAG_FLAG_AD_SHORT
:
565 sad
= (struct short_ad
*)sptr
;
566 sad
->extLength
= cpu_to_le32(
567 EXT_NEXT_EXTENT_ALLOCDECS
|
570 cpu_to_le32(epos
.block
.logicalBlockNum
);
572 case ICBTAG_FLAG_AD_LONG
:
573 lad
= (struct long_ad
*)sptr
;
574 lad
->extLength
= cpu_to_le32(
575 EXT_NEXT_EXTENT_ALLOCDECS
|
578 cpu_to_lelb(epos
.block
);
582 udf_update_tag(oepos
.bh
->b_data
, loffset
);
583 mark_buffer_dirty(oepos
.bh
);
585 mark_inode_dirty(table
);
589 /* It's possible that stealing the block emptied the extent */
591 udf_write_aext(table
, &epos
, &eloc
, elen
, 1);
594 iinfo
->i_lenAlloc
+= adsize
;
595 mark_inode_dirty(table
);
597 aed
= (struct allocExtDesc
*)epos
.bh
->b_data
;
598 le32_add_cpu(&aed
->lengthAllocDescs
, adsize
);
599 udf_update_tag(epos
.bh
->b_data
, epos
.offset
);
600 mark_buffer_dirty(epos
.bh
);
609 mutex_unlock(&sbi
->s_alloc_mutex
);
613 static int udf_table_prealloc_blocks(struct super_block
*sb
,
615 struct inode
*table
, uint16_t partition
,
616 uint32_t first_block
, uint32_t block_count
)
618 struct udf_sb_info
*sbi
= UDF_SB(sb
);
620 uint32_t elen
, adsize
;
621 struct kernel_lb_addr eloc
;
622 struct extent_position epos
;
624 struct udf_inode_info
*iinfo
;
626 if (first_block
>= sbi
->s_partmaps
[partition
].s_partition_len
)
629 iinfo
= UDF_I(table
);
630 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
631 adsize
= sizeof(struct short_ad
);
632 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
633 adsize
= sizeof(struct long_ad
);
637 mutex_lock(&sbi
->s_alloc_mutex
);
638 epos
.offset
= sizeof(struct unallocSpaceEntry
);
639 epos
.block
= iinfo
->i_location
;
641 eloc
.logicalBlockNum
= 0xFFFFFFFF;
643 while (first_block
!= eloc
.logicalBlockNum
&&
644 (etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1) {
645 udf_debug("eloc=%d, elen=%d, first_block=%d\n",
646 eloc
.logicalBlockNum
, elen
, first_block
);
647 ; /* empty loop body */
650 if (first_block
== eloc
.logicalBlockNum
) {
651 epos
.offset
-= adsize
;
653 alloc_count
= (elen
>> sb
->s_blocksize_bits
);
654 if (inode
&& dquot_prealloc_block(inode
,
655 alloc_count
> block_count
? block_count
: alloc_count
))
657 else if (alloc_count
> block_count
) {
658 alloc_count
= block_count
;
659 eloc
.logicalBlockNum
+= alloc_count
;
660 elen
-= (alloc_count
<< sb
->s_blocksize_bits
);
661 udf_write_aext(table
, &epos
, &eloc
,
662 (etype
<< 30) | elen
, 1);
664 udf_delete_aext(table
, epos
, eloc
,
665 (etype
<< 30) | elen
);
673 udf_add_free_space(sb
, partition
, -alloc_count
);
674 mutex_unlock(&sbi
->s_alloc_mutex
);
678 static int udf_table_new_block(struct super_block
*sb
,
680 struct inode
*table
, uint16_t partition
,
681 uint32_t goal
, int *err
)
683 struct udf_sb_info
*sbi
= UDF_SB(sb
);
684 uint32_t spread
= 0xFFFFFFFF, nspread
= 0xFFFFFFFF;
685 uint32_t newblock
= 0, adsize
;
686 uint32_t elen
, goal_elen
= 0;
687 struct kernel_lb_addr eloc
, uninitialized_var(goal_eloc
);
688 struct extent_position epos
, goal_epos
;
690 struct udf_inode_info
*iinfo
= UDF_I(table
);
694 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
695 adsize
= sizeof(struct short_ad
);
696 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
697 adsize
= sizeof(struct long_ad
);
701 mutex_lock(&sbi
->s_alloc_mutex
);
702 if (goal
>= sbi
->s_partmaps
[partition
].s_partition_len
)
705 /* We search for the closest matching block to goal. If we find
706 a exact hit, we stop. Otherwise we keep going till we run out
707 of extents. We store the buffer_head, bloc, and extoffset
708 of the current closest match and use that when we are done.
710 epos
.offset
= sizeof(struct unallocSpaceEntry
);
711 epos
.block
= iinfo
->i_location
;
712 epos
.bh
= goal_epos
.bh
= NULL
;
715 (etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1) {
716 if (goal
>= eloc
.logicalBlockNum
) {
717 if (goal
< eloc
.logicalBlockNum
+
718 (elen
>> sb
->s_blocksize_bits
))
721 nspread
= goal
- eloc
.logicalBlockNum
-
722 (elen
>> sb
->s_blocksize_bits
);
724 nspread
= eloc
.logicalBlockNum
- goal
;
727 if (nspread
< spread
) {
729 if (goal_epos
.bh
!= epos
.bh
) {
730 brelse(goal_epos
.bh
);
731 goal_epos
.bh
= epos
.bh
;
732 get_bh(goal_epos
.bh
);
734 goal_epos
.block
= epos
.block
;
735 goal_epos
.offset
= epos
.offset
- adsize
;
737 goal_elen
= (etype
<< 30) | elen
;
743 if (spread
== 0xFFFFFFFF) {
744 brelse(goal_epos
.bh
);
745 mutex_unlock(&sbi
->s_alloc_mutex
);
749 /* Only allocate blocks from the beginning of the extent.
750 That way, we only delete (empty) extents, never have to insert an
751 extent because of splitting */
752 /* This works, but very poorly.... */
754 newblock
= goal_eloc
.logicalBlockNum
;
755 goal_eloc
.logicalBlockNum
++;
756 goal_elen
-= sb
->s_blocksize
;
758 *err
= dquot_alloc_block(inode
, 1);
760 brelse(goal_epos
.bh
);
761 mutex_unlock(&sbi
->s_alloc_mutex
);
767 udf_write_aext(table
, &goal_epos
, &goal_eloc
, goal_elen
, 1);
769 udf_delete_aext(table
, goal_epos
, goal_eloc
, goal_elen
);
770 brelse(goal_epos
.bh
);
772 udf_add_free_space(sb
, partition
, -1);
774 mutex_unlock(&sbi
->s_alloc_mutex
);
779 void udf_free_blocks(struct super_block
*sb
, struct inode
*inode
,
780 struct kernel_lb_addr
*bloc
, uint32_t offset
,
783 uint16_t partition
= bloc
->partitionReferenceNum
;
784 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
786 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
) {
787 udf_bitmap_free_blocks(sb
, inode
, map
->s_uspace
.s_bitmap
,
788 bloc
, offset
, count
);
789 } else if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
) {
790 udf_table_free_blocks(sb
, inode
, map
->s_uspace
.s_table
,
791 bloc
, offset
, count
);
792 } else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
) {
793 udf_bitmap_free_blocks(sb
, inode
, map
->s_fspace
.s_bitmap
,
794 bloc
, offset
, count
);
795 } else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
) {
796 udf_table_free_blocks(sb
, inode
, map
->s_fspace
.s_table
,
797 bloc
, offset
, count
);
801 inline int udf_prealloc_blocks(struct super_block
*sb
,
803 uint16_t partition
, uint32_t first_block
,
804 uint32_t block_count
)
806 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
808 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
809 return udf_bitmap_prealloc_blocks(sb
, inode
,
810 map
->s_uspace
.s_bitmap
,
811 partition
, first_block
,
813 else if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
814 return udf_table_prealloc_blocks(sb
, inode
,
815 map
->s_uspace
.s_table
,
816 partition
, first_block
,
818 else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
819 return udf_bitmap_prealloc_blocks(sb
, inode
,
820 map
->s_fspace
.s_bitmap
,
821 partition
, first_block
,
823 else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
824 return udf_table_prealloc_blocks(sb
, inode
,
825 map
->s_fspace
.s_table
,
826 partition
, first_block
,
832 inline int udf_new_block(struct super_block
*sb
,
834 uint16_t partition
, uint32_t goal
, int *err
)
836 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
838 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
839 return udf_bitmap_new_block(sb
, inode
,
840 map
->s_uspace
.s_bitmap
,
841 partition
, goal
, err
);
842 else if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
843 return udf_table_new_block(sb
, inode
,
844 map
->s_uspace
.s_table
,
845 partition
, goal
, err
);
846 else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
847 return udf_bitmap_new_block(sb
, inode
,
848 map
->s_fspace
.s_bitmap
,
849 partition
, goal
, err
);
850 else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
851 return udf_table_new_block(sb
, inode
,
852 map
->s_fspace
.s_table
,
853 partition
, goal
, err
);