drivers/ramdisk.c and include/nuttx/fs/ramdisk.h: Add logic to dispose of the drvier and RAM buffer when the RAM disk has been unlinked and all open references to the RAM disk have been closed. Add new parameters to romdisk() to specify what should be done with the RAM/ROM buffer -- Should it be freed or not? Changed all calls to ramdisk() to use these new parameters.
This commit is contained in:
parent
d8561fbcae
commit
b15632e8ba
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_blockdevice.c
|
||||
*
|
||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -84,5 +84,6 @@
|
||||
|
||||
void up_registerblockdevice(void)
|
||||
{
|
||||
ramdisk_register(0, (uint8_t*)up_deviceimage(), NSECTORS, LOGICAL_SECTOR_SIZE, true);
|
||||
ramdisk_register(0, (uint8_t*)up_deviceimage(), NSECTORS,
|
||||
LOGICAL_SECTOR_SIZE, RDFLAG_WRENABLED | RDFLAG_FUNLINK);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/up_deviceimage.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2009, 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -213,7 +213,7 @@ char *up_deviceimage(void)
|
||||
z_stream strm;
|
||||
int ret;
|
||||
|
||||
/* Ininitilize inflate state */
|
||||
/* Initialize inflate state */
|
||||
|
||||
strm.zalloc = Z_NULL;
|
||||
strm.zfree = Z_NULL;
|
||||
@ -223,12 +223,13 @@ char *up_deviceimage(void)
|
||||
ret = inflateInit(&strm);
|
||||
if (ret != Z_OK)
|
||||
{
|
||||
sdbg("inflateInit FAILED: ret=%d msg=\"%s\"\n", ret, strm.msg ? strm.msg : "No message" );
|
||||
sdbg("inflateInit FAILED: ret=%d msg=\"%s\"\n",
|
||||
ret, strm.msg ? strm.msg : "No message" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Allocate a buffer to hold the decompressed buffer. We may have
|
||||
* to reallocate this a few times to get the size right.
|
||||
/* Allocate a buffer to hold the decompressed buffer. We may have to
|
||||
* reallocate this a few times to get the size right.
|
||||
*/
|
||||
|
||||
pbuffer = (char*)kmm_malloc(bufsize);
|
||||
@ -240,7 +241,8 @@ char *up_deviceimage(void)
|
||||
|
||||
/* Run inflate() on input until output buffer not full */
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
/* Set up to catch the next output chunk in the output buffer */
|
||||
|
||||
strm.avail_out = bufsize - offset;
|
||||
@ -258,15 +260,16 @@ char *up_deviceimage(void)
|
||||
case Z_DATA_ERROR:
|
||||
case Z_MEM_ERROR:
|
||||
case Z_STREAM_ERROR:
|
||||
sdbg("inflate FAILED: ret=%d msg=\"%s\"\n", ret, strm.msg ? strm.msg : "No message" );
|
||||
sdbg("inflate FAILED: ret=%d msg=\"%s\"\n",
|
||||
ret, strm.msg ? strm.msg : "No message" );
|
||||
(void)inflateEnd(&strm);
|
||||
kmm_free(pbuffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If avail_out is zero, then inflate() returned only
|
||||
* because it is out of buffer space. In this case, we
|
||||
* will have to reallocate the buffer and try again.
|
||||
/* If avail_out is zero, then inflate() returned only because it is
|
||||
* out of buffer space. In this case, we will have to reallocate
|
||||
* the buffer and try again.
|
||||
*/
|
||||
|
||||
if (strm.avail_out == 0)
|
||||
@ -304,7 +307,8 @@ char *up_deviceimage(void)
|
||||
bufsize = newbufsize;
|
||||
}
|
||||
}
|
||||
} while (strm.avail_out == 0 && ret != Z_STREAM_END);
|
||||
}
|
||||
while (strm.avail_out == 0 && ret != Z_STREAM_END);
|
||||
|
||||
(void)inflateEnd(&strm);
|
||||
return pbuffer;
|
||||
|
Loading…
Reference in New Issue
Block a user