00001 /* 00002 * I/O and buffering 00003 */ 00004 00005 #ifndef __io_h__ 00006 #define __io_h__ 00007 00008 #include "headers.h" 00009 #include "types.h" 00010 00011 /** I/O */ 00012 struct _io { 00013 /** Input path, if given on the command line. This is used when copying a 00014 * file into a directory, the base filename of the input file is used as the 00015 * filename in the destination directory, so we need to keep it around. */ 00016 char *in_path; 00017 /** Input file descriptor. */ 00018 int in; 00019 /** Output file descriptor. */ 00020 int out; 00021 /** Flag: Input source is ready to be read. */ 00022 int in_ready; 00023 /** Flag: Output source is ready to be written to. */ 00024 int out_ready; 00025 /** Flag: End of input has been reached. */ 00026 int eof_in; 00027 /** Flag: End of output has been reached. */ 00028 int eof_out; 00029 /** The size of the I/O buffer. */ 00030 size_t buffer_size; 00031 /** A pointer to the I/O buffer. */ 00032 char *buffer; 00033 /** The location of the start of the ring buffer. */ 00034 size_t buffer_head; 00035 /** The length of the ring buffer. */ 00036 size_t buffer_used; 00037 /** The number of bytes read the last time I/O was performed. */ 00038 ssize_t last_read; 00039 /** The number of bytes written the last time I/O was performed. */ 00040 ssize_t last_write; 00041 /** The total number of bytes read. */ 00042 uint64 total_read; 00043 /** The total number of bytes written. */ 00044 uint64 total_write; 00045 /** The total size of the input stream, if known. */ 00046 uint64 total_size; 00047 /** If continuing from a previously interrupted stream, assume that this 00048 * many bytes have already been read and written. */ 00049 uint64 continue_size; 00050 /** Flag: Whether or not the total size of the input stream is known. */ 00051 int total_size_known; 00052 /** The number of microseconds to wait for a change in I/O state. */ 00053 uint32 timeout; 00054 /** The current time, used for throttling input. */ 00055 time_t current_time; 00056 /** The maximum number of bytes per second that we're allowed to read. */ 00057 uint64 throttle; 00058 /** The number if bytes read so far for this second. */ 00059 uint64 throttle_count; 00060 /** The size of a block in bytes, used for calculating total_size and 00061 * buffer_size. */ 00062 uint64 block_size; 00063 }; 00064 00065 typedef struct _io IO; 00066 00067 extern IO io; 00068 00069 int ioInit(void); 00070 int ioBegin(void); 00071 int ioEnd(void); 00072 void ioCheck(void); 00073 int ioRead(void); 00074 int ioWrite(void); 00075 int ioIsDone(void); 00076 00077 #endif