⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libdevmapper.h

📁 Linux Device Mapper Source Code
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. * * This file is part of the device-mapper userspace tools. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions * of the GNU Lesser General Public License v.2.1. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#ifndef LIB_DEVICE_MAPPER_H#define LIB_DEVICE_MAPPER_H#include <inttypes.h>#include <stdarg.h>#include <sys/types.h>#ifdef linux#  include <linux/types.h>#endif#include <limits.h>#include <string.h>#include <stdlib.h>#include <stdio.h>/***************************************************************** * The first section of this file provides direct access to the  * individual device-mapper ioctls. ****************************************************************//* * Since it is quite laborious to build the ioctl * arguments for the device-mapper people are * encouraged to use this library. * * You will need to build a struct dm_task for * each ioctl command you want to execute. */typedef void (*dm_log_fn) (int level, const char *file, int line,			   const char *f, ...)    __attribute__ ((format(printf, 4, 5)));/* * The library user may wish to register their own * logging function, by default errors go to stderr. * Use dm_log_init(NULL) to restore the default log fn. */void dm_log_init(dm_log_fn fn);void dm_log_init_verbose(int level);enum {	DM_DEVICE_CREATE,	DM_DEVICE_RELOAD,	DM_DEVICE_REMOVE,	DM_DEVICE_REMOVE_ALL,	DM_DEVICE_SUSPEND,	DM_DEVICE_RESUME,	DM_DEVICE_INFO,	DM_DEVICE_DEPS,	DM_DEVICE_RENAME,	DM_DEVICE_VERSION,	DM_DEVICE_STATUS,	DM_DEVICE_TABLE,	DM_DEVICE_WAITEVENT,	DM_DEVICE_LIST,	DM_DEVICE_CLEAR,	DM_DEVICE_MKNODES,	DM_DEVICE_LIST_VERSIONS,		DM_DEVICE_TARGET_MSG,	DM_DEVICE_SET_GEOMETRY};struct dm_task;struct dm_task *dm_task_create(int type);void dm_task_destroy(struct dm_task *dmt);int dm_task_set_name(struct dm_task *dmt, const char *name);int dm_task_set_uuid(struct dm_task *dmt, const char *uuid);/* * Retrieve attributes after an info. */struct dm_info {	int exists;	int suspended;	int live_table;	int inactive_table;	int32_t open_count;	uint32_t event_nr;	uint32_t major;	uint32_t minor;		/* minor device number */	int read_only;		/* 0:read-write; 1:read-only */	int32_t target_count;};struct dm_deps {	uint32_t count;	uint32_t filler;	uint64_t device[0];};struct dm_names {	uint64_t dev;	uint32_t next;		/* Offset to next struct from start of this struct */	char name[0];};struct dm_versions {	uint32_t next;		/* Offset to next struct from start of this struct */	uint32_t version[3];	char name[0];};int dm_get_library_version(char *version, size_t size);int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size);int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);const char *dm_task_get_name(const struct dm_task *dmt);const char *dm_task_get_uuid(const struct dm_task *dmt);struct dm_deps *dm_task_get_deps(struct dm_task *dmt);struct dm_names *dm_task_get_names(struct dm_task *dmt);struct dm_versions *dm_task_get_versions(struct dm_task *dmt);int dm_task_set_ro(struct dm_task *dmt);int dm_task_set_newname(struct dm_task *dmt, const char *newname);int dm_task_set_minor(struct dm_task *dmt, int minor);int dm_task_set_major(struct dm_task *dmt, int major);int dm_task_set_uid(struct dm_task *dmt, uid_t uid);int dm_task_set_gid(struct dm_task *dmt, gid_t gid);int dm_task_set_mode(struct dm_task *dmt, mode_t mode);int dm_task_set_event_nr(struct dm_task *dmt, uint32_t event_nr);int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads, const char *sectors, const char *start);int dm_task_set_message(struct dm_task *dmt, const char *message);int dm_task_set_sector(struct dm_task *dmt, uint64_t sector);int dm_task_no_flush(struct dm_task *dmt);int dm_task_no_open_count(struct dm_task *dmt);int dm_task_skip_lockfs(struct dm_task *dmt);int dm_task_suppress_identical_reload(struct dm_task *dmt);/* * Use these to prepare for a create or reload. */int dm_task_add_target(struct dm_task *dmt,		       uint64_t start,		       uint64_t size, const char *ttype, const char *params);/* * Format major/minor numbers correctly for input to driver */int dm_format_dev(char *buf, int bufsize, uint32_t dev_major, uint32_t dev_minor);/* Use this to retrive target information returned from a STATUS call */void *dm_get_next_target(struct dm_task *dmt,			 void *next, uint64_t *start, uint64_t *length,			 char **target_type, char **params);/* * Call this to actually run the ioctl. */int dm_task_run(struct dm_task *dmt);/* * Call this to make or remove the device nodes associated with previously * issued commands. */void dm_task_update_nodes(void);/* * Configure the device-mapper directory */int dm_set_dev_dir(const char *dir);const char *dm_dir(void);/* * Determine whether a major number belongs to device-mapper or not. */int dm_is_dm_major(uint32_t major);/* * Release library resources */void dm_lib_release(void);void dm_lib_exit(void) __attribute((destructor));/* * Use NULL for all devices. */int dm_mknodes(const char *name);int dm_driver_version(char *version, size_t size);/****************************************************** * Functions to build and manipulate trees of devices * ******************************************************/struct dm_tree;struct dm_tree_node;/* * Initialise an empty dependency tree. * * The tree consists of a root node together with one node for each mapped  * device which has child nodes for each device referenced in its table. * * Every node in the tree has one or more children and one or more parents. * * The root node is the parent/child of every node that doesn't have other  * parents/children. */struct dm_tree *dm_tree_create(void);void dm_tree_free(struct dm_tree *tree);/* * Add nodes to the tree for a given device and all the devices it uses. */int dm_tree_add_dev(struct dm_tree *tree, uint32_t major, uint32_t minor);/* * Add a new node to the tree if it doesn't already exist. */struct dm_tree_node *dm_tree_add_new_dev(struct dm_tree *tree,					 const char *name,					 const char *uuid,					 uint32_t major, uint32_t minor,					 int read_only,					 int clear_inactive,					 void *context);/* * Search for a node in the tree. * Set major and minor to 0 or uuid to NULL to get the root node. */struct dm_tree_node *dm_tree_find_node(struct dm_tree *tree,					  uint32_t major,					  uint32_t minor);struct dm_tree_node *dm_tree_find_node_by_uuid(struct dm_tree *tree,						  const char *uuid);/* * Use this to walk through all children of a given node. * Set handle to NULL in first call. * Returns NULL after the last child. * Set inverted to use inverted tree. */struct dm_tree_node *dm_tree_next_child(void **handle,					   struct dm_tree_node *parent,					   uint32_t inverted);/* * Get properties of a node. */const char *dm_tree_node_get_name(struct dm_tree_node *node);const char *dm_tree_node_get_uuid(struct dm_tree_node *node);const struct dm_info *dm_tree_node_get_info(struct dm_tree_node *node);void *dm_tree_node_get_context(struct dm_tree_node *node);/* * Returns the number of children of the given node (excluding the root node). * Set inverted for the number of parents. */int dm_tree_node_num_children(struct dm_tree_node *node, uint32_t inverted);/* * Deactivate a device plus all dependencies. * Ignores devices that don't have a uuid starting with uuid_prefix. */int dm_tree_deactivate_children(struct dm_tree_node *dnode,				   const char *uuid_prefix,				   size_t uuid_prefix_len);/* * Preload/create a device plus all dependencies. * Ignores devices that don't have a uuid starting with uuid_prefix. */int dm_tree_preload_children(struct dm_tree_node *dnode,			     const char *uuid_prefix,			     size_t uuid_prefix_len);/* * Resume a device plus all dependencies. * Ignores devices that don't have a uuid starting with uuid_prefix. */int dm_tree_activate_children(struct dm_tree_node *dnode,			      const char *uuid_prefix,			      size_t uuid_prefix_len);/* * Suspend a device plus all dependencies. * Ignores devices that don't have a uuid starting with uuid_prefix. */int dm_tree_suspend_children(struct dm_tree_node *dnode,				   const char *uuid_prefix,				   size_t uuid_prefix_len);/* * Skip the filesystem sync when suspending. * Does nothing with other functions. * Use this when no snapshots are involved. */ void dm_tree_skip_lockfs(struct dm_tree_node *dnode);/* * Set the 'noflush' flag when suspending devices. * If the kernel supports it, instead of erroring outstanding I/O that * cannot be completed, the I/O is queued and resubmitted when the * device is resumed.  This affects multipath devices when all paths * have failed and queue_if_no_path is set, and mirror devices when * block_on_error is set and the mirror log has failed. */void dm_tree_use_no_flush_suspend(struct dm_tree_node *dnode);/* * Is the uuid prefix present in the tree? * Only returns 0 if every node was checked successfully. * Returns 1 if the tree walk has to be aborted. */int dm_tree_children_use_uuid(struct dm_tree_node *dnode,				 const char *uuid_prefix,				 size_t uuid_prefix_len);/* * Construct tables for new nodes before activating them. */int dm_tree_node_add_snapshot_origin_target(struct dm_tree_node *dnode,					       uint64_t size,					       const char *origin_uuid);int dm_tree_node_add_snapshot_target(struct dm_tree_node *node,					uint64_t size,					const char *origin_uuid,					const char *cow_uuid,					int persistent,					uint32_t chunk_size);int dm_tree_node_add_error_target(struct dm_tree_node *node,				     uint64_t size);int dm_tree_node_add_zero_target(struct dm_tree_node *node,				    uint64_t size);int dm_tree_node_add_linear_target(struct dm_tree_node *node,				      uint64_t size);int dm_tree_node_add_striped_target(struct dm_tree_node *node,				       uint64_t size,				       uint32_t stripe_size);int dm_tree_node_add_mirror_target(struct dm_tree_node *node,				      uint64_t size); /* Mirror log flags */#define DM_NOSYNC		0x00000001	/* Known already in sync */#define DM_FORCESYNC		0x00000002	/* Force resync */#define DM_BLOCK_ON_ERROR	0x00000004	/* On error, suspend I/O */#define DM_CORELOG		0x00000008	/* In-memory log */int dm_tree_node_add_mirror_target_log(struct dm_tree_node *node,					  uint32_t region_size,					  unsigned clustered,					  const char *log_uuid,					  unsigned area_count,					  uint32_t flags);int dm_tree_node_add_target_area(struct dm_tree_node *node,				    const char *dev_name,				    const char *dlid,				    uint64_t offset);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -