1#ifndef MTOOLS_STREAM_H 2#define MTOOLS_STREAM_H 3 4/* Copyright 1996-1999,2001,2002,2005,2006,2008,2009 Alain Knaff. 5 * This file is part of mtools. 6 * 7 * Mtools is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Mtools is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Mtools. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21typedef struct Stream_t { 22 struct Class_t *Class; 23 int refs; 24 struct Stream_t *Next; 25 struct Stream_t *Buffer; 26} Stream_t; 27 28#include "mtools.h" 29#include "msdos.h" 30 31#include "llong.h" 32 33doscp_t *get_dosConvert_pass_through(Stream_t *Stream); 34 35typedef struct Class_t { 36 int (*read)(Stream_t *, char *, mt_off_t, size_t); 37 int (*write)(Stream_t *, char *, mt_off_t, size_t); 38 int (*flush)(Stream_t *); 39 int (*freeFunc)(Stream_t *); 40 int (*set_geom)(Stream_t *, device_t *, device_t *, int media, 41 struct bootsector *); 42 int (*get_data)(Stream_t *, time_t *, mt_size_t *, int *, int *); 43 int (*pre_allocate)(Stream_t *, mt_size_t); 44 45 doscp_t *(*get_dosConvert)(Stream_t *); 46} Class_t; 47 48#define READS(stream, buf, address, size) \ 49((stream)->Class->read)( (stream), (char *) (buf), (address), (size) ) 50 51#define WRITES(stream, buf, address, size) \ 52((stream)->Class->write)( (stream), (char *) (buf), (address), (size) ) 53 54#define SET_GEOM(stream, dev, orig_dev, media, boot) \ 55(stream)->Class->set_geom( (stream), (dev), (orig_dev), (media), (boot) ) 56 57#define GET_DATA(stream, date, size, type, address) \ 58(stream)->Class->get_data( (stream), (date), (size), (type), (address) ) 59 60#define PRE_ALLOCATE(stream, size) \ 61(stream)->Class->pre_allocate((stream), (size)) 62 63#define GET_DOSCONVERT(stream) \ 64 (stream)->Class->get_dosConvert((stream)) 65 66int flush_stream(Stream_t *Stream); 67Stream_t *copy_stream(Stream_t *Stream); 68int free_stream(Stream_t **Stream); 69 70#define FLUSH(stream) \ 71flush_stream( (stream) ) 72 73#define FREE(stream) \ 74free_stream( (stream) ) 75 76#define COPY(stream) \ 77copy_stream( (stream) ) 78 79 80#define DeclareThis(x) x *This = (x *) Stream 81 82int force_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len); 83int force_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len); 84 85int get_data_pass_through(Stream_t *Stream, time_t *date, mt_size_t *size, 86 int *type, int *address); 87 88int read_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len); 89int write_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len); 90 91 92#endif 93 94