Skip to main content

hyprstream_core/services/
types.rs

1//! Service layer constants and 9P protocol types.
2
3// ─────────────────────────────────────────────────────────────────────────────
4// Resource limits
5// ─────────────────────────────────────────────────────────────────────────────
6
7/// Default iounit for 9P read/write operations (64 KiB).
8/// This is the maximum bytes per single read/write message.
9/// Clients must loop to transfer files larger than this.
10pub const DEFAULT_IOUNIT: u32 = 64 * 1024;
11
12/// Maximum allowed iounit (16 MiB). Server will never return an iounit
13/// larger than this, regardless of what the client requests.
14pub const MAX_IOUNIT: u32 = 16 * 1024 * 1024;
15
16/// Maximum open fids per client.
17pub const MAX_FIDS_PER_CLIENT: u32 = 64;
18
19/// Maximum open fids globally.
20pub const MAX_FIDS_GLOBAL: u32 = 4096;
21
22// Legacy aliases (used in existing code)
23pub const MAX_FS_IO_SIZE: u64 = MAX_IOUNIT as u64;
24pub const MAX_FDS_PER_CLIENT: u32 = MAX_FIDS_PER_CLIENT;
25pub const MAX_FDS_GLOBAL: u32 = MAX_FIDS_GLOBAL;
26
27// ─────────────────────────────────────────────────────────────────────────────
28// 9P Qid types (file type bits in Qid.type)
29// ─────────────────────────────────────────────────────────────────────────────
30
31/// Directory
32pub const QTDIR: u8 = 0x80;
33/// Append-only file
34#[allow(dead_code)]
35pub const QTAPPEND: u8 = 0x40;
36/// Exclusive-use file
37#[allow(dead_code)]
38pub const QTEXCL: u8 = 0x20;
39/// Regular file
40pub const QTFILE: u8 = 0x00;
41
42// ─────────────────────────────────────────────────────────────────────────────
43// 9P open modes (NpOpen.mode / NpCreate.mode)
44// ─────────────────────────────────────────────────────────────────────────────
45
46/// Open for reading
47pub const OREAD: u8 = 0;
48/// Open for writing
49pub const OWRITE: u8 = 1;
50/// Open for read+write
51pub const ORDWR: u8 = 2;
52/// Truncate on open (OR'd with above)
53pub const OTRUNC: u8 = 0x10;
54/// Remove on clunk (OR'd with above)
55pub const ORCLOSE: u8 = 0x40;
56
57// ─────────────────────────────────────────────────────────────────────────────
58// 9P permission bits (NpCreate.perm)
59// ─────────────────────────────────────────────────────────────────────────────
60
61/// Directory flag in perm field
62pub const DMDIR: u32 = 0x80000000;
63
64// ─────────────────────────────────────────────────────────────────────────────
65// Directory entry info (not generated by codegen — standalone type)
66// ─────────────────────────────────────────────────────────────────────────────
67
68/// Directory entry returned by list_dir operations.
69#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
70pub struct FsDirEntryInfo {
71    pub name: String,
72    pub is_dir: bool,
73    pub size: u64,
74}
75
76impl From<hyprstream_vfs::DirEntry> for FsDirEntryInfo {
77    fn from(e: hyprstream_vfs::DirEntry) -> Self {
78        Self {
79            name: e.name,
80            is_dir: e.is_dir,
81            size: e.size,
82        }
83    }
84}