xfs: skip tests that rely on allocation behaviors of the data device
[xfstests-dev.git] / src / getdevicesize.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2004 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 /*
8  * Test program that uses the same interfaces as mkfs.xfs for
9  * Linux, dumps out just the device size values from a driver.
10  */
11
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <stdint.h>
16 #include <sys/ioctl.h>
17 #include <sys/mount.h>
18
19 #ifndef BLKGETSIZE64
20 # define BLKGETSIZE64   _IOR(0x12,114,size_t)
21 #endif
22
23 int main(int argc, char **argv)
24 {
25         uint64_t        size;
26         long long       sz = -1;
27         int             error, fd;
28
29         if (argc != 2) {
30                 fputs("insufficient arguments\n", stderr);
31                 return 1;
32         }
33         fd = open(argv[1], O_RDONLY);
34         if (!fd) {
35                 perror(argv[1]);
36                 return 1;
37         }
38
39         error = ioctl(fd, BLKGETSIZE64, &size);
40         if (error >= 0) {
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);
44         } else {
45                 /* If BLKGETSIZE64 fails, try BLKGETSIZE */
46                 unsigned long tmpsize;
47
48                 error = ioctl(fd, BLKGETSIZE, &tmpsize);
49                 if (error < 0) {
50                         fprintf(stderr, "can't determine device size");
51                         return 1;
52                 }
53                 sz = (long long)tmpsize;
54                 printf("%lld 512 byte blocks (BLKGETSIZE)\n", sz);
55         }
56         return 0;
57 }