+ if(openDenied && !errorReported ) {
+ /* Error if the file exists but permissions are refused. */
+ yaffsfs_SetError(-EACCES);
+ errorReported = 1;
+ }
+
+ /* Check sharing of an existing object. */
+ if(!openDenied){
+ yaffsfs_Handle *hx;
+ int i;
+ sharedReadAllowed = 1;
+ sharedWriteAllowed = 1;
+ alreadyReading = 0;
+ alreadyWriting = 0;
+ for( i = 0; i < YAFFSFS_N_HANDLES; i++){
+ hx = &yaffsfs_handle[i];
+ if(hx->useCount > 0 &&
+ hx->inodeId >= 0 &&
+ yaffsfs_inode[hx->inodeId].iObj == obj){
+ if(!hx->shareRead)
+ sharedReadAllowed = 0;
+ if(!hx->shareWrite)
+ sharedWriteAllowed = 0;
+ if(hx->reading)
+ alreadyReading = 1;
+ if(hx->writing)
+ alreadyWriting = 1;
+ }
+ }
+
+
+
+ if((!sharedReadAllowed && readRequested)||
+ (!shareRead && alreadyReading) ||
+ (!sharedWriteAllowed && writeRequested) ||
+ (!shareWrite && alreadyWriting)){
+ openDenied = 1;
+ yaffsfs_SetError(-EBUSY);
+ errorReported=1;
+ }
+ }
+
+ }
+
+ /* If we could not open an existing object, then let's see if
+ * the directory exists. If not, error.
+ */
+ if(!obj && !errorReported){
+ dir = yaffsfs_FindDirectory(NULL,path,&name,0,NULL);
+ if(!dir){
+ yaffsfs_SetError(-ENOTDIR);
+ errorReported = 1;
+ }
+ }