1*c5855c9eSSalvatore Benedetto /* 2*c5855c9eSSalvatore Benedetto * Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net. 3*c5855c9eSSalvatore Benedetto * Distributed under the terms of the MIT License. 4*c5855c9eSSalvatore Benedetto */ 5*c5855c9eSSalvatore Benedetto 63b9617bcSTyler Dauwalder #include "SparablePartition.h" 73b9617bcSTyler Dauwalder 83b9617bcSTyler Dauwalder #define B_NOT_IMPLEMENTED B_ERROR 93b9617bcSTyler Dauwalder 103b9617bcSTyler Dauwalder 11*c5855c9eSSalvatore Benedetto /*! \brief Creates a new SparablePartition object. */ 123b9617bcSTyler Dauwalder SparablePartition::SparablePartition(uint16 number, uint32 start, uint32 length, 13*c5855c9eSSalvatore Benedetto uint16 packetLength, uint8 tableCount, uint32 *tableLocations) 14*c5855c9eSSalvatore Benedetto : 15*c5855c9eSSalvatore Benedetto fNumber(number), 16*c5855c9eSSalvatore Benedetto fStart(start), 17*c5855c9eSSalvatore Benedetto fLength(length), 18*c5855c9eSSalvatore Benedetto fPacketLength(packetLength), 19*c5855c9eSSalvatore Benedetto fTableCount(tableCount), 20*c5855c9eSSalvatore Benedetto fInitStatus(B_NO_INIT) 213b9617bcSTyler Dauwalder { 22*c5855c9eSSalvatore Benedetto TRACE(("SparablePartition::SparablePartition: number = %d, start = %d, 23*c5855c9eSSalvatore Benedetto length = %d, packetLength = %d\n", number, start, length, packetLength)); 24*c5855c9eSSalvatore Benedetto 25*c5855c9eSSalvatore Benedetto status_t status = (0 < TableCount() && TableCount() <= kMaxSparingTableCount) 263b9617bcSTyler Dauwalder ? B_OK : B_BAD_VALUE; 27*c5855c9eSSalvatore Benedetto if (status != B_OK) 28*c5855c9eSSalvatore Benedetto return; 29*c5855c9eSSalvatore Benedetto 303b9617bcSTyler Dauwalder for (uint8 i = 0; i < TableCount(); i++) 313b9617bcSTyler Dauwalder fTableLocations[i] = tableLocations[i]; 323b9617bcSTyler Dauwalder fInitStatus = B_OK; 333b9617bcSTyler Dauwalder } 343b9617bcSTyler Dauwalder 35*c5855c9eSSalvatore Benedetto 36*c5855c9eSSalvatore Benedetto /*! \brief Destroys the SparablePartition object. */ 373b9617bcSTyler Dauwalder SparablePartition::~SparablePartition() 383b9617bcSTyler Dauwalder { 393b9617bcSTyler Dauwalder } 403b9617bcSTyler Dauwalder 41*c5855c9eSSalvatore Benedetto 423b9617bcSTyler Dauwalder /*! \brief Maps the given logical block to a physical block on disc. 433b9617bcSTyler Dauwalder 443b9617bcSTyler Dauwalder The sparing tables are first checked to see if the logical block has 453b9617bcSTyler Dauwalder been remapped from a defective location to a non-defective one. If 463b9617bcSTyler Dauwalder not, the given logical block is then simply treated as an offset from 473b9617bcSTyler Dauwalder the start of the physical partition. 483b9617bcSTyler Dauwalder */ 493b9617bcSTyler Dauwalder status_t 50a1b5a724STyler Dauwalder SparablePartition::MapBlock(uint32 logicalBlock, off_t &physicalBlock) 513b9617bcSTyler Dauwalder { 52*c5855c9eSSalvatore Benedetto status_t status = InitCheck(); 53*c5855c9eSSalvatore Benedetto 54*c5855c9eSSalvatore Benedetto if (status != B_OK) 55*c5855c9eSSalvatore Benedetto return status; 56*c5855c9eSSalvatore Benedetto 573b9617bcSTyler Dauwalder if (logicalBlock >= fLength) 58*c5855c9eSSalvatore Benedetto return B_BAD_ADDRESS; 593b9617bcSTyler Dauwalder else { 603b9617bcSTyler Dauwalder // Check for the logical block in the sparing tables. If not 613b9617bcSTyler Dauwalder // found, map directly to physical space. 623b9617bcSTyler Dauwalder 633b9617bcSTyler Dauwalder //physicalBlock = fStart + logicalBlock; 643b9617bcSTyler Dauwalder //return B_OK; 65*c5855c9eSSalvatore Benedetto status = B_ERROR; 663b9617bcSTyler Dauwalder } 67*c5855c9eSSalvatore Benedetto return status; 683b9617bcSTyler Dauwalder } 693b9617bcSTyler Dauwalder 70*c5855c9eSSalvatore Benedetto 71*c5855c9eSSalvatore Benedetto /*! Returns the initialization status of the object. */ 723b9617bcSTyler Dauwalder status_t 733b9617bcSTyler Dauwalder SparablePartition::InitCheck() 743b9617bcSTyler Dauwalder { 753b9617bcSTyler Dauwalder return fInitStatus; 763b9617bcSTyler Dauwalder } 77