All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] e2fsprogs: Add memory allocation and zero-out helpers
@ 2011-05-18 11:36 Lukas Czerner
  2011-05-18 11:36 ` [PATCH 2/4 v3] e2image: Add support for qcow2 format Lukas Czerner
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Lukas Czerner @ 2011-05-18 11:36 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, sandeen, adilger, Lukas Czerner

Add functions ext2fs_get_memzero() which will malloc() the memory
using ext2fs_get_mem(), but it will zero the allocated memory afterwards
with memset().

Add function ext2fs_get_arrayzero() which will use calloc() for
allocating and zero-out the array.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 lib/ext2fs/ext2fs.h |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index d3eb31d..4aff26d 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1404,6 +1404,17 @@ _INLINE_ errcode_t ext2fs_get_memalign(unsigned long size,
 	return 0;
 }
 
+_INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr)
+{
+	errcode_t retval;
+
+	retval = ext2fs_get_mem(size, ptr);
+	if (retval)
+		return retval;
+	memset(ptr, 0, size);
+	return 0;
+}
+
 _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr)
 {
 	if (count && (-1UL)/count<size)
@@ -1411,6 +1422,19 @@ _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, voi
 	return ext2fs_get_mem(count*size, ptr);
 }
 
+_INLINE_ errcode_t ext2fs_get_arrayzero(unsigned long count, unsigned long size, void *ptr)
+{
+	void *pp;
+
+	if (count && (-1UL)/count<size)
+		return EXT2_ET_NO_MEMORY; //maybe define EXT2_ET_OVERFLOW ?
+	pp = calloc(count, size);
+	if (!pp)
+		return EXT2_ET_NO_MEMORY;
+	memcpy(ptr, &pp, sizeof (pp));
+	return 0;
+}
+
 /*
  * Free memory
  */
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-05-18 20:59 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-18 11:36 [PATCH 1/4] e2fsprogs: Add memory allocation and zero-out helpers Lukas Czerner
2011-05-18 11:36 ` [PATCH 2/4 v3] e2image: Add support for qcow2 format Lukas Czerner
2011-05-18 16:17   ` Ted Ts'o
2011-05-18 16:20     ` Lukas Czerner
2011-05-18 20:59   ` Andreas Dilger
2011-05-18 11:36 ` [PATCH 3/4 v3] e2image: Support for conversion QCOW2 image into raw Lukas Czerner
2011-05-18 12:20   ` [PATCH 3/4 v4] " Lukas Czerner
2011-05-18 16:18     ` Ted Ts'o
2011-05-18 12:23   ` [PATCH 3/4 v3] " Lukas Czerner
2011-05-18 12:22 ` [PATCH 1/4] e2fsprogs: Add memory allocation and zero-out helpers Lukas Czerner
     [not found] ` <1305718615-5991-4-git-send-email-lczerner@redhat.com>
2011-05-18 16:19   ` [PATCH 4/4 v3] tests: New i_e2image test to validate image creation/conversion Ted Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.