2 * Copyright 2003-2008, Haiku Inc.
3 * Distributed under the terms of the MIT License.
5 #ifndef _DISK_DEVICE_ROSTER_H
6 #define _DISK_DEVICE_ROSTER_H
10 #include <DiskDeviceDefs.h>
11 #include <Messenger.h>
12 #include <SupportDefs.h>
16 class BDiskDeviceVisiting
;
17 class BDiskDeviceVisitor
;
18 class BDiskScannerPartitionAddOn
;
30 B_DEVICE_REQUEST_MOUNT_POINT
= 0x0001, // mount point changes
31 B_DEVICE_REQUEST_MOUNTING
= 0x0002, // mounting/unmounting
32 B_DEVICE_REQUEST_PARTITION
= 0x0004, // partition changes
33 B_DEVICE_REQUEST_DEVICE
= 0x0008, // device changes (media changes)
34 B_DEVICE_REQUEST_DEVICE_LIST
= 0x0010, // device additions/removals
35 B_DEVICE_REQUEST_JOB_LIST
= 0x0020, // job addition/initiation/cancellation/completion
36 B_DEVICE_REQUEST_JOB_SIMPLE_PROGRESS
= 0x0040, // simple job progress (i.e. "% complete" only)
37 B_DEVICE_REQUEST_JOB_EXTRA_PROGRESS
= 0x0080, // extra info on job progress (no "% complete" info)
40 B_DEVICE_REQUEST_JOB_COMPLETE_PROGRESS
= 0x00C0, // complete job progress info
41 B_DEVICE_REQUEST_ALL
= 0xffff, // all events
44 // notification message "what" field
45 // TODO: move to app/AppDefs.h
47 B_DEVICE_UPDATE
= 'DUPD'
50 // notification message "event" field values
52 B_DEVICE_MOUNT_POINT_MOVED
, // mount point moved/renamed
53 B_DEVICE_PARTITION_MOUNTED
, // partition mounted
54 B_DEVICE_PARTITION_UNMOUNTED
, // partition unmounted
55 B_DEVICE_PARTITION_INITIALIZED
, // partition initialized
56 B_DEVICE_PARTITION_RESIZED
, // partition resized
57 B_DEVICE_PARTITION_MOVED
, // partition moved
58 B_DEVICE_PARTITION_CREATED
, // partition created
59 B_DEVICE_PARTITION_DELETED
, // partition deleted
60 B_DEVICE_PARTITION_DEFRAGMENTED
, // partition defragmented
61 B_DEVICE_PARTITION_REPAIRED
, // partition repaired
62 B_DEVICE_MEDIA_CHANGED
, // media changed
63 B_DEVICE_ADDED
, // device added
64 B_DEVICE_REMOVED
, // device removed
65 B_DEVICE_JOB_SCHEDULED
, // job added
66 B_DEVICE_JOB_INITIATED
, // job initiated
67 B_DEVICE_JOB_CANCELED
, // job canceled
68 B_DEVICE_JOB_FINISHED
, // job finished
69 B_DEVICE_JOB_SIMPLE_PROGRESS
, // job percent complete progress
70 B_DEVICE_JOB_EXTRA_PROGRESS
, // extended job progress info
73 // notification message "cause" field values
76 B_DEVICE_CAUSE_MEDIA_CHANGED
,
77 B_DEVICE_CAUSE_FORMATTED
, // is this still applicable?
78 B_DEVICE_CAUSE_PARTITIONED
, // is this still applicable?
79 B_DEVICE_CAUSE_INITIALIZED
, // is this still applicable?
81 B_DEVICE_CAUSE_UNKNOWN
,
82 // for internal use only (e.g.: partition added, because device added)
83 B_DEVICE_CAUSE_PARENT_CHANGED
,
86 class BDiskDeviceRoster
{
91 status_t
GetNextDevice(BDiskDevice
* device
);
92 status_t
RewindDevices();
94 status_t
GetNextDiskSystem(BDiskSystem
* system
);
95 status_t
RewindDiskSystems();
97 status_t
GetDiskSystem(BDiskSystem
* system
, const char* name
);
99 partition_id
RegisterFileDevice(const char* filename
);
100 // publishes: /dev/disk/virtual/files/<disk device ID>/raw
101 status_t
UnregisterFileDevice(const char* filename
);
102 status_t
UnregisterFileDevice(partition_id device
);
104 bool VisitEachDevice(BDiskDeviceVisitor
* visitor
,
105 BDiskDevice
* device
= NULL
);
106 bool VisitEachPartition(BDiskDeviceVisitor
* visitor
,
107 BDiskDevice
* device
= NULL
,
108 BPartition
** _partition
= NULL
);
110 bool VisitEachMountedPartition(
111 BDiskDeviceVisitor
* visitor
,
112 BDiskDevice
* device
= NULL
,
113 BPartition
** _partition
= NULL
);
114 bool VisitEachMountablePartition(
115 BDiskDeviceVisitor
* visitor
,
116 BDiskDevice
* device
= NULL
,
117 BPartition
** _partition
= NULL
);
119 status_t
FindPartitionByVolume(const BVolume
& volume
,
121 BPartition
** _partition
);
122 status_t
FindPartitionByMountPoint(const char* mountPoint
,
124 BPartition
** _partition
);
126 status_t
GetDeviceWithID(partition_id id
,
127 BDiskDevice
* device
) const;
128 status_t
GetPartitionWithID(partition_id id
,
130 BPartition
** _partition
) const;
132 status_t
GetDeviceForPath(const char* filename
,
133 BDiskDevice
* device
);
134 status_t
GetPartitionForPath(const char* filename
,
135 BDiskDevice
* device
, BPartition
** _partition
);
136 status_t
GetFileDeviceForPath(const char* filename
,
137 BDiskDevice
* device
);
139 status_t
StartWatching(BMessenger target
,
140 uint32 eventMask
= B_DEVICE_REQUEST_ALL
);
141 status_t
StopWatching(BMessenger target
);
145 status_t
_GetObjectWithID(const char *fieldName
, partition_id id
,
146 BDiskDevice
*device
) const;
148 // TODO: Introduce iterators instead of these functions.
150 static status_t
_GetNextAddOn(BDirectory
**directory
, int32
*index
,
152 BPrivate::AddOnImage
*image
);
153 static status_t
_GetNextAddOn(BDirectory
*directory
,
154 BPrivate::AddOnImage
*image
);
155 static status_t
_GetNextAddOnDir(BPath
*path
, int32
*index
,
157 static status_t
_GetNextAddOnDir(BDirectory
**directory
, int32
*index
,
160 static status_t
_LoadPartitionAddOn(const char *partitioningSystem
,
161 BPrivate::AddOnImage
*image
,
162 BDiskScannerPartitionAddOn
**addOn
);
166 int32 fDiskSystemCookie
;
168 // BDirectory *fPartitionAddOnDir;
169 // BDirectory *fFSAddOnDir;
170 // int32 fPartitionAddOnDirIndex;
171 // int32 fFSAddOnDirIndex;
174 #endif // _DISK_DEVICE_ROSTER_H