smart.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2009 Willem Dijkstra
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above
  12. * copyright notice, this list of conditions and the following
  13. * disclaimer in the documentation and/or other materials provided
  14. * with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  19. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  20. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  22. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  26. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. * POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. */
  30. #include <sys/types.h>
  31. #include <strings.h>
  32. #include "smart.h"
  33. /*
  34. * smart_values are rewritten to a smart_report here. This function is reused
  35. * across all platforms, as smart_values is the form the disks report the data
  36. * back in.
  37. */
  38. void
  39. smart_parse(struct smart_values *ds, struct smart_report *sr)
  40. {
  41. int i;
  42. bzero(sr, sizeof(struct smart_report));
  43. for (i = 0; i < MAX_SMART_ATTRIBUTES; i++) {
  44. switch (ds->attributes[i].id) {
  45. case ATA_ATTRIBUTE_END:
  46. /* end of attribute block reached */
  47. return;
  48. break;
  49. case ATA_ATTRIBUTE_READ_ERROR_RATE:
  50. sr->read_error_rate = ds->attributes[i].current;
  51. break;
  52. case ATA_ATTRIBUTE_REALLOCATED_SECTOR_COUNT:
  53. sr->reallocated_sectors = ds->attributes[i].current;
  54. break;
  55. case ATA_ATTRIBUTE_SPIN_RETRY_COUNT:
  56. sr->spin_retries = ds->attributes[i].current;
  57. break;
  58. case ATA_ATTRIBUTE_AIR_FLOW_TEMPERATURE:
  59. sr->air_flow_temp = ds->attributes[i].current;
  60. break;
  61. case ATA_ATTRIBUTE_TEMPERATURE:
  62. sr->temperature = ds->attributes[i].current;
  63. break;
  64. case ATA_ATTRIBUTE_REALLOCATION_EVENT_COUNT:
  65. sr->reallocations = ds->attributes[i].current;
  66. break;
  67. case ATA_ATTRIBUTE_CURRENT_PENDING_SECTOR_COUNT:
  68. sr->current_pending = ds->attributes[i].current;
  69. break;
  70. case ATA_ATTRIBUTE_UNCORRECTABLE_SECTOR_COUNT:
  71. sr->uncorrectables = ds->attributes[i].current;
  72. break;
  73. case ATA_ATTRIBUTE_SOFT_READ_ERROR_RATE:
  74. sr->soft_read_error_rate = ds->attributes[i].current;
  75. break;
  76. case ATA_ATTRIBUTE_G_SENSE_ERROR_RATE:
  77. sr->g_sense_error_rate = ds->attributes[i].current;
  78. break;
  79. case ATA_ATTRIBUTE_TEMPERATURE2:
  80. sr->temperature2 = ds->attributes[i].current;
  81. break;
  82. case ATA_ATTRIBUTE_FREE_FALL_PROTECTION:
  83. sr->free_fall_protection = ds->attributes[i].current;
  84. break;
  85. }
  86. }
  87. }