summaryrefslogtreecommitdiff
path: root/sys/dev/null/null.c
AgeCommit message (Collapse)Author
2025-10-18Match style in 3613896David E. O'Brien
Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D53193
2025-10-18knotes: kqueue: handle copy for trivial filtersKonstantin Belousov
Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D52045
2025-08-11null: support EVFILT_READ/EVFILT_WRITE kevent filtersPietro Cerutti
This enhances the full, null, and zero devices to support read and write kevent filters. A read event is immediately triggered for full and null, and never for zero. A write event is immediately triggered for zero and null, and never for full. Reviewed by: cognet MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D51807
2023-11-26sys: Automated cleanup of cdefs and other formattingWarner Losh
Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
2023-08-16sys: Remove $FreeBSD$: one-line .c patternWarner Losh
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-05-12spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
2022-04-15Remove 12.x ABI compat for kernel dump ioctlsMitchell Horne
This code was marked gone_in(14), so it can now be removed. The only consumer of this interface is dumpon(8). We do not maintain strict backwards compatibility for this utility because a) it can't/shouldn't be used from a jail or chroot and b) it is highly specific interface unique to FreeBSD. The host's (presumably more up-to-date) copy of dumpon(8) should be used to configure kernel dump devices. Reviewed by: markj, emaste MFC after: never Differential Revision: https://reviews.freebsd.org/D34914
2022-04-15Remove 11.x ABI compat for kernel dump ioctlsMitchell Horne
This code was marked gone_in(13), so its time has passed. The only consumer of this interface is dumpon(8). We do not maintain strict backwards compatibility for this utility because a) it can't/shouldn't be used from a jail or chroot and b) it is highly specific interface unique to FreeBSD. The host's (presumably more up-to-date) copy of dumpon(8) should be used to configure kernel dump devices. Reviewed by: markj, emaste MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D34913
2020-09-01null: clean up empty lines in .c and .h filesMateusz Guzik
Notes: svn path=/head/; revision=365191
2019-05-06List-ify kernel dump device configurationConrad Meyer
Allow users to specify multiple dump configurations in a prioritized list. This enables fallback to secondary device(s) if primary dump fails. E.g., one might configure a preference for netdump, but fallback to disk dump as a second choice if netdump is unavailable. This change does not list-ify netdump configuration, which is tracked separately from ordinary disk dumps internally; only one netdump configuration can be made at a time, for now. It also does not implement IPv6 netdump. savecore(8) is already capable of scanning and iterating multiple devices from /etc/fstab or passed on the command line. This change doesn't update the rc or loader variables 'dumpdev' in any way; it can still be set to configure a single dump device, and rc.d/savecore still uses it as a single device. Only dumpon(8) is updated to be able to configure the more complicated configurations for now. As part of revving the ABI, unify netdump and disk dump configuration ioctl / structure, and leave room for ipv6 netdump as a future possibility. Backwards-compatibility ioctls are added to smooth ABI transition, especially for developers who may not keep kernel and userspace perfectly synced. Reviewed by: markj, scottl (earlier version) Relnotes: maybe Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D19996 Notes: svn path=/head/; revision=347192
2018-05-06Refactor some of the MI kernel dump code in preparation for netdump.Mark Johnston
- Add clear_dumper() to complement set_dumper(). - Drain netdump's preallocated mbuf pool when clearing the dumper. - Don't do bounds checking for dumpers with mediasize 0. - Add dumper callbacks for initialization for writing out headers. Reviewed by: sbruno MFC after: 1 month Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D15252 Notes: svn path=/head/; revision=333282
2018-04-06Move most of the contents of opt_compat.h to opt_global.h.Brooks Davis
opt_compat.h is mentioned in nearly 180 files. In-progress network driver compabibility improvements may add over 100 more so this is closer to "just about everywhere" than "only some files" per the guidance in sys/conf/options. Keep COMPAT_LINUX32 in opt_compat.h as it is confined to a subset of sys/compat/linux/*.c. A fake _COMPAT_LINUX option ensure opt_compat.h is created on all architectures. Move COMPAT_LINUXKPI to opt_dontuse.h as it is only used to control the set of compiled files. Reviewed by: kib, cem, jhb, jtl Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14941 Notes: svn path=/head/; revision=332122
2017-11-27sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni
Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
2017-10-25Add support for compressed kernel dumps.Mark Johnston
When using a kernel built with the GZIO config option, dumpon -z can be used to configure gzip compression using the in-kernel copy of zlib. This is useful on systems with large amounts of RAM, which require a correspondingly large dump device. Recovery of compressed dumps is also faster since fewer bytes need to be copied from the dump device. Because we have no way of knowing the final size of a compressed dump until it is written, the kernel will always attempt to dump when compression is configured, regardless of the dump device size. If the dump is aborted because we run out of space, an error is reported on the console. savecore(8) is modified to handle compressed dumps and save them to vmcore.<index>.gz, as it does when given the -z option. A new rc.conf variable, dumpon_flags, is added. Its value is added to the boot-time dumpon(8) invocation that occurs when a dump device is configured in rc.conf. Reviewed by: cem (earlier version) Discussed with: def, rgrimes Relnotes: yes Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D11723 Notes: svn path=/head/; revision=324965
2016-12-10Add support for encrypted kernel crash dumps.Konrad Witaszczyk
Changes include modifications in kernel crash dump routines, dumpon(8) and savecore(8). A new tool called decryptcore(8) was added. A new DIOCSKERNELDUMP I/O control was added to send a kernel crash dump configuration in the diocskerneldump_arg structure to the kernel. The old DIOCSKERNELDUMP I/O control was renamed to DIOCSKERNELDUMP_FREEBSD11 for backward ABI compatibility. dumpon(8) generates an one-time random symmetric key and encrypts it using an RSA public key in capability mode. Currently only AES-256-CBC is supported but EKCD was designed to implement support for other algorithms in the future. The public key is chosen using the -k flag. The dumpon rc(8) script can do this automatically during startup using the dumppubkey rc.conf(5) variable. Once the keys are calculated dumpon sends them to the kernel via DIOCSKERNELDUMP I/O control. When the kernel receives the DIOCSKERNELDUMP I/O control it generates a random IV and sets up the key schedule for the specified algorithm. Each time the kernel tries to write a crash dump to the dump device, the IV is replaced by a SHA-256 hash of the previous value. This is intended to make a possible differential cryptanalysis harder since it is possible to write multiple crash dumps without reboot by repeating the following commands: # sysctl debug.kdb.enter=1 db> call doadump(0) db> continue # savecore A kernel dump key consists of an algorithm identifier, an IV and an encrypted symmetric key. The kernel dump key size is included in a kernel dump header. The size is an unsigned 32-bit integer and it is aligned to a block size. The header structure has 512 bytes to match the block size so it was required to make a panic string 4 bytes shorter to add a new field to the header structure. If the kernel dump key size in the header is nonzero it is assumed that the kernel dump key is placed after the first header on the dump device and the core dump is encrypted. Separate functions were implemented to write the kernel dump header and the kernel dump key as they need to be unencrypted. The dump_write function encrypts data if the kernel was compiled with the EKCD option. Encrypted kernel textdumps are not supported due to the way they are constructed which makes it impossible to use the CBC mode for encryption. It should be also noted that textdumps don't contain sensitive data by design as a user decides what information should be dumped. savecore(8) writes the kernel dump key to a key.# file if its size in the header is nonzero. # is the number of the current core dump. decryptcore(8) decrypts the core dump using a private RSA key and the kernel dump key. This is performed by a child process in capability mode. If the decryption was not successful the parent process removes a partially decrypted core dump. Description on how to encrypt crash dumps was added to the decryptcore(8), dumpon(8), rc.conf(5) and savecore(8) manual pages. EKCD was tested on amd64 using bhyve and i386, mipsel and sparc64 using QEMU. The feature still has to be tested on arm and arm64 as it wasn't possible to run FreeBSD due to the problems with QEMU emulation and lack of hardware. Designed by: def, pjd Reviewed by: cem, oshogbo, pjd Partial review: delphij, emaste, jhb, kib Approved by: pjd (mentor) Differential Revision: https://reviews.freebsd.org/D4712 Notes: svn path=/head/; revision=309818
2014-11-11Add missing privilege check when setting the dump device. Before that change itPawel Jakub Dawidek
was possible for a regular user to setup the dump device if he had write access to the given device. In theory it is a security issue as user might get access to kernel's memory after provoking kernel crash, but in practise it is not recommended to give regular users direct access to storage devices. Rework the code so that we do privileges check within the set_dumper() function to avoid similar problems in the future. Discussed with: secteam Notes: svn path=/head/; revision=274366
2014-04-30null.c: uio is unusedEitan Adler
Mark another parameter as unused Reported by: rpaulo Notes: svn path=/head/; revision=265136
2014-04-30null.c: fix orderingEitan Adler
Use a consistent ordering of full -> null -> zero (alphabetical) in null.c Reported by: mjg Notes: svn path=/head/; revision=265134
2014-04-30Add a /dev/full device.Eitan Adler
/dev/full is similar to /dev/zero except it always returns ENOSPC when you attempt to write to it. Reviewed by: jhibbits Discussed with: rpaulo Notes: svn path=/head/; revision=265132
2012-11-01Provide a device name in the sysctl tree for programs to query theAlfred Perlstein
state of crashdump target devices. This will be used to add a "-l" (ell) flag to dumpon(8) to list the currently configured dumpdev. Reviewed by: phk Notes: svn path=/head/; revision=242439
2012-01-11Fix for PR 138526.George V. Neville-Neil
Add the ability for /dev/null and /dev/zero to accept being set into non blocking mode via fcntl(). This brings the code into compliance with IEEE Std 1003.1-2001 as referenced in another PR, 94729. Reviewed by: jhb MFC after: 1 week Notes: svn path=/head/; revision=229965
2011-05-13Move the ZERO_REGION_SIZE to a machine-dependent file, as on manyMatthew D Fleming
architectures (i386, for example) the virtual memory space may be constrained enough that 2MB is a large chunk. Use 64K for arches other than amd64 and ia64, with special handling for sparc64 due to differing hardware. Also commit the comment changes to kmem_init_zero_region() that I missed due to not saving the file. (Darn the unfamiliar development environment). Arch maintainers, please feel free to adjust ZERO_REGION_SIZE as you see fit. Requested by: alc MFC after: 1 week MFC with: r221853 Notes: svn path=/head/; revision=221855
2011-05-13Usa a globally visible region of zeros for both /dev/zero and the mdMatthew D Fleming
device. There are likely other kernel uses of "blob of zeros" than can be converted. Reviewed by: alc MFC after: 1 week Notes: svn path=/head/; revision=221853
2010-08-06Mark /dev/zero and /dev/null as eternal.Konstantin Belousov
In collaboration with: pho MFC after: 1 month Notes: svn path=/head/; revision=210926
2009-09-06Remove unneeded minor numbers from /dev/null and /dev/zero.Ed Schouten
Notes: svn path=/head/; revision=196885
2006-11-06Sweep kernel replacing suser(9) calls with priv(9) calls, assigningRobert Watson
specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net> Notes: svn path=/head/; revision=164033
2005-02-27Use dynamic major number allocation.Poul-Henning Kamp
Notes: svn path=/head/; revision=142707
2004-08-02Go back to the historical minor numbers. Add a module version whileMark Murray
I'm here. Asked for minor numbers by: jhb Notes: svn path=/head/; revision=133033
2004-08-01YA oops. Remove code that was being tested locally.Mark Murray
Notes: svn path=/head/; revision=132963
2004-08-01Break out the MI part of the /dev/[k]mem and /dev/io drivers intoMark Murray
their own directory and module, leaving the MD parts in the MD area (the MD parts _are_ part of the modules). /dev/mem and /dev/io are now loadable modules, thus taking us one step further towards a kernel created entirely out of modules. Of course, there is nothing preventing the kernel from having these statically compiled. Notes: svn path=/head/; revision=132956
2004-07-15Do a pass over all modules in the kernel and make them return EOPNOTSUPPPoul-Henning Kamp
for unknown events. A number of modules return EINVAL in this instance, and I have left those alone for now and instead taught MOD_QUIESCE to accept this as "didn't do anything". Notes: svn path=/head/; revision=132199
2004-06-20Micro-tweaking.Mark Murray
Notes: svn path=/head/; revision=130788
2004-06-16Do the dreaded s/dev_t/struct cdev */Poul-Henning Kamp
Bump __FreeBSD_version accordingly. Notes: svn path=/head/; revision=130585
2004-02-21Device megapatch 4/6:Poul-Henning Kamp
Introduce d_version field in struct cdevsw, this must always be initialized to D_VERSION. Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing four D_NOGIANT flags and adding 145 D_NEEDGIANT flags. Notes: svn path=/head/; revision=126080
2003-11-01Shorten the code by removing one "do-nothing" function, replacing itMark Murray
with nullop(), which is in kern_conf.c. Notes: svn path=/head/; revision=121856
2003-10-18Mark as __unused some arguments that are, erm, unused.Mark Murray
Notes: svn path=/head/; revision=121189
2003-09-27Return ENOIOCTL for unknown ioctls, don't use noioctl to return ENODEV.Poul-Henning Kamp
Notes: svn path=/head/; revision=120510
2003-09-27The present defaults for the open and close for device drivers whichPoul-Henning Kamp
provide no methods does not make any sense, and is not used by any driver. It is a pretty hard to come up with even a theoretical concept of a device driver which would always fail open and close with ENODEV. Change the defaults to be nullopen() and nullclose() which simply does nothing. Remove explicit initializations to these from the drivers which already used them. Notes: svn path=/head/; revision=120506
2003-08-24Use __FBSDID().David E. O'Brien
Also some minor style cleanups. Notes: svn path=/head/; revision=119418
2003-06-24/dev/null and /dev/zero does not need GiantPoul-Henning Kamp
Notes: svn path=/head/; revision=116794
2003-03-03Gigacommit to improve device-driver source compatibility betweenPoul-Henning Kamp
branches: Initialize struct cdevsw using C99 sparse initializtion and remove all initializations to default values. This patch is automatically generated and has been tested by compiling LINT with all the fields in struct cdevsw in reverse order on alpha, sparc64 and i386. Approved by: re(scottl) Notes: svn path=/head/; revision=111815
2003-03-02Don't use evil casts in cdevsw initialization.Poul-Henning Kamp
Notes: svn path=/head/; revision=111758
2003-02-27Warns and lint fix. Nearly all trivial stuff.Mark Murray
Notes: svn path=/head/; revision=111630
2003-02-19Back out M_* changes, per decision of the TRB.Warner Losh
Approved by: trb Notes: svn path=/head/; revision=111119
2003-01-21Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.Alfred Perlstein
Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT. Notes: svn path=/head/; revision=109623
2002-09-21Everywhere else, an argument passed to a device containing flagsMark Murray
is called "flags". Make it so here. Notes: svn path=/head/; revision=103745
2002-08-02Modernise the cdevsw WRT to (unused) kqueue.Mark Murray
Notes: svn path=/head/; revision=101219
2002-04-09Rename DIOCGKERNELDUMP to DIOCSKERNELDUMP as it strictly speakingPoul-Henning Kamp
is a "set" not a "get" operation. Sponsored by: DARPA & NAI Labs. Notes: svn path=/head/; revision=94272
2002-04-08Move generic disk ioctls from <sys/disklabel.h> to <sys/disk.h>.Poul-Henning Kamp
Sponsored by: DARPA & NAI Labs Notes: svn path=/head/; revision=94182
2002-04-01Change the suser() API to take advantage of td_ucred as well as do aJohn Baldwin
general cleanup of the API. The entire API now consists of two functions similar to the pre-KSE API. The suser() function takes a thread pointer as its only argument. The td_ucred member of this thread must be valid so the only valid thread pointers are curthread and a few kernel threads such as thread0. The suser_cred() function takes a pointer to a struct ucred as its first argument and an integer flag as its second argument. The flag is currently only used for the PRISON_ROOT flag. Discussed on: smp@ Notes: svn path=/head/; revision=93593