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