Home:ALL Converter>createFile() and DeviceIoControl() equivalent for volume devices in Unix/Linux

createFile() and DeviceIoControl() equivalent for volume devices in Unix/Linux

Ask Time:2020-02-10T15:51:30         Author:jayprakash

Json Formatter

I have opened volume USB device and locked using CreateFile() and DeviceIoControl() in Windows.

I want same functionality on Linux/Unix system. I am new to Unix So How to get it?

My code for Windows :

HANDLE handle = CreateFile(L"\\\\.\\F:",          // F: drive to open
    GENERIC_READ,                // no access to the drive
    FILE_SHARE_READ, // share mode
    NULL,             // default security attributes
    OPEN_EXISTING,    // disposition
    0x1,                // file attributes
    NULL);            // do not copy file attributes

DWORD lpBytesReturned;

if (DeviceIoControl(handle, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &lpBytesReturned, (LPOVERLAPPED)NULL)){
        printf("\n  Lock SUCCESS !\n");
else {
    printf("\n  Lock Failed !\n");

Langage : c/c++

platform: Linux/Unix

Thanks in Advance.

Author:jayprakash,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60146126/createfile-and-deviceiocontrol-equivalent-for-volume-devices-in-unix-linux