vbsfhlp.c revision 84f633d28fd1840520118fcc4ff7c726aeaa9184
/** @file
*
* VirtualBox Windows Guest Shared Folders
*
* File System Driver system helpers
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <ntifs.h>
#include <ntdddisk.h>
#include "vbsfhlp.h"
#ifdef DEBUG
static int s_iAllocRefCount = 0;
#endif
{
}
/**
* Convert VBox IRT file attributes to NT file attributes
*
* @returns NT file attributes
* @param fMode IRT file attributes
*
*/
{
uint32_t FileAttributes = 0;
if (fMode & RTFS_DOS_READONLY)
if (fMode & RTFS_DOS_HIDDEN)
if (fMode & RTFS_DOS_SYSTEM)
if (fMode & RTFS_DOS_DIRECTORY)
if (fMode & RTFS_DOS_ARCHIVED)
if (fMode & RTFS_DOS_NT_TEMPORARY)
if (fMode & RTFS_DOS_NT_SPARSE_FILE)
if (fMode & RTFS_DOS_NT_REPARSE_POINT)
if (fMode & RTFS_DOS_NT_COMPRESSED)
/* if (fMode & RTFS_DOS_NT_OFFLINE) */
if (fMode & RTFS_DOS_NT_ENCRYPTED)
if (fMode & RTFS_DOS_NT_NORMAL)
{
}
return FileAttributes;
}
/**
* Convert VBox IRT file attributes to NT file attributes
*
* @returns NT file attributes
* @param fMode IRT file attributes
*
*/
{
uint32_t FileAttributes = 0;
if (fMode & FILE_ATTRIBUTE_READONLY)
if (fMode & FILE_ATTRIBUTE_HIDDEN)
if (fMode & FILE_ATTRIBUTE_SYSTEM)
if (fMode & FILE_ATTRIBUTE_DIRECTORY)
if (fMode & FILE_ATTRIBUTE_ARCHIVE)
if (fMode & FILE_ATTRIBUTE_TEMPORARY)
if (fMode & FILE_ATTRIBUTE_SPARSE_FILE)
if (fMode & FILE_ATTRIBUTE_COMPRESSED)
if (fMode & FILE_ATTRIBUTE_ENCRYPTED)
if (fMode & FILE_ATTRIBUTE_NORMAL)
{
}
return FileAttributes;
}
{
/* Replace '_' with actual drive letter */
}
{
/* Replace '_' with actual drive letter */
return IoDeleteSymbolicLink (&driveName);
}
/**
* Convert VBox error code to NT status code
*
* @returns NT status code
* @param vboxRC VBox error code
*
*/
{
switch (vboxRC)
{
case VINF_SUCCESS:
break;
case VERR_ACCESS_DENIED:
break;
case VERR_NO_MORE_FILES:
break;
case VERR_PATH_NOT_FOUND:
break;
case VERR_FILE_NOT_FOUND:
break;
case VERR_DIR_NOT_EMPTY:
break;
case VERR_SHARING_VIOLATION:
break;
case VERR_FILE_LOCK_VIOLATION:
break;
case VERR_FILE_LOCK_FAILED:
break;
case VINF_BUFFER_OVERFLOW:
break;
case VERR_EOF:
case VINF_EOF:
break;
case VERR_READ_ERROR:
case VERR_WRITE_ERROR:
case VERR_FILE_IO_ERROR:
break;
case VERR_WRITE_PROTECT:
break;
case VERR_ALREADY_EXISTS:
break;
case VERR_NOT_A_DIRECTORY:
break;
case VERR_SEEK:
break;
case VERR_INVALID_PARAMETER:
break;
case VERR_NOT_SUPPORTED:
break;
default:
/* @todo error handling */
Log(("Unexpected vbox error %Rrc\n",
vboxRC));
break;
}
return Status;
}
{
#ifdef DEBUG
#endif
/* Tag is reversed (a.k.a "SHFL") to display correctly in debuggers, so search for "SHFL" */
{
#ifdef DEBUG
#endif
}
else
{
#ifdef DEBUG
#endif
}
return pMemory;
}
{
#ifdef DEBUG
#endif
/* MSDN: The ExFreePoolWithTag routine issues a bug check if the specified value for Tag does not match the tag value passed
to the routine that originally allocated the memory block. Otherwise, the behavior of this routine is identical to ExFreePool. */
}
#if 0 //def DEBUG
/**
* Callback for RTLogFormatV which writes to the backdoor.
* See PFNLOGOUTPUT() for details.
*/
{
return cbChars;
}
int RTLogBackdoorPrintf1(const char *pszFormat, ...)
{
return 0;
}
#endif
#if defined(DEBUG) || defined (LOG_ENABLED)
{
switch (MinorFunction)
{
case IRP_MN_START_DEVICE:
return "IRP_MJ_PNP - IRP_MN_START_DEVICE";
return "IRP_MJ_PNP - IRP_MN_QUERY_REMOVE_DEVICE";
case IRP_MN_REMOVE_DEVICE:
return "IRP_MJ_PNP - IRP_MN_REMOVE_DEVICE";
return "IRP_MJ_PNP - IRP_MN_CANCEL_REMOVE_DEVICE";
case IRP_MN_STOP_DEVICE:
return "IRP_MJ_PNP - IRP_MN_STOP_DEVICE";
case IRP_MN_QUERY_STOP_DEVICE:
return "IRP_MJ_PNP - IRP_MN_QUERY_STOP_DEVICE";
return "IRP_MJ_PNP - IRP_MN_CANCEL_STOP_DEVICE";
return "IRP_MJ_PNP - IRP_MN_QUERY_DEVICE_RELATIONS";
case IRP_MN_QUERY_INTERFACE:
return "IRP_MJ_PNP - IRP_MN_QUERY_INTERFACE";
return "IRP_MJ_PNP - IRP_MN_QUERY_CAPABILITIES";
case IRP_MN_QUERY_RESOURCES:
return "IRP_MJ_PNP - IRP_MN_QUERY_RESOURCES";
return "IRP_MJ_PNP - IRP_MN_QUERY_RESOURCE_REQUIREMENTS";
case IRP_MN_QUERY_DEVICE_TEXT:
return "IRP_MJ_PNP - IRP_MN_QUERY_DEVICE_TEXT";
return "IRP_MJ_PNP - IRP_MN_FILTER_RESOURCE_REQUIREMENTS";
case IRP_MN_READ_CONFIG:
return "IRP_MJ_PNP - IRP_MN_READ_CONFIG";
case IRP_MN_WRITE_CONFIG:
return "IRP_MJ_PNP - IRP_MN_WRITE_CONFIG";
case IRP_MN_EJECT:
return "IRP_MJ_PNP - IRP_MN_EJECT";
case IRP_MN_SET_LOCK:
return "IRP_MJ_PNP - IRP_MN_SET_LOCK";
case IRP_MN_QUERY_ID:
return "IRP_MJ_PNP - IRP_MN_QUERY_ID";
return "IRP_MJ_PNP - IRP_MN_QUERY_PNP_DEVICE_STATE";
return "IRP_MJ_PNP - IRP_MN_QUERY_BUS_INFORMATION";
return "IRP_MJ_PNP - IRP_MN_DEVICE_USAGE_NOTIFICATION";
case IRP_MN_SURPRISE_REMOVAL:
return "IRP_MJ_PNP - IRP_MN_SURPRISE_REMOVAL";
default:
return "IRP_MJ_PNP - unknown_pnp_irp";
}
}
{
switch (MinorFunction)
{
case IRP_MJ_CREATE:
return "IRP_MJ_CREATE";
case IRP_MJ_CREATE_NAMED_PIPE:
return "IRP_MJ_CREATE_NAMED_PIPE";
case IRP_MJ_CLOSE:
return "IRP_MJ_CLOSE";
case IRP_MJ_READ:
return "IRP_MJ_READ";
case IRP_MJ_WRITE:
return "IRP_MJ_WRITE";
case IRP_MJ_QUERY_INFORMATION:
return "IRP_MJ_QUERY_INFORMATION";
case IRP_MJ_SET_INFORMATION:
return "IRP_MJ_SET_INFORMATION";
case IRP_MJ_QUERY_EA:
return "IRP_MJ_QUERY_EA";
case IRP_MJ_SET_EA:
return "IRP_MJ_SET_EA";
case IRP_MJ_FLUSH_BUFFERS:
return "IRP_MJ_FLUSH_BUFFERS";
return "IRP_MJ_QUERY_VOLUME_INFORMATION";
return "IRP_MJ_SET_VOLUME_INFORMATION";
case IRP_MJ_DIRECTORY_CONTROL:
return "IRP_MJ_DIRECTORY_CONTROL";
return "IRP_MJ_FILE_SYSTEM_CONTROL";
case IRP_MJ_DEVICE_CONTROL:
return "IRP_MJ_DEVICE_CONTROL";
return "IRP_MJ_INTERNAL_DEVICE_CONTROL";
case IRP_MJ_SHUTDOWN:
return "IRP_MJ_SHUTDOWN";
case IRP_MJ_LOCK_CONTROL:
return "IRP_MJ_LOCK_CONTROL";
case IRP_MJ_CLEANUP:
return "IRP_MJ_CLEANUP";
case IRP_MJ_CREATE_MAILSLOT:
return "IRP_MJ_CREATE_MAILSLOT";
case IRP_MJ_QUERY_SECURITY:
return "IRP_MJ_QUERY_SECURITY";
case IRP_MJ_SET_SECURITY:
return "IRP_MJ_SET_SECURITY";
case IRP_MJ_POWER:
return "IRP_MJ_POWER";
case IRP_MJ_SYSTEM_CONTROL:
return "IRP_MJ_SYSTEM_CONTROL";
case IRP_MJ_DEVICE_CHANGE:
return "IRP_MJ_DEVICE_CHANGE";
case IRP_MJ_QUERY_QUOTA:
return "IRP_MJ_QUERY_QUOTA";
case IRP_MJ_SET_QUOTA:
return "IRP_MJ_SET_QUOTA";
case IRP_MJ_PNP:
return PnPMinorFunctionString(MinorFunction);
default:
return "unknown_pnp_irp";
}
}
#endif
/** Allocate and initialize a SHFLSTRING from a UNICODE string.
*
* @param ppShflString Where to store the pointer to the allocated SHFLSTRING structure.
* The structure must be deallocated with vbsfFreeNonPagedMem.
* @param pwc The UNICODE string. If NULL then SHFL is only allocated.
* @param cb Size of the UNICODE string in bytes without the trailing nul.
*
* @return Status code.
*/
{
/* Calculate length required for the SHFL structure: header + chars + nul. */
if (pShflString)
{
{
if (pwc)
{
}
else
{
}
}
else
{
}
}
else
{
}
return Status;
}