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. */
SparablePartition(uint16 number,uint32 start,uint32 length,uint16 packetLength,uint8 tableCount,uint32 * tableLocations)123b9617bcSTyler Dauwalder SparablePartition::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 {
22*7e5b0f96SJérôme Duval TRACE(("SparablePartition::SparablePartition: number = %d, start = %"
23*7e5b0f96SJérôme Duval B_PRIu32 ",length = %" B_PRIu32 ", packetLength = %d\n", number, start,
24*7e5b0f96SJérôme Duval length, packetLength));
25c5855c9eSSalvatore Benedetto
26c5855c9eSSalvatore Benedetto status_t status = (0 < TableCount() && TableCount() <= kMaxSparingTableCount)
273b9617bcSTyler Dauwalder ? B_OK : B_BAD_VALUE;
28c5855c9eSSalvatore Benedetto if (status != B_OK)
29c5855c9eSSalvatore Benedetto return;
30c5855c9eSSalvatore Benedetto
313b9617bcSTyler Dauwalder for (uint8 i = 0; i < TableCount(); i++)
323b9617bcSTyler Dauwalder fTableLocations[i] = tableLocations[i];
333b9617bcSTyler Dauwalder fInitStatus = B_OK;
343b9617bcSTyler Dauwalder }
353b9617bcSTyler Dauwalder
36c5855c9eSSalvatore Benedetto
37c5855c9eSSalvatore Benedetto /*! \brief Destroys the SparablePartition object. */
~SparablePartition()383b9617bcSTyler Dauwalder SparablePartition::~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 Dauwalder status_t
MapBlock(uint32 logicalBlock,off_t & physicalBlock)51a1b5a724STyler Dauwalder SparablePartition::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
583b9617bcSTyler Dauwalder if (logicalBlock >= fLength)
59c5855c9eSSalvatore Benedetto return B_BAD_ADDRESS;
603b9617bcSTyler Dauwalder else {
613b9617bcSTyler Dauwalder // Check for the logical block in the sparing tables. If not
623b9617bcSTyler Dauwalder // found, map directly to physical space.
633b9617bcSTyler Dauwalder
643b9617bcSTyler Dauwalder //physicalBlock = fStart + logicalBlock;
653b9617bcSTyler Dauwalder //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 Dauwalder status_t
InitCheck()743b9617bcSTyler Dauwalder SparablePartition::InitCheck()
753b9617bcSTyler Dauwalder {
763b9617bcSTyler Dauwalder return fInitStatus;
773b9617bcSTyler Dauwalder }
78