Skip to main content

link_count

Function link_count 

Source
pub fn link_count(path: &Path) -> Result<u32, Error>
Expand description

Get the link count for a file.

Returns the number of hard links pointing to the file. A regular file without hardlinks has a link count of 1. A link count > 1 indicates the file has hard links.

§Fail-Closed Behavior

If the link count cannot be determined (e.g., permission denied, file cannot be opened), this function returns Err. Callers should treat errors as potential hardlinks for security (fail closed).

§Platform Behavior

  • Unix: Uses metadata.nlink() via MetadataExt
  • Windows: Uses GetFileInformationByHandle Win32 API to get nNumberOfLinks

§Arguments

  • path - The path to check. Must be a regular file (not a directory).

§Returns

  • Ok(n) - The file has n hard links
  • Err(e) - Could not determine link count (treat as potential hardlink)