1 /* 2 * Copyright 2003, Tyler Dauwalder, tyler@dauwalder.net. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "SparablePartition.h" 7 8 #define B_NOT_IMPLEMENTED B_ERROR 9 10 11 /*! \brief Creates a new SparablePartition object. */ 12 SparablePartition::SparablePartition(uint16 number, uint32 start, uint32 length, 13 uint16 packetLength, uint8 tableCount, uint32 *tableLocations) 14 : 15 fNumber(number), 16 fStart(start), 17 fLength(length), 18 fPacketLength(packetLength), 19 fTableCount(tableCount), 20 fInitStatus(B_NO_INIT) 21 { 22 TRACE(("SparablePartition::SparablePartition: number = %d, start = %" 23 B_PRIu32 ",length = %" B_PRIu32 ", packetLength = %d\n", number, start, 24 length, packetLength)); 25 26 status_t status = (0 < TableCount() && TableCount() <= kMaxSparingTableCount) 27 ? B_OK : B_BAD_VALUE; 28 if (status != B_OK) 29 return; 30 31 for (uint8 i = 0; i < TableCount(); i++) 32 fTableLocations[i] = tableLocations[i]; 33 fInitStatus = B_OK; 34 } 35 36 37 /*! \brief Destroys the SparablePartition object. */ 38 SparablePartition::~SparablePartition() 39 { 40 } 41 42 43 /*! \brief Maps the given logical block to a physical block on disc. 44 45 The sparing tables are first checked to see if the logical block has 46 been remapped from a defective location to a non-defective one. If 47 not, the given logical block is then simply treated as an offset from 48 the start of the physical partition. 49 */ 50 status_t 51 SparablePartition::MapBlock(uint32 logicalBlock, off_t &physicalBlock) 52 { 53 status_t status = InitCheck(); 54 55 if (status != B_OK) 56 return status; 57 58 if (logicalBlock >= fLength) 59 return B_BAD_ADDRESS; 60 else { 61 // Check for the logical block in the sparing tables. If not 62 // found, map directly to physical space. 63 64 //physicalBlock = fStart + logicalBlock; 65 //return B_OK; 66 status = B_ERROR; 67 } 68 return status; 69 } 70 71 72 /*! Returns the initialization status of the object. */ 73 status_t 74 SparablePartition::InitCheck() 75 { 76 return fInitStatus; 77 } 78