3 * Copyright (C) 2002 ReactOS Team
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.
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.
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.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/volume.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMER: Eric Kohl
26 /* INCLUDES *****************************************************************/
33 /* FUNCTIONS ****************************************************************/
37 NtfsGetFreeClusters(PDEVICE_EXTENSION DeviceExt
)
45 NtfsGetFsVolumeInformation(PDEVICE_OBJECT DeviceObject
,
46 PFILE_FS_VOLUME_INFORMATION FsVolumeInfo
,
49 DPRINT("NtfsGetFsVolumeInformation() called\n");
50 DPRINT("FsVolumeInfo = %p\n", FsVolumeInfo
);
51 DPRINT("BufferLength %lu\n", *BufferLength
);
53 DPRINT("Vpb %p\n", DeviceObject
->Vpb
);
55 DPRINT("Required length %lu\n",
56 sizeof(FILE_FS_VOLUME_INFORMATION
) + DeviceObject
->Vpb
->VolumeLabelLength
);
57 DPRINT("LabelLength %hu\n",
58 DeviceObject
->Vpb
->VolumeLabelLength
);
59 DPRINT("Label %*.S\n",
60 DeviceObject
->Vpb
->VolumeLabelLength
/ sizeof(WCHAR
),
61 DeviceObject
->Vpb
->VolumeLabel
);
63 if (*BufferLength
< sizeof(FILE_FS_VOLUME_INFORMATION
))
64 return STATUS_INFO_LENGTH_MISMATCH
;
66 if (*BufferLength
< (sizeof(FILE_FS_VOLUME_INFORMATION
) + DeviceObject
->Vpb
->VolumeLabelLength
))
67 return STATUS_BUFFER_OVERFLOW
;
70 FsVolumeInfo
->VolumeSerialNumber
= DeviceObject
->Vpb
->SerialNumber
;
71 FsVolumeInfo
->VolumeLabelLength
= DeviceObject
->Vpb
->VolumeLabelLength
;
72 memcpy(FsVolumeInfo
->VolumeLabel
,
73 DeviceObject
->Vpb
->VolumeLabel
,
74 DeviceObject
->Vpb
->VolumeLabelLength
);
77 FsVolumeInfo
->VolumeCreationTime
.QuadPart
= 0;
78 FsVolumeInfo
->SupportsObjects
= FALSE
;
80 *BufferLength
-= (sizeof(FILE_FS_VOLUME_INFORMATION
) + DeviceObject
->Vpb
->VolumeLabelLength
);
82 DPRINT("BufferLength %lu\n", *BufferLength
);
83 DPRINT("NtfsGetFsVolumeInformation() done\n");
85 return STATUS_SUCCESS
;
91 NtfsGetFsAttributeInformation(PDEVICE_EXTENSION DeviceExt
,
92 PFILE_FS_ATTRIBUTE_INFORMATION FsAttributeInfo
,
95 UNREFERENCED_PARAMETER(DeviceExt
);
97 DPRINT("NtfsGetFsAttributeInformation()\n");
98 DPRINT("FsAttributeInfo = %p\n", FsAttributeInfo
);
99 DPRINT("BufferLength %lu\n", *BufferLength
);
100 DPRINT("Required length %lu\n", (sizeof(FILE_FS_ATTRIBUTE_INFORMATION
) + 8));
102 if (*BufferLength
< sizeof (FILE_FS_ATTRIBUTE_INFORMATION
))
103 return STATUS_INFO_LENGTH_MISMATCH
;
105 if (*BufferLength
< (sizeof(FILE_FS_ATTRIBUTE_INFORMATION
) + 8))
106 return STATUS_BUFFER_OVERFLOW
;
108 FsAttributeInfo
->FileSystemAttributes
=
109 FILE_CASE_PRESERVED_NAMES
| FILE_UNICODE_ON_DISK
;
110 FsAttributeInfo
->MaximumComponentNameLength
= 255;
111 FsAttributeInfo
->FileSystemNameLength
= 8;
113 memcpy(FsAttributeInfo
->FileSystemName
, L
"NTFS", 8);
115 DPRINT("Finished NtfsGetFsAttributeInformation()\n");
117 *BufferLength
-= (sizeof(FILE_FS_ATTRIBUTE_INFORMATION
) + 8);
118 DPRINT("BufferLength %lu\n", *BufferLength
);
120 return STATUS_SUCCESS
;
126 NtfsGetFsSizeInformation(PDEVICE_OBJECT DeviceObject
,
127 PFILE_FS_SIZE_INFORMATION FsSizeInfo
,
130 PDEVICE_EXTENSION DeviceExt
;
131 NTSTATUS Status
= STATUS_SUCCESS
;
133 DPRINT("NtfsGetFsSizeInformation()\n");
134 DPRINT("FsSizeInfo = %p\n", FsSizeInfo
);
136 if (*BufferLength
< sizeof(FILE_FS_SIZE_INFORMATION
))
137 return STATUS_BUFFER_OVERFLOW
;
139 DeviceExt
= DeviceObject
->DeviceExtension
;
141 FsSizeInfo
->AvailableAllocationUnits
.QuadPart
= NtfsGetFreeClusters(DeviceExt
);
142 FsSizeInfo
->TotalAllocationUnits
.QuadPart
= DeviceExt
->NtfsInfo
.SectorCount
/ DeviceExt
->NtfsInfo
.SectorsPerCluster
;
143 FsSizeInfo
->SectorsPerAllocationUnit
= DeviceExt
->NtfsInfo
.SectorsPerCluster
;
144 FsSizeInfo
->BytesPerSector
= DeviceExt
->NtfsInfo
.BytesPerSector
;
146 DPRINT("Finished NtfsGetFsSizeInformation()\n");
147 if (NT_SUCCESS(Status
))
148 *BufferLength
-= sizeof(FILE_FS_SIZE_INFORMATION
);
156 NtfsGetFsDeviceInformation(PDEVICE_OBJECT DeviceObject
,
157 PFILE_FS_DEVICE_INFORMATION FsDeviceInfo
,
160 DPRINT("NtfsGetFsDeviceInformation()\n");
161 DPRINT("FsDeviceInfo = %p\n", FsDeviceInfo
);
162 DPRINT("BufferLength %lu\n", *BufferLength
);
163 DPRINT("Required length %lu\n", sizeof(FILE_FS_DEVICE_INFORMATION
));
165 if (*BufferLength
< sizeof(FILE_FS_DEVICE_INFORMATION
))
166 return STATUS_BUFFER_OVERFLOW
;
168 FsDeviceInfo
->DeviceType
= FILE_DEVICE_DISK
;
169 FsDeviceInfo
->Characteristics
= DeviceObject
->Characteristics
;
171 DPRINT("NtfsGetFsDeviceInformation() finished.\n");
173 *BufferLength
-= sizeof(FILE_FS_DEVICE_INFORMATION
);
174 DPRINT("BufferLength %lu\n", *BufferLength
);
176 return STATUS_SUCCESS
;
181 NtfsQueryVolumeInformation(PNTFS_IRP_CONTEXT IrpContext
)
184 PDEVICE_OBJECT DeviceObject
;
185 FS_INFORMATION_CLASS FsInformationClass
;
186 PIO_STACK_LOCATION Stack
;
187 NTSTATUS Status
= STATUS_SUCCESS
;
191 DPRINT("NtfsQueryVolumeInformation() called\n");
195 Irp
= IrpContext
->Irp
;
196 DeviceObject
= IrpContext
->DeviceObject
;
197 Stack
= IoGetCurrentIrpStackLocation(Irp
);
198 FsInformationClass
= Stack
->Parameters
.QueryVolume
.FsInformationClass
;
199 BufferLength
= Stack
->Parameters
.QueryVolume
.Length
;
200 SystemBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
201 RtlZeroMemory(SystemBuffer
, BufferLength
);
203 DPRINT("FsInformationClass %d\n", FsInformationClass
);
204 DPRINT("SystemBuffer %p\n", SystemBuffer
);
206 switch (FsInformationClass
)
208 case FileFsVolumeInformation
:
209 Status
= NtfsGetFsVolumeInformation(DeviceObject
,
214 case FileFsAttributeInformation
:
215 Status
= NtfsGetFsAttributeInformation(DeviceObject
->DeviceExtension
,
220 case FileFsSizeInformation
:
221 Status
= NtfsGetFsSizeInformation(DeviceObject
,
226 case FileFsDeviceInformation
:
227 Status
= NtfsGetFsDeviceInformation(DeviceObject
,
233 Status
= STATUS_NOT_SUPPORTED
;
236 if (NT_SUCCESS(Status
))
237 Irp
->IoStatus
.Information
=
238 Stack
->Parameters
.QueryVolume
.Length
- BufferLength
;
240 Irp
->IoStatus
.Information
= 0;
247 NtfsSetVolumeInformation(PNTFS_IRP_CONTEXT IrpContext
)
251 DPRINT("NtfsSetVolumeInformation() called\n");
255 Irp
= IrpContext
->Irp
;
256 Irp
->IoStatus
.Status
= STATUS_NOT_SUPPORTED
;
257 Irp
->IoStatus
.Information
= 0;
259 return STATUS_NOT_SUPPORTED
;