Add missing os/windows/posix.c file.
[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/endian.h>
11 #include <sys/socket.h>
12
13 #include "../file.h"
14
15 #define FIO_HAVE_POSIXAIO
16 #define FIO_HAVE_ODIRECT
17 #define FIO_HAVE_STRSEP
18 #define FIO_USE_GENERIC_RAND
19 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
20 #define FIO_HAVE_CHARDEV_SIZE
21 #define FIO_HAVE_GETTID
22 #define FIO_HAVE_CLOCK_MONOTONIC
23
24 #define OS_MAP_ANON             MAP_ANON
25
26 #if BYTE_ORDER == LITTLE_ENDIAN
27 #define FIO_LITTLE_ENDIAN
28 #else
29 #define FIO_BIG_ENDIAN
30 #endif
31
32 #define fio_swap16(x)   bswap16(x)
33 #define fio_swap32(x)   bswap32(x)
34 #define fio_swap64(x)   bswap64(x)
35
36 typedef off_t off64_t;
37
38 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
39 {
40         off_t size;
41
42         if (!ioctl(f->fd, DIOCGMEDIASIZE, &size)) {
43                 *bytes = size;
44                 return 0;
45         }
46
47         *bytes = 0;
48         return errno;
49 }
50
51 static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
52 {
53         return blockdev_size(f, bytes);
54 }
55
56 static inline int blockdev_invalidate_cache(struct fio_file *f)
57 {
58         return EINVAL;
59 }
60
61 static inline unsigned long long os_phys_mem(void)
62 {
63         int mib[2] = { CTL_HW, HW_PHYSMEM };
64         unsigned long long mem;
65         size_t len = sizeof(mem);
66
67         sysctl(mib, 2, &mem, &len, NULL, 0);
68         return mem;
69 }
70
71 static inline int gettid(void)
72 {
73         long lwpid;
74
75         thr_self(&lwpid);
76         return (int) lwpid;
77 }
78
79 #ifdef MADV_FREE
80 #define FIO_MADV_FREE   MADV_FREE
81 #endif
82
83 #endif