From a366002cdff09387ac8fc25e170fc269d5b757e9 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sat, 13 Aug 2022 01:53:51 +0000 Subject: [PATCH] spiflash(4): Answer DIOCGPARTINFO with basic size information. --- sys/dev/spi/spiflash.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/sys/dev/spi/spiflash.c b/sys/dev/spi/spiflash.c index 3332a9b0e44a..df48ee7f8339 100644 --- a/sys/dev/spi/spiflash.c +++ b/sys/dev/spi/spiflash.c @@ -297,12 +297,34 @@ int spiflash_ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l) { spiflash_handle_t sc; + int error; sc = device_lookup_private(&spiflash_cd, DISKUNIT(dev)); if (sc == NULL) return ENXIO; - return EINVAL; + switch (cmd) { + case DIOCGPARTINFO: { + struct partinfo *pi = data; + unsigned secsize; + + secsize = MAX(sc->sc_write_size, sc->sc_read_size); + secsize = MAX(DEV_BSIZE, secsize); /* paranoia */ + + memset(pi, 0, sizeof(*pi)); + pi->pi_offset = 0; + pi->pi_secsize = secsize; + pi->pi_size = sc->sc_device_size / secsize; + pi->pi_bsize = MAX(BLKDEV_IOSIZE, secsize); + + error = 0; + break; + } + default: + error = ENOTTY; + } + + return error; } void