From de55d14d486fdf4069153df3aba0957e62745490 Mon Sep 17 00:00:00 2001 From: Charles Manning Date: Mon, 15 Nov 2010 12:16:21 +1300 Subject: [PATCH] yaffs direct: Handle forced unmount Reading and writing need to check whether the device has been remounted read-only or unmounted in a different thread. Signed-off-by: Charles Manning --- direct/yaffsfs.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index aa8d74d..28af280 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -31,7 +31,8 @@ #define YAFFSFS_RW_SIZE (1< nbyte) nToRead = nbyte; - nRead = yaffs_file_rd(obj,buf,pos,nToRead); + + /* Tricky bit... + * Need to reverify object in case the device was + * unmounted in another thread. + */ + obj = yaffsfs_GetHandleObject(fd); + if(!obj) + nRead = 0; + else + nRead = yaffs_file_rd(obj,buf,pos,nToRead); if(nRead > 0){ totalRead += nRead; @@ -953,11 +963,21 @@ int yaffsfs_do_write(int fd, const void *vbuf, unsigned int nbyte, int isPwrite, yaffsfs_GetHandle(fd); pos = startPos; while(nbyte > 0) { + nToWrite = YAFFSFS_RW_SIZE - (pos & (YAFFSFS_RW_SIZE -1)); if(nToWrite > nbyte) nToWrite = nbyte; - nWritten = yaffs_wr_file(obj,buf,pos,nToWrite,write_trhrough); + /* Tricky bit... + * Need to reverify object in case the device was + * remounted or unmounted in another thread. + */ + obj = yaffsfs_GetHandleObject(fd); + if(!obj || obj->my_dev->read_only) + nWritten = 0; + else + nWritten = yaffs_wr_file(obj,buf,pos,nToWrite, + write_trhrough); if(nWritten > 0){ totalWritten += nWritten; pos += nWritten; @@ -1942,7 +1962,8 @@ int yaffs_unmount2(const YCHAR *path, int force) yaffs_checkpoint_save(dev); for(i = inUse = 0; i < YAFFSFS_N_HANDLES && !inUse; i++){ - if(yaffsfs_handle[i].useCount > 0 && yaffsfs_inode[yaffsfs_handle[i].inodeId].iObj->my_dev == dev) + if(yaffsfs_handle[i].useCount > 0 && + yaffsfs_inode[yaffsfs_handle[i].inodeId].iObj->my_dev == dev) inUse = 1; /* the device is in use, can't unmount */ } -- 2.30.2