vfs: check userland buffers before reading them.
[haiku.git] / headers / private / storage / DiskDeviceRoster.h
blob713b745879272c3a2d4c00e885fe8fd1103599d4
1 /*
2 * Copyright 2003-2008, Haiku Inc.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _DISK_DEVICE_ROSTER_H
6 #define _DISK_DEVICE_ROSTER_H
8 #include <image.h>
10 #include <DiskDeviceDefs.h>
11 #include <Messenger.h>
12 #include <SupportDefs.h>
14 class BDirectory;
15 class BDiskDevice;
16 class BDiskDeviceVisiting;
17 class BDiskDeviceVisitor;
18 class BDiskScannerPartitionAddOn;
19 class BDiskSystem;
20 class BPartition;
21 class BVolume;
23 namespace BPrivate {
24 class AddOnImage;
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)
39 // Combination masks
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
46 enum {
47 B_DEVICE_UPDATE = 'DUPD'
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
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,
86 class BDiskDeviceRoster {
87 public:
88 BDiskDeviceRoster();
89 ~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,
120 BDiskDevice* device,
121 BPartition** _partition);
122 status_t FindPartitionByMountPoint(const char* mountPoint,
123 BDiskDevice* device,
124 BPartition** _partition);
126 status_t GetDeviceWithID(partition_id id,
127 BDiskDevice* device) const;
128 status_t GetPartitionWithID(partition_id id,
129 BDiskDevice* device,
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);
143 private:
144 #if 0
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,
151 const char *subdir,
152 BPrivate::AddOnImage *image);
153 static status_t _GetNextAddOn(BDirectory *directory,
154 BPrivate::AddOnImage *image);
155 static status_t _GetNextAddOnDir(BPath *path, int32 *index,
156 const char *subdir);
157 static status_t _GetNextAddOnDir(BDirectory **directory, int32 *index,
158 const char *subdir);
160 static status_t _LoadPartitionAddOn(const char *partitioningSystem,
161 BPrivate::AddOnImage *image,
162 BDiskScannerPartitionAddOn **addOn);
163 #endif // 0
164 private:
165 int32 fDeviceCookie;
166 int32 fDiskSystemCookie;
167 int32 fJobCookie;
168 // BDirectory *fPartitionAddOnDir;
169 // BDirectory *fFSAddOnDir;
170 // int32 fPartitionAddOnDirIndex;
171 // int32 fFSAddOnDirIndex;
174 #endif // _DISK_DEVICE_ROSTER_H