Changeset 24584 in vbox for trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp
- Timestamp:
- Nov 11, 2009 2:54:56 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp
r24001 r24584 48 48 # include <sys/time.h> 49 49 #endif 50 #ifdef RT_OS_LINUX 51 # include <sys/file.h> 52 #endif 50 53 #if defined(RT_OS_OS2) && (!defined(__INNOTEK_LIBC__) || __INNOTEK_LIBC__ < 0x006) 51 54 # include <io.h> … … 217 220 if (fh >= 0) 218 221 { 222 iErr = 0; 223 219 224 /* 220 225 * Mark the file handle close on exec, unless inherit is specified. 221 226 */ 222 if ( !(fOpen & RTFILE_O_INHERIT)227 if ( (fOpen & RTFILE_O_INHERIT) 223 228 #ifdef O_NOINHERIT 224 || (fOpenMode & O_NOINHERIT) /* careful since it could be a dummy. */ 225 #endif 226 || fcntl(fh, F_SETFD, FD_CLOEXEC) >= 0) 229 && !(fOpenMode & O_NOINHERIT) /* Take care since it might be a zero value dummy. */ 230 #endif 231 ) 232 iErr = fcntl(fh, F_SETFD, FD_CLOEXEC) < 0 ? errno : 0; 233 234 /* 235 * Switch direct I/O on now if requested and required. 236 */ 237 #if defined(RT_OS_DARWIN) \ 238 || (defined(RT_OS_SOLARIS) && !defined(IN_GUEST)) 239 if (iErr == 0 && (fOpen & RTFILE_O_NO_CACHE)) 227 240 { 228 #if defined(RT_OS_SOLARIS) || defined(RT_OS_DARWIN) 229 iErr = 0; 230 /* Switch direct I/O on now if requested */ 231 # if defined(RT_OS_SOLARIS) && !defined(IN_GUEST) 232 if (fOpen & RTFILE_O_NO_CACHE) 233 iErr = directio(fh, DIRECTIO_ON); 234 # elif defined(RT_OS_DARWIN) 235 if (fOpen & RTFILE_O_NO_CACHE) 236 iErr = fcntl(fh, F_NOCACHE, 1); 241 # if defined(RT_OS_DARWIN) 242 iErr = fcntl(fh, F_NOCACHE, 1) >= 0 : errno; 243 # else 244 iErr = directio(fh, DIRECTIO_ON) >= 0 : errno; 237 245 # endif 238 if (iErr < 0) 239 iErr = errno; 240 else 241 #endif 246 } 247 #endif 248 249 /* 250 * Implement / emulate file sharing. 251 * 252 * We need another mode which allows skipping this stuff completely 253 * and do things the UNIX way. So for the present this is just a debug 254 * aid that can be enabled by developers too lazy to test on Windows. 255 */ 256 #if 0 && defined(RT_OS_LINUX) 257 if (iErr == 0) 258 { 259 /* This approach doesn't work because only knfsd checks for these 260 buggers. :-( */ 261 int iLockOp; 262 switch (fOpen & RTFILE_O_DENY_MASK) 242 263 { 243 *pFile = (RTFILE)fh; 244 Assert((int)*pFile == fh); 245 LogFlow(("RTFileOpen(%p:{%RTfile}, %p:{%s}, %#x): returns %Rrc\n", 246 pFile, *pFile, pszFilename, pszFilename, fOpen, rc)); 247 return VINF_SUCCESS; 264 default: 265 AssertFailed(); 266 case RTFILE_O_DENY_NONE: 267 case RTFILE_O_DENY_NOT_DELETE: 268 iLockOp = LOCK_MAND | LOCK_READ | LOCK_WRITE; 269 break; 270 case RTFILE_O_DENY_READ: 271 case RTFILE_O_DENY_READ | RTFILE_O_DENY_NOT_DELETE: 272 iLockOp = LOCK_MAND | LOCK_WRITE; 273 break; 274 case RTFILE_O_DENY_WRITE: 275 case RTFILE_O_DENY_WRITE | RTFILE_O_DENY_NOT_DELETE: 276 iLockOp = LOCK_MAND | LOCK_READ; 277 break; 278 case RTFILE_O_DENY_WRITE | RTFILE_O_DENY_READ: 279 case RTFILE_O_DENY_WRITE | RTFILE_O_DENY_READ | RTFILE_O_DENY_NOT_DELETE: 280 iLockOp = LOCK_MAND; 281 break; 282 } 283 iErr = flock(fh, iLockOp | LOCK_NB); 284 if (iErr != 0) 285 iErr = errno == EAGAIN ? ETXTBSY : 0; 286 } 287 #endif /* 0 && RT_OS_LINUX */ 288 #ifdef DEBUG_bird 289 if (iErr == 0) 290 { 291 /* This emulation is incomplete but useful. */ 292 switch (fOpen & RTFILE_O_DENY_MASK) 293 { 294 default: 295 AssertFailed(); 296 case RTFILE_O_DENY_NONE: 297 case RTFILE_O_DENY_NOT_DELETE: 298 case RTFILE_O_DENY_READ: 299 case RTFILE_O_DENY_READ | RTFILE_O_DENY_NOT_DELETE: 300 break; 301 case RTFILE_O_DENY_WRITE: 302 case RTFILE_O_DENY_WRITE | RTFILE_O_DENY_NOT_DELETE: 303 case RTFILE_O_DENY_WRITE | RTFILE_O_DENY_READ: 304 case RTFILE_O_DENY_WRITE | RTFILE_O_DENY_READ | RTFILE_O_DENY_NOT_DELETE: 305 if (fOpen & RTFILE_O_WRITE) 306 { 307 iErr = flock(fh, LOCK_EX | LOCK_NB); 308 if (iErr != 0) 309 iErr = errno == EAGAIN ? ETXTBSY : 0; 310 } 311 break; 248 312 } 249 313 } 250 iErr = errno; 314 #endif 315 #ifdef RT_OS_SOLARIS 316 /** @todo Use fshare_t and associates, it's a perfect match. see sys/fcntl.h */ 317 #endif 318 319 /* 320 * We're done. 321 */ 322 if (iErr == 0) 323 { 324 *pFile = (RTFILE)fh; 325 Assert((int)*pFile == fh); 326 LogFlow(("RTFileOpen(%p:{%RTfile}, %p:{%s}, %#x): returns %Rrc\n", 327 pFile, *pFile, pszFilename, pszFilename, fOpen, rc)); 328 return VINF_SUCCESS; 329 } 330 251 331 close(fh); 252 332 }
Note:
See TracChangeset
for help on using the changeset viewer.