1*d5c9a868SElliott Hughes #ifndef MTOOLS_STREAM_H 2*d5c9a868SElliott Hughes #define MTOOLS_STREAM_H 3*d5c9a868SElliott Hughes 4*d5c9a868SElliott Hughes /* Copyright 1996-1999,2001,2002,2005,2006,2008,2009,2011 Alain Knaff. 5*d5c9a868SElliott Hughes * This file is part of mtools. 6*d5c9a868SElliott Hughes * 7*d5c9a868SElliott Hughes * Mtools is free software: you can redistribute it and/or modify 8*d5c9a868SElliott Hughes * it under the terms of the GNU General Public License as published by 9*d5c9a868SElliott Hughes * the Free Software Foundation, either version 3 of the License, or 10*d5c9a868SElliott Hughes * (at your option) any later version. 11*d5c9a868SElliott Hughes * 12*d5c9a868SElliott Hughes * Mtools is distributed in the hope that it will be useful, 13*d5c9a868SElliott Hughes * but WITHOUT ANY WARRANTY; without even the implied warranty of 14*d5c9a868SElliott Hughes * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*d5c9a868SElliott Hughes * GNU General Public License for more details. 16*d5c9a868SElliott Hughes * 17*d5c9a868SElliott Hughes * You should have received a copy of the GNU General Public License 18*d5c9a868SElliott Hughes * along with Mtools. If not, see <http://www.gnu.org/licenses/>. 19*d5c9a868SElliott Hughes */ 20*d5c9a868SElliott Hughes 21*d5c9a868SElliott Hughes typedef struct Stream_t { 22*d5c9a868SElliott Hughes struct Class_t *Class; 23*d5c9a868SElliott Hughes int refs; 24*d5c9a868SElliott Hughes struct Stream_t *Next; 25*d5c9a868SElliott Hughes } Stream_t; 26*d5c9a868SElliott Hughes 27*d5c9a868SElliott Hughes #include "mtools.h" 28*d5c9a868SElliott Hughes #include "msdos.h" 29*d5c9a868SElliott Hughes #include "device.h" 30*d5c9a868SElliott Hughes #include "llong.h" 31*d5c9a868SElliott Hughes 32*d5c9a868SElliott Hughes void limitSizeToOffT(size_t *len, mt_off_t maxLen); 33*d5c9a868SElliott Hughes 34*d5c9a868SElliott Hughes doscp_t *get_dosConvert_pass_through(Stream_t *Stream); 35*d5c9a868SElliott Hughes 36*d5c9a868SElliott Hughes typedef struct Class_t { 37*d5c9a868SElliott Hughes ssize_t (*read)(Stream_t *, char *, size_t); 38*d5c9a868SElliott Hughes ssize_t (*write)(Stream_t *, char *, size_t); 39*d5c9a868SElliott Hughes ssize_t (*pread)(Stream_t *, char *, mt_off_t, size_t); 40*d5c9a868SElliott Hughes ssize_t (*pwrite)(Stream_t *, char *, mt_off_t, size_t); 41*d5c9a868SElliott Hughes int (*flush)(Stream_t *); 42*d5c9a868SElliott Hughes int (*freeFunc)(Stream_t *); 43*d5c9a868SElliott Hughes int (*set_geom)(Stream_t *, device_t *, device_t *); 44*d5c9a868SElliott Hughes int (*get_data)(Stream_t *, time_t *, mt_off_t *, int *, uint32_t *); 45*d5c9a868SElliott Hughes int (*pre_allocate)(Stream_t *, mt_off_t); 46*d5c9a868SElliott Hughes 47*d5c9a868SElliott Hughes doscp_t *(*get_dosConvert)(Stream_t *); 48*d5c9a868SElliott Hughes 49*d5c9a868SElliott Hughes int (*discard)(Stream_t *); 50*d5c9a868SElliott Hughes } Class_t; 51*d5c9a868SElliott Hughes 52*d5c9a868SElliott Hughes #define READS(stream, buf, size) \ 53*d5c9a868SElliott Hughes ((stream)->Class->read)( (stream), (char *) (buf), (size) ) 54*d5c9a868SElliott Hughes 55*d5c9a868SElliott Hughes #define WRITES(stream, buf, size) \ 56*d5c9a868SElliott Hughes ((stream)->Class->write)( (stream), (char *) (buf), (size) ) 57*d5c9a868SElliott Hughes 58*d5c9a868SElliott Hughes #define PREADS(stream, buf, address, size) \ 59*d5c9a868SElliott Hughes ((stream)->Class->pread)( (stream), (char *) (buf), (address), (size) ) 60*d5c9a868SElliott Hughes 61*d5c9a868SElliott Hughes #define PWRITES(stream, buf, address, size) \ 62*d5c9a868SElliott Hughes ((stream)->Class->pwrite)( (stream), (char *) (buf), (address), (size) ) 63*d5c9a868SElliott Hughes 64*d5c9a868SElliott Hughes #define SET_GEOM(stream, dev, orig_dev) \ 65*d5c9a868SElliott Hughes (stream)->Class->set_geom( (stream), (dev), (orig_dev)) 66*d5c9a868SElliott Hughes 67*d5c9a868SElliott Hughes #define GET_DATA(stream, date, size, type, address) \ 68*d5c9a868SElliott Hughes (stream)->Class->get_data( (stream), (date), (size), (type), (address) ) 69*d5c9a868SElliott Hughes 70*d5c9a868SElliott Hughes #define PRE_ALLOCATE(stream, size) \ 71*d5c9a868SElliott Hughes (stream)->Class->pre_allocate((stream), (size)) 72*d5c9a868SElliott Hughes 73*d5c9a868SElliott Hughes #define GET_DOSCONVERT(stream) \ 74*d5c9a868SElliott Hughes (stream)->Class->get_dosConvert((stream)) 75*d5c9a868SElliott Hughes 76*d5c9a868SElliott Hughes #define DISCARD(stream) \ 77*d5c9a868SElliott Hughes (stream)->Class->discard((stream)) 78*d5c9a868SElliott Hughes 79*d5c9a868SElliott Hughes int flush_stream(Stream_t *Stream); 80*d5c9a868SElliott Hughes Stream_t *copy_stream(Stream_t *Stream); 81*d5c9a868SElliott Hughes int free_stream(Stream_t **Stream); 82*d5c9a868SElliott Hughes 83*d5c9a868SElliott Hughes #define FLUSH(stream) \ 84*d5c9a868SElliott Hughes flush_stream( (stream) ) 85*d5c9a868SElliott Hughes 86*d5c9a868SElliott Hughes #define FREE(stream) \ 87*d5c9a868SElliott Hughes free_stream( (stream) ) 88*d5c9a868SElliott Hughes 89*d5c9a868SElliott Hughes #define COPY(stream) \ 90*d5c9a868SElliott Hughes copy_stream( (stream) ) 91*d5c9a868SElliott Hughes 92*d5c9a868SElliott Hughes 93*d5c9a868SElliott Hughes #define DeclareThis(x) x *This = (x *) Stream 94*d5c9a868SElliott Hughes 95*d5c9a868SElliott Hughes void init_head(Stream_t *Stream, struct Class_t *Class, Stream_t *Next); 96*d5c9a868SElliott Hughes 97*d5c9a868SElliott Hughes ssize_t force_pwrite(Stream_t *Stream, char *buf, mt_off_t start, size_t len); 98*d5c9a868SElliott Hughes ssize_t force_pread(Stream_t *Stream, char *buf, mt_off_t start, size_t len); 99*d5c9a868SElliott Hughes 100*d5c9a868SElliott Hughes ssize_t force_write(Stream_t *Stream, char *buf, size_t len); 101*d5c9a868SElliott Hughes 102*d5c9a868SElliott Hughes int set_geom_pass_through(Stream_t *Stream, device_t *dev, device_t *orig_dev); 103*d5c9a868SElliott Hughes 104*d5c9a868SElliott Hughes int set_geom_noop(Stream_t *Stream, device_t *dev, device_t *orig_dev); 105*d5c9a868SElliott Hughes 106*d5c9a868SElliott Hughes int get_data_pass_through(Stream_t *Stream, time_t *date, mt_off_t *size, 107*d5c9a868SElliott Hughes int *type, uint32_t *address); 108*d5c9a868SElliott Hughes 109*d5c9a868SElliott Hughes ssize_t pread_pass_through(Stream_t *Stream, char *buf, 110*d5c9a868SElliott Hughes mt_off_t start, size_t len); 111*d5c9a868SElliott Hughes ssize_t pwrite_pass_through(Stream_t *Stream, char *buf, 112*d5c9a868SElliott Hughes mt_off_t start, size_t len); 113*d5c9a868SElliott Hughes 114*d5c9a868SElliott Hughes mt_off_t getfree(Stream_t *Stream); 115*d5c9a868SElliott Hughes int getfreeMinBytes(Stream_t *Stream, mt_off_t ref); 116*d5c9a868SElliott Hughes 117*d5c9a868SElliott Hughes Stream_t *find_device(char drive, int mode, struct device *out_dev, 118*d5c9a868SElliott Hughes union bootsector *boot, 119*d5c9a868SElliott Hughes char *name, int *media, mt_off_t *maxSize, 120*d5c9a868SElliott Hughes int *isRop); 121*d5c9a868SElliott Hughes 122*d5c9a868SElliott Hughes int adjust_tot_sectors(struct device *dev, mt_off_t offset, char *errmsg); 123*d5c9a868SElliott Hughes 124*d5c9a868SElliott Hughes #endif 125*d5c9a868SElliott Hughes 126