ReactOS  0.4.13-dev-249-gcba1a2f
fsctl.c
Go to the documentation of this file.
1 /*
2  * FFS File System Driver for Windows
3  *
4  * fsctl.c
5  *
6  * 2004.5.6 ~
7  *
8  * Lee Jae-Hong, http://www.pyrasis.com
9  *
10  * See License.txt
11  *
12  */
13 
14 #include "ntifs.h"
15 #include "ffsdrv.h"
16 
17 /* Globals */
18 
19 extern PFFS_GLOBAL FFSGlobal;
20 
21 
22 /* Definitions */
23 
24 BOOLEAN
26  IN PFFS_IRP_CONTEXT IrpContext,
28 
29 #ifdef ALLOC_PRAGMA
30 //#pragma alloc_text(PAGE, FFSSetVpbFlag)
31 //#pragma alloc_text(PAGE, FFSClearVpbFlag)
32 #pragma alloc_text(PAGE, FFSGetPartition)
33 #pragma alloc_text(PAGE, FFSLoadDiskLabel)
34 #pragma alloc_text(PAGE, FFSIsHandleCountZero)
35 #pragma alloc_text(PAGE, FFSLockVcb)
36 #pragma alloc_text(PAGE, FFSLockVolume)
37 #pragma alloc_text(PAGE, FFSUnlockVcb)
38 #pragma alloc_text(PAGE, FFSUnlockVolume)
39 #pragma alloc_text(PAGE, FFSAllowExtendedDasdIo)
40 #pragma alloc_text(PAGE, FFSUserFsRequest)
41 #pragma alloc_text(PAGE, FFSIsMediaWriteProtected)
42 #pragma alloc_text(PAGE, FFSMountVolume)
43 #pragma alloc_text(PAGE, FFSCheckDismount)
44 #pragma alloc_text(PAGE, FFSPurgeVolume)
45 #pragma alloc_text(PAGE, FFSPurgeFile)
46 #pragma alloc_text(PAGE, FFSDismountVolume)
47 #pragma alloc_text(PAGE, FFSIsVolumeMounted)
48 #pragma alloc_text(PAGE, FFSVerifyVolume)
49 #pragma alloc_text(PAGE, FFSFileSystemControl)
50 #endif
51 
52 
53 VOID
55  IN PVPB Vpb,
56  IN USHORT Flag)
57 {
58  KIRQL OldIrql;
59 
61 
62  Vpb->Flags |= Flag;
63 
65 }
66 
67 
68 VOID
70  IN PVPB Vpb,
71  IN USHORT Flag)
72 {
73  KIRQL OldIrql;
74 
76 
77  Vpb->Flags &= ~Flag;
78 
80 }
81 
82 
86  OUT ULONGLONG *StartOffset)
87 {
88  CHAR Buffer[2048];
89  PIRP Irp;
91  KEVENT Event;
93  PARTITION_INFORMATION *PartInfo;
94 
95  PAGED_CODE();
96 
97  if (IsFlagOn(DeviceObject->Characteristics, FILE_FLOPPY_DISKETTE))
98  {
99  *StartOffset = 0;
100  return STATUS_SUCCESS;
101  }
102 
104 
107  DeviceObject,
108  NULL,
109  0,
110  Buffer,
111  2048,
112  FALSE,
113  &Event,
114  &IoStatus);
115 
116  if (!Irp)
117  {
119  }
120 
122  if (!NT_SUCCESS(Status))
123  {
124  return Status;
125  }
126 
128  if (!NT_SUCCESS(Status))
129  {
130  return Status;
131  }
132 
133  PartInfo = (PARTITION_INFORMATION *)Buffer;
134  *StartOffset = PartInfo->StartingOffset.QuadPart;
135 
136  return Status;
137 }
138 
139 
140 NTSTATUS
143  IN PFFS_VCB Vcb)
144 {
146  PFFS_SUPER_BLOCK FFSSb;
147  PDISKLABEL Disklabel;
148  int i;
149  int RootFS_VERSION;
150  ULONGLONG StartOffset = 0;
151  ULONGLONG FSOffset = 0;
152  ULONGLONG FSRootOffset = 0;
153 
154  PAGED_CODE();
155 
157 
158  FFSReadDisk(Vcb, (LABELSECTOR * SECTOR_SIZE + LABELOFFSET), sizeof(DISKLABEL), (PVOID)Disklabel, FALSE);
159 
160  if (Disklabel->d_magic == DISKMAGIC)
161  {
162  KdPrint(("FFSLoadDiskLabel() Disklabel magic ok\n"));
163 
165  }
166  else
167  {
168  KdPrint(("FFSLoadDiskLabel() No BSD disklabel found, trying to find BSD file system on \"normal\" partition.\n"));
169 
170  if ((FFSSb = FFSLoadSuper(Vcb, FALSE, FSOffset + SBLOCK_UFS1)) &&
171  (FFSSb->fs_magic == FS_UFS1_MAGIC))
172  {
173  FFSPrint((DBG_VITAL, "FFSLoadDiskLabel() \"normal\" partition of FFSv1 file system is found.\n"));
174 /*
175  if ((FFSSb->fs_fsmnt[0] == '/') && (FFSSb->fs_fsmnt[1] == '\0'))
176  {
177  FFSGlobal->RootPartition = i;
178  FSRootOffset = FSOffset;
179  RootFS_VERSION = 1;
180  }
181 */
182  FS_VERSION = 1;
183  Vcb->FSOffset[0] = 0;
184  Vcb->PartitionNumber = 0;
185  Vcb->ffs_super_block = FFSSb;
186 #ifdef __REACTOS__
187  ExFreePoolWithTag(Disklabel, FFS_POOL_TAG);
188 #endif
190  return Status;
191  }
192  else if ((FFSSb = FFSLoadSuper(Vcb, FALSE, FSOffset + SBLOCK_UFS2)) &&
193  (FFSSb->fs_magic == FS_UFS2_MAGIC))
194  {
195  FFSPrint((DBG_VITAL, "FFSLoadDiskLabel() \"normal\" partition of FFSv2 file system is found.\n"));
196 /*
197  if ((FFSSb->fs_fsmnt[0] == '/') && (FFSSb->fs_fsmnt[1] == '\0'))
198  {
199  FFSGlobal->RootPartition = i;
200  FSRootOffset = FSOffset;
201  RootFS_VERSION = 2;
202  }
203 */
204  FS_VERSION = 2;
205  Vcb->FSOffset[0] = 0;
206  Vcb->PartitionNumber = 0;
207  Vcb->ffs_super_block = FFSSb;
208 #ifdef __REACTOS__
209  ExFreePoolWithTag(Disklabel, FFS_POOL_TAG);
210 #endif
212  return Status;
213  }
214  else
215  {
216  KdPrint(("FFSLoadDiskLabel() No BSD file system was found on the \"normal\" partition.\n"));
217 #ifdef __REACTOS__
218  ExFreePoolWithTag(Disklabel, FFS_POOL_TAG);
219 #endif
221  return Status;
222  }
223  }
224 
225  Status = FFSGetPartition(DeviceObject, &StartOffset);
226  if (!NT_SUCCESS(Status))
227  {
228  KdPrint(("FFSLoadDiskLabel() Slice info failed, Status %u\n", Status));
229 #ifdef __REACTOS__
230  ExFreePoolWithTag(Disklabel, FFS_POOL_TAG);
231 #endif
232  return Status;
233  }
234 
235  Vcb->PartitionNumber = FFSGlobal->PartitionNumber;
236 
237  KdPrint(("FFSLoadDiskLabel() Selected BSD Label : %d, StartOffset : %x\n", Vcb->PartitionNumber, StartOffset));
238 
239  for (i = 0; i < MAXPARTITIONS; i++)
240  {
241  if (Disklabel->d_partitions[i].p_fstype == FS_BSDFFS)
242  {
243  /* Important */
244  FSOffset = Disklabel->d_partitions[i].p_offset;
245  FSOffset = FSOffset * SECTOR_SIZE;
246  //FSOffset = FSOffset - StartOffset;
247  Vcb->FSOffset[i] = FSOffset;
248  /* Important */
249 
250  KdPrint(("FFSLoadDiskLabel() Label %d, FS_BSDFFS, %x\n", i, Vcb->FSOffset[i]));
251 
252  if ((FFSSb = FFSLoadSuper(Vcb, FALSE, FSOffset + SBLOCK_UFS1)) &&
253  (FFSSb->fs_magic == FS_UFS1_MAGIC))
254  {
255  FFSPrint((DBG_VITAL, "FFSLoadDiskLabel() Label %d of FFSv1 file system is found.\n", i));
256 
257  if ((FFSSb->fs_fsmnt[0] == '/') && (FFSSb->fs_fsmnt[1] == '\0'))
258  {
259  Vcb->RootPartition = i;
260  FSRootOffset = FSOffset;
261  RootFS_VERSION = 1;
262  }
263 
264  FS_VERSION = 1;
265 
266  if (i == (int)Vcb->PartitionNumber)
267  {
268  Vcb->ffs_super_block = FFSSb;
269  }
270 
272  }
273  else if ((FFSSb = FFSLoadSuper(Vcb, FALSE, FSOffset + SBLOCK_UFS2)) &&
274  (FFSSb->fs_magic == FS_UFS2_MAGIC))
275  {
276  FFSPrint((DBG_VITAL, "FFSLoadDiskLabel() Label %d of FFSv2 file system is found.\n", i));
277 
278  if ((FFSSb->fs_fsmnt[0] == '/') && (FFSSb->fs_fsmnt[1] == '\0'))
279  {
280  Vcb->RootPartition = i;
281  FSRootOffset = FSOffset;
282  RootFS_VERSION = 2;
283  }
284 
285  FS_VERSION = 2;
286 
287  if (i == (int)Vcb->PartitionNumber)
288  {
289  Vcb->ffs_super_block = FFSSb;
290  }
291 
293  }
294  }
295 #if 0
296  else if (i == (int)FFSGlobal->PartitionNumber)
297  {
298  /* 선택된 BSD 파티션이 디스크에 없을 경우 Root 파티션으로 대체 */
299  if (RootFS_VERSION == 1)
300  {
301  FFSSb = FFSLoadSuper(Vcb, FALSE, FSRootOffset + SBLOCK_UFS1);
302  Vcb->ffs_super_block = FFSSb;
303  FFSGlobal->PartitionNumber = FFSGlobal->RootPartition;
304  }
305  else
306  {
307  FFSSb = FFSLoadSuper(Vcb, FALSE, FSRootOffset + SBLOCK_UFS2);
308  Vcb->ffs_super_block = FFSSb;
309  FFSGlobal->PartitionNumber = FFSGlobal->RootPartition;
310  }
311  }
312 #endif
313  }
314 
315  if (Vcb->ffs_super_block == NULL)
317 
318 #ifdef __REACTOS__
319  ExFreePoolWithTag(Disklabel, FFS_POOL_TAG);
320 #endif
321 
322  return Status;
323 }
324 
325 
326 BOOLEAN
328  IN PFFS_VCB Vcb)
329 {
330  PFFS_FCB Fcb;
332 
333  PAGED_CODE();
334 
335  for(List = Vcb->FcbList.Flink;
336  List != &Vcb->FcbList;
337  List = List->Flink)
338  {
339  Fcb = CONTAINING_RECORD(List, FFS_FCB, Next);
340 
341  ASSERT((Fcb->Identifier.Type == FFSFCB) &&
342  (Fcb->Identifier.Size == sizeof(FFS_FCB)));
343 
344  FFSPrint((DBG_INFO, "FFSIsHandleCountZero: Inode:%xh File:%S OpenHandleCount=%xh\n",
345  Fcb->FFSMcb->Inode, Fcb->FFSMcb->ShortName.Buffer, Fcb->OpenHandleCount));
346 
347  if (Fcb->OpenHandleCount)
348  {
349  return FALSE;
350  }
351  }
352 
353  return TRUE;
354 }
355 
356 
357 NTSTATUS
359  IN PFFS_VCB Vcb,
361 {
363 
364  PAGED_CODE();
365 
366  _SEH2_TRY
367  {
368  if (FlagOn(Vcb->Flags, VCB_VOLUME_LOCKED))
369  {
370  FFSPrint((DBG_INFO, "FFSLockVolume: Volume is already locked.\n"));
371 
373 
374  _SEH2_LEAVE;
375  }
376 
377  if (Vcb->OpenFileHandleCount > (ULONG)(FileObject ? 1 : 0))
378  {
379  FFSPrint((DBG_INFO, "FFSLockVcb: There are still opened files.\n"));
380 
382 
383  _SEH2_LEAVE;
384  }
385 
387  {
388  FFSPrint((DBG_INFO, "FFSLockVcb: Thare are still opened files.\n"));
389 
391 
392  _SEH2_LEAVE;
393  }
394 
395  SetFlag(Vcb->Flags, VCB_VOLUME_LOCKED);
396 
398 
399  Vcb->LockFile = FileObject;
400 
401  FFSPrint((DBG_INFO, "FFSLockVcb: Volume locked.\n"));
402 
404  }
405 
407  {
408  // Nothing
409  } _SEH2_END;
410 
411  return Status;
412 }
413 
414 
416 NTSTATUS
418  IN PFFS_IRP_CONTEXT IrpContext)
419 {
422  PFFS_VCB Vcb = 0;
424  BOOLEAN VcbResourceAcquired = FALSE;
425 
426  PAGED_CODE();
427 
428  _SEH2_TRY
429  {
430  ASSERT(IrpContext != NULL);
431 
432  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
433  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
434 
435  DeviceObject = IrpContext->DeviceObject;
436 
438 
439  //
440  // This request is not allowed on the main device object
441  //
443  {
445  _SEH2_LEAVE;
446  }
447 
449 
450  ASSERT(Vcb != NULL);
451 
452  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
453  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
454 
455  ASSERT(IsMounted(Vcb));
456 
457  IrpSp = IoGetCurrentIrpStackLocation(IrpContext->Irp);
458 
459 #if (_WIN32_WINNT >= 0x0500)
461 #endif
463  &Vcb->MainResource,
464  TRUE);
465 
466  VcbResourceAcquired = TRUE;
467 
469  }
470 
472  {
473  if (VcbResourceAcquired)
474  {
476  &Vcb->MainResource,
478  }
479 
480  if (!IrpContext->ExceptionInProgress)
481  {
482  FFSCompleteIrpContext(IrpContext, Status);
483  }
484  } _SEH2_END;
485 
486  return Status;
487 }
488 
489 
490 NTSTATUS
492  IN PFFS_VCB Vcb,
494 {
496 
497  PAGED_CODE();
498 
499  _SEH2_TRY
500  {
501  if (FileObject && FileObject->FsContext != Vcb)
502  {
504  _SEH2_LEAVE;
505  }
506 
507  if (!FlagOn(Vcb->Flags, VCB_VOLUME_LOCKED))
508  {
509  FFSPrint((DBG_ERROR, ": FFSUnlockVcb: Volume is not locked.\n"));
511  _SEH2_LEAVE;
512  }
513 
514  if (Vcb->LockFile == FileObject)
515  {
517 
519 
520  FFSPrint((DBG_INFO, "FFSUnlockVcb: Volume unlocked.\n"));
521 
523  }
524  else
525  {
527  }
528  }
529 
531  {
532  // Nothing
533  } _SEH2_END;
534 
535  return Status;
536 }
537 
538 
540 NTSTATUS
542  IN PFFS_IRP_CONTEXT IrpContext)
543 {
547  PFFS_VCB Vcb = 0;
548  BOOLEAN VcbResourceAcquired = FALSE;
549 
550  PAGED_CODE();
551 
552  _SEH2_TRY
553  {
554  ASSERT(IrpContext != NULL);
555 
556  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
557  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
558 
559  DeviceObject = IrpContext->DeviceObject;
560 
561  //
562  // This request is not allowed on the main device object
563  //
565  {
567  _SEH2_LEAVE;
568  }
569 
571 
572  ASSERT(Vcb != NULL);
573 
574  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
575  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
576 
577  ASSERT(IsMounted(Vcb));
578 
579  IrpSp = IoGetCurrentIrpStackLocation(IrpContext->Irp);
580 
582  &Vcb->MainResource,
583  TRUE);
584 
585  VcbResourceAcquired = TRUE;
586 
588  }
590  {
591  if (VcbResourceAcquired)
592  {
594  &Vcb->MainResource,
596  }
597 
598  if (!IrpContext->ExceptionInProgress)
599  {
600  FFSCompleteIrpContext(IrpContext, Status);
601  }
602  } _SEH2_END;
603 
604  return Status;
605 }
606 
607 
609 NTSTATUS
611  IN PFFS_IRP_CONTEXT IrpContext)
612 {
614  PIRP Irp;
616 
617  HANDLE Handle;
618 
619  PLIST_ENTRY ListEntry;
620 
623  BOOLEAN GlobalResourceAcquired = FALSE;
624 
626 
627  _SEH2_TRY
628  {
629  Irp = IrpContext->Irp;
631 
632  if (!SeSinglePrivilegeCheck(Privilege, Irp->RequestorMode))
633  {
635  _SEH2_LEAVE;
636  }
637 
638  if (
639 #if !defined(_GNU_NTIFS_) || defined(__REACTOS__)
640  IrpSp->Parameters.FileSystemControl.InputBufferLength
641 #else
643  Parameters.FileSystemControl.InputBufferLength
644 #endif
645  != sizeof(HANDLE))
646  {
648 
649  _SEH2_LEAVE;
650  }
651 
652  Handle = *(PHANDLE)Irp->AssociatedIrp.SystemBuffer;
653 
655  0,
657  KernelMode,
658  (void **)&FileObject,
659  NULL);
660 
661  if (!NT_SUCCESS(Status))
662  {
663  _SEH2_LEAVE;
664  }
665  else
666  {
668  DeviceObject = FileObject->DeviceObject;
669  }
670 
671  FFSPrint((DBG_INFO, "FFSInvalidateVolumes: FileObject=%xh ...\n", FileObject));
672 
675  TRUE);
676 
677  GlobalResourceAcquired = TRUE;
678 
679  ListEntry = FFSGlobal->VcbList.Flink;
680 
681  while (ListEntry != &FFSGlobal->VcbList)
682  {
683  PFFS_VCB Vcb;
684 
685  Vcb = CONTAINING_RECORD(ListEntry, FFS_VCB, Next);
686 
687  ListEntry = ListEntry->Flink;
688 
689  FFSPrint((DBG_INFO, "FFSInvalidateVolumes: Vcb=%xh Vcb->Vpb=%xh...\n", Vcb, Vcb->Vpb));
690  if (Vcb->Vpb && (Vcb->Vpb->RealDevice == DeviceObject))
691  {
692  ExAcquireResourceExclusiveLite(&Vcb->MainResource, TRUE);
693  FFSPrint((DBG_INFO, "FFSInvalidateVolumes: FFSPurgeVolume...\n"));
695  ClearFlag(Vcb->Flags, VCB_MOUNTED);
696  ExReleaseResourceLite(&Vcb->MainResource);
697 
698  //
699  // Vcb is still attached on the list ......
700  //
701 
702  if (ListEntry->Blink == &Vcb->Next)
703  {
704  FFSPrint((DBG_INFO, "FFSInvalidateVolumes: FFSCheckDismount...\n"));
705  FFSCheckDismount(IrpContext, Vcb, FALSE);
706  }
707  }
708  }
709  }
710 
712  {
713  if (GlobalResourceAcquired)
714  {
718  }
719 
720  FFSCompleteIrpContext(IrpContext, Status);
721  } _SEH2_END;
722 
723  return Status;
724 }
725 
726 
728 NTSTATUS
730  IN PFFS_IRP_CONTEXT IrpContext)
731 {
733  PFFS_VCB Vcb;
734  PFFS_CCB Ccb;
735 
736  PAGED_CODE();
737 
738  IrpSp = IoGetCurrentIrpStackLocation(IrpContext->Irp);
739 
740  Vcb = (PFFS_VCB)IrpSp->FileObject->FsContext;
741  Ccb = (PFFS_CCB)IrpSp->FileObject->FsContext2;
742 
743  ASSERT(Vcb != NULL);
744 
745  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
746  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
747 
748  ASSERT(IsMounted(Vcb));
749 
750  if (Ccb)
751  {
753 
755 
756  return STATUS_SUCCESS;
757  }
758  else
759  {
761  }
762 }
763 
764 
766 NTSTATUS
768  IN PFFS_IRP_CONTEXT IrpContext)
769 {
770  PIRP Irp;
771  PIO_STACK_LOCATION IoStackLocation;
774 
775  PAGED_CODE();
776 
777  ASSERT(IrpContext);
778 
779  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
780  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
781 
782  Irp = IrpContext->Irp;
783 
784  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
785 
786 #if !defined(_GNU_NTIFS_) || defined(__REACTOS__)
787  FsControlCode =
788  IoStackLocation->Parameters.FileSystemControl.FsControlCode;
789 #else
791  IoStackLocation)->Parameters.FileSystemControl.FsControlCode;
792 #endif
793 
794  switch (FsControlCode)
795  {
796  case FSCTL_LOCK_VOLUME:
797  Status = FFSLockVolume(IrpContext);
798  break;
799 
800  case FSCTL_UNLOCK_VOLUME:
801  Status = FFSUnlockVolume(IrpContext);
802  break;
803 
805  Status = FFSDismountVolume(IrpContext);
806  break;
807 
809  Status = FFSIsVolumeMounted(IrpContext);
810  break;
811 
813  Status = FFSInvalidateVolumes(IrpContext);
814  break;
815 
816 #if (_WIN32_WINNT >= 0x0500)
818  Status = FFSAllowExtendedDasdIo(IrpContext);
819  break;
820 #endif //(_WIN32_WINNT >= 0x0500)
821 
822  default:
823 
824  FFSPrint((DBG_ERROR, "FFSUserFsRequest: Invalid User Request: %xh.\n", FsControlCode));
826 
827  FFSCompleteIrpContext(IrpContext, Status);
828  }
829 
830  return Status;
831 }
832 
833 
834 BOOLEAN
836  IN PFFS_IRP_CONTEXT IrpContext,
838 {
839  PIRP Irp;
840  KEVENT Event;
843 
844  PAGED_CODE();
845 
847 
849  TargetDevice,
850  NULL,
851  0,
852  NULL,
853  0,
854  FALSE,
855  &Event,
856  &IoStatus);
857 
858  if (Irp == NULL)
859  {
860  return FALSE;
861  }
862 
864 
866 
867  if (Status == STATUS_PENDING)
868  {
869 
871  Executive,
872  KernelMode,
873  FALSE,
875 
876  Status = IoStatus.Status;
877  }
878 
880 }
881 
882 
884 NTSTATUS
886  IN PFFS_IRP_CONTEXT IrpContext)
887 {
889  BOOLEAN GlobalDataResourceAcquired = FALSE;
890  PIRP Irp;
891  PIO_STACK_LOCATION IoStackLocation;
894  PDEVICE_OBJECT VolumeDeviceObject = NULL;
895  PFFS_VCB Vcb;
896  PFFS_SUPER_BLOCK FFSSb = NULL;
897  ULONG dwBytes;
898  DISK_GEOMETRY DiskGeometry;
899 
900  PAGED_CODE();
901 
902  _SEH2_TRY
903  {
904  ASSERT(IrpContext != NULL);
905 
906  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
907  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
908 
909  MainDeviceObject = IrpContext->DeviceObject;
910 
911  //
912  // Make sure we can wait.
913  //
914 
915  SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT);
916 
917  //
918  // This request is only allowed on the main device object
919  //
921  {
923  _SEH2_LEAVE;
924  }
925 
927  &(FFSGlobal->Resource),
928  TRUE);
929 
930  GlobalDataResourceAcquired = TRUE;
931 
933  {
935  _SEH2_LEAVE;
936  }
937 
938  Irp = IrpContext->Irp;
939 
940  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
941 
943  IoStackLocation->Parameters.MountVolume.DeviceObject;
944 
945  dwBytes = sizeof(DISK_GEOMETRY);
949  NULL,
950  0,
951  &DiskGeometry,
952  &dwBytes);
953 
954  if (!NT_SUCCESS(Status))
955  {
956  _SEH2_LEAVE;
957  }
958 
960  MainDeviceObject->DriverObject,
961  sizeof(FFS_VCB),
962  NULL,
964  0,
965  FALSE,
966  &VolumeDeviceObject);
967 
968  if (!NT_SUCCESS(Status))
969  {
970  _SEH2_LEAVE;
971  }
972 
973  VolumeDeviceObject->StackSize = (CCHAR)(TargetDeviceObject->StackSize + 1);
974 
975  if (TargetDeviceObject->AlignmentRequirement >
976  VolumeDeviceObject->AlignmentRequirement)
977  {
978 
979  VolumeDeviceObject->AlignmentRequirement =
980  TargetDeviceObject->AlignmentRequirement;
981  }
982 
983  (IoStackLocation->Parameters.MountVolume.Vpb)->DeviceObject =
984  VolumeDeviceObject;
985 
986  Vcb = (PFFS_VCB)VolumeDeviceObject->DeviceExtension;
987 
988  RtlZeroMemory(Vcb, sizeof(FFS_VCB));
989 
990  Vcb->Identifier.Type = FFSVCB;
991  Vcb->Identifier.Size = sizeof(FFS_VCB);
992 
993  Vcb->TargetDeviceObject = TargetDeviceObject;
994  Vcb->DiskGeometry = DiskGeometry;
995 
997 
998  if (!NT_SUCCESS(Status))
999  {
1000  _SEH2_LEAVE;
1001  }
1002 
1003 
1004  FFSSb = Vcb->ffs_super_block;
1005 
1006  Vcb->BlockSize = FFSSb->fs_bsize;
1007  Vcb->SectorBits = FFSLog2(SECTOR_SIZE);
1008 
1009  Status = FFSInitializeVcb(IrpContext, Vcb, FFSSb, TargetDeviceObject,
1010  VolumeDeviceObject, IoStackLocation->Parameters.MountVolume.Vpb);
1011 
1012  if (NT_SUCCESS(Status))
1013  {
1015  {
1016  SetFlag(Vcb->Flags, VCB_WRITE_PROTECTED);
1017  }
1018  else
1019  {
1021  }
1022 
1023  SetFlag(Vcb->Flags, VCB_MOUNTED);
1024 
1025  FFSInsertVcb(Vcb);
1026 
1027  ClearFlag(VolumeDeviceObject->Flags, DO_DEVICE_INITIALIZING);
1028  }
1029  }
1030 
1032  {
1033  if (GlobalDataResourceAcquired)
1034  {
1036  &FFSGlobal->Resource,
1038  }
1039 
1040  if (!NT_SUCCESS(Status))
1041  {
1042  if (FFSSb)
1043  {
1044  ExFreePool(FFSSb);
1045  }
1046 
1047  if (VolumeDeviceObject)
1048  {
1049  IoDeleteDevice(VolumeDeviceObject);
1050  }
1051  }
1052 
1053  if (!IrpContext->ExceptionInProgress)
1054  {
1055  if (NT_SUCCESS(Status))
1056  {
1057  ClearFlag(VolumeDeviceObject->Flags, DO_DEVICE_INITIALIZING);
1058  }
1059 
1060  FFSCompleteIrpContext(IrpContext, Status);
1061  }
1062  } _SEH2_END;
1063 
1064  return Status;
1065 }
1066 
1067 
1069 NTSTATUS
1071  IN PFFS_IRP_CONTEXT IrpContext)
1072 {
1075  PFFS_SUPER_BLOCK FFSSb = NULL;
1076  PFFS_VCB Vcb = 0;
1077  BOOLEAN VcbResourceAcquired = FALSE;
1078  BOOLEAN GlobalResourceAcquired = FALSE;
1079  PIRP Irp;
1080  PIO_STACK_LOCATION IoStackLocation;
1081  ULONG ChangeCount;
1082  ULONG dwReturn;
1083 
1084  PAGED_CODE();
1085 
1086  _SEH2_TRY
1087  {
1088  ASSERT(IrpContext != NULL);
1089 
1090  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
1091  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
1092 
1093  DeviceObject = IrpContext->DeviceObject;
1094  //
1095  // This request is not allowed on the main device object
1096  //
1098  {
1100  _SEH2_LEAVE;
1101  }
1102 
1104  &FFSGlobal->Resource,
1105  TRUE);
1106 
1107  GlobalResourceAcquired = TRUE;
1108 
1110 
1111  ASSERT(Vcb != NULL);
1112 
1113  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
1114  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
1115 
1117  &Vcb->MainResource,
1118  TRUE);
1119 
1120  VcbResourceAcquired = TRUE;
1121 
1122  if (!FlagOn(Vcb->TargetDeviceObject->Flags, DO_VERIFY_VOLUME))
1123  {
1125  _SEH2_LEAVE;
1126  }
1127 
1128  if (!IsMounted(Vcb))
1129  {
1131  _SEH2_LEAVE;
1132  }
1133 
1134  dwReturn = sizeof(ULONG);
1136  Vcb->TargetDeviceObject,
1138  NULL,
1139  0,
1140  &ChangeCount,
1141  &dwReturn);
1142 
1143  if (ChangeCount != Vcb->ChangeCount)
1144  {
1146  _SEH2_LEAVE;
1147  }
1148 
1149  Irp = IrpContext->Irp;
1150 
1151  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
1152 
1153  if (((((FFSSb = FFSLoadSuper(Vcb, TRUE, SBLOCK_UFS1)) != NULL) && (FFSSb->fs_magic == FS_UFS1_MAGIC)) ||
1154  (((FFSSb = FFSLoadSuper(Vcb, TRUE, SBLOCK_UFS2)) != NULL) && (FFSSb->fs_magic == FS_UFS2_MAGIC))) &&
1155  (memcmp(FFSSb->fs_id, SUPER_BLOCK->fs_id, 8) == 0) &&
1156  (memcmp(FFSSb->fs_volname, SUPER_BLOCK->fs_volname, 16) == 0))
1157  {
1158  ClearFlag(Vcb->TargetDeviceObject->Flags, DO_VERIFY_VOLUME);
1159 
1160  if (FFSIsMediaWriteProtected(IrpContext, Vcb->TargetDeviceObject))
1161  {
1162  SetFlag(Vcb->Flags, VCB_WRITE_PROTECTED);
1163  }
1164  else
1165  {
1167  }
1168 
1169  FFSPrint((DBG_INFO, "FFSVerifyVolume: Volume verify succeeded.\n"));
1170 
1172  }
1173  else
1174  {
1176 
1178 
1179  SetFlag(Vcb->Flags, VCB_DISMOUNT_PENDING);
1180 
1181  ClearFlag(Vcb->TargetDeviceObject->Flags, DO_VERIFY_VOLUME);
1182 
1183  FFSPrint((DBG_INFO, "FFSVerifyVolume: Volume verify failed.\n"));
1184  }
1185  }
1186 
1188  {
1189  if (FFSSb)
1190  ExFreePool(FFSSb);
1191 
1192  if (VcbResourceAcquired)
1193  {
1195  &Vcb->MainResource,
1197  }
1198 
1199  if (GlobalResourceAcquired)
1200  {
1202  &FFSGlobal->Resource,
1204  }
1205 
1206  if (!IrpContext->ExceptionInProgress)
1207  {
1208  FFSCompleteIrpContext(IrpContext, Status);
1209  }
1210  } _SEH2_END;
1211 
1212  return Status;
1213 }
1214 
1215 
1217 NTSTATUS
1219  IN PFFS_IRP_CONTEXT IrpContext)
1220 {
1221  PAGED_CODE();
1222 
1223  ASSERT(IrpContext);
1224 
1225  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
1226  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
1227 
1228  return FFSVerifyVolume(IrpContext);
1229 }
1230 
1231 
1233 NTSTATUS
1235  IN PFFS_IRP_CONTEXT IrpContext)
1236 {
1239  PFFS_VCB Vcb = 0;
1240  BOOLEAN VcbResourceAcquired = FALSE;
1241 
1242  PAGED_CODE();
1243 
1244  _SEH2_TRY
1245  {
1246  ASSERT(IrpContext != NULL);
1247 
1248  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
1249  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
1250 
1251  DeviceObject = IrpContext->DeviceObject;
1252 
1253  //
1254  // This request is not allowed on the main device object
1255  //
1257  {
1259  _SEH2_LEAVE;
1260  }
1261 
1263 
1264  ASSERT(Vcb != NULL);
1265 
1266  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
1267  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
1268 
1269  ASSERT(IsMounted(Vcb));
1270 
1272  &Vcb->MainResource,
1273  TRUE);
1274 
1275  VcbResourceAcquired = TRUE;
1276 
1277  if (IsFlagOn(Vcb->Flags, VCB_DISMOUNT_PENDING))
1278  {
1280  _SEH2_LEAVE;
1281  }
1282 
1283  /*
1284  if (!FlagOn(Vcb->Flags, VCB_VOLUME_LOCKED))
1285  {
1286  FFSPrint((DBG_ERROR, "FFSDismount: Volume is not locked.\n"));
1287 
1288  Status = STATUS_ACCESS_DENIED;
1289  _SEH2_LEAVE;
1290  }
1291  */
1292 
1294 
1296 
1298 
1300  &Vcb->MainResource,
1302 
1303  VcbResourceAcquired = FALSE;
1304 
1305  FFSCheckDismount(IrpContext, Vcb, TRUE);
1306 
1307  FFSPrint((DBG_INFO, "FFSDismount: Volume dismount pending.\n"));
1308 
1310  }
1312  {
1313  if (VcbResourceAcquired)
1314  {
1316  &Vcb->MainResource,
1318  }
1319 
1320  if (!IrpContext->ExceptionInProgress)
1321  {
1322  FFSCompleteIrpContext(IrpContext, Status);
1323  }
1324  } _SEH2_END;
1325 
1326  return Status;
1327 }
1328 
1329 
1331 BOOLEAN
1333  IN PFFS_IRP_CONTEXT IrpContext,
1334  IN PFFS_VCB Vcb,
1335  IN BOOLEAN bForce)
1336 {
1337  KIRQL Irql;
1338  PVPB Vpb = Vcb->Vpb;
1339  BOOLEAN bDeleted = FALSE;
1340  ULONG UnCleanCount = 0;
1341 
1342  PAGED_CODE();
1343 
1345  &FFSGlobal->Resource, TRUE);
1346 
1348  &Vcb->MainResource, TRUE);
1349 
1350  if ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
1351  (IrpContext->RealDevice == Vcb->RealDevice))
1352  {
1353  UnCleanCount = 3;
1354  }
1355  else
1356  {
1357  UnCleanCount = 2;
1358  }
1359 
1361 
1362  if ((Vpb->ReferenceCount == UnCleanCount) || bForce)
1363  {
1364 
1365  if ((Vpb->ReferenceCount != UnCleanCount) && bForce)
1366  {
1367  FFSBreakPoint();
1368  }
1369 
1370  ClearFlag(Vpb->Flags, VPB_MOUNTED);
1371  ClearFlag(Vpb->Flags, VPB_LOCKED);
1372 
1373  if ((Vcb->RealDevice != Vpb->RealDevice) &&
1374 #ifdef _MSC_VER
1375 #pragma prefast( suppress: 28175, "allowed in file system drivers" )
1376 #endif
1377  (Vcb->RealDevice->Vpb == Vpb))
1378  {
1379  SetFlag(Vcb->RealDevice->Flags, DO_DEVICE_INITIALIZING);
1380  SetFlag(Vpb->Flags, VPB_PERSISTENT);
1381  }
1382 
1383  FFSRemoveVcb(Vcb);
1384 
1385  ClearFlag(Vpb->Flags, VPB_MOUNTED);
1386  SetFlag(Vcb->Flags, VCB_DISMOUNT_PENDING);
1387 
1388  Vpb->DeviceObject = NULL;
1389 
1390  bDeleted = TRUE;
1391  }
1392 
1393 #if 0
1394 
1395  else if ((Vpb->RealDevice->Vpb == Vpb) && bForce)
1396  {
1397  PVPB NewVpb;
1398 
1399 #define TAG_VPB ' bpV'
1400 
1402  sizeof(VPB), TAG_VPB);
1403 
1404  NewVpb->Type = IO_TYPE_VPB;
1405  NewVpb->Size = sizeof(VPB);
1406  NewVpb->RealDevice = Vcb->Vpb->RealDevice;
1407 
1408  NewVpb->RealDevice->Vpb = NewVpb;
1409 
1410  NewVpb->Flags = FlagOn(Vcb->Vpb->Flags, VPB_REMOVE_PENDING);
1411 
1412  NewVpb = NULL;
1413 
1414  ClearFlag(Vcb->Flags, VCB_MOUNTED);
1416  }
1417 
1418 #endif
1419 
1421 
1423  &Vcb->MainResource,
1425 
1427  &FFSGlobal->Resource,
1429 
1430  if (bDeleted)
1431  {
1432 #if 0
1433  FFSBreakPoint(); /* XP에서 브레이크 포인트 발생 */
1434 #endif
1435 
1436  FFSFreeVcb(Vcb);
1437  }
1438 
1439  return bDeleted;
1440 }
1441 
1442 
1444 NTSTATUS
1446  IN PFFS_VCB Vcb,
1447  IN BOOLEAN FlushBeforePurge)
1448 {
1449  PFFS_FCB Fcb;
1450  LIST_ENTRY FcbList;
1451  PLIST_ENTRY ListEntry;
1452  PFCB_LIST_ENTRY FcbListEntry;
1453 
1454  PAGED_CODE();
1455 
1456  _SEH2_TRY
1457  {
1458  ASSERT(Vcb != NULL);
1459 
1460  ASSERT((Vcb->Identifier.Type == FFSVCB) &&
1461  (Vcb->Identifier.Size == sizeof(FFS_VCB)));
1462 
1463  if (IsFlagOn(Vcb->Flags, VCB_READ_ONLY) ||
1464  IsFlagOn(Vcb->Flags, VCB_WRITE_PROTECTED))
1465  {
1466  FlushBeforePurge = FALSE;
1467  }
1468 
1469  FcbListEntry= NULL;
1470  InitializeListHead(&FcbList);
1471 
1472  for (ListEntry = Vcb->FcbList.Flink;
1473  ListEntry != &Vcb->FcbList;
1474  ListEntry = ListEntry->Flink)
1475  {
1476  Fcb = CONTAINING_RECORD(ListEntry, FFS_FCB, Next);
1477 
1478  Fcb->ReferenceCount++;
1479 
1480  FFSPrint((DBG_INFO, "FFSPurgeVolume: %s refercount=%xh\n", Fcb->AnsiFileName.Buffer, Fcb->ReferenceCount));
1481 
1482  FcbListEntry = ExAllocatePoolWithTag(PagedPool, sizeof(FCB_LIST_ENTRY), FFS_POOL_TAG);
1483 
1484  if (FcbListEntry)
1485  {
1486  FcbListEntry->Fcb = Fcb;
1487 
1488  InsertTailList(&FcbList, &FcbListEntry->Next);
1489  }
1490  else
1491  {
1492  FFSPrint((DBG_ERROR, "FFSPurgeVolume: Error allocating FcbListEntry ...\n"));
1493  }
1494  }
1495 
1496  while (!IsListEmpty(&FcbList))
1497  {
1498  ListEntry = RemoveHeadList(&FcbList);
1499 
1500  FcbListEntry = CONTAINING_RECORD(ListEntry, FCB_LIST_ENTRY, Next);
1501 
1502  Fcb = FcbListEntry->Fcb;
1503 
1505  &Fcb->MainResource,
1506  TRUE))
1507  {
1508  FFSPurgeFile(Fcb, FlushBeforePurge);
1509 
1510  if (!Fcb->OpenHandleCount && Fcb->ReferenceCount == 1)
1511  {
1512  RemoveEntryList(&Fcb->Next);
1513  FFSFreeFcb(Fcb);
1514  }
1515  else
1516  {
1518  &Fcb->MainResource,
1520  }
1521  }
1522 
1523  ExFreePool(FcbListEntry);
1524  }
1525 
1526  if (FlushBeforePurge)
1527  {
1528  ExAcquireSharedStarveExclusive(&Vcb->PagingIoResource, TRUE);
1529  ExReleaseResourceLite(&Vcb->PagingIoResource);
1530 
1531  CcFlushCache(&Vcb->SectionObject, NULL, 0, NULL);
1532  }
1533 
1534  if (Vcb->SectionObject.ImageSectionObject)
1535  {
1536  MmFlushImageSection(&Vcb->SectionObject, MmFlushForWrite);
1537  }
1538 
1539  if (Vcb->SectionObject.DataSectionObject)
1540  {
1541  CcPurgeCacheSection(&Vcb->SectionObject, NULL, 0, FALSE);
1542  }
1543 
1544  FFSPrint((DBG_INFO, "FFSPurgeVolume: Volume flushed and purged.\n"));
1545  }
1547  {
1548  // Nothing
1549  } _SEH2_END;
1550 
1551  return STATUS_SUCCESS;
1552 }
1553 
1554 
1556 NTSTATUS
1558  IN PFFS_FCB Fcb,
1559  IN BOOLEAN FlushBeforePurge)
1560 {
1562 
1563  PAGED_CODE();
1564 
1565  ASSERT(Fcb != NULL);
1566 
1567  ASSERT((Fcb->Identifier.Type == FFSFCB) &&
1568  (Fcb->Identifier.Size == sizeof(FFS_FCB)));
1569 
1570 
1571  if(!IsFlagOn(Fcb->Vcb->Flags, VCB_READ_ONLY) && FlushBeforePurge &&
1572  !IsFlagOn(Fcb->Vcb->Flags, VCB_WRITE_PROTECTED))
1573  {
1574 
1575  FFSPrint((DBG_INFO, "FFSPurgeFile: CcFlushCache on %s.\n",
1576  Fcb->AnsiFileName.Buffer));
1577 
1580 
1581  CcFlushCache(&Fcb->SectionObject, NULL, 0, &IoStatus);
1582 
1584  }
1585 
1586  if (Fcb->SectionObject.ImageSectionObject)
1587  {
1588 
1589  FFSPrint((DBG_INFO, "FFSPurgeFile: MmFlushImageSection on %s.\n",
1590  Fcb->AnsiFileName.Buffer));
1591 
1592  MmFlushImageSection(&Fcb->SectionObject, MmFlushForWrite);
1593  }
1594 
1595  if (Fcb->SectionObject.DataSectionObject)
1596  {
1597 
1598  FFSPrint((DBG_INFO, "FFSPurgeFile: CcPurgeCacheSection on %s.\n",
1599  Fcb->AnsiFileName.Buffer));
1600 
1601  CcPurgeCacheSection(&Fcb->SectionObject, NULL, 0, FALSE);
1602  }
1603 
1604  return STATUS_SUCCESS;
1605 }
1606 
1607 
1609 NTSTATUS
1611  IN PFFS_IRP_CONTEXT IrpContext)
1612 {
1613  PIRP Irp;
1614  NTSTATUS Status;
1615  PFFS_BSD_PARTITION BSDPartition;
1616 
1617  _SEH2_TRY
1618  {
1619  ASSERT(IrpContext != NULL);
1620 
1621  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
1622  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
1623 
1624  Irp = IrpContext->Irp;
1625 
1626  BSDPartition = (PFFS_BSD_PARTITION)Irp->AssociatedIrp.SystemBuffer;
1627  FFSGlobal->PartitionNumber = BSDPartition->Number;
1628 
1630  }
1632  {
1633  if (!IrpContext->ExceptionInProgress)
1634  {
1635  FFSCompleteIrpContext(IrpContext, Status);
1636  }
1637  } _SEH2_END;
1638 
1639  return Status;
1640 }
1641 
1642 
1644 NTSTATUS
1646  IN PFFS_IRP_CONTEXT IrpContext)
1647 {
1648  NTSTATUS Status;
1649 
1650  PAGED_CODE();
1651 
1652  ASSERT(IrpContext);
1653 
1654  ASSERT((IrpContext->Identifier.Type == FFSICX) &&
1655  (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
1656 
1657  switch (IrpContext->MinorFunction)
1658  {
1660  Status = FFSUserFsRequest(IrpContext);
1661  break;
1662 
1663  case IRP_MN_MOUNT_VOLUME:
1664  Status = FFSMountVolume(IrpContext);
1665  break;
1666 
1667  case IRP_MN_VERIFY_VOLUME:
1668  Status = FFSVerifyVolume(IrpContext);
1669  break;
1670 
1671  default:
1672 
1673  FFSPrint((DBG_ERROR, "FFSFilsSystemControl: Invalid Device Request.\n"));
1675  FFSCompleteIrpContext(IrpContext, Status);
1676  }
1677 
1678  return Status;
1679 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
Definition: ext2fs.h:1103
#define ExGetCurrentResourceThread()
Definition: env_spec_w32.h:633
Definition: ffsdrv.h:281
__drv_mustHoldCriticalRegion NTSTATUS FFSSelectBSDPartition(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1610
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
#define LABELOFFSET
Definition: disklabel.h:64
#define IN
Definition: typedefs.h:38
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define IsMounted(Vcb)
Definition: ext2fs.h:803
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
boolean suppress
Definition: jpeglib.h:1005
#define TRUE
Definition: types.h:120
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1221
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PFFS_GLOBAL FFSGlobal
Definition: init.c:22
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
USHORT Flags
Definition: iotypes.h:169
#define FS_VERSION
Definition: ffsdrv.h:81
#define __drv_mustHoldCriticalRegion
Definition: ffsdrv.h:34
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
_Must_inspect_result_ __drv_aliasesMem PDEVICE_OBJECT _In_ PDEVICE_OBJECT TargetDevice
Definition: iofuncs.h:688
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
PFFS_SUPER_BLOCK FFSLoadSuper(IN PFFS_VCB Vcb, IN BOOLEAN bVerify, IN ULONGLONG SuperBlockOffset)
Definition: ffs.c:75
struct _FFS_BSD_PARTITION * PFFS_BSD_PARTITION
NTSTATUS FFSGetPartition(IN PDEVICE_OBJECT DeviceObject, OUT ULONGLONG *StartOffset)
Definition: fsctl.c:84
_In_ PIRP Irp
Definition: csq.h:116
#define VCB_MOUNTED
Definition: ext2fs.h:781
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
VOID FFSSetVpbFlag(IN PVPB Vpb, IN USHORT Flag)
Definition: fsctl.c:54
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
NTSTATUS FFSUnlockVcb(IN PFFS_VCB Vcb, IN PFILE_OBJECT FileObject)
Definition: fsctl.c:491
__drv_mustHoldCriticalRegion NTSTATUS FFSIsVolumeMounted(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1218
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_DISK_CHECK_VERIFY
Definition: cdrw_usr.h:175
#define DO_VERIFY_VOLUME
Definition: env_spec_w32.h:393
ULONG Flags
Definition: ffsdrv.h:395
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1201
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
PVPB Vpb
Definition: cdstruc.h:517
Definition: ffsdrv.h:283
NTSTATUS FFSDiskIoControl(IN PDEVICE_OBJECT DeviceOjbect, IN ULONG IoctlCode, IN PVOID InputBuffer, IN ULONG InputBufferSize, IN OUT PVOID OutputBuffer, IN OUT PULONG OutputBufferSize)
Definition: block.c:500
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define VPB_PERSISTENT
Definition: iotypes.h:1765
#define _GNU_NTIFS_
int32_t fs_bsize
Definition: fs.h:248
NTSTATUS FFSLockVcb(IN PFFS_VCB Vcb, IN PFILE_OBJECT FileObject)
Definition: fsctl.c:358
#define STATUS_WRONG_VOLUME
Definition: udferr_usr.h:140
#define InsertTailList(ListHead, Entry)
Definition: fs.h:235
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_Out_ PKIRQL Irql
Definition: csq.h:179
u_char fs_fsmnt[MAXMNTLEN]
Definition: fs.h:299
#define TAG_VPB
Definition: cdprocs.h:98
__drv_mustHoldCriticalRegion NTSTATUS FFSPurgeFile(IN PFFS_FCB Fcb, IN BOOLEAN FlushBeforePurge)
Definition: fsctl.c:1557
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
PDEVICE_OBJECT DeviceObject
Definition: ffsdrv.h:371
#define PAGED_CODE()
Definition: video.h:57
__drv_mustHoldCriticalRegion NTSTATUS FFSFlushVolume(IN PFFS_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:107
_SEH2_TRY
Definition: create.c:4250
#define FFSBreakPoint()
Definition: ffsdrv.h:43
__drv_mustHoldCriticalRegion NTSTATUS FFSPurgeVolume(IN PFFS_VCB Vcb, IN BOOLEAN FlushBeforePurge)
Definition: fsctl.c:1445
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define DISKMAGIC
Definition: disklabel.h:126
UCHAR KIRQL
Definition: env_spec_w32.h:591
__drv_mustHoldCriticalRegion NTSTATUS FFSUserFsRequest(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:767
else
Definition: tritemp.h:161
NTFSIDENTIFIER Identifier
Definition: ntfs.h:499
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4048
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__drv_mustHoldCriticalRegion NTSTATUS FFSDismountVolume(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1234
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS FFSReadDisk(IN PFFS_VCB Vcb, IN ULONGLONG Offset, IN ULONG Size, IN PVOID Buffer, IN BOOLEAN bVerify)
Definition: block.c:448
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define CCB_ALLOW_EXTENDED_DASD_IO
Definition: ext2fs.h:1028
#define SE_TCB_PRIVILEGE
Definition: security.c:661
#define SECTOR_SIZE
Definition: winldr.h:34
#define FSCTL_INVALIDATE_VOLUMES
Definition: nt_native.h:847
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
#define VPB_LOCKED
Definition: iotypes.h:1764
#define IsFlagOn(a, b)
Definition: ext2fs.h:177
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
__drv_mustHoldCriticalRegion NTSTATUS FFSInvalidateVolumes(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:610
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
BOOLEAN FFSIsMediaWriteProtected(IN PFFS_IRP_CONTEXT IrpContext, IN PDEVICE_OBJECT TargetDevice)
Definition: fsctl.c:835
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1779
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
struct _FFS_VCB * PFFS_VCB
Definition: bufpool.h:45
__drv_mustHoldCriticalRegion NTSTATUS FFSFlushFiles(IN PFFS_VCB Vcb, BOOLEAN bShutDown)
Definition: flush.c:54
#define VPB_REMOVE_PENDING
Definition: ntifs_ex.h:428
__drv_mustHoldCriticalRegion NTSTATUS FFSInitializeVcb(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN PFFS_SUPER_BLOCK FFSSb, IN PDEVICE_OBJECT TargetDevice, IN PDEVICE_OBJECT VolumeDevice, IN PVPB Vpb)
Definition: memory.c:1551
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define SUPER_BLOCK
Definition: ext2fs.h:90
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
ULONG PartitionNumber
Definition: ffsdrv.h:397
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
ULONG OpenHandleCount
Definition: ntfs.h:521
VOID FFSClearVpbFlag(IN PVPB Vpb, IN USHORT Flag)
Definition: fsctl.c:69
NTSTATUS NTAPI CcWaitForCurrentLazyWriterActivity(VOID)
Definition: lazyrite.c:30
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_In_ HANDLE Handle
Definition: extypes.h:390
int32_t fs_magic
Definition: fs.h:341
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4046
NTSTATUS FFSLoadDiskLabel(PDEVICE_OBJECT DeviceObject, IN PFFS_VCB Vcb)
Definition: fsctl.c:141
VOID FFSRemoveVcb(PFFS_VCB Vcb)
Definition: memory.c:1542
LIST_ENTRY List
Definition: psmgr.c:57
__drv_mustHoldCriticalRegion NTSTATUS FFSVerifyVolume(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1070
int32_t fs_id[2]
Definition: fs.h:279
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
PEXT2_FCB Fcb
Definition: ext2fs.h:1104
BOOLEAN NTAPI MmFlushImageSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN MMFLUSH_TYPE FlushType)
Definition: section.c:4796
char CCHAR
Definition: typedefs.h:50
LARGE_INTEGER StartingOffset
Definition: ntdddisk.h:393
uint64_t ULONGLONG
Definition: typedefs.h:65
#define MAXPARTITIONS
Definition: disklabel.h:65
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:172
__drv_mustHoldCriticalRegion VOID FFSFreeFcb(IN PFFS_FCB Fcb)
Definition: memory.c:715
#define Vcb
Definition: cdprocs.h:1425
Definition: xml2sdb.h:79
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
LIST_ENTRY Next
Definition: ext2fs.h:1105
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
Definition: user_lib.cpp:531
#define FS_BSDFFS
Definition: disklabel.h:360
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1954
#define FSCTL_ALLOW_EXTENDED_DASD_IO
Definition: winioctl.h:124
CSHORT Size
Definition: iotypes.h:168
__drv_mustHoldCriticalRegion VOID FFSFreeVcb(IN PFFS_VCB Vcb)
Definition: memory.c:1886
__drv_mustHoldCriticalRegion NTSTATUS FFSUnlockVolume(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:541
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: ntfs.h:520
struct disklabel * PDISKLABEL
Definition: ffsdrv.h:260
#define VCB_WRITE_PROTECTED
Definition: ext2fs.h:796
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
__drv_mustHoldCriticalRegion NTSTATUS FFSCompleteIrpContext(IN PFFS_IRP_CONTEXT IrpContext, IN NTSTATUS Status)
Definition: read.c:53
__drv_mustHoldCriticalRegion BOOLEAN FFSCheckDismount(IN PFFS_IRP_CONTEXT IrpContext, IN PFFS_VCB Vcb, IN BOOLEAN bForce)
Definition: fsctl.c:1332
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:88
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:871
LIST_ENTRY VcbList
Definition: ffsdrv.h:374
#define VCB_DISMOUNT_PENDING
Definition: ext2fs.h:782
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
ULONG Type
Definition: ntfs.h:95
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
#define VOID
Definition: acefi.h:82
#define FCB_FILE_MODIFIED
Definition: ext2fs.h:873
Definition: ffsdrv.h:280
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define DBG_ERROR
Definition: ffsdrv.h:1031
Definition: typedefs.h:117
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define FFS_POOL_TAG
Definition: ffsdrv.h:817
__drv_mustHoldCriticalRegion NTSTATUS FFSMountVolume(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:885
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
ERESOURCE MainResource
Definition: ntfs.h:512
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
#define FS_UFS1_MAGIC
Definition: fs.h:369
#define IO_TYPE_VPB
#define VCB_READ_ONLY
Definition: ext2fs.h:795
#define LABELSECTOR
Definition: disklabel.h:63
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
struct _VPB VPB
Status
Definition: gdiplustypes.h:24
#define FFSPrint(arg)
Definition: ffsdrv.h:1047
BOOLEAN FFSIsHandleCountZero(IN PFFS_VCB Vcb)
Definition: fsctl.c:327
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1063
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
ERESOURCE Resource
Definition: ffsdrv.h:352
struct _DISK_GEOMETRY DISK_GEOMETRY
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
_SEH2_END
Definition: create.c:4424
#define FS_UFS2_MAGIC
Definition: fs.h:370
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static PDEVICE_OBJECT MainDeviceObject
_SEH2_FINALLY
Definition: create.c:4395
VOID FFSInsertVcb(PFFS_VCB Vcb)
Definition: memory.c:1534
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define FSCTL_IS_VOLUME_MOUNTED
Definition: nt_native.h:836
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG FsControlCode
Definition: fltkernel.h:1369
#define VCB_VOLUME_LOCKED
Definition: ext2fs.h:780
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
__drv_mustHoldCriticalRegion NTSTATUS FFSAllowExtendedDasdIo(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:729
CSHORT Type
Definition: iotypes.h:167
ULONG FFSLog2(ULONG Value)
Definition: misc.c:33
__drv_mustHoldCriticalRegion NTSTATUS FFSFileSystemControl(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:1645
Definition: iotypes.h:166
#define OUT
Definition: typedefs.h:39
#define STATUS_VOLUME_DISMOUNTED
Definition: ntstatus.h:733
#define STATUS_NOT_LOCKED
Definition: ntstatus.h:265
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define SBLOCK_UFS2
Definition: fs.h:93
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
ERESOURCE PagingIoResource
Definition: ntfs.h:511
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PVCB Vcb
Definition: cdstruc.h:939
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define DBG_INFO
Definition: ffsdrv.h:1034
IO_STACK_LOCATION * PEXTENDED_IO_STACK_LOCATION
Definition: ext2fs.h:174
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_LEAVE
Definition: filesup.c:20
#define SBLOCK_UFS1
Definition: fs.h:92
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
_In_ PFCB Fcb
Definition: cdprocs.h:151
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1664
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define VPB_MOUNTED
Definition: iotypes.h:1763
#define KdPrint(x)
Definition: env_spec_w32.h:288
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1111
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1212
__drv_mustHoldCriticalRegion NTSTATUS FFSLockVolume(IN PFFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:417
ULONG Size
Definition: ntfs.h:96
#define FFS_UNLOAD_PENDING
Definition: ffsdrv.h:404
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1664
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
#define DBG_VITAL
Definition: ffsdrv.h:1030
struct _FFS_VCB FFS_VCB
LONGLONG QuadPart
Definition: typedefs.h:112
u_char fs_volname[MAXVOLLEN]
Definition: fs.h:300