1 /* 2 * Copyright (c) 2011 Alex Hornung <alex@alexhornung.com>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in 13 * the documentation and/or other materials provided with the 14 * distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 20 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 /* Make dm_task opaque */ 31 struct dm_task; 32 33 struct dm_info { 34 int exists; 35 int suspended; 36 int live_table; 37 int inactive_table; 38 int read_only; 39 int32_t open_count; 40 int32_t target_count; 41 uint32_t event_nr; 42 uint32_t major; 43 uint32_t minor; 44 }; 45 46 struct dm_names { 47 const char *name; 48 uint64_t dev; 49 uint32_t next; 50 }; 51 52 struct dm_deps { 53 uint32_t count; 54 uint64_t deps[1]; 55 }; 56 57 struct dm_versions { 58 const char *name; 59 uint32_t version[3]; 60 uint32_t next; 61 }; 62 63 /* XXX: dm_task_set_geometry */ 64 65 enum { 66 DM_DEVICE_REMOVE, 67 DM_DEVICE_REMOVE_ALL, 68 DM_DEVICE_CREATE, 69 DM_DEVICE_RELOAD, 70 DM_DEVICE_RESUME, 71 DM_DEVICE_SUSPEND, 72 DM_DEVICE_CLEAR, 73 DM_DEVICE_LIST_VERSIONS, 74 DM_DEVICE_STATUS, 75 DM_DEVICE_TABLE, 76 DM_DEVICE_INFO, 77 DM_DEVICE_DEPS, 78 DM_DEVICE_VERSION, 79 DM_DEVICE_TARGET_MSG, 80 DM_DEVICE_RENAME, 81 DM_DEVICE_LIST 82 }; 83 84 /* int level, const char *file, int line, const char *fmt, ... */ 85 typedef void (*dm_error_func_t)(int, const char *, int, const char *, ...); 86 87 struct dm_task *dm_task_create(int task_type); 88 void dm_task_destroy(struct dm_task *dmt); 89 int dm_task_run(struct dm_task *dmt); 90 int dm_task_set_name(struct dm_task *dmt, const char *name); 91 const char *dm_task_get_name(struct dm_task *dmt); 92 int dm_task_set_newname(struct dm_task *dmt, const char *newname); 93 int dm_task_set_major(struct dm_task *dmt, int major); 94 int dm_task_set_minor(struct dm_task *dmt, int minor); 95 int dm_task_get_minor(struct dm_task *dmt); 96 int dm_task_set_uuid(struct dm_task *dmt, const char *uuid); 97 const char *dm_task_get_uuid(struct dm_task *dmt); 98 int dm_task_add_target(struct dm_task *dmt, uint64_t start, size_t size, 99 const char *target, const char *params); 100 int dm_task_set_sector(struct dm_task *dmt, uint64_t sector); 101 int dm_task_set_message(struct dm_task *dmt, const char *msg); 102 int dm_task_set_ro(struct dm_task *dmt); 103 int dm_task_no_open_count(struct dm_task *dmt); 104 int dm_task_query_inactive_table(struct dm_task *dmt); 105 int dm_task_set_read_ahead(struct dm_task *dmt, uint32_t read_ahead); 106 int dm_task_get_read_ahead(struct dm_task *dmt, uint32_t *read_ahead); 107 int dm_task_secure_data(struct dm_task *dmt); 108 int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi); 109 int dm_task_get_driver_version(struct dm_task *dmt, char *ver, size_t ver_sz); 110 struct dm_deps *dm_task_get_deps(struct dm_task *dmt); 111 struct dm_versions *dm_task_get_versions(struct dm_task *dmt); 112 struct dm_names *dm_task_get_names(struct dm_task *dmt); 113 int dm_task_update_nodes(void); 114 void *dm_get_next_target(struct dm_task *dmt, void *cur, uint64_t *startp, 115 uint64_t *lengthp, char **target_type, char **params); 116 uint32_t dm_get_major(void); 117 int dm_is_dm_major(uint32_t major); 118 const char *dm_dir(void); 119 void dm_udev_set_sync_support(int sync_udev); 120 int dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie, 121 uint16_t udev_flags); 122 int dm_udev_wait(uint32_t cookie); 123 void dm_lib_release(void); 124 int dm_log_init(dm_error_func_t fn); 125 int dm_log_init_verbose(int verbose); 126 int dm_task_set_uid(struct dm_task *dmt, uid_t uid); 127 int dm_task_set_gid(struct dm_task *dmt, gid_t gid); 128 int dm_task_set_mode(struct dm_task *dmt, mode_t mode); 129 int dm_task_no_flush(struct dm_task *dmt); 130 int dm_task_skip_lockfs(struct dm_task *dmt); 131 int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, 132 const char *heads, const char *sectors, const char *start); 133 134 135 136 137 /*****************************************************************************/ 138 /********************** DragonFly-specific extensions ************************/ 139 /*****************************************************************************/ 140 void *dm_get_next_version(struct dm_task *dmt, void *cur, 141 const char **target_type, uint32_t *target_ver); 142 void *dm_get_next_dep(struct dm_task *dmt, void *cur, uint64_t *dep); 143 void *dm_get_next_name(struct dm_task *dmt, void *cur, const char **name, 144 uint64_t *dev); 145 146