1 // ---------------------------------------------------------------------- 2 // This software is part of the Haiku distribution and is covered 3 // by the MIT License. 4 // 5 // File Name: VolumeRoster.cpp 6 // 7 // Description: BVolumeRoster class 8 // ---------------------------------------------------------------------- 9 10 11 #include <errno.h> 12 #include <new> 13 14 #include <Bitmap.h> 15 #include <Directory.h> 16 #include <fs_info.h> 17 #include <Node.h> 18 #include <NodeMonitor.h> 19 #include <VolumeRoster.h> 20 21 22 static const char kBootVolumePath[] = "/boot"; 23 24 using namespace std; 25 26 27 #ifdef USE_OPENBEOS_NAMESPACE 28 namespace OpenBeOS { 29 #endif 30 31 32 BVolumeRoster::BVolumeRoster() 33 : fCookie(0), 34 fTarget(NULL) 35 { 36 } 37 38 39 // Deletes the volume roster and frees all associated resources. 40 BVolumeRoster::~BVolumeRoster() 41 { 42 StopWatching(); 43 } 44 45 46 // Fills out the passed in BVolume object with the next available volume. 47 status_t 48 BVolumeRoster::GetNextVolume(BVolume *volume) 49 { 50 // check parameter 51 status_t error = (volume ? B_OK : B_BAD_VALUE); 52 // get next device 53 dev_t device; 54 if (error == B_OK) { 55 device = next_dev(&fCookie); 56 if (device < 0) 57 error = device; 58 } 59 // init volume 60 if (error == B_OK) 61 error = volume->SetTo(device); 62 return error; 63 } 64 65 66 // Rewinds the list of available volumes back to the first item. 67 void 68 BVolumeRoster::Rewind() 69 { 70 fCookie = 0; 71 } 72 73 74 // Fills out the passed in BVolume object with the boot volume. 75 status_t 76 BVolumeRoster::GetBootVolume(BVolume *volume) 77 { 78 // check parameter 79 status_t error = (volume ? B_OK : B_BAD_VALUE); 80 // get device 81 dev_t device; 82 if (error == B_OK) { 83 device = dev_for_path(kBootVolumePath); 84 if (device < 0) 85 error = device; 86 } 87 // init volume 88 if (error == B_OK) 89 error = volume->SetTo(device); 90 return error; 91 } 92 93 94 // Starts watching the available volumes for changes. 95 status_t 96 BVolumeRoster::StartWatching(BMessenger messenger) 97 { 98 StopWatching(); 99 status_t error = (messenger.IsValid() ? B_OK : B_ERROR); 100 // clone messenger 101 if (error == B_OK) { 102 fTarget = new(nothrow) BMessenger(messenger); 103 if (!fTarget) 104 error = B_NO_MEMORY; 105 } 106 // start watching 107 if (error == B_OK) 108 error = watch_node(NULL, B_WATCH_MOUNT, messenger); 109 // cleanup on failure 110 if (error != B_OK && fTarget) { 111 delete fTarget; 112 fTarget = NULL; 113 } 114 return error; 115 } 116 117 118 // Stops watching volumes initiated by StartWatching(). 119 void 120 BVolumeRoster::StopWatching() 121 { 122 if (fTarget) { 123 stop_watching(*fTarget); 124 delete fTarget; 125 fTarget = NULL; 126 } 127 } 128 129 130 // Returns the messenger currently watching the volume list. 131 BMessenger 132 BVolumeRoster::Messenger() const 133 { 134 return (fTarget ? *fTarget : BMessenger()); 135 } 136 137 138 // FBC 139 void BVolumeRoster::_SeveredVRoster1() {} 140 void BVolumeRoster::_SeveredVRoster2() {} 141 142 143 #ifdef USE_OPENBEOS_NAMESPACE 144 } 145 #endif 146