Re: disklabel change?

2024-04-22 Thread Michael van Elst
pr...@welche.eu (Patrick Welche) writes:

>In fact, the difference is between "-t" and "-rt":

>I deem "-t" output to be correct (and matches what I had in /etc/diskpart)


The in-kernel disklabel gets the RAW_PART from by the disk geometry
and if RAW_PART == 3, it gets d_partitions[2] from the MBR partition
table.

That explains why 'disklabel -t' looks correct, it shows the in-kernel
disklabel.

It doesn't explain why the on-disk label has the entries swapped.
When you edit the disklabel, the kernel writes to the disk. When
that corrects the error, the bug is in the disklabel program,
otherwise it's in the kernel.



Re: RPi 4b Wifi Device

2024-04-21 Thread Michael van Elst
michael.chepo...@gmail.com (Michael Cheponis) writes:

>I use the built-in GigE adaptor on the RPi 4B, because it's convenient as I
>have wired ethernet most places.   So I can't help with WiFi.

Ethernet is also faster, even when the WiFi chip does 802.11ac.

For Wifi on a RPI4b:

With RPI-OS running iperf3 shows about 80Mbit/s.
NetBSD (-current, but -10 should be similar) gets me about 40MBit/s.

Wifi is connected to a SDHC controller, and handling I/O there generates
quite some overhead (while iperf3 is running):

  PID   LID USERNAME PRI STATE   TIME   WCPUCPU NAME  COMMAND
0   118 root 123 CPU/1   1:33 39.45% 39.45% sdmmc0[system]
 7467 12269 mlelstv   85 mutex/2 0:03  4.79%  4.79% - iperf3
0 3 root 222 IDLE/0  0:04  2.59%  2.59% softnet*0 [system]
0   101 root 222 IDLE/3  0:03  1.81%  1.81% softnet*3 [system]
030 root 222 IDLE/2  0:02  1.32%  1.32% softnet*2 [system]
024 root 222 IDLE/1  0:02  0.93%  0.93% softnet*1 [system]

That's about 80% of one core.



Re: RPi 4b Wifi Device

2024-04-20 Thread Michael van Elst
tomd...@wavecable.com ("Thomas D. Dean") writes:

># wpa_cli status
>Selected interface 'bwfm0'
>21:58:44.815: bssid=60:38:e0:db:a9:7a
>freq=0
>ssid=tddhome
>id=0
>mode=station
>pairwise_cipher=TKIP
>group_cipher=TKIP
>key_mgmt=WPA-PSK
>wpa_state=GROUP_HANDSHAKE
>ip_address=169.254.135.120
>address=e4:5f:01:da:eb:46

>I don't understand where the inet 169.254.135.120 comes from. The router 
>pool is 192.168.1.xxx.

169.254.x.x is a "link local" address. dhcpcd falls back to such an
address, if it doesn't get an answer from a dhcp server. Apparently
wpa_supplicant cannot connect to the network.

>wpa_state=GROUP_HANDSHAKE

says that it still tries to associate. When it's done this would
change to COMPLETED.



Re: RPi 4b Wifi Device

2024-04-19 Thread Michael van Elst
tomd...@wavecable.com ("Thomas D. Dean") writes:

>How do I setup wpa_supplicant?

That depends on what you want to do.

Here are some examples:
https://wiki.netbsd.org/tutorials/how_to_use_wpa_supplicant/


Greetings,


Re: RPi 4b Wifi Device

2024-04-19 Thread Michael van Elst
tomd...@wavecable.com ("Thomas D. Dean") writes:

>On 4/18/24 22:00, Michael van Elst wrote:
>> bwfm0: Firmware file default:brcmfmac43455-sdio.bin
>> bwfm0: Firmware file model-spec: brcmfmac43455-sdio.raspberrypi,4-model-b.bin
>> bwfm0: Found Firmware file: brcmfmac43455-sdio.raspberrypi,4-model-b.bin

>> bwfm0: NVRAM file default:brcmfmac43455-sdio.txt
>> bwfm0: NVRAM file model-spec: brcmfmac43455-sdio.raspberrypi,4-model-b.txt
>> bwfm0: Found NVRAM file: brcmfmac43455-sdio.raspberrypi,4-model-b.txt

>> bwfm0: CLM file default:brcmfmac43455-sdio.clm_blob
>> bwfm0: CLM file model-spec: brcmfmac43455-sdio.raspberrypi,4-model-b.clm_blob
>> bwfm0: Found CLM file: brcmfmac43455-sdio.raspberrypi,4-model-b.clm_blob


>I saw bwfm0: in /var/log/messages, from memory, similar to the ones listed.
>One error. autoconfiguration error: NVRAM file not available.
>The CHIPACTIVE line is missng.


This means, a firmware file isn't found, because it is searched under
a different name.

You should have:

-r--r--r--  1 root  wheel  1863 Mar 28 17:45 
libdata/firmware/if_bwfm/brcmfmac43455-sdio.raspberrypi,4-model-b.txt

and need to create a symlink like:

cd /libdata/firmware/if_bwfm
ln -s brcmfmac43455-sdio.raspberrypi,4-model-b.txt 
"brcmfmac43455-sdio.Raspberry Pi 4 Model B.txt"

Reason is that the platform is canonically named "raspberrypi,4-model-b"
but UEFI chose "Raspberry Pi 4 Model B" instead.


Greetings,


Re: RPi 4b Wifi Device

2024-04-18 Thread Michael van Elst
tomd...@wavecable.com ("Thomas D. Dean") writes:

>What is the wifi device in the RPi 4b? Driver?

It's a chip similar to the one in the older RPIs:

bwfm0: chip 0x4345 rev 6
bwfm0: Firmware file default:brcmfmac43455-sdio.bin
bwfm0: Firmware file model-spec: brcmfmac43455-sdio.raspberrypi,4-model-b.bin
bwfm0: Found Firmware file: brcmfmac43455-sdio.raspberrypi,4-model-b.bin
bwfm0: NVRAM file default:brcmfmac43455-sdio.txt
bwfm0: NVRAM file model-spec: brcmfmac43455-sdio.raspberrypi,4-model-b.txt
bwfm0: Found NVRAM file: brcmfmac43455-sdio.raspberrypi,4-model-b.txt
bwfm0: CLM file default:brcmfmac43455-sdio.clm_blob
bwfm0: CLM file model-spec: brcmfmac43455-sdio.raspberrypi,4-model-b.clm_blob
bwfm0: Found CLM file: brcmfmac43455-sdio.raspberrypi,4-model-b.clm_blob
bwfm0: CHIPACTIVE

bwfm0: flags=0x8843 mtu 1500
ssid  nwkey *
powersave off
bssid ##:##:##:##:##:## chan 100
address: ##:##:##:##:##:##
media: IEEE802.11 autoselect (VHT mode 11ac)
status: active
inet6 fe80:::::%bwfm0/64 flags 0 scopeid 0x3




CVS commit: src/sys/dev/pckbport

2024-04-18 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Apr 18 17:35:53 UTC 2024

Modified Files:
src/sys/dev/pckbport: synaptics.c

Log Message:
Renamed border/boundary variables to better describe their use.
Fix edge default values, factor out percentage calculation for more consistent
values. Use device_printf/DPRINTF to show errors instead of aprint variants.
Print raw input for debugging.

Correct capability parsing. Old devices were probed with nonexistent
commands and then used undefined boundary values that made them unusuable.

Fixes PR 57874.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/pckbport/synaptics.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pckbport/synaptics.c
diff -u src/sys/dev/pckbport/synaptics.c:1.82 src/sys/dev/pckbport/synaptics.c:1.83
--- src/sys/dev/pckbport/synaptics.c:1.82	Tue Sep  5 05:55:12 2023
+++ src/sys/dev/pckbport/synaptics.c	Thu Apr 18 17:35:53 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: synaptics.c,v 1.82 2023/09/05 05:55:12 mrg Exp $	*/
+/*	$NetBSD: synaptics.c,v 1.83 2024/04/18 17:35:53 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2005, Steve C. Woodford
@@ -48,7 +48,7 @@
 #include "opt_pms.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.82 2023/09/05 05:55:12 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: synaptics.c,v 1.83 2024/04/18 17:35:53 mlelstv Exp $");
 
 #include 
 #include 
@@ -112,10 +112,10 @@ static int synaptics_edge_bottom = SYNAP
 static int synaptics_edge_motion_delta = 32;
 static u_int synaptics_finger_high = SYNAPTICS_FINGER_LIGHT + 5;
 static u_int synaptics_finger_low = SYNAPTICS_FINGER_LIGHT - 10;
-static int synaptics_horiz_pct = 0;
-static int synaptics_vert_pct = 0;
-static int synaptics_button_pct = 30;
-static int synaptics_button_boundary;
+static int synaptics_hscroll_pct = 0;
+static int synaptics_vscroll_pct = 0;
+static int synaptics_button_pct = 0;
+static int synaptics_button_boundary = SYNAPTICS_EDGE_BOTTOM;
 static int synaptics_button2;
 static int synaptics_button3;
 static int synaptics_two_fingers_emul = 0;
@@ -166,23 +166,26 @@ static int synaptics_movement_threshold_
 static int synaptics_movement_enable_nodenum;
 static int synaptics_button_region_movement_nodenum;
 static int synaptics_aux_mid_button_scroll_nodenum;
-static int synaptics_horiz_pct_nodenum;
-static int synaptics_vert_pct_nodenum;
+static int synaptics_hscroll_pct_nodenum;
+static int synaptics_vscroll_pct_nodenum;
 static int synaptics_button_pct_nodenum;
 
 /*
  * copy of edges so we can recalculate edge limit if there is 
  * vertical scroll region
  */
-static int synaptics_actual_edge_right;
-static int synaptics_actual_edge_bottom;
+static int synaptics_true_edge_right;
+static int synaptics_true_edge_bottom;
 
