CD exfat support for Tomato. https://github.com/dorimanx/exfat-nofuse.
[tomato.git] / release / src-rt / linux / linux-2.6 / fs / exfat / exfat_global.c
blob036f08eb0a94d6365ea5800de27413fe0ca75a2e
1 /*
2 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
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.
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.
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.
19 /************************************************************************/
20 /* */
21 /* PROJECT : exFAT & FAT12/16/32 File System */
22 /* FILE : exfat_global.c */
23 /* PURPOSE : exFAT Miscellaneous Functions */
24 /* */
25 /*----------------------------------------------------------------------*/
26 /* NOTES */
27 /* */
28 /*----------------------------------------------------------------------*/
29 /* REVISION HISTORY (Ver 0.9) */
30 /* */
31 /* - 2010.11.15 [Joosun Hahn] : first writing */
32 /* */
33 /************************************************************************/
35 #include "exfat_config.h"
36 #include "exfat_global.h"
38 /*----------------------------------------------------------------------*/
39 /* Global Variable Definitions */
40 /*----------------------------------------------------------------------*/
42 /*======================================================================*/
43 /* */
44 /* LIBRARY FUNCTION DEFINITIONS -- WELL-KNOWN FUNCTIONS */
45 /* */
46 /*======================================================================*/
48 /*----------------------------------------------------------------------*/
49 /* String Manipulation Functions */
50 /* (defined if no system memory functions are available) */
51 /*----------------------------------------------------------------------*/
53 INT32 __wstrchr(UINT16 *str, UINT16 wchar)
55 while (*str) {
56 if (*(str++) == wchar) return(1);
58 return(0);
61 INT32 __wstrlen(UINT16 *str)
63 INT32 length = 0;
65 while (*(str++)) length++;
66 return(length);
69 /*======================================================================*/
70 /* */
71 /* LIBRARY FUNCTION DEFINITIONS -- OTHER UTILITY FUNCTIONS */
72 /* */
73 /*======================================================================*/
75 /*----------------------------------------------------------------------*/
76 /* Bitmap Manipulation Functions */
77 /*----------------------------------------------------------------------*/
79 #define BITMAP_LOC(v) ((v) >> 3)
80 #define BITMAP_SHIFT(v) ((v) & 0x07)
82 void Bitmap_set_all(UINT8 *bitmap, INT32 mapsize)
84 MEMSET(bitmap, 0xFF, mapsize);
85 } /* end of Bitmap_set_all */
87 void Bitmap_clear_all(UINT8 *bitmap, INT32 mapsize)
89 MEMSET(bitmap, 0x0, mapsize);
90 } /* end of Bitmap_clear_all */
92 INT32 Bitmap_test(UINT8 *bitmap, INT32 i)
94 UINT8 data;
96 data = bitmap[BITMAP_LOC(i)];
97 if ((data >> BITMAP_SHIFT(i)) & 0x01) return(1);
98 return(0);
99 } /* end of Bitmap_test */
101 void Bitmap_set(UINT8 *bitmap, INT32 i)
103 bitmap[BITMAP_LOC(i)] |= (0x01 << BITMAP_SHIFT(i));
104 } /* end of Bitmap_set */
106 void Bitmap_clear(UINT8 *bitmap, INT32 i)
108 bitmap[BITMAP_LOC(i)] &= ~(0x01 << BITMAP_SHIFT(i));
109 } /* end of Bitmap_clear */
111 void Bitmap_nbits_set(UINT8 *bitmap, INT32 offset, INT32 nbits)
113 INT32 i;
115 for (i = 0; i < nbits; i++) {
116 Bitmap_set(bitmap, offset+i);
118 } /* end of Bitmap_nbits_set */
120 void Bitmap_nbits_clear(UINT8 *bitmap, INT32 offset, INT32 nbits)
122 INT32 i;
124 for (i = 0; i < nbits; i++) {
125 Bitmap_clear(bitmap, offset+i);
127 } /* end of Bitmap_nbits_clear */
129 /*----------------------------------------------------------------------*/
130 /* Miscellaneous Library Functions */
131 /*----------------------------------------------------------------------*/
133 /* integer to ascii conversion */
134 void my_itoa(INT8 *buf, INT32 v)
136 INT32 mod[10];
137 INT32 i;
139 for (i = 0; i < 10; i++) {
140 mod[i] = (v % 10);
141 v = v / 10;
142 if (v == 0) break;
145 if (i == 10)
146 i--;
148 for (; i >= 0; i--) {
149 *buf = (UINT8) ('0' + mod[i]);
150 buf++;
152 *buf = '\0';
153 } /* end of my_itoa */
155 /* value to base 2 log conversion */
156 INT32 my_log2(UINT32 v)
158 UINT32 bits = 0;
160 while (v > 1) {
161 if (v & 0x01) return(-1);
162 v >>= 1;
163 bits++;
165 return(bits);
166 } /* end of my_log2 */
168 /* end of exfat_global.c */