Uniform writer interface. An implementation of this interface must supply a constructor and implement all RDD_WRITE_OPS
(see the structure definition below).
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.
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>
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 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 |
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.
enum _rdd_write_mode_t |
int rdd_compare_address | ( | RDD_WRITER * | w, | |
struct addrinfo * | address, | |||
int * | result | |||
) |
Checks if a given address equals the current writer address.
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). |
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.
host | the host name | |
port | the port number | |
addr | a pointer to the output address |
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.
w | output value: a new writer object. | |
ops | pointers to implementation-specific writer functions. | |
statesize | size in bytes of implementation-specific state. |
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.
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.
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 |
RDD_OK
on success.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.
int rdd_open_fd_writer | ( | RDD_WRITER ** | w, | |
int | fd | |||
) |
Creates a writer that writes to an open file descriptor.
w | output value: the new writer object | |
fd | the open file descriptor that the new writer will write to |
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.
int rdd_open_file_writer | ( | RDD_WRITER ** | w, | |
const char * | path | |||
) |
Creates a writer that writes to a file.
w | output value: the new writer object | |
path | the name of the file that the new writer will write to |
RDD_OK
on success.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().
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.
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 |
RDD_OK
on success.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:basepath
;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.
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.
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 |
RDD_OK
on success.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.
int rdd_open_tcp_writer | ( | RDD_WRITER ** | w, | |
const char * | host, | |||
unsigned | port | |||
) |
Creates a writer that writes to a TCP server.
w | output value: the new writer object | |
host | the name of the server host | |
port | the TCP port number on the server host |
RDD_OK
on success.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.
w | output value: the new writer object | |
parent,: | all compressed output is written to parent |
RDD_OK
on success.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.
int rdd_writer_close | ( | RDD_WRITER * | w | ) |
Closes a writer AND all writers that are below it in the writer stack.
w | a pointer to the writer object. |
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.
w | a pointer to the writer object. | |
buf | a pointer to the data buffer. | |
nbyte | the number of bytes to write |
RDD_OK
on success.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.