+ else if( h && obj){
+ pos = offset;
+
+ nWritten = yaffs_WriteDataToFile(obj,buf,pos,nbyte,writeThrough);
+
+ if(nWritten < 0 || ((unsigned int)nWritten) < nbyte)
+ yaffsfs_SetError(-ENOSPC);
+
+ }
+
+ yaffsfs_Unlock();
+
+
+ return (nWritten >= 0) ? nWritten : -1;
+
+}
+
+
+int yaffs_truncate(const YCHAR *path,off_t newSize)
+{
+ yaffs_Object *obj = NULL;
+ int result = YAFFS_FAIL;
+
+ yaffsfs_Lock();
+
+ obj = yaffsfs_FindObject(NULL,path,0);
+ if(obj)
+ obj = yaffs_GetEquivalentObject(obj);
+
+ if(!obj)
+ yaffsfs_SetError(-ENOENT);
+ else if(obj->variantType != YAFFS_OBJECT_TYPE_FILE)
+ yaffsfs_SetError(-EISDIR);
+ else
+ result = yaffs_ResizeFile(obj,newSize);
+
+ yaffsfs_Unlock();
+
+
+ return (result) ? 0 : -1;
+}
+
+int yaffs_ftruncate(int fd, off_t newSize)
+{
+ yaffsfs_Handle *h = NULL;
+ yaffs_Object *obj = NULL;
+ int result = 0;
+
+ yaffsfs_Lock();
+ h = yaffsfs_GetHandlePointer(fd);
+ obj = yaffsfs_GetHandleObject(fd);
+
+ if(!h || !obj)
+ // bad handle
+ yaffsfs_SetError(-EBADF);