Add O_APPEND functionality

This commit is contained in:
Jeremy Soller
2017-04-09 22:09:29 -06:00
parent d0dfef2f0b
commit f418d30dc9
2 changed files with 17 additions and 5 deletions
+2 -2
View File
@@ -117,12 +117,12 @@ pub struct FileResource {
}
impl FileResource {
pub fn new(path: String, block: u64, flags: usize) -> FileResource {
pub fn new(path: String, block: u64, flags: usize, seek: u64) -> FileResource {
FileResource {
path: path,
block: block,
flags: flags,
seek: 0,
seek: seek,
}
}
}
+15 -3
View File
@@ -9,7 +9,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use syscall::data::{Stat, StatVfs};
use syscall::error::{Error, Result, EACCES, EEXIST, EISDIR, ENOTDIR, EPERM, ENOENT, EBADF};
use syscall::flag::{O_CREAT, O_DIRECTORY, O_STAT, O_EXCL, O_TRUNC, O_ACCMODE, O_RDONLY, O_WRONLY, O_RDWR, MODE_PERM};
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};
use syscall::scheme::Scheme;
pub struct FileScheme {
@@ -133,7 +133,13 @@ impl Scheme for FileScheme {
try!(fs.node_set_len(node.0, 0));
}
Box::new(FileResource::new(path.to_string(), node.0, flags))
let seek = if flags & O_APPEND == O_APPEND {
try!(fs.node_len(node.0))
} else {
0
};
Box::new(FileResource::new(path.to_string(), node.0, flags, seek))
},
None => if flags & O_CREAT == O_CREAT {
let mut last_part = String::new();
@@ -169,7 +175,13 @@ impl Scheme for FileScheme {
if dir {
Box::new(DirResource::new(path.to_string(), node.0, Vec::new()))
} else {
Box::new(FileResource::new(path.to_string(), node.0, flags))
let seek = if flags & O_APPEND == O_APPEND {
try!(fs.node_len(node.0))
} else {
0
};
Box::new(FileResource::new(path.to_string(), node.0, flags, seek))
}
} else {
return Err(Error::new(EPERM));