Bug Summary

File:ufs/ext2fs/ext2fs_bmap.c
Warning:line 192, column 2
Value stored to 'devvp' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ext2fs_bmap.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -target-feature -sse2 -target-feature -sse -target-feature -3dnow -target-feature -mmx -target-feature +save-args -disable-red-zone -no-implicit-float -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/sys -I /usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -I /usr/src/sys/arch -I /usr/src/sys/dev/pci/drm/include -I /usr/src/sys/dev/pci/drm/include/uapi -I /usr/src/sys/dev/pci/drm/amd/include/asic_reg -I /usr/src/sys/dev/pci/drm/amd/include -I /usr/src/sys/dev/pci/drm/amd/amdgpu -I /usr/src/sys/dev/pci/drm/amd/display -I /usr/src/sys/dev/pci/drm/amd/display/include -I /usr/src/sys/dev/pci/drm/amd/display/dc -I /usr/src/sys/dev/pci/drm/amd/display/amdgpu_dm -I /usr/src/sys/dev/pci/drm/amd/pm/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu11 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu12 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/hwmgr -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/smumgr -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc/hw -I /usr/src/sys/dev/pci/drm/amd/display/dc/clk_mgr -I /usr/src/sys/dev/pci/drm/amd/display/modules/inc -I /usr/src/sys/dev/pci/drm/amd/display/modules/hdcp -I /usr/src/sys/dev/pci/drm/amd/display/dmub/inc -I /usr/src/sys/dev/pci/drm/i915 -D DDB -D DIAGNOSTIC -D KTRACE -D ACCOUNTING -D KMEMSTATS -D PTRACE -D POOL_DEBUG -D CRYPTO -D SYSVMSG -D SYSVSEM -D SYSVSHM -D UVM_SWAP_ENCRYPT -D FFS -D FFS2 -D FFS_SOFTUPDATES -D UFS_DIRHASH -D QUOTA -D EXT2FS -D MFS -D NFSCLIENT -D NFSSERVER -D CD9660 -D UDF -D MSDOSFS -D FIFO -D FUSE -D SOCKET_SPLICE -D TCP_ECN -D TCP_SIGNATURE -D INET6 -D IPSEC -D PPP_BSDCOMP -D PPP_DEFLATE -D PIPEX -D MROUTING -D MPLS -D BOOT_CONFIG -D USER_PCICONF -D APERTURE -D MTRR -D NTFS -D HIBERNATE -D PCIVERBOSE -D USBVERBOSE -D WSDISPLAY_COMPAT_USL -D WSDISPLAY_COMPAT_RAWKBD -D WSDISPLAY_DEFAULTSCREENS=6 -D X86EMU -D ONEWIREVERBOSE -D MULTIPROCESSOR -D MAXUSERS=80 -D _KERNEL -D CONFIG_DRM_AMD_DC_DCN3_0 -O2 -Wno-pointer-sign -Wno-address-of-packed-member -Wno-constant-conversion -Wno-unused-but-set-variable -Wno-gnu-folding-constant -fdebug-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -o /usr/obj/sys/arch/amd64/compile/GENERIC.MP/scan-build/2022-01-12-131800-47421-1 -x c /usr/src/sys/ufs/ext2fs/ext2fs_bmap.c
1/* $OpenBSD: ext2fs_bmap.c,v 1.28 2021/12/12 09:14:59 visa Exp $ */
2/* $NetBSD: ext2fs_bmap.c,v 1.5 2000/03/30 12:41:11 augustss Exp $ */
3
4/*
5 * Copyright (c) 1997 Manuel Bouyer.
6 * Copyright (c) 1989, 1991, 1993
7 * The Regents of the University of California. All rights reserved.
8 * (c) UNIX System Laboratories, Inc.
9 * All or some portions of this file are derived from material licensed
10 * to the University of California by American Telephone and Telegraph
11 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
12 * the permission of UNIX System Laboratories, Inc.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)ufs_bmap.c 8.6 (Berkeley) 1/21/94
39 * Modified for ext2fs by Manuel Bouyer.
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/buf.h>
45#include <sys/proc.h>
46#include <sys/vnode.h>
47#include <sys/mount.h>
48#include <sys/specdev.h>
49
50#include <ufs/ufs/quota.h>
51#include <ufs/ufs/inode.h>
52#include <ufs/ufs/ufsmount.h>
53#include <ufs/ufs/ufs_extern.h>
54#include <ufs/ext2fs/ext2fs.h>
55#include <ufs/ext2fs/ext2fs_extents.h>
56#include <ufs/ext2fs/ext2fs_extern.h>
57
58static int ext4_bmapext(struct vnode *, daddr_t, daddr_t *, struct indir *,
59 int *, int *);
60static int ext2fs_bmaparray(struct vnode *, daddr_t, daddr_t *, struct indir *,
61 int *, int *);
62
63/*
64 * Bmap converts a the logical block number of a file to its physical block
65 * number on the disk. The conversion is done by using the logical block
66 * number to index into the array of block pointers described by the dinode.
67 */
68int
69ext2fs_bmap(void *v)
70{
71 struct vop_bmap_args *ap = v;
72
73 /*
74 * Check for underlying vnode requests and ensure that logical
75 * to physical mapping is requested.
76 */
77 if (ap->a_vpp != NULL((void *)0))
78 *ap->a_vpp = VTOI(ap->a_vp)((struct inode *)(ap->a_vp)->v_data)->i_devvpi_ump->um_devvp;
79 if (ap->a_bnp == NULL((void *)0))
80 return (0);
81
82 if (VTOI(ap->a_vp)((struct inode *)(ap->a_vp)->v_data)->i_e2dindinode_u.e2fs_din->e2di_flags & EXT4_EXTENTS0x00080000) {
83 return (ext4_bmapext(ap->a_vp, ap->a_bn, ap->a_bnp, NULL((void *)0), NULL((void *)0),
84 ap->a_runp));
85 }
86 return (ext2fs_bmaparray(ap->a_vp, ap->a_bn, ap->a_bnp, NULL((void *)0), NULL((void *)0),
87 ap->a_runp));
88}
89
90/*
91 * Logical block number of a file -> physical block number on disk within ext4 extents.
92 */
93int
94ext4_bmapext(struct vnode *vp, daddr_t bn, daddr_t *bnp, struct indir *ap, int *nump, int *runp)
95{
96 struct inode *ip;
97 struct m_ext2fs *fs;
98 struct ext4_extent *ep;
99 struct ext4_extent_path path;
100 daddr_t pos;
101
102 ip = VTOI(vp)((struct inode *)(vp)->v_data);
103 fs = ip->i_e2fsinode_u.e2fs;
104
105 if (runp != NULL((void *)0))
106 *runp = 0;
107 if (nump != NULL((void *)0))
108 *nump = 0;
109
110 ext4_ext_find_extent(fs, ip, bn, &path);
111 if ((ep = path.ep_ext) == NULL((void *)0))
112 return (EIO5);
113
114 pos = bn - ep->e_blk + (((daddr_t)ep->e_start_hi << 32) | ep->e_start_lo);
115 if ((*bnp = fsbtodb(fs, pos)((pos) << (fs)->e2fs_fsbtodb)) == 0)
116 *bnp = -1;
117 return (0);
118}
119
120/*
121 * Indirect blocks are now on the vnode for the file. They are given negative
122 * logical block numbers. Indirect blocks are addressed by the negative
123 * address of the first data block to which they point. Double indirect blocks
124 * are addressed by one less than the address of the first indirect block to
125 * which they point. Triple indirect blocks are addressed by one less than
126 * the address of the first double indirect block to which they point.
127 *
128 * ext2fs_bmaparray does the bmap conversion, and if requested returns the
129 * array of logical blocks which must be traversed to get to a block.
130 * Each entry contains the offset into that block that gets you to the
131 * next block and the disk address of the block (if it is assigned).
132 */
133
134int
135ext2fs_bmaparray(struct vnode *vp, daddr_t bn, daddr_t *bnp,
136 struct indir *ap, int *nump, int *runp)
137{
138 struct inode *ip;
139 struct buf *bp;
140 struct ufsmount *ump;
141 struct mount *mp;
142 struct vnode *devvp;
143 struct indir a[NIADDR3+1], *xap;
144 int32_t daddr;
145 long metalbn;
146 int error, maxrun = 0, num;
147
148 ip = VTOI(vp)((struct inode *)(vp)->v_data);
149 mp = vp->v_mount;
150 ump = VFSTOUFS(mp)((struct ufsmount *)((mp)->mnt_data));
151#ifdef DIAGNOSTIC1
152 if ((ap != NULL((void *)0) && nump == NULL((void *)0)) || (ap == NULL((void *)0) && nump != NULL((void *)0)))
153 panic("ext2fs_bmaparray: invalid arguments");
154#endif
155
156 if (runp) {
157 /*
158 * XXX
159 * If MAXBSIZE is the largest transfer the disks can handle,
160 * we probably want maxrun to be 1 block less so that we
161 * don't create a block larger than the device can handle.
162 */
163 *runp = 0;
164 maxrun = MAXBSIZE(64 * 1024) / mp->mnt_stat.f_iosize - 1;
165 }
166
167 xap = ap == NULL((void *)0) ? a : ap;
168 if (!nump)
169 nump = &num;
170 if ((error = ufs_getlbns(vp, bn, xap, nump)) != 0)
171 return (error);
172
173 num = *nump;
174 if (num == 0) {
175 *bnp = blkptrtodb(ump, letoh32(ip->i_e2fs_blocks[bn]))((((__uint32_t)(ip->dinode_u.e2fs_din->e2di_blocks[bn])
)) << (ump)->um_bptrtodb)
;
176 if (*bnp == 0)
177 *bnp = -1;
178 else if (runp)
179 for (++bn; bn < NDADDR12 && *runp < maxrun &&
180 is_sequential(ump,((((__uint32_t)(ip->dinode_u.e2fs_din->e2di_blocks[bn])
)) == (((__uint32_t)(ip->dinode_u.e2fs_din->e2di_blocks
[bn - 1]))) + ump->um_seqinc)
181 letoh32(ip->i_e2fs_blocks[bn - 1]),((((__uint32_t)(ip->dinode_u.e2fs_din->e2di_blocks[bn])
)) == (((__uint32_t)(ip->dinode_u.e2fs_din->e2di_blocks
[bn - 1]))) + ump->um_seqinc)
182 letoh32(ip->i_e2fs_blocks[bn]))((((__uint32_t)(ip->dinode_u.e2fs_din->e2di_blocks[bn])
)) == (((__uint32_t)(ip->dinode_u.e2fs_din->e2di_blocks
[bn - 1]))) + ump->um_seqinc)
;
183 ++bn, ++*runp)
184 /* nothing */;
185 return (0);
186 }
187
188
189 /* Get disk address out of indirect block array */
190 daddr = letoh32(ip->i_e2fs_blocks[NDADDR + xap->in_off])((__uint32_t)(ip->dinode_u.e2fs_din->e2di_blocks[12 + xap
->in_off]))
;
191
192 devvp = VFSTOUFS(vp->v_mount)((struct ufsmount *)((vp->v_mount)->mnt_data))->um_devvp;
Value stored to 'devvp' is never read
193
194#ifdef DIAGNOSTIC1
195 if (num > NIADDR3 + 1 || num < 1) {
196 printf("ext2fs_bmaparray: num=%d\n", num);
197 panic("ext2fs_bmaparray: num");
198 }
199#endif
200 for (bp = NULL((void *)0), ++xap; --num; ++xap) {
201 /*
202 * Exit the loop if there is no disk address assigned yet and
203 * the indirect block isn't in the cache, or if we were
204 * looking for an indirect block and we've found it.
205 */
206
207 metalbn = xap->in_lbn;
208 if ((daddr == 0 && !incore(vp, metalbn)) || metalbn == bn)
209 break;
210 /*
211 * If we get here, we've either got the block in the cache
212 * or we have a disk address for it, go fetch it.
213 */
214 if (bp)
215 brelse(bp);
216
217 xap->in_exists = 1;
218 bp = getblk(vp, metalbn, mp->mnt_stat.f_iosize, 0, INFSLP0xffffffffffffffffULL);
219 if (bp->b_flags & (B_DONE0x00000100 | B_DELWRI0x00000080)) {
220 ;
221 }
222#ifdef DIAGNOSTIC1
223 else if (!daddr)
224 panic("ext2fs_bmaparry: indirect block not in cache");
225#endif
226 else {
227 bp->b_blkno = blkptrtodb(ump, daddr)((daddr) << (ump)->um_bptrtodb);
228 bp->b_flags |= B_READ0x00008000;
229 VOP_STRATEGY(bp->b_vp, bp);
230 curproc({struct cpu_info *__ci; asm volatile("movq %%gs:%P1,%0" : "=r"
(__ci) :"n" (__builtin_offsetof(struct cpu_info, ci_self)));
__ci;})->ci_curproc
->p_ru.ru_inblock++; /* XXX */
231 bcstats.pendingreads++;
232 if ((error = biowait(bp)) != 0) {
233 brelse(bp);
234 return (error);
235 }
236 }
237
238 daddr = letoh32(((int32_t *)bp->b_data)[xap->in_off])((__uint32_t)(((int32_t *)bp->b_data)[xap->in_off]));
239 if (num == 1 && daddr && runp)
240 for (bn = xap->in_off + 1;
241 bn < MNINDIR(ump)((ump)->um_nindir) && *runp < maxrun &&
242 is_sequential(ump, ((u_int32_t *)bp->b_data)[bn - 1],((((u_int32_t *)bp->b_data)[bn]) == (((u_int32_t *)bp->
b_data)[bn - 1]) + ump->um_seqinc)
243 ((u_int32_t *)bp->b_data)[bn])((((u_int32_t *)bp->b_data)[bn]) == (((u_int32_t *)bp->
b_data)[bn - 1]) + ump->um_seqinc)
;
244 ++bn, ++*runp)
245 /* nothing */;
246 }
247 if (bp)
248 brelse(bp);
249
250 daddr = blkptrtodb(ump, daddr)((daddr) << (ump)->um_bptrtodb);
251 *bnp = daddr == 0 ? -1 : daddr;
252 return (0);
253}