# include/block/copy.h File Reference

Interface for block copy between block devices. More...

`#include <workqueue.h>`
`#include <block/device.h>`

Include dependency graph for copy.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures
struct | block_copy_request
## Defines
#define | BLOCK_COPY_NOMEM 1
| Error code reported if necessary memory could not be allocated.
#define | BLOCK_COPY_BLOCK_SIZE_MISMATCH 2
| Error code reported if the block size of the devices do not match.
## Functions
struct block_copy_request * | block_copy_alloc (uint32_t nr_blocks, uint32_t block_size, void *data)
| Allocate a block copy request and its buffers.
void | block_copy_free (struct block_copy_request *request)
| Free block copy request.
int | block_copy_set_source (struct block_copy_request *req, struct block_device *dev, block_addr_t lba)
| Set source device and blocks for the block copy.
int | block_copy_set_dest (struct block_copy_request *req, struct block_device *dev, block_addr_t lba)
| Set target device and blocks for the block copy.
void | block_copy_set_completion_callback (struct block_copy_request *req, void(*callback)(struct block_copy_request *, uint32_t, void *))
| Set completion callback.
void | block_copy_set_progress_callback (struct block_copy_request *req, void(*callback)(struct block_copy_request *, uint32_t, void *))
| Set progress callback.
void | block_copy_submit (struct block_copy_request *req)
| Submit a block copy request.

## Detailed Description

Interface for block copy between block devices.

This file contains the interface used to copy a chunk of blocks from one block device to another.

- Compiler: IAR EWAVR32 and GNU GCC for AVR32
- Supported devices: All devices
- AppNote:

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file copy.h.

## Define Documentation

#define BLOCK_COPY_BLOCK_SIZE_MISMATCH 2

Error code reported if the block size of the devices do not match.

Definition at line 54 of file copy.h.

Referenced by block_copy_set_dest(), and block_copy_set_source().

#define BLOCK_COPY_NOMEM 1

Error code reported if necessary memory could not be allocated.

Definition at line 52 of file copy.h.

Referenced by block_copy_set_dest(), and block_copy_set_source().

## Function Documentation

struct block_copy_request* block_copy_alloc | ( | uint32_t | nr_blocks,
|  | uint32_t | block_size,
|  | void * | data |
| ) |  |  | `[read]`

Allocate a block copy request and its buffers.

This function will allocate a block copy request with as many buffers as necessary, up to the maximum available memory. If it is not able to allocate the minimum memory needed, or the block size given is not supported, NULL is returned.

Parameters:

  | nr_blocks | The number of blocks to copy
  | block_size | The size of each block in bytes
  | data | Context data passed to callbacks

Returns:
  The block copy request descriptor

Definition at line 201 of file copy.c.

References assert, block_copy_request::block_size, block_copy_request::blocks_allocated, block_copy_request::blocks_pr_buf, block_copy_request::buffer_list, block_copy_request::data, block_copy_request::length, memset(), buffer::node, slist_init(), and slist_insert_tail().

Here is the call graph for this function:

void block_copy_free | ( | struct block_copy_request * | request | ) |

Free block copy request.

This function will free all memory allocated to the block copy request, including all allocated buffers and requests.

Parameters:

  | request | Block copy request descriptor

Definition at line 273 of file copy.c.

References block_free_request(), block_copy_request::buffer_list, buffer::node, block_copy_request::read_req, slist_is_empty(), slist_pop_head, block_copy_request::source, block_copy_request::target, and block_copy_request::write_req.

Here is the call graph for this function:

void block_copy_set_completion_callback | ( | struct block_copy_request * | req,
|  | void(*)(struct block_copy_request *, uint32_t, void *) | callback |
| ) |  |  |

Set completion callback.

This function will set the callback called when the block copy request completes. The callback will also be called if the block copy fails for some reason; an error code can then be found in the status field.

Parameters:

  | req | Block copy request descriptor
  | callback | Completion callback

Definition at line 371 of file copy.c.

References assert, and block_copy_request::completion_callback.

int block_copy_set_dest | ( | struct block_copy_request * | req,
|  | struct block_device * | dev,
|  | block_addr_t | lba |
| ) |  |  |

Set target device and blocks for the block copy.

This function will set the target device and the address of the first block to copy to in the block copy request descriptor.

Parameters:

  | req | Block copy request descriptor
  | dev | Target device
  | lba | Address of first target block

Returns:
  0 on success, negative error code on failure

Definition at line 338 of file copy.c.

References assert, block_alloc_request(), BLOCK_COPY_BLOCK_SIZE_MISMATCH, BLOCK_COPY_NOMEM, block_device::block_size, block_copy_request::block_size, block_request::context, block_request::req_done, block_copy_request::target, block_copy_request::target_start, and block_copy_request::write_req.

Here is the call graph for this function:

void block_copy_set_progress_callback | ( | struct block_copy_request * | req,
|  | void(*)(struct block_copy_request *, uint32_t, void *) | callback |
| ) |  |  |

Set progress callback.

This function will set the callback called as the block copy request progresses. The callback will be called after each successful write operation, except for the last write in the request.

Parameters:

  | req | Block copy request descriptor
  | callback | Progress callback

Definition at line 390 of file copy.c.

References assert, and block_copy_request::progress_callback.

int block_copy_set_source | ( | struct block_copy_request * | req,
|  | struct block_device * | dev,
|  | block_addr_t | lba |
| ) |  |  |

Set source device and blocks for the block copy.

This function will set the source device and the address of the first block to copy from the source in the block copy request descriptor.

Parameters:

  | req | Block copy request descriptor
  | dev | Source device
  | lba | Address of first source block

Returns:
  0 on success, negative error code on failure

Definition at line 304 of file copy.c.

References assert, block_alloc_request(), BLOCK_COPY_BLOCK_SIZE_MISMATCH, BLOCK_COPY_NOMEM, block_device::block_size, block_copy_request::block_size, block_request::context, block_copy_request::read_req, block_request::req_done, block_copy_request::source, and block_copy_request::source_start.

Here is the call graph for this function:

void block_copy_submit | ( | struct block_copy_request * | req | ) |

Submit a block copy request.

This function will submit a block copy request and start the actual copying. When the operation has completed the completion callback set by block_copy_set_completion_callback() is executed.

Parameters:

  | req | Block copy request descriptor

Definition at line 408 of file copy.c.

References assert, block_copy_request::read_req, block_copy_request::source, block_copy_request::target, block_copy_request::total_blocks_copied, and block_copy_request::write_req.