Error out if no volumes are specified instead of core-dumping.
[dragonfly.git] / sys / boot / ofw / libofw / ofw_disk.c
blobe04be4ccd4d8e109965ed9f0e161e3f171e737a8
1 /*
2 * Copyright (C) 2000 Benno Rice.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * $FreeBSD$
26 * $DragonFly: src/sys/boot/ofw/libofw/ofw_disk.c,v 1.1 2003/11/10 06:08:37 dillon Exp $
30 * Disk I/O routines using Open Firmware
33 #include <sys/param.h>
35 #include <netinet/in.h>
37 #include <machine/stdarg.h>
39 #include <stand.h>
41 #include "bootstrap.h"
42 #include "libofw.h"
44 static int ofwd_init(void);
45 static int ofwd_strategy(void *devdata, int flag, daddr_t dblk,
46 size_t size, char *buf, size_t *rsize);
47 static int ofwd_open(struct open_file *f, ...);
48 static int ofwd_close(struct open_file *f);
49 static int ofwd_ioctl(struct open_file *f, u_long cmd, void *data);
50 static void ofwd_print(int verbose);
52 struct devsw ofwdisk = {
53 "block",
54 DEVT_DISK,
55 ofwd_init,
56 ofwd_strategy,
57 ofwd_open,
58 ofwd_close,
59 ofwd_ioctl,
60 ofwd_print
63 static int
64 ofwd_init(void)
66 return 0;
69 static int
70 ofwd_strategy(void *devdata, int flag, daddr_t dblk, size_t size, char *buf,
71 size_t *rsize)
73 struct ofw_devdesc *dp = (struct ofw_devdesc *)devdata;
74 unsigned long pos;
75 int n;
76 int i, j;
78 pos = dblk * 512;
79 do {
80 if (OF_seek(dp->d_handle, pos) < 0)
81 return EIO;
82 n = OF_read(dp->d_handle, buf, size);
83 if (n < 0 && n != -2)
84 return EIO;
85 } while (n == -2);
86 *rsize = size;
87 return 0;
90 static int
91 ofwd_open(struct open_file *f, ...)
93 struct ofw_devdesc *dp;
94 phandle_t handle;
95 va_list vl;
97 va_start(vl, f);
98 dp = va_arg(vl, struct ofw_devdesc *);
99 va_end(vl);
100 if ((handle = OF_open(dp->d_path)) == -1) {
101 printf("ofwd_open: Could not open %s\n", dp->d_path);
102 return 1;
104 dp->d_handle = handle;
105 return 0;
108 static int
109 ofwd_close(struct open_file *f)
111 struct ofw_devdesc *dev = f->f_devdata;
113 OF_close(dev->d_handle);
114 return 0;
117 static int
118 ofwd_ioctl(struct open_file *f, u_long cmd, void *data)
121 return (EINVAL);
124 static void
125 ofwd_print(int verbose)