# dm-linear Reversal Example: Arithmetic Audit

## Finding

The pinned Linux v6.12 tutorial removes one extra complete chunk when its
input size has a partial tail. Native Perl evaluation produces one mapping-loop
iteration for 8192 sectors but zero for 8193. For 16384 and 16385 sectors it
produces two and one. A chunk is 8192 address sectors of 512 bytes, or 4 MiB.

This is a documentation-example observation, not a kernel-driver defect,
vulnerability, hardware measurement or execution of the full tutorial.

## Evidence And Method

Twelve deliberately selected sizes cover exact multiples, partial tails and
inputs shorter than one chunk. observations.json is the unchanged original
Perl 5.38.2 receipt; model.py evaluates only a fixed arithmetic expression and
compares it with a separate Python integer oracle. The source hash is verified
before arithmetic execution. Source text is never evaluated as code.

The count is floor(S/E) minus one when a remainder exists. The loop runs the
maximum of that result and zero. Retaining all complete chunks would instead
use floor(S/E). This arithmetic comparison does not constitute a safe migration
script or establish whether dmsetup accepts an empty table.

Files: [observations](observations.json), [probe](model.py),
[tests](test_model.py), [original retrieval receipt](source.json).

## Reproduce Safely

Retrieve the original document from its immutable source revision:
https://raw.githubusercontent.com/torvalds/linux/adc218676eef25575469234709c2d87185ca223a/Documentation/admin-guide/device-mapper/linear.rst

Expected SHA-256:
ec3ef874783f6a2201c15cd481c5e78b3abe356baf0db61652052ce2783cb66b

With Python 3 and Perl 5.38.2, in a directory containing the five files:

```sh
python3 -B model.py linear-v6.12.rst --check observations.json
python3 -B -m unittest -v test_model.py
python3 -B -O -m unittest -v test_model.py
```

The exact receipt check includes the Perl version. A different version can
therefore fail exact equality even with identical arithmetic; inspect a fresh
probe result separately instead of overwriting the original observation.
No blockdev, dmsetup, mount or raw-device command is run by these checks.
Do not execute the upstream tutorial against valuable storage.

## Provenance And Limits

Original research commit: 57ad1168798d2aca3e5215202e9ed56729b34c2d.
The source receipt records retrieval on 2026-11-30; the source was independently
hash-checked and the twelve cases replayed during review. Publication replay on
2026-11-30 again matched the original receipt in normal and optimized Python.
An attempted new project-host download returned HTTP 429; this replay used the
retained, digest-verified source, not a claimed new successful retrieval.

All cases are designed arithmetic controls, not a probability sample. We did
not measure latency, capacity of a real device, kernel table acceptance, or
extreme Perl integer/floating-point boundaries. No failure rate or confidence
interval follows from these cases. Original source documentation is linked,
not bundled. No upstream correction or new-version verification is claimed.

## Context

Bhadkamkar et al., BORG: Block-reORGanization for Self-optimizing Storage Systems,
FAST 2009, sections 4.4, 5.1-5.3 and 6, separately describes data movement and
indirection-map maintenance. Its historical prototype is not this tutorial
and was not reproduced here.

Read the human interpretation:
https://hesela.com/analyses/sparse-files-preallocation-thin-capacity/#dm-reversal
Canonical concept: https://hesela.dev/terms/device-mapper/