-static int synaptics_old_vert_pct = 0;
-static int synaptics_old_horiz_pct = 0;
-static int synaptics_old_button_pct = 0;
-static int synaptics_old_button_boundary = SYNAPTICS_EDGE_BOTTOM;
-static int synaptics_old_horiz_edge = SYNAPTICS_EDGE_BOTTOM;
-static int synaptics_old_vert_edge = SYNAPTICS_EDGE_RIGHT;
+/*
+ * invalid old values, recalculate everything
+ */
+static int synaptics_old_vscroll_pct = -1;
+static int synaptics_old_hscroll_pct = -1;
+static int synaptics_old_button_pct = -1;
+static int synaptics_old_button_boundary = -1;
+static int synaptics_old_edge_right = -1;
+static int synaptics_old_edge_bottom = -1;
 
 /*
  * This holds the processed packet data, it is global because multiple
@@ -208,7 +211,7 @@ synaptics_poll_cmd(struct pms_softc *psc
 	int res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot, cmd, i, 0,
 	NULL, 0);
 	if (res)
-		aprint_error_dev(psc->sc_dev, "command error %#x\n", cmd[0]);
+		device_printf(psc->sc_dev, "command error %#x\n", cmd[0]);
 	return res;
 }
 
@@ -221,7 +224,7 @@ synaptics_poll_reset(struct pms_softc *p
 	u_char cmd[1] = { PMS_RESET };
 	res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot, cmd, 1, 2,
 	resp, 1);
-	aprint_debug_dev(psc->sc_dev, "reset %d 0x%02x 0x%02x\n",
+	DPRINTF(10, >u.synaptics, "reset %d 0x%02x 0x%02x\n",
 	res, resp[0], resp[1]);
 	return res;
 }
@@ -251,80 +254,90 @@ synaptics_special_write(struct pms_softc
 	return res;
 }
 
+static int
+synaptics_value(int pct, int low, int high)
+{
+	return low + pct * (high - low) / 100UL;
+}
+
+static int
+synaptics_percentage(int val, int low, int high)
+{
+	return ((val - low) * 100UL + high - low - 1) / (high - low);
+}
+
 static void
 pms_synaptics_set_boundaries(void)
 {
-	if (synaptics_vert_pct != synaptics_old_vert_pct ) {
-		synaptics_edge_right = synaptics_actual_edge_right -
-		((unsigned long) synaptics_vert_pct *
-		(synaptics_actual_edge_right - synaptics_edge_left)) / 100;
-		synaptics_old_vert_pct = synaptics_vert_pct;
-		synaptics_old_vert_edge = synaptics_edge_right;
+	if (synaptics_vscroll_pct != synaptics_old_vscroll_pct ) {
+		

CVS commit: src/sys/dev/pckbport

2024-04-18 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Apr 18 17:35:53 UTC 2024

Modified Files:
src/sys/dev/pckbport: synaptics.c

Log Message:
Renamed border/boundary variables to better describe their use.
Fix edge default values, factor out percentage calculation for more consistent
values. Use device_printf/DPRINTF to show errors instead of aprint variants.
Print raw input for debugging.

Correct capability parsing. Old devices were probed with nonexistent
commands and then used undefined boundary values that made them unusuable.

Fixes PR 57874.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/pckbport/synaptics.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: xsrc/external/mit/xf86-input-ws/dist/src

2024-04-14 Thread Michael van Elst
Module Name:xsrc
Committed By:   mlelstv
Date:   Sun Apr 14 20:10:29 UTC 2024

Modified Files:
xsrc/external/mit/xf86-input-ws/dist/src: ws.c

Log Message:
Only limit the scroll warning, but continue to send the scroll events.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 xsrc/external/mit/xf86-input-ws/dist/src/ws.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/xf86-input-ws/dist/src/ws.c
diff -u xsrc/external/mit/xf86-input-ws/dist/src/ws.c:1.17 xsrc/external/mit/xf86-input-ws/dist/src/ws.c:1.18
--- xsrc/external/mit/xf86-input-ws/dist/src/ws.c:1.17	Wed Feb  7 18:01:48 2024
+++ xsrc/external/mit/xf86-input-ws/dist/src/ws.c	Sun Apr 14 20:10:29 2024
@@ -747,11 +747,13 @@ wsReadInput(InputInfoPtr pInfo)
 			dw = 0;
 		}
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 14
-		static int warned = 0;
-		if ((hscroll || vscroll) && !warned) {
-			warned = 1;
-			xf86Msg(X_WARNING, "%s: hscroll=%d, vscroll=%d\n",
-			pInfo->name, hscroll, vscroll);
+		if (hscroll || vscroll) {
+			static int warned = 0;
+			if (!warned) {
+warned = 1;
+xf86Msg(X_WARNING, "%s: hscroll=%d, vscroll=%d\n",
+pInfo->name, hscroll, vscroll);
+			}
 			valuator_mask_zero(priv->scroll_mask);
 			valuator_mask_set_double(priv->scroll_mask,
 			HSCROLL_AXIS, (double) hscroll);



CVS commit: xsrc/external/mit/xf86-input-ws/dist/src

2024-04-14 Thread Michael van Elst
Module Name:xsrc
Committed By:   mlelstv
Date:   Sun Apr 14 20:10:29 UTC 2024

Modified Files:
xsrc/external/mit/xf86-input-ws/dist/src: ws.c

Log Message:
Only limit the scroll warning, but continue to send the scroll events.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 xsrc/external/mit/xf86-input-ws/dist/src/ws.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: hostapd

2024-04-04 Thread Michael van Elst
On Thu, Apr 04, 2024 at 11:28:41AM +0100, Patrick Welche wrote:
> 10:15:22.135344 IP (tos 0x0, ttl 64, id 12912, offset 0, flags [DF], proto 
> TCP (6), length 60)
> 192.168.100.3.60610 > 192.168.100.62.80: Flags [S], cksum 0x783f 
> (correct), seq 50981267, win 65535, options [mss 1460,sackOK,TS val 2022496 
> ecr 0,nop,wscale 6], length 0

> I assume
> 
> hostapd: urtwn0: interface state UNINITIALIZED->ENABLED
> hostapd: urtwn0: AP-ENABLED 
> 
> rules out a monitor mode? or ? The dhcpd response was fine...

dhcpd uses BPF to receive and transmit DHCP packets. So the symptoms would 
point to an issue in the ARP or IP layer.

-- 
        Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: hostapd

2024-04-03 Thread Michael van Elst
pr...@welche.eu (Patrick Welche) writes:

>The system httpd via inetd doesn't receive a web page request from the
>device.
>tcpdump shows the device requesting it, but no response.

If httpd wouldn't run, the request would be answered with
a TCP RST.

If httpd does run, the request (SYN) is answered with a 
TCP SYN/ACK.

Can you say what exactly is "no response" here?


>on the server, telnet localhost 80, GET /, works

Did you configure (in /etc/inetd.conf) http for tcp or tcp6 ?
A 'telnet localhost 80' would see either, but a pure IPv4 client
only sees the 'tcp' one.


Greetings,



Re: raidframe and gpt

2024-03-16 Thread Michael van Elst
p...@whooppee.com (Paul Goyette) writes:

>> Does anyone have an example of how to configure raid0 on a GPT disk?

For a manual setup, you can just reference the wedges like:

# raidctl config file for /dev/rraid0

START array
# numRow numCol numSpare
1 2 0

START disks
NAME=raid0.0
NAME=raid0.1

START layout
# sectPerSU SUsPerParityUnit SUsPerReconUnit RAID_level_1
128 1 1 1

START queue
fifo 100


Auto detection of a RAID works by collecting disks with valid
RAID labels into RAID sets. This also works with wedges, the
actual device or unit number is irrelevant, the RAID set is
identified by the unique serial number in the RAID label.
The serial number is specified with the -I option of raidctl.

Even booting from a RAID on GPT is possible with a recent bootloader
and an autoconfigured RAID set.


Here is more about RAID on GPT:

https://wiki.netbsd.org/users/spz/moderndisk/



>> I can easily set the partition type with gpt, but how do I reserve
>> space for the raid component label?  Do I need to reserve that space?

You don't, the components are the GPT partitions.


>> Also, does raidframe understand the NAME=gpt-label syntax in the
>> config file?  Or does it require me to specify the particular dk ?
>> (And what happens if something moves and  changes?)

I've added support for the NAME= Syntax some time ago.


>One more quuestion: the raidctl man page talks about partitioning the
>raid device using mbr partitions.  Is it possible to use GPT here?
>Will the resulting wedges show up automatically?

Whenever you create a raid device (raidN attaches), it will be
scanned for wedges like a regular disk device.

# dkctl dk4 getwedgeinfo
dk4 at raid2: tank
dk4: 4294967296 blocks at 128, type: ffs

# grep tank /etc/fstab
NAME=tank   /tank   ffs rw,log  1 2

This system configures a RAID1 of two RAID0 sets. That's not supported
by the RAID autoconfiguration, so it is created manually at boot time
and obviously the system can't boot from it.




Re: mbrlabel question

2024-03-15 Thread Michael van Elst
ea1...@gmail.com (Ramiro Aceves) writes:

> The following options are available:
> -f Force an update, even if there has been no change.
> -q Performs operations in a quiet fashion.
> -r In conjunction with -w, also update the on-disk label.
> -s sector  Specifies the logical sector number that has to be read from
>the disk in order to find the MBR.  Useful if the disk has
>remapping drivers on it and the MBR is located in a non-
>standard place.  Defaults to 0. 
> -w Update the in-core label if it has been changed.  See also -r.

>I do not know the difference between the in-core and on-disk options,
>what I should use and if I can break something with it.


The BSD partition information (aka "disklabel") exists in memory ("in-core")
and is also written to disk ("on-disk").

If you change only in-core, the change is temporary and volatile. When
the disk is no longer in use, or after a reboot, the changes are gone.

For permanent changes you need to write the on-disk label.

I.e. use

mbrlabel wd0

to show how the disklabel would look like, and use

mbrlabel -rw wd0

to actually change the disklabel permanently.



Re: dwiic errors

2024-03-14 Thread Michael van Elst
p...@whooppee.com (Paul Goyette) writes:

>as soon as you proceed past this point (including normal non-single-
>user boot), the dwiic starts spewing time-out messages.  These
>messages come every 0.5 second or so, and there's usually a hundred
>or more messages before they stop;  in some cases the messages have
>continued to stream by for several minutes (at which point I pressed
>the reset button).  The value for %d is always 0 or 1.

Probably result of

GENERIC:ihidev* at iic?

that is probing for a modern laptop touchpad.

Can you disable ihidev instead of dwiic and see what happens then ?



Re: Problem with umass/scsibus/wd0

2024-03-13 Thread Michael van Elst
On Tue, Mar 12, 2024 at 11:00:02PM -0700, Paul Goyette wrote:
> 
> ``scsictl sd0 start'' makes a little bit of progress, and claims
> to be "fabricating a geometry".  ``gpt show -a sd0'' shows two
> partitions (one for NetBSD backups, and one for Windoze backups)
> 
>   # gpt show sd0
>  startsize  index  contents
>  0   1 PMBR
>  1   1 Pri GPT header
>  2  32 Pri GPT table
> 342014 Unused
>   2048  4294967296  1  GPT part - NetBSD FFSv1/FFSv2
> 4294969344  3518951424  2  GPT part - Windows basic data
> 7813920768   49119 Unused
> 7813969887  32 Sec GPT table
> 7813969919   1 Sec GPT header

That looks fine.

> But it does not seem to progress to the discover-wedges process,
> and no wedges seem to exist:
> 
>   # dkctl sd0 listwedges
>   /dev/rsd0: no wedges configured

The wedge autodetection happens when the device attaches (and failed
since the disk was offline). This is different from disklabels that
are fetched by the first opener (and are usually dropped with
the last close, except traditionally for vnd).

You can manually trigger autodetection with

dkctl sd0 makewedges



Greetings,
-- 
Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: Problem with umass/scsibus/wd0

2024-03-12 Thread Michael van Elst
p...@whooppee.com (Paul Goyette) writes:


>[ 29641.773703] umass0 at uhub11 port 4 configuration 1 interface 0
>[ 29641.773703] umass0: Western Digital (0x1058) Elements 2621 (0x2621), rev 
>3.20/10.34, addr 4
>[ 29641.773703] umass0: using SCSI over Bulk-Only
>[ 29641.793714] scsibus0 at umass0: 2 targets, 1 lun per target
>[ 29641.793714] sd0 at scsibus0 target 0 lun 0:  disk 
>fixed
>[ 29641.793714] sd0(umass0:0:0:0):  Check Condition on CDB: 0x00 00 00 00 00 00
>[ 29641.793714] SENSE KEY:  Not Ready
>[ 29641.793714]  ASC/ASCQ:  Logical Unit Is In Process Of Becoming Ready
>[ 29641.793714] sd0: drive offline


Sounds like that drive isn't spinning up.

The "Elements" product doesn't exactly tell what it is, some units
either come with their own power supply or require non-standard
USB power.

Maybe 'scsictl sd0 start' helps to get the disk online. If that
has an effect you may need 'dkctl sd0 makewedges' if you use a GPT
label.



CVS commit: src/lib/libcrypt

2024-03-09 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Mar  9 13:48:50 UTC 2024

Modified Files:
src/lib/libcrypt: crypt-argon2.c

Log Message:
Don't use uninitialized variable.
Fixes PR 57895.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libcrypt/crypt-argon2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libcrypt/crypt-argon2.c
diff -u src/lib/libcrypt/crypt-argon2.c:1.19 src/lib/libcrypt/crypt-argon2.c:1.20
--- src/lib/libcrypt/crypt-argon2.c:1.19	Sun May 29 12:15:00 2022
+++ src/lib/libcrypt/crypt-argon2.c	Sat Mar  9 13:48:50 2024
@@ -207,7 +207,7 @@ estimate_argon2_params(argon2_type atype
 
 		if (clock_gettime(CLOCK_MONOTONIC, ) == -1)
 			goto error;
-		for (; delta.tv_sec < 1 && time < ARGON2_MAX_TIME; ++time) {
+		for (; time < ARGON2_MAX_TIME; ++time) {
 			if (argon2_hash(time, memory, threads,
 			tmp_pwd, sizeof(tmp_pwd), 
 			tmp_salt, sizeof(tmp_salt), 
@@ -221,6 +221,8 @@ estimate_argon2_params(argon2_type atype
 			if (timespeccmp(, , >))
 break; /* broken system... */
 			timespecsub(, , );
