change fio_set_odirect() prototype not to use int fd
[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_RAND
20#define FIO_USE_GENERIC_INIT_RANDOM_STATE
21#define FIO_HAVE_GETTID
22#define FIO_HAVE_CHARDEV_SIZE
23#define FIO_HAVE_NATIVE_FALLOCATE
24
25#define OS_MAP_ANON MAP_ANON
26
27#define fio_swap16(x) OSSwapInt16(x)
28#define fio_swap32(x) OSSwapInt32(x)
29#define fio_swap64(x) OSSwapInt64(x)
30
31/*
32 * OSX has a pitifully small shared memory segment by default,
33 * so default to a lower number of max jobs supported
34 */
35#define FIO_MAX_JOBS 128
36
37typedef off_t off64_t;
38
39#ifndef CONFIG_CLOCKID_T
40typedef unsigned int clockid_t;
41#endif
42
43#define FIO_OS_DIRECTIO
44static inline int fio_set_odirect(struct fio_file *f)
45{
46 if (fcntl(f->fd, F_NOCACHE, 1) == -1)
47 return errno;
48 return 0;
49}
50
51static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
52{
53 uint32_t block_size;
54 uint64_t block_count;
55
56 if (ioctl(f->fd, DKIOCGETBLOCKCOUNT, &block_count) == -1)
57 return errno;
58 if (ioctl(f->fd, DKIOCGETBLOCKSIZE, &block_size) == -1)
59 return errno;
60
61 *bytes = block_size;
62 *bytes *= block_count;
63 return 0;
64}
65
66static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
67{
68 /*
69 * Could be a raw block device, this is better than just assuming
70 * we can't get the size at all.
71 */
72 if (!blockdev_size(f, bytes))
73 return 0;
74
75 *bytes = -1ULL;
76 return 0;
77}
78
79static inline int blockdev_invalidate_cache(struct fio_file *f)
80{
81 return ENOTSUP;
82}
83
84static inline unsigned long long os_phys_mem(void)
85{
86 int mib[2] = { CTL_HW, HW_PHYSMEM };
87 unsigned long long mem;
88 size_t len = sizeof(mem);
89
90 sysctl(mib, 2, &mem, &len, NULL, 0);
91 return mem;
92}
93
94static inline int gettid(void)
95{
96 return mach_thread_self();
97}
98
99/*
100 * For some reason, there's no header definition for fdatasync(), even
101 * if it exists.
102 */
103extern int fdatasync(int fd);
104
105static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
106{
107 fstore_t store = {F_ALLOCATEALL, F_PEOFPOSMODE, offset, len};
108 if (fcntl(f->fd, F_PREALLOCATE, &store) != -1) {
109 if (ftruncate(f->fd, len) == 0)
110 return true;
111 }
112
113 return false;
114}
115
116#endif