2 * Copyright (c) 2005 Zmanda, Inc. All Rights Reserved.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 2.1 as
6 * published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 * License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120
18 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
25 static const GEnumValue _concurrency_paradigm_values[] = {
26 { CONCURRENCY_PARADIGM_EXCLUSIVE,
27 "CONCURRENCY_PARADIGM_EXCLUSIVE",
29 { CONCURRENCY_PARADIGM_SHARED_READ,
30 "CONCURRENCY_PARADIGM_SHARED_READ",
32 { CONCURRENCY_PARADIGM_RANDOM_ACCESS,
33 "CONCURRENCY_PARADIGM_RANDOM_ACCESS",
38 GType concurrency_paradigm_get_type (void) {
39 static GType type = 0;
40 if (G_UNLIKELY(type == 0)) {
41 type = g_enum_register_static ("ConcurrencyParadigm",
42 _concurrency_paradigm_values);
47 static const GEnumValue _streaming_requirement_values[] = {
48 { STREAMING_REQUIREMENT_NONE,
49 "STREAMING_REQUIREMENT_NONE",
51 { STREAMING_REQUIREMENT_DESIRED,
52 "STREAMING_REQUIREMENT_DESIRED",
54 { STREAMING_REQUIREMENT_REQUIRED,
55 "STREAMING_REQUIREMENT_REQUIRED",
60 GType streaming_requirement_get_type (void) {
61 static GType type = 0;
62 if (G_UNLIKELY(type == 0)) {
63 type = g_enum_register_static ("StreamingRequirement",
64 _streaming_requirement_values);
69 static const GEnumValue _media_access_mode_values[] = {
70 { MEDIA_ACCESS_MODE_READ_ONLY,
71 "MEDIA_ACCESS_MODE_READ_ONLY",
72 (char *)"read-only" },
73 { MEDIA_ACCESS_MODE_WORM,
74 "MEDIA_ACCESS_MODE_WORM",
75 (char *)"write-once-read-many" },
76 { MEDIA_ACCESS_MODE_READ_WRITE,
77 "MEDIA_ACCESS_MODE_READ_WRITE",
78 (char *)"read-write" },
79 { MEDIA_ACCESS_MODE_WRITE_ONLY,
80 "MEDIA_ACCESS_MODE_WRITE_ONLY",
81 (char *)"write-many-read-never" },
85 GType media_access_mode_get_type (void) {
86 static GType type = 0;
87 if (G_UNLIKELY(type == 0)) {
88 type = g_enum_register_static ("MediaAccessMode",
89 _media_access_mode_values);
94 /* Copy function for GBoxed QualifiedSize. */
95 static gpointer qualified_size_copy(gpointer source) {
96 gpointer rval = malloc(sizeof(QualifiedSize));
97 memcpy(rval, source, sizeof(QualifiedSize));
101 GType qualified_size_get_type (void) {
102 static GType type = 0;
103 if (G_UNLIKELY(type == 0)) {
104 type = g_boxed_type_register_static ("QualifiedSize",
111 static const GFlagsValue _feature_support_flags_values[] = {
112 { FEATURE_STATUS_ENABLED,
113 "FEATURE_STATUS_ENABLED",
115 { FEATURE_STATUS_DISABLED,
116 "FEATURE_STATUS_DISABLED",
118 { FEATURE_SURETY_BAD,
119 "FEATURE_SURETY_BAD",
121 { FEATURE_SURETY_GOOD,
122 "FEATURE_SURETY_GOOD",
124 { FEATURE_SOURCE_DEFAULT,
125 "FEATURE_SOURCE_DEFAULT",
127 { FEATURE_SOURCE_DETECTED,
128 "FEATURE_SOURCE_DETECTED",
130 { FEATURE_SOURCE_USER,
131 "FEATURE_SOURCE_USER",
136 GType feature_support_get_type (void) {
137 static GType type = 0;
138 if (G_UNLIKELY(type == 0)) {
139 type = g_flags_register_static ("FeatureSupportFlags",
140 _feature_support_flags_values);
145 gboolean feature_support_flags_is_valid(FeatureSupportFlags f) {
146 int status = 0, surety = 0, source = 0;
148 if (f & FEATURE_STATUS_ENABLED)
150 if (f & FEATURE_STATUS_DISABLED)
152 if (f & FEATURE_SURETY_BAD)
154 if (f & FEATURE_SURETY_GOOD)
156 if (f & FEATURE_SOURCE_DEFAULT)
158 if (f & FEATURE_SOURCE_DETECTED)
160 if (f & FEATURE_SOURCE_USER)
163 return (!(f & ~FEATURE_SUPPORT_FLAGS_MASK) &&
164 status == 1 && surety == 1 && source == 1);
167 static GSList* device_property_base_list = NULL;
169 const DevicePropertyBase* device_property_get_by_id(DevicePropertyId id) {
172 iter = device_property_base_list;
173 while (iter != NULL) {
174 DevicePropertyBase* rval = (DevicePropertyBase*)(iter->data);
175 if (rval->ID == id) {
178 iter = g_slist_next(iter);
184 const DevicePropertyBase* device_property_get_by_name(const char *name) {
185 GSList *iter = device_property_base_list;
187 g_return_val_if_fail(name != NULL, NULL);
189 while (iter != NULL) {
190 DevicePropertyBase* rval = (DevicePropertyBase*)(iter->data);
191 if (strcasecmp(rval->name, name) == 0) {
194 iter = g_slist_next(iter);
200 DevicePropertyId device_property_register(DevicePropertyBase* base) {
202 g_assert(base != NULL);
203 g_assert(base->ID == -1);
204 g_assert(base->name != NULL);
205 g_assert(base->description != NULL);
209 device_property_base_list = g_slist_prepend(device_property_base_list,
214 /* Does the same thing, but fills in a new DevicePropertyBase. */
216 device_property_fill_and_register(DevicePropertyBase * base,
222 base->description = desc;
224 device_property_register(base);
228 void device_property_init(void) {
229 device_property_fill_and_register(&device_property_concurrency,
230 CONCURRENCY_PARADIGM_TYPE, "concurrency",
231 "Supported concurrency mode (none, multiple readers, multiple writers)");
232 device_property_fill_and_register(&device_property_streaming,
233 STREAMING_REQUIREMENT_TYPE, "streaming",
234 "Streaming desirability (unnecessary, desired, required)");
235 device_property_fill_and_register(&device_property_compression,
236 G_TYPE_BOOLEAN, "compression",
237 "Is device performing data compression?");
238 device_property_fill_and_register(&device_property_compression_rate,
239 G_TYPE_DOUBLE, "compression_rate",
241 "averaged for some (currently undefined) period of time)");
242 device_property_fill_and_register(&device_property_block_size,
243 G_TYPE_INT, "block_size",
244 "Device blocking factor in bytes.");
245 device_property_fill_and_register(&device_property_min_block_size,
246 G_TYPE_UINT, "min_block_size",
247 "Minimum supported blocking factor.");
248 device_property_fill_and_register(&device_property_max_block_size,
249 G_TYPE_UINT, "max_block_size",
250 "Maximum supported blocking factor.");
251 device_property_fill_and_register(&device_property_appendable,
252 G_TYPE_BOOLEAN, "appendable",
253 "Does device support appending to previously-written media?");
254 device_property_fill_and_register(&device_property_canonical_name,
255 G_TYPE_STRING, "canonical_name",
256 "The most reliable device name to use to refer to this device.");
257 device_property_fill_and_register(&device_property_medium_access_type,
258 MEDIA_ACCESS_MODE_TYPE,
259 "medium_access_type",
260 "What kind of media (RO/WORM/RW/WORN) do we have here?");
261 device_property_fill_and_register(&device_property_partial_deletion,
262 G_TYPE_BOOLEAN, "partial_deletion",
263 "Does this device support recycling just part of a volume?" );
264 device_property_fill_and_register(&device_property_free_space,
265 QUALIFIED_SIZE_TYPE, "free_space",
266 "Remaining capacity of the device.");
267 device_property_fill_and_register(&device_property_max_volume_usage,
268 G_TYPE_UINT64, "max_volume_usage",
269 "Artificial limit to data written to volume.");
270 device_property_fill_and_register(&device_property_fsf,
271 FEATURE_SUPPORT_FLAGS_TYPE, "fsf",
272 "Does this drive support the MTFSF command?");
273 device_property_fill_and_register(&device_property_bsf,
274 FEATURE_SUPPORT_FLAGS_TYPE, "bsf",
275 "Does this drive support the MTBSF command?" );
276 device_property_fill_and_register(&device_property_fsr,
277 FEATURE_SUPPORT_FLAGS_TYPE, "fsr",
278 "Does this drive support the MTFSR command?");
279 device_property_fill_and_register(&device_property_bsr,
280 FEATURE_SUPPORT_FLAGS_TYPE, "bsr",
281 "Does this drive support the MTBSR command?");
282 /* FIXME: Is this feature even useful? */
283 device_property_fill_and_register(&device_property_eom,
284 FEATURE_SUPPORT_FLAGS_TYPE, "eom",
285 "Does this drive support the MTEOM command?");
286 device_property_fill_and_register(&device_property_bsf_after_eom,
287 FEATURE_SUPPORT_FLAGS_TYPE,
289 "Does this drive require an MTBSF after MTEOM in order to append?" );
290 device_property_fill_and_register(&device_property_final_filemarks,
291 G_TYPE_UINT, "final_filemarks",
292 "How many filemarks to write after the last tape file?" );
293 device_property_fill_and_register(&device_property_read_buffer_size,
294 G_TYPE_UINT, "read_buffer_size",
295 "What buffer size should be used for reading?");
296 device_property_fill_and_register(&device_property_s3_secret_key,
297 G_TYPE_STRING, "s3_secret_key",
298 "Secret access key to authenticate with Amazon S3");
299 device_property_fill_and_register(&device_property_s3_access_key,
300 G_TYPE_STRING, "s3_access_key",
301 "Access key ID to authenticate with Amazon S3");
303 device_property_fill_and_register(&device_property_s3_user_token,
304 G_TYPE_STRING, "s3_user_token",
305 "User token for authentication Amazon devpay requests");
307 device_property_fill_and_register(&device_property_verbose,
308 G_TYPE_BOOLEAN, "verbose",
309 "Should the device produce verbose output?");
312 DevicePropertyBase device_property_concurrency;
313 DevicePropertyBase device_property_streaming;
314 DevicePropertyBase device_property_compression;
315 DevicePropertyBase device_property_compression_rate;
316 DevicePropertyBase device_property_block_size;
317 DevicePropertyBase device_property_min_block_size;
318 DevicePropertyBase device_property_max_block_size;
319 DevicePropertyBase device_property_appendable;
320 DevicePropertyBase device_property_canonical_name;
321 DevicePropertyBase device_property_medium_access_type;
322 DevicePropertyBase device_property_partial_deletion;
323 DevicePropertyBase device_property_free_space;
324 DevicePropertyBase device_property_max_volume_usage;
325 DevicePropertyBase device_property_fsf;
326 DevicePropertyBase device_property_bsf;
327 DevicePropertyBase device_property_fsr;
328 DevicePropertyBase device_property_bsr;
329 DevicePropertyBase device_property_eom;
330 DevicePropertyBase device_property_bsf_after_eom;
331 DevicePropertyBase device_property_final_filemarks;
332 DevicePropertyBase device_property_read_buffer_size;
333 DevicePropertyBase device_property_s3_access_key;
334 DevicePropertyBase device_property_s3_secret_key;
335 DevicePropertyBase device_property_s3_user_token;
336 DevicePropertyBase device_property_verbose;