ReactOS  0.4.15-dev-1384-g878186b
fileinfo.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: dll/win32/kernel32/client/file/fileinfo.c
5  * PURPOSE: Directory functions
6  * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
7  * Pierre Schweitzer (pierre.schweitzer@reactos.org)
8  * UPDATE HISTORY:
9  * Created 01/11/98
10  */
11 
12 /* INCLUDES *****************************************************************/
13 
14 #include <k32.h>
15 #define NDEBUG
16 #include <debug.h>
18 
19 /* FUNCTIONS ****************************************************************/
20 
21 /*
22  * @implemented
23  */
26 {
29 
31 
33  {
35  }
36 
38  &IoStatusBlock);
39  if (!NT_SUCCESS(Status))
40  {
42  return FALSE;
43  }
44  return TRUE;
45 }
46 
47 
48 /*
49  * @implemented
50  */
51 DWORD
52 WINAPI
55  LONG lDistanceToMove,
56  PLONG lpDistanceToMoveHigh,
57  DWORD dwMoveMethod)
58 {
59  FILE_POSITION_INFORMATION FilePosition;
60  FILE_STANDARD_INFORMATION FileStandard;
61  NTSTATUS errCode;
63  LARGE_INTEGER Distance;
64 
65  TRACE("SetFilePointer(hFile %p, lDistanceToMove %d, dwMoveMethod %lu)\n",
66  hFile,lDistanceToMove,dwMoveMethod);
67 
69  {
72  }
73 
74  if (lpDistanceToMoveHigh)
75  {
76  Distance.u.HighPart = *lpDistanceToMoveHigh;
77  Distance.u.LowPart = lDistanceToMove;
78  }
79  else
80  {
81  Distance.QuadPart = lDistanceToMove;
82  }
83 
84  switch(dwMoveMethod)
85  {
86  case FILE_CURRENT:
87  errCode = NtQueryInformationFile(hFile,
89  &FilePosition,
92  FilePosition.CurrentByteOffset.QuadPart += Distance.QuadPart;
93  if (!NT_SUCCESS(errCode))
94  {
95  if (lpDistanceToMoveHigh != NULL)
96  *lpDistanceToMoveHigh = -1;
97  BaseSetLastNTError(errCode);
99  }
100  break;
101  case FILE_END:
102  errCode = NtQueryInformationFile(hFile,
103  &IoStatusBlock,
104  &FileStandard,
107  FilePosition.CurrentByteOffset.QuadPart =
108  FileStandard.EndOfFile.QuadPart + Distance.QuadPart;
109  if (!NT_SUCCESS(errCode))
110  {
111  if (lpDistanceToMoveHigh != NULL)
112  *lpDistanceToMoveHigh = -1;
113  BaseSetLastNTError(errCode);
115  }
116  break;
117  case FILE_BEGIN:
118  FilePosition.CurrentByteOffset.QuadPart = Distance.QuadPart;
119  break;
120  default:
123  }
124 
125  if(FilePosition.CurrentByteOffset.QuadPart < 0)
126  {
129  }
130 
131  if (lpDistanceToMoveHigh == NULL && FilePosition.CurrentByteOffset.HighPart != 0)
132  {
133  /* If we're moving the pointer outside of the 32 bit boundaries but
134  the application only passed a 32 bit value we need to bail out! */
137  }
138 
139  errCode = NtSetInformationFile(hFile,
140  &IoStatusBlock,
141  &FilePosition,
144  if (!NT_SUCCESS(errCode))
145  {
146  if (lpDistanceToMoveHigh != NULL)
147  *lpDistanceToMoveHigh = -1;
148 
149  BaseSetLastNTError(errCode);
151  }
152 
153  if (lpDistanceToMoveHigh != NULL)
154  {
155  *lpDistanceToMoveHigh = FilePosition.CurrentByteOffset.u.HighPart;
156  }
157 
158  if (FilePosition.CurrentByteOffset.u.LowPart == MAXDWORD)
159  {
160  /* The value of -1 is valid here, especially when the new
161  file position is greater than 4 GB. Since NtSetInformationFile
162  succeeded we never set an error code and we explicitly need
163  to clear a previously set error code in this case, which
164  an application will check if INVALID_SET_FILE_POINTER is returned! */
166  }
167 
168  return FilePosition.CurrentByteOffset.u.LowPart;
169 }
170 
171 
172 /*
173  * @implemented
174  */
175 BOOL
176 WINAPI
178  LARGE_INTEGER liDistanceToMove,
179  PLARGE_INTEGER lpNewFilePointer,
180  DWORD dwMoveMethod)
181 {
184  FILE_POSITION_INFORMATION FilePosition;
185  FILE_STANDARD_INFORMATION FileStandard;
186 
187  if (IsConsoleHandle(hFile))
188  {
190  return FALSE;
191  }
192 
193  switch (dwMoveMethod)
194  {
195  case FILE_CURRENT:
196  {
198  &FilePosition,
201  if (!NT_SUCCESS(Status))
202  {
204  return FALSE;
205  }
206 
207  FilePosition.CurrentByteOffset.QuadPart += liDistanceToMove.QuadPart;
208  break;
209  }
210 
211  case FILE_END:
212  {
214  &FileStandard,
217  if (!NT_SUCCESS(Status))
218  {
220  return FALSE;
221  }
222 
223  FilePosition.CurrentByteOffset.QuadPart = FileStandard.EndOfFile.QuadPart +
224  liDistanceToMove.QuadPart;
225  break;
226  }
227 
228  case FILE_BEGIN:
229  {
230  FilePosition.CurrentByteOffset.QuadPart = liDistanceToMove.QuadPart;
231  break;
232  }
233 
234  default:
235  {
237  return FALSE;
238  }
239  }
240 
241  if (FilePosition.CurrentByteOffset.QuadPart < 0)
242  {
244  return FALSE;
245  }
246 
247  Status = NtSetInformationFile(hFile, &IoStatusBlock, &FilePosition,
250  if (!NT_SUCCESS(Status))
251  {
253  return FALSE;
254  }
255 
256  if (lpNewFilePointer != NULL)
257  {
258  *lpNewFilePointer = FilePosition.CurrentByteOffset;
259  }
260 
261  return TRUE;
262 }
263 
264 
265 /*
266  * @implemented
267  */
270 {
272  IO_STATUS_BLOCK StatusBlock;
274 
275  /* Get real handle */
277 
278  /* Check for console handle */
279  if (IsConsoleHandle(hFile))
280  {
282  return FILE_TYPE_CHAR;
283  }
284 
286  &StatusBlock,
287  &DeviceInfo,
290  if (!NT_SUCCESS(Status))
291  {
293  return FILE_TYPE_UNKNOWN;
294  }
295 
296  switch (DeviceInfo.DeviceType)
297  {
298  case FILE_DEVICE_CD_ROM:
302  case FILE_DEVICE_DFS:
303  case FILE_DEVICE_DISK:
306  return FILE_TYPE_DISK;
307 
309  case FILE_DEVICE_MOUSE:
310  case FILE_DEVICE_NULL:
312  case FILE_DEVICE_PRINTER:
314  case FILE_DEVICE_SCREEN:
315  case FILE_DEVICE_SOUND:
316  case FILE_DEVICE_MODEM:
317  return FILE_TYPE_CHAR;
318 
320  return FILE_TYPE_PIPE;
321  }
322 
323  return FILE_TYPE_UNKNOWN;
324 }
325 
326 
327 /*
328  * @implemented
329  */
332  LPDWORD lpFileSizeHigh)
333 {
334  NTSTATUS errCode;
335  FILE_STANDARD_INFORMATION FileStandard;
337 
338  errCode = NtQueryInformationFile(hFile,
339  &IoStatusBlock,
340  &FileStandard,
343  if (!NT_SUCCESS(errCode))
344  {
345  BaseSetLastNTError(errCode);
346  if ( lpFileSizeHigh == NULL )
347  {
348  return -1;
349  }
350  else
351  {
352  return 0;
353  }
354  }
355  if ( lpFileSizeHigh != NULL )
356  *lpFileSizeHigh = FileStandard.EndOfFile.u.HighPart;
357 
358  return FileStandard.EndOfFile.u.LowPart;
359 }
360 
361 
362 /*
363  * @implemented
364  */
365 BOOL
366 WINAPI
368  HANDLE hFile,
369  PLARGE_INTEGER lpFileSize
370  )
371 {
372  NTSTATUS errCode;
373  FILE_STANDARD_INFORMATION FileStandard;
375 
376  errCode = NtQueryInformationFile(hFile,
377  &IoStatusBlock,
378  &FileStandard,
381  if (!NT_SUCCESS(errCode))
382  {
383  BaseSetLastNTError(errCode);
384  return FALSE;
385  }
386  if (lpFileSize)
387  *lpFileSize = FileStandard.EndOfFile;
388 
389  return TRUE;
390 }
391 
392 
393 /*
394  * @implemented
395  */
398  LPDWORD lpFileSizeHigh)
399 {
400  PWCHAR FileNameW;
401 
402  if (!(FileNameW = FilenameA2W(lpFileName, FALSE)))
403  return INVALID_FILE_SIZE;
404 
405  return GetCompressedFileSizeW(FileNameW, lpFileSizeHigh);
406 }
407 
408 
409 /*
410  * @implemented
411  */
414  LPDWORD lpFileSizeHigh)
415 {
416  FILE_COMPRESSION_INFORMATION FileCompression;
417  NTSTATUS errCode;
419  HANDLE hFile;
420 
422  GENERIC_READ,
424  NULL,
427  NULL);
428 
430  return INVALID_FILE_SIZE;
431 
432  errCode = NtQueryInformationFile(hFile,
433  &IoStatusBlock,
434  &FileCompression,
437 
439 
440  if (!NT_SUCCESS(errCode))
441  {
442  BaseSetLastNTError(errCode);
443  return INVALID_FILE_SIZE;
444  }
445 
446  if(lpFileSizeHigh)
447  *lpFileSizeHigh = FileCompression.CompressedFileSize.u.HighPart;
448 
450  return FileCompression.CompressedFileSize.u.LowPart;
451 }
452 
453 
454 /*
455  * @implemented
456  */
457 BOOL WINAPI
459  LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
460 {
461  struct
462  {
463  FILE_FS_VOLUME_INFORMATION FileFsVolume;
464  WCHAR Name[255];
465  }
466  FileFsVolume;
467 
468  FILE_BASIC_INFORMATION FileBasic;
469  FILE_INTERNAL_INFORMATION FileInternal;
470  FILE_STANDARD_INFORMATION FileStandard;
471  NTSTATUS errCode;
473 
475  {
477  return FALSE;
478  }
479 
480  errCode = NtQueryInformationFile(hFile,
481  &IoStatusBlock,
482  &FileBasic,
483  sizeof(FILE_BASIC_INFORMATION),
485  if (!NT_SUCCESS(errCode))
486  {
487  BaseSetLastNTError(errCode);
488  return FALSE;
489  }
490 
491  lpFileInformation->dwFileAttributes = (DWORD)FileBasic.FileAttributes;
492 
493  lpFileInformation->ftCreationTime.dwHighDateTime = FileBasic.CreationTime.u.HighPart;
494  lpFileInformation->ftCreationTime.dwLowDateTime = FileBasic.CreationTime.u.LowPart;
495 
496  lpFileInformation->ftLastAccessTime.dwHighDateTime = FileBasic.LastAccessTime.u.HighPart;
497  lpFileInformation->ftLastAccessTime.dwLowDateTime = FileBasic.LastAccessTime.u.LowPart;
498 
499  lpFileInformation->ftLastWriteTime.dwHighDateTime = FileBasic.LastWriteTime.u.HighPart;
500  lpFileInformation->ftLastWriteTime.dwLowDateTime = FileBasic.LastWriteTime.u.LowPart;
501 
502  errCode = NtQueryInformationFile(hFile,
503  &IoStatusBlock,
504  &FileInternal,
507  if (!NT_SUCCESS(errCode))
508  {
509  BaseSetLastNTError(errCode);
510  return FALSE;
511  }
512 
513  lpFileInformation->nFileIndexHigh = FileInternal.IndexNumber.u.HighPart;
514  lpFileInformation->nFileIndexLow = FileInternal.IndexNumber.u.LowPart;
515 
517  &IoStatusBlock,
518  &FileFsVolume,
519  sizeof(FileFsVolume),
521  if (!NT_SUCCESS(errCode))
522  {
523  BaseSetLastNTError(errCode);
524  return FALSE;
525  }
526 
527  lpFileInformation->dwVolumeSerialNumber = FileFsVolume.FileFsVolume.VolumeSerialNumber;
528 
529  errCode = NtQueryInformationFile(hFile,
530  &IoStatusBlock,
531  &FileStandard,
534  if (!NT_SUCCESS(errCode))
535  {
536  BaseSetLastNTError(errCode);
537  return FALSE;
538  }
539 
540  lpFileInformation->nNumberOfLinks = FileStandard.NumberOfLinks;
541  lpFileInformation->nFileSizeHigh = FileStandard.EndOfFile.u.HighPart;
542  lpFileInformation->nFileSizeLow = FileStandard.EndOfFile.u.LowPart;
543 
544  return TRUE;
545 }
546 
547 
548 /*
549  * @implemented
550  */
551 BOOL WINAPI
553  GET_FILEEX_INFO_LEVELS fInfoLevelId,
554  LPVOID lpFileInformation)
555 {
560  WIN32_FILE_ATTRIBUTE_DATA* FileAttributeData;
561 
562  TRACE("GetFileAttributesExW(%S) called\n", lpFileName);
563 
564 
565  if (fInfoLevelId != GetFileExInfoStandard || lpFileInformation == NULL)
566  {
568  return FALSE;
569  }
570 
571  /* Validate and translate the filename */
573  &FileName,
574  NULL,
575  NULL))
576  {
577  WARN ("Invalid path '%S'\n", lpFileName);
579  return FALSE;
580  }
581 
582  /* build the object attributes */
584  &FileName,
586  NULL,
587  NULL);
588 
589  /* Get file attributes */
591  &FileInformation);
592 
594  if (!NT_SUCCESS (Status))
595  {
596  WARN ("NtQueryFullAttributesFile() failed (Status %lx)\n", Status);
598  return FALSE;
599  }
600 
601  FileAttributeData = (WIN32_FILE_ATTRIBUTE_DATA*)lpFileInformation;
602  FileAttributeData->dwFileAttributes = FileInformation.FileAttributes;
603  FileAttributeData->ftCreationTime.dwLowDateTime = FileInformation.CreationTime.u.LowPart;
604  FileAttributeData->ftCreationTime.dwHighDateTime = FileInformation.CreationTime.u.HighPart;
605  FileAttributeData->ftLastAccessTime.dwLowDateTime = FileInformation.LastAccessTime.u.LowPart;
606  FileAttributeData->ftLastAccessTime.dwHighDateTime = FileInformation.LastAccessTime.u.HighPart;
607  FileAttributeData->ftLastWriteTime.dwLowDateTime = FileInformation.LastWriteTime.u.LowPart;
608  FileAttributeData->ftLastWriteTime.dwHighDateTime = FileInformation.LastWriteTime.u.HighPart;
609  FileAttributeData->nFileSizeLow = FileInformation.EndOfFile.u.LowPart;
610  FileAttributeData->nFileSizeHigh = FileInformation.EndOfFile.u.HighPart;
611 
612  return TRUE;
613 }
614 
615 /*
616  * @implemented
617  */
618 BOOL WINAPI
620  GET_FILEEX_INFO_LEVELS fInfoLevelId,
621  LPVOID lpFileInformation)
622 {
623  PWCHAR FileNameW;
624 
625  if (!(FileNameW = FilenameA2W(lpFileName, FALSE)))
626  return FALSE;
627 
628  return GetFileAttributesExW(FileNameW, fInfoLevelId, lpFileInformation);
629 }
630 
631 
632 /*
633  * @implemented
634  */
637 {
638  PWSTR FileNameW;
639 
640  if (!lpFileName || !(FileNameW = FilenameA2W(lpFileName, FALSE)))
642 
643  return GetFileAttributesW(FileNameW);
644 }
645 
646 
647 /*
648  * @implemented
649  */
650 DWORD
651 WINAPI
653 {
658 
659  /* Get the NT path name */
661  {
664  }
665 
666  /* Prepare for querying attributes */
669  NULL, NULL);
670  /* Simply query attributes */
672  if (!NT_SUCCESS(Status))
673  {
674  /* It failed? Is it a DOS device? */
676  {
677  return FILE_ATTRIBUTE_ARCHIVE;
678  }
679 
680  /* Set the error otherwise */
683  }
684 
685  /* Return the file attributes */
686  return FileInformation.FileAttributes;
687 }
688 
689 
690 /*
691  * @implemented
692  */
693 BOOL WINAPI
696  IN DWORD dwFlags)
697 {
698  FILE_BASIC_INFORMATION FileBasic;
701 
703 
704  if (IsConsoleHandle(hFile))
705  {
707  return FALSE;
708  }
709 
711  &IoStatusBlock,
712  &FileBasic,
713  sizeof(FileBasic),
715  if (NT_SUCCESS(Status))
716  {
717  *dwFileAttributes = FileBasic.FileAttributes;
718  return TRUE;
719  }
720 
722  return FALSE;
723 }
724 
725 
726 /*
727  * @implemented
728  */
729 BOOL WINAPI
732  IN DWORD dwFlags)
733 {
734  FILE_BASIC_INFORMATION FileBasic;
737 
739 
740  if (IsConsoleHandle(hFile))
741  {
743  return FALSE;
744  }
745 
747  &IoStatusBlock,
748  &FileBasic,
749  sizeof(FileBasic),
751  if (NT_SUCCESS(Status))
752  {
753  FileBasic.FileAttributes = dwFileAttributes;
754 
756  &IoStatusBlock,
757  &FileBasic,
758  sizeof(FileBasic),
760  }
761 
762  if (!NT_SUCCESS(Status))
763  {
765  return FALSE;
766  }
767 
768  return TRUE;
769 }
770 
771 
772 /*
773  * @implemented
774  */
775 BOOL WINAPI
779 {
780  PWCHAR FileNameW;
781 
782  if (!(FileNameW = FilenameA2W(lpFileName, FALSE)))
783  return FALSE;
784 
785  return SetFileAttributesW(FileNameW, dwFileAttributes);
786 }
787 
788 
789 /*
790  * @implemented
791  */
792 BOOL
793 WINAPI
796 {
798  PWSTR PathUBuffer;
800  UNICODE_STRING NtPathU;
802  RTL_RELATIVE_NAME_U RelativeName;
805 
806  /* Get relative name */
807  if (!RtlDosPathNameToRelativeNtPathName_U(lpFileName, &NtPathU, NULL, &RelativeName))
808  {
810  return FALSE;
811  }
812 
813  /* Save buffer to allow later freeing */
814  PathUBuffer = NtPathU.Buffer;
815 
816  /* If we have relative name (and root dir), use them instead */
817  if (RelativeName.RelativeName.Length != 0)
818  {
819  NtPathU.Length = RelativeName.RelativeName.Length;
820  NtPathU.MaximumLength = RelativeName.RelativeName.MaximumLength;
821  NtPathU.Buffer = RelativeName.RelativeName.Buffer;
822  }
823  else
824  {
825  RelativeName.ContainingDirectory = NULL;
826  }
827 
828  /* Prepare the object attribute for opening the file */
831  RelativeName.ContainingDirectory, NULL);
832 
833  /* Attempt to open the file, while supporting reparse point */
838  /* If opening failed, check whether it was because of reparse point support */
839  if (!NT_SUCCESS(Status))
840  {
841  /* Nope, just quit */
843  {
844  RtlReleaseRelativeName(&RelativeName);
845  RtlFreeHeap(RtlGetProcessHeap(), 0, PathUBuffer);
847 
848  return FALSE;
849  }
850 
851  /* Yes, retry without */
856  if (!NT_SUCCESS(Status))
857  {
858  RtlReleaseRelativeName(&RelativeName);
859  RtlFreeHeap(RtlGetProcessHeap(), 0, PathUBuffer);
861 
862  return FALSE;
863  }
864  }
865 
866  /* We don't need strings anylonger */
867  RtlReleaseRelativeName(&RelativeName);
868  RtlFreeHeap(RtlGetProcessHeap(), 0, PathUBuffer);
869 
870  /* Zero our structure, we'll only set file attributes */
872  /* Set the attributes, filtering only allowed attributes, and forcing normal attribute */
874 
875  /* Finally, set the attributes */
878  /* Close the file */
880 
881  /* If it failed, set the error and fail */
882  if (!NT_SUCCESS(Status))
883  {
885 
886  return FALSE;
887  }
888 
889  return TRUE;
890 }
891 
892 /*
893  * @implemented
894  */
895 BOOL WINAPI
897  OUT LPFILETIME lpCreationTime OPTIONAL,
898  OUT LPFILETIME lpLastAccessTime OPTIONAL,
899  OUT LPFILETIME lpLastWriteTime OPTIONAL)
900 {
903  FILE_BASIC_INFORMATION FileBasic;
904 
906  {
908  return FALSE;
909  }
910 
912  &IoStatusBlock,
913  &FileBasic,
914  sizeof(FILE_BASIC_INFORMATION),
916  if (!NT_SUCCESS(Status))
917  {
919  return FALSE;
920  }
921 
922  if (lpCreationTime)
923  {
924  lpCreationTime->dwLowDateTime = FileBasic.CreationTime.LowPart;
925  lpCreationTime->dwHighDateTime = FileBasic.CreationTime.HighPart;
926  }
927 
928  if (lpLastAccessTime)
929  {
930  lpLastAccessTime->dwLowDateTime = FileBasic.LastAccessTime.LowPart;
931  lpLastAccessTime->dwHighDateTime = FileBasic.LastAccessTime.HighPart;
932  }
933 
934  if (lpLastWriteTime)
935  {
936  lpLastWriteTime->dwLowDateTime = FileBasic.LastWriteTime.LowPart;
937  lpLastWriteTime->dwHighDateTime = FileBasic.LastWriteTime.HighPart;
938  }
939 
940  return TRUE;
941 }
942 
943 
944 /*
945  * @implemented
946  */
947 BOOL WINAPI
949  CONST FILETIME *lpCreationTime OPTIONAL,
950  CONST FILETIME *lpLastAccessTime OPTIONAL,
951  CONST FILETIME *lpLastWriteTime OPTIONAL)
952 {
955  FILE_BASIC_INFORMATION FileBasic;
956 
958  {
960  return FALSE;
961  }
962 
963  memset(&FileBasic, 0, sizeof(FILE_BASIC_INFORMATION));
964 
965  if (lpCreationTime)
966  {
967  FileBasic.CreationTime.LowPart = lpCreationTime->dwLowDateTime;
968  FileBasic.CreationTime.HighPart = lpCreationTime->dwHighDateTime;
969  }
970 
971  if (lpLastAccessTime)
972  {
973  FileBasic.LastAccessTime.LowPart = lpLastAccessTime->dwLowDateTime;
974  FileBasic.LastAccessTime.HighPart = lpLastAccessTime->dwHighDateTime;
975  }
976 
977  if (lpLastWriteTime)
978  {
979  FileBasic.LastWriteTime.LowPart = lpLastWriteTime->dwLowDateTime;
980  FileBasic.LastWriteTime.HighPart = lpLastWriteTime->dwHighDateTime;
981  }
982 
984  &IoStatusBlock,
985  &FileBasic,
986  sizeof(FILE_BASIC_INFORMATION),
988  if (!NT_SUCCESS(Status))
989  {
991  return FALSE;
992  }
993 
994  return TRUE;
995 }
996 
997 
998 /*
999  * The caller must have opened the file with the DesiredAccess FILE_WRITE_DATA flag set.
1000  *
1001  * @implemented
1002  */
1003 BOOL WINAPI
1005 {
1007  FILE_END_OF_FILE_INFORMATION EndOfFileInfo;
1008  FILE_ALLOCATION_INFORMATION FileAllocationInfo;
1009  FILE_POSITION_INFORMATION FilePosInfo;
1010  NTSTATUS Status;
1011 
1012  if(IsConsoleHandle(hFile))
1013  {
1015  return FALSE;
1016  }
1017 
1018  //get current position
1020  hFile,
1021  &IoStatusBlock,
1022  &FilePosInfo,
1023  sizeof(FILE_POSITION_INFORMATION),
1025  );
1026 
1027  if (!NT_SUCCESS(Status)){
1029  return FALSE;
1030  }
1031 
1032  EndOfFileInfo.EndOfFile.QuadPart = FilePosInfo.CurrentByteOffset.QuadPart;
1033 
1034  /*
1035  NOTE:
1036  This call is not supposed to free up any space after the eof marker
1037  if the file gets truncated. We have to deallocate the space explicitly afterwards.
1038  But...most file systems dispatch both FileEndOfFileInformation
1039  and FileAllocationInformation as they were the same command.
1040 
1041  */
1043  hFile,
1044  &IoStatusBlock, //out
1045  &EndOfFileInfo,
1048  );
1049 
1050  if (!NT_SUCCESS(Status)){
1052  return FALSE;
1053  }
1054 
1055  FileAllocationInfo.AllocationSize.QuadPart = FilePosInfo.CurrentByteOffset.QuadPart;
1056 
1057 
1059  hFile,
1060  &IoStatusBlock, //out
1061  &FileAllocationInfo,
1064  );
1065 
1066  if (!NT_SUCCESS(Status)){
1068  return FALSE;
1069  }
1070 
1071  return TRUE;
1072 
1073 }
1074 
1075 
1076 /*
1077  * @implemented
1078  */
1079 BOOL
1080 WINAPI
1082  HANDLE hFile,
1083  LONGLONG ValidDataLength
1084  )
1085 {
1087  FILE_VALID_DATA_LENGTH_INFORMATION ValidDataLengthInformation;
1088  NTSTATUS Status;
1089 
1090  ValidDataLengthInformation.ValidDataLength.QuadPart = ValidDataLength;
1091 
1093  hFile,
1094  &IoStatusBlock, //out
1095  &ValidDataLengthInformation,
1098  );
1099 
1100  if (!NT_SUCCESS(Status)){
1102  return FALSE;
1103  }
1104 
1105  return TRUE;
1106 }
1107 
1108 /* EOF */
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:794
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
BOOL WINAPI SetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
Definition: fileinfo.c:177
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:39
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
#define FILE_TYPE_DISK
Definition: winbase.h:256
#define CloseHandle
Definition: compat.h:598
enum _GET_FILEEX_INFO_LEVELS GET_FILEEX_INFO_LEVELS
#define FILE_DEVICE_SCREEN
Definition: winioctl.h:133
NTSTATUS NTAPI NtSetInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
NTSTATUS NTAPI NtQueryFullAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PFILE_NETWORK_OPEN_INFORMATION FileInformation)
Definition: file.c:3989
#define ERROR_SUCCESS
Definition: deptool.c:10
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
USHORT MaximumLength
Definition: env_spec_w32.h:370
LARGE_INTEGER LastAccessTime
Definition: nt_native.h:940
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
uint16_t * PWSTR
Definition: typedefs.h:56
#define FILE_CURRENT
Definition: winbase.h:113
#define FILE_DEVICE_NAMED_PIPE
Definition: winioctl.h:122
HANDLE ContainingDirectory
Definition: rtltypes.h:1379
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
#define WARN(fmt,...)
Definition: debug.h:112
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
VOID NTAPI RtlReleaseRelativeName(_In_ PRTL_RELATIVE_NAME_U RelativeName)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
BOOL WINAPI SetFileAttributesByHandle(IN HANDLE hFile, IN DWORD dwFileAttributes, IN DWORD dwFlags)
Definition: fileinfo.c:730
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
BOOL WINAPI FlushConsoleInputBuffer(IN HANDLE hConsoleInput)
Definition: console.c:217
LARGE_INTEGER CompressedFileSize
Definition: iotypes.h:5828
#define ZeroMemory
Definition: winbase.h:1648
HANDLE TranslateStdHandle(IN HANDLE hHandle)
Definition: handle.c:19
NTSTATUS NTAPI NtFlushBuffersFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock)
Definition: iofunc.c:1485
#define FILE_DEVICE_VIRTUAL_DISK
Definition: winioctl.h:141
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
#define INVALID_FILE_SIZE
Definition: winbase.h:529
#define FILE_BEGIN
Definition: compat.h:620
uint16_t * PWCHAR
Definition: typedefs.h:56
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_DEVICE_NULL
Definition: winioctl.h:126
#define FILE_TYPE_UNKNOWN
Definition: winbase.h:255
#define NO_ERROR
Definition: dderror.h:5
#define DWORD
Definition: nt_native.h:44
#define FILE_DEVICE_MODEM
Definition: winioctl.h:148
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:245
#define FILE_SHARE_READ
Definition: compat.h:136
LARGE_INTEGER AllocationSize
Definition: winternl.h:688
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToRelativeNtPathName_U(_In_ PCWSTR DosName, _Out_ PUNICODE_STRING NtName, _Out_ PCWSTR *PartName, _Out_ PRTL_RELATIVE_NAME_U RelativeName)
BOOL WINAPI DECLSPEC_HOTPATCH VerifyConsoleIoHandle(HANDLE hIoHandle)
Definition: console.c:1110
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:54
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:948
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:107
HANDLE FileHandle
Definition: stats.c:38
DWORD dwHighDateTime
Definition: mapidefs.h:66
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:109
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define FILE_TYPE_CHAR
Definition: winbase.h:257
#define kernel32file
Definition: kernel32.h:6
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:636
#define MAXDWORD
LARGE_INTEGER CurrentByteOffset
Definition: nt_native.h:955
BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:776
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
const char * LPCSTR
Definition: xmlstorage.h:183
#define OPEN_EXISTING
Definition: compat.h:634
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:246
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
#define FILE_DEVICE_DATALINK
Definition: winioctl.h:110
BOOL WINAPI GetFileAttributesByHandle(IN HANDLE hFile, OUT LPDWORD dwFileAttributes, IN DWORD dwFlags)
Definition: fileinfo.c:694
#define TRACE(s)
Definition: solgame.cpp:4
LARGE_INTEGER LastWriteTime
Definition: nt_native.h:941
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:458
#define FILE_END
Definition: winbase.h:114
DWORD WINAPI GetCompressedFileSizeA(LPCSTR lpFileName, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:397
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FILE_DEVICE_DFS
Definition: winioctl.h:111
#define WINAPI
Definition: msvc.h:6
struct _DeviceInfo DeviceInfo
#define FILE_DEVICE_PARALLEL_PORT
Definition: winioctl.h:127
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
#define SetLastError(x)
Definition: compat.h:611
#define FILE_DEVICE_MOUSE
Definition: winioctl.h:120
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define IsConsoleHandle(h)
Definition: console.h:14
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
PWCHAR FilenameA2W(LPCSTR NameA, BOOL alloc)
Definition: fileutils.c:18
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
LARGE_INTEGER CreationTime
Definition: nt_native.h:939
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
DEBUG_CHANNEL(kernel32file)
ULONG LowPart
Definition: typedefs.h:106
struct _LARGE_INTEGER::@2277 u
#define FILE_DEVICE_SOUND
Definition: winioctl.h:134
#define GENERIC_READ
Definition: compat.h:135
NTSTATUS NTAPI NtQueryInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
#define SYNCHRONIZE
Definition: nt_native.h:61
_In_ HANDLE hFile
Definition: mswsock.h:90
#define ERROR_NEGATIVE_SEEK
Definition: winerror.h:203
struct _FileName FileName
Definition: fatprocs.h:893
NTSTATUS NTAPI NtQueryVolumeInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, ULONG Length, FS_INFORMATION_CLASS FsInformationClass)
#define FILE_TYPE_PIPE
Definition: winbase.h:258
NTSTATUS NTAPI NtQueryAttributesFile(IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PFILE_BASIC_INFORMATION FileInformation)
Definition: file.c:3977
#define INVALID_SET_FILE_POINTER
Definition: compat.h:591
#define FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
DWORD WINAPI GetCompressedFileSizeW(LPCWSTR lpFileName, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:413
#define NULL
Definition: types.h:112
#define FileStandardInformation
Definition: propsheet.cpp:61
#define CreateFileW
Definition: compat.h:600
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
DWORD dwFileAttributes
#define OUT
Definition: typedefs.h:40
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:108
uint32_t * LPDWORD
Definition: typedefs.h:59
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
UNICODE_STRING RelativeName
Definition: rtltypes.h:1378
BOOL WINAPI GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation)
Definition: fileinfo.c:552
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
BOOL WINAPI GetFileAttributesExA(LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation)
Definition: fileinfo.c:619
#define FILE_ATTRIBUTE_VALID_SET_FLAGS
Definition: nt_native.h:715
#define FILE_DEVICE_SERIAL_PORT
Definition: serial.c:44
#define memset(x, y, z)
Definition: compat.h:39
signed int * PLONG
Definition: retypes.h:5
#define ERROR_BAD_PATHNAME
Definition: winerror.h:233
BOOL WINAPI SetFileValidData(HANDLE hFile, LONGLONG ValidDataLength)
Definition: fileinfo.c:1081
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
NTSYSAPI ULONG NTAPI RtlIsDosDeviceName_U(_In_ PCWSTR Name)
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:896
#define CONST
Definition: pedump.c:81
#define FILE_DEVICE_KEYBOARD
Definition: winioctl.h:116
DWORD dwLowDateTime
Definition: mapidefs.h:65
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
_In_ LPCSTR lpFileName
Definition: winbase.h:3034
LONGLONG QuadPart
Definition: typedefs.h:114
BOOL WINAPI GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize)
Definition: fileinfo.c:367
#define FILE_DEVICE_PRINTER
Definition: winioctl.h:129
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68