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