exfat_global.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #include "exfat_config.h"
  19. #include "exfat_global.h"
  20. INT32 __wstrchr(UINT16 *str, UINT16 wchar)
  21. {
  22. while (*str) {
  23. if (*(str++) == wchar) return(1);
  24. }
  25. return(0);
  26. }
  27. INT32 __wstrlen(UINT16 *str)
  28. {
  29. INT32 length = 0;
  30. while (*(str++)) length++;
  31. return(length);
  32. }
  33. #define BITMAP_LOC(v) ((v) >> 3)
  34. #define BITMAP_SHIFT(v) ((v) & 0x07)
  35. void Bitmap_set_all(UINT8 *bitmap, INT32 mapsize)
  36. {
  37. MEMSET(bitmap, 0xFF, mapsize);
  38. }
  39. void Bitmap_clear_all(UINT8 *bitmap, INT32 mapsize)
  40. {
  41. MEMSET(bitmap, 0x0, mapsize);
  42. }
  43. INT32 Bitmap_test(UINT8 *bitmap, INT32 i)
  44. {
  45. UINT8 data;
  46. data = bitmap[BITMAP_LOC(i)];
  47. if ((data >> BITMAP_SHIFT(i)) & 0x01) return(1);
  48. return(0);
  49. }
  50. void Bitmap_set(UINT8 *bitmap, INT32 i)
  51. {
  52. bitmap[BITMAP_LOC(i)] |= (0x01 << BITMAP_SHIFT(i));
  53. }
  54. void Bitmap_clear(UINT8 *bitmap, INT32 i)
  55. {
  56. bitmap[BITMAP_LOC(i)] &= ~(0x01 << BITMAP_SHIFT(i));
  57. }
  58. void Bitmap_nbits_set(UINT8 *bitmap, INT32 offset, INT32 nbits)
  59. {
  60. INT32 i;
  61. for (i = 0; i < nbits; i++) {
  62. Bitmap_set(bitmap, offset+i);
  63. }
  64. }
  65. void Bitmap_nbits_clear(UINT8 *bitmap, INT32 offset, INT32 nbits)
  66. {
  67. INT32 i;
  68. for (i = 0; i < nbits; i++) {
  69. Bitmap_clear(bitmap, offset+i);
  70. }
  71. }
  72. void my_itoa(INT8 *buf, INT32 v)
  73. {
  74. INT32 mod[10];
  75. INT32 i;
  76. for (i = 0; i < 10; i++) {
  77. mod[i] = (v % 10);
  78. v = v / 10;
  79. if (v == 0) break;
  80. }
  81. if (i == 10)
  82. i--;
  83. for (; i >= 0; i--) {
  84. *buf = (UINT8) ('0' + mod[i]);
  85. buf++;
  86. }
  87. *buf = '\0';
  88. }
  89. INT32 my_log2(UINT32 v)
  90. {
  91. UINT32 bits = 0;
  92. while (v > 1) {
  93. if (v & 0x01) return(-1);
  94. v >>= 1;
  95. bits++;
  96. }
  97. return(bits);
  98. }