Skip to content

Commit 13ec07f

Browse files
committed
unpfs: don't panic when an invalid fid given
1 parent a3bd278 commit 13ec07f

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

example/unpfs/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Filesystem for Unpfs {
149149
}
150150

151151
fn rread(&mut self, fid: &mut Fid<Self::Fid>, offset: u64, count: u32) -> Result<Fcall> {
152-
let file = fid.aux_mut().file.as_mut().unwrap();
152+
let file = fid.aux_mut().file.as_mut().ok_or(INVALID_FID!())?;
153153
file.seek(SeekFrom::Start(offset))?;
154154

155155
let mut buf = create_buffer(count as usize);
@@ -160,7 +160,7 @@ impl Filesystem for Unpfs {
160160
}
161161

162162
fn rwrite(&mut self, fid: &mut Fid<Self::Fid>, offset: u64, data: &Data) -> Result<Fcall> {
163-
let file = fid.aux_mut().file.as_mut().unwrap();
163+
let file = fid.aux_mut().file.as_mut().ok_or(INVALID_FID!())?;
164164
file.seek(SeekFrom::Start(offset))?;
165165
Ok(Fcall::Rwrite { count: file.write(&data.0)? as u32 })
166166
}
@@ -188,7 +188,7 @@ impl Filesystem for Unpfs {
188188
}
189189

190190
fn rfsync(&mut self, fid: &mut Fid<Self::Fid>) -> Result<Fcall> {
191-
fid.aux_mut().file.as_mut().unwrap().sync_all()?;
191+
fid.aux_mut().file.as_mut().ok_or(INVALID_FID!())?.sync_all()?;
192192
Ok(Fcall::Rfsync)
193193
}
194194

example/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ macro_rules! res { ($err:expr) => { Err(From::from($err)) } }
1111
macro_rules! io_err { ($kind:ident, $msg:expr) => {
1212
::std::io::Error::new(::std::io::ErrorKind::$kind, $msg)
1313
}}
14+
macro_rules! INVALID_FID { () => (io_err!(InvalidInput, "Invalid fid")) }
1415

1516
pub fn create_buffer(size: usize) -> Vec<u8> {
1617
let mut buffer = Vec::with_capacity(size);

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
//! Filesystems library using 9P2000.L protocol, a extended variant of 9P from the Plan 9.
2+
//! Filesystems library using 9P2000.L protocol, an extended variant of 9P from the Plan 9.
33
//!
44
//! 9P protocol is originally developed for Plan 9 distributed OS.
55
//! As it's extendable and suitable for filesystems 9P is ported to Linux.
66
//! However, 9P protocol lacks Linux or unix specific features,
77
//! which is the problem for developing serious filesystems.
88
//!
9-
//! 9P2000.L is a extended protocol of 9P for Linux.
9+
//! 9P2000.L is an extended variant protocol of 9P for Linux.
1010
//! It has Linux specific features and is supported by Linux kernel 9P module.
1111
//!
1212
//! rs9p is a library to develop 9P2000.L virtual filesystems in Rust.

0 commit comments

Comments
 (0)