Add real blockdev_size() for FreeBSD
[fio.git] / os / os-freebsd.h
1 #ifndef FIO_OS_FREEBSD_H
2 #define FIO_OS_FREEBSD_H
3
4 #include <errno.h>
5 #include <sys/sysctl.h>
6 #include <sys/disk.h>
7
8 #define FIO_HAVE_POSIXAIO
9 #define FIO_HAVE_ODIRECT
10 #define FIO_USE_GENERIC_RAND
11
12 #define OS_MAP_ANON             MAP_ANON
13
14 typedef off_t off64_t;
15
16 static inline int blockdev_size(int fd, unsigned long long *bytes)
17 {
18         off_t size;
19
20         if (!ioctl(fd, DIOCGMEDIASIZE, &size)) {
21                 *bytes = size;
22                 return 0;
23         }
24
25         return errno;
26 }
27
28 static inline int blockdev_invalidate_cache(int fd)
29 {
30         return EINVAL;
31 }
32
33 static inline unsigned long long os_phys_mem(void)
34 {
35         int mib[2] = { CTL_HW, HW_PHYSMEM };
36         unsigned long long mem;
37         size_t len = sizeof(mem);
38
39         sysctl(mib, 2, &mem, &len, NULL, 0);
40         return mem;
41 }
42
43 #ifdef MADV_FREE
44 #define FIO_MADV_FREE   MADV_FREE
45 #endif
46
47 #endif