3--ioctl control operation of file system driven programming basic articles

Source: Internet
Author: User

Ii. Object Management and Namespaces (Namespace)

Different types of objects in kernel space are managed uniformly through the object manager, and the logical concept of namespaces is used to organize objects, similar to resource managers. The device directory stores a variety of device objects created through IoCreateDevice, including volume objects created by the file system driver. The FileSystem directory contains file system-driven objects and file system Recognizer device objects (which will be described in the Advanced section). For a more specific description, refer to Data 2.

So far, we have not discussed how applications in user mode interact with drivers, and forget about the "inscrutable" terms of "interrupt doors" and "Trap Doors" (which in turn are misleading motives), These fundamentals, which are contained in the CPU hardware theory, do not have a direct impact on our learning-driven programming, but, rather, the CreateFile function is worth mentioning. A file is a highly abstract concept, since objects in the kernel can be managed uniformly, and external devices are no exception, and they can be described in a file. From the graph we see the serial port COM1 of the computer, it corresponds to the device object Serial0, and C: Disk, corresponds to is the volume device object HarddiskVolume4, this is a kind of map called "Symbolic link", through this mapping, the program in user mode can see the device object in the kernel, They can also be opened by CreateFile. Image of the said, symbolic links similar to the nickname, such as the big Dog is generally called "flourishing wealth", the puppy is called "small white." A symbolic connection is established in the kernel to use Iocreatesymboliclink, and definedosdevice can be used in user mode.

CreateFile Use example, note "." corresponding to the "GLOBAL??" in the namespace. :

if ((hDevice = CreateFile( "\\\\.\\IoctlTest",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL)) == INVALID_HANDLE_VALUE) {

Another way is to IOCTL control operations.

Three, IOCTL control code

The structure of the IOCTL control code is similar to the definition of a message (such as wm_xxx) or Ntstatus, which is a driver-predefined 4-byte integer that defines its macro as:

#define Ioctl_device_function Ctl_code (DeviceType, Function, method, Access)

16-31 2-13 0-1 14-15

The macro creates a IOCTL code by providing a device type, a function code (which can be regarded as the ordinal of a function), buffering, and access rights. Device drivers can define multiple IOCTL codes (using different function codes to differentiate different functional functions) to provide different control functions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.