summaryrefslogtreecommitdiffstats
path: root/sys/boot/ia64/ski/skifs.c
blob: 5a272c74563a254e4cae45a7f210f57e9337d34c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*-
 * Copyright (c) 2001 Doug Rabson
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/time.h>
#include <stddef.h>
#include <stand.h>
#include <stdarg.h>

#include "libski.h"

struct disk_req {
	unsigned long addr;
	unsigned len;
};

struct disk_stat {
	int fd;
	unsigned count;
};

static int
skifs_open(const char *path, struct open_file *f)
{
	int fd;

	/*
	 * Skip leading '/' so that our pretend filesystem starts in
	 * the current working directory.
	 */
	while (*path == '/')
		path++;

	fd = ssc((u_int64_t) path, 1, 0, 0, SSC_OPEN);
	if (fd > 0) {
		f->f_fsdata = (void*)(u_int64_t) fd;
		return 0;
	}
	return ENOENT;
}

static int
skifs_close(struct open_file *f)
{
	ssc((u_int64_t) f->f_fsdata, 0, 0, 0, SSC_CLOSE);
	return 0;
}

static int
skifs_read(struct open_file *f, void *buf, size_t size, size_t *resid)
{
	struct disk_req req;
	struct disk_stat stat;

	req.len = size;
	req.addr = (u_int64_t) buf;
	ssc((u_int64_t) f->f_fsdata, 1, (u_int64_t) &req, f->f_offset, SSC_READ);
	stat.fd = (u_int64_t) f->f_fsdata;
	ssc((u_int64_t)&stat, 0, 0, 0, SSC_WAIT_COMPLETION);

	*resid = size - stat.count;
	f->f_offset += stat.count;
	return 0;
}

static off_t
skifs_seek(struct open_file *f, off_t offset, int where)
{
	u_int64_t base;

	switch (where) {
	case SEEK_SET:
		base = 0;
		break;

	case SEEK_CUR:
		base = f->f_offset;
		break;

	case SEEK_END:
		printf("can't find end of file in SKI\n");
		base = f->f_offset;
		break;
	}

	f->f_offset = base + offset;
	return base;
}

static int
skifs_stat(struct open_file *f, struct stat *sb)
{
	bzero(sb, sizeof(*sb));
	sb->st_mode = S_IFREG | S_IRUSR;
	return 0;
}

static int
skifs_readdir(struct open_file *f, struct dirent *d)
{
	return ENOENT;
}

struct fs_ops ski_fsops = {
	"fs",
	skifs_open,
	skifs_close,
	skifs_read,
	null_write,
	skifs_seek,
	skifs_stat,
	skifs_readdir
};

static int
skifs_dev_init(void) 
{
	return 0;
}

/*
 * Print information about disks
 */
static void
skifs_dev_print(int verbose)
{
}

/*
 * Attempt to open the disk described by (dev) for use by (f).
 *
 * Note that the philosophy here is "give them exactly what
 * they ask for".  This is necessary because being too "smart"
 * about what the user might want leads to complications.
 * (eg. given no slice or partition value, with a disk that is
 *  sliced - are they after the first BSD slice, or the DOS
 *  slice before it?)
 */
static int 
skifs_dev_open(struct open_file *f, ...)
{
	return 0;
}

static int 
skifs_dev_close(struct open_file *f)
{

	return 0;
}

static int 
skifs_dev_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize)
{
	return 0;
}

struct devsw skifs_dev = {
	"fs", 
	DEVT_DISK, 
	skifs_dev_init,
	skifs_dev_strategy, 
	skifs_dev_open, 
	skifs_dev_close, 
	noioctl,
	skifs_dev_print
};
OpenPOWER on IntegriCloud