From 0f3f8eb016b2dbd94ef609cdc09eaf2e22132e75 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Mon, 13 Oct 2025 19:35:30 +0100 Subject: [PATCH] add tid --- src/fs.rs | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 351db72..a9a1524 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -1,4 +1,4 @@ -use std::time; +use std::time::{self, SystemTime, UNIX_EPOCH, Duration}; use atrium_repo::{Repository, blockstore::AsyncBlockStoreRead}; use futures::StreamExt; @@ -6,6 +6,27 @@ use indexmap::{IndexMap, IndexSet}; type Inode = usize; +/// Decode a TID (timestamp identifier) to get the timestamp in microseconds since Unix epoch +fn tid_to_timestamp(tid: &str) -> Option { + const S32_CHAR: &[u8] = b"234567abcdefghijklmnopqrstuvwxyz"; + + if tid.len() != 13 { + return None; + } + + let mut value: u64 = 0; + for ch in tid.chars() { + let pos = S32_CHAR.iter().position(|&c| c as char == ch)?; + // Big-endian: first character is most significant + value = (value << 5) | (pos as u64); + } + + // Extract timestamp from upper bits (shifted by 10) + let micros = value >> 10; + + UNIX_EPOCH.checked_add(Duration::from_micros(micros)) +} + pub struct PdsFs { repos: IndexMap>, inodes: IndexSet, @@ -172,14 +193,18 @@ where .map_or(0, |v| serde_json::to_string(&v).unwrap().len()) as u64; let blocks = ((size as u32 + BLKSIZE - 1) / BLKSIZE) as u64; + + // Decode TID to get creation timestamp + let timestamp = tid_to_timestamp(&r.rkey).unwrap_or(time::UNIX_EPOCH); + fuser::FileAttr { ino, size, blocks, - atime: time::UNIX_EPOCH, - mtime: time::UNIX_EPOCH, - ctime: time::UNIX_EPOCH, - crtime: time::UNIX_EPOCH, + atime: timestamp, + mtime: timestamp, + ctime: timestamp, + crtime: timestamp, kind: fuser::FileType::RegularFile, perm: 0o644, nlink: 1, -- 2.43.0