简体   繁体   中英

Creating a block device entry from an offset of another block device

I am writing what I can guess would be classed as a file system, that's 100% compatible with LUKS/dm-crypt, except for a 128 byte metadata block in the beginning of the device. I don't see a way to specify an offset from crypt_load , crypt_format or crypt_activate_by_passphrase .

So, in the search of a more general solution: How can I, from C (or C++), create a block device pointing to an offset of another block device?

devicemapper can do this. I don't know about the C interface, but you can read the source code of dmsetup .

In particular:

echo "$SIZE linear /dev/$DEVICE $OFFSET" | dmsetup create NEWDEVICE

will create a device named /dev/mapper/NEWDEVICE .

The funny thing is that $SIZE and $OFFSET are in number of blocks, not bytes. And block size is usually 512 bytes, so your offset of 128 bytes will be impossible to do. But anyway, you do not want to misalign the blocks in your device, do you?

UPDATE : Ok, I looked at it. dmsetup uses this cool library libdevmapper to do the hard work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM