tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / fs / exfat / exfat_global.c
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
19 #include "exfat_config.h"
20 #include "exfat_global.h"
21
22 INT32 __wstrchr(UINT16 *str, UINT16 wchar)
23 {
24         while (*str) {
25                 if (*(str++) == wchar) return(1);
26         }
27         return(0);
28 }
29
30 INT32 __wstrlen(UINT16 *str)
31 {
32         INT32 length = 0;
33
34         while (*(str++)) length++;
35         return(length);
36 }
37
38 #define BITMAP_LOC(v)           ((v) >> 3)
39 #define BITMAP_SHIFT(v)         ((v) & 0x07)
40
41 void Bitmap_set_all(UINT8 *bitmap, INT32 mapsize)
42 {
43         MEMSET(bitmap, 0xFF, mapsize);
44 }
45
46 void Bitmap_clear_all(UINT8 *bitmap, INT32 mapsize)
47 {
48         MEMSET(bitmap, 0x0, mapsize);
49 }
50
51 INT32 Bitmap_test(UINT8 *bitmap, INT32 i)
52 {
53         UINT8 data;
54
55         data = bitmap[BITMAP_LOC(i)];
56         if ((data >> BITMAP_SHIFT(i)) & 0x01) return(1);
57         return(0);
58 }
59
60 void Bitmap_set(UINT8 *bitmap, INT32 i)
61 {
62         bitmap[BITMAP_LOC(i)] |= (0x01 << BITMAP_SHIFT(i));
63 }
64
65 void Bitmap_clear(UINT8 *bitmap, INT32 i)
66 {
67         bitmap[BITMAP_LOC(i)] &= ~(0x01 << BITMAP_SHIFT(i));
68 }
69
70 void Bitmap_nbits_set(UINT8 *bitmap, INT32 offset, INT32 nbits)
71 {
72         INT32   i;
73
74         for (i = 0; i < nbits; i++) {
75                 Bitmap_set(bitmap, offset+i);
76         }
77 }
78
79 void Bitmap_nbits_clear(UINT8 *bitmap, INT32 offset, INT32 nbits)
80 {
81         INT32   i;
82
83         for (i = 0; i < nbits; i++) {
84                 Bitmap_clear(bitmap, offset+i);
85         }
86 }
87
88 void my_itoa(INT8 *buf, INT32 v)
89 {
90         INT32 mod[10];
91         INT32 i;
92
93         for (i = 0; i < 10; i++) {
94                 mod[i] = (v % 10);
95                 v = v / 10;
96                 if (v == 0) break;
97         }
98
99         if (i == 10)
100                 i--;
101
102         for (; i >= 0; i--) {
103                 *buf = (UINT8) ('0' + mod[i]);
104                 buf++;
105         }
106         *buf = '\0';
107 }
108
109 INT32 my_log2(UINT32 v)
110 {
111         UINT32 bits = 0;
112
113         while (v > 1) {
114                 if (v & 0x01) return(-1);
115                 v >>= 1;
116                 bits++;
117         }
118         return(bits);
119 }