xref: /haiku/src/add-ons/kernel/file_systems/udf/SparablePartition.cpp (revision 959ff00ddee8411dabb09211f3bfbd52d87229da)
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 = %d,
23 		length = %d, packetLength = %d\n", number, start, length, packetLength));
24 
25 	status_t status = (0 < TableCount() && TableCount() <= kMaxSparingTableCount)
26 		? B_OK : B_BAD_VALUE;
27 	if (status != B_OK)
28 		return;
29 
30 	for (uint8 i = 0; i < TableCount(); i++)
31 		fTableLocations[i] = tableLocations[i];
32 	fInitStatus = B_OK;
33 }
34 
35 
36 /*! \brief Destroys the SparablePartition object. */
37 SparablePartition::~SparablePartition()
38 {
39 }
40 
41 
42 /*! \brief Maps the given logical block to a physical block on disc.
43 
44 	The sparing tables are first checked to see if the logical block has
45 	been remapped from a defective location to a non-defective one. If
46 	not, the given logical block is then simply treated as an offset from
47 	the	start of the physical partition.
48 */
49 status_t
50 SparablePartition::MapBlock(uint32 logicalBlock, off_t &physicalBlock)
51 {
52 	status_t status = InitCheck();
53 
54 	if (status != B_OK)
55 		return status;
56 
57 	if (logicalBlock >= fLength)
58 		return B_BAD_ADDRESS;
59 	else {
60 		// Check for the logical block in the sparing tables. If not
61 		// found, map directly to physical space.
62 
63 		//physicalBlock = fStart + logicalBlock;
64 		//return B_OK;
65 		status = B_ERROR;
66 	}
67 	return status;
68 }
69 
70 
71 /*! Returns the initialization status of the object. */
72 status_t
73 SparablePartition::InitCheck()
74 {
75 	return fInitStatus;
76 }
77