1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//! # Scorpio Filesystem Library
//!
//! Scorpio is a FUSE-based virtual filesystem that provides overlay capabilities
//! for monorepo builds. The library exposes the Antares subsystem for managing
//! union filesystems with copy-on-write semantics.
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use scorpiofs::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Initialize configuration
//! scorpio::util::config::init_config("scorpio.toml")?;
//!
//! // Create Antares service for managing mounts
//! let service = AntaresServiceImpl::new(None).await;
//!
//! // Create HTTP daemon
//! let daemon = AntaresDaemon::new(std::sync::Arc::new(service));
//!
//! // Or use AntaresManager for direct mount operations
//! let paths = AntaresPaths::from_global_config();
//! let manager = AntaresManager::new(paths).await;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Mounting an Antares Directory
//!
//! There are three ways to mount an Antares overlay filesystem:
//!
//! ### Method 1: Using AntaresManager with Default Paths
//!
//! ```rust,ignore
//! use scorpiofs::antares::{AntaresManager, AntaresPaths};
//! use std::path::PathBuf;
//!
//! #[tokio::main]
//! async fn main() -> std::io::Result<()> {
//! // Initialize configuration first
//! scorpio::util::config::init_config("scorpio.toml").unwrap();
//!
//! // Configure paths for layers
//! let paths = AntaresPaths::new(
//! PathBuf::from("/var/lib/antares/upper"), // upper layer root
//! PathBuf::from("/var/lib/antares/cl"), // CL layer root
//! PathBuf::from("/var/lib/antares/mounts"), // mountpoints root
//! PathBuf::from("/var/lib/antares/state.toml"), // state file
//! );
//!
//! // Create manager
//! let manager = AntaresManager::new(paths).await;
//!
//! // Mount a job instance (mountpoint auto-generated at {mount_root}/{job_id})
//! let config = manager.mount_job("build-job-123", Some("cl-456")).await?;
//! println!("Mounted at: {}", config.mountpoint.display());
//!
//! // ... do build work ...
//!
//! // Unmount when done
//! manager.umount_job("build-job-123").await?;
//!
//! Ok(())
//! }
//! ```
//!
//! ### Method 2: Using AntaresManager with Custom Mountpoint
//!
//! Mount to any arbitrary directory using `mount_job_at`:
//!
//! ```rust,ignore
//! use scorpiofs::antares::{AntaresManager, AntaresPaths};
//! use std::path::PathBuf;
//!
//! #[tokio::main]
//! async fn main() -> std::io::Result<()> {
//! scorpio::util::config::init_config("scorpio.toml").unwrap();
//!
//! let paths = AntaresPaths::from_global_config();
//! let manager = AntaresManager::new(paths).await;
//!
//! // Mount to a custom directory (any path you choose)
//! let config = manager.mount_job_at(
//! "my-build",
//! "/home/user/workspace/my-project", // custom mountpoint
//! None, // no CL layer
//! ).await?;
//!
//! println!("Mounted at: {}", config.mountpoint.display());
//! // Output: Mounted at: /home/user/workspace/my-project
//!
//! // Unmount when done
//! manager.umount_job("my-build").await?;
//!
//! Ok(())
//! }
//! ```
//!
//! ### Method 3: Using AntaresFuse Directly
//!
//! For lower-level control over the FUSE mount:
//!
//! ```rust,ignore
//! use scorpiofs::antares::fuse::AntaresFuse;
//! use scorpiofs::dicfuse::DicfuseManager;
//! use std::path::PathBuf;
//!
//! #[tokio::main]
//! async fn main() -> std::io::Result<()> {
//! // Initialize configuration
//! scorpio::util::config::init_config("scorpio.toml").unwrap();
//!
//! // Get shared Dicfuse instance (read-only base layer)
//! let dicfuse = DicfuseManager::global().await;
//!
//! // Create AntaresFuse with custom paths
//! let mut fuse = AntaresFuse::new(
//! PathBuf::from("/mnt/my-build"), // mountpoint
//! dicfuse, // read-only base layer
//! PathBuf::from("/tmp/upper"), // writable upper layer
//! Some(PathBuf::from("/tmp/cl")), // optional CL layer
//! ).await?;
//!
//! // Mount the filesystem (spawns background FUSE session)
//! fuse.mount().await?;
//! println!("Filesystem mounted at /mnt/my-build");
//!
//! // ... use the mounted filesystem ...
//!
//! // Unmount when done
//! fuse.unmount().await?;
//!
//! Ok(())
//! }
//! ```
//!
//! ### Method 4: Using HTTP Daemon
//!
//! For production deployments, use the HTTP daemon for centralized mount management:
//!
//! ```rust,ignore
//! use scorpiofs::daemon::antares::{AntaresDaemon, AntaresServiceImpl, CreateMountRequest};
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! scorpio::util::config::init_config("scorpio.toml")?;
//!
//! // Create service with mount recovery
//! let service = Arc::new(AntaresServiceImpl::new_with_recovery(None).await);
//!
//! // Start HTTP daemon
//! let daemon = AntaresDaemon::new(service);
//! let addr = "0.0.0.0:2726".parse()?;
//!
//! // Serve until shutdown signal
//! daemon.serve(addr).await?;
//!
//! Ok(())
//! }
//! ```
//!
//! Then use HTTP API to create mounts:
//! ```bash
//! curl -X POST http://localhost:2726/mounts \
//! -H "Content-Type: application/json" \
//! -d '{"job_id": "build-123", "path": "/third-party/mega"}'
//! ```
//!
//! ## Core Components
//!
//! - [`antares`]: Union filesystem overlay management
//! - [`daemon::antares`]: HTTP API daemon for mount lifecycle management
//! - [`dicfuse`]: Read-only dictionary-based FUSE layer
//! - [`util::config`]: Configuration management
extern crate log;
/// Commonly used types and traits for working with Antares.
///
/// This module re-exports the most frequently used types for convenience.
///
/// # Usage
///
/// ```rust,ignore
/// use scorpiofs::prelude::*;
/// ```
// Re-export key antares types at crate root for convenience
pub use ;
//const VFS_MAX_INO: u64 = 0xff_ffff_ffff_ffff;
const READONLY_INODE: u64 = 0xffff_ffff;