src/writer.h File Reference


Detailed Description

Generic writer interface.

Uniform writer interface. An implementation of this interface must supply a constructor and implement all RDD_WRITE_OPS (see the structure definition below).

Writer types

There are two types of writers: bottom writers and stackable writers. A stackable writer receives input, optionally transforms it in some way, and passes the transformed data on to a lower-level parent writer. The parent writer is passed to the stackable writer at the time the stackable writer is constructed. The zlib writer is a stackable writer.

A bottom writer receives input, optionally transforms it in some way, and passes the transformed data on to some output device (e.g. a file descriptor), but not to another writer. A bottom writer may well use other writer types in its implementation, but that does not make it a stackable writer.

Constructors

Each constructor must be listed in this header file. Once a writer has been constructed, it should be accessed through the generic writer routines, rdd_writer_write() and rdd_writer_close().

Definition in file writer.h.

#include "hashcontainer.h"
#include <netdb.h>

Include dependency graph for writer.h:

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

Go to the source code of this file.

Data Structures

struct  _RDD_WRITE_OPS
struct  _RDD_WRITER

Typedefs

typedef int(* rdd_wr_close_fun )(struct _RDD_WRITER *w)
typedef int(* rdd_wr_compare_address_fun )(struct _RDD_WRITER *w, struct addrinfo *address, int *result)
typedef int(* rdd_wr_write_fun )(struct _RDD_WRITER *w, const unsigned char *buf, unsigned nbyte)
typedef enum _rdd_write_mode_t rdd_write_mode_t
typedef struct _RDD_WRITE_OPS RDD_WRITE_OPS
typedef struct _RDD_WRITER RDD_WRITER

Enumerations

enum  _rdd_write_mode_t { RDD_NO_OVERWRITE = 0, RDD_OVERWRITE = 1, RDD_OVERWRITE_ASK = 2 }

Functions

int rdd_compare_address (RDD_WRITER *w, struct addrinfo *address, int *result)
 Checks if a given address equals the current writer address.
int rdd_get_address (const char *host, unsigned int port, struct addrinfo **addr)
 Retrieves the addrinfo address for the given host and port.
int rdd_new_writer (RDD_WRITER **w, RDD_WRITE_OPS *ops, unsigned statesize)
 Allocates and partially initializes a new writer object.
int rdd_open_ewf_writer (RDD_WRITER **w, const char *path, rdd_count_t splitlen, int compression_type, rdd_write_mode_t overwrite, RDD_HASH_CONTAINER *hashcontainer)
 Creates a writer that writes ewf files.
int rdd_open_fd_writer (RDD_WRITER **w, int fd)
 Creates a writer that writes to an open file descriptor.
int rdd_open_file_writer (RDD_WRITER **w, const char *path)
 Creates a writer that writes to a file.
int rdd_open_part_writer (RDD_WRITER **w, const char *basepath, rdd_count_t maxlen, rdd_count_t splitlen, rdd_write_mode_t overwrite)
 Creates a writer that can split its output over multiple files.
int rdd_open_safe_writer (RDD_WRITER **w, const char *path, rdd_write_mode_t overwrite)
 Creates a writer that does not blindly overwrite existing files.
int rdd_open_tcp_writer (RDD_WRITER **w, const char *host, unsigned port)
 Creates a writer that writes to a TCP server.
int rdd_open_zlib_writer (RDD_WRITER **w, RDD_WRITER *parent)
 Creates a writer that compresses its input before writing it.
int rdd_writer_close (RDD_WRITER *w)
 Closes a writer AND all writers that are below it in the writer stack.
int rdd_writer_write (RDD_WRITER *w, const unsigned char *buf, unsigned nbyte)
 Writes a data buffer to the output channel associated with a writer.


Typedef Documentation

typedef int(* rdd_wr_close_fun)(struct _RDD_WRITER *w)

Definition at line 84 of file writer.h.

typedef int(* rdd_wr_compare_address_fun)(struct _RDD_WRITER *w, struct addrinfo *address, int *result)

Definition at line 86 of file writer.h.

typedef int(* rdd_wr_write_fun)(struct _RDD_WRITER *w, const unsigned char *buf, unsigned nbyte)

Definition at line 81 of file writer.h.

Values of type rdd_write_mode_t determine the behavior of writers that try to write to an existing file.

typedef struct _RDD_WRITE_OPS RDD_WRITE_OPS

All writer implementations provide a structure of type RDD_WRITE_OPS. This structure contains pointers to the routines that implement the interface.

typedef struct _RDD_WRITER RDD_WRITER

Writer object. A writer object consists of a pointer to a state buffer and a pointer to an operation table.


Enumeration Type Documentation

