/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- sfs_rwblock
- sfs_rblock
- sfs_wblock
1 /*
2 * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
3 * The President and Fellows of Harvard College.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #include <types.h>
31 #include <kern/errno.h>
32 #include <lib.h>
33 #include <uio.h>
34 #include <vfs.h>
35 #include <device.h>
36 #include <sfs.h>
37
38 ////////////////////////////////////////////////////////////
39 //
40 // Basic block-level I/O routines
41 //
42 // Note: sfs_rblock is used to read the superblock
43 // early in mount, before sfs is fully (or even mostly)
44 // initialized, and so may not use anything from sfs
45 // except sfs_device.
46
47 int
48 sfs_rwblock(struct sfs_fs *sfs, struct uio *uio)
49 {
50 int result;
51 int tries=0;
52
53 KASSERT(vfs_biglock_do_i_hold());
54
55 DEBUG(DB_SFS, "sfs: %s %llu\n",
56 uio->uio_rw == UIO_READ ? "read" : "write",
57 uio->uio_offset / SFS_BLOCKSIZE);
58
59 retry:
60 result = sfs->sfs_device->d_io(sfs->sfs_device, uio);
61 if (result == EINVAL) {
62 /*
63 * This means the sector we requested was out of range,
64 * or the seek address we gave wasn't sector-aligned,
65 * or a couple of other things that are our fault.
66 */
67 panic("sfs: d_io returned EINVAL\n");
68 }
69 if (result == EIO) {
70 if (tries == 0) {
71 tries++;
72 kprintf("sfs: block %llu I/O error, retrying\n",
73 uio->uio_offset / SFS_BLOCKSIZE);
74 goto retry;
75 }
76 else if (tries < 10) {
77 tries++;
78 goto retry;
79 }
80 else {
81 kprintf("sfs: block %llu I/O error, giving up after "
82 "%d retries\n",
83 uio->uio_offset / SFS_BLOCKSIZE, tries);
84 }
85 }
86 return result;
87 }
88
89 int
90 sfs_rblock(struct sfs_fs *sfs, void *data, uint32_t block)
91 {
92 struct iovec iov;
93 struct uio ku;
94
95 SFSUIO(&iov, &ku, data, block, UIO_READ);
96 return sfs_rwblock(sfs, &ku);
97 }
98
99 int
100 sfs_wblock(struct sfs_fs *sfs, void *data, uint32_t block)
101 {
102 struct iovec iov;
103 struct uio ku;
104
105 SFSUIO(&iov, &ku, data, block, UIO_WRITE);
106 return sfs_rwblock(sfs, &ku);
107 }