src/buffer_util.c File Reference

Implementation of utility function used by bless_buffer_t. More...

#include <sys/types.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "buffer.h"
#include "buffer_util.h"
#include "buffer_internal.h"
#include "buffer_action.h"
#include "segcol.h"
#include "segment.h"
#include "data_object.h"
#include "data_object_memory.h"
#include "data_object_file.h"
#include "util.h"
#include "debug.h"
#include "type_limits.h"
Include dependency graph for buffer_util.c:

Go to the source code of this file.

Functions

int read_data_object (data_object_t *dobj, off_t offset, void *mem, off_t length)
 Reads data from a data object to memory.
int write_data_object (data_object_t *dobj, off_t offset, off_t length, int fd, off_t file_offset)
 Writes data from a data object to a file.
int write_data_object_safe (data_object_t *dobj, off_t offset, off_t length, int fd, off_t file_offset)
 Writes data from a data object to a file in a safe way.
static int get_data_from_iter (segcol_iter_t *iter, segment_t **segment, off_t *mapping, off_t *read_start, off_t *read_length, off_t offset, off_t length)
 Gets from an iterator the read limits.
int segcol_foreach (segcol_t *segcol, off_t offset, off_t length, segcol_foreach_func *func, void *user_data)
 Calls a function for each segment in the specified range of a segcol_t.
static int read_segment_func (segcol_t *segcol, segment_t *seg, off_t mapping, off_t read_start, off_t read_length, void *user_data)
 A segcol_foreach_func that reads data from a segment_t into memory.
int segcol_store_in_memory (segcol_t *segcol, off_t offset, off_t length)
 Stores a range from a segcol_t in memory data objects.
static int store_segment_func (segcol_t *segcol, segment_t *seg, off_t mapping, off_t read_start, off_t read_length, void *user_data)
 A segcol_foreach_func that writes data from a segment_t into a file.
int segcol_store_in_file (segcol_t *segcol, off_t offset, off_t length, char *tmpdir)
 Stores a range from a segcol_t in a file data object.
int segcol_add_copy (segcol_t *dst, off_t offset, segcol_t *src)
 Copies data from a segcol into another.
int undo_list_enforce_limit (bless_buffer_t *buf, int ensure_vacancy)
 Enforces the undo limit on the undo list.
int action_list_clear (list_t *action_list)
 Clears an action list's contents without freeing the list itself.
int undo_list_append (bless_buffer_t *buf, buffer_action_t *action)
 Appends a buffer_action_t to the undo list of a buffer.

Detailed Description

Implementation of utility function used by bless_buffer_t.

Definition in file buffer_util.c.


Function Documentation

int action_list_clear ( list_t action_list  ) 

Clears an action list's contents without freeing the list itself.

Parameters:
action_list the action_list
Returns:
the operation error code

Definition at line 767 of file buffer_util.c.

References buffer_action_free(), list_delete_chain(), list_entry, list_for_each_safe, and list_head().

Referenced by bless_buffer_append(), bless_buffer_begin_multi_action(), bless_buffer_delete(), bless_buffer_insert(), bless_buffer_save(), and bless_buffer_set_option().

Here is the call graph for this function:

Here is the caller graph for this function:

static int get_data_from_iter ( segcol_iter_t iter,
segment_t **  segment,
off_t *  mapping,
off_t *  read_start,
off_t *  read_length,
off_t  offset,
off_t  length 
) [static]

Gets from an iterator the read limits.

Parameters:
iter the iterator to get data from
[out] segment the segment_t pointed to by the iterator
[out] mapping the mapping of the segment in its segcol
[out] read_start the offset in the segment's data object to start reading from
[out] read_length the length of the data we should read
offset the offset in the segcol we want to read from
length the length of the data we want to read
Returns:
the operation error code

Definition at line 226 of file buffer_util.c.

References segcol_iter_get_mapping(), segcol_iter_get_segment(), segment_get_size(), and segment_get_start().

Referenced by segcol_foreach().

Here is the call graph for this function:

Here is the caller graph for this function:

int read_data_object ( data_object_t dobj,
off_t  offset,
void *  mem,
off_t  length 
)

Reads data from a data object to memory.

Parameters:
dobj the data object to read from
offset the offset in the data object to read from
mem the memory to save the data to
length the number of bytes to read
Returns:
the operation error code

Definition at line 57 of file buffer_util.c.

References data_object_get_data(), and DATA_OBJECT_READ.

Referenced by read_foreach_func(), read_segment_func(), and write_data_object_safe().

Here is the call graph for this function:

Here is the caller graph for this function:

static int read_segment_func ( segcol_t segcol,
segment_t seg,
off_t  mapping,
off_t  read_start,
off_t  read_length,
void *  user_data 
) [static]

A segcol_foreach_func that reads data from a segment_t into memory.

Parameters:
segcol the segcol_t containing the segment
seg the segment to read from
mapping the mapping of the segment in segcol
read_start the offset in the data of the segment to start reading
read_length the length of the data to read
user_data a void ** pointer containing the pointer to write to
Returns:
the operation error code

Definition at line 384 of file buffer_util.c.

References read_data_object(), and segment_get_data().

Referenced by segcol_store_in_memory().

Here is the call graph for this function:

Here is the caller graph for this function:

int segcol_add_copy ( segcol_t dst,
off_t  offset,
segcol_t src 
)

Copies data from a segcol into another.

The dst and src segcol must not be the same.

Parameters:
dst the segcol to copy data into
offset the offset in the segcol to copy data into
src the segcol to copy data from
Returns:
the operation error code

Definition at line 630 of file buffer_util.c.

References segcol_append(), segcol_delete(), segcol_get_size(), segcol_insert(), segcol_iter_free(), segcol_iter_get_mapping(), segcol_iter_get_segment(), segcol_iter_is_valid(), segcol_iter_new(), segcol_iter_next(), segment_copy(), and segment_free().