Values of type rdd_write_mode_t determine the behavior of writers that try to write to an existing file.

Enumerator:
RDD_NO_OVERWRITE  do not overwrite existing files
RDD_OVERWRITE  truncate and overwrite existing files
RDD_OVERWRITE_ASK  ask before overwriting existing files

Definition at line 75 of file writer.h.


Function Documentation

int rdd_compare_address ( RDD_WRITER w,
struct addrinfo *  address,
int *  result 
)

Checks if a given address equals the current writer address.

Parameters:
w a pointer to the writer object.
address a pointer to the address object.
result output value: the result (1 if equal, 0 if not).
Returns:
Returns RDD_OK on success.

Definition at line 116 of file writer.c.

References _RDD_WRITE_OPS::compare_address, _RDD_WRITER::ops, and RDD_BADARG.

int rdd_get_address ( const char *  host,
unsigned int  port,
struct addrinfo **  addr 
)

Retrieves the addrinfo address for the given host and port.

Parameters:
host the host name
port the port number
addr a pointer to the output address
Returns:
Returns RDD_OK on success.

Definition at line 101 of file tcpwriter.c.

References RDD_BADARG, RDD_ECONNECT, and RDD_OK.

int rdd_new_writer ( RDD_WRITER **  w,
RDD_WRITE_OPS ops,
unsigned  statesize 
)

Allocates and partially initializes a new writer object.

Parameters:
w output value: a new writer object.
ops pointers to implementation-specific writer functions.
statesize size in bytes of implementation-specific state.
Returns:
Returns RDD_OK on success. Returns RDD_NOMEM when there is insufficient memory to allocate the writer object or its state buffer.
rdd_new_writer() allocates a writer object and initializes its ops field to argument . The state field is set to point to a new buffer (allocated with malloc()) with size statesize. The state buffer is zeroed.

Definition at line 50 of file writer.c.

References error(), _RDD_WRITER::ops, RDD_BADARG, RDD_NOMEM, RDD_OK, and _RDD_WRITER::state.

Here is the call graph for this function:

int rdd_open_ewf_writer ( RDD_WRITER **  w,
const char *  path,
rdd_count_t  splitlen,
int  compression_type,
rdd_write_mode_t  overwrite,
RDD_HASH_CONTAINER hashcontainer 
)

Creates a writer that writes ewf files.

Parameters:
w a pointer to the writer object.
path the name of the file that the new writer will write to
splitlen maximum size in bytes of each output file
overwrite indicates what to do when path exists
hashes space to pass the hashes to the writer
Returns:
Returns RDD_OK on success.
Routine rdd_open_ewf_writer() exports the copied data into encase6 format. Currently the only encase option which can be set on the rdd command line is the segment size (splitlen).

Definition at line 110 of file ewfwriter.c.

References compress_empty_block(), compress_level(), error(), _RDD_EWF_WRITER::ewf_handle, _RDD_EWF_WRITER::hashcontainer, _RDD_EWF_WRITER::path, path_exists(), RDD_BADARG, RDD_EEXISTS, RDD_EOPEN, RDD_EWF_MIN_SPLITLEN, rdd_new_writer(), RDD_NO_OVERWRITE, RDD_NOMEM, RDD_OK, _RDD_WRITER::state, and _RDD_EWF_WRITER::write_called.

Here is the call graph for this function:

int rdd_open_fd_writer ( RDD_WRITER **  w,
int  fd 
)

Creates a writer that writes to an open file descriptor.

Parameters:
w output value: the new writer object
fd the open file descriptor that the new writer will write to
Returns:
Returns RDD_OK on success.

Definition at line 60 of file fdwriter.c.

References _RDD_FD_WRITER::fd, RDD_BADARG, rdd_new_writer(), RDD_OK, and _RDD_WRITER::state.

Here is the call graph for this function:

int rdd_open_file_writer ( RDD_WRITER **  w,
const char *  path 
)

Creates a writer that writes to a file.

Parameters:
w output value: the new writer object
path the name of the file that the new writer will write to
Returns:
Returns RDD_OK on success.
Routine rdd_open_file_writer() will create file path if it does not exist. It will fail if the directory in which path must be created does not exist. If path already exists then rdd_open_file_writer() will silently truncate the existing file.

Definition at line 55 of file filewriter.c.

References RDD_BADARG, RDD_EOPEN, and rdd_open_fd_writer().

Here is the call graph for this function:

int rdd_open_part_writer ( RDD_WRITER **  w,
const char *  basepath,
rdd_count_t  maxlen,
rdd_count_t  splitlen,
rdd_write_mode_t  overwrite 
)

Creates a writer that can split its output over multiple files.

