Revise some error numbers and messages
This commit is contained in:
parent
d42b006e1a
commit
d66dbdd3bc
|
|
@ -1108,6 +1108,9 @@ impl Inode for ExfatInode {
|
|||
if inner.inode_type.is_directory() {
|
||||
return_errno!(Errno::EISDIR)
|
||||
}
|
||||
if !inner.inode_type.is_regular_file() {
|
||||
return_errno!(Errno::EINVAL);
|
||||
}
|
||||
|
||||
let file_size = inner.size;
|
||||
let fs = inner.fs();
|
||||
|
|
|
|||
|
|
@ -107,9 +107,12 @@ impl Inode {
|
|||
}
|
||||
|
||||
pub fn resize(&self, new_size: usize) -> Result<()> {
|
||||
if self.type_ != InodeType::File {
|
||||
if self.type_ == InodeType::Dir {
|
||||
return_errno!(Errno::EISDIR);
|
||||
}
|
||||
if self.type_ != InodeType::File {
|
||||
return_errno!(Errno::EINVAL);
|
||||
}
|
||||
|
||||
let inner = self.inner.upread();
|
||||
if new_size == inner.file_size() {
|
||||
|
|
@ -782,10 +785,6 @@ impl Inode {
|
|||
}
|
||||
|
||||
pub fn fallocate(&self, mode: FallocMode, offset: usize, len: usize) -> Result<()> {
|
||||
if self.type_ != InodeType::File {
|
||||
return_errno_with_message!(Errno::EISDIR, "not regular file");
|
||||
}
|
||||
|
||||
match mode {
|
||||
FallocMode::PunchHoleKeepSize => {
|
||||
// Make the whole operation atomic
|
||||
|
|
|
|||
|
|
@ -406,6 +406,18 @@ pub fn do_fallocate_util(
|
|||
offset: usize,
|
||||
len: usize,
|
||||
) -> Result<()> {
|
||||
let inode_type = inode.type_();
|
||||
// TODO: `fallocate` on pipe files also fails with `ESPIPE`.
|
||||
if inode_type == InodeType::NamedPipe {
|
||||
return_errno_with_message!(Errno::ESPIPE, "the inode is a FIFO file");
|
||||
}
|
||||
if !(inode_type == InodeType::File || inode_type == InodeType::Dir) {
|
||||
return_errno_with_message!(
|
||||
Errno::ENODEV,
|
||||
"the inode is not a regular file or a directory"
|
||||
);
|
||||
}
|
||||
|
||||
if status_flags.contains(StatusFlags::O_APPEND)
|
||||
&& (mode == FallocMode::PunchHoleKeepSize
|
||||
|| mode == FallocMode::CollapseRange
|
||||
|
|
|
|||
|
|
@ -414,8 +414,11 @@ impl OverlayInode {
|
|||
}
|
||||
|
||||
pub fn resize(&self, new_size: usize) -> Result<()> {
|
||||
if self.type_ == InodeType::Dir {
|
||||
return_errno_with_message!(Errno::EISDIR, "the inode is a directory");
|
||||
}
|
||||
if self.type_ != InodeType::File {
|
||||
return_errno_with_message!(Errno::EISDIR, "not regular file");
|
||||
return_errno_with_message!(Errno::EINVAL, "the inode is not a regular file");
|
||||
}
|
||||
|
||||
if self.get_top_valid_inode().size() == new_size {
|
||||
|
|
|
|||
|
|
@ -613,8 +613,11 @@ impl Inode for RamInode {
|
|||
}
|
||||
|
||||
fn resize(&self, new_size: usize) -> Result<()> {
|
||||
if self.typ == InodeType::Dir {
|
||||
return_errno_with_message!(Errno::EISDIR, "the inode is a directory");
|
||||
}
|
||||
if self.typ != InodeType::File {
|
||||
return_errno_with_message!(Errno::EISDIR, "not regular file");
|
||||
return_errno_with_message!(Errno::EINVAL, "the inode is not a regular file");
|
||||
}
|
||||
|
||||
let file_size = self.size();
|
||||
|
|
@ -1156,10 +1159,6 @@ impl Inode for RamInode {
|
|||
}
|
||||
|
||||
fn fallocate(&self, mode: FallocMode, offset: usize, len: usize) -> Result<()> {
|
||||
if self.typ != InodeType::File {
|
||||
return_errno_with_message!(Errno::EISDIR, "not regular file");
|
||||
}
|
||||
|
||||
// The support for flags is consistent with Linux
|
||||
match mode {
|
||||
FallocMode::Allocate => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue