Search notes:

libc: ioctl

The following example uses ioctl to determine the block size of /dev/sda.
#include <sys/ioctl.h>

#include <stdio.h>
#include <stdlib.h>     // exit()
#include <fcntl.h>      // open()
#include <linux/fs.h>   // BLKSSZGET

int main() {

   int fd = open("/dev/sda", O_RDWR);
   if (fd == -1) exit(1);

   int sectorSize;
   if (ioctl(fd, BLKSSZGET, &sectorSize)) exit(2);

   printf("Sector size: %d\n", sectorSize);
}
Github repository about-libc, path: /ioctl/main.c

See also

The Standard C Library

Index