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