diff options
author | Sage Weil <sage@newdream.net> | 2010-02-02 19:11:19 -0500 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2010-02-10 18:04:39 -0500 |
commit | c7e337d6490d6f2f5e66ddf1b04d00b0dbd10108 (patch) | |
tree | 3a2e12219e38e807c71d8b2c30b89e7efbe82bdd /fs/ceph/decode.h | |
parent | 79788c698b290426320e60374ed1324e4b5c69eb (diff) |
ceph: buffer decoding helpers
Helper for decoding into a ceph_buffer, and other misc decoding helpers
we will need.
Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net>
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/decode.h')
-rw-r--r-- | fs/ceph/decode.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/fs/ceph/decode.h b/fs/ceph/decode.h index b90a33b948c7..65b3e022eaf5 100644 --- a/fs/ceph/decode.h +++ b/fs/ceph/decode.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define __CEPH_DECODE_H | 2 | #define __CEPH_DECODE_H |
3 | 3 | ||
4 | #include <asm/unaligned.h> | 4 | #include <asm/unaligned.h> |
5 | #include <linux/time.h> | ||
5 | 6 | ||
6 | #include "types.h" | 7 | #include "types.h" |
7 | 8 | ||
@@ -65,6 +66,11 @@ static inline void ceph_decode_copy(void **p, void *pv, size_t n) | |||
65 | ceph_decode_need(p, end, sizeof(u16), bad); \ | 66 | ceph_decode_need(p, end, sizeof(u16), bad); \ |
66 | v = ceph_decode_16(p); \ | 67 | v = ceph_decode_16(p); \ |
67 | } while (0) | 68 | } while (0) |
69 | #define ceph_decode_8_safe(p, end, v, bad) \ | ||
70 | do { \ | ||
71 | ceph_decode_need(p, end, sizeof(u8), bad); \ | ||
72 | v = ceph_decode_8(p); \ | ||
73 | } while (0) | ||
68 | 74 | ||
69 | #define ceph_decode_copy_safe(p, end, pv, n, bad) \ | 75 | #define ceph_decode_copy_safe(p, end, pv, n, bad) \ |
70 | do { \ | 76 | do { \ |
@@ -156,5 +162,33 @@ static inline void ceph_encode_string(void **p, void *end, | |||
156 | *p += len; | 162 | *p += len; |
157 | } | 163 | } |
158 | 164 | ||
165 | #define ceph_encode_need(p, end, n, bad) \ | ||
166 | do { \ | ||
167 | if (unlikely(*(p) + (n) > (end))) \ | ||
168 | goto bad; \ | ||
169 | } while (0) | ||
170 | |||
171 | #define ceph_encode_64_safe(p, end, v, bad) \ | ||
172 | do { \ | ||
173 | ceph_encode_need(p, end, sizeof(u64), bad); \ | ||
174 | ceph_encode_64(p, v); \ | ||
175 | } while (0) | ||
176 | #define ceph_encode_32_safe(p, end, v, bad) \ | ||
177 | do { \ | ||
178 | ceph_encode_need(p, end, sizeof(u32), bad); \ | ||
179 | ceph_encode_32(p, v); \ | ||
180 | } while (0) | ||
181 | #define ceph_encode_16_safe(p, end, v, bad) \ | ||
182 | do { \ | ||
183 | ceph_encode_need(p, end, sizeof(u16), bad); \ | ||
184 | ceph_encode_16(p, v); \ | ||
185 | } while (0) | ||
186 | |||
187 | #define ceph_encode_copy_safe(p, end, pv, n, bad) \ | ||
188 | do { \ | ||
189 | ceph_encode_need(p, end, n, bad); \ | ||
190 | ceph_encode_copy(p, pv, n); \ | ||
191 | } while (0) | ||
192 | |||
159 | 193 | ||
160 | #endif | 194 | #endif |