2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* balloc.c
|
|
|
|
*
|
|
|
|
* PURPOSE
|
|
|
|
* Block allocation handling routines for the OSTA-UDF(tm) filesystem.
|
|
|
|
*
|
|
|
|
* COPYRIGHT
|
|
|
|
* This file is distributed under the terms of the GNU General Public
|
|
|
|
* License (GPL). Copies of the GPL can be obtained from:
|
|
|
|
* ftp://prep.ai.mit.edu/pub/gnu/GPL
|
|
|
|
* Each contributing author retains all rights to their own work.
|
|
|
|
*
|
|
|
|
* (C) 1999-2001 Ben Fennema
|
|
|
|
* (C) 1999 Stelias Computing Inc
|
|
|
|
*
|
|
|
|
* HISTORY
|
|
|
|
*
|
|
|
|
* 02/24/99 blf Created.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "udfdecl.h"
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
|
|
|
|
#include "udf_i.h"
|
|
|
|
#include "udf_sb.h"
|
|
|
|
|
2011-03-23 23:42:11 +00:00
|
|
|
#define udf_clear_bit __test_and_clear_bit_le
|
|
|
|
#define udf_set_bit __test_and_set_bit_le
|
|
|
|
#define udf_test_bit test_bit_le
|
|
|
|
#define udf_find_next_one_bit find_next_bit_le
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
static int read_block_bitmap(struct super_block *sb,
|
|
|
|
struct udf_bitmap *bitmap, unsigned int block,
|
|
|
|
unsigned long bitmap_nr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct buffer_head *bh = NULL;
|
2023-02-02 14:04:56 +00:00
|
|
|
int i;
|
|
|
|
int max_bits, off, count;
|
2008-10-15 10:28:03 +00:00
|
|
|
struct kernel_lb_addr loc;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
loc.logicalBlockNum = bitmap->s_extPosition;
|
2008-02-08 12:20:30 +00:00
|
|
|
loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2023-01-18 12:27:07 +00:00
|
|
|
bh = sb_bread(sb, udf_get_lb_pblock(sb, &loc, block));
|
2023-02-02 14:04:56 +00:00
|
|
|
bitmap->s_block_bitmap[bitmap_nr] = bh;
|
2008-02-08 12:20:36 +00:00
|
|
|
if (!bh)
|
2023-02-02 14:04:56 +00:00
|
|
|
return -EIO;
|
2008-02-08 12:20:36 +00:00
|
|
|
|
2023-02-02 14:04:56 +00:00
|
|
|
/* Check consistency of Space Bitmap buffer. */
|
|
|
|
max_bits = sb->s_blocksize * 8;
|
|
|
|
if (!bitmap_nr) {
|
|
|
|
off = sizeof(struct spaceBitmapDesc) << 3;
|
|
|
|
count = min(max_bits - off, bitmap->s_nr_groups);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Rough check if bitmap number is too big to have any bitmap
|
|
|
|
* blocks reserved.
|
|
|
|
*/
|
|
|
|
if (bitmap_nr >
|
|
|
|
(bitmap->s_nr_groups >> (sb->s_blocksize_bits + 3)) + 2)
|
|
|
|
return 0;
|
|
|
|
off = 0;
|
|
|
|
count = bitmap->s_nr_groups - bitmap_nr * max_bits +
|
|
|
|
(sizeof(struct spaceBitmapDesc) << 3);
|
|
|
|
count = min(count, max_bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if (udf_test_bit(i + off, bh->b_data))
|
|
|
|
return -EFSCORRUPTED;
|
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
static int __load_block_bitmap(struct super_block *sb,
|
|
|
|
struct udf_bitmap *bitmap,
|
|
|
|
unsigned int block_group)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
int nr_groups = bitmap->s_nr_groups;
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if (block_group >= nr_groups) {
|
2017-10-12 13:48:41 +00:00
|
|
|
udf_debug("block_group (%u) > nr_groups (%d)\n",
|
2011-10-10 08:08:07 +00:00
|
|
|
block_group, nr_groups);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 20:44:33 +00:00
|
|
|
if (bitmap->s_block_bitmap[block_group])
|
2005-04-16 22:20:36 +00:00
|
|
|
return block_group;
|
2015-03-10 20:44:33 +00:00
|
|
|
|
|
|
|
retval = read_block_bitmap(sb, bitmap, block_group, block_group);
|
|
|
|
if (retval < 0)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
return block_group;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
static inline int load_block_bitmap(struct super_block *sb,
|
|
|
|
struct udf_bitmap *bitmap,
|
|
|
|
unsigned int block_group)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int slot;
|
|
|
|
|
|
|
|
slot = __load_block_bitmap(sb, bitmap, block_group);
|
|
|
|
|
|
|
|
if (slot < 0)
|
|
|
|
return slot;
|
|
|
|
|
|
|
|
if (!bitmap->s_block_bitmap[slot])
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
2009-03-16 17:27:37 +00:00
|
|
|
static void udf_add_free_space(struct super_block *sb, u16 partition, u32 cnt)
|
2008-02-08 12:20:40 +00:00
|
|
|
{
|
2009-03-16 17:27:37 +00:00
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
2008-02-08 12:20:40 +00:00
|
|
|
struct logicalVolIntegrityDesc *lvid;
|
|
|
|
|
2009-03-16 17:27:37 +00:00
|
|
|
if (!sbi->s_lvid_bh)
|
|
|
|
return;
|
2008-02-08 12:20:40 +00:00
|
|
|
|
|
|
|
lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
|
2008-01-30 21:03:57 +00:00
|
|
|
le32_add_cpu(&lvid->freeSpaceTable[partition], cnt);
|
2009-03-16 17:27:37 +00:00
|
|
|
udf_updated_lvid(sb);
|
2008-02-08 12:20:40 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
static void udf_bitmap_free_blocks(struct super_block *sb,
|
|
|
|
struct udf_bitmap *bitmap,
|
2008-10-15 10:29:03 +00:00
|
|
|
struct kernel_lb_addr *bloc,
|
|
|
|
uint32_t offset,
|
2007-07-19 08:47:43 +00:00
|
|
|
uint32_t count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
2007-07-19 08:47:43 +00:00
|
|
|
struct buffer_head *bh = NULL;
|
2008-10-15 10:29:03 +00:00
|
|
|
struct udf_part_map *partmap;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long block;
|
|
|
|
unsigned long block_group;
|
|
|
|
unsigned long bit;
|
|
|
|
unsigned long i;
|
|
|
|
int bitmap_nr;
|
|
|
|
unsigned long overflow;
|
|
|
|
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_lock(&sbi->s_alloc_mutex);
|
2008-10-15 10:29:03 +00:00
|
|
|
partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
|
2010-03-15 08:21:13 +00:00
|
|
|
if (bloc->logicalBlockNum + count < count ||
|
|
|
|
(bloc->logicalBlockNum + count) > partmap->s_partition_len) {
|
2017-10-12 13:48:41 +00:00
|
|
|
udf_debug("%u < %d || %u + %u > %u\n",
|
2011-10-10 08:08:07 +00:00
|
|
|
bloc->logicalBlockNum, 0,
|
|
|
|
bloc->logicalBlockNum, count,
|
|
|
|
partmap->s_partition_len);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
2008-10-15 10:29:03 +00:00
|
|
|
block = bloc->logicalBlockNum + offset +
|
2008-02-08 12:20:36 +00:00
|
|
|
(sizeof(struct spaceBitmapDesc) << 3);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:20:41 +00:00
|
|
|
do {
|
|
|
|
overflow = 0;
|
|
|
|
block_group = block >> (sb->s_blocksize_bits + 3);
|
|
|
|
bit = block % (sb->s_blocksize << 3);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if we are freeing blocks across a group boundary.
|
|
|
|
*/
|
|
|
|
if (bit + count > (sb->s_blocksize << 3)) {
|
|
|
|
overflow = bit + count - (sb->s_blocksize << 3);
|
|
|
|
count -= overflow;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-02-08 12:20:41 +00:00
|
|
|
bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
|
|
|
|
if (bitmap_nr < 0)
|
|
|
|
goto error_return;
|
|
|
|
|
|
|
|
bh = bitmap->s_block_bitmap[bitmap_nr];
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (udf_set_bit(bit + i, bh->b_data)) {
|
2017-10-12 13:48:41 +00:00
|
|
|
udf_debug("bit %lu already set\n", bit + i);
|
2008-02-08 12:20:41 +00:00
|
|
|
udf_debug("byte=%2x\n",
|
2017-10-12 13:48:41 +00:00
|
|
|
((__u8 *)bh->b_data)[(bit + i) >> 3]);
|
2008-02-08 12:20:41 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-20 20:32:02 +00:00
|
|
|
udf_add_free_space(sb, sbi->s_partition, count);
|
2008-02-08 12:20:41 +00:00
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
if (overflow) {
|
|
|
|
block += count;
|
|
|
|
count = overflow;
|
|
|
|
}
|
|
|
|
} while (overflow);
|
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
error_return:
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
static int udf_bitmap_prealloc_blocks(struct super_block *sb,
|
|
|
|
struct udf_bitmap *bitmap,
|
|
|
|
uint16_t partition, uint32_t first_block,
|
|
|
|
uint32_t block_count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
|
|
|
int alloc_count = 0;
|
2018-08-29 10:16:12 +00:00
|
|
|
int bit, block, block_group;
|
|
|
|
int bitmap_nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct buffer_head *bh;
|
2008-02-08 12:20:30 +00:00
|
|
|
__u32 part_len;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_lock(&sbi->s_alloc_mutex);
|
2008-02-08 12:20:30 +00:00
|
|
|
part_len = sbi->s_partmaps[partition].s_partition_len;
|
2009-06-22 21:12:29 +00:00
|
|
|
if (first_block >= part_len)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
|
2008-02-08 12:20:30 +00:00
|
|
|
if (first_block + block_count > part_len)
|
|
|
|
block_count = part_len - first_block;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:20:41 +00:00
|
|
|
do {
|
|
|
|
block = first_block + (sizeof(struct spaceBitmapDesc) << 3);
|
|
|
|
block_group = block >> (sb->s_blocksize_bits + 3);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:20:41 +00:00
|
|
|
bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
|
|
|
|
if (bitmap_nr < 0)
|
|
|
|
goto out;
|
|
|
|
bh = bitmap->s_block_bitmap[bitmap_nr];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:20:41 +00:00
|
|
|
bit = block % (sb->s_blocksize << 3);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:20:41 +00:00
|
|
|
while (bit < (sb->s_blocksize << 3) && block_count > 0) {
|
2010-05-19 14:28:56 +00:00
|
|
|
if (!udf_clear_bit(bit, bh->b_data))
|
2008-02-08 12:20:41 +00:00
|
|
|
goto out;
|
|
|
|
block_count--;
|
|
|
|
alloc_count++;
|
|
|
|
bit++;
|
|
|
|
block++;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-02-08 12:20:41 +00:00
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
} while (block_count > 0);
|
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
out:
|
2009-03-16 17:27:37 +00:00
|
|
|
udf_add_free_space(sb, partition, -alloc_count);
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return alloc_count;
|
|
|
|
}
|
|
|
|
|
2017-10-12 13:48:40 +00:00
|
|
|
static udf_pblk_t udf_bitmap_new_block(struct super_block *sb,
|
2007-07-19 08:47:43 +00:00
|
|
|
struct udf_bitmap *bitmap, uint16_t partition,
|
|
|
|
uint32_t goal, int *err)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
2017-10-12 13:48:40 +00:00
|
|
|
int newbit, bit = 0;
|
|
|
|
udf_pblk_t block;
|
|
|
|
int block_group, group_start;
|
2005-04-16 22:20:36 +00:00
|
|
|
int end_goal, nr_groups, bitmap_nr, i;
|
|
|
|
struct buffer_head *bh = NULL;
|
|
|
|
char *ptr;
|
2017-10-12 13:48:40 +00:00
|
|
|
udf_pblk_t newblock = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
*err = -ENOSPC;
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_lock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
repeat:
|
2009-06-22 21:12:29 +00:00
|
|
|
if (goal >= sbi->s_partmaps[partition].s_partition_len)
|
2005-04-16 22:20:36 +00:00
|
|
|
goal = 0;
|
|
|
|
|
|
|
|
nr_groups = bitmap->s_nr_groups;
|
|
|
|
block = goal + (sizeof(struct spaceBitmapDesc) << 3);
|
|
|
|
block_group = block >> (sb->s_blocksize_bits + 3);
|
|
|
|
group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
|
|
|
|
|
|
|
|
bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
|
|
|
|
if (bitmap_nr < 0)
|
|
|
|
goto error_return;
|
|
|
|
bh = bitmap->s_block_bitmap[bitmap_nr];
|
2007-07-21 11:37:18 +00:00
|
|
|
ptr = memscan((char *)bh->b_data + group_start, 0xFF,
|
|
|
|
sb->s_blocksize - group_start);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) {
|
2005-04-16 22:20:36 +00:00
|
|
|
bit = block % (sb->s_blocksize << 3);
|
2007-07-21 11:37:18 +00:00
|
|
|
if (udf_test_bit(bit, bh->b_data))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto got_block;
|
2007-07-21 11:37:18 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
end_goal = (bit + 63) & ~63;
|
|
|
|
bit = udf_find_next_one_bit(bh->b_data, end_goal, bit);
|
|
|
|
if (bit < end_goal)
|
|
|
|
goto got_block;
|
2007-07-21 11:37:18 +00:00
|
|
|
|
2008-02-08 12:20:36 +00:00
|
|
|
ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF,
|
|
|
|
sb->s_blocksize - ((bit + 7) >> 3));
|
2005-04-16 22:20:36 +00:00
|
|
|
newbit = (ptr - ((char *)bh->b_data)) << 3;
|
2007-07-19 08:47:43 +00:00
|
|
|
if (newbit < sb->s_blocksize << 3) {
|
2005-04-16 22:20:36 +00:00
|
|
|
bit = newbit;
|
|
|
|
goto search_back;
|
|
|
|
}
|
2007-07-21 11:37:18 +00:00
|
|
|
|
2008-02-08 12:20:36 +00:00
|
|
|
newbit = udf_find_next_one_bit(bh->b_data,
|
|
|
|
sb->s_blocksize << 3, bit);
|
2007-07-19 08:47:43 +00:00
|
|
|
if (newbit < sb->s_blocksize << 3) {
|
2005-04-16 22:20:36 +00:00
|
|
|
bit = newbit;
|
|
|
|
goto got_block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
for (i = 0; i < (nr_groups * 2); i++) {
|
|
|
|
block_group++;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (block_group >= nr_groups)
|
|
|
|
block_group = 0;
|
|
|
|
group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
|
|
|
|
|
|
|
|
bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
|
|
|
|
if (bitmap_nr < 0)
|
|
|
|
goto error_return;
|
|
|
|
bh = bitmap->s_block_bitmap[bitmap_nr];
|
2007-07-19 08:47:43 +00:00
|
|
|
if (i < nr_groups) {
|
2007-07-21 11:37:18 +00:00
|
|
|
ptr = memscan((char *)bh->b_data + group_start, 0xFF,
|
|
|
|
sb->s_blocksize - group_start);
|
2007-07-19 08:47:43 +00:00
|
|
|
if ((ptr - ((char *)bh->b_data)) < sb->s_blocksize) {
|
2005-04-16 22:20:36 +00:00
|
|
|
bit = (ptr - ((char *)bh->b_data)) << 3;
|
|
|
|
break;
|
|
|
|
}
|
2007-07-19 08:47:43 +00:00
|
|
|
} else {
|
2011-02-22 19:04:19 +00:00
|
|
|
bit = udf_find_next_one_bit(bh->b_data,
|
2007-07-21 11:37:18 +00:00
|
|
|
sb->s_blocksize << 3,
|
|
|
|
group_start << 3);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (bit < sb->s_blocksize << 3)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 08:47:43 +00:00
|
|
|
if (i >= (nr_groups * 2)) {
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return newblock;
|
|
|
|
}
|
|
|
|
if (bit < sb->s_blocksize << 3)
|
|
|
|
goto search_back;
|
|
|
|
else
|
2008-02-08 12:20:36 +00:00
|
|
|
bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3,
|
|
|
|
group_start << 3);
|
2007-07-19 08:47:43 +00:00
|
|
|
if (bit >= sb->s_blocksize << 3) {
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
search_back:
|
2008-02-08 12:20:36 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < 7 && bit > (group_start << 3) &&
|
|
|
|
udf_test_bit(bit - 1, bh->b_data)) {
|
|
|
|
++i;
|
|
|
|
--bit;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
got_block:
|
2005-04-16 22:20:36 +00:00
|
|
|
newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
|
2007-07-21 11:37:18 +00:00
|
|
|
(sizeof(struct spaceBitmapDesc) << 3);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2019-07-28 19:19:12 +00:00
|
|
|
if (newblock >= sbi->s_partmaps[partition].s_partition_len) {
|
|
|
|
/*
|
|
|
|
* Ran off the end of the bitmap, and bits following are
|
|
|
|
* non-compliant (not all zero)
|
|
|
|
*/
|
|
|
|
udf_err(sb, "bitmap for partition %d corrupted (block %u marked"
|
|
|
|
" as free, partition length is %u)\n", partition,
|
|
|
|
newblock, sbi->s_partmaps[partition].s_partition_len);
|
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if (!udf_clear_bit(bit, bh->b_data)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
udf_debug("bit already cleared for block %d\n", bit);
|
|
|
|
goto repeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
mark_buffer_dirty(bh);
|
|
|
|
|
2009-03-16 17:27:37 +00:00
|
|
|
udf_add_free_space(sb, partition, -1);
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
*err = 0;
|
|
|
|
return newblock;
|
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
error_return:
|
2005-04-16 22:20:36 +00:00
|
|
|
*err = -EIO;
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
static void udf_table_free_blocks(struct super_block *sb,
|
|
|
|
struct inode *table,
|
2008-10-15 10:29:03 +00:00
|
|
|
struct kernel_lb_addr *bloc,
|
|
|
|
uint32_t offset,
|
2007-07-19 08:47:43 +00:00
|
|
|
uint32_t count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
2008-10-15 10:29:03 +00:00
|
|
|
struct udf_part_map *partmap;
|
2005-04-16 22:20:36 +00:00
|
|
|
uint32_t start, end;
|
2007-05-08 07:35:14 +00:00
|
|
|
uint32_t elen;
|
2008-10-15 10:28:03 +00:00
|
|
|
struct kernel_lb_addr eloc;
|
2007-05-08 07:35:14 +00:00
|
|
|
struct extent_position oepos, epos;
|
2005-04-16 22:20:36 +00:00
|
|
|
int8_t etype;
|
2008-02-08 12:20:44 +00:00
|
|
|
struct udf_inode_info *iinfo;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_lock(&sbi->s_alloc_mutex);
|
2008-10-15 10:29:03 +00:00
|
|
|
partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
|
2010-03-15 08:21:13 +00:00
|
|
|
if (bloc->logicalBlockNum + count < count ||
|
|
|
|
(bloc->logicalBlockNum + count) > partmap->s_partition_len) {
|
2017-10-12 13:48:41 +00:00
|
|
|
udf_debug("%u < %d || %u + %u > %u\n",
|
2011-10-10 08:08:07 +00:00
|
|
|
bloc->logicalBlockNum, 0,
|
|
|
|
bloc->logicalBlockNum, count,
|
2008-10-15 10:29:03 +00:00
|
|
|
partmap->s_partition_len);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
2008-02-08 12:20:44 +00:00
|
|
|
iinfo = UDF_I(table);
|
2009-03-16 17:27:37 +00:00
|
|
|
udf_add_free_space(sb, sbi->s_partition, count);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-10-15 10:29:03 +00:00
|
|
|
start = bloc->logicalBlockNum + offset;
|
|
|
|
end = bloc->logicalBlockNum + offset + count - 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-08 07:35:14 +00:00
|
|
|
epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry);
|
2005-04-16 22:20:36 +00:00
|
|
|
elen = 0;
|
2008-02-08 12:20:44 +00:00
|
|
|
epos.block = oepos.block = iinfo->i_location;
|
2007-05-08 07:35:14 +00:00
|
|
|
epos.bh = oepos.bh = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
while (count &&
|
|
|
|
(etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
|
2008-02-08 12:20:36 +00:00
|
|
|
if (((eloc.logicalBlockNum +
|
|
|
|
(elen >> sb->s_blocksize_bits)) == start)) {
|
|
|
|
if ((0x3FFFFFFF - elen) <
|
|
|
|
(count << sb->s_blocksize_bits)) {
|
|
|
|
uint32_t tmp = ((0x3FFFFFFF - elen) >>
|
|
|
|
sb->s_blocksize_bits);
|
|
|
|
count -= tmp;
|
|
|
|
start += tmp;
|
|
|
|
elen = (etype << 30) |
|
|
|
|
(0x40000000 - sb->s_blocksize);
|
2007-07-19 08:47:43 +00:00
|
|
|
} else {
|
2008-02-08 12:20:36 +00:00
|
|
|
elen = (etype << 30) |
|
|
|
|
(elen +
|
|
|
|
(count << sb->s_blocksize_bits));
|
2005-04-16 22:20:36 +00:00
|
|
|
start += count;
|
|
|
|
count = 0;
|
|
|
|
}
|
2008-10-15 10:29:03 +00:00
|
|
|
udf_write_aext(table, &oepos, &eloc, elen, 1);
|
2007-07-19 08:47:43 +00:00
|
|
|
} else if (eloc.logicalBlockNum == (end + 1)) {
|
2008-02-08 12:20:36 +00:00
|
|
|
if ((0x3FFFFFFF - elen) <
|
|
|
|
(count << sb->s_blocksize_bits)) {
|
|
|
|
uint32_t tmp = ((0x3FFFFFFF - elen) >>
|
|
|
|
sb->s_blocksize_bits);
|
|
|
|
count -= tmp;
|
|
|
|
end -= tmp;
|
|
|
|
eloc.logicalBlockNum -= tmp;
|
|
|
|
elen = (etype << 30) |
|
|
|
|
(0x40000000 - sb->s_blocksize);
|
2007-07-19 08:47:43 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
eloc.logicalBlockNum = start;
|
2008-02-08 12:20:36 +00:00
|
|
|
elen = (etype << 30) |
|
|
|
|
(elen +
|
|
|
|
(count << sb->s_blocksize_bits));
|
2005-04-16 22:20:36 +00:00
|
|
|
end -= count;
|
|
|
|
count = 0;
|
|
|
|
}
|
2008-10-15 10:29:03 +00:00
|
|
|
udf_write_aext(table, &oepos, &eloc, elen, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if (epos.bh != oepos.bh) {
|
2007-05-08 07:35:14 +00:00
|
|
|
oepos.block = epos.block;
|
2007-05-08 07:35:16 +00:00
|
|
|
brelse(oepos.bh);
|
|
|
|
get_bh(epos.bh);
|
2007-05-08 07:35:14 +00:00
|
|
|
oepos.bh = epos.bh;
|
|
|
|
oepos.offset = 0;
|
2007-07-21 11:37:18 +00:00
|
|
|
} else {
|
2007-05-08 07:35:14 +00:00
|
|
|
oepos.offset = epos.offset;
|
2007-07-21 11:37:18 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if (count) {
|
2007-07-21 11:37:18 +00:00
|
|
|
/*
|
2008-02-08 12:20:36 +00:00
|
|
|
* NOTE: we CANNOT use udf_add_aext here, as it can try to
|
|
|
|
* allocate a new block, and since we hold the super block
|
|
|
|
* lock already very bad things would happen :)
|
2007-07-21 11:37:18 +00:00
|
|
|
*
|
|
|
|
* We copy the behavior of udf_add_aext, but instead of
|
|
|
|
* trying to allocate a new block close to the existing one,
|
|
|
|
* we just steal a block from the extent we are trying to add.
|
|
|
|
*
|
|
|
|
* It would be nice if the blocks were close together, but it
|
|
|
|
* isn't required.
|
2007-07-19 08:47:43 +00:00
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
int adsize;
|
|
|
|
|
|
|
|
eloc.logicalBlockNum = start;
|
2007-07-21 11:37:18 +00:00
|
|
|
elen = EXT_RECORDED_ALLOCATED |
|
|
|
|
(count << sb->s_blocksize_bits);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:20:44 +00:00
|
|
|
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
|
2008-10-15 10:28:03 +00:00
|
|
|
adsize = sizeof(struct short_ad);
|
2008-02-08 12:20:44 +00:00
|
|
|
else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
|
2008-10-15 10:28:03 +00:00
|
|
|
adsize = sizeof(struct long_ad);
|
2008-02-08 12:20:44 +00:00
|
|
|
else {
|
2007-05-08 07:35:16 +00:00
|
|
|
brelse(oepos.bh);
|
|
|
|
brelse(epos.bh);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if (epos.offset + (2 * adsize) > sb->s_blocksize) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Steal a block from the extent being free'd */
|
2015-12-23 13:21:13 +00:00
|
|
|
udf_setup_indirect_aext(table, eloc.logicalBlockNum,
|
|
|
|
&epos);
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
eloc.logicalBlockNum++;
|
2005-04-16 22:20:36 +00:00
|
|
|
elen -= sb->s_blocksize;
|
|
|
|
}
|
|
|
|
|
2008-02-08 12:20:36 +00:00
|
|
|
/* It's possible that stealing the block emptied the extent */
|
2015-12-23 13:21:13 +00:00
|
|
|
if (elen)
|
|
|
|
__udf_add_aext(table, &epos, &eloc, elen, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-08 07:35:16 +00:00
|
|
|
brelse(epos.bh);
|
|
|
|
brelse(oepos.bh);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
error_return:
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
static int udf_table_prealloc_blocks(struct super_block *sb,
|
|
|
|
struct inode *table, uint16_t partition,
|
|
|
|
uint32_t first_block, uint32_t block_count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
|
|
|
int alloc_count = 0;
|
2007-05-08 07:35:14 +00:00
|
|
|
uint32_t elen, adsize;
|
2008-10-15 10:28:03 +00:00
|
|
|
struct kernel_lb_addr eloc;
|
2007-05-08 07:35:14 +00:00
|
|
|
struct extent_position epos;
|
2005-04-16 22:20:36 +00:00
|
|
|
int8_t etype = -1;
|
2008-02-08 12:20:44 +00:00
|
|
|
struct udf_inode_info *iinfo;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-06-22 21:12:29 +00:00
|
|
|
if (first_block >= sbi->s_partmaps[partition].s_partition_len)
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-02-08 12:20:44 +00:00
|
|
|
iinfo = UDF_I(table);
|
|
|
|
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
|
2008-10-15 10:28:03 +00:00
|
|
|
adsize = sizeof(struct short_ad);
|
2008-02-08 12:20:44 +00:00
|
|
|
else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
|
2008-10-15 10:28:03 +00:00
|
|
|
adsize = sizeof(struct long_ad);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_lock(&sbi->s_alloc_mutex);
|
2007-05-08 07:35:14 +00:00
|
|
|
epos.offset = sizeof(struct unallocSpaceEntry);
|
2008-02-08 12:20:44 +00:00
|
|
|
epos.block = iinfo->i_location;
|
2007-05-08 07:35:14 +00:00
|
|
|
epos.bh = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
eloc.logicalBlockNum = 0xFFFFFFFF;
|
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
while (first_block != eloc.logicalBlockNum &&
|
|
|
|
(etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
|
2017-10-12 13:48:41 +00:00
|
|
|
udf_debug("eloc=%u, elen=%u, first_block=%u\n",
|
2007-07-19 08:47:43 +00:00
|
|
|
eloc.logicalBlockNum, elen, first_block);
|
2007-07-21 11:37:18 +00:00
|
|
|
; /* empty loop body */
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if (first_block == eloc.logicalBlockNum) {
|
2007-05-08 07:35:14 +00:00
|
|
|
epos.offset -= adsize;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
alloc_count = (elen >> sb->s_blocksize_bits);
|
2010-05-19 14:28:56 +00:00
|
|
|
if (alloc_count > block_count) {
|
2005-04-16 22:20:36 +00:00
|
|
|
alloc_count = block_count;
|
|
|
|
eloc.logicalBlockNum += alloc_count;
|
|
|
|
elen -= (alloc_count << sb->s_blocksize_bits);
|
2008-10-15 10:29:03 +00:00
|
|
|
udf_write_aext(table, &epos, &eloc,
|
2008-02-08 12:20:36 +00:00
|
|
|
(etype << 30) | elen, 1);
|
|
|
|
} else
|
2018-06-13 16:04:24 +00:00
|
|
|
udf_delete_aext(table, epos);
|
2007-07-21 11:37:18 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
alloc_count = 0;
|
2007-07-21 11:37:18 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-08 07:35:16 +00:00
|
|
|
brelse(epos.bh);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-16 17:27:37 +00:00
|
|
|
if (alloc_count)
|
|
|
|
udf_add_free_space(sb, partition, -alloc_count);
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return alloc_count;
|
|
|
|
}
|
|
|
|
|
2017-10-12 13:48:40 +00:00
|
|
|
static udf_pblk_t udf_table_new_block(struct super_block *sb,
|
2007-07-19 08:47:43 +00:00
|
|
|
struct inode *table, uint16_t partition,
|
|
|
|
uint32_t goal, int *err)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct udf_sb_info *sbi = UDF_SB(sb);
|
|
|
|
uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF;
|
2017-10-12 13:48:40 +00:00
|
|
|
udf_pblk_t newblock = 0;
|
|
|
|
uint32_t adsize;
|
2007-05-08 07:35:14 +00:00
|
|
|
uint32_t elen, goal_elen = 0;
|
treewide: Remove uninitialized_var() usage
Using uninitialized_var() is dangerous as it papers over real bugs[1]
(or can in the future), and suppresses unrelated compiler warnings
(e.g. "unused variable"). If the compiler thinks it is uninitialized,
either simply initialize the variable or make compiler changes.
In preparation for removing[2] the[3] macro[4], remove all remaining
needless uses with the following script:
git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
xargs perl -pi -e \
's/\buninitialized_var\(([^\)]+)\)/\1/g;
s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'
drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
pathological white-space.
No outstanding warnings were found building allmodconfig with GCC 9.3.0
for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
alpha, and m68k.
[1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
[2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
[3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/
Reviewed-by: Leon Romanovsky <leonro@mellanox.com> # drivers/infiniband and mlx4/mlx5
Acked-by: Jason Gunthorpe <jgg@mellanox.com> # IB
Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless drivers
Reviewed-by: Chao Yu <yuchao0@huawei.com> # erofs
Signed-off-by: Kees Cook <keescook@chromium.org>
2020-06-03 20:09:38 +00:00
|
|
|
struct kernel_lb_addr eloc, goal_eloc;
|
2007-05-08 07:35:14 +00:00
|
|
|
struct extent_position epos, goal_epos;
|
2005-04-16 22:20:36 +00:00
|
|
|
int8_t etype;
|
2008-02-08 12:20:44 +00:00
|
|
|
struct udf_inode_info *iinfo = UDF_I(table);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
*err = -ENOSPC;
|
|
|
|
|
2008-02-08 12:20:44 +00:00
|
|
|
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
|
2008-10-15 10:28:03 +00:00
|
|
|
adsize = sizeof(struct short_ad);
|
2008-02-08 12:20:44 +00:00
|
|
|
else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
|
2008-10-15 10:28:03 +00:00
|
|
|
adsize = sizeof(struct long_ad);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
|
|
|
return newblock;
|
|
|
|
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_lock(&sbi->s_alloc_mutex);
|
2009-06-22 21:12:29 +00:00
|
|
|
if (goal >= sbi->s_partmaps[partition].s_partition_len)
|
2005-04-16 22:20:36 +00:00
|
|
|
goal = 0;
|
|
|
|
|
2008-02-08 12:20:36 +00:00
|
|
|
/* We search for the closest matching block to goal. If we find
|
|
|
|
a exact hit, we stop. Otherwise we keep going till we run out
|
|
|
|
of extents. We store the buffer_head, bloc, and extoffset
|
|
|
|
of the current closest match and use that when we are done.
|
2007-07-19 08:47:43 +00:00
|
|
|
*/
|
2007-05-08 07:35:14 +00:00
|
|
|
epos.offset = sizeof(struct unallocSpaceEntry);
|
2008-02-08 12:20:44 +00:00
|
|
|
epos.block = iinfo->i_location;
|
2007-05-08 07:35:14 +00:00
|
|
|
epos.bh = goal_epos.bh = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-21 11:37:18 +00:00
|
|
|
while (spread &&
|
|
|
|
(etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
|
2007-07-19 08:47:43 +00:00
|
|
|
if (goal >= eloc.logicalBlockNum) {
|
2008-02-08 12:20:36 +00:00
|
|
|
if (goal < eloc.logicalBlockNum +
|
|
|
|
(elen >> sb->s_blocksize_bits))
|
2005-04-16 22:20:36 +00:00
|
|
|
nspread = 0;
|
|
|
|
else
|
|
|
|
nspread = goal - eloc.logicalBlockNum -
|
2007-07-21 11:37:18 +00:00
|
|
|
(elen >> sb->s_blocksize_bits);
|
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
nspread = eloc.logicalBlockNum - goal;
|
2007-07-21 11:37:18 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if (nspread < spread) {
|
2005-04-16 22:20:36 +00:00
|
|
|
spread = nspread;
|
2007-07-19 08:47:43 +00:00
|
|
|
if (goal_epos.bh != epos.bh) {
|
2007-05-08 07:35:16 +00:00
|
|
|
brelse(goal_epos.bh);
|
2007-05-08 07:35:14 +00:00
|
|
|
goal_epos.bh = epos.bh;
|
2007-05-08 07:35:16 +00:00
|
|
|
get_bh(goal_epos.bh);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-05-08 07:35:14 +00:00
|
|
|
goal_epos.block = epos.block;
|
|
|
|
goal_epos.offset = epos.offset - adsize;
|
2005-04-16 22:20:36 +00:00
|
|
|
goal_eloc = eloc;
|
|
|
|
goal_elen = (etype << 30) | elen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-08 07:35:16 +00:00
|
|
|
brelse(epos.bh);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
if (spread == 0xFFFFFFFF) {
|
2007-05-08 07:35:16 +00:00
|
|
|
brelse(goal_epos.bh);
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only allocate blocks from the beginning of the extent.
|
|
|
|
That way, we only delete (empty) extents, never have to insert an
|
|
|
|
extent because of splitting */
|
|
|
|
/* This works, but very poorly.... */
|
|
|
|
|
|
|
|
newblock = goal_eloc.logicalBlockNum;
|
2007-07-19 08:47:43 +00:00
|
|
|
goal_eloc.logicalBlockNum++;
|
2005-04-16 22:20:36 +00:00
|
|
|
goal_elen -= sb->s_blocksize;
|
|
|
|
|
|
|
|
if (goal_elen)
|
2008-10-15 10:29:03 +00:00
|
|
|
udf_write_aext(table, &goal_epos, &goal_eloc, goal_elen, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2018-06-13 16:04:24 +00:00
|
|
|
udf_delete_aext(table, goal_epos);
|
2007-05-08 07:35:16 +00:00
|
|
|
brelse(goal_epos.bh);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-16 17:27:37 +00:00
|
|
|
udf_add_free_space(sb, partition, -1);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-23 11:00:44 +00:00
|
|
|
mutex_unlock(&sbi->s_alloc_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
*err = 0;
|
|
|
|
return newblock;
|
|
|
|
}
|
|
|
|
|
2008-10-15 10:29:03 +00:00
|
|
|
void udf_free_blocks(struct super_block *sb, struct inode *inode,
|
|
|
|
struct kernel_lb_addr *bloc, uint32_t offset,
|
|
|
|
uint32_t count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-10-15 10:29:03 +00:00
|
|
|
uint16_t partition = bloc->partitionReferenceNum;
|
2008-02-08 12:20:30 +00:00
|
|
|
struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-08 12:20:30 +00:00
|
|
|
if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
|
2012-02-16 12:00:14 +00:00
|
|
|
udf_bitmap_free_blocks(sb, map->s_uspace.s_bitmap,
|
2008-12-01 12:06:10 +00:00
|
|
|
bloc, offset, count);
|
2008-02-08 12:20:30 +00:00
|
|
|
} else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
|
2012-02-16 12:00:14 +00:00
|
|
|
udf_table_free_blocks(sb, map->s_uspace.s_table,
|
2008-12-01 12:06:10 +00:00
|
|
|
bloc, offset, count);
|
2007-07-21 11:37:18 +00:00
|
|
|
}
|
2012-02-16 12:00:14 +00:00
|
|
|
|
|
|
|
if (inode) {
|
|
|
|
inode_sub_bytes(inode,
|
|
|
|
((sector_t)count) << sb->s_blocksize_bits);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
inline int udf_prealloc_blocks(struct super_block *sb,
|
|
|
|
struct inode *inode,
|
|
|
|
uint16_t partition, uint32_t first_block,
|
|
|
|
uint32_t block_count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-08 12:20:30 +00:00
|
|
|
struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
|
2015-03-15 09:54:23 +00:00
|
|
|
int allocated;
|
2008-02-08 12:20:30 +00:00
|
|
|
|
2008-02-08 12:20:36 +00:00
|
|
|
if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
|
2012-02-16 12:00:14 +00:00
|
|
|
allocated = udf_bitmap_prealloc_blocks(sb,
|
|
|
|
map->s_uspace.s_bitmap,
|
|
|
|
partition, first_block,
|
|
|
|
block_count);
|
2008-02-08 12:20:36 +00:00
|
|
|
else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
|
2012-02-16 12:00:14 +00:00
|
|
|
allocated = udf_table_prealloc_blocks(sb,
|
|
|
|
map->s_uspace.s_table,
|
|
|
|
partition, first_block,
|
|
|
|
block_count);
|
2008-02-08 12:20:36 +00:00
|
|
|
else
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
2012-02-16 12:00:14 +00:00
|
|
|
|
|
|
|
if (inode && allocated > 0)
|
|
|
|
inode_add_bytes(inode, allocated << sb->s_blocksize_bits);
|
|
|
|
return allocated;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 13:48:40 +00:00
|
|
|
inline udf_pblk_t udf_new_block(struct super_block *sb,
|
2007-07-19 08:47:43 +00:00
|
|
|
struct inode *inode,
|
|
|
|
uint16_t partition, uint32_t goal, int *err)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-02-08 12:20:30 +00:00
|
|
|
struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
|
2017-10-12 13:48:40 +00:00
|
|
|
udf_pblk_t block;
|
2007-05-08 07:35:16 +00:00
|
|
|
|
2008-02-08 12:20:36 +00:00
|
|
|
if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
|
2012-02-16 12:00:14 +00:00
|
|
|
block = udf_bitmap_new_block(sb,
|
|
|
|
map->s_uspace.s_bitmap,
|
|
|
|
partition, goal, err);
|
2008-02-08 12:20:36 +00:00
|
|
|
else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
|
2012-02-16 12:00:14 +00:00
|
|
|
block = udf_table_new_block(sb,
|
|
|
|
map->s_uspace.s_table,
|
2007-07-21 11:37:18 +00:00
|
|
|
partition, goal, err);
|
2008-02-08 12:20:36 +00:00
|
|
|
else {
|
2005-04-16 22:20:36 +00:00
|
|
|
*err = -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-16 12:00:14 +00:00
|
|
|
if (inode && block)
|
|
|
|
inode_add_bytes(inode, sb->s_blocksize);
|
|
|
|
return block;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|