Parameters:
w output value: the new writer object
basepath template for output file names
maxlen maximum number of bytes that will be written
splitlen maximum size in bytes of each output file
overwrite indicates what to do when an output file already exists
Returns:
Returns RDD_OK on success.
Routine rdd_open_part_writer() splits the data stream it receives over a sequence of output files. The first splitlen bytes are written to output file number one, the next splitlen bytes to output file number two, and so on. The name of each output file consists of:
  • the directory part of basepath;
  • the output file's sequence number;
  • a dash;
  • the base name of basepath.

Definition at line 162 of file partwriter.c.

References count_digits(), error(), _RDD_PART_WRITER::maxpathlen, _RDD_PART_WRITER::ndigit, _RDD_PART_WRITER::next_partnum, open_next_part(), _RDD_PART_WRITER::path, _RDD_PART_WRITER::pathbuf, RDD_BADARG, rdd_new_writer(), RDD_NOMEM, RDD_OK, _RDD_PART_WRITER::splitlen, _RDD_WRITER::state, _RDD_PART_WRITER::writemode, and _RDD_PART_WRITER::written.

Here is the call graph for this function:

int rdd_open_safe_writer ( RDD_WRITER **  w,
const char *  path,
rdd_write_mode_t  overwrite 
)

Creates a writer that does not blindly overwrite existing files.

Parameters:
w output value: the new writer object
path the name of the file that the new writer will write to
overwrite indicates what to do when path exists
Returns:
Returns RDD_OK on success.
A safe writer behaves almost exactly like a file writer. The key difference is that a safe writer will only overwrite an existing file if overwrite equals RDD_OVERWRITE. Otherwise rdd_open_safe_writer() will fail.

Definition at line 81 of file safewriter.c.

References error(), _RDD_SAFE_WRITER::parent, _RDD_SAFE_WRITER::path, path_exists(), RDD_BADARG, RDD_EEXISTS, rdd_new_writer(), RDD_NO_OVERWRITE, RDD_NOMEM, RDD_OK, rdd_open_file_writer(), and _RDD_WRITER::state.

Here is the call graph for this function:

int rdd_open_tcp_writer ( RDD_WRITER **  w,
const char *  host,
unsigned  port 
)

Creates a writer that writes to a TCP server.

Parameters:
w output value: the new writer object
host the name of the server host
port the TCP port number on the server host
Returns:
Returns RDD_OK on success.
Routine rdd_open_tcp_writer() connects to a TCP server that runs on host and listens to TCP port port. Any data written to the TCP writer is passed on to the server process at the other end of the TCP connection.

int rdd_open_zlib_writer ( RDD_WRITER **  w,
RDD_WRITER parent 
)

Creates a writer that compresses its input before writing it.

Parameters:
w output value: the new writer object
parent,: all compressed output is written to parent
Returns:
Returns RDD_OK on success.
A zlib writer is stacked on top of a parent writer. Any data written to the zlib writer is written through to the parent writer in compressed zlib format.

Definition at line 83 of file zlibwriter.c.

References error(), _RDD_ZLIB_WRITER::parent, RDD_BADARG, RDD_ECOMPRESS, rdd_new_writer(), RDD_NOMEM, RDD_OK, _RDD_WRITER::state, _RDD_ZLIB_WRITER::zbuf, ZBUF_SIZE, and _RDD_ZLIB_WRITER::zstate.

Here is the call graph for this function:

int rdd_writer_close ( RDD_WRITER w  ) 

Closes a writer AND all writers that are below it in the writer stack.

Parameters:
w a pointer to the writer object.
When writer w is closed its resources are released and no further writes can be issued to writer w. At present, all writers stacked below w are closed as well. This behavior may change in the future.

Definition at line 95 of file writer.c.

References _RDD_WRITE_OPS::close, _RDD_WRITER::ops, RDD_BADARG, RDD_OK, and _RDD_WRITER::state.

int rdd_writer_write ( RDD_WRITER w,
const unsigned char *  buf,
unsigned  nbyte 
)

Writes a data buffer to the output channel associated with a writer.

Parameters:
w a pointer to the writer object.
buf a pointer to the data buffer.
nbyte the number of bytes to write
Returns:
Returns RDD_OK on success.
Routine rdd_writer_write() writes the first nbyte bytes in buffer buf to an output channel. The identity and the nature of the output channel is determined by the type of writer object is used and by the arguments that were passed to the writer's constructor.

When rdd_writer_write() returns, data buffer buf can safely be reused.

Definition at line 88 of file writer.c.

References _RDD_WRITER::ops, and _RDD_WRITE_OPS::write.


Generated on Sun Feb 6 12:36:41 2011 for rdd by  doxygen 1.5.6