+			if (delta.tv_sec >= 1)
+break;
 		}
 	} else {
 		time = *etime;



CVS commit: src/lib/libcrypt

2024-03-09 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Mar  9 13:48:50 UTC 2024

Modified Files:
src/lib/libcrypt: crypt-argon2.c

Log Message:
Don't use uninitialized variable.
Fixes PR 57895.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libcrypt/crypt-argon2.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: ccd error with two large components

2024-03-03 Thread Michael van Elst
roland.il...@gmx.de (Roland Illig) writes:

>That's this line:

>> unit =3D *(const int *)newp;

>I don't know at which point newp is validated; maybe that validation is
>missing in this case, although I'd expect it to be in the common sysctl
>infrastructure code.


newp is valid, it's a userland pointer that gets dereferenced by the
kernel. Without SMAP that probably even worked on x86.






CVS commit: src/sys/kern

2024-03-02 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Mar  2 08:59:47 UTC 2024

Modified Files:
src/sys/kern: sysv_shm.c

Log Message:
Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.
Should fix PR 57979


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/kern/sysv_shm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sysv_shm.c
diff -u src/sys/kern/sysv_shm.c:1.141 src/sys/kern/sysv_shm.c:1.142
--- src/sys/kern/sysv_shm.c:1.141	Wed Oct  9 17:47:13 2019
+++ src/sys/kern/sysv_shm.c	Sat Mar  2 08:59:47 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: sysv_shm.c,v 1.141 2019/10/09 17:47:13 chs Exp $	*/
+/*	$NetBSD: sysv_shm.c,v 1.142 2024/03/02 08:59:47 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.141 2019/10/09 17:47:13 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysv_shm.c,v 1.142 2024/03/02 08:59:47 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sysv.h"
@@ -961,10 +961,10 @@ shminit(void)
 	ALIGN(shminfo.shmmni * sizeof(struct shmid_ds)));
 
 	if (shminfo.shmmax == 0)
-		shminfo.shmmax = uimax(physmem / 4, 1024) * PAGE_SIZE;
+		shminfo.shmall = uimax(physmem / 4, 1024);
 	else
-		shminfo.shmmax *= PAGE_SIZE;
-	shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
+		shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
+	shminfo.shmmax = (uint64_t)shminfo.shmall * PAGE_SIZE;
 
 	for (i = 0; i < shminfo.shmmni; i++) {
 		cv_init(_cv[i], "shmwait");
@@ -1083,7 +1083,7 @@ sysctl_ipc_shmmax(SYSCTLFN_ARGS)
 		return EINVAL;
 
 	shminfo.shmmax = round_page(newsize);
-	shminfo.shmall = shminfo.shmmax >> PAGE_SHIFT;
+	shminfo.shmall = shminfo.shmmax / PAGE_SIZE;
 
 	return 0;
 }



CVS commit: src/sys/kern

2024-03-02 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Mar  2 08:59:47 UTC 2024

Modified Files:
src/sys/kern: sysv_shm.c

Log Message:
Avoid overflow when computing kern.ipc.shmmax. Keep shmmax (bytes) and
shmall (pages) values aligned and use arithmetic everywhere instead
of shifts.
Should fix PR 57979


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/kern/sysv_shm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: NetBSD and ECC RAM?

2024-02-29 Thread Michael van Elst
kevin.bowl...@kev009.com (Kevin Bowling) writes:

>Servers tend to have BMCs, so you can execute 'ipmitool sensors' and
>'ipmi sel elist' to get the information out.

ECC information is usually not provided by sensors. ECC errors may
be listed in the SEL, but even this usually occurs only when some
undocumented limit is reached. Often the messages also do not indicate
the memory module that produced the error.


>Linux has the 'EDAC' subsystem but I don't think it gains you so much
>if you have a BMC.

It gives you the data from the ECC circuits, immediately. So data is
no longer hidden by the BMC, you get precise information and you can
apply your own policies for e.g. replacing memory modules or migrating
services to other hardware.

The OS could be smart, lock out bad memory regions, recover some
errors by e.g. paging in text data again or even use mirrored RAM
(with motherboard support).


>A lot of fragile chipset specific code to get that.

Indeed.


Greetings,



CVS commit: src/sys/arch/virt68k/virt68k

2024-02-25 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Feb 25 14:35:31 UTC 2024

Modified Files:
src/sys/arch/virt68k/virt68k: trap.c

Log Message:
Don't crash in copyin/copyout when a NULL pointer is passed.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/virt68k/virt68k/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/virt68k/virt68k

2024-02-25 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Feb 25 14:35:31 UTC 2024

Modified Files:
src/sys/arch/virt68k/virt68k: trap.c

Log Message:
Don't crash in copyin/copyout when a NULL pointer is passed.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/virt68k/virt68k/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/virt68k/virt68k/trap.c
diff -u src/sys/arch/virt68k/virt68k/trap.c:1.2 src/sys/arch/virt68k/virt68k/trap.c:1.3
--- src/sys/arch/virt68k/virt68k/trap.c:1.2	Sat Jan 20 00:15:33 2024
+++ src/sys/arch/virt68k/virt68k/trap.c	Sun Feb 25 14:35:31 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.2 2024/01/20 00:15:33 thorpej Exp $	*/
+/*	$NetBSD: trap.c,v 1.3 2024/02/25 14:35:31 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.2 2024/01/20 00:15:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.3 2024/02/25 14:35:31 mlelstv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_execfmt.h"
@@ -554,7 +554,7 @@ trap(struct frame *fp, int type, unsigne
 
 		va = trunc_page((vaddr_t)v);
 
-		if (map == kernel_map && va == 0) {
+		if (map == kernel_map && va == 0 && onfault == 0) {
 			printf("trap: bad kernel %s access at 0x%x\n",
 			(ftype & VM_PROT_WRITE) ? "read/write" :
 			"read", v);



Re: Issues with lseek(2) on a block device

2024-02-24 Thread Michael van Elst
t...@panix.com (Thor Lancelot Simon) writes:

>Probably not a good idea to start with lseek() because if you _do_
>encounter a tape device, seeking to SEEK_END could take you an extremely
>long time.

lseek() doesn't move the tape. But the open() or close() may trigger
tape operations like loading or winding. Special files are special.



CVS commit: src/sys/dev/scsipi

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 22:06:50 UTC 2024

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
Don't try to discover wedges when the unit isn't online.


To generate a diff of this commit:
cvs rdiff -u -r1.335 -r1.336 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 22:06:50 UTC 2024

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
Don't try to discover wedges when the unit isn't online.


To generate a diff of this commit:
cvs rdiff -u -r1.335 -r1.336 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.335 src/sys/dev/scsipi/sd.c:1.336
--- src/sys/dev/scsipi/sd.c:1.335	Sun Aug 28 10:26:37 2022
+++ src/sys/dev/scsipi/sd.c	Sat Feb 24 22:06:49 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.335 2022/08/28 10:26:37 mlelstv Exp $	*/
+/*	$NetBSD: sd.c,v 1.336 2024/02/24 22:06:49 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.335 2022/08/28 10:26:37 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.336 2024/02/24 22:06:49 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -351,8 +351,9 @@ sdattach(device_t parent, device_t self,
 	}
 	aprint_normal("\n");
 
-	/* Discover wedges on this disk. */
-	dkwedge_discover(>sc_dkdev);
+	/* Discover wedges on this disk if it is online */
+	if (result == SDGP_RESULT_OK)
+		dkwedge_discover(>sc_dkdev);
 
 	/*
 	 * Establish a shutdown hook so that we can ensure that



CVS commit: src/sys/netinet6

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 21:41:13 UTC 2024

Modified Files:
src/sys/netinet6: icmp6.c raw_ip6.c

Log Message:
Deliver timestamps also to raw sockets.
Fixes PR 57955


To generate a diff of this commit:
cvs rdiff -u -r1.255 -r1.256 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.183 -r1.184 src/sys/netinet6/raw_ip6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/netinet6

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 21:41:13 UTC 2024

Modified Files:
src/sys/netinet6: icmp6.c raw_ip6.c

Log Message:
Deliver timestamps also to raw sockets.
Fixes PR 57955


To generate a diff of this commit:
cvs rdiff -u -r1.255 -r1.256 src/sys/netinet6/icmp6.c
cvs rdiff -u -r1.183 -r1.184 src/sys/netinet6/raw_ip6.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet6/icmp6.c
diff -u src/sys/netinet6/icmp6.c:1.255 src/sys/netinet6/icmp6.c:1.256
--- src/sys/netinet6/icmp6.c:1.255	Sat Dec  9 15:21:02 2023
+++ src/sys/netinet6/icmp6.c	Sat Feb 24 21:41:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.255 2023/12/09 15:21:02 pgoyette Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.256 2024/02/24 21:41:13 mlelstv Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.255 2023/12/09 15:21:02 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.256 2024/02/24 21:41:13 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1987,7 +1987,8 @@ icmp6_rip6_input(struct mbuf **mp, int o
 		}
 #endif
 		else if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
-			if (last->inp_flags & IN6P_CONTROLOPTS)
+			if (last->inp_flags & IN6P_CONTROLOPTS ||
+			SOOPT_TIMESTAMP(last->inp_socket->so_options))
 ip6_savecontrol(last, , ip6, n);
 			/* strip intermediate headers */
 			m_adj(n, off);
@@ -2014,7 +2015,8 @@ icmp6_rip6_input(struct mbuf **mp, int o
 	} else
 #endif
 	if (last) {
-		if (last->inp_flags & IN6P_CONTROLOPTS)
+		if (last->inp_flags & IN6P_CONTROLOPTS ||
+		SOOPT_TIMESTAMP(last->inp_socket->so_options))
 			ip6_savecontrol(last, , ip6, m);
 		/* strip intermediate headers */
 		m_adj(m, off);

Index: src/sys/netinet6/raw_ip6.c
diff -u src/sys/netinet6/raw_ip6.c:1.183 src/sys/netinet6/raw_ip6.c:1.184
--- src/sys/netinet6/raw_ip6.c:1.183	Wed Mar 22 03:17:18 2023
+++ src/sys/netinet6/raw_ip6.c	Sat Feb 24 21:41:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: raw_ip6.c,v 1.183 2023/03/22 03:17:18 ozaki-r Exp $	*/
+/*	$NetBSD: raw_ip6.c,v 1.184 2024/02/24 21:41:13 mlelstv Exp $	*/
 /*	$KAME: raw_ip6.c,v 1.82 2001/07/23 18:57:56 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.183 2023/03/22 03:17:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.184 2024/02/24 21:41:13 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -140,7 +140,8 @@ rip6_sbappendaddr(struct inpcb *last, st
 {
 	struct mbuf *opts = NULL;
 
-	if (last->inp_flags & IN6P_CONTROLOPTS)
+	if (last->inp_flags & IN6P_CONTROLOPTS ||
+	SOOPT_TIMESTAMP(last->inp_socket->so_options))
 		ip6_savecontrol(last, , ip6, n);
 
 	m_adj(n, hlen);



CVS commit: src/sys/netinet

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 21:39:05 UTC 2024

Modified Files:
src/sys/netinet: if_arp.c

Log Message:
Attribute debug message.
Fixes PR 57959


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 src/sys/netinet/if_arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.311 src/sys/netinet/if_arp.c:1.312
--- src/sys/netinet/if_arp.c:1.311	Tue Nov 15 10:47:39 2022
+++ src/sys/netinet/if_arp.c	Sat Feb 24 21:39:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.311 2022/11/15 10:47:39 roy Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.312 2024/02/24 21:39:05 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.311 2022/11/15 10:47:39 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.312 2024/02/24 21:39:05 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1355,8 +1355,8 @@ arp_llinfo_output(struct ifnet *ifp, __u
 		if (sip.s_addr == INADDR_ANY) {
 			char ipbuf[INET_ADDRSTRLEN];
 
-			log(LOG_DEBUG, "source can't be "
-			"determined: dst=%s\n",
+			log(LOG_DEBUG, "%s: source can't be "
+			"determined: dst=%s\n", __func__,
 			IN_PRINT(ipbuf, ));
 			return;
 		}



CVS commit: src/sys/netinet

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 21:39:05 UTC 2024

Modified Files:
src/sys/netinet: if_arp.c

Log Message:
Attribute debug message.
Fixes PR 57959


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 src/sys/netinet/if_arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/seq

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 10:10:05 UTC 2024

Modified Files:
src/usr.bin/seq: seq.c

Log Message:
Chose better number format.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/seq/seq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/seq/seq.c
diff -u src/usr.bin/seq/seq.c:1.12 src/usr.bin/seq/seq.c:1.13
--- src/usr.bin/seq/seq.c:1.12	Sat Mar 20 22:10:17 2021
+++ src/usr.bin/seq/seq.c	Sat Feb 24 10:10:04 2024
@@ -31,7 +31,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 2005\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: seq.c,v 1.12 2021/03/20 22:10:17 cheusov Exp $");
+__RCSID("$NetBSD: seq.c,v 1.13 2024/02/24 10:10:04 mlelstv Exp $");
 #endif /* not lint */
 
 #include 
@@ -56,6 +56,8 @@ __RCSID("$NetBSD: seq.c,v 1.12 2021/03/2
 
 const char *decimal_point = ".";	/* default */
 char default_format[] = { "%g" };	/* default */
+char default_format_fmt[] = { "%%.%uf" };
+#define MAXPRECISION 40
 
 /* Prototypes */
 
@@ -65,9 +67,29 @@ int decimal_places(const char *);
 int numeric(const char *);
 int valid_format(const char *);
 
-char *generate_format(double, double, double, int, char);
+unsigned get_precision(const char *, unsigned);
+char *generate_format(double, double, double, int, char, char *);
 char *unescape(char *);
 
+unsigned
+get_precision(const char *number, unsigned minprec)
+{
+	const char *p;
+	unsigned prec;
+
+	p = strstr(number, decimal_point);
+	if (p) {
+		prec = strlen(number) - (p - number);
+		if (prec > 0)
+			prec -= 1;
+		if (prec > MAXPRECISION)
+			prec = MAXPRECISION;
+	} else
+		prec = 0;
+
+	return prec < minprec ? minprec : prec;
+}
+
 /*
  * The seq command will print out a numeric sequence from 1, the default,
  * to a user specified upper limit by 1.  The lower bound and increment
@@ -79,6 +101,7 @@ main(int argc, char *argv[])
 {
 	int c = 0, errflg = 0;
 	int equalize = 0;
+	unsigned prec;
 	double first = 1.0;
 	double last = 0.0;
 	double incr = 0.0;
@@ -87,6 +110,8 @@ main(int argc, char *argv[])
 	const char *sep = "\n";
 	const char *term = "\n";
 	char pad = ZERO;
+	char buf[6]; /* %.MAXPRECISIONf */
+
 
 	/* Determine the locale's decimal point. */
 	locale = localeconv();
@@ -136,12 +161,16 @@ main(int argc, char *argv[])
 	}
 
 	last = e_atof(argv[argc - 1]);
+	prec = get_precision(argv[argc - 1], 0);
 
-	if (argc > 1)
+	if (argc > 1) {
 		first = e_atof(argv[0]);
+		prec = get_precision(argv[0], prec);
+	}
 	
 	if (argc > 2) {
 		incr = e_atof(argv[1]);
+		prec = get_precision(argv[1], prec);
 		/* Plan 9/GNU don't do zero */
 		if (incr == 0.0)
 			errx(1, "zero %screment", (first < last)? "in" : "de");
@@ -167,8 +196,15 @@ main(int argc, char *argv[])
 	 * XXX to be bug for bug compatible with Plan 9 add a
 		 * newline if none found at the end of the format string.
 		 */
-	} else
-		fmt = generate_format(first, incr, last, equalize, pad);
+	} else {
+		if (prec == 0)
+			fmt = default_format;
+		else {
+			sprintf(buf, default_format_fmt, prec);
+			fmt = buf;
+		}
+		fmt = generate_format(first, incr, last, equalize, pad, fmt);
+	}
 
 	if (incr > 0) {
 		printf(fmt, first);
@@ -428,14 +464,15 @@ decimal_places(const char *number)
  * when "%g" prints as "%e" (this way no width adjustments are made)
  */
 char *
-generate_format(double first, double incr, double last, int equalize, char pad)
+generate_format(double first, double incr, double last,
+int equalize, char pad, char *deffmt)
 {
 	static char buf[256];
 	char cc = '\0';
 	int precision, width1, width2, places;
 
 	if (equalize == 0)
-		return (default_format);
+		return deffmt;
 
 	/* figure out "last" value printed */
 	if (first > last)
@@ -443,12 +480,12 @@ generate_format(double first, double inc
 	else
 		last = first + incr * floor((last - first) / incr);
 
-	sprintf(buf, "%g", incr);
+	sprintf(buf, deffmt, incr);
 	if (strchr(buf, 'e'))
 		cc = 'e';
 	precision = decimal_places(buf);
 
-	width1 = sprintf(buf, "%g", first);
+	width1 = sprintf(buf, deffmt, first);
 	if (strchr(buf, 'e'))
 		cc = 'e';
 	if ((places = decimal_places(buf)))
@@ -456,7 +493,7 @@ generate_format(double first, double inc
 
 	precision = MAX(places, precision);
 
-	width2 = sprintf(buf, "%g", last);
+	width2 = sprintf(buf, deffmt, last);
 	if (strchr(buf, 'e'))
 		cc = 'e';
 	if ((places = decimal_places(buf)))



CVS commit: src/usr.bin/seq

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 10:10:05 UTC 2024

Modified Files:
src/usr.bin/seq: seq.c

Log Message:
Chose better number format.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/seq/seq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/netstat

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 09:53:26 UTC 2024

Modified Files:
src/usr.bin/netstat: mbuf.c

Log Message:
Don't truncate mo_descr output and protect against missing terminating NUL.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/mbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/mbuf.c
diff -u src/usr.bin/netstat/mbuf.c:1.35 src/usr.bin/netstat/mbuf.c:1.36
--- src/usr.bin/netstat/mbuf.c:1.35	Thu Sep  1 10:10:20 2022
+++ src/usr.bin/netstat/mbuf.c	Sat Feb 24 09:53:26 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mbuf.c,v 1.35 2022/09/01 10:10:20 msaitoh Exp $	*/
+/*	$NetBSD: mbuf.c,v 1.36 2024/02/24 09:53:26 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)mbuf.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mbuf.c,v 1.35 2022/09/01 10:10:20 msaitoh Exp $");
+__RCSID("$NetBSD: mbuf.c,v 1.36 2024/02/24 09:53:26 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -225,7 +225,7 @@ dump_drain:
 
 	for (mo = (void *) data, lines = 0; len >= sizeof(*mo);
 	len -= sizeof(*mo), mo++) {
-		char buf[32];
+		char buf[34];
 		if (vflag == 1 &&
 		mo->mo_counter[MOWNER_COUNTER_CLAIMS] == 0 &&
 		mo->mo_counter[MOWNER_COUNTER_EXT_CLAIMS] == 0 &&
@@ -239,7 +239,7 @@ dump_drain:
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_CLAIMS] ==
 		mo->mo_counter[MOWNER_COUNTER_CLUSTER_RELEASES])
 			continue;
-		snprintf(buf, sizeof(buf), "%16.16s %-13s",
+		snprintf(buf, sizeof(buf), "%16.16s %-13.16s",
 		mo->mo_name, mo->mo_descr);
 		if ((lines % 24) == 0 || lines > 24) {
 			printf("%30s %-8s %10s %10s %10s\n",



CVS commit: src/usr.bin/netstat

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 09:53:26 UTC 2024

Modified Files:
src/usr.bin/netstat: mbuf.c

Log Message:
Don't truncate mo_descr output and protect against missing terminating NUL.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/netstat/mbuf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: Issues with lseek(2) on a block device

2024-02-22 Thread Michael van Elst
mlel...@serpens.de (Michael van Elst) writes:

>But it also does not work for wedges or device mapper volumes
>(zfs vol probably fail too) as these don't implement the
>used internal ioctl for disk devices. At least that part
>would be easy to fix, but of questionable value.



Like this:

Index: sys/miscfs/specfs/spec_vnops.c
===
RCS file: /cvsroot/src/sys/miscfs/specfs/spec_vnops.c,v
retrieving revision 1.218
diff -p -u -r1.218 spec_vnops.c
--- sys/miscfs/specfs/spec_vnops.c  22 Apr 2023 15:32:49 -  1.218
+++ sys/miscfs/specfs/spec_vnops.c  22 Feb 2024 08:54:16 -
@@ -727,11 +727,11 @@ spec_open(void *v)
enum kauth_device_req req;
specnode_t *sn, *sn1;
specdev_t *sd;
+   int dtype;
spec_ioctl_t ioctl;
u_int gen = 0;
const char *name = NULL;
bool needclose = false;
-   struct partinfo pi;
 
KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
KASSERTMSG(vp->v_type == VBLK || vp->v_type == VCHR, "type=%d",
@@ -1038,11 +1038,23 @@ spec_open(void *v)
 * forbidden to devsw_detach until closed).  So it is safe to
 * query cdev_type unconditionally here.
 */
-   if (cdev_type(dev) == D_DISK) {
-   ioctl = vp->v_type == VCHR ? cdev_ioctl : bdev_ioctl;
-   if ((*ioctl)(dev, DIOCGPARTINFO, , FREAD, curlwp) == 0)
-   uvm_vnp_setsize(vp,
-   (voff_t)pi.pi_secsize * pi.pi_size);
+   switch (vp->v_type) {
+   case VCHR:
+   ioctl = bdev_ioctl;
+   dtype = cdev_type(dev);
+   break;
+   default:
+   ioctl = bdev_ioctl;
+   dtype = bdev_type(dev);
+   break;
+   }
+   if (dtype == D_DISK) {
+   off_t count;
+   u_int sz;
+
+   if ((*ioctl)(dev, DIOCGMEDIASIZE, , FREAD, curlwp) == 0
+   && (*ioctl)(dev, DIOCGSECTORSIZE, , FREAD, curlwp) == 0)
+   uvm_vnp_setsize(vp, (voff_t)count * sz);
}
 
/* Success!  */



Re: Issues with lseek(2) on a block device

2024-02-21 Thread Michael van Elst
cryintotheblue...@gmail.com (Sad Clouds) writes:

>Hello, for most operating systems determining the size of a block
>device can be done with:

>lseek(fd, 0, SEEK_END);

>However, on NetBSD this does not seem to work.


The disk size is only retrieved at open time and stored in the
cached vnode. stat() therefore only sees the information as
long as the vnode is in cache. Before open, the vnode stores
the bits from e.g. the UFS inode, for UFS that would be zero.

It also does not work for block devices as these aren't really
opened when you call open(). Character devices ("raw disk")
are better, the lseek() or fstat() methods do work for raw
disk devices.

But it also does not work for wedges or device mapper volumes
(zfs vol probably fail too) as these don't implement the
used internal ioctl for disk devices. At least that part
would be easy to fix, but of questionable value.


Currently the only reliable way is to use ioctls. You can use
DIOCGDISKINFO (with proplib) or you can use the two FreeBSD ioctls
DIOCGMEDIASIZE and DIOCGSECTORSIZE to retrieve block count and
size individually as numbers.

For compatibility with netbsd < 8 you may need to fall back to
various older ioctls. That's what is still being implemented
for tools like fsck.




Re: NetBSD and ECC RAM?

2024-02-18 Thread Michael van Elst
michael.chepo...@gmail.com (Michael Cheponis) writes:

>I've been running ECC in the Windows box for years, it seems like a 'no
>brainer' for servers. Servers usually run for years, and Stuff Happens over
>the years [1].
>But I'd prefer a reliable, unhackable, trustable compute fabric.  ECC is
>part of the 'reliable' part.

I agree, but the "box" will run with ECC, even when the OS doesn't
know about it. OS support is needed to get information about errors
and for better fault tolerance.


>I would also like to see per /dev entry ACLs.  I would like to see better
>security than owner-group-everbody permissions.

I have rarely seen ACLs being used for "better security". Even when that
was possible, the complexity usually outweighed any gain in control.

Systems that implied access control through simple rules worked much
better. It's still not a feature that you had to enable or a switch
you toggled, it requires constant effort, in particular on systems
that don't just perform a fixed set of functions.



Re: bug in ftp(1)?

2024-02-18 Thread Michael van Elst
w...@netbsd.org (Thomas Klausner) writes:

>ftp: Receiving HTTP reply: Input line is too long

#define   FTPBUFLEN   (4 * MAXPATHLEN)
char buf[FTPBUFLEN];

That's 4kB.

>curl -v https://sourceforge.net/projects/courier/files/courier-unicode/2.3.=
>0/courier-unicode-2.3.0.tar.bz2

This returns a 5kB HTTP header "content-security-policy".

There is no protocol limit, but common server implementations do limit header
lines to something between 4k (some nginx versions) to 48k (tomcat).



CVS commit: src/sys/ufs/lfs

2024-02-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 17 09:08:21 UTC 2024

Modified Files:
src/sys/ufs/lfs: ulfs_inode.h

Log Message:
Whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/ufs/lfs/ulfs_inode.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/lfs/ulfs_inode.h
diff -u src/sys/ufs/lfs/ulfs_inode.h:1.24 src/sys/ufs/lfs/ulfs_inode.h:1.25
--- src/sys/ufs/lfs/ulfs_inode.h:1.24	Sat Jun 10 05:29:36 2017
+++ src/sys/ufs/lfs/ulfs_inode.h	Sat Feb 17 09:08:21 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_inode.h,v 1.24 2017/06/10 05:29:36 maya Exp $	*/
+/*	$NetBSD: ulfs_inode.h,v 1.25 2024/02/17 09:08:21 mlelstv Exp $	*/
 /*  from NetBSD: inode.h,v 1.72 2016/06/03 15:36:03 christos Exp  */
 
 /*
@@ -147,7 +147,7 @@ struct ulfs_ufid {
 	uint16_t ufid_len;	/* Length of structure. */
 	uint16_t ufid_pad;	/* Force 32-bit alignment. */
 	uint32_t ufid_ino;	/* File number (ino). XXX should be 64 */
-	int32_t	  ufid_gen;	/* Generation number. */
+	int32_t  ufid_gen;	/* Generation number. */
 };
 /* Filehandle structure for exported LFSes */
 struct lfid {



CVS commit: src/sys/ufs/lfs

2024-02-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 17 09:08:21 UTC 2024

Modified Files:
src/sys/ufs/lfs: ulfs_inode.h

Log Message:
Whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/ufs/lfs/ulfs_inode.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: NetBSD and ECC RAM?

2024-02-15 Thread Michael van Elst
h...@spg.tu-darmstadt.de ("Hauke Fath (SPG)") writes:

>one my favourite blogs is sporting a page on AMD ECC RAM support
>,

>Is this of any relevance to NetBSD, or do we just not bother?


We should have EDAC drivers that should at least report events,
but so far there is nothing...




CVS commit: src/distrib/utils/embedded

2024-02-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Feb 12 11:30:33 UTC 2024

Modified Files:
src/distrib/utils/embedded: mkimage

Log Message:
Quote argument to -n as required. [ -n ] is not a syntax error but
evaluates to true.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/distrib/utils/embedded/mkimage

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/utils/embedded/mkimage
diff -u src/distrib/utils/embedded/mkimage:1.80 src/distrib/utils/embedded/mkimage:1.81
--- src/distrib/utils/embedded/mkimage:1.80	Sun Feb 11 17:29:50 2024
+++ src/distrib/utils/embedded/mkimage	Mon Feb 12 11:30:33 2024
@@ -1,5 +1,5 @@
 #!/bin/sh
-# $NetBSD: mkimage,v 1.80 2024/02/11 17:29:50 christos Exp $
+# $NetBSD: mkimage,v 1.81 2024/02/12 11:30:33 mlelstv Exp $
 #
 # Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -190,7 +190,7 @@ do
 	*)	usage;;
 	esac
 done
-if [ -n ${MKREPRO_TIMESTAMP} ]; then
+if [ -n "${MKREPRO_TIMESTAMP}" ]; then
 	timestamp_opt="-T ${MKREPRO_TIMESTAMP}"
 	volume_opt=",volume_id=$((${MKREPRO_TIMESTAMP} & 0x))"
 fi



CVS commit: src/distrib/utils/embedded

2024-02-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Feb 12 11:30:33 UTC 2024

Modified Files:
src/distrib/utils/embedded: mkimage

Log Message:
Quote argument to -n as required. [ -n ] is not a syntax error but
evaluates to true.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/distrib/utils/embedded/mkimage

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: Raspberry Pi Zero W almost useless

2024-02-09 Thread Michael van Elst
ea1...@gmail.com (Ramiro Aceves) writes:

>Oh yes, that would be a right technical fix for the problem but it's a 
>bit of an aberration in terms of cost and size to use a powered HUB with 
>its own power supply to fix a little thing like the ZeroW, you know ;-)

RPI0-3 models all have issues with power.

Especially on the original RPI1 and RPI0 variants you shouldn't
consider USB as being "hot pluggable". For the other models
hot-plugging low power USB devices (i.e. using 100mA or less)
should be fine. Unfortunately that might rule out things like
many gaming keyboards and also some WLAN dongles.



CVS commit: src/sys/dev/pci

2024-02-08 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Feb  9 06:01:03 UTC 2024

Modified Files:
src/sys/dev/pci: if_iwm.c

Log Message:
Fix DMA sync sizes.
Don't panic for inconsistent queue counter, just print an error to console.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/pci/if_iwm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_iwm.c
diff -u src/sys/dev/pci/if_iwm.c:1.88 src/sys/dev/pci/if_iwm.c:1.89
--- src/sys/dev/pci/if_iwm.c:1.88	Thu Sep 21 09:31:50 2023
+++ src/sys/dev/pci/if_iwm.c	Fri Feb  9 06:01:03 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_iwm.c,v 1.88 2023/09/21 09:31:50 msaitoh Exp $	*/
+/*	$NetBSD: if_iwm.c,v 1.89 2024/02/09 06:01:03 mlelstv Exp $	*/
 /*	OpenBSD: if_iwm.c,v 1.148 2016/11/19 21:07:08 stsp Exp	*/
 #define IEEE80211_NO_HT
 /*
@@ -106,7 +106,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_iwm.c,v 1.88 2023/09/21 09:31:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_iwm.c,v 1.89 2024/02/09 06:01:03 mlelstv Exp $");
 
 #include 
 #include 
@@ -1262,8 +1262,9 @@ iwm_free_rx_ring(struct iwm_softc *sc, s
 		struct iwm_rx_data *data = >data[i];
 
 		if (data->m != NULL) {
+			bus_size_t sz = data->m->m_pkthdr.len;
 			bus_dmamap_sync(sc->sc_dmat, data->map, 0,
-			data->map->dm_mapsize, BUS_DMASYNC_POSTREAD);
+			sz, BUS_DMASYNC_POSTREAD);
 			bus_dmamap_unload(sc->sc_dmat, data->map);
 			m_freem(data->m);
 			data->m = NULL;
@@ -1405,8 +1406,9 @@ iwm_reset_tx_ring(struct iwm_softc *sc, 
 		struct iwm_tx_data *data = >data[i];
 
 		if (data->m != NULL) {
+			bus_size_t sz = data->m->m_pkthdr.len;
 			bus_dmamap_sync(sc->sc_dmat, data->map, 0,
-			data->map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
+			sz, BUS_DMASYNC_POSTWRITE);
 			bus_dmamap_unload(sc->sc_dmat, data->map);
 			m_freem(data->m);
 			data->m = NULL;
@@ -1436,8 +1438,9 @@ iwm_free_tx_ring(struct iwm_softc *sc, s
 		struct iwm_tx_data *data = >data[i];
 
 		if (data->m != NULL) {
+			bus_size_t sz = data->m->m_pkthdr.len;
 			bus_dmamap_sync(sc->sc_dmat, data->map, 0,
-			data->map->dm_mapsize, BUS_DMASYNC_POSTWRITE);
+			sz, BUS_DMASYNC_POSTWRITE);
 			bus_dmamap_unload(sc->sc_dmat, data->map);
 			m_freem(data->m);
 			data->m = NULL;
@@ -1517,7 +1520,7 @@ iwm_ict_reset(struct iwm_softc *sc)
 	iwm_disable_interrupts(sc);
 
 	memset(sc->ict_dma.vaddr, 0, IWM_ICT_SIZE);
-	bus_dmamap_sync(sc->sc_dmat, sc->ict_dma.map, 0, IWM_ICT_SIZE,
+	bus_dmamap_sync(sc->sc_dmat, sc->ict_dma.map, 0, sc->ict_dma.size,
 	BUS_DMASYNC_PREWRITE);
 	sc->ict_cur = 0;
 
@@ -3766,7 +3769,7 @@ iwm_rx_addbuf(struct iwm_softc *sc, int 
 	if (size <= MCLBYTES) {
 		MCLGET(m, M_DONTWAIT);
 	} else {
-		MEXTMALLOC(m, IWM_RBUF_SIZE, M_DONTWAIT);
+		MEXTMALLOC(m, size, M_DONTWAIT);
 	}
 	if ((m->m_flags & M_EXT) == 0) {
 		m_freem(m);
@@ -3778,7 +3781,7 @@ iwm_rx_addbuf(struct iwm_softc *sc, int 
 		fatal = 1;
 	}
 
-	m->m_len = m->m_pkthdr.len = m->m_ext.ext_size;
+	m->m_len = m->m_pkthdr.len = size;
 	err = bus_dmamap_load_mbuf(sc->sc_dmat, data->map, m,
 	BUS_DMA_READ|BUS_DMA_NOWAIT);
 	if (err) {
@@ -4452,12 +4455,17 @@ iwm_cmd_done(struct iwm_softc *sc, int q
 	wakeup(>desc[idx]);
 
 	if (((idx + ring->queued) % IWM_TX_RING_COUNT) != ring->cur) {
-		aprint_error_dev(sc->sc_dev,
+		device_printf(sc->sc_dev,
 		"Some HCMDs skipped?: idx=%d queued=%d cur=%d\n",
 		idx, ring->queued, ring->cur);
 	}
 
-	KASSERT(ring->queued > 0);
+	if (ring->queued == 0) {
+		splx(s);
+		device_printf(sc->sc_dev, "cmd_done with empty ring\n");
+		return;
+	}
+
 	if (--ring->queued == 0)
 		iwm_clear_cmd_in_flight(sc);
 
@@ -4785,7 +4793,7 @@ iwm_tx(struct iwm_softc *sc, struct mbuf
 		| ((seg->ds_len) << 4);
 	}
 
-	bus_dmamap_sync(sc->sc_dmat, data->map, 0, data->map->dm_mapsize,
+	bus_dmamap_sync(sc->sc_dmat, data->map, 0, m->m_pkthdr.len,
 	BUS_DMASYNC_PREWRITE);
 	bus_dmamap_sync(sc->sc_dmat, ring->cmd_dma.map,
 	(uint8_t *)cmd - (uint8_t *)ring->cmd, sizeof(*cmd),



CVS commit: src/sys/dev/pci

2024-02-08 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Feb  9 06:01:03 UTC 2024

Modified Files:
src/sys/dev/pci: if_iwm.c

Log Message:
Fix DMA sync sizes.
Don't panic for inconsistent queue counter, just print an error to console.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/pci/if_iwm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: NetBSD 10.0 RC_3 GENERIC amd64 home built kernel doesn't boot

2024-02-04 Thread Michael van Elst
fekete.zol...@minux.hu (=?UTF-8?Q?Fekete_Zolt=C3=A1n?=) writes:

>Hi There,

Hi,

maybe you can provide more information.


>I have a laptop from 2013, and I'm playing around with it.
>I've just compiled a kernel with the command:

>./build.sh -T ../tools -O ../obj -U -N1 -j2 kernel=GENERIC

is that from netbsd-10 sources? Did you change the GENERIC
configuration?


>... boot device: wd0
>... root on wd0c dumps on wd0b
>... vfs_mountroot: can't open root device

wd0c wouldn't be a standard installation. Usually you write a disklabel
that uses wd0a as the root partition.


>... cannot mount root, error = 6

error 6 could mean that the wd0 disk doesn't exist or that partition
wd0c doesn't contain a valid filesystem or that you have a stripped
kernel that lacks the filesystem code.


>I've checked, and as expected, DKWEDGE options are set properly as 
>mentioned in 'man dk(4)'.

What DKWEDGE options did you set?



>The system just boots fine with the kernel bundled in the installation 
>image.

Then you could show your disk layout as seen by the bundled kernel,
also what that kernel prints for 'boot device' and 'root on' and
what filesystem you used.




Re: MNT Reform2 USB LCP flash

2024-02-04 Thread Michael van Elst
staf...@shangtai.net (=?UTF-8?B?U3RhZmZhbiBUaG9tw6lu?=) writes:

>While I was fiddling around with it, I booted a FreeBSD-14 thumbdrive 
>and there it does work as well, and their driver helpfully tells you 
>what quirks it uses. This is what I found:

>umass quirks: 0xc104
>0x0004 - NO_START_STOP, "The drive does not support START STOP"
>0x0100 - NO_GETMAXLUN, "No GetMaxLun call"
>0x4000 - NO_SYNCHRONIZE_CACHE, "Deice cannot handle a SCSI synchronize 
>cache command."
>0x8000 - NO_PREVENT_ALLOW, "Device does not support PREVENT/ALLOW MEDIUM 
>REMOVAL"

>da: quirks: 0x2
>0x2 NO_6_BYTE - use SBC (10-byte) commands instead of RBC (6-byte) commands


There is sys/dev/usb/umass_quirks.c.

These quirks exist:

PQUIRK_NOSYNCCACHE (like NO_SYNCHRONIZE_CACHE)
PQUIRK_NODOORLOCK (like NO_PREVENT_ALLOW)
PQUIRK_ONLYBIG (like NO_6_BYTE)

We don't do GetMaxLun.

There seems to be nothing yet for NO_START_STOP. There is

PQUIRK_START

that forces a start at attach time. But at open time when
the unit still does not report ready, we issue the comamnd
again (and fail if it doesn't succeed). We probably need
another quirk PQUIRK_NOSTART and check it in scsipi_start()
similar to the PQUIRK_NODOORLOCK in scsipi_prevent().



Re: MNT Reform2 USB LCP flash

2024-02-04 Thread Michael van Elst
On Sun, Feb 04, 2024 at 10:37:59AM +0200, Staffan Thomen wrote:

> [ 214.0188739] umass0: NXP (0x1fc9) LPC1XXX IFLASH (0x000b), rev 2.00/7.04,

> [ 214.0288745] sd0(umass0:0:0:0):  sense debug information:
> [ 214.0288745] code 0x70 valid 0
> [ 214.0288745] seg 0x0 key 0x2 ili 0x0 eom 0x0 fmark 0x0
> 
> [ 214.0288745] info: 0x0 0x0 0x0 0x0 followed by 10 extra bytes
> [ 214.0288745] extra (up to 10 bytes): 0x0 0x0 0x0 0x0 0x30 0x1 0x0 0x0
> 0x0 0x0

That's what the device answers, but I cannot tell why. Maybe
the device is not (yet) in the correct mode to accept USB
access.

The product code 0x1fc9:0x000b seems to be a LPC11U24,
there is an application note AN11305 from NXP for
"USB In-System Programming with th LPC11U3X/LPC1U2X",
but I didn't find any hints in that document.


Greetings,
-- 
        Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: MNT Reform2 USB LCP flash

2024-02-04 Thread Michael van Elst
On Sun, Feb 04, 2024 at 09:58:39AM +0200, Staffan Thomén wrote:
> 
> The man page for scsictl(8) says that SCSIPI_DEBUG is the required option...

SCSIPI_DEBUG is it.

It should also set the default debug flags (that the ioctl may
change).

Greetings,
-- 
    Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: MNT Reform2 USB LCP flash

2024-02-03 Thread Michael van Elst
On Sat, Feb 03, 2024 at 09:55:47PM +0200, Staffan Thomén wrote:
> Staffan Thomen wrote:
> > [ 188.679957] sd0: 34816, 1 cyl, 64 head, 32 sec, 512 bytes/sect x 68
> > sectors
> > [ 188.689958] autoconfiguration error: sd0: unable to open device,
> > error = 5
> 
> Any thoughts of how to continue debugging this?


A kernel compiled with SCSI_DEBUG can show which commands to the
device actually fail and how. This should be the initial TEST_UNIT_READY
and possibly the START command. No idea why, it's possible that
these are not implemented and errors need to be ignored.


Greetings,
-- 
        Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: shrinking a filesystem using resize_ffs(8)

2024-02-01 Thread Michael van Elst
jscha...@netmeister.org (Jan Schaumann) writes:

>Hi,

Hi,

>$ sudo newfs -C 2 /dev/rvnd0a

There is no '-C'. Maybe -O 2 ?

But resize_ffs doesn't support shrinking FFS2 and should
complain when you try.


>[ back to two '1048576' sized partitions ]

>$ sudo fsck_ffs -y -f /dev/rvnd0b
>[ all ok ]

The 'b' filesystem was probably never changed but maybe trashed in
a way that fsck doesn't understand.


>$ sudo resize_ffs -v /dev/rvnd0b
>No change requested: already 524288 blocks

The superblock and partition agree. Nothing
to do and nothing to check.


>$ sudo fsck_ffs -y -f /dev/rvnd0a
>** /dev/rvnd0a

>CANNOT READ: BLK 2010160
>CONTINUE? yes

The 'a' filesystem still thinks it is 1GB and you try to shrink
it. But the disklabel already restricts access to the lower half.
Any attempt to access data from the upper half fails.


>$ sudo resize_ffs -v /dev/rvnd0a
>resize_ffs: read failed: Invalid argument

Dito. Shrinking requires access to all the data.


>So... how do I shrink a filesystem?

You tell resize_fsck the new size with -s and then
reduce the partition size accordingly.






Re: MNT Reform2 USB LCP flash

2024-01-26 Thread Michael van Elst
k...@munnari.oz.au (Robert Elz) writes:

>I have been meaning to suggest for ages that we remove all the
>geometry nonsense from everywhere in the kernel, except those
>drivers that actually need it.

We use that nonsense without actually knowing.

The "cylinder" value is used to sort disk accesses.
The "sector" value was used to optimize filesystem allocation.

Neither takes the values as is (the values are mostly fake
anyway), but as a hint.

Newer technologies may not use C/H/S coordinates, but every HDD
still uses cylinders and every SSD has a topology based on erase
blocks where "cylinder" could be a hint to optimize accesses.

So, such information should not be removed but needs to be exposed.
Better if it were exposed 1:1 from the underlying technology, but
it still needs to be compatible with the abstractions that use
it.

Doesn't mean that you could not find a better abstraction for a
storage medium in the future. For now, pretending everything is
a rotational disk from 50 years ago doesn't hurt but helps.



Re: MNT Reform2 USB LCP flash

2024-01-26 Thread Michael van Elst
k...@munnari.oz.au (Robert Elz) writes:

>If you are able, try building a kernel with the patch below.

>I suspect this should probably apply without too many problems
>to any reasonably modern NetBSD kernel version, patch is to
>src/sys/dev/scsipi/sd.c

>+  if (dp->cyls == 0)  /* very small devices */
>+  dp->cyls = 1;   /* round up # cyls */


People using the cylinder count assume that a disk is made of cylinders,
heads (surfaces) and sectors and that cyls * heads * sectors is the capacity.

For modern disks that's not true.

The values are intentionally truncated so that such people cannot access
blocks beyond the end of the device and software that (still) uses C/H/S
coordinates has a chance to use modern devices.

An alternative handling would be round up the values so that you can reach
all blocks using C/H/S coordinates and non-existent blocks return errors.
But what purpose would such fictious C/H/S coordinates serve and would
software relying on C/H/S be able to handle the errors ?

Rounding up only for disks with less than one full cylinder only helps
people that suffer from oudenophobia.



Re: MNT Reform2 USB LCP flash

2024-01-26 Thread Michael van Elst
staf...@shangtai.net (=?UTF-8?B?U3RhZmZhbiBUaG9tw6lu?=) writes:

>[21.611880] scsibus1 at umass1: 2 targets, 1 lun per target
>[21.611880] sd1 at scsibus1 target 0 lun 0: 1.0> disk removable
>[21.611880] sd1: fabricating a geometry
>[21.611880] sd1: 34816, 0 cyl, 64 head, 32 sec, 512 bytes/sect x 68 
>sectors
>[21.611880] autoconfiguration error: sd1: unable to open device, 
>error = 5

>It seems a bit interesting that it reports 2 targets, but only creates 
>an sd for one,

The '2 targets' is a parameter of 'scsibus1', it tells the SCSI layer
that it may look for up to 2 targets. USB mass storage usually only
has a single 'sd' target, but some also provide an extra 'ses'
enclosure target.


>and 0 cylinders seems a bit suspicous but I don't know if 
>that's ok or not.

When the drive doesn't return a valid geometry, the driver uses
a fake one, based on 64 heads and 32 sectors per head. In your
case the drive is smaller than a single cylinder (64*32), so
you get zero (full) cylinders.

Fortunately the drive geometry isn't really used anywhere. All
accesses just use the logical block addresses.


The EIO (5) error probably occurs because the drive is reported
as 'offline'. This is like a drive with a removable medium but
no medium has been loaded.

It is possible that there needs to be some action to 'load'
the 'medium', or it might just take some time to appear online.
You may use

   scsictl sd1 start

to attempt another access.

The LPC1xxx manual didn't reveal anything obvious about
this problem. It just claims that you can copy the firmware
to the storage. It also doesn't say how, with just 68 sectors
that's not a fake filesystem, you probably need to write
the firmware image to the raw device.



CVS commit: src/bin/dd

2024-01-25 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Jan 26 07:10:04 UTC 2024

Modified Files:
src/bin/dd: args.c

Log Message:
Don't use the signal handler to terminate when nothing is to do (count=0, 
files=0).

The signal handler tries to raise the signal again, so that a parent can 
retrieve
the signal from the exit code. Calling the terminate handler with signal code 0
doesn't raise a signal and dd continues with exit(127) making this case an 
error.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/bin/dd/args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/bin/dd

2024-01-25 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Jan 26 07:10:04 UTC 2024

Modified Files:
src/bin/dd: args.c

Log Message:
Don't use the signal handler to terminate when nothing is to do (count=0, 
files=0).

The signal handler tries to raise the signal again, so that a parent can 
retrieve
the signal from the exit code. Calling the terminate handler with signal code 0
doesn't raise a signal and dd continues with exit(127) making this case an 
error.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/bin/dd/args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/dd/args.c
diff -u src/bin/dd/args.c:1.42 src/bin/dd/args.c:1.43
--- src/bin/dd/args.c:1.42	Fri Jan 14 23:55:16 2022
+++ src/bin/dd/args.c	Fri Jan 26 07:10:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.42 2022/01/14 23:55:16 christos Exp $	*/
+/*	$NetBSD: args.c,v 1.43 2024/01/26 07:10:04 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)args.c	8.3 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: args.c,v 1.42 2022/01/14 23:55:16 christos Exp $");
+__RCSID("$NetBSD: args.c,v 1.43 2024/01/26 07:10:04 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -248,8 +248,10 @@ f_count(char *arg)
 {
 
 	cpy_cnt = strsuftoll("block count", arg, 0, LLONG_MAX);
-	if (!cpy_cnt)
-		terminate(0);
+	if (!cpy_cnt) {
+		summary();
+		exit(0);
+	}
 }
 
 static void
@@ -257,8 +259,10 @@ f_files(char *arg)
 {
 
 	files_cnt = (u_int)strsuftoll("file count", arg, 0, UINT_MAX);
-	if (!files_cnt)
-		terminate(0);
+	if (!files_cnt) {
+		summary();
+		exit(0);
+	}
 }
 
 static void



CVS commit: src/sys/dev/stbi

2024-01-20 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jan 20 13:33:03 UTC 2024

Modified Files:
src/sys/dev/stbi: stb_image.c

Log Message:
Don't put big structures on stack.
Should fix PR 57859.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/stbi/stb_image.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/stbi/stb_image.c
diff -u src/sys/dev/stbi/stb_image.c:1.11 src/sys/dev/stbi/stb_image.c:1.12
--- src/sys/dev/stbi/stb_image.c:1.11	Sat Aug 26 21:03:53 2023
+++ src/sys/dev/stbi/stb_image.c	Sat Jan 20 13:33:03 2024
@@ -430,7 +430,7 @@ extern int  stbi_gif_info_from_file 
 #endif
 #ifdef _KERNEL
 #include 
-__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.11 2023/08/26 21:03:53 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.12 2024/01/20 13:33:03 mlelstv Exp $");
 #include 
 #include 
 #include 
@@ -2144,16 +2144,28 @@ int stbi_jpeg_info(char const *filename,
 
 int stbi_jpeg_test_memory(stbi_uc const *buffer, int len)
 {
-   jpeg j;
-   start_mem(, buffer,len);
-   return decode_jpeg_header(, SCAN_type);
+jpeg *j;
+int res;
+
+j = MALLOC(sizeof(*j));
+if (j == NULL) return 0;
+start_mem(>s, buffer,len);
+res = decode_jpeg_header(j, SCAN_type);
+FREE(j);
+return res;
 }
 
 int stbi_jpeg_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp)
 {
-jpeg j;
-start_mem(, buffer, len);
-return stbi_jpeg_info_raw(, x, y, comp);
+jpeg *j;
+int res;
+
+j = MALLOC(sizeof(*j));
+if (j == NULL) return 0;
+start_mem(>s, buffer, len);
+res = stbi_jpeg_info_raw(j, x, y, comp);
+FREE(j);
+return res;
 }
 
 #ifndef STBI_NO_STDIO
@@ -2523,18 +2535,25 @@ static int do_zlib(zbuf *a, char *obuf, 
 
 char *stbi_zlib_decode_malloc_guesssize(const char * buffer, int len, int initial_size, int *outlen)
 {
-   zbuf a;
-   char *p = MALLOC(initial_size);
-   if (p == NULL) return NULL;
-   a.zbuffer = (uint8 const *) buffer;
-   a.zbuffer_end = (uint8 const *) buffer + len;
-   if (do_zlib(, p, initial_size, 1, 1)) {
-  if (outlen) *outlen = (int) (a.zout - a.zout_start);
-  return a.zout_start;
+   zbuf *a;
+   char *p;
+   char *res = NULL;
+
+   a = MALLOC(sizeof(*a));
+   if (a == NULL) return NULL;
+   p = MALLOC(initial_size);
+   if (p == NULL) goto fail;
+   a->zbuffer = (uint8 const *) buffer;
+   a->zbuffer_end = (uint8 const *) buffer + len;
+   if (do_zlib(a, p, initial_size, 1, 1)) {
+  if (outlen) *outlen = (int) (a->zout - a->zout_start);
+  res = a->zout_start;
} else {
-  FREE(a.zout_start);
-  return NULL;
+  FREE(a->zout_start);
}
+fail:
+   FREE(a);
+   return res;
 }
 
 char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen)
@@ -2544,56 +2563,81 @@ char *stbi_zlib_decode_malloc(char const
 
 char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header)
 {
-   zbuf a;
-   char *p = MALLOC(initial_size);
-   if (p == NULL) return NULL;
-   a.zbuffer = (uint8 const *) buffer;
-   a.zbuffer_end = (uint8 const *) buffer + len;
-   if (do_zlib(, p, initial_size, 1, parse_header)) {
-  if (outlen) *outlen = (int) (a.zout - a.zout_start);
-  return a.zout_start;
+   zbuf *a;
+   char *p;
+   char *res = NULL;
+
+   a = MALLOC(sizeof(*a));
+   if (a == NULL) return NULL;
+   p = MALLOC(initial_size);
+   if (p == NULL) goto fail;
+   a->zbuffer = (uint8 const *) buffer;
+   a->zbuffer_end = (uint8 const *) buffer + len;
+   if (do_zlib(a, p, initial_size, 1, parse_header)) {
+  if (outlen) *outlen = (int) (a->zout - a->zout_start);
+  res = a->zout_start;
} else {
-  FREE(a.zout_start);
-  return NULL;
+  FREE(a->zout_start);
}
+fail:
+   FREE(a);
+   return res;
 }
 
 int stbi_zlib_decode_buffer(char *obuffer, int olen, char const *ibuffer, int ilen)
 {
-   zbuf a;
-   a.zbuffer = (uint8 const *) ibuffer;
-   a.zbuffer_end = (uint8 const *) ibuffer + ilen;
-   if (do_zlib(, obuffer, olen, 0, 1))
-  return (int) (a.zout - a.zout_start);
+   zbuf *a;
+   int res;
+
+   a = MALLOC(sizeof(*a));
+   if (a == NULL) return -1;
+   a->zbuffer = (uint8 const *) ibuffer;
+   a->zbuffer_end = (uint8 const *) ibuffer + ilen;
+   if (do_zlib(a, obuffer, olen, 0, 1))
+  res = (int) (a->zout - a->zout_start);
else
-  return -1;
+  res = -1;
+   FREE(a);
+   return res;
 }
 
 char *stbi_zlib_decode_noheader_malloc(char const *buffer, int len, int *outlen)
 {
-   zbuf a;
-   char *p = MALLOC(16384);
-   if (p == NULL) return NULL;
-   a.zbuffer = (uint8 const *) buffer;
-   a.zbuffer_end = (uint8 const *) buffer+len;
-   if (do_zlib(, p, 16384, 1, 0)) {
-  if (outlen) *outlen = (int) (a.zout - a.zout_start);
-  return a.zout_start;
-   } else {
-  FREE(a.zout_start);
-  return NULL;
-   }
+   

CVS commit: src/sys/dev/stbi

2024-01-20 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jan 20 13:33:03 UTC 2024

Modified Files:
src/sys/dev/stbi: stb_image.c

Log Message:
Don't put big structures on stack.
Should fix PR 57859.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/stbi/stb_image.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: *oldlenp comes back with wrong value in helper sysctl_createv() function

2024-01-20 Thread Michael van Elst
On Sat, Jan 20, 2024 at 10:48:12AM +0100, Emile 'iMil' Heitor wrote:


Hi,

that's from sysctl.c:

case CTLTYPE_STRING: {
unsigned char buf[1024], *tbuf;
tbuf = buf;
sz = sizeof(buf); 
rc = prog_sysctl([0], namelen, tbuf, , NULL, 0);

The sysctl command first tries with a buffer of 1024 bytes
and retries with the right size when that was too small.

Compared to "probing" with a NULL buffer this saves a round trip
to the kernel for most sysctls.

A simple helper function would always return the needed size and only
copy out when oldp was set. sysctl will check the returned *oldlenp 
against the value passed by the caller and return ENOMEM as appropriate.


Greetings,
-- 
        Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: *oldlenp comes back with wrong value in helper sysctl_createv() function

2024-01-20 Thread Michael van Elst
i...@home.imil.net (Emile 'iMil' Heitor) writes:

>Except it does not, the first time it calls back the helper function,
>*oldlenp value is 1024 no matter what I set it to before.
>But if I return once again (either with ENOMEM or 0, doesn't matter),
>the helper function will now be called with the right *oldlenp value.

The helper function produces the value that is returned in *oldlenp.

If you happen to use CTL_DESCRIBE (e.g. running sysctl -d), it's
not your helper function being called but the sysctl_describe helper
that returns a value of 1024.

Maybe you can show your helper routine and how you call sysctl ?





Re: WireGuard setup in NetBSD 10

2024-01-18 Thread Michael van Elst
k...@krot.org (Kirill Miazine) writes:

>> Maybe he still has auto_ifconfig=NO ?

>no, he didn't... but issue was if_wg not being loaded upon boot -- but
>loaded when ifconfig wg0 create was called.

The perils of the module autoloader.



Re: WireGuard setup in NetBSD 10

2024-01-18 Thread Michael van Elst
mar...@duskware.de (Martin Husemann) writes:

>On Thu, Jan 18, 2024 at 10:23:11AM +0100, Kirill Miazine wrote:
>> Does your custom kernel provide some wg devices initially?

>No, but "ifconfig -C" lists wg as a clonable device, so /etc/ifconfig.wg0
>is loaded.

Maybe he still has auto_ifconfig=NO ?



CVS commit: src/sys/dev/dm

2024-01-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan 14 07:56:53 UTC 2024

Modified Files:
src/sys/dev/dm: dm_ioctl.c

Log Message:
Avoid leaving a configured device without resources.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/dm/dm_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dm/dm_ioctl.c
diff -u src/sys/dev/dm/dm_ioctl.c:1.56 src/sys/dev/dm/dm_ioctl.c:1.57
--- src/sys/dev/dm/dm_ioctl.c:1.56	Thu Oct 13 06:10:48 2022
+++ src/sys/dev/dm/dm_ioctl.c	Sun Jan 14 07:56:53 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_ioctl.c,v 1.56 2022/10/13 06:10:48 andvar Exp $  */
+/* $NetBSD: dm_ioctl.c,v 1.57 2024/01/14 07:56:53 mlelstv Exp $  */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.56 2022/10/13 06:10:48 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.57 2024/01/14 07:56:53 mlelstv Exp $");
 
 /*
  * Locking is used to synchronise between ioctl calls and between dm_table's
@@ -209,18 +209,21 @@ dm_dev_create_ioctl(prop_dictionary_t dm
 		dm_dev_unbusy(dmv);
 		return EEXIST;
 	}
+
+	if ((dmv = dm_dev_alloc()) == NULL)
+		return ENOMEM;
+
 	cf = kmem_alloc(sizeof(*cf), KM_SLEEP);
 	cf->cf_name = dm_cd.cd_name;
 	cf->cf_atname = dm_ca.ca_name;
 	cf->cf_unit = atomic_inc_32_nv(_minor_num);
 	cf->cf_fstate = FSTATE_NOTFOUND;
 	if ((devt = config_attach_pseudo(cf)) == NULL) {
+		dm_dev_free(dmv);
 		kmem_free(cf, sizeof(*cf));
 		aprint_error("Unable to attach pseudo device dm/%s\n", name);
 		return (ENOMEM);
 	}
-	if ((dmv = dm_dev_alloc()) == NULL)
-		return ENOMEM;
 
 	if (uuid)
 		strncpy(dmv->uuid, uuid, DM_UUID_LEN);
@@ -247,7 +250,7 @@ dm_dev_create_ioctl(prop_dictionary_t dm
 
 	prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
 
-	disk_init(dmv->diskp, dmv->name, );
+	disk_init(dmv->diskp, device_xname(devt), );
 	disk_attach(dmv->diskp);
 
 	dmv->diskp->dk_info = NULL;



CVS commit: src/sys/dev/dm

2024-01-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan 14 07:56:53 UTC 2024

Modified Files:
src/sys/dev/dm: dm_ioctl.c

Log Message:
Avoid leaving a configured device without resources.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/dm/dm_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/fdt

2024-01-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan 14 07:53:38 UTC 2024

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
Handle multiple memory nodes by type, but still allow an untyped
(non-standard) node named /memory.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/fdt_memory.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/fdt

2024-01-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jan 14 07:53:38 UTC 2024

Modified Files:
src/sys/dev/fdt: fdt_memory.c

Log Message:
Handle multiple memory nodes by type, but still allow an untyped
(non-standard) node named /memory.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/fdt_memory.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/fdt/fdt_memory.c
diff -u src/sys/dev/fdt/fdt_memory.c:1.9 src/sys/dev/fdt/fdt_memory.c:1.10
--- src/sys/dev/fdt/fdt_memory.c:1.9	Fri Jan 12 18:06:18 2024
+++ src/sys/dev/fdt/fdt_memory.c	Sun Jan 14 07:53:38 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_memory.c,v 1.9 2024/01/12 18:06:18 skrll Exp $ */
+/* $NetBSD: fdt_memory.c,v 1.10 2024/01/14 07:53:38 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "opt_fdt.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.9 2024/01/12 18:06:18 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_memory.c,v 1.10 2024/01/14 07:53:38 mlelstv Exp $");
 
 #include 
 #include 
@@ -77,26 +77,43 @@ fdt_memory_range_free(struct fdt_memory_
 void
 fdt_memory_get(uint64_t *pstart, uint64_t *pend)
 {
-	const int memory = OF_finddevice("/memory");
+	const void *fdt_data = fdtbus_get_data();
 	uint64_t cur_addr, cur_size;
-	int index, nadd;
+	int index, nadd = 0, off, memory;
 
-	for (index = 0, nadd = 0;
-	 fdtbus_get_reg64(memory, index, _addr, _size) == 0;
-	 index++) {
-		if (cur_size == 0)
-			continue;
-		fdt_memory_add_range(cur_addr, cur_size);
+	off = fdt_node_offset_by_prop_value(fdt_data, -1,
+	"device_type", "memory", sizeof("memory"));
 
-		if (nadd++ == 0) {
-			*pstart = cur_addr;
-			*pend = cur_addr + cur_size;
-			continue;
+	/*
+	 * Device Tree Specification 3.2 says that memory
+	 * nodes are named "memory" and have device_type
+	 * "memory", but if the device_type is missing, try
+	 * to find the (then single) node by name.
+	 */
+	if (off == -FDT_ERR_NOTFOUND)
+		off = fdt_path_offset(fdt_data, "/memory");
+
+	while (off != -FDT_ERR_NOTFOUND) {
+		memory = fdtbus_offset2phandle(off);
+		for (index = 0;
+		 fdtbus_get_reg64(memory, index, _addr, _size) == 0;
+		 index++) {
+			if (cur_size == 0)
+continue;
+			fdt_memory_add_range(cur_addr, cur_size);
+
+			if (nadd++ == 0) {
+*pstart = cur_addr;
+*pend = cur_addr + cur_size;
+continue;
+			}
+			if (cur_addr < *pstart)
+*pstart = cur_addr;
+			if (cur_addr + cur_size > *pend)
+*pend = cur_addr + cur_size;
 		}
-		if (cur_addr < *pstart)
-			*pstart = cur_addr;
-		if (cur_addr + cur_size > *pend)
-			*pend = cur_addr + cur_size;
+		off = fdt_node_offset_by_prop_value(fdt_data, off,
+		"device_type", "memory", sizeof("memory"));
 	}
 	if (nadd == 0)
 		panic("Cannot determine memory size");



CVS commit: src/sys/arch/virt68k/dev

2024-01-11 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Jan 12 06:23:20 UTC 2024

Modified Files:
src/sys/arch/virt68k/dev: gfrtc_mainbus.c

Log Message:
The interrupt handler needs to clear the interrupt condition
before re-arming the timer. Otherwise the timer could expire
again before clearing the interrupt, the interrupt gets lost
and the clock stops.

On real hardware that could only occur if the timer interval
is extremely short or if there is a higher-than-clock interrupt
that delays processing. In the emulated world however, time
can progress non-continously and this happens often under load.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/virt68k/dev/gfrtc_mainbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/virt68k/dev/gfrtc_mainbus.c
diff -u src/sys/arch/virt68k/dev/gfrtc_mainbus.c:1.1 src/sys/arch/virt68k/dev/gfrtc_mainbus.c:1.2
--- src/sys/arch/virt68k/dev/gfrtc_mainbus.c:1.1	Tue Jan  2 07:40:59 2024
+++ src/sys/arch/virt68k/dev/gfrtc_mainbus.c	Fri Jan 12 06:23:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: gfrtc_mainbus.c,v 1.1 2024/01/02 07:40:59 thorpej Exp $	*/
+/*	$NetBSD: gfrtc_mainbus.c,v 1.2 2024/01/12 06:23:20 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2023, 2024 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gfrtc_mainbus.c,v 1.1 2024/01/02 07:40:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gfrtc_mainbus.c,v 1.2 2024/01/12 06:23:20 mlelstv Exp $");
 
 #include 
 #include 
@@ -65,12 +65,12 @@ struct gfrtc_mainbus_softc {
 
 #define	CLOCK_HANDLER()			\
 do {	\
-	/* Get the next alarm set ASAP. */\
-	gfrtc_set_alarm(>sc_gfrtc, sc->sc_interval_ns);		\
-	\
 	/* Clear the interrupt condition. */\
 	gfrtc_clear_interrupt(>sc_gfrtc);\
 	\
+	/* Get the next alarm set ASAP. */\
+	gfrtc_set_alarm(>sc_gfrtc, sc->sc_interval_ns);		\
+	\
 	/* Increment the counter and call the handler. */		\
 	sc->sc_evcnt->ev_count++;	\
 	sc->sc_handler((struct clockframe *)v);\



CVS commit: src/sys/arch/virt68k/dev

2024-01-11 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Jan 12 06:23:20 UTC 2024

Modified Files:
src/sys/arch/virt68k/dev: gfrtc_mainbus.c

Log Message:
The interrupt handler needs to clear the interrupt condition
before re-arming the timer. Otherwise the timer could expire
again before clearing the interrupt, the interrupt gets lost
and the clock stops.

On real hardware that could only occur if the timer interval
is extremely short or if there is a higher-than-clock interrupt
that delays processing. In the emulated world however, time
can progress non-continously and this happens often under load.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/virt68k/dev/gfrtc_mainbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/i386/stand

2024-01-06 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jan  6 21:26:43 UTC 2024

Modified Files:
src/sys/arch/i386/stand/efiboot: efidisk.c efidisk.h
src/sys/arch/i386/stand/lib: biosdisk.c exec.c

Log Message:
In efiboot
- create bootinfo information only once.
- add fake biosgeom entries so that the kernel can distinguish between
  hard drives (with geom) and CD-ROM (without).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/i386/stand/efiboot/efidisk.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/i386/stand/efiboot/efidisk.h
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/i386/stand/lib/biosdisk.c
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/i386/stand/lib/exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/i386/stand/efiboot/efidisk.c
diff -u src/sys/arch/i386/stand/efiboot/efidisk.c:1.10 src/sys/arch/i386/stand/efiboot/efidisk.c:1.11
--- src/sys/arch/i386/stand/efiboot/efidisk.c:1.10	Sun May 14 09:07:54 2023
+++ src/sys/arch/i386/stand/efiboot/efidisk.c	Sat Jan  6 21:26:43 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: efidisk.c,v 1.10 2023/05/14 09:07:54 riastradh Exp $	*/
+/*	$NetBSD: efidisk.c,v 1.11 2024/01/06 21:26:43 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -38,9 +38,12 @@
 #include "biosdisk_ll.h"
 #include "devopen.h"
 #include "efidisk.h"
+#include "bootinfo.h"
 
 static struct efidiskinfo_lh efi_disklist;
 static int nefidisks;
+static struct btinfo_biosgeom *bibg;
+static size_t bibg_len;
 
 #define MAXDEVNAME 39 /* "NAME=" + 34 char part_name */
 
@@ -158,6 +161,23 @@ next:
 		if (edi->bootdev)
 			boot_biosdev = edi->dev;
 	}
+
+	bibg_len = sizeof(*bibg) + nefidisks * sizeof(struct bi_biosgeom_entry);
+	bibg = alloc(bibg_len);
+	if (bibg == NULL)
+		return;
+
+	bibg->num = nefidisks;
+
+	i = 0;
+	TAILQ_FOREACH(edi, _disklist, list) {
+		if (edi->type == BIOSDISK_TYPE_HD) {
+			memset(>disk[i], 0, sizeof(bibg->disk[i]));
+			bibg->disk[i].dev = edi->dev;
+			bibg->disk[i].flags = BI_GEOM_INVALID;
+		}
+		++i;
+	}
 }
 
 static void
