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