kern_shutdown.c (c79126f2e4b31976a54d1c30961d8c7b0f740a3c) kern_shutdown.c (6026dcd7ca888f3433f4df34ede69a77c1eb7701)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1986, 1988, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph

--- 160 unchanged lines hidden (view full) ---

169 keyInstance kdc_ki;
170 cipherInstance kdc_ci;
171 uint32_t kdc_dumpkeysize;
172 struct kerneldumpkey kdc_dumpkey[];
173};
174#endif
175
176struct kerneldumpcomp {
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1986, 1988, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph

--- 160 unchanged lines hidden (view full) ---

169 keyInstance kdc_ki;
170 cipherInstance kdc_ci;
171 uint32_t kdc_dumpkeysize;
172 struct kerneldumpkey kdc_dumpkey[];
173};
174#endif
175
176struct kerneldumpcomp {
177 uint8_t kdc_format;
177 struct compressor *kdc_stream;
178 uint8_t *kdc_buf;
179 size_t kdc_resid;
180};
181
182static struct kerneldumpcomp *kerneldumpcomp_create(struct dumperinfo *di,
183 uint8_t compression);
184static void kerneldumpcomp_destroy(struct dumperinfo *di);

--- 797 unchanged lines hidden (view full) ---

982 return (kdc->kdc_dumpkeysize);
983}
984#endif /* EKCD */
985
986static struct kerneldumpcomp *
987kerneldumpcomp_create(struct dumperinfo *di, uint8_t compression)
988{
989 struct kerneldumpcomp *kdcomp;
178 struct compressor *kdc_stream;
179 uint8_t *kdc_buf;
180 size_t kdc_resid;
181};
182
183static struct kerneldumpcomp *kerneldumpcomp_create(struct dumperinfo *di,
184 uint8_t compression);
185static void kerneldumpcomp_destroy(struct dumperinfo *di);

--- 797 unchanged lines hidden (view full) ---

983 return (kdc->kdc_dumpkeysize);
984}
985#endif /* EKCD */
986
987static struct kerneldumpcomp *
988kerneldumpcomp_create(struct dumperinfo *di, uint8_t compression)
989{
990 struct kerneldumpcomp *kdcomp;
991 int format;
990
992
991 if (compression != KERNELDUMP_COMP_GZIP)
993 switch (compression) {
994 case KERNELDUMP_COMP_GZIP:
995 format = COMPRESS_GZIP;
996 break;
997 case KERNELDUMP_COMP_ZSTD:
998 format = COMPRESS_ZSTD;
999 break;
1000 default:
992 return (NULL);
1001 return (NULL);
1002 }
1003
993 kdcomp = malloc(sizeof(*kdcomp), M_DUMPER, M_WAITOK | M_ZERO);
1004 kdcomp = malloc(sizeof(*kdcomp), M_DUMPER, M_WAITOK | M_ZERO);
1005 kdcomp->kdc_format = compression;
994 kdcomp->kdc_stream = compressor_init(kerneldumpcomp_write_cb,
1006 kdcomp->kdc_stream = compressor_init(kerneldumpcomp_write_cb,
995 COMPRESS_GZIP, di->maxiosize, kerneldump_gzlevel, di);
1007 format, di->maxiosize, kerneldump_gzlevel, di);
996 if (kdcomp->kdc_stream == NULL) {
997 free(kdcomp, M_DUMPER);
998 return (NULL);
999 }
1000 kdcomp->kdc_buf = malloc(di->maxiosize, M_DUMPER, M_WAITOK | M_NODUMP);
1001 return (kdcomp);
1002}
1003

--- 284 unchanged lines hidden (view full) ---

1288 if (di->mediasize < SIZEOF_METADATA + dumpextent + 2 * di->blocksize +
1289 keysize) {
1290 if (di->kdcomp != NULL) {
1291 /*
1292 * We don't yet know how much space the compressed dump
1293 * will occupy, so try to use the whole swap partition
1294 * (minus the first 64KB) in the hope that the
1295 * compressed dump will fit. If that doesn't turn out to
1008 if (kdcomp->kdc_stream == NULL) {
1009 free(kdcomp, M_DUMPER);
1010 return (NULL);
1011 }
1012 kdcomp->kdc_buf = malloc(di->maxiosize, M_DUMPER, M_WAITOK | M_NODUMP);
1013 return (kdcomp);
1014}
1015

--- 284 unchanged lines hidden (view full) ---

1300 if (di->mediasize < SIZEOF_METADATA + dumpextent + 2 * di->blocksize +
1301 keysize) {
1302 if (di->kdcomp != NULL) {
1303 /*
1304 * We don't yet know how much space the compressed dump
1305 * will occupy, so try to use the whole swap partition
1306 * (minus the first 64KB) in the hope that the
1307 * compressed dump will fit. If that doesn't turn out to
1296 * be enouch, the bounds checking in dump_write()
1308 * be enough, the bounds checking in dump_write()
1297 * will catch us and cause the dump to fail.
1298 */
1299 dumpextent = di->mediasize - SIZEOF_METADATA -
1300 2 * di->blocksize - keysize;
1301 kdh->dumpextent = htod64(dumpextent);
1302 } else
1303 return (E2BIG);
1304 }

--- 153 unchanged lines hidden (view full) ---

1458 kdh->blocksize = htod32(di->blocksize);
1459 strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname));
1460 dstsize = sizeof(kdh->versionstring);
1461 if (strlcpy(kdh->versionstring, version, dstsize) >= dstsize)
1462 kdh->versionstring[dstsize - 2] = '\n';
1463 if (panicstr != NULL)
1464 strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
1465 if (di->kdcomp != NULL)
1309 * will catch us and cause the dump to fail.
1310 */
1311 dumpextent = di->mediasize - SIZEOF_METADATA -
1312 2 * di->blocksize - keysize;
1313 kdh->dumpextent = htod64(dumpextent);
1314 } else
1315 return (E2BIG);
1316 }

--- 153 unchanged lines hidden (view full) ---

1470 kdh->blocksize = htod32(di->blocksize);
1471 strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname));
1472 dstsize = sizeof(kdh->versionstring);
1473 if (strlcpy(kdh->versionstring, version, dstsize) >= dstsize)
1474 kdh->versionstring[dstsize - 2] = '\n';
1475 if (panicstr != NULL)
1476 strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring));
1477 if (di->kdcomp != NULL)
1466 kdh->compression = KERNELDUMP_COMP_GZIP;
1478 kdh->compression = di->kdcomp->kdc_format;
1467 kdh->parity = kerneldump_parity(kdh);
1468}
1469
1470#ifdef DDB
1471DB_SHOW_COMMAND(panic, db_show_panic)
1472{
1473
1474 if (panicstr == NULL)
1475 db_printf("panicstr not set\n");
1476 else
1477 db_printf("panic: %s\n", panicstr);
1478}
1479#endif
1479 kdh->parity = kerneldump_parity(kdh);
1480}
1481
1482#ifdef DDB
1483DB_SHOW_COMMAND(panic, db_show_panic)
1484{
1485
1486 if (panicstr == NULL)
1487 db_printf("panicstr not set\n");
1488 else
1489 db_printf("panic: %s\n", panicstr);
1490}
1491#endif