Mon Jan 4 16:17:26 2021 UTC ()
Fix calculation of cylinder count from medium size.
Pullups needed.


(mlelstv)
diff -r1.277 -r1.278 src/sys/dev/vnd.c

cvs diff -r1.277 -r1.278 src/sys/dev/vnd.c (expand / switch to unified diff)

--- src/sys/dev/vnd.c 2020/04/23 09:40:08 1.277
+++ src/sys/dev/vnd.c 2021/01/04 16:17:26 1.278
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vnd.c,v 1.277 2020/04/23 09:40:08 jdolecek Exp $ */ 1/* $NetBSD: vnd.c,v 1.278 2021/01/04 16:17:26 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996, 1997, 1998, 2008, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996, 1997, 1998, 2008, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -81,27 +81,27 @@ @@ -81,27 +81,27 @@
81 * systems where the block-level operations are not implemented for 81 * systems where the block-level operations are not implemented for
82 * whatever reason. 82 * whatever reason.
83 * 83 *
84 * NOTE 2: There is a security issue involved with this driver. 84 * NOTE 2: There is a security issue involved with this driver.
85 * Once mounted all access to the contents of the "mapped" file via 85 * Once mounted all access to the contents of the "mapped" file via
86 * the special file is controlled by the permissions on the special 86 * the special file is controlled by the permissions on the special
87 * file, the protection of the mapped file is ignored (effectively, 87 * file, the protection of the mapped file is ignored (effectively,
88 * by using root credentials in all transactions). 88 * by using root credentials in all transactions).
89 * 89 *
90 * NOTE 3: Doesn't interact with leases, should it? 90 * NOTE 3: Doesn't interact with leases, should it?
91 */ 91 */
92 92
93#include <sys/cdefs.h> 93#include <sys/cdefs.h>
94__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.277 2020/04/23 09:40:08 jdolecek Exp $"); 94__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.278 2021/01/04 16:17:26 mlelstv Exp $");
95 95
96#if defined(_KERNEL_OPT) 96#if defined(_KERNEL_OPT)
97#include "opt_vnd.h" 97#include "opt_vnd.h"
98#include "opt_compat_netbsd.h" 98#include "opt_compat_netbsd.h"
99#endif 99#endif
100 100
101#include <sys/param.h> 101#include <sys/param.h>
102#include <sys/systm.h> 102#include <sys/systm.h>
103#include <sys/namei.h> 103#include <sys/namei.h>
104#include <sys/proc.h> 104#include <sys/proc.h>
105#include <sys/kthread.h> 105#include <sys/kthread.h>
106#include <sys/errno.h> 106#include <sys/errno.h>
107#include <sys/buf.h> 107#include <sys/buf.h>
@@ -1446,28 +1446,29 @@ vndioctl(dev_t dev, u_long cmd, void *da @@ -1446,28 +1446,29 @@ vndioctl(dev_t dev, u_long cmd, void *da
1446 * Sanity-check the sector size. 1446 * Sanity-check the sector size.
1447 */ 1447 */
1448 if (!DK_DEV_BSIZE_OK(vnd->sc_geom.vng_secsize) || 1448 if (!DK_DEV_BSIZE_OK(vnd->sc_geom.vng_secsize) ||
1449 vnd->sc_geom.vng_ntracks == 0 || 1449 vnd->sc_geom.vng_ntracks == 0 ||
1450 vnd->sc_geom.vng_nsectors == 0) { 1450 vnd->sc_geom.vng_nsectors == 0) {
1451 error = EINVAL; 1451 error = EINVAL;
1452 goto close_and_exit; 1452 goto close_and_exit;
1453 } 1453 }
1454 1454
1455 /* 1455 /*
1456 * Compute missing cylinder count from size 1456 * Compute missing cylinder count from size
1457 */ 1457 */
1458 if (vnd->sc_geom.vng_ncylinders == 0) 1458 if (vnd->sc_geom.vng_ncylinders == 0)
1459 vnd->sc_geom.vng_ncylinders = vnd->sc_size / 1459 vnd->sc_geom.vng_ncylinders = vnd->sc_size / (
1460 (vnd->sc_geom.vng_ntracks * 1460 (vnd->sc_geom.vng_secsize / DEV_BSIZE) *
 1461 vnd->sc_geom.vng_ntracks *
1461 vnd->sc_geom.vng_nsectors); 1462 vnd->sc_geom.vng_nsectors);
1462 1463
1463 /* 1464 /*
1464 * Compute the size (in DEV_BSIZE blocks) specified 1465 * Compute the size (in DEV_BSIZE blocks) specified
1465 * by the geometry. 1466 * by the geometry.
1466 */ 1467 */
1467 geomsize = (int64_t)vnd->sc_geom.vng_nsectors * 1468 geomsize = (int64_t)vnd->sc_geom.vng_nsectors *
1468 vnd->sc_geom.vng_ntracks * 1469 vnd->sc_geom.vng_ntracks *
1469 vnd->sc_geom.vng_ncylinders * 1470 vnd->sc_geom.vng_ncylinders *
1470 (vnd->sc_geom.vng_secsize / DEV_BSIZE); 1471 (vnd->sc_geom.vng_secsize / DEV_BSIZE);
1471 1472
1472 /* 1473 /*
1473 * Sanity-check the size against the specified 1474 * Sanity-check the size against the specified