From 61877debc479560d3f2b1a7e455a843375ef5fb2 Mon Sep 17 00:00:00 2001 From: charles Date: Thu, 25 Feb 2010 22:38:03 +0000 Subject: [PATCH] Fix problem caused by void ptr and clean up code paths --- direct/yaffsfs.c | 142 +++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 73 deletions(-) diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index f7dc552..7e2fc39 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -31,7 +31,7 @@ #define YAFFSFS_RW_SIZE (1<position; - + + pos = startPos; + if(yaffs_GetObjectFileLength(obj) > pos) maxRead = yaffs_GetObjectFileLength(obj) - pos; else @@ -727,46 +730,42 @@ int yaffsfs_do_read(int fd, void *buf, unsigned int nbyte, int isPread, int offs nbyte = maxRead; - if(nbyte > 0) { - yaffsfs_GetHandle(fd); - pos = startPos; - - while(nbyte > 0) { - nToRead = YAFFSFS_RW_SIZE - (pos & (YAFFSFS_RW_SIZE -1)); - if(nToRead > nbyte) - nToRead = nbyte; + yaffsfs_GetHandle(fd); - nRead = yaffs_ReadDataFromFile(obj,buf,pos,nToRead); + while(nbyte > 0) { + nToRead = YAFFSFS_RW_SIZE - (pos & (YAFFSFS_RW_SIZE -1)); + if(nToRead > nbyte) + nToRead = nbyte; + nRead = yaffs_ReadDataFromFile(obj,buf,pos,nToRead); - if(nRead > 0){ - totalRead += nRead; - pos += nRead; - buf += nRead; - } + if(nRead > 0){ + totalRead += nRead; + pos += nRead; + buf += nRead; + } - if(nRead == nToRead) - nbyte-=nRead; - else - nbyte = 0; /* no more to read */ + if(nRead == nToRead) + nbyte-=nRead; + else + nbyte = 0; /* no more to read */ - if(nbyte > 0){ - yaffsfs_Unlock(); - yaffsfs_Lock(); - } - + if(nbyte > 0){ + yaffsfs_Unlock(); + yaffsfs_Lock(); } - yaffsfs_PutHandle(fd); - if(!isPread) { - if(totalRead >= 0) - h->position = startPos + totalRead; - else { + } + + yaffsfs_PutHandle(fd); + + if(!isPread) { + if(totalRead >= 0) + h->position = startPos + totalRead; + else { //todo error - } } - } else - totalRead = 0; + } } @@ -786,7 +785,7 @@ int yaffs_pread(int fd, void *buf, unsigned int nbyte, unsigned int offset) return yaffsfs_do_read(fd, buf, nbyte, 1, offset); } -int yaffsfs_do_write(int fd, const void *buf, unsigned int nbyte, int isPwrite, int offset) +int yaffsfs_do_write(int fd, const void *vbuf, unsigned int nbyte, int isPwrite, int offset) { yaffsfs_Handle *h = NULL; yaffs_Object *obj = NULL; @@ -796,6 +795,7 @@ int yaffsfs_do_write(int fd, const void *buf, unsigned int nbyte, int isPwrite, int totalWritten = 0; int writeThrough = 0; int nToWrite = 0; + const __u8 *buf = (const __u8 *)vbuf; yaffsfs_Lock(); h = yaffsfs_GetHandlePointer(fd); @@ -815,55 +815,51 @@ int yaffsfs_do_write(int fd, const void *buf, unsigned int nbyte, int isPwrite, startPos = yaffs_GetObjectFileLength(obj); else startPos = h->position; - if( nbyte > 0){ - yaffsfs_GetHandle(fd); - pos = startPos; - while(nbyte > 0) { - nToWrite = YAFFSFS_RW_SIZE - (pos & (YAFFSFS_RW_SIZE -1)); - if(nToWrite > nbyte) - nToWrite = nbyte; - - nWritten = yaffs_WriteDataToFile(obj,buf,pos,nToWrite,writeThrough); - if(nWritten > 0){ - totalWritten += nWritten; - pos += nWritten; - buf += nWritten; - } - if(nWritten == nToWrite) - nbyte -= nToWrite; - else - nbyte = 0; - - if(nWritten < 1 && totalWritten < 1){ - yaffsfs_SetError(-ENOSPC); - totalWritten = -1; - } - - if(nbyte > 0){ - yaffsfs_Unlock(); - yaffsfs_Lock(); - } + yaffsfs_GetHandle(fd); + pos = startPos; + while(nbyte > 0) { + nToWrite = YAFFSFS_RW_SIZE - (pos & (YAFFSFS_RW_SIZE -1)); + if(nToWrite > nbyte) + nToWrite = nbyte; + + nWritten = yaffs_WriteDataToFile(obj,buf,pos,nToWrite,writeThrough); + if(nWritten > 0){ + totalWritten += nWritten; + pos += nWritten; + buf += nWritten; } - yaffsfs_PutHandle(fd); + if(nWritten == nToWrite) + nbyte -= nToWrite; + else + nbyte = 0; - if(!isPwrite){ - if(totalWritten > 0) - h->position = startPos + totalWritten; - else { - //todo error - } + if(nWritten < 1 && totalWritten < 1){ + yaffsfs_SetError(-ENOSPC); + totalWritten = -1; } - } else - totalWritten = 0; + if(nbyte > 0){ + yaffsfs_Unlock(); + yaffsfs_Lock(); + } + } + + yaffsfs_PutHandle(fd); + + if(!isPwrite){ + if(totalWritten > 0) + h->position = startPos + totalWritten; + else { + //todo error + } + } } yaffsfs_Unlock(); return (totalWritten >= 0) ? totalWritten : -1; - } int yaffs_write(int fd, const void *buf, unsigned int nbyte) -- 2.30.2