Require device device-mapper to build and do not use backend wrapper for dm calls.
[platform/upstream/cryptsetup.git] / lib / internal.h
1 #ifndef INTERNAL_H
2 #define INTERNAL_H
3
4 #ifdef HAVE_CONFIG_H
5 #       include "config.h"
6 #endif
7
8 #include <stdint.h>
9 #include <stdarg.h>
10 #include <unistd.h>
11
12 #define SECTOR_SHIFT            9
13 #define SECTOR_SIZE             (1 << SECTOR_SHIFT)
14 #define DEFAULT_ALIGNMENT       4096
15
16 /* private struct crypt_options flags */
17
18 #define CRYPT_FLAG_FREE_DEVICE  (1 << 24)
19 #define CRYPT_FLAG_FREE_CIPHER  (1 << 25)
20
21 #define CRYPT_FLAG_PRIVATE_MASK ((unsigned int)-1 << 24)
22
23 struct hash_type {
24         char            *name;
25         void            *private;
26         int             (*fn)(void *data, int size, char *key,
27                               int sizep, const char *passphrase);
28 };
29
30 struct hash_backend {
31         const char              *name;
32         struct hash_type *      (*get_hashes)(void);
33         void                    (*free_hashes)(struct hash_type *hashes);
34 };
35
36 struct crypt_device;
37
38 void set_error_va(const char *fmt, va_list va);
39 void set_error(const char *fmt, ...);
40 const char *get_error(void);
41 void *safe_alloc(size_t size);
42 void safe_free(void *data);
43 void *safe_realloc(void *data, size_t size);
44 char *safe_strdup(const char *s);
45
46 struct hash_backend *get_hash_backend(const char *name);
47 void put_hash_backend(struct hash_backend *backend);
48 int hash(const char *backend_name, const char *hash_name,
49          char *result, size_t size,
50          const char *passphrase, size_t sizep);
51
52 void hexprint(char *d, int n);
53
54 /* Device mapper backend */
55 const char *dm_get_dir(void);
56 int dm_init(struct crypt_device *context, int check_kernel);
57 void dm_exit(void);
58 int dm_remove_device(const char *name, int force, uint64_t size);
59 int dm_status_device(const char *name);
60 int dm_query_device(const char *name,
61                     char **device,
62                     uint64_t *size,
63                     uint64_t *skip,
64                     uint64_t *offset,
65                     char **cipher,
66                     int *key_size,
67                     char **key,
68                     int *read_only);
69 int dm_create_device(const char *name, const char *device, const char *cipher, const char *uuid,
70                      uint64_t size, uint64_t skip, uint64_t offset,
71                      size_t key_size, const char *key,
72                      int read_only, int reload);
73
74 int sector_size_for_device(const char *device);
75 ssize_t write_blockwise(int fd, const void *buf, size_t count);
76 ssize_t read_blockwise(int fd, void *_buf, size_t count);
77 ssize_t write_lseek_blockwise(int fd, const char *buf, size_t count, off_t offset);
78
79
80 int get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
81             const char *key_file, int passphrase_fd, int timeout, int how2verify);
82
83 #endif /* INTERNAL_H */