1 /* $NetBSD: dosfile.c,v 1.16 2013/10/20 21:06:37 christos Exp $ */
5 * Matthias Drochner. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * DOS filesystem for libsa
31 * standalone - uses no device, works only with DOS running
32 * needs lowlevel parts from dos_file.S
35 #include <lib/libsa/stand.h>
40 extern int dosopen(const char *);
41 extern void dosclose(int);
42 extern int dosread(int, char *, int);
43 extern int dosseek(int, int, int);
49 extern int doserrno
; /* in dos_file.S */
51 static int dos2errno(void);
76 dos_open(const char *path
, struct open_file
*f
)
80 df
= (struct dosfile
*) alloc(sizeof(*df
));
85 df
->doshandle
= dosopen(path
);
86 if (df
->doshandle
< 0) {
88 printf("DOS error %d\n", doserrno
);
90 dealloc(df
, sizeof(*df
));
93 f
->f_fsdata
= (void *) df
;
98 dos_read(struct open_file
*f
, void *addr
, size_t size
, size_t *resid
)
104 df
= (struct dosfile
*) f
->f_fsdata
;
109 if ((unsigned long) addr
>= 0x10000) {
119 if (tsize
> DISKBUFSIZE
)
122 alloc_diskbuf(dos_read
);
124 tgot
= dosread(df
->doshandle
, diskbufp
, tsize
);
127 printf("DOS error %d\n", doserrno
);
131 memcpy(p
, diskbufp
, tgot
);
141 got
= dosread(df
->doshandle
, addr
, size
);
145 printf("DOS error %d\n", doserrno
);
160 dos_close(struct open_file
*f
)
163 df
= (struct dosfile
*) f
->f_fsdata
;
165 dosclose(df
->doshandle
);
168 dealloc(df
, sizeof(*df
));
173 dos_write(struct open_file
*f
, void *start
, size_t size
, size_t *resid
)
179 dos_stat(struct open_file
*f
, struct stat
*sb
)
190 dos_seek(struct open_file
*f
, off_t offset
, int where
)
197 df
= (struct dosfile
*) f
->f_fsdata
;
203 checkoffs
= offset
; /* don't trust DOS */
209 checkoffs
= df
->off
+ offset
;
215 checkoffs
= -1; /* we dont know len */
222 res
= dosseek(df
->doshandle
, offset
, doswhence
);
228 if ((checkoffs
!= -1) && (res
!= checkoffs
)) {
229 printf("dosfile: unexpected seek result (%d+%d(%d)=%d)\n",
230 df
->off
, offset
, where
, res
);