1. 修改文件权限问题。将777改成755
2. 支持客户端获取config,避免两边维护两个config文件,修改维护比较麻烦。 待完善: 使用clip支持命令行参数的解析和交互。
This commit is contained in:
parent
e044ac77b0
commit
db35d8c9b2
|
@ -4,6 +4,5 @@
|
||||||
"d:\\": "/l0d",
|
"d:\\": "/l0d",
|
||||||
"f:\\": "/l0e"
|
"f:\\": "/l0e"
|
||||||
},
|
},
|
||||||
"port":7412,
|
"port":33444
|
||||||
"addr":"192.168.0.110"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package lws_vfs;
|
||||||
service LwsVfs {
|
service LwsVfs {
|
||||||
// Sends a greeting
|
// Sends a greeting
|
||||||
rpc SayHello(HelloRequest) returns (HelloReply) {}
|
rpc SayHello(HelloRequest) returns (HelloReply) {}
|
||||||
|
rpc GetConfig(get_config) returns (get_config) {}
|
||||||
|
|
||||||
rpc fgetattr(getattr) returns (getattr) {}
|
rpc fgetattr(getattr) returns (getattr) {}
|
||||||
rpc fsetxattr(setxattr) returns (setxattr) {}
|
rpc fsetxattr(setxattr) returns (setxattr) {}
|
||||||
|
@ -48,6 +49,10 @@ message HelloRequest { string name = 1; }
|
||||||
// The response message containing the greetings
|
// The response message containing the greetings
|
||||||
message HelloReply { string message = 1; }
|
message HelloReply { string message = 1; }
|
||||||
|
|
||||||
|
message get_config {
|
||||||
|
string config = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message file_info {
|
message file_info {
|
||||||
uint32 flags = 1;
|
uint32 flags = 1;
|
||||||
uint32 fh_old = 2;
|
uint32 fh_old = 2;
|
||||||
|
|
|
@ -73,19 +73,19 @@ impl FileFdMgnt {
|
||||||
}
|
}
|
||||||
pub fn push(&mut self, handle: FileHandle) -> Result<u64, Box<dyn Error>> {
|
pub fn push(&mut self, handle: FileHandle) -> Result<u64, Box<dyn Error>> {
|
||||||
let fd = self.gen_fd()?;
|
let fd = self.gen_fd()?;
|
||||||
println!("push a fd: {}", fd);
|
log::trace!("push a fd: {}", fd);
|
||||||
self.files.insert(fd as u16, handle);
|
self.files.insert(fd as u16, handle);
|
||||||
Ok(fd)
|
Ok(fd)
|
||||||
}
|
}
|
||||||
pub fn pop(&mut self, fd: u64) -> Option<FileHandle> {
|
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))
|
self.files.remove(&(fd as u16))
|
||||||
}
|
}
|
||||||
// pub fn get(&mut self, fd: u64) -> Option<&FileHandle> {
|
// pub fn get(&mut self, fd: u64) -> Option<&FileHandle> {
|
||||||
// self.files.get(&fd)
|
// self.files.get(&fd)
|
||||||
// }
|
// }
|
||||||
pub fn get_mut(&mut self, fd: u64) -> Option<&mut FileHandle> {
|
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))
|
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) {
|
let metadata = match fs::metadata(path) {
|
||||||
Ok(metadata) => metadata,
|
Ok(metadata) => metadata,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("get {} metadata fail", path);
|
log::warn!("get {} metadata fail", path);
|
||||||
return permissions;
|
return permissions;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -104,7 +104,7 @@ fn get_file_mode_mask(path: &str) -> u32 {
|
||||||
if attributes & FILE_ATTRIBUTE_READONLY != 0 {
|
if attributes & FILE_ATTRIBUTE_READONLY != 0 {
|
||||||
permissions |= 0o0444;
|
permissions |= 0o0444;
|
||||||
} else {
|
} else {
|
||||||
permissions |= 0o0444 | 0o0222;
|
permissions |= 0o0444 | 0o0200;
|
||||||
}
|
}
|
||||||
// add executeable
|
// add executeable
|
||||||
permissions |= 0o0111;
|
permissions |= 0o0111;
|
||||||
|
@ -131,7 +131,7 @@ impl FSImpl {
|
||||||
let metadata = fs::metadata(path)?;
|
let metadata = fs::metadata(path)?;
|
||||||
from_metadata(sta, &metadata)?;
|
from_metadata(sta, &metadata)?;
|
||||||
let perm = get_file_mode_mask(path);
|
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();
|
sta.fst_mode = perm.into();
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ impl FSImpl {
|
||||||
};
|
};
|
||||||
match file.seek_read(buffer, offsize as u64) {
|
match file.seek_read(buffer, offsize as u64) {
|
||||||
Ok(size) => {
|
Ok(size) => {
|
||||||
// println!(
|
// log::info!(
|
||||||
// "size is:{}, buffer is {}",
|
// "size is:{}, buffer is {}",
|
||||||
// size,
|
// size,
|
||||||
// String::from_utf8(buffer.to_vec()).unwrap()
|
// String::from_utf8(buffer.to_vec()).unwrap()
|
||||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -2,10 +2,11 @@
|
||||||
use lws_vfs::lws_vfs_server::LwsVfs;
|
use lws_vfs::lws_vfs_server::LwsVfs;
|
||||||
use lws_vfs::{
|
use lws_vfs::{
|
||||||
Access, Chown, FileInfo, Flush, Fstat, Getattr, Getxattr, HelloReply, HelloRequest, Mkdir,
|
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 self::fs_impl::FSImpl;
|
||||||
use serde_json::{self, Value};
|
use serde_json::{self, Value};
|
||||||
|
use serde::Serialize;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read as _;
|
use std::io::Read as _;
|
||||||
|
@ -29,7 +30,7 @@ pub mod lws_vfs {
|
||||||
// "port":5001
|
// "port":5001
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Serialize, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
port: u16,
|
port: u16,
|
||||||
mount_map: HashMap<String, String>,
|
mount_map: HashMap<String, String>,
|
||||||
|
@ -114,6 +115,14 @@ impl LwsVfs for LwsVfsIns {
|
||||||
|
|
||||||
Ok(Response::new(reply))
|
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> {
|
async fn fgetattr(&self, request: Request<Getattr>) -> Result<Response<Getattr>, Status> {
|
||||||
let request = request.into_inner();
|
let request = request.into_inner();
|
||||||
log::trace!("Got a request: {:?}", request);
|
log::trace!("Got a request: {:?}", request);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user