2000-06-25 08:32:39 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen
|
2004-06-20 13:50:50 +00:00
|
|
|
* Copyright (c) 2001-2004 Mark R. V. Murray
|
2014-04-30 06:20:48 +00:00
|
|
|
* Copyright (c) 2014 Eitan Adler
|
2000-06-25 08:32:39 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-06-25 08:32:39 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2002-04-08 09:20:07 +00:00
|
|
|
#include <sys/disk.h>
|
2000-06-25 08:32:39 +00:00
|
|
|
#include <sys/bus.h>
|
2012-01-11 15:00:16 +00:00
|
|
|
#include <sys/filio.h>
|
2011-05-13 19:35:01 +00:00
|
|
|
|
2000-06-25 08:32:39 +00:00
|
|
|
#include <machine/bus.h>
|
2011-05-13 19:35:01 +00:00
|
|
|
#include <machine/vmparam.h>
|
2000-06-25 08:32:39 +00:00
|
|
|
|
|
|
|
/* For use with destroy_dev(9). */
|
2014-04-30 06:30:37 +00:00
|
|
|
static struct cdev *full_dev;
|
2004-06-16 09:47:26 +00:00
|
|
|
static struct cdev *null_dev;
|
|
|
|
static struct cdev *zero_dev;
|
2000-06-25 08:32:39 +00:00
|
|
|
|
2014-04-30 06:20:48 +00:00
|
|
|
static d_write_t full_write;
|
2000-07-09 12:29:24 +00:00
|
|
|
static d_write_t null_write;
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
static d_ioctl_t null_ioctl;
|
2012-01-11 15:00:16 +00:00
|
|
|
static d_ioctl_t zero_ioctl;
|
2000-07-09 12:29:24 +00:00
|
|
|
static d_read_t zero_read;
|
2000-06-25 08:32:39 +00:00
|
|
|
|
2014-04-30 06:30:37 +00:00
|
|
|
static struct cdevsw full_cdevsw = {
|
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_read = zero_read,
|
|
|
|
.d_write = full_write,
|
|
|
|
.d_ioctl = zero_ioctl,
|
|
|
|
.d_name = "full",
|
|
|
|
};
|
|
|
|
|
2000-06-25 08:32:39 +00:00
|
|
|
static struct cdevsw null_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-11-01 09:31:54 +00:00
|
|
|
.d_read = (d_read_t *)nullop,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_write = null_write,
|
|
|
|
.d_ioctl = null_ioctl,
|
|
|
|
.d_name = "null",
|
2000-06-25 08:32:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct cdevsw zero_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_read = zero_read,
|
|
|
|
.d_write = null_write,
|
2012-01-11 15:00:16 +00:00
|
|
|
.d_ioctl = zero_ioctl,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_name = "zero",
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_flags = D_MMAP_ANON,
|
2000-06-25 08:32:39 +00:00
|
|
|
};
|
|
|
|
|
2014-04-30 06:20:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
2014-04-30 06:40:30 +00:00
|
|
|
full_write(struct cdev *dev __unused, struct uio *uio __unused, int flags __unused)
|
2014-04-30 06:20:48 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSPC);
|
|
|
|
}
|
|
|
|
|
2003-02-27 18:07:11 +00:00
|
|
|
/* ARGSUSED */
|
2000-06-25 08:32:39 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
null_write(struct cdev *dev __unused, struct uio *uio, int flags __unused)
|
2000-06-25 08:32:39 +00:00
|
|
|
{
|
|
|
|
uio->uio_resid = 0;
|
2004-06-20 13:50:50 +00:00
|
|
|
|
|
|
|
return (0);
|
2000-06-25 08:32:39 +00:00
|
|
|
}
|
|
|
|
|
2003-10-18 09:16:01 +00:00
|
|
|
/* ARGSUSED */
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
null_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data __unused,
|
2003-10-18 09:16:01 +00:00
|
|
|
int flags __unused, struct thread *td)
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
{
|
|
|
|
int error;
|
2012-01-11 15:00:16 +00:00
|
|
|
error = 0;
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
|
2012-01-11 15:00:16 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case DIOCSKERNELDUMP:
|
|
|
|
error = priv_check(td, PRIV_SETDUMPER);
|
|
|
|
if (error == 0)
|
2012-11-01 17:01:05 +00:00
|
|
|
error = set_dumper(NULL, NULL);
|
2012-01-11 15:00:16 +00:00
|
|
|
break;
|
|
|
|
case FIONBIO:
|
|
|
|
break;
|
|
|
|
case FIOASYNC:
|
|
|
|
if (*(int *)data != 0)
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = ENOIOCTL;
|
|
|
|
}
|
|
|
|
return (error);
|
Here follows the new kernel dumping infrastructure.
Caveats:
The new savecore program is not complete in the sense that it emulates
enough of the old savecores features to do the job, but implements none
of the options yet.
I would appreciate if a userland hacker could help me out getting savecore
to do what we want it to do from a users point of view, compression,
email-notification, space reservation etc etc. (send me email if
you are interested).
Currently, savecore will scan all devices marked as "swap" or "dump" in
/etc/fstab _or_ any devices specified on the command-line.
All architectures but i386 lack an implementation of dumpsys(), but
looking at the i386 version it should be trivial for anybody familiar
with the platform(s) to provide this function.
Documentation is quite sparse at this time, more to come.
Details:
ATA and SCSI drivers should work as the dump formatting code has been
removed. The IDA, TWE and AAC have not yet been converted.
Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set
the device as dumpdev. To implement the "off" argument, /dev/null
is used as the device.
Savecore will fail if handed any options since they are not (yet)
implemented. All devices marked "dump" or "swap" in /etc/fstab
will be scanned and dumps found will be saved to diskfiles
named from the MD5 hash of the header record. The header record
is dumped in readable format in the .info file. The kernel
is not saved. Only complete dumps will be saved.
All maintainer rights for this code are disclaimed: feel free to
improve and extend.
Sponsored by: DARPA, NAI Labs
2002-03-31 22:37:00 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 15:00:16 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
zero_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data __unused,
|
|
|
|
int flags __unused, struct thread *td)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FIONBIO:
|
|
|
|
break;
|
|
|
|
case FIOASYNC:
|
|
|
|
if (*(int *)data != 0)
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = ENOIOCTL;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-27 18:07:11 +00:00
|
|
|
/* ARGSUSED */
|
2000-06-25 08:32:39 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
zero_read(struct cdev *dev __unused, struct uio *uio, int flags __unused)
|
2000-06-25 08:32:39 +00:00
|
|
|
{
|
2011-05-13 18:48:00 +00:00
|
|
|
void *zbuf;
|
|
|
|
ssize_t len;
|
2000-06-25 08:32:39 +00:00
|
|
|
int error = 0;
|
|
|
|
|
2011-05-13 18:48:00 +00:00
|
|
|
KASSERT(uio->uio_rw == UIO_READ,
|
|
|
|
("Can't be in %s for write", __func__));
|
|
|
|
zbuf = __DECONST(void *, zero_region);
|
|
|
|
while (uio->uio_resid > 0 && error == 0) {
|
|
|
|
len = uio->uio_resid;
|
|
|
|
if (len > ZERO_REGION_SIZE)
|
|
|
|
len = ZERO_REGION_SIZE;
|
|
|
|
error = uiomove(zbuf, len, uio);
|
|
|
|
}
|
2004-06-20 13:50:50 +00:00
|
|
|
|
|
|
|
return (error);
|
2000-06-25 08:32:39 +00:00
|
|
|
}
|
|
|
|
|
2003-02-27 18:07:11 +00:00
|
|
|
/* ARGSUSED */
|
2000-06-25 08:32:39 +00:00
|
|
|
static int
|
2003-02-27 18:07:11 +00:00
|
|
|
null_modevent(module_t mod __unused, int type, void *data __unused)
|
2000-06-25 08:32:39 +00:00
|
|
|
{
|
|
|
|
switch(type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
if (bootverbose)
|
2014-04-30 06:20:48 +00:00
|
|
|
printf("null: <full device, null device, zero device>\n");
|
|
|
|
full_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &full_cdevsw, 0,
|
|
|
|
NULL, UID_ROOT, GID_WHEEL, 0666, "full");
|
2010-08-06 09:47:48 +00:00
|
|
|
null_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &null_cdevsw, 0,
|
|
|
|
NULL, UID_ROOT, GID_WHEEL, 0666, "null");
|
|
|
|
zero_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &zero_cdevsw, 0,
|
|
|
|
NULL, UID_ROOT, GID_WHEEL, 0666, "zero");
|
2004-06-20 13:50:50 +00:00
|
|
|
break;
|
2000-06-25 08:32:39 +00:00
|
|
|
|
|
|
|
case MOD_UNLOAD:
|
2014-04-30 06:20:48 +00:00
|
|
|
destroy_dev(full_dev);
|
2000-06-25 08:32:39 +00:00
|
|
|
destroy_dev(null_dev);
|
|
|
|
destroy_dev(zero_dev);
|
2004-06-20 13:50:50 +00:00
|
|
|
break;
|
2000-06-25 08:32:39 +00:00
|
|
|
|
|
|
|
case MOD_SHUTDOWN:
|
2004-06-20 13:50:50 +00:00
|
|
|
break;
|
2000-06-25 08:32:39 +00:00
|
|
|
|
2004-07-15 08:26:07 +00:00
|
|
|
default:
|
|
|
|
return (EOPNOTSUPP);
|
2000-06-25 08:32:39 +00:00
|
|
|
}
|
2004-06-20 13:50:50 +00:00
|
|
|
|
|
|
|
return (0);
|
2000-06-25 08:32:39 +00:00
|
|
|
}
|
|
|
|
|
2000-10-02 20:16:37 +00:00
|
|
|
DEV_MODULE(null, null_modevent, NULL);
|
2004-08-02 19:59:41 +00:00
|
|
|
MODULE_VERSION(null, 1);
|