2007-10-17 21:05:48 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003-2007, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2003-06-10 03:04:54 +04:00
|
|
|
#ifndef _K_DISK_DEVICE_H
|
|
|
|
#define _K_DISK_DEVICE_H
|
|
|
|
|
2009-10-12 18:29:05 +04:00
|
|
|
|
2003-06-10 03:04:54 +04:00
|
|
|
#include <OS.h>
|
|
|
|
|
2009-10-12 18:29:05 +04:00
|
|
|
#include <lock.h>
|
|
|
|
|
2007-11-02 02:36:21 +03:00
|
|
|
#include "KPartition.h"
|
2003-06-11 02:35:12 +04:00
|
|
|
|
2007-11-02 02:36:21 +03:00
|
|
|
|
2003-06-10 03:04:54 +04:00
|
|
|
namespace BPrivate {
|
|
|
|
namespace DiskDevice {
|
|
|
|
|
2007-11-02 02:36:21 +03:00
|
|
|
|
2003-07-07 03:01:22 +04:00
|
|
|
class UserDataWriter;
|
|
|
|
|
2007-11-02 02:36:21 +03:00
|
|
|
|
|
|
|
class KDiskDevice : public KPartition {
|
2003-06-11 02:35:12 +04:00
|
|
|
public:
|
2003-06-10 03:04:54 +04:00
|
|
|
KDiskDevice(partition_id id = -1);
|
|
|
|
virtual ~KDiskDevice();
|
|
|
|
|
2003-06-13 02:21:10 +04:00
|
|
|
status_t SetTo(const char *path);
|
|
|
|
void Unset();
|
2003-06-23 02:57:42 +04:00
|
|
|
virtual status_t InitCheck() const;
|
2003-06-13 02:21:10 +04:00
|
|
|
// TODO: probably superfluous
|
2003-06-11 02:35:12 +04:00
|
|
|
|
2003-06-10 03:04:54 +04:00
|
|
|
// A read lock owner can be sure that the device (incl. all of its
|
|
|
|
// partitions won't be changed).
|
|
|
|
// A write lock owner is moreover allowed to make changes.
|
|
|
|
// The hierarchy is additionally protected by the disk device manager's
|
|
|
|
// lock -- only a device write lock owner is allowed to change it, but
|
|
|
|
// manager lock owners can be sure, that it won't change.
|
|
|
|
bool ReadLock();
|
|
|
|
void ReadUnlock();
|
|
|
|
bool WriteLock();
|
|
|
|
void WriteUnlock();
|
|
|
|
|
2003-06-11 02:35:12 +04:00
|
|
|
virtual void SetID(partition_id id);
|
|
|
|
|
2003-06-14 04:06:57 +04:00
|
|
|
virtual status_t PublishDevice();
|
|
|
|
virtual status_t UnpublishDevice();
|
2009-07-11 18:35:04 +04:00
|
|
|
virtual status_t RepublishDevice();
|
2003-06-14 04:06:57 +04:00
|
|
|
|
2003-06-10 03:04:54 +04:00
|
|
|
void SetDeviceFlags(uint32 flags); // comprises the ones below
|
|
|
|
uint32 DeviceFlags() const;
|
2003-07-08 21:25:32 +04:00
|
|
|
bool IsReadOnlyMedia() const;
|
|
|
|
bool IsWriteOnce() const;
|
2003-06-10 03:04:54 +04:00
|
|
|
bool IsRemovable() const;
|
|
|
|
bool HasMedia() const;
|
2007-10-19 19:20:36 +04:00
|
|
|
bool MediaChanged() const;
|
2003-06-10 03:04:54 +04:00
|
|
|
|
2007-10-19 19:20:36 +04:00
|
|
|
void UpdateMediaStatusIfNeeded();
|
2007-11-13 02:20:33 +03:00
|
|
|
void UninitializeMedia();
|
2007-10-17 21:05:48 +04:00
|
|
|
|
2007-11-13 15:18:06 +03:00
|
|
|
void UpdateGeometry();
|
|
|
|
|
2003-06-10 03:04:54 +04:00
|
|
|
status_t SetPath(const char *path);
|
2003-06-11 02:35:12 +04:00
|
|
|
// TODO: Remove this method or make it private. Once initialized the
|
|
|
|
// path must not be changed.
|
|
|
|
const char *Path() const;
|
2009-07-11 18:35:04 +04:00
|
|
|
virtual status_t GetFileName(char* buffer, size_t size) const;
|
2004-10-28 01:52:33 +04:00
|
|
|
virtual status_t GetPath(KPath *path) const;
|
2003-06-10 03:04:54 +04:00
|
|
|
|
|
|
|
// File descriptor: Set only from a kernel thread, valid only for
|
|
|
|
// kernel threads.
|
|
|
|
void SetFD(int fd);
|
|
|
|
int FD() const;
|
|
|
|
|
|
|
|
// access to C style device data
|
|
|
|
disk_device_data *DeviceData();
|
|
|
|
const disk_device_data *DeviceData() const;
|
|
|
|
|
2005-01-26 17:57:35 +03:00
|
|
|
virtual void WriteUserData(UserDataWriter &writer,
|
|
|
|
user_partition_data *data);
|
2007-11-02 02:36:21 +03:00
|
|
|
void WriteUserData(UserDataWriter &writer);
|
2003-07-07 03:01:22 +04:00
|
|
|
|
2003-06-23 02:57:42 +04:00
|
|
|
virtual void Dump(bool deep = true, int32 level = 0);
|
|
|
|
|
|
|
|
protected:
|
2007-10-19 19:20:36 +04:00
|
|
|
virtual status_t GetMediaStatus(status_t *mediaStatus);
|
2003-06-23 02:57:42 +04:00
|
|
|
virtual status_t GetGeometry(device_geometry *geometry);
|
|
|
|
|
2003-06-11 02:35:12 +04:00
|
|
|
private:
|
2007-11-13 02:20:33 +03:00
|
|
|
void _ResetGeometry();
|
2003-06-13 02:21:10 +04:00
|
|
|
void _InitPartitionData();
|
2007-11-13 15:18:06 +03:00
|
|
|
void _UpdateDeviceFlags();
|
2003-06-13 02:21:10 +04:00
|
|
|
|
2003-06-11 02:35:12 +04:00
|
|
|
disk_device_data fDeviceData;
|
2009-10-12 18:29:05 +04:00
|
|
|
rw_lock fLocker;
|
2003-06-11 02:35:12 +04:00
|
|
|
int fFD;
|
|
|
|
status_t fMediaStatus;
|
2003-06-10 03:04:54 +04:00
|
|
|
};
|
|
|
|
|
2007-11-02 02:36:21 +03:00
|
|
|
|
2003-06-10 03:04:54 +04:00
|
|
|
} // namespace DiskDevice
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
using BPrivate::DiskDevice::KDiskDevice;
|
|
|
|
|
|
|
|
#endif // _K_DISK_DEVICE_H
|