Skip to content
Snippets Groups Projects
Verified Commit 43533e8d authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Merge branch 'jD91mZM2/redoxfs-master' into HEAD

parents bf4d0161 79cef7c0
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; ...@@ -5,7 +5,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use syscall::data::{Map, Stat, TimeSpec}; use syscall::data::{Map, Stat, TimeSpec};
use syscall::error::{Error, Result, EBADF, EINVAL, EISDIR, ENOMEM, EPERM}; 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 disk::Disk;
use filesystem::FileSystem; use filesystem::FileSystem;
...@@ -256,13 +256,13 @@ pub struct FileResource { ...@@ -256,13 +256,13 @@ pub struct FileResource {
} }
impl 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 { FileResource {
path: path, path,
block: block, block,
flags: flags, flags,
seek: seek, seek: 0,
uid: uid, uid,
fmaps: BTreeMap::new(), fmaps: BTreeMap::new(),
} }
} }
...@@ -296,6 +296,9 @@ impl<D: Disk> Resource<D> for FileResource { ...@@ -296,6 +296,9 @@ impl<D: Disk> Resource<D> for FileResource {
fn write(&mut self, buf: &[u8], fs: &mut FileSystem<D>) -> Result<usize> { 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_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 mtime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let count = fs.write_node(self.block, self.seek, buf, mtime.as_secs(), mtime.subsec_nanos())?; let count = fs.write_node(self.block, self.seek, buf, mtime.as_secs(), mtime.subsec_nanos())?;
self.seek += count as u64; self.seek += count as u64;
......
...@@ -6,7 +6,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; ...@@ -6,7 +6,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use syscall::data::{Map, Stat, StatVfs, TimeSpec}; use syscall::data::{Map, Stat, StatVfs, TimeSpec};
use syscall::error::{Error, Result, EACCES, EEXIST, EISDIR, ENOTDIR, ENOTEMPTY, EPERM, ENOENT, EBADF, ELOOP, EINVAL}; 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 syscall::scheme::Scheme;
use BLOCK_SIZE; use BLOCK_SIZE;
...@@ -250,13 +250,7 @@ impl<D: Disk> Scheme for FileScheme<D> { ...@@ -250,13 +250,7 @@ impl<D: Disk> Scheme for FileScheme<D> {
fs.node_set_len(node.0, 0)?; fs.node_set_len(node.0, 0)?;
} }
let seek = if flags & O_APPEND == O_APPEND { Box::new(FileResource::new(path.to_string(), node.0, flags, uid))
fs.node_len(node.0)?
} else {
0
};
Box::new(FileResource::new(path.to_string(), node.0, flags, seek, uid))
}, },
None => if flags & O_CREAT == O_CREAT { None => if flags & O_CREAT == O_CREAT {
let mut last_part = String::new(); let mut last_part = String::new();
...@@ -290,13 +284,7 @@ impl<D: Disk> Scheme for FileScheme<D> { ...@@ -290,13 +284,7 @@ impl<D: Disk> Scheme for FileScheme<D> {
if dir { if dir {
Box::new(DirResource::new(path.to_string(), node.0, None, uid)) Box::new(DirResource::new(path.to_string(), node.0, None, uid))
} else { } else {
let seek = if flags & O_APPEND == O_APPEND { Box::new(FileResource::new(path.to_string(), node.0, flags, uid))
fs.node_len(node.0)?
} else {
0
};
Box::new(FileResource::new(path.to_string(), node.0, flags, seek, uid))
} }
} else { } else {
return Err(Error::new(EPERM)); return Err(Error::new(EPERM));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment