Tuesday | 05 NOV 2024
[ previous ]
[ next ]

Rust, Fuse, Sqlite - 1 getattr

Title:
Date: 2023-02-07
Tags:  

The simplest possible code to get something going. This has no dependencies besides the crates fuser and rusqlite and the C libraries for fuse and sqlite.

C libraries:

sudo yum install fuse-devel
sudo yum install sqlite-devel

Cargo.toml

[dependencies]
fuser = "0.7"
rusqlite = "0.28.0"

This is just documentation for myself, I'm going to follow my C tutorial and hopefully get something working. The first step is to just see my mount folder, dir, with the correct permissions.

use std::time::{Duration, UNIX_EPOCH};
use fuser::{
    FileAttr, FileType, Filesystem, ReplyAttr, Request,
};

struct RFS;

const TTL: Duration = Duration::from_secs(1);

const DEFAULT_DIR_ATTR: FileAttr = FileAttr {
    ino: 1,
    size: 4096,
    blocks: 0,
    atime: UNIX_EPOCH,
    mtime: UNIX_EPOCH,
    ctime: UNIX_EPOCH,
    crtime: UNIX_EPOCH,
    kind: FileType::Directory,
    perm: 0o755,
    nlink: 2,
    uid: 1000,
    gid: 1000,
    rdev: 0,
    flags: 0,
    blksize: 512,
    padding: 0,
};

impl Filesystem for RFS {
    fn getattr(&mut self, _req: &Request, _ino: u64, reply: ReplyAttr) {
        reply.attr(&TTL, &DEFAULT_DIR_ATTR);
    }
}

fn main() {
    let mountpoint = "dir";
    let options = vec![];
    fuser::mount2(RFS, mountpoint, &options).unwrap();
}

You can use cargo run and this will compile and mount the directory. For now it is mounting nothing.

fusermount -u /home/nivethan/bp/rfs/dir

This command will clean up the mount as ctrl c doesn't clean everything up.

The output of doing ls -l after the folder is mounted.

ls -l 
drwxr-xr-x 2 nivethan nivethan 4.0K Dec 31  1969 dir/