Giter Club home page Giter Club logo

refind's Introduction

refind

Crates License

Keep track of files even after they're renamed or moved.

Introduction

refind is cross platform Rust crate for locating file by it's ID.

Keep track of files even after they're renamed or moved.

Supported platforms

Windows and macOS, with limited functionality on Linux.

Install

cargo add refind

Usage

Create file ID

fn main() {
    let id = refind::get_id("<path>".into()).unwrap();
    println!("ID: {}", id);
}

Find path from ID

fn main() {
    let realpath = refind::find_path("<id">).unwrap();
    println!("Path: {}", realpath.display());
}

Examples

See examples

ID format

In Windows, the ID consists of a string representation of an unsigned 64-bit integer, e.g., 111111111111111.

In macOS, it's the device ID combined with the inode using a : separator, e.g., 111111111:2222222222.

How it works

macOS

macOS has a special directory, .vol, allowing file access via device number and file inode. It also retrieves file paths from descriptors.

refind library creates a file ID with device ID and inode from stat, facilitating path retrieval via .vol. Finally, it uses fcntl with F_GETPATH for realpath. see more Here.

To demonstrate, stat <path>, copy device ID and inode, then use

GetFileInfo /.vol/{device id}/{file inode}

Windows

Windows defines unique identifier for files and provide a way to get it via GetFileInformationByHandle

Later refind uses OpenFileById to open it by the ID, and uses GetFileInformationByHandleEx with FILE_INFO_BY_HANDLE_CLASS to get it's path.

To demonstrate, you can get file id with

fsutil file queryFileid <path>

And to get it's path from the ID you can use

fsutil file queryFileNamebyid <volume> fileID

See microsoft/extendedfileapis

Linux

Linux resorts to a naive approach by traversing the filesystem from the home folder downwards, comparing file IDs. While relatively fast, it lacks the efficiency of macOS and Windows methods. see stackoverflow.com/questions/1406679/

refind's People

Contributors

thewh1teagle avatar

Stargazers

Shujaat Ali Khan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.