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/buffer_head.h>
25 #include <linux/bitops.h>
30 #define udf_clear_bit __test_and_clear_bit_le
31 #define udf_set_bit __test_and_set_bit_le
32 #define udf_test_bit test_bit_le
33 #define udf_find_next_one_bit find_next_bit_le
35 static int read_block_bitmap(struct super_block
*sb
,
36 struct udf_bitmap
*bitmap
, unsigned int block
,
37 unsigned long bitmap_nr
)
39 struct buffer_head
*bh
= NULL
;
41 struct kernel_lb_addr loc
;
43 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
44 loc
.partitionReferenceNum
= UDF_SB(sb
)->s_partition
;
46 bh
= udf_tread(sb
, udf_get_lb_pblock(sb
, &loc
, block
));
50 bitmap
->s_block_bitmap
[bitmap_nr
] = bh
;
54 static int __load_block_bitmap(struct super_block
*sb
,
55 struct udf_bitmap
*bitmap
,
56 unsigned int block_group
)
59 int nr_groups
= bitmap
->s_nr_groups
;
61 if (block_group
>= nr_groups
) {
62 udf_debug("block_group (%d) > nr_groups (%d)\n",
63 block_group
, nr_groups
);
66 if (bitmap
->s_block_bitmap
[block_group
]) {
69 retval
= read_block_bitmap(sb
, bitmap
, block_group
,
77 static inline int load_block_bitmap(struct super_block
*sb
,
78 struct udf_bitmap
*bitmap
,
79 unsigned int block_group
)
83 slot
= __load_block_bitmap(sb
, bitmap
, block_group
);
88 if (!bitmap
->s_block_bitmap
[slot
])
94 static void udf_add_free_space(struct super_block
*sb
, u16 partition
, u32 cnt
)
96 struct udf_sb_info
*sbi
= UDF_SB(sb
);
97 struct logicalVolIntegrityDesc
*lvid
;
102 lvid
= (struct logicalVolIntegrityDesc
*)sbi
->s_lvid_bh
->b_data
;
103 le32_add_cpu(&lvid
->freeSpaceTable
[partition
], cnt
);
104 udf_updated_lvid(sb
);
107 static void udf_bitmap_free_blocks(struct super_block
*sb
,
108 struct udf_bitmap
*bitmap
,
109 struct kernel_lb_addr
*bloc
,
113 struct udf_sb_info
*sbi
= UDF_SB(sb
);
114 struct buffer_head
*bh
= NULL
;
115 struct udf_part_map
*partmap
;
117 unsigned long block_group
;
121 unsigned long overflow
;
123 mutex_lock(&sbi
->s_alloc_mutex
);
124 partmap
= &sbi
->s_partmaps
[bloc
->partitionReferenceNum
];
125 if (bloc
->logicalBlockNum
+ count
< count
||
126 (bloc
->logicalBlockNum
+ count
) > partmap
->s_partition_len
) {
127 udf_debug("%d < %d || %d + %d > %d\n",
128 bloc
->logicalBlockNum
, 0,
129 bloc
->logicalBlockNum
, count
,
130 partmap
->s_partition_len
);
134 block
= bloc
->logicalBlockNum
+ offset
+
135 (sizeof(struct spaceBitmapDesc
) << 3);
139 block_group
= block
>> (sb
->s_blocksize_bits
+ 3);
140 bit
= block
% (sb
->s_blocksize
<< 3);
143 * Check to see if we are freeing blocks across a group boundary.
145 if (bit
+ count
> (sb
->s_blocksize
<< 3)) {
146 overflow
= bit
+ count
- (sb
->s_blocksize
<< 3);
149 bitmap_nr
= load_block_bitmap(sb
, bitmap
, block_group
);
153 bh
= bitmap
->s_block_bitmap
[bitmap_nr
];
154 for (i
= 0; i
< count
; i
++) {
155 if (udf_set_bit(bit
+ i
, bh
->b_data
)) {
156 udf_debug("bit %ld already set\n", bit
+ i
);
157 udf_debug("byte=%2x\n",
158 ((char *)bh
->b_data
)[(bit
+ i
) >> 3]);
161 udf_add_free_space(sb
, sbi
->s_partition
, count
);
162 mark_buffer_dirty(bh
);
170 mutex_unlock(&sbi
->s_alloc_mutex
);
173 static int udf_bitmap_prealloc_blocks(struct super_block
*sb
,
174 struct udf_bitmap
*bitmap
,
175 uint16_t partition
, uint32_t first_block
,
176 uint32_t block_count
)
178 struct udf_sb_info
*sbi
= UDF_SB(sb
);
180 int bit
, block
, block_group
, group_start
;
181 int nr_groups
, bitmap_nr
;
182 struct buffer_head
*bh
;
185 mutex_lock(&sbi
->s_alloc_mutex
);
186 part_len
= sbi
->s_partmaps
[partition
].s_partition_len
;
187 if (first_block
>= part_len
)
190 if (first_block
+ block_count
> part_len
)
191 block_count
= part_len
- first_block
;
194 nr_groups
= udf_compute_nr_groups(sb
, partition
);
195 block
= first_block
+ (sizeof(struct spaceBitmapDesc
) << 3);
196 block_group
= block
>> (sb
->s_blocksize_bits
+ 3);
197 group_start
= block_group
? 0 : sizeof(struct spaceBitmapDesc
);
199 bitmap_nr
= load_block_bitmap(sb
, bitmap
, block_group
);
202 bh
= bitmap
->s_block_bitmap
[bitmap_nr
];
204 bit
= block
% (sb
->s_blocksize
<< 3);
206 while (bit
< (sb
->s_blocksize
<< 3) && block_count
> 0) {
207 if (!udf_clear_bit(bit
, bh
->b_data
))
214 mark_buffer_dirty(bh
);
215 } while (block_count
> 0);
218 udf_add_free_space(sb
, partition
, -alloc_count
);
219 mutex_unlock(&sbi
->s_alloc_mutex
);
223 static int udf_bitmap_new_block(struct super_block
*sb
,
224 struct udf_bitmap
*bitmap
, uint16_t partition
,
225 uint32_t goal
, int *err
)
227 struct udf_sb_info
*sbi
= UDF_SB(sb
);
228 int newbit
, bit
= 0, block
, block_group
, group_start
;
229 int end_goal
, nr_groups
, bitmap_nr
, i
;
230 struct buffer_head
*bh
= NULL
;
235 mutex_lock(&sbi
->s_alloc_mutex
);
238 if (goal
>= sbi
->s_partmaps
[partition
].s_partition_len
)
241 nr_groups
= bitmap
->s_nr_groups
;
242 block
= goal
+ (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
];
250 ptr
= memscan((char *)bh
->b_data
+ group_start
, 0xFF,
251 sb
->s_blocksize
- group_start
);
253 if ((ptr
- ((char *)bh
->b_data
)) < sb
->s_blocksize
) {
254 bit
= block
% (sb
->s_blocksize
<< 3);
255 if (udf_test_bit(bit
, bh
->b_data
))
258 end_goal
= (bit
+ 63) & ~63;
259 bit
= udf_find_next_one_bit(bh
->b_data
, end_goal
, bit
);
263 ptr
= memscan((char *)bh
->b_data
+ (bit
>> 3), 0xFF,
264 sb
->s_blocksize
- ((bit
+ 7) >> 3));
265 newbit
= (ptr
- ((char *)bh
->b_data
)) << 3;
266 if (newbit
< sb
->s_blocksize
<< 3) {
271 newbit
= udf_find_next_one_bit(bh
->b_data
,
272 sb
->s_blocksize
<< 3, bit
);
273 if (newbit
< sb
->s_blocksize
<< 3) {
279 for (i
= 0; i
< (nr_groups
* 2); i
++) {
281 if (block_group
>= nr_groups
)
283 group_start
= block_group
? 0 : sizeof(struct spaceBitmapDesc
);
285 bitmap_nr
= load_block_bitmap(sb
, bitmap
, block_group
);
288 bh
= bitmap
->s_block_bitmap
[bitmap_nr
];
290 ptr
= memscan((char *)bh
->b_data
+ group_start
, 0xFF,
291 sb
->s_blocksize
- group_start
);
292 if ((ptr
- ((char *)bh
->b_data
)) < sb
->s_blocksize
) {
293 bit
= (ptr
- ((char *)bh
->b_data
)) << 3;
297 bit
= udf_find_next_one_bit(bh
->b_data
,
298 sb
->s_blocksize
<< 3,
300 if (bit
< sb
->s_blocksize
<< 3)
304 if (i
>= (nr_groups
* 2)) {
305 mutex_unlock(&sbi
->s_alloc_mutex
);
308 if (bit
< sb
->s_blocksize
<< 3)
311 bit
= udf_find_next_one_bit(bh
->b_data
, sb
->s_blocksize
<< 3,
313 if (bit
>= sb
->s_blocksize
<< 3) {
314 mutex_unlock(&sbi
->s_alloc_mutex
);
320 while (i
< 7 && bit
> (group_start
<< 3) &&
321 udf_test_bit(bit
- 1, bh
->b_data
)) {
327 newblock
= bit
+ (block_group
<< (sb
->s_blocksize_bits
+ 3)) -
328 (sizeof(struct spaceBitmapDesc
) << 3);
330 if (!udf_clear_bit(bit
, bh
->b_data
)) {
331 udf_debug("bit already cleared for block %d\n", bit
);
335 mark_buffer_dirty(bh
);
337 udf_add_free_space(sb
, partition
, -1);
338 mutex_unlock(&sbi
->s_alloc_mutex
);
344 mutex_unlock(&sbi
->s_alloc_mutex
);
348 static void udf_table_free_blocks(struct super_block
*sb
,
350 struct kernel_lb_addr
*bloc
,
354 struct udf_sb_info
*sbi
= UDF_SB(sb
);
355 struct udf_part_map
*partmap
;
358 struct kernel_lb_addr eloc
;
359 struct extent_position oepos
, epos
;
362 struct udf_inode_info
*iinfo
;
364 mutex_lock(&sbi
->s_alloc_mutex
);
365 partmap
= &sbi
->s_partmaps
[bloc
->partitionReferenceNum
];
366 if (bloc
->logicalBlockNum
+ count
< count
||
367 (bloc
->logicalBlockNum
+ count
) > partmap
->s_partition_len
) {
368 udf_debug("%d < %d || %d + %d > %d\n",
369 bloc
->logicalBlockNum
, 0,
370 bloc
->logicalBlockNum
, count
,
371 partmap
->s_partition_len
);
375 iinfo
= UDF_I(table
);
376 udf_add_free_space(sb
, sbi
->s_partition
, count
);
378 start
= bloc
->logicalBlockNum
+ offset
;
379 end
= bloc
->logicalBlockNum
+ offset
+ count
- 1;
381 epos
.offset
= oepos
.offset
= sizeof(struct unallocSpaceEntry
);
383 epos
.block
= oepos
.block
= iinfo
->i_location
;
384 epos
.bh
= oepos
.bh
= NULL
;
387 (etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1) {
388 if (((eloc
.logicalBlockNum
+
389 (elen
>> sb
->s_blocksize_bits
)) == start
)) {
390 if ((0x3FFFFFFF - elen
) <
391 (count
<< sb
->s_blocksize_bits
)) {
392 uint32_t tmp
= ((0x3FFFFFFF - elen
) >>
393 sb
->s_blocksize_bits
);
396 elen
= (etype
<< 30) |
397 (0x40000000 - sb
->s_blocksize
);
399 elen
= (etype
<< 30) |
401 (count
<< sb
->s_blocksize_bits
));
405 udf_write_aext(table
, &oepos
, &eloc
, elen
, 1);
406 } else if (eloc
.logicalBlockNum
== (end
+ 1)) {
407 if ((0x3FFFFFFF - elen
) <
408 (count
<< sb
->s_blocksize_bits
)) {
409 uint32_t tmp
= ((0x3FFFFFFF - elen
) >>
410 sb
->s_blocksize_bits
);
413 eloc
.logicalBlockNum
-= tmp
;
414 elen
= (etype
<< 30) |
415 (0x40000000 - sb
->s_blocksize
);
417 eloc
.logicalBlockNum
= start
;
418 elen
= (etype
<< 30) |
420 (count
<< sb
->s_blocksize_bits
));
424 udf_write_aext(table
, &oepos
, &eloc
, elen
, 1);
427 if (epos
.bh
!= oepos
.bh
) {
429 oepos
.block
= epos
.block
;
435 oepos
.offset
= epos
.offset
;
441 * NOTE: we CANNOT use udf_add_aext here, as it can try to
442 * allocate a new block, and since we hold the super block
443 * lock already very bad things would happen :)
445 * We copy the behavior of udf_add_aext, but instead of
446 * trying to allocate a new block close to the existing one,
447 * we just steal a block from the extent we are trying to add.
449 * It would be nice if the blocks were close together, but it
454 struct short_ad
*sad
= NULL
;
455 struct long_ad
*lad
= NULL
;
456 struct allocExtDesc
*aed
;
458 eloc
.logicalBlockNum
= start
;
459 elen
= EXT_RECORDED_ALLOCATED
|
460 (count
<< sb
->s_blocksize_bits
);
462 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
463 adsize
= sizeof(struct short_ad
);
464 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
465 adsize
= sizeof(struct long_ad
);
472 if (epos
.offset
+ (2 * adsize
) > sb
->s_blocksize
) {
473 unsigned char *sptr
, *dptr
;
479 /* Steal a block from the extent being free'd */
480 epos
.block
.logicalBlockNum
= eloc
.logicalBlockNum
;
481 eloc
.logicalBlockNum
++;
482 elen
-= sb
->s_blocksize
;
484 epos
.bh
= udf_tread(sb
,
485 udf_get_lb_pblock(sb
, &epos
.block
, 0));
490 aed
= (struct allocExtDesc
*)(epos
.bh
->b_data
);
491 aed
->previousAllocExtLocation
=
492 cpu_to_le32(oepos
.block
.logicalBlockNum
);
493 if (epos
.offset
+ adsize
> sb
->s_blocksize
) {
494 loffset
= epos
.offset
;
495 aed
->lengthAllocDescs
= cpu_to_le32(adsize
);
496 sptr
= iinfo
->i_ext
.i_data
+ epos
.offset
498 dptr
= epos
.bh
->b_data
+
499 sizeof(struct allocExtDesc
);
500 memcpy(dptr
, sptr
, adsize
);
501 epos
.offset
= sizeof(struct allocExtDesc
) +
504 loffset
= epos
.offset
+ adsize
;
505 aed
->lengthAllocDescs
= cpu_to_le32(0);
507 sptr
= oepos
.bh
->b_data
+ epos
.offset
;
508 aed
= (struct allocExtDesc
*)
510 le32_add_cpu(&aed
->lengthAllocDescs
,
513 sptr
= iinfo
->i_ext
.i_data
+
515 iinfo
->i_lenAlloc
+= adsize
;
516 mark_inode_dirty(table
);
518 epos
.offset
= sizeof(struct allocExtDesc
);
520 if (sbi
->s_udfrev
>= 0x0200)
521 udf_new_tag(epos
.bh
->b_data
, TAG_IDENT_AED
,
522 3, 1, epos
.block
.logicalBlockNum
,
525 udf_new_tag(epos
.bh
->b_data
, TAG_IDENT_AED
,
526 2, 1, epos
.block
.logicalBlockNum
,
529 switch (iinfo
->i_alloc_type
) {
530 case ICBTAG_FLAG_AD_SHORT
:
531 sad
= (struct short_ad
*)sptr
;
532 sad
->extLength
= cpu_to_le32(
533 EXT_NEXT_EXTENT_ALLOCDECS
|
536 cpu_to_le32(epos
.block
.logicalBlockNum
);
538 case ICBTAG_FLAG_AD_LONG
:
539 lad
= (struct long_ad
*)sptr
;
540 lad
->extLength
= cpu_to_le32(
541 EXT_NEXT_EXTENT_ALLOCDECS
|
544 cpu_to_lelb(epos
.block
);
548 udf_update_tag(oepos
.bh
->b_data
, loffset
);
549 mark_buffer_dirty(oepos
.bh
);
551 mark_inode_dirty(table
);
555 /* It's possible that stealing the block emptied the extent */
557 udf_write_aext(table
, &epos
, &eloc
, elen
, 1);
560 iinfo
->i_lenAlloc
+= adsize
;
561 mark_inode_dirty(table
);
563 aed
= (struct allocExtDesc
*)epos
.bh
->b_data
;
564 le32_add_cpu(&aed
->lengthAllocDescs
, adsize
);
565 udf_update_tag(epos
.bh
->b_data
, epos
.offset
);
566 mark_buffer_dirty(epos
.bh
);
575 mutex_unlock(&sbi
->s_alloc_mutex
);
579 static int udf_table_prealloc_blocks(struct super_block
*sb
,
580 struct inode
*table
, uint16_t partition
,
581 uint32_t first_block
, uint32_t block_count
)
583 struct udf_sb_info
*sbi
= UDF_SB(sb
);
585 uint32_t elen
, adsize
;
586 struct kernel_lb_addr eloc
;
587 struct extent_position epos
;
589 struct udf_inode_info
*iinfo
;
591 if (first_block
>= sbi
->s_partmaps
[partition
].s_partition_len
)
594 iinfo
= UDF_I(table
);
595 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
596 adsize
= sizeof(struct short_ad
);
597 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
598 adsize
= sizeof(struct long_ad
);
602 mutex_lock(&sbi
->s_alloc_mutex
);
603 epos
.offset
= sizeof(struct unallocSpaceEntry
);
604 epos
.block
= iinfo
->i_location
;
606 eloc
.logicalBlockNum
= 0xFFFFFFFF;
608 while (first_block
!= eloc
.logicalBlockNum
&&
609 (etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1) {
610 udf_debug("eloc=%d, elen=%d, first_block=%d\n",
611 eloc
.logicalBlockNum
, elen
, first_block
);
612 ; /* empty loop body */
615 if (first_block
== eloc
.logicalBlockNum
) {
616 epos
.offset
-= adsize
;
618 alloc_count
= (elen
>> sb
->s_blocksize_bits
);
619 if (alloc_count
> block_count
) {
620 alloc_count
= block_count
;
621 eloc
.logicalBlockNum
+= alloc_count
;
622 elen
-= (alloc_count
<< sb
->s_blocksize_bits
);
623 udf_write_aext(table
, &epos
, &eloc
,
624 (etype
<< 30) | elen
, 1);
626 udf_delete_aext(table
, epos
, eloc
,
627 (etype
<< 30) | elen
);
635 udf_add_free_space(sb
, partition
, -alloc_count
);
636 mutex_unlock(&sbi
->s_alloc_mutex
);
640 static int udf_table_new_block(struct super_block
*sb
,
641 struct inode
*table
, uint16_t partition
,
642 uint32_t goal
, int *err
)
644 struct udf_sb_info
*sbi
= UDF_SB(sb
);
645 uint32_t spread
= 0xFFFFFFFF, nspread
= 0xFFFFFFFF;
646 uint32_t newblock
= 0, adsize
;
647 uint32_t elen
, goal_elen
= 0;
648 struct kernel_lb_addr eloc
, uninitialized_var(goal_eloc
);
649 struct extent_position epos
, goal_epos
;
651 struct udf_inode_info
*iinfo
= UDF_I(table
);
655 if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_SHORT
)
656 adsize
= sizeof(struct short_ad
);
657 else if (iinfo
->i_alloc_type
== ICBTAG_FLAG_AD_LONG
)
658 adsize
= sizeof(struct long_ad
);
662 mutex_lock(&sbi
->s_alloc_mutex
);
663 if (goal
>= sbi
->s_partmaps
[partition
].s_partition_len
)
666 /* We search for the closest matching block to goal. If we find
667 a exact hit, we stop. Otherwise we keep going till we run out
668 of extents. We store the buffer_head, bloc, and extoffset
669 of the current closest match and use that when we are done.
671 epos
.offset
= sizeof(struct unallocSpaceEntry
);
672 epos
.block
= iinfo
->i_location
;
673 epos
.bh
= goal_epos
.bh
= NULL
;
676 (etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1) {
677 if (goal
>= eloc
.logicalBlockNum
) {
678 if (goal
< eloc
.logicalBlockNum
+
679 (elen
>> sb
->s_blocksize_bits
))
682 nspread
= goal
- eloc
.logicalBlockNum
-
683 (elen
>> sb
->s_blocksize_bits
);
685 nspread
= eloc
.logicalBlockNum
- goal
;
688 if (nspread
< spread
) {
690 if (goal_epos
.bh
!= epos
.bh
) {
691 brelse(goal_epos
.bh
);
692 goal_epos
.bh
= epos
.bh
;
693 get_bh(goal_epos
.bh
);
695 goal_epos
.block
= epos
.block
;
696 goal_epos
.offset
= epos
.offset
- adsize
;
698 goal_elen
= (etype
<< 30) | elen
;
704 if (spread
== 0xFFFFFFFF) {
705 brelse(goal_epos
.bh
);
706 mutex_unlock(&sbi
->s_alloc_mutex
);
710 /* Only allocate blocks from the beginning of the extent.
711 That way, we only delete (empty) extents, never have to insert an
712 extent because of splitting */
713 /* This works, but very poorly.... */
715 newblock
= goal_eloc
.logicalBlockNum
;
716 goal_eloc
.logicalBlockNum
++;
717 goal_elen
-= sb
->s_blocksize
;
720 udf_write_aext(table
, &goal_epos
, &goal_eloc
, goal_elen
, 1);
722 udf_delete_aext(table
, goal_epos
, goal_eloc
, goal_elen
);
723 brelse(goal_epos
.bh
);
725 udf_add_free_space(sb
, partition
, -1);
727 mutex_unlock(&sbi
->s_alloc_mutex
);
732 void udf_free_blocks(struct super_block
*sb
, struct inode
*inode
,
733 struct kernel_lb_addr
*bloc
, uint32_t offset
,
736 uint16_t partition
= bloc
->partitionReferenceNum
;
737 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
739 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
) {
740 udf_bitmap_free_blocks(sb
, map
->s_uspace
.s_bitmap
,
741 bloc
, offset
, count
);
742 } else if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
) {
743 udf_table_free_blocks(sb
, map
->s_uspace
.s_table
,
744 bloc
, offset
, count
);
745 } else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
) {
746 udf_bitmap_free_blocks(sb
, map
->s_fspace
.s_bitmap
,
747 bloc
, offset
, count
);
748 } else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
) {
749 udf_table_free_blocks(sb
, map
->s_fspace
.s_table
,
750 bloc
, offset
, count
);
754 inode_sub_bytes(inode
,
755 ((sector_t
)count
) << sb
->s_blocksize_bits
);
759 inline int udf_prealloc_blocks(struct super_block
*sb
,
761 uint16_t partition
, uint32_t first_block
,
762 uint32_t block_count
)
764 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
767 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
768 allocated
= udf_bitmap_prealloc_blocks(sb
,
769 map
->s_uspace
.s_bitmap
,
770 partition
, first_block
,
772 else if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
773 allocated
= udf_table_prealloc_blocks(sb
,
774 map
->s_uspace
.s_table
,
775 partition
, first_block
,
777 else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
778 allocated
= udf_bitmap_prealloc_blocks(sb
,
779 map
->s_fspace
.s_bitmap
,
780 partition
, first_block
,
782 else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
783 allocated
= udf_table_prealloc_blocks(sb
,
784 map
->s_fspace
.s_table
,
785 partition
, first_block
,
790 if (inode
&& allocated
> 0)
791 inode_add_bytes(inode
, allocated
<< sb
->s_blocksize_bits
);
795 inline int udf_new_block(struct super_block
*sb
,
797 uint16_t partition
, uint32_t goal
, int *err
)
799 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
802 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
803 block
= udf_bitmap_new_block(sb
,
804 map
->s_uspace
.s_bitmap
,
805 partition
, goal
, err
);
806 else if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
807 block
= udf_table_new_block(sb
,
808 map
->s_uspace
.s_table
,
809 partition
, goal
, err
);
810 else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
811 block
= udf_bitmap_new_block(sb
,
812 map
->s_fspace
.s_bitmap
,
813 partition
, goal
, err
);
814 else if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
815 block
= udf_table_new_block(sb
,
816 map
->s_fspace
.s_table
,
817 partition
, goal
, err
);
823 inode_add_bytes(inode
, sb
->s_blocksize
);