示例#1
0
void
copy_incore_to_ondisk(struct inode *inode, struct ufs2_dinode *dinop)
{
	inode->i_blocks = calc_num_blocks(inode);
	dinop->di_nlink = inode->i_effnlink;
	dinop->di_mode = inode->i_mode;
	dinop->di_nlink = inode->i_nlink;
	dinop->di_size = inode->i_size;
	dinop->di_flags = inode->i_flags;
	dinop->di_gen = inode->i_gen;
	dinop->di_uid = inode->i_uid;
	dinop->di_gid = inode->i_gid;
	dinop->di_blocks = inode->i_blocks;
	dinop->di_atime = inode->i_atime;
	dinop->di_mtime = inode->i_mtime;
	dinop->di_ctime = inode->i_ctime;
}
// Constructor
// @param p_chunk - pointer to chunk of allocated memory - it will be soft copied!
// @param b_owned - true if chunk is now owned by this array (it will be freed upon this array's destruction)
// @param num_bits - the size of each bit field within the array
// @param num_elements - number of addressable bit sets
// @param num_initial_reserved_pool_elements - the number of contiguous elements to reserve - must be power of 2
PkPooledRawBitSetArray::PkPooledRawBitSetArray(
	  buffer_type p_chunk
	, const bool b_owned
	, const size_type num_bits
	, const size_type num_elements
	, const size_type num_initial_reserved_pool_elements
	) : m_num_bits( num_bits )
	  , m_num_blocks( calc_num_blocks( num_bits ) )
	  , m_size( num_elements )
	  // Initialize memory pool
	  , mp_pool_alloc( get_allocated_pool( num_bits, num_initial_reserved_pool_elements ) )
{
	// Assert allocator is non-null
	PkAssert( mp_pool_alloc );
	// Assert number of bits is positive
	PkAssert( 0 < m_num_bits );
	// Append chunk
	append_chunk( (byte_type*) p_chunk, num_total_bytes(), b_owned );
}
// Constructor
// @param num_bits - the size of each bit field within the array
// @param num_elements - number of addressable bit sets
// @param num_initial_reserved_pool_elements - the number of contiguous elements to reserve - must be power of 2
PkPooledRawBitSetArray::PkPooledRawBitSetArray(
	  const size_type num_bits
	, const size_type num_elements
	, const size_type num_initial_reserved_pool_elements
	) : m_num_bits( num_bits )
	  , m_num_blocks( calc_num_blocks( num_bits ) )
	  , m_size( 0 )
	  // Initialize memory pool
	  , mp_pool_alloc( get_allocated_pool( num_bits, num_initial_reserved_pool_elements ) )
{
	// Assert allocator is non-null
	PkAssert( mp_pool_alloc );
	// Assert number of bits is positive
	PkAssert( 0 < num_bits );
	// Allocate bit buffers
	for ( size_t i=0; i<num_elements; ++i )
	{
		PkVerify( NULL != allocate_zeroed_bit_buffer() );
	}
}
// Re-initializes a constructed array to the following parameters (wipes any stored bit sets)
// @param p_chunk - pointer to chunk of allocated memory - it will be soft copied!
// @param b_owned - true if chunk is now owned by this array (it will be freed upon this array's destruction)
// @param num_bits - the size of each bit field within the array
// @param num_elements - number of addressable bit sets
// @param num_initial_reserved_pool_elements - the number of contiguous elements to reserve - must be power of 2
void PkPooledRawBitSetArray::reinit(
	  buffer_type p_chunk
	, const bool b_owned
	, const size_type num_bits
	, const size_type num_elements
	, const size_type num_initial_reserved_pool_elements
	)
{
	// Wipe everything!
	clear();
	// Store number of bits
	force_set_num_bits( num_bits );
	// Assert number of bits is positive
	PkAssert( 0 < m_num_bits );
	// Determine number of blocks
	force_set_num_blocks( calc_num_blocks( num_bits ) );
	// Allocate a new memory pool
	PkVerify( mp_pool_alloc = get_allocated_pool( num_bits, num_initial_reserved_pool_elements ) );
	// Update our size
	m_size = num_elements;
	// Append chunk
	append_chunk( (byte_type*) p_chunk, num_total_bytes(), b_owned );
}
// Re-initializes a constructed array to the following parameters (wipes any stored bit sets)
void PkPooledRawBitSetArray::reinit(
	  const size_type num_bits
	, const size_type num_elements
	, const size_type num_initial_reserved_pool_elements
	)
{
	// Wipe everything!
	clear();
	// Store number of bits
	force_set_num_bits( num_bits );
	if ( num_bits > 0 )
	{
		// Determine number of blocks
		force_set_num_blocks( calc_num_blocks( num_bits ) );
		// Allocate a new memory pool
		PkVerify( mp_pool_alloc = get_allocated_pool( num_bits, num_initial_reserved_pool_elements ) );
		// Allocate bit buffers
		for ( size_t i=0; i<num_elements; ++i )
		{
			PkVerify( NULL != allocate_zeroed_bit_buffer() );
		}
	}
}