xref: /haiku/src/add-ons/kernel/file_systems/udf/MetadataPartition.cpp (revision 25a7b01d15612846f332751841da3579db313082)
1c530d46cSJérôme Duval /*
2c530d46cSJérôme Duval  * Copyright 2012, Jérôme Duval, korli@users.berlios.de.
3c530d46cSJérôme Duval  * Copyright 2003 Tyler Dauwalder, tyler@dauwalder.net
4c530d46cSJérôme Duval  * This file may be used under the terms of the MIT License.
5c530d46cSJérôme Duval  */
6c530d46cSJérôme Duval 
7c530d46cSJérôme Duval 
89be2e8bdSTyler Dauwalder #include "MetadataPartition.h"
99be2e8bdSTyler Dauwalder 
10c530d46cSJérôme Duval #include "Icb.h"
119be2e8bdSTyler Dauwalder 
129be2e8bdSTyler Dauwalder 
139be2e8bdSTyler Dauwalder /*! \brief Creates a new MetadataPartition object.
149be2e8bdSTyler Dauwalder */
MetadataPartition(Volume * volume,uint16 parentNumber,Partition & parentPartition,uint32 metadataFileLocation,uint32 metadataMirrorFileLocation,uint32 metadataBitmapFileLocation,uint32 allocationUnitSize,uint16 alignmentUnitSize,bool metadataIsDuplicated)15c530d46cSJérôme Duval MetadataPartition::MetadataPartition(Volume *volume,
16c530d46cSJérôme Duval 	uint16 parentNumber, Partition &parentPartition, uint32 metadataFileLocation,
17c530d46cSJérôme Duval 	uint32 metadataMirrorFileLocation, uint32 metadataBitmapFileLocation,
18c530d46cSJérôme Duval 	uint32 allocationUnitSize, uint16 alignmentUnitSize,
199be2e8bdSTyler Dauwalder 	bool metadataIsDuplicated)
20c530d46cSJérôme Duval 	: fPartition(parentNumber),
21c530d46cSJérôme Duval 	fParentPartition(parentPartition),
22c530d46cSJérôme Duval 	fAllocationUnitSize(allocationUnitSize),
23c530d46cSJérôme Duval 	fAlignmentUnitSize(alignmentUnitSize),
24c530d46cSJérôme Duval 	fMetadataIsDuplicated(metadataIsDuplicated),
25c530d46cSJérôme Duval 	fInitStatus(B_NO_INIT),
26c530d46cSJérôme Duval 	fMetadataIcb(NULL)
279be2e8bdSTyler Dauwalder {
28c530d46cSJérôme Duval 	long_address address;
29c530d46cSJérôme Duval 	address.set_to(metadataFileLocation, fPartition);
30c530d46cSJérôme Duval 
31c530d46cSJérôme Duval 	fMetadataIcb = new(nothrow) Icb(volume, address);
32c530d46cSJérôme Duval 	if (fMetadataIcb == NULL || fMetadataIcb->InitCheck() != B_OK)
33c530d46cSJérôme Duval 		fInitStatus = B_NO_MEMORY;
34ee3c8867SJérôme Duval 	else
35c530d46cSJérôme Duval 		fInitStatus = B_OK;
36ee3c8867SJérôme Duval 
37ee3c8867SJérôme Duval 	address.set_to(metadataMirrorFileLocation, fPartition);
38ee3c8867SJérôme Duval 
39ee3c8867SJérôme Duval 	fMetadataMirrorIcb = new(nothrow) Icb(volume, address);
40ee3c8867SJérôme Duval 	if (fMetadataMirrorIcb == NULL
41ee3c8867SJérôme Duval 		|| fMetadataMirrorIcb->InitCheck() != B_OK) {
42ee3c8867SJérôme Duval 		fInitStatus = B_NO_MEMORY;
43ee3c8867SJérôme Duval 	}
449be2e8bdSTyler Dauwalder }
459be2e8bdSTyler Dauwalder 
469be2e8bdSTyler Dauwalder /*! \brief Destroys the MetadataPartition object.
479be2e8bdSTyler Dauwalder */
~MetadataPartition()489be2e8bdSTyler Dauwalder MetadataPartition::~MetadataPartition()
499be2e8bdSTyler Dauwalder {
50c530d46cSJérôme Duval 	delete fMetadataIcb;
51*aa18b835SPhilippe Saint-Pierre 	delete fMetadataMirrorIcb;
529be2e8bdSTyler Dauwalder }
539be2e8bdSTyler Dauwalder 
549be2e8bdSTyler Dauwalder /*! \brief Maps the given logical block to a physical block on disc.
559be2e8bdSTyler Dauwalder */
569be2e8bdSTyler Dauwalder status_t
MapBlock(uint32 logicalBlock,off_t & physicalBlock)57a1b5a724STyler Dauwalder MetadataPartition::MapBlock(uint32 logicalBlock, off_t &physicalBlock)
589be2e8bdSTyler Dauwalder {
59c530d46cSJérôme Duval 	off_t block = 0;
60ee3c8867SJérôme Duval 	bool isRecorded;
61ee3c8867SJérôme Duval 	status_t status = fMetadataIcb->FindBlock(logicalBlock, block, isRecorded);
62c530d46cSJérôme Duval 	if (status != B_OK)
63c530d46cSJérôme Duval 		return status;
64ee3c8867SJérôme Duval 	if (!isRecorded) {
65ee3c8867SJérôme Duval 		status = fMetadataMirrorIcb->FindBlock(logicalBlock, block, isRecorded);
66ee3c8867SJérôme Duval 		if (status != B_OK)
67ee3c8867SJérôme Duval 			return status;
68ee3c8867SJérôme Duval 		if (!isRecorded)
69ee3c8867SJérôme Duval 			return B_BAD_DATA;
70ee3c8867SJérôme Duval 	}
71c530d46cSJérôme Duval 	return fParentPartition.MapBlock(block, physicalBlock);
729be2e8bdSTyler Dauwalder }
739be2e8bdSTyler Dauwalder 
749be2e8bdSTyler Dauwalder /*! Returns the initialization status of the object.
759be2e8bdSTyler Dauwalder */
769be2e8bdSTyler Dauwalder status_t
InitCheck()779be2e8bdSTyler Dauwalder MetadataPartition::InitCheck()
789be2e8bdSTyler Dauwalder {
799be2e8bdSTyler Dauwalder 	return fInitStatus;
809be2e8bdSTyler Dauwalder }
81