• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 } Stream_t;
26 
27 #include "mtools.h"
28 #include "msdos.h"
29 #include "device.h"
30 #include "llong.h"
31 
32 void limitSizeToOffT(size_t *len, mt_off_t maxLen);
33 
34 doscp_t *get_dosConvert_pass_through(Stream_t *Stream);
35 
36 typedef struct Class_t {
37 	ssize_t (*read)(Stream_t *, char *, size_t);
38 	ssize_t (*write)(Stream_t *, char *, size_t);
39 	ssize_t (*pread)(Stream_t *, char *, mt_off_t, size_t);
40 	ssize_t (*pwrite)(Stream_t *, char *, mt_off_t, size_t);
41 	int (*flush)(Stream_t *);
42 	int (*freeFunc)(Stream_t *);
43 	int (*set_geom)(Stream_t *, device_t *, device_t *);
44 	int (*get_data)(Stream_t *, time_t *, mt_off_t *, int *, uint32_t *);
45 	int (*pre_allocate)(Stream_t *, mt_off_t);
46 
47 	doscp_t *(*get_dosConvert)(Stream_t *);
48 
49 	int (*discard)(Stream_t *);
50 } Class_t;
51 
52 #define READS(stream, buf, size) \
53 ((stream)->Class->read)( (stream), (char *) (buf), (size) )
54 
55 #define WRITES(stream, buf, size) \
56 ((stream)->Class->write)( (stream), (char *) (buf), (size) )
57 
58 #define PREADS(stream, buf, address, size) \
59 ((stream)->Class->pread)( (stream), (char *) (buf), (address), (size) )
60 
61 #define PWRITES(stream, buf, address, size) \
62 ((stream)->Class->pwrite)( (stream), (char *) (buf), (address), (size) )
63 
64 #define SET_GEOM(stream, dev, orig_dev) \
65 (stream)->Class->set_geom( (stream), (dev), (orig_dev))
66 
67 #define GET_DATA(stream, date, size, type, address) \
68 (stream)->Class->get_data( (stream), (date), (size), (type), (address) )
69 
70 #define PRE_ALLOCATE(stream, size) \
71 (stream)->Class->pre_allocate((stream), (size))
72 
73 #define GET_DOSCONVERT(stream)			\
74 	(stream)->Class->get_dosConvert((stream))
75 
76 #define DISCARD(stream)			\
77 	(stream)->Class->discard((stream))
78 
79 int flush_stream(Stream_t *Stream);
80 Stream_t *copy_stream(Stream_t *Stream);
81 int free_stream(Stream_t **Stream);
82 
83 #define FLUSH(stream) \
84 flush_stream( (stream) )
85 
86 #define FREE(stream) \
87 free_stream( (stream) )
88 
89 #define COPY(stream) \
90 copy_stream( (stream) )
91 
92 
93 #define DeclareThis(x) x *This = (x *) Stream
94 
95 void init_head(Stream_t *Stream, struct Class_t *Class, Stream_t *Next);
96 
97 ssize_t force_pwrite(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
98 ssize_t force_pread(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
99 
100 ssize_t force_write(Stream_t *Stream, char *buf, size_t len);
101 
102 int set_geom_pass_through(Stream_t *Stream, device_t *dev, device_t *orig_dev);
103 
104 int set_geom_noop(Stream_t *Stream, device_t *dev, device_t *orig_dev);
105 
106 int get_data_pass_through(Stream_t *Stream, time_t *date, mt_off_t *size,
107 			  int *type, uint32_t *address);
108 
109 ssize_t pread_pass_through(Stream_t *Stream, char *buf,
110 			   mt_off_t start, size_t len);
111 ssize_t pwrite_pass_through(Stream_t *Stream, char *buf,
112 			    mt_off_t start, size_t len);
113 
114 mt_off_t getfree(Stream_t *Stream);
115 int getfreeMinBytes(Stream_t *Stream, mt_off_t ref);
116 
117 Stream_t *find_device(char drive, int mode, struct device *out_dev,
118 		      union bootsector *boot,
119 		      char *name, int *media, mt_off_t *maxSize,
120 		      int *isRop);
121 
122 int adjust_tot_sectors(struct device *dev, mt_off_t offset, char *errmsg);
123 
124 #endif
125 
126