1 /* 2 * Copyright 2003-2007, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _K_DISK_DEVICE_H 6 #define _K_DISK_DEVICE_H 7 8 9 #include <OS.h> 10 11 #include <lock.h> 12 13 #include "KPartition.h" 14 15 16 namespace BPrivate { 17 namespace DiskDevice { 18 19 20 class UserDataWriter; 21 22 23 class KDiskDevice : public KPartition { 24 public: 25 KDiskDevice(partition_id id = -1); 26 virtual ~KDiskDevice(); 27 28 status_t SetTo(const char *path); 29 void Unset(); 30 virtual status_t InitCheck() const; 31 // TODO: probably superfluous 32 33 // A read lock owner can be sure that the device (incl. all of its 34 // partitions won't be changed). 35 // A write lock owner is moreover allowed to make changes. 36 // The hierarchy is additionally protected by the disk device manager's 37 // lock -- only a device write lock owner is allowed to change it, but 38 // manager lock owners can be sure, that it won't change. 39 bool ReadLock(); 40 void ReadUnlock(); 41 bool WriteLock(); 42 void WriteUnlock(); 43 44 virtual void SetID(partition_id id); 45 46 virtual status_t PublishDevice(); 47 virtual status_t UnpublishDevice(); 48 virtual status_t RepublishDevice(); 49 50 void SetDeviceFlags(uint32 flags); // comprises the ones below 51 uint32 DeviceFlags() const; 52 bool IsReadOnlyMedia() const; 53 bool IsWriteOnce() const; 54 bool IsRemovable() const; 55 bool HasMedia() const; 56 bool MediaChanged() const; 57 58 void UpdateMediaStatusIfNeeded(); 59 void UninitializeMedia(); 60 61 void UpdateGeometry(); 62 63 status_t SetPath(const char *path); 64 // TODO: Remove this method or make it private. Once initialized the 65 // path must not be changed. 66 const char *Path() const; 67 virtual status_t GetFileName(char* buffer, size_t size) const; 68 virtual status_t GetPath(KPath *path) const; 69 70 // File descriptor: Set only from a kernel thread, valid only for 71 // kernel threads. 72 void SetFD(int fd); 73 int FD() const; 74 75 // access to C style device data 76 disk_device_data *DeviceData(); 77 const disk_device_data *DeviceData() const; 78 79 virtual void WriteUserData(UserDataWriter &writer, 80 user_partition_data *data); 81 void WriteUserData(UserDataWriter &writer); 82 83 virtual void Dump(bool deep = true, int32 level = 0); 84 85 protected: 86 virtual status_t GetMediaStatus(status_t *mediaStatus); 87 virtual status_t GetGeometry(device_geometry *geometry); 88 89 private: 90 void _ResetGeometry(); 91 void _InitPartitionData(); 92 void _UpdateDeviceFlags(); 93 94 disk_device_data fDeviceData; 95 rw_lock fLocker; 96 int fFD; 97 status_t fMediaStatus; 98 }; 99 100 101 } // namespace DiskDevice 102 } // namespace BPrivate 103 104 using BPrivate::DiskDevice::KDiskDevice; 105 106 #endif // _K_DISK_DEVICE_H 107