mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-23 08:03:22 +00:00
移植sqlite3,并修复一些bug (#323)
* bugfix: 程序加载器映射内存时,计算要映射的大小不正确的问题。 * 修正brk系统调用不符合规范的地方 * bugfix: 修正fat文件系统未能正确的扩展文件大小的bug * 增加fcntl系统调用 * 移植sqlite3
This commit is contained in:
@ -350,6 +350,10 @@ impl FATFileSystem {
|
||||
/// @return Err(SystemError) 错误码
|
||||
pub fn get_fat_entry(&self, cluster: Cluster) -> Result<FATEntry, SystemError> {
|
||||
let current_cluster = cluster.cluster_num;
|
||||
if current_cluster < 2 {
|
||||
// 0号簇和1号簇是保留簇,不允许用户使用
|
||||
return Err(SystemError::EINVAL);
|
||||
}
|
||||
|
||||
let fat_type: FATType = self.bpb.fat_type;
|
||||
// 获取FAT表的起始扇区(相对分区起始扇区的偏移量)
|
||||
@ -1460,6 +1464,44 @@ impl IndexNode for LockedFATInode {
|
||||
fn metadata(&self) -> Result<Metadata, SystemError> {
|
||||
return Ok(self.0.lock().metadata.clone());
|
||||
}
|
||||
fn resize(&self, len: usize) -> Result<(), SystemError> {
|
||||
let mut guard: SpinLockGuard<FATInode> = self.0.lock();
|
||||
let fs: &Arc<FATFileSystem> = &guard.fs.upgrade().unwrap();
|
||||
let old_size = guard.metadata.size as usize;
|
||||
|
||||
match &mut guard.inode_type {
|
||||
FATDirEntry::File(file) | FATDirEntry::VolId(file) => {
|
||||
// 如果新的长度和旧的长度相同,那么就直接返回
|
||||
if len == old_size {
|
||||
return Ok(());
|
||||
} else if len > old_size {
|
||||
// 如果新的长度比旧的长度大,那么就在文件末尾添加空白
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
let mut remain_size = len - old_size;
|
||||
let buf_size = remain_size;
|
||||
// let buf_size = core::cmp::min(remain_size, 512 * 1024);
|
||||
buf.resize(buf_size, 0);
|
||||
|
||||
let mut offset = old_size;
|
||||
while remain_size > 0 {
|
||||
let write_size = core::cmp::min(remain_size, buf_size);
|
||||
file.write(fs, &buf[0..write_size], offset as u64)?;
|
||||
remain_size -= write_size;
|
||||
offset += write_size;
|
||||
}
|
||||
} else {
|
||||
file.truncate(fs, len as u64)?;
|
||||
}
|
||||
guard.update_metadata();
|
||||
return Ok(());
|
||||
}
|
||||
FATDirEntry::Dir(_) => return Err(SystemError::EOPNOTSUPP_OR_ENOTSUP),
|
||||
FATDirEntry::UnInit => {
|
||||
kerror!("FATFS: param: Inode_type uninitialized.");
|
||||
return Err(SystemError::EROFS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn list(&self) -> Result<Vec<String>, SystemError> {
|
||||
let mut guard: SpinLockGuard<FATInode> = self.0.lock();
|
||||
|
Reference in New Issue
Block a user