Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. Create.c
  5. Abstract:
  6. This module implements the File Create routine for Raw called by the
  7. dispatch driver.
  8. Author:
  9. David Goebel [DavidGoe] 18-Mar-91
  10. Revision History:
  11. --*/
  12. #include "RawProcs.h"
  13. #ifdef ALLOC_PRAGMA
  14. #pragma alloc_text(PAGE, RawCreate)
  15. #endif
  16. NTSTATUS
  17. RawCreate (
  18. IN PVCB Vcb,
  19. IN PIRP Irp,
  20. IN PIO_STACK_LOCATION IrpSp
  21. )
  22. /*++
  23. Routine Description:
  24. Open the volume.
  25. Arguments:
  26. Vcb - Supplies the volume being queried.
  27. Irp - Supplies the Irp being processed.
  28. IrpSp - Supplies parameters describing the read
  29. Return Value:
  30. NTSTATUS - the return status for the operation
  31. --*/
  32. {
  33. NTSTATUS Status;
  34. BOOLEAN DeleteVolume = FALSE;
  35. PAGED_CODE();
  36. //
  37. // This is an open/create request. The only valid operation that
  38. // is supported by the RAW file system is if the caller:
  39. //
  40. // o Specifies the device itself (file name == ""),
  41. // o specifies that this is an OPEN operation,
  42. // o and does not ask to create a directory.
  43. //
  44. Status = KeWaitForSingleObject( &Vcb->Mutex,
  45. Executive,
  46. KernelMode,
  47. FALSE,
  48. (PLARGE_INTEGER) NULL );
  49. ASSERT( NT_SUCCESS( Status ) );
  50. //
  51. // Don't allow any relative opens as well as opens with a filename. These opens have
  52. // only been checked for traverse access by the I/O manager.
  53. //
  54. if (((IrpSp->FileObject == NULL) || ((IrpSp->FileObject->FileName.Length == 0) &&
  55. IrpSp->FileObject->RelatedFileObject == NULL)) &&
  56. ((IrpSp->Parameters.Create.Options >> 24) == FILE_OPEN) &&
  57. ((IrpSp->Parameters.Create.Options & FILE_DIRECTORY_FILE) == 0)) {
  58. //
  59. // If the volume is locked or dismounted we cannot open it again.
  60. //
  61. if ( FlagOn(Vcb->VcbState, VCB_STATE_FLAG_LOCKED) ) {
  62. Status = STATUS_ACCESS_DENIED;
  63. Irp->IoStatus.Information = 0;
  64. } if ( FlagOn(Vcb->VcbState, VCB_STATE_FLAG_DISMOUNTED) ) {
  65. Status = STATUS_VOLUME_DISMOUNTED;
  66. Irp->IoStatus.Information = 0;
  67. } else {
  68. //
  69. // If the volume is already opened by someone then we need to check
  70. // the share access
  71. //
  72. USHORT ShareAccess;
  73. ACCESS_MASK DesiredAccess;
  74. ShareAccess = IrpSp->Parameters.Create.ShareAccess;
  75. DesiredAccess = IrpSp->Parameters.Create.SecurityContext->DesiredAccess;
  76. if ((Vcb->OpenCount > 0) &&
  77. !NT_SUCCESS(Status = IoCheckShareAccess( DesiredAccess,
  78. ShareAccess,
  79. IrpSp->FileObject,
  80. &Vcb->ShareAccess,
  81. TRUE ))) {
  82. Irp->IoStatus.Information = 0;
  83. } else {
  84. //
  85. // This is a valid create. Increment the "OpenCount" and
  86. // stuff the Vpb into the file object.
  87. //
  88. if (Vcb->OpenCount == 0) {
  89. IoSetShareAccess( DesiredAccess,
  90. ShareAccess,
  91. IrpSp->FileObject,
  92. &Vcb->ShareAccess );
  93. }
  94. Vcb->OpenCount += 1;
  95. IrpSp->FileObject->Vpb = Vcb->Vpb;
  96. Status = STATUS_SUCCESS;
  97. Irp->IoStatus.Information = FILE_OPENED;
  98. IrpSp->FileObject->Flags |= FO_NO_INTERMEDIATE_BUFFERING;
  99. }
  100. }
  101. } else {
  102. //
  103. // Fail this I/O request since one of the above conditions was
  104. // not met.
  105. //
  106. // KdPrint (("Failing raw open\n"));
  107. // ASSERT (FALSE);
  108. Status = STATUS_INVALID_PARAMETER;
  109. Irp->IoStatus.Information = 0;
  110. }
  111. //
  112. // If this was not successfull and this was the first open on the
  113. // volume, we must implicitly dis-mount the volume.
  114. //
  115. if (!NT_SUCCESS(Status) && (Vcb->OpenCount == 0)) {
  116. DeleteVolume = RawCheckForDismount( Vcb, TRUE );
  117. }
  118. if (!DeleteVolume) {
  119. (VOID)KeReleaseMutex( &Vcb->Mutex, FALSE );
  120. }
  121. RawCompleteRequest( Irp, Status );
  122. return Status;
  123. }