1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
|
/*
*
* Copyright (c) International Business Machines Corp., 2001
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Module: readable.c
*/
#include <frontend.h>
#include <gtk/gtk.h>
#include "support.h"
#include "logging.h"
#define MB_IN_KB ((u_int64_t)1024)
#define GB_IN_KB ((u_int64_t)1024 * MB_IN_KB)
#define TB_IN_KB ((u_int64_t)1024 * GB_IN_KB)
#define PB_IN_KB ((u_int64_t)1024 * TB_IN_KB)
/*
*
* inline gchar* make_data_type_readable_string (data_type_t)
*
* Description:
* This routine takes a data type code and returns
* the string description of the data type.
*
* Entry:
* type - data type enumeration value
*
* Exit:
* Returns a pointer to a dynamically allocated string that
* describes the data type.
*
*/
inline gchar* make_data_type_readable_string (data_type_t type)
{
gchar *readable_string = NULL;
switch (type) {
case META_DATA_TYPE:
readable_string = _("Meta Data");
break;
case DATA_TYPE:
readable_string = _("Data");
break;
case FREE_SPACE_TYPE:
readable_string = _("Free Space");
break;
default:
readable_string = _("Unknown");
}
return readable_string;
}
/*
*
* inline gchar* make_unit_readable_string (value_unit_t, gboolean)
*
* Description:
* This routine takes a value unit type code and returns
* the string description of the data type. The caller can
* request a short form if available, i.e. "KB" instead of
* "kilobytes".
*
* Entry:
* unit - unit measurement enumeration value
* use_short_form - TRUE if a condensed version is preferred
*
* Exit:
* Returns a pointer to a dynamically allocated string that
* describes the unit measurement.
*
*/
inline gchar* make_unit_readable_string (value_unit_t unit, gboolean use_short_form)
{
gchar *readable_string = NULL;
switch (unit) {
case EVMS_Unit_Bytes:
readable_string = g_strdup (_("bytes"));
break;
case EVMS_Unit_Kilobytes:
if (use_short_form)
readable_string = g_strdup ("KB");
else
readable_string = g_strdup (_("kilobytes"));
break;
case EVMS_Unit_Megabytes:
if (use_short_form)
readable_string = g_strdup ("MB");
else
readable_string = g_strdup (_("megabytes"));
break;
case EVMS_Unit_Gigabytes:
if (use_short_form)
readable_string = g_strdup ("GB");
else
readable_string = g_strdup (_("gigabytes"));
break;
case EVMS_Unit_Terabytes:
if (use_short_form)
readable_string = g_strdup ("TB");
else
readable_string = g_strdup (_("terabytes"));
break;
case EVMS_Unit_Petabytes:
if (use_short_form)
readable_string = g_strdup ("PB");
else
readable_string = g_strdup (_("petabytes"));
break;
case EVMS_Unit_Sectors:
readable_string = g_strdup (_("sectors"));
break;
case EVMS_Unit_Percent:
if (use_short_form)
readable_string = g_strdup ("%");
else
readable_string = g_strdup (_("percent"));
break;
default:
log_error ("%s: Unit type %d not handled.\n", __FUNCTION__, unit);
case EVMS_Unit_None:
readable_string = NULL;
}
return readable_string;
}
/*
*
* inline gchar* make_sectors_readable_size_string (u_int64_t, value_unit_t *)
*
* Description:
* This routine takes a size in sectors and returns the
* size as a string representation in either TB, GB,
* MB, KB, or bytes. The dynamically allocated string
* should be freed by the caller with g_free() when no
* longer needed.
*
* Entry:
* size_in_sectors - the size in 512 byte sector units
* unit - address to write new unit measurement
*
* Exit:
* Returns a dynamically allocated string that expresses
* the size in a readable form. The new unit is written
* to address given by the unit parameter.
*
*/
inline gchar* make_sectors_readable_size_string (u_int64_t size_in_sectors, value_unit_t *unit)
{
gchar *readable_string = NULL;
u_int64_t size_in_kilobytes = size_in_sectors/2;
if (size_in_kilobytes >= PB_IN_KB)
{
*unit = EVMS_Unit_Petabytes;
readable_string = g_strdup_printf ("%.1f", (double)size_in_kilobytes / PB_IN_KB);
}
else if (size_in_kilobytes >= TB_IN_KB)
{
*unit = EVMS_Unit_Terabytes;
readable_string = g_strdup_printf ("%.1f", (double)size_in_kilobytes / TB_IN_KB);
}
else if (size_in_kilobytes >= GB_IN_KB)
{
*unit = EVMS_Unit_Gigabytes;
readable_string = g_strdup_printf ("%.1f", (double)size_in_kilobytes / GB_IN_KB);
}
else if (size_in_kilobytes >= MB_IN_KB)
{
*unit = EVMS_Unit_Megabytes;
readable_string = g_strdup_printf ("%.1f", (double)size_in_kilobytes / MB_IN_KB);
}
else if (size_in_sectors >= 2)
{
*unit = EVMS_Unit_Kilobytes;
readable_string = g_strdup_printf ("%llu", size_in_kilobytes);
}
else
{
*unit = EVMS_Unit_Bytes;
readable_string = g_strdup_printf ("%llu", size_in_sectors * EVMS_VSECTOR_SIZE);
}
return readable_string;
}
/*
*
* inline gchar* make_size_readable_string (gchar *, value_unit_t)
*
* Description:
* This routine takes a size string value and generates
* a new string with the unit measurement appended to it.
*
* Entry:
* size_string - the size value already converted to a string
* unit - the size's unit measurement
*
* Exit:
* Returns a dynamically allocated string that expresses
* the size in a readable form.
*
*/
inline gchar* make_size_readable_string (gchar *size_string, value_unit_t unit)
{
gchar *readable_string=NULL;
if (size_string != NULL)
{
gchar *unit_string;
unit_string = make_unit_readable_string (unit, TRUE);
readable_string = g_strjoin (" ", size_string, unit_string, NULL);
g_free (unit_string);
}
return readable_string;
}
/*
*
* inline gchar* make_sectors_readable_string (u_int64_t)
*
* Description:
* This routine takes a size in sectors and returns the
* size as a string representation in either TB, GB,
* MB, KB, or bytes. The dynamically allocated string
* should be freed by the caller with g_free() when no
* longer needed.
*
* Entry:
* size_in_sectors - the size in 512 byte sector units
*
* Exit:
* Returns a dynamically allocated string that expresses
* the size in a readable form.
*
*/
inline gchar* make_sectors_readable_string (u_int64_t size_in_sectors)
{
gchar *size_string;
gchar *readable_string = NULL;
value_unit_t unit;
size_string = make_sectors_readable_size_string (size_in_sectors, &unit);
readable_string = make_size_readable_string (size_string, unit);
if (readable_string == NULL)
readable_string = size_string;
else
g_free (size_string);
return readable_string;
}
/*
*
* inline gchar* make_kbytes_readable_string (u_int64_t)
*
* Description:
* This routine takes a size in kilobytes and returns the
* size as a string representation in either TB, GB,
* MB, or KB. The dynamically allocated string
* should be freed by the caller with g_free() when no
* longer needed.
*
* Entry:
* size_in_kbytes - the size in kbytes
*
* Exit:
* Returns a dynamically allocated string that expresses
* the size in a readable form.
*
*/
inline gchar* make_kbytes_readable_string (u_int64_t size_in_kbytes)
{
return make_sectors_readable_string (size_in_kbytes * 2);
}
/*
*
* inline void get_object_and_plugin_names (object_handle_t, gchar **, gchar **)
*
* Description:
* This routine takes an object handle and returns
* its given name and also the short name of its
* plugin. If the handle is for a plugin, the
* object_name will be the long descriptive name.
*
* Entry:
* handle - handle to the object
* object_name - address to store pointer to dynamically allocated object name
* plugin_name - address to store pointer to dynamically allocated plugin name
*
* Exit:
* Returns dynamically allocated strings that contain the
* respective names. The caller should call g_free() to free
* the memory once they are no longer needed.
*
*/
inline void get_object_and_plugin_names (object_handle_t handle, gchar **object_name, gchar **plugin_name)
{
gint rc;
handle_object_info_t *object;
g_return_if_fail (object_name != NULL);
g_return_if_fail (plugin_name != NULL);
*object_name = NULL;
*plugin_name = NULL;
rc = evms_get_info (handle, &object);
if (rc == SUCCESS)
{
plugin_handle_t plugin_handle=0;
handle_object_info_t *plugin;
switch (object->type)
{
case PLUGIN:
*object_name = g_strdup (object->info.plugin.long_name);
plugin_handle = handle;
break;
case DISK:
case SEGMENT:
case REGION:
case EVMS_OBJECT:
*object_name = g_strdup (object->info.object.name);
plugin_handle = object->info.object.plugin;
break;
case CONTAINER:
*object_name = g_strdup (object->info.container.name);
plugin_handle = object->info.container.plugin;
break;
case VOLUME:
*object_name = g_strdup (object->info.volume.name);
plugin_handle = object->info.volume.file_system_manager;
break;
default:
log_debug ("%s: Unknown object type %d.\n", __FUNCTION__, object->type);
break;
}
if (plugin_handle != 0)
{
rc = evms_get_info (plugin_handle, &plugin);
if (rc == SUCCESS)
{
*plugin_name = g_strdup (plugin->info.plugin.short_name);
evms_free (plugin);
}
}
else
{
*plugin_name = g_strdup ("Plug-in not available");
}
evms_free (object);
}
}
/*
*
* inline gchar *get_object_name (object_handle_t)
*
* Description:
* This routine takes an object handle and returns
* its given name. If the handle is for a plugin, the
* object_name will be the long descriptive name.
*
* Entry:
* handle - handle to the object
*
* Exit:
* Returns a dynamically allocated string that contains
* the objects name. The caller should call g_free() to
* free the memory once it is no longer needed. NULL
* is returned if an error retrieving the name was
* encountered.
*
*/
inline gchar *get_object_name (object_handle_t handle)
{
gint rc;
gchar *object_name=NULL;
handle_object_info_t *object;
rc = evms_get_info (handle, &object);
if (rc == SUCCESS)
{
switch (object->type)
{
case PLUGIN:
object_name = g_strdup (object->info.plugin.long_name);
break;
case DISK:
case SEGMENT:
case REGION:
case EVMS_OBJECT:
object_name = g_strdup (object->info.object.name);
break;
case CONTAINER:
object_name = g_strdup (object->info.container.name);
break;
case VOLUME:
object_name = g_strdup (object->info.volume.name);
break;
default:
log_debug ("%s: Unknown object type %d.\n", __FUNCTION__, object->type);
break;
}
evms_free (object);
}
return object_name;
}
/*
*
* inline gchar* make_object_type_readable_string (object_type_t)
*
* Description:
* This routine takes a object type code and returns
* the string description of the object type.
*
* Entry:
* type - data type enumeration value
*
* Exit:
* Returns a static string that describes the object type.
*
*/
inline gchar* make_object_type_readable_string (object_type_t type)
{
gchar *readable_string = NULL;
switch (type) {
case VOLUME:
readable_string = _("Logical Volume");
break;
case EVMS_OBJECT:
readable_string = _("Feature Object");
break;
case REGION:
readable_string = _("Storage Region");
break;
case CONTAINER:
readable_string = _("Storage Container");
break;
case SEGMENT:
readable_string = _("Disk Segment");
break;
case DISK:
readable_string = _("Logical Disk");
break;
default:
readable_string = _("Unknown");
}
return readable_string;
}
/*
*
* gchar* get_volume_fsim_name (logical_volume_info_t *)
*
* Description:
* This routine retrieves the shortname of the
* plugin identified as the filesystem interface
* manager for the volume supplied.
*
* Entry:
* volume - address of the logical_volume_info_t
*
* Exit:
* Returns a dynamically allocated string
* containing the shortname of the plugin
* or an empty string if no FSIM exists.
*
*/
gchar* get_volume_fsim_name (logical_volume_info_t *volume)
{
gint rc;
gchar *plugin_name;
handle_object_info_t *plugin;
plugin_name = g_strdup ("");
if (volume->file_system_manager != 0)
{
rc = evms_get_info (volume->file_system_manager, &plugin);
if (rc != SUCCESS)
{
log_error ("%s: evms_get_info() returned error %d.\n", __FUNCTION__, rc);
}
else
{
g_free (plugin_name);
plugin_name = g_strdup (plugin->info.plugin.short_name);
evms_free (plugin);
}
}
return plugin_name;
}
|