xref: /netbsd-src/sys/arch/ia64/stand/ia64/ski/skifs.c (revision 93b81f4c81fbf76a2df731f1f7732195957c4734)
1 /*	$NetBSD: skifs.c,v 1.4 2009/07/20 04:59:04 kiyohara Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 Doug Rabson
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 /* __FBSDID("$FreeBSD: src/sys/boot/ia64/libski/skifs.c,v 1.2 2003/09/08 09:11:32 obrien Exp $"); */
31 
32 #include <sys/param.h>
33 #include <sys/time.h>
34 #include <lib/libsa/stand.h>
35 #include <lib/libsa/loadfile.h>
36 
37 #include "bootstrap.h"
38 #include "libski.h"
39 
40 struct disk_req {
41 	unsigned long addr;
42 	unsigned len;
43 };
44 
45 struct disk_stat {
46 	int fd;
47 	unsigned count;
48 };
49 
50 int
skifs_open(const char * path,struct open_file * f)51 skifs_open(const char *path, struct open_file *f)
52 {
53 	int fd;
54 
55 	/*
56 	 * Skip leading '/' so that our pretend filesystem starts in
57 	 * the current working directory.
58 	 */
59 	while (*path == '/')
60 		path++;
61 
62 	fd = ssc((u_int64_t) path, 1, 0, 0, SSC_OPEN);
63 
64 	if (fd > 0) {
65 		f->f_fsdata = (void*)(u_int64_t) fd;
66 		return 0;
67 	}
68 	return ENOENT;
69 }
70 
71 int
skifs_close(struct open_file * f)72 skifs_close(struct open_file *f)
73 {
74 	ssc((u_int64_t) f->f_fsdata, 0, 0, 0, SSC_CLOSE);
75 	return 0;
76 }
77 
78 int
skifs_read(struct open_file * f,void * buf,size_t size,size_t * resid)79 skifs_read(struct open_file *f, void *buf, size_t size, size_t *resid)
80 {
81 	struct disk_req req;
82 	struct disk_stat stat;
83 
84 	req.len = size;
85 	req.addr = (u_int64_t) buf;
86 	ssc((u_int64_t) f->f_fsdata, 1, (u_int64_t) &req, f->f_offset, SSC_READ);
87 	stat.fd = (u_int64_t) f->f_fsdata;
88 	ssc((u_int64_t)&stat, 0, 0, 0, SSC_WAIT_COMPLETION);
89 
90 	*resid = size - stat.count;
91 	f->f_offset += stat.count;
92 	return 0;
93 }
94 
95 off_t
skifs_seek(struct open_file * f,off_t offset,int where)96 skifs_seek(struct open_file *f, off_t offset, int where)
97 {
98 	u_int64_t base;
99 
100 	switch (where) {
101 	case SEEK_SET:
102 		base = 0;
103 		break;
104 
105 	case SEEK_CUR:
106 		base = f->f_offset;
107 		break;
108 
109 	case SEEK_END:
110 		printf("can't find end of file in SKI\n");
111 		base = f->f_offset;
112 		break;
113 	}
114 
115 	f->f_offset = base + offset;
116 	return base;
117 }
118 
119 int
skifs_stat(struct open_file * f,struct stat * sb)120 skifs_stat(struct open_file *f, struct stat *sb)
121 {
122 	memset(sb, 0, sizeof(*sb));
123 	sb->st_mode = S_IFREG | S_IRUSR;
124 	return 0;
125 }
126 
127 int
skifs_readdir(struct open_file * f,struct dirent * d)128 skifs_readdir(struct open_file *f, struct dirent *d)
129 {
130 	return ENOENT;
131 }
132 
133 int
skifs_dev_init(void)134 skifs_dev_init(void)
135 {
136 	return 0;
137 }
138 
139 /*
140  * Print information about disks
141  */
142 void
skifs_dev_print(int verbose)143 skifs_dev_print(int verbose)
144 {
145 }
146 
147 /*
148  * Attempt to open the disk described by (dev) for use by (f).
149  *
150  * Note that the philosophy here is "give them exactly what
151  * they ask for".  This is necessary because being too "smart"
152  * about what the user might want leads to complications.
153  * (eg. given no slice or partition value, with a disk that is
154  *  sliced - are they after the first BSD slice, or the DOS
155  *  slice before it?)
156  */
157 int
skifs_dev_open(struct open_file * f,...)158 skifs_dev_open(struct open_file *f, ...)
159 {
160 	return 0;
161 }
162 
163 int
skifs_dev_close(struct open_file * f)164 skifs_dev_close(struct open_file *f)
165 {
166 
167 	return 0;
168 }
169 
170 int
skifs_dev_strategy(void * devdata,int rw,daddr_t dblk,size_t size,void * buf,size_t * rsize)171 skifs_dev_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize)
172 {
173 	return 0;
174 }
175 
176