BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / udf / MetadataPartition.cpp
blob2b66da5fee9d62ac5f1c39ff99f3b17d60e5f036
1 /*
2 * Copyright 2012, Jérôme Duval, korli@users.berlios.de.
3 * Copyright 2003 Tyler Dauwalder, tyler@dauwalder.net
4 * This file may be used under the terms of the MIT License.
5 */
8 #include "MetadataPartition.h"
10 #include "Icb.h"
13 /*! \brief Creates a new MetadataPartition object.
15 MetadataPartition::MetadataPartition(Volume *volume,
16 uint16 parentNumber, Partition &parentPartition, uint32 metadataFileLocation,
17 uint32 metadataMirrorFileLocation, uint32 metadataBitmapFileLocation,
18 uint32 allocationUnitSize, uint16 alignmentUnitSize,
19 bool metadataIsDuplicated)
20 : fPartition(parentNumber),
21 fParentPartition(parentPartition),
22 fAllocationUnitSize(allocationUnitSize),
23 fAlignmentUnitSize(alignmentUnitSize),
24 fMetadataIsDuplicated(metadataIsDuplicated),
25 fInitStatus(B_NO_INIT),
26 fMetadataIcb(NULL)
28 long_address address;
29 address.set_to(metadataFileLocation, fPartition);
31 fMetadataIcb = new(nothrow) Icb(volume, address);
32 if (fMetadataIcb == NULL || fMetadataIcb->InitCheck() != B_OK)
33 fInitStatus = B_NO_MEMORY;
34 else
35 fInitStatus = B_OK;
37 address.set_to(metadataMirrorFileLocation, fPartition);
39 fMetadataMirrorIcb = new(nothrow) Icb(volume, address);
40 if (fMetadataMirrorIcb == NULL
41 || fMetadataMirrorIcb->InitCheck() != B_OK) {
42 fInitStatus = B_NO_MEMORY;
46 /*! \brief Destroys the MetadataPartition object.
48 MetadataPartition::~MetadataPartition()
50 delete fMetadataIcb;
51 delete fMetadataMirrorIcb;
54 /*! \brief Maps the given logical block to a physical block on disc.
56 status_t
57 MetadataPartition::MapBlock(uint32 logicalBlock, off_t &physicalBlock)
59 off_t block = 0;
60 bool isRecorded;
61 status_t status = fMetadataIcb->FindBlock(logicalBlock, block, isRecorded);
62 if (status != B_OK)
63 return status;
64 if (!isRecorded) {
65 status = fMetadataMirrorIcb->FindBlock(logicalBlock, block, isRecorded);
66 if (status != B_OK)
67 return status;
68 if (!isRecorded)
69 return B_BAD_DATA;
71 return fParentPartition.MapBlock(block, physicalBlock);
74 /*! Returns the initialization status of the object.
76 status_t
77 MetadataPartition::InitCheck()
79 return fInitStatus;