1 #ifndef MTOOLS_STREAM_H
2 #define MTOOLS_STREAM_H
4 /* Copyright 1996-1999,2001,2002,2005,2006,2008,2009,2011 Alain Knaff.
5 * This file is part of mtools.
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.
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.
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/>.
21 typedef struct Stream_t {
22 struct Class_t *Class;
24 struct Stream_t *Next;
31 void limitSizeToOffT(size_t *len, mt_off_t maxLen);
33 doscp_t *get_dosConvert_pass_through(Stream_t *Stream);
35 typedef struct Class_t {
36 ssize_t (*read)(Stream_t *, char *, size_t);
37 ssize_t (*write)(Stream_t *, char *, size_t);
38 ssize_t (*pread)(Stream_t *, char *, mt_off_t, size_t);
39 ssize_t (*pwrite)(Stream_t *, char *, mt_off_t, size_t);
40 int (*flush)(Stream_t *);
41 int (*freeFunc)(Stream_t *);
42 int (*set_geom)(Stream_t *, device_t *, device_t *);
43 int (*get_data)(Stream_t *, time_t *, mt_off_t *, int *, uint32_t *);
44 int (*pre_allocate)(Stream_t *, mt_off_t);
46 doscp_t *(*get_dosConvert)(Stream_t *);
48 int (*discard)(Stream_t *);
51 #define READS(stream, buf, size) \
52 ((stream)->Class->read)( (stream), (char *) (buf), (size) )
54 #define WRITES(stream, buf, size) \
55 ((stream)->Class->write)( (stream), (char *) (buf), (size) )
57 #define PREADS(stream, buf, address, size) \
58 ((stream)->Class->pread)( (stream), (char *) (buf), (address), (size) )
60 #define PWRITES(stream, buf, address, size) \
61 ((stream)->Class->pwrite)( (stream), (char *) (buf), (address), (size) )
63 #define SET_GEOM(stream, dev, orig_dev) \
64 (stream)->Class->set_geom( (stream), (dev), (orig_dev))
66 #define GET_DATA(stream, date, size, type, address) \
67 (stream)->Class->get_data( (stream), (date), (size), (type), (address) )
69 #define PRE_ALLOCATE(stream, size) \
70 (stream)->Class->pre_allocate((stream), (size))
72 #define GET_DOSCONVERT(stream) \
73 (stream)->Class->get_dosConvert((stream))
75 #define DISCARD(stream) \
76 (stream)->Class->discard((stream))
78 int flush_stream(Stream_t *Stream);
79 Stream_t *copy_stream(Stream_t *Stream);
80 int free_stream(Stream_t **Stream);
82 #define FLUSH(stream) \
83 flush_stream( (stream) )
85 #define FREE(stream) \
86 free_stream( (stream) )
88 #define COPY(stream) \
89 copy_stream( (stream) )
92 #define DeclareThis(x) x *This = (x *) Stream
94 void init_head(Stream_t *Stream, struct Class_t *Class, Stream_t *Next);
96 ssize_t force_pwrite(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
97 ssize_t force_pread(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
99 ssize_t force_write(Stream_t *Stream, char *buf, size_t len);
101 int set_geom_pass_through(Stream_t *Stream, device_t *dev, device_t *orig_dev);
103 int set_geom_noop(Stream_t *Stream, device_t *dev, device_t *orig_dev);
105 int get_data_pass_through(Stream_t *Stream, time_t *date, mt_off_t *size,
106 int *type, uint32_t *address);
108 ssize_t pread_pass_through(Stream_t *Stream, char *buf,
109 mt_off_t start, size_t len);
110 ssize_t pwrite_pass_through(Stream_t *Stream, char *buf,
111 mt_off_t start, size_t len);
113 mt_off_t getfree(Stream_t *Stream);
114 int getfreeMinBytes(Stream_t *Stream, mt_off_t ref);
116 int adjust_tot_sectors(struct device *dev, mt_off_t offset, char *errmsg);
118 Stream_t *open_root_dir(char drivename, int flags, int *isRop);