fs/xfs/scrub/symlink_repair.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/symlink_repair.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/symlink_repair.c- Extension
.c- Size
- 13981 bytes
- Lines
- 511
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
xfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_trans_resv.hxfs_mount.hxfs_defer.hxfs_btree.hxfs_bit.hxfs_log_format.hxfs_trans.hxfs_sb.hxfs_inode.hxfs_inode_fork.hxfs_symlink.hxfs_bmap.hxfs_quota.hxfs_da_format.hxfs_da_btree.hxfs_bmap_btree.hxfs_trans_space.hxfs_symlink_remote.hxfs_exchmaps.hxfs_exchrange.hxfs_health.hscrub/xfs_scrub.hscrub/scrub.hscrub/common.hscrub/trace.hscrub/repair.hscrub/tempfile.hscrub/tempexch.h
Detected Declarations
function Copyrightfunction xrep_symlink_salvage_remotefunction xrep_symlink_salvage_inlinefunction xrep_symlink_salvagefunction xrep_symlink_local_to_remotefunction xrep_symlink_swap_prepfunction xrep_symlink_swapfunction xrep_symlink_reset_forkfunction xrep_symlink_rebuildfunction xrep_symlink
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2018-2024 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <djwong@kernel.org>
*/
#include "xfs_platform.h"
#include "xfs_fs.h"
#include "xfs_shared.h"
#include "xfs_format.h"
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
#include "xfs_defer.h"
#include "xfs_btree.h"
#include "xfs_bit.h"
#include "xfs_log_format.h"
#include "xfs_trans.h"
#include "xfs_sb.h"
#include "xfs_inode.h"
#include "xfs_inode_fork.h"
#include "xfs_symlink.h"
#include "xfs_bmap.h"
#include "xfs_quota.h"
#include "xfs_da_format.h"
#include "xfs_da_btree.h"
#include "xfs_bmap_btree.h"
#include "xfs_trans_space.h"
#include "xfs_symlink_remote.h"
#include "xfs_exchmaps.h"
#include "xfs_exchrange.h"
#include "xfs_health.h"
#include "scrub/xfs_scrub.h"
#include "scrub/scrub.h"
#include "scrub/common.h"
#include "scrub/trace.h"
#include "scrub/repair.h"
#include "scrub/tempfile.h"
#include "scrub/tempexch.h"
#include "scrub/reap.h"
#include "scrub/health.h"
/*
* Symbolic Link Repair
* ====================
*
* We repair symbolic links by reading whatever target data we can find, up to
* the first NULL byte. If the recovered target strlen matches i_size, then
* we rewrite the target. In all other cases, we replace the target with an
* overly long string that cannot possibly resolve. The new target is written
* into a private hidden temporary file, and then a file contents exchange
* commits the new symlink target to the file being repaired.
*/
/* Set us up to repair the symlink file. */
int
xrep_setup_symlink(
struct xfs_scrub *sc,
unsigned int *resblks)
{
struct xfs_mount *mp = sc->mp;
unsigned long long blocks;
int error;
error = xrep_tempfile_create(sc, S_IFLNK);
if (error)
return error;
/*
* If we're doing a repair, we reserve enough blocks to write out a
* completely new symlink file, plus twice as many blocks as we would
* need if we can only allocate one block per data fork mapping. This
* should cover the preallocation of the temporary file and exchanging
* the extent mappings.
*
* We cannot use xfs_exchmaps_estimate because we have not yet
* constructed the replacement symlink and therefore do not know how
* many extents it will use. By the time we do, we will have a dirty
* transaction (which we cannot drop because we cannot drop the
* symlink ILOCK) and cannot ask for more reservation.
*/
blocks = xfs_symlink_blocks(sc->mp, XFS_SYMLINK_MAXLEN);
blocks += xfs_bmbt_calc_size(mp, blocks) * 2;
if (blocks > UINT_MAX)
return -EOPNOTSUPP;
*resblks += blocks;
return 0;
}
/*
* Try to salvage the pathname from remote blocks. Returns the number of bytes
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_defer.h`, `xfs_btree.h`.
- Detected declarations: `function Copyright`, `function xrep_symlink_salvage_remote`, `function xrep_symlink_salvage_inline`, `function xrep_symlink_salvage`, `function xrep_symlink_local_to_remote`, `function xrep_symlink_swap_prep`, `function xrep_symlink_swap`, `function xrep_symlink_reset_fork`, `function xrep_symlink_rebuild`, `function xrep_symlink`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.