c55a7c315ca2efc2ab609f5d60019da0805f46b3
[fio.git] / os / os-freebsd.h
1 #ifndef FIO_OS_FREEBSD_H
2 #define FIO_OS_FREEBSD_H
3
4 #define FIO_OS  os_freebsd
5
6 #include <errno.h>
7 #include <sys/sysctl.h>
8 #include <sys/disk.h>
9 #include <sys/thr.h>
10 #include <sys/socket.h>
11
12 #include "../file.h"
13
14 #define FIO_HAVE_ODIRECT
15 #define FIO_USE_GENERIC_RAND
16 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
17 #define FIO_HAVE_CHARDEV_SIZE
18 #define FIO_HAVE_GETTID
19
20 #define OS_MAP_ANON             MAP_ANON
21
22 #define fio_swap16(x)   bswap16(x)
23 #define fio_swap32(x)   bswap32(x)
24 #define fio_swap64(x)   bswap64(x)
25
26 typedef off_t off64_t;
27
28 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
29 {
30         off_t size;
31
32         if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
33                 *bytes = size;
34                 return 0;
35         }
36
37         *bytes = 0;
38         return errno;
39 }
40
41 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
42 {
43         return blockdev_size(f, bytes);
44 }
45
46 static inline int blockdev_invalidate_cache(struct fio_file *f)
47 {
48         return EINVAL;
49 }
50
51 static inline unsigned long long os_phys_mem(void)
52 {
53         int mib[2] = { CTL_HW, HW_PHYSMEM };
54         unsigned long long mem;
55         size_t len = sizeof(mem);
56
57         sysctl(mib, 2, &mem, &len, NULL, 0);
58         return mem;
59 }
60
61 static inline int gettid(void)
62 {
63         long lwpid;
64
65         thr_self(&lwpid);
66         return (int) lwpid;
67 }
68
69 #ifdef MADV_FREE
70 #define FIO_MADV_FREE   MADV_FREE
71 #endif
72
73 #endif