1 #ifndef MTOOLS_STREAM_H
2 #define MTOOLS_STREAM_H
3 
4 /*  Copyright 1996-1999,2001,2002,2005,2006,2008,2009,2011 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 
21 typedef 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 
33 doscp_t *get_dosConvert_pass_through(Stream_t *Stream);
34 
35 typedef 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 					union 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 
47 	int (*discard)(Stream_t *);
48 } Class_t;
49 
50 #define READS(stream, buf, address, size) \
51 ((stream)->Class->read)( (stream), (char *) (buf), (address), (size) )
52 
53 #define WRITES(stream, buf, address, size) \
54 ((stream)->Class->write)( (stream), (char *) (buf), (address), (size) )
55 
56 #define SET_GEOM(stream, dev, orig_dev, media, boot) \
57 (stream)->Class->set_geom( (stream), (dev), (orig_dev), (media), (boot) )
58 
59 #define GET_DATA(stream, date, size, type, address) \
60 (stream)->Class->get_data( (stream), (date), (size), (type), (address) )
61 
62 #define PRE_ALLOCATE(stream, size) \
63 (stream)->Class->pre_allocate((stream), (size))
64 
65 #define GET_DOSCONVERT(stream)			\
66 	(stream)->Class->get_dosConvert((stream))
67 
68 #define DISCARD(stream)			\
69 	(stream)->Class->discard((stream))
70 
71 int flush_stream(Stream_t *Stream);
72 Stream_t *copy_stream(Stream_t *Stream);
73 int free_stream(Stream_t **Stream);
74 
75 #define FLUSH(stream) \
76 flush_stream( (stream) )
77 
78 #define FREE(stream) \
79 free_stream( (stream) )
80 
81 #define COPY(stream) \
82 copy_stream( (stream) )
83 
84 
85 #define DeclareThis(x) x *This = (x *) Stream
86 
87 int force_write(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
88 int force_read(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
89 
90 int get_data_pass_through(Stream_t *Stream, time_t *date, mt_size_t *size,
91 						  int *type, int *address);
92 
93 int read_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
94 int write_pass_through(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
95 
96 mt_off_t sectorsToBytes(Stream_t *This, off_t off);
97 
98 mt_size_t getfree(Stream_t *Stream);
99 int getfreeMinBytes(Stream_t *Stream, mt_size_t ref);
100 
101 Stream_t *find_device(char drive, int mode, struct device *out_dev,
102 		      union bootsector *boot,
103 		      char *name, int *media, mt_size_t *maxSize,
104 		      int *isRop);
105 
106 #endif
107 
108