xref: /haiku/headers/private/storage/DiskDeviceRoster.h (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
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 BDiskDeviceJob;
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 	// Active jobs are those that are scheduled or in-progress
98 	status_t GetNextActiveJob(BDiskDeviceJob *job);
99 	status_t RewindActiveJobs();
100 
101 	partition_id RegisterFileDevice(const char *filename);
102 		// publishes: /dev/disk/virtual/files/<disk device ID>/raw
103 	status_t UnregisterFileDevice(const char *filename);
104 	status_t UnregisterFileDevice(partition_id device);
105 
106 	bool VisitEachDevice(BDiskDeviceVisitor *visitor,
107 						 BDiskDevice *device = NULL);
108 	bool VisitEachPartition(BDiskDeviceVisitor *visitor,
109 							BDiskDevice *device = NULL,
110 							BPartition **partition = NULL);
111 	bool VisitAll(BDiskDeviceVisitor *visitor);
112 
113 	bool VisitEachMountedPartition(BDiskDeviceVisitor *visitor,
114 								   BDiskDevice *device = NULL,
115 								   BPartition **partition = NULL);
116 	bool VisitEachMountablePartition(BDiskDeviceVisitor *visitor,
117 									 BDiskDevice *device = NULL,
118 									 BPartition **partition = NULL);
119 
120 	status_t GetDeviceWithID(partition_id id, BDiskDevice *device) const;
121 	status_t GetPartitionWithID(partition_id id, BDiskDevice *device,
122 								BPartition **partition) const;
123 
124 	status_t GetDeviceForPath(const char *filename, BDiskDevice *device);
125 	status_t GetPartitionForPath(const char *filename, BDiskDevice *device,
126 								 BPartition **partition);
127 
128 	status_t StartWatching(BMessenger target,
129 						   uint32 eventMask = B_DEVICE_REQUEST_ALL);
130 	status_t StartWatchingJob(BDiskDeviceJob *job, BMessenger target,
131 	                          uint32 eventMask = B_DEVICE_REQUEST_JOB_COMPLETE_PROGRESS);
132 		// TODO: Maybe better a BDiskDeviceJob::{Start,Stop}Watching()?
133 	status_t StopWatching(BMessenger target);
134 
135 private:
136 #if 0
137 	status_t _GetObjectWithID(const char *fieldName, partition_id id,
138 							  BDiskDevice *device) const;
139 
140 	// TODO: Introduce iterators instead of these functions.
141 
142 	static status_t _GetNextAddOn(BDirectory **directory, int32 *index,
143 								  const char *subdir,
144 								  BPrivate::AddOnImage *image);
145 	static status_t _GetNextAddOn(BDirectory *directory,
146 								  BPrivate::AddOnImage *image);
147 	static status_t _GetNextAddOnDir(BPath *path, int32 *index,
148 									 const char *subdir);
149 	static status_t _GetNextAddOnDir(BDirectory **directory, int32 *index,
150 									 const char *subdir);
151 
152 	static status_t _LoadPartitionAddOn(const char *partitioningSystem,
153 										BPrivate::AddOnImage *image,
154 										BDiskScannerPartitionAddOn **addOn);
155 #endif	// 0
156 private:
157 	int32		fDeviceCookie;
158 	int32		fDiskSystemCookie;
159 	int32		fJobCookie;
160 //	BDirectory	*fPartitionAddOnDir;
161 //	BDirectory	*fFSAddOnDir;
162 //	int32		fPartitionAddOnDirIndex;
163 //	int32		fFSAddOnDirIndex;
164 };
165 
166 #endif	// _DISK_DEVICE_ROSTER_H
167