X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=c4fc2151b695c4fc7b71a301ee2505bcffcaa5f7;hp=c20c738874c3395b43b5c8a439c1b201b8aa19b4;hb=b7c52ec83e9094c255f5a8b6d113fbca09cdcc2f;hpb=83bae7928558997b6e7e81cee00da75f9c9791fa diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index c20c738..c4fc215 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -1,7 +1,7 @@ /* * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. * - * Copyright (C) 2002-2007 Aleph One Ltd. + * Copyright (C) 2002-2010 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering * * Created by Charles Manning @@ -31,7 +31,7 @@ #define YAFFSFS_RW_SIZE (1< 0 && - obj == yaffsfs_inode[yaffsfs_handle[i].inodeId].iObj){ - alreadyOpen = 1; - if(yaffsfs_handle[i].exclusive) - alreadyExclusive = 1; - } - } - if(((oflag & O_EXCL) && alreadyOpen) || alreadyExclusive) - openDenied = 1; + /* The file already exists */ - // Open should fail if O_CREAT and O_EXCL are specified + // Open should fail if O_CREAT and O_EXCL are specified since + // the file exists if((oflag & O_EXCL) && (oflag & O_CREAT)){ openDenied = 1; yaffsfs_SetError(-EEXIST); @@ -605,7 +595,6 @@ int yaffs_open(const YCHAR *path, int oflag, int mode) h->inodeId = inodeId; h->readOnly = (oflag & (O_WRONLY | O_RDWR)) ? 0 : 1; h->append = (oflag & O_APPEND) ? 1 : 0; - h->exclusive = (oflag & O_EXCL) ? 1 : 0; h->position = 0; /* Hook inode to object */ @@ -693,7 +682,7 @@ int yaffs_close(int fd) -int yaffsfs_do_read(int fd, void *buf, unsigned int nbyte, int isPread, int offset) +int yaffsfs_do_read(int fd, void *vbuf, unsigned int nbyte, int isPread, int offset) { yaffsfs_Handle *h = NULL; yaffs_Object *obj = NULL; @@ -703,6 +692,7 @@ int yaffsfs_do_read(int fd, void *buf, unsigned int nbyte, int isPread, int offs int nToRead = 0; int totalRead = 0; unsigned int maxRead; + __u8 *buf = (__u8 *)vbuf; yaffsfs_Lock(); h = yaffsfs_GetHandlePointer(fd); @@ -717,7 +707,9 @@ int yaffsfs_do_read(int fd, void *buf, unsigned int nbyte, int isPread, int offs startPos = offset; else startPos = h->position; - + + pos = startPos; + if(yaffs_GetObjectFileLength(obj) > pos) maxRead = yaffs_GetObjectFileLength(obj) - pos; else @@ -727,46 +719,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 +774,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 +784,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 +804,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) @@ -1076,7 +1061,7 @@ static int yaffsfs_DoStat(yaffs_Object *obj,struct yaffs_stat *buf) obj = yaffs_GetEquivalentObject(obj); if(obj && buf){ - buf->st_dev = (int)obj->myDev->genericDevice; + buf->st_dev = (int)obj->myDev->context; buf->st_ino = obj->objectId; buf->st_mode = obj->yst_mode & ~S_IFMT; // clear out file type bits @@ -1556,8 +1541,8 @@ loff_t yaffs_totalspace(const YCHAR *path) yaffsfs_Lock(); dev = yaffsfs_FindDevice(path,&dummy); if(dev && dev->isMounted){ - retVal = (dev->endBlock - dev->startBlock + 1) - dev->nReservedBlocks; - retVal *= dev->nChunksPerBlock; + retVal = (dev->param.endBlock - dev->param.startBlock + 1) - dev->param.nReservedBlocks; + retVal *= dev->param.nChunksPerBlock; retVal *= dev->nDataBytesPerChunk; } else @@ -1603,7 +1588,7 @@ void yaffs_initialise(yaffsfs_DeviceConfiguration *cfgList) while(cfg && cfg->prefix && cfg->dev){ cfg->dev->isMounted = 0; - cfg->dev->removeObjectCallback = yaffsfs_RemoveObjectCallback; + cfg->dev->param.removeObjectCallback = yaffsfs_RemoveObjectCallback; cfg++; }