dm-ioctl.h 11 KB

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