From d713d1d9739f28e8e4bb0e015c85173f33f59b14 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 31 Jan 2003 21:17:20 +0000 Subject: [PATCH] The beginning of the DiskDevice API. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2609 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/storage/DiskDevice.h | 64 +++++++++++++++ headers/private/storage/DiskDeviceRoster.h | 90 +++++++++++++++++++++ headers/private/storage/DiskDeviceVisitor.h | 21 +++++ headers/private/storage/Partition.h | 79 ++++++++++++++++++ headers/private/storage/Session.h | 64 +++++++++++++++ 5 files changed, 318 insertions(+) create mode 100644 headers/private/storage/DiskDevice.h create mode 100644 headers/private/storage/DiskDeviceRoster.h create mode 100644 headers/private/storage/DiskDeviceVisitor.h create mode 100644 headers/private/storage/Partition.h create mode 100644 headers/private/storage/Session.h diff --git a/headers/private/storage/DiskDevice.h b/headers/private/storage/DiskDevice.h new file mode 100644 index 0000000000..89f1b7fb38 --- /dev/null +++ b/headers/private/storage/DiskDevice.h @@ -0,0 +1,64 @@ +// DiskDevice.h + +#ifndef _DISK_DEVICE_H +#define _DISK_DEVICE_H + +#include +#include + +class BPartition; +class BSession; + +class BDiskDevice { +public: + BDiskDevice(); + ~BDiskDevice(); + + int32 CountSessions() const; + BSession *SessionAt(int32 index) const; + + int32 CountPartitions() const; + + int32 BlockSize() const; + + const char *DevicePath() const; + void GetName(BString *name, bool includeBusID = true, + bool includeLUN = false) const; + void GetName(char *name, bool includeBusID = true, + bool includeLUN = false) const; + + bool IsReadOnly() const; + bool IsRemovable() const; + bool HasMedia() const; + bool IsFloppy() const; + uint8 Type() const; // cf. device_geometry::device_type + + int32 UniqueID() const; + + status_t Eject(); + status_t LowLevelFormat(); // TODO: remove? + + status_t Update(); // sync this object with reality + + BSession *VisitEachSession(BDiskDeviceVisitor *visitor); + // return BSession* if terminated early + BPartition *VisitEachPartition(BDiskDeviceVisitor *visitor); + // return BPartition* if terminated early + bool Traverse(BDiskDeviceVisitor *visitor); + // return true if terminated early + +private: + BDiskDevice(const BDiskDevice &); + BDiskDevice &operator=(const BDiskDevice &); + +private: + BObjectList fSessions; + int32 fUniqueID; + int32 fBlockSize; + char fPath[B_FILE_NAME_LENGTH]; + bool fReadOnly; + bool fRemovable; + bool fIsFloppy; +}; + +#endif // _DISK_DEVICE_H diff --git a/headers/private/storage/DiskDeviceRoster.h b/headers/private/storage/DiskDeviceRoster.h new file mode 100644 index 0000000000..2d21974bb1 --- /dev/null +++ b/headers/private/storage/DiskDeviceRoster.h @@ -0,0 +1,90 @@ +// DiskDeviceRoster.h + +#ifndef _DISK_DEVICE_ROSTER_H +#define _DISK_DEVICE_ROSTER_H + +#include +#include + +class BDiskDevice; +class BPartition; +class BSession; + +// watchable events +enum { + B_DEVICE_REQUEST_MOUNT_POINT = 0x01, // mount point changes + B_DEVICE_REQUEST_MOUNTING = 0x02, // mounting/unmounting + B_DEVICE_REQUEST_PARTITION = 0x04, // partition changes (initial.) + B_DEVICE_REQUEST_SESSION = 0x08, // session changes (partitioning) + B_DEVICE_REQUEST_DEVICE = 0x10, // device changes (media changes) + B_DEVICE_REQUEST_DEVICE_LIST = 0x20, // device additions/removals + B_DEVICE_REQUEST_ALL = 0xff, // all events +}; + +// notification message "what" field +// TODO: move to app/AppDefs.h +enum { + B_DEVICE_UPDATE = 'DUPD' +}; + +// notification message "event" field values +enum { + B_DEVICE_MOUNT_POINT_MOVED, // mount point moved/renamed + B_DEVICE_PARTITION_MOUNTED, // partition mounted + B_DEVICE_PARTITION_UNMOUNTED, // partition unmounted + B_DEVICE_PARTITION_CHANGED, // partition changed, e.g. initialized + // or resized + B_DEVICE_PARTITION_ADDED, // partition added + B_DEVICE_PARTITION_REMOVED, // partition removed + B_DEVICE_MEDIA_CHANGED, // media changed + B_DEVICE_ADDED, // device added + B_DEVICE_REMOVED // device removed +}; + +class BDiskDeviceRoster { +public: + BDiskDeviceRoster(); + ~BDiskDeviceRoster(); + + status_t GetNextDevice(BDiskDevice *device); + status_t Rewind(); + + bool VisitEachDevice(BDiskDeviceVisitor *visitor, + BDiskDevice *device = NULL); + // return true if terminated early + + bool VisitEachPartition(BDiskDeviceVisitor *visitor, + BDiskDevice *device = NULL, + BPartition **partition = NULL); + // return true if terminated early + bool Traverse(BDiskDeviceVisitor *visitor); + // return true if terminated early + + bool VisitEachMountedPartition(BDiskDeviceVisitor *visitor, + BDiskDevice *device = NULL, + BPartition **partition = NULL); + // return true if terminated early + bool VisitEachMountablePartition(BDiskDeviceVisitor *visitor, + BDiskDevice *device = NULL, + BPartition **partition = NULL); + // return true if terminated early + bool VisitEachInitializablePartition(BDiskDeviceVisitor *visitor, + BDiskDevice *device = NULL, + BPartition **partition = NULL); + // return true if terminated early + + BDiskDevice *DeviceWithID(int32 id) const; + BSession *SessionWithID(int32 id, BDiskDevice *device) const; + // inits device to the device containing the session + BPartition *PartitionWithID(int32 id, BDiskDevice *device) const; + // inits device to the device containing the partition + + status_t StartWatching(BMessenger target, + uint32 eventMask = B_DEVICE_REQUEST_ALL); + status_t StopWatching(BMessenger target); + +private: + int32 fDeviceID; // iteration state +}; + +#endif // _DISK_DEVICE_ROSTER_H diff --git a/headers/private/storage/DiskDeviceVisitor.h b/headers/private/storage/DiskDeviceVisitor.h new file mode 100644 index 0000000000..8b0b64f4c7 --- /dev/null +++ b/headers/private/storage/DiskDeviceVisitor.h @@ -0,0 +1,21 @@ +// DiskDeviceIteration.h + +#ifndef _DISK_DEVICE_VISITOR_H +#define _DISK_DEVICE_VISITOR_H + +class BDiskDevice; +class BPartition; +class BSession; + +// BDiskDeviceVisitor +class BDiskDeviceVisitor { + BDiskDeviceVisitor(); + virtual ~BDiskDeviceVisitor(); + + // return true to abort iteration + virtual bool Visit(BDiskDevice *device); + virtual bool Visit(BSession *device); + virtual bool Visit(BPartition *device); +}; + +#endif _DISK_DEVICE_VISITOR_H diff --git a/headers/private/storage/Partition.h b/headers/private/storage/Partition.h new file mode 100644 index 0000000000..21d6d5c23e --- /dev/null +++ b/headers/private/storage/Partition.h @@ -0,0 +1,79 @@ +// Partition.h + +#ifndef _PARTITION_H +#define _PARTITION_H + +#include +#include +#include +#include +#include + +class BDiskDevice; +class BSession; +class BVolume; + +class BPartition { +public: + BPartition(); + ~BPartition(); + + BSession *Session() const; + BDiskDevice *Device() const; + + off_t Offset() const; + off_t Size() const; + int32 BlockSize() const; + int32 Index() const; + + uint32 Flags() const; + bool IsHidden() const; + bool IsVirtual() const; + bool IsEmpty() const; + + const char *Name() const; + const char *Type() const; + const char *FileSystemShortName() const; + const char *FileSystemLongName() const; + const char *VolumeName() const; + + uint32 FileSystemFlags() const; + + bool IsMounted() const; + + int32 UniqueID() const; + + status_t GetVolume(BVolume *volume) const; + + status_t GetIcon(BBitmap *icon, icon_size which) const; + + status_t Mount(uint32 mountflags = 0, const char *parameters = NULL); + status_t Unmount(); + + status_t GetInitializationParameters(const char *fileSystem, + BPoint dialogCenter, + BString *parameters, + bool *cancelled = NULL); + status_t Initialize(const char *fileSystem, const char *parameters); + status_t Initialize(const char *fileSystem = "bfs", + BPoint dialogCenter = BPoint(-1, -1), + bool *cancelled = NULL); + + static status_t GetFileSystemList(BObjectList *list); + +private: + BPartition(const BPartition &); + BPartition &operator=(const BPartition &); + +private: + BSession *fSession; +// TODO: Also contains the device name, which we can get from Device() anyway. +// We could either remove it from extended_partition_info or list +// the individual fields here. + extended_partition_info fInfo; + int32 fUniqueID; + dev_t fVolumeID; + node_ref fMountPoint; +}; + +#endif // _PARTITION_H diff --git a/headers/private/storage/Session.h b/headers/private/storage/Session.h new file mode 100644 index 0000000000..edca35bfc4 --- /dev/null +++ b/headers/private/storage/Session.h @@ -0,0 +1,64 @@ +// Session.h + +#ifndef _SESSION_H +#define _SESSION_H + +#include +#include +#include +#include +#include + +class BDiskDevice; +class BPartition; + +extern const char *B_INTEL_PARTITION_STYLE; + +class BSession { +public: + BSession(); + ~BSession(); + + BDiskDevice *Device() const; + + off_t Offset() const; + off_t Size() const; + + int32 CountPartitions() const; + BPartition *PartitionAt(int32 index) const; + + int32 Index() const; + + uint32 Flags() const; + bool IsAudio() const; + bool IsData() const; + bool IsVirtual() const; + + const char *PartitionStyle() const; + + int32 UniqueID() const; + + BPartition *EachPartition(BDiskDeviceVisitor *visitor); + // return BPartition* if terminated early + + status_t GetPartitioningParameters(const char *partitioningSystem, + BPoint dialogCenter, + BString *parameters, + bool *cancelled = NULL); + status_t Partition(const char *partitioningSystem, const char *parameters); + status_t Partition(const char *partitioningSystem, + BPoint dialogCenter = BPoint(-1, -1), + bool *cancelled = NULL); + +private: + BSession(const BSession &); + BSession &operator=(const BSession &); + +private: + BDiskDevice *fDevice; + BObjectList fPartitions; + int32 fUniqueID; + session_info fInfo; +}; + +#endif // _SESSION_H