This header file defines rdd's uniform reader interface. The rdd package contains multiple implementations of this interface (see the files named *reader.c
).
Definition in file reader.h.
Go to the source code of this file.
Data Structures | |
struct | _RDD_READ_OPS |
struct | _RDD_READER |
Typedefs | |
typedef int(* | rdd_rd_close_fun )(struct _RDD_READER *r, int recurse) |
typedef int(* | rdd_rd_read_fun )(struct _RDD_READER *r, unsigned char *buf, unsigned nbyte, unsigned *nread) |
typedef int(* | rdd_rd_seek_fun )(struct _RDD_READER *r, rdd_count_t pos) |
typedef int(* | rdd_rd_tell_fun )(struct _RDD_READER *r, rdd_count_t *pos) |
typedef struct _RDD_READ_OPS | RDD_READ_OPS |
typedef struct _RDD_READER | RDD_READER |
Functions | |
int | rdd_new_reader (RDD_READER **r, RDD_READ_OPS *ops, unsigned statesize) |
Allocates and partially initializes a reader object. | |
int | rdd_open_aligned_reader (RDD_READER **r, RDD_READER *parent, unsigned align) |
Instantiates a reader that reads from a reader that expects aligned accesses and aligned user buffers. | |
int | rdd_open_atomic_reader (RDD_READER **r, RDD_READER *p) |
Instantiates a reader that does not move the file pointer when a read error occurs. | |
int | rdd_open_cdrom_reader (RDD_READER **r, const char *path) |
int | rdd_open_faulty_reader (RDD_READER **r, RDD_READER *p, char *specfile) |
Instantiates a reader that simulates read errors. | |
int | rdd_open_fd_reader (RDD_READER **r, int fd) |
Instantiates a reader that reads from an open file descriptor. | |
int | rdd_open_file_reader (RDD_READER **r, const char *path, int raw) |
Instantiates a reader that reads from a file. | |
int | rdd_open_raw_reader (RDD_READER **r, int fd) |
Instantiates a reader that reads from an open file descriptor that refers to a raw block device. | |
int | rdd_open_zlib_reader (RDD_READER **r, RDD_READER *p) |
Instantiates a reader that decompresses zlib-compressed data. | |
int | rdd_reader_close (RDD_READER *r, int recurse) |
Closes and deallocates the reader object. | |
int | rdd_reader_read (RDD_READER *r, unsigned char *buf, unsigned nbyte, unsigned *nread) |
Generic read routine. | |
int | rdd_reader_seek (RDD_READER *r, rdd_count_t pos) |
Updates the current file position. | |
int | rdd_reader_skip (RDD_READER *r, rdd_count_t skip) |
Moves the file pointer skip bytes forward. | |
int | rdd_reader_tell (RDD_READER *r, rdd_count_t *pos) |
Returns the current file position in bytes. |
typedef int(* rdd_rd_close_fun)(struct _RDD_READER *r, int recurse) |
typedef int(* rdd_rd_read_fun)(struct _RDD_READER *r, unsigned char *buf, unsigned nbyte, unsigned *nread) |
typedef int(* rdd_rd_seek_fun)(struct _RDD_READER *r, rdd_count_t pos) |
typedef int(* rdd_rd_tell_fun)(struct _RDD_READER *r, rdd_count_t *pos) |
typedef struct _RDD_READ_OPS RDD_READ_OPS |
All reader implementations provide a structure of type RDD_READ_OPS
. This structure contains pointers to the routines that implement the interface.
typedef struct _RDD_READER RDD_READER |
A reader object consists of a pointer to implementation-defined state and a pointer to the routines that implement the uniform interface.
int rdd_new_reader | ( | RDD_READER ** | r, | |
RDD_READ_OPS * | ops, | |||
unsigned | statesize | |||
) |
Allocates and partially initializes a reader object.
r | output value: a new reader object. | |
ops | pointers to implementation-specific reader functions. | |
statesize | size in bytes of implementation-specific state. |
RDD_OK
on success. Returns RDD_NOMEM
when there is insufficient memory to allocate the reader object or its state buffer.rdd_new_reader
allocates a reader 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 reader.c.
References _RDD_READER::ops, RDD_BADARG, RDD_NOMEM, RDD_OK, and _RDD_READER::state.
int rdd_open_aligned_reader | ( | RDD_READER ** | r, | |
RDD_READER * | parent, | |||
unsigned | align | |||
) |
Instantiates a reader that reads from a reader that expects aligned accesses and aligned user buffers.
r | output value: a new reader object. | |
parent | output value: the parent reader. | |
align | alignment in bytes. |
RDD_OK
on success.Definition at line 79 of file alignedreader.c.
References _RDD_ALIGNED_READER::align, _RDD_ALIGNED_READER::parent, rdd_new_reader(), RDD_OK, and _RDD_READER::state.
int rdd_open_atomic_reader | ( | RDD_READER ** | r, | |
RDD_READER * | p | |||
) |
Instantiates a reader that does not move the file pointer when a read error occurs.
r | output value: a new reader object. | |
p | an existing parent reader. |
p
. All read requests received by r
are forwarded to p
. If a read on p
fails with error code RDD_EREAD
, then r
will restore the file position to the same value it had before the read was issued.
Note: the parent reader p
MUST implement the seek()
and tell()
operations.
Definition at line 73 of file atomicreader.c.
References _RDD_ATOMIC_READER::parent, RDD_BADARG, rdd_new_reader(), RDD_OK, and _RDD_READER::state.
int rdd_open_cdrom_reader | ( | RDD_READER ** | r, | |
const char * | path | |||
) |
Definition at line 72 of file cdromreader.c.
References fd_read_ops, _RDD_CDROMREADER_STATE::path, _RDD_CDROMREADER_STATE::pos, RDD_BADARG, rdd_new_reader(), RDD_NOMEM, RDD_OK, and _RDD_READER::state.
int rdd_open_faulty_reader | ( | RDD_READER ** | r, | |
RDD_READER * | p, | |||
char * | specfile | |||
) |
Instantiates a reader that simulates read errors.
r | output value: a new reader object. | |
p | an existing parent reader. | |
specfile | a file that specifies the file positions at which read errors should be simulated by this reader. |
Definition at line 146 of file faultyreader.c.
References fault_compare(), _FAULTY_READER_STATE::faults, _FAULTY_READER_STATE::nfault, _FAULTY_READER_STATE::parent, RDD_BADARG, RDD_ECLOSE, RDD_EOPEN, rdd_new_reader(), RDD_OK, read_faults(), and _RDD_READER::state.
int rdd_open_fd_reader | ( | RDD_READER ** | r, | |
int | fd | |||
) |
Instantiates a reader that reads from an open file descriptor.
Constructors
r | output value: a new reader object. | |
fd | the open file descriptor that the reader will read from. |
RDD_OK
on success.Definition at line 72 of file fdreader.c.
References _RDD_FD_READER::fd, rdd_new_reader(), RDD_OK, and _RDD_READER::state.
int rdd_open_file_reader | ( | RDD_READER ** | r, | |
const char * | path, | |||
int | raw | |||
) |
Instantiates a reader that reads from a file.
r | output value: a new reader object. | |
path | the name of the file that the reader will read from. | |
raw | true iff path refers to a raw-device file |
RDD_OK
on success.Definition at line 51 of file filereader.c.
References RDD_EOPEN, and rdd_open_fd_reader().
int rdd_open_raw_reader | ( | RDD_READER ** | r, | |
int | fd | |||
) |
Instantiates a reader that reads from an open file descriptor that refers to a raw block device.
r | output value: a new reader object. | |
fd | the open file descriptor that the reader will read from. |
RDD_OK
on success.int rdd_open_zlib_reader | ( | RDD_READER ** | r, | |
RDD_READER * | p | |||
) |
Instantiates a reader that decompresses zlib-compressed data.
r | output value: a new reader object. | |
p | an existing parent reader. |
p
that reads zlib-compressed data.
Note: a zlib reader does not implement the seek()
routine.
Definition at line 84 of file zlibreader.c.
References error(), _RDD_ZLIB_READER::parent, _RDD_ZLIB_READER::pos, RDD_ECOMPRESS, rdd_new_reader(), RDD_NOMEM, RDD_OK, _RDD_READER::state, _RDD_ZLIB_READER::zbuf, ZBUF_SIZE, and _RDD_ZLIB_READER::zstate.
int rdd_reader_close | ( | RDD_READER * | r, | |
int | recurse | |||
) |
Closes and deallocates the reader object.
r | pointer to the reader object. | |
recurse | recursive-close flag |
recurse
is nonzero.
Definition at line 107 of file reader.c.
References _RDD_READ_OPS::close, _RDD_READER::ops, RDD_OK, and _RDD_READER::state.
int rdd_reader_read | ( | RDD_READER * | r, | |
unsigned char * | buf, | |||
unsigned | nbyte, | |||
unsigned * | nread | |||
) |
Generic read routine.
r | pointer to the reader object. | |
buf | pointer to the target buffer; the size of this buffer must be at least nbyte bytes. | |
nbyte | the number of bytes to read | |
nread | output value: the number of bytes actually read; the value in *read is valid only if RDD_OK is returned. |
*nread
will be equal to nbyte
except when there are fewer than nbyte
bytes left until the end of the file is reached. In that case *nread
will be equal to the number of bytes left. If *nread
equals 0
, then end-of-file has been reached. Definition at line 71 of file reader.c.
References _RDD_READER::ops, and _RDD_READ_OPS::read.
int rdd_reader_seek | ( | RDD_READER * | r, | |
rdd_count_t | pos | |||
) |
Updates the current file position.
r | pointer to the reader object. | |
pos | the new (absolute) file position in bytes. |
seek()
routine.
Definition at line 84 of file reader.c.
References _RDD_READER::ops, and _RDD_READ_OPS::seek.
int rdd_reader_skip | ( | RDD_READER * | r, | |
rdd_count_t | skip | |||
) |
Moves the file pointer skip
bytes forward.
r | pointer to the reader object. | |
skip | the number of bytes to move forward. |
skip()
routine.
Definition at line 90 of file reader.c.
References RDD_OK, rdd_reader_seek(), and rdd_reader_tell().
int rdd_reader_tell | ( | RDD_READER * | r, | |
rdd_count_t * | pos | |||
) |
Returns the current file position in bytes.
r | pointer to the reader object. | |
pos | output value: the current file position in bytes. The value in *pos is valid only if RDD_OK is returned. |
Definition at line 78 of file reader.c.
References _RDD_READER::ops, and _RDD_READ_OPS::tell.