Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现系统调用Fstat #295

Merged
merged 42 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f21d90b
支持时间子系统
houmkh Apr 26, 2023
90235c1
解决报错问题
fslongjin Apr 29, 2023
76c4043
timekeeping+clocksource,待测试
houmkh May 10, 2023
dfdaa92
整理time文件夹
houmkh May 11, 2023
69c68e8
整理clocksource jiffies
houmkh May 13, 2023
cdbcdc9
修改time模块
houmkh May 15, 2023
8178217
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh May 15, 2023
f924465
实现timeconv,clocksource+timekeeping板块测试完成
houmkh May 21, 2023
a0a78aa
测试gettimeofday
houmkh May 27, 2023
753b175
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh May 27, 2023
b237645
修改系统调用+修改update wall time
houmkh May 30, 2023
12a2d1e
把一些变量改为Atomic的,并且把裸指针改为Option
fslongjin May 30, 2023
124beae
解决update wall time报错问题。原因:local_irq_save和local_irq_restore汇编代码不规范
fslongjin May 30, 2023
7bb25b7
debug timekeeping
houmkh May 31, 2023
520a93a
清理kdebug
houmkh Jun 1, 2023
e8f0c5e
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh Jun 1, 2023
2a47e68
test gettimeofday
houmkh Jun 5, 2023
3f5f18f
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh Jun 7, 2023
0024bd9
暂时注释process_exit_mm()
houmkh Jun 7, 2023
5cec1df
修改dadk
houmkh Jun 7, 2023
2f7e9e9
解决了几个warning
fslongjin Jun 8, 2023
08d0cc0
修复一些小问题
fslongjin Jun 8, 2023
987f295
清理代码
houmkh Jun 15, 2023
03583ae
Merge branch 'posix-timer' of github.com:houmkh/DragonOS into posix-t…
houmkh Jun 15, 2023
8598483
为一些结构体加上了Debug trait
fslongjin Jun 17, 2023
7552345
增加工作队列todo
houmkh Jun 17, 2023
77327bb
Merge branch 'posix-timer' of github.com:houmkh/DragonOS into posix-t…
houmkh Jun 17, 2023
8622271
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh Jun 28, 2023
8f0c88a
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh Jul 11, 2023
6e9ae0d
fstat实现,还未加入系统调用表
houmkh Jul 12, 2023
4a69c6c
fstat加入系统调用表
houmkh Jul 12, 2023
509064d
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh Jul 13, 2023
776c0ed
测试fstat
houmkh Jul 17, 2023
da45384
测试fstat
houmkh Jul 17, 2023
1fa0780
fstat测试完成
houmkh Jul 26, 2023
f64b01c
fstat测试完成
houmkh Jul 26, 2023
ef78d88
Merge branch 'master' into fstat
houmkh Jul 26, 2023
794fc4e
Merge branch 'master' of github.com:DragonOS-Community/DragonOS into …
houmkh Jul 29, 2023
3630b3f
修改syscall.rs中的verify_area
houmkh Jul 31, 2023
774cea2
merge fstat
houmkh Jul 31, 2023
9aafc99
Merge branch 'master' into houmkh-fstat
fslongjin Aug 5, 2023
431a7f2
修正编译参数
fslongjin Aug 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "DragonOS",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/bin/sysroot/usr/include",
"${workspaceFolder}/user/libs/libc/src/include",
"${workspaceFolder}/user/libs/libc/src/include/export"
],
Expand Down
1 change: 1 addition & 0 deletions kernel/src/filesystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod procfs;
pub mod ramfs;
pub mod sysfs;
pub mod vfs;
pub mod syscall;
167 changes: 167 additions & 0 deletions kernel/src/filesystem/syscall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
use crate::{
arch::asm::current::current_pcb,
filesystem::vfs::FileType,
kdebug,
syscall::{Syscall, SystemError},
time::TimeSpec,
};

