Message ID | 1305718615-5991-1-git-send-email-lczerner@redhat.com |
---|---|
State | Accepted, archived |
Headers | show |
On Wed, 18 May 2011, Lukas Czerner wrote: > 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. Sorry this is not right I forgot to commit my changes. Version 2 is out there. Thanks! -Lukas > > 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 > */ >
On Wed, May 18, 2011 at 01:36:55PM +0200, Lukas Czerner wrote: > This commit adds new regression test called i_e2image which should > validate expected behaviour of e2image raw and qcow2 image creation > and qcow2 -> raw image conversion. You can run it with "make check" as > the rest of regression tests. > > Testing is performed on three filesystem images with different block > sizes (1024, 2048, 4096). It creates raw and qcow2 images from the > original and then convert qcow2 image back to raw image. The results are > checksummed and compared with pre-prepared results. All md5sums should > stay the same and raw image created from original and qcow2 image should > be the same as well (just for the record). > > Signed-off-by: Lukas Czerner <lczerner@redhat.com> Applied into the e2fsprogs next branch. I had to fix up this commit so that it works when you are using a $VPATH build directory. Note that, temp files for tests should go in the current directory, and that files in the source file have to be referenced via $SRCDIR. - Ted -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 */
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(-)