Detailed macro CTL_CODE

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/mao0514/article/details/91410878

Macro CTL_CODE

The CTL_CODE: used to create a unique 32-bit system I / O control code, this control code consists of four components:

The DeviceType (device type, the upper 16 bits (bits 16-31)),

Function (Functions 2-13 bits),

Method (I / O access memory usage),

Access (access restrictions, 14-15 bits).

 

The macro creates a unique system I / O (Input Output) control codes (IOCTL).

#define xxx_xxx_xxx CTL_CODE(DeviceType, Function, Method, Access)

( ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))

As Example:

#include <winioctl.h> // used to create a unique 32-bit system I / O control code, this control code consists of four parts

#define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS)

#define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x801,METHOD_BUFFERED,FILE_ANY_ACCESS)

Parameters (parameters)

The CTL_CODE: used to create a unique 32-bit system I / O control code, this control code consists of four components:

The DeviceType (device type, the upper 16 bits (bits 16-31)),

Function (Functions 2-13 bits),

Method (I / O access memory usage),

Access (access restrictions, 14-15 bits).


DeviceType      to the transmission control device defines a device type code.
Range of values is used by Microsoft 0-32767; 32768-65535 value is retained by the use of OEM and IHV.
The following system-defined device type (enumeration):

FILE_DEVICE_BEEP 
FILE_DEVICE_CD_ROM 
FILE_DEVICE_CD_ROM_FILE_SYSTEM 
FILE_DEVICE_CONTROLLER 
FILE_DEVICE_DATALINK 
FILE_DEVICE_DFS 
FILE_DEVICE_DISK 
FILE_DEVICE_DISK_FILE_SYSTEM 
FILE_DEVICE_FILE_SYSTEM 
FILE_DEVICE_INPORT_PORT 
FILE_DEVICE_KEYBOARD 
FILE_DEVICE_MAILSLOT 
FILE_DEVICE_MIDI_IN 
FILE_DEVICE_MIDI_OUT 
FILE_DEVICE_MOUSE 
FILE_DEVICE_MULTI_UNC_PROVIDER 
FILE_DEVICE_NAMED_PIPE 
FILE_DEVICE_NETWORK 
FILE_DEVICE_NETWORK_BROWSER 
FILE_DEVICE_NETWORK_FILE_SYSTEM 
FILE_DEVICE_NULL 
FILE_DEVICE_PARALLEL_PORT 
FILE_DEVICE_PHYSICAL_NETCARD 
FILE_DEVICE_PRINTER 
FILE_DEVICE_SCANNER 
FILE_DEVICE_SERIAL_MOUSE_PORT 
FILE_DEVICE_SERIAL_PORT 
FILE_DEVICE_SCREEN 
FILE_DEVICE_SOUND 
FILE_DEVICE_DEVICE_STREAMS 
FILE_DEVICE_TAPE 
FILE_DEVICE_TAPE_FILE_SYSTEM 
FILE_DEVICE_TRANSPORT 
FILE_DEVICE_UNKNOWN   未知的设备类型
FILE_DEVICE_VIDEO 
FILE_DEVICE_VIRTUAL_DISK 
FILE_DEVICE_WAVE_IN 
FILE_DEVICE_WAVE_OUT 
FILE_DEVICE_8042_PORT 
FILE_DEVICE_NETWORK_REDIRECTOR 
FILE_DEVICE_BATTERY 
FILE_DEVICE_BUS_EXTENDER 
FILE_DEVICE_MODEM 
FILE_DEVICE_VDM 
FILE_DEVICE_MASS_STORAGE 
FILE_DEVICE_SMB 
FILE_DEVICE_KS 
FILE_DEVICE_CHANGER 
FILE_DEVICE_SMARTCARD 
FILE_DEVICE_ACPI 
FILE_DEVICE_DVD 
FILE_DEVICE_FULLSCREEN_VIDEO 
FILE_DEVICE_DFS_FILE_SYSTEM 
FILE_DEVICE_DFS_VOLUME

The following is a Windows CE device type system:

FILE_DEVICE_HAL 
FILE_DEVICE_CONSOLE 
FILE_DEVICE_PSL 
FILE_DEVICE_SERVICE

 

Function     of the above device is unique function number one device type definition.
CODE unique identification number of the function expressed in hexadecimal, the effective range is converted to decimal: 0-2047 are reserved for Microsoft; Code 2048-4095 are reserved for OEM and IHV. Other defined function code is greater than 4095.

 

Method,       the I / O memory access use

Let coding buffer Press (enumeration) method by I / O and file system control

METHOD_BUFFERED 
METHOD_IN_DIRECT 
METHOD_OUT_DIRECT 
METHOD_NEITHER 
this field is ignored by Windows CE (enumeration). You should always use METHOD_BUFFERED value unless compatibility with Windows-based desktop platform is required to use a different approach

Access        Access Restrictions

The following table shows the possible signs of this parameter (enumeration). The FILE_ANY_ACCESS is usually the correct value.

FILE_ANY_ACCESS all access requests. 
FILE_READ_ACCESS request read access. It can be used FILE_WRITE_ACCESS. 
FILE_WRITE_ACCESS read and write access request. It can be used FILE_READ_ACCESS.

Values the Return (return value)
no return value.

Remarks (Remarks)
macro can be used to define and FSCTL IOCTL function control codes. All IOCTL must be defined in such a way as to ensure by Microsoft, the value of the OEM, IHV and use do not overlap.

Guess you like

Origin blog.csdn.net/mao0514/article/details/91410878