chiark / gitweb /
6549af364155f1486a0a1b73abcebac4e7186ef3
[elogind.git] / extras / multipath-tools / libdevmapper / libdevmapper.h
1 /*
2  * Copyright (C) 2001 Sistina Software (UK) Limited.
3  *
4  * This file is released under the LGPL.
5  */
6
7 #ifndef LIB_DEVICE_MAPPER_H
8 #define LIB_DEVICE_MAPPER_H
9
10 #include <inttypes.h>
11 #include <sys/types.h>
12
13 #ifdef linux
14 #  include <linux/types.h>
15 #endif
16
17 /*
18  * Since it is quite laborious to build the ioctl
19  * arguments for the device-mapper people are
20  * encouraged to use this library.
21  *
22  * You will need to build a struct dm_task for
23  * each ioctl command you want to execute.
24  */
25
26 typedef void (*dm_log_fn) (int level, const char *file, int line,
27                            const char *f, ...);
28
29 /*
30  * The library user may wish to register their own
31  * logging function, by default errors go to
32  * stderr.
33  */
34 void dm_log_init(dm_log_fn fn);
35 void dm_log_init_verbose(int level);
36
37 enum {
38         DM_DEVICE_CREATE,
39         DM_DEVICE_RELOAD,
40         DM_DEVICE_REMOVE,
41         DM_DEVICE_REMOVE_ALL,
42
43         DM_DEVICE_SUSPEND,
44         DM_DEVICE_RESUME,
45
46         DM_DEVICE_INFO,
47         DM_DEVICE_DEPS,
48         DM_DEVICE_RENAME,
49
50         DM_DEVICE_VERSION,
51
52         DM_DEVICE_STATUS,
53         DM_DEVICE_TABLE,
54         DM_DEVICE_WAITEVENT,
55
56         DM_DEVICE_LIST,
57
58         DM_DEVICE_CLEAR,
59
60         DM_DEVICE_MKNODES
61 };
62
63 struct dm_task;
64
65 struct dm_task *dm_task_create(int type);
66 void dm_task_destroy(struct dm_task *dmt);
67
68 int dm_task_set_name(struct dm_task *dmt, const char *name);
69 int dm_task_set_uuid(struct dm_task *dmt, const char *uuid);
70
71 /*
72  * Retrieve attributes after an info.
73  */
74 struct dm_info {
75         int exists;
76         int suspended;
77         int live_table;
78         int inactive_table;
79         int32_t open_count;
80         uint32_t event_nr;
81         uint32_t major;
82         uint32_t minor;         /* minor device number */
83         int read_only;          /* 0:read-write; 1:read-only */
84
85         int32_t target_count;
86 };
87
88 struct dm_deps {
89         uint32_t count;
90         uint32_t filler;
91         uint64_t device[0];
92 };
93
94 struct dm_names {
95         uint64_t dev;
96         uint32_t next;          /* Offset to next struct from start of this struct */
97         char name[0];
98 };
99
100 int dm_get_library_version(char *version, size_t size);
101 int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size);
102 int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);
103 const char *dm_task_get_name(struct dm_task *dmt);
104 const char *dm_task_get_uuid(struct dm_task *dmt);
105
106 struct dm_deps *dm_task_get_deps(struct dm_task *dmt);
107 struct dm_names *dm_task_get_names(struct dm_task *dmt);
108
109 int dm_task_set_ro(struct dm_task *dmt);
110 int dm_task_set_newname(struct dm_task *dmt, const char *newname);
111 int dm_task_set_minor(struct dm_task *dmt, int minor);
112 int dm_task_set_major(struct dm_task *dmt, int major);
113 int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr);
114
115 /*
116  * Use these to prepare for a create or reload.
117  */
118 int dm_task_add_target(struct dm_task *dmt,
119                        uint64_t start,
120                        uint64_t size, const char *ttype, const char *params);
121
122 /*
123  * Format major/minor numbers correctly for input to driver
124  */
125 int dm_format_dev(char *buf, int bufsize, uint32_t dev_major, uint32_t dev_minor);
126
127 /* Use this to retrive target information returned from a STATUS call */
128 void *dm_get_next_target(struct dm_task *dmt,
129                          void *next, uint64_t *start, uint64_t *length,
130                          char **target_type, char **params);
131
132 /*
133  * Call this to actually run the ioctl.
134  */
135 int dm_task_run(struct dm_task *dmt);
136
137 /*
138  * Configure the device-mapper directory
139  */
140 int dm_set_dev_dir(const char *dir);
141 const char *dm_dir(void);
142
143 /* Release library resources */
144 void dm_lib_release(void);
145 void dm_lib_exit(void);
146
147 #endif                          /* LIB_DEVICE_MAPPER_H */