📄 mavioctl.c
字号:
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 8)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
//
// Get the modification date/time.
//
pOut->ulDate = ((ULONG *)buffer)[1];
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "close" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorClose(IN PDEVICE_OBJECT DeviceObject, IN PURB urb, PUCHAR buffer,
PULONG result)
{
NTSTATUS ntStatus;
//
// Send the "close" vendor request.
//
ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, 0, USB_Vendor_Close,
0, 0, buffer, 4);
//
// If the vendor packet was sent successfully, then return the result.
//
if(NT_SUCCESS(ntStatus))
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "delete" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorDelete(IN PDEVICE_OBJECT DeviceObject, IN PURB urb, PUCHAR buffer,
MavUsb_DeleteParams *pIn, PULONG result)
{
NTSTATUS ntStatus;
//
// Send the file name.
//
ntStatus = MavUsb_BulkXfer(DeviceObject, (char *)pIn->pusFileName, 256,
FALSE);
if(!NT_SUCCESS(ntStatus))
{
return(ntStatus);
}
//
// Send the "delete" vendor request.
//
ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulDriveNum,
USB_Vendor_Delete, 0, 0, buffer, 4);
//
// If the vendor packet was sent successfully, then return the result.
//
if(NT_SUCCESS(ntStatus))
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "opendir" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorOpenDir(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
PUCHAR buffer, MavUsb_OpenDirParams *pIn, PULONG result)
{
NTSTATUS ntStatus;
//
// Send the directory name.
//
ntStatus = MavUsb_BulkXfer(DeviceObject, (char *)pIn->pusDirName, 256,
FALSE);
if(!NT_SUCCESS(ntStatus))
{
return(ntStatus);
}
//
// Send the "open_dir" vendor request.
//
ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulDriveNum,
USB_Vendor_OpenDir, 0, 0, buffer, 4);
//
// If the vendor packet was sent successfully, then return the result.
//
if(NT_SUCCESS(ntStatus))
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "readdir" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorReadDir(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
PUCHAR buffer, MavUsb_ReadDirParams *pIn,
MavUsb_ReadDirResult *pOut, PULONG result)
{
NTSTATUS ntStatus;
//
// Send the "read_dir" vendor request.
//
ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, 0,
USB_Vendor_ReadDir,
(USHORT)pIn->ulType, 0, buffer, 4);
//
// If the vendor packet was sent successfully, then return the result.
//
if(NT_SUCCESS(ntStatus))
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
//
// Read the file name.
//
if(*result)
{
ntStatus = MavUsb_BulkXfer(DeviceObject, (char *)pOut->pusName,
256, TRUE);
}
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "closedir" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorCloseDir(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
PUCHAR buffer, PULONG result)
{
NTSTATUS ntStatus;
//
// Send the "closedir" vendor request.
//
ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, 0,
USB_Vendor_CloseDir, 0, 0, buffer, 4);
//
// If the vendor packet was sent successfully, then return the result.
//
if(NT_SUCCESS(ntStatus))
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "makedir" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorMakeDir(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
PUCHAR buffer, MavUsb_MakeDirParams *pIn, PULONG result)
{
NTSTATUS ntStatus;
//
// Send the directory name.
//
ntStatus = MavUsb_BulkXfer(DeviceObject, (char *)pIn->pusDirName, 256,
FALSE);
if(!NT_SUCCESS(ntStatus))
{
return(ntStatus);
}
//
// Send the "make_dir" vendor request.
//
ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulDriveNum,
USB_Vendor_MakeDir, 0, 0, buffer, 4);
//
// If the vendor packet was sent successfully, then return the result.
//
if(NT_SUCCESS(ntStatus))
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "removedir" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorRemoveDir(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
PUCHAR buffer, MavUsb_RemoveDirParams *pIn,
PULONG result)
{
NTSTATUS ntStatus;
//
// Send the directory name.
//
ntStatus = MavUsb_BulkXfer(DeviceObject, (char *)pIn->pusDirName, 256,
FALSE);
if(!NT_SUCCESS(ntStatus))
{
return(ntStatus);
}
//
// Send the "remove_dir" vendor request.
//
ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulDriveNum,
USB_Vendor_RemoveDir, 0, 0, buffer, 4);
//
// If the vendor packet was sent successfully, then return the result.
//
if(NT_SUCCESS(ntStatus))
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "total space" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorTotalSpace(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
PUCHAR buffer, MavUsb_TotalSpaceParams *pIn,
MavUsb_TotalSpaceResult *pOut, PULONG result)
{
NTSTATUS ntStatus;
//
// Send the "total_space" vendor request.
//
ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulDriveNum,
USB_Vendor_TotalSpace, 0, 0, buffer,
8);
//
// If the vendor packet was sent successfully, then return the result.
//
if(NT_SUCCESS(ntStatus))
{
//
// Make sure that the correct amount of data was returned.
//
if(urb->UrbControlVendorClassRequest.TransferBufferLength != 8)
{
//
// The wrong amount of data was returned, so return a device error.
//
ntStatus = STATUS_DEVICE_DATA_ERROR;
}
else
{
//
// Get the return code.
//
*result = ((ULONG *)buffer)[0];
//
// Get the total space.
//
pOut->ulBytes = ((ULONG *)buffer)[1];
}
}
//
// Return the result.
//
return(ntStatus);
}
//****************************************************************************
//
// Handles the "free space" request IOCTL.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -