pathfs.c revision 1.1.4.2 1 1.1.4.2 mrg /* $NetBSD: pathfs.c,v 1.1.4.2 2012/02/18 07:33:52 mrg Exp $ */
2 1.1.4.2 mrg
3 1.1.4.2 mrg /*-
4 1.1.4.2 mrg * Copyright (C) 2012 NONAKA Kimihiro <nonaka (at) netbsd.org>
5 1.1.4.2 mrg * All rights reserved.
6 1.1.4.2 mrg *
7 1.1.4.2 mrg * Redistribution and use in source and binary forms, with or without
8 1.1.4.2 mrg * modification, are permitted provided that the following conditions
9 1.1.4.2 mrg * are met:
10 1.1.4.2 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1.4.2 mrg * notice, this list of conditions and the following disclaimer.
12 1.1.4.2 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.4.2 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1.4.2 mrg * documentation and/or other materials provided with the distribution.
15 1.1.4.2 mrg *
16 1.1.4.2 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1.4.2 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1.4.2 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1.4.2 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1.4.2 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1.4.2 mrg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1.4.2 mrg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1.4.2 mrg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1.4.2 mrg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1.4.2 mrg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1.4.2 mrg */
27 1.1.4.2 mrg
28 1.1.4.2 mrg #include "boot.h"
29 1.1.4.2 mrg #include "pathfs.h"
30 1.1.4.2 mrg #include "unixdev.h"
31 1.1.4.2 mrg #include "compat_linux.h"
32 1.1.4.2 mrg
33 1.1.4.2 mrg __compactcall int
34 1.1.4.2 mrg pathfs_open(const char *path, struct open_file *fd)
35 1.1.4.2 mrg {
36 1.1.4.2 mrg
37 1.1.4.2 mrg if (strcmp(fd->f_dev->dv_name, "path"))
38 1.1.4.2 mrg return EINVAL;
39 1.1.4.2 mrg
40 1.1.4.2 mrg (void) ulseek((int)fd->f_devdata, 0L, SEEK_SET);
41 1.1.4.2 mrg return 0;
42 1.1.4.2 mrg }
43 1.1.4.2 mrg
44 1.1.4.2 mrg __compactcall int
45 1.1.4.2 mrg pathfs_read(struct open_file *fd, void *vbuf, size_t nbyte, size_t *resid)
46 1.1.4.2 mrg {
47 1.1.4.2 mrg char *buf = vbuf;
48 1.1.4.2 mrg size_t off = 0;
49 1.1.4.2 mrg ssize_t rsz;
50 1.1.4.2 mrg
51 1.1.4.2 mrg while (off < nbyte) {
52 1.1.4.2 mrg rsz = uread((int)fd->f_devdata, buf + off, nbyte - off);
53 1.1.4.2 mrg if (rsz < 0)
54 1.1.4.2 mrg return errno;
55 1.1.4.2 mrg if (rsz == 0)
56 1.1.4.2 mrg break;
57 1.1.4.2 mrg off += rsz;
58 1.1.4.2 mrg }
59 1.1.4.2 mrg
60 1.1.4.2 mrg *resid -= off;
61 1.1.4.2 mrg return 0;
62 1.1.4.2 mrg }
63 1.1.4.2 mrg
64 1.1.4.2 mrg __compactcall int
65 1.1.4.2 mrg pathfs_write(struct open_file *fd, void *vbuf, size_t size, size_t *resid)
66 1.1.4.2 mrg {
67 1.1.4.2 mrg
68 1.1.4.2 mrg return EROFS;
69 1.1.4.2 mrg }
70 1.1.4.2 mrg
71 1.1.4.2 mrg __compactcall off_t
72 1.1.4.2 mrg pathfs_seek(struct open_file *fd, off_t offset, int whence)
73 1.1.4.2 mrg {
74 1.1.4.2 mrg
75 1.1.4.2 mrg return ulseek((int)fd->f_devdata, offset, whence);
76 1.1.4.2 mrg }
77 1.1.4.2 mrg
78 1.1.4.2 mrg __compactcall int
79 1.1.4.2 mrg pathfs_close(struct open_file *fd)
80 1.1.4.2 mrg {
81 1.1.4.2 mrg
82 1.1.4.2 mrg return 0;
83 1.1.4.2 mrg }
84 1.1.4.2 mrg
85 1.1.4.2 mrg __compactcall int
86 1.1.4.2 mrg pathfs_stat(struct open_file *fd, struct stat *sb)
87 1.1.4.2 mrg {
88 1.1.4.2 mrg struct linux_stat lsb;
89 1.1.4.2 mrg int rv;
90 1.1.4.2 mrg
91 1.1.4.2 mrg rv = ufstat((int)fd->f_devdata, &lsb);
92 1.1.4.2 mrg if (rv < 0)
93 1.1.4.2 mrg return errno;
94 1.1.4.2 mrg
95 1.1.4.2 mrg sb->st_ino = lsb.lst_ino;
96 1.1.4.2 mrg sb->st_mode = lsb.lst_mode;
97 1.1.4.2 mrg sb->st_nlink = lsb.lst_nlink;
98 1.1.4.2 mrg sb->st_uid = lsb.lst_uid;
99 1.1.4.2 mrg sb->st_gid = lsb.lst_gid;
100 1.1.4.2 mrg sb->st_size = lsb.lst_size;
101 1.1.4.2 mrg sb->st_blksize = lsb.lst_blksize;
102 1.1.4.2 mrg sb->st_blocks = lsb.lst_blocks;
103 1.1.4.2 mrg sb->st_atime = lsb.lst_atime;
104 1.1.4.2 mrg sb->st_mtime = lsb.lst_mtime;
105 1.1.4.2 mrg sb->st_ctime = lsb.lst_ctime;
106 1.1.4.2 mrg return 0;
107 1.1.4.2 mrg }
108 1.1.4.2 mrg
109 1.1.4.2 mrg __compactcall void
110 1.1.4.2 mrg pathfs_ls(struct open_file *f, const char *pattern)
111 1.1.4.2 mrg {
112 1.1.4.2 mrg
113 1.1.4.2 mrg printf("Currently ls command is unsupported by pathfs.\n");
114 1.1.4.2 mrg }
115