@@ -383,3 +403,10 @@ efidisk_get_efi_system_partition(int dev
 	*partition = i;
 	return 0;
 }
+
+void
+efidisk_getbiosgeom()
+{
+	BI_ADD(bibg, BTINFO_BIOSGEOM, bibg_len);
+}
+

Index: src/sys/arch/i386/stand/efiboot/efidisk.h
diff -u src/sys/arch/i386/stand/efiboot/efidisk.h:1.3 src/sys/arch/i386/stand/efiboot/efidisk.h:1.4
--- src/sys/arch/i386/stand/efiboot/efidisk.h:1.3	Mon Apr  2 09:44:18 2018
+++ src/sys/arch/i386/stand/efiboot/efidisk.h	Sat Jan  6 21:26:43 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: efidisk.h,v 1.3 2018/04/02 09:44:18 nonaka Exp $	*/
+/*	$NetBSD: efidisk.h,v 1.4 2024/01/06 21:26:43 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -41,3 +41,4 @@ TAILQ_HEAD(efidiskinfo_lh, efidiskinfo);
 
 const struct efidiskinfo *efidisk_getinfo(int);
 int efidisk_get_efi_system_partition(int, int *);
+void efidisk_getbiosgeom(void);

Index: src/sys/arch/i386/stand/lib/biosdisk.c
diff -u src/sys/arch/i386/stand/lib/biosdisk.c:1.60 src/sys/arch/i386/stand/lib/biosdisk.c:1.61
--- src/sys/arch/i386/stand/lib/biosdisk.c:1.60	Mon Oct  2 00:02:33 2023
+++ src/sys/arch/i386/stand/lib/biosdisk.c	Sat Jan  6 21:26:43 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: biosdisk.c,v 1.60 2023/10/02 00:02:33 manu Exp $	*/
+/*	$NetBSD: biosdisk.c,v 1.61 2024/01/06 21:26:43 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1998
@@ -1198,11 +1198,13 @@ out:
 static void
 add_biosdisk_bootinfo(void)
 {
+#ifndef EFIBOOT
 	if (bootinfo == NULL) {
 		return;
 	}
 	BI_ADD(_disk, BTINFO_BOOTDISK, sizeof(bi_disk));
 	BI_ADD(_wedge, BTINFO_BOOTWEDGE, sizeof(bi_wedge));
+#endif
 	return;
 }
 #endif

Index: src/sys/arch/i386/stand/lib/exec.c
diff -u src/sys/arch/i386/stand/lib/exec.c:1.79 src/sys/arch/i386/stand/lib/exec.c:1.80
--- src/sys/arch/i386/stand/lib/exec.c:1.79	Thu Apr 20 00:42:24 2023
+++ src/sys/arch/i386/stand/lib/exec.c	Sat Jan  6 21:26:43 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec.c,v 1.79 2023/04/20 00:42:24 manu Exp $	 */
+/*	$NetBSD: exec.c,v 1.80 2024/01/06 21:26:43 mlelstv Exp $	 */
 
 /*
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -108,6 +108,8 @@
 #endif
 #ifdef EFIBOOT
 #include "efiboot.h"
+#include "biosdisk.h"
+#include "efidisk.h"
 #undef DEBUG	/* XXX */
 #endif
 
