Windows核心學習筆記(五)– 詳解CTL_CODE宏

來源:互聯網
上載者:User

我們在說DeviceIoControl函數時其第二個參數dwIoControlCode就是由CTL_CODE宏定義的,下邊我們可以瞭解一下CTL_CODE的內容。


CTL_CODE:用於建立一個唯一的32位系統I/O控制碼,這個控制碼包括4部分
組成:DeviceType(裝置類型,高16位(16-31位)),Access(訪問限制,14-15位),Function(功能2-13
位),Method(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_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 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 should always use the
METHOD_BUFFERED value unless compatibility with Windows-based desktop
platforms is required using a different Method
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(傳回值)

None.

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 illustration shows the format of the resulting IOCTL.

參考自:http://msdn.microsoft.com/en-us/library/ms904001.aspx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.