Patches from Petteri Aimonen + stdbool and rand() changes for Freddie Chopin

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5415 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-12-07 16:00:56 +00:00
parent 419bb814c5
commit 5306523bce
34 changed files with 1110 additions and 181 deletions
+27 -4
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* drivers/mtd/ftl.c
*
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -229,6 +229,10 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
remaining = nblocks;
if (alignedblock > startblock)
{
/* Check if the write is shorter than to the end of the erase block */
bool short_write = (remaining < (alignedblock - startblock));
/* Read the full erase block into the buffer */
rwblock = startblock & ~mask;
@@ -252,9 +256,19 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
/* Copy the user data at the end of the buffered erase block */
offset = (startblock & mask) * dev->geo.blocksize;
nbytes = dev->geo.erasesize - offset;
if (short_write)
{
nbytes = remaining * dev->geo.blocksize;
}
else
{
nbytes = dev->geo.erasesize - offset;
}
fvdbg("Copy %d bytes into erase block=%d at offset=%d\n",
nbytes, eraseblock, offset);
memcpy(dev->eblock + offset, buffer, nbytes);
/* And write the erase back to flash */
@@ -268,8 +282,16 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
/* Then update for amount written */
remaining -= dev->blkper - (startblock & mask);
buffer += nbytes;
if (short_write)
{
remaining = 0;
}
else
{
remaining -= dev->blkper - (startblock & mask);
}
buffer += nbytes;
}
/* How handle full erase pages in the middle */
@@ -290,6 +312,7 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
fvdbg("Write %d bytes into erase block=%d at offset=0\n",
dev->geo.erasesize, alignedblock);
nxfrd = MTD_BWRITE(dev->mtd, alignedblock, dev->blkper, buffer);
if (nxfrd != dev->blkper)
{