Skip to content
Snippets Groups Projects
Unverified Commit dc5bd707 authored by Ian Douglas Scott's avatar Ian Douglas Scott
Browse files

futimens: do not require O_RWONLY/O_RDWR

parent fc0af50b
No related branches found
No related tags found
No related merge requests found
...@@ -131,15 +131,17 @@ pub struct FileResource { ...@@ -131,15 +131,17 @@ pub struct FileResource {
block: u64, block: u64,
flags: usize, flags: usize,
seek: u64, seek: u64,
uid: u32,
} }
impl FileResource { impl FileResource {
pub fn new(path: String, block: u64, flags: usize, seek: u64) -> FileResource { pub fn new(path: String, block: u64, flags: usize, seek: u64, uid: u32) -> FileResource {
FileResource { FileResource {
path: path, path: path,
block: block, block: block,
flags: flags, flags: flags,
seek: seek, seek: seek,
uid: uid,
} }
} }
} }
...@@ -151,6 +153,7 @@ impl Resource for FileResource { ...@@ -151,6 +153,7 @@ impl Resource for FileResource {
block: self.block, block: self.block,
flags: self.flags, flags: self.flags,
seek: self.seek, seek: self.seek,
uid: self.uid,
})) }))
} }
...@@ -246,9 +249,10 @@ impl Resource for FileResource { ...@@ -246,9 +249,10 @@ impl Resource for FileResource {
} }
fn utimens(&mut self, times: &[TimeSpec], fs: &mut FileSystem) -> Result<usize> { fn utimens(&mut self, times: &[TimeSpec], fs: &mut FileSystem) -> Result<usize> {
if self.flags & O_ACCMODE == O_RDWR || self.flags & O_ACCMODE == O_WRONLY { let mut node = fs.node(self.block)?;
if node.1.uid == self.uid || self.uid == 0 {
if let Some(mtime) = times.get(1) { if let Some(mtime) = times.get(1) {
let mut node = fs.node(self.block)?;
node.1.mtime = mtime.tv_sec as u64; node.1.mtime = mtime.tv_sec as u64;
node.1.mtime_nsec = mtime.tv_nsec as u32; node.1.mtime_nsec = mtime.tv_nsec as u32;
......
...@@ -253,7 +253,7 @@ impl Scheme for FileScheme { ...@@ -253,7 +253,7 @@ impl Scheme for FileScheme {
0 0
}; };
Box::new(FileResource::new(path.to_string(), node.0, flags, seek)) 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();
...@@ -293,7 +293,7 @@ impl Scheme for FileScheme { ...@@ -293,7 +293,7 @@ impl Scheme for FileScheme {
0 0
}; };
Box::new(FileResource::new(path.to_string(), node.0, flags, seek)) 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