#include <sys/ioctl.h>
#include <linux/fs.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(
  int argc,
  char **argv
) {
  int ret=1; /* Program's return value; 0=success. */
  int fd; /* File descriptor (handler) */
  long long size;

  if (argc != 2) {
    printf("Usage:\n ioctls <device>\n"
      "Print ioctl-size of a device in bytes.\n"
    );
  }
  else {
    fd = open(argv[1], O_RDONLY);
    if (fd >= 0) {
      if (ioctl(fd, BLKGETSIZE64, &size) != (-1)) {
        printf("%lld\n", size);
        ret=0;
      }
      close(fd);
    }
  }
  return ret;
}
