mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-08 11:19:07 +00:00
tools: fix create_path: don't use O_PATH
open(2) says file descriptors opened with O_PATH cannot be passed to fchmod(), fchown(), etc. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
5e1468bff8
commit
3c284b131d
@ -281,7 +281,7 @@ fn create_path_do(
|
|||||||
let _ = iter.next();
|
let _ = iter.next();
|
||||||
Fd::open(
|
Fd::open(
|
||||||
unsafe { CStr::from_bytes_with_nul_unchecked(b"/\0") },
|
unsafe { CStr::from_bytes_with_nul_unchecked(b"/\0") },
|
||||||
OFlag::O_DIRECTORY | OFlag::O_PATH,
|
OFlag::O_DIRECTORY,
|
||||||
stat::Mode::empty(),
|
stat::Mode::empty(),
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ fn create_path_do(
|
|||||||
let _ = iter.next();
|
let _ = iter.next();
|
||||||
Fd::open(
|
Fd::open(
|
||||||
unsafe { CStr::from_bytes_with_nul_unchecked(b"..\0") },
|
unsafe { CStr::from_bytes_with_nul_unchecked(b"..\0") },
|
||||||
OFlag::O_DIRECTORY | OFlag::O_PATH,
|
OFlag::O_DIRECTORY,
|
||||||
stat::Mode::empty(),
|
stat::Mode::empty(),
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
@ -323,7 +323,7 @@ fn create_path_at_do(
|
|||||||
at = Fd::openat(
|
at = Fd::openat(
|
||||||
at,
|
at,
|
||||||
unsafe { CStr::from_bytes_with_nul_unchecked(b"..\0") },
|
unsafe { CStr::from_bytes_with_nul_unchecked(b"..\0") },
|
||||||
OFlag::O_DIRECTORY | OFlag::O_PATH,
|
OFlag::O_DIRECTORY,
|
||||||
stat::Mode::empty(),
|
stat::Mode::empty(),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
@ -346,12 +346,7 @@ fn create_path_at_do(
|
|||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
Ok(_) => true,
|
Ok(_) => true,
|
||||||
};
|
};
|
||||||
at = Fd::openat(
|
at = Fd::openat(at, path, OFlag::O_DIRECTORY, stat::Mode::empty())?;
|
||||||
at,
|
|
||||||
path,
|
|
||||||
OFlag::O_DIRECTORY | OFlag::O_PATH,
|
|
||||||
stat::Mode::empty(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if let (true, Some(opts)) = (created, opts) {
|
if let (true, Some(opts)) = (created, opts) {
|
||||||
if opts.owner.is_some() || opts.group.is_some() {
|
if opts.owner.is_some() || opts.group.is_some() {
|
||||||
@ -366,6 +361,20 @@ fn create_path_at_do(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_create_path() {
|
||||||
|
create_path(
|
||||||
|
"testdir/testsub/testsub2/testfinal",
|
||||||
|
Some(CreateOptions::new().perm(stat::Mode::from_bits_truncate(0o755))),
|
||||||
|
Some(
|
||||||
|
CreateOptions::new()
|
||||||
|
.owner(Uid::effective())
|
||||||
|
.group(Gid::effective()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.expect("expected create_path to work");
|
||||||
|
}
|
||||||
|
|
||||||
// /usr/include/linux/fs.h: #define BLKGETSIZE64 _IOR(0x12,114,size_t)
|
// /usr/include/linux/fs.h: #define BLKGETSIZE64 _IOR(0x12,114,size_t)
|
||||||
// return device size in bytes (u64 *arg)
|
// return device size in bytes (u64 *arg)
|
||||||
nix::ioctl_read!(blkgetsize64, 0x12, 114, u64);
|
nix::ioctl_read!(blkgetsize64, 0x12, 114, u64);
|
||||||
|
Loading…
Reference in New Issue
Block a user