Repository navigation
Commit 2dbff17
committed
lib: Add LCFS_BUILD_TRACK_HARDLINKS for directory scans
lcfs_build() walks a directory tree via readdir()/fstatat() and never
looks at st_ino/st_dev, so two paths that are hardlinked to the same
inode on disk silently become two independent inodes with nlink=1 in
the composefs image. This causes fs-verity digest mismatches against
hardlink-aware tools and a mounted image that misreports nlink/size
(composefs#444).
Add an opt-in LCFS_BUILD_TRACK_HARDLINKS flag that keeps a (dev,ino)
-> node hash table alive for the whole recursive walk (a link's two
names can be anywhere under the root, not just siblings) and, on a
repeat inode, wires up a hardlink via the existing
lcfs_node_make_hardlink() instead of re-reading the file content.
This is opt-in and not the default, matching composefs-rs's own
mkcomposefs-compatible implementation, which requires the same
--hardlinks flag to enable deduplication. Directories from
scanning a real filesystem today rely on every path becoming an
independent inode, and changing that by default would change digests
for existing consumers (RHEL9, ostree, etc.) that build composefs
images from directories.
Tracking is also unconditional on st_nlink, i.e. it doesn't skip
looking up a file just because its st_nlink report is 1: some
filesystems (e.g. fuse-overlayfs, see
containers/fuse-overlayfs#435) can misreport that field.
Every non-directory type is tracked (regular files, symlinks, FIFOs,
device nodes, sockets), since all of them are hardlinkable on disk
(e.g. via `ln -P`) and composefs-rs's own scanner doesn't special-case
regular files either. The one deliberate exception is a chardev with
rdev=0: composefs represents an overlayfs whiteout this way, and the
EROFS writer already rejects such an inode outright if it ends up
with nlink>1 (a whiteout marks the absence of a file, so hardlinking
two of them together is semantically invalid) -- but only when
*loading* an image, not when writing one. Leave those untracked so a
directory scan can't silently produce an image composefs itself would
refuse to read back.
Assisted-by: AI
Signed-off-by: Colin Walters <walters@verbum.org>1 parent 379f8ab commit 2dbff17
2 files changed
Lines changed: 128 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
786 | 786 | | |
787 | 787 | | |
788 | 788 | | |
789 | | - | |
| 789 | + | |
790 | 790 | | |
791 | 791 | | |
792 | 792 | | |
| |||
1504 | 1504 | | |
1505 | 1505 | | |
1506 | 1506 | | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1507 | 1531 | | |
1508 | 1532 | | |
1509 | 1533 | | |
1510 | 1534 | | |
1511 | 1535 | | |
1512 | 1536 | | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
1513 | 1542 | | |
1514 | 1543 | | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
1515 | 1618 | | |
1516 | 1619 | | |
1517 | 1620 | | |
| |||
1525 | 1628 | | |
1526 | 1629 | | |
1527 | 1630 | | |
1528 | | - | |
| 1631 | + | |
1529 | 1632 | | |
1530 | 1633 | | |
1531 | 1634 | | |
| |||
1595 | 1698 | | |
1596 | 1699 | | |
1597 | 1700 | | |
1598 | | - | |
| 1701 | + | |
1599 | 1702 | | |
1600 | 1703 | | |
1601 | 1704 | | |
| |||
1633 | 1736 | | |
1634 | 1737 | | |
1635 | 1738 | | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
1636 | 1750 | | |
1637 | | - | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1638 | 1760 | | |
1639 | 1761 | | |
1640 | 1762 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
0 commit comments