X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=yaffs_nameval.c;h=4bdf4ed743a7195dca0e3af8ac7775801b96b42c;hp=8d0fa4e565ed11f6157ac91f165ba3da30a710be;hb=33308768bd24abe4e1f59c5025a3dd824119ae1d;hpb=6500cebaa2c93512d544719956af259ca13f83b7 diff --git a/yaffs_nameval.c b/yaffs_nameval.c index 8d0fa4e..4bdf4ed 100644 --- a/yaffs_nameval.c +++ b/yaffs_nameval.c @@ -1,7 +1,7 @@ /* * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. * - * Copyright (C) 2002-2010 Aleph One Ltd. + * Copyright (C) 2002-2011 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering * * Created by Charles Manning @@ -37,7 +37,8 @@ static int nval_find(const char *xb, int xb_size, const YCHAR *name, memcpy(&size, xb, sizeof(int)); while (size > 0 && (size < xb_size) && (pos + size < xb_size)) { - if (!strncmp((YCHAR *) (xb + pos + sizeof(int)), name, size)) { + if (!strncmp((YCHAR *) (xb + pos + sizeof(int)), + name, size)) { if (exist_size) *exist_size = size; return pos; @@ -50,7 +51,7 @@ static int nval_find(const char *xb, int xb_size, const YCHAR *name, } if (exist_size) *exist_size = 0; - return -1; + return -ENODATA; } static int nval_used(const char *xb, int xb_size) @@ -74,16 +75,15 @@ int nval_del(char *xb, int xb_size, const YCHAR *name) int pos = nval_find(xb, xb_size, name, NULL); int size; - if (pos >= 0 && pos < xb_size) { - /* Find size, shift rest over this record, - * then zero out the rest of buffer */ - memcpy(&size, xb + pos, sizeof(int)); - memcpy(xb + pos, xb + pos + size, xb_size - (pos + size)); - memset(xb + (xb_size - size), 0, size); - return 0; - } else { + if (pos < 0 || pos >= xb_size) return -ENODATA; - } + + /* Find size, shift rest over this record, + * then zero out the rest of buffer */ + memcpy(&size, xb + pos, sizeof(int)); + memcpy(xb + pos, xb + pos + size, xb_size - (pos + size)); + memset(xb + (xb_size - size), 0, size); + return 0; } int nval_set(char *xb, int xb_size, const YCHAR *name, const char *buf, @@ -147,6 +147,12 @@ int nval_get(const char *xb, int xb_size, const YCHAR * name, char *buf, pos++; size--; + /* If bsize is zero then this is a size query. + * Return the size, but don't copy. + */ + if (!bsize) + return size; + if (size <= bsize) { memcpy(buf, xb + pos, size); return size;