diskio.c revision 1.8.80.1 1 1.8.80.1 thorpej /* $NetBSD: diskio.c,v 1.8.80.1 2021/06/17 04:46:19 thorpej Exp $ */
2 1.1 leo
3 1.1 leo /*
4 1.1 leo * Copyright (c) 1995 Waldi Ravens.
5 1.1 leo * All rights reserved.
6 1.1 leo *
7 1.1 leo * Redistribution and use in source and binary forms, with or without
8 1.1 leo * modification, are permitted provided that the following conditions
9 1.1 leo * are met:
10 1.1 leo * 1. Redistributions of source code must retain the above copyright
11 1.1 leo * notice, this list of conditions and the following disclaimer.
12 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 leo * notice, this list of conditions and the following disclaimer in the
14 1.1 leo * documentation and/or other materials provided with the distribution.
15 1.1 leo * 3. All advertising materials mentioning features or use of this software
16 1.1 leo * must display the following acknowledgement:
17 1.1 leo * This product includes software developed by Waldi Ravens.
18 1.1 leo * 4. The name of the author may not be used to endorse or promote products
19 1.1 leo * derived from this software without specific prior written permission
20 1.1 leo *
21 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 leo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 leo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 leo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 leo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 leo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 leo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 leo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 leo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 leo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 leo */
32 1.1 leo
33 1.3 junyoung #include <lib/libsa/stand.h>
34 1.2 leo #include "atari_stand.h"
35 1.1 leo #include <sys/disklabel.h>
36 1.1 leo
37 1.8.80.1 thorpej #include <lib/libkern/libkern.h>
38 1.8.80.1 thorpej
39 1.6 dsl typedef int (*rdsec_f)(void *buffer, u_int offset, u_int count);
40 1.1 leo typedef struct { rdsec_f rds; u_int rst; u_int rend; } bdevd_t;
41 1.1 leo
42 1.6 dsl static int rootstrategy(void *, int, daddr_t, size_t, void *, size_t *);
43 1.6 dsl static int rootopen(struct open_file *, ...);
44 1.6 dsl static int rootclose(struct open_file *);
45 1.6 dsl static int rootioctl(struct open_file *, u_long, void *);
46 1.1 leo
47 1.5 mhitch struct devsw devsw[] = {
48 1.1 leo { "root", rootstrategy, rootopen, rootclose, rootioctl }
49 1.1 leo };
50 1.1 leo static bdevd_t bootdev;
51 1.1 leo
52 1.1 leo /*
53 1.1 leo * Initialise boot device info.
54 1.1 leo */
55 1.1 leo int
56 1.7 dsl init_dskio (void *func, void *label, int root)
57 1.1 leo {
58 1.1 leo struct disklabel *dl = label;
59 1.1 leo struct partition *pd = &dl->d_partitions[root];
60 1.1 leo
61 1.1 leo if (dl->d_magic != DISKMAGIC || dl->d_magic2 != DISKMAGIC
62 1.1 leo || dl->d_npartitions > MAXPARTITIONS || dkcksum(dl) != 0) {
63 1.1 leo printf("Invalid disk label.\n");
64 1.1 leo return(-1);
65 1.1 leo }
66 1.1 leo if (root >= 0) {
67 1.1 leo if (root >= dl->d_npartitions
68 1.1 leo || pd->p_fstype != FS_BSDFFS || pd->p_size == 0) {
69 1.1 leo printf("No suitable root.\n");
70 1.1 leo return(-1);
71 1.1 leo }
72 1.1 leo bootdev.rds = func;
73 1.1 leo bootdev.rst = pd->p_offset;
74 1.1 leo bootdev.rend = pd->p_offset + pd->p_size - 1;
75 1.1 leo }
76 1.1 leo return(0);
77 1.1 leo }
78 1.1 leo
79 1.1 leo /*
80 1.1 leo * No choice, the kernel is loaded from the
81 1.1 leo * same device as the bootstrap.
82 1.1 leo */
83 1.1 leo int
84 1.7 dsl devopen (struct open_file *f, const char *fname, char **file)
85 1.1 leo {
86 1.1 leo f->f_devdata = &bootdev;
87 1.1 leo f->f_dev = &devsw[0];
88 1.1 leo *file = (char *)fname;
89 1.1 leo return(0);
90 1.1 leo }
91 1.1 leo
92 1.1 leo static int
93 1.7 dsl rootstrategy (void *devd, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize)
94 1.1 leo {
95 1.1 leo bdevd_t *dd = devd;
96 1.1 leo daddr_t stb = dd->rst + dblk;
97 1.1 leo size_t nb = size >> 9;
98 1.1 leo
99 1.1 leo if ((flag == F_READ) && !(size & 511) && (stb + nb <= dd->rend)) {
100 1.1 leo if (!dd->rds(buf, stb, nb)) {
101 1.1 leo *rsize = size;
102 1.1 leo return(0);
103 1.1 leo }
104 1.1 leo }
105 1.1 leo *rsize = 0;
106 1.1 leo return(EIO);
107 1.1 leo }
108 1.1 leo
109 1.1 leo static int
110 1.8 he rootopen (struct open_file *f, ...)
111 1.1 leo {
112 1.1 leo return(0);
113 1.1 leo }
114 1.1 leo
115 1.1 leo static int
116 1.7 dsl rootclose (struct open_file *f)
117 1.1 leo {
118 1.1 leo return(EIO);
119 1.1 leo }
120 1.1 leo
121 1.1 leo static int
122 1.7 dsl rootioctl (struct open_file *f, u_long cmd, void *data)
123 1.1 leo {
124 1.1 leo return(EIO);
125 1.1 leo }
126