{FULLFAT]
[reactos.git] / reactos / include / reactos / libs / fullfat / ff_memory.h
1 /*****************************************************************************
2 * FullFAT - High Performance, Thread-Safe Embedded FAT File-System *
3 * Copyright (C) 2009 James Walmsley (james@worm.me.uk) *
4 * *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 * *
18 * IMPORTANT NOTICE: *
19 * ================= *
20 * Alternative Licensing is available directly from the Copyright holder, *
21 * (James Walmsley). For more information consult LICENSING.TXT to obtain *
22 * a Commercial license. *
23 * *
24 * See RESTRICTIONS.TXT for extra restrictions on the use of FullFAT. *
25 * *
26 * Removing the above notice is illegal and will invalidate this license. *
27 *****************************************************************************
28 * See http://worm.me.uk/fullfat for more information. *
29 * Or http://fullfat.googlecode.com/ for latest releases and the wiki. *
30 *****************************************************************************/
31
32 /**
33 * @file ff_memory.h
34 * @author James Walmsley
35 * @ingroup MEMORY
36 **/
37
38 #ifndef _FF_MEMORY_H_
39 #define _FF_MEMORY_H_
40
41 #include "ff_config.h"
42 #include "ff_types.h"
43
44 /*
45 HT changed type of aOffset to u32
46 */
47 //---------- PROTOTYPES
48
49 #if defined(FF_LITTLE_ENDIAN)
50
51 typedef struct {
52 FF_T_UINT8 u8_0;
53 FF_T_UINT8 u8_1;
54 } FF_T_SHORT;
55
56 typedef struct {
57 FF_T_UINT8 u8_0;
58 FF_T_UINT8 u8_1;
59 FF_T_UINT8 u8_2;
60 FF_T_UINT8 u8_3;
61 } FF_T_LONG;
62
63 #elif defined(FF_BIG_ENDIAN)
64
65 typedef struct {
66 FF_T_UINT8 u8_1;
67 FF_T_UINT8 u8_0;
68 } FF_T_SHORT;
69
70 typedef struct {
71 FF_T_UINT8 u8_3;
72 FF_T_UINT8 u8_2;
73 FF_T_UINT8 u8_1;
74 FF_T_UINT8 u8_0;
75 } FF_T_LONG;
76
77 #else
78
79 #error Little or Big Endian?
80
81 #endif
82
83 //! 16-bit union.
84 typedef union {
85 FF_T_UINT16 u16;
86 FF_T_SHORT bytes;
87 } FF_T_UN16;
88
89 //! 32-bit union.
90 typedef union {
91 FF_T_UINT32 u32;
92 FF_T_LONG bytes;
93 } FF_T_UN32;
94
95 /* HT inlined these functions:
96 */
97
98 #ifdef FF_INLINE_MEMORY_ACCESS
99
100 FF_INLINE FF_T_UINT8 FF_getChar(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset)
101 {
102 return (FF_T_UINT8) (pBuffer[aOffset]);
103 }
104
105 FF_INLINE FF_T_UINT16 FF_getShort(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset)
106 {
107 FF_T_UN16 u16;
108 pBuffer += aOffset;
109 u16.bytes.u8_1 = pBuffer[1];
110 u16.bytes.u8_0 = pBuffer[0];
111 return u16.u16;
112 }
113
114 FF_INLINE FF_T_UINT32 FF_getLong(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset) {
115 FF_T_UN32 u32;
116 pBuffer += aOffset;
117 u32.bytes.u8_3 = pBuffer[3];
118 u32.bytes.u8_2 = pBuffer[2];
119 u32.bytes.u8_1 = pBuffer[1];
120 u32.bytes.u8_0 = pBuffer[0];
121 return u32.u32;
122 }
123
124 FF_INLINE void FF_putChar(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset, FF_T_UINT8 Value) {
125 pBuffer[aOffset] = Value;
126 }
127
128 FF_INLINE void FF_putShort(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset, FF_T_UINT16 Value) {
129 FF_T_UN16 u16;
130 u16.u16 = Value;
131 pBuffer += aOffset;
132 pBuffer[0] = u16.bytes.u8_0;
133 pBuffer[1] = u16.bytes.u8_1;
134 }
135
136 FF_INLINE void FF_putLong(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset, FF_T_UINT32 Value) {
137 FF_T_UN32 u32;
138 u32.u32 = Value;
139 pBuffer += aOffset;
140 pBuffer[0] = u32.bytes.u8_0;
141 pBuffer[1] = u32.bytes.u8_1;
142 pBuffer[2] = u32.bytes.u8_2;
143 pBuffer[3] = u32.bytes.u8_3;
144 }
145
146 #else
147
148 FF_T_UINT8 FF_getChar(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset);
149 FF_T_UINT16 FF_getShort(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset);
150 FF_T_UINT32 FF_getLong(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset);
151 void FF_putChar(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset, FF_T_UINT8 Value);
152 void FF_putShort(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset, FF_T_UINT16 Value);
153 void FF_putLong(FF_T_UINT8 *pBuffer, FF_T_UINT32 aOffset, FF_T_UINT32 Value);
154
155
156 #endif
157
158 #endif
159