IOCTL(CTL_CODE)

IOCTL

 下图显示控制代码结果格式:

在wdm.h中定义了一系统宏来解析/反解析IO控制代码:

//宏:用来生成IOCTL 和 FSCTL功能控制代码,功能代码0-2047由微软使用,2048-4095供用户使用

#define CTL_CODE( DeviceType, Function, Method, Access ) (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))

//宏:提取设备类型的宏

#define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16)

//宏:提取缓存方法
#define METHOD_FROM_CTL_CODE(ctrlCode) ((ULONG)(ctrlCode & 3))

//宏:提取功能代码

#define IoGetFunctionCodeFromCtlCode( ControlCode ) (( ControlCode >> 2) & 0x00000FFF )

 

 设备类型代码:

 1 //
 2 // Define the various device type values.  Note that values used by Microsoft
 3 // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
 4 // by customers.
 5 //
 6 
 7 #define DEVICE_TYPE ULONG
 8 
 9 #define FILE_DEVICE_BEEP                0x00000001
10 #define FILE_DEVICE_CD_ROM              0x00000002
11 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM  0x00000003
12 #define FILE_DEVICE_CONTROLLER          0x00000004
13 #define FILE_DEVICE_DATALINK            0x00000005
14 #define FILE_DEVICE_DFS                 0x00000006
15 #define FILE_DEVICE_DISK                0x00000007
16 #define FILE_DEVICE_DISK_FILE_SYSTEM    0x00000008
17 #define FILE_DEVICE_FILE_SYSTEM         0x00000009
18 #define FILE_DEVICE_INPORT_PORT         0x0000000a
19 #define FILE_DEVICE_KEYBOARD            0x0000000b
20 #define FILE_DEVICE_MAILSLOT            0x0000000c
21 #define FILE_DEVICE_MIDI_IN             0x0000000d
22 #define FILE_DEVICE_MIDI_OUT            0x0000000e
23 #define FILE_DEVICE_MOUSE               0x0000000f
24 #define FILE_DEVICE_MULTI_UNC_PROVIDER  0x00000010
25 #define FILE_DEVICE_NAMED_PIPE          0x00000011
26 #define FILE_DEVICE_NETWORK             0x00000012
27 #define FILE_DEVICE_NETWORK_BROWSER     0x00000013
28 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
29 #define FILE_DEVICE_NULL                0x00000015
30 #define FILE_DEVICE_PARALLEL_PORT       0x00000016
31 #define FILE_DEVICE_PHYSICAL_NETCARD    0x00000017
32 #define FILE_DEVICE_PRINTER             0x00000018
33 #define FILE_DEVICE_SCANNER             0x00000019
34 #define FILE_DEVICE_SERIAL_MOUSE_PORT   0x0000001a
35 #define FILE_DEVICE_SERIAL_PORT         0x0000001b
36 #define FILE_DEVICE_SCREEN              0x0000001c
37 #define FILE_DEVICE_SOUND               0x0000001d
38 #define FILE_DEVICE_STREAMS             0x0000001e
39 #define FILE_DEVICE_TAPE                0x0000001f
40 #define FILE_DEVICE_TAPE_FILE_SYSTEM    0x00000020
41 #define FILE_DEVICE_TRANSPORT           0x00000021
42 #define FILE_DEVICE_UNKNOWN             0x00000022
43 #define FILE_DEVICE_VIDEO               0x00000023
44 #define FILE_DEVICE_VIRTUAL_DISK        0x00000024
45 #define FILE_DEVICE_WAVE_IN             0x00000025
46 #define FILE_DEVICE_WAVE_OUT            0x00000026
47 #define FILE_DEVICE_8042_PORT           0x00000027
48 #define FILE_DEVICE_NETWORK_REDIRECTOR  0x00000028
49 #define FILE_DEVICE_BATTERY             0x00000029
50 #define FILE_DEVICE_BUS_EXTENDER        0x0000002a
51 #define FILE_DEVICE_MODEM               0x0000002b
52 #define FILE_DEVICE_VDM                 0x0000002c
53 #define FILE_DEVICE_MASS_STORAGE        0x0000002d
54 #define FILE_DEVICE_SMB                 0x0000002e
55 #define FILE_DEVICE_KS                  0x0000002f
56 #define FILE_DEVICE_CHANGER             0x00000030
57 #define FILE_DEVICE_SMARTCARD           0x00000031
58 #define FILE_DEVICE_ACPI                0x00000032
59 #define FILE_DEVICE_DVD                 0x00000033
60 #define FILE_DEVICE_FULLSCREEN_VIDEO    0x00000034
61 #define FILE_DEVICE_DFS_FILE_SYSTEM     0x00000035
62 #define FILE_DEVICE_DFS_VOLUME          0x00000036
63 #define FILE_DEVICE_SERENUM             0x00000037
64 #define FILE_DEVICE_TERMSRV             0x00000038
65 #define FILE_DEVICE_KSEC                0x00000039
66 #define FILE_DEVICE_FIPS                0x0000003A
67 #define FILE_DEVICE_INFINIBAND          0x0000003B
68 #define FILE_DEVICE_VMBUS               0x0000003E
69 #define FILE_DEVICE_CRYPT_PROVIDER      0x0000003F
70 #define FILE_DEVICE_WPD                 0x00000040
71 #define FILE_DEVICE_BLUETOOTH           0x00000041
72 #define FILE_DEVICE_MT_COMPOSITE        0x00000042
73 #define FILE_DEVICE_MT_TRANSPORT        0x00000043
74 #define FILE_DEVICE_BIOMETRIC           0x00000044
75 #define FILE_DEVICE_PMI                 0x00000045
76 #define FILE_DEVICE_EHSTOR              0x00000046
77 #define FILE_DEVICE_DEVAPI              0x00000047
78 #define FILE_DEVICE_GPIO                0x00000048
79 #define FILE_DEVICE_USBEX               0x00000049
80 #define FILE_DEVICE_CONSOLE             0x00000050
81 #define FILE_DEVICE_NFP                 0x00000051
82 #define FILE_DEVICE_SYSENV              0x00000052
83 #define FILE_DEVICE_VIRTUAL_BLOCK       0x00000053
84 #define FILE_DEVICE_POINT_OF_SERVICE    0x00000054
85 #define FILE_DEVICE_STORAGE_REPLICATION 0x00000055
86 #define FILE_DEVICE_TRUST_ENV           0x00000056
87 #define FILE_DEVICE_UCM                 0x00000057
88 #define FILE_DEVICE_UCMTCPCI            0x00000058
89 #define FILE_DEVICE_PERSISTENT_MEMORY   0x00000059
90 #define FILE_DEVICE_NVDIMM              0x0000005a
91 #define FILE_DEVICE_HOLOGRAPHIC         0x0000005b
92 #define FILE_DEVICE_SDFXHCI             0x0000005c
设备类型代码

 

缓存方法:

1 // 定义I/O和FS控制如何传递缓存的方法代码
2 
3 #define METHOD_BUFFERED                 0
4 #define METHOD_IN_DIRECT                1
5 #define METHOD_OUT_DIRECT               2
6 #define METHOD_NEITHER                  3
缓存方法

 

Windows系统定义IOCTLS定义于winioctl.h文件中

System IOCTLS

 

Defining I/O Control Codes

IRP处理参考 生成的IOCTL对应IRP派遣函数 内核模式参见

Handling IRPs

  文件系统访问功能代码:https://msdn.microsoft.com/en-us/library/windows/hardware/ff548603(v=vs.85).aspx

posted @ 2018-10-03 09:22  平凡人  阅读(1026)  评论(0编辑  收藏  举报