Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 320313
b: refs/heads/master
c: f8c36c5
h: refs/heads/master
i:
  320311: 8bf825e
v: v3
  • Loading branch information
Alex Elder authored and Sage Weil committed Jul 30, 2012
1 parent b65dc78 commit 21f09ee
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ad4f232f28e8059fa1de51f3127d8a6a2759ef16
refs/heads/master: f8c36c58accd5c53a472b5c289910565b3df9f9d
47 changes: 47 additions & 0 deletions trunk/include/linux/ceph/decode.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __CEPH_DECODE_H
#define __CEPH_DECODE_H

#include <linux/err.h>
#include <linux/bug.h>
#include <linux/time.h>
#include <asm/unaligned.h>
Expand Down Expand Up @@ -84,6 +85,52 @@ static inline int ceph_has_room(void **p, void *end, size_t n)
ceph_decode_copy(p, pv, n); \
} while (0)

/*
* Allocate a buffer big enough to hold the wire-encoded string, and
* decode the string into it. The resulting string will always be
* terminated with '\0'. If successful, *p will be advanced
* past the decoded data. Also, if lenp is not a null pointer, the
* length (not including the terminating '\0') will be recorded in
* *lenp. Note that a zero-length string is a valid return value.
*
* Returns a pointer to the newly-allocated string buffer, or a
* pointer-coded errno if an error occurs. Neither *p nor *lenp
* will have been updated if an error is returned.
*
* There are two possible failures:
* - converting the string would require accessing memory at or
* beyond the "end" pointer provided (-E
* - memory could not be allocated for the result
*/
static inline char *ceph_extract_encoded_string(void **p, void *end,
size_t *lenp, gfp_t gfp)
{
u32 len;
void *sp = *p;
char *buf;

ceph_decode_32_safe(&sp, end, len, bad);
if (!ceph_has_room(&sp, end, len))
goto bad;

buf = kmalloc(len + 1, gfp);
if (!buf)
return ERR_PTR(-ENOMEM);

if (len)
memcpy(buf, sp, len);
buf[len] = '\0';

*p = (char *) *p + sizeof (u32) + len;
if (lenp)
*lenp = (size_t) len;

return buf;

bad:
return ERR_PTR(-ERANGE);
}

/*
* struct ceph_timespec <-> struct timespec
*/
Expand Down

0 comments on commit 21f09ee

Please sign in to comment.