blob: 66dd0ed122531c4d94d29a4eb6493404472924b2 [file] [log] [blame]
Alistair Delvabeaee832021-02-24 11:27:23 -08001#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
21typedef struct Stream_t {
22 struct Class_t *Class;
23 int refs;
24 struct Stream_t *Next;
Alistair Delvabeaee832021-02-24 11:27:23 -080025} Stream_t;
26
27#include "mtools.h"
28#include "msdos.h"
Yi Kong39bbd962022-01-09 19:41:38 +080029#include "device.h"
Alistair Delvabeaee832021-02-24 11:27:23 -080030#include "llong.h"
31
Yi Kong39bbd962022-01-09 19:41:38 +080032void limitSizeToOffT(size_t *len, mt_off_t maxLen);
33
Alistair Delvabeaee832021-02-24 11:27:23 -080034doscp_t *get_dosConvert_pass_through(Stream_t *Stream);
35
36typedef struct Class_t {
Yi Kong39bbd962022-01-09 19:41:38 +080037 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);
Alistair Delvabeaee832021-02-24 11:27:23 -080041 int (*flush)(Stream_t *);
42 int (*freeFunc)(Stream_t *);
Yi Kong39bbd962022-01-09 19:41:38 +080043 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);
Alistair Delvabeaee832021-02-24 11:27:23 -080046
47 doscp_t *(*get_dosConvert)(Stream_t *);
48
49 int (*discard)(Stream_t *);
50} Class_t;
51
Yi Kong39bbd962022-01-09 19:41:38 +080052#define READS(stream, buf, size) \
53((stream)->Class->read)( (stream), (char *) (buf), (size) )
Alistair Delvabeaee832021-02-24 11:27:23 -080054
Yi Kong39bbd962022-01-09 19:41:38 +080055#define WRITES(stream, buf, size) \
56((stream)->Class->write)( (stream), (char *) (buf), (size) )
Alistair Delvabeaee832021-02-24 11:27:23 -080057
Yi Kong39bbd962022-01-09 19:41:38 +080058#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))
Alistair Delvabeaee832021-02-24 11:27:23 -080066
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
79int flush_stream(Stream_t *Stream);
80Stream_t *copy_stream(Stream_t *Stream);
81int free_stream(Stream_t **Stream);
82
83#define FLUSH(stream) \
84flush_stream( (stream) )
85
86#define FREE(stream) \
87free_stream( (stream) )
88
89#define COPY(stream) \
90copy_stream( (stream) )
91
92
93#define DeclareThis(x) x *This = (x *) Stream
94
Yi Kong39bbd962022-01-09 19:41:38 +080095void init_head(Stream_t *Stream, struct Class_t *Class, Stream_t *Next);
Alistair Delvabeaee832021-02-24 11:27:23 -080096
Yi Kong39bbd962022-01-09 19:41:38 +080097ssize_t force_pwrite(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
98ssize_t force_pread(Stream_t *Stream, char *buf, mt_off_t start, size_t len);
Alistair Delvabeaee832021-02-24 11:27:23 -080099
Yi Kong39bbd962022-01-09 19:41:38 +0800100ssize_t force_write(Stream_t *Stream, char *buf, size_t len);
Alistair Delvabeaee832021-02-24 11:27:23 -0800101
Yi Kong39bbd962022-01-09 19:41:38 +0800102int set_geom_pass_through(Stream_t *Stream, device_t *dev, device_t *orig_dev);
Alistair Delvabeaee832021-02-24 11:27:23 -0800103
Yi Kong39bbd962022-01-09 19:41:38 +0800104int set_geom_noop(Stream_t *Stream, device_t *dev, device_t *orig_dev);
105
106int get_data_pass_through(Stream_t *Stream, time_t *date, mt_off_t *size,
107 int *type, uint32_t *address);
108
109ssize_t pread_pass_through(Stream_t *Stream, char *buf,
110 mt_off_t start, size_t len);
111ssize_t pwrite_pass_through(Stream_t *Stream, char *buf,
112 mt_off_t start, size_t len);
113
114mt_off_t getfree(Stream_t *Stream);
115int getfreeMinBytes(Stream_t *Stream, mt_off_t ref);
Alistair Delvabeaee832021-02-24 11:27:23 -0800116
117Stream_t *find_device(char drive, int mode, struct device *out_dev,
118 union bootsector *boot,
Yi Kong39bbd962022-01-09 19:41:38 +0800119 char *name, int *media, mt_off_t *maxSize,
Alistair Delvabeaee832021-02-24 11:27:23 -0800120 int *isRop);
121
Yi Kong39bbd962022-01-09 19:41:38 +0800122int adjust_tot_sectors(struct device *dev, mt_off_t offset, char *errmsg);
123
Alistair Delvabeaee832021-02-24 11:27:23 -0800124#endif
125