skifs.c revision 256281
1249259Sdim/*- 2249259Sdim * Copyright (c) 2001 Doug Rabson 3249259Sdim * All rights reserved. 4249259Sdim * 5249259Sdim * Redistribution and use in source and binary forms, with or without 6249259Sdim * modification, are permitted provided that the following conditions 7249259Sdim * are met: 8249259Sdim * 1. Redistributions of source code must retain the above copyright 9249259Sdim * notice, this list of conditions and the following disclaimer. 10249259Sdim * 2. Redistributions in binary form must reproduce the above copyright 11249259Sdim * notice, this list of conditions and the following disclaimer in the 12249259Sdim * documentation and/or other materials provided with the distribution. 13249259Sdim * 14249259Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15249259Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16249259Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17249259Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18249259Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19249259Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20249259Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21249259Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22249259Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23249259Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24249259Sdim * SUCH DAMAGE. 25249259Sdim */ 26249259Sdim 27249259Sdim#include <sys/cdefs.h> 28249259Sdim__FBSDID("$FreeBSD: stable/10/sys/boot/ia64/ski/skifs.c 164010 2006-11-05 22:03:04Z marcel $"); 29249259Sdim 30249259Sdim#include <sys/param.h> 31249259Sdim#include <sys/time.h> 32249259Sdim#include <stddef.h> 33249259Sdim#include <stand.h> 34249259Sdim#include <stdarg.h> 35249259Sdim 36249259Sdim#include <bootstrap.h> 37249259Sdim#include "libski.h" 38249259Sdim 39249259Sdimstruct disk_req { 40249259Sdim unsigned long addr; 41249259Sdim unsigned len; 42249259Sdim}; 43249259Sdim 44249259Sdimstruct disk_stat { 45249259Sdim int fd; 46249259Sdim unsigned count; 47249259Sdim}; 48249259Sdim 49static int 50skifs_open(const char *path, struct open_file *f) 51{ 52 int fd; 53 54 /* 55 * Skip leading '/' so that our pretend filesystem starts in 56 * the current working directory. 57 */ 58 while (*path == '/') 59 path++; 60 61 fd = ssc((u_int64_t) path, 1, 0, 0, SSC_OPEN); 62 if (fd > 0) { 63 f->f_fsdata = (void*)(u_int64_t) fd; 64 return 0; 65 } 66 return ENOENT; 67} 68 69static int 70skifs_close(struct open_file *f) 71{ 72 ssc((u_int64_t) f->f_fsdata, 0, 0, 0, SSC_CLOSE); 73 return 0; 74} 75 76static int 77skifs_read(struct open_file *f, void *buf, size_t size, size_t *resid) 78{ 79 struct disk_req req; 80 struct disk_stat stat; 81 82 req.len = size; 83 req.addr = (u_int64_t) buf; 84 ssc((u_int64_t) f->f_fsdata, 1, (u_int64_t) &req, f->f_offset, SSC_READ); 85 stat.fd = (u_int64_t) f->f_fsdata; 86 ssc((u_int64_t)&stat, 0, 0, 0, SSC_WAIT_COMPLETION); 87 88 *resid = size - stat.count; 89 f->f_offset += stat.count; 90 return 0; 91} 92 93static off_t 94skifs_seek(struct open_file *f, off_t offset, int where) 95{ 96 u_int64_t base; 97 98 switch (where) { 99 case SEEK_SET: 100 base = 0; 101 break; 102 103 case SEEK_CUR: 104 base = f->f_offset; 105 break; 106 107 case SEEK_END: 108 printf("can't find end of file in SKI\n"); 109 base = f->f_offset; 110 break; 111 } 112 113 f->f_offset = base + offset; 114 return base; 115} 116 117static int 118skifs_stat(struct open_file *f, struct stat *sb) 119{ 120 bzero(sb, sizeof(*sb)); 121 sb->st_mode = S_IFREG | S_IRUSR; 122 return 0; 123} 124 125static int 126skifs_readdir(struct open_file *f, struct dirent *d) 127{ 128 return ENOENT; 129} 130 131struct fs_ops ski_fsops = { 132 "fs", 133 skifs_open, 134 skifs_close, 135 skifs_read, 136 null_write, 137 skifs_seek, 138 skifs_stat, 139 skifs_readdir 140}; 141 142static int 143skifs_dev_init(void) 144{ 145 return 0; 146} 147 148/* 149 * Print information about disks 150 */ 151static void 152skifs_dev_print(int verbose) 153{ 154} 155 156/* 157 * Attempt to open the disk described by (dev) for use by (f). 158 * 159 * Note that the philosophy here is "give them exactly what 160 * they ask for". This is necessary because being too "smart" 161 * about what the user might want leads to complications. 162 * (eg. given no slice or partition value, with a disk that is 163 * sliced - are they after the first BSD slice, or the DOS 164 * slice before it?) 165 */ 166static int 167skifs_dev_open(struct open_file *f, ...) 168{ 169 return 0; 170} 171 172static int 173skifs_dev_close(struct open_file *f) 174{ 175 176 return 0; 177} 178 179static int 180skifs_dev_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize) 181{ 182 return 0; 183} 184 185struct devsw skifs_dev = { 186 "fs", 187 DEVT_DISK, 188 skifs_dev_init, 189 skifs_dev_strategy, 190 skifs_dev_open, 191 skifs_dev_close, 192 noioctl, 193 skifs_dev_print 194}; 195