1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

mknod: cleanup dev handling

This commit is contained in:
Daniel Hofstetter 2025-04-23 11:49:29 +02:00
parent a3c181dce3
commit be4e6913a5

View file

@ -123,43 +123,38 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let set_selinux_context = matches.get_flag(options::SELINUX); let set_selinux_context = matches.get_flag(options::SELINUX);
let context = matches.get_one::<String>(options::CONTEXT); let context = matches.get_one::<String>(options::CONTEXT);
let mut config = Config { let dev = match (
file_type,
matches.get_one::<u64>(options::MAJOR),
matches.get_one::<u64>(options::MINOR),
) {
(FileType::Fifo, None, None) => 0,
(FileType::Fifo, _, _) => {
return Err(UUsageError::new(
1,
"Fifos do not have major and minor device numbers.",
));
}
(_, Some(&major), Some(&minor)) => makedev(major, minor),
_ => {
return Err(UUsageError::new(
1,
"Special files require major and minor device numbers.",
));
}
};
let config = Config {
mode, mode,
dev: 0, dev,
set_selinux_context: set_selinux_context || context.is_some(), set_selinux_context: set_selinux_context || context.is_some(),
context, context,
}; };
if *file_type == FileType::Fifo {
if matches.contains_id(options::MAJOR) || matches.contains_id(options::MINOR) {
Err(UUsageError::new(
1,
"Fifos do not have major and minor device numbers.",
))
} else {
let exit_code = mknod(file_name, config); let exit_code = mknod(file_name, config);
set_exit_code(exit_code); set_exit_code(exit_code);
Ok(()) Ok(())
} }
} else {
match (
matches.get_one::<u64>(options::MAJOR),
matches.get_one::<u64>(options::MINOR),
) {
(_, None) | (None, _) => Err(UUsageError::new(
1,
"Special files require major and minor device numbers.",
)),
(Some(&major), Some(&minor)) => {
let dev = makedev(major, minor);
config.dev = dev;
let exit_code = mknod(file_name, config);
set_exit_code(exit_code);
Ok(())
}
}
}
}
pub fn uu_app() -> Command { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())