1 /* $NetBSD: riscosdisk.c,v 1.2 2006/04/01 19:08:08 bjh21 Exp $ */
4 * Copyright (c) 2001, 2006 Ben Harris
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.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/disklabel.h>
33 #include <lib/libsa/stand.h>
34 #include <riscoscalls.h>
35 #include <riscosdisk.h>
36 #include <riscospart.h>
38 #include <machine/stdarg.h>
47 rodisk_getprivateword(char const *fsname
)
53 /* XXX The %c dance is because libsa printf can't do %% */
54 snprintf(module
, sizeof(module
), "FileCore%c%s", '%', fsname
);
55 err
= xosmodule_lookup(module
, NULL
, NULL
, NULL
, &privword
, NULL
);
62 rodisk_open(struct open_file
*f
, ... /* char const *fsname, int drive,
68 int drive
, partition
, nfd
, nhd
, err
;
69 struct riscosdisk
*rd
;
73 fsname
= va_arg(ap
, char const *);
74 drive
= va_arg(ap
, int);
75 partition
= va_arg(ap
, int);
78 if ((privword
= rodisk_getprivateword(fsname
)) == NULL
)
80 if (xfilecore_drives(&privword
, NULL
, &nfd
, &nhd
) != NULL
)
83 (drive
< 4 && drive
>= nfd
) ||
87 rd
= alloc(sizeof(*rd
));
88 rd
->privword
= privword
;
92 if (partition
!= RAW_PART
) {
93 err
= getdisklabel_acorn(f
, &dl
);
95 dealloc(rd
, sizeof(*rd
));
98 if (partition
>= dl
.d_npartitions
||
99 dl
.d_partitions
[partition
].p_size
== 0) {
100 dealloc(rd
, sizeof(*rd
));
103 rd
->boff
= dl
.d_partitions
[partition
].p_offset
;
109 rodisk_close(struct open_file
*f
)
111 struct riscosdisk
*rd
= f
->f_devdata
;
113 dealloc(rd
, sizeof *rd
);
118 rodisk_strategy(void *devdata
, int flag
, daddr_t dblk
, size_t size
,
119 void *buf
, size_t *rsize
)
121 struct riscosdisk
*rd
= devdata
;
123 uint32_t daddr
, ndaddr
;
132 if (rsize
) *rsize
= 0;
133 if (dblk
< 1 << (29 - DEV_BSHIFT
)) {
134 daddr
= (dblk
* DEV_BSIZE
) | (rd
->drive
<< 29);
135 if ((err
= xfilecorediscop_read_sectors(0, daddr
, buf
, size
,
136 &rd
->privword
, &ndaddr
, &nbuf
, &resid
)) != NULL
)
138 } else if (dblk
< 1 << 29) {
139 daddr
= dblk
| (rd
->drive
<< 29);
140 if ((err
= xfilecoresectorop_read_sectors(0, daddr
, buf
, size
,
141 &rd
->privword
, &ndaddr
, &nbuf
, &resid
)) != NULL
)
143 } else if (dblk
< 1LL << (64 - DEV_BSHIFT
)){
144 struct filecore_daddr64 daddr64
;
145 daddr64
.drive
= rd
->drive
;
146 daddr64
.daddr
= dblk
* DEV_BSIZE
;
147 if ((err
= xfilecorediscop64_read_sectors(0, &daddr64
, buf
,
148 size
, NULL
, &rd
->privword
, &ndaddr
, &nbuf
, &resid
)) !=
154 *rsize
= size
- resid
;
157 printf("Error: %s\n", err
->errmess
);