Changeset 82835 in vbox for trunk/src/VBox
- Timestamp:
- Jan 22, 2020 9:53:59 PM (5 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/fileio-win.cpp
r82834 r82835 56 56 typedef BOOL WINAPI FNVERIFYCONSOLEIOHANDLE(HANDLE); 57 57 typedef FNVERIFYCONSOLEIOHANDLE *PFNVERIFYCONSOLEIOHANDLE; /* No, nobody fell on the keyboard, really! */ 58 58 59 59 60 /** … … 753 754 } 754 755 755 756 #if 0 756 #if 1 757 758 /** 759 * Checks the the two handles refers to the same file. 760 * 761 * @returns true if the same file, false if different ones or invalid handles. 762 * @param hFile1 Handle \#1. 763 * @param hFile2 Handle \#2. 764 */ 765 static bool rtFileIsSame(HANDLE hFile1, HANDLE hFile2) 766 { 767 /* 768 * We retry in case CreationTime or the Object ID is being modified and there 769 * aren't any IndexNumber (file ID) on this kind of file system. 770 */ 771 for (uint32_t iTries = 0; iTries < 3; iTries++) 772 { 773 /* 774 * Fetch data to compare (being a little lazy here). 775 */ 776 struct 777 { 778 HANDLE hFile; 779 NTSTATUS rcObjId; 780 FILE_OBJECTID_INFORMATION ObjId; 781 FILE_ALL_INFORMATION All; 782 FILE_FS_VOLUME_INFORMATION Vol; 783 } auData[2]; 784 auData[0].hFile = hFile1; 785 auData[1].hFile = hFile2; 786 787 for (uintptr_t i = 0; i < RT_ELEMENTS(auData); i++) 788 { 789 RT_ZERO(auData[i].ObjId); 790 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 791 auData[i].rcObjId = NtQueryInformationFile(auData[i].hFile, &Ios, &auData[i].ObjId, sizeof(auData[i].ObjId), 792 FileObjectIdInformation); 793 794 RT_ZERO(auData[i].All); 795 RTNT_IO_STATUS_BLOCK_REINIT(&Ios); 796 NTSTATUS rcNt = NtQueryInformationFile(auData[i].hFile, &Ios, &auData[i].All, sizeof(auData[i].All), 797 FileAllInformation); 798 AssertReturn(rcNt == STATUS_BUFFER_OVERFLOW /* insufficient space for name info */ || NT_SUCCESS(rcNt), false); 799 800 union 801 { 802 FILE_FS_VOLUME_INFORMATION Info; 803 uint8_t abBuf[sizeof(FILE_FS_VOLUME_INFORMATION) + 4096]; 804 } uVol; 805 RT_ZERO(uVol.Info); 806 RTNT_IO_STATUS_BLOCK_REINIT(&Ios); 807 rcNt = NtQueryVolumeInformationFile(auData[i].hFile, &Ios, &uVol, sizeof(uVol), FileFsVolumeInformation); 808 if (NT_SUCCESS(rcNt)) 809 auData[i].Vol = uVol.Info; 810 else 811 RT_ZERO(auData[i].Vol); 812 } 813 814 /* 815 * Compare it. 816 */ 817 if ( auData[0].All.StandardInformation.Directory 818 == auData[1].All.StandardInformation.Directory) 819 { /* likely */ } 820 else 821 break; 822 823 if ( (auData[0].All.BasicInformation.FileAttributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_REPARSE_POINT)) 824 == (auData[1].All.BasicInformation.FileAttributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_REPARSE_POINT))) 825 { /* likely */ } 826 else 827 break; 828 829 if ( auData[0].Vol.VolumeSerialNumber 830 == auData[1].Vol.VolumeSerialNumber) 831 { /* likely */ } 832 else 833 break; 834 835 if ( auData[0].All.InternalInformation.IndexNumber.QuadPart 836 == auData[1].All.InternalInformation.IndexNumber.QuadPart) 837 { /* likely */ } 838 else 839 break; 840 841 if ( !NT_SUCCESS(auData[0].rcObjId) 842 || memcmp(&auData[0].ObjId, &auData[1].ObjId, RT_UOFFSETOF(FILE_OBJECTID_INFORMATION, ExtendedInfo)) == 0) 843 { 844 if ( auData[0].All.BasicInformation.CreationTime.QuadPart 845 == auData[1].All.BasicInformation.CreationTime.QuadPart) 846 return true; 847 } 848 } 849 850 return false; 851 } 852 853 757 854 /** 758 855 * If @a hFile is opened in append mode, try return a handle with … … 804 901 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 805 902 FILE_OPEN, 806 FILE_OPEN_FOR_BACKUP_INTENT ,903 FILE_OPEN_FOR_BACKUP_INTENT /*??*/, 807 904 NULL /*EaBuffer*/, 808 905 0 /*EaLength*/); … … 810 907 if (NT_SUCCESS(rcNt)) 811 908 { 812 /** @todo Check that the two handles are for the same file object. */ 813 814 return hDupFile; 909 /* 910 * Check that we've opened the same file. 911 */ 912 if (rtFileIsSame(hFile, hDupFile)) 913 return hDupFile; 914 NtClose(hDupFile); 815 915 } 816 916 } 917 AssertFailed(); 817 918 } 818 919 } 819 920 return INVALID_HANDLE_VALUE; 820 921 } 922 821 923 #endif 822 823 924 824 925 RTR3DECL(int) RTFileSetSize(RTFILE hFile, uint64_t cbSize) -
trunk/src/VBox/Runtime/testcase/tstFile.cpp
r82832 r82835 286 286 * Test appending & truncation. 287 287 */ 288 RTTestSub(hTest, " Basics");288 RTTestSub(hTest, "Append"); 289 289 hFile = NIL_RTFILE; 290 290 RTTESTI_CHECK_RC(rc = RTFileOpen(&hFile, "tstFile#2.tst",
Note:
See TracChangeset
for help on using the changeset viewer.