about summary refs log tree commit diff
path: root/tvix/store/src/fuse/file_attr.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-05-29T12·11+0300
committerflokli <flokli@flokli.de>2023-06-20T10·14+0000
commitb25d98a84e9830c3f800ca8c84d9df09d6b1296d (patch)
tree9f1240fdf3a349e735ad2c62d4e7e230ba12a97d /tvix/store/src/fuse/file_attr.rs
parent4516cd09c51b7a19707de0a5ba171c9592241a18 (diff)
feat(tvix/store/fuse): initial implementation r/6337
This is a first implementation of a FUSE filesystem, mounting tvix-store
to a given location.

This is mostly meant as one additional lens into a store, and could be
used for builds. It's not meant to be used as a general-purpose thing.

It still has some rough edges:

 - It doesn't implement open/close, so it doesn't use file handles.
   Which means, we need to open blobs for partial reads over and over
   again.
 - It doesn't implement seek, as BlobReader doesn't implement seek yet.
 - It doesn't track "lifetimes" of inodes by listening on forget,
   meaning it might hold more data in memory than necessary.
 - As we don't have store composition (and a caching layer) yet,
   operations might be slow.

Change-Id: Ib1812ed761dfaf6aeb548443ae939c87530b7be8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8667
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/store/src/fuse/file_attr.rs')
-rw-r--r--tvix/store/src/fuse/file_attr.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/tvix/store/src/fuse/file_attr.rs b/tvix/store/src/fuse/file_attr.rs
new file mode 100644
index 000000000000..b2b971d9e409
--- /dev/null
+++ b/tvix/store/src/fuse/file_attr.rs
@@ -0,0 +1,56 @@
+use std::time::SystemTime;
+
+use super::inodes::{DirectoryInodeData, InodeData};
+use fuser::FileAttr;
+
+/// The [FileAttr] describing the root
+pub const ROOT_FILE_ATTR: FileAttr = FileAttr {
+    ino: fuser::FUSE_ROOT_ID,
+    size: 0,
+    blksize: 1024,
+    blocks: 0,
+    atime: SystemTime::UNIX_EPOCH,
+    mtime: SystemTime::UNIX_EPOCH,
+    ctime: SystemTime::UNIX_EPOCH,
+    crtime: SystemTime::UNIX_EPOCH,
+    kind: fuser::FileType::Directory,
+    perm: 0o555,
+    nlink: 0,
+    uid: 0,
+    gid: 0,
+    rdev: 0,
+    flags: 0,
+};
+
+/// for given &Node and inode, construct a [FileAttr]
+pub fn gen_file_attr(inode_data: &InodeData, inode: u64) -> FileAttr {
+    FileAttr {
+        ino: inode,
+        size: match inode_data {
+            InodeData::Regular(_, size, _) => *size as u64,
+            InodeData::Symlink(target) => target.len() as u64,
+            InodeData::Directory(DirectoryInodeData::Sparse(_, size)) => *size as u64,
+            InodeData::Directory(DirectoryInodeData::Populated(_, ref children)) => {
+                children.len() as u64
+            }
+        },
+        // FUTUREWORK: play with this numbers, as it affects read sizes for client applications.
+        blksize: 1024,
+        blocks: 0,
+        atime: SystemTime::UNIX_EPOCH,
+        mtime: SystemTime::UNIX_EPOCH,
+        ctime: SystemTime::UNIX_EPOCH,
+        crtime: SystemTime::UNIX_EPOCH,
+        kind: inode_data.into(),
+        perm: match inode_data {
+            InodeData::Regular(..) => 0o444,
+            InodeData::Symlink(_) => 0o444,
+            InodeData::Directory(..) => 0o555,
+        },
+        nlink: 0,
+        uid: 0,
+        gid: 0,
+        rdev: 0,
+        flags: 0,
+    }
+}