When we talk about the deviceiocontrol function, the second parameter dwiocontrolcode is defined by the ctl_code Macro. Let's take a look at the content of ctl_code.
Ctl_code: used to create a unique 32-bit system I/O control code. This control code consists of four parts.
Composition: devicetype (device type, high 16-bit (16-31 bits), access (access restriction, 14-15 bits), function (function 2-13
(I/O ).
This macro creates a unique system I/O control code (IOCTL ).
#define CTL_CODE(DeviceType, Function, Method, Access) (
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)
)
Parameters)
-
Devicetype
-
Defines the type of device for the given IOCTL.
This parameter can be no bigger than a word value.
The values used by Microsoft are in the range 0-32767; the values 32768-65535 are reserved for use by OEMs and ihvs.
The following device types are defined by the system:
- 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_plugin
- 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 device types are specific to Windows CE:
- File_device_hal
- File_device_console
- File_device_psl
- File_device_service
-
Function
-
Defines an action within the device category.
Function codes 0-2047 are reserved for Microsoft; codes 2048-4095 are reserved for OEMs and ihvs.
A function code can be no larger then 4095.
-
Method
-
Defines the method codes for how buffers are passed for I/O and file system controls.
The following values are possible for this parameter:
- Method_buffered
- Method_in_direct
- Method_out_direct
- Method_neither
This field is ignored by Windows CE. You shoshould always use
Method_buffered value unless compatibility with Windows-based desktop
Platforms is required using a differentMethod
Value.
-
Access
-
Defines the access check value for any access.
The following table shows the possible flags for this parameter. The file_access_any is generally the correct value.
Flag |
Description |
File_any_access |
Request all access. |
File_read_access |
Request read access. can be used with file_write_access. |
File_write_access |
Request write access. can be used with file_read_access. |
Return values (return value)
None.
Remarks (Remarks)
The macro can be used for defining IOCTL and fsctl Function Control
Codes. All IOCTLs must be defined this way to ensure that values used
By Microsoft, OEMs, and ihvs do not overlap.
The following validation shows the format of the resulting IOCTL.
Reference: http://msdn.microsoft.com/en-us/library/ms904001.aspx