6

In the Red Hat documentation on Device Mapper, it reads:

"the application interface to the Device Mapper is the ioctl system call."

So far, I understand that the ioctls are sent to /dev/mapper/control (for most distributions), but it seems I will need to dig around the source code for dmsetup, libdevmapper, or similar to understand how the ioctls actually work and how to use them.

Are there any books, lectures, or documentation that expand on this topic? Am I stuck parsing through complicated source code? Am I better off using libdevmapper instead of the ioctl system calls? The man page for ioctl is too general to be of much use in this case.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Zomp
  • 117
  • 1
  • 7
  • Googling "device mapper ioctl" comes up with [this](https://lwn.net/Articles/35077/), which seems quite readable and not really complicated. The corresponding file is `include/uapi/linux/dm-ioctl.h`. `Documentation/device-mapper` also exists. Or was the question "I don't understand what an ioctl is"? And what do you actually want to achieve? Understand how the kernel works? – dirkt Apr 28 '17 at 06:48
  • 2
    @dirkt Yes, thank you. A newer source of dm-ioctl.h can be found [here](https://sourceware.org/git/?p=lvm2.git;a=blob;f=libdm/misc/dm-ioctl.h;h=cdb0c4c20f48b2ecf33c79058c2fe963f1e5843a;hb=ca427a711a33b02264689dcfca4bc5e5d2f9434e). My goal is to use ioctl's to create, destroy, and modify dm-crypt targets. To clarify, my question is how to go about learning to use the ioctl's to accomplish these goals. I understand the extent of what the header tells me, but how to _use_ the ioctls, including formatting and initializing the structs, correctly for each command, is not clear to me. – Zomp Apr 28 '17 at 21:40
  • Actually the kernel source doesn't say much, unless you want to analyze the source of drivers/md/dm-ioctl.c The documentation in include/uapi/linux/dm-ioctl.h only lists the DM_* ioctls and doesn't even show how to fill the struct dm_ioctl In theory you can emulate dmsetup create testdm --table "0 12345678 crypt aes-xts-plain 01234567…1234 just in three ioctl (including ioctl(dev_mapper_control_fd, DM_VERSION…) but there is little docs about how tu fill the structure passed as the third argument. – ChewbaccaKL Jun 23 '22 at 10:01

0 Answers0