1 /* $NetBSD: rawfs.c,v 1.7 2006/06/25 17:36:07 tsutsui Exp $ */
4 * Copyright (c) 1995 Gordon W. Ross
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Raw file system - for stream devices like tapes.
30 * No random access, only sequential read allowed.
31 * This exists only to allow upper level code to be
32 * shielded from the fact that the device must be
33 * read only with whole block position and size.
36 #include <sys/param.h>
38 #include <lib/libsa/stand.h>
39 #include <hp300/stand/common/rawfs.h>
43 /* Our devices are generally willing to do 8K transfers. */
44 #define RAWFS_BSIZE 0x2000
50 daddr_t fs_nextblk
; /* block number to read next */
51 int fs_len
; /* amount left in f_buf */
52 char * fs_ptr
; /* read pointer into f_buf */
53 char fs_buf
[RAWFS_BSIZE
];
56 static int rawfs_get_block(struct open_file
*);
59 rawfs_open(const char *path
, struct open_file
*f
)
61 struct rawfs_file
*fs
;
64 * The actual tape driver has already been opened.
65 * Just allocate the I/O buffer, etc.
67 fs
= alloc(sizeof(struct rawfs_file
));
70 fs
->fs_ptr
= fs
->fs_buf
;
73 printf("rawfs_open: fs=0x%x\n", (u_long
)fs
);
81 rawfs_close(struct open_file
*f
)
83 struct rawfs_file
*fs
;
85 fs
= (struct rawfs_file
*) f
->f_fsdata
;
86 f
->f_fsdata
= (void *)0;
89 printf("rawfs_close: fs=0x%x\n", (u_long
)fs
);
92 if (fs
!= (struct rawfs_file
*)0)
93 dealloc(fs
, sizeof(*fs
));
99 rawfs_read(struct open_file
*f
, void *start
, u_int size
, u_int
*resid
)
101 struct rawfs_file
*fs
= (struct rawfs_file
*)f
->f_fsdata
;
107 printf("rawfs_read: file=0x%x, start=0x%x, size=%d, resid=0x%x\n",
108 (u_long
)f
, (u_long
)start
, size
, resid
);
109 printf(" fs=0x%x\n", (u_long
)fs
);
115 if ((error
= rawfs_get_block(f
)) != 0)
122 if (csize
> fs
->fs_len
)
125 memcpy(addr
, fs
->fs_ptr
, csize
);
137 rawfs_write(struct open_file
*f
, void *start
, size_t size
, size_t *resid
)
141 printf("rawfs_write: YOU'RE NOT SUPPOSED TO GET HERE!\n");
147 rawfs_seek(struct open_file
*f
, off_t offset
, int where
)
151 printf("rawfs_seek: YOU'RE NOT SUPPOSED TO GET HERE!\n");
157 rawfs_stat(struct open_file
*f
, struct stat
*sb
)
161 printf("rawfs_stat: I'll let you live only because of exec.c\n");
164 * Clear out the stat buffer so that the uid check
165 * won't fail. See sys/lib/libsa/exec.c
167 memset(sb
, 0, sizeof(*sb
));
173 * Read a block from the underlying stream device
174 * (In our case, a tape drive.)
177 rawfs_get_block(struct open_file
*f
)
179 struct rawfs_file
*fs
;
183 fs
= (struct rawfs_file
*)f
->f_fsdata
;
184 fs
->fs_ptr
= fs
->fs_buf
;
188 printf("rawfs_get_block: calling strategy\n");
190 error
= f
->f_dev
->dv_strategy(f
->f_devdata
, F_READ
,
191 fs
->fs_nextblk
, RAWFS_BSIZE
, fs
->fs_buf
, &len
);
193 printf("rawfs_get_block: strategy returned %d\n", error
);
198 fs
->fs_nextblk
+= (RAWFS_BSIZE
/ DEV_BSIZE
);