|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/fixedLayout.h#1 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef FIXED_LAYOUT_H
|
|
Packit Service |
310c69 |
#define FIXED_LAYOUT_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "buffer.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "types.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef enum {
|
|
Packit Service |
310c69 |
FROM_BEGINNING,
|
|
Packit Service |
310c69 |
FROM_END,
|
|
Packit Service |
310c69 |
} PartitionDirection;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
extern const BlockCount ALL_FREE_BLOCKS;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* A fixed layout is like a traditional disk partitioning scheme. In the
|
|
Packit Service |
310c69 |
* beginning there is one large unused area, of which parts are carved off.
|
|
Packit Service |
310c69 |
* Each carved off section has its own internal offset and size.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef struct fixedLayout FixedLayout;
|
|
Packit Service |
310c69 |
typedef struct partition Partition;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Make an unpartitioned fixed layout.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] totalBlocks The total size of the layout, in blocks
|
|
Packit Service |
310c69 |
* @param [in] startOffset The block offset in the underlying layer at which
|
|
Packit Service |
310c69 |
* the fixed layout begins
|
|
Packit Service |
310c69 |
* @param [out] layoutPtr The pointer to hold the resulting layout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return a success or error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeFixedLayout(BlockCount totalBlocks,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber startOffset,
|
|
Packit Service |
310c69 |
FixedLayout **layoutPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Free the fixed layout and null out the reference to it.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layoutPtr The reference to the layout to free
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @note all partitions created by this layout become invalid pointers
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeFixedLayout(FixedLayout **layoutPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the total size of the layout in blocks.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layout The layout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The size of the layout
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
BlockCount getTotalFixedLayoutSize(const FixedLayout *layout)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get a partition by id.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layout The layout from which to get a partition
|
|
Packit Service |
310c69 |
* @param id The id of the partition
|
|
Packit Service |
310c69 |
* @param partitionPtr A pointer to hold the partition
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int getPartition(FixedLayout *layout, PartitionID id, Partition **partitionPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Translate a block number from the partition's view to the layer's
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param partition The partition to use for translation
|
|
Packit Service |
310c69 |
* @param partitionBlockNumber The block number relative to the partition
|
|
Packit Service |
310c69 |
* @param layerBlockNumber The block number relative to the layer
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int translateToPBN(const Partition *partition,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber partitionBlockNumber,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber *layerBlockNumber)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Translate a block number from the layer's view to the partition's.
|
|
Packit Service |
310c69 |
* This is the inverse of translateToPBN().
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param partition The partition to use for translation
|
|
Packit Service |
310c69 |
* @param layerBlockNumber The block number relative to the layer
|
|
Packit Service |
310c69 |
* @param partitionBlockNumber The block number relative to the partition
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int translateFromPBN(const Partition *partition,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber layerBlockNumber,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber *partitionBlockNumber)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Return the number of unallocated blocks available.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layout the fixed layout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the number of blocks yet unallocated to partitions
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
BlockCount getFixedLayoutBlocksAvailable(const FixedLayout *layout)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Create a new partition from the beginning or end of the unused space
|
|
Packit Service |
310c69 |
* within a fixed layout.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layout the fixed layout
|
|
Packit Service |
310c69 |
* @param id the id of the partition to make
|
|
Packit Service |
310c69 |
* @param blockCount the number of blocks to carve out, if set
|
|
Packit Service |
310c69 |
* to ALL_FREE_BLOCKS, all remaining blocks will
|
|
Packit Service |
310c69 |
* be used
|
|
Packit Service |
310c69 |
* @param direction whether to carve out from beginning or end
|
|
Packit Service |
310c69 |
* @param base the number of the first block in the partition
|
|
Packit Service |
310c69 |
* from the point of view of its users
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return a success or error code, particularly
|
|
Packit Service |
310c69 |
* VDO_NO_SPACE if there are less than blockCount blocks remaining
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeFixedLayoutPartition(FixedLayout *layout,
|
|
Packit Service |
310c69 |
PartitionID id,
|
|
Packit Service |
310c69 |
BlockCount blockCount,
|
|
Packit Service |
310c69 |
PartitionDirection direction,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber base)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Return the size in blocks of a partition.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param partition a partition of the fixedLayout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the size of the partition in blocks
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
BlockCount getFixedLayoutPartitionSize(const Partition *partition)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the first block of the partition in the layout.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param partition a partition of the fixedLayout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the partition's offset in blocks
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
PhysicalBlockNumber getFixedLayoutPartitionOffset(const Partition *partition)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the number of the first block in the partition from the partition users
|
|
Packit Service |
310c69 |
* point of view.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param partition a partition of the fixedLayout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the number of the first block in the partition
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
PhysicalBlockNumber getFixedLayoutPartitionBase(const Partition *partition)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the size of an encoded layout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layout The layout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The encoded size of the layout
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
size_t getFixedLayoutEncodedSize(const FixedLayout *layout)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Encode a layout into a buffer.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param layout The layout to encode
|
|
Packit Service |
310c69 |
* @param buffer The buffer to encode into
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int encodeFixedLayout(const FixedLayout *layout, Buffer *buffer)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Decode a fixed layout from a buffer.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] buffer The buffer from which to decode
|
|
Packit Service |
310c69 |
* @param [out] layoutPtr A pointer to hold the layout
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int decodeFixedLayout(Buffer *buffer, FixedLayout **layoutPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif // FIXED_LAYOUT_H
|