ReactOS  0.4.14-dev-554-g2f8d847
fsctl.c
Go to the documentation of this file.
1 /*
2  * ReactOS kernel
3  * Copyright (C) 2002 ReactOS Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * COPYRIGHT: See COPYING in the top level directory
20  * PROJECT: ReactOS kernel
21  * FILE: drivers/filesystems/ntfs/fsctl.c
22  * PURPOSE: NTFS filesystem driver
23  * PROGRAMMER: Eric Kohl
24  * Valentin Verkhovsky
25  * Pierre Schweitzer
26  */
27 
28 /* INCLUDES *****************************************************************/
29 
30 #include "ntfs.h"
31 
32 #include <ntdddisk.h>
33 
34 #define NDEBUG
35 #include <debug.h>
36 
37 /* FUNCTIONS ****************************************************************/
38 
39 /*
40  * FUNCTION: Tests if the device contains a filesystem that can be mounted
41  * by this fsd.
42  */
43 static
46 {
48  DISK_GEOMETRY DiskGeometry;
52 
53  DPRINT("NtfsHasFileSystem() called\n");
54 
55  Size = sizeof(DISK_GEOMETRY);
56  Status = NtfsDeviceIoControl(DeviceToMount,
58  NULL,
59  0,
60  &DiskGeometry,
61  &Size,
62  TRUE);
63  if (!NT_SUCCESS(Status))
64  {
65  DPRINT1("NtfsDeviceIoControl() failed (Status %lx)\n", Status);
66  return Status;
67  }
68 
69  if (DiskGeometry.MediaType == FixedMedia)
70  {
71  /* We have found a hard disk */
72  Size = sizeof(PARTITION_INFORMATION);
73  Status = NtfsDeviceIoControl(DeviceToMount,
75  NULL,
76  0,
78  &Size,
79  TRUE);
80  if (!NT_SUCCESS(Status))
81  {
82  DPRINT1("NtfsDeviceIoControl() failed (Status %lx)\n", Status);
83  return Status;
84  }
85 
86  if (PartitionInfo.PartitionType != PARTITION_IFS)
87  {
88  DPRINT1("Invalid partition type\n");
90  }
91  }
92 
93  DPRINT1("BytesPerSector: %lu\n", DiskGeometry.BytesPerSector);
95  DiskGeometry.BytesPerSector,
96  TAG_NTFS);
97  if (BootSector == NULL)
98  {
100  }
101 
102  Status = NtfsReadSectors(DeviceToMount,
103  0,
104  1,
105  DiskGeometry.BytesPerSector,
106  (PVOID)BootSector,
107  TRUE);
108  if (!NT_SUCCESS(Status))
109  {
110  goto ByeBye;
111  }
112 
113  /*
114  * Check values of different fields. If those fields have not expected
115  * values, we fail, to avoid mounting partitions that Windows won't mount.
116  */
117 
118  /* OEMID: this field must be NTFS */
119  if (RtlCompareMemory(BootSector->OEMID, "NTFS ", 8) != 8)
120  {
121  DPRINT1("Failed with NTFS-identifier: [%.8s]\n", BootSector->OEMID);
123  goto ByeBye;
124  }
125 
126  /* Unused0: this field must be COMPLETELY null */
127  for (k = 0; k < 7; k++)
128  {
129  if (BootSector->BPB.Unused0[k] != 0)
130  {
131  DPRINT1("Failed in field Unused0: [%.7s]\n", BootSector->BPB.Unused0);
133  goto ByeBye;
134  }
135  }
136 
137  /* Unused3: this field must be COMPLETELY null */
138  for (k = 0; k < 4; k++)
139  {
140  if (BootSector->BPB.Unused3[k] != 0)
141  {
142  DPRINT1("Failed in field Unused3: [%.4s]\n", BootSector->BPB.Unused3);
144  goto ByeBye;
145  }
146  }
147 
148  /* Check cluster size */
150  if (ClusterSize != 512 && ClusterSize != 1024 &&
151  ClusterSize != 2048 && ClusterSize != 4096 &&
152  ClusterSize != 8192 && ClusterSize != 16384 &&
153  ClusterSize != 32768 && ClusterSize != 65536)
154  {
155  DPRINT1("Cluster size failed: %hu, %hu, %hu\n",
158  ClusterSize);
160  goto ByeBye;
161  }
162 
163 ByeBye:
165 
166  return Status;
167 }
168 
169 
170 static
171 ULONG
173 {
174  ULONG ZoneReservation = 1;
176 
179  QueryTable[0].Name = L"NtfsMftZoneReservation";
180  QueryTable[0].EntryContext = &ZoneReservation;
181 
183  L"FileSystem",
184  QueryTable,
185  NULL,
186  NULL);
187 
188  return ZoneReservation;
189 }
190 
191 
192 static
193 NTSTATUS
195  PDEVICE_EXTENSION DeviceExt)
196 {
197  DISK_GEOMETRY DiskGeometry;
198  PFILE_RECORD_HEADER VolumeRecord;
201  ULONG Size;
202  PNTFS_INFO NtfsInfo = &DeviceExt->NtfsInfo;
204  PNTFS_ATTR_CONTEXT AttrCtxt;
205  PNTFS_ATTR_RECORD Attribute;
206  PNTFS_FCB VolumeFcb;
207  PWSTR VolumeNameU;
208 
209  DPRINT("NtfsGetVolumeData() called\n");
210 
211  Size = sizeof(DISK_GEOMETRY);
214  NULL,
215  0,
216  &DiskGeometry,
217  &Size,
218  TRUE);
219  if (!NT_SUCCESS(Status))
220  {
221  DPRINT("NtfsDeviceIoControl() failed (Status %lx)\n", Status);
222  return Status;
223  }
224 
225  DPRINT("BytesPerSector: %lu\n", DiskGeometry.BytesPerSector);
227  DiskGeometry.BytesPerSector,
228  TAG_NTFS);
229  if (BootSector == NULL)
230  {
232  }
233 
235  0, /* Partition boot sector */
236  1,
237  DiskGeometry.BytesPerSector,
238  (PVOID)BootSector,
239  TRUE);
240  if (!NT_SUCCESS(Status))
241  {
243  return Status;
244  }
245 
246  /* Read data from the bootsector */
247  NtfsInfo->BytesPerSector = BootSector->BPB.BytesPerSector;
250  NtfsInfo->SectorCount = BootSector->EBPB.SectorCount;
251  NtfsInfo->ClusterCount = DeviceExt->NtfsInfo.SectorCount / (ULONGLONG)DeviceExt->NtfsInfo.SectorsPerCluster;
252 
253  NtfsInfo->MftStart.QuadPart = BootSector->EBPB.MftLocation;
254  NtfsInfo->MftMirrStart.QuadPart = BootSector->EBPB.MftMirrLocation;
255  NtfsInfo->SerialNumber = BootSector->EBPB.SerialNumber;
256  if (BootSector->EBPB.ClustersPerMftRecord > 0)
257  NtfsInfo->BytesPerFileRecord = BootSector->EBPB.ClustersPerMftRecord * NtfsInfo->BytesPerCluster;
258  else
259  NtfsInfo->BytesPerFileRecord = 1 << (-BootSector->EBPB.ClustersPerMftRecord);
260  if (BootSector->EBPB.ClustersPerIndexRecord > 0)
261  NtfsInfo->BytesPerIndexRecord = BootSector->EBPB.ClustersPerIndexRecord * NtfsInfo->BytesPerCluster;
262  else
263  NtfsInfo->BytesPerIndexRecord = 1 << (-BootSector->EBPB.ClustersPerIndexRecord);
264 
265  DPRINT("Boot sector information:\n");
266  DPRINT(" BytesPerSector: %hu\n", BootSector->BPB.BytesPerSector);
267  DPRINT(" SectorsPerCluster: %hu\n", BootSector->BPB.SectorsPerCluster);
268  DPRINT(" SectorCount: %I64u\n", BootSector->EBPB.SectorCount);
269  DPRINT(" MftStart: %I64u\n", BootSector->EBPB.MftLocation);
270  DPRINT(" MftMirrStart: %I64u\n", BootSector->EBPB.MftMirrLocation);
271  DPRINT(" ClustersPerMftRecord: %lx\n", BootSector->EBPB.ClustersPerMftRecord);
272  DPRINT(" ClustersPerIndexRecord: %lx\n", BootSector->EBPB.ClustersPerIndexRecord);
273  DPRINT(" SerialNumber: %I64x\n", BootSector->EBPB.SerialNumber);
274 
276 
277  ExInitializeNPagedLookasideList(&DeviceExt->FileRecLookasideList,
278  NULL, NULL, 0, NtfsInfo->BytesPerFileRecord, TAG_FILE_REC, 0);
279 
280  DeviceExt->MasterFileTable = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
281  if (DeviceExt->MasterFileTable == NULL)
282  {
283  ExDeleteNPagedLookasideList(&DeviceExt->FileRecLookasideList);
285  }
286 
288  NtfsInfo->MftStart.u.LowPart * NtfsInfo->SectorsPerCluster,
289  NtfsInfo->BytesPerFileRecord / NtfsInfo->BytesPerSector,
290  NtfsInfo->BytesPerSector,
291  (PVOID)DeviceExt->MasterFileTable,
292  TRUE);
293  if (!NT_SUCCESS(Status))
294  {
295  DPRINT1("Failed reading MFT.\n");
296  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, DeviceExt->MasterFileTable);
297  ExDeleteNPagedLookasideList(&DeviceExt->FileRecLookasideList);
298  return Status;
299  }
300 
301  Status = FindAttribute(DeviceExt,
302  DeviceExt->MasterFileTable,
304  L"",
305  0,
306  &DeviceExt->MFTContext,
307  &DeviceExt->MftDataOffset);
308  if (!NT_SUCCESS(Status))
309  {
310  DPRINT1("Can't find data attribute for Master File Table.\n");
311  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, DeviceExt->MasterFileTable);
312  ExDeleteNPagedLookasideList(&DeviceExt->FileRecLookasideList);
313  return Status;
314  }
315 
316  VolumeRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
317  if (VolumeRecord == NULL)
318  {
319  DPRINT1("Allocation failed for volume record\n");
320  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, DeviceExt->MasterFileTable);
321  ExDeleteNPagedLookasideList(&DeviceExt->FileRecLookasideList);
323  }
324 
325  /* Read Volume File (MFT index 3) */
326  DeviceExt->StorageDevice = DeviceObject;
327  Status = ReadFileRecord(DeviceExt,
329  VolumeRecord);
330  if (!NT_SUCCESS(Status))
331  {
332  DPRINT1("Failed reading volume file\n");
333  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, VolumeRecord);
334  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, DeviceExt->MasterFileTable);
335  ExDeleteNPagedLookasideList(&DeviceExt->FileRecLookasideList);
336  return Status;
337  }
338 
339  /* Enumerate attributes */
340  NtfsDumpFileAttributes(DeviceExt, DeviceExt->MasterFileTable);
341 
342  /* Enumerate attributes */
343  NtfsDumpFileAttributes(DeviceExt, VolumeRecord);
344 
345  /* Get volume name */
346  Status = FindAttribute(DeviceExt, VolumeRecord, AttributeVolumeName, L"", 0, &AttrCtxt, NULL);
347 
348  if (NT_SUCCESS(Status) && AttrCtxt->pRecord->Resident.ValueLength != 0)
349  {
350  Attribute = AttrCtxt->pRecord;
351  DPRINT("Data length %lu\n", AttributeDataLength(Attribute));
352  NtfsInfo->VolumeLabelLength =
353  min (Attribute->Resident.ValueLength, MAXIMUM_VOLUME_LABEL_LENGTH);
354  RtlCopyMemory(NtfsInfo->VolumeLabel,
355  (PVOID)((ULONG_PTR)Attribute + Attribute->Resident.ValueOffset),
356  NtfsInfo->VolumeLabelLength);
357  VolumeNameU = NtfsInfo->VolumeLabel;
358  }
359  else
360  {
361  NtfsInfo->VolumeLabelLength = 0;
362  VolumeNameU = L"\0";
363  }
364 
365  if (NT_SUCCESS(Status))
366  {
367  ReleaseAttributeContext(AttrCtxt);
368  }
369 
370  VolumeFcb = NtfsCreateFCB(VolumeNameU, NULL, DeviceExt);
371  if (VolumeFcb == NULL)
372  {
373  DPRINT1("Failed allocating volume FCB\n");
374  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, VolumeRecord);
375  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, DeviceExt->MasterFileTable);
376  ExDeleteNPagedLookasideList(&DeviceExt->FileRecLookasideList);
378  }
379 
380  VolumeFcb->Flags = FCB_IS_VOLUME;
381  VolumeFcb->RFCB.FileSize.QuadPart = DeviceExt->NtfsInfo.SectorCount * DeviceExt->NtfsInfo.BytesPerSector;
382  VolumeFcb->RFCB.ValidDataLength = VolumeFcb->RFCB.FileSize;
383  VolumeFcb->RFCB.AllocationSize = VolumeFcb->RFCB.FileSize;
384  VolumeFcb->MFTIndex = 0;
385  DeviceExt->VolumeFcb = VolumeFcb;
386 
387  /* Get volume information */
388  Status = FindAttribute(DeviceExt, VolumeRecord, AttributeVolumeInformation, L"", 0, &AttrCtxt, NULL);
389 
390  if (NT_SUCCESS(Status) && AttrCtxt->pRecord->Resident.ValueLength != 0)
391  {
392  Attribute = AttrCtxt->pRecord;
393  DPRINT("Data length %lu\n", AttributeDataLength (Attribute));
394  VolumeInfo = (PVOID)((ULONG_PTR)Attribute + Attribute->Resident.ValueOffset);
395 
396  NtfsInfo->MajorVersion = VolumeInfo->MajorVersion;
397  NtfsInfo->MinorVersion = VolumeInfo->MinorVersion;
398  NtfsInfo->Flags = VolumeInfo->Flags;
399  }
400 
401  if (NT_SUCCESS(Status))
402  {
403  ReleaseAttributeContext(AttrCtxt);
404  }
405 
406  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, VolumeRecord);
407 
409 
410  return Status;
411 }
412 
413 
414 static
415 NTSTATUS
417  PIRP Irp)
418 {
419  PDEVICE_OBJECT NewDeviceObject = NULL;
420  PDEVICE_OBJECT DeviceToMount;
421  PIO_STACK_LOCATION Stack;
422  PNTFS_FCB Fcb = NULL;
423  PNTFS_CCB Ccb = NULL;
424  PNTFS_VCB Vcb = NULL;
427 
428  DPRINT("NtfsMountVolume() called\n");
429 
431  {
433  goto ByeBye;
434  }
435 
437  DeviceToMount = Stack->Parameters.MountVolume.DeviceObject;
438 
439  Status = NtfsHasFileSystem(DeviceToMount);
440  if (!NT_SUCCESS(Status))
441  {
442  goto ByeBye;
443  }
444 
446  sizeof(DEVICE_EXTENSION),
447  NULL,
449  0,
450  FALSE,
451  &NewDeviceObject);
452  if (!NT_SUCCESS(Status))
453  goto ByeBye;
454 
455  Lookaside = TRUE;
456 
457  NewDeviceObject->Flags |= DO_DIRECT_IO;
458  Vcb = (PVOID)NewDeviceObject->DeviceExtension;
459  RtlZeroMemory(Vcb, sizeof(NTFS_VCB));
460 
461  Vcb->Identifier.Type = NTFS_TYPE_VCB;
462  Vcb->Identifier.Size = sizeof(NTFS_TYPE_VCB);
463 
464  Status = NtfsGetVolumeData(DeviceToMount,
465  Vcb);
466  if (!NT_SUCCESS(Status))
467  goto ByeBye;
468 
469  NewDeviceObject->Vpb = DeviceToMount->Vpb;
470 
471  Vcb->StorageDevice = DeviceToMount;
472  Vcb->StorageDevice->Vpb->DeviceObject = NewDeviceObject;
473  Vcb->StorageDevice->Vpb->RealDevice = Vcb->StorageDevice;
474  Vcb->StorageDevice->Vpb->Flags |= VPB_MOUNTED;
475  NewDeviceObject->StackSize = Vcb->StorageDevice->StackSize + 1;
476  NewDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
477 
478  Vcb->StreamFileObject = IoCreateStreamFileObject(NULL,
479  Vcb->StorageDevice);
480 
481  InitializeListHead(&Vcb->FcbListHead);
482 
484  if (Fcb == NULL)
485  {
487  goto ByeBye;
488  }
489 
491  sizeof(NTFS_CCB),
492  TAG_CCB);
493  if (Ccb == NULL)
494  {
496  goto ByeBye;
497  }
498 
499  RtlZeroMemory(Ccb, sizeof(NTFS_CCB));
500 
502  Ccb->Identifier.Size = sizeof(NTFS_TYPE_CCB);
503 
504  Vcb->StreamFileObject->FsContext = Fcb;
505  Vcb->StreamFileObject->FsContext2 = Ccb;
506  Vcb->StreamFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
507  Vcb->StreamFileObject->PrivateCacheMap = NULL;
508  Vcb->StreamFileObject->Vpb = Vcb->Vpb;
509  Ccb->PtrFileObject = Vcb->StreamFileObject;
510  Fcb->FileObject = Vcb->StreamFileObject;
511  Fcb->Vcb = (PDEVICE_EXTENSION)Vcb->StorageDevice;
512 
514 
515  Fcb->RFCB.FileSize.QuadPart = Vcb->NtfsInfo.SectorCount * Vcb->NtfsInfo.BytesPerSector;
516  Fcb->RFCB.ValidDataLength.QuadPart = Vcb->NtfsInfo.SectorCount * Vcb->NtfsInfo.BytesPerSector;
517  Fcb->RFCB.AllocationSize.QuadPart = Vcb->NtfsInfo.SectorCount * Vcb->NtfsInfo.BytesPerSector; /* Correct? */
518 
519 // Fcb->Entry.ExtentLocationL = 0;
520 // Fcb->Entry.DataLengthL = DeviceExt->CdInfo.VolumeSpaceSize * BLOCKSIZE;
521 
522  _SEH2_TRY
523  {
524  CcInitializeCacheMap(Vcb->StreamFileObject,
526  TRUE,
528  Fcb);
529  }
531  {
533  goto ByeBye;
534  }
535  _SEH2_END;
536 
537  ExInitializeResourceLite(&Vcb->DirResource);
538 
539  KeInitializeSpinLock(&Vcb->FcbListLock);
540 
541  /* Get serial number */
542  NewDeviceObject->Vpb->SerialNumber = Vcb->NtfsInfo.SerialNumber;
543 
544  /* Get volume label */
545  NewDeviceObject->Vpb->VolumeLabelLength = Vcb->NtfsInfo.VolumeLabelLength;
546  RtlCopyMemory(NewDeviceObject->Vpb->VolumeLabel,
547  Vcb->NtfsInfo.VolumeLabel,
548  Vcb->NtfsInfo.VolumeLabelLength);
549 
550  FsRtlNotifyVolumeEvent(Vcb->StreamFileObject, FSRTL_VOLUME_MOUNT);
551 
553 
554 ByeBye:
555  if (!NT_SUCCESS(Status))
556  {
557  /* Cleanup */
558  if (Vcb && Vcb->StreamFileObject)
559  ObDereferenceObject(Vcb->StreamFileObject);
560 
561  if (Fcb)
563 
564  if (Ccb)
565  ExFreePool(Ccb);
566 
567  if (NewDeviceObject)
568  IoDeleteDevice(NewDeviceObject);
569 
570  if (Lookaside)
571  ExDeleteNPagedLookasideList(&Vcb->FileRecLookasideList);
572  }
573 
574  DPRINT("NtfsMountVolume() done (Status: %lx)\n", Status);
575 
576  return Status;
577 }
578 
579 
580 static
581 NTSTATUS
583  PIRP Irp)
584 {
587  DPRINT1("NtfsVerifyVolume() called\n");
588  return STATUS_WRONG_VOLUME;
589 }
590 
591 
592 static
593 NTSTATUS
595  PIRP Irp)
596 {
597  PIO_STACK_LOCATION Stack;
598  PNTFS_VOLUME_DATA_BUFFER DataBuffer;
599  PNTFS_ATTR_RECORD Attribute;
602 
603  DataBuffer = (PNTFS_VOLUME_DATA_BUFFER)Irp->AssociatedIrp.SystemBuffer;
605 
606  if (Stack->Parameters.FileSystemControl.OutputBufferLength < sizeof(NTFS_VOLUME_DATA_BUFFER) ||
607  Irp->UserBuffer == NULL)
608  {
609  DPRINT1("Invalid output! %d %p\n", Stack->Parameters.FileSystemControl.OutputBufferLength, Irp->UserBuffer);
611  }
612 
613  DataBuffer->VolumeSerialNumber.QuadPart = DeviceExt->NtfsInfo.SerialNumber;
614  DataBuffer->NumberSectors.QuadPart = DeviceExt->NtfsInfo.SectorCount;
615  DataBuffer->TotalClusters.QuadPart = DeviceExt->NtfsInfo.ClusterCount;
616  DataBuffer->FreeClusters.QuadPart = NtfsGetFreeClusters(DeviceExt);
617  DataBuffer->TotalReserved.QuadPart = 0LL; // FIXME
618  DataBuffer->BytesPerSector = DeviceExt->NtfsInfo.BytesPerSector;
619  DataBuffer->BytesPerCluster = DeviceExt->NtfsInfo.BytesPerCluster;
620  DataBuffer->BytesPerFileRecordSegment = DeviceExt->NtfsInfo.BytesPerFileRecord;
621  DataBuffer->ClustersPerFileRecordSegment = DeviceExt->NtfsInfo.BytesPerFileRecord / DeviceExt->NtfsInfo.BytesPerCluster;
622  DataBuffer->MftStartLcn.QuadPart = DeviceExt->NtfsInfo.MftStart.QuadPart;
623  DataBuffer->Mft2StartLcn.QuadPart = DeviceExt->NtfsInfo.MftMirrStart.QuadPart;
624  DataBuffer->MftZoneStart.QuadPart = 0; // FIXME
625  DataBuffer->MftZoneEnd.QuadPart = 0; // FIXME
626 
627  Status = FindFirstAttribute(&Context, DeviceExt, DeviceExt->MasterFileTable, FALSE, &Attribute);
628  while (NT_SUCCESS(Status))
629  {
630  if (Attribute->Type == AttributeData)
631  {
632  ASSERT(Attribute->IsNonResident);
633  DataBuffer->MftValidDataLength.QuadPart = Attribute->NonResident.DataSize;
634 
635  break;
636  }
637 
638  Status = FindNextAttribute(&Context, &Attribute);
639  }
641 
642  Irp->IoStatus.Information = sizeof(NTFS_VOLUME_DATA_BUFFER);
643 
644  if (Stack->Parameters.FileSystemControl.OutputBufferLength >= sizeof(NTFS_EXTENDED_VOLUME_DATA) + sizeof(NTFS_VOLUME_DATA_BUFFER))
645  {
647 
648  ExtendedData->ByteCount = sizeof(NTFS_EXTENDED_VOLUME_DATA);
649  ExtendedData->MajorVersion = DeviceExt->NtfsInfo.MajorVersion;
650  ExtendedData->MinorVersion = DeviceExt->NtfsInfo.MinorVersion;
651  Irp->IoStatus.Information += sizeof(NTFS_EXTENDED_VOLUME_DATA);
652  }
653 
654  return STATUS_SUCCESS;
655 }
656 
657 
658 static
659 NTSTATUS
661  PIRP Irp)
662 {
664  PIO_STACK_LOCATION Stack;
666  PFILE_RECORD_HEADER FileRecord;
668  ULONGLONG MFTRecord;
669 
671 
672  if (Stack->Parameters.FileSystemControl.InputBufferLength < sizeof(NTFS_FILE_RECORD_INPUT_BUFFER) ||
673  Irp->AssociatedIrp.SystemBuffer == NULL)
674  {
675  DPRINT1("Invalid input! %d %p\n", Stack->Parameters.FileSystemControl.InputBufferLength, Irp->AssociatedIrp.SystemBuffer);
677  }
678 
679  if (Stack->Parameters.FileSystemControl.OutputBufferLength < (FIELD_OFFSET(NTFS_FILE_RECORD_OUTPUT_BUFFER, FileRecordBuffer) + DeviceExt->NtfsInfo.BytesPerFileRecord) ||
680  Irp->AssociatedIrp.SystemBuffer == NULL)
681  {
682  DPRINT1("Invalid output! %d %p\n", Stack->Parameters.FileSystemControl.OutputBufferLength, Irp->AssociatedIrp.SystemBuffer);
684  }
685 
686  FileRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
687  if (FileRecord == NULL)
688  {
690  }
691 
692  InputBuffer = (PNTFS_FILE_RECORD_INPUT_BUFFER)Irp->AssociatedIrp.SystemBuffer;
693 
694  MFTRecord = InputBuffer->FileReferenceNumber.QuadPart;
695  DPRINT1("Requesting: %I64x\n", MFTRecord);
696 
697  do
698  {
699  Status = ReadFileRecord(DeviceExt, MFTRecord, FileRecord);
700  if (NT_SUCCESS(Status))
701  {
702  if (FileRecord->Flags & FRH_IN_USE)
703  {
704  break;
705  }
706  }
707 
708  --MFTRecord;
709  } while (TRUE);
710 
711  DPRINT1("Returning: %I64x\n", MFTRecord);
712  OutputBuffer = (PNTFS_FILE_RECORD_OUTPUT_BUFFER)Irp->AssociatedIrp.SystemBuffer;
713  OutputBuffer->FileReferenceNumber.QuadPart = MFTRecord;
714  OutputBuffer->FileRecordLength = DeviceExt->NtfsInfo.BytesPerFileRecord;
715  RtlCopyMemory(OutputBuffer->FileRecordBuffer, FileRecord, DeviceExt->NtfsInfo.BytesPerFileRecord);
716 
717  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, FileRecord);
718 
719  Irp->IoStatus.Information = FIELD_OFFSET(NTFS_FILE_RECORD_OUTPUT_BUFFER, FileRecordBuffer) + DeviceExt->NtfsInfo.BytesPerFileRecord;
720 
721  return STATUS_SUCCESS;
722 }
723 
724 
725 static
726 NTSTATUS
728  PIRP Irp)
729 {
731  PIO_STACK_LOCATION Stack;
733  LONGLONG StartingLcn;
734  PFILE_RECORD_HEADER BitmapRecord;
735  PNTFS_ATTR_CONTEXT DataContext;
736  ULONGLONG TotalClusters;
737  ULONGLONG ToCopy;
738  BOOLEAN Overflow = FALSE;
739 
740  DPRINT("GetVolumeBitmap(%p, %p)\n", DeviceExt, Irp);
741 
743 
744  if (Stack->Parameters.FileSystemControl.InputBufferLength < sizeof(STARTING_LCN_INPUT_BUFFER))
745  {
746  DPRINT1("Invalid input! %d\n", Stack->Parameters.FileSystemControl.InputBufferLength);
748  }
749 
750  if (Stack->Parameters.FileSystemControl.OutputBufferLength < sizeof(VOLUME_BITMAP_BUFFER))
751  {
752  DPRINT1("Invalid output! %d\n", Stack->Parameters.FileSystemControl.OutputBufferLength);
754  }
755 
757  if (Irp->RequestorMode == UserMode)
758  {
759  _SEH2_TRY
760  {
761  ProbeForRead(Stack->Parameters.FileSystemControl.Type3InputBuffer,
762  Stack->Parameters.FileSystemControl.InputBufferLength,
763  sizeof(CHAR));
764  ProbeForWrite(BitmapBuffer, Stack->Parameters.FileSystemControl.OutputBufferLength,
765  sizeof(CHAR));
766  }
768  {
770  }
771  _SEH2_END;
772  }
773  else
774  {
775  if (Stack->Parameters.FileSystemControl.Type3InputBuffer == NULL ||
776  BitmapBuffer == NULL)
777  {
779  }
780  }
781 
782  if (!NT_SUCCESS(Status))
783  {
784  DPRINT1("Invalid buffer! %p %p\n", Stack->Parameters.FileSystemControl.Type3InputBuffer, BitmapBuffer);
785  return Status;
786  }
787 
788  StartingLcn = ((PSTARTING_LCN_INPUT_BUFFER)Stack->Parameters.FileSystemControl.Type3InputBuffer)->StartingLcn.QuadPart;
789  if (StartingLcn > DeviceExt->NtfsInfo.ClusterCount)
790  {
791  DPRINT1("Requested bitmap start beyond partition end: %I64x %I64x\n", DeviceExt->NtfsInfo.ClusterCount, StartingLcn);
793  }
794 
795  /* Round down to a multiple of 8 */
796  StartingLcn = StartingLcn & ~7;
797  TotalClusters = DeviceExt->NtfsInfo.ClusterCount - StartingLcn;
798  ToCopy = TotalClusters / 8;
799  if ((ToCopy + FIELD_OFFSET(VOLUME_BITMAP_BUFFER, Buffer)) > Stack->Parameters.FileSystemControl.OutputBufferLength)
800  {
801  DPRINT1("Buffer too small: %x, needed: %x\n", Stack->Parameters.FileSystemControl.OutputBufferLength, (ToCopy + FIELD_OFFSET(VOLUME_BITMAP_BUFFER, Buffer)));
802  Overflow = TRUE;
803  ToCopy = Stack->Parameters.FileSystemControl.OutputBufferLength - FIELD_OFFSET(VOLUME_BITMAP_BUFFER, Buffer);
804  }
805 
806  BitmapRecord = ExAllocateFromNPagedLookasideList(&DeviceExt->FileRecLookasideList);
807  if (BitmapRecord == NULL)
808  {
810  }
811 
812  Status = ReadFileRecord(DeviceExt, NTFS_FILE_BITMAP, BitmapRecord);
813  if (!NT_SUCCESS(Status))
814  {
815  DPRINT1("Failed reading volume bitmap: %lx\n", Status);
816  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, BitmapRecord);
817  return Status;
818  }
819 
820  Status = FindAttribute(DeviceExt, BitmapRecord, AttributeData, L"", 0, &DataContext, NULL);
821  if (!NT_SUCCESS(Status))
822  {
823  DPRINT1("Failed find $DATA for bitmap: %lx\n", Status);
824  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, BitmapRecord);
825  return Status;
826  }
827 
828  BitmapBuffer->StartingLcn.QuadPart = StartingLcn;
829  BitmapBuffer->BitmapSize.QuadPart = ToCopy * 8;
830 
831  Irp->IoStatus.Information = FIELD_OFFSET(VOLUME_BITMAP_BUFFER, Buffer);
832  _SEH2_TRY
833  {
834  Irp->IoStatus.Information += ReadAttribute(DeviceExt, DataContext, StartingLcn / 8, (PCHAR)BitmapBuffer->Buffer, ToCopy);
836  }
838  {
840  }
841  _SEH2_END;
842  ReleaseAttributeContext(DataContext);
843  ExFreeToNPagedLookasideList(&DeviceExt->FileRecLookasideList, BitmapRecord);
844 
845  return Status;
846 }
847 
848 
849 static
850 NTSTATUS
852  PIRP Irp,
853  BOOLEAN Lock)
854 {
856  PNTFS_FCB Fcb;
857  PIO_STACK_LOCATION Stack;
858 
859  DPRINT("LockOrUnlockVolume(%p, %p, %d)\n", DeviceExt, Irp, Lock);
860 
862  FileObject = Stack->FileObject;
863  Fcb = FileObject->FsContext;
864 
865  /* Only allow locking with the volume open */
866  if (!(Fcb->Flags & FCB_IS_VOLUME))
867  {
868  return STATUS_ACCESS_DENIED;
869  }
870 
871  /* Bail out if it's already in the demanded state */
872  if (((DeviceExt->Flags & VCB_VOLUME_LOCKED) && Lock) ||
873  (!(DeviceExt->Flags & VCB_VOLUME_LOCKED) && !Lock))
874  {
875  return STATUS_ACCESS_DENIED;
876  }
877 
878  /* Deny locking if we're not alone */
879  if (Lock && DeviceExt->OpenHandleCount != 1)
880  {
881  return STATUS_ACCESS_DENIED;
882  }
883 
884  /* Finally, proceed */
885  if (Lock)
886  {
887  DeviceExt->Flags |= VCB_VOLUME_LOCKED;
888  }
889  else
890  {
891  DeviceExt->Flags &= ~VCB_VOLUME_LOCKED;
892  }
893 
894  return STATUS_SUCCESS;
895 }
896 
897 
898 static
899 NTSTATUS
901  PIRP Irp)
902 {
904  PIO_STACK_LOCATION Stack;
905  PDEVICE_EXTENSION DeviceExt;
906 
907  DPRINT("NtfsUserFsRequest(%p, %p)\n", DeviceObject, Irp);
908 
910  DeviceExt = DeviceObject->DeviceExtension;
911  switch (Stack->Parameters.FileSystemControl.FsControlCode)
912  {
915  case FSCTL_ENUM_USN_DATA:
916  case FSCTL_EXTEND_VOLUME:
917  //case FSCTL_GET_RETRIEVAL_POINTER_BASE:
919  //case FSCTL_LOOKUP_STREAM_FROM_CLUSTER:
920  case FSCTL_MARK_HANDLE:
921  case FSCTL_MOVE_FILE:
925  //case FSCTL_SHRINK_VOLUME:
928  DPRINT1("Unimplemented user request: %x\n", Stack->Parameters.FileSystemControl.FsControlCode);
930  break;
931 
932  case FSCTL_LOCK_VOLUME:
933  Status = LockOrUnlockVolume(DeviceExt, Irp, TRUE);
934  break;
935 
936  case FSCTL_UNLOCK_VOLUME:
937  Status = LockOrUnlockVolume(DeviceExt, Irp, FALSE);
938  break;
939 
941  Status = GetNfsVolumeData(DeviceExt, Irp);
942  break;
943 
945  Status = GetNtfsFileRecord(DeviceExt, Irp);
946  break;
947 
949  Status = GetVolumeBitmap(DeviceExt, Irp);
950  break;
951 
952  default:
953  DPRINT("Invalid user request: %x\n", Stack->Parameters.FileSystemControl.FsControlCode);
955  break;
956  }
957 
958  return Status;
959 }
960 
961 
962 NTSTATUS
964 {
966  PIRP Irp;
968 
969  DPRINT("NtfsFileSystemControl() called\n");
970 
971  DeviceObject = IrpContext->DeviceObject;
972  Irp = IrpContext->Irp;
973  Irp->IoStatus.Information = 0;
974 
975  switch (IrpContext->MinorFunction)
976  {
977  case IRP_MN_KERNEL_CALL:
978  DPRINT1("NTFS: IRP_MN_USER_FS_REQUEST\n");
980  break;
981 
984  break;
985 
986  case IRP_MN_MOUNT_VOLUME:
987  DPRINT("NTFS: IRP_MN_MOUNT_VOLUME\n");
989  break;
990 
992  DPRINT1("NTFS: IRP_MN_VERIFY_VOLUME\n");
994  break;
995 
996  default:
997  DPRINT1("NTFS FSC: MinorFunction %d\n", IrpContext->MinorFunction);
999  break;
1000  }
1001 
1002  return Status;
1003 }
1004 
1005 /* EOF */
#define FCB_IS_VOLUME_STREAM
Definition: ntfs.h:505
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
signed char * PCHAR
Definition: retypes.h:7
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4004
#define NTFS_TYPE_VCB
Definition: ntfs.h:89
PDRIVER_OBJECT DriverObject
Definition: ntfs.h:147
PDEVICE_OBJECT DeviceObject
Definition: ntfs.h:484
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
WORD BytesPerSector
Definition: fatfs.h:75
DWORD BytesPerFileRecordSegment
Definition: winioctl.h:564
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define LL
Definition: tui.h:85
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BYTE SectorsPerCluster
Definition: fatfs.h:76
#define FSCTL_DELETE_USN_JOURNAL
Definition: winioctl.h:153
UCHAR MinorFunction
Definition: ntfs.h:480
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
ULONGLONG SerialNumber
Definition: ntfs.h:77
ULONG BytesPerSector
Definition: ntfs.h:67
PFILE_OBJECT FileObject
Definition: ntfs.h:516
#define NTFS_FILE_BITMAP
Definition: ntfs.h:29
static NTSTATUS GetNfsVolumeData(PDEVICE_EXTENSION DeviceExt, PIRP Irp)
Definition: fsctl.c:594
_In_ PIRP Irp
Definition: csq.h:116
#define FSCTL_MARK_HANDLE
Definition: winioctl.h:154
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
uint16_t * PWSTR
Definition: typedefs.h:54
#define FSCTL_READ_USN_JOURNAL
Definition: winioctl.h:137
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PNTFS_FCB NtfsCreateFCB(PCWSTR FileName, PCWSTR Stream, PNTFS_VCB Vcb)
Definition: fcb.c:67
ULONG Type
Definition: ntfs.h:122
ULONG BytesPerSector
Definition: ntdddisk.h:381
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
LARGE_INTEGER MftStartLcn
Definition: winioctl.h:567
NTSTATUS FindAttribute(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER MftRecord, ULONG Type, PCWSTR Name, ULONG NameLength, PNTFS_ATTR_CONTEXT *AttrCtx, PULONG Offset)
Definition: mft.c:131
#define STATUS_WRONG_VOLUME
Definition: udferr_usr.h:140
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
ULONGLONG MFTIndex
Definition: ntfs.h:535
ULONGLONG ClusterCount
Definition: ntfs.h:71
struct _PARTITION_INFORMATION PARTITION_INFORMATION
ULONGLONG NtfsGetFreeClusters(PDEVICE_EXTENSION DeviceExt)
Definition: volinfo.c:37
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
PNTFS_GLOBAL_DATA NtfsGlobalData
Definition: ntfs.c:41
CHAR InputBuffer[80]
Definition: conmgr.c:33
UCHAR MajorVersion
Definition: ntfs.h:80
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
struct STARTING_LCN_INPUT_BUFFER * PSTARTING_LCN_INPUT_BUFFER
struct _BootSector BootSector
Definition: vfat.h:108
#define FRH_IN_USE
Definition: ntfs.h:263
Definition: ntfs.h:129
NTSTATUS NtfsDeviceIoControl(IN PDEVICE_OBJECT DeviceObject, IN ULONG ControlCode, IN PVOID InputBuffer, IN ULONG InputBufferSize, IN OUT PVOID OutputBuffer, IN OUT PULONG OutputBufferSize, IN BOOLEAN Override)
Definition: blockdev.c:326
NTFSIDENTIFIER Identifier
Definition: ntfs.h:511
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4049
#define NTFS_FILE_VOLUME
Definition: ntfs.h:26
LARGE_INTEGER MftZoneEnd
Definition: winioctl.h:570
static NTSTATUS LockOrUnlockVolume(PDEVICE_EXTENSION DeviceExt, PIRP Irp, BOOLEAN Lock)
Definition: fsctl.c:851
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
VOID NtfsDumpFileAttributes(PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord)
Definition: attrib.c:1790
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
ULARGE_INTEGER MftMirrStart
Definition: ntfs.h:73
LARGE_INTEGER Mft2StartLcn
Definition: winioctl.h:568
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
LARGE_INTEGER TotalClusters
Definition: winioctl.h:559
USHORT VolumeLabelLength
Definition: ntfs.h:78
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
ULONGLONG SectorCount
Definition: ntfs.h:70
VOID NtfsDestroyFCB(PNTFS_FCB Fcb)
Definition: fcb.c:115
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define MAXIMUM_VOLUME_LABEL_LENGTH
Definition: iotypes.h:154
static NTSTATUS NtfsVerifyVolume(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fsctl.c:582
Definition: bufpool.h:45
ULONG BytesPerIndexRecord
Definition: ntfs.h:75
#define PARTITION_IFS
Definition: disk.h:93
#define FSCTL_GET_NTFS_VOLUME_DATA
Definition: ntifs_ex.h:261
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
void * PVOID
Definition: retypes.h:9
static NTSTATUS GetNtfsFileRecord(PDEVICE_EXTENSION DeviceExt, PIRP Irp)
Definition: fsctl.c:660
LARGE_INTEGER VolumeSerialNumber
Definition: winioctl.h:557
LARGE_INTEGER MftZoneStart
Definition: winioctl.h:569
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS FindNextAttribute(PFIND_ATTR_CONTXT Context, PNTFS_ATTR_RECORD *Attribute)
Definition: attrib.c:1431
PFILE_OBJECT NTAPI IoCreateStreamFileObject(IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:3186
FSRTL_COMMON_FCB_HEADER RFCB
Definition: ntfs.h:513
struct NTFS_FILE_RECORD_OUTPUT_BUFFER * PNTFS_FILE_RECORD_OUTPUT_BUFFER
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
LARGE_INTEGER TotalReserved
Definition: winioctl.h:561
static NTSTATUS NtfsHasFileSystem(PDEVICE_OBJECT DeviceToMount)
Definition: fsctl.c:45
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4048
int64_t LONGLONG
Definition: typedefs.h:66
struct NTFS_EXTENDED_VOLUME_DATA * PNTFS_EXTENDED_VOLUME_DATA
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4047
#define FSCTL_QUERY_USN_JOURNAL
Definition: winioctl.h:152
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:222
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
_Inout_ PVOID Lookaside
Definition: fltkernel.h:2532
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct NTFS_FILE_RECORD_INPUT_BUFFER * PNTFS_FILE_RECORD_INPUT_BUFFER
VOID NTAPI CcInitializeCacheMap(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes, IN BOOLEAN PinAccess, IN PCACHE_MANAGER_CALLBACKS Callbacks, IN PVOID LazyWriteContext)
Definition: fssup.c:193
uint64_t ULONGLONG
Definition: typedefs.h:65
ULONG BytesPerFileRecord
Definition: ntfs.h:74
#define Vcb
Definition: cdprocs.h:1425
DWORD ClusterSize
Definition: format.c:67
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
MEDIA_TYPE MediaType
Definition: ntdddisk.h:378
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define TAG_CCB
Definition: cdprocs.h:77
* PFILE_OBJECT
Definition: iotypes.h:1955
#define TAG_NTFS
Definition: ntfs.h:12
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: ntfs.h:532
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FSCTL_GET_NTFS_FILE_RECORD
Definition: ntifs_ex.h:262
static ULONG BitmapBuffer[(XMS_BLOCKS+31)/32]
Definition: himem.c:86
#define IRP_MN_KERNEL_CALL
Definition: iotypes.h:4052
#define FSCTL_READ_FILE_USN_DATA
Definition: winioctl.h:149
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:88
static const WCHAR L[]
Definition: oid.c:1250
ULONG Type
Definition: ntfs.h:95
#define FSCTL_WRITE_USN_CLOSE_RECORD
Definition: winioctl.h:150
#define FSCTL_GET_RETRIEVAL_POINTERS
Definition: winioctl.h:95
UCHAR IsNonResident
Definition: ntfs.h:124
static ULONG NtfsQueryMftZoneReservation(VOID)
Definition: fsctl.c:172
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
#define NTFS_TYPE_CCB
Definition: ntfs.h:87
VOID FindCloseAttribute(PFIND_ATTR_CONTXT Context)
Definition: attrib.c:1465
LARGE_INTEGER AllocationSize
Definition: env_spec_w32.h:755
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
USHORT Flags
Definition: ntfs.h:82
PDEVICE_OBJECT DeviceObject
Definition: ntfs.h:148
Status
Definition: gdiplustypes.h:24
#define FCB_IS_VOLUME
Definition: vfat.h:431
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NtfsFileSystemControl(PNTFS_IRP_CONTEXT IrpContext)
Definition: fsctl.c:963
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
struct _DISK_GEOMETRY DISK_GEOMETRY
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS NtfsReadSectors(IN PDEVICE_OBJECT DeviceObject, IN ULONG DiskSector, IN ULONG SectorCount, IN ULONG SectorSize, IN OUT PUCHAR Buffer, IN BOOLEAN Override)
Definition: blockdev.c:308
_SEH2_END
Definition: create.c:4424
NTSTATUS FindFirstAttribute(PFIND_ATTR_CONTXT Context, PDEVICE_EXTENSION Vcb, PFILE_RECORD_HEADER FileRecord, BOOLEAN OnlyResident, PNTFS_ATTR_RECORD *Attribute)
Definition: attrib.c:1383
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
ULONG MftZoneReservation
Definition: ntfs.h:84
NTSTATUS ReadFileRecord(PDEVICE_EXTENSION Vcb, ULONGLONG index, PFILE_RECORD_HEADER file)
Definition: mft.c:1631
VOID ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context)
Definition: mft.c:104
CACHE_MANAGER_CALLBACKS CacheMgrCallbacks
Definition: ntfs.h:149
#define FSCTL_GET_VOLUME_BITMAP
Definition: winioctl.h:94
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH]
Definition: ntfs.h:79
struct NTFS_ATTR_RECORD::@165::@168 NonResident
#define TAG_FILE_REC
Definition: ntfs.h:17
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define FSCTL_ENUM_USN_DATA
Definition: winioctl.h:135
ULONG ReadAttribute(PDEVICE_EXTENSION Vcb, PNTFS_ATTR_CONTEXT Context, ULONGLONG Offset, PCHAR Buffer, ULONG Length)
Definition: mft.c:1065
#define min(a, b)
Definition: monoChain.cc:55
USHORT Flags
Definition: ntfs.h:252
#define VCB_VOLUME_LOCKED
Definition: ext2fs.h:780
#define DPRINT1
Definition: precomp.h:8
PVOID NtfsGetUserBuffer(PIRP Irp, BOOLEAN Paging)
Definition: misc.c:120
static NTSTATUS NtfsUserFsRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fsctl.c:900
#define FSCTL_CREATE_USN_JOURNAL
Definition: winioctl.h:148
struct NTFS_VOLUME_DATA_BUFFER * PNTFS_VOLUME_DATA_BUFFER
LARGE_INTEGER NumberSectors
Definition: winioctl.h:558
#define FSRTL_VOLUME_MOUNT
Definition: ntifs_ex.h:444
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
#define FSCTL_MOVE_FILE
Definition: winioctl.h:96
struct tagContext Context
Definition: acpixf.h:1030
LARGE_INTEGER MftValidDataLength
Definition: winioctl.h:566
DWORD ClustersPerFileRecordSegment
Definition: winioctl.h:565
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
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PVCB Vcb
Definition: cdstruc.h:939
ULONG SectorsPerCluster
Definition: ntfs.h:68
ULARGE_INTEGER MftStart
Definition: ntfs.h:72
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
static NTSTATUS GetVolumeBitmap(PDEVICE_EXTENSION DeviceExt, PIRP Irp)
Definition: fsctl.c:727
LARGE_INTEGER FreeClusters
Definition: winioctl.h:560
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
_In_ PFCB Fcb
Definition: cdprocs.h:151
struct NTFS_ATTR_RECORD::@165::@167 Resident
LARGE_INTEGER ValidDataLength
Definition: env_spec_w32.h:757
return STATUS_SUCCESS
Definition: btrfs.c:2938
VOID NTAPI ExDeleteNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside)
Definition: lookas.c:174
#define VPB_MOUNTED
Definition: iotypes.h:1764
ULONGLONG AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord)
Definition: mft.c:259
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:514
UCHAR MinorVersion
Definition: ntfs.h:81
int k
Definition: mpi.c:3369
struct _ULARGE_INTEGER::@3769 u
ULONG Size
Definition: ntfs.h:96
static NTSTATUS NtfsMountVolume(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: fsctl.c:416
ULONG BytesPerCluster
Definition: ntfs.h:69
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
LONGLONG QuadPart
Definition: typedefs.h:112
#define FSCTL_EXTEND_VOLUME
Definition: winioctl.h:151
static NTSTATUS NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, PDEVICE_EXTENSION DeviceExt)
Definition: fsctl.c:194