@@ -498,6 +500,10 @@ exec_netbsd(const char *file, physaddr_t
 		goto out;
 	}
 #ifdef EFIBOOT
+	BI_ADD(_disk, BTINFO_BOOTDISK, sizeof(bi_disk));
+	BI_ADD(_wedge, BTINFO_BOOTWEDGE, sizeof(bi_wedge));
+	efidisk_getbiosgeom();
+
 	efi_load_start = marks[MARK_START];
 
 	/* adjust to the real load address */



CVS commit: src/sys/arch/i386/stand

2024-01-06 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Jan  6 21:26:43 UTC 2024

Modified Files:
src/sys/arch/i386/stand/efiboot: efidisk.c efidisk.h
src/sys/arch/i386/stand/lib: biosdisk.c exec.c

Log Message:
In efiboot
- create bootinfo information only once.
- add fake biosgeom entries so that the kernel can distinguish between
  hard drives (with geom) and CD-ROM (without).


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/i386/stand/efiboot/efidisk.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/i386/stand/efiboot/efidisk.h
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/i386/stand/lib/biosdisk.c
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/i386/stand/lib/exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2024-01-04 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Jan  4 11:18:20 UTC 2024

Modified Files:
src/sys/kern: subr_cpu.c

Log Message:
dump topology information with aprint_debug instead of requiring to build
a DEBUG kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/kern/subr_cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2024-01-04 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Jan  4 11:18:20 UTC 2024

