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 : fDevice(NULL), 16 fPartitionID(partitionID) 17 { 18 } 19 20 // destructor 21 PartitionLocker::~PartitionLocker() 22 { 23 } 24 25 // IsLocked 26 bool 27 PartitionLocker::IsLocked() const 28 { 29 return fDevice; 30 } 31 32 // PartitionId 33 partition_id 34 PartitionLocker::PartitionId() const 35 { 36 return fPartitionID; 37 } 38 39 40 // #pragma mark - PartitionReadLocker 41 42 43 // constructor 44 PartitionReadLocker::PartitionReadLocker(partition_id partitionID) 45 : PartitionLocker(partitionID) 46 { 47 fDevice = read_lock_disk_device(partitionID); 48 } 49 50 // destructor 51 PartitionReadLocker::~PartitionReadLocker() 52 { 53 if (IsLocked()) 54 read_unlock_disk_device(PartitionId()); 55 } 56 57 58 // #pragma mark - PartitionWriteLocker 59 60 61 // constructor 62 PartitionWriteLocker::PartitionWriteLocker(partition_id partitionID) 63 : PartitionLocker(partitionID) 64 { 65 fDevice = write_lock_disk_device(partitionID); 66 } 67 68 // destructor 69 PartitionWriteLocker::~PartitionWriteLocker() 70 { 71 if (IsLocked()) 72 write_unlock_disk_device(PartitionId()); 73 } 74