13b9617bcSTyler Dauwalder #include "SparablePartition.h" 23b9617bcSTyler Dauwalder 33b9617bcSTyler Dauwalder #define B_NOT_IMPLEMENTED B_ERROR 43b9617bcSTyler Dauwalder 53b9617bcSTyler Dauwalder using namespace Udf; 63b9617bcSTyler Dauwalder 73b9617bcSTyler Dauwalder /*! \brief Creates a new SparablePartition object. 83b9617bcSTyler Dauwalder */ 93b9617bcSTyler Dauwalder SparablePartition::SparablePartition(uint16 number, uint32 start, uint32 length, 103b9617bcSTyler Dauwalder uint16 packetLength, uint8 tableCount, 113b9617bcSTyler Dauwalder uint32 *tableLocations) 123b9617bcSTyler Dauwalder : fNumber(number) 133b9617bcSTyler Dauwalder , fStart(start) 143b9617bcSTyler Dauwalder , fLength(length) 153b9617bcSTyler Dauwalder , fPacketLength(packetLength) 163b9617bcSTyler Dauwalder , fTableCount(tableCount) 173b9617bcSTyler Dauwalder , fInitStatus(B_NO_INIT) 183b9617bcSTyler Dauwalder { 193b9617bcSTyler Dauwalder status_t error = (0 < TableCount() && TableCount() <= kMaxSparingTableCount) 203b9617bcSTyler Dauwalder ? B_OK : B_BAD_VALUE; 213b9617bcSTyler Dauwalder if (!error) { 223b9617bcSTyler Dauwalder for (uint8 i = 0; i < TableCount(); i++) 233b9617bcSTyler Dauwalder fTableLocations[i] = tableLocations[i]; 243b9617bcSTyler Dauwalder } 253b9617bcSTyler Dauwalder if (!error) 263b9617bcSTyler Dauwalder fInitStatus = B_OK; 273b9617bcSTyler Dauwalder } 283b9617bcSTyler Dauwalder 293b9617bcSTyler Dauwalder /*! \brief Destroys the SparablePartition object. 303b9617bcSTyler Dauwalder */ 313b9617bcSTyler Dauwalder SparablePartition::~SparablePartition() 323b9617bcSTyler Dauwalder { 333b9617bcSTyler Dauwalder } 343b9617bcSTyler Dauwalder 353b9617bcSTyler Dauwalder /*! \brief Maps the given logical block to a physical block on disc. 363b9617bcSTyler Dauwalder 373b9617bcSTyler Dauwalder The sparing tables are first checked to see if the logical block has 383b9617bcSTyler Dauwalder been remapped from a defective location to a non-defective one. If 393b9617bcSTyler Dauwalder not, the given logical block is then simply treated as an offset from 403b9617bcSTyler Dauwalder the start of the physical partition. 413b9617bcSTyler Dauwalder */ 423b9617bcSTyler Dauwalder status_t 43*a1b5a724STyler Dauwalder SparablePartition::MapBlock(uint32 logicalBlock, off_t &physicalBlock) 443b9617bcSTyler Dauwalder { 453b9617bcSTyler Dauwalder status_t error = InitCheck(); 463b9617bcSTyler Dauwalder if (!error) { 473b9617bcSTyler Dauwalder if (logicalBlock >= fLength) 483b9617bcSTyler Dauwalder error = B_BAD_ADDRESS; 493b9617bcSTyler Dauwalder else { 503b9617bcSTyler Dauwalder // Check for the logical block in the sparing tables. If not 513b9617bcSTyler Dauwalder // found, map directly to physical space. 523b9617bcSTyler Dauwalder 533b9617bcSTyler Dauwalder //physicalBlock = fStart + logicalBlock; 543b9617bcSTyler Dauwalder //return B_OK; 55*a1b5a724STyler Dauwalder error = B_ERROR; 563b9617bcSTyler Dauwalder } 573b9617bcSTyler Dauwalder } 583b9617bcSTyler Dauwalder return error; 593b9617bcSTyler Dauwalder } 603b9617bcSTyler Dauwalder 613b9617bcSTyler Dauwalder /*! Returns the initialization status of the object. 623b9617bcSTyler Dauwalder */ 633b9617bcSTyler Dauwalder status_t 643b9617bcSTyler Dauwalder SparablePartition::InitCheck() 653b9617bcSTyler Dauwalder { 663b9617bcSTyler Dauwalder return fInitStatus; 673b9617bcSTyler Dauwalder } 68