Modified Files:
src/sys/kern: subr_cpu.c

Log Message:
dump topology information with aprint_debug instead of requiring to build
a DEBUG kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/kern/subr_cpu.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_cpu.c
diff -u src/sys/kern/subr_cpu.c:1.19 src/sys/kern/subr_cpu.c:1.20
--- src/sys/kern/subr_cpu.c:1.19	Sat Jul  8 13:59:05 2023
+++ src/sys/kern/subr_cpu.c	Thu Jan  4 11:18:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_cpu.c,v 1.19 2023/07/08 13:59:05 riastradh Exp $	*/
+/*	$NetBSD: subr_cpu.c,v 1.20 2024/01/04 11:18:19 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009, 2010, 2012, 2019, 2020
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_cpu.c,v 1.19 2023/07/08 13:59:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_cpu.c,v 1.20 2024/01/04 11:18:19 mlelstv Exp $");
 
 #include 
 #include 
@@ -223,7 +223,6 @@ cpu_topology_link(struct cpu_info *ci, s
 static void
 cpu_topology_dump(void)
 {
-#ifdef DEBUG
 	CPU_INFO_ITERATOR cii;
 	struct cpu_info *ci, *ci2;
 	const char *names[] = { "core", "pkg", "1st" };
@@ -237,25 +236,24 @@ cpu_topology_dump(void)
 
 	for (CPU_INFO_FOREACH(cii, ci)) {
 		if (cpu_topology_haveslow)
-			printf("%s ", ci->ci_is_slow ? "slow" : "fast");
+			aprint_debug("%s ", ci->ci_is_slow ? "slow" : "fast");
 		for (rel = 0; rel < __arraycount(ci->ci_sibling); rel++) {
-			printf("%s has %d %s siblings:", cpu_name(ci),
+			aprint_debug("%s has %d %s siblings:", cpu_name(ci),
 			ci->ci_nsibling[rel], names[rel]);
 			ci2 = ci->ci_sibling[rel];
 			i = 0;
 			do {
-printf(" %s", cpu_name(ci2));
+aprint_debug(" %s", cpu_name(ci2));
 ci2 = ci2->ci_sibling[rel];
 			} while (++i < 64 && ci2 != ci->ci_sibling[rel]);
 			if (i == 64) {
-printf(" GAVE UP");
+aprint_debug(" GAVE UP");
 			}
-			printf("\n");
+			aprint_debug("\n");
 		}
-		printf("%s first in package: %s\n", cpu_name(ci),
+		aprint_debug("%s first in package: %s\n", cpu_name(ci),
 		cpu_name(ci->ci_package1st));
 	}
-#endif	/* DEBUG */
 }
 
 /*



Re: Network and port redirection with QEMU not working with package compiled on 10.0_RC1

2024-01-03 Thread Michael van Elst
baba...@babafou.eu.org (Marc Baudoin) writes:

>Has anybody got a working QEMU (at least network-wise) compiled
>on NetBSD 10.0_RC[12]?

No problems here, neither with qemu-8.1.0 (2023Q3) nor qemu-8.1.3 (2023Q4):

Host:
NetBSD tazz 10.99.10 NetBSD 10.99.10 (TAZZ) #311: Sun Dec 24 15:24:24 UTC 2023  
mlelstv@slowpoke:/scratch2/obj.amd64/scratch/netbsd-current/src/sys/arch/amd64/compile/TAZZ
 amd64

Guest:
NetBSD standalone 10.99.5 NetBSD 10.99.5 (GENERIC) #0: Sun Jul  9 00:01:55 UTC 
2023  mkre...@mkrepro.netbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64

configured with:

-netdev user,id=n1
-device virtio-net,netdev=n1



Re: Prob using CPIO

2024-01-01 Thread Michael van Elst
tgru...@gmail.com (Todd Gruhn) writes:

>I zip up much  music:

>   find . -depth -print | cpio -ov > file.cpio

>To unzip it , I must undo *cpio severa times severa times:

>   cpio -iv < file.cpio

Your 'zip' packs the local directory including the cpio file that
is being created. You don't have to cpio several times to unpack,
but the data (most likely) exists twice in the archive.


>Am I messing this up somehow? The *.cpio file is about 250MB...

Yes, don't include the resulting cpio file, easiest by writing
it to a separate directory.



Re: PSA: Clock drift and pkgin

2023-12-30 Thread Michael van Elst
mo...@rodents-montreal.org (Mouse) writes:

>> Modern hardware could easily do 100kHz.

>Not with curren^Wat least one moderately recent NetBSD version!

>At work, I had occasion to run 9.1/amd64 with HZ=8000.  This was to get
>8-bit data pushed out a parallel port at 8kHz; I added special-case
>hooks between the relevant driver and the clock (I forget whether
>softclock or hardclock).  It worked for its intended use fairly
>nicely...but when I tried one of my SIGALRM testers on it, instead of
>the 100Hz it asked for, I got signals at, IIRC, about 77Hz.


Scheduling and switching userland processes is heavy. For a test
try to schedule kernel callouts with high HZ values. That still
generates lots of overhead with the current design but you should
be able to go faster than 8kHz.



PSA: Clock drift and pkgin

2023-12-30 Thread Michael van Elst
On Sun, Dec 31, 2023 at 12:42:29AM +0100, Johnny Billquist wrote:
> > Better than 100Hz is possible and still precise. Something around 1000Hz
> > is necessary for human interaction. Modern hardware could easily do 100kHz.
> 
> ? If I remember right, anything less than 200ms is immediate response for a
> human brain. Which means you can get away with much coarser than even 100Hz.
> And there are certainly lots of examples of older computers with clocks
> running in the 10s of ms, where human interaction feels perfect.

You may not be able to react faster than 200ms, but you can notice
shorter time periods.


> I think that is a separate question/problem/issue. That we fail when guest
> and host run at the same rate is something I consider a flaw in the system.

With a fixed tick, they cannot run at the same speed. This becomes
obvious when you try to run at different speeds that aren't just
integer multiples.

N.B. my m68k emulator runs a HZ=100 guest without a problem. But that's
a fake, in reality it only runs 100 ticks per second on average, In
particular when the guest becomes idle.


Greetings,
-- 
        Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: PSA: Clock drift and pkgin

2023-12-30 Thread Michael van Elst
On Sat, Dec 30, 2023 at 10:48:26PM +0100, Johnny Billquist wrote:
> 
> Right. But if you expect high precision on delays and scheduling, then you
> start also having issues with just random unpredictable delays because of
> other interrupts, paging, and whatnot. So in the end, your high precision
> delays and scheduling becomes very imprecise again. So, is there really that
> much value in that higher resolution?

Better than 100Hz is possible and still precise. Something around 1000Hz
is necessary for human interaction. Modern hardware could easily do 100kHz.

Another advantage is that you can use independent timing (that's what
bites in the emulator case where guest and host clocks run at the same
rate).

-- 
            Michael van Elst
Internet: mlel...@serpens.de
"A potential Snark may lurk in every tree."


Re: PSA: Clock drift and pkgin

2023-12-30 Thread Michael van Elst
b...@softjar.se (Johnny Billquist) writes:

>Being able to measure time with high precision is desierable, but we can 
>already do that without being tickless.

We cannot delay with high precision. You can increase HZ to some degree,
but that comes at a price.



CVS commit: src/sys/dev/iscsi

2023-12-28 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Dec 28 15:58:24 UTC 2023

Modified Files:
src/sys/dev/iscsi: iscsi_main.c

Log Message:
Use correct status value SCSI_BUSY (0x08) instead of XS_BUSY (7) when running
out of sessions. The bug had no impact as scsipi was only comparing
against SCSI_CHECK (0x02) and SCSI_QUEUE_FULL (0x28).


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/iscsi/iscsi_main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/iscsi

2023-12-28 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Dec 28 15:58:24 UTC 2023

Modified Files:
src/sys/dev/iscsi: iscsi_main.c

Log Message:
Use correct status value SCSI_BUSY (0x08) instead of XS_BUSY (7) when running
out of sessions. The bug had no impact as scsipi was only comparing
against SCSI_CHECK (0x02) and SCSI_QUEUE_FULL (0x28).


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/iscsi/iscsi_main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/iscsi/iscsi_main.c
diff -u src/sys/dev/iscsi/iscsi_main.c:1.41 src/sys/dev/iscsi/iscsi_main.c:1.42
--- src/sys/dev/iscsi/iscsi_main.c:1.41	Tue Sep 13 13:09:16 2022
+++ src/sys/dev/iscsi/iscsi_main.c	Thu Dec 28 15:58:24 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: iscsi_main.c,v 1.41 2022/09/13 13:09:16 mlelstv Exp $	*/
+/*	$NetBSD: iscsi_main.c,v 1.42 2023/12/28 15:58:24 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -490,7 +490,7 @@ iscsi_scsipi_request(struct scsipi_chann
 			DEB(9, ("ISCSI: refcount too high: %d, winsize %d\n",
 sess->s_refcount, sess->s_send_window));
 			xs->error = XS_BUSY;
-			xs->status = XS_BUSY;
+			xs->status = SCSI_BUSY;
 			scsipi_done(xs);
 			return;
 		}



CVS commit: src/sbin/iscsid

2023-12-27 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Wed Dec 27 18:07:30 UTC 2023

Modified Files:
src/sbin/iscsid: iscsid_driverif.c

Log Message:
Treat port 0 (unset) as ISCSI_DEFAULT_PORT like before.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sbin/iscsid/iscsid_driverif.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/iscsid/iscsid_driverif.c
diff -u src/sbin/iscsid/iscsid_driverif.c:1.9 src/sbin/iscsid/iscsid_driverif.c:1.10
--- src/sbin/iscsid/iscsid_driverif.c:1.9	Sat Nov 25 08:06:02 2023
+++ src/sbin/iscsid/iscsid_driverif.c	Wed Dec 27 18:07:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: iscsid_driverif.c,v 1.9 2023/11/25 08:06:02 mlelstv Exp $	*/
+/*	$NetBSD: iscsid_driverif.c,v 1.10 2023/12/27 18:07:30 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -285,7 +285,8 @@ make_connection(session_t * sess, iscsid
 	memset(, 0, sizeof(hints));
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	snprintf(portnum, sizeof(portnum), "%u", addr->port);
+	snprintf(portnum, sizeof(portnum), "%u", addr->port
+	? addr->port : ISCSI_DEFAULT_PORT);
 	ret = getaddrinfo((char *)addr->address, portnum, , );
 	switch (ret) {
 	case 0:
@@ -553,7 +554,8 @@ event_recover_connection(uint32_t sid, u
 	memset(, 0, sizeof(hints));
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	snprintf(portnum, sizeof(portnum), "%u", addr->port);
+	snprintf(portnum, sizeof(portnum), "%u", addr->port
+	? addr->port : ISCSI_DEFAULT_PORT);
 	ret = getaddrinfo((char *)addr->address, portnum, , );
 	if (ret) {
 		DEB(1, ("getaddrinfo failed (%s)", gai_strerror(ret)));



CVS commit: src/sbin/iscsid

2023-12-27 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Wed Dec 27 18:07:30 UTC 2023

Modified Files:
src/sbin/iscsid: iscsid_driverif.c

Log Message:
Treat port 0 (unset) as ISCSI_DEFAULT_PORT like before.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sbin/iscsid/iscsid_driverif.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: After -10 patch that fixes kern/57669

2023-12-27 Thread Michael van Elst
joel.bertr...@systella.fr (=?UTF-8?Q?BERTRAND_Jo=c3=abl?=) writes:

>   I have seen Michael has applied patch to fix ccb_timout to -10 kernel.
>Thus, I have rebuilt my tree to have a unpatched kernel and I cannot now
>access to my NAS over iSCSI. Of course, I have reinstalled kernel /and/
>userland.

>   In dmesg, I only obtain :

>[71,854636] Invalid socket 7


Looks like there is a bug with the default port number.

Quick workaround is to specify the target with port number
like 1.2.3.4:3260.




Re: PSA: Clock drift and pkgin

2023-12-24 Thread Michael van Elst
sim...@netbsd.org (Simon Burge) writes:

>qemu uses ppoll() which is implemented with pollts() to do emulated
>timers, so that doesn't help here.  I don't know what simh uses, nor
>any of the other emulators.

simh uses pthread_cond_timedwait().

This actually waits using TIMER_ABSTIME for a deadline, but which is
converted to a timeout with ts2timo() and passed to sleepq_block()
as a number of ticks to wait for.

ts2timo() uses tvothz() which rounds up...



Re: PSA: Clock drift and pkgin

2023-12-23 Thread Michael van Elst
mo...@rodents-montreal.org (Mouse) writes:

>} else if (sec <= (LONG_MAX / 100))
>ticks = (((sec * 100) + (unsigned long)usec + (tick - 1))
>/ tick) + 1;

>which looks suspicious.  If sec is zero and usec is tick, that
>expression will return 2 instead of the 1 I suspect it needs to return.


The delay is always rounded up to the resolution of the clock,
so waiting for 1 microsecond waits at least 10ms.

The interval to the next tick can be arbitrarily short. Waiting
for at least 10ms therefore means to wait for the second next
tick.

In a tickless system, such a problem doesn't exist.



Re: Are The Packages Gone Again?

2023-12-19 Thread Michael van Elst
j...@m5.chicago.il.us ("Jay F. Shachter") writes:

>I was able to reinstall ghostscript (as I stated).  The others --
>ImageMagick6, atril, gv, libspectre and okular -- are gone.

At least there was no problem to build them.

-rw-r--r--  1 root  wheel  11102472 Sep 29 14:25 
final-amd64-10.0-2023Q3/All/ImageMagick6-6.9.12.91.tgz
-rw-r--r--  1 root  wheel   4430189 Sep 29 18:01 
final-amd64-10.0-2023Q3/All/atril-1.26.1nb1.tgz
-rw-r--r--  1 root  wheel220628 Sep 29 17:37 
final-amd64-10.0-2023Q3/All/gv-3.7.4nb12.tgz
-rw-r--r--  1 root  wheel 71680 Sep 29 13:50 
final-amd64-10.0-2023Q3/All/libspectre-0.2.9nb2.tgz
-rw-r--r--  1 root  wheel   9531552 Sep 30 00:34 
final-amd64-10.0-2023Q3/All/okular-23.04.3.tgz



Re: Change max ttys from 8 to 12?

2023-12-19 Thread Michael van Elst
u...@stderr.spb.ru (Valery Ushakov) writes:

>Switching from a fixed size array to a dynamic one is probably not too
>much work either.  But then, overall, I think that trying to make the
>kernel substitute for screen, tmux (in base), etc is kinda dead end,
>so I'd rather we don't encourage it.


We currently already have an inconsistent configuration. wscons
is limited to 8 screens but there are keyboard symbols to switch
to 10 screens where the last two cannot be used.

So bumping the screen limit to 10 shouldn't really be the question.

Bumping both limits to 12 (and augmenting keysyms and the keymaps
for this) would align this with the other *BSDs. The con side here
is that some keyboards either only have 10 function keys or already
use F11 and F12 for other purposes (like DEC keyboard has F11=ESC,
so ctrl-alt-f11 invokes DDB).



Re: Are The Packages Gone Again?

2023-12-19 Thread Michael van Elst
j...@m5.chicago.il.us ("Jay F. Shachter") writes:

>Are the NetBSD 10 packages gone again?  I recently removed ghostscript
>with the intention of re-installing it (gs was complaining that there
>was no libtiff.so, which is preposterous, because there was, but I
>didn't want to argue with it).

Can't tell why they are gone. My last private bulk build yielded:

-rw-r--r--  1 root  wheel  1390 Sep 29 07:47 
final-amd64-10.0-2023Q3/All/ghostscript-9.05nb31.tgz
-rw-r--r--  1 root  wheel  23276644 Sep 29 07:47 
final-amd64-10.0-2023Q3/All/ghostscript-agpl-10.01.2.tgz
-rw-r--r--  1 root  wheel  5460 Sep 30 01:12 
final-amd64-10.0-2023Q3/All/ghostscript-cidfonts-2901nb6.tgz
-rw-r--r--  1 root  wheel  5456 Sep 30 14:37 
final-amd64-10.0-2023Q3/All/ghostscript-cmaps-20020913nb3.tgz
-rw-r--r--  1 root  wheel827591 Sep 29 07:30 
final-amd64-10.0-2023Q3/All/ghostscript-fonts-8.11nb3.tgz
-rw-r--r--  1 root  wheel  14937225 Sep 30 04:45 
final-amd64-10.0-2023Q3/All/ghostscript-gpl-9.06nb47.tgz




CVS commit: src/sys/dev/pci

2023-12-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Dec 16 16:35:49 UTC 2023

Modified Files:
src/sys/dev/pci: if_rge.c

Log Message:
- handle stuck transmitter (descriptor still owned)
- restart send queue after transmit
- count output packets
- use deferred start

Should fix PR 57694


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/pci/if_rge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_rge.c
diff -u src/sys/dev/pci/if_rge.c:1.28 src/sys/dev/pci/if_rge.c:1.29
--- src/sys/dev/pci/if_rge.c:1.28	Thu Oct 19 23:43:40 2023
+++ src/sys/dev/pci/if_rge.c	Sat Dec 16 16:35:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_rge.c,v 1.28 2023/10/19 23:43:40 mrg Exp $	*/
+/*	$NetBSD: if_rge.c,v 1.29 2023/12/16 16:35:49 mlelstv Exp $	*/
 /*	$OpenBSD: if_rge.c,v 1.9 2020/12/12 11:48:53 jan Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_rge.c,v 1.28 2023/10/19 23:43:40 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_rge.c,v 1.29 2023/12/16 16:35:49 mlelstv Exp $");
 
 #include 
 
@@ -351,6 +351,7 @@ rge_attach(device_t parent, device_t sel
 	sc->sc_media.ifm_media = sc->sc_media.ifm_cur->ifm_media;
 
 	if_attach(ifp);
+	if_deferred_start_init(ifp, NULL);
 	ether_ifattach(ifp, eaddr);
 
 	if (pmf_device_register(self, NULL, NULL))
@@ -1385,10 +1386,14 @@ rge_txeof(struct rge_softc *sc)
 		m_freem(txq->txq_mbuf);
 		txq->txq_mbuf = NULL;
 
+		net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
 		if (txstat & (RGE_TDCMDSTS_EXCESSCOLL | RGE_TDCMDSTS_COLL))
-			if_statinc(ifp, if_collisions);
+			if_statinc_ref(nsr, if_collisions);
 		if (txstat & RGE_TDCMDSTS_TXERR)
-			if_statinc(ifp, if_oerrors);
+			if_statinc_ref(nsr, if_oerrors);
+		else
+			if_statinc_ref(nsr, if_opackets);
+		IF_STAT_PUTREF(ifp);
 
 		bus_dmamap_sync(sc->sc_dmat, sc->rge_ldata.rge_tx_list_map,
 		idx * sizeof(struct rge_tx_desc),
@@ -1404,24 +1409,12 @@ rge_txeof(struct rge_softc *sc)
 
 	sc->rge_ldata.rge_txq_considx = cons;
 
-#if 0
-	if (ifq_is_oactive(>if_snd))
-		ifq_restart(>if_snd);
-	else if (free == 2)
-		ifq_serialize(>if_snd, >sc_task);
-	else
-		ifp->if_timer = 0;
-#else
-#if 0
-	if (!IF_IS_EMPTY(>if_snd))
-		rge_start(ifp);
-	else
 	if (free == 2)
-		if (0) { rge_txstart(>sc_task, sc); }
-	else
-#endif
-		ifp->if_timer = 0;
-#endif
+		rge_txstart(>sc_task, sc);
+
+	CLR(ifp->if_flags, IFF_OACTIVE);
+	ifp->if_timer = 0;
+	if_schedule_deferred_start(ifp);
 
 	return (1);
 }



CVS commit: src/sys/dev/pci

2023-12-16 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Dec 16 16:35:49 UTC 2023

Modified Files:
src/sys/dev/pci: if_rge.c

Log Message:
- handle stuck transmitter (descriptor still owned)
- restart send queue after transmit
- count output packets
- use deferred start

Should fix PR 57694


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/pci/if_rge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/i386/stand/libsa

2023-12-14 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Dec 14 08:06:23 UTC 2023

Modified Files:
src/sys/arch/i386/stand/libsa: nfs.c

Log Message:
Align again with libsa (NFS_NOSYMLINK fix).


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/i386/stand/libsa/nfs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/i386/stand/libsa

2023-12-14 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu Dec 14 08:06:23 UTC 2023

Modified Files:
src/sys/arch/i386/stand/libsa: nfs.c

Log Message:
Align again with libsa (NFS_NOSYMLINK fix).


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/i386/stand/libsa/nfs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/i386/stand/libsa/nfs.c
diff -u src/sys/arch/i386/stand/libsa/nfs.c:1.20 src/sys/arch/i386/stand/libsa/nfs.c:1.21
--- src/sys/arch/i386/stand/libsa/nfs.c:1.20	Tue Dec 12 09:16:17 2023
+++ src/sys/arch/i386/stand/libsa/nfs.c	Thu Dec 14 08:06:23 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs.c,v 1.20 2023/12/12 09:16:17 mlelstv Exp $	*/
+/*	$NetBSD: nfs.c,v 1.21 2023/12/14 08:06:23 mlelstv Exp $	*/
 
 /*-
  *  Copyright (c) 1993 John Brezak
@@ -597,9 +597,9 @@ nfs_open(const char *path, struct open_f
 	char namebuf[NFS_MAXPATHLEN + 1];
 	char linkbuf[NFS_MAXPATHLEN + 1];
 	int nlinks = 0;
+	n_long fa_type;
 #endif
 	int error = 0;
-	n_long fa_type;
 
 #ifdef NFS_DEBUG
  	if (debug)



CVS commit: src/sys/arch/i386/stand/libsa

2023-12-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Dec 12 09:16:17 UTC 2023

Modified Files:
src/sys/arch/i386/stand/libsa: nfs.c

Log Message:
Merge with generic libsa NFS code to minimize differences and to learn NFSv3.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/i386/stand/libsa/nfs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/i386/stand/libsa

2023-12-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Dec 12 09:16:17 UTC 2023

Modified Files:
src/sys/arch/i386/stand/libsa: nfs.c

Log Message:
Merge with generic libsa NFS code to minimize differences and to learn NFSv3.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/i386/stand/libsa/nfs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/i386/stand/libsa/nfs.c
diff -u src/sys/arch/i386/stand/libsa/nfs.c:1.19 src/sys/arch/i386/stand/libsa/nfs.c:1.20
--- src/sys/arch/i386/stand/libsa/nfs.c:1.19	Sun Dec 25 06:09:09 2011
+++ src/sys/arch/i386/stand/libsa/nfs.c	Tue Dec 12 09:16:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfs.c,v 1.19 2011/12/25 06:09:09 tsutsui Exp $	*/
+/*	$NetBSD: nfs.c,v 1.20 2023/12/12 09:16:17 mlelstv Exp $	*/
 
 /*-
  *  Copyright (c) 1993 John Brezak
@@ -28,6 +28,16 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * XXX Does not currently implement:
+ * XXX
+ * XXX LIBSA_NO_FS_CLOSE
+ * XXX LIBSA_NO_FS_SEEK
+ * XXX LIBSA_NO_FS_WRITE
+ * XXX LIBSA_NO_FS_SYMLINK (does this even make sense?)
+ * XXX LIBSA_FS_SINGLECOMPONENT (does this even make sense?)
+ */
+
 #include 
 #include 
 #include 
