Add os_trim() support for DragonFlyBSD
[fio.git] / os / os-dragonfly.h
1 #ifndef FIO_OS_DRAGONFLY_H
2 #define FIO_OS_DRAGONFLY_H
3
4 #define FIO_OS  os_dragonfly
5
6 #include <errno.h>
7 #include <unistd.h>
8 #include <sys/param.h>
9 #include <sys/sysctl.h>
10 #include <sys/statvfs.h>
11 #include <sys/diskslice.h>
12 #include <sys/ioctl_compat.h>
13
14 #include "../file.h"
15
16 #define FIO_HAVE_ODIRECT
17 #define FIO_USE_GENERIC_RAND
18 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
19 #define FIO_HAVE_FS_STAT
20 #define FIO_HAVE_TRIM
21 #define FIO_HAVE_CHARDEV_SIZE
22 #define FIO_HAVE_GETTID
23
24 #undef  FIO_HAVE_CPU_AFFINITY   /* XXX notyet */
25
26 #define OS_MAP_ANON             MAP_ANON
27
28 #ifndef PTHREAD_STACK_MIN
29 #define PTHREAD_STACK_MIN 4096
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         struct partinfo pi;
41
42         if (!ioctl(f->fd, DIOCGPART, &pi)) {
43                 *bytes = (unsigned long long) pi.media_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         uint64_t 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         return (int) lwp_gettid();
74 }
75
76 static inline unsigned long long get_fs_free_size(const char *path)
77 {
78         unsigned long long ret;
79         struct statvfs s;
80
81         if (statvfs(path, &s) < 0)
82                 return -1ULL;
83
84         ret = s.f_frsize;
85         ret *= (unsigned long long) s.f_bfree;
86         return ret;
87 }
88
89 static inline int os_trim(int fd, unsigned long long start,
90                           unsigned long long len)
91 {
92         off_t range[2];
93
94         range[0] = start;
95         range[1] = len;
96
97         if (!ioctl(fd, IOCTLTRIM, range))
98                 return 0;
99
100         return errno;
101 }
102
103 #ifdef MADV_FREE
104 #define FIO_MADV_FREE   MADV_FREE
105 #endif
106
107 #endif