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 /************************************************************************/
21 /* PROJECT : exFAT & FAT12/16/32 File System */
22 /* FILE : exfat_global.c */
23 /* PURPOSE : exFAT Miscellaneous Functions */
25 /*----------------------------------------------------------------------*/
28 /*----------------------------------------------------------------------*/
29 /* REVISION HISTORY (Ver 0.9) */
31 /* - 2010.11.15 [Joosun Hahn] : first writing */
33 /************************************************************************/
35 #include "exfat_config.h"
36 #include "exfat_global.h"
38 /*----------------------------------------------------------------------*/
39 /* Global Variable Definitions */
40 /*----------------------------------------------------------------------*/
42 /*======================================================================*/
44 /* LIBRARY FUNCTION DEFINITIONS -- WELL-KNOWN FUNCTIONS */
46 /*======================================================================*/
48 /*----------------------------------------------------------------------*/
49 /* String Manipulation Functions */
50 /* (defined if no system memory functions are available) */
51 /*----------------------------------------------------------------------*/
53 INT32
__wstrchr(UINT16
*str
, UINT16 wchar
)
56 if (*(str
++) == wchar
) return(1);
61 INT32
__wstrlen(UINT16
*str
)
65 while (*(str
++)) length
++;
69 /*======================================================================*/
71 /* LIBRARY FUNCTION DEFINITIONS -- OTHER UTILITY FUNCTIONS */
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
)
96 data
= bitmap
[BITMAP_LOC(i
)];
97 if ((data
>> BITMAP_SHIFT(i
)) & 0x01) return(1);
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
)
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
)
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
)
139 for (i
= 0; i
< 10; i
++) {
148 for (; i
>= 0; i
--) {
149 *buf
= (UINT8
) ('0' + mod
[i
]);
153 } /* end of my_itoa */
155 /* value to base 2 log conversion */
156 INT32
my_log2(UINT32 v
)
161 if (v
& 0x01) return(-1);
166 } /* end of my_log2 */
168 /* end of exfat_global.c */