@@ -43,6 +53,7 @@
 
 #include "rpcv2.h"
 #include "nfsv2.h"
+#include "nfsv3.h"
 
 #include 
 #include "net.h"
@@ -50,40 +61,11 @@
 #include "nfs.h"
 #include "rpc.h"
 
-/* Define our own NFS attributes. */
-struct nfsv2_fattrs {
-	n_long	fa_type;
-	n_long	fa_mode;
-	n_long	fa_nlink;
-	n_long	fa_uid;
-	n_long	fa_gid;
-	n_long	fa_size;
-	n_long	fa_blocksize;
-	n_long	fa_rdev;
-	n_long	fa_blocks;
-	n_long	fa_fsid;
-	n_long	fa_fileid;
-	struct nfsv2_time fa_atime;
-	struct nfsv2_time fa_mtime;
-	struct nfsv2_time fa_ctime;
-};
-
-
-struct nfs_read_args {
-	u_char	fh[NFS_FHSIZE];
-	n_long	off;
-	n_long	len;
-	n_long	xxx;			/* XXX what's this for? */
-};
+/* Storage for any filehandle (including length for V3) */
+#define NFS_FHSTORE (NFS_FHSIZE < NFS_V3FHSIZE ? NFS_V3FHSIZE + 4: NFS_FHSIZE)
 
 /* Data part of nfs rpc reply (also the largest thing we receive) */
 #define NFSREAD_SIZE 1024
