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