1- use std:: {
2- convert:: TryInto , fs:: OpenOptions , os:: unix:: prelude:: OpenOptionsExt , path:: Path , path:: PathBuf ,
3- } ;
1+ use std:: { convert:: TryInto , fs:: OpenOptions , os:: unix:: prelude:: OpenOptionsExt , path:: Path } ;
42
53use nix:: {
64 mount:: MsFlags ,
@@ -14,7 +12,7 @@ use crate::{mounts, rootfs};
1412pub fn create_devices ( spec_devices : & Option < Vec < runtime:: LinuxDevice > > , rootfs : & Path ) {
1513 let mut default_devices = vec ! [
1614 runtime:: LinuxDeviceBuilder :: default ( )
17- . path( PathBuf :: from ( "/dev/null" ) )
15+ . path( "/dev/null" )
1816 . file_mode( 0o666u32 )
1917 . typ( runtime:: LinuxDeviceType :: C )
2018 . major( 1 )
@@ -24,7 +22,7 @@ pub fn create_devices(spec_devices: &Option<Vec<runtime::LinuxDevice>>, rootfs:
2422 . build( )
2523 . unwrap( ) ,
2624 runtime:: LinuxDeviceBuilder :: default ( )
27- . path( PathBuf :: from ( "/dev/zero" ) )
25+ . path( "/dev/zero" )
2826 . file_mode( 0o666u32 )
2927 . typ( runtime:: LinuxDeviceType :: C )
3028 . major( 1 )
@@ -34,7 +32,7 @@ pub fn create_devices(spec_devices: &Option<Vec<runtime::LinuxDevice>>, rootfs:
3432 . build( )
3533 . unwrap( ) ,
3634 runtime:: LinuxDeviceBuilder :: default ( )
37- . path( PathBuf :: from ( "/dev/full" ) )
35+ . path( "/dev/full" )
3836 . file_mode( 0o666u32 )
3937 . typ( runtime:: LinuxDeviceType :: C )
4038 . major( 1 )
@@ -44,7 +42,7 @@ pub fn create_devices(spec_devices: &Option<Vec<runtime::LinuxDevice>>, rootfs:
4442 . build( )
4543 . unwrap( ) ,
4644 runtime:: LinuxDeviceBuilder :: default ( )
47- . path( PathBuf :: from ( "/dev/random" ) )
45+ . path( "/dev/random" )
4846 . file_mode( 0o666u32 )
4947 . typ( runtime:: LinuxDeviceType :: C )
5048 . major( 1 )
@@ -54,7 +52,7 @@ pub fn create_devices(spec_devices: &Option<Vec<runtime::LinuxDevice>>, rootfs:
5452 . build( )
5553 . unwrap( ) ,
5654 runtime:: LinuxDeviceBuilder :: default ( )
57- . path( PathBuf :: from ( "/dev/urandom" ) )
55+ . path( "/dev/urandom" )
5856 . file_mode( 0o666u32 )
5957 . typ( runtime:: LinuxDeviceType :: C )
6058 . major( 1 )
@@ -64,7 +62,7 @@ pub fn create_devices(spec_devices: &Option<Vec<runtime::LinuxDevice>>, rootfs:
6462 . build( )
6563 . unwrap( ) ,
6664 runtime:: LinuxDeviceBuilder :: default ( )
67- . path( PathBuf :: from ( "/dev/tty" ) )
65+ . path( "/dev/tty" )
6866 . file_mode( 0o666u32 )
6967 . typ( runtime:: LinuxDeviceType :: C )
7068 . major( 5 )
@@ -96,14 +94,12 @@ pub fn create_devices(spec_devices: &Option<Vec<runtime::LinuxDevice>>, rootfs:
9694 if !destination_resolved. starts_with ( rootfs) {
9795 panic ! ( "Device at {:?} cannot be mounted into rootfs!" , dev. path( ) ) ;
9896 }
99- mounts:: create_all_dirs ( & PathBuf :: from (
100- & destination_resolved. parent ( ) . unwrap_or_else ( || {
101- panic ! (
102- "Could create device at destination {:?} which has no parent dir!" ,
103- destination_resolved
104- )
105- } ) ,
106- ) ) ;
97+ mounts:: create_all_dirs ( destination_resolved. parent ( ) . unwrap_or_else ( || {
98+ panic ! (
99+ "Could create device at destination {:?} which has no parent dir!" ,
100+ destination_resolved
101+ )
102+ } ) ) ;
107103
108104 //Just assume we are not in a user namespace and that mknod will work. Error out if it does not (FIXME ?)
109105 let node_kind = match dev. typ ( ) {
@@ -158,8 +154,8 @@ fn verify_device(path: &Path, major_exp: u64, minor_exp: u64) {
158154}
159155
160156pub fn create_tun ( rootfs : & Path , uid : Uid , gid : Gid ) {
161- let destination_relative = PathBuf :: from ( "/dev/net/tun" ) ;
162- let destination_resolved = rootfs:: resolve_in_rootfs ( & destination_relative, rootfs) ;
157+ let destination_relative = Path :: new ( "/dev/net/tun" ) ;
158+ let destination_resolved = rootfs:: resolve_in_rootfs ( destination_relative, rootfs) ;
163159 if !destination_resolved. starts_with ( rootfs) {
164160 panic ! (
165161 "Device at {:?} cannot be mounted into rootfs!" ,
@@ -174,7 +170,7 @@ pub fn create_tun(rootfs: &Path, uid: Uid, gid: Gid) {
174170 )
175171 } ) ;
176172 if !parent. exists ( ) {
177- mounts:: create_all_dirs ( & PathBuf :: from ( & destination_resolved. parent ( ) . unwrap ( ) ) ) ;
173+ mounts:: create_all_dirs ( destination_resolved. parent ( ) . unwrap ( ) ) ;
178174 }
179175
180176 if destination_resolved. exists ( ) {
@@ -194,13 +190,13 @@ pub fn create_tun(rootfs: &Path, uid: Uid, gid: Gid) {
194190
195191pub fn mount_hermit_devices ( rootfs : & Path ) {
196192 if std:: fs:: metadata ( "/dev/kvm" ) . is_ok ( ) {
197- mount_device ( rootfs, & PathBuf :: from ( "/dev/kvm" ) , 10 , 232 ) ;
193+ mount_device ( rootfs, Path :: new ( "/dev/kvm" ) , 10 , 232 ) ;
198194 } else {
199195 warn ! ( "/dev/kvm doesn't exist and is consequently not supported!" ) ;
200196 }
201197
202198 if std:: fs:: metadata ( "/dev/vhost-net" ) . is_ok ( ) {
203- mount_device ( rootfs, & PathBuf :: from ( "/dev/vhost-net" ) , 10 , 238 ) ;
199+ mount_device ( rootfs, Path :: new ( "/dev/vhost-net" ) , 10 , 238 ) ;
204200 } else {
205201 warn ! ( "/dev/vhost-net doesn't exist and is consequently not supported!" ) ;
206202 }
@@ -216,7 +212,7 @@ fn mount_device(rootfs: &Path, destination_rel: &Path, major: u64, minor: u64) {
216212 } ) ;
217213
218214 if !parent. exists ( ) {
219- mounts:: create_all_dirs ( & PathBuf :: from ( & destination. parent ( ) . unwrap ( ) ) ) ;
215+ mounts:: create_all_dirs ( destination. parent ( ) . unwrap ( ) ) ;
220216 }
221217
222218 if destination. exists ( ) {
@@ -253,7 +249,7 @@ fn mount_device(rootfs: &Path, destination_rel: &Path, major: u64, minor: u64) {
253249}
254250
255251pub fn setup_dev_symlinks ( rootfs : & Path ) {
256- // if PathBuf::from ("/proc/kcore").exists() {
252+ // if Path::new ("/proc/kcore").exists() {
257253 // nix::unistd::symlinkat("/proc/kcore", None, &rootfs.join("dev/core"))
258254 // .expect("Could not symlink /proc/kcore to /dev/core");
259255 // }
0 commit comments