1 /* $NetBSD: sdread.c,v 1.1 2009/10/05 13:05:31 pooka Exp $ */
4 * Copyright (c) 2009 Antti Kantee. All Rights Reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/types.h>
29 #include <sys/dirent.h>
30 #include <sys/mount.h>
32 #include <ufs/ufs/ufsmount.h>
33 #include <msdosfs/msdosfsmount.h>
35 #include <rump/rump.h>
36 #include <rump/rump_syscalls.h>
47 * Proof-of-concept program:
49 * Mount rump file system from device driver stack included in the
50 * rump kernel. Optionally copy a file out of the mounted file system.
54 main(int argc
, char *argv
[])
57 struct msdosfs_args args
;
58 struct ufs_args uargs
;
60 const char *msg
= NULL
;
61 int fd
, n
, fd_h
, sverrno
;
63 if (argc
> 1 && argc
!= 3) {
64 fprintf(stderr
, "usage: a.out [src hostdest]\n");
68 memset(&args
, 0, sizeof(args
));
69 args
.fspec
= strdup("/dev/sd0e");
70 args
.version
= MSDOSFSMNT_VERSION
;
72 memset(&uargs
, 0, sizeof(uargs
));
73 uargs
.fspec
= strdup("/dev/sd0e");
77 if (rump_sys_mkdir("/mp", 0777) == -1)
79 if (rump_sys_mount(MOUNT_MSDOS
, "/mp", MNT_RDONLY
,
80 &args
, sizeof(args
)) == -1) {
81 if (rump_sys_mount(MOUNT_FFS
, "/mp", MNT_RDONLY
,
82 &uargs
, sizeof(uargs
)) == -1) {
87 fd
= rump_sys_open("/mp", O_RDONLY
, 0);
93 while ((n
= rump_sys_getdents(fd
, buf
, sizeof(buf
))) > 0) {
94 for (dp
= (struct dirent
*)buf
;
96 dp
= _DIRENT_NEXT(dp
)) {
97 printf("%" PRIu64
": %s\n", dp
->d_fileno
, dp
->d_name
);
104 rump_sys_chdir("/mp");
105 fd
= rump_sys_open(argv
[1], O_RDONLY
, 0);
107 msg
= "open fs file";
111 fd_h
= open(argv
[2], O_RDWR
| O_CREAT
, 0777);
113 msg
= "open host file";
117 while ((n
= rump_sys_read(fd
, buf
, sizeof(buf
))) == sizeof(buf
)) {
118 if (write(fd_h
, buf
, sizeof(buf
)) != sizeof(buf
)) {
119 msg
= "write host file";
124 msg
= "read fs file";
129 if (write(fd_h
, buf
, n
) == -1)
138 if (rump_sys_unmount("/mp", 0) == -1)