1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2004 Silicon Graphics, Inc.
8 * Test program that uses the same interfaces as mkfs.xfs for
9 * Linux, dumps out just the device size values from a driver.
16 #include <sys/ioctl.h>
17 #include <sys/mount.h>
20 # define BLKGETSIZE64 _IOR(0x12,114,size_t)
23 int main(int argc, char **argv)
30 fputs("insufficient arguments\n", stderr);
33 fd = open(argv[1], O_RDONLY);
39 error = ioctl(fd, BLKGETSIZE64, &size);
41 /* BLKGETSIZE64 returns size in bytes not 512-byte blocks */
42 sz = (long long)(size >> 9);
43 printf("%lld 512 byte blocks (BLKGETSIZE64)\n", sz);
45 /* If BLKGETSIZE64 fails, try BLKGETSIZE */
46 unsigned long tmpsize;
48 error = ioctl(fd, BLKGETSIZE, &tmpsize);
50 fprintf(stderr, "can't determine device size");
53 sz = (long long)tmpsize;
54 printf("%lld 512 byte blocks (BLKGETSIZE)\n", sz);