Fix typo
[fio.git] / fio.c
1 /*
2  * fio - the flexible io tester
3  *
4  * Copyright (C) 2005 Jens Axboe <axboe@suse.de>
5  * Copyright (C) 2006-2012 Jens Axboe <axboe@kernel.dk>
6  *
7  * The license below covers all files distributed with fio unless otherwise
8  * noted in the file itself.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License version 2 as
12  *  published by the Free Software Foundation.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  */
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <string.h>
27 #include <limits.h>
28 #include <signal.h>
29 #include <time.h>
30 #include <locale.h>
31 #include <assert.h>
32 #include <time.h>
33 #include <sys/stat.h>
34 #include <sys/wait.h>
35 #include <sys/ipc.h>
36 #include <sys/shm.h>
37 #include <sys/mman.h>
38
39 #include "fio.h"
40 #include "hash.h"
41 #include "smalloc.h"
42 #include "verify.h"
43 #include "trim.h"
44 #include "diskutil.h"
45 #include "profile.h"
46 #include "lib/rand.h"
47 #include "memalign.h"
48 #include "server.h"
49
50 unsigned long page_mask;
51 unsigned long page_size;
52
53 static int endian_check(void)
54 {
55         union {
56                 uint8_t c[8];
57                 uint64_t v;
58         } u;
59         int le = 0, be = 0;
60
61         u.v = 0x12;
62         if (u.c[7] == 0x12)
63                 be = 1;
64         else if (u.c[0] == 0x12)
65                 le = 1;
66
67 #if defined(FIO_LITTLE_ENDIAN)
68         if (be)
69                 return 1;
70 #elif defined(FIO_BIG_ENDIAN)
71         if (le)
72                 return 1;
73 #else
74         return 1;
75 #endif
76
77         if (!le && !be)
78                 return 1;
79
80         return 0;
81 }
82
83 int main(int argc, char *argv[], char *envp[])
84 {
85         long ps;
86
87         if (endian_check()) {
88                 log_err("fio: endianness settings appear wrong.\n");
89                 log_err("fio: please report this to fio@vger.kernel.org\n");
90                 return 1;
91         }
92
93         arch_init(envp);
94
95         sinit();
96
97         /*
98          * We need locale for number printing, if it isn't set then just
99          * go with the US format.
100          */
101         if (!getenv("LC_NUMERIC"))
102                 setlocale(LC_NUMERIC, "en_US");
103
104         ps = sysconf(_SC_PAGESIZE);
105         if (ps < 0) {
106                 log_err("Failed to get page size\n");
107                 return 1;
108         }
109
110         page_size = ps;
111         page_mask = ps - 1;
112
113         fio_keywords_init();
114
115         if (parse_options(argc, argv))
116                 return 1;
117
118         if (nr_clients)
119                 return fio_handle_clients();
120         else
121                 return fio_backend();
122 }