2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2022 Tomohiro Kusumi <tkusumi@netbsd.org>
5 * Copyright (c) 2011-2022 The DragonFly Project. All rights reserved.
7 * This code is derived from software contributed to The DragonFly Project
8 * by Matthew Dillon <dillon@dragonflybsd.org>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
20 * 3. Neither the name of The DragonFly Project nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific, prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 getblkx(struct m_vnode
*vp
, off_t loffset
, int size
, int blkflags
, int slptimeo
)
50 blkno
= loffset
/ DEV_BSIZE
; /* fsopts->sectorsize */
52 bp
= getblk(vp
, blkno
, size
, 0, 0, 0);
56 bp
->b_loffset
= loffset
;
62 breadx(struct m_vnode
*vp
, off_t loffset
, int size
, struct m_buf
**bpp
)
69 bp
= getblkx(vp
, loffset
, size
, 0, 0);
71 errx(1, "buf %p for vp %p has no makefs_fsinfo", bp
, vp
);
73 assert(bp
->b_blkno
* DEV_BSIZE
== bp
->b_loffset
);
74 assert(bp
->b_bcount
== size
);
76 assert(!bp
->b_vp
->v_logical
);
79 if (lseek(bp
->b_fs
->fd
, bp
->b_loffset
, SEEK_SET
) == -1)
80 err(1, "%s: lseek vp %p offset 0x%016jx",
81 __func__
, vp
, (intmax_t)bp
->b_loffset
);
83 ret
= read(bp
->b_fs
->fd
, bp
->b_data
, bp
->b_bcount
);
84 if (debug
& DEBUG_BUF_BREAD
)
85 printf("%s: read vp %p offset 0x%016jx size 0x%jx -> 0x%jx\n",
86 __func__
, vp
, (intmax_t)bp
->b_loffset
,
87 (intmax_t)bp
->b_bcount
, (intmax_t)ret
);
90 err(1, "%s: read vp %p offset 0x%016jx size 0x%jx",
91 __func__
, vp
, (intmax_t)bp
->b_loffset
,
92 (intmax_t)bp
->b_bcount
);
93 } else if (ret
!= bp
->b_bcount
) {
95 printf("%s: read vp %p offset 0x%016jx size 0x%jx -> "
97 __func__
, vp
, (intmax_t)bp
->b_loffset
,
98 (intmax_t)bp
->b_bcount
, (intmax_t)ret
,
99 (intmax_t)bp
->b_bcount
);
107 bread_kvabio(struct m_vnode
*vp
, off_t loffset
, int size
, struct m_buf
**bpp
)
109 return (breadx(vp
, loffset
, size
, bpp
));
113 bqrelse(struct m_buf
*bp
)
119 bawrite(struct m_buf
*bp
)
125 uiomove(caddr_t cp
, size_t n
, struct uio
*uio
)
131 KASSERT(uio
->uio_rw
== UIO_READ
|| uio
->uio_rw
== UIO_WRITE
,
134 while (n
> 0 && uio
->uio_resid
) {
145 switch (uio
->uio_segflg
) {
147 /* emulate copyout/copyin */
148 if (uio
->uio_rw
== UIO_READ
)
149 bcopy(cp
, iov
->iov_base
, cnt
);
151 bcopy(iov
->iov_base
, cp
, cnt
);
154 if (uio
->uio_rw
== UIO_READ
)
155 bcopy(cp
, iov
->iov_base
, cnt
);
157 bcopy(iov
->iov_base
, cp
, cnt
);
160 assert(0); /* no UIO_NOCOPY in makefs */
166 iov
->iov_base
= (char *)iov
->iov_base
+ cnt
;
168 uio
->uio_resid
-= cnt
;
169 uio
->uio_offset
+= cnt
;
178 uiomovebp(struct m_buf
*bp
, caddr_t cp
, size_t n
, struct uio
*uio
)
180 return (uiomove(cp
, n
, uio
));