MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / open

Method open

kernel/src/vfs.rs:57–87  ·  view source on GitHub ↗

Open a path, returning a handle to read/write and the length of the string matched.

(&self,
                path: &str)

Source from the content-addressed store, hash-verified

55 /// Open a path, returning a handle to read/write and the
56 /// length of the string matched.
57 pub fn open(&self,
58 path: &str) -> Option<(Arc<RwLock<Rendezvous>>, usize)> {
59 let mounts = self.0.read();
60 let mut found: Option<(usize, usize)> = None;
61 for (i, mount_path) in mounts.iter().enumerate() {
62 if path.starts_with(&mount_path.0) {
63 let len = mount_path.0.len();
64 if path.len() > len {
65 // The path should be a subdirectory
66 // - the next character in path should be "/"
67 // Note: str.len() is bytes, not characters
68 if path.as_bytes()[len] != b'/' {
69 // Not this path
70 continue;
71 }
72 }
73 // Choose the longest match
74 if let Some((_, maxlen)) = found {
75 if len > maxlen {
76 found = Some((i, len));
77 }
78 } else {
79 found = Some((i, len));
80 }
81 }
82 }
83 if let Some((ind, match_len)) = found {
84 return Some((mounts[ind].1.clone(), match_len));
85 }
86 None
87 }
88
89 /// Return a list of mount points as a JSON string
90 pub fn to_json(&self) -> String {

Callers 2

mainFunction · 0.45
open_pathFunction · 0.45

Calls 4

iterMethod · 0.80
cloneMethod · 0.80
readMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected