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