1. 修改文件权限问题。将777改成755

2. 支持客户端获取config,避免两边维护两个config文件,修改维护比较麻烦。

待完善:
使用clip支持命令行参数的解析和交互。
This commit is contained in:
Ekko.bao 2024-08-06 08:45:24 +08:00
parent e044ac77b0
commit db35d8c9b2
4 changed files with 24 additions and 11 deletions

View File

@ -4,6 +4,5 @@
"d:\\": "/l0d",
"f:\\": "/l0e"
},
"port":7412,
"addr":"192.168.0.110"
"port":33444
}

View File

@ -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;

View File

@ -73,19 +73,19 @@ impl FileFdMgnt {
}
pub fn push(&mut self, handle: FileHandle) -> Result<u64, Box<dyn Error>> {
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<FileHandle> {
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()

View File

@ -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<String, String>,
@ -114,6 +115,14 @@ impl LwsVfs for LwsVfsIns {
Ok(Response::new(reply))
}
async fn get_config(&self, _req: Request<GetConfig>) -> Result<Response<GetConfig>, 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<Getattr>) -> Result<Response<Getattr>, Status> {
let request = request.into_inner();
log::trace!("Got a request: {:?}", request);