-struct nfs_read_repl {
-	n_long	errno;
-	struct	nfsv2_fattrs fa;
-	n_long	count;
-	u_char	data[NFSREAD_SIZE];
-};
 
 #ifndef NFS_NOSYMLINK
 struct nfs_readlnk_repl {
@@ -93,36 +75,88 @@ struct nfs_readlnk_repl {
 };
 #endif
 
+static inline uint64_t
+getnquad(n_long x[2]) {
+	return (uint64_t)ntohl(x[0]) << 32 | ntohl(x[1]);
+}
+
+static inline void
+setnquad(n_long x[2], uint64_t v)
+{
+	x[0] = htonl((n_long)(v >> 32));
+	x[1] = htonl((n_long)(v & 0x));
+}
+
 struct nfs_iodesc {
 	struct	iodesc	*iodesc;
 	off_t	off;
-	u_char	fh[NFS_FHSIZE];
-	struct nfsv2_fattrs fa;	/* all in network order */
+	int	version;
+	u_char	fh[NFS_FHSTORE];
+	union {
+		/* all in network order */
+		struct nfsv2_fattr v2;
+		struct nfsv3_fattr v3;
+	} u_fa;
 };
 
-int	nfs_getrootfh(struct iodesc *, char *, u_char *);
+static inline size_t
+fhstore(int version, u_char *fh)
+{
+	size_t len;
+
+	switch (version) {
+	case NFS_VER2:
+		len = NFS_FHSIZE;
+		break;
+	case NFS_VER3:
+		len = fh[0] << 24 | fh[1] << 16 | fh[2] << 8 | fh[3];
+		if (len > NFS_V3FHSIZE)
+			len = NFS_V3FHSIZE;
+		len = 4 + roundup(len, 4);
+		break;
+	default:
+		len = 0;
+		break;
+	}
+
+	return len;
+}
+
+static inline size_t
+fhcopy(int version, u_char *src, u_char *dst)
+{
+	size_t len = fhstore(version, src);
+	memcpy(dst, src, len);
+	return len;
+}
+
+#define setfh(d, s) fhcopy((d)->version, (s), (d)->fh)
+#define getfh(d, s) fhcopy((d)->version, (d)->fh, (s))
+
+
+struct nfs_iodesc nfs_root_node;
+
+int	nfs_getrootfh(struct iodesc *, char *, u_char *, int *);
 int	nfs_lookupfh(struct nfs_iodesc *, const char *, int,
 	struct nfs_iodesc *);
-#ifndef NFS_NOSYMLINK
 int	nfs_readlink(struct nfs_iodesc *, char *);
-#endif
 ssize_t	nfs_readdata(struct nfs_iodesc *, off_t, void *, size_t);
 
 /*
  * Fetch the root file handle (call mount daemon)
- * Return zero or error number.
+ * On error, return non-zero and set errno.
  */
 int
-nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp)
+nfs_getrootfh(struct iodesc *d, char *path, u_char *fhp, int *versionp)
 {
-	size_t len;
+	int len;
 	struct args {
 		n_long	len;
 		char	path[FNAME_SIZE];
 	} *args;
 	struct repl {
 		n_long	errno;
-		u_char	fh[NFS_FHSIZE];
+		u_char	fh[NFS_FHSTORE];
 	} *repl;
 	struct {
 		n_long	h[RPC_HEADER_WORDS];
@@ -136,32 +170,42 @@ nfs_getrootfh(struct iodesc *d, char *pa
 
 #ifdef NFS_DEBUG
 	if (debug)
-		printf("nfs_getrootfh: %s\n", path);
+		printf("%s: %s\n", __func__, path);
 #endif
 
 	args = 
 	repl = 
 
-	memset(args, 0, sizeof(*args));
+	(void)memset(args, 0, sizeof(*args));
 	len = strlen(path);
-	if (len > sizeof(args->path))
+	if ((size_t)len > sizeof(args->path))
 		len = sizeof(args->path);
 	args->len = htonl(len);
-	memcpy(args->path, path, len);
+	(void)memcpy(args->path, path, len);
 	len = 4 + roundup(len, 4);
 
-	cc = 

CVS commit: src/sys/lib/libsa

2023-12-12 Thread Michael van Elst
type = currfd->u_fa.v2.fa_type;
+			break;
+		case NFS_VER3:
+			fa_type = currfd->u_fa.v3.fa_type;
+			break;
+		default:
+			fa_type = htonl(NFNON);
+			break;
+		}
+		if (fa_type != htonl(NFDIR)) {
 			error = ENOTDIR;
 			goto out;
 		}
@@ -431,6 +647,7 @@ nfs_open(const char *path, struct open_f
 		newfd = alloc(sizeof(*newfd));
 		newfd->iodesc = currfd->iodesc;
 		newfd->off = 0;
+		newfd->version = currfd->version;
 
 		/*
 		 * Get next component of path name.
@@ -456,7 +673,18 @@ nfs_open(const char *path, struct open_f
 		/*
 		 * Check for symbolic link
 		 */
-		if (newfd->fa.fa_type == htonl(NFLNK)) {
+		switch (newfd->version) {
+		case NFS_VER2:
+			fa_type = newfd->u_fa.v2.fa_type;
+			break;
+		case NFS_VER3:
+			fa_type = newfd->u_fa.v3.fa_type;
+			break;
+		default:
+			fa_type = htonl(NFNON);
+			break;
+		}
+		if (fa_type == htonl(NFLNK)) {
 			int link_len, len;
 
 			error = nfs_readlink(newfd, linkbuf);
@@ -506,6 +734,7 @@ out:
 	currfd = alloc(sizeof(*currfd));
 	currfd->iodesc = nfs_root_node.iodesc;
 	currfd->off = 0;
+	currfd->version = nfs_root_node.version;
 
 	cp = path;
 	/*
@@ -613,7 +842,18 @@ __compactcall off_t
 nfs_seek(struct open_file *f, off_t offset, int where)
 {
 	struct nfs_iodesc *d = (struct nfs_iodesc *)f->f_fsdata;
-	n_long size = ntohl(d->fa.fa_size);
+	off_t size;
+
+	switch (d->version) {
+	case NFS_VER2:
+		size = ntohl(d->u_fa.v2.fa_size);
+		break;
+	case NFS_VER3:
+		size = getnquad(d->u_fa.v3.fa_size);
+		break;
+	default:
+		return -1;
+	}
 
 	switch (where) {
 	case SEEK_SET:
@@ -642,15 +882,29 @@ nfs_stat(struct open_file *f, struct sta
 	struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata;
 	n_long ftype, mode;
 
-	ftype = ntohl(fp->fa.fa_type);
-	mode  = ntohl(fp->fa.fa_mode);
-	mode |= nfs_stat_types[ftype & 7];
+	switch (fp->version) {
+	case NFS_VER2:
+		ftype = ntohl(fp->u_fa.v2.fa_type);
+		mode  = ntohl(fp->u_fa.v2.fa_mode);
+		sb->st_nlink = ntohl(fp->u_fa.v2.fa_nlink);
+		sb->st_uid   = ntohl(fp->u_fa.v2.fa_uid);
+		sb->st_gid   = ntohl(fp->u_fa.v2.fa_gid);
+		sb->st_size  = ntohl(fp->u_fa.v2.fa_size);
+		break;
+	case NFS_VER3:
+		ftype = ntohl(fp->u_fa.v3.fa_type);
+		mode  = ntohl(fp->u_fa.v3.fa_mode);
+		sb->st_nlink = ntohl(fp->u_fa.v3.fa_nlink);
+		sb->st_uid   = ntohl(fp->u_fa.v3.fa_uid);
+		sb->st_gid   = ntohl(fp->u_fa.v3.fa_gid);
+		sb->st_size  = getnquad(fp->u_fa.v3.fa_size);
+		break;
+	default:
+		return -1;
+	}
 
+	mode |= nfs_stat_types[ftype & 7];
 	sb->st_mode  = mode;
-	sb->st_nlink = ntohl(fp->fa.fa_nlink);
-	sb->st_uid   = ntohl(fp->fa.fa_uid);
-	sb->st_gid   = ntohl(fp->fa.fa_gid);
-	sb->st_size  = ntohl(fp->fa.fa_size);
 
 	return 0;
 }

Index: src/sys/lib/libsa/nfsv2.h
diff -u src/sys/lib/libsa/nfsv2.h:1.4 src/sys/lib/libsa/nfsv2.h:1.5
--- src/sys/lib/libsa/nfsv2.h:1.4	Sun Dec 11 12:24:46 2005
+++ src/sys/lib/libsa/nfsv2.h	Tue Dec 12 09:12:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: nfsv2.h,v 1.4 2005/12/11 12:24:46 christos Exp $	*/
+/*	$NetBSD: nfsv2.h,v 1.5 2023/12/12 09:12:55 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -144,19 +144,3 @@ struct nfsv2_fattr {
 	struct nfsv2_time fa_ctime;
 };
 
-struct nfsv2_sattr {
-	n_long	sa_mode;
-	n_long	sa_uid;
-	n_long	sa_gid;
-	n_long	sa_size;
-	struct nfsv2_time sa_atime;
-	struct nfsv2_time sa_mtime;
-};
-
-struct nfsv2_statfs {
-	n_long	sf_tsize;
-	n_long	sf_bsize;
-	n_long	sf_blocks;
-	n_long	sf_bfree;
-	n_long	sf_bavail;
-};

Index: src/sys/lib/libsa/rpcv2.h
diff -u src/sys/lib/libsa/rpcv2.h:1.3 src/sys/lib/libsa/rpcv2.h:1.4
--- src/sys/lib/libsa/rpcv2.h:1.3	Sun Dec 11 12:24:46 2005
+++ src/sys/lib/libsa/rpcv2.h	Tue Dec 12 09:12:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpcv2.h,v 1.3 2005/12/11 12:24:46 christos Exp $	*/
+/*	$NetBSD: rpcv2.h,v 1.4 2023/12/12 09:12:55 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -75,6 +75,7 @@
 /* RPC Prog definitions */
 #define	RPCPROG_MNT	15
 #define	RPCMNT_VER1	1
+#define	RPCMNT_VER3	3
 #define	RPCMNT_MOUNT	1
 #define	RPCMNT_DUMP	2
 #define	RPCMNT_UMOUNT	3

Added files:

Index: src/sys/lib/libsa/nfsv3.h
diff -u /dev/null src/sys/lib/libsa/nfsv3.h:1.1
--- /dev/null	Tue Dec 12 09:12:55 2023
+++ src/sys/lib/libsa/nfsv3.h	Tue Dec 12 09:12:55 2023
@@ -0,0 +1,73 @@
+/*	$NetBSD: nfsv3.h,v 1.1 2023/12/12 09:12:55 mlelstv Exp $	*/
+
+/*
+ * Copyright (c) 2023 Michael van Elst
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *no

CVS commit: src/sys/lib/libsa

2023-12-12 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Dec 12 09:12:55 UTC 2023

Modified Files:
src/sys/lib/libsa: nfs.c nfsv2.h rpcv2.h
Added Files:
src/sys/lib/libsa: nfsv3.h

Log Message:
Add NFSv3 support. Try NFSv3 and fall back to NFSv2.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/lib/libsa/nfs.c
cvs rdiff -u -r1.4 -r1.5 src/sys/lib/libsa/nfsv2.h
cvs rdiff -u -r0 -r1.1 src/sys/lib/libsa/nfsv3.h
cvs rdiff -u -r1.3 -r1.4 src/sys/lib/libsa/rpcv2.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.sbin/crash

2023-12-11 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Dec 11 14:00:47 UTC 2023

Modified Files:
src/usr.sbin/crash: crash.c

Log Message:
Implement cngetc, don't abort.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/crash/crash.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/crash/crash.c
diff -u src/usr.sbin/crash/crash.c:1.15 src/usr.sbin/crash/crash.c:1.16
--- src/usr.sbin/crash/crash.c:1.15	Wed Apr 12 17:53:32 2023
+++ src/usr.sbin/crash/crash.c	Mon Dec 11 14:00:47 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: crash.c,v 1.15 2023/04/12 17:53:32 riastradh Exp $	*/
+/*	$NetBSD: crash.c,v 1.16 2023/12/11 14:00:47 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: crash.c,v 1.15 2023/04/12 17:53:32 riastradh Exp $");
+__RCSID("$NetBSD: crash.c,v 1.16 2023/12/11 14:00:47 mlelstv Exp $");
 #endif /* not lint */
 
 #include 
@@ -94,7 +94,6 @@ void lockdebug_lock_print(void) {
 }
 #endif
 
-
 static void
 cleanup(void)
 {
@@ -309,9 +308,11 @@ db_check_interrupt(void)
 int
 cngetc(void)
 {
+	char ch;
 
-	fprintf(stderr, "cngetc\n");
-	abort();
+	if (el_getc(elptr, ) <= 0)
+		return 0;
+	return (unsigned char)ch;
 }
 
 void



  1   2   3   4   5   6   7   8   9   10   >