Verified Commit 43533e8d authored by Jeremy Soller's avatar Jeremy Soller

Merge branch 'jD91mZM2/redoxfs-master' into HEAD

parents bf4d0161 79cef7c0
Pipeline #5360 passed with stages
in 2 minutes and 49 seconds
......@@ -5,7 +5,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use syscall::data::{Map, Stat, TimeSpec};
use syscall::error::{Error, Result, EBADF, EINVAL, EISDIR, ENOMEM, EPERM};
use syscall::flag::{O_ACCMODE, O_RDONLY, O_WRONLY, O_RDWR, F_GETFL, F_SETFL, MODE_PERM, PROT_READ, PROT_WRITE, SEEK_SET, SEEK_CUR, SEEK_END};
use syscall::flag::{O_ACCMODE, O_APPEND, O_RDONLY, O_WRONLY, O_RDWR, F_GETFL, F_SETFL, MODE_PERM, PROT_READ, PROT_WRITE, SEEK_SET, SEEK_CUR, SEEK_END};
use disk::Disk;
use filesystem::FileSystem;
......@@ -256,13 +256,13 @@ pub struct FileResource {
}
impl FileResource {
pub fn new(path: String, block: u64, flags: usize, seek: u64, uid: u32) -> FileResource {
pub fn new(path: String, block: u64, flags: usize, uid: u32) -> FileResource {
FileResource {
path: path,
block: block,
flags: flags,
seek: seek,
uid: uid,
path,
block,
flags,
seek: 0,
uid,
fmaps: BTreeMap::new(),
}
}
......@@ -296,6 +296,9 @@ impl<D: Disk> Resource<D> for FileResource {
fn write(&mut self, buf: &[u8], fs: &mut FileSystem<D>) -> Result<usize> {
if self.flags & O_ACCMODE == O_RDWR || self.flags & O_ACCMODE == O_WRONLY {
if self.flags & O_APPEND == O_APPEND {
self.seek = fs.node_len(self.block)?;
}
let mtime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let count = fs.write_node(self.block, self.seek, buf, mtime.as_secs(), mtime.subsec_nanos())?;
self.seek += count as u64;
......
......@@ -6,7 +6,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use syscall::data::{Map, Stat, StatVfs, TimeSpec};
use syscall::error::{Error, Result, EACCES, EEXIST, EISDIR, ENOTDIR, ENOTEMPTY, EPERM, ENOENT, EBADF, ELOOP, EINVAL};
use syscall::flag::{O_APPEND, O_CREAT, O_DIRECTORY, O_STAT, O_EXCL, O_TRUNC, O_ACCMODE, O_RDONLY, O_WRONLY, O_RDWR, MODE_PERM, O_SYMLINK, O_NOFOLLOW};
use syscall::flag::{O_CREAT, O_DIRECTORY, O_STAT, O_EXCL, O_TRUNC, O_ACCMODE, O_RDONLY, O_WRONLY, O_RDWR, MODE_PERM, O_SYMLINK, O_NOFOLLOW};
use syscall::scheme::Scheme;
use BLOCK_SIZE;
......@@ -250,13 +250,7 @@ impl<D: Disk> Scheme for FileScheme<D> {
fs.node_set_len(node.0, 0)?;
}
let seek = if flags & O_APPEND == O_APPEND {
fs.node_len(node.0)?
} else {
0
};
Box::new(FileResource::new(path.to_string(), node.0, flags, seek, uid))
Box::new(FileResource::new(path.to_string(), node.0, flags, uid))
},
None => if flags & O_CREAT == O_CREAT {
let mut last_part = String::new();
......@@ -290,13 +284,7 @@ impl<D: Disk> Scheme for FileScheme<D> {
if dir {
Box::new(DirResource::new(path.to_string(), node.0, None, uid))
} else {
let seek = if flags & O_APPEND == O_APPEND {
fs.node_len(node.0)?
} else {
0
};
Box::new(FileResource::new(path.to_string(), node.0, flags, seek, uid))
Box::new(FileResource::new(path.to_string(), node.0, flags, uid))
}
} else {
return Err(Error::new(EPERM));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment