mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 01:05:42 +00:00
GetFileAttributes() and SetFileAttributes() must use NtOpenFile() to open directories too.
svn path=/trunk/; revision=4404
This commit is contained in:
parent
8b0fa2ce3d
commit
68c3b158fc
1 changed files with 135 additions and 81 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: file.c,v 1.42 2003/03/06 13:00:51 ekohl Exp $
|
/* $Id: file.c,v 1.43 2003/03/23 04:01:16 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
|
@ -523,36 +523,64 @@ GetFileAttributesA(LPCSTR lpFileName)
|
||||||
DWORD STDCALL
|
DWORD STDCALL
|
||||||
GetFileAttributesW(LPCWSTR lpFileName)
|
GetFileAttributesW(LPCWSTR lpFileName)
|
||||||
{
|
{
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
FILE_BASIC_INFORMATION FileInformation;
|
||||||
FILE_BASIC_INFORMATION FileBasic;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
HANDLE hFile;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
NTSTATUS errCode;
|
UNICODE_STRING FileName;
|
||||||
|
HANDLE FileHandle;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
hFile = CreateFileW(lpFileName,
|
DPRINT ("GetFileAttributeW(%S) called\n", lpFileName);
|
||||||
FILE_READ_ATTRIBUTES,
|
|
||||||
FILE_SHARE_READ,
|
|
||||||
NULL,
|
|
||||||
OPEN_EXISTING,
|
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
|
||||||
NULL);
|
|
||||||
if (hFile == INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
return 0xFFFFFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
errCode = NtQueryInformationFile(hFile,
|
/* Validate and translate the filename */
|
||||||
&IoStatusBlock,
|
if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName,
|
||||||
&FileBasic,
|
&FileName,
|
||||||
sizeof(FILE_BASIC_INFORMATION),
|
NULL,
|
||||||
FileBasicInformation);
|
NULL))
|
||||||
if (!NT_SUCCESS(errCode))
|
{
|
||||||
{
|
DPRINT ("Invalid path\n");
|
||||||
CloseHandle(hFile);
|
SetLastError (ERROR_BAD_PATHNAME);
|
||||||
SetLastErrorByStatus(errCode);
|
return 0xFFFFFFFF;
|
||||||
return 0xFFFFFFFF;
|
}
|
||||||
}
|
DPRINT ("FileName: \'%wZ\'\n", &FileName);
|
||||||
CloseHandle(hFile);
|
|
||||||
return (DWORD)FileBasic.FileAttributes;
|
/* build the object attributes */
|
||||||
|
InitializeObjectAttributes (&ObjectAttributes,
|
||||||
|
&FileName,
|
||||||
|
OBJ_CASE_INSENSITIVE,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
/* Open the file */
|
||||||
|
Status = NtOpenFile (&FileHandle,
|
||||||
|
SYNCHRONIZE | FILE_READ_ATTRIBUTES,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||||
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
||||||
|
RtlFreeUnicodeString (&FileName);
|
||||||
|
if (!NT_SUCCESS (Status))
|
||||||
|
{
|
||||||
|
DPRINT ("NtOpenFile() failed (Status %lx)\n", Status);
|
||||||
|
SetLastErrorByStatus (Status);
|
||||||
|
return 0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get file attributes */
|
||||||
|
Status = NtQueryInformationFile (FileHandle,
|
||||||
|
&IoStatusBlock,
|
||||||
|
&FileInformation,
|
||||||
|
sizeof(FILE_BASIC_INFORMATION),
|
||||||
|
FileBasicInformation);
|
||||||
|
NtClose (FileHandle);
|
||||||
|
if (!NT_SUCCESS (Status))
|
||||||
|
{
|
||||||
|
DPRINT ("NtQueryInformationFile() failed (Status %lx)\n", Status);
|
||||||
|
SetLastErrorByStatus (Status);
|
||||||
|
return 0xFFFFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (DWORD)FileInformation.FileAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -560,29 +588,29 @@ WINBOOL STDCALL
|
||||||
SetFileAttributesA(LPCSTR lpFileName,
|
SetFileAttributesA(LPCSTR lpFileName,
|
||||||
DWORD dwFileAttributes)
|
DWORD dwFileAttributes)
|
||||||
{
|
{
|
||||||
UNICODE_STRING FileNameU;
|
UNICODE_STRING FileNameU;
|
||||||
ANSI_STRING FileName;
|
ANSI_STRING FileName;
|
||||||
WINBOOL Result;
|
WINBOOL Result;
|
||||||
|
|
||||||
RtlInitAnsiString(&FileName,
|
RtlInitAnsiString (&FileName,
|
||||||
(LPSTR)lpFileName);
|
(LPSTR)lpFileName);
|
||||||
|
|
||||||
/* convert ansi (or oem) string to unicode */
|
/* convert ansi (or oem) string to unicode */
|
||||||
if (bIsFileApiAnsi)
|
if (bIsFileApiAnsi)
|
||||||
RtlAnsiStringToUnicodeString(&FileNameU,
|
RtlAnsiStringToUnicodeString (&FileNameU,
|
||||||
&FileName,
|
&FileName,
|
||||||
TRUE);
|
TRUE);
|
||||||
else
|
else
|
||||||
RtlOemStringToUnicodeString(&FileNameU,
|
RtlOemStringToUnicodeString (&FileNameU,
|
||||||
&FileName,
|
&FileName,
|
||||||
TRUE);
|
TRUE);
|
||||||
|
|
||||||
Result = SetFileAttributesW(FileNameU.Buffer,
|
Result = SetFileAttributesW (FileNameU.Buffer,
|
||||||
dwFileAttributes);
|
dwFileAttributes);
|
||||||
|
|
||||||
RtlFreeUnicodeString(&FileNameU);
|
RtlFreeUnicodeString (&FileNameU);
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -590,51 +618,77 @@ WINBOOL STDCALL
|
||||||
SetFileAttributesW(LPCWSTR lpFileName,
|
SetFileAttributesW(LPCWSTR lpFileName,
|
||||||
DWORD dwFileAttributes)
|
DWORD dwFileAttributes)
|
||||||
{
|
{
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
FILE_BASIC_INFORMATION FileInformation;
|
||||||
FILE_BASIC_INFORMATION FileBasic;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
HANDLE hFile;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
NTSTATUS errCode;
|
UNICODE_STRING FileName;
|
||||||
|
HANDLE FileHandle;
|
||||||
hFile = CreateFileW(lpFileName,
|
NTSTATUS Status;
|
||||||
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
|
|
||||||
FILE_SHARE_READ,
|
|
||||||
NULL,
|
|
||||||
OPEN_EXISTING,
|
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
|
||||||
NULL);
|
|
||||||
if (INVALID_HANDLE_VALUE == hFile)
|
|
||||||
{
|
|
||||||
DPRINT("SetFileAttributes CreateFileW failed with code %d\n", GetLastError());
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
errCode = NtQueryInformationFile(hFile,
|
DPRINT ("SetFileAttributeW(%S, 0x%lx) called\n", lpFileName, dwFileAttributes);
|
||||||
&IoStatusBlock,
|
|
||||||
&FileBasic,
|
/* Validate and translate the filename */
|
||||||
sizeof(FILE_BASIC_INFORMATION),
|
if (!RtlDosPathNameToNtPathName_U ((LPWSTR)lpFileName,
|
||||||
FileBasicInformation);
|
&FileName,
|
||||||
if (!NT_SUCCESS(errCode))
|
NULL,
|
||||||
{
|
NULL))
|
||||||
CloseHandle(hFile);
|
{
|
||||||
DPRINT("SetFileAttributes NtQueryInformationFile failed with status 0x%08x\n", errCode);
|
DPRINT ("Invalid path\n");
|
||||||
SetLastErrorByStatus(errCode);
|
SetLastError (ERROR_BAD_PATHNAME);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
FileBasic.FileAttributes = dwFileAttributes;
|
DPRINT ("FileName: \'%wZ\'\n", &FileName);
|
||||||
errCode = NtSetInformationFile(hFile,
|
|
||||||
|
/* build the object attributes */
|
||||||
|
InitializeObjectAttributes (&ObjectAttributes,
|
||||||
|
&FileName,
|
||||||
|
OBJ_CASE_INSENSITIVE,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
/* Open the file */
|
||||||
|
Status = NtOpenFile (&FileHandle,
|
||||||
|
SYNCHRONIZE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
|
||||||
|
&ObjectAttributes,
|
||||||
|
&IoStatusBlock,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||||
|
FILE_SYNCHRONOUS_IO_NONALERT);
|
||||||
|
RtlFreeUnicodeString (&FileName);
|
||||||
|
if (!NT_SUCCESS (Status))
|
||||||
|
{
|
||||||
|
DPRINT ("NtOpenFile() failed (Status %lx)\n", Status);
|
||||||
|
SetLastErrorByStatus (Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = NtQueryInformationFile(FileHandle,
|
||||||
&IoStatusBlock,
|
&IoStatusBlock,
|
||||||
&FileBasic,
|
&FileInformation,
|
||||||
sizeof(FILE_BASIC_INFORMATION),
|
sizeof(FILE_BASIC_INFORMATION),
|
||||||
FileBasicInformation);
|
FileBasicInformation);
|
||||||
if (!NT_SUCCESS(errCode))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
CloseHandle(hFile);
|
DPRINT ("SetFileAttributes NtQueryInformationFile failed with status 0x%08x\n", Status);
|
||||||
DPRINT("SetFileAttributes NtSetInformationFile failed with status 0x%08x\n", errCode);
|
NtClose (FileHandle);
|
||||||
SetLastErrorByStatus(errCode);
|
SetLastErrorByStatus (Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
CloseHandle(hFile);
|
|
||||||
return TRUE;
|
FileInformation.FileAttributes = dwFileAttributes;
|
||||||
|
Status = NtSetInformationFile(FileHandle,
|
||||||
|
&IoStatusBlock,
|
||||||
|
&FileInformation,
|
||||||
|
sizeof(FILE_BASIC_INFORMATION),
|
||||||
|
FileBasicInformation);
|
||||||
|
NtClose (FileHandle);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT ("SetFileAttributes NtSetInformationFile failed with status 0x%08x\n", Status);
|
||||||
|
SetLastErrorByStatus (Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue