Tizen 2.1 base
[external/device-mapper.git] / libdm / misc / dm-ioctl.h
1 /*
2  * Copyright (C) 2001 - 2003 Sistina Software (UK) Limited.
3  * Copyright (C) 2004 - 2009 Red Hat, Inc. All rights reserved.
4  *
5  * This file is released under the LGPL.
6  */
7
8 #ifndef _LINUX_DM_IOCTL_V4_H
9 #define _LINUX_DM_IOCTL_V4_H
10
11 #ifdef linux
12 #  include <linux/types.h>
13 #endif
14
15 #define DM_DIR "mapper"         /* Slashes not supported */
16 #define DM_CONTROL_NODE "control"
17 #define DM_MAX_TYPE_NAME 16
18 #define DM_NAME_LEN 128
19 #define DM_UUID_LEN 129
20
21 /*
22  * A traditional ioctl interface for the device mapper.
23  *
24  * Each device can have two tables associated with it, an
25  * 'active' table which is the one currently used by io passing
26  * through the device, and an 'inactive' one which is a table
27  * that is being prepared as a replacement for the 'active' one.
28  *
29  * DM_VERSION:
30  * Just get the version information for the ioctl interface.
31  *
32  * DM_REMOVE_ALL:
33  * Remove all dm devices, destroy all tables.  Only really used
34  * for debug.
35  *
36  * DM_LIST_DEVICES:
37  * Get a list of all the dm device names.
38  *
39  * DM_DEV_CREATE:
40  * Create a new device, neither the 'active' or 'inactive' table
41  * slots will be filled.  The device will be in suspended state
42  * after creation, however any io to the device will get errored
43  * since it will be out-of-bounds.
44  *
45  * DM_DEV_REMOVE:
46  * Remove a device, destroy any tables.
47  *
48  * DM_DEV_RENAME:
49  * Rename a device or set its uuid if none was previously supplied.
50  *
51  * DM_SUSPEND:
52  * This performs both suspend and resume, depending which flag is
53  * passed in.
54  * Suspend: This command will not return until all pending io to
55  * the device has completed.  Further io will be deferred until
56  * the device is resumed.
57  * Resume: It is no longer an error to issue this command on an
58  * unsuspended device.  If a table is present in the 'inactive'
59  * slot, it will be moved to the active slot, then the old table
60  * from the active slot will be _destroyed_.  Finally the device
61  * is resumed.
62  *
63  * DM_DEV_STATUS:
64  * Retrieves the status for the table in the 'active' slot.
65  *
66  * DM_DEV_WAIT:
67  * Wait for a significant event to occur to the device.  This
68  * could either be caused by an event triggered by one of the
69  * targets of the table in the 'active' slot, or a table change.
70  *
71  * DM_TABLE_LOAD:
72  * Load a table into the 'inactive' slot for the device.  The
73  * device does _not_ need to be suspended prior to this command.
74  *
75  * DM_TABLE_CLEAR:
76  * Destroy any table in the 'inactive' slot (ie. abort).
77  *
78  * DM_TABLE_DEPS:
79  * Return a set of device dependencies for the 'active' table.
80  *
81  * DM_TABLE_STATUS:
82  * Return the targets status for the 'active' table.
83  *
84  * DM_TARGET_MSG:
85  * Pass a message string to the target at a specific offset of a device.
86  *
87  * DM_DEV_SET_GEOMETRY:
88  * Set the geometry of a device by passing in a string in this format:
89  *
90  * "cylinders heads sectors_per_track start_sector"
91  *
92  * Beware that CHS geometry is nearly obsolete and only provided
93  * for compatibility with dm devices that can be booted by a PC
94  * BIOS.  See struct hd_geometry for range limits.  Also note that
95  * the geometry is erased if the device size changes.
96  */
97
98 /*
99  * All ioctl arguments consist of a single chunk of memory, with
100  * this structure at the start.  If a uuid is specified any
101  * lookup (eg. for a DM_INFO) will be done on that, *not* the
102  * name.
103  */
104 struct dm_ioctl {
105         /*
106          * The version number is made up of three parts:
107          * major - no backward or forward compatibility,
108          * minor - only backwards compatible,
109          * patch - both backwards and forwards compatible.
110          *
111          * All clients of the ioctl interface should fill in the
112          * version number of the interface that they were
113          * compiled with.
114          *
115          * All recognised ioctl commands (ie. those that don't
116          * return -ENOTTY) fill out this field, even if the
117          * command failed.
118          */
119         uint32_t version[3];    /* in/out */
120         uint32_t data_size;     /* total size of data passed in
121                                  * including this struct */
122
123         uint32_t data_start;    /* offset to start of data
124                                  * relative to start of this struct */
125
126         uint32_t target_count;  /* in/out */
127         int32_t open_count;     /* out */
128         uint32_t flags;         /* in/out */
129
130         /*
131          * event_nr holds either the event number (input and output) or the
132          * udev cookie value (input only).
133          * The DM_DEV_WAIT ioctl takes an event number as input.
134          * The DM_SUSPEND, DM_DEV_REMOVE and DM_DEV_RENAME ioctls
135          * use the field as a cookie to return in the DM_COOKIE
136          * variable with the uevents they issue.
137          * For output, the ioctls return the event number, not the cookie.
138          */
139         uint32_t event_nr;              /* in/out */
140         uint32_t padding;
141
142         uint64_t dev;           /* in/out */
143
144         char name[DM_NAME_LEN]; /* device name */
145         char uuid[DM_UUID_LEN]; /* unique identifier for
146                                  * the block device */
147         char data[7];           /* padding or data */
148 };
149
150 /*
151  * Used to specify tables.  These structures appear after the
152  * dm_ioctl.
153  */
154 struct dm_target_spec {
155         uint64_t sector_start;
156         uint64_t length;
157         int32_t status;         /* used when reading from kernel only */
158
159         /*
160          * Location of the next dm_target_spec.
161          * - When specifying targets on a DM_TABLE_LOAD command, this value is
162          *   the number of bytes from the start of the "current" dm_target_spec
163          *   to the start of the "next" dm_target_spec.
164          * - When retrieving targets on a DM_TABLE_STATUS command, this value
165          *   is the number of bytes from the start of the first dm_target_spec
166          *   (that follows the dm_ioctl struct) to the start of the "next"
167          *   dm_target_spec.
168          */
169         uint32_t next;
170
171         char target_type[DM_MAX_TYPE_NAME];
172
173         /*
174          * Parameter string starts immediately after this object.
175          * Be careful to add padding after string to ensure correct
176          * alignment of subsequent dm_target_spec.
177          */
178 };
179
180 /*
181  * Used to retrieve the target dependencies.
182  */
183 struct dm_target_deps {
184         uint32_t count; /* Array size */
185         uint32_t padding;       /* unused */
186         uint64_t dev[0];        /* out */
187 };
188
189 /*
190  * Used to get a list of all dm devices.
191  */
192 struct dm_name_list {
193         uint64_t dev;
194         uint32_t next;          /* offset to the next record from
195                                    the _start_ of this */
196         char name[0];
197 };
198
199 /*
200  * Used to retrieve the target versions
201  */
202 struct dm_target_versions {
203         uint32_t next;
204         uint32_t version[3];
205
206         char name[0];
207 };
208
209 /*
210  * Used to pass message to a target
211  */
212 struct dm_target_msg {
213         uint64_t sector;        /* Device sector */
214
215         char message[0];
216 };
217
218 /*
219  * If you change this make sure you make the corresponding change
220  * to dm-ioctl.c:lookup_ioctl()
221  */
222 enum {
223         /* Top level cmds */
224         DM_VERSION_CMD = 0,
225         DM_REMOVE_ALL_CMD,
226         DM_LIST_DEVICES_CMD,
227
228         /* device level cmds */
229         DM_DEV_CREATE_CMD,
230         DM_DEV_REMOVE_CMD,
231         DM_DEV_RENAME_CMD,
232         DM_DEV_SUSPEND_CMD,
233         DM_DEV_STATUS_CMD,
234         DM_DEV_WAIT_CMD,
235
236         /* Table level cmds */
237         DM_TABLE_LOAD_CMD,
238         DM_TABLE_CLEAR_CMD,
239         DM_TABLE_DEPS_CMD,
240         DM_TABLE_STATUS_CMD,
241
242         /* Added later */
243         DM_LIST_VERSIONS_CMD,
244         DM_TARGET_MSG_CMD,
245         DM_DEV_SET_GEOMETRY_CMD
246 };
247
248 #define DM_IOCTL 0xfd
249
250 #define DM_VERSION       _IOWR(DM_IOCTL, DM_VERSION_CMD, struct dm_ioctl)
251 #define DM_REMOVE_ALL    _IOWR(DM_IOCTL, DM_REMOVE_ALL_CMD, struct dm_ioctl)
252 #define DM_LIST_DEVICES  _IOWR(DM_IOCTL, DM_LIST_DEVICES_CMD, struct dm_ioctl)
253
254 #define DM_DEV_CREATE    _IOWR(DM_IOCTL, DM_DEV_CREATE_CMD, struct dm_ioctl)
255 #define DM_DEV_REMOVE    _IOWR(DM_IOCTL, DM_DEV_REMOVE_CMD, struct dm_ioctl)
256 #define DM_DEV_RENAME    _IOWR(DM_IOCTL, DM_DEV_RENAME_CMD, struct dm_ioctl)
257 #define DM_DEV_SUSPEND   _IOWR(DM_IOCTL, DM_DEV_SUSPEND_CMD, struct dm_ioctl)
258 #define DM_DEV_STATUS    _IOWR(DM_IOCTL, DM_DEV_STATUS_CMD, struct dm_ioctl)
259 #define DM_DEV_WAIT      _IOWR(DM_IOCTL, DM_DEV_WAIT_CMD, struct dm_ioctl)
260
261 #define DM_TABLE_LOAD    _IOWR(DM_IOCTL, DM_TABLE_LOAD_CMD, struct dm_ioctl)
262 #define DM_TABLE_CLEAR   _IOWR(DM_IOCTL, DM_TABLE_CLEAR_CMD, struct dm_ioctl)
263 #define DM_TABLE_DEPS    _IOWR(DM_IOCTL, DM_TABLE_DEPS_CMD, struct dm_ioctl)
264 #define DM_TABLE_STATUS  _IOWR(DM_IOCTL, DM_TABLE_STATUS_CMD, struct dm_ioctl)
265
266 #define DM_LIST_VERSIONS _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, struct dm_ioctl)
267
268 #define DM_TARGET_MSG    _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, struct dm_ioctl)
269 #define DM_DEV_SET_GEOMETRY     _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
270
271 #define DM_VERSION_MAJOR        4
272 #define DM_VERSION_MINOR        19
273 #define DM_VERSION_PATCHLEVEL   0
274 #define DM_VERSION_EXTRA        "-ioctl (2010-10-14)"
275
276 /* Status bits */
277 #define DM_READONLY_FLAG        (1 << 0) /* In/Out */
278 #define DM_SUSPEND_FLAG         (1 << 1) /* In/Out */
279 #define DM_PERSISTENT_DEV_FLAG  (1 << 3) /* In */
280
281 /*
282  * Flag passed into ioctl STATUS command to get table information
283  * rather than current status.
284  */
285 #define DM_STATUS_TABLE_FLAG    (1 << 4) /* In */
286
287 /*
288  * Flags that indicate whether a table is present in either of
289  * the two table slots that a device has.
290  */
291 #define DM_ACTIVE_PRESENT_FLAG   (1 << 5) /* Out */
292 #define DM_INACTIVE_PRESENT_FLAG (1 << 6) /* Out */
293
294 /*
295  * Indicates that the buffer passed in wasn't big enough for the
296  * results.
297  */
298 #define DM_BUFFER_FULL_FLAG     (1 << 8) /* Out */
299
300 /*
301  * This flag is now ignored.
302  */
303 #define DM_SKIP_BDGET_FLAG      (1 << 9) /* In */
304
305 /*
306  * Set this to avoid attempting to freeze any filesystem when suspending.
307  */
308 #define DM_SKIP_LOCKFS_FLAG     (1 << 10) /* In */
309
310 /*
311  * Set this to suspend without flushing queued ios.
312  */
313 #define DM_NOFLUSH_FLAG         (1 << 11) /* In */
314
315 /*
316  * If set, any table information returned will relate to the inactive
317  * table instead of the live one.  Always check DM_INACTIVE_PRESENT_FLAG
318  * is set before using the data returned.
319  */
320 #define DM_QUERY_INACTIVE_TABLE_FLAG    (1 << 12) /* In */
321
322 /*
323  * If set, a uevent was generated for which the caller may need to wait.
324  */
325 #define DM_UEVENT_GENERATED_FLAG        (1 << 13) /* Out */
326
327 /*
328  * If set, rename changes the uuid not the name.  Only permitted
329  * if no uuid was previously supplied: an existing uuid cannot be changed.
330  */
331 #define DM_UUID_FLAG                    (1 << 14) /* In */
332
333 #endif                          /* _LINUX_DM_IOCTL_H */