btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / kernel / disk_device_manager / KDiskDevice.h
blob799e7f038d2adb64bb89886841e3ef710995a5cb
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
9 #include <OS.h>
11 #include <lock.h>
13 #include "KPartition.h"
16 namespace BPrivate {
17 namespace DiskDevice {
20 class UserDataWriter;
23 class KDiskDevice : public KPartition {
24 public:
25 KDiskDevice(partition_id id = -1);
26 virtual ~KDiskDevice();
28 status_t SetTo(const char *path);
29 void Unset();
30 virtual status_t InitCheck() const;
31 // TODO: probably superfluous
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();
44 virtual void SetID(partition_id id);
46 virtual status_t PublishDevice();
47 virtual status_t UnpublishDevice();
48 virtual status_t RepublishDevice();
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;
58 void UpdateMediaStatusIfNeeded();
59 void UninitializeMedia();
61 void UpdateGeometry();
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;
70 // File descriptor: Set only from a kernel thread, valid only for
71 // kernel threads.
72 void SetFD(int fd);
73 int FD() const;
75 // access to C style device data
76 disk_device_data *DeviceData();
77 const disk_device_data *DeviceData() const;
79 virtual void WriteUserData(UserDataWriter &writer,
80 user_partition_data *data);
81 void WriteUserData(UserDataWriter &writer);
83 virtual void Dump(bool deep = true, int32 level = 0);
85 protected:
86 virtual status_t GetMediaStatus(status_t *mediaStatus);
87 virtual status_t GetGeometry(device_geometry *geometry);
89 private:
90 void _ResetGeometry();
91 void _InitPartitionData();
92 void _UpdateDeviceFlags();
94 disk_device_data fDeviceData;
95 rw_lock fLocker;
96 int fFD;
97 status_t fMediaStatus;
101 } // namespace DiskDevice
102 } // namespace BPrivate
104 using BPrivate::DiskDevice::KDiskDevice;
106 #endif // _K_DISK_DEVICE_H