Here is the call graph for this function:

int segcol_foreach ( segcol_t segcol,
off_t  offset,
off_t  length,
segcol_foreach_func *  func,
void *  user_data 
)

Calls a function for each segment in the specified range of a segcol_t.

Parameters:
segcol the segcol_t to search in
offset the offset in the segcol_t to start from
length the length of the range
func the function to call for each segment
user_data user specified data to pass to func
Returns:
the operation error code

Definition at line 296 of file buffer_util.c.

References get_data_from_iter(), segcol_find(), segcol_get_size(), segcol_iter_free(), segcol_iter_is_valid(), and segcol_iter_next().

Referenced by bless_buffer_read(), segcol_store_in_file(), and segcol_store_in_memory().

Here is the call graph for this function:

Here is the caller graph for this function:

int segcol_store_in_file ( segcol_t segcol,
off_t  offset,
off_t  length,
char *  tmpdir 
)

Stores a range from a segcol_t in a file data object.

Parameters:
segcol the segcol_t
offset the offset to starting storing from
length the length of the data to store
tmpdir the directory where to create the file
Returns:
the operation error code

Definition at line 527 of file buffer_util.c.

References data_object_file_set_close_func(), data_object_free(), data_object_tempfile_new(), data_object_update_usage(), path_join(), segcol_append(), segcol_delete(), segcol_foreach(), segcol_get_size(), segcol_insert(), segment_free(), segment_new(), and store_segment_func().

Referenced by break_edge().

Here is the call graph for this function:

Here is the caller graph for this function:

int segcol_store_in_memory ( segcol_t segcol,
off_t  offset,
off_t  length 
)

Stores a range from a segcol_t in memory data objects.

Parameters:
segcol the segcol_t
offset the offset to starting storing from
length the length of the data to store
Returns:
the operation error code

Definition at line 415 of file buffer_util.c.

References data_object_free(), data_object_memory_new(), data_object_memory_set_free_func(), data_object_update_usage(), read_segment_func(), segcol_append(), segcol_delete(), segcol_foreach(), segcol_get_size(), segcol_insert(), segment_free(), and segment_new().

Referenced by break_edge().

Here is the call graph for this function:

Here is the caller graph for this function:

static int store_segment_func ( segcol_t segcol,
segment_t seg,
off_t  mapping,
off_t  read_start,
off_t  read_length,
void *  user_data 
) [static]

A segcol_foreach_func that writes data from a segment_t into a file.

Parameters:
segcol the segcol_t containing the segment
seg the segment to read from
mapping the mapping of the segment in segcol
read_start the offset in the data of the segment to start reading
read_length the length of the data to read
user_data a int * pointer pointing to the fd to write to
Returns:
the operation error code

Definition at line 495 of file buffer_util.c.

References segment_get_data(), and write_data_object().

Referenced by segcol_store_in_file().

Here is the call graph for this function:

Here is the caller graph for this function:

int undo_list_append ( bless_buffer_t buf,
buffer_action_t action 
)

Appends a buffer_action_t to the undo list of a buffer.

Parameters:
buf the bless_buffer_t to append to
action the action to append
Returns:
the operation error code

Definition at line 799 of file buffer_util.c.

References list_insert_before(), and list_tail().

Referenced by bless_buffer_append(), bless_buffer_begin_multi_action(), bless_buffer_delete(), and bless_buffer_insert().

Here is the call graph for this function:

Here is the caller graph for this function:

int undo_list_enforce_limit ( bless_buffer_t buf,
int  ensure_vacancy 
)

Enforces the undo limit on the undo list.

After the operation the undo list contains at most the most recent buf->options->undo_limit actions. Additionally if ensure_vacancy == 1 the undo list contains space for at least one action (unless the undo limit is 0).

Parameters:
buf the bless_buffer_t
ensure_vacancy whether to make sure that there is space for one additional action
Returns:
the operation error code

Definition at line 713 of file buffer_util.c.

References buffer_action_free(), list_delete_chain(), list_entry, list_for_each_safe, and list_head().

Referenced by bless_buffer_append(), bless_buffer_begin_multi_action(), bless_buffer_delete(), bless_buffer_insert(), and bless_buffer_set_option().

Here is the call graph for this function:

Here is the caller graph for this function:

int write_data_object ( data_object_t dobj,
off_t  offset,
off_t  length,
int  fd,
off_t  file_offset 
)

Writes data from a data object to a file.

Use write_data_object_safe() instead of this function when writing to the same file that the data object is associated with and there is an overlap between the original data object range and the range we are writing it to.

Parameters:
dobj the data object to read from
offset the offset in the data object to read from
length the number of bytes to read
fd the file descriptor to write the data to
file_offset the offset in the file to write the data
Returns:
the operation error code

Definition at line 109 of file buffer_util.c.

References data_object_get_data(), and DATA_OBJECT_READ.

Referenced by store_segment_func(), and write_segment().

Here is the call graph for this function:

Here is the caller graph for this function:

int write_data_object_safe ( data_object_t dobj,
off_t  offset,
off_t  length,
int  fd,
off_t  file_offset 
)

Writes data from a data object to a file in a safe way.

Use this function instead of write_data_object() when writing to the same file that the data object is associated with and there is an overlap between the original data object range and the range we are writing it to.

Parameters:
dobj the data object to read from
offset the offset in the data object to read from
length the number of bytes to read
fd the file descriptor to write the data to
file_offset the offset in the file to write the data
Returns:
the operation error code

Definition at line 157 of file buffer_util.c.

References read_data_object().

Referenced by write_segment().

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sun Nov 15 15:27:42 2009 for libbls by  doxygen 1.6.1