From db35d8c9b205a89c7ee8785c139cac206abe27b8 Mon Sep 17 00:00:00 2001 From: Begild Date: Tue, 6 Aug 2024 08:45:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98=E3=80=82=E5=B0=86777?= =?UTF-8?q?=E6=94=B9=E6=88=90755=202.=20=E6=94=AF=E6=8C=81=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E8=8E=B7=E5=8F=96config=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E4=B8=A4=E8=BE=B9=E7=BB=B4=E6=8A=A4=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?config=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BF=AE=E6=94=B9=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4=E6=AF=94=E8=BE=83=E9=BA=BB=E7=83=A6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 待完善: 使用clip支持命令行参数的解析和交互。 --- config.json | 3 +-- proto/lws.proto | 5 +++++ src/fs_impl/mod.rs | 14 +++++++------- src/lib.rs | 13 +++++++++++-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/config.json b/config.json index bf50163..5c4620c 100755 --- a/config.json +++ b/config.json @@ -4,6 +4,5 @@ "d:\\": "/l0d", "f:\\": "/l0e" }, - "port":7412, - "addr":"192.168.0.110" + "port":33444 } diff --git a/proto/lws.proto b/proto/lws.proto index 0181575..895e00e 100644 --- a/proto/lws.proto +++ b/proto/lws.proto @@ -19,6 +19,7 @@ package lws_vfs; service LwsVfs { // Sends a greeting rpc SayHello(HelloRequest) returns (HelloReply) {} + rpc GetConfig(get_config) returns (get_config) {} rpc fgetattr(getattr) returns (getattr) {} rpc fsetxattr(setxattr) returns (setxattr) {} @@ -48,6 +49,10 @@ message HelloRequest { string name = 1; } // The response message containing the greetings message HelloReply { string message = 1; } +message get_config { + string config = 1; +} + message file_info { uint32 flags = 1; uint32 fh_old = 2; diff --git a/src/fs_impl/mod.rs b/src/fs_impl/mod.rs index c55a97f..ab5b96a 100755 --- a/src/fs_impl/mod.rs +++ b/src/fs_impl/mod.rs @@ -73,19 +73,19 @@ impl FileFdMgnt { } pub fn push(&mut self, handle: FileHandle) -> Result> { let fd = self.gen_fd()?; - println!("push a fd: {}", fd); + log::trace!("push a fd: {}", fd); self.files.insert(fd as u16, handle); Ok(fd) } pub fn pop(&mut self, fd: u64) -> Option { - println!("pop a fd: {}", fd); + log::trace!("pop a fd: {}", fd); self.files.remove(&(fd as u16)) } // pub fn get(&mut self, fd: u64) -> Option<&FileHandle> { // self.files.get(&fd) // } pub fn get_mut(&mut self, fd: u64) -> Option<&mut FileHandle> { - println!("get a fd: {}", fd); + log::trace!("get a fd: {}", fd); self.files.get_mut(&(fd as u16)) } } @@ -95,7 +95,7 @@ fn get_file_mode_mask(path: &str) -> u32 { let metadata = match fs::metadata(path) { Ok(metadata) => metadata, Err(_) => { - println!("get {} metadata fail", path); + log::warn!("get {} metadata fail", path); return permissions; } }; @@ -104,7 +104,7 @@ fn get_file_mode_mask(path: &str) -> u32 { if attributes & FILE_ATTRIBUTE_READONLY != 0 { permissions |= 0o0444; } else { - permissions |= 0o0444 | 0o0222; + permissions |= 0o0444 | 0o0200; } // add executeable permissions |= 0o0111; @@ -131,7 +131,7 @@ impl FSImpl { let metadata = fs::metadata(path)?; from_metadata(sta, &metadata)?; let perm = get_file_mode_mask(path); - println!("file mode is Oct:{:o}", perm); + // log::trace!("file mode is Oct:{:o}", perm); sta.fst_mode = perm.into(); Ok(0) } @@ -167,7 +167,7 @@ impl FSImpl { }; match file.seek_read(buffer, offsize as u64) { Ok(size) => { - // println!( + // log::info!( // "size is:{}, buffer is {}", // size, // String::from_utf8(buffer.to_vec()).unwrap() diff --git a/src/lib.rs b/src/lib.rs index aebce4e..b27edbf 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,10 +2,11 @@ use lws_vfs::lws_vfs_server::LwsVfs; use lws_vfs::{ Access, Chown, FileInfo, Flush, Fstat, Getattr, Getxattr, HelloReply, HelloRequest, Mkdir, - Open, Read, Readdir, Release, Rmdir, Setxattr, Truncate, Utimens, Write, Create, Unlink, Opendir, Releasedir, Rename + Open, Read, Readdir, Release, Rmdir, Setxattr, Truncate, Utimens, Write, Create, Unlink, Opendir, Releasedir, Rename, GetConfig, }; use self::fs_impl::FSImpl; use serde_json::{self, Value}; +use serde::Serialize; use std::error::Error; use std::fs::File; use std::io::Read as _; @@ -29,7 +30,7 @@ pub mod lws_vfs { // "port":5001 // } -#[derive(Debug, Default)] +#[derive(Debug, Serialize, Default)] pub struct Config { port: u16, mount_map: HashMap, @@ -114,6 +115,14 @@ impl LwsVfs for LwsVfsIns { Ok(Response::new(reply)) } + async fn get_config(&self, _req: Request) -> Result, Status> { + let config = serde_json::to_string(&self.config).unwrap(); + log::info!("reply config: {}", config); + let reply = GetConfig { + config, + }; + Ok(Response::new(reply)) + } async fn fgetattr(&self, request: Request) -> Result, Status> { let request = request.into_inner(); log::trace!("Got a request: {:?}", request);