| 1357 | } |
| 1358 | |
| 1359 | static int |
| 1360 | dump_check_bounds(struct dumperinfo *di, off_t offset, size_t length) |
| 1361 | { |
| 1362 | |
| 1363 | if (di->mediasize > 0 && length != 0 && (offset < di->mediaoffset || |
| 1364 | offset - di->mediaoffset + length > di->mediasize)) { |
| 1365 | if (di->kdcomp != NULL && offset >= di->mediaoffset) { |
| 1366 | printf( |
| 1367 | "Compressed dump failed to fit in device boundaries.\n"); |
| 1368 | return (E2BIG); |
| 1369 | } |
| 1370 | |
| 1371 | printf("Attempt to write outside dump device boundaries.\n" |
| 1372 | "offset(%jd), mediaoffset(%jd), length(%ju), mediasize(%jd).\n", |
| 1373 | (intmax_t)offset, (intmax_t)di->mediaoffset, |
| 1374 | (uintmax_t)length, (intmax_t)di->mediasize); |
| 1375 | return (ENOSPC); |
| 1376 | } |
| 1377 | if (length % di->blocksize != 0) { |
| 1378 | printf("Attempt to write partial block of length %ju.\n", |
| 1379 | (uintmax_t)length); |
| 1380 | return (EINVAL); |
| 1381 | } |
| 1382 | if (offset % di->blocksize != 0) { |
| 1383 | printf("Attempt to write at unaligned offset %jd.\n", |
| 1384 | (intmax_t)offset); |
| 1385 | return (EINVAL); |
| 1386 | } |
| 1387 | |
| 1388 | return (0); |
| 1389 | } |
| 1390 | |
| 1391 | #ifdef EKCD |
| 1392 | static int |