rtFileNativeSetAttributes-win.cpp revision dc0a54940789f994c84390cb4a9f03da0b492285
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync/* $Id$ */
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync/** @file
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * IPRT - NtSetInformationFile wrapper.
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync */
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2009 Oracle Corporation
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync *
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * available from http://www.virtualbox.org. This file is free software;
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * General Public License (GPL) as published by the Free Software
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync *
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * The contents of this file may alternatively be used under the terms
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * of the Common Development and Distribution License Version 1.0
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * VirtualBox OSE distribution, in which case the provisions of the
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * CDDL are applicable instead of those of the GPL.
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync *
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * You may elect to license modified versions of this file under the
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * terms and conditions of either the GPL or the CDDL or both.
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync */
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync/*******************************************************************************
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync* Header Files *
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync*******************************************************************************/
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync/* APIs used here require DDK headers. */
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync#include <wdm.h>
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync/* Declare ntdll exports. */
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsyncextern "C"
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync{
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsyncNTSYSAPI ULONG NTAPI RtlNtStatusToDosError (IN NTSTATUS Status);
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsyncNTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE FileHandle,
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync OUT PIO_STATUS_BLOCK IoStatusBlock,
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync IN PVOID FileInformation,
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync IN ULONG Length,
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync IN FILE_INFORMATION_CLASS FileInformationClass);
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync}
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync/** Windows/NT worker.
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * @todo rename to rtFileWinSetAttributes */
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsyncint rtFileNativeSetAttributes(HANDLE hFile, ULONG fAttributes)
4f812c244b4730e1f36be3fb5515a9981adacb4dvboxsync{
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync IO_STATUS_BLOCK IoStatusBlock;
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync memset(&IoStatusBlock, 0, sizeof(IoStatusBlock));
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync /*
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * Members that are set 0 will not be modified on the file object.
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * See http://msdn.microsoft.com/en-us/library/aa491634.aspx (the struct docs)
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync * for details.
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync */
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync FILE_BASIC_INFORMATION Info;
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync memset(&Info, 0, sizeof(Info));
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync Info.FileAttributes = fAttributes;
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync /** @todo resolve dynamically to avoid dragging in NtDll? */
ec43172498014653e46c4f09253594cebde6fed2vboxsync NTSTATUS Status = NtSetInformationFile(RTFileToNative(hFile),
ec43172498014653e46c4f09253594cebde6fed2vboxsync &IoStatusBlock,
ec43172498014653e46c4f09253594cebde6fed2vboxsync &Info,
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync sizeof(Info),
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync FileBasicInformation);
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync return RtlNtStatusToDosError(Status);
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync}
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync
002ceede8bd0a6978946f0fbf9877b6a07e94db7vboxsync