1 /* $NetBSD: bfs_sysvbfs.c,v 1.9 2008/04/28 20:24:02 martin Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: bfs_sysvbfs.c,v 1.9 2008/04/28 20:24:02 martin Exp $");
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/systm.h>
40 #include <sys/malloc.h>
41 #include <sys/kauth.h>
42 #include <fs/sysvbfs/bfs.h>
45 struct sector_io_ops io
;
52 STATIC
bool bc_read_n(void *, uint8_t *, daddr_t
, int);
53 STATIC
bool bc_read(void *, uint8_t *, daddr_t
);
54 STATIC
bool bc_write_n(void *, uint8_t *, daddr_t
, int);
55 STATIC
bool bc_write(void *, uint8_t *, daddr_t
);
58 sysvbfs_bfs_init(struct bfs
**bfsp
, struct vnode
*vp
)
60 struct bc_io_ops
*bio
;
62 if ((bio
= malloc(sizeof(*bio
), M_TEMP
, M_WAITOK
| M_ZERO
)) == NULL
) {
63 printf("can't allocate I/O ops.\n");
67 bio
->io
.read
= bc_read
;
68 bio
->io
.read_n
= bc_read_n
;
69 bio
->io
.write
= bc_write
;
70 bio
->io
.write_n
= bc_write_n
;
72 bio
->cred
= NOCRED
; /* sysvbfs layer check cred. */
74 return bfs_init2(bfsp
, 0, (struct sector_io_ops
*)bio
, false);
78 sysvbfs_bfs_fini(struct bfs
*bfs
)
81 free(bfs
->io
, M_TEMP
);
86 bc_read_n(void *self
, uint8_t *buf
, daddr_t block
, int count
)
90 for (i
= 0; i
< count
; i
++) {
91 if (!bc_read(self
, buf
, block
))
101 bc_read(void *self
, uint8_t *buf
, daddr_t block
)
103 struct bc_io_ops
*bio
= self
;
104 struct buf
*bp
= NULL
;
106 if (bread(bio
->vp
, block
, DEV_BSIZE
, bio
->cred
, 0, &bp
) != 0)
108 memcpy(buf
, bp
->b_data
, DEV_BSIZE
);
113 printf("%s: block %lld read failed.\n", __func__
,
114 (long long int)block
);
122 bc_write_n(void *self
, uint8_t *buf
, daddr_t block
, int count
)
126 for (i
= 0; i
< count
; i
++) {
127 if (!bc_write(self
, buf
, block
))
137 bc_write(void *self
, uint8_t *buf
, daddr_t block
)
139 struct bc_io_ops
*bio
= self
;
143 printf("%s: block=%lld\n", __func__
, block
);
145 if ((bp
= getblk(bio
->vp
, block
, DEV_BSIZE
, 0, 0)) == 0) {
146 printf("getblk failed.\n");
149 memcpy(bp
->b_data
, buf
, DEV_BSIZE
);
151 if (bwrite(bp
) != 0) {
152 printf("bwrite failed.\n");