diff --git a/Cargo.lock b/Cargo.lock index 01338f4..645f3e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -184,6 +184,15 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "env_logger" version = "0.8.4" @@ -472,6 +481,7 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" name = "lws_vfs" version = "0.1.0" dependencies = [ + "encoding_rs", "env_logger", "libc", "log", diff --git a/src/lib.rs b/src/lib.rs index 4a370a9..05a11e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -176,8 +176,8 @@ impl LwsVfs for LwsVfsIns { let mut fi = FileInfo::default(); let reply = match self.fs.fgetattr(path, &mut fstat, &mut fi) { Ok(0) => GetattrResponse { stat: Some(fstat), status: ok_status() }, - Ok(_) => GetattrResponse { stat: None, status: err_status(FsOp::FSOP_GETATTR, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => GetattrResponse { stat: None, status: err_status(FsOp::FSOP_GETATTR, vec![path.to_string()], &*e) }, + Ok(_) => GetattrResponse { stat: None, status: err_status(FsOp::FsopGetattr, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => GetattrResponse { stat: None, status: err_status(FsOp::FsopGetattr, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -188,8 +188,8 @@ impl LwsVfs for LwsVfsIns { let mut fi = FileInfo::default(); let reply = match self.fs.fopen(path, &mut fi) { Ok(0) => OpenResponse{ fi: Some(fi), status: ok_status() }, - Ok(_) => OpenResponse{ fi: None, status: err_status(FsOp::FSOP_OPEN, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => OpenResponse{ fi: None, status: err_status(FsOp::FSOP_OPEN, vec![path.to_string()], &*e) }, + Ok(_) => OpenResponse{ fi: None, status: err_status(FsOp::FsopOpen, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => OpenResponse{ fi: None, status: err_status(FsOp::FsopOpen, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -203,8 +203,8 @@ impl LwsVfs for LwsVfsIns { let mut buff: Vec = vec![0; size]; let reply = match self.fs.fread(path, &mut buff, &mut size, offset, &mut fi) { Ok(0) => ReadResponse { data: buff, status: ok_status() }, - Ok(_) => ReadResponse { data: Vec::new(), status: err_status(FsOp::FSOP_READ, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => ReadResponse { data: Vec::new(), status: err_status(FsOp::FSOP_READ, vec![path.to_string()], &*e) }, + Ok(_) => ReadResponse { data: Vec::new(), status: err_status(FsOp::FsopRead, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => ReadResponse { data: Vec::new(), status: err_status(FsOp::FsopRead, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -218,8 +218,8 @@ impl LwsVfs for LwsVfsIns { let offset = request.offset as usize; let reply = match self.fs.fwrite(path, &buff, &mut size, offset, &mut fi) { Ok(0) => WriteResponse { written: size as u64, status: ok_status() }, - Ok(_) => WriteResponse { written: 0, status: err_status(FsOp::FSOP_WRITE, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => WriteResponse { written: 0, status: err_status(FsOp::FSOP_WRITE, vec![path.to_string()], &*e) }, + Ok(_) => WriteResponse { written: 0, status: err_status(FsOp::FsopWrite, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => WriteResponse { written: 0, status: err_status(FsOp::FsopWrite, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -230,8 +230,8 @@ impl LwsVfs for LwsVfsIns { let mask = request.mask; let reply = match self.fs.faccess(path, mask) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_ACCESS, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_ACCESS, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopAccess, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopAccess, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -245,8 +245,8 @@ impl LwsVfs for LwsVfsIns { let flags = request.flags; let reply = match self.fs.fsetxattr(path, name, &value, size, flags) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_SETXATTR, vec![path.to_string()], &std::io::Error::from_raw_os_error(libc::ENOSYS)) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_SETXATTR, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopSetxattr, vec![path.to_string()], &std::io::Error::from_raw_os_error(libc::ENOSYS)) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopSetxattr, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -258,8 +258,8 @@ impl LwsVfs for LwsVfsIns { let size = request.size as usize; let reply = match self.fs.fgetxattr(path, name, size) { Ok(0) => GetxattrResponse { value: Vec::new(), status: ok_status() }, - Ok(_) => GetxattrResponse { value: Vec::new(), status: err_status(FsOp::FSOP_GETXATTR, vec![path.to_string()], &std::io::Error::from_raw_os_error(libc::ENOSYS)) }, - Err(e) => GetxattrResponse { value: Vec::new(), status: err_status(FsOp::FSOP_GETXATTR, vec![path.to_string()], &*e) }, + Ok(_) => GetxattrResponse { value: Vec::new(), status: err_status(FsOp::FsopGetxattr, vec![path.to_string()], &std::io::Error::from_raw_os_error(libc::ENOSYS)) }, + Err(e) => GetxattrResponse { value: Vec::new(), status: err_status(FsOp::FsopGetxattr, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -273,8 +273,8 @@ impl LwsVfs for LwsVfsIns { let size = 0; let reply = match self.fs.freaddir(path, &mut dirs, size, offset, &mut fi) { Ok(0) => ReaddirResponse { dirs, status: ok_status() }, - Ok(_) => ReaddirResponse { dirs: vec![], status: err_status(FsOp::FSOP_READDIR, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => ReaddirResponse { dirs: vec![], status: err_status(FsOp::FSOP_READDIR, vec![path.to_string()], &*e) }, + Ok(_) => ReaddirResponse { dirs: vec![], status: err_status(FsOp::FsopReaddir, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => ReaddirResponse { dirs: vec![], status: err_status(FsOp::FsopReaddir, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -285,8 +285,8 @@ impl LwsVfs for LwsVfsIns { let mode = request.mode; let reply = match self.fs.fmkdir(&path, mode) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_MKDIR, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_MKDIR, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopMkdir, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopMkdir, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -297,8 +297,8 @@ impl LwsVfs for LwsVfsIns { let size = request.size as u64; let reply = match self.fs.ftruncate(path, size) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_TRUNCATE, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_TRUNCATE, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopTruncate, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopTruncate, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -310,8 +310,8 @@ impl LwsVfs for LwsVfsIns { let m_time = vec![request.ts[1].tv_sec as u64, request.ts[1].tv_nsec as u64]; let reply = match self.fs.futimens(path, &a_time, &m_time) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_UTIMENS, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_UTIMENS, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopUtimens, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopUtimens, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -323,8 +323,8 @@ impl LwsVfs for LwsVfsIns { let gid = request.gid as u32; let reply = match self.fs.fchown(path, uid, gid) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_CHOWN, vec![path.to_string()], &std::io::Error::from_raw_os_error(libc::ENOSYS)) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_CHOWN, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopChown, vec![path.to_string()], &std::io::Error::from_raw_os_error(libc::ENOSYS)) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopChown, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -335,8 +335,8 @@ impl LwsVfs for LwsVfsIns { let mut fi = FileInfo::default(); let reply = match self.fs.frelease(path, &mut fi, request.flush != 0) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_RELEASE, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_RELEASE, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopRelease, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopRelease, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -346,8 +346,8 @@ impl LwsVfs for LwsVfsIns { let path = &self.lpath(&request.path); let reply = match self.fs.frmdir(path) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_RMDIR, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_RMDIR, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopRmdir, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopRmdir, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -358,8 +358,8 @@ impl LwsVfs for LwsVfsIns { let mut fi = FileInfo::default(); let reply = match self.fs.fflush(path, &mut fi) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_FLUSH, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_FLUSH, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopFlush, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopFlush, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -371,8 +371,8 @@ impl LwsVfs for LwsVfsIns { let mut fi = FileInfo::default(); let reply = match self.fs.fcreate(path, mode, &mut fi) { Ok(0) => CreateResponse { fi: Some(fi), status: ok_status() }, - Ok(_) => CreateResponse { fi: None, status: err_status(FsOp::FSOP_CREATE, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => CreateResponse { fi: None, status: err_status(FsOp::FSOP_CREATE, vec![path.to_string()], &*e) }, + Ok(_) => CreateResponse { fi: None, status: err_status(FsOp::FsopCreate, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => CreateResponse { fi: None, status: err_status(FsOp::FsopCreate, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -382,8 +382,8 @@ impl LwsVfs for LwsVfsIns { let path = &self.lpath(&request.path); let reply = match self.fs.funlink(path) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_UNLINK, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_UNLINK, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopUnlink, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopUnlink, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -394,8 +394,8 @@ impl LwsVfs for LwsVfsIns { let mut fi = FileInfo::default(); let reply = match self.fs.fopendir(path, &mut fi) { Ok(0) => OpendirResponse { fi: Some(fi), status: ok_status() }, - Ok(_) => OpendirResponse { fi: None, status: err_status(FsOp::FSOP_OPENDIR, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => OpendirResponse { fi: None, status: err_status(FsOp::FSOP_OPENDIR, vec![path.to_string()], &*e) }, + Ok(_) => OpendirResponse { fi: None, status: err_status(FsOp::FsopOpendir, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => OpendirResponse { fi: None, status: err_status(FsOp::FsopOpendir, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -406,8 +406,8 @@ impl LwsVfs for LwsVfsIns { let mut fi = FileInfo::default(); let reply = match self.fs.freleasedir(path, &mut fi) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_RELEASEDIR, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_RELEASEDIR, vec![path.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopReleasedir, vec![path.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopReleasedir, vec![path.to_string()], &*e) }, }; Ok(Response::new(reply)) } @@ -418,8 +418,8 @@ impl LwsVfs for LwsVfsIns { let to = &self.lpath(&request.new); let reply = match self.fs.frename(from, to) { Ok(0) => EmptyResponse { status: ok_status() }, - Ok(_) => EmptyResponse { status: err_status(FsOp::FSOP_RENAME, vec![from.to_string(), to.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, - Err(e) => EmptyResponse { status: err_status(FsOp::FSOP_RENAME, vec![from.to_string(), to.to_string()], &*e) }, + Ok(_) => EmptyResponse { status: err_status(FsOp::FsopRename, vec![from.to_string(), to.to_string()], &std::io::Error::new(std::io::ErrorKind::Other, "op failed")) }, + Err(e) => EmptyResponse { status: err_status(FsOp::FsopRename, vec![from.to_string(), to.to_string()], &*e) }, }; Ok(Response::new(reply)) }