1 // ---------------------------------------------------------------------- 2 // This software is part of the OpenBeOS distribution and is covered 3 // by the OpenBeOS license. 4 // 5 // File Name: Volume.cpp 6 // 7 // Description: BVolume class 8 // ---------------------------------------------------------------------- 9 /*! 10 \file Volume.h 11 BVolume implementation. 12 */ 13 14 #include <errno.h> 15 #include <string.h> 16 17 #include <Bitmap.h> 18 #include <Directory.h> 19 #include <Node.h> 20 #include <Path.h> 21 #include <Volume.h> 22 23 #include <storage_support.h> 24 #include <syscalls.h> 25 26 #ifdef USE_OPENBEOS_NAMESPACE 27 namespace OpenBeOS { 28 #endif 29 30 /*! 31 \class BVolume 32 \brief Represents a disk volume 33 34 Provides an interface for querying information about a volume. 35 36 The class is a simple wrapper for a \c dev_t and the function 37 fs_stat_dev. The only exception is the method is SetName(), which 38 sets the name of the volume. 39 40 \author Vincent Dominguez 41 \author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a> 42 43 \version 0.0.0 44 */ 45 46 /*! \var dev_t BVolume::fDevice 47 \brief The volume's device ID. 48 */ 49 50 /*! \var dev_t BVolume::fCStatus 51 \brief The object's initialization status. 52 */ 53 54 // constructor 55 /*! \brief Creates an uninitialized BVolume. 56 57 InitCheck() will return \c B_NO_INIT. 58 */ 59 BVolume::BVolume() 60 : fDevice((dev_t)-1), 61 fCStatus(B_NO_INIT) 62 { 63 } 64 65 // constructor 66 /*! \brief Creates a BVolume and initializes it to the volume specified 67 by the supplied device ID. 68 69 InitCheck() should be called to check whether the initialization was 70 successful. 71 72 \param device The device ID of the volume. 73 */ 74 BVolume::BVolume(dev_t device) 75 : fDevice((dev_t)-1), 76 fCStatus(B_NO_INIT) 77 { 78 SetTo(device); 79 } 80 81 // copy constructor 82 /*! \brief Creates a BVolume and makes it a clone of the supplied one. 83 84 Afterwards the object refers to the same device the supplied object 85 does. If the latter is not properly initialized, this object isn't 86 either. 87 88 \param volume The volume object to be cloned. 89 */ 90 BVolume::BVolume(const BVolume &volume) 91 : fDevice(volume.fDevice), 92 fCStatus(volume.fCStatus) 93 { 94 } 95 96 // destructor 97 /*! \brief Frees all resources associated with the object. 98 99 Does nothing. 100 */ 101 BVolume::~BVolume() 102 { 103 } 104 105 // InitCheck 106 /*! \brief Returns the result of the last initialization. 107 \return 108 - \c B_OK: The object is properly initialized. 109 - an error code otherwise 110 */ 111 status_t 112 BVolume::InitCheck(void) const 113 { 114 return fCStatus; 115 } 116 117 // SetTo 118 /*! \brief Re-initializes the object to refer to the volume specified by 119 the supplied device ID. 120 \param device The device ID of the volume. 121 \param 122 - \c B_OK: Everything went fine. 123 - an error code otherwise 124 */ 125 status_t 126 BVolume::SetTo(dev_t device) 127 { 128 // uninitialize 129 Unset(); 130 // check the parameter 131 status_t error = (device >= 0 ? B_OK : B_BAD_VALUE); 132 if (error == B_OK) { 133 // fs_info info; 134 // if (fs_stat_dev(device, &info) != 0) 135 // error = errno; 136 } 137 // set the new value 138 if (error == B_OK) 139 fDevice = device; 140 // set the init status variable 141 fCStatus = error; 142 return fCStatus; 143 } 144 145 // Unset 146 /*! \brief Uninitialized the BVolume. 147 */ 148 void 149 BVolume::Unset() 150 { 151 fDevice = (dev_t)-1; 152 fCStatus = B_NO_INIT; 153 } 154 155 // Device 156 /*! \brief Returns the device ID of the volume the object refers to. 157 \return Returns the device ID of the volume the object refers to 158 or -1, if the object is not properly initialized. 159 */ 160 dev_t 161 BVolume::Device() const 162 { 163 return fDevice; 164 } 165 166 // == 167 /*! \brief Returns whether two BVolume objects are equal. 168 169 Two volume objects are said to be equal, if they either are both 170 uninitialized, or both are initialized and refer to the same volume. 171 172 \param volume The object to be compared with. 173 \result \c true, if this object and the supplied one are equal, \c false 174 otherwise. 175 */ 176 bool 177 BVolume::operator==(const BVolume &volume) const 178 { 179 return (InitCheck() != B_OK && volume.InitCheck() != B_OK 180 || fDevice == volume.fDevice); 181 } 182 183 // != 184 /*! \brief Returns whether two BVolume objects are unequal. 185 186 Two volume objects are said to be equal, if they either are both 187 uninitialized, or both are initialized and refer to the same volume. 188 189 \param volume The object to be compared with. 190 \result \c true, if this object and the supplied one are unequal, \c false 191 otherwise. 192 */ 193 bool 194 BVolume::operator!=(const BVolume &volume) const 195 { 196 return !(*this == volume); 197 } 198 199 // = 200 /*! \brief Assigns another BVolume object to this one. 201 202 This object is made an exact clone of the supplied one. 203 204 \param volume The volume from which shall be assigned. 205 \return A reference to this object. 206 */ 207 BVolume& 208 BVolume::operator=(const BVolume &volume) 209 { 210 if (&volume != this) { 211 this->fDevice = volume.fDevice; 212 this->fCStatus = volume.fCStatus; 213 } 214 return *this; 215 } 216 217 218 // FBC 219 void BVolume::_TurnUpTheVolume1() {} 220 void BVolume::_TurnUpTheVolume2() {} 221 void BVolume::_TurnUpTheVolume3() {} 222 void BVolume::_TurnUpTheVolume4() {} 223 void BVolume::_TurnUpTheVolume5() {} 224 void BVolume::_TurnUpTheVolume6() {} 225 void BVolume::_TurnUpTheVolume7() {} 226 void BVolume::_TurnUpTheVolume8() {} 227 228 #ifdef USE_OPENBEOS_NAMESPACE 229 } 230 #endif 231