1 /* 2 * Copyright 2003-2007, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Tomas Kucera, kucerat@centrum.cz 7 */ 8 9 #include "PartitionLocker.h" 10 11 // #pragma mark - PartitionLocker 12 13 // constructor 14 PartitionLocker::PartitionLocker(partition_id partitionID) 15 : 16 fDevice(NULL), 17 fPartitionID(partitionID) 18 { 19 } 20 21 // destructor 22 PartitionLocker::~PartitionLocker() 23 { 24 } 25 26 // IsLocked 27 bool 28 PartitionLocker::IsLocked() const 29 { 30 return fDevice; 31 } 32 33 // PartitionId 34 partition_id 35 PartitionLocker::PartitionId() const 36 { 37 return fPartitionID; 38 } 39 40 41 // #pragma mark - PartitionReadLocker 42 43 44 // constructor 45 PartitionReadLocker::PartitionReadLocker(partition_id partitionID) 46 : 47 PartitionLocker(partitionID) 48 { 49 fDevice = read_lock_disk_device(partitionID); 50 } 51 52 // destructor 53 PartitionReadLocker::~PartitionReadLocker() 54 { 55 if (IsLocked()) 56 read_unlock_disk_device(PartitionId()); 57 } 58 59 60 // #pragma mark - PartitionWriteLocker 61 62 63 // constructor 64 PartitionWriteLocker::PartitionWriteLocker(partition_id partitionID) 65 : 66 PartitionLocker(partitionID) 67 { 68 fDevice = write_lock_disk_device(partitionID); 69 } 70 71 // destructor 72 PartitionWriteLocker::~PartitionWriteLocker() 73 { 74 if (IsLocked()) 75 write_unlock_disk_device(PartitionId()); 76 } 77