bitflags! {
/// 文件类型和权限
pub struct ModeType: u32 {
/// 掩码
const S_IFMT = 0o0_170_000;
/// 文件类型
const S_IFSOCK = 0o140000;
const S_IFLNK = 0o120000;
const S_IFREG = 0o100000;
const S_IFBLK = 0o060000;
const S_IFDIR = 0o040000;
const S_IFCHR = 0o020000;
const S_IFIFO = 0o010000;

const S_ISUID = 0o004000;
const S_ISGID = 0o002000;
const S_ISVTX = 0o001000;
/// 文件用户权限
const S_IRWXU = 0o0700;
const S_IRUSR = 0o0400;
const S_IWUSR = 0o0200;
const S_IXUSR = 0o0100;
/// 文件组权限
const S_IRWXG = 0o0070;
const S_IRGRP = 0o0040;
const S_IWGRP = 0o0020;
const S_IXGRP = 0o0010;
/// 文件其他用户权限
const S_IRWXO = 0o0007;
const S_IROTH = 0o0004;
const S_IWOTH = 0o0002;
const S_IXOTH = 0o0001;
}
}

#[repr(C)]
/// # 文件信息结构体
pub struct PosixKstat {
/// 硬件设备ID
dev_id: u64,
/// inode号
inode: u64,
/// 硬链接数
nlink: u64,
/// 文件权限
mode: ModeType,
/// 所有者用户ID
uid: i32,
/// 所有者组ID
gid: i32,
/// 设备ID
rdev: i64,
/// 文件大小
size: i64,
/// 文件系统块大小
blcok_size: i64,
/// 分配的512B块数
blocks: u64,
/// 最后访问时间
atime: TimeSpec,
/// 最后修改时间
mtime: TimeSpec,
/// 最后状态变化时间
ctime: TimeSpec,
/// 用于填充结构体大小的空白数据
pub _pad: [i8; 24],
}
impl PosixKstat {
fn new() -> Self {
Self {
inode: 0,
dev_id: 0,
mode: ModeType { bits: 0 },
nlink: 0,
uid: 0,
gid: 0,
rdev: 0,
size: 0,
atime: TimeSpec {
tv_sec: 0,
tv_nsec: 0,
},
mtime: TimeSpec {
tv_sec: 0,
tv_nsec: 0,
},
ctime: TimeSpec {
tv_sec: 0,
tv_nsec: 0,
},
blcok_size: 0,
blocks: 0,
_pad: Default::default(),
}
}
}
impl Syscall {
fn do_fstat(fd: i32) -> Result<PosixKstat, SystemError> {
let cur = current_pcb();
match cur.get_file_ref_by_fd(fd) {
Some(file) => {
let mut kstat = PosixKstat::new();
fslongjin marked this conversation as resolved.
Show resolved Hide resolved
// 获取文件信息
match file.metadata() {
Ok(metadata) => {
kstat.size = metadata.size as i64;
kstat.dev_id = metadata.dev_id as u64;
kstat.inode = metadata.inode_id as u64;
kstat.blcok_size = metadata.blk_size as i64;
kstat.blocks = metadata.blocks as u64;

kstat.atime.tv_sec = metadata.atime.tv_sec;
kstat.atime.tv_nsec = metadata.atime.tv_nsec;
kstat.mtime.tv_sec = metadata.mtime.tv_sec;
kstat.mtime.tv_nsec = metadata.mtime.tv_nsec;
kstat.ctime.tv_sec = metadata.ctime.tv_sec;
kstat.ctime.tv_nsec = metadata.ctime.tv_nsec;

kstat.nlink = metadata.nlinks as u64;
kstat.uid = metadata.uid as i32;
kstat.gid = metadata.gid as i32;
kstat.rdev = metadata.raw_dev as i64;
kstat.mode.bits = metadata.mode;
match file.file_type() {
FileType::File => kstat.mode.insert(ModeType::S_IFMT),
FileType::Dir => kstat.mode.insert(ModeType::S_IFDIR),
FileType::BlockDevice => kstat.mode.insert(ModeType::S_IFBLK),
FileType::CharDevice => kstat.mode.insert(ModeType::S_IFCHR),
FileType::SymLink => kstat.mode.insert(ModeType::S_IFLNK),
FileType::Socket => kstat.mode.insert(ModeType::S_IFSOCK),
FileType::Pipe => kstat.mode.insert(ModeType::S_IFIFO),
}
}
Err(e) => return Err(e),
}

return Ok(kstat);
}
None => {
kdebug!("file not be opened");
return Err(SystemError::EINVAL);
}
}
}
pub fn fstat(fd: i32, usr_kstat: *mut PosixKstat) -> Result<usize, SystemError> {
match Self::do_fstat(fd) {
Ok(kstat) => {
if usr_kstat.is_null() {
return Err(SystemError::EFAULT);
}
unsafe {
*usr_kstat = kstat;
}
return Ok(0);
}
Err(e) => return Err(e),
}
}
}
Loading