1 /* Copyright 2021 Alain Knaff.
2 * This file is part of mtools.
4 * Mtools is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Mtools is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
17 * filter to support filesystems stored at an offset into their image
20 #include "sysincludes.h"
24 typedef struct Offset_t {
30 static ssize_t offset_pread(Stream_t *Stream, char *buf,
31 mt_off_t start, size_t len)
33 DeclareThis(Offset_t);
34 return PREADS(This->head.Next, buf, start+This->offset, len);
37 static ssize_t offset_pwrite(Stream_t *Stream, char *buf,
38 mt_off_t start, size_t len)
40 DeclareThis(Offset_t);
41 return PWRITES(This->head.Next, buf, start+This->offset, len);
44 static Class_t OffsetClass = {
51 set_geom_pass_through, /* set_geom */
54 get_dosConvert_pass_through, /* dos convert */
58 Stream_t *OpenOffset(Stream_t *Next, struct device *dev, off_t offset,
59 char *errmsg, mt_off_t *maxSize) {
67 memset((void*)This, 0, sizeof(Offset_t));
68 init_head(&This->head, &OffsetClass, Next);
70 This->offset = offset;
73 if(This->offset > *maxSize) {
75 sprintf(errmsg,"init: Big disks not supported");
79 *maxSize -= This->offset;
82 if(adjust_tot_sectors(dev, This->offset, errmsg) < 0)