Imported Upstream version 4.0.43
[platform/upstream/mtools.git] / stream.h
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 "device.h"
29 #include "llong.h"
30
31 void limitSizeToOffT(size_t *len, mt_off_t maxLen);
32
33 doscp_t *get_dosConvert_pass_through(Stream_t *Stream);
34
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);
45
46         doscp_t *(*get_dosConvert)(Stream_t *);
47
48         int (*discard)(Stream_t *);
49 } Class_t;
50
51 #define READS(stream, buf, size) \
52 ((stream)->Class->read)( (stream), (char *) (buf), (size) )
53
54 #define WRITES(stream, buf, size) \
55 ((stream)->Class->write)( (stream), (char *) (buf), (size) )
56
57 #define PREADS(stream, buf, address, size) \
58 ((stream)->Class->pread)( (stream), (char *) (buf), (address), (size) )
59
60 #define PWRITES(stream, buf, address, size) \
61 ((stream)->Class->pwrite)( (stream), (char *) (buf), (address), (size) )
62
63 #define SET_GEOM(stream, dev, orig_dev) \
64 (stream)->Class->set_geom( (stream), (dev), (orig_dev))
65
66 #define GET_DATA(stream, date, size, type, address) \
67 (stream)->Class->get_data( (stream), (date), (size), (type), (address) )
68
69 #define PRE_ALLOCATE(stream, size) \
70 (stream)->Class->pre_allocate((stream), (size))
71
72 #define GET_DOSCONVERT(stream)                  \
73         (stream)->Class->get_dosConvert((stream))
74
75 #define DISCARD(stream)                 \
76         (stream)->Class->discard((stream))
77
78 int flush_stream(Stream_t *Stream);
79 Stream_t *copy_stream(Stream_t *Stream);
80 int free_stream(Stream_t **Stream);
81
82 #define FLUSH(stream) \
83 flush_stream( (stream) )
84
85 #define FREE(stream) \
86 free_stream( (stream) )
87
88 #define COPY(stream) \
89 copy_stream( (stream) )
90
91
92 #define DeclareThis(x) x *This = (x *) Stream
93
94 void init_head(Stream_t *Stream, struct Class_t *Class, Stream_t *Next);
95
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);
98
99 ssize_t force_write(Stream_t *Stream, char *buf, size_t len);
100
101 int set_geom_pass_through(Stream_t *Stream, device_t *dev, device_t *orig_dev);
102
103 int set_geom_noop(Stream_t *Stream, device_t *dev, device_t *orig_dev);
104
105 int get_data_pass_through(Stream_t *Stream, time_t *date, mt_off_t *size,
106                           int *type, uint32_t *address);
107
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);
112
113 mt_off_t getfree(Stream_t *Stream);
114 int getfreeMinBytes(Stream_t *Stream, mt_off_t ref);
115
116 int adjust_tot_sectors(struct device *dev, mt_off_t offset, char *errmsg);
117
118 Stream_t *open_root_dir(char drivename, int flags, int *isRop);
119
120 #endif