t/zbd: fix wrong units in test case #37
[fio.git] / os / os-mac.h
CommitLineData
2afd826b
JA
1#ifndef FIO_OS_APPLE_H
2#define FIO_OS_APPLE_H
3
cca84643
JA
4#define FIO_OS os_mac
5
2afd826b 6#include <errno.h>
7e8ad197 7#include <fcntl.h>
c64646f0 8#include <sys/disk.h>
2afd826b 9#include <sys/sysctl.h>
9b836561
BC
10#include <sys/time.h>
11#include <unistd.h>
12#include <signal.h>
3dee087c 13#include <mach/mach_init.h>
ff245192
JA
14#include <machine/endian.h>
15#include <libkern/OSByteOrder.h>
2afd826b 16
e2e58886
JA
17#include "../file.h"
18
93bcfd20 19#define FIO_USE_GENERIC_INIT_RANDOM_STATE
e8d588e4 20#define FIO_HAVE_GETTID
b42ffd19 21#define FIO_HAVE_CHARDEV_SIZE
2c3e17be 22#define FIO_HAVE_NATIVE_FALLOCATE
2afd826b
JA
23
24#define OS_MAP_ANON MAP_ANON
25
ff245192
JA
26#define fio_swap16(x) OSSwapInt16(x)
27#define fio_swap32(x) OSSwapInt32(x)
28#define fio_swap64(x) OSSwapInt64(x)
29
25f8227d 30#ifndef CONFIG_CLOCKID_T
9b836561 31typedef unsigned int clockid_t;
25f8227d 32#endif
9b836561 33
7e8ad197 34#define FIO_OS_DIRECTIO
2905de74 35static inline int fio_set_odirect(struct fio_file *f)
7e8ad197 36{
2905de74 37 if (fcntl(f->fd, F_NOCACHE, 1) == -1)
7e8ad197
SN
38 return errno;
39 return 0;
40}
41
c64646f0
SN
42static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
43{
79d73100
JA
44 uint32_t block_size;
45 uint64_t block_count;
46
47 if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1)
c64646f0 48 return errno;
79d73100 49 if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1)
c64646f0 50 return errno;
79d73100
JA
51
52 *bytes = block_size;
53 *bytes *= block_count;
54 return 0;
c64646f0
SN
55}
56
b42ffd19
JA
57static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
58{
59 /*
60 * Could be a raw block device, this is better than just assuming
61 * we can't get the size at all.
62 */
63 if (!blockdev_size(f, bytes))
64 return 0;
65
66 *bytes = -1ULL;
67 return 0;
68}
69
9b836561 70static inline int blockdev_invalidate_cache(struct fio_file *f)
2afd826b 71{
22de5d77 72 return ENOTSUP;
2afd826b
JA
73}
74
75static inline unsigned long long os_phys_mem(void)
76{
77 int mib[2] = { CTL_HW, HW_PHYSMEM };
78 unsigned long long mem;
79 size_t len = sizeof(mem);
80
81 sysctl(mib, 2, &mem, &len, NULL, 0);
82 return mem;
83}
e8d588e4 84
de5ed0e4 85#ifndef CONFIG_HAVE_GETTID
e8d588e4
JA
86static inline int gettid(void)
87{
88 return mach_thread_self();
89}
de5ed0e4 90#endif
5351f564 91
2c3e17be
SW
92static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
93{
94 fstore_t store = {F_ALLOCATEALL, F_PEOFPOSMODE, offset, len};
95 if (fcntl(f->fd, F_PREALLOCATE, &store) != -1) {
96 if (ftruncate(f->fd, len) == 0)
97 return true;
98 }
99
100 return false;
101}
102
2afd826b 103#endif