a365e1cfbb
* devfs: - devfs_[un]publish_partition(): They no longer get the partition path as parameter, but rather the device path and the partition name. - Added devfs_rename_partition(), which renames an already published partition node. * KPartition/KDiskDevice: - Replaced the fPublished flag by fPublishedName, the name under which the partition is published. This simplifies UnpublishDevice() and makes it practically infallible. - Added GetFileName(), which only returns the partition's file name. Simplified GetPath() by using it. - When a partition is added/removed the subsequent sibling partitions get a new index. Now we also rename their published device nodes (and those of their descendents). When something goes wrong we unpublish the concerned partition's device to be on the safe side. Would be a shame to accidentally format the wrong partition, eh? :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31520 a95241bf-73f2-0310-859d-f6bbb57e9c96
107 lines
2.6 KiB
C++
107 lines
2.6 KiB
C++
/*
|
|
* Copyright 2003-2007, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _K_DISK_DEVICE_H
|
|
#define _K_DISK_DEVICE_H
|
|
|
|
#include <OS.h>
|
|
|
|
#include "KPartition.h"
|
|
#include "RWLocker.h"
|
|
|
|
|
|
namespace BPrivate {
|
|
namespace DiskDevice {
|
|
|
|
|
|
class UserDataWriter;
|
|
|
|
|
|
class KDiskDevice : public KPartition {
|
|
public:
|
|
KDiskDevice(partition_id id = -1);
|
|
virtual ~KDiskDevice();
|
|
|
|
status_t SetTo(const char *path);
|
|
void Unset();
|
|
virtual status_t InitCheck() const;
|
|
// TODO: probably superfluous
|
|
|
|
// 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 IsReadLocked(bool orWriteLocked = true);
|
|
bool WriteLock();
|
|
void WriteUnlock();
|
|
bool IsWriteLocked();
|
|
|
|
virtual void SetID(partition_id id);
|
|
|
|
virtual status_t PublishDevice();
|
|
virtual status_t UnpublishDevice();
|
|
virtual status_t RepublishDevice();
|
|
|
|
void SetDeviceFlags(uint32 flags); // comprises the ones below
|
|
uint32 DeviceFlags() const;
|
|
bool IsReadOnlyMedia() const;
|
|
bool IsWriteOnce() const;
|
|
bool IsRemovable() const;
|
|
bool HasMedia() const;
|
|
bool MediaChanged() const;
|
|
|
|
void UpdateMediaStatusIfNeeded();
|
|
void UninitializeMedia();
|
|
|
|
void UpdateGeometry();
|
|
|
|
status_t SetPath(const char *path);
|
|
// TODO: Remove this method or make it private. Once initialized the
|
|
// path must not be changed.
|
|
const char *Path() const;
|
|
virtual status_t GetFileName(char* buffer, size_t size) const;
|
|
virtual status_t GetPath(KPath *path) const;
|
|
|
|
// 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;
|
|
|
|
virtual void WriteUserData(UserDataWriter &writer,
|
|
user_partition_data *data);
|
|
void WriteUserData(UserDataWriter &writer);
|
|
|
|
virtual void Dump(bool deep = true, int32 level = 0);
|
|
|
|
protected:
|
|
virtual status_t GetMediaStatus(status_t *mediaStatus);
|
|
virtual status_t GetGeometry(device_geometry *geometry);
|
|
|
|
private:
|
|
void _ResetGeometry();
|
|
void _InitPartitionData();
|
|
void _UpdateDeviceFlags();
|
|
|
|
disk_device_data fDeviceData;
|
|
RWLocker fLocker;
|
|
int fFD;
|
|
status_t fMediaStatus;
|
|
};
|
|
|
|
|
|
} // namespace DiskDevice
|
|
} // namespace BPrivate
|
|
|
|
using BPrivate::DiskDevice::KDiskDevice;
|
|
|
|
#endif // _K_DISK_DEVICE_H
|