1c5855c9eSSalvatore Benedetto/*
2c5855c9eSSalvatore Benedetto * Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net.
3c5855c9eSSalvatore Benedetto * Distributed under the terms of the MIT License.
4c5855c9eSSalvatore Benedetto */
5c5855c9eSSalvatore Benedetto
63b9617bcSTyler Dauwalder#include "SparablePartition.h"
73b9617bcSTyler Dauwalder
83b9617bcSTyler Dauwalder#define B_NOT_IMPLEMENTED B_ERROR
93b9617bcSTyler Dauwalder
103b9617bcSTyler Dauwalder
11c5855c9eSSalvatore Benedetto/*! \brief Creates a new SparablePartition object. */
123b9617bcSTyler DauwalderSparablePartition::SparablePartition(uint16 number, uint32 start, uint32 length,
13c5855c9eSSalvatore Benedetto	uint16 packetLength, uint8 tableCount, uint32 *tableLocations)
14c5855c9eSSalvatore Benedetto	:
15c5855c9eSSalvatore Benedetto	fNumber(number),
16c5855c9eSSalvatore Benedetto	fStart(start),
17c5855c9eSSalvatore Benedetto	fLength(length),
18c5855c9eSSalvatore Benedetto	fPacketLength(packetLength),
19c5855c9eSSalvatore Benedetto	fTableCount(tableCount),
20c5855c9eSSalvatore Benedetto	fInitStatus(B_NO_INIT)
213b9617bcSTyler Dauwalder{
227e5b0f96SJérôme Duval	TRACE(("SparablePartition::SparablePartition: number = %d, start = %"
237e5b0f96SJérôme Duval		B_PRIu32 ",length = %" B_PRIu32 ", packetLength = %d\n", number, start,
247e5b0f96SJérôme Duval		length, packetLength));
25c5855c9eSSalvatore Benedetto
26c5855c9eSSalvatore Benedetto	status_t status = (0 < TableCount() && TableCount() <= kMaxSparingTableCount)
27c5855c9eSSalvatore Benedetto		? B_OK : B_BAD_VALUE;
28c5855c9eSSalvatore Benedetto	if (status != B_OK)
29c5855c9eSSalvatore Benedetto		return;
30c5855c9eSSalvatore Benedetto
31c5855c9eSSalvatore Benedetto	for (uint8 i = 0; i < TableCount(); i++)
32c5855c9eSSalvatore Benedetto		fTableLocations[i] = tableLocations[i];
33c5855c9eSSalvatore Benedetto	fInitStatus = B_OK;
343b9617bcSTyler Dauwalder}
353b9617bcSTyler Dauwalder
36c5855c9eSSalvatore Benedetto
37c5855c9eSSalvatore Benedetto/*! \brief Destroys the SparablePartition object. */
383b9617bcSTyler DauwalderSparablePartition::~SparablePartition()
393b9617bcSTyler Dauwalder{
403b9617bcSTyler Dauwalder}
413b9617bcSTyler Dauwalder
42c5855c9eSSalvatore Benedetto
433b9617bcSTyler Dauwalder/*! \brief Maps the given logical block to a physical block on disc.
443b9617bcSTyler Dauwalder
453b9617bcSTyler Dauwalder	The sparing tables are first checked to see if the logical block has
463b9617bcSTyler Dauwalder	been remapped from a defective location to a non-defective one. If
473b9617bcSTyler Dauwalder	not, the given logical block is then simply treated as an offset from
483b9617bcSTyler Dauwalder	the	start of the physical partition.
493b9617bcSTyler Dauwalder*/
503b9617bcSTyler Dauwalderstatus_t
51a1b5a724STyler DauwalderSparablePartition::MapBlock(uint32 logicalBlock, off_t &physicalBlock)
523b9617bcSTyler Dauwalder{
53c5855c9eSSalvatore Benedetto	status_t status = InitCheck();
54c5855c9eSSalvatore Benedetto
55c5855c9eSSalvatore Benedetto	if (status != B_OK)
56c5855c9eSSalvatore Benedetto		return status;
57c5855c9eSSalvatore Benedetto
58c5855c9eSSalvatore Benedetto	if (logicalBlock >= fLength)
59c5855c9eSSalvatore Benedetto		return B_BAD_ADDRESS;
60c5855c9eSSalvatore Benedetto	else {
61c5855c9eSSalvatore Benedetto		// Check for the logical block in the sparing tables. If not
62c5855c9eSSalvatore Benedetto		// found, map directly to physical space.
63c5855c9eSSalvatore Benedetto
64c5855c9eSSalvatore Benedetto		//physicalBlock = fStart + logicalBlock;
65c5855c9eSSalvatore Benedetto		//return B_OK;
66c5855c9eSSalvatore Benedetto		status = B_ERROR;
673b9617bcSTyler Dauwalder	}
68c5855c9eSSalvatore Benedetto	return status;
693b9617bcSTyler Dauwalder}
703b9617bcSTyler Dauwalder
71c5855c9eSSalvatore Benedetto
72c5855c9eSSalvatore Benedetto/*! Returns the initialization status of the object. */
733b9617bcSTyler Dauwalderstatus_t
743b9617bcSTyler DauwalderSparablePartition::InitCheck()
753b9617bcSTyler Dauwalder{
763b9617bcSTyler Dauwalder	return fInitStatus;
773b9617bcSTyler Dauwalder}