Git Product home page Git Product logo

rust-fs-tutorial's Introduction

Rust fs module and filesystem tutorial

Rust standard library has a rich set of abstractions for multiplatform file and directory operations. This tutorial shows the basics of how files are managed by Unix/Linux systems, and how to use Rust APIs to work with files, directories, paths and links.

  • Files

Files are just an amount of bytes. They can be a text, video, audio, image, or any other digital information. Is the application that does the interpretation of the file and its contents. There is a Unix/Linux philosophy that every system resource is a file.

  1. Regular files - We use to store binary or text data.
  2. Directories - Files wich contains references to other files.
  3. Block device files - Hard disks, tape drives, USB cameras.
  4. Character device files - A terminal, a keyboard, a printer, a sound card.
  5. Named pipes - In-memory inter-process communication machanism.
  6. Unix domain sockets - Is a form of inter-process communication.
  7. Links - Hard links and symbolic links.

All resources above are files.

  • System Calls

Is a programmatic way in which a computer program requests a service from the kernel of the operation system on which it is executed. The same system calls used to open, read, write and close regular files can also be used in any other type of files such as block devices, links.

  • File Descriptors

A file descriptor is a handle to a file. Opening a file returns a descriptor, and other operations such as reading, writing and closing use the file descriptor. File operations are performed by processes. A process perform this operations by invoking system calls on the kernel. Eche process has a limit on the number of files it can open.

  • Examples
  1. File Operations
  2. Directory Operations
  3. Link Operations
  4. The rstat tool
  • Test rstat tool
$ cargo test
  • Build rstat tool

The rstat is a tool that extracts information about rust source code. It uses all APIs from all examples.

$ cargo build --bin rstat
  • Run rstat
$ cargo run --bin rstat -- -m src src
$ Summary stats: SrcStats { number_of_files: 6, number_of_lines: 323, loc: 277, comments: 3, blanks: 43 }
  • Build all examples and tools
$ cargo build

References

  1. System calls
  2. Practical System Programming for Rust Developers

rust-fs-tutorial's People

Contributors

jgardona avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

jgardona

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.