xref: /netbsd/sys/arch/macppc/stand/ofwboot/hfs.c (revision bf9ec67e)
1 /*	$NetBSD: hfs.c,v 1.2 2001/07/22 11:29:48 wiz Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/param.h>
30 #include <lib/libkern/libkern.h>
31 #include <lib/libsa/stand.h>
32 
33 #include <openfirm.h>
34 #include <hfs.h>
35 
36 static int OF_fd;	/* XXX */
37 
38 int
39 hfs_open(path, f)
40 	char *path;
41 	struct open_file *f;
42 {
43 	int chosen;
44 	char bootpath[128], *cp;
45 
46 	if ((chosen = OF_finddevice("/chosen")) == -1)
47 		return ENXIO;
48 	memset(bootpath, 0, sizeof bootpath);
49 	OF_getprop(chosen, "bootpath", bootpath, sizeof bootpath);
50 	cp = strrchr(bootpath, ',');
51 	if (cp == NULL)
52 		return ENXIO;
53 
54 	strcpy(cp + 1, path);
55 	OF_fd = OF_open(bootpath);
56 	if (OF_fd == -1)
57 		return ENOENT;
58 
59 	return 0;
60 }
61 
62 int
63 hfs_close(f)
64 	struct open_file *f;
65 {
66 	OF_close(OF_fd);
67 	return 0;
68 }
69 
70 int
71 hfs_read(f, start, size, resid)
72 	struct open_file *f;
73 	void *start;
74 	size_t size, *resid;
75 {
76 	int len;
77 
78 	len = OF_read(OF_fd, start, size);
79 	size -= len;
80 	if (resid)
81 		*resid = size;
82 	return 0;
83 }
84 
85 int
86 hfs_write(f, start, size, resid)
87 	struct open_file *f;
88 	void *start;
89 	size_t size, *resid;
90 {
91 	printf("hfs_write\n");
92 	return ENXIO;
93 }
94 
95 off_t
96 hfs_seek(f, offset, where)
97 	struct open_file *f;
98 	off_t offset;
99 	int where;
100 {
101 	switch (where) {
102 	case SEEK_SET:
103 		return OF_seek(OF_fd, offset);
104 	case SEEK_CUR:
105 	case SEEK_END:
106 	default:
107 		return -1;
108 	}
109 }
110 
111 int
112 hfs_stat(f, sb)
113 	struct open_file *f;
114 	struct stat *sb;
115 {
116 	return 0;
117 }
118