eminence / eminence/procfs

API for deleted files / raw FD

Open
#317 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
445
Forks
134
PR merge metrics
No merged PRs in 30d

Description

Hi,

If a file is deleted while still opened by a process, the fd under `/proc/$pid/fd/$fd` will show up as

```console
[tatref@srv dev]$ ls -ld /proc/12779/fd/*
lr-x------ 1 tatref tatref 64 Oct 16 01:00 /proc/12779/fd/4 -> '/home/tatref/dev/tes (deleted)'
```

We can get that info with

```rust
use std::fs::File;
use std::fs::Metadata;
use std::os::unix::fs::MetadataExt;

let f = File::open(&format!("/proc/{}/fd/{}", p.pid, fd.fd)).unwrap();
let metadata = f.metadata().unwrap();

if metadata.nlink() == 0 {}
```

So this means format a String, open a file, and do a syscall to get metadata.

Currently it seems there is no easier API in `procfs` to access this information (please correct me if I'm wrong).
`FDTarget` has a `Path` variant, but there is no guarantee that another file with the same name hasn't be created.

Maybe we could store a `File` in the `FDInfo`, and add it where it is created:

https://github.com/eminence/procfs/blob/e303757cd3e21c763e339f6f7e4c9cb4e435ff83/procfs/src/process/mod.rs#L149-L175

What do you think?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.