t/zbd: fix wrong units in test case #37
[fio.git] / os / os-mac.h
... / ...
CommitLineData
1#ifndef FIO_OS_APPLE_H
2#define FIO_OS_APPLE_H
3
4#define FIO_OS os_mac
5
6#include <errno.h>
7#include <fcntl.h>
8#include <sys/disk.h>
9#include <sys/sysctl.h>
10#include <sys/time.h>
11#include <unistd.h>
12#include <signal.h>
13#include <mach/mach_init.h>
14#include <machine/endian.h>
15#include <libkern/OSByteOrder.h>
16
17#include "../file.h"
18
19#define FIO_USE_GENERIC_INIT_RANDOM_STATE
20#define FIO_HAVE_GETTID
21#define FIO_HAVE_CHARDEV_SIZE
22#define FIO_HAVE_NATIVE_FALLOCATE
23
24#define OS_MAP_ANON MAP_ANON
25
26#define fio_swap16(x) OSSwapInt16(x)
27#define fio_swap32(x) OSSwapInt32(x)
28#define fio_swap64(x) OSSwapInt64(x)
29
30#ifndef CONFIG_CLOCKID_T
31typedef unsigned int clockid_t;
32#endif
33
34#define FIO_OS_DIRECTIO
35static inline int fio_set_odirect(struct fio_file *f)
36{
37 if (fcntl(f->fd, F_NOCACHE, 1) == -1)
38 return errno;
39 return 0;
40}
41
42static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
43{
44 uint32_t block_size;
45 uint64_t block_count;
46
47 if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1)
48 return errno;
49 if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1)
50 return errno;
51
52 *bytes = block_size;
53 *bytes *= block_count;
54 return 0;
55}
56
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
70static inline int blockdev_invalidate_cache(struct fio_file *f)
71{
72 return ENOTSUP;
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}
84
85#ifndef CONFIG_HAVE_GETTID
86static inline int gettid(void)
87{
88 return mach_thread_self();
89}
90#endif
91
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
103#endif