Revise some error messages
This commit is contained in:
parent
9ac0e31981
commit
7e7ba43cdf
|
|
@ -13,8 +13,7 @@ use crate::{
|
|||
file_table::FdFlags,
|
||||
fs_resolver::FsPath,
|
||||
inode_handle::FileIo,
|
||||
open_args::OpenArgs,
|
||||
utils::{mkmod, AccessMode, Inode, IoctlCmd},
|
||||
utils::{mkmod, AccessMode, Inode, IoctlCmd, OpenArgs},
|
||||
},
|
||||
prelude::*,
|
||||
process::{
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ impl FsResolver {
|
|||
debug_assert!(!relative_path.starts_with('/'));
|
||||
|
||||
if relative_path.len() > PATH_MAX {
|
||||
return_errno_with_message!(Errno::ENAMETOOLONG, "path is too long");
|
||||
return_errno_with_message!(Errno::ENAMETOOLONG, "the path is too long");
|
||||
}
|
||||
if relative_path.is_empty() {
|
||||
return Ok(LookupResult::Resolved(parent.clone()));
|
||||
|
|
@ -208,12 +208,12 @@ impl FsResolver {
|
|||
// If next inode is a symlink, follow symlinks at most `SYMLINKS_MAX` times.
|
||||
if next_type == InodeType::SymLink && (follow_tail_link || !next_is_tail) {
|
||||
if follows >= SYMLINKS_MAX {
|
||||
return_errno_with_message!(Errno::ELOOP, "too many symlinks");
|
||||
return_errno_with_message!(Errno::ELOOP, "there are too many symlinks");
|
||||
}
|
||||
let link_path_remain = {
|
||||
let mut tmp_link_path = next_path.inode().read_link()?;
|
||||
if tmp_link_path.is_empty() {
|
||||
return_errno_with_message!(Errno::ENOENT, "empty symlink");
|
||||
return_errno_with_message!(Errno::ENOENT, "the symlink path is empty");
|
||||
}
|
||||
if !path_remain.is_empty() {
|
||||
tmp_link_path += "/";
|
||||
|
|
@ -236,7 +236,7 @@ impl FsResolver {
|
|||
} else {
|
||||
// If path ends with `/`, the inode must be a directory
|
||||
if target_is_dir && next_type != InodeType::Dir {
|
||||
return_errno_with_message!(Errno::ENOTDIR, "inode is not dir");
|
||||
return_errno_with_message!(Errno::ENOTDIR, "the inode is not a directory");
|
||||
}
|
||||
current_path = next_path;
|
||||
relative_path = path_remain;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ pub mod file_table;
|
|||
pub mod fs_resolver;
|
||||
pub mod inode_handle;
|
||||
pub mod named_pipe;
|
||||
pub mod open_args;
|
||||
pub mod overlayfs;
|
||||
pub mod path;
|
||||
pub mod pipe;
|
||||
|
|
@ -34,8 +33,7 @@ use crate::{
|
|||
ext2::Ext2,
|
||||
file_table::FdFlags,
|
||||
fs_resolver::{FsPath, FsResolver},
|
||||
open_args::OpenArgs,
|
||||
utils::{mkmod, AccessMode},
|
||||
utils::{mkmod, AccessMode, OpenArgs},
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@ pub use mount_namespace::MountNamespace;
|
|||
use crate::{
|
||||
fs::{
|
||||
inode_handle::InodeHandle,
|
||||
open_args::OpenArgs,
|
||||
path::dentry::{Dentry, DentryKey},
|
||||
utils::{
|
||||
CreationFlags, FileSystem, Inode, InodeMode, InodeType, Metadata, MknodType,
|
||||
CreationFlags, FileSystem, Inode, InodeMode, InodeType, Metadata, MknodType, OpenArgs,
|
||||
Permission, StatusFlags, XattrName, XattrNamespace, XattrSetFlags, NAME_MAX,
|
||||
},
|
||||
},
|
||||
|
|
@ -379,14 +378,14 @@ impl Path {
|
|||
|
||||
match inode_type {
|
||||
InodeType::NamedPipe => {
|
||||
warn!("NamedPipe doesn't support additional operation when opening.");
|
||||
debug!("Open NamedPipe with args: {open_args:?}.");
|
||||
warn!("named pipes don't support additional operation when opening");
|
||||
debug!("the named pipe is opened with {:?}", open_args);
|
||||
}
|
||||
InodeType::SymLink => {
|
||||
if creation_flags.contains(CreationFlags::O_NOFOLLOW)
|
||||
&& !open_args.status_flags.contains(StatusFlags::O_PATH)
|
||||
{
|
||||
return_errno_with_message!(Errno::ELOOP, "file is a symlink");
|
||||
return_errno_with_message!(Errno::ELOOP, "the file is a symlink");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
@ -395,12 +394,12 @@ impl Path {
|
|||
if creation_flags.contains(CreationFlags::O_CREAT)
|
||||
&& creation_flags.contains(CreationFlags::O_EXCL)
|
||||
{
|
||||
return_errno_with_message!(Errno::EEXIST, "file exists");
|
||||
return_errno_with_message!(Errno::EEXIST, "the file already exists");
|
||||
}
|
||||
if creation_flags.contains(CreationFlags::O_DIRECTORY) && inode_type != InodeType::Dir {
|
||||
return_errno_with_message!(
|
||||
Errno::ENOTDIR,
|
||||
"O_DIRECTORY is specified but file is not a directory"
|
||||
"O_DIRECTORY is specified but the file is not a directory"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ pub use inode::{Extension, Inode, InodeType, Metadata, MknodType, Permission};
|
|||
pub use inode_mode::InodeMode;
|
||||
pub(crate) use inode_mode::{chmod, mkmod, perms_to_mask, who_and_perms_to_mask, who_to_mask};
|
||||
pub use ioctl::IoctlCmd;
|
||||
pub use open_args::OpenArgs;
|
||||
pub use page_cache::{CachePage, PageCache, PageCacheBackend};
|
||||
pub use random_test::{generate_random_operation, new_fs_in_memory};
|
||||
pub use range_lock::{FileRange, RangeLockItem, RangeLockList, RangeLockType, OFFSET_MAX};
|
||||
|
|
@ -36,6 +37,7 @@ mod fs;
|
|||
mod inode;
|
||||
mod inode_mode;
|
||||
mod ioctl;
|
||||
mod open_args;
|
||||
mod page_cache;
|
||||
mod random_test;
|
||||
mod range_lock;
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
file_table::{FdFlags, FileDesc},
|
||||
fs_resolver::{FsPath, FsResolver, LookupResult, AT_FDCWD},
|
||||
inode_handle::InodeHandle,
|
||||
open_args::OpenArgs,
|
||||
utils::{AccessMode, CreationFlags, InodeMode, InodeType},
|
||||
utils::{AccessMode, CreationFlags, InodeMode, InodeType, OpenArgs},
|
||||
},
|
||||
prelude::*,
|
||||
syscall::constants::MAX_FILENAME_LEN,
|
||||
|
|
@ -91,16 +90,22 @@ fn do_open(
|
|||
LookupResult::Resolved(target_path) => target_path.open(open_args)?,
|
||||
LookupResult::AtParent(result) => {
|
||||
if !open_args.creation_flags.contains(CreationFlags::O_CREAT) {
|
||||
return_errno_with_message!(Errno::ENOENT, "file does not exist");
|
||||
return_errno_with_message!(Errno::ENOENT, "the file does not exist");
|
||||
}
|
||||
if open_args
|
||||
.creation_flags
|
||||
.contains(CreationFlags::O_DIRECTORY)
|
||||
{
|
||||
return_errno_with_message!(Errno::ENOTDIR, "cannot create directory");
|
||||
return_errno_with_message!(
|
||||
Errno::EINVAL,
|
||||
"O_CREAT and O_DIRECTORY cannot be specified together"
|
||||
);
|
||||
}
|
||||
if result.target_is_dir() {
|
||||
return_errno_with_message!(Errno::EISDIR, "cannot create directory");
|
||||
return_errno_with_message!(
|
||||
Errno::EISDIR,
|
||||
"O_CREAT is specified but the file is a directory"
|
||||
);
|
||||
}
|
||||
|
||||
let (parent, tail_name) = result.into_parent_and_basename();
|
||||
|
|
|
|||
Loading…
Reference in New Issue