246f40732e4729acc26fe72688a3cd8b5c58f8c7
[platform/upstream/cryptsetup.git] / src / cryptsetup.h
1 /*
2  * cryptsetup - setup cryptographic volumes for dm-crypt
3  *
4  * Copyright (C) 2004, Christophe Saout <christophe@saout.de>
5  * Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
6  * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef CRYPTSETUP_H
23 #define CRYPTSETUP_H
24
25 #define _LARGEFILE64_SOURCE
26 #define _FILE_OFFSET_BITS 64
27
28 #include <config.h>
29
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <stdio.h>
34 #include <stdint.h>
35 #include <errno.h>
36 #include <unistd.h>
37 #include <inttypes.h>
38 #include <limits.h>
39 #include <ctype.h>
40 #include <fcntl.h>
41 #include <popt.h>
42 #include <sys/stat.h>
43
44 #include "lib/nls.h"
45 #include "lib/utils_crypt.h"
46 #include "lib/utils_loop.h"
47 #include "lib/utils_fips.h"
48
49 #include "libcryptsetup.h"
50
51 #define CONST_CAST(x) (x)(uintptr_t)
52 #define DEFAULT_CIPHER(type)    (DEFAULT_##type##_CIPHER "-" DEFAULT_##type##_MODE)
53 #define SECTOR_SIZE 512
54 #define ROUND_SECTOR(x) (((x) + SECTOR_SIZE - 1) / SECTOR_SIZE)
55
56 extern int opt_debug;
57 extern int opt_verbose;
58 extern int opt_batch_mode;
59
60 /* Common tools */
61 void clogger(struct crypt_device *cd, int level, const char *file, int line,
62              const char *format, ...);
63 void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)));
64 void quiet_log(int level, const char *msg, void *usrptr);
65
66 int yesDialog(const char *msg, void *usrptr __attribute__((unused)));
67 void show_status(int errcode);
68 const char *uuid_or_device(const char *spec);
69 void usage(poptContext popt_context, int exitcode, const char *error, const char *more);
70 void dbg_version_and_cmd(int argc, const char **argv);
71 int translate_errno(int r);
72
73 extern volatile int quit;
74 void set_int_block(int block);
75 void set_int_handler(int block);
76 void check_signal(int *r);
77
78 int tools_get_key(const char *prompt,
79                   char **key, size_t *key_size,
80                   size_t keyfile_offset, size_t keyfile_size_max,
81                   const char *key_file,
82                   int timeout, int verify,
83                   struct crypt_device *cd);
84
85 /* Log */
86 #define log_dbg(x...) clogger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
87 #define log_std(x...) clogger(NULL, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
88 #define log_verbose(x...) clogger(NULL, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
89 #define log_err(x...) clogger(NULL, CRYPT_LOG_ERROR, __FILE__, __LINE__, x)
90
91 #endif /* CRYPTSETUP_H */