xref: /haiku/headers/private/storage/DiskDeviceRoster.h (revision d9cebac2b77547b7064f22497514eecd2d047160)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //---------------------------------------------------------------------
5 
6 #ifndef _DISK_DEVICE_ROSTER_H
7 #define _DISK_DEVICE_ROSTER_H
8 
9 #include <image.h>
10 
11 #include <DiskDeviceDefs.h>
12 #include <Messenger.h>
13 #include <SupportDefs.h>
14 
15 class BDirectory;
16 class BDiskDevice;
17 class BDiskDeviceVisiting;
18 class BDiskDeviceVisitor;
19 class BDiskScannerPartitionAddOn;
20 class BDiskSystem;
21 class BPartition;
22 
23 namespace BPrivate {
24 	class AddOnImage;
25 }
26 
27 // watchable events
28 enum {
29 	// Basic masks
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)
38 
39 	// Combination masks
40 	B_DEVICE_REQUEST_JOB_COMPLETE_PROGRESS	= 0x00C0, 	// complete job progress info
41 	B_DEVICE_REQUEST_ALL					= 0xffff,	// all events
42 };
43 
44 // notification message "what" field
45 // TODO: move to app/AppDefs.h
46 enum {
47 	B_DEVICE_UPDATE	= 'DUPD'
48 };
49 
50 // notification message "event" field values
51 enum {
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
71 };
72 
73 // notification message "cause" field values
74 enum {
75 	// helpful causes
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?
80 	// unknown cause
81 	B_DEVICE_CAUSE_UNKNOWN,
82 	// for internal use only (e.g.: partition added, because device added)
83 	B_DEVICE_CAUSE_PARENT_CHANGED,
84 };
85 
86 class BDiskDeviceRoster {
87 public:
88 	BDiskDeviceRoster();
89 	~BDiskDeviceRoster();
90 
91 	status_t GetNextDevice(BDiskDevice *device);
92 	status_t RewindDevices();
93 
94 	status_t GetNextDiskSystem(BDiskSystem *system);
95 	status_t RewindDiskSystems();
96 
97 	partition_id RegisterFileDevice(const char *filename);
98 		// publishes: /dev/disk/virtual/files/<disk device ID>/raw
99 	status_t UnregisterFileDevice(const char *filename);
100 	status_t UnregisterFileDevice(partition_id device);
101 
102 	bool VisitEachDevice(BDiskDeviceVisitor *visitor,
103 						 BDiskDevice *device = NULL);
104 	bool VisitEachPartition(BDiskDeviceVisitor *visitor,
105 							BDiskDevice *device = NULL,
106 							BPartition **partition = NULL);
107 
108 	bool VisitEachMountedPartition(BDiskDeviceVisitor *visitor,
109 								   BDiskDevice *device = NULL,
110 								   BPartition **partition = NULL);
111 	bool VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
112 									 BDiskDevice *device = NULL,
113 									 BPartition **partition = NULL);
114 
115 	status_t GetDeviceWithID(partition_id id, BDiskDevice *device) const;
116 	status_t GetPartitionWithID(partition_id id, BDiskDevice *device,
117 								BPartition **partition) const;
118 
119 	status_t GetDeviceForPath(const char *filename, BDiskDevice *device);
120 	status_t GetPartitionForPath(const char *filename, BDiskDevice *device,
121 								 BPartition **partition);
122 
123 	status_t StartWatching(BMessenger target,
124 						   uint32 eventMask = B_DEVICE_REQUEST_ALL);
125 	status_t StopWatching(BMessenger target);
126 
127 private:
128 #if 0
129 	status_t _GetObjectWithID(const char *fieldName, partition_id id,
130 							  BDiskDevice *device) const;
131 
132 	// TODO: Introduce iterators instead of these functions.
133 
134 	static status_t _GetNextAddOn(BDirectory **directory, int32 *index,
135 								  const char *subdir,
136 								  BPrivate::AddOnImage *image);
137 	static status_t _GetNextAddOn(BDirectory *directory,
138 								  BPrivate::AddOnImage *image);
139 	static status_t _GetNextAddOnDir(BPath *path, int32 *index,
140 									 const char *subdir);
141 	static status_t _GetNextAddOnDir(BDirectory **directory, int32 *index,
142 									 const char *subdir);
143 
144 	static status_t _LoadPartitionAddOn(const char *partitioningSystem,
145 										BPrivate::AddOnImage *image,
146 										BDiskScannerPartitionAddOn **addOn);
147 #endif	// 0
148 private:
149 	int32		fDeviceCookie;
150 	int32		fDiskSystemCookie;
151 	int32		fJobCookie;
152 //	BDirectory	*fPartitionAddOnDir;
153 //	BDirectory	*fFSAddOnDir;
154 //	int32		fPartitionAddOnDirIndex;
155 //	int32		fFSAddOnDirIndex;
156 };
157 
158 #endif	// _DISK_DEVICE_ROSTER_H
159