2 * Copyright 2002-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
8 * John Scipione, jscipione@gmail.com
9 * Ingo Weinhold, bonefish@users.sf.net
12 * headers/os/storage/Volume.h hrev47402
13 * src/kits/storage/Volume.cpp hrev47402
21 \brief Provides the BVolume class.
29 \brief Provides an interface for querying information about a volume.
31 The class is a simple wrapper for a \c dev_t and the function
32 fs_stat_dev(). The sole exception is the SetName() method which
33 sets the name of the volume.
40 \fn BVolume::BVolume()
41 \brief Creates an uninitialized BVolume object.
43 InitCheck() will return \c B_NO_INIT.
52 \fn BVolume::BVolume(dev_t device)
53 \brief Creates a BVolume and initializes it to the volume specified
54 by the supplied device ID.
56 InitCheck() should be called afterwards to check if initialization was
59 \param device The device ID of the volume.
66 \fn BVolume::BVolume(const BVolume& volume)
67 \brief Creates a copy of the supplied BVolume object.
69 Afterwards the object refers to the same device the supplied object
70 does. If the latter is not properly initialized, this result isn't
73 \param volume The volume object to be copied.
80 \fn BVolume::~BVolume()
81 \brief Destroys the object and frees all associated resources.
88 \name Constructor Helpers
96 \fn status_t BVolume::InitCheck(void) const
97 \brief Returns the initialization status.
99 \return \c B_OK if the object was properly initialized, or an error code
107 \fn status_t BVolume::SetTo(dev_t device)
108 \brief Initializes the object to refer to the volume specified by
109 the supplied device ID.
111 \param device The device ID of the volume to set.
113 \return \c B_OK if the object was properly initialized, or an error code
121 \fn void BVolume::Unset()
122 \brief Brings the BVolume object to an uninitialized state.
124 InitCheck() will return \c B_NO_INIT.
134 \name Volume Information
142 \fn dev_t BVolume::Device() const
143 \brief Returns the device ID of the volume the object refers to.
145 \return Returns the device ID of the volume the object refers to
146 or -1 if the object was not properly initialized.
153 \fn status_t BVolume::GetRootDirectory(BDirectory *directory) const
154 \brief Writes the root directory of the volume referred to by this
155 object into \a directory.
157 \param directory A pointer to a pre-allocated BDirectory to be initialized
158 to the volume's root directory.
160 \return A status code.
161 \retval B_OK Everything went fine.
162 \retval B_BAD_VALUE \a directory was \c NULL or the object was not properly
170 \fn off_t BVolume::Capacity() const
171 \brief Returns the total storage capacity of the volume.
173 \return The volume's total storage capacity (in bytes), or \c B_BAD_VALUE
174 if the object is not properly initialized.
183 \fn off_t BVolume::FreeBytes() const
184 \brief Returns the amount of unused space on the volume (in bytes).
186 \return The amount of unused space on the volume (in bytes), or
187 \c B_BAD_VALUE if the object is not properly initialized.
194 \fn off_t BVolume::BlockSize() const
195 \brief Returns the size of one block (in bytes). The meaning of this
196 depends on the underlying file system.
198 \return The block size in bytes, \c B_NO_INIT if the volume is not
199 initialized or other errors forwarded from the file system.
217 \fn status_t BVolume::GetName(char* name) const
218 \brief Writes the volume's name into the provided buffer.
220 \param name A pointer to a pre-allocated character buffer of size
221 \c B_FILE_NAME_LENGTH or larger into which the name of the
224 \return A status code.
225 \retval B_OK Everything went fine.
226 \retval B_BAD_VALUE \a name was \c NULL or the object was not properly
236 \fn status_t BVolume::SetName(const char *name)
237 \brief Sets the volume's name to \a name.
239 \note The R5 implementation checks if an entry with the volume's old name
240 exists in the root directory and renames that entry, if it is indeed
241 the mount point of the volume (or a link referring to it). In all
242 other cases, nothing is done (even if the mount point is named like
243 the volume, but lives in a different directory). We follow suit for
246 \warning If the volume name is set to "boot" this method tries to rename
247 it to /boot, but is prevented by the kernel.
249 \param name The new name of the volume, must not be longer than
250 \c B_FILE_NAME_LENGTH (including the terminating \c NULL).
252 \return A status code.
253 \retval B_OK Everything went fine.
254 \retval B_BAD_VALUE \a name was \c NULL or the object was not properly
273 \fn status_t BVolume::GetIcon(BBitmap *icon, icon_size which) const
274 \brief Writes the volume's icon into the supplied BBitmap.
276 \param icon A pointer to a pre-allocated BBitmap of the correct dimension
277 to store the requested icon (16x16 for the mini and 32x32 for the
280 \param which The icon size to be retrieved: \c B_MINI_ICON for the mini or
281 \c B_LARGE_ICON for the large icon.
288 \fn status_t BVolume::GetIcon(uint8** _data, size_t* _size,
289 type_code* _type) const
290 \brief Writes the volume's icon data into the supplied \c uint8 array.
292 \param _data A pointer to a pointer to a pre-allocated \c uint8 array of
293 the correct size to store the requested icon.
294 \param _size The size of the retrieved icon (in bytes).
295 \param _type The type code of the retrieve icon.
297 \returns A status code.
298 \retval B_OK Everything went fine.
299 \retval B_NO_INIT Object was not properly initialized.
301 \see fs_stat_dev() for more return codes.
302 \see get_device_icon() for more return codes.
312 \name Volume Capabilities
320 \fn bool BVolume::IsRemovable() const
321 \brief Returns whether or not the volume is removable.
323 \return \c true, if the volume was properly initialized and is removable,
331 \fn bool BVolume::IsReadOnly(void) const
332 \brief Returns whether or not the volume is read-only.
334 \return \c true, if the volume was properly initialized and is read-only,
342 \fn bool BVolume::IsPersistent(void) const
343 \brief Returns whether or not the volume is persistent.
345 \return \c true, if the volume was properly initialized and is persistent,
353 \fn bool BVolume::IsShared(void) const
354 \brief Returns whether or not the volume is shared.
356 return \c true, if the volume was properly initialized and is shared,
364 \fn bool BVolume::KnowsMime(void) const
365 \brief Returns whether or not the volume supports MIME-types.
367 \return \c true, if the volume was properly initialized and supports
368 MIME-types, \c false otherwise.
375 \fn bool BVolume::KnowsAttr(void) const
376 \brief Returns whether or not the volume supports attributes.
378 \return \c true, if the volume was properly initialized and supports
379 attributes, \c false otherwise.
386 \fn bool BVolume::KnowsQuery(void) const
387 \brief Returns whether or not the volume supports queries.
389 \return \c true, if the volume was properly initialized and supports
390 queries, \c false otherwise.
408 \fn bool BVolume::operator==(const BVolume &volume) const
409 \brief Returns whether or not the supplied BVolume object is equal to this
412 Two volume objects are said to be equal if they are both uninitialized,
413 or they are both initialized and refer to the same volume.
415 \param volume The volume to be tested for equality.
417 \return \c true, if the objects are equal, \c false otherwise.
424 \fn bool BVolume::operator!=(const BVolume &volume) const
425 \brief Returns whether or not the supplied BVolume object is NOT equal to
428 Two volume objects are said to be unequal if one is initialized and the
429 other is not or if they are both initialized and refer to the different
432 \param volume The volume to be tested for inequality.
434 \return \c true, if the objects and unequal, \c false otherwise.
441 \fn BVolume& BVolume::operator=(const BVolume &volume)
442 \brief Assigns the supplied BVolume object to this volume, this object is
443 made to be an exact clone of the supplied one.
445 \param volume The volume to be assigned.
447 \return A reference to this object.